/**
 * Note: this file should import all other files for type discovery and declaration merging
 */ import type { PatchQueryDataThunk , UpdateQueryDataThunk } from './buildThunks' ; import { buildThunks } from './buildThunks' ; import type { ActionCreatorWithPayload , AnyAction , Middleware , Reducer , ThunkAction , ThunkDispatch , } from '@reduxjs/toolkit' ; import type { EndpointDefinitions , QueryArgFrom , QueryDefinition , MutationDefinition , AssertTagTypes , TagDescription , } from '../endpointDefinitions' ; import { isQueryDefinition , isMutationDefinition } from '../endpointDefinitions' ; import type { CombinedState , QueryKeys , MutationKeys , RootState , } from './apiState' ; import type { Api , Module } from '../apiTypes' ; import { onFocus , onFocusLost , onOnline , onOffline } from './setupListeners' ; import { buildSlice } from './buildSlice' ; import { buildMiddleware } from './buildMiddleware' ; import { buildSelectors } from './buildSelectors' ; import type { MutationActionCreatorResult , QueryActionCreatorResult , } from './buildInitiate' ; import { buildInitiate } from './buildInitiate' ; import { assertCast , safeAssign } from '../tsHelpers' ; import type { InternalSerializeQueryArgs } from '../defaultSerializeQueryArgs' ; import type { SliceActions } from './buildSlice' ; import type { BaseQueryFn } from '../baseQueryTypes' ; import type { ReferenceCacheLifecycle } from './buildMiddleware/cacheLifecycle' ; import type { ReferenceQueryLifecycle } from './buildMiddleware/queryLifecycle' ; import type { ReferenceCacheCollection } from './buildMiddleware/cacheCollection' ; import { enablePatches } from 'immer' ; overloadSummary export type PrefetchOptions = { ifOlderThan ? : false | number ; } | { force ? : boolean ; } ; export const coreModuleName = Symbol ( ) ; export type CoreModule = typeof coreModuleName | ReferenceCacheLifecycle | ReferenceQueryLifecycle | ReferenceCacheCollection ; declare module '../apiTypes' { export interface ApiModules < BaseQuery extends BaseQueryFn , Definitions extends EndpointDefinitions , ReducerPath extends string , TagTypes extends string > { [ coreModuleName ] : { example reducerPath : ReducerPath ; /**
             * Internal actions not part of the public API. Note: These are subject to change at any given time.
             */ internalActions : InternalActions ; example reducer : Reducer < CombinedState < Definitions , TagTypes , ReducerPath > , AnyAction > ; example middleware : Middleware < { } , RootState < Definitions , string , ReducerPath > , ThunkDispatch < any , any , AnyAction > > ; /**
             * A collection of utility thunks for various situations.
             */ util : { /**
                 * Returns all promises for running queries and mutations.
                 * Useful for SSR scenarios to await everything triggered in any way,
                 * including via hook calls, or manually dispatching `initiate` actions.
                 */ getRunningOperationPromises : ( ) => Array < Promise < unknown > > ; /**
                 * If a promise is running for a given endpoint name + argument combination,
                 * returns that promise. Otherwise, returns `undefined`.
                 * Can be used to await a specific query/mutation triggered in any way,
                 * including via hook calls, or manually dispatching `initiate` actions.
                 */ getRunningOperationPromise < EndpointName extends QueryKeys < Definitions > > ( endpointName , args ) : QueryActionCreatorResult < Definitions [ EndpointName ] & { type : 'query' ; } > | undefined ; getRunningOperationPromise < EndpointName extends MutationKeys < Definitions > > ( endpointName , fixedCacheKeyOrRequestId ) : MutationActionCreatorResult < Definitions [ EndpointName ] & { type : 'mutation' ; } > | undefined ; example prefetch < EndpointName extends QueryKeys < Definitions > > ( endpointName , arg , options ) : ThunkAction < void , any , any , AnyAction > ; example updateQueryData : UpdateQueryDataThunk < Definitions , RootState < Definitions , string , ReducerPath > > ; deprecated updateQueryResult : UpdateQueryDataThunk < Definitions , RootState < Definitions , string , ReducerPath > > ; example patchQueryData : PatchQueryDataThunk < Definitions , RootState < Definitions , string , ReducerPath > > ; deprecated patchQueryResult : PatchQueryDataThunk < Definitions , RootState < Definitions , string , ReducerPath > > ; example resetApiState : SliceActions [ 'resetApiState' ] ; example invalidateTags : ActionCreatorWithPayload < Array < TagDescription < TagTypes > > , string > ; selectInvalidatedBy : ( state : RootState < Definitions , string , ReducerPath > , tags : ReadonlyArray < TagDescription < TagTypes > > ) => Array < { endpointName : string ; originalArgs : any ; queryCacheKey : string ; } > ; } ; /**
             * Endpoints based on the input endpoints provided to `createApi`, containing `select` and `action matchers`.
             */ endpoints : { [ K in keyof Definitions ] : Definitions [ K ] extends QueryDefinition < any , any , any , any , any > ? ApiEndpointQuery < Definitions [ K ] , Definitions > : Definitions [ K ] extends MutationDefinition < any , any , any , any , any > ? ApiEndpointMutation < Definitions [ K ] , Definitions > : never ; } ; } ; } } export interface ApiEndpointQuery < Definition extends QueryDefinition < any , any , any , any , any > , Definitions extends EndpointDefinitions > { } export interface ApiEndpointMutation < Definition extends MutationDefinition < any , any , any , any , any > , Definitions extends EndpointDefinitions > { } export type ListenerActions = { link onOnline : typeof onOnline ; onOffline : typeof onOffline ; link onFocus : typeof onFocus ; onFocusLost : typeof onFocusLost ; } ; export type InternalActions = SliceActions & ListenerActions ; example export const coreModule = ( ) : Module < CoreModule > => ( { name : coreModuleName , init ( api , { baseQuery , tagTypes , reducerPath , serializeQueryArgs , keepUnusedDataFor , refetchOnMountOrArgChange , refetchOnFocus , refetchOnReconnect , } , context ) { enablePatches ( ) ; assertCast < InternalSerializeQueryArgs > ( serializeQueryArgs ) ; const assertTagType = ( tag ) => { if ( typeof process !== 'undefined' && process . env . NODE_ENV === 'development' ) { if ( ! tagTypes . includes ( tag . type as any ) ) { console . error ( `Tag type '${ tag . type }' was used, but not specified in \`tagTypes\`!` ) ; } } return tag ; } ; Object . assign ( api , { reducerPath , endpoints : { } , internalActions : { onOnline , onOffline , onFocus , onFocusLost , } , util : { } , } ) ; const { queryThunk , mutationThunk , patchQueryData , updateQueryData , prefetch , buildMatchThunkActions , } = buildThunks ( { baseQuery , reducerPath , context , api , serializeQueryArgs , } ) ; const { reducer , actions : sliceActions } = buildSlice ( { context , queryThunk , mutationThunk , reducerPath , assertTagType , config : { refetchOnFocus , refetchOnReconnect , refetchOnMountOrArgChange , keepUnusedDataFor , reducerPath , } , } ) ; safeAssign ( api . util , { patchQueryData , updateQueryData , prefetch , resetApiState : sliceActions . resetApiState , } ) ; safeAssign ( api . internalActions , sliceActions ) ; Object . defineProperty ( api . util , 'updateQueryResult' , { get ( ) { if ( typeof process !== 'undefined' && process . env . NODE_ENV === 'development' ) { console . warn ( '`api.util.updateQueryResult` has been renamed to `api.util.updateQueryData`, please change your code accordingly' ) ; } return api . util . updateQueryData ; } , } ) ; Object . defineProperty ( api . util , 'patchQueryResult' , { get ( ) { if ( typeof process !== 'undefined' && process . env . NODE_ENV === 'development' ) { console . warn ( '`api.util.patchQueryResult` has been renamed to `api.util.patchQueryData`, please change your code accordingly' ) ; } return api . util . patchQueryData ; } , } ) ; const { middleware , actions : middlewareActions } = buildMiddleware ( { reducerPath , context , queryThunk , mutationThunk , api , assertTagType , } ) ; safeAssign ( api . util , middlewareActions ) ; safeAssign ( api , { reducer : reducer as any , middleware } ) ; const { buildQuerySelector , buildMutationSelector , selectInvalidatedBy } = buildSelectors ( { serializeQueryArgs : serializeQueryArgs as any , reducerPath , } ) ; safeAssign ( api . util , { selectInvalidatedBy } ) ; const { buildInitiateQuery , buildInitiateMutation , getRunningOperationPromises , getRunningOperationPromise , } = buildInitiate ( { queryThunk , mutationThunk , api , serializeQueryArgs : serializeQueryArgs as any , context , } ) ; safeAssign ( api . util , { getRunningOperationPromises , getRunningOperationPromise , } ) ; return { name : coreModuleName , injectEndpoint ( endpointName , definition ) { const anyApi = api as any as Api < any , Record < string , any > , string , string , CoreModule > ; anyApi . endpoints [ endpointName ] ??= { } as any ; if ( isQueryDefinition ( definition ) ) { safeAssign ( anyApi . endpoints [ endpointName ] , { select : buildQuerySelector ( endpointName , definition ) , initiate : buildInitiateQuery ( endpointName , definition ) , } , buildMatchThunkActions ( queryThunk , endpointName ) ) ; } else if ( isMutationDefinition ( definition ) ) { safeAssign ( anyApi . endpoints [ endpointName ] , { select : buildMutationSelector ( ) , initiate : buildInitiateMutation ( endpointName ) , } , buildMatchThunkActions ( mutationThunk , endpointName ) ) ; } } , } ; } , } ) ;