import type { EndpointDefinitions, EndpointBuilder, EndpointDefinition, UpdateDefinitions, } from './endpointDefinitions' import type { UnionToIntersection, NoInfer, WithRequiredProp, } from './tsHelpers' import type { CoreModule } from './core/module' import type { CreateApiOptions } from './createApi' import type { BaseQueryFn } from './baseQueryTypes' import type { CombinedState } from './core/apiState' import type { UnknownAction } from '@reduxjs/toolkit' export interface ApiModules< // eslint-disable-next-line @typescript-eslint/no-unused-vars BaseQuery extends BaseQueryFn, // eslint-disable-next-line @typescript-eslint/no-unused-vars Definitions extends EndpointDefinitions, // eslint-disable-next-line @typescript-eslint/no-unused-vars ReducerPath extends string, // eslint-disable-next-line @typescript-eslint/no-unused-vars TagTypes extends string, > {} export type ModuleName = keyof ApiModules export type Module = { name: Name init< BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string, >( api: Api, options: WithRequiredProp< CreateApiOptions, | 'reducerPath' | 'serializeQueryArgs' | 'keepUnusedDataFor' | 'refetchOnMountOrArgChange' | 'refetchOnFocus' | 'refetchOnReconnect' | 'invalidationBehavior' | 'tagTypes' >, context: ApiContext, ): { injectEndpoint( endpointName: string, definition: EndpointDefinition, ): void } } export interface ApiContext { apiUid: string endpointDefinitions: Definitions batch(cb: () => void): void extractRehydrationInfo: ( action: UnknownAction, ) => CombinedState | undefined hasRehydrationInfo: (action: UnknownAction) => boolean } export type Api< BaseQuery extends BaseQueryFn, Definitions extends EndpointDefinitions, ReducerPath extends string, TagTypes extends string, Enhancers extends ModuleName = CoreModule, > = UnionToIntersection< ApiModules[Enhancers] > & { /** * 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. */ injectEndpoints(_: { endpoints: ( build: EndpointBuilder, ) => NewDefinitions /** * Optionally allows endpoints to be overridden if defined by multiple `injectEndpoints` calls. * * If set to `true`, will override existing endpoints with the new definition. * If set to `'throw'`, will throw an error if an endpoint is redefined with a different definition. * If set to `false` (or unset), will not override existing endpoints with the new definition, and log a warning in development. */ overrideExisting?: boolean | 'throw' }): Api< BaseQuery, Definitions & NewDefinitions, ReducerPath, TagTypes, Enhancers > /** *A function to enhance a generated API with additional information. Useful with code-generation. */ enhanceEndpoints< NewTagTypes extends string = never, NewDefinitions extends EndpointDefinitions = never, >(_: { addTagTypes?: readonly NewTagTypes[] endpoints?: UpdateDefinitions< Definitions, TagTypes | NoInfer, NewDefinitions > extends infer NewDefinitions ? { [K in keyof NewDefinitions]?: | Partial | ((definition: NewDefinitions[K]) => void) } : never }): Api< BaseQuery, UpdateDefinitions, ReducerPath, TagTypes | NewTagTypes, Enhancers > }