import { AdapterInstance, ResponseType } from '../adapter'; import { HttpAdapterType } from '../http-adapter'; import { ClientErrorType, ClientInstance, ClientMode, ClientOptionsType, RequestGenericType, RequestInterceptorType, ResponseInterceptorType } from '.'; import { Cache } from '../cache'; import { Dispatcher } from '../dispatcher'; import { PluginInstance, PluginMethodParameters, PluginMethods } from '../plugin'; import { RequestInstance, RequestJSON, RequestOptionsType, Request } from '../request'; import { LogLevel, AppManager, LoggerManager, RequestManager } from '../managers'; import { EmptyTypes, TypeWithDefaults, ExtractAdapterMethodType, ExtractAdapterOptionsType, ExtractAdapterQueryParamsType, ExtractAdapterEndpointType, ExtractUnionAdapter, HydrateDataType, HydrationOptions, ExtractAdapterDefaultQueryParamsType } from '../types'; /** * **Client** is a class that allows you to configure the connection with the server and then use it to create * requests. It allows you to set global defaults for the requests configuration, query params configuration. * It is also orchestrator for all of the HyperFetch modules like Cache, Dispatcher, AppManager, LoggerManager, * RequestManager and more. */ export declare class Client { options: ClientOptionsType>; readonly url: string; readonly mode: ClientMode; debug: boolean; unstable_onErrorCallbacks: ResponseInterceptorType[]; unstable_onSuccessCallbacks: ResponseInterceptorType[]; unstable_onResponseCallbacks: ResponseInterceptorType[]; unstable_onAuthCallbacks: RequestInterceptorType[]; unstable_onRequestCallbacks: RequestInterceptorType[]; loggerManager: LoggerManager; requestManager: RequestManager; appManager: AppManager; adapter: Adapter; cache: Cache; fetchDispatcher: Dispatcher; submitDispatcher: Dispatcher; isMockerEnabled: boolean; plugins: PluginInstance[]; /** @internal */ unstable_abortKeyMapper: (request: RequestInstance) => string; /** @internal */ unstable_cacheKeyMapper: (request: RequestInstance) => string; /** @internal */ unstable_queryKeyMapper: (request: RequestInstance) => string; /** @internal */ unstable_requestIdMapper: (request: RequestInstance) => string; logger: import('../managers').LoggerMethods; constructor(options: ClientOptionsType>); /** * This method enables the logger usage and display the logs in console */ setDebug: (enabled: boolean) => Client; /** * Set the logger severity of the messages displayed to the console */ setLogLevel: (severity: LogLevel) => Client; /** * Set the new logger instance to the Client */ setLogger: (callback: (Client: ClientInstance) => LoggerManager) => Client; /** * Set globally if mocking should be enabled or disabled for all client requests. * @param isMockerEnabled */ setEnableGlobalMocking: (isMockerEnabled: boolean) => this; /** * Set custom http adapter to handle graphql, rest, firebase or others */ setAdapter: (adapter: NewAdapter) => Client; /** * Method of manipulating requests before sending the request. We can for example add custom header with token to the request which request had the auth set to true. */ onAuth: (callback: RequestInterceptorType) => Client; /** * Method for removing listeners on auth. * */ removeOnAuthInterceptors: (callbacks: RequestInterceptorType[]) => Client; /** * Method for intercepting error responses. It can be used for example to refresh tokens. */ onError: (callback: ResponseInterceptorType) => Client; /** * Method for removing listeners on error. * */ removeOnErrorInterceptors: (callbacks: ResponseInterceptorType[]) => Client; /** * Method for intercepting success responses. */ onSuccess: (callback: ResponseInterceptorType) => Client; /** * Method for removing listeners on success. * */ removeOnSuccessInterceptors: (callbacks: ResponseInterceptorType[]) => Client; /** * Method of manipulating requests before sending the request. */ onRequest: (callback: RequestInterceptorType) => Client; /** * Method for removing listeners on request. * */ removeOnRequestInterceptors: (callbacks: RequestInterceptorType[]) => Client; /** * Method for intercepting any responses. */ onResponse: (callback: ResponseInterceptorType) => Client; /** * Method for removing listeners on request. * */ removeOnResponseInterceptors: (callbacks: ResponseInterceptorType[]) => Client; /** * Add persistent plugins which trigger on the request lifecycle */ addPlugin: (plugin: PluginInstance) => this; /** * Remove plugins from Client */ removePlugin: (plugin: PluginInstance) => this; triggerPlugins: >(key: Key, data: PluginMethodParameters) => this; /** * Key setters */ setAbortKeyMapper: (callback: (request: RequestInstance) => string) => this; setCacheKeyMapper: (callback: (request: RequestInstance) => string) => this; setQueryKeyMapper: (callback: (request: RequestInstance) => string) => this; setRequestIdMapper: (callback: (request: RequestInstance) => string) => this; /** * Helper used by http adapter to apply the modifications on response error * @private */ unstable_modifyAuth: (request: RequestInstance) => Promise; /** * Private helper to run async pre-request processing * @private */ unstable_modifyRequest: (request: RequestInstance) => Promise; /** * Private helper to run async on-error response processing * @private */ unstable_modifyErrorResponse: (response: ResponseType, request: RequestInstance) => Promise>; /** * Private helper to run async on-success response processing * @private */ unstable_modifySuccessResponse: (response: ResponseType, request: RequestInstance) => Promise>; /** * Private helper to run async response processing * @private */ unstable_modifyResponse: (response: ResponseType, request: RequestInstance) => Promise>; /** * Reconstruct a Request class instance from its serialized JSON form. * Useful when dispatcher storage serializes queue data (e.g. MMKV, AsyncStorage) * and the deserialized request loses its class identity. */ fromJSON: > = {}>(json: RequestJSON) => Request, TypeWithDefaults, TypeWithDefaults, never>, TypeWithDefaults, TypeWithDefaults extends string ? TypeWithDefaults : string, Client>; /** * Clears the Client instance and remove all listeners on it's dependencies */ clear: () => void; /** * Hydrate your SSR cache data * @param hydrationData * @param options */ hydrate: (hydrationData: (HydrateDataType | EmptyTypes)[], options?: Partial | ((item: HydrateDataType) => Partial)) => void; /** * Create requests based on the Client setup * * @template Response Your response */ createRequest: > = {}>( /** * `createRequest` must be initialized twice(currying). * * ✅ Good: * ```ts * const request = createRequest()(params) * ``` * ⛔ Bad: * ```ts * const request = createRequest(params) * ``` * * We are using currying to achieve auto generated types for the endpoint string. * * This solution will be removed once https://github.com/microsoft/TypeScript/issues/10571 get resolved. */ _USE_DOUBLE_INITIALIZATION?: never) => , AdapterOptions extends ExtractAdapterOptionsType, MethodType extends ExtractAdapterMethodType>(params: RequestOptionsType) => Request, TypeWithDefaults, TypeWithDefaults, never>, TypeWithDefaults, TypeWithDefaults extends string ? TypeWithDefaults : any, Client, never>; }> extends EmptyTypes ? Adapter : ExtractUnionAdapter, never>; }>>, false, false, false, undefined>; } //# sourceMappingURL=client.d.ts.map