import type { AnyAction , ThunkDispatch } from '@reduxjs/toolkit' ; import type { RootState } from './core/apiState' ; import type { BaseQueryExtraOptions , BaseQueryFn , BaseQueryResult , BaseQueryArg , BaseQueryApi , QueryReturnValue , BaseQueryError , BaseQueryMeta , } from './baseQueryTypes' ; import type { HasRequiredProps , MaybePromise , OmitFromUnion , CastAny , } from './tsHelpers' ; import type { NEVER } from './fakeBaseQuery' ; const resultType = Symbol ( ) ; const baseQuery = Symbol ( ) ; interface EndpointDefinitionWithQuery < QueryArg , BaseQuery extends BaseQueryFn , ResultType > { example query ( arg ) : BaseQueryArg < BaseQuery > ; queryFn ? : never ; /**
     * A function to manipulate the data returned by a query or mutation.
     */ transformResponse ? ( baseQueryReturnValue , meta , arg ) : ResultType | Promise < ResultType > ; } interface EndpointDefinitionWithQueryFn < QueryArg , BaseQuery extends BaseQueryFn , ResultType > { example queryFn ( arg , api , extraOptions , baseQuery ) : MaybePromise < QueryReturnValue < ResultType , BaseQueryError < BaseQuery > > > ; query ? : never ; transformResponse ? : never ; } export type BaseEndpointDefinition < QueryArg , BaseQuery extends BaseQueryFn , ResultType > = ( ( [ CastAny < BaseQueryResult < BaseQuery > , { } > ] extends [ NEVER ] ? never : EndpointDefinitionWithQuery < QueryArg , BaseQuery , ResultType > ) | EndpointDefinitionWithQueryFn < QueryArg , BaseQuery , ResultType > ) & { [ resultType ] ? : ResultType ; [ baseQuery ] ? : BaseQuery ; } & HasRequiredProps < BaseQueryExtraOptions < BaseQuery > , { extraOptions : BaseQueryExtraOptions < BaseQuery > ; } , { extraOptions ? : BaseQueryExtraOptions < BaseQuery > ; } > ; export enum DefinitionType { query = 'query' , mutation = 'mutation' } export type GetResultDescriptionFn < TagTypes extends string , ResultType , QueryArg , ErrorType , MetaType > = ( result : ResultType | undefined , error : ErrorType | undefined , arg : QueryArg , meta : MetaType ) => ReadonlyArray < TagDescription < TagTypes > > ; export type FullTagDescription < TagType > = { type : TagType ; id ? : number | string ; } ; export type TagDescription < TagType > = TagType | FullTagDescription < TagType > ; export type ResultDescription < TagTypes extends string , ResultType , QueryArg , ErrorType , MetaType > = ReadonlyArray < TagDescription < TagTypes > > | GetResultDescriptionFn < TagTypes , ResultType , QueryArg , ErrorType , MetaType > ; deprecated export interface QueryApi < ReducerPath extends string , Context extends { } > { deprecated dispatch : ThunkDispatch < any , any , AnyAction > ; deprecated getState ( ) : RootState < any , any , ReducerPath > ; deprecated extra : unknown ; deprecated requestId : string ; deprecated context : Context ; } export interface QueryExtraOptions < TagTypes extends string , ResultType , QueryArg , BaseQuery extends BaseQueryFn , ReducerPath extends string = string > { type : DefinitionType . query ; example providesTags ? : ResultDescription < TagTypes , ResultType , QueryArg , BaseQueryError < BaseQuery > , BaseQueryMeta < BaseQuery > > ; /**
     * Not to be used. A query should not invalidate tags in the cache.
     */ invalidatesTags ? : never ; } export type QueryDefinition < QueryArg , BaseQuery extends BaseQueryFn , TagTypes extends string , ResultType , ReducerPath extends string = string > = BaseEndpointDefinition < QueryArg , BaseQuery , ResultType > & QueryExtraOptions < TagTypes , ResultType , QueryArg , BaseQuery , ReducerPath > ; export interface MutationExtraOptions < TagTypes extends string , ResultType , QueryArg , BaseQuery extends BaseQueryFn , ReducerPath extends string = string > { type : DefinitionType . mutation ; example invalidatesTags ? : ResultDescription < TagTypes , ResultType , QueryArg , BaseQueryError < BaseQuery > , BaseQueryMeta < BaseQuery > > ; /**
     * Not to be used. A mutation should not provide tags to the cache.
     */ providesTags ? : never ; } export type MutationDefinition < QueryArg , BaseQuery extends BaseQueryFn , TagTypes extends string , ResultType , ReducerPath extends string = string > = BaseEndpointDefinition < QueryArg , BaseQuery , ResultType > & MutationExtraOptions < TagTypes , ResultType , QueryArg , BaseQuery , ReducerPath > ; export type EndpointDefinition < QueryArg , BaseQuery extends BaseQueryFn , TagTypes extends string , ResultType , ReducerPath extends string = string > = QueryDefinition < QueryArg , BaseQuery , TagTypes , ResultType , ReducerPath > | MutationDefinition < QueryArg , BaseQuery , TagTypes , ResultType , ReducerPath > ; export type EndpointDefinitions = Record < string , EndpointDefinition < any , any , any , any > > ; export function isQueryDefinition ( e ) { return e . type === DefinitionType . query ; } export function isMutationDefinition ( e ) { return e . type === DefinitionType . mutation ; } export type EndpointBuilder < BaseQuery extends BaseQueryFn , TagTypes extends string , ReducerPath extends string > = { example query < ResultType , QueryArg > ( definition ) : QueryDefinition < QueryArg , BaseQuery , TagTypes , ResultType > ; example mutation < ResultType , QueryArg > ( definition ) : MutationDefinition < QueryArg , BaseQuery , TagTypes , ResultType , ReducerPath > ; } ; export type AssertTagTypes = < T extends FullTagDescription < string > > ( t : T ) => T ; export function calculateProvidedBy < ResultType , QueryArg , ErrorType , MetaType > ( description , result , error , queryArg , meta , assertTagTypes ) { if ( isFunction ( description ) ) { return description ( result as ResultType , error as undefined , queryArg , meta as MetaType ) . map ( expandTagDescription ) . map ( assertTagTypes ) ; } if ( Array . isArray ( description ) ) { return description . map ( expandTagDescription ) . map ( assertTagTypes ) ; } return [ ] ; } function isFunction < T > ( t ) { return typeof t === 'function' ; } export function expandTagDescription ( description ) { return typeof description === 'string' ? { type : description } : description ; } export type QueryArgFrom < D extends BaseEndpointDefinition < any , any , any > > = D extends BaseEndpointDefinition < infer QA , any , any > ? QA : unknown ; export type ResultTypeFrom < D extends BaseEndpointDefinition < any , any , any > > = D extends BaseEndpointDefinition < any , any , infer RT > ? RT : unknown ; export type ReducerPathFrom < D extends EndpointDefinition < any , any , any , any , any > > = D extends EndpointDefinition < any , any , any , any , infer RP > ? RP : unknown ; export type TagTypesFrom < D extends EndpointDefinition < any , any , any , any > > = D extends EndpointDefinition < any , any , infer RP , any > ? RP : unknown ; export type ReplaceTagTypes < Definitions extends EndpointDefinitions , NewTagTypes extends string > = { [ K in keyof Definitions ] : Definitions [ K ] extends QueryDefinition < infer QueryArg , infer BaseQuery , any , infer ResultType , infer ReducerPath > ? QueryDefinition < QueryArg , BaseQuery , NewTagTypes , ResultType , ReducerPath > : Definitions [ K ] extends MutationDefinition < infer QueryArg , infer BaseQuery , any , infer ResultType , infer ReducerPath > ? MutationDefinition < QueryArg , BaseQuery , NewTagTypes , ResultType , ReducerPath > : never ; } ;