@tanstack/query-core 5.102.7 → 5.103.0
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/environmentManager.cjs +15 -1
- package/build/legacy/environmentManager.cjs.map +1 -1
- package/build/legacy/environmentManager.d.cts +15 -1
- package/build/legacy/environmentManager.d.cts.map +1 -1
- package/build/legacy/environmentManager.d.ts +15 -1
- package/build/legacy/environmentManager.d.ts.map +1 -1
- package/build/legacy/environmentManager.js +15 -1
- package/build/legacy/environmentManager.js.map +1 -1
- package/build/legacy/focusManager.cjs +57 -0
- package/build/legacy/focusManager.cjs.map +1 -1
- package/build/legacy/focusManager.d.cts +57 -0
- package/build/legacy/focusManager.d.cts.map +1 -1
- package/build/legacy/focusManager.d.ts +57 -0
- package/build/legacy/focusManager.d.ts.map +1 -1
- package/build/legacy/focusManager.js +57 -0
- package/build/legacy/focusManager.js.map +1 -1
- package/build/legacy/{hydration-Bjs0MSgg.d.ts → hydration-Cq7QYAzB.d.ts} +1424 -7
- package/build/legacy/hydration-Cq7QYAzB.d.ts.map +1 -0
- package/build/legacy/{hydration-DWGr3cFC.d.cts → hydration-DwR10Hi-.d.cts} +1424 -7
- package/build/legacy/hydration-DwR10Hi-.d.cts.map +1 -0
- package/build/legacy/hydration.cjs +57 -4
- package/build/legacy/hydration.cjs.map +1 -1
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/hydration.js +57 -4
- package/build/legacy/hydration.js.map +1 -1
- package/build/legacy/index.cjs.map +1 -1
- package/build/legacy/index.d.cts +5 -5
- package/build/legacy/index.d.ts +5 -5
- package/build/legacy/index.js.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
- package/build/legacy/infiniteQueryObserver.cjs +67 -0
- package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +68 -1
- package/build/legacy/infiniteQueryObserver.d.cts.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.ts +68 -1
- package/build/legacy/infiniteQueryObserver.d.ts.map +1 -1
- package/build/legacy/infiniteQueryObserver.js +67 -0
- package/build/legacy/infiniteQueryObserver.js.map +1 -1
- package/build/legacy/mutation.cjs +74 -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 +74 -0
- package/build/legacy/mutation.js.map +1 -1
- package/build/legacy/mutationCache.cjs +74 -0
- package/build/legacy/mutationCache.cjs.map +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationCache.js +74 -0
- package/build/legacy/mutationCache.js.map +1 -1
- package/build/legacy/mutationObserver.cjs +71 -0
- package/build/legacy/mutationObserver.cjs.map +1 -1
- package/build/legacy/mutationObserver.d.cts +1 -1
- package/build/legacy/mutationObserver.d.ts +1 -1
- package/build/legacy/mutationObserver.js +71 -0
- package/build/legacy/mutationObserver.js.map +1 -1
- package/build/legacy/notifyManager.cjs +45 -1
- package/build/legacy/notifyManager.cjs.map +1 -1
- package/build/legacy/notifyManager.d.cts +83 -2
- package/build/legacy/notifyManager.d.cts.map +1 -1
- package/build/legacy/notifyManager.d.ts +83 -2
- package/build/legacy/notifyManager.d.ts.map +1 -1
- package/build/legacy/notifyManager.js +45 -1
- package/build/legacy/notifyManager.js.map +1 -1
- package/build/legacy/onlineManager.cjs +47 -0
- package/build/legacy/onlineManager.cjs.map +1 -1
- package/build/legacy/onlineManager.d.cts +47 -0
- package/build/legacy/onlineManager.d.cts.map +1 -1
- package/build/legacy/onlineManager.d.ts +47 -0
- package/build/legacy/onlineManager.d.ts.map +1 -1
- package/build/legacy/onlineManager.js +47 -0
- package/build/legacy/onlineManager.js.map +1 -1
- package/build/legacy/queriesObserver.cjs +64 -0
- package/build/legacy/queriesObserver.cjs.map +1 -1
- package/build/legacy/queriesObserver.d.cts +73 -1
- package/build/legacy/queriesObserver.d.cts.map +1 -1
- package/build/legacy/queriesObserver.d.ts +73 -1
- package/build/legacy/queriesObserver.d.ts.map +1 -1
- package/build/legacy/queriesObserver.js +64 -0
- package/build/legacy/queriesObserver.js.map +1 -1
- package/build/legacy/query.cjs +141 -0
- 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 +141 -0
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryCache.cjs +120 -0
- package/build/legacy/queryCache.cjs.map +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryCache.js +120 -0
- package/build/legacy/queryCache.js.map +1 -1
- package/build/legacy/queryClient.cjs +363 -0
- 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 +363 -0
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryObserver.cjs +116 -2
- package/build/legacy/queryObserver.cjs.map +1 -1
- package/build/legacy/queryObserver.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/queryObserver.js +116 -2
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/legacy/retryer.cjs +18 -0
- package/build/legacy/retryer.cjs.map +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/retryer.js +18 -0
- package/build/legacy/retryer.js.map +1 -1
- package/build/legacy/streamedQuery.cjs +10 -1
- package/build/legacy/streamedQuery.cjs.map +1 -1
- package/build/legacy/streamedQuery.d.cts +26 -2
- package/build/legacy/streamedQuery.d.cts.map +1 -1
- package/build/legacy/streamedQuery.d.ts +26 -2
- package/build/legacy/streamedQuery.d.ts.map +1 -1
- package/build/legacy/streamedQuery.js +10 -1
- package/build/legacy/streamedQuery.js.map +1 -1
- package/build/legacy/timeoutManager.cjs +99 -0
- package/build/legacy/timeoutManager.cjs.map +1 -1
- package/build/legacy/timeoutManager.d.cts +105 -0
- package/build/legacy/timeoutManager.d.cts.map +1 -1
- package/build/legacy/timeoutManager.d.ts +105 -0
- package/build/legacy/timeoutManager.d.ts.map +1 -1
- package/build/legacy/timeoutManager.js +99 -0
- package/build/legacy/timeoutManager.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/utils.cjs +76 -0
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/legacy/utils.js +76 -0
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/environmentManager.cjs +15 -1
- package/build/modern/environmentManager.cjs.map +1 -1
- package/build/modern/environmentManager.d.cts +15 -1
- package/build/modern/environmentManager.d.cts.map +1 -1
- package/build/modern/environmentManager.d.ts +15 -1
- package/build/modern/environmentManager.d.ts.map +1 -1
- package/build/modern/environmentManager.js +15 -1
- package/build/modern/environmentManager.js.map +1 -1
- package/build/modern/focusManager.cjs +57 -0
- package/build/modern/focusManager.cjs.map +1 -1
- package/build/modern/focusManager.d.cts +57 -0
- package/build/modern/focusManager.d.cts.map +1 -1
- package/build/modern/focusManager.d.ts +57 -0
- package/build/modern/focusManager.d.ts.map +1 -1
- package/build/modern/focusManager.js +57 -0
- package/build/modern/focusManager.js.map +1 -1
- package/build/modern/{hydration-Bjs0MSgg.d.ts → hydration-Cq7QYAzB.d.ts} +1424 -7
- package/build/modern/hydration-Cq7QYAzB.d.ts.map +1 -0
- package/build/modern/{hydration-DWGr3cFC.d.cts → hydration-DwR10Hi-.d.cts} +1424 -7
- package/build/modern/hydration-DwR10Hi-.d.cts.map +1 -0
- package/build/modern/hydration.cjs +57 -4
- package/build/modern/hydration.cjs.map +1 -1
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/hydration.js +57 -4
- package/build/modern/hydration.js.map +1 -1
- package/build/modern/index.cjs.map +1 -1
- package/build/modern/index.d.cts +5 -5
- package/build/modern/index.d.ts +5 -5
- package/build/modern/index.js.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +1 -1
- package/build/modern/infiniteQueryObserver.cjs +67 -0
- package/build/modern/infiniteQueryObserver.cjs.map +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +68 -1
- package/build/modern/infiniteQueryObserver.d.cts.map +1 -1
- package/build/modern/infiniteQueryObserver.d.ts +68 -1
- package/build/modern/infiniteQueryObserver.d.ts.map +1 -1
- package/build/modern/infiniteQueryObserver.js +67 -0
- package/build/modern/infiniteQueryObserver.js.map +1 -1
- package/build/modern/mutation.cjs +74 -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 +74 -0
- package/build/modern/mutation.js.map +1 -1
- package/build/modern/mutationCache.cjs +74 -0
- package/build/modern/mutationCache.cjs.map +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationCache.js +74 -0
- package/build/modern/mutationCache.js.map +1 -1
- package/build/modern/mutationObserver.cjs +71 -0
- package/build/modern/mutationObserver.cjs.map +1 -1
- package/build/modern/mutationObserver.d.cts +1 -1
- package/build/modern/mutationObserver.d.ts +1 -1
- package/build/modern/mutationObserver.js +71 -0
- package/build/modern/mutationObserver.js.map +1 -1
- package/build/modern/notifyManager.cjs +45 -1
- package/build/modern/notifyManager.cjs.map +1 -1
- package/build/modern/notifyManager.d.cts +83 -2
- package/build/modern/notifyManager.d.cts.map +1 -1
- package/build/modern/notifyManager.d.ts +83 -2
- package/build/modern/notifyManager.d.ts.map +1 -1
- package/build/modern/notifyManager.js +45 -1
- package/build/modern/notifyManager.js.map +1 -1
- package/build/modern/onlineManager.cjs +47 -0
- package/build/modern/onlineManager.cjs.map +1 -1
- package/build/modern/onlineManager.d.cts +47 -0
- package/build/modern/onlineManager.d.cts.map +1 -1
- package/build/modern/onlineManager.d.ts +47 -0
- package/build/modern/onlineManager.d.ts.map +1 -1
- package/build/modern/onlineManager.js +47 -0
- package/build/modern/onlineManager.js.map +1 -1
- package/build/modern/queriesObserver.cjs +64 -0
- package/build/modern/queriesObserver.cjs.map +1 -1
- package/build/modern/queriesObserver.d.cts +73 -1
- package/build/modern/queriesObserver.d.cts.map +1 -1
- package/build/modern/queriesObserver.d.ts +73 -1
- package/build/modern/queriesObserver.d.ts.map +1 -1
- package/build/modern/queriesObserver.js +64 -0
- package/build/modern/queriesObserver.js.map +1 -1
- package/build/modern/query.cjs +141 -0
- 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 +141 -0
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryCache.cjs +120 -0
- package/build/modern/queryCache.cjs.map +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryCache.js +120 -0
- package/build/modern/queryCache.js.map +1 -1
- package/build/modern/queryClient.cjs +363 -0
- 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 +363 -0
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryObserver.cjs +116 -2
- package/build/modern/queryObserver.cjs.map +1 -1
- package/build/modern/queryObserver.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/queryObserver.js +116 -2
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/retryer.cjs +18 -0
- package/build/modern/retryer.cjs.map +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/retryer.js +18 -0
- package/build/modern/retryer.js.map +1 -1
- package/build/modern/streamedQuery.cjs +10 -1
- package/build/modern/streamedQuery.cjs.map +1 -1
- package/build/modern/streamedQuery.d.cts +26 -2
- package/build/modern/streamedQuery.d.cts.map +1 -1
- package/build/modern/streamedQuery.d.ts +26 -2
- package/build/modern/streamedQuery.d.ts.map +1 -1
- package/build/modern/streamedQuery.js +10 -1
- package/build/modern/streamedQuery.js.map +1 -1
- package/build/modern/timeoutManager.cjs +99 -0
- package/build/modern/timeoutManager.cjs.map +1 -1
- package/build/modern/timeoutManager.d.cts +105 -0
- package/build/modern/timeoutManager.d.cts.map +1 -1
- package/build/modern/timeoutManager.d.ts +105 -0
- package/build/modern/timeoutManager.d.ts.map +1 -1
- package/build/modern/timeoutManager.js +99 -0
- package/build/modern/timeoutManager.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/types.js.map +1 -1
- package/build/modern/utils.cjs +76 -0
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/build/modern/utils.js +76 -0
- package/build/modern/utils.js.map +1 -1
- package/package.json +9 -9
- package/src/environmentManager.ts +15 -1
- package/src/focusManager.ts +57 -0
- package/src/hydration.ts +82 -16
- package/src/index.ts +3 -0
- package/src/infiniteQueryObserver.ts +67 -0
- package/src/mutation.ts +108 -0
- package/src/mutationCache.ts +91 -0
- package/src/mutationObserver.ts +71 -0
- package/src/notifyManager.ts +46 -1
- package/src/onlineManager.ts +47 -0
- package/src/queriesObserver.ts +72 -0
- package/src/query.ts +193 -0
- package/src/queryCache.ts +134 -0
- package/src/queryClient.ts +369 -0
- package/src/queryObserver.ts +117 -4
- package/src/retryer.ts +18 -0
- package/src/streamedQuery.ts +25 -1
- package/src/timeoutManager.ts +105 -0
- package/src/types.ts +147 -5
- package/src/utils.ts +107 -0
- package/build/legacy/hydration-Bjs0MSgg.d.ts.map +0 -1
- package/build/legacy/hydration-DWGr3cFC.d.cts.map +0 -1
- package/build/modern/hydration-Bjs0MSgg.d.ts.map +0 -1
- package/build/modern/hydration-DWGr3cFC.d.cts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["import { timeoutManager } from './timeoutManager'\nimport type {\n DefaultError,\n FetchStatus,\n MutationKey,\n MutationStatus,\n QueryFunction,\n QueryKey,\n QueryOptions,\n} from './types'\nimport type { Mutation } from './mutation'\nimport type { FetchOptions, Query } from './query'\n\n// TYPES\n\ntype DropLast<T extends ReadonlyArray<unknown>> = T extends readonly [\n ...infer R,\n unknown,\n]\n ? readonly [...R]\n : never\n\ntype TuplePrefixes<T extends ReadonlyArray<unknown>> = T extends readonly []\n ? readonly []\n : TuplePrefixes<DropLast<T>> | T\n\nexport interface QueryFilters<TQueryKey extends QueryKey = QueryKey> {\n /**\n * Filter to active queries, inactive queries or all queries\n */\n type?: QueryTypeFilter\n /**\n * Match query key exactly\n */\n exact?: boolean\n /**\n * Include queries matching this predicate function\n */\n predicate?: (query: Query) => boolean\n /**\n * Include queries matching this query key\n */\n queryKey?: TQueryKey | TuplePrefixes<TQueryKey>\n /**\n * Include or exclude stale queries\n */\n stale?: boolean\n /**\n * Include queries matching their fetchStatus\n */\n fetchStatus?: FetchStatus\n}\n\nexport interface MutationFilters<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> {\n /**\n * Match mutation key exactly\n */\n exact?: boolean\n /**\n * Include mutations matching this predicate function\n */\n predicate?: (\n mutation: Mutation<TData, TError, TVariables, TOnMutateResult>,\n ) => boolean\n /**\n * Include mutations matching this mutation key\n */\n mutationKey?: TuplePrefixes<MutationKey>\n /**\n * Filter by mutation status\n */\n status?: MutationStatus\n}\n\nexport type Updater<TInput, TOutput> = TOutput | ((input: TInput) => TOutput)\n\nexport type QueryTypeFilter = 'all' | 'active' | 'inactive'\n\n// UTILS\n\n/** @deprecated\n * use `environmentManager.isServer()` instead.\n */\nexport const isServer = typeof window === 'undefined' || 'Deno' in globalThis\n\nexport function noop(): void\nexport function noop(): undefined\nexport function noop() {}\n\nexport function functionalUpdate<TInput, TOutput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as (_: TInput) => TOutput)(input)\n : updater\n}\n\nexport function isValidTimeout(value: unknown): value is number {\n return typeof value === 'number' && value >= 0 && value !== Infinity\n}\n\nexport function timeUntilStale(updatedAt: number, staleTime?: number): number {\n return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0)\n}\n\nexport function resolveQueryValue<\n TValue,\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n value:\n | undefined\n | TValue\n | ((query: Query<TQueryFnData, TError, TData, TQueryKey>) => TValue),\n query: Query<TQueryFnData, TError, TData, TQueryKey>,\n): TValue | undefined {\n return typeof value === 'function'\n ? (\n value as (\n query: Query<TQueryFnData, TError, TData, TQueryKey>,\n ) => TValue\n )(query)\n : value\n}\n\nexport function matchQuery(\n filters: QueryFilters,\n query: Query<any, any, any, any>,\n): boolean {\n const {\n type = 'all',\n exact,\n fetchStatus,\n predicate,\n queryKey,\n stale,\n } = filters\n\n if (queryKey) {\n if (exact) {\n if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {\n return false\n }\n } else if (!partialMatchKey(query.queryKey, queryKey)) {\n return false\n }\n }\n\n if (type !== 'all') {\n const isActive = query.isActive()\n if (type === 'active' && !isActive) {\n return false\n }\n if (type === 'inactive' && isActive) {\n return false\n }\n }\n\n if (typeof stale === 'boolean' && query.isStale() !== stale) {\n return false\n }\n\n if (fetchStatus && fetchStatus !== query.state.fetchStatus) {\n return false\n }\n\n if (predicate && !predicate(query)) {\n return false\n }\n\n return true\n}\n\nexport function matchMutation(\n filters: MutationFilters,\n mutation: Mutation<any, any>,\n): boolean {\n const { exact, status, predicate, mutationKey } = filters\n if (mutationKey) {\n if (!mutation.options.mutationKey) {\n return false\n }\n if (exact) {\n if (hashKey(mutation.options.mutationKey) !== hashKey(mutationKey)) {\n return false\n }\n } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {\n return false\n }\n }\n\n if (status && mutation.state.status !== status) {\n return false\n }\n\n if (predicate && !predicate(mutation)) {\n return false\n }\n\n return true\n}\n\nexport function hashQueryKeyByOptions<TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n options?: Pick<QueryOptions<any, any, any, any>, 'queryKeyHashFn'>,\n): string {\n const hashFn = options?.queryKeyHashFn || hashKey\n return hashFn(queryKey)\n}\n\n/**\n * Default query & mutation keys hash function.\n * Hashes the value into a stable hash.\n */\nexport function hashKey(queryKey: QueryKey | MutationKey): string {\n return JSON.stringify(queryKey, (_, val) =>\n isPlainObject(val)\n ? Object.keys(val)\n .sort()\n .reduce((result, key) => {\n result[key] = val[key]\n return result\n }, {} as any)\n : val,\n )\n}\n\n/**\n * Checks if key `b` partially matches with key `a`.\n */\nexport function partialMatchKey(a: QueryKey, b: QueryKey): boolean\nexport function partialMatchKey(a: any, b: any): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (a && b && typeof a === 'object' && typeof b === 'object') {\n if (Array.isArray(a) && Array.isArray(b)) {\n for (let i = 0; i < b.length; i++) {\n if (!partialMatchKey(a[i], b[i])) {\n return false\n }\n }\n return true\n }\n\n const bKeys = Object.keys(b)\n for (const key of bKeys) {\n if (!partialMatchKey(a[key], b[key])) {\n return false\n }\n }\n return true\n }\n\n return false\n}\n\nconst hasOwn = Object.prototype.hasOwnProperty\n\n/**\n * This function returns `a` if `b` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between JSON values for example.\n */\nexport function replaceEqualDeep<T>(a: unknown, b: T, depth?: number): T\nexport function replaceEqualDeep(a: any, b: any, depth = 0): any {\n if (a === b) {\n return a\n }\n\n if (depth > 500) return b\n\n const array = isPlainArray(a) && isPlainArray(b)\n\n if (!array && !(isPlainObject(a) && isPlainObject(b))) return b\n\n const aItems = array ? a : Object.keys(a)\n const aSize = aItems.length\n const bItems = array ? b : Object.keys(b)\n const bSize = bItems.length\n const copy: any = array ? new Array(bSize) : {}\n\n let equalItems = 0\n\n for (let i = 0; i < bSize; i++) {\n const key: any = array ? i : bItems[i]\n const aItem = a[key]\n const bItem = b[key]\n\n if (aItem === bItem) {\n copy[key] = aItem\n if (array ? i < aSize : hasOwn.call(a, key)) equalItems++\n continue\n }\n\n if (\n aItem === null ||\n bItem === null ||\n typeof aItem !== 'object' ||\n typeof bItem !== 'object'\n ) {\n copy[key] = bItem\n continue\n }\n\n const v = replaceEqualDeep(aItem, bItem, depth + 1)\n copy[key] = v\n if (v === aItem) equalItems++\n }\n\n return aSize === bSize && equalItems === aSize ? a : copy\n}\n\n/**\n * Shallow compare objects.\n */\nexport function shallowEqualObjects<T extends Record<string, any>>(\n a: T,\n b: T | undefined,\n): boolean {\n if (!b || Object.keys(a).length !== Object.keys(b).length) {\n return false\n }\n\n for (const key in a) {\n if (a[key] !== b[key]) {\n return false\n }\n }\n\n return true\n}\n\nexport function isPlainArray(value: unknown): value is Array<unknown> {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any): o is Record<PropertyKey, unknown> {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has no constructor\n const ctor = o.constructor\n if (ctor === undefined) {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Handles Objects created by Object.create(<arbitrary prototype>)\n if (Object.getPrototypeOf(o) !== Object.prototype) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any): boolean {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function sleep(timeout: number): Promise<void> {\n return new Promise((resolve) => {\n timeoutManager.setTimeout(resolve, timeout)\n })\n}\n\nexport function replaceData<\n TData,\n TOptions extends QueryOptions<any, any, any, any>,\n>(prevData: TData | undefined, data: TData, options: TOptions): TData {\n if (typeof options.structuralSharing === 'function') {\n return options.structuralSharing(prevData, data) as TData\n } else if (options.structuralSharing !== false) {\n if (process.env.NODE_ENV !== 'production') {\n try {\n return replaceEqualDeep(prevData, data)\n } catch (error) {\n console.error(\n `Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${options.queryHash}]: ${error}`,\n )\n\n // Prevent the replaceEqualDeep from being called again down below.\n throw error\n }\n }\n // Structurally share data between prev and new data if needed\n return replaceEqualDeep(prevData, data)\n }\n return data\n}\n\nexport function keepPreviousData<T>(\n previousData: T | undefined,\n): T | undefined {\n return previousData\n}\n\nexport function addToEnd<T>(items: Array<T>, item: T, max = 0): Array<T> {\n const newItems = [...items, item]\n return max && newItems.length > max ? newItems.slice(1) : newItems\n}\n\nexport function addToStart<T>(items: Array<T>, item: T, max = 0): Array<T> {\n const newItems = [item, ...items]\n return max && newItems.length > max ? newItems.slice(0, -1) : newItems\n}\n\nexport const skipToken = Symbol()\nexport type SkipToken = typeof skipToken\n\nexport function ensureQueryFn<\n TQueryFnData = unknown,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: {\n queryFn?: QueryFunction<TQueryFnData, TQueryKey> | SkipToken\n queryHash?: string\n },\n fetchOptions?: FetchOptions<TQueryFnData>,\n): QueryFunction<TQueryFnData, TQueryKey> {\n if (process.env.NODE_ENV !== 'production') {\n if (options.queryFn === skipToken) {\n console.error(\n `Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${options.queryHash}'`,\n )\n }\n }\n\n // if we attempt to retry a fetch that was triggered from an initialPromise\n // when we don't have a queryFn yet, we can't retry, so we just return the already rejected initialPromise\n // if an observer has already mounted, we will be able to retry with that queryFn\n if (!options.queryFn && fetchOptions?.initialPromise) {\n return () => fetchOptions.initialPromise!\n }\n\n if (!options.queryFn || options.queryFn === skipToken) {\n return () =>\n Promise.reject(new Error(`Missing queryFn: '${options.queryHash}'`))\n }\n\n return options.queryFn\n}\n\nexport function shouldThrowError<T extends (...args: Array<any>) => boolean>(\n throwOnError: boolean | T | undefined,\n params: Parameters<T>,\n): boolean {\n // Allow throwOnError function to override throwing behavior on a per-error basis\n if (typeof throwOnError === 'function') {\n return throwOnError(...params)\n }\n\n return !!throwOnError\n}\n\nexport function addConsumeAwareSignal<T>(\n object: T,\n getSignal: () => AbortSignal,\n onCancelled: VoidFunction,\n): T & { signal: AbortSignal } {\n let consumed = false\n let signal: AbortSignal | undefined\n\n Object.defineProperty(object, 'signal', {\n enumerable: true,\n get: () => {\n signal ??= getSignal()\n if (consumed) {\n return signal\n }\n\n consumed = true\n if (signal.aborted) {\n onCancelled()\n } else {\n signal.addEventListener('abort', onCancelled, { once: true })\n }\n\n return signal\n },\n })\n\n return object as T & { signal: AbortSignal }\n}\n"],"mappings":";;;;;AAwFA,MAAa,WAAW,OAAO,WAAW,eAAe,UAAU;AAInE,SAAgB,OAAO,CAAC;AAExB,SAAgB,iBACd,SACA,OACS;CACT,OAAO,OAAO,YAAY,aACrB,QAAmC,KAAK,IACzC;AACN;AAEA,SAAgB,eAAe,OAAiC;CAC9D,OAAO,OAAO,UAAU,YAAY,SAAS,KAAK,UAAU;AAC9D;AAEA,SAAgB,eAAe,WAAmB,WAA4B;CAC5E,OAAO,KAAK,IAAI,aAAa,aAAa,KAAK,KAAK,IAAI,GAAG,CAAC;AAC9D;AAEA,SAAgB,kBAOd,OAIA,OACoB;CACpB,OAAO,OAAO,UAAU,aAElB,MAGA,KAAK,IAC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;EACZ,WAAW;GACT,WAAW,UAAU;GACrB,IAAI,UACF,OAAO;GAGT,WAAW;GACX,IAAI,OAAO,SACT,YAAY;QAEZ,OAAO,iBAAiB,SAAS,aAAa,EAAE,MAAM,KAAK,CAAC;GAG9D,OAAO;EACT;CACF,CAAC;CAED,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["import { timeoutManager } from './timeoutManager'\nimport type {\n DefaultError,\n FetchStatus,\n MutationKey,\n MutationStatus,\n QueryFunction,\n QueryKey,\n QueryOptions,\n} from './types'\nimport type { Mutation } from './mutation'\nimport type { FetchOptions, Query } from './query'\n\n// TYPES\n\ntype DropLast<T extends ReadonlyArray<unknown>> = T extends readonly [\n ...infer R,\n unknown,\n]\n ? readonly [...R]\n : never\n\ntype TuplePrefixes<T extends ReadonlyArray<unknown>> = T extends readonly []\n ? readonly []\n : TuplePrefixes<DropLast<T>> | T\n\n/**\n * Filters used to select queries, for example in `queryClient.getQueriesData` or `queryClient.invalidateQueries`.\n * All provided filters must match; filters that are left unspecified are ignored.\n */\nexport interface QueryFilters<TQueryKey extends QueryKey = QueryKey> {\n /**\n * Filter to active queries, inactive queries or all queries\n *\n * Defaults to `'all'`.\n */\n type?: QueryTypeFilter\n /**\n * Match query key exactly\n */\n exact?: boolean\n /**\n * Include queries matching this predicate function\n */\n predicate?: (query: Query) => boolean\n /**\n * Include queries matching this query key\n */\n queryKey?: TQueryKey | TuplePrefixes<TQueryKey>\n /**\n * Include or exclude stale queries\n */\n stale?: boolean\n /**\n * Include queries matching their fetchStatus\n */\n fetchStatus?: FetchStatus\n}\n\n/**\n * Filters used to select mutations, for example in `mutationCache.findAll` or `queryClient.isMutating`.\n * All provided filters must match; filters that are left unspecified are ignored.\n */\nexport interface MutationFilters<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> {\n /**\n * Match mutation key exactly\n */\n exact?: boolean\n /**\n * Include mutations matching this predicate function\n */\n predicate?: (\n mutation: Mutation<TData, TError, TVariables, TOnMutateResult>,\n ) => boolean\n /**\n * Include mutations matching this mutation key\n */\n mutationKey?: TuplePrefixes<MutationKey>\n /**\n * Filter by mutation status\n */\n status?: MutationStatus\n}\n\n/**\n * Either a plain value of type `TOutput`, or a function that receives `TInput` and returns `TOutput`.\n * Used for example by `setQueryData`-style updaters, which accept either the new data directly or a\n * function that computes it from the previous data. See {@link functionalUpdate}.\n *\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) =>\n * oldPosts ? [...oldPosts, newPost] : oldPosts,\n * )\n * ```\n */\nexport type Updater<TInput, TOutput> = TOutput | ((input: TInput) => TOutput)\n\nexport type QueryTypeFilter = 'all' | 'active' | 'inactive'\n\n// UTILS\n\n/** @deprecated\n * use `environmentManager.isServer()` instead.\n */\nexport const isServer = typeof window === 'undefined' || 'Deno' in globalThis\n\n/**\n * A function that does nothing.\n */\nexport function noop(): void\nexport function noop(): undefined\nexport function noop() {}\n\nexport function functionalUpdate<TInput, TOutput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as (_: TInput) => TOutput)(input)\n : updater\n}\n\nexport function isValidTimeout(value: unknown): value is number {\n return typeof value === 'number' && value >= 0 && value !== Infinity\n}\n\nexport function timeUntilStale(updatedAt: number, staleTime?: number): number {\n return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0)\n}\n\nexport function resolveQueryValue<\n TValue,\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n value:\n | undefined\n | TValue\n | ((query: Query<TQueryFnData, TError, TData, TQueryKey>) => TValue),\n query: Query<TQueryFnData, TError, TData, TQueryKey>,\n): TValue | undefined {\n return typeof value === 'function'\n ? (\n value as (\n query: Query<TQueryFnData, TError, TData, TQueryKey>,\n ) => TValue\n )(query)\n : value\n}\n\n/**\n * Checks whether a query matches the given {@link QueryFilters}.\n * Every filter that is specified must match; filters that are left unspecified are ignored.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const matchingQueries = queryCache\n * .getAll()\n * .filter((query) => matchQuery({ queryKey: ['posts'] }, query))\n * ```\n */\nexport function matchQuery(\n filters: QueryFilters,\n query: Query<any, any, any, any>,\n): boolean {\n const {\n type = 'all',\n exact,\n fetchStatus,\n predicate,\n queryKey,\n stale,\n } = filters\n\n if (queryKey) {\n if (exact) {\n if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {\n return false\n }\n } else if (!partialMatchKey(query.queryKey, queryKey)) {\n return false\n }\n }\n\n if (type !== 'all') {\n const isActive = query.isActive()\n if (type === 'active' && !isActive) {\n return false\n }\n if (type === 'inactive' && isActive) {\n return false\n }\n }\n\n if (typeof stale === 'boolean' && query.isStale() !== stale) {\n return false\n }\n\n if (fetchStatus && fetchStatus !== query.state.fetchStatus) {\n return false\n }\n\n if (predicate && !predicate(query)) {\n return false\n }\n\n return true\n}\n\n/**\n * Checks whether a mutation matches the given {@link MutationFilters}.\n * Every filter that is specified must match; filters that are left unspecified are ignored.\n * If a `mutationKey` filter is provided but the mutation has no `mutationKey` of its own, it does not match.\n *\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const matchingMutations = mutationCache\n * .getAll()\n * .filter((mutation) => matchMutation({ mutationKey: ['addPost'] }, mutation))\n * ```\n */\nexport function matchMutation(\n filters: MutationFilters,\n mutation: Mutation<any, any>,\n): boolean {\n const { exact, status, predicate, mutationKey } = filters\n if (mutationKey) {\n if (!mutation.options.mutationKey) {\n return false\n }\n if (exact) {\n if (hashKey(mutation.options.mutationKey) !== hashKey(mutationKey)) {\n return false\n }\n } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {\n return false\n }\n }\n\n if (status && mutation.state.status !== status) {\n return false\n }\n\n if (predicate && !predicate(mutation)) {\n return false\n }\n\n return true\n}\n\nexport function hashQueryKeyByOptions<TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n options?: Pick<QueryOptions<any, any, any, any>, 'queryKeyHashFn'>,\n): string {\n const hashFn = options?.queryKeyHashFn || hashKey\n return hashFn(queryKey)\n}\n\n/**\n * Default query & mutation keys hash function.\n * Hashes the value into a stable hash.\n *\n * @example\n * ```ts\n * // Object keys are sorted, so key order doesn't affect the hash:\n * hashKey(['todos', { page: 1, filter: 'done' }]) // === '[\"todos\",{\"filter\":\"done\",\"page\":1}]'\n * ```\n */\nexport function hashKey(queryKey: QueryKey | MutationKey): string {\n return JSON.stringify(queryKey, (_, val) =>\n isPlainObject(val)\n ? Object.keys(val)\n .sort()\n .reduce((result, key) => {\n result[key] = val[key]\n return result\n }, {} as any)\n : val,\n )\n}\n\n/**\n * Checks if key `b` partially matches with key `a`.\n */\nexport function partialMatchKey(a: QueryKey, b: QueryKey): boolean\nexport function partialMatchKey(a: any, b: any): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (a && b && typeof a === 'object' && typeof b === 'object') {\n if (Array.isArray(a) && Array.isArray(b)) {\n if (b.length > a.length) return false\n for (let i = 0; i < b.length; i++) {\n if (!partialMatchKey(a[i], b[i])) {\n return false\n }\n }\n return true\n }\n\n const bKeys = Object.keys(b)\n for (const key of bKeys) {\n if (!partialMatchKey(a[key], b[key])) {\n return false\n }\n }\n return true\n }\n\n return false\n}\n\nconst hasOwn = Object.prototype.hasOwnProperty\n\n/**\n * This function returns `a` if `b` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between JSON values for example.\n */\nexport function replaceEqualDeep<T>(a: unknown, b: T, depth?: number): T\nexport function replaceEqualDeep(a: any, b: any, depth = 0): any {\n if (a === b) {\n return a\n }\n\n if (depth > 500) return b\n\n const array = isPlainArray(a) && isPlainArray(b)\n\n if (!array && !(isPlainObject(a) && isPlainObject(b))) return b\n\n const aItems = array ? a : Object.keys(a)\n const aSize = aItems.length\n const bItems = array ? b : Object.keys(b)\n const bSize = bItems.length\n const copy: any = array ? new Array(bSize) : {}\n\n let equalItems = 0\n\n for (let i = 0; i < bSize; i++) {\n const key: any = array ? i : bItems[i]\n const aItem = a[key]\n const bItem = b[key]\n\n if (aItem === bItem) {\n copy[key] = aItem\n if (array ? i < aSize : hasOwn.call(a, key)) equalItems++\n continue\n }\n\n if (\n aItem === null ||\n bItem === null ||\n typeof aItem !== 'object' ||\n typeof bItem !== 'object'\n ) {\n copy[key] = bItem\n continue\n }\n\n const v = replaceEqualDeep(aItem, bItem, depth + 1)\n copy[key] = v\n if (v === aItem) equalItems++\n }\n\n return aSize === bSize && equalItems === aSize ? a : copy\n}\n\n/**\n * Shallow compare objects.\n */\nexport function shallowEqualObjects<T extends Record<string, any>>(\n a: T,\n b: T | undefined,\n): boolean {\n if (!b || Object.keys(a).length !== Object.keys(b).length) {\n return false\n }\n\n for (const key in a) {\n if (a[key] !== b[key]) {\n return false\n }\n }\n\n return true\n}\n\nexport function isPlainArray(value: unknown): value is Array<unknown> {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any): o is Record<PropertyKey, unknown> {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has no constructor\n const ctor = o.constructor\n if (ctor === undefined) {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Handles Objects created by Object.create(<arbitrary prototype>)\n if (Object.getPrototypeOf(o) !== Object.prototype) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any): boolean {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function sleep(timeout: number): Promise<void> {\n return new Promise((resolve) => {\n timeoutManager.setTimeout(resolve, timeout)\n })\n}\n\nexport function replaceData<\n TData,\n TOptions extends QueryOptions<any, any, any, any>,\n>(prevData: TData | undefined, data: TData, options: TOptions): TData {\n if (typeof options.structuralSharing === 'function') {\n return options.structuralSharing(prevData, data) as TData\n } else if (options.structuralSharing !== false) {\n if (process.env.NODE_ENV !== 'production') {\n try {\n return replaceEqualDeep(prevData, data)\n } catch (error) {\n console.error(\n `Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${options.queryHash}]: ${error}`,\n )\n\n // Prevent the replaceEqualDeep from being called again down below.\n throw error\n }\n }\n // Structurally share data between prev and new data if needed\n return replaceEqualDeep(prevData, data)\n }\n return data\n}\n\n/**\n * Intended to be passed as a query's `placeholderData` option, for example\n * `placeholderData: keepPreviousData`. Instead of resetting the query's data to `undefined` while a new\n * query key is fetching, it keeps displaying the previously fetched data until the new data arrives.\n *\n * @example\n * ```ts\n * new QueryObserver(queryClient, {\n * queryKey: ['posts', page],\n * queryFn: () => fetchPosts(page),\n * placeholderData: keepPreviousData,\n * })\n * ```\n */\nexport function keepPreviousData<T>(\n previousData: T | undefined,\n): T | undefined {\n return previousData\n}\n\nexport function addToEnd<T>(items: Array<T>, item: T, max = 0): Array<T> {\n const newItems = [...items, item]\n return max && newItems.length > max ? newItems.slice(1) : newItems\n}\n\nexport function addToStart<T>(items: Array<T>, item: T, max = 0): Array<T> {\n const newItems = [item, ...items]\n return max && newItems.length > max ? newItems.slice(0, -1) : newItems\n}\n\n/**\n * Sentinel value that can be passed as a query's `queryFn` to conditionally disable the query (equivalent\n * to `enabled: false`) while preserving full type inference for the query's data. Unlike `enabled: false`,\n * a query disabled via `skipToken` cannot be triggered with `refetch`.\n *\n * @example\n * ```ts\n * new QueryObserver(queryClient, {\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * })\n * ```\n */\nexport const skipToken = Symbol()\n/**\n * The type of the {@link skipToken} sentinel value.\n */\nexport type SkipToken = typeof skipToken\n\nexport function ensureQueryFn<\n TQueryFnData = unknown,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: {\n queryFn?: QueryFunction<TQueryFnData, TQueryKey> | SkipToken\n queryHash?: string\n },\n fetchOptions?: FetchOptions<TQueryFnData>,\n): QueryFunction<TQueryFnData, TQueryKey> {\n if (process.env.NODE_ENV !== 'production') {\n if (options.queryFn === skipToken) {\n console.error(\n `Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${options.queryHash}'`,\n )\n }\n }\n\n // if we attempt to retry a fetch that was triggered from an initialPromise\n // when we don't have a queryFn yet, we can't retry, so we just return the already rejected initialPromise\n // if an observer has already mounted, we will be able to retry with that queryFn\n if (!options.queryFn && fetchOptions?.initialPromise) {\n return () => fetchOptions.initialPromise!\n }\n\n if (!options.queryFn || options.queryFn === skipToken) {\n return () =>\n Promise.reject(new Error(`Missing queryFn: '${options.queryHash}'`))\n }\n\n return options.queryFn\n}\n\n/**\n * Resolves a `throwOnError` option to a boolean.\n * If `throwOnError` is a function, it is called with `params` (e.g. the error and, depending on the caller,\n * additional context such as the query or mutation) and its result is returned, allowing the throwing\n * behavior to be decided per error. Otherwise, `throwOnError` itself is coerced to a boolean (`undefined`\n * resolves to `false`).\n *\n * @example\n * ```ts\n * const throwOnError =\n * query.state.error && typeof options.throwOnError === 'function'\n * ? shouldThrowError(options.throwOnError, [query.state.error, query])\n * : options.throwOnError\n * ```\n */\nexport function shouldThrowError<T extends (...args: Array<any>) => boolean>(\n throwOnError: boolean | T | undefined,\n params: Parameters<T>,\n): boolean {\n // Allow throwOnError function to override throwing behavior on a per-error basis\n if (typeof throwOnError === 'function') {\n return throwOnError(...params)\n }\n\n return !!throwOnError\n}\n\nexport function addConsumeAwareSignal<T>(\n object: T,\n getSignal: () => AbortSignal,\n onCancelled: VoidFunction,\n): T & { signal: AbortSignal } {\n let consumed = false\n let signal: AbortSignal | undefined\n\n Object.defineProperty(object, 'signal', {\n enumerable: true,\n get: () => {\n signal ??= getSignal()\n if (consumed) {\n return signal\n }\n\n consumed = true\n if (signal.aborted) {\n onCancelled()\n } else {\n signal.addEventListener('abort', onCancelled, { once: true })\n }\n\n return signal\n },\n })\n\n return object as T & { signal: AbortSignal }\n}\n"],"mappings":";;;;;AAiHA,MAAa,WAAW,OAAO,WAAW,eAAe,UAAU;AAOnE,SAAgB,OAAO,CAAC;AAExB,SAAgB,iBACd,SACA,OACS;CACT,OAAO,OAAO,YAAY,aACrB,QAAmC,KAAK,IACzC;AACN;AAEA,SAAgB,eAAe,OAAiC;CAC9D,OAAO,OAAO,UAAU,YAAY,SAAS,KAAK,UAAU;AAC9D;AAEA,SAAgB,eAAe,WAAmB,WAA4B;CAC5E,OAAO,KAAK,IAAI,aAAa,aAAa,KAAK,KAAK,IAAI,GAAG,CAAC;AAC9D;AAEA,SAAgB,kBAOd,OAIA,OACoB;CACpB,OAAO,OAAO,UAAU,aAElB,MAGA,KAAK,IACP;AACN;;;;;;;;;;;;;;AAeA,SAAgB,WACd,SACA,OACS;CACT,MAAM,EACJ,OAAO,OACP,OACA,aACA,WACA,UACA,UACE;CAEJ,IAAI,UAAU;EACZ,IAAI,OACE;OAAA,MAAM,cAAc,sBAAsB,UAAU,MAAM,OAAO,GACnE,OAAO;EAAA,OAEJ,IAAI,CAAC,gBAAgB,MAAM,UAAU,QAAQ,GAClD,OAAO;CAEX;CAEA,IAAI,SAAS,OAAO;EAClB,MAAM,WAAW,MAAM,SAAS;EAChC,IAAI,SAAS,YAAY,CAAC,UACxB,OAAO;EAET,IAAI,SAAS,cAAc,UACzB,OAAO;CAEX;CAEA,IAAI,OAAO,UAAU,aAAa,MAAM,QAAQ,MAAM,OACpD,OAAO;CAGT,IAAI,eAAe,gBAAgB,MAAM,MAAM,aAC7C,OAAO;CAGT,IAAI,aAAa,CAAC,UAAU,KAAK,GAC/B,OAAO;CAGT,OAAO;AACT;;;;;;;;;;;;;;;AAgBA,SAAg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AAS,MAAM,GAAa;CACzE,MAAM,WAAW,CAAC,MAAM,GAAG,KAAK;CAChC,OAAO,OAAO,SAAS,SAAS,MAAM,SAAS,MAAM,GAAG,EAAE,IAAI;AAChE;;;;;;;;;;;;;;AAeA,MAAa,YAAY,OAAO;AAMhC,SAAgB,cAId,SAIA,cACwC;CACxC,IAAI,QAAQ,IAAI,aAAa,cACvB;MAAA,QAAQ,YAAY,WACtB,QAAQ,MACN,yGAAyG,QAAQ,UAAU,EAC7H;CAAA;CAOJ,IAAI,CAAC,QAAQ,WAAW,cAAc,gBACpC,aAAa,aAAa;CAG5B,IAAI,CAAC,QAAQ,WAAW,QAAQ,YAAY,WAC1C,aACE,QAAQ,uBAAO,IAAI,MAAM,qBAAqB,QAAQ,UAAU,EAAE,CAAC;CAGvE,OAAO,QAAQ;AACjB;;;;;;;;;;;;;;;;AAiBA,SAAgB,iBACd,cACA,QACS;CAET,IAAI,OAAO,iBAAiB,YAC1B,OAAO,aAAa,GAAG,MAAM;CAG/B,OAAO,CAAC,CAAC;AACX;AAEA,SAAgB,sBACd,QACA,WACA,aAC6B;CAC7B,IAAI,WAAW;CACf,IAAI;CAEJ,OAAO,eAAe,QAAQ,UAAU;EACtC,YAAY;EACZ,WAAW;GACT,WAAW,UAAU;GACrB,IAAI,UACF,OAAO;GAGT,WAAW;GACX,IAAI,OAAO,SACT,YAAY;QAEZ,OAAO,iBAAiB,SAAS,aAAa,EAAE,MAAM,KAAK,CAAC;GAG9D,OAAO;EACT;CACF,CAAC;CAED,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/query-core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.103.0",
|
|
4
4
|
"description": "The framework agnostic core that powers TanStack Query",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,16 +44,16 @@
|
|
|
44
44
|
"@tanstack/query-test-utils": "0.0.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
|
-
"clean": "premove ./build ./coverage ./dist-ts",
|
|
48
|
-
"compile": "tsc --
|
|
47
|
+
"clean": "premove ./build ./coverage ./dist-ts ./.cache/test-types",
|
|
48
|
+
"compile": "tsc --project tsconfig.json",
|
|
49
49
|
"test:eslint": "eslint --concurrency=auto ./src",
|
|
50
50
|
"test:types": "npm-run-all --serial test:types:*",
|
|
51
|
-
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --
|
|
52
|
-
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --
|
|
53
|
-
"test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --
|
|
54
|
-
"test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --
|
|
55
|
-
"test:types:tscurrent": "tsc --
|
|
56
|
-
"test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --
|
|
51
|
+
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts56 --tsBuildInfoFile .cache/test-types/ts56.tsbuildinfo",
|
|
52
|
+
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts57 --tsBuildInfoFile .cache/test-types/ts57.tsbuildinfo",
|
|
53
|
+
"test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts58 --tsBuildInfoFile .cache/test-types/ts58.tsbuildinfo",
|
|
54
|
+
"test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts59 --tsBuildInfoFile .cache/test-types/ts59.tsbuildinfo",
|
|
55
|
+
"test:types:tscurrent": "tsc --project tsconfig.json --outDir .cache/test-types/tscurrent --tsBuildInfoFile .cache/test-types/tscurrent.tsbuildinfo",
|
|
56
|
+
"test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
|
|
57
57
|
"test:lib": "vitest",
|
|
58
58
|
"test:lib:dev": "pnpm run test:lib --watch",
|
|
59
59
|
"test:build": "publint --strict && attw --pack",
|
|
@@ -10,7 +10,21 @@ let isServerFn: IsServerValue = () => defaultIsServer
|
|
|
10
10
|
export const isServer = (): boolean => isServerFn()
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Manages
|
|
13
|
+
* Manages how TanStack Query detects whether the current runtime should be treated as
|
|
14
|
+
* server-side, which disables scheduling refetch timers and changes the default `retry` count
|
|
15
|
+
* and `gcTime`. By default, the detection treats a missing `window` (or the presence of a
|
|
16
|
+
* `Deno` global) as server.
|
|
17
|
+
*
|
|
18
|
+
* Override this for runtimes where that default detection would give the wrong answer — for
|
|
19
|
+
* example, a Service Worker, where `window` is undefined even though the environment should
|
|
20
|
+
* behave like a client.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { environmentManager } from '@tanstack/query-core'
|
|
25
|
+
*
|
|
26
|
+
* environmentManager.setIsServer(() => false)
|
|
27
|
+
* ```
|
|
14
28
|
*/
|
|
15
29
|
export const environmentManager = {
|
|
16
30
|
isServer,
|
package/src/focusManager.ts
CHANGED
|
@@ -6,6 +6,11 @@ type SetupFn = (
|
|
|
6
6
|
setFocused: (focused?: boolean) => void,
|
|
7
7
|
) => (() => void) | undefined
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* The `FocusManager` manages the focus state within TanStack Query.
|
|
11
|
+
*
|
|
12
|
+
* It can be used to change the default event listeners or to manually change the focus state.
|
|
13
|
+
*/
|
|
9
14
|
export class FocusManager extends Subscribable<Listener> {
|
|
10
15
|
#focused?: boolean
|
|
11
16
|
#cleanup?: () => void
|
|
@@ -44,6 +49,31 @@ export class FocusManager extends Subscribable<Listener> {
|
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
51
|
|
|
52
|
+
/**
|
|
53
|
+
* `setEventListener` can be used to set a custom event listener that will
|
|
54
|
+
* be used to determine the focus state. The provided `setup` function
|
|
55
|
+
* receives a `setFocused` callback: call it with a `boolean` to manually
|
|
56
|
+
* set the focus state, or with no arguments to re-evaluate the current
|
|
57
|
+
* focus state and notify subscribers.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { focusManager } from '@tanstack/query-core'
|
|
62
|
+
*
|
|
63
|
+
* focusManager.setEventListener((handleFocus) => {
|
|
64
|
+
* const listener = () => handleFocus()
|
|
65
|
+
* // Listen to visibilitychange
|
|
66
|
+
* if (typeof window !== 'undefined' && window.addEventListener) {
|
|
67
|
+
* window.addEventListener('visibilitychange', listener, false)
|
|
68
|
+
* }
|
|
69
|
+
*
|
|
70
|
+
* return () => {
|
|
71
|
+
* // Be sure to unsubscribe if a new handler is set
|
|
72
|
+
* window.removeEventListener('visibilitychange', listener)
|
|
73
|
+
* }
|
|
74
|
+
* })
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
47
77
|
setEventListener(setup: SetupFn): void {
|
|
48
78
|
this.#setup = setup
|
|
49
79
|
this.#cleanup?.()
|
|
@@ -56,6 +86,24 @@ export class FocusManager extends Subscribable<Listener> {
|
|
|
56
86
|
})
|
|
57
87
|
}
|
|
58
88
|
|
|
89
|
+
/**
|
|
90
|
+
* `setFocused` can be used to manually set the focus state. Set `undefined`
|
|
91
|
+
* to fall back to the default focus check.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { focusManager } from '@tanstack/query-core'
|
|
96
|
+
*
|
|
97
|
+
* // Set focused
|
|
98
|
+
* focusManager.setFocused(true)
|
|
99
|
+
*
|
|
100
|
+
* // Set unfocused
|
|
101
|
+
* focusManager.setFocused(false)
|
|
102
|
+
*
|
|
103
|
+
* // Fallback to the default focus check
|
|
104
|
+
* focusManager.setFocused(undefined)
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
59
107
|
setFocused(focused?: boolean): void {
|
|
60
108
|
const changed = this.#focused !== focused
|
|
61
109
|
if (changed) {
|
|
@@ -64,6 +112,9 @@ export class FocusManager extends Subscribable<Listener> {
|
|
|
64
112
|
}
|
|
65
113
|
}
|
|
66
114
|
|
|
115
|
+
/**
|
|
116
|
+
* `onFocus` notifies all subscribed listeners with the current focus state.
|
|
117
|
+
*/
|
|
67
118
|
onFocus(): void {
|
|
68
119
|
const isFocused = this.isFocused()
|
|
69
120
|
this.listeners.forEach((listener) => {
|
|
@@ -71,6 +122,9 @@ export class FocusManager extends Subscribable<Listener> {
|
|
|
71
122
|
})
|
|
72
123
|
}
|
|
73
124
|
|
|
125
|
+
/**
|
|
126
|
+
* `isFocused` can be used to get the current focus state.
|
|
127
|
+
*/
|
|
74
128
|
isFocused(): boolean {
|
|
75
129
|
if (typeof this.#focused === 'boolean') {
|
|
76
130
|
return this.#focused
|
|
@@ -82,4 +136,7 @@ export class FocusManager extends Subscribable<Listener> {
|
|
|
82
136
|
}
|
|
83
137
|
}
|
|
84
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Singleton instance of {@link FocusManager}, used to manage and observe the focus state within TanStack Query.
|
|
141
|
+
*/
|
|
85
142
|
export const focusManager = new FocusManager()
|
package/src/hydration.ts
CHANGED
|
@@ -35,17 +35,36 @@ function tryResolveSync(promise: PromiseLike<unknown>) {
|
|
|
35
35
|
return undefined
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Options for `dehydrate`, controlling which queries/mutations are included in the resulting `DehydratedState` and
|
|
40
|
+
* how their data/errors are transformed before being serialized (e.g. for embedding in server-rendered markup).
|
|
41
|
+
*/
|
|
38
42
|
export interface DehydrateOptions {
|
|
43
|
+
/** Transforms a query's `data` before it is dehydrated. Useful for non-JSON-serializable data. */
|
|
39
44
|
serializeData?: TransformerFn
|
|
45
|
+
/** Predicate to decide whether a given `Mutation` should be dehydrated. Defaults to `defaultShouldDehydrateMutation`. */
|
|
40
46
|
shouldDehydrateMutation?: (mutation: Mutation) => boolean
|
|
47
|
+
/** Predicate to decide whether a given `Query` should be dehydrated. Defaults to `defaultShouldDehydrateQuery`. */
|
|
41
48
|
shouldDehydrateQuery?: (query: Query) => boolean
|
|
49
|
+
/**
|
|
50
|
+
* Predicate to decide whether a query's error should be redacted before dehydration. Errors are redacted
|
|
51
|
+
* (replaced with a generic `Error('redacted')`) unless this function is provided and returns `false` for the
|
|
52
|
+
* given error, in which case the original error is kept.
|
|
53
|
+
*/
|
|
42
54
|
shouldRedactErrors?: (error: unknown) => boolean
|
|
43
55
|
}
|
|
44
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Options for `hydrate`, controlling the default options applied to queries/mutations restored from a
|
|
59
|
+
* `DehydratedState`, and how to reverse any transformation applied by `DehydrateOptions.serializeData`.
|
|
60
|
+
*/
|
|
45
61
|
export interface HydrateOptions {
|
|
46
62
|
defaultOptions?: {
|
|
63
|
+
/** Transforms a query's `data` after it is read from the dehydrated state, reversing `serializeData`. */
|
|
47
64
|
deserializeData?: TransformerFn
|
|
65
|
+
/** Default options merged into every query restored from the dehydrated state. */
|
|
48
66
|
queries?: QueryOptions
|
|
67
|
+
/** Default options merged into every mutation restored from the dehydrated state. */
|
|
49
68
|
mutations?: MutationOptions<unknown, DefaultError, unknown, unknown>
|
|
50
69
|
}
|
|
51
70
|
}
|
|
@@ -61,15 +80,17 @@ interface DehydratedQuery {
|
|
|
61
80
|
queryHash: string
|
|
62
81
|
queryKey: QueryKey
|
|
63
82
|
state: QueryState
|
|
83
|
+
dehydratedAt: number
|
|
64
84
|
promise?: Promise<unknown>
|
|
65
85
|
meta?: QueryMeta
|
|
66
86
|
queryType?: 'infinite'
|
|
67
|
-
// This is only optional because older versions of Query might have dehydrated
|
|
68
|
-
// without it which we need to handle for backwards compatibility.
|
|
69
|
-
// This should be changed to required in the future.
|
|
70
|
-
dehydratedAt?: number
|
|
71
87
|
}
|
|
72
88
|
|
|
89
|
+
/**
|
|
90
|
+
* A serializable snapshot of a `QueryClient`'s cache, as produced by `dehydrate` and consumed by `hydrate`. Typically
|
|
91
|
+
* transported from server to client (e.g. embedded in server-rendered markup) to seed the client's cache with data
|
|
92
|
+
* that has already been fetched, avoiding a redundant fetch on the client.
|
|
93
|
+
*/
|
|
73
94
|
export interface DehydratedState {
|
|
74
95
|
mutations: Array<DehydratedMutation>
|
|
75
96
|
queries: Array<DehydratedQuery>
|
|
@@ -114,10 +135,16 @@ function dehydratePromise(
|
|
|
114
135
|
return promise
|
|
115
136
|
}
|
|
116
137
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Dehydrates a single `Query` into a serializable `DehydratedQuery` snapshot. Note that most query config (e.g.
|
|
140
|
+
* `queryFn`, `staleTime`) is not dehydrated but instead meant to be configured again when consuming the
|
|
141
|
+
* de/rehydrated data, typically with `useQuery` on the client. If the query is still `pending`, its in-flight
|
|
142
|
+
* promise is dehydrated too so it can be resumed on the other side instead of re-fetched.
|
|
143
|
+
* @param query - The query to dehydrate.
|
|
144
|
+
* @param serializeData - Optional transform applied to `query.state.data` before it is included in the snapshot.
|
|
145
|
+
* @param shouldRedactErrors - Optional predicate; if it returns `false` for the promise's rejection error, that
|
|
146
|
+
* error is kept as-is instead of being redacted.
|
|
147
|
+
*/
|
|
121
148
|
export function dehydrateQuery(
|
|
122
149
|
query: Query,
|
|
123
150
|
serializeData?: TransformerFn,
|
|
@@ -143,14 +170,40 @@ export function dehydrateQuery(
|
|
|
143
170
|
}
|
|
144
171
|
}
|
|
145
172
|
|
|
173
|
+
/**
|
|
174
|
+
* The default `shouldDehydrateMutation` predicate used by `dehydrate`. Only dehydrates mutations that are
|
|
175
|
+
* currently paused (e.g. paused by `networkMode` while offline).
|
|
176
|
+
*/
|
|
146
177
|
export function defaultShouldDehydrateMutation(mutation: Mutation) {
|
|
147
178
|
return mutation.state.isPaused
|
|
148
179
|
}
|
|
149
180
|
|
|
181
|
+
/**
|
|
182
|
+
* The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrates queries whose status is
|
|
183
|
+
* `'success'`.
|
|
184
|
+
*/
|
|
150
185
|
export function defaultShouldDehydrateQuery(query: Query) {
|
|
151
186
|
return query.state.status === 'success'
|
|
152
187
|
}
|
|
153
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Dehydrates a `QueryClient`'s cache (queries and mutations) into a plain, serializable `DehydratedState`,
|
|
191
|
+
* typically to embed in server-rendered markup and later restore into a client-side `QueryClient` via `hydrate`.
|
|
192
|
+
* Which queries/mutations are included, and how their data/errors are transformed, is controlled by `options`,
|
|
193
|
+
* falling back to the client's `dehydrate` default options, and finally to `defaultShouldDehydrateQuery` /
|
|
194
|
+
* `defaultShouldDehydrateMutation`.
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* const queryClient = new QueryClient()
|
|
198
|
+
*
|
|
199
|
+
* await queryClient.prefetchQuery({
|
|
200
|
+
* queryKey: ['posts'],
|
|
201
|
+
* queryFn: getPosts,
|
|
202
|
+
* })
|
|
203
|
+
*
|
|
204
|
+
* const dehydratedState = dehydrate(queryClient)
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
154
207
|
export function dehydrate(
|
|
155
208
|
client: QueryClient,
|
|
156
209
|
options: DehydrateOptions = {},
|
|
@@ -191,6 +244,23 @@ export function dehydrate(
|
|
|
191
244
|
return { mutations, queries }
|
|
192
245
|
}
|
|
193
246
|
|
|
247
|
+
/**
|
|
248
|
+
* Restores a `DehydratedState` (as produced by `dehydrate`) into a `QueryClient`'s cache, typically to seed the
|
|
249
|
+
* client with data already fetched on the server. `mutations` and `queries` are each optional on `dehydratedState`.
|
|
250
|
+
* Queries not yet in the cache are built from the dehydrated snapshot; queries that already exist are only updated
|
|
251
|
+
* when the dehydrated data is newer than what's already cached. Newly built queries have their `fetchStatus` reset
|
|
252
|
+
* to `'idle'` so they don't hydrate stuck in a fetching state. If a dehydrated query still had an in-flight
|
|
253
|
+
* promise, it is resumed via `query.fetch()` (reusing that promise as `initialPromise`) rather than re-invoking
|
|
254
|
+
* `queryFn`.
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* // dehydratedState was produced by `dehydrate` on the server
|
|
258
|
+
* // and sent to the client, e.g. embedded in server-rendered markup.
|
|
259
|
+
* const queryClient = new QueryClient()
|
|
260
|
+
*
|
|
261
|
+
* hydrate(queryClient, dehydratedState)
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
194
264
|
export function hydrate(
|
|
195
265
|
client: QueryClient,
|
|
196
266
|
dehydratedState: Partial<DehydratedState>,
|
|
@@ -240,11 +310,7 @@ export function hydrate(
|
|
|
240
310
|
// Do not hydrate if an existing query exists with newer data
|
|
241
311
|
if (query) {
|
|
242
312
|
const hasNewerSyncData =
|
|
243
|
-
syncData &&
|
|
244
|
-
// We only need this undefined check to handle older dehydration
|
|
245
|
-
// payloads that might not have dehydratedAt
|
|
246
|
-
dehydratedAt !== undefined &&
|
|
247
|
-
dehydratedAt > query.state.dataUpdatedAt
|
|
313
|
+
syncData && dehydratedAt > query.state.dataUpdatedAt
|
|
248
314
|
if (
|
|
249
315
|
state.dataUpdatedAt > query.state.dataUpdatedAt ||
|
|
250
316
|
hasNewerSyncData
|
|
@@ -262,7 +328,7 @@ export function hydrate(
|
|
|
262
328
|
...(state.status === 'pending' &&
|
|
263
329
|
data !== undefined && {
|
|
264
330
|
status: 'success' as const,
|
|
265
|
-
dataUpdatedAt: dehydratedAt
|
|
331
|
+
dataUpdatedAt: dehydratedAt,
|
|
266
332
|
// Preserve existing fetchStatus if the existing query is actively fetching.
|
|
267
333
|
...(!existingQueryIsFetching && {
|
|
268
334
|
fetchStatus: 'idle' as const,
|
|
@@ -296,7 +362,7 @@ export function hydrate(
|
|
|
296
362
|
: state.status,
|
|
297
363
|
...(state.status === 'pending' &&
|
|
298
364
|
data !== undefined && {
|
|
299
|
-
dataUpdatedAt: dehydratedAt
|
|
365
|
+
dataUpdatedAt: dehydratedAt,
|
|
300
366
|
}),
|
|
301
367
|
},
|
|
302
368
|
)
|
|
@@ -311,7 +377,7 @@ export function hydrate(
|
|
|
311
377
|
!existingQueryIsFetching &&
|
|
312
378
|
// Only hydrate if dehydration is newer than any existing data,
|
|
313
379
|
// this is always true for new queries
|
|
314
|
-
|
|
380
|
+
dehydratedAt > query.state.dataUpdatedAt
|
|
315
381
|
) {
|
|
316
382
|
// This doesn't actually fetch - it just creates a retryer
|
|
317
383
|
// which will re-use the passed `initialPromise`
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* istanbul ignore file */
|
|
2
2
|
|
|
3
3
|
export { focusManager } from './focusManager'
|
|
4
|
+
export type { FocusManager } from './focusManager'
|
|
4
5
|
export { environmentManager } from './environmentManager'
|
|
5
6
|
export {
|
|
6
7
|
defaultShouldDehydrateMutation,
|
|
@@ -15,6 +16,7 @@ export type { MutationCacheNotifyEvent } from './mutationCache'
|
|
|
15
16
|
export { MutationObserver } from './mutationObserver'
|
|
16
17
|
export { defaultScheduler, notifyManager } from './notifyManager'
|
|
17
18
|
export { onlineManager } from './onlineManager'
|
|
19
|
+
export type { OnlineManager } from './onlineManager'
|
|
18
20
|
export { QueriesObserver } from './queriesObserver'
|
|
19
21
|
export { QueryCache } from './queryCache'
|
|
20
22
|
export type { QueryCacheNotifyEvent } from './queryCache'
|
|
@@ -25,6 +27,7 @@ export {
|
|
|
25
27
|
timeoutManager,
|
|
26
28
|
type ManagedTimerId,
|
|
27
29
|
type TimeoutCallback,
|
|
30
|
+
type TimeoutManager,
|
|
28
31
|
type TimeoutProvider,
|
|
29
32
|
} from './timeoutManager'
|
|
30
33
|
export {
|
|
@@ -19,6 +19,25 @@ type InfiniteQueryObserverListener<TData, TError> = (
|
|
|
19
19
|
result: InfiniteQueryObserverResult<TData, TError>,
|
|
20
20
|
) => void
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* An `InfiniteQueryObserver` extends `QueryObserver` to observe and switch
|
|
24
|
+
* between infinite queries. It augments the base `QueryObserverResult` with
|
|
25
|
+
* infinite-query-specific fields and methods, such as `hasNextPage` and
|
|
26
|
+
* `fetchNextPage`, and is the primitive that framework adapters (e.g.
|
|
27
|
+
* `useInfiniteQuery`) build their hooks on top of.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const observer = new InfiniteQueryObserver(queryClient, {
|
|
32
|
+
* queryKey: ['projects'],
|
|
33
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
34
|
+
* initialPageParam: 0,
|
|
35
|
+
* getNextPageParam: (lastPage) => lastPage.nextCursor,
|
|
36
|
+
* })
|
|
37
|
+
*
|
|
38
|
+
* const unsubscribe = observer.subscribe((result) => console.log(result))
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
22
41
|
export class InfiniteQueryObserver<
|
|
23
42
|
TQueryFnData = unknown,
|
|
24
43
|
TError = DefaultError,
|
|
@@ -80,6 +99,12 @@ export class InfiniteQueryObserver<
|
|
|
80
99
|
this.fetchPreviousPage = this.fetchPreviousPage.bind(this)
|
|
81
100
|
}
|
|
82
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Updates the observer's options. Behaves the same as
|
|
104
|
+
* `QueryObserver.setOptions`, additionally marking the options as
|
|
105
|
+
* belonging to an infinite query before delegating to the base
|
|
106
|
+
* implementation.
|
|
107
|
+
*/
|
|
83
108
|
setOptions(
|
|
84
109
|
options: InfiniteQueryObserverOptions<
|
|
85
110
|
TQueryFnData,
|
|
@@ -93,6 +118,12 @@ export class InfiniteQueryObserver<
|
|
|
93
118
|
super.setOptions(options)
|
|
94
119
|
}
|
|
95
120
|
|
|
121
|
+
/**
|
|
122
|
+
* The infinite-query counterpart of {@link QueryObserver#getOptimisticResult}, marking the
|
|
123
|
+
* options as an infinite query before delegating to it. Called by framework adapters (e.g.
|
|
124
|
+
* `useInfiniteQuery`) ahead of subscribing, to compute the current `InfiniteQueryObserverResult`
|
|
125
|
+
* synchronously.
|
|
126
|
+
*/
|
|
96
127
|
getOptimisticResult(
|
|
97
128
|
options: DefaultedInfiniteQueryObserverOptions<
|
|
98
129
|
TQueryFnData,
|
|
@@ -109,6 +140,24 @@ export class InfiniteQueryObserver<
|
|
|
109
140
|
>
|
|
110
141
|
}
|
|
111
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Fetches the next page of the infinite query and returns a promise that
|
|
145
|
+
* resolves with the resulting `InfiniteQueryObserverResult`. The page
|
|
146
|
+
* param used for the fetch is determined by `getNextPageParam`, which
|
|
147
|
+
* receives the current pages/page params and whose result also determines
|
|
148
|
+
* `hasNextPage`.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const { hasNextPage } = observer.getCurrentResult()
|
|
153
|
+
*
|
|
154
|
+
* if (hasNextPage) {
|
|
155
|
+
* await observer.fetchNextPage()
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*
|
|
159
|
+
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
|
|
160
|
+
*/
|
|
112
161
|
fetchNextPage(
|
|
113
162
|
options?: FetchNextPageOptions,
|
|
114
163
|
): Promise<InfiniteQueryObserverResult<TData, TError>> {
|
|
@@ -120,6 +169,24 @@ export class InfiniteQueryObserver<
|
|
|
120
169
|
})
|
|
121
170
|
}
|
|
122
171
|
|
|
172
|
+
/**
|
|
173
|
+
* Fetches the previous page of the infinite query and returns a promise
|
|
174
|
+
* that resolves with the resulting `InfiniteQueryObserverResult`. The page
|
|
175
|
+
* param used for the fetch is determined by `getPreviousPageParam`, which
|
|
176
|
+
* receives the current pages/page params and whose result also determines
|
|
177
|
+
* `hasPreviousPage`.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* const { hasPreviousPage } = observer.getCurrentResult()
|
|
182
|
+
*
|
|
183
|
+
* if (hasPreviousPage) {
|
|
184
|
+
* await observer.fetchPreviousPage()
|
|
185
|
+
* }
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @see {@link InfiniteQueryObserver#fetchNextPage}
|
|
189
|
+
*/
|
|
123
190
|
fetchPreviousPage(
|
|
124
191
|
options?: FetchPreviousPageOptions,
|
|
125
192
|
): Promise<InfiniteQueryObserverResult<TData, TError>> {
|