@tanstack/query-core 5.105.1 → 5.105.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/legacy/{hydration-DdkP3REv.d.cts → hydration-BXjqUj_D.d.cts} +25 -14
- package/build/legacy/hydration-BXjqUj_D.d.cts.map +1 -0
- package/build/legacy/{hydration-gHEs4kLM.d.ts → hydration-vgIjIhk6.d.ts} +25 -14
- package/build/legacy/hydration-vgIjIhk6.d.ts.map +1 -0
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/index.d.cts +1 -1
- package/build/legacy/index.d.ts +1 -1
- package/build/legacy/infiniteQueryBehavior.cjs +2 -1
- package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts.map +1 -1
- package/build/legacy/infiniteQueryBehavior.js +3 -2
- package/build/legacy/infiniteQueryBehavior.js.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +1 -1
- package/build/legacy/infiniteQueryObserver.d.ts +1 -1
- package/build/legacy/mutation.cjs +1 -0
- package/build/legacy/mutation.cjs.map +1 -1
- package/build/legacy/mutation.d.cts +1 -1
- package/build/legacy/mutation.d.ts +1 -1
- package/build/legacy/mutation.js +1 -0
- package/build/legacy/mutation.js.map +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationObserver.d.cts +1 -1
- package/build/legacy/mutationObserver.d.ts +1 -1
- package/build/legacy/queriesObserver.d.cts +1 -1
- package/build/legacy/queriesObserver.d.ts +1 -1
- package/build/legacy/query.cjs +54 -36
- package/build/legacy/query.cjs.map +1 -1
- package/build/legacy/query.d.cts +1 -1
- package/build/legacy/query.d.ts +1 -1
- package/build/legacy/query.js +55 -37
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryClient.cjs +11 -6
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryClient.js +11 -6
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryObserver.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/streamedQuery.cjs +10 -4
- package/build/legacy/streamedQuery.cjs.map +1 -1
- package/build/legacy/streamedQuery.d.cts +3 -1
- package/build/legacy/streamedQuery.d.cts.map +1 -1
- package/build/legacy/streamedQuery.d.ts +3 -1
- package/build/legacy/streamedQuery.d.ts.map +1 -1
- package/build/legacy/streamedQuery.js +11 -5
- package/build/legacy/streamedQuery.js.map +1 -1
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/utils.cjs +23 -19
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +2 -2
- package/build/legacy/utils.d.ts +2 -2
- package/build/legacy/utils.js +23 -20
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/{hydration-DdkP3REv.d.cts → hydration-BXjqUj_D.d.cts} +25 -14
- package/build/modern/hydration-BXjqUj_D.d.cts.map +1 -0
- package/build/modern/{hydration-gHEs4kLM.d.ts → hydration-vgIjIhk6.d.ts} +25 -14
- package/build/modern/hydration-vgIjIhk6.d.ts.map +1 -0
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/index.d.cts +1 -1
- package/build/modern/index.d.ts +1 -1
- package/build/modern/infiniteQueryBehavior.cjs +2 -1
- package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts.map +1 -1
- package/build/modern/infiniteQueryBehavior.js +3 -2
- package/build/modern/infiniteQueryBehavior.js.map +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +1 -1
- package/build/modern/infiniteQueryObserver.d.ts +1 -1
- package/build/modern/mutation.cjs +1 -0
- package/build/modern/mutation.cjs.map +1 -1
- package/build/modern/mutation.d.cts +1 -1
- package/build/modern/mutation.d.ts +1 -1
- package/build/modern/mutation.js +1 -0
- package/build/modern/mutation.js.map +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationObserver.d.cts +1 -1
- package/build/modern/mutationObserver.d.ts +1 -1
- package/build/modern/queriesObserver.d.cts +1 -1
- package/build/modern/queriesObserver.d.ts +1 -1
- package/build/modern/query.cjs +51 -34
- package/build/modern/query.cjs.map +1 -1
- package/build/modern/query.d.cts +1 -1
- package/build/modern/query.d.ts +1 -1
- package/build/modern/query.js +52 -35
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryClient.cjs +11 -6
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryClient.js +11 -6
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryObserver.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/streamedQuery.cjs +10 -4
- package/build/modern/streamedQuery.cjs.map +1 -1
- package/build/modern/streamedQuery.d.cts +3 -1
- package/build/modern/streamedQuery.d.cts.map +1 -1
- package/build/modern/streamedQuery.d.ts +3 -1
- package/build/modern/streamedQuery.d.ts.map +1 -1
- package/build/modern/streamedQuery.js +11 -5
- package/build/modern/streamedQuery.js.map +1 -1
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/utils.cjs +23 -19
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +2 -2
- package/build/modern/utils.d.ts +2 -2
- package/build/modern/utils.js +23 -20
- package/build/modern/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/infiniteQueryBehavior.ts +5 -1
- package/src/mutation.ts +4 -0
- package/src/query.ts +78 -64
- package/src/queryClient.ts +16 -10
- package/src/streamedQuery.ts +14 -3
- package/src/utils.ts +39 -26
- package/build/legacy/hydration-DdkP3REv.d.cts.map +0 -1
- package/build/legacy/hydration-gHEs4kLM.d.ts.map +0 -1
- package/build/modern/hydration-DdkP3REv.d.cts.map +0 -1
- package/build/modern/hydration-gHEs4kLM.d.ts.map +0 -1
|
@@ -359,13 +359,17 @@ var QueryClient = class {
|
|
|
359
359
|
* have observers with a static `staleTime`), are never refetched.
|
|
360
360
|
*
|
|
361
361
|
* By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new
|
|
362
|
-
* one starts. The returned promise
|
|
363
|
-
*
|
|
362
|
+
* one starts. The returned promise does not reject on individual query failures unless
|
|
363
|
+
* `throwOnError` is `true`.
|
|
364
|
+
*
|
|
365
|
+
* Initially paused fetches do not delay the returned promise. Their later errors are handled
|
|
366
|
+
* even when `throwOnError` is `true`.
|
|
364
367
|
* @param filters - The filters that select which queries to refetch. Without filters, every query
|
|
365
368
|
* in the cache is included.
|
|
366
369
|
* @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling
|
|
367
|
-
* it, and `throwOnError` to `true` to reject when a refetch fails.
|
|
368
|
-
* @returns A promise that resolves once
|
|
370
|
+
* it, and `throwOnError` to `true` to reject when a refetch that was not initially paused fails.
|
|
371
|
+
* @returns A promise that resolves once all matching refetches that were not initially paused
|
|
372
|
+
* have settled.
|
|
369
373
|
* @example
|
|
370
374
|
* ```ts
|
|
371
375
|
* // refetch all active queries partially matching a query key:
|
|
@@ -379,8 +383,9 @@ var QueryClient = class {
|
|
|
379
383
|
};
|
|
380
384
|
const promises = require_notifyManager.notifyManager.batch(() => require_classPrivateFieldSet2._classPrivateFieldGet2(_queryCache, this).findAll(filters).filter((query) => !query.isDisabled() && !query.isStatic()).map((query) => {
|
|
381
385
|
let promise = query.fetch(void 0, fetchOptions);
|
|
382
|
-
|
|
383
|
-
|
|
386
|
+
const isPaused = query.state.fetchStatus === "paused";
|
|
387
|
+
if (!fetchOptions.throwOnError || isPaused) promise = promise.catch(require_utils.noop);
|
|
388
|
+
return isPaused ? Promise.resolve() : promise;
|
|
384
389
|
}));
|
|
385
390
|
return Promise.all(promises).then(require_utils.noop);
|
|
386
391
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryClient.cjs","names":["QueryCache","MutationCache","focusManager","onlineManager","resolveQueryValue","functionalUpdate","notifyManager","noop","hashKey","partialMatchKey","hashQueryKeyByOptions","skipToken"],"sources":["../../src/queryClient.ts"],"sourcesContent":["import {\n functionalUpdate,\n hashKey,\n hashQueryKeyByOptions,\n noop,\n partialMatchKey,\n resolveQueryValue,\n skipToken,\n} from './utils'\nimport { QueryCache } from './queryCache'\nimport { MutationCache } from './mutationCache'\nimport { focusManager } from './focusManager'\nimport { onlineManager } from './onlineManager'\nimport { notifyManager } from './notifyManager'\nimport type {\n CancelOptions,\n DefaultError,\n DefaultOptions,\n DefaultedQueryObserverOptions,\n EnsureInfiniteQueryDataOptions,\n EnsureQueryDataOptions,\n FetchInfiniteQueryOptions,\n FetchQueryOptions,\n InferDataFromTag,\n InferErrorFromTag,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n InvalidateOptions,\n InvalidateQueryFilters,\n MutationKey,\n MutationObserverOptions,\n MutationOptions,\n OmitKeyof,\n QueryClientConfig,\n QueryExecuteOptions,\n QueryKey,\n QueryObserverOptions,\n QueryOptions,\n RefetchOptions,\n RefetchQueryFilters,\n ResetOptions,\n SetDataOptions,\n} from './types'\nimport type { QueryState } from './query'\nimport type { MutationFilters, QueryFilters, Updater } from './utils'\n\n// TYPES\n\ninterface QueryDefaults {\n queryKey: QueryKey\n defaultOptions: OmitKeyof<QueryOptions<any, any, any>, 'queryKey'>\n}\n\ninterface MutationDefaults {\n mutationKey: MutationKey\n defaultOptions: MutationOptions<any, any, any, any>\n}\n\n// CLASS\n\n/**\n * `QueryClient` is used to interact with a cache of queries and mutations. It owns a\n * `QueryCache` and a `MutationCache` (creating default ones if none are passed in) and holds\n * the default options that are applied to queries and mutations created through it.\n * @example\n * ```ts\n * const queryClient = new QueryClient({\n * defaultOptions: {\n * queries: {\n * staleTime: Infinity,\n * },\n * },\n * })\n *\n * await queryClient.query({ queryKey: ['posts'], queryFn: fetchPosts })\n * ```\n */\nexport class QueryClient {\n #queryCache: QueryCache\n #mutationCache: MutationCache\n #defaultOptions: DefaultOptions\n #queryDefaults: Map<string, QueryDefaults>\n #mutationDefaults: Map<string, MutationDefaults>\n #mountCount: number\n #unsubscribeFocus?: () => void\n #unsubscribeOnline?: () => void\n\n constructor(config: QueryClientConfig = {}) {\n this.#queryCache = config.queryCache || new QueryCache()\n this.#mutationCache = config.mutationCache || new MutationCache()\n this.#defaultOptions = config.defaultOptions || {}\n this.#queryDefaults = new Map()\n this.#mutationDefaults = new Map()\n this.#mountCount = 0\n }\n\n /**\n * Called by a framework adapter's `QueryClientProvider`-equivalent when it mounts, to start\n * listening for focus/online events and resume paused mutations. Ref-counted via an internal\n * mount count, so nested or multiple providers sharing the same `QueryClient` don't tear down\n * the shared listeners until the last one unmounts.\n */\n mount(): void {\n this.#mountCount++\n if (this.#mountCount !== 1) return\n\n this.#unsubscribeFocus = focusManager.subscribe(async (focused) => {\n if (focused) {\n await this.resumePausedMutations()\n this.#queryCache.onFocus()\n }\n })\n this.#unsubscribeOnline = onlineManager.subscribe(async (online) => {\n if (online) {\n await this.resumePausedMutations()\n this.#queryCache.onOnline()\n }\n })\n }\n\n /**\n * The inverse of {@link QueryClient#mount} — called by a framework adapter's\n * `QueryClientProvider`-equivalent when it unmounts. Only tears down the focus/online\n * listeners once the mount count returns to `0`.\n */\n unmount(): void {\n this.#mountCount--\n if (this.#mountCount !== 0) return\n\n this.#unsubscribeFocus?.()\n this.#unsubscribeFocus = undefined\n\n this.#unsubscribeOnline?.()\n this.#unsubscribeOnline = undefined\n }\n\n /**\n * Returns the number of queries in the cache that are currently fetching, optionally\n * matching a set of filters. This includes background-fetching, loading new pages, and\n * loading more infinite query results.\n * @param filters - Narrows down which fetching queries are counted. Without filters, every\n * fetching query is counted.\n * @returns The number of matching queries whose `fetchStatus` is `'fetching'`.\n * @example\n * ```ts\n * if (queryClient.isFetching()) {\n * console.log('At least one query is fetching!')\n * }\n * ```\n */\n isFetching(filters?: Omit<QueryFilters, 'fetchStatus'>): number {\n return this.#queryCache.findAll({ ...filters, fetchStatus: 'fetching' })\n .length\n }\n\n /**\n * Returns the number of mutations in the cache that are currently pending, optionally\n * matching a set of filters.\n * @param filters - Narrows down which pending mutations are counted. Without filters, every\n * pending mutation is counted.\n * @returns The number of matching mutations whose `status` is `'pending'`.\n * @example\n * ```ts\n * if (queryClient.isMutating()) {\n * console.log('At least one mutation is pending!')\n * }\n * ```\n */\n isMutating<\n TMutationFilters extends MutationFilters<any, any> = MutationFilters,\n >(filters?: TMutationFilters): number {\n return this.#mutationCache.findAll({ ...filters, status: 'pending' }).length\n }\n\n /**\n * Imperative (non-reactive) way to retrieve data for a QueryKey.\n * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.\n *\n * Hint: Do not use this function inside a component, because it won't receive updates.\n * Use `useQuery` to create a `QueryObserver` that subscribes to changes.\n * @param queryKey - The query key of the query to read.\n * @returns The cached data for the query, or `undefined` if no query with this key has been observed yet.\n * @see {@link QueryClient#getQueriesData}\n */\n getQueryData<\n TQueryFnData = unknown,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n >(queryKey: TTaggedQueryKey): TInferredQueryFnData | undefined {\n const options = this.defaultQueryOptions({ queryKey })\n\n return this.#queryCache.get<TInferredQueryFnData>(options.queryHash)?.state\n .data\n }\n\n /**\n * Returns the cached data of a query, or fetches it if there is none. With `revalidateIfStale`,\n * stale cached data is also refetched in the background.\n * @param options - The query options. If the query has no cached data yet, it is fetched with\n * these options.\n * @returns A promise that resolves to the cached data, or to the fetched data if nothing was\n * cached yet.\n * @deprecated Use queryClient.query({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.\n */\n ensureQueryData<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: EnsureQueryDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n const query = this.#queryCache.build(this, defaultedOptions)\n const cachedData = query.state.data\n\n if (cachedData === undefined) {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchQuery(options)\n }\n\n if (\n options.revalidateIfStale &&\n query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query))\n ) {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n void this.prefetchQuery(defaultedOptions)\n }\n\n return Promise.resolve(cachedData)\n }\n\n /**\n * Imperative (non-reactive) way to retrieve the cached data of multiple queries at once.\n * Only queries matching the given filters are returned; if none match, an empty array is\n * returned.\n *\n * Because the matched queries can hold data of different shapes (e.g. a broad filter can match\n * queries with unrelated data types), the `TQueryFnData` generic defaults to `unknown` rather\n * than being inferred. Passing a more specific type is a convenience for call sites that know\n * every matched query holds the same shape — it is not checked against the actual cache\n * contents.\n * @param filters - The filters that select which queries to read.\n * @returns An array of query key and data pairs. The data is `undefined` for a query with no cached data.\n * @see {@link QueryClient#getQueryData}\n * @example\n * ```ts\n * const data = queryClient.getQueriesData({ queryKey: ['posts'] })\n * ```\n */\n getQueriesData<\n TQueryFnData = unknown,\n TQueryFilters extends QueryFilters<any> = QueryFilters,\n >(filters: TQueryFilters): Array<[QueryKey, TQueryFnData | undefined]> {\n return this.#queryCache.findAll(filters).map(({ queryKey, state }) => {\n const data = state.data as TQueryFnData | undefined\n return [queryKey, data]\n })\n }\n\n /**\n * Synchronous way to immediately update a query's cached data. If the updater (or the value\n * passed) resolves to `undefined`, the cache is left untouched and no query is created;\n * otherwise, if the query does not exist yet, it will be created. To update multiple queries\n * at once by partially matching query keys, use {@link QueryClient#setQueriesData} instead.\n *\n * Updates must be performed immutably: do not mutate `oldData`, or data previously retrieved\n * via {@link QueryClient#getQueryData}, in place.\n * @param queryKey - The query key to set data for.\n * @param updater - Either the new data, or a function that receives the current data (which\n * may be `undefined`) and returns the new data.\n * @param options - Set `updatedAt` to override the timestamp the written data is recorded with.\n * @returns The data that was written, or `undefined` if the updater returned `undefined` — in that case\n * the write is skipped and the cache is left unchanged.\n * @example\n * ```ts\n * queryClient.setQueryData(['posts'], newPosts)\n *\n * // Or, using an updater function that receives the current data:\n * queryClient.setQueryData(['posts'], (oldPosts) => [...oldPosts, newPost])\n * ```\n */\n setQueryData<\n TQueryFnData = unknown,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n >(\n queryKey: TTaggedQueryKey,\n updater: Updater<\n InferDataFromTag<NoInfer<TQueryFnData>, TTaggedQueryKey> | undefined,\n NoInfer<TInferredQueryFnData> | undefined\n >,\n options?: SetDataOptions,\n ): NoInfer<TInferredQueryFnData> | undefined {\n const defaultedOptions = this.defaultQueryOptions<\n any,\n any,\n unknown,\n any,\n QueryKey\n >({ queryKey })\n\n const query = this.#queryCache.get<\n InferDataFromTag<NoInfer<TQueryFnData>, TTaggedQueryKey>\n >(defaultedOptions.queryHash)\n const prevData = query?.state.data\n const data = functionalUpdate(updater, prevData)\n\n if (data === undefined) {\n return undefined\n }\n\n return this.#queryCache\n .build(this, defaultedOptions)\n .setData(data, { ...options, manual: true })\n }\n\n /**\n * Synchronous way to immediately update the cached data of multiple queries at once, using\n * filters or partial query key matching. Only queries that already exist and match the given\n * filters are updated; no new cache entries are created. Internally this calls\n * {@link QueryClient#setQueryData} for each matching query.\n * @param filters - The filters that select which existing queries to update.\n * @param updater - Either the new data, or a function that receives each matched query's current\n * data (which may be `undefined`) and returns the new data.\n * @param options - Set `updatedAt` to override the timestamp the written data is recorded with.\n * @returns One `[queryKey, data]` tuple per matched query, in the same shape and with the same\n * `undefined` case as {@link QueryClient#setQueryData}.\n * @example\n * ```ts\n * queryClient.setQueriesData({ queryKey: ['posts'] }, (oldPosts) =>\n * oldPosts ? oldPosts.filter((post) => post.id !== deletedId) : oldPosts,\n * )\n * ```\n */\n setQueriesData<\n TQueryFnData,\n TQueryFilters extends QueryFilters<any> = QueryFilters,\n >(\n filters: TQueryFilters,\n updater: Updater<\n NoInfer<TQueryFnData> | undefined,\n NoInfer<TQueryFnData> | undefined\n >,\n options?: SetDataOptions,\n ): Array<[QueryKey, TQueryFnData | undefined]> {\n return notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .map(({ queryKey }) => [\n queryKey,\n this.setQueryData<TQueryFnData>(queryKey, updater, options),\n ]),\n )\n }\n\n /**\n * Imperative (non-reactive) way to retrieve an existing query's state. If the query does not\n * exist, `undefined` is returned.\n * @param queryKey - The query key of the query to read.\n * @returns The query's state, or `undefined` if no query with this key exists.\n * @example\n * ```ts\n * const state = queryClient.getQueryState(['posts'])\n * console.log(state?.dataUpdatedAt)\n * ```\n */\n getQueryState<\n TQueryFnData = unknown,\n TError = DefaultError,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n TInferredError = InferErrorFromTag<TError, TTaggedQueryKey>,\n >(\n queryKey: TTaggedQueryKey,\n ): QueryState<TInferredQueryFnData, TInferredError> | undefined {\n const options = this.defaultQueryOptions({ queryKey })\n return this.#queryCache.get<TInferredQueryFnData, TInferredError>(\n options.queryHash,\n )?.state\n }\n\n /**\n * Removes queries from the cache that match the given filters. Unlike\n * {@link QueryClient#invalidateQueries} or {@link QueryClient#refetchQueries}, this removes\n * matching queries from the cache instead of refetching them. Without filters, every query in\n * the cache is removed.\n * @param filters - The filters that select which queries to remove. Without filters, every query\n * is removed.\n * @example\n * ```ts\n * queryClient.removeQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n removeQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n ): void {\n const queryCache = this.#queryCache\n notifyManager.batch(() => {\n queryCache.findAll(filters).forEach((query) => {\n queryCache.remove(query)\n })\n })\n }\n\n /**\n * Resets queries matching the given filters back to their initial state (e.g. any\n * `initialData`), notifying subscribers rather than removing them. Active queries among the\n * matched set are then refetched, and the returned promise resolves once that refetch settles.\n * @param filters - The filters that select which queries to reset. Without filters, every query\n * is reset.\n * @param options - Passed to the refetch of the active matched queries, e.g. `cancelRefetch` and\n * `throwOnError`.\n * @returns A promise that resolves once the refetch of the active matched queries settles.\n * @example\n * ```ts\n * await queryClient.resetQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n resetQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n options?: ResetOptions,\n ): Promise<void> {\n const queryCache = this.#queryCache\n\n return notifyManager.batch(() => {\n const matched = queryCache.findAll(filters)\n const queriesToRefetch = new Set(matched)\n matched.forEach((query) => {\n query.reset()\n })\n return this.refetchQueries(\n {\n type: 'active',\n predicate: (query) => queriesToRefetch.has(query),\n },\n options,\n )\n })\n }\n\n /**\n * Cancels outgoing fetches for queries matching the given filters. Most useful when performing\n * optimistic updates, since any outgoing refetch that resolves afterwards would otherwise\n * overwrite the optimistic update. By default (`revert: true`), a cancelled query's data is\n * reverted to its state before the outgoing fetch started.\n *\n * The returned promise never rejects, even if individual cancellations fail.\n * @param filters - The filters that select which queries to cancel. Without filters, every query\n * is cancelled.\n * @param cancelOptions - Passed to each matched query's cancellation. `revert` defaults to\n * `true`.\n * @returns A promise that resolves once every cancellation has settled.\n * @example\n * ```ts\n * await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n cancelQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n cancelOptions: CancelOptions = {},\n ): Promise<void> {\n const defaultedCancelOptions = { revert: true, ...cancelOptions }\n\n const promises = notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .map((query) => query.cancel(defaultedCancelOptions)),\n )\n\n return Promise.all(promises).then(noop).catch(noop)\n }\n\n /**\n * Marks queries matching the given filters as invalidated. Unlike\n * {@link QueryClient#removeQueries}, invalidated queries stay in the cache.\n *\n * Unless `filters.refetchType` is `'none'`, matching queries are then refetched via\n * {@link QueryClient#refetchQueries}, using `filters.refetchType` if set, otherwise\n * `filters.type`, otherwise `'active'`.\n * @param filters - The filters that select which queries to invalidate, plus `refetchType` to\n * control which of them to refetch afterwards. Without filters, every query is invalidated.\n * @param options - Passed to {@link QueryClient#refetchQueries}, e.g. `cancelRefetch` and\n * `throwOnError`.\n * @returns A promise that resolves once the refetch settles, or immediately if `refetchType` is\n * `'none'`.\n * @example\n * ```ts\n * await queryClient.invalidateQueries({ queryKey: ['posts'], refetchType: 'active' })\n * ```\n */\n invalidateQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: InvalidateQueryFilters<TTaggedQueryKey>,\n options: InvalidateOptions = {},\n ): Promise<void> {\n return notifyManager.batch(() => {\n this.#queryCache.findAll(filters).forEach((query) => {\n query.invalidate()\n })\n\n if (filters?.refetchType === 'none') {\n return Promise.resolve()\n }\n return this.refetchQueries(\n {\n ...filters,\n type: filters?.refetchType ?? filters?.type ?? 'active',\n },\n options,\n )\n })\n }\n\n /**\n * Refetches queries matching the given filters, regardless of whether they are stale. Without\n * filters, every query in the cache is refetched. Queries that are disabled, or static (only\n * have observers with a static `staleTime`), are never refetched.\n *\n * By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new\n * one starts. The returned promise resolves once all matching queries have settled; it does\n * not reject on individual query failures unless `throwOnError` is set.\n * @param filters - The filters that select which queries to refetch. Without filters, every query\n * in the cache is included.\n * @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling\n * it, and `throwOnError` to `true` to reject when a refetch fails.\n * @returns A promise that resolves once every matched query has settled.\n * @example\n * ```ts\n * // refetch all active queries partially matching a query key:\n * await queryClient.refetchQueries({ queryKey: ['posts'], type: 'active' })\n * ```\n */\n refetchQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: RefetchQueryFilters<TTaggedQueryKey>,\n options: RefetchOptions = {},\n ): Promise<void> {\n const fetchOptions = {\n ...options,\n cancelRefetch: options.cancelRefetch ?? true,\n }\n const promises = notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .filter((query) => !query.isDisabled() && !query.isStatic())\n .map((query) => {\n let promise = query.fetch(undefined, fetchOptions)\n if (!fetchOptions.throwOnError) {\n promise = promise.catch(noop)\n }\n return query.state.fetchStatus === 'paused'\n ? Promise.resolve()\n : promise\n }),\n )\n\n return Promise.all(promises).then(noop)\n }\n\n /**\n * Asynchronous method to fetch and cache a query, resolving with the data or throwing with\n * the error.\n *\n * If the query already exists in the cache and its data is not stale (per the given\n * `staleTime`), the cached data is returned without fetching. Otherwise, the query is fetched\n * and the promise resolves once the fetch settles. If a `select` function is provided, it is\n * applied to the data in both cases (cached or freshly fetched) before it is returned.\n *\n * Unlike a reactive observer, retries are disabled by default here (`retry: false`) unless\n * explicitly configured, since there is no component to catch a thrown error and retry through\n * re-render.\n *\n * The accepted options are `QueryObserverOptions` minus the fields that only make sense for a\n * reactive observer — `enabled`, `refetchInterval`, `refetchIntervalInBackground`,\n * `refetchOnWindowFocus`, `refetchOnReconnect`, `refetchOnMount`, `retryOnMount`,\n * `notifyOnChangeProps`, `throwOnError`, `suspense`, and `placeholderData` are not part of this\n * method's options.\n *\n * This method replaces the deprecated `fetchQuery`, and — combined with\n * `{ staleTime: 'static' }` — the deprecated `ensureQueryData`.\n * @param options - The query options, including the `queryKey` and the `queryFn` used if the\n * query needs to fetch.\n * @returns A promise that resolves to the data, or to the result of `select` if provided. It\n * rejects with the error from the fetch or from `select`.\n * @example\n * ```ts\n * try {\n * const data = await queryClient.query({ queryKey, queryFn, staleTime: 10000 })\n * } catch (error) {\n * console.log(error)\n * }\n * ```\n */\n async query<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options: QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n\n // https://github.com/tannerlinsley/react-query/issues/652\n if (defaultedOptions.retry === undefined) {\n defaultedOptions.retry = false\n }\n\n const query = this.#queryCache.build(this, defaultedOptions)\n\n const isStale = query.isStaleByTime(\n resolveQueryValue(defaultedOptions.staleTime, query),\n )\n\n const queryData = isStale\n ? await query.fetch(defaultedOptions)\n : (query.state.data as TQueryData)\n\n const select = defaultedOptions.select\n\n if (select) {\n return select(queryData)\n }\n\n return queryData as unknown as TData\n }\n\n /**\n * Fetches and caches a query, or returns its cached data if it isn't stale. Unlike in observers,\n * the fetch isn't retried unless `retry` is set.\n * @param options - The query options, including the `queryKey` and the `queryFn` used if the\n * query needs to fetch.\n * @returns A promise that resolves to the cached or fetched data, or rejects with the fetch\n * error.\n * @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.\n */\n fetchQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options: FetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n\n // https://github.com/tannerlinsley/react-query/issues/652\n if (defaultedOptions.retry === undefined) {\n defaultedOptions.retry = false\n }\n\n const query = this.#queryCache.build(this, defaultedOptions)\n\n return query.isStaleByTime(\n resolveQueryValue(defaultedOptions.staleTime, query),\n )\n ? query.fetch(defaultedOptions)\n : Promise.resolve(query.state.data as TData)\n }\n\n /**\n * Fetches and caches a query like {@link QueryClient#fetchQuery}, but ignores the result and any\n * error.\n * @param options - The query options, including the `queryKey` and the `queryFn` used if the\n * query needs to fetch.\n * @returns A promise that resolves once the fetch settles. It never rejects.\n * @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.\n */\n prefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): Promise<void> {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchQuery(options).then(noop).catch(noop)\n }\n\n /**\n * Asynchronous method to fetch and cache an infinite query, resolving with an\n * {@link InfiniteData} object or throwing with the error.\n *\n * Behaves like {@link QueryClient#query}, accepting the same options (minus\n * `initialPageParam`), plus the required `initialPageParam`, and an optional `pages` /\n * `getNextPageParam` pair used to refetch a fixed number of pages from the start.\n *\n * This method replaces the deprecated `fetchInfiniteQuery`, and — combined with\n * `{ staleTime: 'static' }` — the deprecated `ensureInfiniteQueryData`.\n * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the\n * `initialPageParam`.\n * @returns A promise that resolves to the {@link InfiniteData}, or to the result of `select` if\n * provided. It rejects with the error from the fetch or from `select`.\n * @example\n * ```ts\n * try {\n * const data = await queryClient.infiniteQuery({ queryKey, queryFn, initialPageParam: 0 })\n * console.log(data.pages)\n * } catch (error) {\n * console.log(error)\n * }\n * ```\n */\n infiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<\n Array<TData> extends Array<InfiniteData<TQueryFnData>>\n ? InfiniteData<TQueryFnData, TPageParam>\n : TData\n > {\n options._type = 'infinite'\n return this.query(options as any)\n }\n\n /**\n * Fetches and caches an infinite query, or returns its cached data if it isn't stale.\n * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the\n * `initialPageParam`.\n * @returns A promise that resolves to the cached or fetched {@link InfiniteData}, or rejects with\n * the fetch error.\n * @deprecated Use queryClient.infiniteQuery(options) instead. This method will be removed in the next major version.\n */\n fetchInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: FetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<InfiniteData<TData, TPageParam>> {\n options._type = 'infinite'\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchQuery(options as any)\n }\n\n /**\n * Fetches and caches an infinite query like {@link QueryClient#fetchInfiniteQuery}, but ignores\n * the result and any error.\n * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the\n * `initialPageParam`.\n * @returns A promise that resolves once the fetch settles. It never rejects.\n * @deprecated Use queryClient.infiniteQuery(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.\n */\n prefetchInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: FetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<void> {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchInfiniteQuery(options).then(noop).catch(noop)\n }\n\n /**\n * Returns the cached data of an infinite query, or fetches it if there is none. With\n * `revalidateIfStale`, stale cached data is also refetched in the background.\n * @param options - The infinite query options. If the query has no cached data yet, it is fetched\n * with these options.\n * @returns A promise that resolves to the cached {@link InfiniteData}, or to the fetched data if\n * nothing was cached yet.\n * @deprecated Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.\n */\n ensureInfiniteQueryData<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: EnsureInfiniteQueryDataOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<InfiniteData<TData, TPageParam>> {\n options._type = 'infinite'\n\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.ensureQueryData(options as any)\n }\n\n /**\n * Resumes mutations that were paused because there was no network connection. Does nothing\n * (resolving immediately) if the client is currently offline.\n * @returns A promise that resolves once the resumed mutations have settled.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * await queryClient.resumePausedMutations()\n * ```\n */\n resumePausedMutations(): Promise<unknown> {\n if (onlineManager.isOnline()) {\n return this.#mutationCache.resumePausedMutations()\n }\n return Promise.resolve()\n }\n\n /**\n * Returns the query cache this client is connected to.\n * @returns The {@link QueryCache} instance.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const queryCache = queryClient.getQueryCache()\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n getQueryCache(): QueryCache {\n return this.#queryCache\n }\n\n /**\n * Returns the mutation cache this client is connected to.\n * @returns The {@link MutationCache} instance.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const mutationCache = queryClient.getMutationCache()\n * const mutations = mutationCache.findAll({ status: 'pending' })\n * ```\n */\n getMutationCache(): MutationCache {\n return this.#mutationCache\n }\n\n /**\n * Returns the default options that were set when creating the client, or via\n * {@link QueryClient#setDefaultOptions}.\n * @returns The client's current default options.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const defaultOptions = queryClient.getDefaultOptions()\n * ```\n */\n getDefaultOptions(): DefaultOptions {\n return this.#defaultOptions\n }\n\n /**\n * Dynamically sets the default options for this client, overwriting any previously defined\n * default options.\n * @param options - The new default options for queries and mutations.\n * @see {@link QueryClient#getDefaultOptions}\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * queryClient.setDefaultOptions({\n * queries: {\n * staleTime: Infinity,\n * },\n * })\n * ```\n */\n setDefaultOptions(options: DefaultOptions): void {\n this.#defaultOptions = options\n }\n\n /**\n * Sets default options for queries whose query key partially matches the given `queryKey`.\n *\n * If several registered query defaults match a given query key, they are merged together in\n * registration order by {@link QueryClient#getQueryDefaults}, so register defaults from the\n * most generic key to the least generic one — more specific defaults should be registered\n * after more generic ones so they take precedence.\n * @param queryKey - The query key that query keys are partially matched against.\n * @param options - The default options applied to matching queries.\n * @example\n * ```ts\n * queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts })\n *\n * await queryClient.query({ queryKey: ['posts'] })\n * ```\n */\n setQueryDefaults<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n >(\n queryKey: QueryKey,\n options: Partial<\n OmitKeyof<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData>,\n 'queryKey'\n >\n >,\n ): void {\n this.#queryDefaults.set(hashKey(queryKey), {\n queryKey,\n defaultOptions: options,\n })\n }\n\n /**\n * Returns the default options registered for queries whose query key partially matches the\n * given `queryKey`, via {@link QueryClient#setQueryDefaults}. If multiple registered defaults\n * match, they are merged together in registration order.\n * @param queryKey - The query key to look up registered defaults for.\n * @returns The merged default options of every registration that matches, or an empty object if\n * none match.\n * @example\n * ```ts\n * const defaultOptions = queryClient.getQueryDefaults(['posts'])\n * ```\n */\n getQueryDefaults(\n queryKey: QueryKey,\n ): OmitKeyof<QueryObserverOptions<any, any, any, any, any>, 'queryKey'> {\n const defaults = [...this.#queryDefaults.values()]\n\n const result: OmitKeyof<\n QueryObserverOptions<any, any, any, any, any>,\n 'queryKey'\n > = {}\n\n defaults.forEach((queryDefault) => {\n if (partialMatchKey(queryKey, queryDefault.queryKey)) {\n Object.assign(result, queryDefault.defaultOptions)\n }\n })\n return result\n }\n\n /**\n * Sets default options for mutations whose mutation key partially matches the given\n * `mutationKey`. As with {@link QueryClient#setQueryDefaults}, the order of registration\n * matters when several registered defaults match the same mutation key.\n * @param mutationKey - The mutation key that mutation keys are partially matched against.\n * @param options - The default options applied to matching mutations.\n * @see {@link QueryClient#getMutationDefaults}\n * @example\n * ```ts\n * queryClient.setMutationDefaults(['addPost'], { mutationFn: addPost })\n * ```\n */\n setMutationDefaults<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n >(\n mutationKey: MutationKey,\n options: OmitKeyof<\n MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n ): void {\n this.#mutationDefaults.set(hashKey(mutationKey), {\n mutationKey,\n defaultOptions: options,\n })\n }\n\n /**\n * Returns the default options registered for mutations whose mutation key partially matches\n * the given `mutationKey`, via {@link QueryClient#setMutationDefaults}. If multiple registered\n * defaults match, they are merged together in registration order.\n * @param mutationKey - The mutation key to look up registered defaults for.\n * @returns The merged default options of every registration that matches, or an empty object if\n * none match.\n * @example\n * ```ts\n * const defaultOptions = queryClient.getMutationDefaults(['addPost'])\n * ```\n */\n getMutationDefaults(\n mutationKey: MutationKey,\n ): OmitKeyof<MutationObserverOptions<any, any, any, any>, 'mutationKey'> {\n const defaults = [...this.#mutationDefaults.values()]\n\n const result: OmitKeyof<\n MutationObserverOptions<any, any, any, any>,\n 'mutationKey'\n > = {}\n\n defaults.forEach((queryDefault) => {\n if (partialMatchKey(mutationKey, queryDefault.mutationKey)) {\n Object.assign(result, queryDefault.defaultOptions)\n }\n })\n\n return result\n }\n\n /**\n * Called by framework adapters (e.g. inside `useQuery`) to resolve the options passed by the\n * caller into their final, defaulted form: merging the client's own `defaultOptions.queries`,\n * then `queryClient.setQueryDefaults` for the given `queryKey`, then the caller's options on\n * top. A no-op if the options are already defaulted (`_defaulted: true`).\n * @param options - The query options passed by the caller.\n * @returns The defaulted options, with `queryHash` and dependent defaults (e.g.\n * `refetchOnReconnect`) filled in.\n */\n defaultQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options:\n | QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n | DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > {\n if (options._defaulted) {\n return options as DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n }\n\n const defaultedOptions = {\n ...this.#defaultOptions.queries,\n ...this.getQueryDefaults(options.queryKey),\n ...options,\n _defaulted: true,\n }\n\n if (!defaultedOptions.queryHash) {\n defaultedOptions.queryHash = hashQueryKeyByOptions(\n defaultedOptions.queryKey,\n defaultedOptions,\n )\n }\n\n // dependent default values\n if (defaultedOptions.refetchOnReconnect === undefined) {\n defaultedOptions.refetchOnReconnect =\n defaultedOptions.networkMode !== 'always'\n }\n if (defaultedOptions.throwOnError === undefined) {\n defaultedOptions.throwOnError = !!defaultedOptions.suspense\n }\n\n if (!defaultedOptions.networkMode && defaultedOptions.persister) {\n defaultedOptions.networkMode = 'offlineFirst'\n }\n\n if (defaultedOptions.queryFn === skipToken) {\n defaultedOptions.enabled = false\n }\n\n return defaultedOptions as DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n }\n\n /**\n * The mutation counterpart of {@link QueryClient#defaultQueryOptions}. Called by framework\n * adapters (e.g. inside `useMutation`) to merge the client's `defaultOptions.mutations`, then\n * `queryClient.setMutationDefaults` for the given `mutationKey`, then the caller's options on\n * top. A no-op if the options are already defaulted (`_defaulted: true`).\n * @param options - The mutation options passed by the caller.\n * @returns The defaulted options.\n */\n defaultMutationOptions<T extends MutationOptions<any, any, any, any>>(\n options?: T,\n ): T {\n if (options?._defaulted) {\n return options\n }\n return {\n ...this.#defaultOptions.mutations,\n ...(options?.mutationKey &&\n this.getMutationDefaults(options.mutationKey)),\n ...options,\n _defaulted: true,\n } as T\n }\n\n /**\n * Clears both the query cache and the mutation cache this client is connected to.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * queryClient.clear()\n * ```\n */\n clear(): void {\n this.#queryCache.clear()\n this.#mutationCache.clear()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,IAAa,cAAb,MAAyB;CAUvB,YAAY,SAA4B,CAAC,GAAG;;;;;;;;;EAC1C,8BAAA,uBAAA,aAAA,MAAmB,OAAO,cAAc,IAAIA,mBAAAA,WAAW,CAAA;EACvD,8BAAA,uBAAA,gBAAA,MAAsB,OAAO,iBAAiB,IAAIC,sBAAAA,cAAc,CAAA;EAChE,8BAAA,uBAAA,iBAAA,MAAuB,OAAO,kBAAkB,CAAC,CAAA;EACjD,8BAAA,uBAAA,gBAAA,sBAAsB,IAAI,IAAI,CAAA;EAC9B,8BAAA,uBAAA,mBAAA,sBAAyB,IAAI,IAAI,CAAA;EACjC,8BAAA,uBAAA,aAAA,MAAmB,CAAA;CACrB;;;;;;;CAQA,QAAc;;EACZ,8BAAA,uBAAA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A,IAAA,CAAA,CAAoB,MAAM;CAC5B;AACF"}
|
|
1
|
+
{"version":3,"file":"queryClient.cjs","names":["QueryCache","MutationCache","focusManager","onlineManager","resolveQueryValue","functionalUpdate","notifyManager","noop","hashKey","partialMatchKey","hashQueryKeyByOptions","skipToken"],"sources":["../../src/queryClient.ts"],"sourcesContent":["import {\n functionalUpdate,\n hashKey,\n hashQueryKeyByOptions,\n noop,\n partialMatchKey,\n resolveQueryValue,\n skipToken,\n} from './utils'\nimport { QueryCache } from './queryCache'\nimport { MutationCache } from './mutationCache'\nimport { focusManager } from './focusManager'\nimport { onlineManager } from './onlineManager'\nimport { notifyManager } from './notifyManager'\nimport type {\n CancelOptions,\n DefaultError,\n DefaultOptions,\n DefaultedQueryObserverOptions,\n EnsureInfiniteQueryDataOptions,\n EnsureQueryDataOptions,\n FetchInfiniteQueryOptions,\n FetchQueryOptions,\n InferDataFromTag,\n InferErrorFromTag,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n InvalidateOptions,\n InvalidateQueryFilters,\n MutationKey,\n MutationObserverOptions,\n MutationOptions,\n OmitKeyof,\n QueryClientConfig,\n QueryExecuteOptions,\n QueryKey,\n QueryObserverOptions,\n QueryOptions,\n RefetchOptions,\n RefetchQueryFilters,\n ResetOptions,\n SetDataOptions,\n} from './types'\nimport type { QueryState } from './query'\nimport type { MutationFilters, QueryFilters, Updater } from './utils'\n\n// TYPES\n\ninterface QueryDefaults {\n queryKey: QueryKey\n defaultOptions: OmitKeyof<QueryOptions<any, any, any>, 'queryKey'>\n}\n\ninterface MutationDefaults {\n mutationKey: MutationKey\n defaultOptions: MutationOptions<any, any, any, any>\n}\n\n// CLASS\n\n/**\n * `QueryClient` is used to interact with a cache of queries and mutations. It owns a\n * `QueryCache` and a `MutationCache` (creating default ones if none are passed in) and holds\n * the default options that are applied to queries and mutations created through it.\n * @example\n * ```ts\n * const queryClient = new QueryClient({\n * defaultOptions: {\n * queries: {\n * staleTime: Infinity,\n * },\n * },\n * })\n *\n * await queryClient.query({ queryKey: ['posts'], queryFn: fetchPosts })\n * ```\n */\nexport class QueryClient {\n #queryCache: QueryCache\n #mutationCache: MutationCache\n #defaultOptions: DefaultOptions\n #queryDefaults: Map<string, QueryDefaults>\n #mutationDefaults: Map<string, MutationDefaults>\n #mountCount: number\n #unsubscribeFocus?: () => void\n #unsubscribeOnline?: () => void\n\n constructor(config: QueryClientConfig = {}) {\n this.#queryCache = config.queryCache || new QueryCache()\n this.#mutationCache = config.mutationCache || new MutationCache()\n this.#defaultOptions = config.defaultOptions || {}\n this.#queryDefaults = new Map()\n this.#mutationDefaults = new Map()\n this.#mountCount = 0\n }\n\n /**\n * Called by a framework adapter's `QueryClientProvider`-equivalent when it mounts, to start\n * listening for focus/online events and resume paused mutations. Ref-counted via an internal\n * mount count, so nested or multiple providers sharing the same `QueryClient` don't tear down\n * the shared listeners until the last one unmounts.\n */\n mount(): void {\n this.#mountCount++\n if (this.#mountCount !== 1) return\n\n this.#unsubscribeFocus = focusManager.subscribe(async (focused) => {\n if (focused) {\n await this.resumePausedMutations()\n this.#queryCache.onFocus()\n }\n })\n this.#unsubscribeOnline = onlineManager.subscribe(async (online) => {\n if (online) {\n await this.resumePausedMutations()\n this.#queryCache.onOnline()\n }\n })\n }\n\n /**\n * The inverse of {@link QueryClient#mount} — called by a framework adapter's\n * `QueryClientProvider`-equivalent when it unmounts. Only tears down the focus/online\n * listeners once the mount count returns to `0`.\n */\n unmount(): void {\n this.#mountCount--\n if (this.#mountCount !== 0) return\n\n this.#unsubscribeFocus?.()\n this.#unsubscribeFocus = undefined\n\n this.#unsubscribeOnline?.()\n this.#unsubscribeOnline = undefined\n }\n\n /**\n * Returns the number of queries in the cache that are currently fetching, optionally\n * matching a set of filters. This includes background-fetching, loading new pages, and\n * loading more infinite query results.\n * @param filters - Narrows down which fetching queries are counted. Without filters, every\n * fetching query is counted.\n * @returns The number of matching queries whose `fetchStatus` is `'fetching'`.\n * @example\n * ```ts\n * if (queryClient.isFetching()) {\n * console.log('At least one query is fetching!')\n * }\n * ```\n */\n isFetching(filters?: Omit<QueryFilters, 'fetchStatus'>): number {\n return this.#queryCache.findAll({ ...filters, fetchStatus: 'fetching' })\n .length\n }\n\n /**\n * Returns the number of mutations in the cache that are currently pending, optionally\n * matching a set of filters.\n * @param filters - Narrows down which pending mutations are counted. Without filters, every\n * pending mutation is counted.\n * @returns The number of matching mutations whose `status` is `'pending'`.\n * @example\n * ```ts\n * if (queryClient.isMutating()) {\n * console.log('At least one mutation is pending!')\n * }\n * ```\n */\n isMutating<\n TMutationFilters extends MutationFilters<any, any> = MutationFilters<\n any,\n any\n >,\n >(filters?: NoInfer<Omit<TMutationFilters, 'status'>>): number {\n return this.#mutationCache.findAll({ ...filters, status: 'pending' }).length\n }\n\n /**\n * Imperative (non-reactive) way to retrieve data for a QueryKey.\n * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.\n *\n * Hint: Do not use this function inside a component, because it won't receive updates.\n * Use `useQuery` to create a `QueryObserver` that subscribes to changes.\n * @param queryKey - The query key of the query to read.\n * @returns The cached data for the query, or `undefined` if no query with this key has been observed yet.\n * @see {@link QueryClient#getQueriesData}\n */\n getQueryData<\n TQueryFnData = unknown,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n >(queryKey: TTaggedQueryKey): TInferredQueryFnData | undefined {\n const options = this.defaultQueryOptions({ queryKey })\n\n return this.#queryCache.get<TInferredQueryFnData>(options.queryHash)?.state\n .data\n }\n\n /**\n * Returns the cached data of a query, or fetches it if there is none. With `revalidateIfStale`,\n * stale cached data is also refetched in the background.\n * @param options - The query options. If the query has no cached data yet, it is fetched with\n * these options.\n * @returns A promise that resolves to the cached data, or to the fetched data if nothing was\n * cached yet.\n * @deprecated Use queryClient.query({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.\n */\n ensureQueryData<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: EnsureQueryDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n const query = this.#queryCache.build(this, defaultedOptions)\n const cachedData = query.state.data\n\n if (cachedData === undefined) {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchQuery(options)\n }\n\n if (\n options.revalidateIfStale &&\n query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query))\n ) {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n void this.prefetchQuery(defaultedOptions)\n }\n\n return Promise.resolve(cachedData)\n }\n\n /**\n * Imperative (non-reactive) way to retrieve the cached data of multiple queries at once.\n * Only queries matching the given filters are returned; if none match, an empty array is\n * returned.\n *\n * Because the matched queries can hold data of different shapes (e.g. a broad filter can match\n * queries with unrelated data types), the `TQueryFnData` generic defaults to `unknown` rather\n * than being inferred. Passing a more specific type is a convenience for call sites that know\n * every matched query holds the same shape — it is not checked against the actual cache\n * contents.\n * @param filters - The filters that select which queries to read.\n * @returns An array of query key and data pairs. The data is `undefined` for a query with no cached data.\n * @see {@link QueryClient#getQueryData}\n * @example\n * ```ts\n * const data = queryClient.getQueriesData({ queryKey: ['posts'] })\n * ```\n */\n getQueriesData<\n TQueryFnData = unknown,\n TQueryFilters extends QueryFilters<any> = QueryFilters,\n >(filters: TQueryFilters): Array<[QueryKey, TQueryFnData | undefined]> {\n return this.#queryCache.findAll(filters).map(({ queryKey, state }) => {\n const data = state.data as TQueryFnData | undefined\n return [queryKey, data]\n })\n }\n\n /**\n * Synchronous way to immediately update a query's cached data. If the updater (or the value\n * passed) resolves to `undefined`, the cache is left untouched and no query is created;\n * otherwise, if the query does not exist yet, it will be created. To update multiple queries\n * at once by partially matching query keys, use {@link QueryClient#setQueriesData} instead.\n *\n * Updates must be performed immutably: do not mutate `oldData`, or data previously retrieved\n * via {@link QueryClient#getQueryData}, in place.\n * @param queryKey - The query key to set data for.\n * @param updater - Either the new data, or a function that receives the current data (which\n * may be `undefined`) and returns the new data.\n * @param options - Set `updatedAt` to override the timestamp the written data is recorded with.\n * @returns The data that was written, or `undefined` if the updater returned `undefined` — in that case\n * the write is skipped and the cache is left unchanged.\n * @example\n * ```ts\n * queryClient.setQueryData(['posts'], newPosts)\n *\n * // Or, using an updater function that receives the current data:\n * queryClient.setQueryData(['posts'], (oldPosts) => [...oldPosts, newPost])\n * ```\n */\n setQueryData<\n TQueryFnData = unknown,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n >(\n queryKey: TTaggedQueryKey,\n updater: Updater<\n InferDataFromTag<NoInfer<TQueryFnData>, TTaggedQueryKey> | undefined,\n NoInfer<TInferredQueryFnData> | undefined\n >,\n options?: SetDataOptions,\n ): NoInfer<TInferredQueryFnData> | undefined {\n const defaultedOptions = this.defaultQueryOptions<\n any,\n any,\n unknown,\n any,\n QueryKey\n >({ queryKey })\n\n const query = this.#queryCache.get<\n InferDataFromTag<NoInfer<TQueryFnData>, TTaggedQueryKey>\n >(defaultedOptions.queryHash)\n const prevData = query?.state.data\n const data = functionalUpdate(updater, prevData)\n\n if (data === undefined) {\n return undefined\n }\n\n return this.#queryCache\n .build(this, defaultedOptions)\n .setData(data, { ...options, manual: true })\n }\n\n /**\n * Synchronous way to immediately update the cached data of multiple queries at once, using\n * filters or partial query key matching. Only queries that already exist and match the given\n * filters are updated; no new cache entries are created. Internally this calls\n * {@link QueryClient#setQueryData} for each matching query.\n * @param filters - The filters that select which existing queries to update.\n * @param updater - Either the new data, or a function that receives each matched query's current\n * data (which may be `undefined`) and returns the new data.\n * @param options - Set `updatedAt` to override the timestamp the written data is recorded with.\n * @returns One `[queryKey, data]` tuple per matched query, in the same shape and with the same\n * `undefined` case as {@link QueryClient#setQueryData}.\n * @example\n * ```ts\n * queryClient.setQueriesData({ queryKey: ['posts'] }, (oldPosts) =>\n * oldPosts ? oldPosts.filter((post) => post.id !== deletedId) : oldPosts,\n * )\n * ```\n */\n setQueriesData<\n TQueryFnData,\n TQueryFilters extends QueryFilters<any> = QueryFilters,\n >(\n filters: TQueryFilters,\n updater: Updater<\n NoInfer<TQueryFnData> | undefined,\n NoInfer<TQueryFnData> | undefined\n >,\n options?: SetDataOptions,\n ): Array<[QueryKey, TQueryFnData | undefined]> {\n return notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .map(({ queryKey }) => [\n queryKey,\n this.setQueryData<TQueryFnData>(queryKey, updater, options),\n ]),\n )\n }\n\n /**\n * Imperative (non-reactive) way to retrieve an existing query's state. If the query does not\n * exist, `undefined` is returned.\n * @param queryKey - The query key of the query to read.\n * @returns The query's state, or `undefined` if no query with this key exists.\n * @example\n * ```ts\n * const state = queryClient.getQueryState(['posts'])\n * console.log(state?.dataUpdatedAt)\n * ```\n */\n getQueryState<\n TQueryFnData = unknown,\n TError = DefaultError,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n TInferredError = InferErrorFromTag<TError, TTaggedQueryKey>,\n >(\n queryKey: TTaggedQueryKey,\n ): QueryState<TInferredQueryFnData, TInferredError> | undefined {\n const options = this.defaultQueryOptions({ queryKey })\n return this.#queryCache.get<TInferredQueryFnData, TInferredError>(\n options.queryHash,\n )?.state\n }\n\n /**\n * Removes queries from the cache that match the given filters. Unlike\n * {@link QueryClient#invalidateQueries} or {@link QueryClient#refetchQueries}, this removes\n * matching queries from the cache instead of refetching them. Without filters, every query in\n * the cache is removed.\n * @param filters - The filters that select which queries to remove. Without filters, every query\n * is removed.\n * @example\n * ```ts\n * queryClient.removeQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n removeQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n ): void {\n const queryCache = this.#queryCache\n notifyManager.batch(() => {\n queryCache.findAll(filters).forEach((query) => {\n queryCache.remove(query)\n })\n })\n }\n\n /**\n * Resets queries matching the given filters back to their initial state (e.g. any\n * `initialData`), notifying subscribers rather than removing them. Active queries among the\n * matched set are then refetched, and the returned promise resolves once that refetch settles.\n * @param filters - The filters that select which queries to reset. Without filters, every query\n * is reset.\n * @param options - Passed to the refetch of the active matched queries, e.g. `cancelRefetch` and\n * `throwOnError`.\n * @returns A promise that resolves once the refetch of the active matched queries settles.\n * @example\n * ```ts\n * await queryClient.resetQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n resetQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n options?: ResetOptions,\n ): Promise<void> {\n const queryCache = this.#queryCache\n\n return notifyManager.batch(() => {\n const matched = queryCache.findAll(filters)\n const queriesToRefetch = new Set(matched)\n matched.forEach((query) => {\n query.reset()\n })\n return this.refetchQueries(\n {\n type: 'active',\n predicate: (query) => queriesToRefetch.has(query),\n },\n options,\n )\n })\n }\n\n /**\n * Cancels outgoing fetches for queries matching the given filters. Most useful when performing\n * optimistic updates, since any outgoing refetch that resolves afterwards would otherwise\n * overwrite the optimistic update. By default (`revert: true`), a cancelled query's data is\n * reverted to its state before the outgoing fetch started.\n *\n * The returned promise never rejects, even if individual cancellations fail.\n * @param filters - The filters that select which queries to cancel. Without filters, every query\n * is cancelled.\n * @param cancelOptions - Passed to each matched query's cancellation. `revert` defaults to\n * `true`.\n * @returns A promise that resolves once every cancellation has settled.\n * @example\n * ```ts\n * await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n cancelQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n cancelOptions: CancelOptions = {},\n ): Promise<void> {\n const defaultedCancelOptions = { revert: true, ...cancelOptions }\n\n const promises = notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .map((query) => query.cancel(defaultedCancelOptions)),\n )\n\n return Promise.all(promises).then(noop).catch(noop)\n }\n\n /**\n * Marks queries matching the given filters as invalidated. Unlike\n * {@link QueryClient#removeQueries}, invalidated queries stay in the cache.\n *\n * Unless `filters.refetchType` is `'none'`, matching queries are then refetched via\n * {@link QueryClient#refetchQueries}, using `filters.refetchType` if set, otherwise\n * `filters.type`, otherwise `'active'`.\n * @param filters - The filters that select which queries to invalidate, plus `refetchType` to\n * control which of them to refetch afterwards. Without filters, every query is invalidated.\n * @param options - Passed to {@link QueryClient#refetchQueries}, e.g. `cancelRefetch` and\n * `throwOnError`.\n * @returns A promise that resolves once the refetch settles, or immediately if `refetchType` is\n * `'none'`.\n * @example\n * ```ts\n * await queryClient.invalidateQueries({ queryKey: ['posts'], refetchType: 'active' })\n * ```\n */\n invalidateQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: InvalidateQueryFilters<TTaggedQueryKey>,\n options: InvalidateOptions = {},\n ): Promise<void> {\n return notifyManager.batch(() => {\n this.#queryCache.findAll(filters).forEach((query) => {\n query.invalidate()\n })\n\n if (filters?.refetchType === 'none') {\n return Promise.resolve()\n }\n return this.refetchQueries(\n {\n ...filters,\n type: filters?.refetchType ?? filters?.type ?? 'active',\n },\n options,\n )\n })\n }\n\n /**\n * Refetches queries matching the given filters, regardless of whether they are stale. Without\n * filters, every query in the cache is refetched. Queries that are disabled, or static (only\n * have observers with a static `staleTime`), are never refetched.\n *\n * By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new\n * one starts. The returned promise does not reject on individual query failures unless\n * `throwOnError` is `true`.\n *\n * Initially paused fetches do not delay the returned promise. Their later errors are handled\n * even when `throwOnError` is `true`.\n * @param filters - The filters that select which queries to refetch. Without filters, every query\n * in the cache is included.\n * @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling\n * it, and `throwOnError` to `true` to reject when a refetch that was not initially paused fails.\n * @returns A promise that resolves once all matching refetches that were not initially paused\n * have settled.\n * @example\n * ```ts\n * // refetch all active queries partially matching a query key:\n * await queryClient.refetchQueries({ queryKey: ['posts'], type: 'active' })\n * ```\n */\n refetchQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: RefetchQueryFilters<TTaggedQueryKey>,\n options: RefetchOptions = {},\n ): Promise<void> {\n const fetchOptions = {\n ...options,\n cancelRefetch: options.cancelRefetch ?? true,\n }\n const promises = notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .filter((query) => !query.isDisabled() && !query.isStatic())\n .map((query) => {\n let promise = query.fetch(undefined, fetchOptions)\n const isPaused = query.state.fetchStatus === 'paused'\n if (!fetchOptions.throwOnError || isPaused) {\n promise = promise.catch(noop)\n }\n return isPaused ? Promise.resolve() : promise\n }),\n )\n\n return Promise.all(promises).then(noop)\n }\n\n /**\n * Asynchronous method to fetch and cache a query, resolving with the data or throwing with\n * the error.\n *\n * If the query already exists in the cache and its data is not stale (per the given\n * `staleTime`), the cached data is returned without fetching. Otherwise, the query is fetched\n * and the promise resolves once the fetch settles. If a `select` function is provided, it is\n * applied to the data in both cases (cached or freshly fetched) before it is returned.\n *\n * Unlike a reactive observer, retries are disabled by default here (`retry: false`) unless\n * explicitly configured, since there is no component to catch a thrown error and retry through\n * re-render.\n *\n * The accepted options are `QueryObserverOptions` minus the fields that only make sense for a\n * reactive observer — `enabled`, `refetchInterval`, `refetchIntervalInBackground`,\n * `refetchOnWindowFocus`, `refetchOnReconnect`, `refetchOnMount`, `retryOnMount`,\n * `notifyOnChangeProps`, `throwOnError`, `suspense`, and `placeholderData` are not part of this\n * method's options.\n *\n * This method replaces the deprecated `fetchQuery`, and — combined with\n * `{ staleTime: 'static' }` — the deprecated `ensureQueryData`.\n * @param options - The query options, including the `queryKey` and the `queryFn` used if the\n * query needs to fetch.\n * @returns A promise that resolves to the data, or to the result of `select` if provided. It\n * rejects with the error from the fetch or from `select`.\n * @example\n * ```ts\n * try {\n * const data = await queryClient.query({ queryKey, queryFn, staleTime: 10000 })\n * } catch (error) {\n * console.log(error)\n * }\n * ```\n */\n async query<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options: QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n\n // https://github.com/tannerlinsley/react-query/issues/652\n if (defaultedOptions.retry === undefined) {\n defaultedOptions.retry = false\n }\n\n const query = this.#queryCache.build(this, defaultedOptions)\n\n const isStale = query.isStaleByTime(\n resolveQueryValue(defaultedOptions.staleTime, query),\n )\n\n const queryData = isStale\n ? await query.fetch(defaultedOptions)\n : (query.state.data as TQueryData)\n\n const select = defaultedOptions.select\n\n if (select) {\n return select(queryData)\n }\n\n return queryData as unknown as TData\n }\n\n /**\n * Fetches and caches a query, or returns its cached data if it isn't stale. Unlike in observers,\n * the fetch isn't retried unless `retry` is set.\n * @param options - The query options, including the `queryKey` and the `queryFn` used if the\n * query needs to fetch.\n * @returns A promise that resolves to the cached or fetched data, or rejects with the fetch\n * error.\n * @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.\n */\n fetchQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options: FetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n\n // https://github.com/tannerlinsley/react-query/issues/652\n if (defaultedOptions.retry === undefined) {\n defaultedOptions.retry = false\n }\n\n const query = this.#queryCache.build(this, defaultedOptions)\n\n return query.isStaleByTime(\n resolveQueryValue(defaultedOptions.staleTime, query),\n )\n ? query.fetch(defaultedOptions)\n : Promise.resolve(query.state.data as TData)\n }\n\n /**\n * Fetches and caches a query like {@link QueryClient#fetchQuery}, but ignores the result and any\n * error.\n * @param options - The query options, including the `queryKey` and the `queryFn` used if the\n * query needs to fetch.\n * @returns A promise that resolves once the fetch settles. It never rejects.\n * @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.\n */\n prefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): Promise<void> {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchQuery(options).then(noop).catch(noop)\n }\n\n /**\n * Asynchronous method to fetch and cache an infinite query, resolving with an\n * {@link InfiniteData} object or throwing with the error.\n *\n * Behaves like {@link QueryClient#query}, accepting the same options (minus\n * `initialPageParam`), plus the required `initialPageParam`, and an optional `pages` /\n * `getNextPageParam` pair used to refetch a fixed number of pages from the start.\n *\n * This method replaces the deprecated `fetchInfiniteQuery`, and — combined with\n * `{ staleTime: 'static' }` — the deprecated `ensureInfiniteQueryData`.\n * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the\n * `initialPageParam`.\n * @returns A promise that resolves to the {@link InfiniteData}, or to the result of `select` if\n * provided. It rejects with the error from the fetch or from `select`.\n * @example\n * ```ts\n * try {\n * const data = await queryClient.infiniteQuery({ queryKey, queryFn, initialPageParam: 0 })\n * console.log(data.pages)\n * } catch (error) {\n * console.log(error)\n * }\n * ```\n */\n infiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<\n Array<TData> extends Array<InfiniteData<TQueryFnData>>\n ? InfiniteData<TQueryFnData, TPageParam>\n : TData\n > {\n options._type = 'infinite'\n return this.query(options as any)\n }\n\n /**\n * Fetches and caches an infinite query, or returns its cached data if it isn't stale.\n * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the\n * `initialPageParam`.\n * @returns A promise that resolves to the cached or fetched {@link InfiniteData}, or rejects with\n * the fetch error.\n * @deprecated Use queryClient.infiniteQuery(options) instead. This method will be removed in the next major version.\n */\n fetchInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: FetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<InfiniteData<TData, TPageParam>> {\n options._type = 'infinite'\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchQuery(options as any)\n }\n\n /**\n * Fetches and caches an infinite query like {@link QueryClient#fetchInfiniteQuery}, but ignores\n * the result and any error.\n * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the\n * `initialPageParam`.\n * @returns A promise that resolves once the fetch settles. It never rejects.\n * @deprecated Use queryClient.infiniteQuery(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.\n */\n prefetchInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: FetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<void> {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchInfiniteQuery(options).then(noop).catch(noop)\n }\n\n /**\n * Returns the cached data of an infinite query, or fetches it if there is none. With\n * `revalidateIfStale`, stale cached data is also refetched in the background.\n * @param options - The infinite query options. If the query has no cached data yet, it is fetched\n * with these options.\n * @returns A promise that resolves to the cached {@link InfiniteData}, or to the fetched data if\n * nothing was cached yet.\n * @deprecated Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.\n */\n ensureInfiniteQueryData<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: EnsureInfiniteQueryDataOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<InfiniteData<TData, TPageParam>> {\n options._type = 'infinite'\n\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.ensureQueryData(options as any)\n }\n\n /**\n * Resumes mutations that were paused because there was no network connection. Does nothing\n * (resolving immediately) if the client is currently offline.\n * @returns A promise that resolves once the resumed mutations have settled.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * await queryClient.resumePausedMutations()\n * ```\n */\n resumePausedMutations(): Promise<unknown> {\n if (onlineManager.isOnline()) {\n return this.#mutationCache.resumePausedMutations()\n }\n return Promise.resolve()\n }\n\n /**\n * Returns the query cache this client is connected to.\n * @returns The {@link QueryCache} instance.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const queryCache = queryClient.getQueryCache()\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n getQueryCache(): QueryCache {\n return this.#queryCache\n }\n\n /**\n * Returns the mutation cache this client is connected to.\n * @returns The {@link MutationCache} instance.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const mutationCache = queryClient.getMutationCache()\n * const mutations = mutationCache.findAll({ status: 'pending' })\n * ```\n */\n getMutationCache(): MutationCache {\n return this.#mutationCache\n }\n\n /**\n * Returns the default options that were set when creating the client, or via\n * {@link QueryClient#setDefaultOptions}.\n * @returns The client's current default options.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const defaultOptions = queryClient.getDefaultOptions()\n * ```\n */\n getDefaultOptions(): DefaultOptions {\n return this.#defaultOptions\n }\n\n /**\n * Dynamically sets the default options for this client, overwriting any previously defined\n * default options.\n * @param options - The new default options for queries and mutations.\n * @see {@link QueryClient#getDefaultOptions}\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * queryClient.setDefaultOptions({\n * queries: {\n * staleTime: Infinity,\n * },\n * })\n * ```\n */\n setDefaultOptions(options: DefaultOptions): void {\n this.#defaultOptions = options\n }\n\n /**\n * Sets default options for queries whose query key partially matches the given `queryKey`.\n *\n * If several registered query defaults match a given query key, they are merged together in\n * registration order by {@link QueryClient#getQueryDefaults}, so register defaults from the\n * most generic key to the least generic one — more specific defaults should be registered\n * after more generic ones so they take precedence.\n * @param queryKey - The query key that query keys are partially matched against.\n * @param options - The default options applied to matching queries.\n * @example\n * ```ts\n * queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts })\n *\n * await queryClient.query({ queryKey: ['posts'] })\n * ```\n */\n setQueryDefaults<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n >(\n queryKey: QueryKey,\n options: Partial<\n OmitKeyof<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData>,\n 'queryKey'\n >\n >,\n ): void {\n this.#queryDefaults.set(hashKey(queryKey), {\n queryKey,\n defaultOptions: options,\n })\n }\n\n /**\n * Returns the default options registered for queries whose query key partially matches the\n * given `queryKey`, via {@link QueryClient#setQueryDefaults}. If multiple registered defaults\n * match, they are merged together in registration order.\n * @param queryKey - The query key to look up registered defaults for.\n * @returns The merged default options of every registration that matches, or an empty object if\n * none match.\n * @example\n * ```ts\n * const defaultOptions = queryClient.getQueryDefaults(['posts'])\n * ```\n */\n getQueryDefaults(\n queryKey: QueryKey,\n ): OmitKeyof<QueryObserverOptions<any, any, any, any, any>, 'queryKey'> {\n const defaults = [...this.#queryDefaults.values()]\n\n const result: OmitKeyof<\n QueryObserverOptions<any, any, any, any, any>,\n 'queryKey'\n > = {}\n\n defaults.forEach((queryDefault) => {\n if (partialMatchKey(queryKey, queryDefault.queryKey)) {\n Object.assign(result, queryDefault.defaultOptions)\n }\n })\n return result\n }\n\n /**\n * Sets default options for mutations whose mutation key partially matches the given\n * `mutationKey`. As with {@link QueryClient#setQueryDefaults}, the order of registration\n * matters when several registered defaults match the same mutation key.\n * @param mutationKey - The mutation key that mutation keys are partially matched against.\n * @param options - The default options applied to matching mutations.\n * @see {@link QueryClient#getMutationDefaults}\n * @example\n * ```ts\n * queryClient.setMutationDefaults(['addPost'], { mutationFn: addPost })\n * ```\n */\n setMutationDefaults<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n >(\n mutationKey: MutationKey,\n options: OmitKeyof<\n MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n ): void {\n this.#mutationDefaults.set(hashKey(mutationKey), {\n mutationKey,\n defaultOptions: options,\n })\n }\n\n /**\n * Returns the default options registered for mutations whose mutation key partially matches\n * the given `mutationKey`, via {@link QueryClient#setMutationDefaults}. If multiple registered\n * defaults match, they are merged together in registration order.\n * @param mutationKey - The mutation key to look up registered defaults for.\n * @returns The merged default options of every registration that matches, or an empty object if\n * none match.\n * @example\n * ```ts\n * const defaultOptions = queryClient.getMutationDefaults(['addPost'])\n * ```\n */\n getMutationDefaults(\n mutationKey: MutationKey,\n ): OmitKeyof<MutationObserverOptions<any, any, any, any>, 'mutationKey'> {\n const defaults = [...this.#mutationDefaults.values()]\n\n const result: OmitKeyof<\n MutationObserverOptions<any, any, any, any>,\n 'mutationKey'\n > = {}\n\n defaults.forEach((queryDefault) => {\n if (partialMatchKey(mutationKey, queryDefault.mutationKey)) {\n Object.assign(result, queryDefault.defaultOptions)\n }\n })\n\n return result\n }\n\n /**\n * Called by framework adapters (e.g. inside `useQuery`) to resolve the options passed by the\n * caller into their final, defaulted form: merging the client's own `defaultOptions.queries`,\n * then `queryClient.setQueryDefaults` for the given `queryKey`, then the caller's options on\n * top. A no-op if the options are already defaulted (`_defaulted: true`).\n * @param options - The query options passed by the caller.\n * @returns The defaulted options, with `queryHash` and dependent defaults (e.g.\n * `refetchOnReconnect`) filled in.\n */\n defaultQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options:\n | QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n | DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > {\n if (options._defaulted) {\n return options as DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n }\n\n const defaultedOptions = {\n ...this.#defaultOptions.queries,\n ...this.getQueryDefaults(options.queryKey),\n ...options,\n _defaulted: true,\n }\n\n if (!defaultedOptions.queryHash) {\n defaultedOptions.queryHash = hashQueryKeyByOptions(\n defaultedOptions.queryKey,\n defaultedOptions,\n )\n }\n\n // dependent default values\n if (defaultedOptions.refetchOnReconnect === undefined) {\n defaultedOptions.refetchOnReconnect =\n defaultedOptions.networkMode !== 'always'\n }\n if (defaultedOptions.throwOnError === undefined) {\n defaultedOptions.throwOnError = !!defaultedOptions.suspense\n }\n\n if (!defaultedOptions.networkMode && defaultedOptions.persister) {\n defaultedOptions.networkMode = 'offlineFirst'\n }\n\n if (defaultedOptions.queryFn === skipToken) {\n defaultedOptions.enabled = false\n }\n\n return defaultedOptions as DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n }\n\n /**\n * The mutation counterpart of {@link QueryClient#defaultQueryOptions}. Called by framework\n * adapters (e.g. inside `useMutation`) to merge the client's `defaultOptions.mutations`, then\n * `queryClient.setMutationDefaults` for the given `mutationKey`, then the caller's options on\n * top. A no-op if the options are already defaulted (`_defaulted: true`).\n * @param options - The mutation options passed by the caller.\n * @returns The defaulted options.\n */\n defaultMutationOptions<T extends MutationOptions<any, any, any, any>>(\n options?: T,\n ): T {\n if (options?._defaulted) {\n return options\n }\n return {\n ...this.#defaultOptions.mutations,\n ...(options?.mutationKey &&\n this.getMutationDefaults(options.mutationKey)),\n ...options,\n _defaulted: true,\n } as T\n }\n\n /**\n * Clears both the query cache and the mutation cache this client is connected to.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * queryClient.clear()\n * ```\n */\n clear(): void {\n this.#queryCache.clear()\n this.#mutationCache.clear()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,IAAa,cAAb,MAAyB;CAUvB,YAAY,SAA4B,CAAC,GAAG;;;;;;;;;EAC1C,8BAAA,uBAAA,aAAA,MAAmB,OAAO,cAAc,IAAIA,mBAAAA,WAAW,CAAA;EACvD,8BAAA,uBAAA,gBAAA,MAAsB,OAAO,iBAAiB,IAAIC,sBAAAA,cAAc,CAAA;EAChE,8BAAA,uBAAA,iBAAA,MAAuB,OAAO,kBAAkB,CAAC,CAAA;EACjD,8BAAA,uBAAA,gBAAA,sBAAsB,IAAI,IAAI,CAAA;EAC9B,8BAAA,uBAAA,mBAAA,sBAAyB,IAAI,IAAI,CAAA;EACjC,8BAAA,uBAAA,aAAA,MAAmB,CAAA;CACrB;;;;;;;CAQA,QAAc;;EACZ,8BAAA,uBAAA,aAAA,OAAA,mBAAA,8BAAA,uBAAA,aAAA,IAAA,GAAA,oBAAA,iBAAA;EACA,IAAA,8BAAA,uBAAA,aAAI,IAAA,MAAqB,GAAG;EAE5B,8BAAA,uBAAA,mBAAA,MAAyBC,qBAAAA,aAAa,UAAU,OAAO,YAAY;GACjE,IAAI,SAAS;IACX,MAAM,KAAK,sBAAsB;IACjC,8BAAA,uBAAA,aAAA,IAAA,CAAA,CAAiB,QAAQ;GAC3B;EACF,CAAC,CAAA;EACD,8BAAA,uBAAA,oBAAA,MAA0BC,sBAAAA,cAAc,UAAU,OAAO,WAAW;GAClE,I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;GACvB,GAAA,8BAAA,uBAAA,iBAAG,IAAA,CAAA,CAAqB;GACxB,GAAG,KAAK,iBAAiB,QAAQ,QAAQ;GACzC,GAAG;GACH,YAAY;EACd;EAEA,IAAI,CAAC,iBAAiB,WACpB,iBAAiB,YAAYC,cAAAA,sBAC3B,iBAAiB,UACjB,gBACF;EAIF,IAAI,iBAAiB,uBAAuB,KAAA,GAC1C,iBAAiB,qBACf,iBAAiB,gBAAgB;EAErC,IAAI,iBAAiB,iBAAiB,KAAA,GACpC,iBAAiB,eAAe,CAAC,CAAC,iBAAiB;EAGrD,IAAI,CAAC,iBAAiB,eAAe,iBAAiB,WACpD,iBAAiB,cAAc;EAGjC,IAAI,iBAAiB,YAAYC,cAAAA,WAC/B,iBAAiB,UAAU;EAG7B,OAAO;CAOT;;;;;;;;;CAUA,uBACE,SACG;EACH,IAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAI,QAAS,YACX,OAAO;EAET,OAAO;GACL,GAAA,8BAAA,uBAAA,iBAAG,IAAA,CAAA,CAAqB;GACxB,IAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAI,QAAS,gBACX,KAAK,oBAAoB,QAAQ,WAAW;GAC9C,GAAG;GACH,YAAY;EACd;CACF;;;;;;;;;;;CAYA,QAAc;EACZ,8BAAA,uBAAA,aAAA,IAAA,CAAA,CAAiB,MAAM;EACvB,8BAAA,uBAAA,gBAAA,IAAA,CAAA,CAAoB,MAAM;CAC5B;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { on as QueryClient } from "./hydration-
|
|
1
|
+
import { on as QueryClient } from "./hydration-BXjqUj_D.cjs";
|
|
2
2
|
export { QueryClient };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { on as QueryClient } from "./hydration-
|
|
1
|
+
import { on as QueryClient } from "./hydration-vgIjIhk6.js";
|
|
2
2
|
export { QueryClient };
|
|
@@ -358,13 +358,17 @@ var QueryClient = class {
|
|
|
358
358
|
* have observers with a static `staleTime`), are never refetched.
|
|
359
359
|
*
|
|
360
360
|
* By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new
|
|
361
|
-
* one starts. The returned promise
|
|
362
|
-
*
|
|
361
|
+
* one starts. The returned promise does not reject on individual query failures unless
|
|
362
|
+
* `throwOnError` is `true`.
|
|
363
|
+
*
|
|
364
|
+
* Initially paused fetches do not delay the returned promise. Their later errors are handled
|
|
365
|
+
* even when `throwOnError` is `true`.
|
|
363
366
|
* @param filters - The filters that select which queries to refetch. Without filters, every query
|
|
364
367
|
* in the cache is included.
|
|
365
368
|
* @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling
|
|
366
|
-
* it, and `throwOnError` to `true` to reject when a refetch fails.
|
|
367
|
-
* @returns A promise that resolves once
|
|
369
|
+
* it, and `throwOnError` to `true` to reject when a refetch that was not initially paused fails.
|
|
370
|
+
* @returns A promise that resolves once all matching refetches that were not initially paused
|
|
371
|
+
* have settled.
|
|
368
372
|
* @example
|
|
369
373
|
* ```ts
|
|
370
374
|
* // refetch all active queries partially matching a query key:
|
|
@@ -378,8 +382,9 @@ var QueryClient = class {
|
|
|
378
382
|
};
|
|
379
383
|
const promises = notifyManager.batch(() => _classPrivateFieldGet2(_queryCache, this).findAll(filters).filter((query) => !query.isDisabled() && !query.isStatic()).map((query) => {
|
|
380
384
|
let promise = query.fetch(void 0, fetchOptions);
|
|
381
|
-
|
|
382
|
-
|
|
385
|
+
const isPaused = query.state.fetchStatus === "paused";
|
|
386
|
+
if (!fetchOptions.throwOnError || isPaused) promise = promise.catch(noop);
|
|
387
|
+
return isPaused ? Promise.resolve() : promise;
|
|
383
388
|
}));
|
|
384
389
|
return Promise.all(promises).then(noop);
|
|
385
390
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryClient.js","names":[],"sources":["../../src/queryClient.ts"],"sourcesContent":["import {\n functionalUpdate,\n hashKey,\n hashQueryKeyByOptions,\n noop,\n partialMatchKey,\n resolveQueryValue,\n skipToken,\n} from './utils'\nimport { QueryCache } from './queryCache'\nimport { MutationCache } from './mutationCache'\nimport { focusManager } from './focusManager'\nimport { onlineManager } from './onlineManager'\nimport { notifyManager } from './notifyManager'\nimport type {\n CancelOptions,\n DefaultError,\n DefaultOptions,\n DefaultedQueryObserverOptions,\n EnsureInfiniteQueryDataOptions,\n EnsureQueryDataOptions,\n FetchInfiniteQueryOptions,\n FetchQueryOptions,\n InferDataFromTag,\n InferErrorFromTag,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n InvalidateOptions,\n InvalidateQueryFilters,\n MutationKey,\n MutationObserverOptions,\n MutationOptions,\n OmitKeyof,\n QueryClientConfig,\n QueryExecuteOptions,\n QueryKey,\n QueryObserverOptions,\n QueryOptions,\n RefetchOptions,\n RefetchQueryFilters,\n ResetOptions,\n SetDataOptions,\n} from './types'\nimport type { QueryState } from './query'\nimport type { MutationFilters, QueryFilters, Updater } from './utils'\n\n// TYPES\n\ninterface QueryDefaults {\n queryKey: QueryKey\n defaultOptions: OmitKeyof<QueryOptions<any, any, any>, 'queryKey'>\n}\n\ninterface MutationDefaults {\n mutationKey: MutationKey\n defaultOptions: MutationOptions<any, any, any, any>\n}\n\n// CLASS\n\n/**\n * `QueryClient` is used to interact with a cache of queries and mutations. It owns a\n * `QueryCache` and a `MutationCache` (creating default ones if none are passed in) and holds\n * the default options that are applied to queries and mutations created through it.\n * @example\n * ```ts\n * const queryClient = new QueryClient({\n * defaultOptions: {\n * queries: {\n * staleTime: Infinity,\n * },\n * },\n * })\n *\n * await queryClient.query({ queryKey: ['posts'], queryFn: fetchPosts })\n * ```\n */\nexport class QueryClient {\n #queryCache: QueryCache\n #mutationCache: MutationCache\n #defaultOptions: DefaultOptions\n #queryDefaults: Map<string, QueryDefaults>\n #mutationDefaults: Map<string, MutationDefaults>\n #mountCount: number\n #unsubscribeFocus?: () => void\n #unsubscribeOnline?: () => void\n\n constructor(config: QueryClientConfig = {}) {\n this.#queryCache = config.queryCache || new QueryCache()\n this.#mutationCache = config.mutationCache || new MutationCache()\n this.#defaultOptions = config.defaultOptions || {}\n this.#queryDefaults = new Map()\n this.#mutationDefaults = new Map()\n this.#mountCount = 0\n }\n\n /**\n * Called by a framework adapter's `QueryClientProvider`-equivalent when it mounts, to start\n * listening for focus/online events and resume paused mutations. Ref-counted via an internal\n * mount count, so nested or multiple providers sharing the same `QueryClient` don't tear down\n * the shared listeners until the last one unmounts.\n */\n mount(): void {\n this.#mountCount++\n if (this.#mountCount !== 1) return\n\n this.#unsubscribeFocus = focusManager.subscribe(async (focused) => {\n if (focused) {\n await this.resumePausedMutations()\n this.#queryCache.onFocus()\n }\n })\n this.#unsubscribeOnline = onlineManager.subscribe(async (online) => {\n if (online) {\n await this.resumePausedMutations()\n this.#queryCache.onOnline()\n }\n })\n }\n\n /**\n * The inverse of {@link QueryClient#mount} — called by a framework adapter's\n * `QueryClientProvider`-equivalent when it unmounts. Only tears down the focus/online\n * listeners once the mount count returns to `0`.\n */\n unmount(): void {\n this.#mountCount--\n if (this.#mountCount !== 0) return\n\n this.#unsubscribeFocus?.()\n this.#unsubscribeFocus = undefined\n\n this.#unsubscribeOnline?.()\n this.#unsubscribeOnline = undefined\n }\n\n /**\n * Returns the number of queries in the cache that are currently fetching, optionally\n * matching a set of filters. This includes background-fetching, loading new pages, and\n * loading more infinite query results.\n * @param filters - Narrows down which fetching queries are counted. Without filters, every\n * fetching query is counted.\n * @returns The number of matching queries whose `fetchStatus` is `'fetching'`.\n * @example\n * ```ts\n * if (queryClient.isFetching()) {\n * console.log('At least one query is fetching!')\n * }\n * ```\n */\n isFetching(filters?: Omit<QueryFilters, 'fetchStatus'>): number {\n return this.#queryCache.findAll({ ...filters, fetchStatus: 'fetching' })\n .length\n }\n\n /**\n * Returns the number of mutations in the cache that are currently pending, optionally\n * matching a set of filters.\n * @param filters - Narrows down which pending mutations are counted. Without filters, every\n * pending mutation is counted.\n * @returns The number of matching mutations whose `status` is `'pending'`.\n * @example\n * ```ts\n * if (queryClient.isMutating()) {\n * console.log('At least one mutation is pending!')\n * }\n * ```\n */\n isMutating<\n TMutationFilters extends MutationFilters<any, any> = MutationFilters,\n >(filters?: TMutationFilters): number {\n return this.#mutationCache.findAll({ ...filters, status: 'pending' }).length\n }\n\n /**\n * Imperative (non-reactive) way to retrieve data for a QueryKey.\n * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.\n *\n * Hint: Do not use this function inside a component, because it won't receive updates.\n * Use `useQuery` to create a `QueryObserver` that subscribes to changes.\n * @param queryKey - The query key of the query to read.\n * @returns The cached data for the query, or `undefined` if no query with this key has been observed yet.\n * @see {@link QueryClient#getQueriesData}\n */\n getQueryData<\n TQueryFnData = unknown,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n >(queryKey: TTaggedQueryKey): TInferredQueryFnData | undefined {\n const options = this.defaultQueryOptions({ queryKey })\n\n return this.#queryCache.get<TInferredQueryFnData>(options.queryHash)?.state\n .data\n }\n\n /**\n * Returns the cached data of a query, or fetches it if there is none. With `revalidateIfStale`,\n * stale cached data is also refetched in the background.\n * @param options - The query options. If the query has no cached data yet, it is fetched with\n * these options.\n * @returns A promise that resolves to the cached data, or to the fetched data if nothing was\n * cached yet.\n * @deprecated Use queryClient.query({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.\n */\n ensureQueryData<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: EnsureQueryDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n const query = this.#queryCache.build(this, defaultedOptions)\n const cachedData = query.state.data\n\n if (cachedData === undefined) {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchQuery(options)\n }\n\n if (\n options.revalidateIfStale &&\n query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query))\n ) {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n void this.prefetchQuery(defaultedOptions)\n }\n\n return Promise.resolve(cachedData)\n }\n\n /**\n * Imperative (non-reactive) way to retrieve the cached data of multiple queries at once.\n * Only queries matching the given filters are returned; if none match, an empty array is\n * returned.\n *\n * Because the matched queries can hold data of different shapes (e.g. a broad filter can match\n * queries with unrelated data types), the `TQueryFnData` generic defaults to `unknown` rather\n * than being inferred. Passing a more specific type is a convenience for call sites that know\n * every matched query holds the same shape — it is not checked against the actual cache\n * contents.\n * @param filters - The filters that select which queries to read.\n * @returns An array of query key and data pairs. The data is `undefined` for a query with no cached data.\n * @see {@link QueryClient#getQueryData}\n * @example\n * ```ts\n * const data = queryClient.getQueriesData({ queryKey: ['posts'] })\n * ```\n */\n getQueriesData<\n TQueryFnData = unknown,\n TQueryFilters extends QueryFilters<any> = QueryFilters,\n >(filters: TQueryFilters): Array<[QueryKey, TQueryFnData | undefined]> {\n return this.#queryCache.findAll(filters).map(({ queryKey, state }) => {\n const data = state.data as TQueryFnData | undefined\n return [queryKey, data]\n })\n }\n\n /**\n * Synchronous way to immediately update a query's cached data. If the updater (or the value\n * passed) resolves to `undefined`, the cache is left untouched and no query is created;\n * otherwise, if the query does not exist yet, it will be created. To update multiple queries\n * at once by partially matching query keys, use {@link QueryClient#setQueriesData} instead.\n *\n * Updates must be performed immutably: do not mutate `oldData`, or data previously retrieved\n * via {@link QueryClient#getQueryData}, in place.\n * @param queryKey - The query key to set data for.\n * @param updater - Either the new data, or a function that receives the current data (which\n * may be `undefined`) and returns the new data.\n * @param options - Set `updatedAt` to override the timestamp the written data is recorded with.\n * @returns The data that was written, or `undefined` if the updater returned `undefined` — in that case\n * the write is skipped and the cache is left unchanged.\n * @example\n * ```ts\n * queryClient.setQueryData(['posts'], newPosts)\n *\n * // Or, using an updater function that receives the current data:\n * queryClient.setQueryData(['posts'], (oldPosts) => [...oldPosts, newPost])\n * ```\n */\n setQueryData<\n TQueryFnData = unknown,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n >(\n queryKey: TTaggedQueryKey,\n updater: Updater<\n InferDataFromTag<NoInfer<TQueryFnData>, TTaggedQueryKey> | undefined,\n NoInfer<TInferredQueryFnData> | undefined\n >,\n options?: SetDataOptions,\n ): NoInfer<TInferredQueryFnData> | undefined {\n const defaultedOptions = this.defaultQueryOptions<\n any,\n any,\n unknown,\n any,\n QueryKey\n >({ queryKey })\n\n const query = this.#queryCache.get<\n InferDataFromTag<NoInfer<TQueryFnData>, TTaggedQueryKey>\n >(defaultedOptions.queryHash)\n const prevData = query?.state.data\n const data = functionalUpdate(updater, prevData)\n\n if (data === undefined) {\n return undefined\n }\n\n return this.#queryCache\n .build(this, defaultedOptions)\n .setData(data, { ...options, manual: true })\n }\n\n /**\n * Synchronous way to immediately update the cached data of multiple queries at once, using\n * filters or partial query key matching. Only queries that already exist and match the given\n * filters are updated; no new cache entries are created. Internally this calls\n * {@link QueryClient#setQueryData} for each matching query.\n * @param filters - The filters that select which existing queries to update.\n * @param updater - Either the new data, or a function that receives each matched query's current\n * data (which may be `undefined`) and returns the new data.\n * @param options - Set `updatedAt` to override the timestamp the written data is recorded with.\n * @returns One `[queryKey, data]` tuple per matched query, in the same shape and with the same\n * `undefined` case as {@link QueryClient#setQueryData}.\n * @example\n * ```ts\n * queryClient.setQueriesData({ queryKey: ['posts'] }, (oldPosts) =>\n * oldPosts ? oldPosts.filter((post) => post.id !== deletedId) : oldPosts,\n * )\n * ```\n */\n setQueriesData<\n TQueryFnData,\n TQueryFilters extends QueryFilters<any> = QueryFilters,\n >(\n filters: TQueryFilters,\n updater: Updater<\n NoInfer<TQueryFnData> | undefined,\n NoInfer<TQueryFnData> | undefined\n >,\n options?: SetDataOptions,\n ): Array<[QueryKey, TQueryFnData | undefined]> {\n return notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .map(({ queryKey }) => [\n queryKey,\n this.setQueryData<TQueryFnData>(queryKey, updater, options),\n ]),\n )\n }\n\n /**\n * Imperative (non-reactive) way to retrieve an existing query's state. If the query does not\n * exist, `undefined` is returned.\n * @param queryKey - The query key of the query to read.\n * @returns The query's state, or `undefined` if no query with this key exists.\n * @example\n * ```ts\n * const state = queryClient.getQueryState(['posts'])\n * console.log(state?.dataUpdatedAt)\n * ```\n */\n getQueryState<\n TQueryFnData = unknown,\n TError = DefaultError,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n TInferredError = InferErrorFromTag<TError, TTaggedQueryKey>,\n >(\n queryKey: TTaggedQueryKey,\n ): QueryState<TInferredQueryFnData, TInferredError> | undefined {\n const options = this.defaultQueryOptions({ queryKey })\n return this.#queryCache.get<TInferredQueryFnData, TInferredError>(\n options.queryHash,\n )?.state\n }\n\n /**\n * Removes queries from the cache that match the given filters. Unlike\n * {@link QueryClient#invalidateQueries} or {@link QueryClient#refetchQueries}, this removes\n * matching queries from the cache instead of refetching them. Without filters, every query in\n * the cache is removed.\n * @param filters - The filters that select which queries to remove. Without filters, every query\n * is removed.\n * @example\n * ```ts\n * queryClient.removeQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n removeQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n ): void {\n const queryCache = this.#queryCache\n notifyManager.batch(() => {\n queryCache.findAll(filters).forEach((query) => {\n queryCache.remove(query)\n })\n })\n }\n\n /**\n * Resets queries matching the given filters back to their initial state (e.g. any\n * `initialData`), notifying subscribers rather than removing them. Active queries among the\n * matched set are then refetched, and the returned promise resolves once that refetch settles.\n * @param filters - The filters that select which queries to reset. Without filters, every query\n * is reset.\n * @param options - Passed to the refetch of the active matched queries, e.g. `cancelRefetch` and\n * `throwOnError`.\n * @returns A promise that resolves once the refetch of the active matched queries settles.\n * @example\n * ```ts\n * await queryClient.resetQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n resetQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n options?: ResetOptions,\n ): Promise<void> {\n const queryCache = this.#queryCache\n\n return notifyManager.batch(() => {\n const matched = queryCache.findAll(filters)\n const queriesToRefetch = new Set(matched)\n matched.forEach((query) => {\n query.reset()\n })\n return this.refetchQueries(\n {\n type: 'active',\n predicate: (query) => queriesToRefetch.has(query),\n },\n options,\n )\n })\n }\n\n /**\n * Cancels outgoing fetches for queries matching the given filters. Most useful when performing\n * optimistic updates, since any outgoing refetch that resolves afterwards would otherwise\n * overwrite the optimistic update. By default (`revert: true`), a cancelled query's data is\n * reverted to its state before the outgoing fetch started.\n *\n * The returned promise never rejects, even if individual cancellations fail.\n * @param filters - The filters that select which queries to cancel. Without filters, every query\n * is cancelled.\n * @param cancelOptions - Passed to each matched query's cancellation. `revert` defaults to\n * `true`.\n * @returns A promise that resolves once every cancellation has settled.\n * @example\n * ```ts\n * await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n cancelQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n cancelOptions: CancelOptions = {},\n ): Promise<void> {\n const defaultedCancelOptions = { revert: true, ...cancelOptions }\n\n const promises = notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .map((query) => query.cancel(defaultedCancelOptions)),\n )\n\n return Promise.all(promises).then(noop).catch(noop)\n }\n\n /**\n * Marks queries matching the given filters as invalidated. Unlike\n * {@link QueryClient#removeQueries}, invalidated queries stay in the cache.\n *\n * Unless `filters.refetchType` is `'none'`, matching queries are then refetched via\n * {@link QueryClient#refetchQueries}, using `filters.refetchType` if set, otherwise\n * `filters.type`, otherwise `'active'`.\n * @param filters - The filters that select which queries to invalidate, plus `refetchType` to\n * control which of them to refetch afterwards. Without filters, every query is invalidated.\n * @param options - Passed to {@link QueryClient#refetchQueries}, e.g. `cancelRefetch` and\n * `throwOnError`.\n * @returns A promise that resolves once the refetch settles, or immediately if `refetchType` is\n * `'none'`.\n * @example\n * ```ts\n * await queryClient.invalidateQueries({ queryKey: ['posts'], refetchType: 'active' })\n * ```\n */\n invalidateQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: InvalidateQueryFilters<TTaggedQueryKey>,\n options: InvalidateOptions = {},\n ): Promise<void> {\n return notifyManager.batch(() => {\n this.#queryCache.findAll(filters).forEach((query) => {\n query.invalidate()\n })\n\n if (filters?.refetchType === 'none') {\n return Promise.resolve()\n }\n return this.refetchQueries(\n {\n ...filters,\n type: filters?.refetchType ?? filters?.type ?? 'active',\n },\n options,\n )\n })\n }\n\n /**\n * Refetches queries matching the given filters, regardless of whether they are stale. Without\n * filters, every query in the cache is refetched. Queries that are disabled, or static (only\n * have observers with a static `staleTime`), are never refetched.\n *\n * By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new\n * one starts. The returned promise resolves once all matching queries have settled; it does\n * not reject on individual query failures unless `throwOnError` is set.\n * @param filters - The filters that select which queries to refetch. Without filters, every query\n * in the cache is included.\n * @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling\n * it, and `throwOnError` to `true` to reject when a refetch fails.\n * @returns A promise that resolves once every matched query has settled.\n * @example\n * ```ts\n * // refetch all active queries partially matching a query key:\n * await queryClient.refetchQueries({ queryKey: ['posts'], type: 'active' })\n * ```\n */\n refetchQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: RefetchQueryFilters<TTaggedQueryKey>,\n options: RefetchOptions = {},\n ): Promise<void> {\n const fetchOptions = {\n ...options,\n cancelRefetch: options.cancelRefetch ?? true,\n }\n const promises = notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .filter((query) => !query.isDisabled() && !query.isStatic())\n .map((query) => {\n let promise = query.fetch(undefined, fetchOptions)\n if (!fetchOptions.throwOnError) {\n promise = promise.catch(noop)\n }\n return query.state.fetchStatus === 'paused'\n ? Promise.resolve()\n : promise\n }),\n )\n\n return Promise.all(promises).then(noop)\n }\n\n /**\n * Asynchronous method to fetch and cache a query, resolving with the data or throwing with\n * the error.\n *\n * If the query already exists in the cache and its data is not stale (per the given\n * `staleTime`), the cached data is returned without fetching. Otherwise, the query is fetched\n * and the promise resolves once the fetch settles. If a `select` function is provided, it is\n * applied to the data in both cases (cached or freshly fetched) before it is returned.\n *\n * Unlike a reactive observer, retries are disabled by default here (`retry: false`) unless\n * explicitly configured, since there is no component to catch a thrown error and retry through\n * re-render.\n *\n * The accepted options are `QueryObserverOptions` minus the fields that only make sense for a\n * reactive observer — `enabled`, `refetchInterval`, `refetchIntervalInBackground`,\n * `refetchOnWindowFocus`, `refetchOnReconnect`, `refetchOnMount`, `retryOnMount`,\n * `notifyOnChangeProps`, `throwOnError`, `suspense`, and `placeholderData` are not part of this\n * method's options.\n *\n * This method replaces the deprecated `fetchQuery`, and — combined with\n * `{ staleTime: 'static' }` — the deprecated `ensureQueryData`.\n * @param options - The query options, including the `queryKey` and the `queryFn` used if the\n * query needs to fetch.\n * @returns A promise that resolves to the data, or to the result of `select` if provided. It\n * rejects with the error from the fetch or from `select`.\n * @example\n * ```ts\n * try {\n * const data = await queryClient.query({ queryKey, queryFn, staleTime: 10000 })\n * } catch (error) {\n * console.log(error)\n * }\n * ```\n */\n async query<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options: QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n\n // https://github.com/tannerlinsley/react-query/issues/652\n if (defaultedOptions.retry === undefined) {\n defaultedOptions.retry = false\n }\n\n const query = this.#queryCache.build(this, defaultedOptions)\n\n const isStale = query.isStaleByTime(\n resolveQueryValue(defaultedOptions.staleTime, query),\n )\n\n const queryData = isStale\n ? await query.fetch(defaultedOptions)\n : (query.state.data as TQueryData)\n\n const select = defaultedOptions.select\n\n if (select) {\n return select(queryData)\n }\n\n return queryData as unknown as TData\n }\n\n /**\n * Fetches and caches a query, or returns its cached data if it isn't stale. Unlike in observers,\n * the fetch isn't retried unless `retry` is set.\n * @param options - The query options, including the `queryKey` and the `queryFn` used if the\n * query needs to fetch.\n * @returns A promise that resolves to the cached or fetched data, or rejects with the fetch\n * error.\n * @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.\n */\n fetchQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options: FetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n\n // https://github.com/tannerlinsley/react-query/issues/652\n if (defaultedOptions.retry === undefined) {\n defaultedOptions.retry = false\n }\n\n const query = this.#queryCache.build(this, defaultedOptions)\n\n return query.isStaleByTime(\n resolveQueryValue(defaultedOptions.staleTime, query),\n )\n ? query.fetch(defaultedOptions)\n : Promise.resolve(query.state.data as TData)\n }\n\n /**\n * Fetches and caches a query like {@link QueryClient#fetchQuery}, but ignores the result and any\n * error.\n * @param options - The query options, including the `queryKey` and the `queryFn` used if the\n * query needs to fetch.\n * @returns A promise that resolves once the fetch settles. It never rejects.\n * @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.\n */\n prefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): Promise<void> {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchQuery(options).then(noop).catch(noop)\n }\n\n /**\n * Asynchronous method to fetch and cache an infinite query, resolving with an\n * {@link InfiniteData} object or throwing with the error.\n *\n * Behaves like {@link QueryClient#query}, accepting the same options (minus\n * `initialPageParam`), plus the required `initialPageParam`, and an optional `pages` /\n * `getNextPageParam` pair used to refetch a fixed number of pages from the start.\n *\n * This method replaces the deprecated `fetchInfiniteQuery`, and — combined with\n * `{ staleTime: 'static' }` — the deprecated `ensureInfiniteQueryData`.\n * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the\n * `initialPageParam`.\n * @returns A promise that resolves to the {@link InfiniteData}, or to the result of `select` if\n * provided. It rejects with the error from the fetch or from `select`.\n * @example\n * ```ts\n * try {\n * const data = await queryClient.infiniteQuery({ queryKey, queryFn, initialPageParam: 0 })\n * console.log(data.pages)\n * } catch (error) {\n * console.log(error)\n * }\n * ```\n */\n infiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<\n Array<TData> extends Array<InfiniteData<TQueryFnData>>\n ? InfiniteData<TQueryFnData, TPageParam>\n : TData\n > {\n options._type = 'infinite'\n return this.query(options as any)\n }\n\n /**\n * Fetches and caches an infinite query, or returns its cached data if it isn't stale.\n * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the\n * `initialPageParam`.\n * @returns A promise that resolves to the cached or fetched {@link InfiniteData}, or rejects with\n * the fetch error.\n * @deprecated Use queryClient.infiniteQuery(options) instead. This method will be removed in the next major version.\n */\n fetchInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: FetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<InfiniteData<TData, TPageParam>> {\n options._type = 'infinite'\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchQuery(options as any)\n }\n\n /**\n * Fetches and caches an infinite query like {@link QueryClient#fetchInfiniteQuery}, but ignores\n * the result and any error.\n * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the\n * `initialPageParam`.\n * @returns A promise that resolves once the fetch settles. It never rejects.\n * @deprecated Use queryClient.infiniteQuery(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.\n */\n prefetchInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: FetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<void> {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchInfiniteQuery(options).then(noop).catch(noop)\n }\n\n /**\n * Returns the cached data of an infinite query, or fetches it if there is none. With\n * `revalidateIfStale`, stale cached data is also refetched in the background.\n * @param options - The infinite query options. If the query has no cached data yet, it is fetched\n * with these options.\n * @returns A promise that resolves to the cached {@link InfiniteData}, or to the fetched data if\n * nothing was cached yet.\n * @deprecated Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.\n */\n ensureInfiniteQueryData<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: EnsureInfiniteQueryDataOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<InfiniteData<TData, TPageParam>> {\n options._type = 'infinite'\n\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.ensureQueryData(options as any)\n }\n\n /**\n * Resumes mutations that were paused because there was no network connection. Does nothing\n * (resolving immediately) if the client is currently offline.\n * @returns A promise that resolves once the resumed mutations have settled.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * await queryClient.resumePausedMutations()\n * ```\n */\n resumePausedMutations(): Promise<unknown> {\n if (onlineManager.isOnline()) {\n return this.#mutationCache.resumePausedMutations()\n }\n return Promise.resolve()\n }\n\n /**\n * Returns the query cache this client is connected to.\n * @returns The {@link QueryCache} instance.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const queryCache = queryClient.getQueryCache()\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n getQueryCache(): QueryCache {\n return this.#queryCache\n }\n\n /**\n * Returns the mutation cache this client is connected to.\n * @returns The {@link MutationCache} instance.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const mutationCache = queryClient.getMutationCache()\n * const mutations = mutationCache.findAll({ status: 'pending' })\n * ```\n */\n getMutationCache(): MutationCache {\n return this.#mutationCache\n }\n\n /**\n * Returns the default options that were set when creating the client, or via\n * {@link QueryClient#setDefaultOptions}.\n * @returns The client's current default options.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const defaultOptions = queryClient.getDefaultOptions()\n * ```\n */\n getDefaultOptions(): DefaultOptions {\n return this.#defaultOptions\n }\n\n /**\n * Dynamically sets the default options for this client, overwriting any previously defined\n * default options.\n * @param options - The new default options for queries and mutations.\n * @see {@link QueryClient#getDefaultOptions}\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * queryClient.setDefaultOptions({\n * queries: {\n * staleTime: Infinity,\n * },\n * })\n * ```\n */\n setDefaultOptions(options: DefaultOptions): void {\n this.#defaultOptions = options\n }\n\n /**\n * Sets default options for queries whose query key partially matches the given `queryKey`.\n *\n * If several registered query defaults match a given query key, they are merged together in\n * registration order by {@link QueryClient#getQueryDefaults}, so register defaults from the\n * most generic key to the least generic one — more specific defaults should be registered\n * after more generic ones so they take precedence.\n * @param queryKey - The query key that query keys are partially matched against.\n * @param options - The default options applied to matching queries.\n * @example\n * ```ts\n * queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts })\n *\n * await queryClient.query({ queryKey: ['posts'] })\n * ```\n */\n setQueryDefaults<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n >(\n queryKey: QueryKey,\n options: Partial<\n OmitKeyof<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData>,\n 'queryKey'\n >\n >,\n ): void {\n this.#queryDefaults.set(hashKey(queryKey), {\n queryKey,\n defaultOptions: options,\n })\n }\n\n /**\n * Returns the default options registered for queries whose query key partially matches the\n * given `queryKey`, via {@link QueryClient#setQueryDefaults}. If multiple registered defaults\n * match, they are merged together in registration order.\n * @param queryKey - The query key to look up registered defaults for.\n * @returns The merged default options of every registration that matches, or an empty object if\n * none match.\n * @example\n * ```ts\n * const defaultOptions = queryClient.getQueryDefaults(['posts'])\n * ```\n */\n getQueryDefaults(\n queryKey: QueryKey,\n ): OmitKeyof<QueryObserverOptions<any, any, any, any, any>, 'queryKey'> {\n const defaults = [...this.#queryDefaults.values()]\n\n const result: OmitKeyof<\n QueryObserverOptions<any, any, any, any, any>,\n 'queryKey'\n > = {}\n\n defaults.forEach((queryDefault) => {\n if (partialMatchKey(queryKey, queryDefault.queryKey)) {\n Object.assign(result, queryDefault.defaultOptions)\n }\n })\n return result\n }\n\n /**\n * Sets default options for mutations whose mutation key partially matches the given\n * `mutationKey`. As with {@link QueryClient#setQueryDefaults}, the order of registration\n * matters when several registered defaults match the same mutation key.\n * @param mutationKey - The mutation key that mutation keys are partially matched against.\n * @param options - The default options applied to matching mutations.\n * @see {@link QueryClient#getMutationDefaults}\n * @example\n * ```ts\n * queryClient.setMutationDefaults(['addPost'], { mutationFn: addPost })\n * ```\n */\n setMutationDefaults<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n >(\n mutationKey: MutationKey,\n options: OmitKeyof<\n MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n ): void {\n this.#mutationDefaults.set(hashKey(mutationKey), {\n mutationKey,\n defaultOptions: options,\n })\n }\n\n /**\n * Returns the default options registered for mutations whose mutation key partially matches\n * the given `mutationKey`, via {@link QueryClient#setMutationDefaults}. If multiple registered\n * defaults match, they are merged together in registration order.\n * @param mutationKey - The mutation key to look up registered defaults for.\n * @returns The merged default options of every registration that matches, or an empty object if\n * none match.\n * @example\n * ```ts\n * const defaultOptions = queryClient.getMutationDefaults(['addPost'])\n * ```\n */\n getMutationDefaults(\n mutationKey: MutationKey,\n ): OmitKeyof<MutationObserverOptions<any, any, any, any>, 'mutationKey'> {\n const defaults = [...this.#mutationDefaults.values()]\n\n const result: OmitKeyof<\n MutationObserverOptions<any, any, any, any>,\n 'mutationKey'\n > = {}\n\n defaults.forEach((queryDefault) => {\n if (partialMatchKey(mutationKey, queryDefault.mutationKey)) {\n Object.assign(result, queryDefault.defaultOptions)\n }\n })\n\n return result\n }\n\n /**\n * Called by framework adapters (e.g. inside `useQuery`) to resolve the options passed by the\n * caller into their final, defaulted form: merging the client's own `defaultOptions.queries`,\n * then `queryClient.setQueryDefaults` for the given `queryKey`, then the caller's options on\n * top. A no-op if the options are already defaulted (`_defaulted: true`).\n * @param options - The query options passed by the caller.\n * @returns The defaulted options, with `queryHash` and dependent defaults (e.g.\n * `refetchOnReconnect`) filled in.\n */\n defaultQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options:\n | QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n | DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > {\n if (options._defaulted) {\n return options as DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n }\n\n const defaultedOptions = {\n ...this.#defaultOptions.queries,\n ...this.getQueryDefaults(options.queryKey),\n ...options,\n _defaulted: true,\n }\n\n if (!defaultedOptions.queryHash) {\n defaultedOptions.queryHash = hashQueryKeyByOptions(\n defaultedOptions.queryKey,\n defaultedOptions,\n )\n }\n\n // dependent default values\n if (defaultedOptions.refetchOnReconnect === undefined) {\n defaultedOptions.refetchOnReconnect =\n defaultedOptions.networkMode !== 'always'\n }\n if (defaultedOptions.throwOnError === undefined) {\n defaultedOptions.throwOnError = !!defaultedOptions.suspense\n }\n\n if (!defaultedOptions.networkMode && defaultedOptions.persister) {\n defaultedOptions.networkMode = 'offlineFirst'\n }\n\n if (defaultedOptions.queryFn === skipToken) {\n defaultedOptions.enabled = false\n }\n\n return defaultedOptions as DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n }\n\n /**\n * The mutation counterpart of {@link QueryClient#defaultQueryOptions}. Called by framework\n * adapters (e.g. inside `useMutation`) to merge the client's `defaultOptions.mutations`, then\n * `queryClient.setMutationDefaults` for the given `mutationKey`, then the caller's options on\n * top. A no-op if the options are already defaulted (`_defaulted: true`).\n * @param options - The mutation options passed by the caller.\n * @returns The defaulted options.\n */\n defaultMutationOptions<T extends MutationOptions<any, any, any, any>>(\n options?: T,\n ): T {\n if (options?._defaulted) {\n return options\n }\n return {\n ...this.#defaultOptions.mutations,\n ...(options?.mutationKey &&\n this.getMutationDefaults(options.mutationKey)),\n ...options,\n _defaulted: true,\n } as T\n }\n\n /**\n * Clears both the query cache and the mutation cache this client is connected to.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * queryClient.clear()\n * ```\n */\n clear(): void {\n this.#queryCache.clear()\n this.#mutationCache.clear()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,IAAa,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uB,OAAO,CAAC;EAEpD,MAAM,SAGF,CAAC;EAEL,SAAS,SAAS,iBAAiB;GACjC,IAAI,gBAAgB,aAAa,aAAa,WAAW,GACvD,OAAO,OAAO,QAAQ,aAAa,cAAc;EAErD,CAAC;EAED,OAAO;CACT;;;;;;;;;;CAWA,oBAQE,SAsBA;EACA,IAAI,QAAQ,YACV,OAAO;EAST,MAAM,mBAAmB;GACvB,GAAA,uBAAA,iBAAG,IAAA,CAAA,CAAqB;GACxB,GAAG,KAAK,iBAAiB,QAAQ,QAAQ;GACzC,GAAG;GACH,YAAY;EACd;EAEA,IAAI,CAAC,iBAAiB,WACpB,iBAAiB,YAAY,sBAC3B,iBAAiB,UACjB,gBACF;EAIF,IAAI,iBAAiB,uBAAuB,KAAA,GAC1C,iBAAiB,qBACf,iBAAiB,gBAAgB;EAErC,IAAI,iBAAiB,iBAAiB,KAAA,GACpC,iBAAiB,eAAe,CAAC,CAAC,iBAAiB;EAGrD,IAAI,CAAC,iBAAiB,eAAe,iBAAiB,WACpD,iBAAiB,cAAc;EAGjC,IAAI,iBAAiB,YAAY,WAC/B,iBAAiB,UAAU;EAG7B,OAAO;CAOT;;;;;;;;;CAUA,uBACE,SACG;EACH,IAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAI,QAAS,YACX,OAAO;EAET,OAAO;GACL,GAAA,uBAAA,iBAAG,IAAA,CAAA,CAAqB;GACxB,IAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAI,QAAS,gBACX,KAAK,oBAAoB,QAAQ,WAAW;GAC9C,GAAG;GACH,YAAY;EACd;CACF;;;;;;;;;;;CAYA,QAAc;EACZ,uBAAA,aAAA,IAAA,CAAA,CAAiB,MAAM;EACvB,uBAAA,gBAAA,IAAA,CAAA,CAAoB,MAAM;CAC5B;AACF"}
|
|
1
|
+
{"version":3,"file":"queryClient.js","names":[],"sources":["../../src/queryClient.ts"],"sourcesContent":["import {\n functionalUpdate,\n hashKey,\n hashQueryKeyByOptions,\n noop,\n partialMatchKey,\n resolveQueryValue,\n skipToken,\n} from './utils'\nimport { QueryCache } from './queryCache'\nimport { MutationCache } from './mutationCache'\nimport { focusManager } from './focusManager'\nimport { onlineManager } from './onlineManager'\nimport { notifyManager } from './notifyManager'\nimport type {\n CancelOptions,\n DefaultError,\n DefaultOptions,\n DefaultedQueryObserverOptions,\n EnsureInfiniteQueryDataOptions,\n EnsureQueryDataOptions,\n FetchInfiniteQueryOptions,\n FetchQueryOptions,\n InferDataFromTag,\n InferErrorFromTag,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n InvalidateOptions,\n InvalidateQueryFilters,\n MutationKey,\n MutationObserverOptions,\n MutationOptions,\n OmitKeyof,\n QueryClientConfig,\n QueryExecuteOptions,\n QueryKey,\n QueryObserverOptions,\n QueryOptions,\n RefetchOptions,\n RefetchQueryFilters,\n ResetOptions,\n SetDataOptions,\n} from './types'\nimport type { QueryState } from './query'\nimport type { MutationFilters, QueryFilters, Updater } from './utils'\n\n// TYPES\n\ninterface QueryDefaults {\n queryKey: QueryKey\n defaultOptions: OmitKeyof<QueryOptions<any, any, any>, 'queryKey'>\n}\n\ninterface MutationDefaults {\n mutationKey: MutationKey\n defaultOptions: MutationOptions<any, any, any, any>\n}\n\n// CLASS\n\n/**\n * `QueryClient` is used to interact with a cache of queries and mutations. It owns a\n * `QueryCache` and a `MutationCache` (creating default ones if none are passed in) and holds\n * the default options that are applied to queries and mutations created through it.\n * @example\n * ```ts\n * const queryClient = new QueryClient({\n * defaultOptions: {\n * queries: {\n * staleTime: Infinity,\n * },\n * },\n * })\n *\n * await queryClient.query({ queryKey: ['posts'], queryFn: fetchPosts })\n * ```\n */\nexport class QueryClient {\n #queryCache: QueryCache\n #mutationCache: MutationCache\n #defaultOptions: DefaultOptions\n #queryDefaults: Map<string, QueryDefaults>\n #mutationDefaults: Map<string, MutationDefaults>\n #mountCount: number\n #unsubscribeFocus?: () => void\n #unsubscribeOnline?: () => void\n\n constructor(config: QueryClientConfig = {}) {\n this.#queryCache = config.queryCache || new QueryCache()\n this.#mutationCache = config.mutationCache || new MutationCache()\n this.#defaultOptions = config.defaultOptions || {}\n this.#queryDefaults = new Map()\n this.#mutationDefaults = new Map()\n this.#mountCount = 0\n }\n\n /**\n * Called by a framework adapter's `QueryClientProvider`-equivalent when it mounts, to start\n * listening for focus/online events and resume paused mutations. Ref-counted via an internal\n * mount count, so nested or multiple providers sharing the same `QueryClient` don't tear down\n * the shared listeners until the last one unmounts.\n */\n mount(): void {\n this.#mountCount++\n if (this.#mountCount !== 1) return\n\n this.#unsubscribeFocus = focusManager.subscribe(async (focused) => {\n if (focused) {\n await this.resumePausedMutations()\n this.#queryCache.onFocus()\n }\n })\n this.#unsubscribeOnline = onlineManager.subscribe(async (online) => {\n if (online) {\n await this.resumePausedMutations()\n this.#queryCache.onOnline()\n }\n })\n }\n\n /**\n * The inverse of {@link QueryClient#mount} — called by a framework adapter's\n * `QueryClientProvider`-equivalent when it unmounts. Only tears down the focus/online\n * listeners once the mount count returns to `0`.\n */\n unmount(): void {\n this.#mountCount--\n if (this.#mountCount !== 0) return\n\n this.#unsubscribeFocus?.()\n this.#unsubscribeFocus = undefined\n\n this.#unsubscribeOnline?.()\n this.#unsubscribeOnline = undefined\n }\n\n /**\n * Returns the number of queries in the cache that are currently fetching, optionally\n * matching a set of filters. This includes background-fetching, loading new pages, and\n * loading more infinite query results.\n * @param filters - Narrows down which fetching queries are counted. Without filters, every\n * fetching query is counted.\n * @returns The number of matching queries whose `fetchStatus` is `'fetching'`.\n * @example\n * ```ts\n * if (queryClient.isFetching()) {\n * console.log('At least one query is fetching!')\n * }\n * ```\n */\n isFetching(filters?: Omit<QueryFilters, 'fetchStatus'>): number {\n return this.#queryCache.findAll({ ...filters, fetchStatus: 'fetching' })\n .length\n }\n\n /**\n * Returns the number of mutations in the cache that are currently pending, optionally\n * matching a set of filters.\n * @param filters - Narrows down which pending mutations are counted. Without filters, every\n * pending mutation is counted.\n * @returns The number of matching mutations whose `status` is `'pending'`.\n * @example\n * ```ts\n * if (queryClient.isMutating()) {\n * console.log('At least one mutation is pending!')\n * }\n * ```\n */\n isMutating<\n TMutationFilters extends MutationFilters<any, any> = MutationFilters<\n any,\n any\n >,\n >(filters?: NoInfer<Omit<TMutationFilters, 'status'>>): number {\n return this.#mutationCache.findAll({ ...filters, status: 'pending' }).length\n }\n\n /**\n * Imperative (non-reactive) way to retrieve data for a QueryKey.\n * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.\n *\n * Hint: Do not use this function inside a component, because it won't receive updates.\n * Use `useQuery` to create a `QueryObserver` that subscribes to changes.\n * @param queryKey - The query key of the query to read.\n * @returns The cached data for the query, or `undefined` if no query with this key has been observed yet.\n * @see {@link QueryClient#getQueriesData}\n */\n getQueryData<\n TQueryFnData = unknown,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n >(queryKey: TTaggedQueryKey): TInferredQueryFnData | undefined {\n const options = this.defaultQueryOptions({ queryKey })\n\n return this.#queryCache.get<TInferredQueryFnData>(options.queryHash)?.state\n .data\n }\n\n /**\n * Returns the cached data of a query, or fetches it if there is none. With `revalidateIfStale`,\n * stale cached data is also refetched in the background.\n * @param options - The query options. If the query has no cached data yet, it is fetched with\n * these options.\n * @returns A promise that resolves to the cached data, or to the fetched data if nothing was\n * cached yet.\n * @deprecated Use queryClient.query({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.\n */\n ensureQueryData<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: EnsureQueryDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n const query = this.#queryCache.build(this, defaultedOptions)\n const cachedData = query.state.data\n\n if (cachedData === undefined) {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchQuery(options)\n }\n\n if (\n options.revalidateIfStale &&\n query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query))\n ) {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n void this.prefetchQuery(defaultedOptions)\n }\n\n return Promise.resolve(cachedData)\n }\n\n /**\n * Imperative (non-reactive) way to retrieve the cached data of multiple queries at once.\n * Only queries matching the given filters are returned; if none match, an empty array is\n * returned.\n *\n * Because the matched queries can hold data of different shapes (e.g. a broad filter can match\n * queries with unrelated data types), the `TQueryFnData` generic defaults to `unknown` rather\n * than being inferred. Passing a more specific type is a convenience for call sites that know\n * every matched query holds the same shape — it is not checked against the actual cache\n * contents.\n * @param filters - The filters that select which queries to read.\n * @returns An array of query key and data pairs. The data is `undefined` for a query with no cached data.\n * @see {@link QueryClient#getQueryData}\n * @example\n * ```ts\n * const data = queryClient.getQueriesData({ queryKey: ['posts'] })\n * ```\n */\n getQueriesData<\n TQueryFnData = unknown,\n TQueryFilters extends QueryFilters<any> = QueryFilters,\n >(filters: TQueryFilters): Array<[QueryKey, TQueryFnData | undefined]> {\n return this.#queryCache.findAll(filters).map(({ queryKey, state }) => {\n const data = state.data as TQueryFnData | undefined\n return [queryKey, data]\n })\n }\n\n /**\n * Synchronous way to immediately update a query's cached data. If the updater (or the value\n * passed) resolves to `undefined`, the cache is left untouched and no query is created;\n * otherwise, if the query does not exist yet, it will be created. To update multiple queries\n * at once by partially matching query keys, use {@link QueryClient#setQueriesData} instead.\n *\n * Updates must be performed immutably: do not mutate `oldData`, or data previously retrieved\n * via {@link QueryClient#getQueryData}, in place.\n * @param queryKey - The query key to set data for.\n * @param updater - Either the new data, or a function that receives the current data (which\n * may be `undefined`) and returns the new data.\n * @param options - Set `updatedAt` to override the timestamp the written data is recorded with.\n * @returns The data that was written, or `undefined` if the updater returned `undefined` — in that case\n * the write is skipped and the cache is left unchanged.\n * @example\n * ```ts\n * queryClient.setQueryData(['posts'], newPosts)\n *\n * // Or, using an updater function that receives the current data:\n * queryClient.setQueryData(['posts'], (oldPosts) => [...oldPosts, newPost])\n * ```\n */\n setQueryData<\n TQueryFnData = unknown,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n >(\n queryKey: TTaggedQueryKey,\n updater: Updater<\n InferDataFromTag<NoInfer<TQueryFnData>, TTaggedQueryKey> | undefined,\n NoInfer<TInferredQueryFnData> | undefined\n >,\n options?: SetDataOptions,\n ): NoInfer<TInferredQueryFnData> | undefined {\n const defaultedOptions = this.defaultQueryOptions<\n any,\n any,\n unknown,\n any,\n QueryKey\n >({ queryKey })\n\n const query = this.#queryCache.get<\n InferDataFromTag<NoInfer<TQueryFnData>, TTaggedQueryKey>\n >(defaultedOptions.queryHash)\n const prevData = query?.state.data\n const data = functionalUpdate(updater, prevData)\n\n if (data === undefined) {\n return undefined\n }\n\n return this.#queryCache\n .build(this, defaultedOptions)\n .setData(data, { ...options, manual: true })\n }\n\n /**\n * Synchronous way to immediately update the cached data of multiple queries at once, using\n * filters or partial query key matching. Only queries that already exist and match the given\n * filters are updated; no new cache entries are created. Internally this calls\n * {@link QueryClient#setQueryData} for each matching query.\n * @param filters - The filters that select which existing queries to update.\n * @param updater - Either the new data, or a function that receives each matched query's current\n * data (which may be `undefined`) and returns the new data.\n * @param options - Set `updatedAt` to override the timestamp the written data is recorded with.\n * @returns One `[queryKey, data]` tuple per matched query, in the same shape and with the same\n * `undefined` case as {@link QueryClient#setQueryData}.\n * @example\n * ```ts\n * queryClient.setQueriesData({ queryKey: ['posts'] }, (oldPosts) =>\n * oldPosts ? oldPosts.filter((post) => post.id !== deletedId) : oldPosts,\n * )\n * ```\n */\n setQueriesData<\n TQueryFnData,\n TQueryFilters extends QueryFilters<any> = QueryFilters,\n >(\n filters: TQueryFilters,\n updater: Updater<\n NoInfer<TQueryFnData> | undefined,\n NoInfer<TQueryFnData> | undefined\n >,\n options?: SetDataOptions,\n ): Array<[QueryKey, TQueryFnData | undefined]> {\n return notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .map(({ queryKey }) => [\n queryKey,\n this.setQueryData<TQueryFnData>(queryKey, updater, options),\n ]),\n )\n }\n\n /**\n * Imperative (non-reactive) way to retrieve an existing query's state. If the query does not\n * exist, `undefined` is returned.\n * @param queryKey - The query key of the query to read.\n * @returns The query's state, or `undefined` if no query with this key exists.\n * @example\n * ```ts\n * const state = queryClient.getQueryState(['posts'])\n * console.log(state?.dataUpdatedAt)\n * ```\n */\n getQueryState<\n TQueryFnData = unknown,\n TError = DefaultError,\n TTaggedQueryKey extends QueryKey = QueryKey,\n TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>,\n TInferredError = InferErrorFromTag<TError, TTaggedQueryKey>,\n >(\n queryKey: TTaggedQueryKey,\n ): QueryState<TInferredQueryFnData, TInferredError> | undefined {\n const options = this.defaultQueryOptions({ queryKey })\n return this.#queryCache.get<TInferredQueryFnData, TInferredError>(\n options.queryHash,\n )?.state\n }\n\n /**\n * Removes queries from the cache that match the given filters. Unlike\n * {@link QueryClient#invalidateQueries} or {@link QueryClient#refetchQueries}, this removes\n * matching queries from the cache instead of refetching them. Without filters, every query in\n * the cache is removed.\n * @param filters - The filters that select which queries to remove. Without filters, every query\n * is removed.\n * @example\n * ```ts\n * queryClient.removeQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n removeQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n ): void {\n const queryCache = this.#queryCache\n notifyManager.batch(() => {\n queryCache.findAll(filters).forEach((query) => {\n queryCache.remove(query)\n })\n })\n }\n\n /**\n * Resets queries matching the given filters back to their initial state (e.g. any\n * `initialData`), notifying subscribers rather than removing them. Active queries among the\n * matched set are then refetched, and the returned promise resolves once that refetch settles.\n * @param filters - The filters that select which queries to reset. Without filters, every query\n * is reset.\n * @param options - Passed to the refetch of the active matched queries, e.g. `cancelRefetch` and\n * `throwOnError`.\n * @returns A promise that resolves once the refetch of the active matched queries settles.\n * @example\n * ```ts\n * await queryClient.resetQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n resetQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n options?: ResetOptions,\n ): Promise<void> {\n const queryCache = this.#queryCache\n\n return notifyManager.batch(() => {\n const matched = queryCache.findAll(filters)\n const queriesToRefetch = new Set(matched)\n matched.forEach((query) => {\n query.reset()\n })\n return this.refetchQueries(\n {\n type: 'active',\n predicate: (query) => queriesToRefetch.has(query),\n },\n options,\n )\n })\n }\n\n /**\n * Cancels outgoing fetches for queries matching the given filters. Most useful when performing\n * optimistic updates, since any outgoing refetch that resolves afterwards would otherwise\n * overwrite the optimistic update. By default (`revert: true`), a cancelled query's data is\n * reverted to its state before the outgoing fetch started.\n *\n * The returned promise never rejects, even if individual cancellations fail.\n * @param filters - The filters that select which queries to cancel. Without filters, every query\n * is cancelled.\n * @param cancelOptions - Passed to each matched query's cancellation. `revert` defaults to\n * `true`.\n * @returns A promise that resolves once every cancellation has settled.\n * @example\n * ```ts\n * await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })\n * ```\n */\n cancelQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: QueryFilters<TTaggedQueryKey>,\n cancelOptions: CancelOptions = {},\n ): Promise<void> {\n const defaultedCancelOptions = { revert: true, ...cancelOptions }\n\n const promises = notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .map((query) => query.cancel(defaultedCancelOptions)),\n )\n\n return Promise.all(promises).then(noop).catch(noop)\n }\n\n /**\n * Marks queries matching the given filters as invalidated. Unlike\n * {@link QueryClient#removeQueries}, invalidated queries stay in the cache.\n *\n * Unless `filters.refetchType` is `'none'`, matching queries are then refetched via\n * {@link QueryClient#refetchQueries}, using `filters.refetchType` if set, otherwise\n * `filters.type`, otherwise `'active'`.\n * @param filters - The filters that select which queries to invalidate, plus `refetchType` to\n * control which of them to refetch afterwards. Without filters, every query is invalidated.\n * @param options - Passed to {@link QueryClient#refetchQueries}, e.g. `cancelRefetch` and\n * `throwOnError`.\n * @returns A promise that resolves once the refetch settles, or immediately if `refetchType` is\n * `'none'`.\n * @example\n * ```ts\n * await queryClient.invalidateQueries({ queryKey: ['posts'], refetchType: 'active' })\n * ```\n */\n invalidateQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: InvalidateQueryFilters<TTaggedQueryKey>,\n options: InvalidateOptions = {},\n ): Promise<void> {\n return notifyManager.batch(() => {\n this.#queryCache.findAll(filters).forEach((query) => {\n query.invalidate()\n })\n\n if (filters?.refetchType === 'none') {\n return Promise.resolve()\n }\n return this.refetchQueries(\n {\n ...filters,\n type: filters?.refetchType ?? filters?.type ?? 'active',\n },\n options,\n )\n })\n }\n\n /**\n * Refetches queries matching the given filters, regardless of whether they are stale. Without\n * filters, every query in the cache is refetched. Queries that are disabled, or static (only\n * have observers with a static `staleTime`), are never refetched.\n *\n * By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new\n * one starts. The returned promise does not reject on individual query failures unless\n * `throwOnError` is `true`.\n *\n * Initially paused fetches do not delay the returned promise. Their later errors are handled\n * even when `throwOnError` is `true`.\n * @param filters - The filters that select which queries to refetch. Without filters, every query\n * in the cache is included.\n * @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling\n * it, and `throwOnError` to `true` to reject when a refetch that was not initially paused fails.\n * @returns A promise that resolves once all matching refetches that were not initially paused\n * have settled.\n * @example\n * ```ts\n * // refetch all active queries partially matching a query key:\n * await queryClient.refetchQueries({ queryKey: ['posts'], type: 'active' })\n * ```\n */\n refetchQueries<TTaggedQueryKey extends QueryKey = QueryKey>(\n filters?: RefetchQueryFilters<TTaggedQueryKey>,\n options: RefetchOptions = {},\n ): Promise<void> {\n const fetchOptions = {\n ...options,\n cancelRefetch: options.cancelRefetch ?? true,\n }\n const promises = notifyManager.batch(() =>\n this.#queryCache\n .findAll(filters)\n .filter((query) => !query.isDisabled() && !query.isStatic())\n .map((query) => {\n let promise = query.fetch(undefined, fetchOptions)\n const isPaused = query.state.fetchStatus === 'paused'\n if (!fetchOptions.throwOnError || isPaused) {\n promise = promise.catch(noop)\n }\n return isPaused ? Promise.resolve() : promise\n }),\n )\n\n return Promise.all(promises).then(noop)\n }\n\n /**\n * Asynchronous method to fetch and cache a query, resolving with the data or throwing with\n * the error.\n *\n * If the query already exists in the cache and its data is not stale (per the given\n * `staleTime`), the cached data is returned without fetching. Otherwise, the query is fetched\n * and the promise resolves once the fetch settles. If a `select` function is provided, it is\n * applied to the data in both cases (cached or freshly fetched) before it is returned.\n *\n * Unlike a reactive observer, retries are disabled by default here (`retry: false`) unless\n * explicitly configured, since there is no component to catch a thrown error and retry through\n * re-render.\n *\n * The accepted options are `QueryObserverOptions` minus the fields that only make sense for a\n * reactive observer — `enabled`, `refetchInterval`, `refetchIntervalInBackground`,\n * `refetchOnWindowFocus`, `refetchOnReconnect`, `refetchOnMount`, `retryOnMount`,\n * `notifyOnChangeProps`, `throwOnError`, `suspense`, and `placeholderData` are not part of this\n * method's options.\n *\n * This method replaces the deprecated `fetchQuery`, and — combined with\n * `{ staleTime: 'static' }` — the deprecated `ensureQueryData`.\n * @param options - The query options, including the `queryKey` and the `queryFn` used if the\n * query needs to fetch.\n * @returns A promise that resolves to the data, or to the result of `select` if provided. It\n * rejects with the error from the fetch or from `select`.\n * @example\n * ```ts\n * try {\n * const data = await queryClient.query({ queryKey, queryFn, staleTime: 10000 })\n * } catch (error) {\n * console.log(error)\n * }\n * ```\n */\n async query<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options: QueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n\n // https://github.com/tannerlinsley/react-query/issues/652\n if (defaultedOptions.retry === undefined) {\n defaultedOptions.retry = false\n }\n\n const query = this.#queryCache.build(this, defaultedOptions)\n\n const isStale = query.isStaleByTime(\n resolveQueryValue(defaultedOptions.staleTime, query),\n )\n\n const queryData = isStale\n ? await query.fetch(defaultedOptions)\n : (query.state.data as TQueryData)\n\n const select = defaultedOptions.select\n\n if (select) {\n return select(queryData)\n }\n\n return queryData as unknown as TData\n }\n\n /**\n * Fetches and caches a query, or returns its cached data if it isn't stale. Unlike in observers,\n * the fetch isn't retried unless `retry` is set.\n * @param options - The query options, including the `queryKey` and the `queryFn` used if the\n * query needs to fetch.\n * @returns A promise that resolves to the cached or fetched data, or rejects with the fetch\n * error.\n * @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.\n */\n fetchQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options: FetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<TData> {\n const defaultedOptions = this.defaultQueryOptions(options)\n\n // https://github.com/tannerlinsley/react-query/issues/652\n if (defaultedOptions.retry === undefined) {\n defaultedOptions.retry = false\n }\n\n const query = this.#queryCache.build(this, defaultedOptions)\n\n return query.isStaleByTime(\n resolveQueryValue(defaultedOptions.staleTime, query),\n )\n ? query.fetch(defaultedOptions)\n : Promise.resolve(query.state.data as TData)\n }\n\n /**\n * Fetches and caches a query like {@link QueryClient#fetchQuery}, but ignores the result and any\n * error.\n * @param options - The query options, including the `queryKey` and the `queryFn` used if the\n * query needs to fetch.\n * @returns A promise that resolves once the fetch settles. It never rejects.\n * @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.\n */\n prefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): Promise<void> {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchQuery(options).then(noop).catch(noop)\n }\n\n /**\n * Asynchronous method to fetch and cache an infinite query, resolving with an\n * {@link InfiniteData} object or throwing with the error.\n *\n * Behaves like {@link QueryClient#query}, accepting the same options (minus\n * `initialPageParam`), plus the required `initialPageParam`, and an optional `pages` /\n * `getNextPageParam` pair used to refetch a fixed number of pages from the start.\n *\n * This method replaces the deprecated `fetchInfiniteQuery`, and — combined with\n * `{ staleTime: 'static' }` — the deprecated `ensureInfiniteQueryData`.\n * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the\n * `initialPageParam`.\n * @returns A promise that resolves to the {@link InfiniteData}, or to the result of `select` if\n * provided. It rejects with the error from the fetch or from `select`.\n * @example\n * ```ts\n * try {\n * const data = await queryClient.infiniteQuery({ queryKey, queryFn, initialPageParam: 0 })\n * console.log(data.pages)\n * } catch (error) {\n * console.log(error)\n * }\n * ```\n */\n infiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<\n Array<TData> extends Array<InfiniteData<TQueryFnData>>\n ? InfiniteData<TQueryFnData, TPageParam>\n : TData\n > {\n options._type = 'infinite'\n return this.query(options as any)\n }\n\n /**\n * Fetches and caches an infinite query, or returns its cached data if it isn't stale.\n * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the\n * `initialPageParam`.\n * @returns A promise that resolves to the cached or fetched {@link InfiniteData}, or rejects with\n * the fetch error.\n * @deprecated Use queryClient.infiniteQuery(options) instead. This method will be removed in the next major version.\n */\n fetchInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: FetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<InfiniteData<TData, TPageParam>> {\n options._type = 'infinite'\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchQuery(options as any)\n }\n\n /**\n * Fetches and caches an infinite query like {@link QueryClient#fetchInfiniteQuery}, but ignores\n * the result and any error.\n * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the\n * `initialPageParam`.\n * @returns A promise that resolves once the fetch settles. It never rejects.\n * @deprecated Use queryClient.infiniteQuery(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.\n */\n prefetchInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: FetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<void> {\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.fetchInfiniteQuery(options).then(noop).catch(noop)\n }\n\n /**\n * Returns the cached data of an infinite query, or fetches it if there is none. With\n * `revalidateIfStale`, stale cached data is also refetched in the background.\n * @param options - The infinite query options. If the query has no cached data yet, it is fetched\n * with these options.\n * @returns A promise that resolves to the cached {@link InfiniteData}, or to the fetched data if\n * nothing was cached yet.\n * @deprecated Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.\n */\n ensureInfiniteQueryData<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n >(\n options: EnsureInfiniteQueryDataOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): Promise<InfiniteData<TData, TPageParam>> {\n options._type = 'infinite'\n\n // oxlint-disable-next-line tanstack-query/no-restricted-syntax\n return this.ensureQueryData(options as any)\n }\n\n /**\n * Resumes mutations that were paused because there was no network connection. Does nothing\n * (resolving immediately) if the client is currently offline.\n * @returns A promise that resolves once the resumed mutations have settled.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * await queryClient.resumePausedMutations()\n * ```\n */\n resumePausedMutations(): Promise<unknown> {\n if (onlineManager.isOnline()) {\n return this.#mutationCache.resumePausedMutations()\n }\n return Promise.resolve()\n }\n\n /**\n * Returns the query cache this client is connected to.\n * @returns The {@link QueryCache} instance.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const queryCache = queryClient.getQueryCache()\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n getQueryCache(): QueryCache {\n return this.#queryCache\n }\n\n /**\n * Returns the mutation cache this client is connected to.\n * @returns The {@link MutationCache} instance.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const mutationCache = queryClient.getMutationCache()\n * const mutations = mutationCache.findAll({ status: 'pending' })\n * ```\n */\n getMutationCache(): MutationCache {\n return this.#mutationCache\n }\n\n /**\n * Returns the default options that were set when creating the client, or via\n * {@link QueryClient#setDefaultOptions}.\n * @returns The client's current default options.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * const defaultOptions = queryClient.getDefaultOptions()\n * ```\n */\n getDefaultOptions(): DefaultOptions {\n return this.#defaultOptions\n }\n\n /**\n * Dynamically sets the default options for this client, overwriting any previously defined\n * default options.\n * @param options - The new default options for queries and mutations.\n * @see {@link QueryClient#getDefaultOptions}\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new QueryClient()\n * queryClient.setDefaultOptions({\n * queries: {\n * staleTime: Infinity,\n * },\n * })\n * ```\n */\n setDefaultOptions(options: DefaultOptions): void {\n this.#defaultOptions = options\n }\n\n /**\n * Sets default options for queries whose query key partially matches the given `queryKey`.\n *\n * If several registered query defaults match a given query key, they are merged together in\n * registration order by {@link QueryClient#getQueryDefaults}, so register defaults from the\n * most generic key to the least generic one — more specific defaults should be registered\n * after more generic ones so they take precedence.\n * @param queryKey - The query key that query keys are partially matched against.\n * @param options - The default options applied to matching queries.\n * @example\n * ```ts\n * queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts })\n *\n * await queryClient.query({ queryKey: ['posts'] })\n * ```\n */\n setQueryDefaults<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n >(\n queryKey: QueryKey,\n options: Partial<\n OmitKeyof<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData>,\n 'queryKey'\n >\n >,\n ): void {\n this.#queryDefaults.set(hashKey(queryKey), {\n queryKey,\n defaultOptions: options,\n })\n }\n\n /**\n * Returns the default options registered for queries whose query key partially matches the\n * given `queryKey`, via {@link QueryClient#setQueryDefaults}. If multiple registered defaults\n * match, they are merged together in registration order.\n * @param queryKey - The query key to look up registered defaults for.\n * @returns The merged default options of every registration that matches, or an empty object if\n * none match.\n * @example\n * ```ts\n * const defaultOptions = queryClient.getQueryDefaults(['posts'])\n * ```\n */\n getQueryDefaults(\n queryKey: QueryKey,\n ): OmitKeyof<QueryObserverOptions<any, any, any, any, any>, 'queryKey'> {\n const defaults = [...this.#queryDefaults.values()]\n\n const result: OmitKeyof<\n QueryObserverOptions<any, any, any, any, any>,\n 'queryKey'\n > = {}\n\n defaults.forEach((queryDefault) => {\n if (partialMatchKey(queryKey, queryDefault.queryKey)) {\n Object.assign(result, queryDefault.defaultOptions)\n }\n })\n return result\n }\n\n /**\n * Sets default options for mutations whose mutation key partially matches the given\n * `mutationKey`. As with {@link QueryClient#setQueryDefaults}, the order of registration\n * matters when several registered defaults match the same mutation key.\n * @param mutationKey - The mutation key that mutation keys are partially matched against.\n * @param options - The default options applied to matching mutations.\n * @see {@link QueryClient#getMutationDefaults}\n * @example\n * ```ts\n * queryClient.setMutationDefaults(['addPost'], { mutationFn: addPost })\n * ```\n */\n setMutationDefaults<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n >(\n mutationKey: MutationKey,\n options: OmitKeyof<\n MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n ): void {\n this.#mutationDefaults.set(hashKey(mutationKey), {\n mutationKey,\n defaultOptions: options,\n })\n }\n\n /**\n * Returns the default options registered for mutations whose mutation key partially matches\n * the given `mutationKey`, via {@link QueryClient#setMutationDefaults}. If multiple registered\n * defaults match, they are merged together in registration order.\n * @param mutationKey - The mutation key to look up registered defaults for.\n * @returns The merged default options of every registration that matches, or an empty object if\n * none match.\n * @example\n * ```ts\n * const defaultOptions = queryClient.getMutationDefaults(['addPost'])\n * ```\n */\n getMutationDefaults(\n mutationKey: MutationKey,\n ): OmitKeyof<MutationObserverOptions<any, any, any, any>, 'mutationKey'> {\n const defaults = [...this.#mutationDefaults.values()]\n\n const result: OmitKeyof<\n MutationObserverOptions<any, any, any, any>,\n 'mutationKey'\n > = {}\n\n defaults.forEach((queryDefault) => {\n if (partialMatchKey(mutationKey, queryDefault.mutationKey)) {\n Object.assign(result, queryDefault.defaultOptions)\n }\n })\n\n return result\n }\n\n /**\n * Called by framework adapters (e.g. inside `useQuery`) to resolve the options passed by the\n * caller into their final, defaulted form: merging the client's own `defaultOptions.queries`,\n * then `queryClient.setQueryDefaults` for the given `queryKey`, then the caller's options on\n * top. A no-op if the options are already defaulted (`_defaulted: true`).\n * @param options - The query options passed by the caller.\n * @returns The defaulted options, with `queryHash` and dependent defaults (e.g.\n * `refetchOnReconnect`) filled in.\n */\n defaultQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n >(\n options:\n | QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n | DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > {\n if (options._defaulted) {\n return options as DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n }\n\n const defaultedOptions = {\n ...this.#defaultOptions.queries,\n ...this.getQueryDefaults(options.queryKey),\n ...options,\n _defaulted: true,\n }\n\n if (!defaultedOptions.queryHash) {\n defaultedOptions.queryHash = hashQueryKeyByOptions(\n defaultedOptions.queryKey,\n defaultedOptions,\n )\n }\n\n // dependent default values\n if (defaultedOptions.refetchOnReconnect === undefined) {\n defaultedOptions.refetchOnReconnect =\n defaultedOptions.networkMode !== 'always'\n }\n if (defaultedOptions.throwOnError === undefined) {\n defaultedOptions.throwOnError = !!defaultedOptions.suspense\n }\n\n if (!defaultedOptions.networkMode && defaultedOptions.persister) {\n defaultedOptions.networkMode = 'offlineFirst'\n }\n\n if (defaultedOptions.queryFn === skipToken) {\n defaultedOptions.enabled = false\n }\n\n return defaultedOptions as DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n }\n\n /**\n * The mutation counterpart of {@link QueryClient#defaultQueryOptions}. Called by framework\n * adapters (e.g. inside `useMutation`) to merge the client's `defaultOptions.mutations`, then\n * `queryClient.setMutationDefaults` for the given `mutationKey`, then the caller's options on\n * top. A no-op if the options are already defaulted (`_defaulted: true`).\n * @param options - The mutation options passed by the caller.\n * @returns The defaulted options.\n */\n defaultMutationOptions<T extends MutationOptions<any, any, any, any>>(\n options?: T,\n ): T {\n if (options?._defaulted) {\n return options\n }\n return {\n ...this.#defaultOptions.mutations,\n ...(options?.mutationKey &&\n this.getMutationDefaults(options.mutationKey)),\n ...options,\n _defaulted: true,\n } as T\n }\n\n /**\n * Clears both the query cache and the mutation cache this client is connected to.\n * @example\n * ```ts\n * import { QueryClient } from '@tanstack/query-core'\n *\n * const queryClient = new Que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AiB,MAAM;EACvB,uBAAA,gBAAA,IAAA,CAAA,CAAoB,MAAM;CAC5B;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ar as QueryObserver } from "./hydration-BXjqUj_D.cjs";
|
|
2
2
|
export { QueryObserver };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ar as QueryObserver } from "./hydration-vgIjIhk6.js";
|
|
2
2
|
export { QueryObserver };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $t as CancelledError, an as isCancelledError, en as RetryDelayValue, in as createRetryer, nn as Retryer, rn as canFetch, tn as RetryValue } from "./hydration-
|
|
1
|
+
import { $t as CancelledError, an as isCancelledError, en as RetryDelayValue, in as createRetryer, nn as Retryer, rn as canFetch, tn as RetryValue } from "./hydration-BXjqUj_D.cjs";
|
|
2
2
|
export { CancelledError, RetryDelayValue, RetryValue, Retryer, canFetch, createRetryer, isCancelledError };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $t as CancelledError, an as isCancelledError, en as RetryDelayValue, in as createRetryer, nn as Retryer, rn as canFetch, tn as RetryValue } from "./hydration-
|
|
1
|
+
import { $t as CancelledError, an as isCancelledError, en as RetryDelayValue, in as createRetryer, nn as Retryer, rn as canFetch, tn as RetryValue } from "./hydration-vgIjIhk6.js";
|
|
2
2
|
export { CancelledError, RetryDelayValue, RetryValue, Retryer, canFetch, createRetryer, isCancelledError };
|