import { RequestSendType, PayloadType, RequestJSON, RequestOptionsType, RequestConfigurationType, PayloadMapperType, RequestInstance, RequestMapper, ResponseMapper, ExtractUrlParams, RetryOnErrorCallbackType, OptimisticCallback } from './request.types'; import { RequestHooks } from './request.hooks'; import { ClientInstance } from '../client'; import { ResponseErrorType, ResponseSuccessType, ResponseType } from '../adapter'; import { ExtractClientAdapterType, ExtractClientGlobalError, ExtractParamsType, EmptyTypes, ExtractAdapterMethodType, ExtractAdapterOptionsType, HydrateDataType, SyncOrAsync } from '../types'; import { MockerConfigType, MockResponseType } from '../mocker'; type ClientAdapterOptions = ExtractAdapterOptionsType>; type ClientAdapterMethod = ExtractAdapterMethodType>; type ClientRequestOptions = RequestOptionsType, ClientAdapterMethod>; /** * Request is a class that represents a request sent to the server. It contains all the necessary information to make a request, like endpoint, method, headers, data, and much more. * It is executed at any time via methods like `send` or `exec`. * * We can set it up with options like endpoint, method, headers and more. * We can choose some of advanced settings like cache, invalidation patterns, concurrency, retries and much, much more. * * @info We should not use this class directly in the standard development flow. * We can initialize it using the `createRequest` method on the **Client** class. * * @attention The most important thing about the request is that it keeps data in the format that can be dumped. * This is necessary for the persistence and different dispatcher storage types. * This class doesn't have any callback methods by design and communicate with dispatcher and cache by events. * * It should be serializable to JSON and deserializable back to the class. * Serialization should not affect the result of the request, so it's methods and functional part should be only syntax sugar for given runtime. */ export declare class Request { readonly client: Client; readonly requestOptions: ClientRequestOptions; readonly initialRequestConfiguration?: RequestConfigurationType : never, QueryParams, Endpoint, ClientAdapterOptions, ClientAdapterMethod> | undefined; endpoint: Endpoint; headers?: HeadersInit; auth: boolean; method: ClientAdapterMethod; params: ExtractUrlParams | EmptyTypes; payload: PayloadType; queryParams: QueryParams | EmptyTypes; options?: ClientAdapterOptions | undefined; cancelable: boolean; retry: number; retryTime: number; cacheTime: number; cache: boolean; staleTime: number; queued: boolean; offline: boolean; abortKey: string; cacheKey: string; queryKey: string; used: boolean; deduplicate: boolean; deduplicateTime: number | null; scope: string | null; /** * Instance-level lifecycle hooks. These callbacks fire for every `send()` / `exec()` call * made on this request instance (and its clones), without needing to pass them to `send()` each time. * Useful for cross-cutting concerns like logging, analytics, or toast notifications. * * Each method registers a callback and returns an unsubscribe function. * Multiple listeners per hook are supported. */ $hooks: RequestHooks; isMockerEnabled: boolean; unstable_mock?: { fn: (options: { request: RequestInstance; requestId: string; }) => MockResponseType, ExtractClientAdapterType>; config: MockerConfigType; }; /** @internal */ unstable_payloadMapper?: PayloadMapperType; /** @internal */ unstable_requestMapper?: RequestMapper; /** @internal */ unstable_responseMapper?: ResponseMapper | ResponseErrorType>; /** @internal */ retryOnError?: RetryOnErrorCallbackType; /** @internal */ optimistic?: OptimisticCallback; unstable_hasParams: HasParams; unstable_hasPayload: HasPayload; unstable_hasQuery: HasQuery; unstable_hasMutationContext: MutationContext; private updatedAbortKey; private updatedCacheKey; private updatedQueryKey; constructor(client: Client, requestOptions: ClientRequestOptions, initialRequestConfiguration?: RequestConfigurationType : never, QueryParams, Endpoint, ClientAdapterOptions, ClientAdapterMethod> | undefined); setHeaders: (headers: HeadersInit) => Request; setAuth: (auth: boolean) => Request; setParams:

>(params: P) => Request; setPayload:

(payload: P) => Request; setQueryParams: (queryParams: QueryParams) => Request; setOptions: (options: ClientAdapterOptions) => Request; /** * Set a scope identifier for this request. * All keys (cache, queue, abort) are prefixed with this scope, isolating * the request from other scopes. In "server" client mode, setting a scope * also enables caching (which is otherwise disabled to prevent cross-request leaks). */ setScope: (scopeId: string) => Request; setCancelable: (cancelable: boolean) => Request; setRetry: (retry: ClientRequestOptions["retry"]) => Request; setRetryTime: (retryTime: ClientRequestOptions["retryTime"]) => Request; /** * Set a callback that controls whether a failed request should be retried. * Called on each failed attempt before scheduling the next retry. * Return `true` to allow the retry, `false` to stop retrying immediately. */ setRetryOnError: (callback: RetryOnErrorCallbackType>) => Request; /** * Configure optimistic update behavior for this request. * The callback runs before the request is sent (in React's `useSubmit`) and receives * the request, client, and payload. Return `context` (available in submit callbacks), * `rollback` (called automatically on failure/abort), and `invalidate` (cache keys * invalidated on success). */ setOptimistic: (callback: OptimisticCallback) => Request; setCacheTime: (cacheTime: ClientRequestOptions["cacheTime"]) => Request; setCache: (cache: ClientRequestOptions["cache"]) => Request; setStaleTime: (staleTime: ClientRequestOptions["staleTime"]) => Request; setQueued: (queued: boolean) => Request; setAbortKey: (abortKey: string) => Request; setCacheKey: (cacheKey: string) => Request; setQueryKey: (queryKey: string) => Request; setDeduplicate: (deduplicate: boolean) => Request; setDeduplicateTime: (deduplicateTime: number) => Request; setUsed: (used: boolean) => Request; setOffline: (offline: boolean) => Request; setMock: (fn: (options: { request: Request; requestId: string; }) => SyncOrAsync, ExtractClientAdapterType>>, config?: MockerConfigType) => this; clearMock: () => this; setMockingEnabled: (isMockerEnabled: boolean) => this; /** * Map data before it gets send to the server * @param payloadMapper * @returns */ setPayloadMapper: >(payloadMapper: (data: Payload) => MappedPayload) => Request; /** * Map request before it gets send to the server * @param requestMapper mapper of the request * @returns new request */ setRequestMapper: (requestMapper: RequestMapper) => Request; /** * Map the response to the new interface * @param responseMapper our mapping callback * @returns new response */ setResponseMapper: | ResponseErrorType>(responseMapper?: ResponseMapper) => Request ? R : Response, Payload, QueryParams, MappedResponse extends ResponseType ? E : LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>; private paramsMapper; toJSON(): RequestJSON; clone(configuration?: RequestConfigurationType, ClientAdapterMethod>): Request; abort: () => Request; dehydrate: (config?: { /** in case of using adapter without cache we can provide response to dehydrate */ response?: ResponseType, ExtractClientAdapterType>; /** override cache data */ override?: boolean; }) => HydrateDataType, ExtractClientAdapterType> | undefined; /** * Read the response from cache data * * If it returns error and data at the same time, it means that latest request was failed * and we show previous data from cache together with error received from actual request */ read(): ResponseType, ExtractClientAdapterType> | undefined; /** * Method to use the request WITHOUT adding it to cache and queues. This mean it will make simple request without queue side effects. * @param options * @disableReturns * @returns * ```tsx * Promise<[Data | null, Error | null, HttpStatus]> * ``` */ exec: RequestSendType; /** * Method used to perform requests with usage of cache and queues * @param options * @param requestCallback * @disableReturns * @returns * ```tsx * Promise<{ data: Data | null, error: Error | null, status: HttpStatus, ... }> * ``` */ send: RequestSendType; static fromJSON: (client: NewClient, json: RequestJSON>) => Request; } export {}; //# sourceMappingURL=request.d.ts.map