UNPKG

@reduxjs/toolkit

Version:

The official, opinionated, batteries-included toolset for efficient Redux development

1 lines 312 kB
{"version":3,"sources":["../../../src/query/index.ts","../../../src/query/core/apiState.ts","../../../src/query/core/rtkImports.ts","../../../src/query/utils/copyWithStructuralSharing.ts","../../../src/query/utils/countObjectKeys.ts","../../../src/query/utils/flatten.ts","../../../src/query/utils/isAbsoluteUrl.ts","../../../src/query/utils/isDocumentVisible.ts","../../../src/query/utils/isNotNullish.ts","../../../src/query/utils/isOnline.ts","../../../src/query/utils/joinUrls.ts","../../../src/query/utils/getOrInsert.ts","../../../src/query/fetchBaseQuery.ts","../../../src/query/HandledError.ts","../../../src/query/retry.ts","../../../src/query/core/setupListeners.ts","../../../src/query/endpointDefinitions.ts","../../../src/query/core/buildThunks.ts","../../../src/query/core/buildInitiate.ts","../../../src/tsHelpers.ts","../../../src/query/core/buildSlice.ts","../../../src/query/core/buildSelectors.ts","../../../src/query/createApi.ts","../../../src/query/defaultSerializeQueryArgs.ts","../../../src/query/fakeBaseQuery.ts","../../../src/query/core/module.ts","../../../src/query/tsHelpers.ts","../../../src/query/core/buildMiddleware/batchActions.ts","../../../src/query/core/buildMiddleware/cacheCollection.ts","../../../src/query/core/buildMiddleware/cacheLifecycle.ts","../../../src/query/core/buildMiddleware/devMiddleware.ts","../../../src/query/core/buildMiddleware/invalidationByTags.ts","../../../src/query/core/buildMiddleware/polling.ts","../../../src/query/core/buildMiddleware/queryLifecycle.ts","../../../src/query/core/buildMiddleware/windowEventHandling.ts","../../../src/query/core/buildMiddleware/index.ts","../../../src/query/core/index.ts"],"sourcesContent":["// This must remain here so that the `mangleErrors.cjs` build script\n// does not have to import this into each source file it rewrites.\nimport { formatProdErrorMessage } from '@reduxjs/toolkit';\nexport type { CombinedState, QueryCacheKey, QueryKeys, QuerySubState, RootState, SubscriptionOptions } from './core/apiState';\nexport { QueryStatus } from './core/apiState';\nexport type { Api, ApiContext, Module } from './apiTypes';\nexport type { BaseQueryApi, BaseQueryArg, BaseQueryEnhancer, BaseQueryError, BaseQueryExtraOptions, BaseQueryFn, BaseQueryMeta, BaseQueryResult, QueryReturnValue } from './baseQueryTypes';\nexport type { BaseEndpointDefinition, EndpointDefinitions, EndpointDefinition, EndpointBuilder, QueryDefinition, MutationDefinition, MutationExtraOptions, InfiniteQueryArgFrom, InfiniteQueryDefinition, InfiniteQueryExtraOptions, PageParamFrom, TagDescription, QueryArgFrom, QueryExtraOptions, ResultTypeFrom, DefinitionType, DefinitionsFromApi, OverrideResultType, ResultDescription, TagTypesFromApi, UpdateDefinitions } from './endpointDefinitions';\nexport { fetchBaseQuery } from './fetchBaseQuery';\nexport type { FetchBaseQueryArgs, FetchBaseQueryError, FetchBaseQueryMeta, FetchArgs } from './fetchBaseQuery';\nexport { retry } from './retry';\nexport type { RetryOptions } from './retry';\nexport { setupListeners } from './core/setupListeners';\nexport { skipToken } from './core/buildSelectors';\nexport type { QueryResultSelectorResult, MutationResultSelectorResult, SkipToken } from './core/buildSelectors';\nexport type { QueryActionCreatorResult, MutationActionCreatorResult, StartQueryActionCreatorOptions } from './core/buildInitiate';\nexport type { CreateApi, CreateApiOptions } from './createApi';\nexport { buildCreateApi } from './createApi';\nexport { _NEVER, fakeBaseQuery } from './fakeBaseQuery';\nexport { copyWithStructuralSharing } from './utils/copyWithStructuralSharing';\nexport { createApi, coreModule, coreModuleName } from './core/index';\nexport type { InfiniteData, InfiniteQueryActionCreatorResult, InfiniteQueryConfigOptions, InfiniteQueryResultSelectorResult, InfiniteQuerySubState, TypedMutationOnQueryStarted, TypedQueryOnQueryStarted } from './core/index';\nexport type { ApiEndpointMutation, ApiEndpointQuery, ApiEndpointInfiniteQuery, ApiModules, CoreModule, PrefetchOptions } from './core/module';\nexport { defaultSerializeQueryArgs } from './defaultSerializeQueryArgs';\nexport type { SerializeQueryArgs } from './defaultSerializeQueryArgs';\nexport type { Id as TSHelpersId, NoInfer as TSHelpersNoInfer, Override as TSHelpersOverride } from './tsHelpers';","import type { SerializedError } from '@reduxjs/toolkit';\nimport type { BaseQueryError } from '../baseQueryTypes';\nimport type { BaseEndpointDefinition, EndpointDefinitions, InfiniteQueryDefinition, MutationDefinition, PageParamFrom, QueryArgFromAnyQuery, QueryDefinition, ResultTypeFrom } from '../endpointDefinitions';\nimport type { Id, WithRequiredProp } from '../tsHelpers';\nexport type QueryCacheKey = string & {\n _type: 'queryCacheKey';\n};\nexport type QuerySubstateIdentifier = {\n queryCacheKey: QueryCacheKey;\n};\nexport type MutationSubstateIdentifier = {\n requestId: string;\n fixedCacheKey?: string;\n} | {\n requestId?: string;\n fixedCacheKey: string;\n};\nexport type RefetchConfigOptions = {\n refetchOnMountOrArgChange: boolean | number;\n refetchOnReconnect: boolean;\n refetchOnFocus: boolean;\n};\nexport type PageParamFunction<DataType, PageParam> = (firstPage: DataType, allPages: Array<DataType>, firstPageParam: PageParam, allPageParams: Array<PageParam>) => PageParam | undefined | null;\nexport type InfiniteQueryConfigOptions<DataType, PageParam> = {\n /**\n * The initial page parameter to use for the first page fetch.\n */\n initialPageParam: PageParam;\n /**\n * This function is required to automatically get the next cursor for infinite queries.\n * The result will also be used to determine the value of `hasNextPage`.\n */\n getNextPageParam: PageParamFunction<DataType, PageParam>;\n /**\n * This function can be set to automatically get the previous cursor for infinite queries.\n * The result will also be used to determine the value of `hasPreviousPage`.\n */\n getPreviousPageParam?: PageParamFunction<DataType, PageParam>;\n /**\n * If specified, only keep this many pages in cache at once.\n * If additional pages are fetched, older pages in the other\n * direction will be dropped from the cache.\n */\n maxPages?: number;\n};\nexport type InfiniteData<DataType, PageParam> = {\n pages: Array<DataType>;\n pageParams: Array<PageParam>;\n};\n\n/**\n * Strings describing the query state at any given time.\n */\nexport enum QueryStatus {\n uninitialized = 'uninitialized',\n pending = 'pending',\n fulfilled = 'fulfilled',\n rejected = 'rejected',\n}\nexport type RequestStatusFlags = {\n status: QueryStatus.uninitialized;\n isUninitialized: true;\n isLoading: false;\n isSuccess: false;\n isError: false;\n} | {\n status: QueryStatus.pending;\n isUninitialized: false;\n isLoading: true;\n isSuccess: false;\n isError: false;\n} | {\n status: QueryStatus.fulfilled;\n isUninitialized: false;\n isLoading: false;\n isSuccess: true;\n isError: false;\n} | {\n status: QueryStatus.rejected;\n isUninitialized: false;\n isLoading: false;\n isSuccess: false;\n isError: true;\n};\nexport function getRequestStatusFlags(status: QueryStatus): RequestStatusFlags {\n return {\n status,\n isUninitialized: status === QueryStatus.uninitialized,\n isLoading: status === QueryStatus.pending,\n isSuccess: status === QueryStatus.fulfilled,\n isError: status === QueryStatus.rejected\n } as any;\n}\n\n/**\n * @public\n */\nexport type SubscriptionOptions = {\n /**\n * How frequently to automatically re-fetch data (in milliseconds). Defaults to `0` (off).\n */\n pollingInterval?: number;\n /**\n * Defaults to 'false'. This setting allows you to control whether RTK Query will continue polling if the window is not focused.\n *\n * If pollingInterval is not set or set to 0, this **will not be evaluated** until pollingInterval is greater than 0.\n *\n * Note: requires [`setupListeners`](./setupListeners) to have been called.\n */\n skipPollingIfUnfocused?: boolean;\n /**\n * Defaults to `false`. This setting allows you to control whether RTK Query will try to refetch all subscribed queries after regaining a network connection.\n *\n * If you specify this option alongside `skip: true`, this **will not be evaluated** until `skip` is false.\n *\n * Note: requires [`setupListeners`](./setupListeners) to have been called.\n */\n refetchOnReconnect?: boolean;\n /**\n * Defaults to `false`. This setting allows you to control whether RTK Query will try to refetch all subscribed queries after the application window regains focus.\n *\n * If you specify this option alongside `skip: true`, this **will not be evaluated** until `skip` is false.\n *\n * Note: requires [`setupListeners`](./setupListeners) to have been called.\n */\n refetchOnFocus?: boolean;\n};\nexport type Subscribers = {\n [requestId: string]: SubscriptionOptions;\n};\nexport type QueryKeys<Definitions extends EndpointDefinitions> = { [K in keyof Definitions]: Definitions[K] extends QueryDefinition<any, any, any, any> ? K : never }[keyof Definitions];\nexport type InfiniteQueryKeys<Definitions extends EndpointDefinitions> = { [K in keyof Definitions]: Definitions[K] extends InfiniteQueryDefinition<any, any, any, any, any> ? K : never }[keyof Definitions];\nexport type MutationKeys<Definitions extends EndpointDefinitions> = { [K in keyof Definitions]: Definitions[K] extends MutationDefinition<any, any, any, any> ? K : never }[keyof Definitions];\ntype BaseQuerySubState<D extends BaseEndpointDefinition<any, any, any>, DataType = ResultTypeFrom<D>> = {\n /**\n * The argument originally passed into the hook or `initiate` action call\n */\n originalArgs: QueryArgFromAnyQuery<D>;\n /**\n * A unique ID associated with the request\n */\n requestId: string;\n /**\n * The received data from the query\n */\n data?: DataType;\n /**\n * The received error if applicable\n */\n error?: SerializedError | (D extends QueryDefinition<any, infer BaseQuery, any, any> ? BaseQueryError<BaseQuery> : never);\n /**\n * The name of the endpoint associated with the query\n */\n endpointName: string;\n /**\n * Time that the latest query started\n */\n startedTimeStamp: number;\n /**\n * Time that the latest query was fulfilled\n */\n fulfilledTimeStamp?: number;\n};\nexport type QuerySubState<D extends BaseEndpointDefinition<any, any, any>, DataType = ResultTypeFrom<D>> = Id<({\n status: QueryStatus.fulfilled;\n} & WithRequiredProp<BaseQuerySubState<D, DataType>, 'data' | 'fulfilledTimeStamp'> & {\n error: undefined;\n}) | ({\n status: QueryStatus.pending;\n} & BaseQuerySubState<D, DataType>) | ({\n status: QueryStatus.rejected;\n} & WithRequiredProp<BaseQuerySubState<D, DataType>, 'error'>) | {\n status: QueryStatus.uninitialized;\n originalArgs?: undefined;\n data?: undefined;\n error?: undefined;\n requestId?: undefined;\n endpointName?: string;\n startedTimeStamp?: undefined;\n fulfilledTimeStamp?: undefined;\n}>;\nexport type InfiniteQueryDirection = 'forward' | 'backward';\nexport type InfiniteQuerySubState<D extends BaseEndpointDefinition<any, any, any>> = D extends InfiniteQueryDefinition<any, any, any, any, any> ? QuerySubState<D, InfiniteData<ResultTypeFrom<D>, PageParamFrom<D>>> & {\n direction?: InfiniteQueryDirection;\n} : never;\ntype BaseMutationSubState<D extends BaseEndpointDefinition<any, any, any>> = {\n requestId: string;\n data?: ResultTypeFrom<D>;\n error?: SerializedError | (D extends MutationDefinition<any, infer BaseQuery, any, any> ? BaseQueryError<BaseQuery> : never);\n endpointName: string;\n startedTimeStamp: number;\n fulfilledTimeStamp?: number;\n};\nexport type MutationSubState<D extends BaseEndpointDefinition<any, any, any>> = (({\n status: QueryStatus.fulfilled;\n} & WithRequiredProp<BaseMutationSubState<D>, 'data' | 'fulfilledTimeStamp'>) & {\n error: undefined;\n}) | (({\n status: QueryStatus.pending;\n} & BaseMutationSubState<D>) & {\n data?: undefined;\n}) | ({\n status: QueryStatus.rejected;\n} & WithRequiredProp<BaseMutationSubState<D>, 'error'>) | {\n requestId?: undefined;\n status: QueryStatus.uninitialized;\n data?: undefined;\n error?: undefined;\n endpointName?: string;\n startedTimeStamp?: undefined;\n fulfilledTimeStamp?: undefined;\n};\nexport type CombinedState<D extends EndpointDefinitions, E extends string, ReducerPath extends string> = {\n queries: QueryState<D>;\n mutations: MutationState<D>;\n provided: InvalidationState<E>;\n subscriptions: SubscriptionState;\n config: ConfigState<ReducerPath>;\n};\nexport type InvalidationState<TagTypes extends string> = { [_ in TagTypes]: {\n [id: string]: Array<QueryCacheKey>;\n [id: number]: Array<QueryCacheKey>;\n} };\nexport type QueryState<D extends EndpointDefinitions> = {\n [queryCacheKey: string]: QuerySubState<D[string]> | InfiniteQuerySubState<D[string]> | undefined;\n};\nexport type SubscriptionState = {\n [queryCacheKey: string]: Subscribers | undefined;\n};\nexport type ConfigState<ReducerPath> = RefetchConfigOptions & {\n reducerPath: ReducerPath;\n online: boolean;\n focused: boolean;\n middlewareRegistered: boolean | 'conflict';\n} & ModifiableConfigState;\nexport type ModifiableConfigState = {\n keepUnusedDataFor: number;\n invalidationBehavior: 'delayed' | 'immediately';\n} & RefetchConfigOptions;\nexport type MutationState<D extends EndpointDefinitions> = {\n [requestId: string]: MutationSubState<D[string]> | undefined;\n};\nexport type RootState<Definitions extends EndpointDefinitions, TagTypes extends string, ReducerPath extends string> = { [P in ReducerPath]: CombinedState<Definitions, TagTypes, P> };","// This file exists to consolidate all of the imports from the `@reduxjs/toolkit` package.\n// ESBuild does not de-duplicate imports, so this file is used to ensure that each method\n// imported is only listed once, and there's only one mention of the `@reduxjs/toolkit` package.\n\nexport { createAction, createSlice, createSelector, createAsyncThunk, combineReducers, createNextState, isAnyOf, isAllOf, isAction, isPending, isRejected, isFulfilled, isRejectedWithValue, isAsyncThunkAction, prepareAutoBatched, SHOULD_AUTOBATCH, isPlainObject, nanoid } from '@reduxjs/toolkit';","import { isPlainObject as _iPO } from '../core/rtkImports';\n\n// remove type guard\nconst isPlainObject: (_: any) => boolean = _iPO;\nexport function copyWithStructuralSharing<T>(oldObj: any, newObj: T): T;\nexport function copyWithStructuralSharing(oldObj: any, newObj: any): any {\n if (oldObj === newObj || !(isPlainObject(oldObj) && isPlainObject(newObj) || Array.isArray(oldObj) && Array.isArray(newObj))) {\n return newObj;\n }\n const newKeys = Object.keys(newObj);\n const oldKeys = Object.keys(oldObj);\n let isSameObject = newKeys.length === oldKeys.length;\n const mergeObj: any = Array.isArray(newObj) ? [] : {};\n for (const key of newKeys) {\n mergeObj[key] = copyWithStructuralSharing(oldObj[key], newObj[key]);\n if (isSameObject) isSameObject = oldObj[key] === mergeObj[key];\n }\n return isSameObject ? oldObj : mergeObj;\n}","// Fast method for counting an object's keys\n// without resorting to `Object.keys(obj).length\n// Will this make a big difference in perf? Probably not\n// But we can save a few allocations.\n\nexport function countObjectKeys(obj: Record<any, any>) {\n let count = 0;\n for (const _key in obj) {\n count++;\n }\n return count;\n}","/**\r\n * Alternative to `Array.flat(1)`\r\n * @param arr An array like [1,2,3,[1,2]]\r\n * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat\r\n */\nexport const flatten = (arr: readonly any[]) => [].concat(...arr);","/**\r\n * If either :// or // is present consider it to be an absolute url\r\n *\r\n * @param url string\r\n */\n\nexport function isAbsoluteUrl(url: string) {\n return new RegExp(`(^|:)//`).test(url);\n}","/**\r\n * Assumes true for a non-browser env, otherwise makes a best effort\r\n * @link https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilityState\r\n */\nexport function isDocumentVisible(): boolean {\n // `document` may not exist in non-browser envs (like RN)\n if (typeof document === 'undefined') {\n return true;\n }\n // Match true for visible, prerender, undefined\n return document.visibilityState !== 'hidden';\n}","export function isNotNullish<T>(v: T | null | undefined): v is T {\n return v != null;\n}","/**\n * Assumes a browser is online if `undefined`, otherwise makes a best effort\n * @link https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine\n */\nexport function isOnline() {\n // We set the default config value in the store, so we'd need to check for this in a SSR env\n return typeof navigator === 'undefined' ? true : navigator.onLine === undefined ? true : navigator.onLine;\n}","import { isAbsoluteUrl } from './isAbsoluteUrl';\nconst withoutTrailingSlash = (url: string) => url.replace(/\\/$/, '');\nconst withoutLeadingSlash = (url: string) => url.replace(/^\\//, '');\nexport function joinUrls(base: string | undefined, url: string | undefined): string {\n if (!base) {\n return url!;\n }\n if (!url) {\n return base;\n }\n if (isAbsoluteUrl(url)) {\n return url;\n }\n const delimiter = base.endsWith('/') || !url.startsWith('?') ? '/' : '';\n base = withoutTrailingSlash(base);\n url = withoutLeadingSlash(url);\n return `${base}${delimiter}${url}`;\n}","export function getOrInsert<K extends object, V>(map: WeakMap<K, V>, key: K, value: V): V;\nexport function getOrInsert<K, V>(map: Map<K, V>, key: K, value: V): V;\nexport function getOrInsert<K extends object, V>(map: Map<K, V> | WeakMap<K, V>, key: K, value: V): V {\n if (map.has(key)) return map.get(key) as V;\n return map.set(key, value).get(key) as V;\n}","import { joinUrls } from './utils';\nimport { isPlainObject } from './core/rtkImports';\nimport type { BaseQueryApi, BaseQueryFn } from './baseQueryTypes';\nimport type { MaybePromise, Override } from './tsHelpers';\nexport type ResponseHandler = 'content-type' | 'json' | 'text' | ((response: Response) => Promise<any>);\ntype CustomRequestInit = Override<RequestInit, {\n headers?: Headers | string[][] | Record<string, string | undefined> | undefined;\n}>;\nexport interface FetchArgs extends CustomRequestInit {\n url: string;\n params?: Record<string, any>;\n body?: any;\n responseHandler?: ResponseHandler;\n validateStatus?: (response: Response, body: any) => boolean;\n /**\n * A number in milliseconds that represents that maximum time a request can take before timing out.\n */\n timeout?: number;\n}\n\n/**\n * A mini-wrapper that passes arguments straight through to\n * {@link [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)}.\n * Avoids storing `fetch` in a closure, in order to permit mocking/monkey-patching.\n */\nconst defaultFetchFn: typeof fetch = (...args) => fetch(...args);\nconst defaultValidateStatus = (response: Response) => response.status >= 200 && response.status <= 299;\nconst defaultIsJsonContentType = (headers: Headers) => /*applicat*//ion\\/(vnd\\.api\\+)?json/.test(headers.get('content-type') || '');\nexport type FetchBaseQueryError = {\n /**\n * * `number`:\n * HTTP status code\n */\n status: number;\n data: unknown;\n} | {\n /**\n * * `\"FETCH_ERROR\"`:\n * An error that occurred during execution of `fetch` or the `fetchFn` callback option\n **/\n status: 'FETCH_ERROR';\n data?: undefined;\n error: string;\n} | {\n /**\n * * `\"PARSING_ERROR\"`:\n * An error happened during parsing.\n * Most likely a non-JSON-response was returned with the default `responseHandler` \"JSON\",\n * or an error occurred while executing a custom `responseHandler`.\n **/\n status: 'PARSING_ERROR';\n originalStatus: number;\n data: string;\n error: string;\n} | {\n /**\n * * `\"TIMEOUT_ERROR\"`:\n * Request timed out\n **/\n status: 'TIMEOUT_ERROR';\n data?: undefined;\n error: string;\n} | {\n /**\n * * `\"CUSTOM_ERROR\"`:\n * A custom error type that you can return from your `queryFn` where another error might not make sense.\n **/\n status: 'CUSTOM_ERROR';\n data?: unknown;\n error: string;\n};\nfunction stripUndefined(obj: any) {\n if (!isPlainObject(obj)) {\n return obj;\n }\n const copy: Record<string, any> = {\n ...obj\n };\n for (const [k, v] of Object.entries(copy)) {\n if (v === undefined) delete copy[k];\n }\n return copy;\n}\nexport type FetchBaseQueryArgs = {\n baseUrl?: string;\n prepareHeaders?: (headers: Headers, api: Pick<BaseQueryApi, 'getState' | 'extra' | 'endpoint' | 'type' | 'forced'> & {\n arg: string | FetchArgs;\n extraOptions: unknown;\n }) => MaybePromise<Headers | void>;\n fetchFn?: (input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>;\n paramsSerializer?: (params: Record<string, any>) => string;\n /**\n * By default, we only check for 'application/json' and 'application/vnd.api+json' as the content-types for json. If you need to support another format, you can pass\n * in a predicate function for your given api to get the same automatic stringifying behavior\n * @example\n * ```ts\n * const isJsonContentType = (headers: Headers) => [\"application/vnd.api+json\", \"application/json\", \"application/vnd.hal+json\"].includes(headers.get(\"content-type\")?.trim());\n * ```\n */\n isJsonContentType?: (headers: Headers) => boolean;\n /**\n * Defaults to `application/json`;\n */\n jsonContentType?: string;\n\n /**\n * Custom replacer function used when calling `JSON.stringify()`;\n */\n jsonReplacer?: (this: any, key: string, value: any) => any;\n} & RequestInit & Pick<FetchArgs, 'responseHandler' | 'validateStatus' | 'timeout'>;\nexport type FetchBaseQueryMeta = {\n request: Request;\n response?: Response;\n};\n\n/**\n * This is a very small wrapper around fetch that aims to simplify requests.\n *\n * @example\n * ```ts\n * const baseQuery = fetchBaseQuery({\n * baseUrl: 'https://api.your-really-great-app.com/v1/',\n * prepareHeaders: (headers, { getState }) => {\n * const token = (getState() as RootState).auth.token;\n * // If we have a token set in state, let's assume that we should be passing it.\n * if (token) {\n * headers.set('authorization', `Bearer ${token}`);\n * }\n * return headers;\n * },\n * })\n * ```\n *\n * @param {string} baseUrl\n * The base URL for an API service.\n * Typically in the format of https://example.com/\n *\n * @param {(headers: Headers, api: { getState: () => unknown; arg: string | FetchArgs; extra: unknown; endpoint: string; type: 'query' | 'mutation'; forced: boolean; }) => Headers} prepareHeaders\n * An optional function that can be used to inject headers on requests.\n * Provides a Headers object, most of the `BaseQueryApi` (`dispatch` is not available), and the arg passed into the query function.\n * Useful for setting authentication or headers that need to be set conditionally.\n *\n * @link https://developer.mozilla.org/en-US/docs/Web/API/Headers\n *\n * @param {(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>} fetchFn\n * Accepts a custom `fetch` function if you do not want to use the default on the window.\n * Useful in SSR environments if you need to use a library such as `isomorphic-fetch` or `cross-fetch`\n *\n * @param {(params: Record<string, unknown>) => string} paramsSerializer\n * An optional function that can be used to stringify querystring parameters.\n *\n * @param {(headers: Headers) => boolean} isJsonContentType\n * An optional predicate function to determine if `JSON.stringify()` should be called on the `body` arg of `FetchArgs`\n *\n * @param {string} jsonContentType Used when automatically setting the content-type header for a request with a jsonifiable body that does not have an explicit content-type header. Defaults to `application/json`.\n *\n * @param {(this: any, key: string, value: any) => any} jsonReplacer Custom replacer function used when calling `JSON.stringify()`.\n *\n * @param {number} timeout\n * A number in milliseconds that represents the maximum time a request can take before timing out.\n */\n\nexport function fetchBaseQuery({\n baseUrl,\n prepareHeaders = x => x,\n fetchFn = defaultFetchFn,\n paramsSerializer,\n isJsonContentType = defaultIsJsonContentType,\n jsonContentType = 'application/json',\n jsonReplacer,\n timeout: defaultTimeout,\n responseHandler: globalResponseHandler,\n validateStatus: globalValidateStatus,\n ...baseFetchOptions\n}: FetchBaseQueryArgs = {}): BaseQueryFn<string | FetchArgs, unknown, FetchBaseQueryError, {}, FetchBaseQueryMeta> {\n if (typeof fetch === 'undefined' && fetchFn === defaultFetchFn) {\n console.warn('Warning: `fetch` is not available. Please supply a custom `fetchFn` property to use `fetchBaseQuery` on SSR environments.');\n }\n return async (arg, api, extraOptions) => {\n const {\n getState,\n extra,\n endpoint,\n forced,\n type\n } = api;\n let meta: FetchBaseQueryMeta | undefined;\n let {\n url,\n headers = new Headers(baseFetchOptions.headers),\n params = undefined,\n responseHandler = globalResponseHandler ?? 'json' as const,\n validateStatus = globalValidateStatus ?? defaultValidateStatus,\n timeout = defaultTimeout,\n ...rest\n } = typeof arg == 'string' ? {\n url: arg\n } : arg;\n let abortController: AbortController | undefined,\n signal = api.signal;\n if (timeout) {\n abortController = new AbortController();\n api.signal.addEventListener('abort', abortController.abort);\n signal = abortController.signal;\n }\n let config: RequestInit = {\n ...baseFetchOptions,\n signal,\n ...rest\n };\n headers = new Headers(stripUndefined(headers));\n config.headers = (await prepareHeaders(headers, {\n getState,\n arg,\n extra,\n endpoint,\n forced,\n type,\n extraOptions\n })) || headers;\n\n // Only set the content-type to json if appropriate. Will not be true for FormData, ArrayBuffer, Blob, etc.\n const isJsonifiable = (body: any) => typeof body === 'object' && (isPlainObject(body) || Array.isArray(body) || typeof body.toJSON === 'function');\n if (!config.headers.has('content-type') && isJsonifiable(config.body)) {\n config.headers.set('content-type', jsonContentType);\n }\n if (isJsonifiable(config.body) && isJsonContentType(config.headers)) {\n config.body = JSON.stringify(config.body, jsonReplacer);\n }\n if (params) {\n const divider = ~url.indexOf('?') ? '&' : '?';\n const query = paramsSerializer ? paramsSerializer(params) : new URLSearchParams(stripUndefined(params));\n url += divider + query;\n }\n url = joinUrls(baseUrl, url);\n const request = new Request(url, config);\n const requestClone = new Request(url, config);\n meta = {\n request: requestClone\n };\n let response,\n timedOut = false,\n timeoutId = abortController && setTimeout(() => {\n timedOut = true;\n abortController!.abort();\n }, timeout);\n try {\n response = await fetchFn(request);\n } catch (e) {\n return {\n error: {\n status: timedOut ? 'TIMEOUT_ERROR' : 'FETCH_ERROR',\n error: String(e)\n },\n meta\n };\n } finally {\n if (timeoutId) clearTimeout(timeoutId);\n abortController?.signal.removeEventListener('abort', abortController.abort);\n }\n const responseClone = response.clone();\n meta.response = responseClone;\n let resultData: any;\n let responseText: string = '';\n try {\n let handleResponseError;\n await Promise.all([handleResponse(response, responseHandler).then(r => resultData = r, e => handleResponseError = e),\n // see https://github.com/node-fetch/node-fetch/issues/665#issuecomment-538995182\n // we *have* to \"use up\" both streams at the same time or they will stop running in node-fetch scenarios\n responseClone.text().then(r => responseText = r, () => {})]);\n if (handleResponseError) throw handleResponseError;\n } catch (e) {\n return {\n error: {\n status: 'PARSING_ERROR',\n originalStatus: response.status,\n data: responseText,\n error: String(e)\n },\n meta\n };\n }\n return validateStatus(response, resultData) ? {\n data: resultData,\n meta\n } : {\n error: {\n status: response.status,\n data: resultData\n },\n meta\n };\n };\n async function handleResponse(response: Response, responseHandler: ResponseHandler) {\n if (typeof responseHandler === 'function') {\n return responseHandler(response);\n }\n if (responseHandler === 'content-type') {\n responseHandler = isJsonContentType(response.headers) ? 'json' : 'text';\n }\n if (responseHandler === 'json') {\n const text = await response.text();\n return text.length ? JSON.parse(text) : null;\n }\n return response.text();\n }\n}","export class HandledError {\n constructor(public readonly value: any, public readonly meta: any = undefined) {}\n}","import type { BaseQueryApi, BaseQueryArg, BaseQueryEnhancer, BaseQueryError, BaseQueryExtraOptions, BaseQueryFn, BaseQueryMeta } from './baseQueryTypes';\nimport type { FetchBaseQueryError } from './fetchBaseQuery';\nimport { HandledError } from './HandledError';\n\n/**\n * Exponential backoff based on the attempt number.\n *\n * @remarks\n * 1. 600ms * random(0.4, 1.4)\n * 2. 1200ms * random(0.4, 1.4)\n * 3. 2400ms * random(0.4, 1.4)\n * 4. 4800ms * random(0.4, 1.4)\n * 5. 9600ms * random(0.4, 1.4)\n *\n * @param attempt - Current attempt\n * @param maxRetries - Maximum number of retries\n */\nasync function defaultBackoff(attempt: number = 0, maxRetries: number = 5) {\n const attempts = Math.min(attempt, maxRetries);\n const timeout = ~~((Math.random() + 0.4) * (300 << attempts)); // Force a positive int in the case we make this an option\n await new Promise(resolve => setTimeout((res: any) => resolve(res), timeout));\n}\ntype RetryConditionFunction = (error: BaseQueryError<BaseQueryFn>, args: BaseQueryArg<BaseQueryFn>, extraArgs: {\n attempt: number;\n baseQueryApi: BaseQueryApi;\n extraOptions: BaseQueryExtraOptions<BaseQueryFn> & RetryOptions;\n}) => boolean;\nexport type RetryOptions = {\n /**\n * Function used to determine delay between retries\n */\n backoff?: (attempt: number, maxRetries: number) => Promise<void>;\n} & ({\n /**\n * How many times the query will be retried (default: 5)\n */\n maxRetries?: number;\n retryCondition?: undefined;\n} | {\n /**\n * Callback to determine if a retry should be attempted.\n * Return `true` for another retry and `false` to quit trying prematurely.\n */\n retryCondition?: RetryConditionFunction;\n maxRetries?: undefined;\n});\nfunction fail<BaseQuery extends BaseQueryFn = BaseQueryFn>(error: BaseQueryError<BaseQuery>, meta?: BaseQueryMeta<BaseQuery>): never {\n throw Object.assign(new HandledError({\n error,\n meta\n }), {\n throwImmediately: true\n });\n}\nconst EMPTY_OPTIONS = {};\nconst retryWithBackoff: BaseQueryEnhancer<unknown, RetryOptions, RetryOptions | void> = (baseQuery, defaultOptions) => async (args, api, extraOptions) => {\n // We need to figure out `maxRetries` before we define `defaultRetryCondition.\n // This is probably goofy, but ought to work.\n // Put our defaults in one array, filter out undefineds, grab the last value.\n const possibleMaxRetries: number[] = [5, (defaultOptions as any || EMPTY_OPTIONS).maxRetries, (extraOptions as any || EMPTY_OPTIONS).maxRetries].filter(x => x !== undefined);\n const [maxRetries] = possibleMaxRetries.slice(-1);\n const defaultRetryCondition: RetryConditionFunction = (_, __, {\n attempt\n }) => attempt <= maxRetries;\n const options: {\n maxRetries: number;\n backoff: typeof defaultBackoff;\n retryCondition: typeof defaultRetryCondition;\n } = {\n maxRetries,\n backoff: defaultBackoff,\n retryCondition: defaultRetryCondition,\n ...defaultOptions,\n ...extraOptions\n };\n let retry = 0;\n while (true) {\n try {\n const result = await baseQuery(args, api, extraOptions);\n // baseQueries _should_ return an error property, so we should check for that and throw it to continue retrying\n if (result.error) {\n throw new HandledError(result);\n }\n return result;\n } catch (e: any) {\n retry++;\n if (e.throwImmediately) {\n if (e instanceof HandledError) {\n return e.value;\n }\n\n // We don't know what this is, so we have to rethrow it\n throw e;\n }\n if (e instanceof HandledError && !options.retryCondition(e.value.error as FetchBaseQueryError, args, {\n attempt: retry,\n baseQueryApi: api,\n extraOptions\n })) {\n return e.value;\n }\n await options.backoff(retry, options.maxRetries);\n }\n }\n};\n\n/**\n * A utility that can wrap `baseQuery` in the API definition to provide retries with a basic exponential backoff.\n *\n * @example\n *\n * ```ts\n * // codeblock-meta title=\"Retry every request 5 times by default\"\n * import { createApi, fetchBaseQuery, retry } from '@reduxjs/toolkit/query/react'\n * interface Post {\n * id: number\n * name: string\n * }\n * type PostsResponse = Post[]\n *\n * // maxRetries: 5 is the default, and can be omitted. Shown for documentation purposes.\n * const staggeredBaseQuery = retry(fetchBaseQuery({ baseUrl: '/' }), { maxRetries: 5 });\n * export const api = createApi({\n * baseQuery: staggeredBaseQuery,\n * endpoints: (build) => ({\n * getPosts: build.query<PostsResponse, void>({\n * query: () => ({ url: 'posts' }),\n * }),\n * getPost: build.query<PostsResponse, string>({\n * query: (id) => ({ url: `post/${id}` }),\n * extraOptions: { maxRetries: 8 }, // You can override the retry behavior on each endpoint\n * }),\n * }),\n * });\n *\n * export const { useGetPostsQuery, useGetPostQuery } = api;\n * ```\n */\nexport const retry = /* @__PURE__ */Object.assign(retryWithBackoff, {\n fail\n});","import type { ThunkDispatch, ActionCreatorWithoutPayload // Workaround for API-Extractor\n} from '@reduxjs/toolkit';\nimport { createAction } from './rtkImports';\nexport const onFocus = /* @__PURE__ */createAction('__rtkq/focused');\nexport const onFocusLost = /* @__PURE__ */createAction('__rtkq/unfocused');\nexport const onOnline = /* @__PURE__ */createAction('__rtkq/online');\nexport const onOffline = /* @__PURE__ */createAction('__rtkq/offline');\nlet initialized = false;\n\n/**\n * A utility used to enable `refetchOnMount` and `refetchOnReconnect` behaviors.\n * It requires the dispatch method from your store.\n * Calling `setupListeners(store.dispatch)` will configure listeners with the recommended defaults,\n * but you have the option of providing a callback for more granular control.\n *\n * @example\n * ```ts\n * setupListeners(store.dispatch)\n * ```\n *\n * @param dispatch - The dispatch method from your store\n * @param customHandler - An optional callback for more granular control over listener behavior\n * @returns Return value of the handler.\n * The default handler returns an `unsubscribe` method that can be called to remove the listeners.\n */\nexport function setupListeners(dispatch: ThunkDispatch<any, any, any>, customHandler?: (dispatch: ThunkDispatch<any, any, any>, actions: {\n onFocus: typeof onFocus;\n onFocusLost: typeof onFocusLost;\n onOnline: typeof onOnline;\n onOffline: typeof onOffline;\n}) => () => void) {\n function defaultHandler() {\n const handleFocus = () => dispatch(onFocus());\n const handleFocusLost = () => dispatch(onFocusLost());\n const handleOnline = () => dispatch(onOnline());\n const handleOffline = () => dispatch(onOffline());\n const handleVisibilityChange = () => {\n if (window.document.visibilityState === 'visible') {\n handleFocus();\n } else {\n handleFocusLost();\n }\n };\n if (!initialized) {\n if (typeof window !== 'undefined' && window.addEventListener) {\n // Handle focus events\n window.addEventListener('visibilitychange', handleVisibilityChange, false);\n window.addEventListener('focus', handleFocus, false);\n\n // Handle connection events\n window.addEventListener('online', handleOnline, false);\n window.addEventListener('offline', handleOffline, false);\n initialized = true;\n }\n }\n const unsubscribe = () => {\n window.removeEventListener('focus', handleFocus);\n window.removeEventListener('visibilitychange', handleVisibilityChange);\n window.removeEventListener('online', handleOnline);\n window.removeEventListener('offline', handleOffline);\n initialized = false;\n };\n return unsubscribe;\n }\n return customHandler ? customHandler(dispatch, {\n onFocus,\n onFocusLost,\n onOffline,\n onOnline\n }) : defaultHandler();\n}","import type { Api } from '@reduxjs/toolkit/query';\nimport type { BaseQueryApi, BaseQueryArg, BaseQueryError, BaseQueryExtraOptions, BaseQueryFn, BaseQueryMeta, BaseQueryResult, QueryReturnValue } from './baseQueryTypes';\nimport type { CacheCollectionQueryExtraOptions } from './core/buildMiddleware/cacheCollection';\nimport type { CacheLifecycleInfiniteQueryExtraOptions, CacheLifecycleMutationExtraOptions, CacheLifecycleQueryExtraOptions } from './core/buildMiddleware/cacheLifecycle';\nimport type { QueryLifecycleInfiniteQueryExtraOptions, QueryLifecycleMutationExtraOptions, QueryLifecycleQueryExtraOptions } from './core/buildMiddleware/queryLifecycle';\nimport type { InfiniteData, InfiniteQueryConfigOptions, QuerySubState, RootState } from './core/index';\nimport type { SerializeQueryArgs } from './defaultSerializeQueryArgs';\nimport type { NEVER } from './fakeBaseQuery';\nimport type { CastAny, HasRequiredProps, MaybePromise, NonUndefined, OmitFromUnion, UnwrapPromise } from './tsHelpers';\nimport { isNotNullish } from './utils';\nconst resultType = /* @__PURE__ */Symbol();\nconst baseQuery = /* @__PURE__ */Symbol();\ntype EndpointDefinitionWithQuery<QueryArg, BaseQuery extends BaseQueryFn, ResultType> = {\n /**\n * `query` can be a function that returns either a `string` or an `object` which is passed to your `baseQuery`. If you are using [fetchBaseQuery](./fetchBaseQuery), this can return either a `string` or an `object` of properties in `FetchArgs`. If you use your own custom [`baseQuery`](../../rtk-query/usage/customizing-queries), you can customize this behavior to your liking.\n *\n * @example\n *\n * ```ts\n * // codeblock-meta title=\"query example\"\n *\n * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'\n * interface Post {\n * id: number\n * name: string\n * }\n * type PostsResponse = Post[]\n *\n * const api = createApi({\n * baseQuery: fetchBaseQuery({ baseUrl: '/' }),\n * tagTypes: ['Post'],\n * endpoints: (build) => ({\n * getPosts: build.query<PostsResponse, void>({\n * // highlight-start\n * query: () => 'posts',\n * // highlight-end\n * }),\n * addPost: build.mutation<Post, Partial<Post>>({\n * // highlight-start\n * query: (body) => ({\n * url: `posts`,\n * method: 'POST',\n * body,\n * }),\n * // highlight-end\n * invalidatesTags: [{ type: 'Post', id: 'LIST' }],\n * }),\n * })\n * })\n * ```\n */\n query(arg: QueryArg): BaseQueryArg<BaseQuery>;\n queryFn?: never;\n /**\n * A function to manipulate the data returned by a query or mutation.\n */\n transformResponse?(baseQueryReturnValue: BaseQueryResult<BaseQuery>, meta: BaseQueryMeta<BaseQuery>, arg: QueryArg): ResultType | Promise<ResultType>;\n /**\n * A function to manipulate the data returned by a failed query or mutation.\n */\n transformErrorResponse?(baseQueryReturnValue: BaseQueryError<BaseQuery>, meta: BaseQueryMeta<BaseQuery>, arg: QueryArg): unknown;\n /**\n * Defaults to `true`.\n *\n * Most apps should leave this setting on. The only time it can be a performance issue\n * is if an API returns extremely large amounts of data (e.g. 10,000 rows per request) and\n * you're unable to paginate it.\n *\n * For details of how this works, please see the below. When it is set to `false`,\n * every request will cause subscribed components to rerender, even when the data has not changed.\n *\n * @see https://redux-toolkit.js.org/api/other-exports#copywithstructuralsharing\n */\n structuralSharing?: boolean;\n};\ntype EndpointDefinitionWithQueryFn<QueryArg, BaseQuery extends BaseQueryFn, ResultType> = {\n /**\n * Can be used in place of `query` as an inline function that bypasses `baseQuery` completely for the endpoint.\n *\n * @example\n * ```ts\n * // codeblock-meta title=\"Basic queryFn example\"\n *\n * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'\n * interface Post {\n * id: number\n * name: string\n * }\n * type PostsResponse = Post[]\n *\n * const api = createApi({\n * baseQuery: fetchBaseQuery({ baseUrl: '/' }),\n * endpoints: (build) => ({\n * getPosts: build.query<PostsResponse, void>({\n * query: () => 'posts',\n * }),\n * flipCoin: build.query<'heads' | 'tails', void>({\n * // highlight-start\n * queryFn(arg, queryApi, extraOptions, baseQuery) {\n * const randomVal = Math.random()\n * if (randomVal < 0.45) {\n * return { data: 'heads' }\n * }\n * if (randomVal < 0.9) {\n * return { data: 'tails' }\n * }\n * return { error: { status: 500, statusText: 'Internal Server Error', data: \"Coin landed on its edge!\" } }\n * }\n * // highlight-end\n * })\n * })\n * })\n * ```\n */\n queryFn(arg: QueryArg, api: BaseQueryApi, extraOptions: BaseQueryExtraOptions<BaseQuery>, baseQuery: (arg: Parameters<BaseQuery>[0]) => ReturnType<BaseQuery>): MaybePromise<QueryReturnValue<ResultType, BaseQueryError<BaseQuery>, BaseQueryMeta<BaseQuery>>>;\n query?: never;\n transformResponse?: never;\n transformErrorResponse?: never;\n /**\n * Defaults to `true`.\n *\n * Most apps should leave this setting on. The only time it can be a performance issue\n * is if an API returns extremely large amounts of data (e.g. 10,000 rows per request) and\n * you're unable to paginate it.\n *\n * For details of how this works, please see the below. When it is set to `false`,\n * every request will cause subscribed components to rerender, even when the data has not changed.\n *\n * @see https://redux-toolkit.js.org/api/other-exports#copywithstructuralsharing\n */\n structuralSharing?: boolean;\n};\ntype BaseEndpointTypes<QueryArg, BaseQuery extends BaseQueryFn, ResultType> = {\n QueryArg: QueryArg;\n BaseQuery: BaseQuery;\n ResultType: ResultType;\n};\nexport type BaseEndpointDefinition<QueryArg, BaseQuery extends BaseQueryFn, ResultType> = (([CastAny<BaseQueryResult<BaseQuery>, {}>] extends [NEVER] ? never : EndpointDefinitionWithQuery<QueryArg, BaseQuery, ResultType>) | EndpointDefinitionWithQueryFn<QueryArg, BaseQuery, ResultType>) & {\n /* phantom type */\n [resultType]?: ResultType;\n /* phantom type */\n [baseQuery]?: BaseQuery;\n} & HasRequiredProps<BaseQueryExtraOptions<BaseQuery>, {\n extraOptions: BaseQueryExtraOptions<BaseQuery>;\n}, {\n extraOptions?: BaseQueryExtraOptions<BaseQuery>;\n}>;\nexport enum DefinitionType {\n query = 'query',\n mutation = 'mutation',\n infinitequery = 'infinitequery',\n}\nexport type GetResultDescriptionFn<TagTypes extends string, ResultType, QueryArg, ErrorType, MetaType> = (result: ResultType | undefined, error: ErrorType | undefined, arg: QueryArg, meta: MetaType) => ReadonlyArray<TagDescription<TagTypes> | undefined | null>;\nexport type FullTagDescription<TagType> = {\n type: TagType;\n id?: number | string;\n};\nexport type TagDescription<TagType> = TagType | FullTagDescription<TagType>;\n\n/**\n * @public\n */\nexport type ResultDescription<TagTypes extends string, ResultType, QueryArg, ErrorType, MetaType> = ReadonlyArray<TagDescription<TagTypes> | undefined | null> | GetResultDescriptionFn<TagTypes, ResultType, QueryArg, ErrorType, MetaType>;\ntype QueryTypes<QueryArg, BaseQuery extends BaseQueryFn, TagTypes extends string, ResultType, ReducerPath extends string = string> = BaseEndpointTypes<QueryArg, BaseQuery, ResultType> & {\n /**\n * The endpoint definition type. To be used with some internal generic types.\n * @example\n * ```ts\n * const useMyWrappedHook: UseQuery<typeof api.endpoints.query.Types.QueryDefinition> = ...\n * ```\n */\n QueryDefinition: QueryDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>;\n TagTypes: TagTypes;\n ReducerPath: ReducerPath;\n};\n\n/**\n * @public\n */\nexport interface QueryExtraOptions<TagTypes extends string, ResultType, QueryArg, BaseQuery extends BaseQueryFn, ReducerPath extends string = string> extends CacheLifecycleQueryExtraOptions<ResultType, QueryArg, BaseQuery, ReducerPath>, QueryLifecycleQueryExtraOptions<ResultType, QueryArg, BaseQuery, ReducerPath>, CacheCollectionQueryExtraOptions {\n type: DefinitionType.query;\n\n /**\n * Used by `query` endpoints. Determines which 'tag' is attached to the cached data returned by the query.\n * Expects an array of tag type strings, an array of objects of tag types with ids, or a function that returns such an array.\n * 1. `['Post']` - equivalent to `2`\n * 2. `[{ type: 'Post' }]` - equivalent to `1`\n * 3. `[{ type: 'Post', id: 1 }]`\n * 4. `(result, error, arg) => ['Post']` - equivalent to `5`\n * 5. `(result, error, arg) => [{ type: 'Post' }]` - equivalent to `4`\n * 6. `(result, error, arg) => [{ type: 'Post', id: 1 }]`\n *\n * @example\n *\n * ```ts\n * // codeblock-meta title=\"providesTags example\"\n *\n * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'\n * interface Post {\n * id: number\n * name: string\n * }\n * type PostsResponse = Post[]\n *\n * const api = createApi({\n * baseQuery: fetchBaseQuery({ baseUrl: '/' }),\n * tagTypes: ['Posts'],\n * endpoints: (build) => ({\n * getPosts: build.query<PostsResponse, void>({\n * query: () => 'posts',\n * // highlight-start\n * providesTags: (result) =>\n * result\n * ? [\n * ...result.map(({ id }) => ({ type: 'Posts' as const, id })),\n * { type: 'Posts', id: 'LIST' },\n * ]\n * : [{ type: 'Posts', id: 'LIST' }],\n * // highlight-end\n * })\n * })\n * })\n * ```\n */\n providesTags?: ResultDescription<TagTypes, ResultType, QueryArg, BaseQueryError<BaseQuery>, BaseQueryMeta<BaseQuery>>;\n /**\n * Not to be used. A query should not invalidate tags in the cache.\n */\n invalidatesTags?: never;\n\n /**\n * Can be provided to return a custom cache key value based on the query arguments.\n *\n * This is primarily intended for cases where a non-serializable value is passed as part of the query arg object and should be excluded from the cache key. It may also be used for cases where an endpoint should only have a single cache entry, such as an infinite loading / pagination implementation.\n *\n * Unlike the `createApi` version which can _only_ return a string, this per-endpoint option can also return an an object, number, or boolean. If it returns a string, that value will be used as the cache key directly. If it returns an object / number / boolean, that value will be passed to the built-in `defaultSerializeQueryArgs`. This simplifies the use case of stripping out args you don't want included in the cache key.\n *\n *\n * @example\n *\n * ```ts\n * // codeblock-meta title=\"serializeQueryArgs : exclude value\"\n *\n * import { createApi, fetchBaseQuery, defaultSerializeQueryArgs } from '@reduxjs/toolkit/query/react'\n * interface Post {\n * id: number\n * name: string\n * }\n *\n * interface MyApiClient {\n * fetchPost: (id: string) => Promise<Post>\n * }\n *\n * createApi({\n * baseQuery: fetchBaseQuery({ baseUrl: '/' }),\n * endpoints: (build) => ({\n * // Example: an endpoint with an API client passed in as an argument,\n * // but only the item ID should be used as the cache key\n * getPost: build.query<Post, { id: string; client: MyApiClient }>({\n * queryFn: async ({ id, client }) => {\n * const post = await client.fetchPost(id)\n * return { data: post }\n * },\n * // highlight-start\n * serializeQueryArgs: ({ queryArgs, endpointDefinition, endpointName }) => {\n * const { id } = queryArgs\n * // This can return a string, an object, a number, or a boolean.\n * // If it returns an object, number or boolean, that value\n * // will be serialized automatically via `defaultSerializeQueryArgs`\n * return { id } // omit `client` from the cache key\n *\n * // Alternately, you can use `defaultSerializeQueryArgs` yourself:\n * // return defaultSerializeQueryArgs({\n * // endpointName,\n * // queryArgs: { id },\n * // endpointDef