UNPKG

3.08 kBTypeScriptView Raw
1import type { EndpointDefinitions, EndpointBuilder, EndpointDefinition, ReplaceTagTypes } from './endpointDefinitions';
2import type { UnionToIntersection, NoInfer, WithRequiredProp } from './tsHelpers';
3import type { CoreModule } from './core/module';
4import type { CreateApiOptions } from './createApi';
5import type { BaseQueryFn } from './baseQueryTypes';
6import type { CombinedState } from './core/apiState';
7import type { AnyAction } from '@reduxjs/toolkit';
8export interface ApiModules<BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string> {
9}
10export declare type ModuleName = keyof ApiModules<any, any, any, any>;
11export declare type Module<Name extends ModuleName> = {
12 name: Name;
13 init<BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string>(api: Api<BaseQuery, EndpointDefinitions, ReducerPath, TagTypes, ModuleName>, options: WithRequiredProp<CreateApiOptions<BaseQuery, Definitions, ReducerPath, TagTypes>, 'reducerPath' | 'serializeQueryArgs' | 'keepUnusedDataFor' | 'refetchOnMountOrArgChange' | 'refetchOnFocus' | 'refetchOnReconnect' | 'tagTypes'>, context: ApiContext<Definitions>): {
14 injectEndpoint(endpointName: string, definition: EndpointDefinition<any, any, any, any>): void;
15 };
16};
17export interface ApiContext<Definitions extends EndpointDefinitions> {
18 apiUid: string;
19 endpointDefinitions: Definitions;
20 batch(cb: () => void): void;
21 extractRehydrationInfo: (action: AnyAction) => CombinedState<any, any, any> | undefined;
22 hasRehydrationInfo: (action: AnyAction) => boolean;
23}
24export declare type Api<BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string, Enhancers extends ModuleName = CoreModule> = UnionToIntersection<ApiModules<BaseQuery, Definitions, ReducerPath, TagTypes>[Enhancers]> & {
25 /**
26 * A function to inject the endpoints into the original API, but also give you that same API with correct types for these endpoints back. Useful with code-splitting.
27 */
28 injectEndpoints<NewDefinitions extends EndpointDefinitions>(_: {
29 endpoints: (build: EndpointBuilder<BaseQuery, TagTypes, ReducerPath>) => NewDefinitions;
30 overrideExisting?: boolean;
31 }): Api<BaseQuery, Definitions & NewDefinitions, ReducerPath, TagTypes, Enhancers>;
32 /**
33 *A function to enhance a generated API with additional information. Useful with code-generation.
34 */
35 enhanceEndpoints<NewTagTypes extends string = never>(_: {
36 addTagTypes?: readonly NewTagTypes[];
37 endpoints?: ReplaceTagTypes<Definitions, TagTypes | NoInfer<NewTagTypes>> extends infer NewDefinitions ? {
38 [K in keyof NewDefinitions]?: Partial<NewDefinitions[K]> | ((definition: NewDefinitions[K]) => void);
39 } : never;
40 }): Api<BaseQuery, ReplaceTagTypes<Definitions, TagTypes | NewTagTypes>, ReducerPath, TagTypes | NewTagTypes, Enhancers>;
41};
42
\No newline at end of file