@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":"queryCache.cjs","names":["Subscribable","hashQueryKeyByOptions","Query","matchQuery"],"sources":["../../src/queryCache.ts"],"sourcesContent":["import { hashQueryKeyByOptions, matchQuery } from './utils'\nimport { Query } from './query'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport type { QueryFilters } from './utils'\nimport type { Action, QueryState } from './query'\nimport type {\n DefaultError,\n NotifyEvent,\n QueryKey,\n QueryOptions,\n WithRequired,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { QueryObserver } from './queryObserver'\n\n// TYPES\n\nexport interface QueryCacheConfig {\n onError?: (\n error: DefaultError,\n query: Query<unknown, unknown, unknown>,\n ) => void\n onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n query: Query<unknown, unknown, unknown>,\n ) => void\n}\n\ninterface NotifyEventQueryAdded extends NotifyEvent {\n type: 'added'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryRemoved extends NotifyEvent {\n type: 'removed'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryUpdated extends NotifyEvent {\n type: 'updated'\n query: Query<any, any, any, any>\n action: Action<any, any>\n}\n\ninterface NotifyEventQueryObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverResultsUpdated extends NotifyEvent {\n type: 'observerResultsUpdated'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\nexport type QueryCacheNotifyEvent =\n | NotifyEventQueryAdded\n | NotifyEventQueryRemoved\n | NotifyEventQueryUpdated\n | NotifyEventQueryObserverAdded\n | NotifyEventQueryObserverRemoved\n | NotifyEventQueryObserverResultsUpdated\n | NotifyEventQueryObserverOptionsUpdated\n\ntype QueryCacheListener = (event: QueryCacheNotifyEvent) => void\n\nexport interface QueryStore {\n has: (queryHash: string) => boolean\n set: (queryHash: string, query: Query) => void\n get: (queryHash: string) => Query | undefined\n delete: (queryHash: string) => void\n values: () => IterableIterator<Query>\n}\n\n// CLASS\n\nexport class QueryCache extends Subscribable<QueryCacheListener> {\n #queries: QueryStore\n\n constructor(public config: QueryCacheConfig = {}) {\n super()\n this.#queries = new Map<string, Query>()\n }\n\n build<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n client: QueryClient,\n options: WithRequired<\n QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n state?: QueryState<TData, TError>,\n ): Query<TQueryFnData, TError, TData, TQueryKey> {\n const queryKey = options.queryKey\n const queryHash =\n options.queryHash ?? hashQueryKeyByOptions(queryKey, options)\n let query = this.get<TQueryFnData, TError, TData, TQueryKey>(queryHash)\n\n if (!query) {\n query = new Query({\n client,\n queryKey,\n queryHash,\n options: client.defaultQueryOptions(options),\n state,\n defaultOptions: client.getQueryDefaults(queryKey),\n })\n this.add(query)\n }\n\n return query\n }\n\n add(query: Query<any, any, any, any>): void {\n if (!this.#queries.has(query.queryHash)) {\n this.#queries.set(query.queryHash, query)\n\n this.notify({\n type: 'added',\n query,\n })\n }\n }\n\n remove(query: Query<any, any, any, any>): void {\n const queryInMap = this.#queries.get(query.queryHash)\n\n if (queryInMap) {\n query.destroy()\n\n if (queryInMap === query) {\n this.#queries.delete(query.queryHash)\n }\n\n this.notify({ type: 'removed', query })\n }\n }\n\n clear(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n this.remove(query)\n })\n })\n }\n\n get<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryHash: string,\n ): Query<TQueryFnData, TError, TData, TQueryKey> | undefined {\n return this.#queries.get(queryHash) as\n | Query<TQueryFnData, TError, TData, TQueryKey>\n | undefined\n }\n\n getAll(): Array<Query> {\n return [...this.#queries.values()]\n }\n\n find<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData>(\n filters: WithRequired<QueryFilters, 'queryKey'>,\n ): Query<TQueryFnData, TError, TData> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((query) =>\n matchQuery(defaultedFilters, query),\n ) as Query<TQueryFnData, TError, TData> | undefined\n }\n\n findAll(filters: QueryFilters<any> = {}): Array<Query> {\n const queries = this.getAll()\n return Object.keys(filters).length > 0\n ? queries.filter((query) => matchQuery(filters, query))\n : queries\n }\n\n notify(event: QueryCacheNotifyEvent): void {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n onFocus(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onFocus()\n })\n })\n }\n\n onOnline(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onOnline()\n })\n })\n }\n}\n"],"mappings":";;;;;;;;AA2FA,IAAa,aAAb,cAAgCA,qBAAAA,aAAiC;CAG/D,YAAY,SAAkC,CAAC,GAAG;EAChD,MAAM;EADW,KAAA,SAAA;;EAEjB,8BAAA,uBAAA,UAAA,sBAAgB,IAAI,IAAmB,CAAA;CACzC;CAEA,MAME,QACA,SAIA,OAC+C;EAC/C,MAAM,WAAW,QA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,UACzBC,cAAAA,WAAW,kBAAkB,KAAK,CACpC;CACF;CAEA,QAAQ,UAA6B,CAAC,GAAiB;EACrD,MAAM,UAAU,KAAK,OAAO;EAC5B,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IACjC,QAAQ,QAAQ,UAAUA,cAAAA,WAAW,SAAS,KAAK,CAAC,IACpD;CACN;CAEA,OAAO,OAAoC;EACzC,sBAAA,cAAc,YAAY;GACxB,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,KAAK;GAChB,CAAC;EACH,CAAC;CACH;CAEA,UAAgB;EACd,sBAAA,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,QAAQ;GAChB,CAAC;EACH,CAAC;CACH;CAEA,WAAiB;EACf,sBAAA,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,SAAS;GACjB,CAAC;EACH,CAAC;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"queryCache.cjs","names":["Subscribable","hashQueryKeyByOptions","Query","matchQuery"],"sources":["../../src/queryCache.ts"],"sourcesContent":["import { hashQueryKeyByOptions, matchQuery } from './utils'\nimport { Query } from './query'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport type { QueryFilters } from './utils'\nimport type { Action, QueryState } from './query'\nimport type {\n DefaultError,\n NotifyEvent,\n QueryKey,\n QueryOptions,\n WithRequired,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { QueryObserver } from './queryObserver'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every query handled by a `QueryCache`, regardless of which\n * component or observer triggered it. Unlike `QueryClient`'s `defaultOptions`, which a query can\n * override, these callbacks are always called. Unlike `MutationCacheConfig`'s callbacks, these\n * are fire-and-forget: their return value is not awaited before the query settles.\n */\nexport interface QueryCacheConfig {\n /** Called when any query in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n query: Query<unknown, unknown, unknown>,\n ) => void\n /** Called when any query in the cache is successful. */\n onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void\n /** Called when any query in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n query: Query<unknown, unknown, unknown>,\n ) => void\n}\n\ninterface NotifyEventQueryAdded extends NotifyEvent {\n type: 'added'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryRemoved extends NotifyEvent {\n type: 'removed'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryUpdated extends NotifyEvent {\n type: 'updated'\n query: Query<any, any, any, any>\n action: Action<any, any>\n}\n\ninterface NotifyEventQueryObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverResultsUpdated extends NotifyEvent {\n type: 'observerResultsUpdated'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\n/**\n * The event passed to a `QueryCache` subscriber. Fired whenever a query is added or removed from\n * the cache, its state is updated (e.g. via `query.setState` or `queryClient.removeQueries`), or\n * one of its observers is added, removed, or has its results or options updated.\n */\nexport type QueryCacheNotifyEvent =\n | NotifyEventQueryAdded\n | NotifyEventQueryRemoved\n | NotifyEventQueryUpdated\n | NotifyEventQueryObserverAdded\n | NotifyEventQueryObserverRemoved\n | NotifyEventQueryObserverResultsUpdated\n | NotifyEventQueryObserverOptionsUpdated\n\ntype QueryCacheListener = (event: QueryCacheNotifyEvent) => void\n\nexport interface QueryStore {\n has: (queryHash: string) => boolean\n set: (queryHash: string, query: Query) => void\n get: (queryHash: string) => Query | undefined\n delete: (queryHash: string) => void\n values: () => IterableIterator<Query>\n}\n\n// CLASS\n\n/**\n * The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta\n * information, and state of the queries it contains.\n *\n * Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`\n * for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as queries being added, removed, or updated — updates made\n * outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do\n * not notify subscribers.\n *\n * @example\n * ```ts\n * const unsubscribe = queryCache.subscribe((event) => {\n * console.log(event.type, event.query)\n * })\n * ```\n */\nexport class QueryCache extends Subscribable<QueryCacheListener> {\n #queries: QueryStore\n\n constructor(public config: QueryCacheConfig = {}) {\n super()\n this.#queries = new Map<string, Query>()\n }\n\n /**\n * Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or\n * builds and adds a new one to the cache if none exists yet. Used by framework adapters and\n * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing\n * the reactive `QueryObserver` machinery.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.build(queryClient, {\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n */\n build<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n client: QueryClient,\n options: WithRequired<\n QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n state?: QueryState<TData, TError>,\n ): Query<TQueryFnData, TError, TData, TQueryKey> {\n const queryKey = options.queryKey\n const queryHash =\n options.queryHash ?? hashQueryKeyByOptions(queryKey, options)\n let query = this.get<TQueryFnData, TError, TData, TQueryKey>(queryHash)\n\n if (!query) {\n query = new Query({\n client,\n queryKey,\n queryHash,\n options: client.defaultQueryOptions(options),\n state,\n defaultOptions: client.getQueryDefaults(queryKey),\n })\n this.add(query)\n }\n\n return query\n }\n\n /** @internal */\n add(query: Query<any, any, any, any>): void {\n if (!this.#queries.has(query.queryHash)) {\n this.#queries.set(query.queryHash, query)\n\n this.notify({\n type: 'added',\n query,\n })\n }\n }\n\n /**\n * Destroys the given `Query` and removes it from the cache, notifying subscribers with a\n * `'removed'` event. A no-op if the query is no longer the one currently stored under its hash\n * (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror\n * removals across `QueryCache` instances.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * queryCache.remove(query)\n * }\n * ```\n */\n remove(query: Query<any, any, any, any>): void {\n const queryInMap = this.#queries.get(query.queryHash)\n\n if (queryInMap) {\n query.destroy()\n\n if (queryInMap === query) {\n this.#queries.delete(query.queryHash)\n }\n\n this.notify({ type: 'removed', query })\n }\n }\n\n /**\n * Removes all queries from the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * queryCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n this.remove(query)\n })\n })\n }\n\n /**\n * Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none\n * exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather\n * than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash\n * to look up directly.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const queryHash = hashKey(['posts'])\n *\n * const query = queryCache.get(queryHash)\n * ```\n */\n get<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryHash: string,\n ): Query<TQueryFnData, TError, TData, TQueryKey> | undefined {\n return this.#queries.get(queryHash) as\n | Query<TQueryFnData, TError, TData, TQueryKey>\n | undefined\n }\n\n /**\n * Returns all queries within the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.getAll()\n * ```\n */\n getAll(): Array<Query> {\n return [...this.#queries.values()]\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing query instance from the\n * cache. This instance not only contains all the state for the query, but all of the instances,\n * and underlying guts of the query as well. If the query does not exist, `undefined` is\n * returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to\n * decide whether a query is fresh enough to be used as an initial value).\n *\n * @see {@link QueryCache#findAll}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.find({ queryKey: ['posts'] })\n * ```\n */\n find<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData>(\n filters: WithRequired<QueryFilters, 'queryKey'>,\n ): Query<TQueryFnData, TError, TData> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((query) =>\n matchQuery(defaultedFilters, query),\n ) as Query<TQueryFnData, TError, TData> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing query instances from the cache\n * that partially match a query key. If no queries match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about queries in rare scenarios.\n *\n * @see {@link QueryCache#find}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n findAll(filters: QueryFilters<any> = {}): Array<Query> {\n const queries = this.getAll()\n return Object.keys(filters).length > 0\n ? queries.filter((query) => matchQuery(filters, query))\n : queries\n }\n\n /** @internal */\n notify(event: QueryCacheNotifyEvent): void {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /** @internal */\n onFocus(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onFocus()\n })\n })\n }\n\n /** @internal */\n onOnline(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onOnline()\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0HA,IAAa,a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EAC3D,OAAA,8BAAA,uBAAA,UAAO,IAAA,CAAA,CAAc,IAAI,SAAS;CAGpC;;;;;;;;;;;CAYA,SAAuB;EACrB,OAAO,CAAC,GAAA,8BAAA,uBAAA,UAAG,IAAA,CAAA,CAAc,OAAO,CAAC;CACnC;;;;;;;;;;;;;;;;;;;CAoBA,KACE,SACgD;EAChD,MAAM,mBAAmB;GAAE,OAAO;GAAM,GAAG;EAAQ;EAEnD,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,UACzBC,cAAAA,WAAW,kBAAkB,KAAK,CACpC;CACF;;;;;;;;;;;;;;;;CAiBA,QAAQ,UAA6B,CAAC,GAAiB;EACrD,MAAM,UAAU,KAAK,OAAO;EAC5B,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IACjC,QAAQ,QAAQ,UAAUA,cAAAA,WAAW,SAAS,KAAK,CAAC,IACpD;CACN;;CAGA,OAAO,OAAoC;EACzC,sBAAA,cAAc,YAAY;GACxB,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,KAAK;GAChB,CAAC;EACH,CAAC;CACH;;CAGA,UAAgB;EACd,sBAAA,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,QAAQ;GAChB,CAAC;EACH,CAAC;CACH;;CAGA,WAAiB;EACf,sBAAA,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,SAAS;GACjB,CAAC;EACH,CAAC;CACH;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { cn as QueryCacheConfig, ln as QueryCacheNotifyEvent, sn as QueryCache, un as QueryStore } from "./hydration-
|
|
1
|
+
import { cn as QueryCacheConfig, ln as QueryCacheNotifyEvent, sn as QueryCache, un as QueryStore } from "./hydration-DwR10Hi-.cjs";
|
|
2
2
|
export { QueryCache, QueryCacheConfig, QueryCacheNotifyEvent, QueryStore };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { cn as QueryCacheConfig, ln as QueryCacheNotifyEvent, sn as QueryCache, un as QueryStore } from "./hydration-
|
|
1
|
+
import { cn as QueryCacheConfig, ln as QueryCacheNotifyEvent, sn as QueryCache, un as QueryStore } from "./hydration-Cq7QYAzB.js";
|
|
2
2
|
export { QueryCache, QueryCacheConfig, QueryCacheNotifyEvent, QueryStore };
|
|
@@ -5,6 +5,23 @@ import { notifyManager } from "./notifyManager.js";
|
|
|
5
5
|
import { Query } from "./query.js";
|
|
6
6
|
//#region src/queryCache.ts
|
|
7
7
|
var _queries = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
/**
|
|
9
|
+
* The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta
|
|
10
|
+
* information, and state of the queries it contains.
|
|
11
|
+
*
|
|
12
|
+
* Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`
|
|
13
|
+
* for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of
|
|
14
|
+
* safe/known updates to the cache, such as queries being added, removed, or updated — updates made
|
|
15
|
+
* outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do
|
|
16
|
+
* not notify subscribers.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const unsubscribe = queryCache.subscribe((event) => {
|
|
21
|
+
* console.log(event.type, event.query)
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
8
25
|
var QueryCache = class extends Subscribable {
|
|
9
26
|
constructor(config = {}) {
|
|
10
27
|
super();
|
|
@@ -12,6 +29,22 @@ var QueryCache = class extends Subscribable {
|
|
|
12
29
|
_classPrivateFieldInitSpec(this, _queries, void 0);
|
|
13
30
|
_classPrivateFieldSet2(_queries, this, /* @__PURE__ */ new Map());
|
|
14
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or
|
|
34
|
+
* builds and adds a new one to the cache if none exists yet. Used by framework adapters and
|
|
35
|
+
* plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing
|
|
36
|
+
* the reactive `QueryObserver` machinery.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const queryCache = queryClient.getQueryCache()
|
|
41
|
+
*
|
|
42
|
+
* const query = queryCache.build(queryClient, {
|
|
43
|
+
* queryKey: ['posts'],
|
|
44
|
+
* queryFn: fetchPosts,
|
|
45
|
+
* })
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
15
48
|
build(client, options, state) {
|
|
16
49
|
const queryKey = options.queryKey;
|
|
17
50
|
const queryHash = options.queryHash ?? hashQueryKeyByOptions(queryKey, options);
|
|
@@ -29,6 +62,7 @@ var QueryCache = class extends Subscribable {
|
|
|
29
62
|
}
|
|
30
63
|
return query;
|
|
31
64
|
}
|
|
65
|
+
/** @internal */
|
|
32
66
|
add(query) {
|
|
33
67
|
if (!_classPrivateFieldGet2(_queries, this).has(query.queryHash)) {
|
|
34
68
|
_classPrivateFieldGet2(_queries, this).set(query.queryHash, query);
|
|
@@ -38,6 +72,22 @@ var QueryCache = class extends Subscribable {
|
|
|
38
72
|
});
|
|
39
73
|
}
|
|
40
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Destroys the given `Query` and removes it from the cache, notifying subscribers with a
|
|
77
|
+
* `'removed'` event. A no-op if the query is no longer the one currently stored under its hash
|
|
78
|
+
* (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror
|
|
79
|
+
* removals across `QueryCache` instances.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const queryCache = queryClient.getQueryCache()
|
|
84
|
+
* const query = queryCache.find({ queryKey: ['posts'] })
|
|
85
|
+
*
|
|
86
|
+
* if (query) {
|
|
87
|
+
* queryCache.remove(query)
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
41
91
|
remove(query) {
|
|
42
92
|
const queryInMap = _classPrivateFieldGet2(_queries, this).get(query.queryHash);
|
|
43
93
|
if (queryInMap) {
|
|
@@ -49,6 +99,16 @@ var QueryCache = class extends Subscribable {
|
|
|
49
99
|
});
|
|
50
100
|
}
|
|
51
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Removes all queries from the cache.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const queryCache = queryClient.getQueryCache()
|
|
108
|
+
*
|
|
109
|
+
* queryCache.clear()
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
52
112
|
clear() {
|
|
53
113
|
notifyManager.batch(() => {
|
|
54
114
|
this.getAll().forEach((query) => {
|
|
@@ -56,12 +116,54 @@ var QueryCache = class extends Subscribable {
|
|
|
56
116
|
});
|
|
57
117
|
});
|
|
58
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none
|
|
121
|
+
* exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather
|
|
122
|
+
* than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash
|
|
123
|
+
* to look up directly.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* const queryCache = queryClient.getQueryCache()
|
|
128
|
+
* const queryHash = hashKey(['posts'])
|
|
129
|
+
*
|
|
130
|
+
* const query = queryCache.get(queryHash)
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
59
133
|
get(queryHash) {
|
|
60
134
|
return _classPrivateFieldGet2(_queries, this).get(queryHash);
|
|
61
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns all queries within the cache.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* const queryCache = queryClient.getQueryCache()
|
|
142
|
+
*
|
|
143
|
+
* const queries = queryCache.getAll()
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
62
146
|
getAll() {
|
|
63
147
|
return [..._classPrivateFieldGet2(_queries, this).values()];
|
|
64
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* A slightly more advanced method that can be used to get an existing query instance from the
|
|
151
|
+
* cache. This instance not only contains all the state for the query, but all of the instances,
|
|
152
|
+
* and underlying guts of the query as well. If the query does not exist, `undefined` is
|
|
153
|
+
* returned.
|
|
154
|
+
*
|
|
155
|
+
* This is not typically needed for most applications, but can come in handy when needing more
|
|
156
|
+
* information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to
|
|
157
|
+
* decide whether a query is fresh enough to be used as an initial value).
|
|
158
|
+
*
|
|
159
|
+
* @see {@link QueryCache#findAll}
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* const queryCache = queryClient.getQueryCache()
|
|
163
|
+
*
|
|
164
|
+
* const query = queryCache.find({ queryKey: ['posts'] })
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
65
167
|
find(filters) {
|
|
66
168
|
const defaultedFilters = {
|
|
67
169
|
exact: true,
|
|
@@ -69,10 +171,26 @@ var QueryCache = class extends Subscribable {
|
|
|
69
171
|
};
|
|
70
172
|
return this.getAll().find((query) => matchQuery(defaultedFilters, query));
|
|
71
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* An even more advanced method that can be used to get existing query instances from the cache
|
|
176
|
+
* that partially match a query key. If no queries match, an empty array is returned.
|
|
177
|
+
*
|
|
178
|
+
* This is not typically needed for most applications, but can come in handy when needing more
|
|
179
|
+
* information about queries in rare scenarios.
|
|
180
|
+
*
|
|
181
|
+
* @see {@link QueryCache#find}
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* const queryCache = queryClient.getQueryCache()
|
|
185
|
+
*
|
|
186
|
+
* const queries = queryCache.findAll({ queryKey: ['posts'] })
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
72
189
|
findAll(filters = {}) {
|
|
73
190
|
const queries = this.getAll();
|
|
74
191
|
return Object.keys(filters).length > 0 ? queries.filter((query) => matchQuery(filters, query)) : queries;
|
|
75
192
|
}
|
|
193
|
+
/** @internal */
|
|
76
194
|
notify(event) {
|
|
77
195
|
notifyManager.batch(() => {
|
|
78
196
|
this.listeners.forEach((listener) => {
|
|
@@ -80,6 +198,7 @@ var QueryCache = class extends Subscribable {
|
|
|
80
198
|
});
|
|
81
199
|
});
|
|
82
200
|
}
|
|
201
|
+
/** @internal */
|
|
83
202
|
onFocus() {
|
|
84
203
|
notifyManager.batch(() => {
|
|
85
204
|
this.getAll().forEach((query) => {
|
|
@@ -87,6 +206,7 @@ var QueryCache = class extends Subscribable {
|
|
|
87
206
|
});
|
|
88
207
|
});
|
|
89
208
|
}
|
|
209
|
+
/** @internal */
|
|
90
210
|
onOnline() {
|
|
91
211
|
notifyManager.batch(() => {
|
|
92
212
|
this.getAll().forEach((query) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryCache.js","names":[],"sources":["../../src/queryCache.ts"],"sourcesContent":["import { hashQueryKeyByOptions, matchQuery } from './utils'\nimport { Query } from './query'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport type { QueryFilters } from './utils'\nimport type { Action, QueryState } from './query'\nimport type {\n DefaultError,\n NotifyEvent,\n QueryKey,\n QueryOptions,\n WithRequired,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { QueryObserver } from './queryObserver'\n\n// TYPES\n\nexport interface QueryCacheConfig {\n onError?: (\n error: DefaultError,\n query: Query<unknown, unknown, unknown>,\n ) => void\n onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n query: Query<unknown, unknown, unknown>,\n ) => void\n}\n\ninterface NotifyEventQueryAdded extends NotifyEvent {\n type: 'added'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryRemoved extends NotifyEvent {\n type: 'removed'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryUpdated extends NotifyEvent {\n type: 'updated'\n query: Query<any, any, any, any>\n action: Action<any, any>\n}\n\ninterface NotifyEventQueryObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverResultsUpdated extends NotifyEvent {\n type: 'observerResultsUpdated'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\nexport type QueryCacheNotifyEvent =\n | NotifyEventQueryAdded\n | NotifyEventQueryRemoved\n | NotifyEventQueryUpdated\n | NotifyEventQueryObserverAdded\n | NotifyEventQueryObserverRemoved\n | NotifyEventQueryObserverResultsUpdated\n | NotifyEventQueryObserverOptionsUpdated\n\ntype QueryCacheListener = (event: QueryCacheNotifyEvent) => void\n\nexport interface QueryStore {\n has: (queryHash: string) => boolean\n set: (queryHash: string, query: Query) => void\n get: (queryHash: string) => Query | undefined\n delete: (queryHash: string) => void\n values: () => IterableIterator<Query>\n}\n\n// CLASS\n\nexport class QueryCache extends Subscribable<QueryCacheListener> {\n #queries: QueryStore\n\n constructor(public config: QueryCacheConfig = {}) {\n super()\n this.#queries = new Map<string, Query>()\n }\n\n build<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n client: QueryClient,\n options: WithRequired<\n QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n state?: QueryState<TData, TError>,\n ): Query<TQueryFnData, TError, TData, TQueryKey> {\n const queryKey = options.queryKey\n const queryHash =\n options.queryHash ?? hashQueryKeyByOptions(queryKey, options)\n let query = this.get<TQueryFnData, TError, TData, TQueryKey>(queryHash)\n\n if (!query) {\n query = new Query({\n client,\n queryKey,\n queryHash,\n options: client.defaultQueryOptions(options),\n state,\n defaultOptions: client.getQueryDefaults(queryKey),\n })\n this.add(query)\n }\n\n return query\n }\n\n add(query: Query<any, any, any, any>): void {\n if (!this.#queries.has(query.queryHash)) {\n this.#queries.set(query.queryHash, query)\n\n this.notify({\n type: 'added',\n query,\n })\n }\n }\n\n remove(query: Query<any, any, any, any>): void {\n const queryInMap = this.#queries.get(query.queryHash)\n\n if (queryInMap) {\n query.destroy()\n\n if (queryInMap === query) {\n this.#queries.delete(query.queryHash)\n }\n\n this.notify({ type: 'removed', query })\n }\n }\n\n clear(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n this.remove(query)\n })\n })\n }\n\n get<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryHash: string,\n ): Query<TQueryFnData, TError, TData, TQueryKey> | undefined {\n return this.#queries.get(queryHash) as\n | Query<TQueryFnData, TError, TData, TQueryKey>\n | undefined\n }\n\n getAll(): Array<Query> {\n return [...this.#queries.values()]\n }\n\n find<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData>(\n filters: WithRequired<QueryFilters, 'queryKey'>,\n ): Query<TQueryFnData, TError, TData> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((query) =>\n matchQuery(defaultedFilters, query),\n ) as Query<TQueryFnData, TError, TData> | undefined\n }\n\n findAll(filters: QueryFilters<any> = {}): Array<Query> {\n const queries = this.getAll()\n return Object.keys(filters).length > 0\n ? queries.filter((query) => matchQuery(filters, query))\n : queries\n }\n\n notify(event: QueryCacheNotifyEvent): void {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n onFocus(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onFocus()\n })\n })\n }\n\n on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CAAc,IAAI,SAAS;CAGpC;CAEA,SAAuB;EACrB,OAAO,CAAC,GAAA,uBAAA,UAAG,IAAA,CAAA,CAAc,OAAO,CAAC;CACnC;CAEA,KACE,SACgD;EAChD,MAAM,mBAAmB;GAAE,OAAO;GAAM,GAAG;EAAQ;EAEnD,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,UACzB,WAAW,kBAAkB,KAAK,CACpC;CACF;CAEA,QAAQ,UAA6B,CAAC,GAAiB;EACrD,MAAM,UAAU,KAAK,OAAO;EAC5B,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IACjC,QAAQ,QAAQ,UAAU,WAAW,SAAS,KAAK,CAAC,IACpD;CACN;CAEA,OAAO,OAAoC;EACzC,cAAc,YAAY;GACxB,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,KAAK;GAChB,CAAC;EACH,CAAC;CACH;CAEA,UAAgB;EACd,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,QAAQ;GAChB,CAAC;EACH,CAAC;CACH;CAEA,WAAiB;EACf,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,SAAS;GACjB,CAAC;EACH,CAAC;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"queryCache.js","names":[],"sources":["../../src/queryCache.ts"],"sourcesContent":["import { hashQueryKeyByOptions, matchQuery } from './utils'\nimport { Query } from './query'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport type { QueryFilters } from './utils'\nimport type { Action, QueryState } from './query'\nimport type {\n DefaultError,\n NotifyEvent,\n QueryKey,\n QueryOptions,\n WithRequired,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { QueryObserver } from './queryObserver'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every query handled by a `QueryCache`, regardless of which\n * component or observer triggered it. Unlike `QueryClient`'s `defaultOptions`, which a query can\n * override, these callbacks are always called. Unlike `MutationCacheConfig`'s callbacks, these\n * are fire-and-forget: their return value is not awaited before the query settles.\n */\nexport interface QueryCacheConfig {\n /** Called when any query in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n query: Query<unknown, unknown, unknown>,\n ) => void\n /** Called when any query in the cache is successful. */\n onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void\n /** Called when any query in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n query: Query<unknown, unknown, unknown>,\n ) => void\n}\n\ninterface NotifyEventQueryAdded extends NotifyEvent {\n type: 'added'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryRemoved extends NotifyEvent {\n type: 'removed'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryUpdated extends NotifyEvent {\n type: 'updated'\n query: Query<any, any, any, any>\n action: Action<any, any>\n}\n\ninterface NotifyEventQueryObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverResultsUpdated extends NotifyEvent {\n type: 'observerResultsUpdated'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\n/**\n * The event passed to a `QueryCache` subscriber. Fired whenever a query is added or removed from\n * the cache, its state is updated (e.g. via `query.setState` or `queryClient.removeQueries`), or\n * one of its observers is added, removed, or has its results or options updated.\n */\nexport type QueryCacheNotifyEvent =\n | NotifyEventQueryAdded\n | NotifyEventQueryRemoved\n | NotifyEventQueryUpdated\n | NotifyEventQueryObserverAdded\n | NotifyEventQueryObserverRemoved\n | NotifyEventQueryObserverResultsUpdated\n | NotifyEventQueryObserverOptionsUpdated\n\ntype QueryCacheListener = (event: QueryCacheNotifyEvent) => void\n\nexport interface QueryStore {\n has: (queryHash: string) => boolean\n set: (queryHash: string, query: Query) => void\n get: (queryHash: string) => Query | undefined\n delete: (queryHash: string) => void\n values: () => IterableIterator<Query>\n}\n\n// CLASS\n\n/**\n * The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta\n * information, and state of the queries it contains.\n *\n * Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`\n * for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as queries being added, removed, or updated — updates made\n * outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do\n * not notify subscribers.\n *\n * @example\n * ```ts\n * const unsubscribe = queryCache.subscribe((event) => {\n * console.log(event.type, event.query)\n * })\n * ```\n */\nexport class QueryCache extends Subscribable<QueryCacheListener> {\n #queries: QueryStore\n\n constructor(public config: QueryCacheConfig = {}) {\n super()\n this.#queries = new Map<string, Query>()\n }\n\n /**\n * Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or\n * builds and adds a new one to the cache if none exists yet. Used by framework adapters and\n * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing\n * the reactive `QueryObserver` machinery.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.build(queryClient, {\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n */\n build<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n client: QueryClient,\n options: WithRequired<\n QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n state?: QueryState<TData, TError>,\n ): Query<TQueryFnData, TError, TData, TQueryKey> {\n const queryKey = options.queryKey\n const queryHash =\n options.queryHash ?? hashQueryKeyByOptions(queryKey, options)\n let query = this.get<TQueryFnData, TError, TData, TQueryKey>(queryHash)\n\n if (!query) {\n query = new Query({\n client,\n queryKey,\n queryHash,\n options: client.defaultQueryOptions(options),\n state,\n defaultOptions: client.getQueryDefaults(queryKey),\n })\n this.add(query)\n }\n\n return query\n }\n\n /** @internal */\n add(query: Query<any, any, any, any>): void {\n if (!this.#queries.has(query.queryHash)) {\n this.#queries.set(query.queryHash, query)\n\n this.notify({\n type: 'added',\n query,\n })\n }\n }\n\n /**\n * Destroys the given `Query` and removes it from the cache, notifying subscribers with a\n * `'removed'` event. A no-op if the query is no longer the one currently stored under its hash\n * (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror\n * removals across `QueryCache` instances.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * queryCache.remove(query)\n * }\n * ```\n */\n remove(query: Query<any, any, any, any>): void {\n const queryInMap = this.#queries.get(query.queryHash)\n\n if (queryInMap) {\n query.destroy()\n\n if (queryInMap === query) {\n this.#queries.delete(query.queryHash)\n }\n\n this.notify({ type: 'removed', query })\n }\n }\n\n /**\n * Removes all queries from the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * queryCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n this.remove(query)\n })\n })\n }\n\n /**\n * Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none\n * exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather\n * than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash\n * to look up directly.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const queryHash = hashKey(['posts'])\n *\n * const query = queryCache.get(queryHash)\n * ```\n */\n get<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryHash: string,\n ): Query<TQueryFnData, TError, TData, TQueryKey> | undefined {\n return this.#queries.get(queryHash) as\n | Query<TQueryFnData, TError, TData, TQueryKey>\n | undefined\n }\n\n /**\n * Returns all queries within the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.getAll()\n * ```\n */\n getAll(): Array<Query> {\n return [...this.#queries.values()]\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing query instance from the\n * cache. This instance not only contains all the state for the query, but all of the instances,\n * and underlying guts of the query as well. If the query does not exist, `undefined` is\n * returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to\n * decide whether a query is fresh enough to be used as an initial value).\n *\n * @see {@link QueryCache#findAll}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.find({ queryKey: ['posts'] })\n * ```\n */\n find<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData>(\n filters: WithRequired<QueryFilters, 'queryKey'>,\n ): Query<TQueryFnData, TError, TData> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((query) =>\n matchQuery(defaultedFilters, query),\n ) as Query<TQueryFnData, TError, TData> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing query instances from the cache\n * that partially match a query key. If no queries match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about queries in rare scenarios.\n *\n * @see {@link QueryCache#find}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n findAll(filters: QueryFilters<any> = {}): Array<Query> {\n const queries = this.getAll()\n return Object.keys(filters).length > 0\n ? queries.filter((query) => matchQuery(filters, query))\n : queries\n }\n\n /** @internal */\n notify(event: QueryCacheNotifyEvent): void {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /** @internal */\n onFocus(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onFocus()\n })\n })\n }\n\n /** @internal */\n onOnline(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onOnline()\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0HA,IAAa,aAAb,cAAgC,aAAiC;CAG/D,YAAY,SAAkC,CAAC,GAAG;EAChD,MAAM;EADW,KAAA,SAAA;;EAEjB,uBAAA,UAAA,sBAAgB,IAAI,IAAmB,CAAA;CACzC;;;;;;;;;;;;;;;;;CAkBA,MAME,QACA,SAIA,OAC+C;EAC/C,MAAM,WAAW,QAAQ;EACzB,MAAM,YACJ,QAAQ,aAAa,sBAAsB,UAAU,OAAO;EAC9D,IAAI,QAAQ,KAAK,IAA4C,SAAS;EAEtE,IAAI,CAAC,OAAO;GACV,QAAQ,IAAI,MAAM;IAChB;IACA;IACA;IACA,SAAS,OAAO,oBAAoB,OAAO;IAC3C;IACA,gBAAgB,OAAO,iBAAiB,QAAQ;GAClD,CAAC;GACD,KAAK,IAAI,KAAK;EAChB;EAEA,OAAO;CACT;;CAGA,IAAI,OAAwC;EAC1C,IAAI,CAAA,uBAAA,UAAC,IAAA,CAAA,CAAc,IAAI,MAAM,SAAS,GAAG;GACvC,uBAAA,UAAA,IAAA,CAAA,CAAc,IAAI,MAAM,WAAW,KAAK;GAExC,KAAK,OAAO;IACV,MAAM;IACN;GACF,CAAC;EACH;CACF;;;;;;;;;;;;;;;;;CAkBA,OAAO,OAAwC;EAC7C,MAAM,aAAA,uBAAA,UAAa,IAAA,CAAA,CAAc,IAAI,MAAM,SAAS;EAEpD,IAAI,YAAY;GACd,MAAM,QAAQ;GAEd,IAAI,eAAe,OACjB,uBAAA,UAAA,IAAA,CAAA,CAAc,OAAO,MAAM,SAAS;GAGtC,KAAK,OAAO;IAAE,MAAM;IAAW;GAAM,CAAC;EACxC;CACF;;;;;;;;;;;CAYA,QAAc;EACZ,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,KAAK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