UNPKG

2.65 kBTypeScriptView Raw
1import type { EndpointDefinitions, EndpointBuilder, EndpointDefinition, ReplaceTagTypes } from './endpointDefinitions';
2import type { UnionToIntersection, NoInfer } from './tsHelpers';
3import type { CoreModule } from './core/module';
4import type { CreateApiOptions } from './createApi';
5import type { BaseQueryFn } from './baseQueryTypes';
6export interface ApiModules<BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string> {
7}
8export declare type ModuleName = keyof ApiModules<any, any, any, any>;
9export declare type Module<Name extends ModuleName> = {
10 name: Name;
11 init<BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string>(api: Api<BaseQuery, EndpointDefinitions, ReducerPath, TagTypes, ModuleName>, options: Required<CreateApiOptions<BaseQuery, Definitions, ReducerPath, TagTypes>>, context: ApiContext<Definitions>): {
12 injectEndpoint(endpointName: string, definition: EndpointDefinition<any, any, any, any>): void;
13 };
14};
15export interface ApiContext<Definitions extends EndpointDefinitions> {
16 apiUid: string;
17 endpointDefinitions: Definitions;
18 batch(cb: () => void): void;
19}
20export 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]> & {
21 /**
22 * 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.
23 */
24 injectEndpoints<NewDefinitions extends EndpointDefinitions>(_: {
25 endpoints: (build: EndpointBuilder<BaseQuery, TagTypes, ReducerPath>) => NewDefinitions;
26 overrideExisting?: boolean;
27 }): Api<BaseQuery, Definitions & NewDefinitions, ReducerPath, TagTypes, Enhancers>;
28 /**
29 *A function to enhance a generated API with additional information. Useful with code-generation.
30 */
31 enhanceEndpoints<NewTagTypes extends string = never>(_: {
32 addTagTypes?: readonly NewTagTypes[];
33 endpoints?: ReplaceTagTypes<Definitions, TagTypes | NoInfer<NewTagTypes>> extends infer NewDefinitions ? {
34 [K in keyof NewDefinitions]?: Partial<NewDefinitions[K]> | ((definition: NewDefinitions[K]) => void);
35 } : never;
36 }): Api<BaseQuery, ReplaceTagTypes<Definitions, TagTypes | NewTagTypes>, ReducerPath, TagTypes | NewTagTypes, Enhancers>;
37};
38
\No newline at end of file