import { AnyAction, ThunkDispatch } from '@reduxjs/toolkit'; import { RootState } from './core/apiState'; import { BaseQueryExtraOptions, BaseQueryFn, BaseQueryResult, BaseQueryArg, BaseQueryApi, QueryReturnValue, BaseQueryError, BaseQueryMeta } from './baseQueryTypes'; import { HasRequiredProps, MaybePromise, OmitFromUnion, CastAny } from './tsHelpers'; import { NEVER } from './fakeBaseQuery'; declare const resultType: unique symbol; declare const baseQuery: unique symbol; interface EndpointDefinitionWithQuery { /** * `query` is the only required property, and can be a function that returns either a `string` or an `object` which is passed to your `baseQuery`. If you are using [fetchBaseQuery](./fetchBaseQuery), this can return either a `string` or an `object` of properties in `FetchArgs`. If you use your own custom `baseQuery`, you can customize this behavior to your liking */ query(arg: QueryArg): BaseQueryArg; queryFn?: never; /** * A function to manipulate the data returned by a query or mutation */ transformResponse?(baseQueryReturnValue: BaseQueryResult, meta: BaseQueryMeta): ResultType | Promise; } interface EndpointDefinitionWithQueryFn { queryFn(arg: QueryArg, api: BaseQueryApi, extraOptions: BaseQueryExtraOptions, baseQuery: (arg: Parameters[0]) => ReturnType): MaybePromise>>; query?: never; transformResponse?: never; } export declare type BaseEndpointDefinition = (([CastAny, {}>] extends [NEVER] ? never : EndpointDefinitionWithQuery) | EndpointDefinitionWithQueryFn) & { [resultType]?: ResultType; [baseQuery]?: BaseQuery; } & HasRequiredProps, { extraOptions: BaseQueryExtraOptions; }, { extraOptions?: BaseQueryExtraOptions; }>; export declare enum DefinitionType { query = "query", mutation = "mutation" } declare type GetResultDescriptionFn = (result: ResultType | undefined, error: ErrorType | undefined, arg: QueryArg) => ReadonlyArray>; export declare type FullTagDescription = { type: TagType; id?: number | string; }; declare type TagDescription = TagType | FullTagDescription; declare type ResultDescription = ReadonlyArray> | GetResultDescriptionFn; export interface QueryApi { /** * The dispatch method for the store */ dispatch: ThunkDispatch; /** * A method to get the current state */ getState(): RootState; /** * `extra` as provided as `thunk.extraArgument` to the `configureStore` `getDefaultMiddleware` option. */ extra: unknown; /** * A unique ID generated for the mutation */ requestId: string; /** * A variable shared between `onStart`, `onError` and `onSuccess` of one request to pass data forward between them */ context: Context; } interface QueryExtraOptions> { type: DefinitionType.query; /** * - Used by `queries` to provide tags to the cache. * - Expects an array of tag type strings, or an array of objects of tag types with ids. * 1. `['Post']` - equivalent to `b` * 2. `[{ type: 'Post' }]` - equivalent to `a` * 3. `[{ type: 'Post', id: 1 }]` */ providesTags?: ResultDescription>; /** @deprecated renamed to `providesTags` */ provides?: ResultDescription>; /** * Not to be used. A query should not invalidate tags in the cache. */ invalidatesTags?: never; /** @deprecated */ invalidates?: never; /** * Called when the query is triggered. * @param arg - The argument supplied to the query * @param queryApi - An object containing `dispatch`, `getState()`, `extra`, `request`Id`, `context` */ onStart?(arg: QueryArg, queryApi: QueryApi): void; /** * Called when an error response is returned by the query. * @param arg - The argument supplied to the query * @param queryApi - A query API containing `dispatch`, `getState()`, `extra`, `request`Id`, `context` * @param error - The error returned by the query * @param meta - Meta item from the base query */ onError?(arg: QueryArg, queryApi: QueryApi, error: unknown, meta: BaseQueryMeta): void; /** * Called when a successful response is returned by the query. * @param arg - The argument supplied to the query * @param queryApi - A query API containing `dispatch`, `getState()`, `extra`, `request`Id`, `context` * @param result - The response returned by the query * @param meta - Meta item from the base query */ onSuccess?(arg: QueryArg, queryApi: QueryApi, result: ResultType, meta: BaseQueryMeta | undefined): void; } export declare type QueryDefinition> = BaseEndpointDefinition & QueryExtraOptions; export interface MutationApi { /** * The dispatch method for the store */ dispatch: ThunkDispatch; /** * A method to get the current state */ getState(): RootState; /** * `extra` as provided as `thunk.extraArgument` to the `configureStore` `getDefaultMiddleware` option. */ extra: unknown; /** * A unique ID generated for the mutation */ requestId: string; /** * A variable shared between `onStart`, `onError` and `onSuccess` of one request to pass data forward between them */ context: Context; } interface MutationExtraOptions> { type: DefinitionType.mutation; /** * - Used by `mutations` for [cache invalidation](../concepts/mutations#advanced-mutations-with-revalidation) purposes. * - Expects the same shapes as `provides`. */ invalidatesTags?: ResultDescription>; /** @deprecated renamed to `invalidatesTags` */ invalidates?: ResultDescription>; /** * Not to be used. A mutation should not provide tags to the cache. */ providesTags?: never; /** @deprecated */ provides?: never; /** * Called when the mutation is triggered. * @param arg - The argument supplied to the query * @param mutationApi - An object containing `dispatch`, `getState()`, `extra`, `request`Id`, `context` */ onStart?(arg: QueryArg, mutationApi: MutationApi): void; /** * Called when an error response is returned by the mutation. * @param arg - The argument supplied to the query * @param mutationApi - A mutation API containing `dispatch`, `getState()`, `extra`, `request`Id`, `context` * @param error - The error returned by the mutation * @param meta - Meta item from the base query */ onError?(arg: QueryArg, mutationApi: MutationApi, error: unknown, meta: BaseQueryMeta): void; /** * Called when a successful response is returned by the mutation. * @param arg - The argument supplied to the query * @param mutationApi - A mutation API containing `dispatch`, `getState()`, `extra`, `request`Id`, `context` * @param result - The response returned by the mutation * @param meta - Meta item from the base query */ onSuccess?(arg: QueryArg, mutationApi: MutationApi, result: ResultType, meta: BaseQueryMeta | undefined): void; } export declare type MutationDefinition> = BaseEndpointDefinition & MutationExtraOptions; export declare type EndpointDefinition = QueryDefinition | MutationDefinition; export declare type EndpointDefinitions = Record>; export declare function isQueryDefinition(e: EndpointDefinition): e is QueryDefinition; export declare function isMutationDefinition(e: EndpointDefinition): e is MutationDefinition; export declare type EndpointBuilder = { /** * An endpoint definition that retrieves data, and may provide tags to the cache. * * @example * ```js * // codeblock-meta title="Example of all query endpoint options" * const api = createApi({ * baseQuery, * endpoints: (build) => ({ * getPost: build.query({ * query: (id) => ({ url: `post/${id}` }), * // Pick out data and prevent nested properties in a hook or selector * transformResponse: (response) => response.data, * // The 2nd parameter is the destructured `queryApi` * onStart(id, { dispatch, getState, extra, requestId, context }) {}, * // `result` is the server response * onSuccess(id, queryApi, result) {}, * onError(id, queryApi) {}, * providesTags: (result, error, id) => [{ type: 'Post', id }], * }), * }), *}); *``` */ query(definition: OmitFromUnion, 'type'>): QueryDefinition; /** * An endpoint definition that alters data on the server or will possibly invalidate the cache. * * @example * ```js * // codeblock-meta title="Example of all mutation endpoint options" * const api = createApi({ * baseQuery, * endpoints: (build) => ({ * updatePost: build.mutation({ * query: ({ id, ...patch }) => ({ url: `post/${id}`, method: 'PATCH', body: patch }), * // Pick out data and prevent nested properties in a hook or selector * transformResponse: (response) => response.data, * // onStart, onSuccess, onError are useful for optimistic updates * // The 2nd parameter is the destructured `mutationApi` * onStart({ id, ...patch }, { dispatch, getState, extra, requestId, context }) {}, * // `result` is the server response * onSuccess({ id }, mutationApi, result) {}, * onError({ id }, { dispatch, getState, extra, requestId, context }) {}, * invalidatesTags: (result, error, id) => [{ type: 'Post', id }], * }), * }), * }); * ``` */ mutation>(definition: OmitFromUnion, 'type'>): MutationDefinition; }; export declare type AssertTagTypes = >(t: T) => T; export declare function calculateProvidedBy(description: ResultDescription | undefined, result: ResultType | undefined, error: ErrorType | undefined, queryArg: QueryArg, assertTagTypes: AssertTagTypes): readonly FullTagDescription[]; export declare type QueryArgFrom> = D extends BaseEndpointDefinition ? QA : unknown; export declare type ResultTypeFrom> = D extends BaseEndpointDefinition ? RT : unknown; export declare type ReducerPathFrom> = D extends EndpointDefinition ? RP : unknown; export declare type TagTypesFrom> = D extends EndpointDefinition ? RP : unknown; export declare type ReplaceTagTypes = { [K in keyof Definitions]: Definitions[K] extends QueryDefinition ? QueryDefinition : Definitions[K] extends MutationDefinition ? MutationDefinition : never; }; export {}; //# sourceMappingURL=endpointDefinitions.d.ts.map