@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
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
import { A as InfiniteData, V as InfiniteQueryPageParamsOptions, er as QueryBehavior } from "./hydration-
|
|
1
|
+
import { A as InfiniteData, V as InfiniteQueryPageParamsOptions, er as QueryBehavior } from "./hydration-UAqdtMIf.js";
|
|
2
2
|
//#region src/infiniteQueryBehavior.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates the behavior that fetches the pages of an infinite query: the next or previous page for
|
|
5
|
+
* `fetchNextPage`/`fetchPreviousPage`, or all pages again from the start on a refetch.
|
|
6
|
+
* @param pages - The number of pages to fetch from the start when all pages are fetched again,
|
|
7
|
+
* e.g. from the `pages` option of `queryClient.infiniteQuery`. Defaults to the number of cached
|
|
8
|
+
* pages.
|
|
9
|
+
* @returns The query behavior to set on an infinite query.
|
|
10
|
+
*/
|
|
3
11
|
export declare function infiniteQueryBehavior<TQueryFnData, TError, TData, TPageParam>(pages?: number): QueryBehavior<TQueryFnData, TError, InfiniteData<TData, TPageParam>>;
|
|
4
12
|
/**
|
|
5
13
|
* Checks if there is a next page.
|
|
14
|
+
* @param options - The infinite query options with `getNextPageParam`.
|
|
15
|
+
* @param data - The current pages and page params.
|
|
16
|
+
* @returns `true` if `getNextPageParam` returns a value other than `null` or `undefined`.
|
|
6
17
|
*/
|
|
7
18
|
export declare function hasNextPage(options: InfiniteQueryPageParamsOptions<any, any>, data?: InfiniteData<unknown>): boolean;
|
|
8
19
|
/**
|
|
9
20
|
* Checks if there is a previous page.
|
|
21
|
+
* @param options - The infinite query options with `getPreviousPageParam`.
|
|
22
|
+
* @param data - The current pages and page params.
|
|
23
|
+
* @returns `true` if `getPreviousPageParam` is set and returns a value other than `null` or
|
|
24
|
+
* `undefined`.
|
|
10
25
|
*/
|
|
11
26
|
export declare function hasPreviousPage(options: InfiniteQueryPageParamsOptions<any, any>, data?: InfiniteData<unknown>): boolean;
|
|
12
27
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infiniteQueryBehavior.d.ts","names":[],"sources":["../../src/infiniteQueryBehavior.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"infiniteQueryBehavior.d.ts","names":[],"sources":["../../src/infiniteQueryBehavior.ts"],"mappings":";;;;;;;;;;wBAuBgB,sBAAsB,cAAc,QAAQ,OAAO,YACjE,iBACC,cAAc,cAAc,QAAQ,aAAa,OAAO;;;;;;;wBA8J3C,YACd,SAAS,0CACT,OAAO;;;;;;;;wBAaO,gBACd,SAAS,0CACT,OAAO"}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { addConsumeAwareSignal, addToEnd, addToStart, ensureQueryFn } from "./utils.js";
|
|
2
2
|
//#region src/infiniteQueryBehavior.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates the behavior that fetches the pages of an infinite query: the next or previous page for
|
|
5
|
+
* `fetchNextPage`/`fetchPreviousPage`, or all pages again from the start on a refetch.
|
|
6
|
+
* @param pages - The number of pages to fetch from the start when all pages are fetched again,
|
|
7
|
+
* e.g. from the `pages` option of `queryClient.infiniteQuery`. Defaults to the number of cached
|
|
8
|
+
* pages.
|
|
9
|
+
* @returns The query behavior to set on an infinite query.
|
|
10
|
+
*/
|
|
3
11
|
function infiniteQueryBehavior(pages) {
|
|
4
12
|
return { onFetch: (context, query) => {
|
|
5
13
|
const options = context.options;
|
|
@@ -70,15 +78,32 @@ function infiniteQueryBehavior(pages) {
|
|
|
70
78
|
else context.fetchFn = fetchFn;
|
|
71
79
|
} };
|
|
72
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Computes the page param of the page after the last one, with the `getNextPageParam` option.
|
|
83
|
+
* @param options - The infinite query options.
|
|
84
|
+
* @param data - The current pages and page params.
|
|
85
|
+
* @returns The next page param, or `undefined` if there are no pages yet.
|
|
86
|
+
*/
|
|
73
87
|
function getNextPageParam(options, { pages, pageParams }) {
|
|
74
88
|
const lastIndex = pages.length - 1;
|
|
75
89
|
return pages.length > 0 ? options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams) : void 0;
|
|
76
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Computes the page param of the page before the first one, with the `getPreviousPageParam`
|
|
93
|
+
* option.
|
|
94
|
+
* @param options - The infinite query options.
|
|
95
|
+
* @param data - The current pages and page params.
|
|
96
|
+
* @returns The previous page param, or `undefined` if there are no pages yet or no
|
|
97
|
+
* `getPreviousPageParam` option.
|
|
98
|
+
*/
|
|
77
99
|
function getPreviousPageParam(options, { pages, pageParams }) {
|
|
78
100
|
return pages.length > 0 ? options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams) : void 0;
|
|
79
101
|
}
|
|
80
102
|
/**
|
|
81
103
|
* Checks if there is a next page.
|
|
104
|
+
* @param options - The infinite query options with `getNextPageParam`.
|
|
105
|
+
* @param data - The current pages and page params.
|
|
106
|
+
* @returns `true` if `getNextPageParam` returns a value other than `null` or `undefined`.
|
|
82
107
|
*/
|
|
83
108
|
function hasNextPage(options, data) {
|
|
84
109
|
if (!data) return false;
|
|
@@ -86,6 +111,10 @@ function hasNextPage(options, data) {
|
|
|
86
111
|
}
|
|
87
112
|
/**
|
|
88
113
|
* Checks if there is a previous page.
|
|
114
|
+
* @param options - The infinite query options with `getPreviousPageParam`.
|
|
115
|
+
* @param data - The current pages and page params.
|
|
116
|
+
* @returns `true` if `getPreviousPageParam` is set and returns a value other than `null` or
|
|
117
|
+
* `undefined`.
|
|
89
118
|
*/
|
|
90
119
|
function hasPreviousPage(options, data) {
|
|
91
120
|
if (!data || !options.getPreviousPageParam) return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infiniteQueryBehavior.js","names":[],"sources":["../../src/infiniteQueryBehavior.ts"],"sourcesContent":["import {\n addConsumeAwareSignal,\n addToEnd,\n addToStart,\n ensureQueryFn,\n} from './utils'\nimport type { QueryBehavior } from './query'\nimport type {\n InfiniteData,\n InfiniteQueryPageParamsOptions,\n OmitKeyof,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\nexport function infiniteQueryBehavior<TQueryFnData, TError, TData, TPageParam>(\n pages?: number,\n): QueryBehavior<TQueryFnData, TError, InfiniteData<TData, TPageParam>> {\n return {\n onFetch: (context, query) => {\n const options = context.options as InfiniteQueryPageParamsOptions<TData>\n const direction = context.fetchOptions?.meta?.fetchMore?.direction\n const oldPages = context.state.data?.pages || []\n const oldPageParams = context.state.data?.pageParams || []\n let result: InfiniteData<unknown> = { pages: [], pageParams: [] }\n let currentPage = 0\n\n const fetchFn = async () => {\n let cancelled = false\n const addSignalProperty = (object: unknown) => {\n addConsumeAwareSignal(\n object,\n () => context.signal,\n () => (cancelled = true),\n )\n }\n\n const queryFn = ensureQueryFn(context.options, context.fetchOptions)\n\n // Create function to fetch a page\n const fetchPage = async (\n data: InfiniteData<unknown>,\n param: unknown,\n previous?: boolean,\n ): Promise<InfiniteData<unknown>> => {\n if (cancelled) {\n return Promise.reject(context.signal.reason)\n }\n\n if (param == null && data.pages.length) {\n return Promise.resolve(data)\n }\n\n const createQueryFnContext = () => {\n const queryFnContext: OmitKeyof<\n QueryFunctionContext<QueryKey, unknown>,\n 'signal'\n > = {\n client: context.client,\n queryKey: context.queryKey,\n pageParam: param,\n direction: previous ? 'backward' : 'forward',\n meta: context.options.meta,\n }\n addSignalProperty(queryFnContext)\n return queryFnContext as QueryFunctionContext<QueryKey, unknown>\n }\n\n const queryFnContext = createQueryFnContext()\n\n const page = await queryFn(queryFnContext)\n\n const { maxPages } = context.options\n const addTo = previous ? addToStart : addToEnd\n\n return {\n pages: addTo(data.pages, page, maxPages),\n pageParams: addTo(data.pageParams, param, maxPages),\n }\n }\n\n // fetch next / previous page?\n if (direction && oldPages.length) {\n const previous = direction === 'backward'\n const pageParamFn = previous ? getPreviousPageParam : getNextPageParam\n const oldData = {\n pages: oldPages,\n pageParams: oldPageParams,\n }\n const param = pageParamFn(options, oldData)\n\n result = await fetchPage(oldData, param, previous)\n } else {\n const remainingPages = pages ?? oldPages.length\n\n // Fetch all pages\n do {\n const param =\n currentPage === 0\n ? (oldPageParams[0] ?? options.initialPageParam)\n : getNextPageParam(options, result)\n if (currentPage > 0 && param == null) {\n break\n }\n result = await fetchPage(result, param)\n currentPage++\n } while (currentPage < remainingPages)\n }\n\n return result\n }\n if (context.options.persister) {\n context.fetchFn = () => {\n return context.options.persister?.(\n fetchFn as any,\n {\n client: context.client,\n queryKey: context.queryKey,\n meta: context.options.meta,\n signal: context.signal,\n },\n query,\n )\n }\n } else {\n context.fetchFn = fetchFn\n }\n },\n }\n}\n\nfunction getNextPageParam(\n options: InfiniteQueryPageParamsOptions<any>,\n { pages, pageParams }: InfiniteData<unknown>,\n): unknown | undefined {\n const lastIndex = pages.length - 1\n return pages.length > 0\n ? options.getNextPageParam(\n pages[lastIndex],\n pages,\n pageParams[lastIndex],\n pageParams,\n )\n : undefined\n}\n\nfunction getPreviousPageParam(\n options: InfiniteQueryPageParamsOptions<any>,\n { pages, pageParams }: InfiniteData<unknown>,\n): unknown | undefined {\n return pages.length > 0\n ? options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams)\n : undefined\n}\n\n/**\n * Checks if there is a next page.\n */\nexport function hasNextPage(\n options: InfiniteQueryPageParamsOptions<any, any>,\n data?: InfiniteData<unknown>,\n): boolean {\n if (!data) return false\n return getNextPageParam(options, data) != null\n}\n\n/**\n * Checks if there is a previous page.\n */\nexport function hasPreviousPage(\n options: InfiniteQueryPageParamsOptions<any, any>,\n data?: InfiniteData<unknown>,\n): boolean {\n if (!data || !options.getPreviousPageParam) return false\n return getPreviousPageParam(options, data) != null\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"infiniteQueryBehavior.js","names":[],"sources":["../../src/infiniteQueryBehavior.ts"],"sourcesContent":["import {\n addConsumeAwareSignal,\n addToEnd,\n addToStart,\n ensureQueryFn,\n} from './utils'\nimport type { QueryBehavior } from './query'\nimport type {\n InfiniteData,\n InfiniteQueryPageParamsOptions,\n OmitKeyof,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\n/**\n * Creates the behavior that fetches the pages of an infinite query: the next or previous page for\n * `fetchNextPage`/`fetchPreviousPage`, or all pages again from the start on a refetch.\n * @param pages - The number of pages to fetch from the start when all pages are fetched again,\n * e.g. from the `pages` option of `queryClient.infiniteQuery`. Defaults to the number of cached\n * pages.\n * @returns The query behavior to set on an infinite query.\n */\nexport function infiniteQueryBehavior<TQueryFnData, TError, TData, TPageParam>(\n pages?: number,\n): QueryBehavior<TQueryFnData, TError, InfiniteData<TData, TPageParam>> {\n return {\n onFetch: (context, query) => {\n const options = context.options as InfiniteQueryPageParamsOptions<TData>\n const direction = context.fetchOptions?.meta?.fetchMore?.direction\n const oldPages = context.state.data?.pages || []\n const oldPageParams = context.state.data?.pageParams || []\n let result: InfiniteData<unknown> = { pages: [], pageParams: [] }\n let currentPage = 0\n\n const fetchFn = async () => {\n let cancelled = false\n const addSignalProperty = (object: unknown) => {\n addConsumeAwareSignal(\n object,\n () => context.signal,\n () => (cancelled = true),\n )\n }\n\n const queryFn = ensureQueryFn(context.options, context.fetchOptions)\n\n // Create function to fetch a page\n const fetchPage = async (\n data: InfiniteData<unknown>,\n param: unknown,\n previous?: boolean,\n ): Promise<InfiniteData<unknown>> => {\n if (cancelled) {\n return Promise.reject(context.signal.reason)\n }\n\n if (param == null && data.pages.length) {\n return Promise.resolve(data)\n }\n\n const createQueryFnContext = () => {\n const queryFnContext: OmitKeyof<\n QueryFunctionContext<QueryKey, unknown>,\n 'signal'\n > = {\n client: context.client,\n queryKey: context.queryKey,\n pageParam: param,\n direction: previous ? 'backward' : 'forward',\n meta: context.options.meta,\n }\n addSignalProperty(queryFnContext)\n return queryFnContext as QueryFunctionContext<QueryKey, unknown>\n }\n\n const queryFnContext = createQueryFnContext()\n\n const page = await queryFn(queryFnContext)\n\n const { maxPages } = context.options\n const addTo = previous ? addToStart : addToEnd\n\n return {\n pages: addTo(data.pages, page, maxPages),\n pageParams: addTo(data.pageParams, param, maxPages),\n }\n }\n\n // fetch next / previous page?\n if (direction && oldPages.length) {\n const previous = direction === 'backward'\n const pageParamFn = previous ? getPreviousPageParam : getNextPageParam\n const oldData = {\n pages: oldPages,\n pageParams: oldPageParams,\n }\n const param = pageParamFn(options, oldData)\n\n result = await fetchPage(oldData, param, previous)\n } else {\n const remainingPages = pages ?? oldPages.length\n\n // Fetch all pages\n do {\n const param =\n currentPage === 0\n ? (oldPageParams[0] ?? options.initialPageParam)\n : getNextPageParam(options, result)\n if (currentPage > 0 && param == null) {\n break\n }\n result = await fetchPage(result, param)\n currentPage++\n } while (currentPage < remainingPages)\n }\n\n return result\n }\n if (context.options.persister) {\n context.fetchFn = () => {\n return context.options.persister?.(\n fetchFn as any,\n {\n client: context.client,\n queryKey: context.queryKey,\n meta: context.options.meta,\n signal: context.signal,\n },\n query,\n )\n }\n } else {\n context.fetchFn = fetchFn\n }\n },\n }\n}\n\n/**\n * Computes the page param of the page after the last one, with the `getNextPageParam` option.\n * @param options - The infinite query options.\n * @param data - The current pages and page params.\n * @returns The next page param, or `undefined` if there are no pages yet.\n */\nfunction getNextPageParam(\n options: InfiniteQueryPageParamsOptions<any>,\n { pages, pageParams }: InfiniteData<unknown>,\n): unknown | undefined {\n const lastIndex = pages.length - 1\n return pages.length > 0\n ? options.getNextPageParam(\n pages[lastIndex],\n pages,\n pageParams[lastIndex],\n pageParams,\n )\n : undefined\n}\n\n/**\n * Computes the page param of the page before the first one, with the `getPreviousPageParam`\n * option.\n * @param options - The infinite query options.\n * @param data - The current pages and page params.\n * @returns The previous page param, or `undefined` if there are no pages yet or no\n * `getPreviousPageParam` option.\n */\nfunction getPreviousPageParam(\n options: InfiniteQueryPageParamsOptions<any>,\n { pages, pageParams }: InfiniteData<unknown>,\n): unknown | undefined {\n return pages.length > 0\n ? options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams)\n : undefined\n}\n\n/**\n * Checks if there is a next page.\n * @param options - The infinite query options with `getNextPageParam`.\n * @param data - The current pages and page params.\n * @returns `true` if `getNextPageParam` returns a value other than `null` or `undefined`.\n */\nexport function hasNextPage(\n options: InfiniteQueryPageParamsOptions<any, any>,\n data?: InfiniteData<unknown>,\n): boolean {\n if (!data) return false\n return getNextPageParam(options, data) != null\n}\n\n/**\n * Checks if there is a previous page.\n * @param options - The infinite query options with `getPreviousPageParam`.\n * @param data - The current pages and page params.\n * @returns `true` if `getPreviousPageParam` is set and returns a value other than `null` or\n * `undefined`.\n */\nexport function hasPreviousPage(\n options: InfiniteQueryPageParamsOptions<any, any>,\n data?: InfiniteData<unknown>,\n): boolean {\n if (!data || !options.getPreviousPageParam) return false\n return getPreviousPageParam(options, data) != null\n}\n"],"mappings":";;;;;;;;;;AAuBA,SAAgB,sBACd,OACsE;CACtE,OAAO,EACL,UAAU,SAAS,UAAU;EAC3B,MAAM,UAAU,QAAQ;EACxB,MAAM,YAAY,QAAQ,cAAc,MAAM,WAAW;EACzD,MAAM,WAAW,QAAQ,MAAM,MAAM,SAAS,CAAC;EAC/C,MAAM,gBAAgB,QAAQ,MAAM,MAAM,cAAc,CAAC;EACzD,IAAI,SAAgC;GAAE,OAAO,CAAC;GAAG,YAAY,CAAC;EAAE;EAChE,IAAI,cAAc;EAElB,MAAM,UAAU,YAAY;GAC1B,IAAI,YAAY;GAChB,MAAM,qBAAqB,WAAoB;IAC7C,sBACE,cACM,QAAQ,cACP,YAAY,IACrB;GACF;GAEA,MAAM,UAAU,cAAc,QAAQ,SAAS,QAAQ,YAAY;GAGnE,MAAM,YAAY,OAChB,MACA,OACA,aACmC;IACnC,IAAI,WACF,OAAO,QAAQ,OAAO,QAAQ,OAAO,MAAM;IAG7C,IAAI,SAAS,QAAQ,KAAK,MAAM,QAC9B,OAAO,QAAQ,QAAQ,IAAI;IAG7B,MAAM,6BAA6B;KACjC,MAAM,iBAGF;MACF,QAAQ,QAAQ;MAChB,UAAU,QAAQ;MAClB,WAAW;MACX,WAAW,WAAW,aAAa;MACnC,MAAM,QAAQ,QAAQ;KACxB;KACA,kBAAkB,cAAc;KAChC,OAAO;IACT;IAEA,MAAM,iBAAiB,qBAAqB;IAE5C,MAAM,OAAO,MAAM,QAAQ,cAAc;IAEzC,MAAM,EAAE,aAAa,QAAQ;IAC7B,MAAM,QAAQ,WAAW,aAAa;IAEtC,OAAO;KACL,OAAO,MAAM,KAAK,OAAO,MAAM,QAAQ;KACvC,YAAY,MAAM,KAAK,YAAY,OAAO,QAAQ;IACpD;GACF;GAGA,IAAI,aAAa,SAAS,QAAQ;IAChC,MAAM,WAAW,cAAc;IAC/B,MAAM,cAAc,WAAW,uBAAuB;IACtD,MAAM,UAAU;KACd,OAAO;KACP,YAAY;IACd;IAGA,SAAS,MAAM,UAAU,SAFX,YAAY,SAAS,OAEG,GAAG,QAAQ;GACnD,OAAO;IACL,MAAM,iBAAiB,SAAS,SAAS;IAGzC,GAAG;KACD,MAAM,QACJ,gBAAgB,IACX,cAAc,MAAM,QAAQ,mBAC7B,iBAAiB,SAAS,MAAM;KACtC,IAAI,cAAc,KAAK,SAAS,MAC9B;KAEF,SAAS,MAAM,UAAU,QAAQ,KAAK;KACtC;IACF,SAAS,cAAc;GACzB;GAEA,OAAO;EACT;EACA,IAAI,QAAQ,QAAQ,WAClB,QAAQ,gBAAgB;GACtB,OAAO,QAAQ,QAAQ,YACrB,SACA;IACE,QAAQ,QAAQ;IAChB,UAAU,QAAQ;IAClB,MAAM,QAAQ,QAAQ;IACtB,QAAQ,QAAQ;GAClB,GACA,KACF;EACF;OAEA,QAAQ,UAAU;CAEtB,EACF;AACF;;;;;;;AAQA,SAAS,iBACP,SACA,EAAE,OAAO,cACY;CACrB,MAAM,YAAY,MAAM,SAAS;CACjC,OAAO,MAAM,SAAS,IAClB,QAAQ,iBACN,MAAM,YACN,OACA,WAAW,YACX,UACF,IACA,KAAA;AACN;;;;;;;;;AAUA,SAAS,qBACP,SACA,EAAE,OAAO,cACY;CACrB,OAAO,MAAM,SAAS,IAClB,QAAQ,uBAAuB,MAAM,IAAI,OAAO,WAAW,IAAI,UAAU,IACzE,KAAA;AACN;;;;;;;AAQA,SAAgB,YACd,SACA,MACS;CACT,IAAI,CAAC,MAAM,OAAO;CAClB,OAAO,iBAAiB,SAAS,IAAI,KAAK;AAC5C;;;;;;;;AASA,SAAgB,gBACd,SACA,MACS;CACT,IAAI,CAAC,QAAQ,CAAC,QAAQ,sBAAsB,OAAO;CACnD,OAAO,qBAAqB,SAAS,IAAI,KAAK;AAChD"}
|
|
@@ -8,7 +8,6 @@ const require_queryObserver = require("./queryObserver.cjs");
|
|
|
8
8
|
* infinite-query-specific fields and methods, such as `hasNextPage` and
|
|
9
9
|
* `fetchNextPage`, and is the primitive that framework adapters (e.g.
|
|
10
10
|
* `useInfiniteQuery`) build their hooks on top of.
|
|
11
|
-
*
|
|
12
11
|
* @example
|
|
13
12
|
* ```ts
|
|
14
13
|
* const observer = new InfiniteQueryObserver(queryClient, {
|
|
@@ -35,6 +34,7 @@ var InfiniteQueryObserver = class extends require_queryObserver.QueryObserver {
|
|
|
35
34
|
* `QueryObserver.setOptions`, additionally marking the options as
|
|
36
35
|
* belonging to an infinite query before delegating to the base
|
|
37
36
|
* implementation.
|
|
37
|
+
* @param options - The new infinite query observer options.
|
|
38
38
|
*/
|
|
39
39
|
setOptions(options) {
|
|
40
40
|
options._type = "infinite";
|
|
@@ -45,6 +45,8 @@ var InfiniteQueryObserver = class extends require_queryObserver.QueryObserver {
|
|
|
45
45
|
* options as an infinite query before delegating to it. Called by framework adapters (e.g.
|
|
46
46
|
* `useInfiniteQuery`) ahead of subscribing, to compute the current `InfiniteQueryObserverResult`
|
|
47
47
|
* synchronously.
|
|
48
|
+
* @param options - The defaulted infinite query observer options to compute the result for.
|
|
49
|
+
* @returns The result for the given options.
|
|
48
50
|
*/
|
|
49
51
|
getOptimisticResult(options) {
|
|
50
52
|
options._type = "infinite";
|
|
@@ -56,7 +58,11 @@ var InfiniteQueryObserver = class extends require_queryObserver.QueryObserver {
|
|
|
56
58
|
* param used for the fetch is determined by `getNextPageParam`, which
|
|
57
59
|
* receives the current pages/page params and whose result also determines
|
|
58
60
|
* `hasNextPage`.
|
|
59
|
-
*
|
|
61
|
+
* @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,
|
|
62
|
+
* and `throwOnError` to `true` to reject when the fetch fails.
|
|
63
|
+
* @returns A promise that resolves with the result after the next page is fetched. With
|
|
64
|
+
* `cancelRefetch: false`, a running fetch is reused instead, so the next page may not be fetched.
|
|
65
|
+
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
|
|
60
66
|
* @example
|
|
61
67
|
* ```ts
|
|
62
68
|
* const { hasNextPage } = observer.getCurrentResult()
|
|
@@ -65,8 +71,6 @@ var InfiniteQueryObserver = class extends require_queryObserver.QueryObserver {
|
|
|
65
71
|
* await observer.fetchNextPage()
|
|
66
72
|
* }
|
|
67
73
|
* ```
|
|
68
|
-
*
|
|
69
|
-
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
|
|
70
74
|
*/
|
|
71
75
|
fetchNextPage(options) {
|
|
72
76
|
return this.fetch({
|
|
@@ -80,7 +84,11 @@ var InfiniteQueryObserver = class extends require_queryObserver.QueryObserver {
|
|
|
80
84
|
* param used for the fetch is determined by `getPreviousPageParam`, which
|
|
81
85
|
* receives the current pages/page params and whose result also determines
|
|
82
86
|
* `hasPreviousPage`.
|
|
83
|
-
*
|
|
87
|
+
* @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,
|
|
88
|
+
* and `throwOnError` to `true` to reject when the fetch fails.
|
|
89
|
+
* @returns A promise that resolves with the result after the previous page is fetched. With
|
|
90
|
+
* `cancelRefetch: false`, a running fetch is reused instead, so the previous page may not be fetched.
|
|
91
|
+
* @see {@link InfiniteQueryObserver#fetchNextPage}
|
|
84
92
|
* @example
|
|
85
93
|
* ```ts
|
|
86
94
|
* const { hasPreviousPage } = observer.getCurrentResult()
|
|
@@ -89,8 +97,6 @@ var InfiniteQueryObserver = class extends require_queryObserver.QueryObserver {
|
|
|
89
97
|
* await observer.fetchPreviousPage()
|
|
90
98
|
* }
|
|
91
99
|
* ```
|
|
92
|
-
*
|
|
93
|
-
* @see {@link InfiniteQueryObserver#fetchNextPage}
|
|
94
100
|
*/
|
|
95
101
|
fetchPreviousPage(options) {
|
|
96
102
|
return this.fetch({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infiniteQueryObserver.cjs","names":["QueryObserver","hasNextPage","hasPreviousPage"],"sources":["../../src/infiniteQueryObserver.ts"],"sourcesContent":["import { QueryObserver } from './queryObserver'\nimport { hasNextPage, hasPreviousPage } from './infiniteQueryBehavior'\nimport type { Subscribable } from './subscribable'\nimport type {\n DefaultError,\n DefaultedInfiniteQueryObserverOptions,\n FetchNextPageOptions,\n FetchPreviousPageOptions,\n InfiniteData,\n InfiniteQueryObserverBaseResult,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Query } from './query'\n\ntype InfiniteQueryObserverListener<TData, TError> = (\n result: InfiniteQueryObserverResult<TData, TError>,\n) => void\n\n/**\n * An `InfiniteQueryObserver` extends `QueryObserver` to observe and switch\n * between infinite queries. It augments the base `QueryObserverResult` with\n * infinite-query-specific fields and methods, such as `hasNextPage` and\n * `fetchNextPage`, and is the primitive that framework adapters (e.g.\n * `useInfiniteQuery`) build their hooks on top of.\n
|
|
1
|
+
{"version":3,"file":"infiniteQueryObserver.cjs","names":["QueryObserver","hasNextPage","hasPreviousPage"],"sources":["../../src/infiniteQueryObserver.ts"],"sourcesContent":["import { QueryObserver } from './queryObserver'\nimport { hasNextPage, hasPreviousPage } from './infiniteQueryBehavior'\nimport type { Subscribable } from './subscribable'\nimport type {\n DefaultError,\n DefaultedInfiniteQueryObserverOptions,\n FetchNextPageOptions,\n FetchPreviousPageOptions,\n InfiniteData,\n InfiniteQueryObserverBaseResult,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Query } from './query'\n\ntype InfiniteQueryObserverListener<TData, TError> = (\n result: InfiniteQueryObserverResult<TData, TError>,\n) => void\n\n/**\n * An `InfiniteQueryObserver` extends `QueryObserver` to observe and switch\n * between infinite queries. It augments the base `QueryObserverResult` with\n * infinite-query-specific fields and methods, such as `hasNextPage` and\n * `fetchNextPage`, and is the primitive that framework adapters (e.g.\n * `useInfiniteQuery`) build their hooks on top of.\n * @example\n * ```ts\n * const observer = new InfiniteQueryObserver(queryClient, {\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextCursor,\n * })\n *\n * const unsubscribe = observer.subscribe((result) => console.log(result))\n * ```\n */\nexport class InfiniteQueryObserver<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> extends QueryObserver<\n TQueryFnData,\n TError,\n TData,\n InfiniteData<TQueryFnData, TPageParam>,\n TQueryKey\n> {\n // Type override\n override subscribe!: Subscribable<\n InfiniteQueryObserverListener<TData, TError>\n >['subscribe']\n\n // Type override\n override getCurrentResult!: ReplaceReturnType<\n QueryObserver<\n TQueryFnData,\n TError,\n TData,\n InfiniteData<TQueryFnData, TPageParam>,\n TQueryKey\n >['getCurrentResult'],\n InfiniteQueryObserverResult<TData, TError>\n >\n\n // Type override\n protected override fetch!: ReplaceReturnType<\n QueryObserver<\n TQueryFnData,\n TError,\n TData,\n InfiniteData<TQueryFnData, TPageParam>,\n TQueryKey\n >['fetch'],\n Promise<InfiniteQueryObserverResult<TData, TError>>\n >\n\n constructor(\n client: QueryClient,\n options: InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ) {\n super(client, options)\n }\n\n protected override bindMethods(): void {\n super.bindMethods()\n this.fetchNextPage = this.fetchNextPage.bind(this)\n this.fetchPreviousPage = this.fetchPreviousPage.bind(this)\n }\n\n /**\n * Updates the observer's options. Behaves the same as\n * `QueryObserver.setOptions`, additionally marking the options as\n * belonging to an infinite query before delegating to the base\n * implementation.\n * @param options - The new infinite query observer options.\n */\n override setOptions(\n options: InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): void {\n options._type = 'infinite'\n super.setOptions(options)\n }\n\n /**\n * The infinite-query counterpart of {@link QueryObserver#getOptimisticResult}, marking the\n * options as an infinite query before delegating to it. Called by framework adapters (e.g.\n * `useInfiniteQuery`) ahead of subscribing, to compute the current `InfiniteQueryObserverResult`\n * synchronously.\n * @param options - The defaulted infinite query observer options to compute the result for.\n * @returns The result for the given options.\n */\n override getOptimisticResult(\n options: DefaultedInfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): InfiniteQueryObserverResult<TData, TError> {\n options._type = 'infinite'\n return super.getOptimisticResult(options) as InfiniteQueryObserverResult<\n TData,\n TError\n >\n }\n\n /**\n * Fetches the next page of the infinite query and returns a promise that\n * resolves with the resulting `InfiniteQueryObserverResult`. The page\n * param used for the fetch is determined by `getNextPageParam`, which\n * receives the current pages/page params and whose result also determines\n * `hasNextPage`.\n * @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,\n * and `throwOnError` to `true` to reject when the fetch fails.\n * @returns A promise that resolves with the result after the next page is fetched. With\n * `cancelRefetch: false`, a running fetch is reused instead, so the next page may not be fetched.\n * @see {@link InfiniteQueryObserver#fetchPreviousPage}\n * @example\n * ```ts\n * const { hasNextPage } = observer.getCurrentResult()\n *\n * if (hasNextPage) {\n * await observer.fetchNextPage()\n * }\n * ```\n */\n fetchNextPage(\n options?: FetchNextPageOptions,\n ): Promise<InfiniteQueryObserverResult<TData, TError>> {\n return this.fetch({\n ...options,\n meta: {\n fetchMore: { direction: 'forward' },\n },\n })\n }\n\n /**\n * Fetches the previous page of the infinite query and returns a promise\n * that resolves with the resulting `InfiniteQueryObserverResult`. The page\n * param used for the fetch is determined by `getPreviousPageParam`, which\n * receives the current pages/page params and whose result also determines\n * `hasPreviousPage`.\n * @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,\n * and `throwOnError` to `true` to reject when the fetch fails.\n * @returns A promise that resolves with the result after the previous page is fetched. With\n * `cancelRefetch: false`, a running fetch is reused instead, so the previous page may not be fetched.\n * @see {@link InfiniteQueryObserver#fetchNextPage}\n * @example\n * ```ts\n * const { hasPreviousPage } = observer.getCurrentResult()\n *\n * if (hasPreviousPage) {\n * await observer.fetchPreviousPage()\n * }\n * ```\n */\n fetchPreviousPage(\n options?: FetchPreviousPageOptions,\n ): Promise<InfiniteQueryObserverResult<TData, TError>> {\n return this.fetch({\n ...options,\n meta: {\n fetchMore: { direction: 'backward' },\n },\n })\n }\n\n protected override createResult(\n query: Query<\n TQueryFnData,\n TError,\n InfiniteData<TQueryFnData, TPageParam>,\n TQueryKey\n >,\n options: InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): InfiniteQueryObserverResult<TData, TError> {\n const { state } = query\n const parentResult = super.createResult(query, options)\n\n const { isFetching, isRefetching, isError, isRefetchError } = parentResult\n const fetchDirection = state.fetchMeta?.fetchMore?.direction\n\n const isFetchNextPageError = isError && fetchDirection === 'forward'\n const isFetchingNextPage = isFetching && fetchDirection === 'forward'\n\n const isFetchPreviousPageError = isError && fetchDirection === 'backward'\n const isFetchingPreviousPage = isFetching && fetchDirection === 'backward'\n\n const result: InfiniteQueryObserverBaseResult<TData, TError> = {\n ...parentResult,\n fetchNextPage: this.fetchNextPage,\n fetchPreviousPage: this.fetchPreviousPage,\n hasNextPage: hasNextPage(options, state.data),\n hasPreviousPage: hasPreviousPage(options, state.data),\n isFetchNextPageError,\n isFetchingNextPage,\n isFetchPreviousPageError,\n isFetchingPreviousPage,\n isRefetchError:\n isRefetchError && !isFetchNextPageError && !isFetchPreviousPageError,\n isRefetching:\n isRefetching && !isFetchingNextPage && !isFetchingPreviousPage,\n }\n\n return result as InfiniteQueryObserverResult<TData, TError>\n }\n}\n\ntype ReplaceReturnType<\n TFunction extends (...args: Array<any>) => unknown,\n TReturn,\n> = (...args: Parameters<TFunction>) => TReturn\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,wBAAb,cAMUA,sBAAAA,cAMR;CA8BA,YACE,QACA,SAOA;EACA,MAAM,QAAQ,OAAO;CACvB;CAEA,cAAuC;EACrC,MAAM,YAAY;EAClB,KAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;EACjD,KAAK,oBAAoB,KAAK,kBAAkB,KAAK,IAAI;CAC3D;;;;;;;;CASA,WACE,SAOM;EACN,QAAQ,QAAQ;EAChB,MAAM,WAAW,OAAO;CAC1B;;;;;;;;;CAUA,oBACE,SAO4C;EAC5C,QAAQ,QAAQ;EAChB,OAAO,MAAM,oBAAoB,OAAO;CAI1C;;;;;;;;;;;;;;;;;;;;;CAsBA,cACE,SACqD;EACrD,OAAO,KAAK,MAAM;GAChB,GAAG;GACH,MAAM,EACJ,WAAW,EAAE,WAAW,UAAU,EACpC;EACF,CAAC;CACH;;;;;;;;;;;;;;;;;;;;;CAsBA,kBACE,SACqD;EACrD,OAAO,KAAK,MAAM;GAChB,GAAG;GACH,MAAM,EACJ,WAAW,EAAE,WAAW,WAAW,EACrC;EACF,CAAC;CACH;CAEA,aACE,OAMA,SAO4C;EAC5C,MAAM,EAAE,UAAU;EAClB,MAAM,eAAe,MAAM,aAAa,OAAO,OAAO;EAEtD,MAAM,EAAE,YAAY,cAAc,SAAS,mBAAmB;EAC9D,MAAM,iBAAiB,MAAM,WAAW,WAAW;EAEnD,MAAM,uBAAuB,WAAW,mBAAmB;EAC3D,MAAM,qBAAqB,cAAc,mBAAmB;EAE5D,MAAM,2BAA2B,WAAW,mBAAmB;EAC/D,MAAM,yBAAyB,cAAc,mBAAmB;EAkBhE,OAAO;GAfL,GAAG;GACH,eAAe,KAAK;GACpB,mBAAmB,KAAK;GACxB,aAAaC,8BAAAA,YAAY,SAAS,MAAM,IAAI;GAC5C,iBAAiBC,8BAAAA,gBAAgB,SAAS,MAAM,IAAI;GACpD;GACA;GACA;GACA;GACA,gBACE,kBAAkB,CAAC,wBAAwB,CAAC;GAC9C,cACE,gBAAgB,CAAC,sBAAsB,CAAC;EAGhC;CACd;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Subscribable } from "./subscribable-
|
|
2
|
-
import { $n as Query, A as InfiniteData, C as FetchPreviousPageOptions, Ct as QueryKey, F as InfiniteQueryObserverOptions, S as FetchNextPageOptions, f as DefaultError, m as DefaultedInfiniteQueryObserverOptions, on as QueryClient, rr as QueryObserver, z as InfiniteQueryObserverResult } from "./hydration-
|
|
1
|
+
import { t as Subscribable } from "./subscribable-czlHOxMP.cjs";
|
|
2
|
+
import { $n as Query, A as InfiniteData, C as FetchPreviousPageOptions, Ct as QueryKey, F as InfiniteQueryObserverOptions, S as FetchNextPageOptions, f as DefaultError, m as DefaultedInfiniteQueryObserverOptions, on as QueryClient, rr as QueryObserver, z as InfiniteQueryObserverResult } from "./hydration-Dfuxd5FW.cjs";
|
|
3
3
|
//#region src/infiniteQueryObserver.d.ts
|
|
4
4
|
type InfiniteQueryObserverListener<TData, TError> = (result: InfiniteQueryObserverResult<TData, TError>) => void;
|
|
5
5
|
/**
|
|
@@ -8,7 +8,6 @@ type InfiniteQueryObserverListener<TData, TError> = (result: InfiniteQueryObserv
|
|
|
8
8
|
* infinite-query-specific fields and methods, such as `hasNextPage` and
|
|
9
9
|
* `fetchNextPage`, and is the primitive that framework adapters (e.g.
|
|
10
10
|
* `useInfiniteQuery`) build their hooks on top of.
|
|
11
|
-
*
|
|
12
11
|
* @example
|
|
13
12
|
* ```ts
|
|
14
13
|
* const observer = new InfiniteQueryObserver(queryClient, {
|
|
@@ -32,6 +31,7 @@ export declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = Defa
|
|
|
32
31
|
* `QueryObserver.setOptions`, additionally marking the options as
|
|
33
32
|
* belonging to an infinite query before delegating to the base
|
|
34
33
|
* implementation.
|
|
34
|
+
* @param options - The new infinite query observer options.
|
|
35
35
|
*/
|
|
36
36
|
setOptions(options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): void;
|
|
37
37
|
/**
|
|
@@ -39,6 +39,8 @@ export declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = Defa
|
|
|
39
39
|
* options as an infinite query before delegating to it. Called by framework adapters (e.g.
|
|
40
40
|
* `useInfiniteQuery`) ahead of subscribing, to compute the current `InfiniteQueryObserverResult`
|
|
41
41
|
* synchronously.
|
|
42
|
+
* @param options - The defaulted infinite query observer options to compute the result for.
|
|
43
|
+
* @returns The result for the given options.
|
|
42
44
|
*/
|
|
43
45
|
getOptimisticResult(options: DefaultedInfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): InfiniteQueryObserverResult<TData, TError>;
|
|
44
46
|
/**
|
|
@@ -47,7 +49,11 @@ export declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = Defa
|
|
|
47
49
|
* param used for the fetch is determined by `getNextPageParam`, which
|
|
48
50
|
* receives the current pages/page params and whose result also determines
|
|
49
51
|
* `hasNextPage`.
|
|
50
|
-
*
|
|
52
|
+
* @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,
|
|
53
|
+
* and `throwOnError` to `true` to reject when the fetch fails.
|
|
54
|
+
* @returns A promise that resolves with the result after the next page is fetched. With
|
|
55
|
+
* `cancelRefetch: false`, a running fetch is reused instead, so the next page may not be fetched.
|
|
56
|
+
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
|
|
51
57
|
* @example
|
|
52
58
|
* ```ts
|
|
53
59
|
* const { hasNextPage } = observer.getCurrentResult()
|
|
@@ -56,8 +62,6 @@ export declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = Defa
|
|
|
56
62
|
* await observer.fetchNextPage()
|
|
57
63
|
* }
|
|
58
64
|
* ```
|
|
59
|
-
*
|
|
60
|
-
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
|
|
61
65
|
*/
|
|
62
66
|
fetchNextPage(options?: FetchNextPageOptions): Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
63
67
|
/**
|
|
@@ -66,7 +70,11 @@ export declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = Defa
|
|
|
66
70
|
* param used for the fetch is determined by `getPreviousPageParam`, which
|
|
67
71
|
* receives the current pages/page params and whose result also determines
|
|
68
72
|
* `hasPreviousPage`.
|
|
69
|
-
*
|
|
73
|
+
* @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,
|
|
74
|
+
* and `throwOnError` to `true` to reject when the fetch fails.
|
|
75
|
+
* @returns A promise that resolves with the result after the previous page is fetched. With
|
|
76
|
+
* `cancelRefetch: false`, a running fetch is reused instead, so the previous page may not be fetched.
|
|
77
|
+
* @see {@link InfiniteQueryObserver#fetchNextPage}
|
|
70
78
|
* @example
|
|
71
79
|
* ```ts
|
|
72
80
|
* const { hasPreviousPage } = observer.getCurrentResult()
|
|
@@ -75,8 +83,6 @@ export declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = Defa
|
|
|
75
83
|
* await observer.fetchPreviousPage()
|
|
76
84
|
* }
|
|
77
85
|
* ```
|
|
78
|
-
*
|
|
79
|
-
* @see {@link InfiniteQueryObserver#fetchNextPage}
|
|
80
86
|
*/
|
|
81
87
|
fetchPreviousPage(options?: FetchPreviousPageOptions): Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
82
88
|
protected createResult(query: Query<TQueryFnData, TError, InfiniteData<TQueryFnData, TPageParam>, TQueryKey>, options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): InfiniteQueryObserverResult<TData, TError>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infiniteQueryObserver.d.cts","names":[],"sources":["../../src/infiniteQueryObserver.ts"],"mappings":";;;KAiBK,8BAA8B,OAAO,WACxC,QAAQ,4BAA4B,OAAO
|
|
1
|
+
{"version":3,"file":"infiniteQueryObserver.d.cts","names":[],"sources":["../../src/infiniteQueryObserver.ts"],"mappings":";;;KAiBK,8BAA8B,OAAO,WACxC,QAAQ,4BAA4B,OAAO;;;;;;;;;;;;;;;;;;;qBAqBhC,sBACX,wBACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,8BACQ,cACR,cACA,QACA,OACA,aAAa,cAAc,aAC3B;EAGS,WAAY,aACnB,8BAA8B,OAAO;EAI9B,kBAAmB,kBAC1B,cACE,cACA,QACA,OACA,aAAa,cAAc,aAC3B,gCAEF,4BAA4B,OAAO;YAIlB,OAAQ,kBACzB,cACE,cACA,QACA,OACA,aAAa,cAAc,aAC3B,qBAEF,QAAQ,4BAA4B,OAAO;EAI3C,YAAA,QAAQ,aACR,SAAS,6BACP,cACA,QACA,OACA,WACA;YAMe;;;;;;;;EAaV,WACP,SAAS,6BACP,cACA,QACA,OACA,WACA;;;;;;;;;EAeK,oBACP,SAAS,sCACP,cACA,QACA,OACA,WACA,cAED,4BAA4B,OAAO;;;;;;;;;;;;;;;;;;;;;EA4BtC,cACE,UAAU,uBACT,QAAQ,4BAA4B,OAAO;;;;;;;;;;;;;;;;;;;;;EA6B9C,kBACE,UAAU,2BACT,QAAQ,4BAA4B,OAAO;YAS3B,aACjB,OAAO,MACL,cACA,QACA,aAAa,cAAc,aAC3B,YAEF,SAAS,6BACP,cACA,QACA,OACA,WACA,cAED,4BAA4B,OAAO;;KAiCnC,kBACH,sBAAsB,MAAM,wBAC5B,eACM,MAAM,WAAW,eAAe"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Subscribable } from "./subscribable-
|
|
2
|
-
import { $n as Query, A as InfiniteData, C as FetchPreviousPageOptions, Ct as QueryKey, F as InfiniteQueryObserverOptions, S as FetchNextPageOptions, f as DefaultError, m as DefaultedInfiniteQueryObserverOptions, on as QueryClient, rr as QueryObserver, z as InfiniteQueryObserverResult } from "./hydration-
|
|
1
|
+
import { t as Subscribable } from "./subscribable-czlHOxMP.js";
|
|
2
|
+
import { $n as Query, A as InfiniteData, C as FetchPreviousPageOptions, Ct as QueryKey, F as InfiniteQueryObserverOptions, S as FetchNextPageOptions, f as DefaultError, m as DefaultedInfiniteQueryObserverOptions, on as QueryClient, rr as QueryObserver, z as InfiniteQueryObserverResult } from "./hydration-UAqdtMIf.js";
|
|
3
3
|
//#region src/infiniteQueryObserver.d.ts
|
|
4
4
|
type InfiniteQueryObserverListener<TData, TError> = (result: InfiniteQueryObserverResult<TData, TError>) => void;
|
|
5
5
|
/**
|
|
@@ -8,7 +8,6 @@ type InfiniteQueryObserverListener<TData, TError> = (result: InfiniteQueryObserv
|
|
|
8
8
|
* infinite-query-specific fields and methods, such as `hasNextPage` and
|
|
9
9
|
* `fetchNextPage`, and is the primitive that framework adapters (e.g.
|
|
10
10
|
* `useInfiniteQuery`) build their hooks on top of.
|
|
11
|
-
*
|
|
12
11
|
* @example
|
|
13
12
|
* ```ts
|
|
14
13
|
* const observer = new InfiniteQueryObserver(queryClient, {
|
|
@@ -32,6 +31,7 @@ export declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = Defa
|
|
|
32
31
|
* `QueryObserver.setOptions`, additionally marking the options as
|
|
33
32
|
* belonging to an infinite query before delegating to the base
|
|
34
33
|
* implementation.
|
|
34
|
+
* @param options - The new infinite query observer options.
|
|
35
35
|
*/
|
|
36
36
|
setOptions(options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): void;
|
|
37
37
|
/**
|
|
@@ -39,6 +39,8 @@ export declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = Defa
|
|
|
39
39
|
* options as an infinite query before delegating to it. Called by framework adapters (e.g.
|
|
40
40
|
* `useInfiniteQuery`) ahead of subscribing, to compute the current `InfiniteQueryObserverResult`
|
|
41
41
|
* synchronously.
|
|
42
|
+
* @param options - The defaulted infinite query observer options to compute the result for.
|
|
43
|
+
* @returns The result for the given options.
|
|
42
44
|
*/
|
|
43
45
|
getOptimisticResult(options: DefaultedInfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): InfiniteQueryObserverResult<TData, TError>;
|
|
44
46
|
/**
|
|
@@ -47,7 +49,11 @@ export declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = Defa
|
|
|
47
49
|
* param used for the fetch is determined by `getNextPageParam`, which
|
|
48
50
|
* receives the current pages/page params and whose result also determines
|
|
49
51
|
* `hasNextPage`.
|
|
50
|
-
*
|
|
52
|
+
* @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,
|
|
53
|
+
* and `throwOnError` to `true` to reject when the fetch fails.
|
|
54
|
+
* @returns A promise that resolves with the result after the next page is fetched. With
|
|
55
|
+
* `cancelRefetch: false`, a running fetch is reused instead, so the next page may not be fetched.
|
|
56
|
+
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
|
|
51
57
|
* @example
|
|
52
58
|
* ```ts
|
|
53
59
|
* const { hasNextPage } = observer.getCurrentResult()
|
|
@@ -56,8 +62,6 @@ export declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = Defa
|
|
|
56
62
|
* await observer.fetchNextPage()
|
|
57
63
|
* }
|
|
58
64
|
* ```
|
|
59
|
-
*
|
|
60
|
-
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
|
|
61
65
|
*/
|
|
62
66
|
fetchNextPage(options?: FetchNextPageOptions): Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
63
67
|
/**
|
|
@@ -66,7 +70,11 @@ export declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = Defa
|
|
|
66
70
|
* param used for the fetch is determined by `getPreviousPageParam`, which
|
|
67
71
|
* receives the current pages/page params and whose result also determines
|
|
68
72
|
* `hasPreviousPage`.
|
|
69
|
-
*
|
|
73
|
+
* @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,
|
|
74
|
+
* and `throwOnError` to `true` to reject when the fetch fails.
|
|
75
|
+
* @returns A promise that resolves with the result after the previous page is fetched. With
|
|
76
|
+
* `cancelRefetch: false`, a running fetch is reused instead, so the previous page may not be fetched.
|
|
77
|
+
* @see {@link InfiniteQueryObserver#fetchNextPage}
|
|
70
78
|
* @example
|
|
71
79
|
* ```ts
|
|
72
80
|
* const { hasPreviousPage } = observer.getCurrentResult()
|
|
@@ -75,8 +83,6 @@ export declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = Defa
|
|
|
75
83
|
* await observer.fetchPreviousPage()
|
|
76
84
|
* }
|
|
77
85
|
* ```
|
|
78
|
-
*
|
|
79
|
-
* @see {@link InfiniteQueryObserver#fetchNextPage}
|
|
80
86
|
*/
|
|
81
87
|
fetchPreviousPage(options?: FetchPreviousPageOptions): Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
82
88
|
protected createResult(query: Query<TQueryFnData, TError, InfiniteData<TQueryFnData, TPageParam>, TQueryKey>, options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): InfiniteQueryObserverResult<TData, TError>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infiniteQueryObserver.d.ts","names":[],"sources":["../../src/infiniteQueryObserver.ts"],"mappings":";;;KAiBK,8BAA8B,OAAO,WACxC,QAAQ,4BAA4B,OAAO
|
|
1
|
+
{"version":3,"file":"infiniteQueryObserver.d.ts","names":[],"sources":["../../src/infiniteQueryObserver.ts"],"mappings":";;;KAiBK,8BAA8B,OAAO,WACxC,QAAQ,4BAA4B,OAAO;;;;;;;;;;;;;;;;;;;qBAqBhC,sBACX,wBACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,8BACQ,cACR,cACA,QACA,OACA,aAAa,cAAc,aAC3B;EAGS,WAAY,aACnB,8BAA8B,OAAO;EAI9B,kBAAmB,kBAC1B,cACE,cACA,QACA,OACA,aAAa,cAAc,aAC3B,gCAEF,4BAA4B,OAAO;YAIlB,OAAQ,kBACzB,cACE,cACA,QACA,OACA,aAAa,cAAc,aAC3B,qBAEF,QAAQ,4BAA4B,OAAO;EAI3C,YAAA,QAAQ,aACR,SAAS,6BACP,cACA,QACA,OACA,WACA;YAMe;;;;;;;;EAaV,WACP,SAAS,6BACP,cACA,QACA,OACA,WACA;;;;;;;;;EAeK,oBACP,SAAS,sCACP,cACA,QACA,OACA,WACA,cAED,4BAA4B,OAAO;;;;;;;;;;;;;;;;;;;;;EA4BtC,cACE,UAAU,uBACT,QAAQ,4BAA4B,OAAO;;;;;;;;;;;;;;;;;;;;;EA6B9C,kBACE,UAAU,2BACT,QAAQ,4BAA4B,OAAO;YAS3B,aACjB,OAAO,MACL,cACA,QACA,aAAa,cAAc,aAC3B,YAEF,SAAS,6BACP,cACA,QACA,OACA,WACA,cAED,4BAA4B,OAAO;;KAiCnC,kBACH,sBAAsB,MAAM,wBAC5B,eACM,MAAM,WAAW,eAAe"}
|
|
@@ -7,7 +7,6 @@ import { QueryObserver } from "./queryObserver.js";
|
|
|
7
7
|
* infinite-query-specific fields and methods, such as `hasNextPage` and
|
|
8
8
|
* `fetchNextPage`, and is the primitive that framework adapters (e.g.
|
|
9
9
|
* `useInfiniteQuery`) build their hooks on top of.
|
|
10
|
-
*
|
|
11
10
|
* @example
|
|
12
11
|
* ```ts
|
|
13
12
|
* const observer = new InfiniteQueryObserver(queryClient, {
|
|
@@ -34,6 +33,7 @@ var InfiniteQueryObserver = class extends QueryObserver {
|
|
|
34
33
|
* `QueryObserver.setOptions`, additionally marking the options as
|
|
35
34
|
* belonging to an infinite query before delegating to the base
|
|
36
35
|
* implementation.
|
|
36
|
+
* @param options - The new infinite query observer options.
|
|
37
37
|
*/
|
|
38
38
|
setOptions(options) {
|
|
39
39
|
options._type = "infinite";
|
|
@@ -44,6 +44,8 @@ var InfiniteQueryObserver = class extends QueryObserver {
|
|
|
44
44
|
* options as an infinite query before delegating to it. Called by framework adapters (e.g.
|
|
45
45
|
* `useInfiniteQuery`) ahead of subscribing, to compute the current `InfiniteQueryObserverResult`
|
|
46
46
|
* synchronously.
|
|
47
|
+
* @param options - The defaulted infinite query observer options to compute the result for.
|
|
48
|
+
* @returns The result for the given options.
|
|
47
49
|
*/
|
|
48
50
|
getOptimisticResult(options) {
|
|
49
51
|
options._type = "infinite";
|
|
@@ -55,7 +57,11 @@ var InfiniteQueryObserver = class extends QueryObserver {
|
|
|
55
57
|
* param used for the fetch is determined by `getNextPageParam`, which
|
|
56
58
|
* receives the current pages/page params and whose result also determines
|
|
57
59
|
* `hasNextPage`.
|
|
58
|
-
*
|
|
60
|
+
* @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,
|
|
61
|
+
* and `throwOnError` to `true` to reject when the fetch fails.
|
|
62
|
+
* @returns A promise that resolves with the result after the next page is fetched. With
|
|
63
|
+
* `cancelRefetch: false`, a running fetch is reused instead, so the next page may not be fetched.
|
|
64
|
+
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
|
|
59
65
|
* @example
|
|
60
66
|
* ```ts
|
|
61
67
|
* const { hasNextPage } = observer.getCurrentResult()
|
|
@@ -64,8 +70,6 @@ var InfiniteQueryObserver = class extends QueryObserver {
|
|
|
64
70
|
* await observer.fetchNextPage()
|
|
65
71
|
* }
|
|
66
72
|
* ```
|
|
67
|
-
*
|
|
68
|
-
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
|
|
69
73
|
*/
|
|
70
74
|
fetchNextPage(options) {
|
|
71
75
|
return this.fetch({
|
|
@@ -79,7 +83,11 @@ var InfiniteQueryObserver = class extends QueryObserver {
|
|
|
79
83
|
* param used for the fetch is determined by `getPreviousPageParam`, which
|
|
80
84
|
* receives the current pages/page params and whose result also determines
|
|
81
85
|
* `hasPreviousPage`.
|
|
82
|
-
*
|
|
86
|
+
* @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,
|
|
87
|
+
* and `throwOnError` to `true` to reject when the fetch fails.
|
|
88
|
+
* @returns A promise that resolves with the result after the previous page is fetched. With
|
|
89
|
+
* `cancelRefetch: false`, a running fetch is reused instead, so the previous page may not be fetched.
|
|
90
|
+
* @see {@link InfiniteQueryObserver#fetchNextPage}
|
|
83
91
|
* @example
|
|
84
92
|
* ```ts
|
|
85
93
|
* const { hasPreviousPage } = observer.getCurrentResult()
|
|
@@ -88,8 +96,6 @@ var InfiniteQueryObserver = class extends QueryObserver {
|
|
|
88
96
|
* await observer.fetchPreviousPage()
|
|
89
97
|
* }
|
|
90
98
|
* ```
|
|
91
|
-
*
|
|
92
|
-
* @see {@link InfiniteQueryObserver#fetchNextPage}
|
|
93
99
|
*/
|
|
94
100
|
fetchPreviousPage(options) {
|
|
95
101
|
return this.fetch({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infiniteQueryObserver.js","names":[],"sources":["../../src/infiniteQueryObserver.ts"],"sourcesContent":["import { QueryObserver } from './queryObserver'\nimport { hasNextPage, hasPreviousPage } from './infiniteQueryBehavior'\nimport type { Subscribable } from './subscribable'\nimport type {\n DefaultError,\n DefaultedInfiniteQueryObserverOptions,\n FetchNextPageOptions,\n FetchPreviousPageOptions,\n InfiniteData,\n InfiniteQueryObserverBaseResult,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Query } from './query'\n\ntype InfiniteQueryObserverListener<TData, TError> = (\n result: InfiniteQueryObserverResult<TData, TError>,\n) => void\n\n/**\n * An `InfiniteQueryObserver` extends `QueryObserver` to observe and switch\n * between infinite queries. It augments the base `QueryObserverResult` with\n * infinite-query-specific fields and methods, such as `hasNextPage` and\n * `fetchNextPage`, and is the primitive that framework adapters (e.g.\n * `useInfiniteQuery`) build their hooks on top of.\n
|
|
1
|
+
{"version":3,"file":"infiniteQueryObserver.js","names":[],"sources":["../../src/infiniteQueryObserver.ts"],"sourcesContent":["import { QueryObserver } from './queryObserver'\nimport { hasNextPage, hasPreviousPage } from './infiniteQueryBehavior'\nimport type { Subscribable } from './subscribable'\nimport type {\n DefaultError,\n DefaultedInfiniteQueryObserverOptions,\n FetchNextPageOptions,\n FetchPreviousPageOptions,\n InfiniteData,\n InfiniteQueryObserverBaseResult,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Query } from './query'\n\ntype InfiniteQueryObserverListener<TData, TError> = (\n result: InfiniteQueryObserverResult<TData, TError>,\n) => void\n\n/**\n * An `InfiniteQueryObserver` extends `QueryObserver` to observe and switch\n * between infinite queries. It augments the base `QueryObserverResult` with\n * infinite-query-specific fields and methods, such as `hasNextPage` and\n * `fetchNextPage`, and is the primitive that framework adapters (e.g.\n * `useInfiniteQuery`) build their hooks on top of.\n * @example\n * ```ts\n * const observer = new InfiniteQueryObserver(queryClient, {\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextCursor,\n * })\n *\n * const unsubscribe = observer.subscribe((result) => console.log(result))\n * ```\n */\nexport class InfiniteQueryObserver<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> extends QueryObserver<\n TQueryFnData,\n TError,\n TData,\n InfiniteData<TQueryFnData, TPageParam>,\n TQueryKey\n> {\n // Type override\n override subscribe!: Subscribable<\n InfiniteQueryObserverListener<TData, TError>\n >['subscribe']\n\n // Type override\n override getCurrentResult!: ReplaceReturnType<\n QueryObserver<\n TQueryFnData,\n TError,\n TData,\n InfiniteData<TQueryFnData, TPageParam>,\n TQueryKey\n >['getCurrentResult'],\n InfiniteQueryObserverResult<TData, TError>\n >\n\n // Type override\n protected override fetch!: ReplaceReturnType<\n QueryObserver<\n TQueryFnData,\n TError,\n TData,\n InfiniteData<TQueryFnData, TPageParam>,\n TQueryKey\n >['fetch'],\n Promise<InfiniteQueryObserverResult<TData, TError>>\n >\n\n constructor(\n client: QueryClient,\n options: InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ) {\n super(client, options)\n }\n\n protected override bindMethods(): void {\n super.bindMethods()\n this.fetchNextPage = this.fetchNextPage.bind(this)\n this.fetchPreviousPage = this.fetchPreviousPage.bind(this)\n }\n\n /**\n * Updates the observer's options. Behaves the same as\n * `QueryObserver.setOptions`, additionally marking the options as\n * belonging to an infinite query before delegating to the base\n * implementation.\n * @param options - The new infinite query observer options.\n */\n override setOptions(\n options: InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): void {\n options._type = 'infinite'\n super.setOptions(options)\n }\n\n /**\n * The infinite-query counterpart of {@link QueryObserver#getOptimisticResult}, marking the\n * options as an infinite query before delegating to it. Called by framework adapters (e.g.\n * `useInfiniteQuery`) ahead of subscribing, to compute the current `InfiniteQueryObserverResult`\n * synchronously.\n * @param options - The defaulted infinite query observer options to compute the result for.\n * @returns The result for the given options.\n */\n override getOptimisticResult(\n options: DefaultedInfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): InfiniteQueryObserverResult<TData, TError> {\n options._type = 'infinite'\n return super.getOptimisticResult(options) as InfiniteQueryObserverResult<\n TData,\n TError\n >\n }\n\n /**\n * Fetches the next page of the infinite query and returns a promise that\n * resolves with the resulting `InfiniteQueryObserverResult`. The page\n * param used for the fetch is determined by `getNextPageParam`, which\n * receives the current pages/page params and whose result also determines\n * `hasNextPage`.\n * @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,\n * and `throwOnError` to `true` to reject when the fetch fails.\n * @returns A promise that resolves with the result after the next page is fetched. With\n * `cancelRefetch: false`, a running fetch is reused instead, so the next page may not be fetched.\n * @see {@link InfiniteQueryObserver#fetchPreviousPage}\n * @example\n * ```ts\n * const { hasNextPage } = observer.getCurrentResult()\n *\n * if (hasNextPage) {\n * await observer.fetchNextPage()\n * }\n * ```\n */\n fetchNextPage(\n options?: FetchNextPageOptions,\n ): Promise<InfiniteQueryObserverResult<TData, TError>> {\n return this.fetch({\n ...options,\n meta: {\n fetchMore: { direction: 'forward' },\n },\n })\n }\n\n /**\n * Fetches the previous page of the infinite query and returns a promise\n * that resolves with the resulting `InfiniteQueryObserverResult`. The page\n * param used for the fetch is determined by `getPreviousPageParam`, which\n * receives the current pages/page params and whose result also determines\n * `hasPreviousPage`.\n * @param options - Set `cancelRefetch` to `false` to ignore the call while a fetch is running,\n * and `throwOnError` to `true` to reject when the fetch fails.\n * @returns A promise that resolves with the result after the previous page is fetched. With\n * `cancelRefetch: false`, a running fetch is reused instead, so the previous page may not be fetched.\n * @see {@link InfiniteQueryObserver#fetchNextPage}\n * @example\n * ```ts\n * const { hasPreviousPage } = observer.getCurrentResult()\n *\n * if (hasPreviousPage) {\n * await observer.fetchPreviousPage()\n * }\n * ```\n */\n fetchPreviousPage(\n options?: FetchPreviousPageOptions,\n ): Promise<InfiniteQueryObserverResult<TData, TError>> {\n return this.fetch({\n ...options,\n meta: {\n fetchMore: { direction: 'backward' },\n },\n })\n }\n\n protected override createResult(\n query: Query<\n TQueryFnData,\n TError,\n InfiniteData<TQueryFnData, TPageParam>,\n TQueryKey\n >,\n options: InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n ): InfiniteQueryObserverResult<TData, TError> {\n const { state } = query\n const parentResult = super.createResult(query, options)\n\n const { isFetching, isRefetching, isError, isRefetchError } = parentResult\n const fetchDirection = state.fetchMeta?.fetchMore?.direction\n\n const isFetchNextPageError = isError && fetchDirection === 'forward'\n const isFetchingNextPage = isFetching && fetchDirection === 'forward'\n\n const isFetchPreviousPageError = isError && fetchDirection === 'backward'\n const isFetchingPreviousPage = isFetching && fetchDirection === 'backward'\n\n const result: InfiniteQueryObserverBaseResult<TData, TError> = {\n ...parentResult,\n fetchNextPage: this.fetchNextPage,\n fetchPreviousPage: this.fetchPreviousPage,\n hasNextPage: hasNextPage(options, state.data),\n hasPreviousPage: hasPreviousPage(options, state.data),\n isFetchNextPageError,\n isFetchingNextPage,\n isFetchPreviousPageError,\n isFetchingPreviousPage,\n isRefetchError:\n isRefetchError && !isFetchNextPageError && !isFetchPreviousPageError,\n isRefetching:\n isRefetching && !isFetchingNextPage && !isFetchingPreviousPage,\n }\n\n return result as InfiniteQueryObserverResult<TData, TError>\n }\n}\n\ntype ReplaceReturnType<\n TFunction extends (...args: Array<any>) => unknown,\n TReturn,\n> = (...args: Parameters<TFunction>) => TReturn\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,wBAAb,cAMU,cAMR;CA8BA,YACE,QACA,SAOA;EACA,MAAM,QAAQ,OAAO;CACvB;CAEA,cAAuC;EACrC,MAAM,YAAY;EAClB,KAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;EACjD,KAAK,oBAAoB,KAAK,kBAAkB,KAAK,IAAI;CAC3D;;;;;;;;CASA,WACE,SAOM;EACN,QAAQ,QAAQ;EAChB,MAAM,WAAW,OAAO;CAC1B;;;;;;;;;CAUA,oBACE,SAO4C;EAC5C,QAAQ,QAAQ;EAChB,OAAO,MAAM,oBAAoB,OAAO;CAI1C;;;;;;;;;;;;;;;;;;;;;CAsBA,cACE,SACqD;EACrD,OAAO,KAAK,MAAM;GAChB,GAAG;GACH,MAAM,EACJ,WAAW,EAAE,WAAW,UAAU,EACpC;EACF,CAAC;CACH;;;;;;;;;;;;;;;;;;;;;CAsBA,kBACE,SACqD;EACrD,OAAO,KAAK,MAAM;GAChB,GAAG;GACH,MAAM,EACJ,WAAW,EAAE,WAAW,WAAW,EACrC;EACF,CAAC;CACH;CAEA,aACE,OAMA,SAO4C;EAC5C,MAAM,EAAE,UAAU;EAClB,MAAM,eAAe,MAAM,aAAa,OAAO,OAAO;EAEtD,MAAM,EAAE,YAAY,cAAc,SAAS,mBAAmB;EAC9D,MAAM,iBAAiB,MAAM,WAAW,WAAW;EAEnD,MAAM,uBAAuB,WAAW,mBAAmB;EAC3D,MAAM,qBAAqB,cAAc,mBAAmB;EAE5D,MAAM,2BAA2B,WAAW,mBAAmB;EAC/D,MAAM,yBAAyB,cAAc,mBAAmB;EAkBhE,OAAO;GAfL,GAAG;GACH,eAAe,KAAK;GACpB,mBAAmB,KAAK;GACxB,aAAa,YAAY,SAAS,MAAM,IAAI;GAC5C,iBAAiB,gBAAgB,SAAS,MAAM,IAAI;GACpD;GACA;GACA;GACA;GACA,gBACE,kBAAkB,CAAC,wBAAwB,CAAC;GAC9C,cACE,gBAAgB,CAAC,sBAAsB,CAAC;EAGhC;CACd;AACF"}
|
|
@@ -12,7 +12,6 @@ const require_removable = require("./removable.cjs");
|
|
|
12
12
|
* code typically interacts with mutations indirectly through `QueryClient` or
|
|
13
13
|
* a framework hook like `useMutation`. Direct access to a `Mutation` instance
|
|
14
14
|
* is possible via `mutationCache.find()`/`getAll()` for inspecting cache state.
|
|
15
|
-
*
|
|
16
15
|
* @example
|
|
17
16
|
* ```ts
|
|
18
17
|
* const mutationCache = queryClient.getMutationCache()
|
|
@@ -35,18 +34,28 @@ var Mutation = class extends require_removable.Removable {
|
|
|
35
34
|
this.setOptions(config.options);
|
|
36
35
|
this.scheduleGc();
|
|
37
36
|
}
|
|
38
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Replaces the mutation's options and applies their `gcTime`.
|
|
39
|
+
* @internal
|
|
40
|
+
* @param options - The new mutation options.
|
|
41
|
+
*/
|
|
39
42
|
setOptions(options) {
|
|
40
43
|
this.options = options;
|
|
41
44
|
this.updateGcTime(this.options.gcTime);
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
47
|
* The `meta` object passed in the mutation's options, if any.
|
|
48
|
+
* @returns The mutation's `meta`, or `undefined` if none was set.
|
|
45
49
|
*/
|
|
46
50
|
get meta() {
|
|
47
51
|
return this.options.meta;
|
|
48
52
|
}
|
|
49
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Subscribes an observer to the mutation and stops its garbage collection.
|
|
55
|
+
* @internal
|
|
56
|
+
* @param observer - The observer to add. Adding an observer that is already subscribed does
|
|
57
|
+
* nothing.
|
|
58
|
+
*/
|
|
50
59
|
addObserver(observer) {
|
|
51
60
|
if (!this.#observers.includes(observer)) {
|
|
52
61
|
this.#observers.push(observer);
|
|
@@ -58,7 +67,11 @@ var Mutation = class extends require_removable.Removable {
|
|
|
58
67
|
});
|
|
59
68
|
}
|
|
60
69
|
}
|
|
61
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Unsubscribes an observer from the mutation.
|
|
72
|
+
* @internal
|
|
73
|
+
* @param observer - The observer to remove. Garbage collection is scheduled afterwards.
|
|
74
|
+
*/
|
|
62
75
|
removeObserver(observer) {
|
|
63
76
|
this.#observers = this.#observers.filter((x) => x !== observer);
|
|
64
77
|
this.scheduleGc();
|
|
@@ -85,15 +98,15 @@ var Mutation = class extends require_removable.Removable {
|
|
|
85
98
|
* this instance), `execute` is called again with the last known variables.
|
|
86
99
|
* - Otherwise the mutation has already settled and this resolves immediately
|
|
87
100
|
* without running anything again.
|
|
88
|
-
*
|
|
101
|
+
* @returns A promise that settles with the resumed mutation: it rejects if the mutation fails.
|
|
102
|
+
* It resolves immediately if the mutation has already settled.
|
|
103
|
+
* @see {@link Mutation#execute}
|
|
89
104
|
* @example
|
|
90
105
|
* ```ts
|
|
91
106
|
* // typically driven by reconnect handling, e.g. queryClient.resumePausedMutations()
|
|
92
107
|
* const mutation = mutationCache.find({ mutationKey: ['addPost'] })
|
|
93
108
|
* await mutation?.continue()
|
|
94
109
|
* ```
|
|
95
|
-
*
|
|
96
|
-
* @see {@link Mutation#execute}
|
|
97
110
|
*/
|
|
98
111
|
continue() {
|
|
99
112
|
return this.#retryer?.continue() ?? (this.state.status === "pending" ? this.execute(this.state.variables) : Promise.resolve());
|
|
@@ -118,15 +131,15 @@ var Mutation = class extends require_removable.Removable {
|
|
|
118
131
|
* those four callbacks is individually caught so that a throwing callback
|
|
119
132
|
* cannot mask the original error; an `error` action is then dispatched and
|
|
120
133
|
* the original error is re-thrown.
|
|
121
|
-
*
|
|
134
|
+
* @param variables - The variables passed to the `mutationFn`.
|
|
135
|
+
* @returns A promise that resolves with the mutation's data, or rejects with its error.
|
|
136
|
+
* @see {@link Mutation#continue}
|
|
122
137
|
* @example
|
|
123
138
|
* ```ts
|
|
124
139
|
* // Called internally by `MutationObserver.mutate` and `Mutation.continue` —
|
|
125
140
|
* // applications normally trigger mutations through those, not this method.
|
|
126
141
|
* const data = await mutation.execute(variables)
|
|
127
142
|
* ```
|
|
128
|
-
*
|
|
129
|
-
* @see {@link Mutation#continue}
|
|
130
143
|
*/
|
|
131
144
|
async execute(variables) {
|
|
132
145
|
const onContinue = () => {
|
|
@@ -279,6 +292,10 @@ var Mutation = class extends require_removable.Removable {
|
|
|
279
292
|
});
|
|
280
293
|
}
|
|
281
294
|
};
|
|
295
|
+
/**
|
|
296
|
+
* Returns the initial state of a mutation: `'idle'`, with no data, error, or variables.
|
|
297
|
+
* @returns The initial mutation state.
|
|
298
|
+
*/
|
|
282
299
|
function getDefaultState() {
|
|
283
300
|
return {
|
|
284
301
|
context: void 0,
|