Adapter
import { Adapter } from "@hyper-fetch/core"
Parameters
class Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType> {
constructor(options: { defaultExtra: Extra; defaultMethod: MethodType; defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>; name: string; systemErrorExtra: Extra; systemErrorStatus: StatusType }) {};
unstable_queryParamsMapperConfig: Parameters<QueryParamsMapperType>[1];
unstable_queryParamsMapper: QueryParamsMapperType;
unstable_payloadMapperConfig: Parameters<PayloadMapperType>[1];
unstable_payloadMapper: PayloadMapperType;
unstable_headerMapperConfig: Parameters<HeaderMapperType>[1];
unstable_headerMapper: HeaderMapperType;
unstable_endpointMapperConfig: Parameters<EndpointMapperType>[1];
unstable_endpointMapper: EndpointMapperType;
systemErrorStatus: StatusType;
systemErrorExtra: Extra;
options: { defaultExtra: Extra; defaultMethod: MethodType; defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>; name: string; systemErrorExtra: Extra; systemErrorStatus: StatusType };
name: string;
logger: LoggerMethods;
initialized: boolean;
defaultRequestOptions: RequestOptionsType<EndpointType, AdapterOptions, MethodType>;
defaultMethod: MethodType;
defaultExtra: Extra;
client: ClientInstance;
unstable_devtoolsEndpointGetter() => (endpoint: string) => string;
unstable_fetcher() => AdapterFetcherType<Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>;
unstable_getAdapterDefaults() => (request: ExtendRequest<RequestInstance, { client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>> }>) => AdapterOptions;
unstable_getRequestDefaults() => (options: RequestOptionsType<EndpointType, AdapterOptions, MethodType>) => Partial<RequestOptionsType<EndpointType, AdapterOptions, MethodType>>;
unstable_internalErrorMapping() => (error: TimeoutError | AbortError | DeletedError | RequestProcessingError | UnexpectedError) => any;
unstable_onInitializeCallback() => (options: { client: ClientInstance }) => void;
fetch(request: ExtendRequest<RequestInstance, { client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>> }>, requestId: string) => Promise<RequestResponseType<RequestInstance>>;
initialize(client: ClientInstance) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
onInitialize(callback: (options: { client: ClientInstance }) => void) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setAdapterDefaults(callback: (request: ExtendRequest<RequestInstance, { client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>> }>) => AdapterOptions) => this;
setDefaultExtra(extra: Extra) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setDefaultMethod(method: MethodType) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setDevtoolsEndpointGetter(callback: (endpoint: string) => string) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setEndpointMapper<NewEndpointMapper>(endpointMapper: NewEndpointMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, NewEndpointMapper, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setEndpointMapperConfig<NewEndpointMapperConfig>(config: NewEndpointMapperConfig) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setFetcher(fetcher: AdapterFetcherType<Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setHeaderMapper<NewMapper>(headerMapper: NewMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, NewMapper, PayloadMapperType>;
setHeaderMapperConfig<NewHeaderMapperConfig>(config: NewHeaderMapperConfig) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setInternalErrorMapping(callback: (error: TimeoutError | AbortError | DeletedError | RequestProcessingError | UnexpectedError) => any) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setPayloadMapper<NewMapper>(payloadMapper: NewMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, NewMapper>;
setPayloadMapperConfig<NewPayloadMapperConfig>(config: NewPayloadMapperConfig) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setQueryParamsMapper<NewQueryParamsMapper>(queryParamsMapper: NewQueryParamsMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, NewQueryParamsMapper, HeaderMapperType, PayloadMapperType>;
setQueryParamsMapperConfig<NewQueryParamsMapperConfig>(config: NewQueryParamsMapperConfig) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setRequestDefaults(callback: undefined | (options: RequestOptionsType<EndpointType, AdapterOptions, MethodType>) => Partial<RequestOptionsType<EndpointType, AdapterOptions, MethodType>>) => this;
}
| Name | Type | Description |
|---|---|---|
| options | |
Properties
options
Type
{ defaultExtra: Extra; defaultMethod: MethodType; defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>; name: string; systemErrorExtra: Extra; systemErrorStatus: StatusType }
unstable_endpointMapper
Method to get the endpoint for the adapter request.
Type
EndpointMapperType
unstable_headerMapper
Method to get default headers and to map them based on the data format exchange, by default it handles FormData / JSON formats.
Type
HeaderMapperType
unstable_payloadMapper
Method to get request data and transform them to the required format. It handles FormData and JSON by default.
Type
PayloadMapperType
unstable_queryParamsMapper
Method to get request data and transform them to the required format.
Type
QueryParamsMapperType
Methods
fetch()
Preview
fetch(request: ExtendRequest<RequestInstance, { client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>> }>, requestId: string)
Parameters
| Name | Type | Description |
|---|---|---|
| request | | |
| requestId | |
Returns
Promise<RequestResponseType<RequestInstance>>
initialize()
Preview
initialize(client: ClientInstance)
Parameters
| Name | Type | Description |
|---|---|---|
| client | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>
onInitialize()
Preview
onInitialize(callback: (options: { client: ClientInstance }) => void)
Parameters
| Name | Type | Description |
|---|---|---|
| callback | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>
setAdapterDefaults()
Set the adapter default options added to every sent request
Preview
setAdapterDefaults(callback: (request: ExtendRequest<RequestInstance, { client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>> }>) => AdapterOptions)
Parameters
| Name | Type | Description |
|---|---|---|
| callback | |
Returns
this
setDefaultExtra()
Preview
setDefaultExtra(extra: Extra)
Parameters
| Name | Type | Description |
|---|---|---|
| extra | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>
setDefaultMethod()
Methods
Preview
setDefaultMethod(method: MethodType)
Parameters
| Name | Type | Description |
|---|---|---|
| method | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>
setDevtoolsEndpointGetter()
Preview
setDevtoolsEndpointGetter(callback: (endpoint: string) => string)
Parameters
| Name | Type | Description |
|---|---|---|
| callback | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>
setEndpointMapper()
Set the request payload mapping function which get triggered before request get sent
Preview
setEndpointMapper<NewEndpointMapper>(endpointMapper: NewEndpointMapper)
Parameters
| Name | Type | Description |
|---|---|---|
| endpointMapper | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, NewEndpointMapper, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>
setEndpointMapperConfig()
Preview
setEndpointMapperConfig<NewEndpointMapperConfig>(config: NewEndpointMapperConfig)
Parameters
| Name | Type | Description |
|---|---|---|
| config | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>
setFetcher()
Fetching
Preview
setFetcher(fetcher: AdapterFetcherType<Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>)
Parameters
| Name | Type | Description |
|---|---|---|
| fetcher | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>
setHeaderMapper()
Set the custom header mapping function
Preview
setHeaderMapper<NewMapper>(headerMapper: NewMapper)
Parameters
| Name | Type | Description |
|---|---|---|
| headerMapper | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, NewMapper, PayloadMapperType>
setHeaderMapperConfig()
Preview
setHeaderMapperConfig<NewHeaderMapperConfig>(config: NewHeaderMapperConfig)
Parameters
| Name | Type | Description |
|---|---|---|
| config | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>
setInternalErrorMapping()
Preview
setInternalErrorMapping(callback: (error: TimeoutError | AbortError | DeletedError | RequestProcessingError | UnexpectedError) => any)
Parameters
| Name | Type | Description |
|---|---|---|
| callback | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>
setPayloadMapper()
Set the request payload mapping function which gets triggered before request is send
Preview
setPayloadMapper<NewMapper>(payloadMapper: NewMapper)
Parameters
| Name | Type | Description |
|---|---|---|
| payloadMapper | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, NewMapper>
setPayloadMapperConfig()
Preview
setPayloadMapperConfig<NewPayloadMapperConfig>(config: NewPayloadMapperConfig)
Parameters
| Name | Type | Description |
|---|---|---|
| config | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>
setQueryParamsMapper()
Set the query params mapping function which get triggered before request get sent
Preview
setQueryParamsMapper<NewQueryParamsMapper>(queryParamsMapper: NewQueryParamsMapper)
Parameters
| Name | Type | Description |
|---|---|---|
| queryParamsMapper | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, NewQueryParamsMapper, HeaderMapperType, PayloadMapperType>
setQueryParamsMapperConfig()
Preview
setQueryParamsMapperConfig<NewQueryParamsMapperConfig>(config: NewQueryParamsMapperConfig)
Parameters
| Name | Type | Description |
|---|---|---|
| config | |
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>
setRequestDefaults()
This method allows to configure global defaults for the request configuration like method, auth, deduplication etc.
Preview
setRequestDefaults(callback: undefined | (options: RequestOptionsType<EndpointType, AdapterOptions, MethodType>) => Partial<RequestOptionsType<EndpointType, AdapterOptions, MethodType>>)
Parameters
| Name | Type | Description |
|---|---|---|
| callback | |
Returns
this
