1 | import type { InternalSerializeQueryArgs } from '../defaultSerializeQueryArgs';
|
2 | import type { Api, ApiContext } from '../apiTypes';
|
3 | import type { BaseQueryFn, BaseQueryError } from '../baseQueryTypes';
|
4 | import type { RootState, QueryKeys, QuerySubstateIdentifier } from './apiState';
|
5 | import { CombinedState } from './apiState';
|
6 | import type { StartQueryActionCreatorOptions } from './buildInitiate';
|
7 | import type { AssertTagTypes, EndpointDefinition, EndpointDefinitions, MutationDefinition, QueryArgFrom, QueryDefinition, ResultTypeFrom } from '../endpointDefinitions';
|
8 | import { FullTagDescription } from '../endpointDefinitions';
|
9 | import type { Draft } from '@reduxjs/toolkit';
|
10 | import type { Patch } from 'immer';
|
11 | import type { AnyAction, ThunkAction, AsyncThunk } from '@reduxjs/toolkit';
|
12 | import type { PrefetchOptions } from './module';
|
13 | import type { UnwrapPromise } from '../tsHelpers';
|
14 | declare 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 | }
|
20 | declare 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;
|
25 | export declare type PendingAction<Thunk extends QueryThunk | MutationThunk, Definition extends EndpointDefinition<any, any, any, any>> = ReturnType<EndpointThunk<Thunk, Definition>['pending']>;
|
26 | export declare type FulfilledAction<Thunk extends QueryThunk | MutationThunk, Definition extends EndpointDefinition<any, any, any, any>> = ReturnType<EndpointThunk<Thunk, Definition>['fulfilled']>;
|
27 | export declare type RejectedAction<Thunk extends QueryThunk | MutationThunk, Definition extends EndpointDefinition<any, any, any, any>> = ReturnType<EndpointThunk<Thunk, Definition>['rejected']>;
|
28 | export declare type Matcher<M> = (value: any) => value is M;
|
29 | export 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 | }
|
34 | export interface QueryThunkArg extends QuerySubstateIdentifier, StartQueryActionCreatorOptions {
|
35 | originalArgs: unknown;
|
36 | endpointName: string;
|
37 | }
|
38 | export interface MutationThunkArg {
|
39 | originalArgs: unknown;
|
40 | endpointName: string;
|
41 | track?: boolean;
|
42 | }
|
43 | export declare type ThunkResult = unknown;
|
44 | export 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 | };
|
56 | export declare type QueryThunk = AsyncThunk<ThunkResult, QueryThunkArg, ThunkApiMetaConfig>;
|
57 | export declare type MutationThunk = AsyncThunk<ThunkResult, MutationThunkArg, ThunkApiMetaConfig>;
|
58 | export declare type MaybeDrafted<T> = T | Draft<T>;
|
59 | export declare type Recipe<T> = (data: MaybeDrafted<T>) => void | MaybeDrafted<T>;
|
60 | export 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>;
|
61 | export 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 |
|
64 |
|
65 | export declare type PatchCollection = {
|
66 | |
67 |
|
68 |
|
69 | patches: Patch[];
|
70 | |
71 |
|
72 |
|
73 | inversePatches: Patch[];
|
74 | |
75 |
|
76 |
|
77 | undo: () => void;
|
78 | };
|
79 | export 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 | };
|
97 | export declare function calculateProvidedByThunk(action: UnwrapPromise<ReturnType<ReturnType<QueryThunk>> | ReturnType<ReturnType<MutationThunk>>>, type: 'providesTags' | 'invalidatesTags', endpointDefinitions: EndpointDefinitions, assertTagType: AssertTagTypes): readonly FullTagDescription<string>[];
|
98 | export {};
|