@tanstack/query-core 5.104.0 → 5.104.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/legacy/environmentManager.cjs +3 -1
- package/build/legacy/environmentManager.cjs.map +1 -1
- package/build/legacy/environmentManager.d.cts +6 -1
- package/build/legacy/environmentManager.d.cts.map +1 -1
- package/build/legacy/environmentManager.d.ts +6 -1
- package/build/legacy/environmentManager.d.ts.map +1 -1
- package/build/legacy/environmentManager.js +3 -1
- package/build/legacy/environmentManager.js.map +1 -1
- package/build/legacy/focusManager.cjs +4 -2
- package/build/legacy/focusManager.cjs.map +1 -1
- package/build/legacy/focusManager.d.cts +5 -3
- package/build/legacy/focusManager.d.cts.map +1 -1
- package/build/legacy/focusManager.d.ts +5 -3
- package/build/legacy/focusManager.d.ts.map +1 -1
- package/build/legacy/focusManager.js +4 -2
- package/build/legacy/focusManager.js.map +1 -1
- package/build/legacy/{hydration-B9t5w6NC.d.ts → hydration-Dfuxd5FW.d.cts} +1410 -128
- package/build/legacy/hydration-Dfuxd5FW.d.cts.map +1 -0
- package/build/legacy/{hydration-Br9VIGXa.d.cts → hydration-UAqdtMIf.d.ts} +1410 -128
- package/build/legacy/hydration-UAqdtMIf.d.ts.map +1 -0
- package/build/legacy/hydration.cjs +35 -0
- 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 +35 -0
- package/build/legacy/hydration.js.map +1 -1
- package/build/legacy/index.d.cts +1 -1
- package/build/legacy/index.d.ts +1 -1
- package/build/legacy/infiniteQueryBehavior.cjs +29 -0
- package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +16 -1
- package/build/legacy/infiniteQueryBehavior.d.cts.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +16 -1
- package/build/legacy/infiniteQueryBehavior.d.ts.map +1 -1
- package/build/legacy/infiniteQueryBehavior.js +29 -0
- package/build/legacy/infiniteQueryBehavior.js.map +1 -1
- package/build/legacy/infiniteQueryObserver.cjs +13 -7
- package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +15 -9
- package/build/legacy/infiniteQueryObserver.d.cts.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.ts +15 -9
- package/build/legacy/infiniteQueryObserver.d.ts.map +1 -1
- package/build/legacy/infiniteQueryObserver.js +13 -7
- package/build/legacy/infiniteQueryObserver.js.map +1 -1
- package/build/legacy/mutation.cjs +27 -10
- 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 +27 -10
- package/build/legacy/mutation.js.map +1 -1
- package/build/legacy/mutationCache.cjs +53 -12
- 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 +53 -12
- package/build/legacy/mutationCache.js.map +1 -1
- package/build/legacy/mutationObserver.cjs +27 -16
- 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 +27 -16
- package/build/legacy/mutationObserver.js.map +1 -1
- package/build/legacy/notifyManager.cjs +12 -2
- package/build/legacy/notifyManager.cjs.map +1 -1
- package/build/legacy/notifyManager.d.cts +19 -4
- package/build/legacy/notifyManager.d.cts.map +1 -1
- package/build/legacy/notifyManager.d.ts +19 -4
- package/build/legacy/notifyManager.d.ts.map +1 -1
- package/build/legacy/notifyManager.js +12 -2
- package/build/legacy/notifyManager.js.map +1 -1
- package/build/legacy/onlineManager.cjs +4 -2
- package/build/legacy/onlineManager.cjs.map +1 -1
- package/build/legacy/onlineManager.d.cts +5 -3
- package/build/legacy/onlineManager.d.cts.map +1 -1
- package/build/legacy/onlineManager.d.ts +5 -3
- package/build/legacy/onlineManager.d.ts.map +1 -1
- package/build/legacy/onlineManager.js +4 -2
- package/build/legacy/onlineManager.js.map +1 -1
- package/build/legacy/queriesObserver.cjs +15 -3
- package/build/legacy/queriesObserver.cjs.map +1 -1
- package/build/legacy/queriesObserver.d.cts +14 -5
- package/build/legacy/queriesObserver.d.cts.map +1 -1
- package/build/legacy/queriesObserver.d.ts +14 -5
- package/build/legacy/queriesObserver.d.ts.map +1 -1
- package/build/legacy/queriesObserver.js +15 -3
- package/build/legacy/queriesObserver.js.map +1 -1
- package/build/legacy/query.cjs +89 -15
- 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 +89 -15
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryCache.cjs +34 -12
- 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 +34 -12
- package/build/legacy/queryCache.js.map +1 -1
- package/build/legacy/queryClient.cjs +104 -32
- 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 +104 -32
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryObserver.cjs +78 -6
- 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 +78 -6
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/{modern/removable-0GzhW1PK.d.cts → legacy/removable-Cw9GNGyK.d.cts} +17 -1
- package/build/legacy/removable-Cw9GNGyK.d.cts.map +1 -0
- package/build/legacy/{removable-0GzhW1PK.d.cts → removable-Cw9GNGyK.d.ts} +17 -1
- package/build/legacy/removable-Cw9GNGyK.d.ts.map +1 -0
- package/build/legacy/removable.cjs +12 -0
- package/build/legacy/removable.cjs.map +1 -1
- package/build/legacy/removable.d.cts +1 -1
- package/build/legacy/removable.d.ts +1 -1
- package/build/legacy/removable.js +12 -0
- package/build/legacy/removable.js.map +1 -1
- package/build/legacy/retryer.cjs +26 -4
- 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 +26 -4
- package/build/legacy/retryer.js.map +1 -1
- package/build/legacy/streamedQuery.cjs +3 -1
- package/build/legacy/streamedQuery.cjs.map +1 -1
- package/build/legacy/streamedQuery.d.cts +4 -2
- package/build/legacy/streamedQuery.d.cts.map +1 -1
- package/build/legacy/streamedQuery.d.ts +4 -2
- package/build/legacy/streamedQuery.d.ts.map +1 -1
- package/build/legacy/streamedQuery.js +3 -1
- package/build/legacy/streamedQuery.js.map +1 -1
- package/build/{modern/subscribable-CysQ0tne.d.cts → legacy/subscribable-czlHOxMP.d.cts} +11 -1
- package/build/legacy/subscribable-czlHOxMP.d.cts.map +1 -0
- package/build/legacy/{subscribable-CysQ0tne.d.cts → subscribable-czlHOxMP.d.ts} +11 -1
- package/build/legacy/subscribable-czlHOxMP.d.ts.map +1 -0
- package/build/legacy/subscribable.cjs +10 -0
- package/build/legacy/subscribable.cjs.map +1 -1
- package/build/legacy/subscribable.d.cts +1 -1
- package/build/legacy/subscribable.d.ts +1 -1
- package/build/legacy/subscribable.js +10 -0
- package/build/legacy/subscribable.js.map +1 -1
- package/build/legacy/timeoutManager.cjs +11 -6
- package/build/legacy/timeoutManager.cjs.map +1 -1
- package/build/legacy/timeoutManager.d.cts +23 -6
- package/build/legacy/timeoutManager.d.cts.map +1 -1
- package/build/legacy/timeoutManager.d.ts +23 -6
- package/build/legacy/timeoutManager.d.ts.map +1 -1
- package/build/legacy/timeoutManager.js +11 -6
- 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 +117 -8
- 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 +117 -8
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/environmentManager.cjs +3 -1
- package/build/modern/environmentManager.cjs.map +1 -1
- package/build/modern/environmentManager.d.cts +6 -1
- package/build/modern/environmentManager.d.cts.map +1 -1
- package/build/modern/environmentManager.d.ts +6 -1
- package/build/modern/environmentManager.d.ts.map +1 -1
- package/build/modern/environmentManager.js +3 -1
- package/build/modern/environmentManager.js.map +1 -1
- package/build/modern/focusManager.cjs +4 -2
- package/build/modern/focusManager.cjs.map +1 -1
- package/build/modern/focusManager.d.cts +5 -3
- package/build/modern/focusManager.d.cts.map +1 -1
- package/build/modern/focusManager.d.ts +5 -3
- package/build/modern/focusManager.d.ts.map +1 -1
- package/build/modern/focusManager.js +4 -2
- package/build/modern/focusManager.js.map +1 -1
- package/build/modern/{hydration-B9t5w6NC.d.ts → hydration-Dfuxd5FW.d.cts} +1410 -128
- package/build/modern/hydration-Dfuxd5FW.d.cts.map +1 -0
- package/build/modern/{hydration-Br9VIGXa.d.cts → hydration-UAqdtMIf.d.ts} +1410 -128
- package/build/modern/hydration-UAqdtMIf.d.ts.map +1 -0
- package/build/modern/hydration.cjs +35 -0
- 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 +35 -0
- package/build/modern/hydration.js.map +1 -1
- package/build/modern/index.d.cts +1 -1
- package/build/modern/index.d.ts +1 -1
- package/build/modern/infiniteQueryBehavior.cjs +29 -0
- package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +16 -1
- package/build/modern/infiniteQueryBehavior.d.cts.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +16 -1
- package/build/modern/infiniteQueryBehavior.d.ts.map +1 -1
- package/build/modern/infiniteQueryBehavior.js +29 -0
- package/build/modern/infiniteQueryBehavior.js.map +1 -1
- package/build/modern/infiniteQueryObserver.cjs +13 -7
- package/build/modern/infiniteQueryObserver.cjs.map +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +15 -9
- package/build/modern/infiniteQueryObserver.d.cts.map +1 -1
- package/build/modern/infiniteQueryObserver.d.ts +15 -9
- package/build/modern/infiniteQueryObserver.d.ts.map +1 -1
- package/build/modern/infiniteQueryObserver.js +13 -7
- package/build/modern/infiniteQueryObserver.js.map +1 -1
- package/build/modern/mutation.cjs +27 -10
- 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 +27 -10
- package/build/modern/mutation.js.map +1 -1
- package/build/modern/mutationCache.cjs +53 -12
- 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 +53 -12
- package/build/modern/mutationCache.js.map +1 -1
- package/build/modern/mutationObserver.cjs +23 -12
- 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 +23 -12
- package/build/modern/mutationObserver.js.map +1 -1
- package/build/modern/notifyManager.cjs +12 -2
- package/build/modern/notifyManager.cjs.map +1 -1
- package/build/modern/notifyManager.d.cts +19 -4
- package/build/modern/notifyManager.d.cts.map +1 -1
- package/build/modern/notifyManager.d.ts +19 -4
- package/build/modern/notifyManager.d.ts.map +1 -1
- package/build/modern/notifyManager.js +12 -2
- package/build/modern/notifyManager.js.map +1 -1
- package/build/modern/onlineManager.cjs +4 -2
- package/build/modern/onlineManager.cjs.map +1 -1
- package/build/modern/onlineManager.d.cts +5 -3
- package/build/modern/onlineManager.d.cts.map +1 -1
- package/build/modern/onlineManager.d.ts +5 -3
- package/build/modern/onlineManager.d.ts.map +1 -1
- package/build/modern/onlineManager.js +4 -2
- package/build/modern/onlineManager.js.map +1 -1
- package/build/modern/queriesObserver.cjs +15 -3
- package/build/modern/queriesObserver.cjs.map +1 -1
- package/build/modern/queriesObserver.d.cts +14 -5
- package/build/modern/queriesObserver.d.cts.map +1 -1
- package/build/modern/queriesObserver.d.ts +14 -5
- package/build/modern/queriesObserver.d.ts.map +1 -1
- package/build/modern/queriesObserver.js +15 -3
- package/build/modern/queriesObserver.js.map +1 -1
- package/build/modern/query.cjs +89 -15
- 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 +89 -15
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryCache.cjs +34 -12
- 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 +34 -12
- package/build/modern/queryCache.js.map +1 -1
- package/build/modern/queryClient.cjs +104 -32
- 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 +104 -32
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryObserver.cjs +78 -6
- 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 +78 -6
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/{removable-0GzhW1PK.d.ts → removable-Cw9GNGyK.d.cts} +17 -1
- package/build/modern/removable-Cw9GNGyK.d.cts.map +1 -0
- package/build/{legacy/removable-0GzhW1PK.d.ts → modern/removable-Cw9GNGyK.d.ts} +17 -1
- package/build/modern/removable-Cw9GNGyK.d.ts.map +1 -0
- package/build/modern/removable.cjs +12 -0
- package/build/modern/removable.cjs.map +1 -1
- package/build/modern/removable.d.cts +1 -1
- package/build/modern/removable.d.ts +1 -1
- package/build/modern/removable.js +12 -0
- package/build/modern/removable.js.map +1 -1
- package/build/modern/retryer.cjs +26 -4
- 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 +26 -4
- package/build/modern/retryer.js.map +1 -1
- package/build/modern/streamedQuery.cjs +3 -1
- package/build/modern/streamedQuery.cjs.map +1 -1
- package/build/modern/streamedQuery.d.cts +4 -2
- package/build/modern/streamedQuery.d.cts.map +1 -1
- package/build/modern/streamedQuery.d.ts +4 -2
- package/build/modern/streamedQuery.d.ts.map +1 -1
- package/build/modern/streamedQuery.js +3 -1
- package/build/modern/streamedQuery.js.map +1 -1
- package/build/modern/{subscribable-CysQ0tne.d.ts → subscribable-czlHOxMP.d.cts} +11 -1
- package/build/modern/subscribable-czlHOxMP.d.cts.map +1 -0
- package/build/{legacy/subscribable-CysQ0tne.d.ts → modern/subscribable-czlHOxMP.d.ts} +11 -1
- package/build/modern/subscribable-czlHOxMP.d.ts.map +1 -0
- package/build/modern/subscribable.cjs +10 -0
- package/build/modern/subscribable.cjs.map +1 -1
- package/build/modern/subscribable.d.cts +1 -1
- package/build/modern/subscribable.d.ts +1 -1
- package/build/modern/subscribable.js +10 -0
- package/build/modern/subscribable.js.map +1 -1
- package/build/modern/timeoutManager.cjs +11 -6
- package/build/modern/timeoutManager.cjs.map +1 -1
- package/build/modern/timeoutManager.d.cts +23 -6
- package/build/modern/timeoutManager.d.cts.map +1 -1
- package/build/modern/timeoutManager.d.ts +23 -6
- package/build/modern/timeoutManager.d.ts.map +1 -1
- package/build/modern/timeoutManager.js +11 -6
- 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 +117 -8
- 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 +117 -8
- package/build/modern/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/environmentManager.ts +6 -1
- package/src/focusManager.ts +8 -6
- package/src/hydration.ts +42 -1
- package/src/infiniteQueryBehavior.ts +29 -0
- package/src/infiniteQueryObserver.ts +20 -14
- package/src/mutation.ts +32 -11
- package/src/mutationCache.ts +53 -12
- package/src/mutationObserver.ts +29 -14
- package/src/notifyManager.ts +12 -2
- package/src/onlineManager.ts +7 -5
- package/src/queriesObserver.ts +20 -5
- package/src/query.ts +153 -20
- package/src/queryCache.ts +54 -13
- package/src/queryClient.ts +110 -38
- package/src/queryObserver.ts +88 -12
- package/src/removable.ts +16 -0
- package/src/retryer.ts +57 -4
- package/src/streamedQuery.ts +4 -3
- package/src/subscribable.ts +10 -0
- package/src/timeoutManager.ts +23 -6
- package/src/types.ts +801 -27
- package/src/utils.ts +130 -10
- package/build/legacy/hydration-B9t5w6NC.d.ts.map +0 -1
- package/build/legacy/hydration-Br9VIGXa.d.cts.map +0 -1
- package/build/legacy/removable-0GzhW1PK.d.cts.map +0 -1
- package/build/legacy/removable-0GzhW1PK.d.ts.map +0 -1
- package/build/legacy/subscribable-CysQ0tne.d.cts.map +0 -1
- package/build/legacy/subscribable-CysQ0tne.d.ts.map +0 -1
- package/build/modern/hydration-B9t5w6NC.d.ts.map +0 -1
- package/build/modern/hydration-Br9VIGXa.d.cts.map +0 -1
- package/build/modern/removable-0GzhW1PK.d.cts.map +0 -1
- package/build/modern/removable-0GzhW1PK.d.ts.map +0 -1
- package/build/modern/subscribable-CysQ0tne.d.cts.map +0 -1
- package/build/modern/subscribable-CysQ0tne.d.ts.map +0 -1
package/src/queryClient.ts
CHANGED
|
@@ -62,7 +62,6 @@ interface MutationDefaults {
|
|
|
62
62
|
* `QueryClient` is used to interact with a cache of queries and mutations. It owns a
|
|
63
63
|
* `QueryCache` and a `MutationCache` (creating default ones if none are passed in) and holds
|
|
64
64
|
* the default options that are applied to queries and mutations created through it.
|
|
65
|
-
*
|
|
66
65
|
* @example
|
|
67
66
|
* ```ts
|
|
68
67
|
* const queryClient = new QueryClient({
|
|
@@ -139,7 +138,9 @@ export class QueryClient {
|
|
|
139
138
|
* Returns the number of queries in the cache that are currently fetching, optionally
|
|
140
139
|
* matching a set of filters. This includes background-fetching, loading new pages, and
|
|
141
140
|
* loading more infinite query results.
|
|
142
|
-
*
|
|
141
|
+
* @param filters - Narrows down which fetching queries are counted. Without filters, every
|
|
142
|
+
* fetching query is counted.
|
|
143
|
+
* @returns The number of matching queries whose `fetchStatus` is `'fetching'`.
|
|
143
144
|
* @example
|
|
144
145
|
* ```ts
|
|
145
146
|
* if (queryClient.isFetching()) {
|
|
@@ -157,7 +158,9 @@ export class QueryClient {
|
|
|
157
158
|
/**
|
|
158
159
|
* Returns the number of mutations in the cache that are currently pending, optionally
|
|
159
160
|
* matching a set of filters.
|
|
160
|
-
*
|
|
161
|
+
* @param filters - Narrows down which pending mutations are counted. Without filters, every
|
|
162
|
+
* pending mutation is counted.
|
|
163
|
+
* @returns The number of matching mutations whose `status` is `'pending'`.
|
|
161
164
|
* @example
|
|
162
165
|
* ```ts
|
|
163
166
|
* if (queryClient.isMutating()) {
|
|
@@ -177,7 +180,7 @@ export class QueryClient {
|
|
|
177
180
|
*
|
|
178
181
|
* Hint: Do not use this function inside a component, because it won't receive updates.
|
|
179
182
|
* Use `useQuery` to create a `QueryObserver` that subscribes to changes.
|
|
180
|
-
*
|
|
183
|
+
* @param queryKey - The query key of the query to read.
|
|
181
184
|
* @returns The cached data for the query, or `undefined` if no query with this key has been observed yet.
|
|
182
185
|
* @see {@link QueryClient#getQueriesData}
|
|
183
186
|
*/
|
|
@@ -193,6 +196,12 @@ export class QueryClient {
|
|
|
193
196
|
}
|
|
194
197
|
|
|
195
198
|
/**
|
|
199
|
+
* Returns the cached data of a query, or fetches it if there is none. With `revalidateIfStale`,
|
|
200
|
+
* stale cached data is also refetched in the background.
|
|
201
|
+
* @param options - The query options. If the query has no cached data yet, it is fetched with
|
|
202
|
+
* these options.
|
|
203
|
+
* @returns A promise that resolves to the cached data, or to the fetched data if nothing was
|
|
204
|
+
* cached yet.
|
|
196
205
|
* @deprecated Use queryClient.query({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
|
|
197
206
|
*/
|
|
198
207
|
ensureQueryData<
|
|
@@ -208,7 +217,7 @@ export class QueryClient {
|
|
|
208
217
|
const cachedData = query.state.data
|
|
209
218
|
|
|
210
219
|
if (cachedData === undefined) {
|
|
211
|
-
//
|
|
220
|
+
// oxlint-disable-next-line tanstack-query/no-restricted-syntax
|
|
212
221
|
return this.fetchQuery(options)
|
|
213
222
|
}
|
|
214
223
|
|
|
@@ -216,7 +225,7 @@ export class QueryClient {
|
|
|
216
225
|
options.revalidateIfStale &&
|
|
217
226
|
query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query))
|
|
218
227
|
) {
|
|
219
|
-
//
|
|
228
|
+
// oxlint-disable-next-line tanstack-query/no-restricted-syntax
|
|
220
229
|
void this.prefetchQuery(defaultedOptions)
|
|
221
230
|
}
|
|
222
231
|
|
|
@@ -233,7 +242,7 @@ export class QueryClient {
|
|
|
233
242
|
* than being inferred. Passing a more specific type is a convenience for call sites that know
|
|
234
243
|
* every matched query holds the same shape — it is not checked against the actual cache
|
|
235
244
|
* contents.
|
|
236
|
-
*
|
|
245
|
+
* @param filters - The filters that select which queries to read.
|
|
237
246
|
* @returns An array of query key and data pairs. The data is `undefined` for a query with no cached data.
|
|
238
247
|
* @see {@link QueryClient#getQueryData}
|
|
239
248
|
* @example
|
|
@@ -259,14 +268,12 @@ export class QueryClient {
|
|
|
259
268
|
*
|
|
260
269
|
* Updates must be performed immutably: do not mutate `oldData`, or data previously retrieved
|
|
261
270
|
* via {@link QueryClient#getQueryData}, in place.
|
|
262
|
-
*
|
|
263
271
|
* @param queryKey - The query key to set data for.
|
|
264
272
|
* @param updater - Either the new data, or a function that receives the current data (which
|
|
265
273
|
* may be `undefined`) and returns the new data.
|
|
266
274
|
* @param options - Set `updatedAt` to override the timestamp the written data is recorded with.
|
|
267
275
|
* @returns The data that was written, or `undefined` if the updater returned `undefined` — in that case
|
|
268
276
|
* the write is skipped and the cache is left unchanged.
|
|
269
|
-
*
|
|
270
277
|
* @example
|
|
271
278
|
* ```ts
|
|
272
279
|
* queryClient.setQueryData(['posts'], newPosts)
|
|
@@ -315,7 +322,10 @@ export class QueryClient {
|
|
|
315
322
|
* filters or partial query key matching. Only queries that already exist and match the given
|
|
316
323
|
* filters are updated; no new cache entries are created. Internally this calls
|
|
317
324
|
* {@link QueryClient#setQueryData} for each matching query.
|
|
318
|
-
*
|
|
325
|
+
* @param filters - The filters that select which existing queries to update.
|
|
326
|
+
* @param updater - Either the new data, or a function that receives each matched query's current
|
|
327
|
+
* data (which may be `undefined`) and returns the new data.
|
|
328
|
+
* @param options - Set `updatedAt` to override the timestamp the written data is recorded with.
|
|
319
329
|
* @returns One `[queryKey, data]` tuple per matched query, in the same shape and with the same
|
|
320
330
|
* `undefined` case as {@link QueryClient#setQueryData}.
|
|
321
331
|
* @example
|
|
@@ -349,7 +359,8 @@ export class QueryClient {
|
|
|
349
359
|
/**
|
|
350
360
|
* Imperative (non-reactive) way to retrieve an existing query's state. If the query does not
|
|
351
361
|
* exist, `undefined` is returned.
|
|
352
|
-
*
|
|
362
|
+
* @param queryKey - The query key of the query to read.
|
|
363
|
+
* @returns The query's state, or `undefined` if no query with this key exists.
|
|
353
364
|
* @example
|
|
354
365
|
* ```ts
|
|
355
366
|
* const state = queryClient.getQueryState(['posts'])
|
|
@@ -376,7 +387,8 @@ export class QueryClient {
|
|
|
376
387
|
* {@link QueryClient#invalidateQueries} or {@link QueryClient#refetchQueries}, this removes
|
|
377
388
|
* matching queries from the cache instead of refetching them. Without filters, every query in
|
|
378
389
|
* the cache is removed.
|
|
379
|
-
*
|
|
390
|
+
* @param filters - The filters that select which queries to remove. Without filters, every query
|
|
391
|
+
* is removed.
|
|
380
392
|
* @example
|
|
381
393
|
* ```ts
|
|
382
394
|
* queryClient.removeQueries({ queryKey: ['posts'], exact: true })
|
|
@@ -397,7 +409,11 @@ export class QueryClient {
|
|
|
397
409
|
* Resets queries matching the given filters back to their initial state (e.g. any
|
|
398
410
|
* `initialData`), notifying subscribers rather than removing them. Active queries among the
|
|
399
411
|
* matched set are then refetched, and the returned promise resolves once that refetch settles.
|
|
400
|
-
*
|
|
412
|
+
* @param filters - The filters that select which queries to reset. Without filters, every query
|
|
413
|
+
* is reset.
|
|
414
|
+
* @param options - Passed to the refetch of the active matched queries, e.g. `cancelRefetch` and
|
|
415
|
+
* `throwOnError`.
|
|
416
|
+
* @returns A promise that resolves once the refetch of the active matched queries settles.
|
|
401
417
|
* @example
|
|
402
418
|
* ```ts
|
|
403
419
|
* await queryClient.resetQueries({ queryKey: ['posts'], exact: true })
|
|
@@ -432,7 +448,11 @@ export class QueryClient {
|
|
|
432
448
|
* reverted to its state before the outgoing fetch started.
|
|
433
449
|
*
|
|
434
450
|
* The returned promise never rejects, even if individual cancellations fail.
|
|
435
|
-
*
|
|
451
|
+
* @param filters - The filters that select which queries to cancel. Without filters, every query
|
|
452
|
+
* is cancelled.
|
|
453
|
+
* @param cancelOptions - Passed to each matched query's cancellation. `revert` defaults to
|
|
454
|
+
* `true`.
|
|
455
|
+
* @returns A promise that resolves once every cancellation has settled.
|
|
436
456
|
* @example
|
|
437
457
|
* ```ts
|
|
438
458
|
* await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })
|
|
@@ -460,7 +480,12 @@ export class QueryClient {
|
|
|
460
480
|
* Unless `filters.refetchType` is `'none'`, matching queries are then refetched via
|
|
461
481
|
* {@link QueryClient#refetchQueries}, using `filters.refetchType` if set, otherwise
|
|
462
482
|
* `filters.type`, otherwise `'active'`.
|
|
463
|
-
*
|
|
483
|
+
* @param filters - The filters that select which queries to invalidate, plus `refetchType` to
|
|
484
|
+
* control which of them to refetch afterwards. Without filters, every query is invalidated.
|
|
485
|
+
* @param options - Passed to {@link QueryClient#refetchQueries}, e.g. `cancelRefetch` and
|
|
486
|
+
* `throwOnError`.
|
|
487
|
+
* @returns A promise that resolves once the refetch settles, or immediately if `refetchType` is
|
|
488
|
+
* `'none'`.
|
|
464
489
|
* @example
|
|
465
490
|
* ```ts
|
|
466
491
|
* await queryClient.invalidateQueries({ queryKey: ['posts'], refetchType: 'active' })
|
|
@@ -496,7 +521,11 @@ export class QueryClient {
|
|
|
496
521
|
* By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new
|
|
497
522
|
* one starts. The returned promise resolves once all matching queries have settled; it does
|
|
498
523
|
* not reject on individual query failures unless `throwOnError` is set.
|
|
499
|
-
*
|
|
524
|
+
* @param filters - The filters that select which queries to refetch. Without filters, every query
|
|
525
|
+
* in the cache is included.
|
|
526
|
+
* @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling
|
|
527
|
+
* it, and `throwOnError` to `true` to reject when a refetch fails.
|
|
528
|
+
* @returns A promise that resolves once every matched query has settled.
|
|
500
529
|
* @example
|
|
501
530
|
* ```ts
|
|
502
531
|
* // refetch all active queries partially matching a query key:
|
|
@@ -550,7 +579,10 @@ export class QueryClient {
|
|
|
550
579
|
*
|
|
551
580
|
* This method replaces the deprecated `fetchQuery`, and — combined with
|
|
552
581
|
* `{ staleTime: 'static' }` — the deprecated `ensureQueryData`.
|
|
553
|
-
*
|
|
582
|
+
* @param options - The query options, including the `queryKey` and the `queryFn` used if the
|
|
583
|
+
* query needs to fetch.
|
|
584
|
+
* @returns A promise that resolves to the data, or to the result of `select` if provided. It
|
|
585
|
+
* rejects with the error from the fetch or from `select`.
|
|
554
586
|
* @example
|
|
555
587
|
* ```ts
|
|
556
588
|
* try {
|
|
@@ -604,6 +636,12 @@ export class QueryClient {
|
|
|
604
636
|
}
|
|
605
637
|
|
|
606
638
|
/**
|
|
639
|
+
* Fetches and caches a query, or returns its cached data if it isn't stale. Unlike in observers,
|
|
640
|
+
* the fetch isn't retried unless `retry` is set.
|
|
641
|
+
* @param options - The query options, including the `queryKey` and the `queryFn` used if the
|
|
642
|
+
* query needs to fetch.
|
|
643
|
+
* @returns A promise that resolves to the cached or fetched data, or rejects with the fetch
|
|
644
|
+
* error.
|
|
607
645
|
* @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.
|
|
608
646
|
*/
|
|
609
647
|
fetchQuery<
|
|
@@ -638,6 +676,11 @@ export class QueryClient {
|
|
|
638
676
|
}
|
|
639
677
|
|
|
640
678
|
/**
|
|
679
|
+
* Fetches and caches a query like {@link QueryClient#fetchQuery}, but ignores the result and any
|
|
680
|
+
* error.
|
|
681
|
+
* @param options - The query options, including the `queryKey` and the `queryFn` used if the
|
|
682
|
+
* query needs to fetch.
|
|
683
|
+
* @returns A promise that resolves once the fetch settles. It never rejects.
|
|
641
684
|
* @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.
|
|
642
685
|
*/
|
|
643
686
|
prefetchQuery<
|
|
@@ -648,7 +691,7 @@ export class QueryClient {
|
|
|
648
691
|
>(
|
|
649
692
|
options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
650
693
|
): Promise<void> {
|
|
651
|
-
//
|
|
694
|
+
// oxlint-disable-next-line tanstack-query/no-restricted-syntax
|
|
652
695
|
return this.fetchQuery(options).then(noop).catch(noop)
|
|
653
696
|
}
|
|
654
697
|
|
|
@@ -662,7 +705,10 @@ export class QueryClient {
|
|
|
662
705
|
*
|
|
663
706
|
* This method replaces the deprecated `fetchInfiniteQuery`, and — combined with
|
|
664
707
|
* `{ staleTime: 'static' }` — the deprecated `ensureInfiniteQueryData`.
|
|
665
|
-
*
|
|
708
|
+
* @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the
|
|
709
|
+
* `initialPageParam`.
|
|
710
|
+
* @returns A promise that resolves to the {@link InfiniteData}, or to the result of `select` if
|
|
711
|
+
* provided. It rejects with the error from the fetch or from `select`.
|
|
666
712
|
* @example
|
|
667
713
|
* ```ts
|
|
668
714
|
* try {
|
|
@@ -697,6 +743,11 @@ export class QueryClient {
|
|
|
697
743
|
}
|
|
698
744
|
|
|
699
745
|
/**
|
|
746
|
+
* Fetches and caches an infinite query, or returns its cached data if it isn't stale.
|
|
747
|
+
* @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the
|
|
748
|
+
* `initialPageParam`.
|
|
749
|
+
* @returns A promise that resolves to the cached or fetched {@link InfiniteData}, or rejects with
|
|
750
|
+
* the fetch error.
|
|
700
751
|
* @deprecated Use queryClient.infiniteQuery(options) instead. This method will be removed in the next major version.
|
|
701
752
|
*/
|
|
702
753
|
fetchInfiniteQuery<
|
|
@@ -715,11 +766,16 @@ export class QueryClient {
|
|
|
715
766
|
>,
|
|
716
767
|
): Promise<InfiniteData<TData, TPageParam>> {
|
|
717
768
|
options._type = 'infinite'
|
|
718
|
-
//
|
|
769
|
+
// oxlint-disable-next-line tanstack-query/no-restricted-syntax
|
|
719
770
|
return this.fetchQuery(options as any)
|
|
720
771
|
}
|
|
721
772
|
|
|
722
773
|
/**
|
|
774
|
+
* Fetches and caches an infinite query like {@link QueryClient#fetchInfiniteQuery}, but ignores
|
|
775
|
+
* the result and any error.
|
|
776
|
+
* @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the
|
|
777
|
+
* `initialPageParam`.
|
|
778
|
+
* @returns A promise that resolves once the fetch settles. It never rejects.
|
|
723
779
|
* @deprecated Use queryClient.infiniteQuery(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.
|
|
724
780
|
*/
|
|
725
781
|
prefetchInfiniteQuery<
|
|
@@ -737,11 +793,17 @@ export class QueryClient {
|
|
|
737
793
|
TPageParam
|
|
738
794
|
>,
|
|
739
795
|
): Promise<void> {
|
|
740
|
-
//
|
|
796
|
+
// oxlint-disable-next-line tanstack-query/no-restricted-syntax
|
|
741
797
|
return this.fetchInfiniteQuery(options).then(noop).catch(noop)
|
|
742
798
|
}
|
|
743
799
|
|
|
744
800
|
/**
|
|
801
|
+
* Returns the cached data of an infinite query, or fetches it if there is none. With
|
|
802
|
+
* `revalidateIfStale`, stale cached data is also refetched in the background.
|
|
803
|
+
* @param options - The infinite query options. If the query has no cached data yet, it is fetched
|
|
804
|
+
* with these options.
|
|
805
|
+
* @returns A promise that resolves to the cached {@link InfiniteData}, or to the fetched data if
|
|
806
|
+
* nothing was cached yet.
|
|
745
807
|
* @deprecated Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
|
|
746
808
|
*/
|
|
747
809
|
ensureInfiniteQueryData<
|
|
@@ -761,14 +823,14 @@ export class QueryClient {
|
|
|
761
823
|
): Promise<InfiniteData<TData, TPageParam>> {
|
|
762
824
|
options._type = 'infinite'
|
|
763
825
|
|
|
764
|
-
//
|
|
826
|
+
// oxlint-disable-next-line tanstack-query/no-restricted-syntax
|
|
765
827
|
return this.ensureQueryData(options as any)
|
|
766
828
|
}
|
|
767
829
|
|
|
768
830
|
/**
|
|
769
831
|
* Resumes mutations that were paused because there was no network connection. Does nothing
|
|
770
832
|
* (resolving immediately) if the client is currently offline.
|
|
771
|
-
*
|
|
833
|
+
* @returns A promise that resolves once the resumed mutations have settled.
|
|
772
834
|
* @example
|
|
773
835
|
* ```ts
|
|
774
836
|
* import { QueryClient } from '@tanstack/query-core'
|
|
@@ -786,7 +848,7 @@ export class QueryClient {
|
|
|
786
848
|
|
|
787
849
|
/**
|
|
788
850
|
* Returns the query cache this client is connected to.
|
|
789
|
-
*
|
|
851
|
+
* @returns The {@link QueryCache} instance.
|
|
790
852
|
* @example
|
|
791
853
|
* ```ts
|
|
792
854
|
* import { QueryClient } from '@tanstack/query-core'
|
|
@@ -802,7 +864,7 @@ export class QueryClient {
|
|
|
802
864
|
|
|
803
865
|
/**
|
|
804
866
|
* Returns the mutation cache this client is connected to.
|
|
805
|
-
*
|
|
867
|
+
* @returns The {@link MutationCache} instance.
|
|
806
868
|
* @example
|
|
807
869
|
* ```ts
|
|
808
870
|
* import { QueryClient } from '@tanstack/query-core'
|
|
@@ -819,7 +881,7 @@ export class QueryClient {
|
|
|
819
881
|
/**
|
|
820
882
|
* Returns the default options that were set when creating the client, or via
|
|
821
883
|
* {@link QueryClient#setDefaultOptions}.
|
|
822
|
-
*
|
|
884
|
+
* @returns The client's current default options.
|
|
823
885
|
* @example
|
|
824
886
|
* ```ts
|
|
825
887
|
* import { QueryClient } from '@tanstack/query-core'
|
|
@@ -835,7 +897,7 @@ export class QueryClient {
|
|
|
835
897
|
/**
|
|
836
898
|
* Dynamically sets the default options for this client, overwriting any previously defined
|
|
837
899
|
* default options.
|
|
838
|
-
*
|
|
900
|
+
* @param options - The new default options for queries and mutations.
|
|
839
901
|
* @see {@link QueryClient#getDefaultOptions}
|
|
840
902
|
* @example
|
|
841
903
|
* ```ts
|
|
@@ -860,7 +922,8 @@ export class QueryClient {
|
|
|
860
922
|
* registration order by {@link QueryClient#getQueryDefaults}, so register defaults from the
|
|
861
923
|
* most generic key to the least generic one — more specific defaults should be registered
|
|
862
924
|
* after more generic ones so they take precedence.
|
|
863
|
-
*
|
|
925
|
+
* @param queryKey - The query key that query keys are partially matched against.
|
|
926
|
+
* @param options - The default options applied to matching queries.
|
|
864
927
|
* @example
|
|
865
928
|
* ```ts
|
|
866
929
|
* queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts })
|
|
@@ -892,7 +955,9 @@ export class QueryClient {
|
|
|
892
955
|
* Returns the default options registered for queries whose query key partially matches the
|
|
893
956
|
* given `queryKey`, via {@link QueryClient#setQueryDefaults}. If multiple registered defaults
|
|
894
957
|
* match, they are merged together in registration order.
|
|
895
|
-
*
|
|
958
|
+
* @param queryKey - The query key to look up registered defaults for.
|
|
959
|
+
* @returns The merged default options of every registration that matches, or an empty object if
|
|
960
|
+
* none match.
|
|
896
961
|
* @example
|
|
897
962
|
* ```ts
|
|
898
963
|
* const defaultOptions = queryClient.getQueryDefaults(['posts'])
|
|
@@ -920,7 +985,8 @@ export class QueryClient {
|
|
|
920
985
|
* Sets default options for mutations whose mutation key partially matches the given
|
|
921
986
|
* `mutationKey`. As with {@link QueryClient#setQueryDefaults}, the order of registration
|
|
922
987
|
* matters when several registered defaults match the same mutation key.
|
|
923
|
-
*
|
|
988
|
+
* @param mutationKey - The mutation key that mutation keys are partially matched against.
|
|
989
|
+
* @param options - The default options applied to matching mutations.
|
|
924
990
|
* @see {@link QueryClient#getMutationDefaults}
|
|
925
991
|
* @example
|
|
926
992
|
* ```ts
|
|
@@ -949,7 +1015,9 @@ export class QueryClient {
|
|
|
949
1015
|
* Returns the default options registered for mutations whose mutation key partially matches
|
|
950
1016
|
* the given `mutationKey`, via {@link QueryClient#setMutationDefaults}. If multiple registered
|
|
951
1017
|
* defaults match, they are merged together in registration order.
|
|
952
|
-
*
|
|
1018
|
+
* @param mutationKey - The mutation key to look up registered defaults for.
|
|
1019
|
+
* @returns The merged default options of every registration that matches, or an empty object if
|
|
1020
|
+
* none match.
|
|
953
1021
|
* @example
|
|
954
1022
|
* ```ts
|
|
955
1023
|
* const defaultOptions = queryClient.getMutationDefaults(['addPost'])
|
|
@@ -976,9 +1044,12 @@ export class QueryClient {
|
|
|
976
1044
|
|
|
977
1045
|
/**
|
|
978
1046
|
* Called by framework adapters (e.g. inside `useQuery`) to resolve the options passed by the
|
|
979
|
-
* caller into their final, defaulted form: merging `
|
|
980
|
-
*
|
|
981
|
-
*
|
|
1047
|
+
* caller into their final, defaulted form: merging the client's own `defaultOptions.queries`,
|
|
1048
|
+
* then `queryClient.setQueryDefaults` for the given `queryKey`, then the caller's options on
|
|
1049
|
+
* top. A no-op if the options are already defaulted (`_defaulted: true`).
|
|
1050
|
+
* @param options - The query options passed by the caller.
|
|
1051
|
+
* @returns The defaulted options, with `queryHash` and dependent defaults (e.g.
|
|
1052
|
+
* `refetchOnReconnect`) filled in.
|
|
982
1053
|
*/
|
|
983
1054
|
defaultQueryOptions<
|
|
984
1055
|
TQueryFnData = unknown,
|
|
@@ -1063,9 +1134,11 @@ export class QueryClient {
|
|
|
1063
1134
|
|
|
1064
1135
|
/**
|
|
1065
1136
|
* The mutation counterpart of {@link QueryClient#defaultQueryOptions}. Called by framework
|
|
1066
|
-
* adapters (e.g. inside `useMutation`) to merge `
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
1137
|
+
* adapters (e.g. inside `useMutation`) to merge the client's `defaultOptions.mutations`, then
|
|
1138
|
+
* `queryClient.setMutationDefaults` for the given `mutationKey`, then the caller's options on
|
|
1139
|
+
* top. A no-op if the options are already defaulted (`_defaulted: true`).
|
|
1140
|
+
* @param options - The mutation options passed by the caller.
|
|
1141
|
+
* @returns The defaulted options.
|
|
1069
1142
|
*/
|
|
1070
1143
|
defaultMutationOptions<T extends MutationOptions<any, any, any, any>>(
|
|
1071
1144
|
options?: T,
|
|
@@ -1084,7 +1157,6 @@ export class QueryClient {
|
|
|
1084
1157
|
|
|
1085
1158
|
/**
|
|
1086
1159
|
* Clears both the query cache and the mutation cache this client is connected to.
|
|
1087
|
-
*
|
|
1088
1160
|
* @example
|
|
1089
1161
|
* ```ts
|
|
1090
1162
|
* import { QueryClient } from '@tanstack/query-core'
|
package/src/queryObserver.ts
CHANGED
|
@@ -41,7 +41,6 @@ interface ObserverFetchOptions extends FetchOptions {
|
|
|
41
41
|
* the primitive that framework adapters (e.g. `useQuery`) build their hooks
|
|
42
42
|
* on top of, but it can also be used directly to observe and switch between
|
|
43
43
|
* queries outside of any framework.
|
|
44
|
-
*
|
|
45
44
|
* @example
|
|
46
45
|
* ```ts
|
|
47
46
|
* const observer = new QueryObserver(queryClient, {
|
|
@@ -103,11 +102,15 @@ export class QueryObserver<
|
|
|
103
102
|
this.setOptions(options)
|
|
104
103
|
}
|
|
105
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Binds the methods of the result (`refetch`) to the observer, so they keep working when destructured
|
|
107
|
+
* from it. Subclasses override it to bind their own result methods as well.
|
|
108
|
+
*/
|
|
106
109
|
protected bindMethods(): void {
|
|
107
110
|
this.refetch = this.refetch.bind(this)
|
|
108
111
|
}
|
|
109
112
|
|
|
110
|
-
protected onSubscribe(): void {
|
|
113
|
+
protected override onSubscribe(): void {
|
|
111
114
|
if (this.listeners.size === 1) {
|
|
112
115
|
this.#currentQuery.addObserver(this)
|
|
113
116
|
|
|
@@ -121,7 +124,7 @@ export class QueryObserver<
|
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
126
|
|
|
124
|
-
protected onUnsubscribe(): void {
|
|
127
|
+
protected override onUnsubscribe(): void {
|
|
125
128
|
if (!this.hasListeners()) {
|
|
126
129
|
this.destroy()
|
|
127
130
|
}
|
|
@@ -131,6 +134,7 @@ export class QueryObserver<
|
|
|
131
134
|
* Returns whether the observed query is currently stale and configured
|
|
132
135
|
* (via the `refetchOnReconnect` option) to refetch when the network
|
|
133
136
|
* reconnects.
|
|
137
|
+
* @returns `true` if the observer should refetch the query on reconnect.
|
|
134
138
|
*/
|
|
135
139
|
shouldFetchOnReconnect(): boolean {
|
|
136
140
|
return shouldFetchOn(
|
|
@@ -144,6 +148,7 @@ export class QueryObserver<
|
|
|
144
148
|
* Returns whether the observed query is currently stale and configured
|
|
145
149
|
* (via the `refetchOnWindowFocus` option) to refetch when the window
|
|
146
150
|
* regains focus.
|
|
151
|
+
* @returns `true` if the observer should refetch the query on window focus.
|
|
147
152
|
*/
|
|
148
153
|
shouldFetchOnWindowFocus(): boolean {
|
|
149
154
|
return shouldFetchOn(
|
|
@@ -171,7 +176,9 @@ export class QueryObserver<
|
|
|
171
176
|
* trigger a fetch if the new options require one and the observer has
|
|
172
177
|
* subscribers, recompute the current result, and reschedule the stale and
|
|
173
178
|
* refetch-interval timers as needed.
|
|
174
|
-
*
|
|
179
|
+
* @param options - The new observer options. They are defaulted with {@link
|
|
180
|
+
* QueryClient#defaultQueryOptions} before being applied.
|
|
181
|
+
* @throws {Error} If `enabled` is neither a boolean nor a function.
|
|
175
182
|
* @example
|
|
176
183
|
* ```ts
|
|
177
184
|
* observer.setOptions({ queryKey: ['posts', 1], queryFn: () => fetchPost(1) })
|
|
@@ -268,6 +275,8 @@ export class QueryObserver<
|
|
|
268
275
|
* right now, building the underlying `Query` if it doesn't exist yet, without waiting for a
|
|
269
276
|
* subscription callback. Called by framework adapters on every render (e.g. `useQuery`) so the
|
|
270
277
|
* returned value is available synchronously, ahead of `setOptions` triggering an actual fetch.
|
|
278
|
+
* @param options - The defaulted observer options to compute the result for.
|
|
279
|
+
* @returns The result for the given options.
|
|
271
280
|
*/
|
|
272
281
|
getOptimisticResult(
|
|
273
282
|
options: DefaultedQueryObserverOptions<
|
|
@@ -311,7 +320,7 @@ export class QueryObserver<
|
|
|
311
320
|
* observed query. This is a point-in-time read; to be notified of updates
|
|
312
321
|
* as they happen, subscribe to the observer instead (its inherited
|
|
313
322
|
* `subscribe` method).
|
|
314
|
-
*
|
|
323
|
+
* @returns The observer's latest result.
|
|
315
324
|
* @example
|
|
316
325
|
* ```ts
|
|
317
326
|
* const result = observer.getCurrentResult()
|
|
@@ -327,6 +336,9 @@ export class QueryObserver<
|
|
|
327
336
|
* {@link QueryObserver#trackProp} (and an optional `onPropTracked` callback). Used by framework
|
|
328
337
|
* adapters when `notifyOnChangeProps` is not set, to implement its default "only re-render on
|
|
329
338
|
* properties you actually read" behavior.
|
|
339
|
+
* @param result - The result to wrap.
|
|
340
|
+
* @param onPropTracked - Called with the name of each property that is read.
|
|
341
|
+
* @returns A proxy of `result` that tracks property reads.
|
|
330
342
|
*/
|
|
331
343
|
trackResult(
|
|
332
344
|
result: QueryObserverResult<TData, TError>,
|
|
@@ -346,6 +358,7 @@ export class QueryObserver<
|
|
|
346
358
|
* notifies this observer if a tracked property actually changed. Normally called indirectly via
|
|
347
359
|
* {@link QueryObserver#trackResult}'s proxy; exposed directly for adapters that track property
|
|
348
360
|
* access themselves (e.g. through their own reactivity system) instead of via the proxy.
|
|
361
|
+
* @param key - The name of the property that was read.
|
|
349
362
|
*/
|
|
350
363
|
trackProp(key: keyof QueryObserverResult) {
|
|
351
364
|
this.#trackedProps.add(key)
|
|
@@ -353,6 +366,7 @@ export class QueryObserver<
|
|
|
353
366
|
|
|
354
367
|
/**
|
|
355
368
|
* Returns the `Query` instance this observer is currently observing.
|
|
369
|
+
* @returns The observed query.
|
|
356
370
|
*/
|
|
357
371
|
getCurrentQuery(): Query<TQueryFnData, TError, TQueryData, TQueryKey> {
|
|
358
372
|
return this.#currentQuery
|
|
@@ -361,7 +375,9 @@ export class QueryObserver<
|
|
|
361
375
|
/**
|
|
362
376
|
* Refetches the observed query and returns a promise that resolves with
|
|
363
377
|
* the resulting `QueryObserverResult`.
|
|
364
|
-
*
|
|
378
|
+
* @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling
|
|
379
|
+
* it, and `throwOnError` to `true` to reject when the refetch fails.
|
|
380
|
+
* @returns A promise that resolves with the result after the refetch.
|
|
365
381
|
* @example
|
|
366
382
|
* ```ts
|
|
367
383
|
* const result = await observer.refetch({ cancelRefetch: false })
|
|
@@ -382,7 +398,8 @@ export class QueryObserver<
|
|
|
382
398
|
* resolves with the `QueryObserverResult` for that fetch. This is useful
|
|
383
399
|
* for prefetching data that another observer (e.g. a query about to be
|
|
384
400
|
* navigated to) will need, ahead of time.
|
|
385
|
-
*
|
|
401
|
+
* @param options - The observer options of the query to fetch.
|
|
402
|
+
* @returns A promise that resolves with the result for the fetched query.
|
|
386
403
|
* @example
|
|
387
404
|
* ```ts
|
|
388
405
|
* const result = await observer.fetchOptimistic({
|
|
@@ -409,7 +426,8 @@ export class QueryObserver<
|
|
|
409
426
|
|
|
410
427
|
let unsubscribe = () => {}
|
|
411
428
|
let resolveEarly:
|
|
412
|
-
((result: QueryObserverResult<TData, TError>) => void)
|
|
429
|
+
| ((result: QueryObserverResult<TData, TError>) => void)
|
|
430
|
+
| undefined
|
|
413
431
|
|
|
414
432
|
const cachePromise = new Promise<QueryObserverResult<TData, TError>>(
|
|
415
433
|
(resolve) => {
|
|
@@ -444,6 +462,12 @@ export class QueryObserver<
|
|
|
444
462
|
])
|
|
445
463
|
}
|
|
446
464
|
|
|
465
|
+
/**
|
|
466
|
+
* Fetches the observed query and updates the result once the fetch settles. Used by `refetch` and,
|
|
467
|
+
* in `InfiniteQueryObserver`, to fetch more pages.
|
|
468
|
+
* @param fetchOptions - Options for this fetch. `cancelRefetch` defaults to `true`.
|
|
469
|
+
* @returns A promise that resolves with the updated result.
|
|
470
|
+
*/
|
|
447
471
|
protected fetch(
|
|
448
472
|
fetchOptions: ObserverFetchOptions,
|
|
449
473
|
): Promise<QueryObserverResult<TData, TError>> {
|
|
@@ -555,6 +579,13 @@ export class QueryObserver<
|
|
|
555
579
|
}
|
|
556
580
|
}
|
|
557
581
|
|
|
582
|
+
/**
|
|
583
|
+
* Computes the result for a query and options from the query's state, applying `select`,
|
|
584
|
+
* `placeholderData`, and the derived flags. Subclasses override it to add their own fields.
|
|
585
|
+
* @param query - The query to compute the result for.
|
|
586
|
+
* @param options - The observer options to compute the result with.
|
|
587
|
+
* @returns The computed result.
|
|
588
|
+
*/
|
|
558
589
|
protected createResult(
|
|
559
590
|
query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,
|
|
560
591
|
options: QueryObserverOptions<
|
|
@@ -568,7 +599,8 @@ export class QueryObserver<
|
|
|
568
599
|
const prevQuery = this.#currentQuery
|
|
569
600
|
const prevOptions = this.options
|
|
570
601
|
const prevResult = this.#currentResult as
|
|
571
|
-
QueryObserverResult<TData, TError>
|
|
602
|
+
| QueryObserverResult<TData, TError>
|
|
603
|
+
| undefined
|
|
572
604
|
const prevResultState = this.#currentResultState
|
|
573
605
|
const prevResultOptions = this.#currentResultOptions
|
|
574
606
|
const queryChange = query !== prevQuery
|
|
@@ -732,7 +764,8 @@ export class QueryObserver<
|
|
|
732
764
|
*/
|
|
733
765
|
updateResult(): void {
|
|
734
766
|
const prevResult = this.#currentResult as
|
|
735
|
-
QueryObserverResult<TData, TError>
|
|
767
|
+
| QueryObserverResult<TData, TError>
|
|
768
|
+
| undefined
|
|
736
769
|
|
|
737
770
|
const nextResult = this.createResult(this.#currentQuery, this.options)
|
|
738
771
|
|
|
@@ -810,7 +843,8 @@ export class QueryObserver<
|
|
|
810
843
|
}
|
|
811
844
|
|
|
812
845
|
const prevQuery = this.#currentQuery as
|
|
813
|
-
Query<TQueryFnData, TError, TQueryData, TQueryKey>
|
|
846
|
+
| Query<TQueryFnData, TError, TQueryData, TQueryKey>
|
|
847
|
+
| undefined
|
|
814
848
|
this.#currentQuery = query
|
|
815
849
|
this.#currentQueryInitialState = query.state
|
|
816
850
|
|
|
@@ -820,7 +854,11 @@ export class QueryObserver<
|
|
|
820
854
|
}
|
|
821
855
|
}
|
|
822
856
|
|
|
823
|
-
/**
|
|
857
|
+
/**
|
|
858
|
+
* Updates the observer's result when the observed query changes, and reschedules its timers if it
|
|
859
|
+
* has listeners.
|
|
860
|
+
* @internal
|
|
861
|
+
*/
|
|
824
862
|
onQueryUpdate(): void {
|
|
825
863
|
this.updateResult()
|
|
826
864
|
|
|
@@ -830,6 +868,13 @@ export class QueryObserver<
|
|
|
830
868
|
}
|
|
831
869
|
}
|
|
832
870
|
|
|
871
|
+
/**
|
|
872
|
+
* Checks whether a query has no data yet and should do its initial load when an observer mounts.
|
|
873
|
+
* @param query - The query to check.
|
|
874
|
+
* @param options - The observer options.
|
|
875
|
+
* @returns `true` if the query is enabled, has no data, and isn't in an error state with
|
|
876
|
+
* `retryOnMount: false`.
|
|
877
|
+
*/
|
|
833
878
|
function shouldLoadOnMount(
|
|
834
879
|
query: Query<any, any, any, any>,
|
|
835
880
|
options: QueryObserverOptions<any, any, any, any>,
|
|
@@ -844,6 +889,13 @@ function shouldLoadOnMount(
|
|
|
844
889
|
)
|
|
845
890
|
}
|
|
846
891
|
|
|
892
|
+
/**
|
|
893
|
+
* Checks whether a query should fetch when an observer mounts: either for its initial load, or
|
|
894
|
+
* because it has data and `refetchOnMount` asks for a refetch.
|
|
895
|
+
* @param query - The query to check.
|
|
896
|
+
* @param options - The observer options.
|
|
897
|
+
* @returns `true` if the query should fetch on mount.
|
|
898
|
+
*/
|
|
847
899
|
function shouldFetchOnMount(
|
|
848
900
|
query: Query<any, any, any, any>,
|
|
849
901
|
options: QueryObserverOptions<any, any, any, any, any>,
|
|
@@ -855,6 +907,15 @@ function shouldFetchOnMount(
|
|
|
855
907
|
)
|
|
856
908
|
}
|
|
857
909
|
|
|
910
|
+
/**
|
|
911
|
+
* Checks whether a query should fetch for a `refetchOnMount`, `refetchOnWindowFocus`, or
|
|
912
|
+
* `refetchOnReconnect` option.
|
|
913
|
+
* @param query - The query to check.
|
|
914
|
+
* @param options - The observer options.
|
|
915
|
+
* @param field - The value of the option to check.
|
|
916
|
+
* @returns `true` if the query is enabled, not static, and the option is `'always'`, or is not
|
|
917
|
+
* `false` and the query is stale.
|
|
918
|
+
*/
|
|
858
919
|
function shouldFetchOn(
|
|
859
920
|
query: Query<any, any, any, any>,
|
|
860
921
|
options: QueryObserverOptions<any, any, any, any, any>,
|
|
@@ -873,6 +934,15 @@ function shouldFetchOn(
|
|
|
873
934
|
return false
|
|
874
935
|
}
|
|
875
936
|
|
|
937
|
+
/**
|
|
938
|
+
* Checks whether a query should fetch after the observer's options change.
|
|
939
|
+
* @param query - The query observed with the new options.
|
|
940
|
+
* @param prevQuery - The query observed with the previous options.
|
|
941
|
+
* @param options - The new observer options.
|
|
942
|
+
* @param prevOptions - The previous observer options.
|
|
943
|
+
* @returns `true` if the query changed or was disabled before, it isn't a suspense query in an
|
|
944
|
+
* error state, and it is stale.
|
|
945
|
+
*/
|
|
876
946
|
function shouldFetchOptionally(
|
|
877
947
|
query: Query<any, any, any, any>,
|
|
878
948
|
prevQuery: Query<any, any, any, any>,
|
|
@@ -887,6 +957,12 @@ function shouldFetchOptionally(
|
|
|
887
957
|
)
|
|
888
958
|
}
|
|
889
959
|
|
|
960
|
+
/**
|
|
961
|
+
* Checks whether a query is stale for the given observer options.
|
|
962
|
+
* @param query - The query to check.
|
|
963
|
+
* @param options - The observer options, whose `enabled` and `staleTime` are used.
|
|
964
|
+
* @returns `true` if the query is enabled and its data is stale for `staleTime`.
|
|
965
|
+
*/
|
|
890
966
|
function isStale(
|
|
891
967
|
query: Query<any, any, any, any>,
|
|
892
968
|
options: QueryObserverOptions<any, any, any, any, any>,
|