1import type { InternalSerializeQueryArgs } from '../defaultSerializeQueryArgs'; 2import type { Api, ApiContext } from '../apiTypes'; 3import type { BaseQueryFn, BaseQueryError } from '../baseQueryTypes'; 4import type { RootState, QueryKeys, QuerySubstateIdentifier } from './apiState'; 5import { CombinedState } from './apiState'; 6import type { StartQueryActionCreatorOptions } from './buildInitiate'; 7import type { AssertTagTypes, EndpointDefinition, EndpointDefinitions, MutationDefinition, QueryArgFrom, QueryDefinition, ResultTypeFrom } from '../endpointDefinitions'; 8import { FullTagDescription } from '../endpointDefinitions'; 9import type { Draft } from '@reduxjs/toolkit'; 10import type { Patch } from 'immer'; 11import type { AnyAction, ThunkAction, AsyncThunk } from '@reduxjs/toolkit'; 12import type { PrefetchOptions } from './module'; 13import type { UnwrapPromise } from '../tsHelpers'; 14declare module './module' { 15 interface ApiEndpointQuery<Definition extends QueryDefinition<any, any, any, any, any>, Definitions extends EndpointDefinitions> extends Matchers<QueryThunk, Definition> { 16 } 17 interface ApiEndpointMutation<Definition extends MutationDefinition<any, any, any, any, any>, Definitions extends EndpointDefinitions> extends Matchers<MutationThunk, Definition> { 18 } 19} 20declare type EndpointThunk<Thunk extends QueryThunk | MutationThunk, Definition extends EndpointDefinition<any, any, any, any>> = Definition extends EndpointDefinition<infer QueryArg, infer BaseQueryFn, any, infer ResultType> ? Thunk extends AsyncThunk<unknown, infer ATArg, infer ATConfig> ? AsyncThunk<ResultType, ATArg & { 21 originalArgs: QueryArg; 22}, ATConfig & { 23 rejectValue: BaseQueryError<BaseQueryFn>; 24}> : never : never; 25export declare type PendingAction<Thunk extends QueryThunk | MutationThunk, Definition extends EndpointDefinition<any, any, any, any>> = ReturnType<EndpointThunk<Thunk, Definition>['pending']>; 26export declare type FulfilledAction<Thunk extends QueryThunk | MutationThunk, Definition extends EndpointDefinition<any, any, any, any>> = ReturnType<EndpointThunk<Thunk, Definition>['fulfilled']>; 27export declare type RejectedAction<Thunk extends QueryThunk | MutationThunk, Definition extends EndpointDefinition<any, any, any, any>> = ReturnType<EndpointThunk<Thunk, Definition>['rejected']>; 28export declare type Matcher<M> = (value: any) => value is M; 29export interface Matchers<Thunk extends QueryThunk | MutationThunk, Definition extends EndpointDefinition<any, any, any, any>> { 30 matchPending: Matcher<PendingAction<Thunk, Definition>>; 31 matchFulfilled: Matcher<FulfilledAction<Thunk, Definition>>; 32 matchRejected: Matcher<RejectedAction<Thunk, Definition>>; 33} 34export interface QueryThunkArg extends QuerySubstateIdentifier, StartQueryActionCreatorOptions { 35 originalArgs: unknown; 36 endpointName: string; 37} 38export interface MutationThunkArg { 39 originalArgs: unknown; 40 endpointName: string; 41 track?: boolean; 42} 43export declare type ThunkResult = unknown; 44export declare type ThunkApiMetaConfig = { 45 pendingMeta: { 46 startedTimeStamp: number; 47 }; 48 fulfilledMeta: { 49 fulfilledTimeStamp: number; 50 baseQueryMeta: unknown; 51 }; 52 rejectedMeta: { 53 baseQueryMeta: unknown; 54 }; 55}; 56export declare type QueryThunk = AsyncThunk<ThunkResult, QueryThunkArg, ThunkApiMetaConfig>; 57export declare type MutationThunk = AsyncThunk<ThunkResult, MutationThunkArg, ThunkApiMetaConfig>; 58export declare type MaybeDrafted<T> = T | Draft<T>; 59export declare type Recipe<T> = (data: MaybeDrafted<T>) => void | MaybeDrafted<T>; 60export declare type PatchQueryDataThunk<Definitions extends EndpointDefinitions, PartialState> = <EndpointName extends QueryKeys<Definitions>>(endpointName: EndpointName, args: QueryArgFrom<Definitions[EndpointName]>, patches: readonly Patch[]) => ThunkAction<void, PartialState, any, AnyAction>; 61export declare type UpdateQueryDataThunk<Definitions extends EndpointDefinitions, PartialState> = <EndpointName extends QueryKeys<Definitions>>(endpointName: EndpointName, args: QueryArgFrom<Definitions[EndpointName]>, updateRecipe: Recipe<ResultTypeFrom<Definitions[EndpointName]>>) => ThunkAction<PatchCollection, PartialState, any, AnyAction>; 62/** 63 * An object returned from dispatching a `api.util.updateQueryData` call. 64 */ 65export declare type PatchCollection = { 66 /** 67 * An `immer` Patch describing the cache update. 68 */ 69 patches: Patch[]; 70 /** 71 * An `immer` Patch to revert the cache update. 72 */ 73 inversePatches: Patch[]; 74 /** 75 * A function that will undo the cache update. 76 */ 77 undo: () => void; 78}; 79export declare function buildThunks<BaseQuery extends BaseQueryFn, ReducerPath extends string, Definitions extends EndpointDefinitions>({ reducerPath, baseQuery, context: { endpointDefinitions }, serializeQueryArgs, api, }: { 80 baseQuery: BaseQuery; 81 reducerPath: ReducerPath; 82 context: ApiContext<Definitions>; 83 serializeQueryArgs: InternalSerializeQueryArgs; 84 api: Api<BaseQuery, Definitions, ReducerPath, any>; 85}): { 86 queryThunk: AsyncThunk<unknown, QueryThunkArg, ThunkApiMetaConfig & { 87 state: RootState<any, string, ReducerPath>; 88 }>; 89 mutationThunk: AsyncThunk<unknown, MutationThunkArg, ThunkApiMetaConfig & { 90 state: RootState<any, string, ReducerPath>; 91 }>; 92 prefetch: <EndpointName extends QueryKeys<Definitions>>(endpointName: EndpointName, arg: any, options: PrefetchOptions) => ThunkAction<void, any, any, AnyAction>; 93 updateQueryData: UpdateQueryDataThunk<EndpointDefinitions, { [P in ReducerPath]: CombinedState<any, string, P>; }>; 94 patchQueryData: PatchQueryDataThunk<EndpointDefinitions, { [P in ReducerPath]: CombinedState<any, string, P>; }>; 95 buildMatchThunkActions: <Thunk extends AsyncThunk<any, QueryThunkArg, ThunkApiMetaConfig> | AsyncThunk<any, MutationThunkArg, ThunkApiMetaConfig>>(thunk: Thunk, endpointName: string) => Matchers<Thunk, any>; 96}; 97export declare function calculateProvidedByThunk(action: UnwrapPromise<ReturnType<ReturnType<QueryThunk>> | ReturnType<ReturnType<MutationThunk>>>, type: 'providesTags' | 'invalidatesTags', endpointDefinitions: EndpointDefinitions, assertTagType: AssertTagTypes): readonly FullTagDescription<string>[]; 98export {}; 99