@tanstack/query-core 5.102.7 → 5.103.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/legacy/environmentManager.cjs +15 -1
- package/build/legacy/environmentManager.cjs.map +1 -1
- package/build/legacy/environmentManager.d.cts +15 -1
- package/build/legacy/environmentManager.d.cts.map +1 -1
- package/build/legacy/environmentManager.d.ts +15 -1
- package/build/legacy/environmentManager.d.ts.map +1 -1
- package/build/legacy/environmentManager.js +15 -1
- package/build/legacy/environmentManager.js.map +1 -1
- package/build/legacy/focusManager.cjs +57 -0
- package/build/legacy/focusManager.cjs.map +1 -1
- package/build/legacy/focusManager.d.cts +57 -0
- package/build/legacy/focusManager.d.cts.map +1 -1
- package/build/legacy/focusManager.d.ts +57 -0
- package/build/legacy/focusManager.d.ts.map +1 -1
- package/build/legacy/focusManager.js +57 -0
- package/build/legacy/focusManager.js.map +1 -1
- package/build/legacy/{hydration-Bjs0MSgg.d.ts → hydration-Cq7QYAzB.d.ts} +1424 -7
- package/build/legacy/hydration-Cq7QYAzB.d.ts.map +1 -0
- package/build/legacy/{hydration-DWGr3cFC.d.cts → hydration-DwR10Hi-.d.cts} +1424 -7
- package/build/legacy/hydration-DwR10Hi-.d.cts.map +1 -0
- package/build/legacy/hydration.cjs +57 -4
- package/build/legacy/hydration.cjs.map +1 -1
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/hydration.js +57 -4
- package/build/legacy/hydration.js.map +1 -1
- package/build/legacy/index.cjs.map +1 -1
- package/build/legacy/index.d.cts +5 -5
- package/build/legacy/index.d.ts +5 -5
- package/build/legacy/index.js.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
- package/build/legacy/infiniteQueryObserver.cjs +67 -0
- package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +68 -1
- package/build/legacy/infiniteQueryObserver.d.cts.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.ts +68 -1
- package/build/legacy/infiniteQueryObserver.d.ts.map +1 -1
- package/build/legacy/infiniteQueryObserver.js +67 -0
- package/build/legacy/infiniteQueryObserver.js.map +1 -1
- package/build/legacy/mutation.cjs +74 -0
- package/build/legacy/mutation.cjs.map +1 -1
- package/build/legacy/mutation.d.cts +1 -1
- package/build/legacy/mutation.d.ts +1 -1
- package/build/legacy/mutation.js +74 -0
- package/build/legacy/mutation.js.map +1 -1
- package/build/legacy/mutationCache.cjs +74 -0
- package/build/legacy/mutationCache.cjs.map +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationCache.js +74 -0
- package/build/legacy/mutationCache.js.map +1 -1
- package/build/legacy/mutationObserver.cjs +71 -0
- package/build/legacy/mutationObserver.cjs.map +1 -1
- package/build/legacy/mutationObserver.d.cts +1 -1
- package/build/legacy/mutationObserver.d.ts +1 -1
- package/build/legacy/mutationObserver.js +71 -0
- package/build/legacy/mutationObserver.js.map +1 -1
- package/build/legacy/notifyManager.cjs +45 -1
- package/build/legacy/notifyManager.cjs.map +1 -1
- package/build/legacy/notifyManager.d.cts +83 -2
- package/build/legacy/notifyManager.d.cts.map +1 -1
- package/build/legacy/notifyManager.d.ts +83 -2
- package/build/legacy/notifyManager.d.ts.map +1 -1
- package/build/legacy/notifyManager.js +45 -1
- package/build/legacy/notifyManager.js.map +1 -1
- package/build/legacy/onlineManager.cjs +47 -0
- package/build/legacy/onlineManager.cjs.map +1 -1
- package/build/legacy/onlineManager.d.cts +47 -0
- package/build/legacy/onlineManager.d.cts.map +1 -1
- package/build/legacy/onlineManager.d.ts +47 -0
- package/build/legacy/onlineManager.d.ts.map +1 -1
- package/build/legacy/onlineManager.js +47 -0
- package/build/legacy/onlineManager.js.map +1 -1
- package/build/legacy/queriesObserver.cjs +64 -0
- package/build/legacy/queriesObserver.cjs.map +1 -1
- package/build/legacy/queriesObserver.d.cts +73 -1
- package/build/legacy/queriesObserver.d.cts.map +1 -1
- package/build/legacy/queriesObserver.d.ts +73 -1
- package/build/legacy/queriesObserver.d.ts.map +1 -1
- package/build/legacy/queriesObserver.js +64 -0
- package/build/legacy/queriesObserver.js.map +1 -1
- package/build/legacy/query.cjs +141 -0
- package/build/legacy/query.cjs.map +1 -1
- package/build/legacy/query.d.cts +1 -1
- package/build/legacy/query.d.ts +1 -1
- package/build/legacy/query.js +141 -0
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryCache.cjs +120 -0
- package/build/legacy/queryCache.cjs.map +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryCache.js +120 -0
- package/build/legacy/queryCache.js.map +1 -1
- package/build/legacy/queryClient.cjs +363 -0
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryClient.js +363 -0
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryObserver.cjs +116 -2
- package/build/legacy/queryObserver.cjs.map +1 -1
- package/build/legacy/queryObserver.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/queryObserver.js +116 -2
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/legacy/retryer.cjs +18 -0
- package/build/legacy/retryer.cjs.map +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/retryer.js +18 -0
- package/build/legacy/retryer.js.map +1 -1
- package/build/legacy/streamedQuery.cjs +10 -1
- package/build/legacy/streamedQuery.cjs.map +1 -1
- package/build/legacy/streamedQuery.d.cts +26 -2
- package/build/legacy/streamedQuery.d.cts.map +1 -1
- package/build/legacy/streamedQuery.d.ts +26 -2
- package/build/legacy/streamedQuery.d.ts.map +1 -1
- package/build/legacy/streamedQuery.js +10 -1
- package/build/legacy/streamedQuery.js.map +1 -1
- package/build/legacy/timeoutManager.cjs +99 -0
- package/build/legacy/timeoutManager.cjs.map +1 -1
- package/build/legacy/timeoutManager.d.cts +105 -0
- package/build/legacy/timeoutManager.d.cts.map +1 -1
- package/build/legacy/timeoutManager.d.ts +105 -0
- package/build/legacy/timeoutManager.d.ts.map +1 -1
- package/build/legacy/timeoutManager.js +99 -0
- package/build/legacy/timeoutManager.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/utils.cjs +76 -0
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/legacy/utils.js +76 -0
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/environmentManager.cjs +15 -1
- package/build/modern/environmentManager.cjs.map +1 -1
- package/build/modern/environmentManager.d.cts +15 -1
- package/build/modern/environmentManager.d.cts.map +1 -1
- package/build/modern/environmentManager.d.ts +15 -1
- package/build/modern/environmentManager.d.ts.map +1 -1
- package/build/modern/environmentManager.js +15 -1
- package/build/modern/environmentManager.js.map +1 -1
- package/build/modern/focusManager.cjs +57 -0
- package/build/modern/focusManager.cjs.map +1 -1
- package/build/modern/focusManager.d.cts +57 -0
- package/build/modern/focusManager.d.cts.map +1 -1
- package/build/modern/focusManager.d.ts +57 -0
- package/build/modern/focusManager.d.ts.map +1 -1
- package/build/modern/focusManager.js +57 -0
- package/build/modern/focusManager.js.map +1 -1
- package/build/modern/{hydration-Bjs0MSgg.d.ts → hydration-Cq7QYAzB.d.ts} +1424 -7
- package/build/modern/hydration-Cq7QYAzB.d.ts.map +1 -0
- package/build/modern/{hydration-DWGr3cFC.d.cts → hydration-DwR10Hi-.d.cts} +1424 -7
- package/build/modern/hydration-DwR10Hi-.d.cts.map +1 -0
- package/build/modern/hydration.cjs +57 -4
- package/build/modern/hydration.cjs.map +1 -1
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/hydration.js +57 -4
- package/build/modern/hydration.js.map +1 -1
- package/build/modern/index.cjs.map +1 -1
- package/build/modern/index.d.cts +5 -5
- package/build/modern/index.d.ts +5 -5
- package/build/modern/index.js.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +1 -1
- package/build/modern/infiniteQueryObserver.cjs +67 -0
- package/build/modern/infiniteQueryObserver.cjs.map +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +68 -1
- package/build/modern/infiniteQueryObserver.d.cts.map +1 -1
- package/build/modern/infiniteQueryObserver.d.ts +68 -1
- package/build/modern/infiniteQueryObserver.d.ts.map +1 -1
- package/build/modern/infiniteQueryObserver.js +67 -0
- package/build/modern/infiniteQueryObserver.js.map +1 -1
- package/build/modern/mutation.cjs +74 -0
- package/build/modern/mutation.cjs.map +1 -1
- package/build/modern/mutation.d.cts +1 -1
- package/build/modern/mutation.d.ts +1 -1
- package/build/modern/mutation.js +74 -0
- package/build/modern/mutation.js.map +1 -1
- package/build/modern/mutationCache.cjs +74 -0
- package/build/modern/mutationCache.cjs.map +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationCache.js +74 -0
- package/build/modern/mutationCache.js.map +1 -1
- package/build/modern/mutationObserver.cjs +71 -0
- package/build/modern/mutationObserver.cjs.map +1 -1
- package/build/modern/mutationObserver.d.cts +1 -1
- package/build/modern/mutationObserver.d.ts +1 -1
- package/build/modern/mutationObserver.js +71 -0
- package/build/modern/mutationObserver.js.map +1 -1
- package/build/modern/notifyManager.cjs +45 -1
- package/build/modern/notifyManager.cjs.map +1 -1
- package/build/modern/notifyManager.d.cts +83 -2
- package/build/modern/notifyManager.d.cts.map +1 -1
- package/build/modern/notifyManager.d.ts +83 -2
- package/build/modern/notifyManager.d.ts.map +1 -1
- package/build/modern/notifyManager.js +45 -1
- package/build/modern/notifyManager.js.map +1 -1
- package/build/modern/onlineManager.cjs +47 -0
- package/build/modern/onlineManager.cjs.map +1 -1
- package/build/modern/onlineManager.d.cts +47 -0
- package/build/modern/onlineManager.d.cts.map +1 -1
- package/build/modern/onlineManager.d.ts +47 -0
- package/build/modern/onlineManager.d.ts.map +1 -1
- package/build/modern/onlineManager.js +47 -0
- package/build/modern/onlineManager.js.map +1 -1
- package/build/modern/queriesObserver.cjs +64 -0
- package/build/modern/queriesObserver.cjs.map +1 -1
- package/build/modern/queriesObserver.d.cts +73 -1
- package/build/modern/queriesObserver.d.cts.map +1 -1
- package/build/modern/queriesObserver.d.ts +73 -1
- package/build/modern/queriesObserver.d.ts.map +1 -1
- package/build/modern/queriesObserver.js +64 -0
- package/build/modern/queriesObserver.js.map +1 -1
- package/build/modern/query.cjs +141 -0
- package/build/modern/query.cjs.map +1 -1
- package/build/modern/query.d.cts +1 -1
- package/build/modern/query.d.ts +1 -1
- package/build/modern/query.js +141 -0
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryCache.cjs +120 -0
- package/build/modern/queryCache.cjs.map +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryCache.js +120 -0
- package/build/modern/queryCache.js.map +1 -1
- package/build/modern/queryClient.cjs +363 -0
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryClient.js +363 -0
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryObserver.cjs +116 -2
- package/build/modern/queryObserver.cjs.map +1 -1
- package/build/modern/queryObserver.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/queryObserver.js +116 -2
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/retryer.cjs +18 -0
- package/build/modern/retryer.cjs.map +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/retryer.js +18 -0
- package/build/modern/retryer.js.map +1 -1
- package/build/modern/streamedQuery.cjs +10 -1
- package/build/modern/streamedQuery.cjs.map +1 -1
- package/build/modern/streamedQuery.d.cts +26 -2
- package/build/modern/streamedQuery.d.cts.map +1 -1
- package/build/modern/streamedQuery.d.ts +26 -2
- package/build/modern/streamedQuery.d.ts.map +1 -1
- package/build/modern/streamedQuery.js +10 -1
- package/build/modern/streamedQuery.js.map +1 -1
- package/build/modern/timeoutManager.cjs +99 -0
- package/build/modern/timeoutManager.cjs.map +1 -1
- package/build/modern/timeoutManager.d.cts +105 -0
- package/build/modern/timeoutManager.d.cts.map +1 -1
- package/build/modern/timeoutManager.d.ts +105 -0
- package/build/modern/timeoutManager.d.ts.map +1 -1
- package/build/modern/timeoutManager.js +99 -0
- package/build/modern/timeoutManager.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/types.js.map +1 -1
- package/build/modern/utils.cjs +76 -0
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/build/modern/utils.js +76 -0
- package/build/modern/utils.js.map +1 -1
- package/package.json +9 -9
- package/src/environmentManager.ts +15 -1
- package/src/focusManager.ts +57 -0
- package/src/hydration.ts +82 -16
- package/src/index.ts +3 -0
- package/src/infiniteQueryObserver.ts +67 -0
- package/src/mutation.ts +108 -0
- package/src/mutationCache.ts +91 -0
- package/src/mutationObserver.ts +71 -0
- package/src/notifyManager.ts +46 -1
- package/src/onlineManager.ts +47 -0
- package/src/queriesObserver.ts +72 -0
- package/src/query.ts +193 -0
- package/src/queryCache.ts +134 -0
- package/src/queryClient.ts +369 -0
- package/src/queryObserver.ts +117 -4
- package/src/retryer.ts +18 -0
- package/src/streamedQuery.ts +25 -1
- package/src/timeoutManager.ts +105 -0
- package/src/types.ts +147 -5
- package/src/utils.ts +107 -0
- package/build/legacy/hydration-Bjs0MSgg.d.ts.map +0 -1
- package/build/legacy/hydration-DWGr3cFC.d.cts.map +0 -1
- package/build/modern/hydration-Bjs0MSgg.d.ts.map +0 -1
- package/build/modern/hydration-DWGr3cFC.d.cts.map +0 -1
|
@@ -2,6 +2,25 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_infiniteQueryBehavior = require("./infiniteQueryBehavior.cjs");
|
|
3
3
|
const require_queryObserver = require("./queryObserver.cjs");
|
|
4
4
|
//#region src/infiniteQueryObserver.ts
|
|
5
|
+
/**
|
|
6
|
+
* An `InfiniteQueryObserver` extends `QueryObserver` to observe and switch
|
|
7
|
+
* between infinite queries. It augments the base `QueryObserverResult` with
|
|
8
|
+
* infinite-query-specific fields and methods, such as `hasNextPage` and
|
|
9
|
+
* `fetchNextPage`, and is the primitive that framework adapters (e.g.
|
|
10
|
+
* `useInfiniteQuery`) build their hooks on top of.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const observer = new InfiniteQueryObserver(queryClient, {
|
|
15
|
+
* queryKey: ['projects'],
|
|
16
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
17
|
+
* initialPageParam: 0,
|
|
18
|
+
* getNextPageParam: (lastPage) => lastPage.nextCursor,
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* const unsubscribe = observer.subscribe((result) => console.log(result))
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
5
24
|
var InfiniteQueryObserver = class extends require_queryObserver.QueryObserver {
|
|
6
25
|
constructor(client, options) {
|
|
7
26
|
super(client, options);
|
|
@@ -11,20 +30,68 @@ var InfiniteQueryObserver = class extends require_queryObserver.QueryObserver {
|
|
|
11
30
|
this.fetchNextPage = this.fetchNextPage.bind(this);
|
|
12
31
|
this.fetchPreviousPage = this.fetchPreviousPage.bind(this);
|
|
13
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Updates the observer's options. Behaves the same as
|
|
35
|
+
* `QueryObserver.setOptions`, additionally marking the options as
|
|
36
|
+
* belonging to an infinite query before delegating to the base
|
|
37
|
+
* implementation.
|
|
38
|
+
*/
|
|
14
39
|
setOptions(options) {
|
|
15
40
|
options._type = "infinite";
|
|
16
41
|
super.setOptions(options);
|
|
17
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The infinite-query counterpart of {@link QueryObserver#getOptimisticResult}, marking the
|
|
45
|
+
* options as an infinite query before delegating to it. Called by framework adapters (e.g.
|
|
46
|
+
* `useInfiniteQuery`) ahead of subscribing, to compute the current `InfiniteQueryObserverResult`
|
|
47
|
+
* synchronously.
|
|
48
|
+
*/
|
|
18
49
|
getOptimisticResult(options) {
|
|
19
50
|
options._type = "infinite";
|
|
20
51
|
return super.getOptimisticResult(options);
|
|
21
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Fetches the next page of the infinite query and returns a promise that
|
|
55
|
+
* resolves with the resulting `InfiniteQueryObserverResult`. The page
|
|
56
|
+
* param used for the fetch is determined by `getNextPageParam`, which
|
|
57
|
+
* receives the current pages/page params and whose result also determines
|
|
58
|
+
* `hasNextPage`.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const { hasNextPage } = observer.getCurrentResult()
|
|
63
|
+
*
|
|
64
|
+
* if (hasNextPage) {
|
|
65
|
+
* await observer.fetchNextPage()
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
|
|
70
|
+
*/
|
|
22
71
|
fetchNextPage(options) {
|
|
23
72
|
return this.fetch({
|
|
24
73
|
...options,
|
|
25
74
|
meta: { fetchMore: { direction: "forward" } }
|
|
26
75
|
});
|
|
27
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Fetches the previous page of the infinite query and returns a promise
|
|
79
|
+
* that resolves with the resulting `InfiniteQueryObserverResult`. The page
|
|
80
|
+
* param used for the fetch is determined by `getPreviousPageParam`, which
|
|
81
|
+
* receives the current pages/page params and whose result also determines
|
|
82
|
+
* `hasPreviousPage`.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const { hasPreviousPage } = observer.getCurrentResult()
|
|
87
|
+
*
|
|
88
|
+
* if (hasPreviousPage) {
|
|
89
|
+
* await observer.fetchPreviousPage()
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @see {@link InfiniteQueryObserver#fetchNextPage}
|
|
94
|
+
*/
|
|
28
95
|
fetchPreviousPage(options) {
|
|
29
96
|
return this.fetch({
|
|
30
97
|
...options,
|
|
@@ -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\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 subscribe!: Subscribable<\n InfiniteQueryObserverListener<TData, TError>\n >['subscribe']\n\n // Type override\n 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 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 bindMethods(): void {\n super.bindMethods()\n this.fetchNextPage = this.fetchNextPage.bind(this)\n this.fetchPreviousPage = this.fetchPreviousPage.bind(this)\n }\n\n 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 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 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 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 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":"
|
|
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 *\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 subscribe!: Subscribable<\n InfiniteQueryObserverListener<TData, TError>\n >['subscribe']\n\n // Type override\n 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 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 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 */\n 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 */\n 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 *\n * @example\n * ```ts\n * const { hasNextPage } = observer.getCurrentResult()\n *\n * if (hasNextPage) {\n * await observer.fetchNextPage()\n * }\n * ```\n *\n * @see {@link InfiniteQueryObserver#fetchPreviousPage}\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 *\n * @example\n * ```ts\n * const { hasPreviousPage } = observer.getCurrentResult()\n *\n * if (hasPreviousPage) {\n * await observer.fetchPreviousPage()\n * }\n * ```\n *\n * @see {@link InfiniteQueryObserver#fetchNextPage}\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 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":";;;;;;;;;;;;;;;;;;;;;;;AAwCA,IAAa,wBAAb,cAMUA,sBAAAA,cAMR;CA8BA,YACE,QACA,SAOA;EACA,MAAM,QAAQ,OAAO;CACvB;CAEA,cAA8B;EAC5B,MAAM,YAAY;EAClB,KAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;EACjD,KAAK,oBAAoB,KAAK,kBAAkB,KAAK,IAAI;CAC3D;;;;;;;CAQA,WACE,SAOM;EACN,QAAQ,QAAQ;EAChB,MAAM,WAAW,OAAO;CAC1B;;;;;;;CAQA,oBACE,SAO4C;EAC5C,QAAQ,QAAQ;EAChB,OAAO,MAAM,oBAAoB,OAAO;CAI1C;;;;;;;;;;;;;;;;;;;CAoBA,cACE,SACqD;EACrD,OAAO,KAAK,MAAM;GAChB,GAAG;GACH,MAAM,EACJ,WAAW,EAAE,WAAW,UAAU,EACpC;EACF,CAAC;CACH;;;;;;;;;;;;;;;;;;;CAoBA,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,kBAAA,mBAAiB,MAAM,eAAA,QAAA,qBAAA,KAAA,MAAA,mBAAA,iBAAW,eAAA,QAAA,qBAAA,KAAA,IAAA,KAAA,IAAA,iBAAW;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,16 +1,83 @@
|
|
|
1
1
|
import { t as Subscribable } from "./subscribable-CbifVTKz.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-
|
|
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-DwR10Hi-.cjs";
|
|
3
3
|
//#region src/infiniteQueryObserver.d.ts
|
|
4
4
|
type InfiniteQueryObserverListener<TData, TError> = (result: InfiniteQueryObserverResult<TData, TError>) => void;
|
|
5
|
+
/**
|
|
6
|
+
* An `InfiniteQueryObserver` extends `QueryObserver` to observe and switch
|
|
7
|
+
* between infinite queries. It augments the base `QueryObserverResult` with
|
|
8
|
+
* infinite-query-specific fields and methods, such as `hasNextPage` and
|
|
9
|
+
* `fetchNextPage`, and is the primitive that framework adapters (e.g.
|
|
10
|
+
* `useInfiniteQuery`) build their hooks on top of.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const observer = new InfiniteQueryObserver(queryClient, {
|
|
15
|
+
* queryKey: ['projects'],
|
|
16
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
17
|
+
* initialPageParam: 0,
|
|
18
|
+
* getNextPageParam: (lastPage) => lastPage.nextCursor,
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* const unsubscribe = observer.subscribe((result) => console.log(result))
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
5
24
|
declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> extends QueryObserver<TQueryFnData, TError, TData, InfiniteData<TQueryFnData, TPageParam>, TQueryKey> {
|
|
6
25
|
subscribe: Subscribable<InfiniteQueryObserverListener<TData, TError>>['subscribe'];
|
|
7
26
|
getCurrentResult: ReplaceReturnType<QueryObserver<TQueryFnData, TError, TData, InfiniteData<TQueryFnData, TPageParam>, TQueryKey>['getCurrentResult'], InfiniteQueryObserverResult<TData, TError>>;
|
|
8
27
|
protected fetch: ReplaceReturnType<QueryObserver<TQueryFnData, TError, TData, InfiniteData<TQueryFnData, TPageParam>, TQueryKey>['fetch'], Promise<InfiniteQueryObserverResult<TData, TError>>>;
|
|
9
28
|
constructor(client: QueryClient, options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>);
|
|
10
29
|
protected bindMethods(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Updates the observer's options. Behaves the same as
|
|
32
|
+
* `QueryObserver.setOptions`, additionally marking the options as
|
|
33
|
+
* belonging to an infinite query before delegating to the base
|
|
34
|
+
* implementation.
|
|
35
|
+
*/
|
|
11
36
|
setOptions(options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): void;
|
|
37
|
+
/**
|
|
38
|
+
* The infinite-query counterpart of {@link QueryObserver#getOptimisticResult}, marking the
|
|
39
|
+
* options as an infinite query before delegating to it. Called by framework adapters (e.g.
|
|
40
|
+
* `useInfiniteQuery`) ahead of subscribing, to compute the current `InfiniteQueryObserverResult`
|
|
41
|
+
* synchronously.
|
|
42
|
+
*/
|
|
12
43
|
getOptimisticResult(options: DefaultedInfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): InfiniteQueryObserverResult<TData, TError>;
|
|
44
|
+
/**
|
|
45
|
+
* Fetches the next page of the infinite query and returns a promise that
|
|
46
|
+
* resolves with the resulting `InfiniteQueryObserverResult`. The page
|
|
47
|
+
* param used for the fetch is determined by `getNextPageParam`, which
|
|
48
|
+
* receives the current pages/page params and whose result also determines
|
|
49
|
+
* `hasNextPage`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const { hasNextPage } = observer.getCurrentResult()
|
|
54
|
+
*
|
|
55
|
+
* if (hasNextPage) {
|
|
56
|
+
* await observer.fetchNextPage()
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
|
|
61
|
+
*/
|
|
13
62
|
fetchNextPage(options?: FetchNextPageOptions): Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
63
|
+
/**
|
|
64
|
+
* Fetches the previous page of the infinite query and returns a promise
|
|
65
|
+
* that resolves with the resulting `InfiniteQueryObserverResult`. The page
|
|
66
|
+
* param used for the fetch is determined by `getPreviousPageParam`, which
|
|
67
|
+
* receives the current pages/page params and whose result also determines
|
|
68
|
+
* `hasPreviousPage`.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const { hasPreviousPage } = observer.getCurrentResult()
|
|
73
|
+
*
|
|
74
|
+
* if (hasPreviousPage) {
|
|
75
|
+
* await observer.fetchPreviousPage()
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @see {@link InfiniteQueryObserver#fetchNextPage}
|
|
80
|
+
*/
|
|
14
81
|
fetchPreviousPage(options?: FetchPreviousPageOptions): Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
15
82
|
protected createResult(query: Query<TQueryFnData, TError, InfiniteData<TQueryFnData, TPageParam>, TQueryKey>, options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): InfiniteQueryObserverResult<TData, TError>;
|
|
16
83
|
}
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;cAsBhC,sBACX,wBACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,8BACQ,cACR,cACA,QACA,OACA,aAAa,cAAc,aAC3B;EAGA,WAAY,aACV,8BAA8B,OAAO;EAIvC,kBAAmB,kBACjB,cACE,cACA,QACA,OACA,aAAa,cAAc,aAC3B,gCAEF,4BAA4B,OAAO;YAI3B,OAAQ,kBAChB,cACE,cACA,QACA,OACA,aAAa,cAAc,aAC3B,qBAEF,QAAQ,4BAA4B,OAAO;EAI3C,YAAA,QAAQ,aACR,SAAS,6BACP,cACA,QACA,OACA,WACA;YAMM;;;;;;;EAYV,WACE,SAAS,6BACP,cACA,QACA,OACA,WACA;;;;;;;EAaJ,oBACE,SAAS,sCACP,cACA,QACA,OACA,WACA,cAED,4BAA4B,OAAO;;;;;;;;;;;;;;;;;;;EA0BtC,cACE,UAAU,uBACT,QAAQ,4BAA4B,OAAO;;;;;;;;;;;;;;;;;;;EA2B9C,kBACE,UAAU,2BACT,QAAQ,4BAA4B,OAAO;YASpC,aACR,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,16 +1,83 @@
|
|
|
1
1
|
import { t as Subscribable } from "./subscribable-CbifVTKz.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-
|
|
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-Cq7QYAzB.js";
|
|
3
3
|
//#region src/infiniteQueryObserver.d.ts
|
|
4
4
|
type InfiniteQueryObserverListener<TData, TError> = (result: InfiniteQueryObserverResult<TData, TError>) => void;
|
|
5
|
+
/**
|
|
6
|
+
* An `InfiniteQueryObserver` extends `QueryObserver` to observe and switch
|
|
7
|
+
* between infinite queries. It augments the base `QueryObserverResult` with
|
|
8
|
+
* infinite-query-specific fields and methods, such as `hasNextPage` and
|
|
9
|
+
* `fetchNextPage`, and is the primitive that framework adapters (e.g.
|
|
10
|
+
* `useInfiniteQuery`) build their hooks on top of.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const observer = new InfiniteQueryObserver(queryClient, {
|
|
15
|
+
* queryKey: ['projects'],
|
|
16
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
17
|
+
* initialPageParam: 0,
|
|
18
|
+
* getNextPageParam: (lastPage) => lastPage.nextCursor,
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* const unsubscribe = observer.subscribe((result) => console.log(result))
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
5
24
|
declare class InfiniteQueryObserver<TQueryFnData = unknown, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> extends QueryObserver<TQueryFnData, TError, TData, InfiniteData<TQueryFnData, TPageParam>, TQueryKey> {
|
|
6
25
|
subscribe: Subscribable<InfiniteQueryObserverListener<TData, TError>>['subscribe'];
|
|
7
26
|
getCurrentResult: ReplaceReturnType<QueryObserver<TQueryFnData, TError, TData, InfiniteData<TQueryFnData, TPageParam>, TQueryKey>['getCurrentResult'], InfiniteQueryObserverResult<TData, TError>>;
|
|
8
27
|
protected fetch: ReplaceReturnType<QueryObserver<TQueryFnData, TError, TData, InfiniteData<TQueryFnData, TPageParam>, TQueryKey>['fetch'], Promise<InfiniteQueryObserverResult<TData, TError>>>;
|
|
9
28
|
constructor(client: QueryClient, options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>);
|
|
10
29
|
protected bindMethods(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Updates the observer's options. Behaves the same as
|
|
32
|
+
* `QueryObserver.setOptions`, additionally marking the options as
|
|
33
|
+
* belonging to an infinite query before delegating to the base
|
|
34
|
+
* implementation.
|
|
35
|
+
*/
|
|
11
36
|
setOptions(options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): void;
|
|
37
|
+
/**
|
|
38
|
+
* The infinite-query counterpart of {@link QueryObserver#getOptimisticResult}, marking the
|
|
39
|
+
* options as an infinite query before delegating to it. Called by framework adapters (e.g.
|
|
40
|
+
* `useInfiniteQuery`) ahead of subscribing, to compute the current `InfiniteQueryObserverResult`
|
|
41
|
+
* synchronously.
|
|
42
|
+
*/
|
|
12
43
|
getOptimisticResult(options: DefaultedInfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): InfiniteQueryObserverResult<TData, TError>;
|
|
44
|
+
/**
|
|
45
|
+
* Fetches the next page of the infinite query and returns a promise that
|
|
46
|
+
* resolves with the resulting `InfiniteQueryObserverResult`. The page
|
|
47
|
+
* param used for the fetch is determined by `getNextPageParam`, which
|
|
48
|
+
* receives the current pages/page params and whose result also determines
|
|
49
|
+
* `hasNextPage`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const { hasNextPage } = observer.getCurrentResult()
|
|
54
|
+
*
|
|
55
|
+
* if (hasNextPage) {
|
|
56
|
+
* await observer.fetchNextPage()
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
|
|
61
|
+
*/
|
|
13
62
|
fetchNextPage(options?: FetchNextPageOptions): Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
63
|
+
/**
|
|
64
|
+
* Fetches the previous page of the infinite query and returns a promise
|
|
65
|
+
* that resolves with the resulting `InfiniteQueryObserverResult`. The page
|
|
66
|
+
* param used for the fetch is determined by `getPreviousPageParam`, which
|
|
67
|
+
* receives the current pages/page params and whose result also determines
|
|
68
|
+
* `hasPreviousPage`.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const { hasPreviousPage } = observer.getCurrentResult()
|
|
73
|
+
*
|
|
74
|
+
* if (hasPreviousPage) {
|
|
75
|
+
* await observer.fetchPreviousPage()
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @see {@link InfiniteQueryObserver#fetchNextPage}
|
|
80
|
+
*/
|
|
14
81
|
fetchPreviousPage(options?: FetchPreviousPageOptions): Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
15
82
|
protected createResult(query: Query<TQueryFnData, TError, InfiniteData<TQueryFnData, TPageParam>, TQueryKey>, options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): InfiniteQueryObserverResult<TData, TError>;
|
|
16
83
|
}
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;cAsBhC,sBACX,wBACA,SAAS,cACT,QAAQ,aAAa,eACrB,kBAAkB,WAAW,UAC7B,8BACQ,cACR,cACA,QACA,OACA,aAAa,cAAc,aAC3B;EAGA,WAAY,aACV,8BAA8B,OAAO;EAIvC,kBAAmB,kBACjB,cACE,cACA,QACA,OACA,aAAa,cAAc,aAC3B,gCAEF,4BAA4B,OAAO;YAI3B,OAAQ,kBAChB,cACE,cACA,QACA,OACA,aAAa,cAAc,aAC3B,qBAEF,QAAQ,4BAA4B,OAAO;EAI3C,YAAA,QAAQ,aACR,SAAS,6BACP,cACA,QACA,OACA,WACA;YAMM;;;;;;;EAYV,WACE,SAAS,6BACP,cACA,QACA,OACA,WACA;;;;;;;EAaJ,oBACE,SAAS,sCACP,cACA,QACA,OACA,WACA,cAED,4BAA4B,OAAO;;;;;;;;;;;;;;;;;;;EA0BtC,cACE,UAAU,uBACT,QAAQ,4BAA4B,OAAO;;;;;;;;;;;;;;;;;;;EA2B9C,kBACE,UAAU,2BACT,QAAQ,4BAA4B,OAAO;YASpC,aACR,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,6 +1,25 @@
|
|
|
1
1
|
import { hasNextPage, hasPreviousPage } from "./infiniteQueryBehavior.js";
|
|
2
2
|
import { QueryObserver } from "./queryObserver.js";
|
|
3
3
|
//#region src/infiniteQueryObserver.ts
|
|
4
|
+
/**
|
|
5
|
+
* An `InfiniteQueryObserver` extends `QueryObserver` to observe and switch
|
|
6
|
+
* between infinite queries. It augments the base `QueryObserverResult` with
|
|
7
|
+
* infinite-query-specific fields and methods, such as `hasNextPage` and
|
|
8
|
+
* `fetchNextPage`, and is the primitive that framework adapters (e.g.
|
|
9
|
+
* `useInfiniteQuery`) build their hooks on top of.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const observer = new InfiniteQueryObserver(queryClient, {
|
|
14
|
+
* queryKey: ['projects'],
|
|
15
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
16
|
+
* initialPageParam: 0,
|
|
17
|
+
* getNextPageParam: (lastPage) => lastPage.nextCursor,
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* const unsubscribe = observer.subscribe((result) => console.log(result))
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
4
23
|
var InfiniteQueryObserver = class extends QueryObserver {
|
|
5
24
|
constructor(client, options) {
|
|
6
25
|
super(client, options);
|
|
@@ -10,20 +29,68 @@ var InfiniteQueryObserver = class extends QueryObserver {
|
|
|
10
29
|
this.fetchNextPage = this.fetchNextPage.bind(this);
|
|
11
30
|
this.fetchPreviousPage = this.fetchPreviousPage.bind(this);
|
|
12
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Updates the observer's options. Behaves the same as
|
|
34
|
+
* `QueryObserver.setOptions`, additionally marking the options as
|
|
35
|
+
* belonging to an infinite query before delegating to the base
|
|
36
|
+
* implementation.
|
|
37
|
+
*/
|
|
13
38
|
setOptions(options) {
|
|
14
39
|
options._type = "infinite";
|
|
15
40
|
super.setOptions(options);
|
|
16
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The infinite-query counterpart of {@link QueryObserver#getOptimisticResult}, marking the
|
|
44
|
+
* options as an infinite query before delegating to it. Called by framework adapters (e.g.
|
|
45
|
+
* `useInfiniteQuery`) ahead of subscribing, to compute the current `InfiniteQueryObserverResult`
|
|
46
|
+
* synchronously.
|
|
47
|
+
*/
|
|
17
48
|
getOptimisticResult(options) {
|
|
18
49
|
options._type = "infinite";
|
|
19
50
|
return super.getOptimisticResult(options);
|
|
20
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Fetches the next page of the infinite query and returns a promise that
|
|
54
|
+
* resolves with the resulting `InfiniteQueryObserverResult`. The page
|
|
55
|
+
* param used for the fetch is determined by `getNextPageParam`, which
|
|
56
|
+
* receives the current pages/page params and whose result also determines
|
|
57
|
+
* `hasNextPage`.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const { hasNextPage } = observer.getCurrentResult()
|
|
62
|
+
*
|
|
63
|
+
* if (hasNextPage) {
|
|
64
|
+
* await observer.fetchNextPage()
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @see {@link InfiniteQueryObserver#fetchPreviousPage}
|
|
69
|
+
*/
|
|
21
70
|
fetchNextPage(options) {
|
|
22
71
|
return this.fetch({
|
|
23
72
|
...options,
|
|
24
73
|
meta: { fetchMore: { direction: "forward" } }
|
|
25
74
|
});
|
|
26
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Fetches the previous page of the infinite query and returns a promise
|
|
78
|
+
* that resolves with the resulting `InfiniteQueryObserverResult`. The page
|
|
79
|
+
* param used for the fetch is determined by `getPreviousPageParam`, which
|
|
80
|
+
* receives the current pages/page params and whose result also determines
|
|
81
|
+
* `hasPreviousPage`.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const { hasPreviousPage } = observer.getCurrentResult()
|
|
86
|
+
*
|
|
87
|
+
* if (hasPreviousPage) {
|
|
88
|
+
* await observer.fetchPreviousPage()
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @see {@link InfiniteQueryObserver#fetchNextPage}
|
|
93
|
+
*/
|
|
27
94
|
fetchPreviousPage(options) {
|
|
28
95
|
return this.fetch({
|
|
29
96
|
...options,
|
|
@@ -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\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 subscribe!: Subscribable<\n InfiniteQueryObserverListener<TData, TError>\n >['subscribe']\n\n // Type override\n 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 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 bindMethods(): void {\n super.bindMethods()\n this.fetchNextPage = this.fetchNextPage.bind(this)\n this.fetchPreviousPage = this.fetchPreviousPage.bind(this)\n }\n\n 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 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 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 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 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":"
|
|
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 *\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 subscribe!: Subscribable<\n InfiniteQueryObserverListener<TData, TError>\n >['subscribe']\n\n // Type override\n 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 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 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 */\n 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 */\n 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 *\n * @example\n * ```ts\n * const { hasNextPage } = observer.getCurrentResult()\n *\n * if (hasNextPage) {\n * await observer.fetchNextPage()\n * }\n * ```\n *\n * @see {@link InfiniteQueryObserver#fetchPreviousPage}\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 *\n * @example\n * ```ts\n * const { hasPreviousPage } = observer.getCurrentResult()\n *\n * if (hasPreviousPage) {\n * await observer.fetchPreviousPage()\n * }\n * ```\n *\n * @see {@link InfiniteQueryObserver#fetchNextPage}\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 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":";;;;;;;;;;;;;;;;;;;;;;AAwCA,IAAa,wBAAb,cAMU,cAMR;CA8BA,YACE,QACA,SAOA;EACA,MAAM,QAAQ,OAAO;CACvB;CAEA,cAA8B;EAC5B,MAAM,YAAY;EAClB,KAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;EACjD,KAAK,oBAAoB,KAAK,kBAAkB,KAAK,IAAI;CAC3D;;;;;;;CAQA,WACE,SAOM;EACN,QAAQ,QAAQ;EAChB,MAAM,WAAW,OAAO;CAC1B;;;;;;;CAQA,oBACE,SAO4C;EAC5C,QAAQ,QAAQ;EAChB,OAAO,MAAM,oBAAoB,OAAO;CAI1C;;;;;;;;;;;;;;;;;;;CAoBA,cACE,SACqD;EACrD,OAAO,KAAK,MAAM;GAChB,GAAG;GACH,MAAM,EACJ,WAAW,EAAE,WAAW,UAAU,EACpC;EACF,CAAC;CACH;;;;;;;;;;;;;;;;;;;CAoBA,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,kBAAA,mBAAiB,MAAM,eAAA,QAAA,qBAAA,KAAA,MAAA,mBAAA,iBAAW,eAAA,QAAA,qBAAA,KAAA,IAAA,KAAA,IAAA,iBAAW;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"}
|
|
@@ -10,6 +10,23 @@ var _observers = /* @__PURE__ */ new WeakMap();
|
|
|
10
10
|
var _mutationCache = /* @__PURE__ */ new WeakMap();
|
|
11
11
|
var _retryer = /* @__PURE__ */ new WeakMap();
|
|
12
12
|
var _Mutation_brand = /* @__PURE__ */ new WeakSet();
|
|
13
|
+
/**
|
|
14
|
+
* Represents a single mutation attempt. A `Mutation` holds the mutation's
|
|
15
|
+
* options, state (data/error/status), and the `MutationObserver`s currently
|
|
16
|
+
* subscribed to it.
|
|
17
|
+
*
|
|
18
|
+
* Instances are created and managed internally by `MutationCache`; application
|
|
19
|
+
* code typically interacts with mutations indirectly through `QueryClient` or
|
|
20
|
+
* a framework hook like `useMutation`. Direct access to a `Mutation` instance
|
|
21
|
+
* is possible via `mutationCache.find()`/`getAll()` for inspecting cache state.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const mutationCache = queryClient.getMutationCache()
|
|
26
|
+
*
|
|
27
|
+
* const mutation = mutationCache.find({ mutationKey: ['addPost'] })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
13
30
|
var Mutation = class extends require_removable.Removable {
|
|
14
31
|
constructor(config) {
|
|
15
32
|
super();
|
|
@@ -26,13 +43,18 @@ var Mutation = class extends require_removable.Removable {
|
|
|
26
43
|
this.setOptions(config.options);
|
|
27
44
|
this.scheduleGc();
|
|
28
45
|
}
|
|
46
|
+
/** @internal */
|
|
29
47
|
setOptions(options) {
|
|
30
48
|
this.options = options;
|
|
31
49
|
this.updateGcTime(this.options.gcTime);
|
|
32
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* The `meta` object passed in the mutation's options, if any.
|
|
53
|
+
*/
|
|
33
54
|
get meta() {
|
|
34
55
|
return this.options.meta;
|
|
35
56
|
}
|
|
57
|
+
/** @internal */
|
|
36
58
|
addObserver(observer) {
|
|
37
59
|
if (!require_classPrivateFieldSet2._classPrivateFieldGet2(_observers, this).includes(observer)) {
|
|
38
60
|
require_classPrivateFieldSet2._classPrivateFieldGet2(_observers, this).push(observer);
|
|
@@ -44,6 +66,7 @@ var Mutation = class extends require_removable.Removable {
|
|
|
44
66
|
});
|
|
45
67
|
}
|
|
46
68
|
}
|
|
69
|
+
/** @internal */
|
|
47
70
|
removeObserver(observer) {
|
|
48
71
|
require_classPrivateFieldSet2._classPrivateFieldSet2(_observers, this, require_classPrivateFieldSet2._classPrivateFieldGet2(_observers, this).filter((x) => x !== observer));
|
|
49
72
|
this.scheduleGc();
|
|
@@ -59,10 +82,61 @@ var Mutation = class extends require_removable.Removable {
|
|
|
59
82
|
else require_classPrivateFieldSet2._classPrivateFieldGet2(_mutationCache, this).remove(this);
|
|
60
83
|
}
|
|
61
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Resumes a mutation that is currently paused or was restored from a
|
|
87
|
+
* dehydrated, still-`pending` state.
|
|
88
|
+
*
|
|
89
|
+
* - If this mutation has an active retryer (it paused mid-attempt, e.g. due
|
|
90
|
+
* to the network mode or scope-based queuing), its retryer is resumed.
|
|
91
|
+
* - Otherwise, if the mutation's status is still `pending` (e.g. it was
|
|
92
|
+
* dehydrated while an attempt was in flight and never got a retryer in
|
|
93
|
+
* this instance), `execute` is called again with the last known variables.
|
|
94
|
+
* - Otherwise the mutation has already settled and this resolves immediately
|
|
95
|
+
* without running anything again.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* // typically driven by reconnect handling, e.g. queryClient.resumePausedMutations()
|
|
100
|
+
* const mutation = mutationCache.find({ mutationKey: ['addPost'] })
|
|
101
|
+
* await mutation?.continue()
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @see {@link Mutation#execute}
|
|
105
|
+
*/
|
|
62
106
|
continue() {
|
|
63
107
|
var _classPrivateFieldGet2$1;
|
|
64
108
|
return ((_classPrivateFieldGet2$1 = require_classPrivateFieldSet2._classPrivateFieldGet2(_retryer, this)) === null || _classPrivateFieldGet2$1 === void 0 ? void 0 : _classPrivateFieldGet2$1.continue()) ?? (this.state.status === "pending" ? this.execute(this.state.variables) : Promise.resolve());
|
|
65
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Runs the mutation function for the given variables through a retryer, and
|
|
112
|
+
* drives the mutation's state and lifecycle callbacks through to settlement.
|
|
113
|
+
*
|
|
114
|
+
* If this mutation's state is already `pending` when `execute` is called
|
|
115
|
+
* (i.e. it was restored, still in-flight, from a dehydrated state), the
|
|
116
|
+
* `onMutate` step is skipped and a `continue` action is dispatched to
|
|
117
|
+
* unpause it; otherwise a `pending` action is dispatched first, then the
|
|
118
|
+
* mutation cache's `onMutate` and the mutation's own `onMutate` option are
|
|
119
|
+
* awaited in that order, and the resulting context is stored.
|
|
120
|
+
*
|
|
121
|
+
* The mutation function is then run (subject to `retry`/`retryDelay`/
|
|
122
|
+
* `networkMode`, and to the mutation cache's scope-based serialization).
|
|
123
|
+
* On success, the cache's `onSuccess`/`onSettled` callbacks run before the
|
|
124
|
+
* mutation's own `onSuccess`/`onSettled` options, a `success` action is
|
|
125
|
+
* dispatched, and the resolved data is returned. On failure, the same
|
|
126
|
+
* cache-then-option ordering is used for `onError`/`onSettled`, but each of
|
|
127
|
+
* those four callbacks is individually caught so that a throwing callback
|
|
128
|
+
* cannot mask the original error; an `error` action is then dispatched and
|
|
129
|
+
* the original error is re-thrown.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* // Called internally by `MutationObserver.mutate` and `Mutation.continue` —
|
|
134
|
+
* // applications normally trigger mutations through those, not this method.
|
|
135
|
+
* const data = await mutation.execute(variables)
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @see {@link Mutation#continue}
|
|
139
|
+
*/
|
|
66
140
|
async execute(variables) {
|
|
67
141
|
const onContinue = () => {
|
|
68
142
|
require_classPrivateFieldSet2._assertClassBrand(_Mutation_brand, this, _dispatch).call(this, { type: "continue" });
|