@scrippsproduct/networks-ui-library 2.0.8 → 2.0.9
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/dist/components/ActionButton/ActionButton.test.js +3 -3
- package/dist/components/AdBlock/AdBlock.test.js +2 -2
- package/dist/components/AdjustableTwoColumnGrid/AdjustableTwoColumnGrid.test.js +2 -2
- package/dist/components/AirDateFormatter/AirDateFormatter.test.js +2 -2
- package/dist/components/AnchorTag/AnchorTag.test.js +3 -3
- package/dist/components/BCVideoPlayer/BCVideoPlayer.test.js +2 -2
- package/dist/components/BasicGridModule/BasicGridModule.test.js +2 -2
- package/dist/components/Button/Button.test.js +3 -3
- package/dist/components/ButtonAnchor/ButtonAnchor.test.js +3 -3
- package/dist/components/Carousel/Carousel.suspense-regression.test.js +2 -2
- package/dist/components/Carousel/Carousel.test.js +2 -2
- package/dist/components/Carousel/navigations/Pagination.test.js +2 -2
- package/dist/components/CarouselSlide/CarouselSlide.test.js +2 -2
- package/dist/components/CarouselSlide/slide-layouts/TwoColumn/TwoColumnSlide.js +1 -1
- package/dist/components/CastInfoLayout/CastInfoLayout.test.js +2 -2
- package/dist/components/ChannelSearch/ChannelSearch.test.js +2 -2
- package/dist/components/ChoicesItem/ChoicesItem.test.js +2 -2
- package/dist/components/Concat/Concat.js +1 -1
- package/dist/components/Concat/Concat.test.js +2 -2
- package/dist/components/CtaBlock/CtaBlock.js +1 -1
- package/dist/components/CtaBlock/CtaBlock.test.js +3 -3
- package/dist/components/CustomSelect/CustomSelect.test.js +3 -3
- package/dist/components/DateNavigation/DateNavigation.test.js +3 -3
- package/dist/components/DatePicker/DatePicker.js +2309 -2324
- package/dist/components/DeviceAndPlatformLists/DeviceAndPlatformLists.test.js +2 -2
- package/dist/components/DrawerNavigation/DrawerNavigation.test.js +3 -3
- package/dist/components/EqualSizeFlexRow/EqualSizeFlexRow.test.js +2 -2
- package/dist/components/EqualSizeGrid/EqualSizeGrid.test.js +2 -2
- package/dist/components/ErrorHandler/ErrorHandler.js +1 -1
- package/dist/components/ErrorHandler/ErrorHandler.test.js +2 -2
- package/dist/components/FeaturedList/FeaturedList.test.js +3 -3
- package/dist/components/Figure/Figure.js +1 -1
- package/dist/components/Figure/Figure.test.js +2 -2
- package/dist/components/FindUs/FindUs.test.js +2 -2
- package/dist/components/FooterNavigation/FooterNavigation.test.js +2 -2
- package/dist/components/GenericList/GenericList.js +1 -1
- package/dist/components/GenericList/GenericList.test.js +2 -2
- package/dist/components/GetAirdateWrapper/GetAirdateWrapper.test.js +2 -2
- package/dist/components/GradientButton/GradientButton.test.js +2 -2
- package/dist/components/GridList/GridList.test.js +1 -1
- package/dist/components/ImageCard/ImageCard.test.js +2 -2
- package/dist/components/ImageCard/ImageCardCore.js +1 -1
- package/dist/components/ImageCard/ImageCardCore.test.js +2 -2
- package/dist/components/ImageReplacementAnchor/ImageReplacementAnchor.test.js +1 -1
- package/dist/components/InlineNavigation/InlineNavigation.test.js +1 -1
- package/dist/components/Input/Input.test.js +2 -2
- package/dist/components/InstructionsList/InstructionsList.js +1 -1
- package/dist/components/InstructionsList/InstructionsList.test.js +1 -1
- package/dist/components/LogoListItem/LogoListItem.test.js +1 -1
- package/dist/components/LogoNavigation/LogoNavigation.test.js +1 -1
- package/dist/components/ModalContainer/ModalContainer.js +1 -1
- package/dist/components/NavList/NavList.test.js +2 -2
- package/dist/components/Overlay/Overlay.js +1 -1
- package/dist/components/Overlay/Overlay.test.js +1 -1
- package/dist/components/PageHero/PageHero.test.js +1 -1
- package/dist/components/PageHero/page-hero-layouts/IONShow/IONShowHero.js +1 -1
- package/dist/components/ProgramAirdate/ProgramAirdate.js +1 -1
- package/dist/components/ProgramAirdate/ProgramAirdate.test.js +1 -1
- package/dist/components/PromotionsRowBlock/PromotionsRowBlock.test.js +2 -2
- package/dist/components/PromotionsRowModule/PromotionsRowModule.js +1 -1
- package/dist/components/PromotionsRowModule/PromotionsRowModule.test.js +2 -2
- package/dist/components/RescanInstructions/RescanInstructions.test.js +1 -1
- package/dist/components/ResponsiveImage/ResponsiveImage.test.js +2 -2
- package/dist/components/ResultsTable/ResultsTable.test.js +1 -1
- package/dist/components/ResultsTableBody/ResultsTableBody.test.js +1 -1
- package/dist/components/ResultsTableHeader/ResultsTableHeader.test.js +1 -1
- package/dist/components/ScheduleLayout/ScheduleContext.js +1893 -1123
- package/dist/components/SectionedContent/SectionedContent.js +1 -1
- package/dist/components/SectionedContent/SectionedContent.test.js +2 -2
- package/dist/components/Select/Select.test.js +2 -2
- package/dist/components/ShowAboutContent/ShowAboutContent.js +1 -1
- package/dist/components/ShowAboutContent/ShowAboutContent.test.js +2 -2
- package/dist/components/ShowAboutLayout/ShowAboutLayout.test.js +2 -2
- package/dist/components/StringList/StringList.js +1 -1
- package/dist/components/StringList/StringList.test.js +1 -1
- package/dist/components/TabContent/TabContent.js +1 -1
- package/dist/components/TabContent/TabContent.test.js +1 -1
- package/dist/components/TabNavigation/TabNavigation.test.js +1 -1
- package/dist/components/TabbedContent/TabbedContent.test.js +1 -1
- package/dist/components/UpcomingList/UpcomingList.test.js +2 -2
- package/dist/index-BCErBUQT.mjs +3 -0
- package/dist/{index-sxnwPHiC.mjs → index-CHzqLQze.mjs} +181 -166
- package/dist/index-DnEp_Vsr.mjs +3085 -0
- package/dist/{index-5kXULIVv.mjs → index-DrfkaNHX.mjs} +16 -16
- package/dist/{magic-string.es-uPKorP4O.mjs → magic-string.es-DDAFx1CP.mjs} +93 -93
- package/dist/matchers-35e4d3bd-CfhTZpyY.mjs +2572 -0
- package/dist/react.esm-CX7MGXBg.mjs +52738 -0
- package/dist/src/icons/Facebook.d.ts +2 -1
- package/dist/src/icons/Tiktok.d.ts +2 -1
- package/dist/src/icons/Twitter.d.ts +2 -1
- package/dist/src/utils/analytics.d.ts +24 -5
- package/dist/test/setupTests.js +2 -2
- package/dist/utils/analytics.js +247 -446
- package/package.json +3 -3
- package/dist/index-B03xsUba.mjs +0 -3
- package/dist/index-C-uizG4-.mjs +0 -3098
- package/dist/matchers-35e4d3bd-BckKR3wh.mjs +0 -2404
- package/dist/react.esm-CUNRDkfQ.mjs +0 -49632
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
1
|
+
var le = (e) => {
|
|
2
2
|
throw TypeError(e);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var i = (e, t, s) => (
|
|
6
|
-
var
|
|
4
|
+
var Bt = (e, t, s) => t.has(e) || le("Cannot " + s);
|
|
5
|
+
var i = (e, t, s) => (Bt(e, t, "read from private field"), s ? s.call(e) : t.get(e)), c = (e, t, s) => t.has(e) ? le("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, s), o = (e, t, s, r) => (Bt(e, t, "write to private field"), r ? r.call(e, s) : t.set(e, s), s), m = (e, t, s) => (Bt(e, t, "access private method"), s);
|
|
6
|
+
var jt = (e, t, s, r) => ({
|
|
7
7
|
set _(n) {
|
|
8
8
|
o(e, t, n, s);
|
|
9
9
|
},
|
|
@@ -11,321 +11,406 @@ var Gt = (e, t, s, r) => ({
|
|
|
11
11
|
return i(e, t, r);
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
-
import { jsx as
|
|
15
|
-
import * as
|
|
16
|
-
import { createContext as
|
|
17
|
-
import { f as
|
|
18
|
-
import { l as
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return this.listeners.size > 0;
|
|
30
|
-
}
|
|
31
|
-
onSubscribe() {
|
|
32
|
-
}
|
|
33
|
-
onUnsubscribe() {
|
|
34
|
-
}
|
|
35
|
-
}, ht, tt, bt, Te, ss = (Te = class extends kt {
|
|
36
|
-
constructor() {
|
|
37
|
-
super();
|
|
38
|
-
c(this, ht);
|
|
39
|
-
c(this, tt);
|
|
40
|
-
c(this, bt);
|
|
41
|
-
o(this, bt, (t) => {
|
|
42
|
-
if (typeof window < "u" && window.addEventListener) {
|
|
43
|
-
const s = () => t();
|
|
44
|
-
return window.addEventListener("visibilitychange", s, !1), () => {
|
|
45
|
-
window.removeEventListener("visibilitychange", s);
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
onSubscribe() {
|
|
51
|
-
i(this, tt) || this.setEventListener(i(this, bt));
|
|
52
|
-
}
|
|
53
|
-
onUnsubscribe() {
|
|
54
|
-
var t;
|
|
55
|
-
this.hasListeners() || ((t = i(this, tt)) == null || t.call(this), o(this, tt, void 0));
|
|
56
|
-
}
|
|
57
|
-
setEventListener(t) {
|
|
58
|
-
var s;
|
|
59
|
-
o(this, bt, t), (s = i(this, tt)) == null || s.call(this), o(this, tt, t((r) => {
|
|
60
|
-
typeof r == "boolean" ? this.setFocused(r) : this.onFocus();
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
63
|
-
setFocused(t) {
|
|
64
|
-
i(this, ht) !== t && (o(this, ht, t), this.onFocus());
|
|
65
|
-
}
|
|
66
|
-
onFocus() {
|
|
67
|
-
const t = this.isFocused();
|
|
68
|
-
this.listeners.forEach((s) => {
|
|
69
|
-
s(t);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
isFocused() {
|
|
73
|
-
var t;
|
|
74
|
-
return typeof i(this, ht) == "boolean" ? i(this, ht) : ((t = globalThis.document) == null ? void 0 : t.visibilityState) !== "hidden";
|
|
75
|
-
}
|
|
76
|
-
}, ht = new WeakMap(), tt = new WeakMap(), bt = new WeakMap(), Te), fe = new ss(), rs = {
|
|
77
|
-
// We need the wrapper function syntax below instead of direct references to
|
|
78
|
-
// global setTimeout etc.
|
|
79
|
-
//
|
|
80
|
-
// BAD: `setTimeout: setTimeout`
|
|
81
|
-
// GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`
|
|
82
|
-
//
|
|
83
|
-
// If we use direct references here, then anything that wants to spy on or
|
|
84
|
-
// replace the global setTimeout (like tests) won't work since we'll already
|
|
85
|
-
// have a hard reference to the original implementation at the time when this
|
|
86
|
-
// file was imported.
|
|
14
|
+
import { jsx as Lt } from "react/jsx-runtime";
|
|
15
|
+
import * as L from "react";
|
|
16
|
+
import { createContext as Be, useRef as Ae, useState as de, useCallback as Ge, useEffect as fe, useMemo as Ve } from "react";
|
|
17
|
+
import { f as Gt } from "../../format-YhWt2D8M.mjs";
|
|
18
|
+
import { l as kt } from "../../logger-C0N7U0YY.mjs";
|
|
19
|
+
const Ie = L.createContext(void 0), $e = (e) => {
|
|
20
|
+
const t = L.useContext(Ie);
|
|
21
|
+
if (!t) throw new Error("No QueryClient set, use QueryClientProvider to set one");
|
|
22
|
+
return t;
|
|
23
|
+
}, ze = ({ client: e, children: t }) => (L.useEffect(() => (e.mount(), () => {
|
|
24
|
+
e.unmount();
|
|
25
|
+
}), [e]), /* @__PURE__ */ Lt(Ie.Provider, {
|
|
26
|
+
value: e,
|
|
27
|
+
children: t
|
|
28
|
+
})), We = {
|
|
87
29
|
setTimeout: (e, t) => setTimeout(e, t),
|
|
88
30
|
clearTimeout: (e) => clearTimeout(e),
|
|
89
31
|
setInterval: (e, t) => setInterval(e, t),
|
|
90
32
|
clearInterval: (e) => clearInterval(e)
|
|
91
|
-
}
|
|
33
|
+
};
|
|
34
|
+
var G, at, Oe, Je = (Oe = class {
|
|
92
35
|
constructor() {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
// would need to support the default provider's concrete timer ID, which is
|
|
96
|
-
// infeasible across environments.
|
|
97
|
-
//
|
|
98
|
-
// We settle for type safety for the TimeoutProvider type, and accept that
|
|
99
|
-
// this class is unsafe internally to allow for extension.
|
|
100
|
-
c(this, G, rs);
|
|
101
|
-
c(this, ct, !1);
|
|
36
|
+
c(this, G, We);
|
|
37
|
+
c(this, at, !1);
|
|
102
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* `setTimeoutProvider` can be used to set a custom implementation of the
|
|
41
|
+
* `setTimeout`, `clearTimeout`, `setInterval`, `clearInterval` functions,
|
|
42
|
+
* called a `TimeoutProvider`.
|
|
43
|
+
*
|
|
44
|
+
* This may be useful if you notice event loop performance issues with
|
|
45
|
+
* thousands of queries. A custom TimeoutProvider could also support timer
|
|
46
|
+
* delays longer than the global `setTimeout` maximum delay value of about
|
|
47
|
+
* 24 days.
|
|
48
|
+
*
|
|
49
|
+
* It is important to call `setTimeoutProvider` before creating a
|
|
50
|
+
* QueryClient or queries, so that the same provider is used consistently
|
|
51
|
+
* for all timers in the application, since different TimeoutProviders
|
|
52
|
+
* cannot cancel each others' timers.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { timeoutManager, QueryClient } from '@tanstack/query-core'
|
|
57
|
+
* import { CustomTimeoutProvider } from './CustomTimeoutProvider'
|
|
58
|
+
*
|
|
59
|
+
* timeoutManager.setTimeoutProvider(new CustomTimeoutProvider())
|
|
60
|
+
*
|
|
61
|
+
* export const queryClient = new QueryClient()
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
103
64
|
setTimeoutProvider(e) {
|
|
104
|
-
process.env.NODE_ENV !== "production" && i(this,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
), o(this, G, e), process.env.NODE_ENV !== "production" && o(this,
|
|
65
|
+
process.env.NODE_ENV !== "production" && i(this, at) && e !== i(this, G) && console.error("[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.", {
|
|
66
|
+
previous: i(this, G),
|
|
67
|
+
provider: e
|
|
68
|
+
}), o(this, G, e), process.env.NODE_ENV !== "production" && o(this, at, !1);
|
|
108
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* `setTimeout` schedules a callback to run after approximately `delay`
|
|
72
|
+
* milliseconds, like the global `setTimeout` function. The callback can be
|
|
73
|
+
* canceled with `clearTimeout`.
|
|
74
|
+
*
|
|
75
|
+
* It returns a timer ID, which may be a number or an object that can be
|
|
76
|
+
* coerced to a number via `Symbol.toPrimitive`.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { timeoutManager } from '@tanstack/query-core'
|
|
81
|
+
*
|
|
82
|
+
* const timeoutId = timeoutManager.setTimeout(
|
|
83
|
+
* () => console.log('ran at:', new Date()),
|
|
84
|
+
* 1000,
|
|
85
|
+
* )
|
|
86
|
+
*
|
|
87
|
+
* const timeoutIdNumber: number = Number(timeoutId)
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
109
90
|
setTimeout(e, t) {
|
|
110
|
-
return process.env.NODE_ENV !== "production" && o(this,
|
|
91
|
+
return process.env.NODE_ENV !== "production" && o(this, at, !0), i(this, G).setTimeout(e, t);
|
|
111
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* `clearTimeout` cancels a timeout callback scheduled with `setTimeout`,
|
|
95
|
+
* like the global `clearTimeout` function. It should be called with a
|
|
96
|
+
* timer ID returned by `setTimeout`.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { timeoutManager } from '@tanstack/query-core'
|
|
101
|
+
*
|
|
102
|
+
* const timeoutId = timeoutManager.setTimeout(
|
|
103
|
+
* () => console.log('ran at:', new Date()),
|
|
104
|
+
* 1000,
|
|
105
|
+
* )
|
|
106
|
+
*
|
|
107
|
+
* timeoutManager.clearTimeout(timeoutId)
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
112
110
|
clearTimeout(e) {
|
|
113
111
|
i(this, G).clearTimeout(e);
|
|
114
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* `setInterval` schedules a callback to be called approximately every
|
|
115
|
+
* `delay` milliseconds, like the global `setInterval` function.
|
|
116
|
+
*
|
|
117
|
+
* Like `setTimeout`, it returns a timer ID, which may be a number or an
|
|
118
|
+
* object that can be coerced to a number via `Symbol.toPrimitive`.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* import { timeoutManager } from '@tanstack/query-core'
|
|
123
|
+
*
|
|
124
|
+
* const intervalId = timeoutManager.setInterval(
|
|
125
|
+
* () => console.log('ran at:', new Date()),
|
|
126
|
+
* 1000,
|
|
127
|
+
* )
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
115
130
|
setInterval(e, t) {
|
|
116
|
-
return process.env.NODE_ENV !== "production" && o(this,
|
|
131
|
+
return process.env.NODE_ENV !== "production" && o(this, at, !0), i(this, G).setInterval(e, t);
|
|
117
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* `clearInterval` can be used to cancel an interval, like the global
|
|
135
|
+
* `clearInterval` function. It should be called with an interval ID
|
|
136
|
+
* returned by `setInterval`.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* import { timeoutManager } from '@tanstack/query-core'
|
|
141
|
+
*
|
|
142
|
+
* const intervalId = timeoutManager.setInterval(
|
|
143
|
+
* () => console.log('ran at:', new Date()),
|
|
144
|
+
* 1000,
|
|
145
|
+
* )
|
|
146
|
+
*
|
|
147
|
+
* timeoutManager.clearInterval(intervalId)
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
118
150
|
clearInterval(e) {
|
|
119
151
|
i(this, G).clearInterval(e);
|
|
120
152
|
}
|
|
121
|
-
}, G = new WeakMap(),
|
|
122
|
-
|
|
153
|
+
}, G = new WeakMap(), at = new WeakMap(), Oe);
|
|
154
|
+
const nt = new Je();
|
|
155
|
+
function Ze(e) {
|
|
123
156
|
setTimeout(e, 0);
|
|
124
157
|
}
|
|
125
|
-
|
|
126
|
-
function
|
|
158
|
+
const Xe = typeof window > "u" || "Deno" in globalThis;
|
|
159
|
+
function k() {
|
|
127
160
|
}
|
|
128
|
-
function
|
|
161
|
+
function Ye(e, t) {
|
|
129
162
|
return typeof e == "function" ? e(t) : e;
|
|
130
163
|
}
|
|
131
|
-
function
|
|
164
|
+
function xe(e) {
|
|
132
165
|
return typeof e == "number" && e >= 0 && e !== 1 / 0;
|
|
133
166
|
}
|
|
134
|
-
function
|
|
167
|
+
function Ue(e, t) {
|
|
135
168
|
return Math.max(e + (t || 0) - Date.now(), 0);
|
|
136
169
|
}
|
|
137
|
-
function
|
|
138
|
-
return typeof e == "function" ? e(t) : e;
|
|
139
|
-
}
|
|
140
|
-
function L(e, t) {
|
|
170
|
+
function P(e, t) {
|
|
141
171
|
return typeof e == "function" ? e(t) : e;
|
|
142
172
|
}
|
|
143
|
-
function
|
|
144
|
-
const {
|
|
145
|
-
type: s = "all",
|
|
146
|
-
exact: r,
|
|
147
|
-
fetchStatus: n,
|
|
148
|
-
predicate: a,
|
|
149
|
-
queryKey: h,
|
|
150
|
-
stale: u
|
|
151
|
-
} = e;
|
|
173
|
+
function ye(e, t) {
|
|
174
|
+
const { type: s = "all", exact: r, fetchStatus: n, predicate: a, queryKey: h, stale: u } = e;
|
|
152
175
|
if (h) {
|
|
153
176
|
if (r) {
|
|
154
|
-
if (t.queryHash !==
|
|
155
|
-
|
|
156
|
-
} else if (!At(t.queryKey, h))
|
|
157
|
-
return !1;
|
|
177
|
+
if (t.queryHash !== ae(h, t.options)) return !1;
|
|
178
|
+
} else if (!Qt(t.queryKey, h)) return !1;
|
|
158
179
|
}
|
|
159
180
|
if (s !== "all") {
|
|
160
|
-
const
|
|
161
|
-
if (s === "active" && !
|
|
162
|
-
return !1;
|
|
181
|
+
const d = t.isActive();
|
|
182
|
+
if (s === "active" && !d || s === "inactive" && d) return !1;
|
|
163
183
|
}
|
|
164
184
|
return !(typeof u == "boolean" && t.isStale() !== u || n && n !== t.state.fetchStatus || a && !a(t));
|
|
165
185
|
}
|
|
166
|
-
function
|
|
186
|
+
function pe(e, t) {
|
|
167
187
|
const { exact: s, status: r, predicate: n, mutationKey: a } = e;
|
|
168
188
|
if (a) {
|
|
169
|
-
if (!t.options.mutationKey)
|
|
170
|
-
return !1;
|
|
189
|
+
if (!t.options.mutationKey) return !1;
|
|
171
190
|
if (s) {
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
-
} else if (!At(t.options.mutationKey, a))
|
|
175
|
-
return !1;
|
|
191
|
+
if (Dt(t.options.mutationKey) !== Dt(a)) return !1;
|
|
192
|
+
} else if (!Qt(t.options.mutationKey, a)) return !1;
|
|
176
193
|
}
|
|
177
194
|
return !(r && t.state.status !== r || n && !n(t));
|
|
178
195
|
}
|
|
179
|
-
function
|
|
180
|
-
return ((t == null ? void 0 : t.queryKeyHashFn) ||
|
|
196
|
+
function ae(e, t) {
|
|
197
|
+
return ((t == null ? void 0 : t.queryKeyHashFn) || Dt)(e);
|
|
181
198
|
}
|
|
182
|
-
function
|
|
183
|
-
return JSON.stringify(
|
|
184
|
-
e,
|
|
185
|
-
(t, s) => ee(s) ? Object.keys(s).sort().reduce((r, n) => (r[n] = s[n], r), {}) : s
|
|
186
|
-
);
|
|
199
|
+
function Dt(e) {
|
|
200
|
+
return JSON.stringify(e, (t, s) => zt(s) ? Object.keys(s).sort().reduce((r, n) => (r[n] = s[n], r), {}) : s);
|
|
187
201
|
}
|
|
188
|
-
function
|
|
189
|
-
|
|
202
|
+
function Qt(e, t) {
|
|
203
|
+
if (e === t) return !0;
|
|
204
|
+
if (typeof e != typeof t) return !1;
|
|
205
|
+
if (e && t && typeof e == "object" && typeof t == "object") {
|
|
206
|
+
if (Array.isArray(e) && Array.isArray(t)) {
|
|
207
|
+
if (t.length > e.length) return !1;
|
|
208
|
+
for (let r = 0; r < t.length; r++) if (!Qt(e[r], t[r])) return !1;
|
|
209
|
+
return !0;
|
|
210
|
+
}
|
|
211
|
+
const s = Object.keys(t);
|
|
212
|
+
for (const r of s) if (!Qt(e[r], t[r])) return !1;
|
|
213
|
+
return !0;
|
|
214
|
+
}
|
|
215
|
+
return !1;
|
|
190
216
|
}
|
|
191
|
-
|
|
192
|
-
function
|
|
193
|
-
if (e === t)
|
|
194
|
-
return e;
|
|
217
|
+
const ts = Object.prototype.hasOwnProperty;
|
|
218
|
+
function $t(e, t, s = 0) {
|
|
219
|
+
if (e === t) return e;
|
|
195
220
|
if (s > 500) return t;
|
|
196
|
-
const r =
|
|
197
|
-
if (!r && !(
|
|
198
|
-
const
|
|
199
|
-
let
|
|
200
|
-
for (let
|
|
201
|
-
const
|
|
221
|
+
const r = me(e) && me(t);
|
|
222
|
+
if (!r && !(zt(e) && zt(t))) return t;
|
|
223
|
+
const n = (r ? e : Object.keys(e)).length, a = r ? t : Object.keys(t), h = a.length, u = r ? new Array(h) : {};
|
|
224
|
+
let d = 0;
|
|
225
|
+
for (let p = 0; p < h; p++) {
|
|
226
|
+
const f = r ? p : a[p], C = e[f], y = t[f];
|
|
202
227
|
if (C === y) {
|
|
203
|
-
f
|
|
228
|
+
u[f] = C, (r ? p < n : ts.call(e, f)) && d++;
|
|
204
229
|
continue;
|
|
205
230
|
}
|
|
206
231
|
if (C === null || y === null || typeof C != "object" || typeof y != "object") {
|
|
207
|
-
f
|
|
232
|
+
u[f] = y;
|
|
208
233
|
continue;
|
|
209
234
|
}
|
|
210
|
-
const
|
|
211
|
-
f
|
|
235
|
+
const R = $t(C, y, s + 1);
|
|
236
|
+
u[f] = R, R === C && d++;
|
|
212
237
|
}
|
|
213
|
-
return
|
|
238
|
+
return n === h && d === n ? e : u;
|
|
214
239
|
}
|
|
215
|
-
function
|
|
216
|
-
if (!t || Object.keys(e).length !== Object.keys(t).length)
|
|
217
|
-
|
|
218
|
-
for (const s in e)
|
|
219
|
-
if (e[s] !== t[s])
|
|
220
|
-
return !1;
|
|
240
|
+
function Vt(e, t) {
|
|
241
|
+
if (!t || Object.keys(e).length !== Object.keys(t).length) return !1;
|
|
242
|
+
for (const s in e) if (e[s] !== t[s]) return !1;
|
|
221
243
|
return !0;
|
|
222
244
|
}
|
|
223
|
-
function
|
|
245
|
+
function me(e) {
|
|
224
246
|
return Array.isArray(e) && e.length === Object.keys(e).length;
|
|
225
247
|
}
|
|
226
|
-
function
|
|
227
|
-
if (!
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return !(!Oe(s) || !s.hasOwnProperty("isPrototypeOf") || Object.getPrototypeOf(e) !== Object.prototype);
|
|
248
|
+
function zt(e) {
|
|
249
|
+
if (!ve(e)) return !1;
|
|
250
|
+
const t = Object.getPrototypeOf(e), s = t == null ? void 0 : t.constructor;
|
|
251
|
+
if (s === void 0) return !0;
|
|
252
|
+
if (typeof s != "function") return !1;
|
|
253
|
+
const r = s.prototype;
|
|
254
|
+
return !(!ve(r) || !r.hasOwnProperty("isPrototypeOf") || t !== Object.prototype);
|
|
234
255
|
}
|
|
235
|
-
function
|
|
256
|
+
function ve(e) {
|
|
236
257
|
return Object.prototype.toString.call(e) === "[object Object]";
|
|
237
258
|
}
|
|
238
|
-
function
|
|
259
|
+
function es(e) {
|
|
239
260
|
return new Promise((t) => {
|
|
240
|
-
|
|
261
|
+
nt.setTimeout(t, e);
|
|
241
262
|
});
|
|
242
263
|
}
|
|
243
|
-
function
|
|
244
|
-
if (typeof s.structuralSharing == "function")
|
|
245
|
-
return s.structuralSharing(e, t);
|
|
264
|
+
function Wt(e, t, s) {
|
|
265
|
+
if (typeof s.structuralSharing == "function") return s.structuralSharing(e, t);
|
|
246
266
|
if (s.structuralSharing !== !1) {
|
|
247
|
-
if (process.env.NODE_ENV !== "production")
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
), r;
|
|
254
|
-
}
|
|
255
|
-
return Yt(e, t);
|
|
267
|
+
if (process.env.NODE_ENV !== "production") try {
|
|
268
|
+
return $t(e, t);
|
|
269
|
+
} catch (r) {
|
|
270
|
+
throw console.error(`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${s.queryHash}]: ${r}`), r;
|
|
271
|
+
}
|
|
272
|
+
return $t(e, t);
|
|
256
273
|
}
|
|
257
274
|
return t;
|
|
258
275
|
}
|
|
259
|
-
function
|
|
276
|
+
function ss(e, t, s = 0) {
|
|
260
277
|
const r = [...e, t];
|
|
261
278
|
return s && r.length > s ? r.slice(1) : r;
|
|
262
279
|
}
|
|
263
|
-
function
|
|
280
|
+
function rs(e, t, s = 0) {
|
|
264
281
|
const r = [t, ...e];
|
|
265
282
|
return s && r.length > s ? r.slice(0, -1) : r;
|
|
266
283
|
}
|
|
267
|
-
|
|
268
|
-
function
|
|
269
|
-
return process.env.NODE_ENV !== "production" && e.queryFn ===
|
|
270
|
-
`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${e.queryHash}'`
|
|
271
|
-
), !e.queryFn && (t != null && t.initialPromise) ? () => t.initialPromise : !e.queryFn || e.queryFn === $t ? () => Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)) : e.queryFn;
|
|
284
|
+
const Kt = Symbol();
|
|
285
|
+
function Ne(e, t) {
|
|
286
|
+
return process.env.NODE_ENV !== "production" && e.queryFn === Kt && console.error(`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${e.queryHash}'`), !e.queryFn && (t != null && t.initialPromise) ? () => t.initialPromise : !e.queryFn || e.queryFn === Kt ? () => Promise.reject(/* @__PURE__ */ new Error(`Missing queryFn: '${e.queryHash}'`)) : e.queryFn;
|
|
272
287
|
}
|
|
273
|
-
function
|
|
288
|
+
function je(e, t) {
|
|
274
289
|
return typeof e == "function" ? e(...t) : !!e;
|
|
275
290
|
}
|
|
276
|
-
function
|
|
291
|
+
function is(e, t, s) {
|
|
277
292
|
let r = !1, n;
|
|
278
293
|
return Object.defineProperty(e, "signal", {
|
|
279
294
|
enumerable: !0,
|
|
280
295
|
get: () => (n ?? (n = t()), r || (r = !0, n.aborted ? s() : n.addEventListener("abort", s, { once: !0 })), n)
|
|
281
296
|
}), e;
|
|
282
297
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
})
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
298
|
+
let ns = () => Xe;
|
|
299
|
+
const oe = () => ns();
|
|
300
|
+
var Nt = class {
|
|
301
|
+
constructor() {
|
|
302
|
+
this.listeners = /* @__PURE__ */ new Set(), this.subscribe = this.subscribe.bind(this);
|
|
303
|
+
}
|
|
304
|
+
subscribe(e) {
|
|
305
|
+
return this.listeners.add(e), this.onSubscribe(), () => {
|
|
306
|
+
this.listeners.delete(e), this.onUnsubscribe();
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
hasListeners() {
|
|
310
|
+
return this.listeners.size > 0;
|
|
311
|
+
}
|
|
312
|
+
onSubscribe() {
|
|
313
|
+
}
|
|
314
|
+
onUnsubscribe() {
|
|
315
|
+
}
|
|
316
|
+
}, ot, Y, mt, Pe, as = (Pe = class extends Nt {
|
|
317
|
+
constructor() {
|
|
318
|
+
super();
|
|
319
|
+
c(this, ot);
|
|
320
|
+
c(this, Y);
|
|
321
|
+
c(this, mt);
|
|
322
|
+
o(this, mt, (t) => {
|
|
323
|
+
if (typeof window < "u" && window.addEventListener) {
|
|
324
|
+
const s = () => t();
|
|
325
|
+
return window.addEventListener("visibilitychange", s, !1), () => {
|
|
326
|
+
window.removeEventListener("visibilitychange", s);
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
onSubscribe() {
|
|
332
|
+
i(this, Y) || this.setEventListener(i(this, mt));
|
|
333
|
+
}
|
|
334
|
+
onUnsubscribe() {
|
|
335
|
+
var t;
|
|
336
|
+
this.hasListeners() || ((t = i(this, Y)) == null || t.call(this), o(this, Y, void 0));
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* `setEventListener` can be used to set a custom event listener that will
|
|
340
|
+
* be used to determine the focus state. The provided `setup` function
|
|
341
|
+
* receives a `setFocused` callback: call it with a `boolean` to manually
|
|
342
|
+
* set the focus state, or with no arguments to re-evaluate the current
|
|
343
|
+
* focus state and notify subscribers.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```ts
|
|
347
|
+
* import { focusManager } from '@tanstack/query-core'
|
|
348
|
+
*
|
|
349
|
+
* focusManager.setEventListener((handleFocus) => {
|
|
350
|
+
* const listener = () => handleFocus()
|
|
351
|
+
* // Listen to visibilitychange
|
|
352
|
+
* if (typeof window !== 'undefined' && window.addEventListener) {
|
|
353
|
+
* window.addEventListener('visibilitychange', listener, false)
|
|
354
|
+
* }
|
|
355
|
+
*
|
|
356
|
+
* return () => {
|
|
357
|
+
* // Be sure to unsubscribe if a new handler is set
|
|
358
|
+
* window.removeEventListener('visibilitychange', listener)
|
|
359
|
+
* }
|
|
360
|
+
* })
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
setEventListener(t) {
|
|
364
|
+
var s;
|
|
365
|
+
o(this, mt, t), (s = i(this, Y)) == null || s.call(this), o(this, Y, t((r) => {
|
|
366
|
+
typeof r == "boolean" ? this.setFocused(r) : this.onFocus();
|
|
367
|
+
}));
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* `setFocused` can be used to manually set the focus state. Set `undefined`
|
|
371
|
+
* to fall back to the default focus check.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```ts
|
|
375
|
+
* import { focusManager } from '@tanstack/query-core'
|
|
376
|
+
*
|
|
377
|
+
* // Set focused
|
|
378
|
+
* focusManager.setFocused(true)
|
|
379
|
+
*
|
|
380
|
+
* // Set unfocused
|
|
381
|
+
* focusManager.setFocused(false)
|
|
382
|
+
*
|
|
383
|
+
* // Fallback to the default focus check
|
|
384
|
+
* focusManager.setFocused(undefined)
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
setFocused(t) {
|
|
388
|
+
i(this, ot) !== t && (o(this, ot, t), this.onFocus());
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* `onFocus` notifies all subscribed listeners with the current focus state.
|
|
392
|
+
*/
|
|
393
|
+
onFocus() {
|
|
394
|
+
const t = this.isFocused();
|
|
395
|
+
this.listeners.forEach((s) => {
|
|
396
|
+
s(t);
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* `isFocused` can be used to get the current focus state.
|
|
401
|
+
*/
|
|
402
|
+
isFocused() {
|
|
403
|
+
var t;
|
|
404
|
+
return typeof i(this, ot) == "boolean" ? i(this, ot) : ((t = globalThis.document) == null ? void 0 : t.visibilityState) !== "hidden";
|
|
405
|
+
}
|
|
406
|
+
}, ot = new WeakMap(), Y = new WeakMap(), mt = new WeakMap(), Pe);
|
|
407
|
+
const ue = new as(), os = Ze;
|
|
408
|
+
function us() {
|
|
324
409
|
let e = [], t = 0, s = (u) => {
|
|
325
410
|
u();
|
|
326
411
|
}, r = (u) => {
|
|
327
412
|
u();
|
|
328
|
-
}, n =
|
|
413
|
+
}, n = os;
|
|
329
414
|
const a = (u) => {
|
|
330
415
|
t ? e.push(u) : n(() => {
|
|
331
416
|
s(u);
|
|
@@ -334,58 +419,96 @@ function ys() {
|
|
|
334
419
|
const u = e;
|
|
335
420
|
e = [], u.length && n(() => {
|
|
336
421
|
r(() => {
|
|
337
|
-
u.forEach((
|
|
338
|
-
s(
|
|
422
|
+
u.forEach((d) => {
|
|
423
|
+
s(d);
|
|
339
424
|
});
|
|
340
425
|
});
|
|
341
426
|
});
|
|
342
427
|
};
|
|
343
428
|
return {
|
|
429
|
+
/**
|
|
430
|
+
* Batches all updates scheduled inside the passed callback.
|
|
431
|
+
* This is mainly used internally to optimize query client updating.
|
|
432
|
+
* Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
|
|
433
|
+
* The return value of `callback` is passed through.
|
|
434
|
+
*/
|
|
344
435
|
batch: (u) => {
|
|
345
|
-
let
|
|
436
|
+
let d;
|
|
346
437
|
t++;
|
|
347
438
|
try {
|
|
348
|
-
|
|
439
|
+
d = u();
|
|
349
440
|
} finally {
|
|
350
441
|
t--, t || h();
|
|
351
442
|
}
|
|
352
|
-
return
|
|
443
|
+
return d;
|
|
353
444
|
},
|
|
354
445
|
/**
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
batchCalls: (u) => (...
|
|
446
|
+
* All calls to the wrapped function will be batched.
|
|
447
|
+
*/
|
|
448
|
+
batchCalls: (u) => (...d) => {
|
|
358
449
|
a(() => {
|
|
359
|
-
u(...
|
|
450
|
+
u(...d);
|
|
360
451
|
});
|
|
361
452
|
},
|
|
453
|
+
/**
|
|
454
|
+
* Schedules a function to be run on the next batch.
|
|
455
|
+
* By default, the batch is run with a `setTimeout`, but this can be configured via `setScheduler`.
|
|
456
|
+
*/
|
|
362
457
|
schedule: a,
|
|
363
458
|
/**
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
459
|
+
* Use this method to set a custom notify function.
|
|
460
|
+
* This can be used to for example wrap notifications with `React.act` while running tests.
|
|
461
|
+
*/
|
|
367
462
|
setNotifyFunction: (u) => {
|
|
368
463
|
s = u;
|
|
369
464
|
},
|
|
370
465
|
/**
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
466
|
+
* Use this method to set a custom function to batch notifications together into a single tick.
|
|
467
|
+
* Framework adapters use this to plug in their own batching primitive, so that a single query
|
|
468
|
+
* update only triggers one re-render instead of one per subscriber.
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* ```ts
|
|
472
|
+
* import { notifyManager } from '@tanstack/query-core'
|
|
473
|
+
* import { batch } from 'solid-js'
|
|
474
|
+
*
|
|
475
|
+
* notifyManager.setBatchNotifyFunction(batch)
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
374
478
|
setBatchNotifyFunction: (u) => {
|
|
375
479
|
r = u;
|
|
376
480
|
},
|
|
481
|
+
/**
|
|
482
|
+
* Configures a custom callback that schedules when the next batch runs.
|
|
483
|
+
* The default behavior is `setTimeout(callback, 0)`.
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```ts
|
|
487
|
+
* import { notifyManager } from '@tanstack/query-core'
|
|
488
|
+
*
|
|
489
|
+
* // Schedule batches in the next microtask
|
|
490
|
+
* notifyManager.setScheduler(queueMicrotask)
|
|
491
|
+
*
|
|
492
|
+
* // Schedule batches before the next frame is rendered
|
|
493
|
+
* notifyManager.setScheduler(requestAnimationFrame)
|
|
494
|
+
*
|
|
495
|
+
* // Schedule batches some time in the future
|
|
496
|
+
* notifyManager.setScheduler((cb) => setTimeout(cb, 10))
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
377
499
|
setScheduler: (u) => {
|
|
378
500
|
n = u;
|
|
379
501
|
}
|
|
380
502
|
};
|
|
381
503
|
}
|
|
382
|
-
|
|
504
|
+
const A = us();
|
|
505
|
+
var vt, tt, gt, Ee, hs = (Ee = class extends Nt {
|
|
383
506
|
constructor() {
|
|
384
507
|
super();
|
|
385
|
-
c(this,
|
|
386
|
-
c(this,
|
|
387
|
-
c(this,
|
|
388
|
-
o(this,
|
|
508
|
+
c(this, vt, !0);
|
|
509
|
+
c(this, tt);
|
|
510
|
+
c(this, gt);
|
|
511
|
+
o(this, gt, (t) => {
|
|
389
512
|
if (typeof window < "u" && window.addEventListener) {
|
|
390
513
|
const s = () => t(!0), r = () => t(!1);
|
|
391
514
|
return window.addEventListener("online", s, !1), window.addEventListener("offline", r, !1), () => {
|
|
@@ -395,284 +518,514 @@ var I = ys(), wt, et, St, Ae, ps = (Ae = class extends kt {
|
|
|
395
518
|
});
|
|
396
519
|
}
|
|
397
520
|
onSubscribe() {
|
|
398
|
-
i(this,
|
|
521
|
+
i(this, tt) || this.setEventListener(i(this, gt));
|
|
399
522
|
}
|
|
400
523
|
onUnsubscribe() {
|
|
401
524
|
var t;
|
|
402
|
-
this.hasListeners() || ((t = i(this,
|
|
525
|
+
this.hasListeners() || ((t = i(this, tt)) == null || t.call(this), o(this, tt, void 0));
|
|
403
526
|
}
|
|
527
|
+
/**
|
|
528
|
+
* `setEventListener` can be used to set a custom event listener that will
|
|
529
|
+
* be used to determine the online state. The provided `setup` function
|
|
530
|
+
* receives a `setOnline` callback that should be called with a `boolean`
|
|
531
|
+
* whenever the online state changes.
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```ts
|
|
535
|
+
* import NetInfo from '@react-native-community/netinfo'
|
|
536
|
+
* import { onlineManager } from '@tanstack/query-core'
|
|
537
|
+
*
|
|
538
|
+
* onlineManager.setEventListener((setOnline) => {
|
|
539
|
+
* return NetInfo.addEventListener((state) => {
|
|
540
|
+
* setOnline(!!state.isConnected)
|
|
541
|
+
* })
|
|
542
|
+
* })
|
|
543
|
+
* ```
|
|
544
|
+
*/
|
|
404
545
|
setEventListener(t) {
|
|
405
546
|
var s;
|
|
406
|
-
o(this,
|
|
547
|
+
o(this, gt, t), (s = i(this, tt)) == null || s.call(this), o(this, tt, t(this.setOnline.bind(this)));
|
|
407
548
|
}
|
|
549
|
+
/**
|
|
550
|
+
* `setOnline` can be used to manually set the online state.
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* ```ts
|
|
554
|
+
* import { onlineManager } from '@tanstack/query-core'
|
|
555
|
+
*
|
|
556
|
+
* // Set to online
|
|
557
|
+
* onlineManager.setOnline(true)
|
|
558
|
+
*
|
|
559
|
+
* // Set to offline
|
|
560
|
+
* onlineManager.setOnline(false)
|
|
561
|
+
* ```
|
|
562
|
+
*/
|
|
408
563
|
setOnline(t) {
|
|
409
|
-
i(this,
|
|
410
|
-
|
|
564
|
+
i(this, vt) !== t && (o(this, vt, t), this.listeners.forEach((s) => {
|
|
565
|
+
s(t);
|
|
411
566
|
}));
|
|
412
567
|
}
|
|
568
|
+
/**
|
|
569
|
+
* `isOnline` can be used to get the current online state.
|
|
570
|
+
*/
|
|
413
571
|
isOnline() {
|
|
414
|
-
return i(this,
|
|
572
|
+
return i(this, vt);
|
|
415
573
|
}
|
|
416
|
-
},
|
|
417
|
-
|
|
574
|
+
}, vt = new WeakMap(), tt = new WeakMap(), gt = new WeakMap(), Ee);
|
|
575
|
+
const Ht = new hs();
|
|
576
|
+
function cs(e) {
|
|
418
577
|
return Math.min(1e3 * 2 ** e, 3e4);
|
|
419
578
|
}
|
|
420
|
-
function
|
|
421
|
-
return (e ?? "online") === "online" ?
|
|
579
|
+
function ke(e) {
|
|
580
|
+
return (e ?? "online") === "online" ? Ht.isOnline() : !0;
|
|
422
581
|
}
|
|
423
|
-
var
|
|
582
|
+
var Jt = class extends Error {
|
|
424
583
|
constructor(e) {
|
|
425
584
|
super("CancelledError"), this.revert = e == null ? void 0 : e.revert, this.silent = e == null ? void 0 : e.silent;
|
|
426
585
|
}
|
|
427
586
|
};
|
|
428
|
-
function
|
|
429
|
-
let t = !1, s = 0, r;
|
|
430
|
-
const
|
|
587
|
+
function _e(e) {
|
|
588
|
+
let t = !1, s = 0, r, n = "pending", a, h;
|
|
589
|
+
const u = new Promise((g, b) => {
|
|
590
|
+
a = g, h = b;
|
|
591
|
+
});
|
|
592
|
+
u.catch(k);
|
|
593
|
+
const d = () => n !== "pending", p = (g) => {
|
|
431
594
|
var b;
|
|
432
|
-
if (!
|
|
433
|
-
const S = new
|
|
434
|
-
|
|
595
|
+
if (!d()) {
|
|
596
|
+
const S = new Jt(g);
|
|
597
|
+
O(S), (b = e.onCancel) == null || b.call(e, S);
|
|
435
598
|
}
|
|
436
|
-
}, u = () => {
|
|
437
|
-
t = !0;
|
|
438
599
|
}, f = () => {
|
|
600
|
+
t = !0;
|
|
601
|
+
}, C = () => {
|
|
439
602
|
t = !1;
|
|
440
|
-
},
|
|
441
|
-
|
|
442
|
-
},
|
|
443
|
-
|
|
444
|
-
},
|
|
603
|
+
}, y = () => ue.isFocused() && (e.networkMode === "always" || Ht.isOnline()) && e.canRun(), R = () => ke(e.networkMode) && e.canRun(), D = (g) => {
|
|
604
|
+
d() || (r == null || r(), n = "resolved", a(g));
|
|
605
|
+
}, O = (g) => {
|
|
606
|
+
d() || (r == null || r(), n = "rejected", h(g));
|
|
607
|
+
}, q = () => new Promise((g) => {
|
|
445
608
|
var b;
|
|
446
609
|
r = (S) => {
|
|
447
|
-
(
|
|
610
|
+
(d() || y()) && g(S);
|
|
448
611
|
}, (b = e.onPause) == null || b.call(e);
|
|
449
612
|
}).then(() => {
|
|
450
|
-
var
|
|
451
|
-
r = void 0,
|
|
452
|
-
}),
|
|
453
|
-
if (
|
|
454
|
-
|
|
455
|
-
let v;
|
|
613
|
+
var g;
|
|
614
|
+
r = void 0, d() || (g = e.onContinue) == null || g.call(e);
|
|
615
|
+
}), M = () => {
|
|
616
|
+
if (d()) return;
|
|
617
|
+
let g;
|
|
456
618
|
const b = s === 0 ? e.initialPromise : void 0;
|
|
457
619
|
try {
|
|
458
|
-
|
|
620
|
+
g = b ?? e.fn();
|
|
459
621
|
} catch (S) {
|
|
460
|
-
|
|
622
|
+
g = Promise.reject(S);
|
|
461
623
|
}
|
|
462
|
-
Promise.resolve(
|
|
463
|
-
var
|
|
464
|
-
if (
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
C(S);
|
|
624
|
+
Promise.resolve(g).then(D).catch((S) => {
|
|
625
|
+
var E;
|
|
626
|
+
if (d()) return;
|
|
627
|
+
const l = e.retry ?? (oe() ? 0 : 3), x = e.retryDelay ?? cs, Q = typeof x == "function" ? x(s, S) : x, K = l === !0 || typeof l == "number" && s < l || typeof l == "function" && l(s, S);
|
|
628
|
+
if (t || !K) {
|
|
629
|
+
O(S);
|
|
469
630
|
return;
|
|
470
631
|
}
|
|
471
|
-
s++, (
|
|
472
|
-
t ?
|
|
632
|
+
s++, (E = e.onFail) == null || E.call(e, s, S), es(Q).then(() => y() ? void 0 : q()).then(() => {
|
|
633
|
+
t ? O(S) : M();
|
|
473
634
|
});
|
|
474
635
|
});
|
|
475
636
|
};
|
|
476
637
|
return {
|
|
477
|
-
promise:
|
|
478
|
-
status: () => n
|
|
479
|
-
cancel:
|
|
480
|
-
continue: () => (r == null || r(),
|
|
481
|
-
cancelRetry:
|
|
482
|
-
continueRetry:
|
|
483
|
-
canStart:
|
|
484
|
-
start: () => (
|
|
638
|
+
promise: u,
|
|
639
|
+
status: () => n,
|
|
640
|
+
cancel: p,
|
|
641
|
+
continue: () => (r == null || r(), u),
|
|
642
|
+
cancelRetry: f,
|
|
643
|
+
continueRetry: C,
|
|
644
|
+
canStart: R,
|
|
645
|
+
start: () => (R() ? M() : q().then(M), u)
|
|
485
646
|
};
|
|
486
647
|
}
|
|
487
|
-
var
|
|
648
|
+
var ut, Fe, Le = (Fe = class {
|
|
488
649
|
constructor() {
|
|
489
|
-
c(this,
|
|
650
|
+
c(this, ut);
|
|
490
651
|
}
|
|
491
652
|
destroy() {
|
|
492
653
|
this.clearGcTimeout();
|
|
493
654
|
}
|
|
494
655
|
scheduleGc() {
|
|
495
|
-
this.clearGcTimeout(),
|
|
656
|
+
this.clearGcTimeout(), xe(this.gcTime) && o(this, ut, nt.setTimeout(() => {
|
|
496
657
|
this.optionalRemove();
|
|
497
658
|
}, this.gcTime));
|
|
498
659
|
}
|
|
499
660
|
updateGcTime(e) {
|
|
500
|
-
this.gcTime = Math.max(
|
|
501
|
-
this.gcTime || 0,
|
|
502
|
-
e ?? (xt.isServer() ? 1 / 0 : 300 * 1e3)
|
|
503
|
-
);
|
|
661
|
+
this.gcTime = Math.max(this.gcTime || 0, e ?? (oe() ? 1 / 0 : 3e5));
|
|
504
662
|
}
|
|
505
663
|
clearGcTimeout() {
|
|
506
|
-
i(this,
|
|
507
|
-
}
|
|
508
|
-
},
|
|
664
|
+
i(this, ut) !== void 0 && (nt.clearTimeout(i(this, ut)), o(this, ut, void 0));
|
|
665
|
+
}
|
|
666
|
+
}, ut = new WeakMap(), Fe);
|
|
667
|
+
function ls(e) {
|
|
668
|
+
return { onFetch: (t, s) => {
|
|
669
|
+
var f, C, y, R, D;
|
|
670
|
+
const r = t.options, n = (y = (C = (f = t.fetchOptions) == null ? void 0 : f.meta) == null ? void 0 : C.fetchMore) == null ? void 0 : y.direction, a = ((R = t.state.data) == null ? void 0 : R.pages) || [], h = ((D = t.state.data) == null ? void 0 : D.pageParams) || [];
|
|
671
|
+
let u = {
|
|
672
|
+
pages: [],
|
|
673
|
+
pageParams: []
|
|
674
|
+
}, d = 0;
|
|
675
|
+
const p = async () => {
|
|
676
|
+
let O = !1;
|
|
677
|
+
const q = (b) => {
|
|
678
|
+
is(b, () => t.signal, () => O = !0);
|
|
679
|
+
}, M = Ne(t.options, t.fetchOptions), g = async (b, S, l) => {
|
|
680
|
+
if (O) return Promise.reject(t.signal.reason);
|
|
681
|
+
if (S == null && b.pages.length) return Promise.resolve(b);
|
|
682
|
+
const Q = (() => {
|
|
683
|
+
const ce = {
|
|
684
|
+
client: t.client,
|
|
685
|
+
queryKey: t.queryKey,
|
|
686
|
+
pageParam: S,
|
|
687
|
+
direction: l ? "backward" : "forward",
|
|
688
|
+
meta: t.options.meta
|
|
689
|
+
};
|
|
690
|
+
return q(ce), ce;
|
|
691
|
+
})(), K = await M(Q), { maxPages: E } = t.options, U = l ? rs : ss;
|
|
692
|
+
return {
|
|
693
|
+
pages: U(b.pages, K, E),
|
|
694
|
+
pageParams: U(b.pageParams, S, E)
|
|
695
|
+
};
|
|
696
|
+
};
|
|
697
|
+
if (n && a.length) {
|
|
698
|
+
const b = n === "backward", S = b ? ds : ge, l = {
|
|
699
|
+
pages: a,
|
|
700
|
+
pageParams: h
|
|
701
|
+
};
|
|
702
|
+
u = await g(l, S(r, l), b);
|
|
703
|
+
} else {
|
|
704
|
+
const b = e ?? a.length;
|
|
705
|
+
do {
|
|
706
|
+
const S = d === 0 ? h[0] ?? r.initialPageParam : ge(r, u);
|
|
707
|
+
if (d > 0 && S == null) break;
|
|
708
|
+
u = await g(u, S), d++;
|
|
709
|
+
} while (d < b);
|
|
710
|
+
}
|
|
711
|
+
return u;
|
|
712
|
+
};
|
|
713
|
+
t.options.persister ? t.fetchFn = () => {
|
|
714
|
+
var O, q;
|
|
715
|
+
return (q = (O = t.options).persister) == null ? void 0 : q.call(O, p, {
|
|
716
|
+
client: t.client,
|
|
717
|
+
queryKey: t.queryKey,
|
|
718
|
+
meta: t.options.meta,
|
|
719
|
+
signal: t.signal
|
|
720
|
+
}, s);
|
|
721
|
+
} : t.fetchFn = p;
|
|
722
|
+
} };
|
|
723
|
+
}
|
|
724
|
+
function ge(e, { pages: t, pageParams: s }) {
|
|
725
|
+
const r = t.length - 1;
|
|
726
|
+
return t.length > 0 ? e.getNextPageParam(t[r], t, s[r], s) : void 0;
|
|
727
|
+
}
|
|
728
|
+
function ds(e, { pages: t, pageParams: s }) {
|
|
729
|
+
var r;
|
|
730
|
+
return t.length > 0 ? (r = e.getPreviousPageParam) == null ? void 0 : r.call(e, t[0], t, s[0], s) : void 0;
|
|
731
|
+
}
|
|
732
|
+
var bt, ht, wt, _, ct, T, qt, lt, H, W, Re, fs = (Re = class extends Le {
|
|
509
733
|
constructor(t) {
|
|
510
734
|
super();
|
|
735
|
+
c(this, H);
|
|
736
|
+
c(this, bt);
|
|
737
|
+
c(this, ht);
|
|
738
|
+
c(this, wt);
|
|
511
739
|
c(this, _);
|
|
512
|
-
c(this,
|
|
513
|
-
c(this, Ct);
|
|
514
|
-
c(this, k);
|
|
515
|
-
c(this, ft);
|
|
740
|
+
c(this, ct);
|
|
516
741
|
c(this, T);
|
|
517
742
|
c(this, qt);
|
|
518
|
-
c(this,
|
|
519
|
-
o(this,
|
|
743
|
+
c(this, lt);
|
|
744
|
+
o(this, lt, !1), o(this, qt, t.defaultOptions), this.setOptions(t.options), this.observers = [], o(this, ct, t.client), o(this, _, i(this, ct).getQueryCache()), this.queryKey = t.queryKey, this.queryHash = t.queryHash, o(this, ht, we(this.options)), this.state = t.state ?? i(this, ht), this.scheduleGc();
|
|
520
745
|
}
|
|
746
|
+
/**
|
|
747
|
+
* The `meta` object passed in the query's options, if any.
|
|
748
|
+
*/
|
|
521
749
|
get meta() {
|
|
522
750
|
return this.options.meta;
|
|
523
751
|
}
|
|
752
|
+
/** @internal */
|
|
753
|
+
get queryType() {
|
|
754
|
+
return i(this, bt);
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* The promise for the currently in-flight fetch, if the query is fetching.
|
|
758
|
+
* `undefined` when the query is not fetching.
|
|
759
|
+
*/
|
|
524
760
|
get promise() {
|
|
525
761
|
var t;
|
|
526
762
|
return (t = i(this, T)) == null ? void 0 : t.promise;
|
|
527
763
|
}
|
|
764
|
+
/** @internal */
|
|
528
765
|
setOptions(t) {
|
|
529
|
-
if (this.options = {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
766
|
+
if (this.options = {
|
|
767
|
+
...i(this, qt),
|
|
768
|
+
...t
|
|
769
|
+
}, t != null && t._type && o(this, bt, t._type), this.updateGcTime(this.options.gcTime), this.state && this.state.data === void 0) {
|
|
770
|
+
const s = we(this.options);
|
|
771
|
+
s.data !== void 0 && (this.setState(be(s.data, s.dataUpdatedAt)), o(this, ht, s));
|
|
534
772
|
}
|
|
535
773
|
}
|
|
536
774
|
optionalRemove() {
|
|
537
|
-
!this.observers.length && this.state.fetchStatus === "idle" && i(this,
|
|
775
|
+
!this.observers.length && this.state.fetchStatus === "idle" && i(this, _).remove(this);
|
|
538
776
|
}
|
|
777
|
+
/** @internal */
|
|
539
778
|
setData(t, s) {
|
|
540
|
-
const r =
|
|
541
|
-
return
|
|
779
|
+
const r = Wt(this.state.data, t, this.options);
|
|
780
|
+
return m(this, H, W).call(this, {
|
|
542
781
|
data: r,
|
|
543
782
|
type: "success",
|
|
544
783
|
dataUpdatedAt: s == null ? void 0 : s.updatedAt,
|
|
545
784
|
manual: s == null ? void 0 : s.manual
|
|
546
785
|
}), r;
|
|
547
786
|
}
|
|
548
|
-
|
|
549
|
-
|
|
787
|
+
/**
|
|
788
|
+
* Merges the given partial state directly into this query's state, notifying observers. Used
|
|
789
|
+
* by persistence and broadcast plugins to restore a state snapshot, and by devtools to let a
|
|
790
|
+
* user manually trigger a loading/error state or edit the cached data.
|
|
791
|
+
*/
|
|
792
|
+
setState(t) {
|
|
793
|
+
m(this, H, W).call(this, {
|
|
794
|
+
type: "setState",
|
|
795
|
+
state: t
|
|
796
|
+
});
|
|
550
797
|
}
|
|
798
|
+
/**
|
|
799
|
+
* Cancels the query's currently in-flight fetch, if any.
|
|
800
|
+
* - Returns a promise that resolves once the cancellation has settled.
|
|
801
|
+
* - If no fetch is in progress, resolves immediately.
|
|
802
|
+
*
|
|
803
|
+
* @example
|
|
804
|
+
* ```ts
|
|
805
|
+
* await query.cancel()
|
|
806
|
+
* ```
|
|
807
|
+
*/
|
|
551
808
|
cancel(t) {
|
|
552
809
|
var r, n;
|
|
553
810
|
const s = (r = i(this, T)) == null ? void 0 : r.promise;
|
|
554
|
-
return (n = i(this, T)) == null || n.cancel(t), s ? s.then(
|
|
811
|
+
return (n = i(this, T)) == null || n.cancel(t), s ? s.then(k).catch(k) : Promise.resolve();
|
|
555
812
|
}
|
|
813
|
+
/**
|
|
814
|
+
* Clears the query's garbage collection timeout and silently cancels any
|
|
815
|
+
* in-flight fetch. Called by `QueryCache` when the query is removed from
|
|
816
|
+
* the cache.
|
|
817
|
+
*
|
|
818
|
+
* @see {@link Query#cancel}
|
|
819
|
+
*/
|
|
556
820
|
destroy() {
|
|
557
821
|
super.destroy(), this.cancel({ silent: !0 });
|
|
558
822
|
}
|
|
823
|
+
/** @internal */
|
|
559
824
|
get resetState() {
|
|
560
|
-
return i(this,
|
|
825
|
+
return i(this, ht);
|
|
561
826
|
}
|
|
827
|
+
/**
|
|
828
|
+
* Resets the query back to its initial state (the state it had when it was
|
|
829
|
+
* first created, e.g. any `initialData`), destroying it first to cancel any
|
|
830
|
+
* in-flight fetch.
|
|
831
|
+
*/
|
|
562
832
|
reset() {
|
|
563
833
|
this.destroy(), this.setState(this.resetState);
|
|
564
834
|
}
|
|
835
|
+
/**
|
|
836
|
+
* Returns `true` if the query has at least one observer for which `enabled`
|
|
837
|
+
* does not resolve to `false`.
|
|
838
|
+
*/
|
|
565
839
|
isActive() {
|
|
566
|
-
return this.observers.some(
|
|
567
|
-
(t) => L(t.options.enabled, this) !== !1
|
|
568
|
-
);
|
|
840
|
+
return this.observers.some((t) => P(t.options.enabled, this) !== !1);
|
|
569
841
|
}
|
|
842
|
+
/**
|
|
843
|
+
* Returns `true` if the query is disabled, meaning it will not fetch
|
|
844
|
+
* automatically.
|
|
845
|
+
* - If the query has observers, it is disabled when none of them are active
|
|
846
|
+
* (see `isActive`).
|
|
847
|
+
* - If the query has no observers, it is disabled when its `queryFn` is
|
|
848
|
+
* `skipToken` or it has never been fetched.
|
|
849
|
+
*/
|
|
570
850
|
isDisabled() {
|
|
571
|
-
return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn ===
|
|
851
|
+
return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === Kt || !this.isFetched();
|
|
572
852
|
}
|
|
853
|
+
/**
|
|
854
|
+
* Returns `true` if the query has been fetched, i.e. it has resolved with
|
|
855
|
+
* either data or an error at least once.
|
|
856
|
+
*/
|
|
573
857
|
isFetched() {
|
|
574
858
|
return this.state.dataUpdateCount + this.state.errorUpdateCount > 0;
|
|
575
859
|
}
|
|
860
|
+
/**
|
|
861
|
+
* Returns `true` if the query has at least one observer configured with
|
|
862
|
+
* `staleTime: 'static'`, meaning it is treated as never stale.
|
|
863
|
+
*/
|
|
576
864
|
isStatic() {
|
|
577
|
-
return this.getObserversCount() > 0 ? this.observers.some(
|
|
578
|
-
(t) => ot(t.options.staleTime, this) === "static"
|
|
579
|
-
) : !1;
|
|
865
|
+
return this.getObserversCount() > 0 ? this.observers.some((t) => P(t.options.staleTime, this) === "static") : !1;
|
|
580
866
|
}
|
|
867
|
+
/**
|
|
868
|
+
* Returns `true` if the query is stale.
|
|
869
|
+
* - If the query has observers, defers to whether any observer's current
|
|
870
|
+
* result reports `isStale` (which accounts for each observer's own
|
|
871
|
+
* `staleTime` and `enabled` state).
|
|
872
|
+
* - If the query has no observers, it is considered stale when it has no
|
|
873
|
+
* data or has been invalidated.
|
|
874
|
+
*
|
|
875
|
+
* @see {@link Query#isStaleByTime}
|
|
876
|
+
* @example
|
|
877
|
+
* ```ts
|
|
878
|
+
* if (query.isStale()) {
|
|
879
|
+
* // refetch or otherwise treat the cached data as outdated
|
|
880
|
+
* }
|
|
881
|
+
* ```
|
|
882
|
+
*/
|
|
581
883
|
isStale() {
|
|
582
|
-
return this.getObserversCount() > 0 ? this.observers.some(
|
|
583
|
-
(t) => t.getCurrentResult().isStale
|
|
584
|
-
) : this.state.data === void 0 || this.state.isInvalidated;
|
|
884
|
+
return this.getObserversCount() > 0 ? this.observers.some((t) => t.getCurrentResult().isStale) : this.state.data === void 0 || this.state.isInvalidated;
|
|
585
885
|
}
|
|
886
|
+
/**
|
|
887
|
+
* Returns `true` if the query's data is stale relative to the given
|
|
888
|
+
* `staleTime` (defaults to `0`).
|
|
889
|
+
* - A query with no data is always stale.
|
|
890
|
+
* - `staleTime: 'static'` is never stale.
|
|
891
|
+
* - An invalidated query is always stale.
|
|
892
|
+
* - Otherwise, staleness is based on elapsed time since `dataUpdatedAt`.
|
|
893
|
+
*
|
|
894
|
+
* @see {@link Query#isStale}
|
|
895
|
+
* @example
|
|
896
|
+
* ```ts
|
|
897
|
+
* const isStale = query.isStaleByTime(1000 * 60)
|
|
898
|
+
* ```
|
|
899
|
+
*/
|
|
586
900
|
isStaleByTime(t = 0) {
|
|
587
|
-
return this.state.data === void 0 ? !0 : t === "static" ? !1 : this.state.isInvalidated ? !0 : !
|
|
901
|
+
return this.state.data === void 0 ? !0 : t === "static" ? !1 : this.state.isInvalidated ? !0 : !Ue(this.state.dataUpdatedAt, t);
|
|
588
902
|
}
|
|
903
|
+
/** @internal */
|
|
589
904
|
onFocus() {
|
|
590
|
-
var s;
|
|
591
|
-
|
|
592
|
-
t == null || t.refetch({ cancelRefetch: !1 }), (s = i(this, T)) == null || s.continue();
|
|
905
|
+
var t, s;
|
|
906
|
+
(t = this.observers.find((r) => r.shouldFetchOnWindowFocus())) == null || t.refetch({ cancelRefetch: !1 }), (s = i(this, T)) == null || s.continue();
|
|
593
907
|
}
|
|
908
|
+
/** @internal */
|
|
594
909
|
onOnline() {
|
|
595
|
-
var s;
|
|
596
|
-
|
|
597
|
-
t == null || t.refetch({ cancelRefetch: !1 }), (s = i(this, T)) == null || s.continue();
|
|
910
|
+
var t, s;
|
|
911
|
+
(t = this.observers.find((r) => r.shouldFetchOnReconnect())) == null || t.refetch({ cancelRefetch: !1 }), (s = i(this, T)) == null || s.continue();
|
|
598
912
|
}
|
|
913
|
+
/** @internal */
|
|
599
914
|
addObserver(t) {
|
|
600
|
-
this.observers.includes(t) || (this.observers.push(t), this.clearGcTimeout(), i(this,
|
|
915
|
+
this.observers.includes(t) || (this.observers.push(t), this.clearGcTimeout(), i(this, _).notify({
|
|
916
|
+
type: "observerAdded",
|
|
917
|
+
query: this,
|
|
918
|
+
observer: t
|
|
919
|
+
}));
|
|
601
920
|
}
|
|
921
|
+
/** @internal */
|
|
602
922
|
removeObserver(t) {
|
|
603
|
-
|
|
923
|
+
const s = this.observers.indexOf(t);
|
|
924
|
+
s !== -1 && (this.observers.splice(s, 1), this.observers.length || (i(this, T) && (i(this, lt) || this.state.fetchStatus === "paused" && this.state.status === "pending" ? i(this, T).cancel({ revert: !0 }) : i(this, T).cancelRetry()), this.scheduleGc()), i(this, _).notify({
|
|
925
|
+
type: "observerRemoved",
|
|
926
|
+
query: this,
|
|
927
|
+
observer: t
|
|
928
|
+
}));
|
|
604
929
|
}
|
|
930
|
+
/**
|
|
931
|
+
* Returns the number of observers currently subscribed to this query.
|
|
932
|
+
*
|
|
933
|
+
* @example
|
|
934
|
+
* ```ts
|
|
935
|
+
* if (query.getObserversCount() === 0) {
|
|
936
|
+
* // no component is currently watching this query
|
|
937
|
+
* }
|
|
938
|
+
* ```
|
|
939
|
+
*/
|
|
605
940
|
getObserversCount() {
|
|
606
941
|
return this.observers.length;
|
|
607
942
|
}
|
|
943
|
+
/**
|
|
944
|
+
* Marks the query as invalidated, unless it is already invalidated. This
|
|
945
|
+
* updates `state.isInvalidated` and notifies observers, but does not by
|
|
946
|
+
* itself trigger a refetch.
|
|
947
|
+
*
|
|
948
|
+
* @example
|
|
949
|
+
* ```ts
|
|
950
|
+
* query.invalidate()
|
|
951
|
+
* ```
|
|
952
|
+
*/
|
|
608
953
|
invalidate() {
|
|
609
|
-
this.state.isInvalidated ||
|
|
954
|
+
this.state.isInvalidated || m(this, H, W).call(this, { type: "invalidate" });
|
|
610
955
|
}
|
|
956
|
+
/**
|
|
957
|
+
* Fetches the query, i.e. runs its `queryFn` (through any configured
|
|
958
|
+
* retryer/behavior) and updates the query's state with the result.
|
|
959
|
+
* - If a fetch is already in flight, returns its promise instead of
|
|
960
|
+
* starting a new one, unless `fetchOptions.cancelRefetch` is set and the
|
|
961
|
+
* query already has data, in which case the current fetch is silently
|
|
962
|
+
* cancelled first.
|
|
963
|
+
* - If `options` is passed, it replaces the query's current options
|
|
964
|
+
* before fetching.
|
|
965
|
+
*/
|
|
611
966
|
async fetch(t, s) {
|
|
612
|
-
var
|
|
613
|
-
if (this.state.fetchStatus !== "idle" &&
|
|
614
|
-
|
|
615
|
-
// pending state when that happens
|
|
616
|
-
((f = i(this, T)) == null ? void 0 : f.status()) !== "rejected") {
|
|
617
|
-
if (this.state.data !== void 0 && (s != null && s.cancelRefetch))
|
|
618
|
-
this.cancel({ silent: !0 });
|
|
967
|
+
var p, f, C, y, R, D, O, q, M, g, b, S;
|
|
968
|
+
if (this.state.fetchStatus !== "idle" && ((p = i(this, T)) == null ? void 0 : p.status()) !== "rejected") {
|
|
969
|
+
if (this.state.data !== void 0 && (s != null && s.cancelRefetch)) this.cancel({ silent: !0 });
|
|
619
970
|
else if (i(this, T))
|
|
620
971
|
return i(this, T).continueRetry(), i(this, T).promise;
|
|
621
972
|
}
|
|
622
973
|
if (t && this.setOptions(t), !this.options.queryFn) {
|
|
623
|
-
const l = this.observers.find((
|
|
974
|
+
const l = this.observers.find((x) => x.options.queryFn);
|
|
624
975
|
l && this.setOptions(l.options);
|
|
625
976
|
}
|
|
626
|
-
process.env.NODE_ENV !== "production" && (Array.isArray(this.options.queryKey) || console.error(
|
|
627
|
-
"As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"
|
|
628
|
-
));
|
|
977
|
+
process.env.NODE_ENV !== "production" && (Array.isArray(this.options.queryKey) || console.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"));
|
|
629
978
|
const r = new AbortController(), n = (l) => {
|
|
630
979
|
Object.defineProperty(l, "signal", {
|
|
631
980
|
enumerable: !0,
|
|
632
|
-
get: () => (o(this,
|
|
981
|
+
get: () => (o(this, lt, !0), r.signal)
|
|
633
982
|
});
|
|
634
983
|
}, a = () => {
|
|
635
|
-
const l =
|
|
636
|
-
const
|
|
637
|
-
client: i(this,
|
|
984
|
+
const l = Ne(this.options, s), Q = (() => {
|
|
985
|
+
const K = {
|
|
986
|
+
client: i(this, ct),
|
|
638
987
|
queryKey: this.queryKey,
|
|
639
988
|
meta: this.meta
|
|
640
989
|
};
|
|
641
|
-
return n(
|
|
990
|
+
return n(K), K;
|
|
642
991
|
})();
|
|
643
|
-
return o(this,
|
|
644
|
-
l,
|
|
645
|
-
j,
|
|
646
|
-
this
|
|
647
|
-
) : l(j);
|
|
992
|
+
return o(this, lt, !1), this.options.persister ? this.options.persister(l, Q, this) : l(Q);
|
|
648
993
|
}, u = (() => {
|
|
649
994
|
const l = {
|
|
650
995
|
fetchOptions: s,
|
|
651
996
|
options: this.options,
|
|
652
997
|
queryKey: this.queryKey,
|
|
653
|
-
client: i(this,
|
|
998
|
+
client: i(this, ct),
|
|
654
999
|
state: this.state,
|
|
655
1000
|
fetchFn: a
|
|
656
1001
|
};
|
|
657
1002
|
return n(l), l;
|
|
658
1003
|
})();
|
|
659
|
-
(
|
|
1004
|
+
(f = i(this, bt) === "infinite" ? ls(this.options.pages) : this.options.behavior) == null || f.onFetch(u, this), o(this, wt, this.state), (this.state.fetchStatus === "idle" || this.state.fetchMeta !== ((C = u.fetchOptions) == null ? void 0 : C.meta)) && m(this, H, W).call(this, {
|
|
1005
|
+
type: "fetch",
|
|
1006
|
+
meta: (y = u.fetchOptions) == null ? void 0 : y.meta
|
|
1007
|
+
});
|
|
1008
|
+
const d = o(this, T, _e({
|
|
660
1009
|
initialPromise: s == null ? void 0 : s.initialPromise,
|
|
661
1010
|
fn: u.fetchFn,
|
|
662
1011
|
onCancel: (l) => {
|
|
663
|
-
l instanceof
|
|
664
|
-
...i(this,
|
|
1012
|
+
l instanceof Jt && l.revert && this.setState({
|
|
1013
|
+
...i(this, wt),
|
|
665
1014
|
fetchStatus: "idle"
|
|
666
1015
|
}), r.abort();
|
|
667
1016
|
},
|
|
668
|
-
onFail: (l,
|
|
669
|
-
|
|
1017
|
+
onFail: (l, x) => {
|
|
1018
|
+
m(this, H, W).call(this, {
|
|
1019
|
+
type: "failed",
|
|
1020
|
+
failureCount: l,
|
|
1021
|
+
error: x
|
|
1022
|
+
});
|
|
670
1023
|
},
|
|
671
1024
|
onPause: () => {
|
|
672
|
-
|
|
1025
|
+
m(this, H, W).call(this, { type: "pause" });
|
|
673
1026
|
},
|
|
674
1027
|
onContinue: () => {
|
|
675
|
-
|
|
1028
|
+
m(this, H, W).call(this, { type: "continue" });
|
|
676
1029
|
},
|
|
677
1030
|
retry: u.options.retry,
|
|
678
1031
|
retryDelay: u.options.retryDelay,
|
|
@@ -680,47 +1033,27 @@ var lt, xe, ze = (xe = class {
|
|
|
680
1033
|
canRun: () => !0
|
|
681
1034
|
}));
|
|
682
1035
|
try {
|
|
683
|
-
const l = await
|
|
1036
|
+
const l = await d.start();
|
|
684
1037
|
if (l === void 0)
|
|
685
|
-
throw process.env.NODE_ENV !== "production" && console.error(
|
|
686
|
-
|
|
687
|
-
), new Error(`${this.queryHash} data is undefined`);
|
|
688
|
-
return this.setData(l), (y = (C = i(this, k).config).onSuccess) == null || y.call(C, l, this), (v = (P = i(this, k).config).onSettled) == null || v.call(
|
|
689
|
-
P,
|
|
690
|
-
l,
|
|
691
|
-
this.state.error,
|
|
692
|
-
this
|
|
693
|
-
), l;
|
|
1038
|
+
throw process.env.NODE_ENV !== "production" && console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`), new Error(`${this.queryHash} data is undefined`);
|
|
1039
|
+
return this.setData(l), (D = (R = i(this, _).config).onSuccess) == null || D.call(R, l, this), (q = (O = i(this, _).config).onSettled) == null || q.call(O, l, this.state.error, this), l;
|
|
694
1040
|
} catch (l) {
|
|
695
|
-
if (l instanceof
|
|
696
|
-
if (l.silent)
|
|
697
|
-
return i(this, T).promise;
|
|
1041
|
+
if (l instanceof Jt) {
|
|
1042
|
+
if (l.silent) return i(this, T).promise;
|
|
698
1043
|
if (l.revert) {
|
|
699
|
-
if (this.state.data === void 0)
|
|
700
|
-
throw l;
|
|
1044
|
+
if (this.state.data === void 0) throw l;
|
|
701
1045
|
return this.state.data;
|
|
702
1046
|
}
|
|
703
1047
|
}
|
|
704
|
-
throw
|
|
1048
|
+
throw m(this, H, W).call(this, {
|
|
705
1049
|
type: "error",
|
|
706
1050
|
error: l
|
|
707
|
-
}), (S = (b = i(this,
|
|
708
|
-
b,
|
|
709
|
-
l,
|
|
710
|
-
this
|
|
711
|
-
), (F = (R = i(this, k).config).onSettled) == null || F.call(
|
|
712
|
-
R,
|
|
713
|
-
this.state.data,
|
|
714
|
-
l,
|
|
715
|
-
this
|
|
716
|
-
), l;
|
|
1051
|
+
}), (g = (M = i(this, _).config).onError) == null || g.call(M, l, this), (S = (b = i(this, _).config).onSettled) == null || S.call(b, this.state.data, l, this), l;
|
|
717
1052
|
} finally {
|
|
718
|
-
this.scheduleGc();
|
|
1053
|
+
i(this, T) === d && o(this, T, void 0), this.scheduleGc();
|
|
719
1054
|
}
|
|
720
1055
|
}
|
|
721
|
-
},
|
|
722
|
-
return this.state.fetchStatus === "paused" && this.state.status === "pending";
|
|
723
|
-
}, $ = function(t) {
|
|
1056
|
+
}, bt = new WeakMap(), ht = new WeakMap(), wt = new WeakMap(), _ = new WeakMap(), ct = new WeakMap(), T = new WeakMap(), qt = new WeakMap(), lt = new WeakMap(), H = new WeakSet(), W = function(t) {
|
|
724
1057
|
const s = (r) => {
|
|
725
1058
|
switch (t.type) {
|
|
726
1059
|
case "failed":
|
|
@@ -742,13 +1075,13 @@ var lt, xe, ze = (xe = class {
|
|
|
742
1075
|
case "fetch":
|
|
743
1076
|
return {
|
|
744
1077
|
...r,
|
|
745
|
-
...
|
|
1078
|
+
...Ke(r.data, this.options),
|
|
746
1079
|
fetchMeta: t.meta ?? null
|
|
747
1080
|
};
|
|
748
1081
|
case "success":
|
|
749
1082
|
const n = {
|
|
750
1083
|
...r,
|
|
751
|
-
...
|
|
1084
|
+
...be(t.data, t.dataUpdatedAt),
|
|
752
1085
|
dataUpdateCount: r.dataUpdateCount + 1,
|
|
753
1086
|
...!t.manual && {
|
|
754
1087
|
fetchStatus: "idle",
|
|
@@ -756,7 +1089,7 @@ var lt, xe, ze = (xe = class {
|
|
|
756
1089
|
fetchFailureReason: null
|
|
757
1090
|
}
|
|
758
1091
|
};
|
|
759
|
-
return o(this,
|
|
1092
|
+
return o(this, wt, t.manual ? n : void 0), n;
|
|
760
1093
|
case "error":
|
|
761
1094
|
const a = t.error;
|
|
762
1095
|
return {
|
|
@@ -768,8 +1101,6 @@ var lt, xe, ze = (xe = class {
|
|
|
768
1101
|
fetchFailureReason: a,
|
|
769
1102
|
fetchStatus: "idle",
|
|
770
1103
|
status: "error",
|
|
771
|
-
// flag existing data as invalidated if we get a background error
|
|
772
|
-
// note that "no data" always means stale so we can set unconditionally here
|
|
773
1104
|
isInvalidated: !0
|
|
774
1105
|
};
|
|
775
1106
|
case "invalidate":
|
|
@@ -784,24 +1115,28 @@ var lt, xe, ze = (xe = class {
|
|
|
784
1115
|
};
|
|
785
1116
|
}
|
|
786
1117
|
};
|
|
787
|
-
this.state = s(this.state),
|
|
788
|
-
this.observers.forEach((r) => {
|
|
1118
|
+
this.state = s(this.state), A.batch(() => {
|
|
1119
|
+
this.observers.slice().forEach((r) => {
|
|
789
1120
|
r.onQueryUpdate();
|
|
790
|
-
}), i(this,
|
|
1121
|
+
}), i(this, _).notify({
|
|
1122
|
+
query: this,
|
|
1123
|
+
type: "updated",
|
|
1124
|
+
action: t
|
|
1125
|
+
});
|
|
791
1126
|
});
|
|
792
|
-
},
|
|
793
|
-
function
|
|
1127
|
+
}, Re);
|
|
1128
|
+
function Ke(e, t) {
|
|
794
1129
|
return {
|
|
795
1130
|
fetchFailureCount: 0,
|
|
796
1131
|
fetchFailureReason: null,
|
|
797
|
-
fetchStatus:
|
|
1132
|
+
fetchStatus: ke(t.networkMode) ? "fetching" : "paused",
|
|
798
1133
|
...e === void 0 && {
|
|
799
1134
|
error: null,
|
|
800
1135
|
status: "pending"
|
|
801
1136
|
}
|
|
802
1137
|
};
|
|
803
1138
|
}
|
|
804
|
-
function
|
|
1139
|
+
function be(e, t) {
|
|
805
1140
|
return {
|
|
806
1141
|
data: e,
|
|
807
1142
|
dataUpdatedAt: t ?? Date.now(),
|
|
@@ -810,7 +1145,7 @@ function Pe(e, t) {
|
|
|
810
1145
|
status: "success"
|
|
811
1146
|
};
|
|
812
1147
|
}
|
|
813
|
-
function
|
|
1148
|
+
function we(e) {
|
|
814
1149
|
const t = typeof e.initialData == "function" ? e.initialData() : e.initialData, s = t !== void 0, r = s ? typeof e.initialDataUpdatedAt == "function" ? e.initialDataUpdatedAt() : e.initialDataUpdatedAt : 0;
|
|
815
1150
|
return {
|
|
816
1151
|
data: t,
|
|
@@ -827,539 +1162,496 @@ function Ee(e) {
|
|
|
827
1162
|
fetchStatus: "idle"
|
|
828
1163
|
};
|
|
829
1164
|
}
|
|
830
|
-
var
|
|
1165
|
+
var N, v, At, j, dt, St, J, It, Ct, Ot, ft, yt, et, Pt, w, Tt, Zt, Xt, Yt, te, ee, se, re, ie, Me, ys = (Me = class extends Nt {
|
|
831
1166
|
constructor(t, s) {
|
|
832
1167
|
super();
|
|
833
|
-
c(this,
|
|
834
|
-
c(this,
|
|
835
|
-
c(this,
|
|
836
|
-
c(this,
|
|
837
|
-
c(this,
|
|
838
|
-
c(this,
|
|
1168
|
+
c(this, w);
|
|
1169
|
+
c(this, N);
|
|
1170
|
+
c(this, v);
|
|
1171
|
+
c(this, At);
|
|
1172
|
+
c(this, j);
|
|
1173
|
+
c(this, dt);
|
|
1174
|
+
c(this, St);
|
|
1175
|
+
c(this, J);
|
|
1176
|
+
c(this, It);
|
|
1177
|
+
c(this, Ct);
|
|
839
1178
|
c(this, Ot);
|
|
840
|
-
c(this,
|
|
841
|
-
c(this,
|
|
842
|
-
c(this,
|
|
843
|
-
c(this, Pt);
|
|
844
|
-
|
|
845
|
-
// It will be used to pass the previous data and query to the placeholder function between renders.
|
|
846
|
-
c(this, Et);
|
|
847
|
-
c(this, mt);
|
|
848
|
-
c(this, vt);
|
|
849
|
-
c(this, rt);
|
|
850
|
-
c(this, Ft, /* @__PURE__ */ new Set());
|
|
851
|
-
this.options = s, o(this, U, t), o(this, st, null), o(this, W, re()), this.bindMethods(), this.setOptions(s);
|
|
1179
|
+
c(this, ft);
|
|
1180
|
+
c(this, yt);
|
|
1181
|
+
c(this, et);
|
|
1182
|
+
c(this, Pt, /* @__PURE__ */ new Set());
|
|
1183
|
+
this.options = s, o(this, N, t), o(this, J, null), this.bindMethods(), this.setOptions(s);
|
|
852
1184
|
}
|
|
853
1185
|
bindMethods() {
|
|
854
1186
|
this.refetch = this.refetch.bind(this);
|
|
855
1187
|
}
|
|
856
1188
|
onSubscribe() {
|
|
857
|
-
this.listeners.size === 1 && (i(this,
|
|
1189
|
+
this.listeners.size === 1 && (i(this, v).addObserver(this), Se(i(this, v), this.options) ? m(this, w, Tt).call(this) : this.updateResult(), m(this, w, ee).call(this));
|
|
858
1190
|
}
|
|
859
1191
|
onUnsubscribe() {
|
|
860
1192
|
this.hasListeners() || this.destroy();
|
|
861
1193
|
}
|
|
1194
|
+
/**
|
|
1195
|
+
* Returns whether the observed query is currently stale and configured
|
|
1196
|
+
* (via the `refetchOnReconnect` option) to refetch when the network
|
|
1197
|
+
* reconnects.
|
|
1198
|
+
*/
|
|
862
1199
|
shouldFetchOnReconnect() {
|
|
863
|
-
return
|
|
864
|
-
i(this, g),
|
|
865
|
-
this.options,
|
|
866
|
-
this.options.refetchOnReconnect
|
|
867
|
-
);
|
|
1200
|
+
return ne(i(this, v), this.options, this.options.refetchOnReconnect);
|
|
868
1201
|
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Returns whether the observed query is currently stale and configured
|
|
1204
|
+
* (via the `refetchOnWindowFocus` option) to refetch when the window
|
|
1205
|
+
* regains focus.
|
|
1206
|
+
*/
|
|
869
1207
|
shouldFetchOnWindowFocus() {
|
|
870
|
-
return
|
|
871
|
-
i(this, g),
|
|
872
|
-
this.options,
|
|
873
|
-
this.options.refetchOnWindowFocus
|
|
874
|
-
);
|
|
1208
|
+
return ne(i(this, v), this.options, this.options.refetchOnWindowFocus);
|
|
875
1209
|
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Stops observing the current query: clears all listeners, cancels the
|
|
1212
|
+
* stale and refetch-interval timers, and removes this observer from the
|
|
1213
|
+
* query it was observing.
|
|
1214
|
+
*/
|
|
876
1215
|
destroy() {
|
|
877
|
-
this.listeners = /* @__PURE__ */ new Set(),
|
|
1216
|
+
this.listeners = /* @__PURE__ */ new Set(), m(this, w, se).call(this), m(this, w, re).call(this), i(this, v).removeObserver(this);
|
|
878
1217
|
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Updates the observer's options. This will re-resolve the query being
|
|
1220
|
+
* observed (switching to a different query if the `queryKey` changed),
|
|
1221
|
+
* trigger a fetch if the new options require one and the observer has
|
|
1222
|
+
* subscribers, recompute the current result, and reschedule the stale and
|
|
1223
|
+
* refetch-interval timers as needed.
|
|
1224
|
+
*
|
|
1225
|
+
* @example
|
|
1226
|
+
* ```ts
|
|
1227
|
+
* observer.setOptions({ queryKey: ['posts', 1], queryFn: () => fetchPost(1) })
|
|
1228
|
+
* // later: switch to a different query, reusing the same observer
|
|
1229
|
+
* observer.setOptions({ queryKey: ['posts', 2], queryFn: () => fetchPost(2) })
|
|
1230
|
+
* ```
|
|
1231
|
+
*/
|
|
879
1232
|
setOptions(t) {
|
|
880
|
-
const s = this.options, r = i(this,
|
|
881
|
-
if (this.options = i(this,
|
|
882
|
-
|
|
883
|
-
"Expected enabled to be a boolean or a callback that returns a boolean"
|
|
884
|
-
);
|
|
885
|
-
p(this, O, le).call(this), i(this, g).setOptions(this.options), s._defaulted && !te(this.options, s) && i(this, U).getQueryCache().notify({
|
|
1233
|
+
const s = this.options, r = i(this, v);
|
|
1234
|
+
if (this.options = i(this, N).defaultQueryOptions(t), this.options.enabled !== void 0 && typeof this.options.enabled != "boolean" && typeof this.options.enabled != "function" && typeof P(this.options.enabled, i(this, v)) != "boolean") throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");
|
|
1235
|
+
m(this, w, ie).call(this), i(this, v).setOptions(this.options), s._defaulted && !Vt(this.options, s) && i(this, N).getQueryCache().notify({
|
|
886
1236
|
type: "observerOptionsUpdated",
|
|
887
|
-
query: i(this,
|
|
1237
|
+
query: i(this, v),
|
|
888
1238
|
observer: this
|
|
889
1239
|
});
|
|
890
1240
|
const n = this.hasListeners();
|
|
891
|
-
n &&
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
this.options,
|
|
895
|
-
s
|
|
896
|
-
) && p(this, O, Tt).call(this), this.updateResult(), n && (i(this, g) !== r || L(this.options.enabled, i(this, g)) !== L(s.enabled, i(this, g)) || ot(this.options.staleTime, i(this, g)) !== ot(s.staleTime, i(this, g))) && p(this, O, ne).call(this);
|
|
897
|
-
const a = p(this, O, ae).call(this);
|
|
898
|
-
n && (i(this, g) !== r || L(this.options.enabled, i(this, g)) !== L(s.enabled, i(this, g)) || a !== i(this, rt)) && p(this, O, oe).call(this, a);
|
|
1241
|
+
n && Ce(i(this, v), r, this.options, s) && m(this, w, Tt).call(this), this.updateResult(), n && (i(this, v) !== r || P(this.options.enabled, i(this, v)) !== P(s.enabled, i(this, v)) || P(this.options.staleTime, i(this, v)) !== P(s.staleTime, i(this, v))) && m(this, w, Xt).call(this);
|
|
1242
|
+
const a = m(this, w, Yt).call(this);
|
|
1243
|
+
n && (i(this, v) !== r || P(this.options.enabled, i(this, v)) !== P(s.enabled, i(this, v)) || a !== i(this, et)) && m(this, w, te).call(this, a);
|
|
899
1244
|
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Computes the result the observer would produce for the given (already-defaulted) options
|
|
1247
|
+
* right now, building the underlying `Query` if it doesn't exist yet, without waiting for a
|
|
1248
|
+
* subscription callback. Called by framework adapters on every render (e.g. `useQuery`) so the
|
|
1249
|
+
* returned value is available synchronously, ahead of `setOptions` triggering an actual fetch.
|
|
1250
|
+
*/
|
|
900
1251
|
getOptimisticResult(t) {
|
|
901
|
-
const s = i(this,
|
|
902
|
-
return
|
|
1252
|
+
const s = i(this, N).getQueryCache().build(i(this, N), t), r = this.createResult(s, t);
|
|
1253
|
+
return Vt(this.getCurrentResult(), r) || (o(this, j, r), o(this, St, this.options), o(this, dt, i(this, v).state)), r;
|
|
903
1254
|
}
|
|
1255
|
+
/**
|
|
1256
|
+
* Returns the most recently computed `QueryObserverResult` for the
|
|
1257
|
+
* observed query. This is a point-in-time read; to be notified of updates
|
|
1258
|
+
* as they happen, subscribe to the observer instead (its inherited
|
|
1259
|
+
* `subscribe` method).
|
|
1260
|
+
*
|
|
1261
|
+
* @example
|
|
1262
|
+
* ```ts
|
|
1263
|
+
* const result = observer.getCurrentResult()
|
|
1264
|
+
* console.log(result.status, result.data)
|
|
1265
|
+
* ```
|
|
1266
|
+
*/
|
|
904
1267
|
getCurrentResult() {
|
|
905
|
-
return i(this,
|
|
1268
|
+
return i(this, j);
|
|
906
1269
|
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Wraps a `QueryObserverResult` in a `Proxy` that records which properties are read, via
|
|
1272
|
+
* {@link QueryObserver#trackProp} (and an optional `onPropTracked` callback). Used by framework
|
|
1273
|
+
* adapters when `notifyOnChangeProps` is not set, to implement its default "only re-render on
|
|
1274
|
+
* properties you actually read" behavior.
|
|
1275
|
+
*/
|
|
907
1276
|
trackResult(t, s) {
|
|
908
|
-
return new Proxy(t, {
|
|
909
|
-
get: (r, n) => (this.trackProp(n), s == null || s(n), n === "promise" && (this.trackProp("data"), !this.options.experimental_prefetchInRender && i(this, W).status === "pending" && i(this, W).reject(
|
|
910
|
-
new Error(
|
|
911
|
-
"experimental_prefetchInRender feature flag is not enabled"
|
|
912
|
-
)
|
|
913
|
-
)), Reflect.get(r, n))
|
|
914
|
-
});
|
|
1277
|
+
return new Proxy(t, { get: (r, n) => (this.trackProp(n), s == null || s(n), Reflect.get(r, n)) });
|
|
915
1278
|
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Records that the given `QueryObserverResult` property was read, so a subsequent update only
|
|
1281
|
+
* notifies this observer if a tracked property actually changed. Normally called indirectly via
|
|
1282
|
+
* {@link QueryObserver#trackResult}'s proxy; exposed directly for adapters that track property
|
|
1283
|
+
* access themselves (e.g. through their own reactivity system) instead of via the proxy.
|
|
1284
|
+
*/
|
|
916
1285
|
trackProp(t) {
|
|
917
|
-
i(this,
|
|
1286
|
+
i(this, Pt).add(t);
|
|
918
1287
|
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Returns the `Query` instance this observer is currently observing.
|
|
1290
|
+
*/
|
|
919
1291
|
getCurrentQuery() {
|
|
920
|
-
return i(this,
|
|
1292
|
+
return i(this, v);
|
|
921
1293
|
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Refetches the observed query and returns a promise that resolves with
|
|
1296
|
+
* the resulting `QueryObserverResult`.
|
|
1297
|
+
*
|
|
1298
|
+
* @example
|
|
1299
|
+
* ```ts
|
|
1300
|
+
* const result = await observer.refetch({ cancelRefetch: false })
|
|
1301
|
+
* console.log(result.data)
|
|
1302
|
+
* ```
|
|
1303
|
+
*/
|
|
922
1304
|
refetch({ ...t } = {}) {
|
|
923
|
-
return this.fetch({
|
|
924
|
-
...t
|
|
925
|
-
});
|
|
1305
|
+
return this.fetch({ ...t });
|
|
926
1306
|
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Fetches a query defined by the given options without affecting this
|
|
1309
|
+
* observer's own tracked query or result, and returns a promise that
|
|
1310
|
+
* resolves with the `QueryObserverResult` for that fetch. This is useful
|
|
1311
|
+
* for prefetching data that another observer (e.g. a query about to be
|
|
1312
|
+
* navigated to) will need, ahead of time.
|
|
1313
|
+
*
|
|
1314
|
+
* @example
|
|
1315
|
+
* ```ts
|
|
1316
|
+
* const result = await observer.fetchOptimistic({
|
|
1317
|
+
* queryKey: ['posts', 2],
|
|
1318
|
+
* queryFn: () => fetchPost(2),
|
|
1319
|
+
* })
|
|
1320
|
+
* console.log(result.data)
|
|
1321
|
+
* ```
|
|
1322
|
+
*/
|
|
927
1323
|
fetchOptimistic(t) {
|
|
928
|
-
const s = i(this,
|
|
929
|
-
|
|
1324
|
+
const s = i(this, N).defaultQueryOptions(t), r = i(this, N).getQueryCache().build(i(this, N), s);
|
|
1325
|
+
let n = () => {
|
|
1326
|
+
}, a;
|
|
1327
|
+
const h = new Promise((u) => {
|
|
1328
|
+
a = u, n = i(this, N).getQueryCache().subscribe((d) => {
|
|
1329
|
+
d.type === "updated" && d.query.queryHash === r.queryHash && r.state.data !== void 0 && (n(), u(this.createResult(r, s)));
|
|
1330
|
+
});
|
|
1331
|
+
});
|
|
1332
|
+
return Promise.race([r.fetch().then(() => {
|
|
1333
|
+
const u = this.createResult(r, s);
|
|
1334
|
+
return a == null || a(u), u;
|
|
1335
|
+
}).finally(() => {
|
|
1336
|
+
n();
|
|
1337
|
+
}), h]);
|
|
930
1338
|
}
|
|
931
1339
|
fetch(t) {
|
|
932
|
-
return
|
|
1340
|
+
return m(this, w, Tt).call(this, {
|
|
933
1341
|
...t,
|
|
934
1342
|
cancelRefetch: t.cancelRefetch ?? !0
|
|
935
|
-
}).then(() => (this.updateResult(), i(this,
|
|
1343
|
+
}).then(() => (this.updateResult(), i(this, j)));
|
|
936
1344
|
}
|
|
937
1345
|
createResult(t, s) {
|
|
938
|
-
var
|
|
939
|
-
const r = i(this,
|
|
940
|
-
let
|
|
1346
|
+
var x;
|
|
1347
|
+
const r = i(this, v), n = this.options, a = i(this, j), h = i(this, dt), u = i(this, St), d = t !== r ? t.state : i(this, At), { state: p } = t;
|
|
1348
|
+
let f = { ...p }, C = !1, y;
|
|
941
1349
|
if (s._optimisticResults) {
|
|
942
|
-
const
|
|
943
|
-
(
|
|
944
|
-
...
|
|
945
|
-
...
|
|
946
|
-
}), s._optimisticResults === "isRestoring" && (
|
|
1350
|
+
const Q = this.hasListeners(), K = !Q && Se(t, s), E = Q && Ce(t, r, s, n);
|
|
1351
|
+
(K || E) && (f = {
|
|
1352
|
+
...f,
|
|
1353
|
+
...Ke(p.data, t.options)
|
|
1354
|
+
}), s._optimisticResults === "isRestoring" && (f.fetchStatus = "idle");
|
|
947
1355
|
}
|
|
948
|
-
let { error:
|
|
949
|
-
y =
|
|
950
|
-
let
|
|
951
|
-
if (s.placeholderData !== void 0 && y === void 0 &&
|
|
952
|
-
let
|
|
953
|
-
a != null && a.isPlaceholderData && s.placeholderData === (u == null ? void 0 : u.placeholderData) ? (
|
|
954
|
-
(Q = i(this, Et)) == null ? void 0 : Q.state.data,
|
|
955
|
-
i(this, Et)
|
|
956
|
-
) : s.placeholderData, x !== void 0 && (b = "success", y = se(
|
|
957
|
-
a == null ? void 0 : a.data,
|
|
958
|
-
x,
|
|
959
|
-
s
|
|
960
|
-
), C = !0);
|
|
1356
|
+
let { error: R, errorUpdatedAt: D, status: O } = f;
|
|
1357
|
+
y = f.data;
|
|
1358
|
+
let q = !1;
|
|
1359
|
+
if (s.placeholderData !== void 0 && y === void 0 && O === "pending") {
|
|
1360
|
+
let Q;
|
|
1361
|
+
a != null && a.isPlaceholderData && s.placeholderData === (u == null ? void 0 : u.placeholderData) ? (Q = a.data, q = !0) : Q = typeof s.placeholderData == "function" ? s.placeholderData((x = i(this, Ot)) == null ? void 0 : x.state.data, i(this, Ot)) : s.placeholderData, Q !== void 0 && (O = "success", y = Wt(a == null ? void 0 : a.data, Q, s), C = !0);
|
|
961
1362
|
}
|
|
962
|
-
if (s.select && y !== void 0 && !
|
|
963
|
-
if (a && y === (h == null ? void 0 : h.data) && s.select === i(this,
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
status:
|
|
974
|
-
fetchStatus:
|
|
975
|
-
isPending:
|
|
976
|
-
isSuccess:
|
|
977
|
-
isError:
|
|
978
|
-
isInitialLoading:
|
|
979
|
-
isLoading:
|
|
1363
|
+
if (s.select && y !== void 0 && !q)
|
|
1364
|
+
if (a && y === (h == null ? void 0 : h.data) && s.select === i(this, It)) y = i(this, Ct);
|
|
1365
|
+
else try {
|
|
1366
|
+
o(this, It, s.select), y = s.select(y), y = Wt(a == null ? void 0 : a.data, y, s), o(this, Ct, y), o(this, J, null);
|
|
1367
|
+
} catch (Q) {
|
|
1368
|
+
o(this, J, Q);
|
|
1369
|
+
}
|
|
1370
|
+
else y === void 0 && o(this, J, null);
|
|
1371
|
+
i(this, J) && (R = i(this, J), y = i(this, Ct), D = Date.now(), O = "error", C = !1);
|
|
1372
|
+
const M = f.fetchStatus === "fetching", g = O === "pending", b = O === "error", S = g && M, l = y !== void 0;
|
|
1373
|
+
return {
|
|
1374
|
+
status: O,
|
|
1375
|
+
fetchStatus: f.fetchStatus,
|
|
1376
|
+
isPending: g,
|
|
1377
|
+
isSuccess: O === "success",
|
|
1378
|
+
isError: b,
|
|
1379
|
+
isInitialLoading: S,
|
|
1380
|
+
isLoading: S,
|
|
980
1381
|
data: y,
|
|
981
|
-
dataUpdatedAt:
|
|
982
|
-
error:
|
|
983
|
-
errorUpdatedAt:
|
|
984
|
-
failureCount:
|
|
985
|
-
failureReason:
|
|
986
|
-
errorUpdateCount:
|
|
1382
|
+
dataUpdatedAt: f.dataUpdatedAt,
|
|
1383
|
+
error: R,
|
|
1384
|
+
errorUpdatedAt: D,
|
|
1385
|
+
failureCount: f.fetchFailureCount,
|
|
1386
|
+
failureReason: f.fetchFailureReason,
|
|
1387
|
+
errorUpdateCount: f.errorUpdateCount,
|
|
987
1388
|
isFetched: t.isFetched(),
|
|
988
|
-
isFetchedAfterMount:
|
|
989
|
-
isFetching:
|
|
990
|
-
isRefetching:
|
|
991
|
-
isLoadingError:
|
|
992
|
-
isPaused:
|
|
1389
|
+
isFetchedAfterMount: f.dataUpdateCount > d.dataUpdateCount || f.errorUpdateCount > d.errorUpdateCount,
|
|
1390
|
+
isFetching: M,
|
|
1391
|
+
isRefetching: M && !g,
|
|
1392
|
+
isLoadingError: b && !l,
|
|
1393
|
+
isPaused: f.fetchStatus === "paused",
|
|
993
1394
|
isPlaceholderData: C,
|
|
994
|
-
isRefetchError:
|
|
995
|
-
isStale:
|
|
1395
|
+
isRefetchError: b && l,
|
|
1396
|
+
isStale: he(t, s),
|
|
996
1397
|
refetch: this.refetch,
|
|
997
|
-
|
|
998
|
-
isEnabled: L(s.enabled, t) !== !1
|
|
1398
|
+
isEnabled: P(s.enabled, t) !== !1
|
|
999
1399
|
};
|
|
1000
|
-
if (this.options.experimental_prefetchInRender) {
|
|
1001
|
-
const x = E.data !== void 0, X = E.status === "error" && !x, Lt = (Ht) => {
|
|
1002
|
-
X ? Ht.reject(E.error) : x && Ht.resolve(E.data);
|
|
1003
|
-
}, me = () => {
|
|
1004
|
-
const Ht = o(this, W, E.promise = re());
|
|
1005
|
-
Lt(Ht);
|
|
1006
|
-
}, Kt = i(this, W);
|
|
1007
|
-
switch (Kt.status) {
|
|
1008
|
-
case "pending":
|
|
1009
|
-
t.queryHash === r.queryHash && Lt(Kt);
|
|
1010
|
-
break;
|
|
1011
|
-
case "fulfilled":
|
|
1012
|
-
(X || E.data !== Kt.value) && me();
|
|
1013
|
-
break;
|
|
1014
|
-
case "rejected":
|
|
1015
|
-
(!X || E.error !== Kt.reason) && me();
|
|
1016
|
-
break;
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
return E;
|
|
1020
1400
|
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Recomputes and stores the current result from the current query/options, notifying listeners
|
|
1403
|
+
* if it changed. Framework adapters call this right after subscribing to make sure no query
|
|
1404
|
+
* update was missed in the gap between creating the observer and subscribing to it.
|
|
1405
|
+
*/
|
|
1021
1406
|
updateResult() {
|
|
1022
|
-
const t = i(this,
|
|
1023
|
-
if (o(this,
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
const
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
a ?? i(this, Ft)
|
|
1034
|
-
);
|
|
1035
|
-
return this.options.throwOnError && h.add("error"), Object.keys(i(this, q)).some((u) => {
|
|
1036
|
-
const f = u;
|
|
1037
|
-
return i(this, q)[f] !== t[f] && h.has(f);
|
|
1407
|
+
const t = i(this, j), s = this.createResult(i(this, v), this.options);
|
|
1408
|
+
if (o(this, dt, i(this, v).state), o(this, St, this.options), i(this, dt).data !== void 0 && o(this, Ot, i(this, v)), Vt(s, t)) return;
|
|
1409
|
+
o(this, j, s);
|
|
1410
|
+
const n = (() => {
|
|
1411
|
+
if (!t) return !0;
|
|
1412
|
+
const { notifyOnChangeProps: a } = this.options, h = typeof a == "function" ? a() : a;
|
|
1413
|
+
if (h === "all" || !h && !i(this, Pt).size) return !0;
|
|
1414
|
+
const u = new Set(h ?? i(this, Pt));
|
|
1415
|
+
return this.options.throwOnError && u.add("error"), Object.keys(i(this, j)).some((d) => {
|
|
1416
|
+
const p = d;
|
|
1417
|
+
return i(this, j)[p] !== t[p] && u.has(p);
|
|
1038
1418
|
});
|
|
1039
|
-
};
|
|
1040
|
-
|
|
1419
|
+
})();
|
|
1420
|
+
A.batch(() => {
|
|
1421
|
+
n && this.listeners.forEach((a) => {
|
|
1422
|
+
a(i(this, j));
|
|
1423
|
+
}), i(this, N).getQueryCache().notify({
|
|
1424
|
+
query: i(this, v),
|
|
1425
|
+
type: "observerResultsUpdated"
|
|
1426
|
+
});
|
|
1427
|
+
});
|
|
1041
1428
|
}
|
|
1429
|
+
/** @internal */
|
|
1042
1430
|
onQueryUpdate() {
|
|
1043
|
-
this.updateResult(), this.hasListeners() &&
|
|
1044
|
-
}
|
|
1045
|
-
},
|
|
1046
|
-
|
|
1047
|
-
let s = i(this,
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
);
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
},
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
},
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
return;
|
|
1080
|
-
const s = i(this, g);
|
|
1081
|
-
o(this, g, t), o(this, jt, t.state), this.hasListeners() && (s == null || s.removeObserver(this), t.addObserver(this));
|
|
1082
|
-
}, Je = function(t) {
|
|
1083
|
-
I.batch(() => {
|
|
1084
|
-
t.listeners && this.listeners.forEach((s) => {
|
|
1085
|
-
s(i(this, q));
|
|
1086
|
-
}), i(this, U).getQueryCache().notify({
|
|
1087
|
-
query: i(this, g),
|
|
1088
|
-
type: "observerResultsUpdated"
|
|
1089
|
-
});
|
|
1090
|
-
});
|
|
1091
|
-
}, je);
|
|
1092
|
-
function bs(e, t) {
|
|
1093
|
-
return L(t.enabled, e) !== !1 && e.state.data === void 0 && !(e.state.status === "error" && t.retryOnMount === !1);
|
|
1431
|
+
this.updateResult(), this.hasListeners() && m(this, w, ee).call(this);
|
|
1432
|
+
}
|
|
1433
|
+
}, N = new WeakMap(), v = new WeakMap(), At = new WeakMap(), j = new WeakMap(), dt = new WeakMap(), St = new WeakMap(), J = new WeakMap(), It = new WeakMap(), Ct = new WeakMap(), Ot = new WeakMap(), ft = new WeakMap(), yt = new WeakMap(), et = new WeakMap(), Pt = new WeakMap(), w = new WeakSet(), Tt = function(t) {
|
|
1434
|
+
m(this, w, ie).call(this);
|
|
1435
|
+
let s = i(this, v).fetch(this.options, t);
|
|
1436
|
+
return t != null && t.throwOnError || (s = s.catch(k)), s;
|
|
1437
|
+
}, Zt = function(t) {
|
|
1438
|
+
return !oe() && P(this.options.enabled, i(this, v)) !== !1 && xe(t);
|
|
1439
|
+
}, Xt = function() {
|
|
1440
|
+
m(this, w, se).call(this);
|
|
1441
|
+
const t = P(this.options.staleTime, i(this, v));
|
|
1442
|
+
if (i(this, j).isStale || !m(this, w, Zt).call(this, t)) return;
|
|
1443
|
+
const s = Ue(i(this, j).dataUpdatedAt, t) + 1;
|
|
1444
|
+
o(this, ft, nt.setTimeout(() => {
|
|
1445
|
+
i(this, j).isStale || this.updateResult();
|
|
1446
|
+
}, s));
|
|
1447
|
+
}, Yt = function() {
|
|
1448
|
+
return P(this.options.refetchInterval, i(this, v)) ?? !1;
|
|
1449
|
+
}, te = function(t) {
|
|
1450
|
+
m(this, w, re).call(this), o(this, et, t), !(i(this, et) === 0 || !m(this, w, Zt).call(this, i(this, et))) && o(this, yt, nt.setInterval(() => {
|
|
1451
|
+
(this.options.refetchIntervalInBackground || ue.isFocused()) && m(this, w, Tt).call(this);
|
|
1452
|
+
}, i(this, et)));
|
|
1453
|
+
}, ee = function() {
|
|
1454
|
+
m(this, w, Xt).call(this), m(this, w, te).call(this, m(this, w, Yt).call(this));
|
|
1455
|
+
}, se = function() {
|
|
1456
|
+
i(this, ft) !== void 0 && (nt.clearTimeout(i(this, ft)), o(this, ft, void 0));
|
|
1457
|
+
}, re = function() {
|
|
1458
|
+
i(this, yt) !== void 0 && (nt.clearInterval(i(this, yt)), o(this, yt, void 0));
|
|
1459
|
+
}, ie = function() {
|
|
1460
|
+
const t = i(this, N).getQueryCache().build(i(this, N), this.options);
|
|
1461
|
+
if (t === i(this, v)) return;
|
|
1462
|
+
const s = i(this, v);
|
|
1463
|
+
o(this, v, t), o(this, At, t.state), this.hasListeners() && (s == null || s.removeObserver(this), t.addObserver(this));
|
|
1464
|
+
}, Me);
|
|
1465
|
+
function ps(e, t) {
|
|
1466
|
+
return P(t.enabled, e) !== !1 && e.state.data === void 0 && !(e.state.status === "error" && P(t.retryOnMount, e) === !1);
|
|
1094
1467
|
}
|
|
1095
|
-
function
|
|
1096
|
-
return
|
|
1468
|
+
function Se(e, t) {
|
|
1469
|
+
return ps(e, t) || e.state.data !== void 0 && ne(e, t, t.refetchOnMount);
|
|
1097
1470
|
}
|
|
1098
|
-
function
|
|
1099
|
-
if (
|
|
1100
|
-
const r =
|
|
1101
|
-
return r === "always" || r !== !1 &&
|
|
1471
|
+
function ne(e, t, s) {
|
|
1472
|
+
if (P(t.enabled, e) !== !1 && P(t.staleTime, e) !== "static") {
|
|
1473
|
+
const r = P(s, e);
|
|
1474
|
+
return r === "always" || r !== !1 && he(e, t);
|
|
1102
1475
|
}
|
|
1103
1476
|
return !1;
|
|
1104
1477
|
}
|
|
1105
|
-
function
|
|
1106
|
-
return (e !== t ||
|
|
1107
|
-
}
|
|
1108
|
-
function pe(e, t) {
|
|
1109
|
-
return L(t.enabled, e) !== !1 && e.isStaleByTime(ot(t.staleTime, e));
|
|
1478
|
+
function Ce(e, t, s, r) {
|
|
1479
|
+
return (e !== t || P(r.enabled, e) === !1) && (!s.suspense || e.state.status !== "error") && he(e, s);
|
|
1110
1480
|
}
|
|
1111
|
-
function
|
|
1112
|
-
return
|
|
1481
|
+
function he(e, t) {
|
|
1482
|
+
return P(t.enabled, e) !== !1 && e.isStaleByTime(P(t.staleTime, e));
|
|
1113
1483
|
}
|
|
1114
|
-
|
|
1115
|
-
return {
|
|
1116
|
-
onFetch: (t, s) => {
|
|
1117
|
-
var w, d, C, y, P;
|
|
1118
|
-
const r = t.options, n = (C = (d = (w = t.fetchOptions) == null ? void 0 : w.meta) == null ? void 0 : d.fetchMore) == null ? void 0 : C.direction, a = ((y = t.state.data) == null ? void 0 : y.pages) || [], h = ((P = t.state.data) == null ? void 0 : P.pageParams) || [];
|
|
1119
|
-
let u = { pages: [], pageParams: [] }, f = 0;
|
|
1120
|
-
const m = async () => {
|
|
1121
|
-
let v = !1;
|
|
1122
|
-
const b = (F) => {
|
|
1123
|
-
ds(
|
|
1124
|
-
F,
|
|
1125
|
-
() => t.signal,
|
|
1126
|
-
() => v = !0
|
|
1127
|
-
);
|
|
1128
|
-
}, S = He(t.options, t.fetchOptions), R = async (F, l, D) => {
|
|
1129
|
-
if (v)
|
|
1130
|
-
return Promise.reject();
|
|
1131
|
-
if (l == null && F.pages.length)
|
|
1132
|
-
return Promise.resolve(F);
|
|
1133
|
-
const Z = (() => {
|
|
1134
|
-
const X = {
|
|
1135
|
-
client: t.client,
|
|
1136
|
-
queryKey: t.queryKey,
|
|
1137
|
-
pageParam: l,
|
|
1138
|
-
direction: D ? "backward" : "forward",
|
|
1139
|
-
meta: t.options.meta
|
|
1140
|
-
};
|
|
1141
|
-
return b(X), X;
|
|
1142
|
-
})(), E = await S(Z), { maxPages: Q } = t.options, x = D ? ls : cs;
|
|
1143
|
-
return {
|
|
1144
|
-
pages: x(F.pages, E, Q),
|
|
1145
|
-
pageParams: x(F.pageParams, l, Q)
|
|
1146
|
-
};
|
|
1147
|
-
};
|
|
1148
|
-
if (n && a.length) {
|
|
1149
|
-
const F = n === "backward", l = F ? Ss : De, D = {
|
|
1150
|
-
pages: a,
|
|
1151
|
-
pageParams: h
|
|
1152
|
-
}, j = l(r, D);
|
|
1153
|
-
u = await R(D, j, F);
|
|
1154
|
-
} else {
|
|
1155
|
-
const F = e ?? a.length;
|
|
1156
|
-
do {
|
|
1157
|
-
const l = f === 0 ? h[0] ?? r.initialPageParam : De(r, u);
|
|
1158
|
-
if (f > 0 && l == null)
|
|
1159
|
-
break;
|
|
1160
|
-
u = await R(u, l), f++;
|
|
1161
|
-
} while (f < F);
|
|
1162
|
-
}
|
|
1163
|
-
return u;
|
|
1164
|
-
};
|
|
1165
|
-
t.options.persister ? t.fetchFn = () => {
|
|
1166
|
-
var v, b;
|
|
1167
|
-
return (b = (v = t.options).persister) == null ? void 0 : b.call(
|
|
1168
|
-
v,
|
|
1169
|
-
m,
|
|
1170
|
-
{
|
|
1171
|
-
client: t.client,
|
|
1172
|
-
queryKey: t.queryKey,
|
|
1173
|
-
meta: t.options.meta,
|
|
1174
|
-
signal: t.signal
|
|
1175
|
-
},
|
|
1176
|
-
s
|
|
1177
|
-
);
|
|
1178
|
-
} : t.fetchFn = m;
|
|
1179
|
-
}
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
function De(e, { pages: t, pageParams: s }) {
|
|
1183
|
-
const r = t.length - 1;
|
|
1184
|
-
return t.length > 0 ? e.getNextPageParam(
|
|
1185
|
-
t[r],
|
|
1186
|
-
t,
|
|
1187
|
-
s[r],
|
|
1188
|
-
s
|
|
1189
|
-
) : void 0;
|
|
1190
|
-
}
|
|
1191
|
-
function Ss(e, { pages: t, pageParams: s }) {
|
|
1192
|
-
var r;
|
|
1193
|
-
return t.length > 0 ? (r = e.getPreviousPageParam) == null ? void 0 : r.call(e, t[0], t, s[0], s) : void 0;
|
|
1194
|
-
}
|
|
1195
|
-
var Nt, B, A, gt, V, Y, Ue, Cs = (Ue = class extends ze {
|
|
1484
|
+
var xt, V, I, pt, $, X, Qe, ms = (Qe = class extends Le {
|
|
1196
1485
|
constructor(t) {
|
|
1197
1486
|
super();
|
|
1487
|
+
c(this, $);
|
|
1488
|
+
c(this, xt);
|
|
1198
1489
|
c(this, V);
|
|
1199
|
-
c(this,
|
|
1200
|
-
c(this,
|
|
1201
|
-
|
|
1202
|
-
c(this, gt);
|
|
1203
|
-
o(this, Nt, t.client), this.mutationId = t.mutationId, o(this, A, t.mutationCache), o(this, B, []), this.state = t.state || Os(), this.setOptions(t.options), this.scheduleGc();
|
|
1490
|
+
c(this, I);
|
|
1491
|
+
c(this, pt);
|
|
1492
|
+
o(this, xt, t.client), this.mutationId = t.mutationId, o(this, I, t.mutationCache), o(this, V, []), this.state = t.state || vs(), this.setOptions(t.options), this.scheduleGc();
|
|
1204
1493
|
}
|
|
1494
|
+
/** @internal */
|
|
1205
1495
|
setOptions(t) {
|
|
1206
1496
|
this.options = t, this.updateGcTime(this.options.gcTime);
|
|
1207
1497
|
}
|
|
1498
|
+
/**
|
|
1499
|
+
* The `meta` object passed in the mutation's options, if any.
|
|
1500
|
+
*/
|
|
1208
1501
|
get meta() {
|
|
1209
1502
|
return this.options.meta;
|
|
1210
1503
|
}
|
|
1504
|
+
/** @internal */
|
|
1211
1505
|
addObserver(t) {
|
|
1212
|
-
i(this,
|
|
1506
|
+
i(this, V).includes(t) || (i(this, V).push(t), this.clearGcTimeout(), i(this, I).notify({
|
|
1213
1507
|
type: "observerAdded",
|
|
1214
1508
|
mutation: this,
|
|
1215
1509
|
observer: t
|
|
1216
1510
|
}));
|
|
1217
1511
|
}
|
|
1512
|
+
/** @internal */
|
|
1218
1513
|
removeObserver(t) {
|
|
1219
|
-
o(this,
|
|
1514
|
+
o(this, V, i(this, V).filter((s) => s !== t)), this.scheduleGc(), i(this, I).notify({
|
|
1220
1515
|
type: "observerRemoved",
|
|
1221
1516
|
mutation: this,
|
|
1222
1517
|
observer: t
|
|
1223
1518
|
});
|
|
1224
1519
|
}
|
|
1225
1520
|
optionalRemove() {
|
|
1226
|
-
i(this,
|
|
1521
|
+
i(this, V).length || (this.state.status === "pending" ? this.scheduleGc() : i(this, I).remove(this));
|
|
1227
1522
|
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Resumes a mutation that is currently paused or was restored from a
|
|
1525
|
+
* dehydrated, still-`pending` state.
|
|
1526
|
+
*
|
|
1527
|
+
* - If this mutation has an active retryer (it paused mid-attempt, e.g. due
|
|
1528
|
+
* to the network mode or scope-based queuing), its retryer is resumed.
|
|
1529
|
+
* - Otherwise, if the mutation's status is still `pending` (e.g. it was
|
|
1530
|
+
* dehydrated while an attempt was in flight and never got a retryer in
|
|
1531
|
+
* this instance), `execute` is called again with the last known variables.
|
|
1532
|
+
* - Otherwise the mutation has already settled and this resolves immediately
|
|
1533
|
+
* without running anything again.
|
|
1534
|
+
*
|
|
1535
|
+
* @example
|
|
1536
|
+
* ```ts
|
|
1537
|
+
* // typically driven by reconnect handling, e.g. queryClient.resumePausedMutations()
|
|
1538
|
+
* const mutation = mutationCache.find({ mutationKey: ['addPost'] })
|
|
1539
|
+
* await mutation?.continue()
|
|
1540
|
+
* ```
|
|
1541
|
+
*
|
|
1542
|
+
* @see {@link Mutation#execute}
|
|
1543
|
+
*/
|
|
1228
1544
|
continue() {
|
|
1229
1545
|
var t;
|
|
1230
|
-
return ((t = i(this,
|
|
1231
|
-
this.execute(this.state.variables);
|
|
1546
|
+
return ((t = i(this, pt)) == null ? void 0 : t.continue()) ?? (this.state.status === "pending" ? this.execute(this.state.variables) : Promise.resolve());
|
|
1232
1547
|
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Runs the mutation function for the given variables through a retryer, and
|
|
1550
|
+
* drives the mutation's state and lifecycle callbacks through to settlement.
|
|
1551
|
+
*
|
|
1552
|
+
* If this mutation's state is already `pending` when `execute` is called
|
|
1553
|
+
* (i.e. it was restored, still in-flight, from a dehydrated state), the
|
|
1554
|
+
* `onMutate` step is skipped and a `continue` action is dispatched to
|
|
1555
|
+
* unpause it; otherwise a `pending` action is dispatched first, then the
|
|
1556
|
+
* mutation cache's `onMutate` and the mutation's own `onMutate` option are
|
|
1557
|
+
* awaited in that order, and the resulting context is stored.
|
|
1558
|
+
*
|
|
1559
|
+
* The mutation function is then run (subject to `retry`/`retryDelay`/
|
|
1560
|
+
* `networkMode`, and to the mutation cache's scope-based serialization).
|
|
1561
|
+
* On success, the cache's `onSuccess`/`onSettled` callbacks run before the
|
|
1562
|
+
* mutation's own `onSuccess`/`onSettled` options, a `success` action is
|
|
1563
|
+
* dispatched, and the resolved data is returned. On failure, the same
|
|
1564
|
+
* cache-then-option ordering is used for `onError`/`onSettled`, but each of
|
|
1565
|
+
* those four callbacks is individually caught so that a throwing callback
|
|
1566
|
+
* cannot mask the original error; an `error` action is then dispatched and
|
|
1567
|
+
* the original error is re-thrown.
|
|
1568
|
+
*
|
|
1569
|
+
* @example
|
|
1570
|
+
* ```ts
|
|
1571
|
+
* // Called internally by `MutationObserver.mutate` and `Mutation.continue` —
|
|
1572
|
+
* // applications normally trigger mutations through those, not this method.
|
|
1573
|
+
* const data = await mutation.execute(variables)
|
|
1574
|
+
* ```
|
|
1575
|
+
*
|
|
1576
|
+
* @see {@link Mutation#continue}
|
|
1577
|
+
*/
|
|
1233
1578
|
async execute(t) {
|
|
1234
|
-
var
|
|
1579
|
+
var u, d, p, f, C, y, R, D, O, q, M, g, b, S, l, x, Q, K;
|
|
1235
1580
|
const s = () => {
|
|
1236
|
-
|
|
1581
|
+
m(this, $, X).call(this, { type: "continue" });
|
|
1237
1582
|
}, r = {
|
|
1238
|
-
client: i(this,
|
|
1583
|
+
client: i(this, xt),
|
|
1239
1584
|
meta: this.options.meta,
|
|
1240
1585
|
mutationKey: this.options.mutationKey
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1586
|
+
}, n = o(this, pt, _e({
|
|
1587
|
+
fn: () => this.options.mutationFn ? this.options.mutationFn(t, r) : Promise.reject(/* @__PURE__ */ new Error("No mutationFn found")),
|
|
1588
|
+
onFail: (E, U) => {
|
|
1589
|
+
m(this, $, X).call(this, {
|
|
1590
|
+
type: "failed",
|
|
1591
|
+
failureCount: E,
|
|
1592
|
+
error: U
|
|
1593
|
+
});
|
|
1246
1594
|
},
|
|
1247
1595
|
onPause: () => {
|
|
1248
|
-
|
|
1596
|
+
m(this, $, X).call(this, { type: "pause" });
|
|
1249
1597
|
},
|
|
1250
1598
|
onContinue: s,
|
|
1251
1599
|
retry: this.options.retry ?? 0,
|
|
1252
1600
|
retryDelay: this.options.retryDelay,
|
|
1253
1601
|
networkMode: this.options.networkMode,
|
|
1254
|
-
canRun: () => i(this,
|
|
1255
|
-
}));
|
|
1256
|
-
const n = this.state.status === "pending", a = !i(this, gt).canStart();
|
|
1602
|
+
canRun: () => i(this, I).canRun(this)
|
|
1603
|
+
})), a = this.state.status === "pending", h = !n.canStart();
|
|
1257
1604
|
try {
|
|
1258
|
-
if (
|
|
1259
|
-
s();
|
|
1605
|
+
if (a) s();
|
|
1260
1606
|
else {
|
|
1261
|
-
|
|
1262
|
-
t,
|
|
1263
|
-
this,
|
|
1264
|
-
r
|
|
1265
|
-
);
|
|
1266
|
-
const Q = await ((u = (h = this.options).onMutate) == null ? void 0 : u.call(
|
|
1267
|
-
h,
|
|
1268
|
-
t,
|
|
1269
|
-
r
|
|
1270
|
-
));
|
|
1271
|
-
Q !== this.state.context && p(this, V, Y).call(this, {
|
|
1607
|
+
m(this, $, X).call(this, {
|
|
1272
1608
|
type: "pending",
|
|
1273
|
-
context: Q,
|
|
1274
1609
|
variables: t,
|
|
1275
|
-
isPaused:
|
|
1610
|
+
isPaused: h
|
|
1611
|
+
}), i(this, I).config.onMutate && await i(this, I).config.onMutate(t, this, r);
|
|
1612
|
+
const U = await ((d = (u = this.options).onMutate) == null ? void 0 : d.call(u, t, r));
|
|
1613
|
+
U !== this.state.context && m(this, $, X).call(this, {
|
|
1614
|
+
type: "pending",
|
|
1615
|
+
context: U,
|
|
1616
|
+
variables: t,
|
|
1617
|
+
isPaused: h
|
|
1276
1618
|
});
|
|
1277
1619
|
}
|
|
1278
|
-
const E = await
|
|
1279
|
-
return await ((
|
|
1280
|
-
|
|
1281
|
-
E
|
|
1282
|
-
|
|
1283
|
-
this.state.context,
|
|
1284
|
-
this,
|
|
1285
|
-
r
|
|
1286
|
-
)), await ((d = (w = this.options).onSuccess) == null ? void 0 : d.call(
|
|
1287
|
-
w,
|
|
1288
|
-
E,
|
|
1289
|
-
t,
|
|
1290
|
-
this.state.context,
|
|
1291
|
-
r
|
|
1292
|
-
)), await ((y = (C = i(this, A).config).onSettled) == null ? void 0 : y.call(
|
|
1293
|
-
C,
|
|
1294
|
-
E,
|
|
1295
|
-
null,
|
|
1296
|
-
this.state.variables,
|
|
1297
|
-
this.state.context,
|
|
1298
|
-
this,
|
|
1299
|
-
r
|
|
1300
|
-
)), await ((v = (P = this.options).onSettled) == null ? void 0 : v.call(
|
|
1301
|
-
P,
|
|
1302
|
-
E,
|
|
1303
|
-
null,
|
|
1304
|
-
t,
|
|
1305
|
-
this.state.context,
|
|
1306
|
-
r
|
|
1307
|
-
)), p(this, V, Y).call(this, { type: "success", data: E }), E;
|
|
1620
|
+
const E = await n.start();
|
|
1621
|
+
return await ((f = (p = i(this, I).config).onSuccess) == null ? void 0 : f.call(p, E, t, this.state.context, this, r)), await ((y = (C = this.options).onSuccess) == null ? void 0 : y.call(C, E, t, this.state.context, r)), await ((D = (R = i(this, I).config).onSettled) == null ? void 0 : D.call(R, E, null, this.state.variables, this.state.context, this, r)), await ((q = (O = this.options).onSettled) == null ? void 0 : q.call(O, E, null, t, this.state.context, r)), m(this, $, X).call(this, {
|
|
1622
|
+
type: "success",
|
|
1623
|
+
data: E
|
|
1624
|
+
}), E;
|
|
1308
1625
|
} catch (E) {
|
|
1309
1626
|
try {
|
|
1310
|
-
await ((
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
t,
|
|
1314
|
-
this.state.context,
|
|
1315
|
-
this,
|
|
1316
|
-
r
|
|
1317
|
-
));
|
|
1318
|
-
} catch (Q) {
|
|
1319
|
-
Promise.reject(Q);
|
|
1627
|
+
await ((g = (M = i(this, I).config).onError) == null ? void 0 : g.call(M, E, t, this.state.context, this, r));
|
|
1628
|
+
} catch (U) {
|
|
1629
|
+
Promise.reject(U);
|
|
1320
1630
|
}
|
|
1321
1631
|
try {
|
|
1322
|
-
await ((
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
t,
|
|
1326
|
-
this.state.context,
|
|
1327
|
-
r
|
|
1328
|
-
));
|
|
1329
|
-
} catch (Q) {
|
|
1330
|
-
Promise.reject(Q);
|
|
1632
|
+
await ((S = (b = this.options).onError) == null ? void 0 : S.call(b, E, t, this.state.context, r));
|
|
1633
|
+
} catch (U) {
|
|
1634
|
+
Promise.reject(U);
|
|
1331
1635
|
}
|
|
1332
1636
|
try {
|
|
1333
|
-
await ((
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
E,
|
|
1337
|
-
this.state.variables,
|
|
1338
|
-
this.state.context,
|
|
1339
|
-
this,
|
|
1340
|
-
r
|
|
1341
|
-
));
|
|
1342
|
-
} catch (Q) {
|
|
1343
|
-
Promise.reject(Q);
|
|
1637
|
+
await ((x = (l = i(this, I).config).onSettled) == null ? void 0 : x.call(l, void 0, E, this.state.variables, this.state.context, this, r));
|
|
1638
|
+
} catch (U) {
|
|
1639
|
+
Promise.reject(U);
|
|
1344
1640
|
}
|
|
1345
1641
|
try {
|
|
1346
|
-
await ((
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
E,
|
|
1350
|
-
t,
|
|
1351
|
-
this.state.context,
|
|
1352
|
-
r
|
|
1353
|
-
));
|
|
1354
|
-
} catch (Q) {
|
|
1355
|
-
Promise.reject(Q);
|
|
1642
|
+
await ((K = (Q = this.options).onSettled) == null ? void 0 : K.call(Q, void 0, E, t, this.state.context, r));
|
|
1643
|
+
} catch (U) {
|
|
1644
|
+
Promise.reject(U);
|
|
1356
1645
|
}
|
|
1357
|
-
throw
|
|
1646
|
+
throw m(this, $, X).call(this, {
|
|
1647
|
+
type: "error",
|
|
1648
|
+
error: E
|
|
1649
|
+
}), E;
|
|
1358
1650
|
} finally {
|
|
1359
|
-
i(this,
|
|
1651
|
+
i(this, pt) === n && o(this, pt, void 0), i(this, I).runNext(this);
|
|
1360
1652
|
}
|
|
1361
1653
|
}
|
|
1362
|
-
},
|
|
1654
|
+
}, xt = new WeakMap(), V = new WeakMap(), I = new WeakMap(), pt = new WeakMap(), $ = new WeakSet(), X = function(t) {
|
|
1363
1655
|
const s = (r) => {
|
|
1364
1656
|
switch (t.type) {
|
|
1365
1657
|
case "failed":
|
|
@@ -1413,17 +1705,17 @@ var Nt, B, A, gt, V, Y, Ue, Cs = (Ue = class extends ze {
|
|
|
1413
1705
|
};
|
|
1414
1706
|
}
|
|
1415
1707
|
};
|
|
1416
|
-
this.state = s(this.state),
|
|
1417
|
-
i(this,
|
|
1708
|
+
this.state = s(this.state), A.batch(() => {
|
|
1709
|
+
i(this, V).forEach((r) => {
|
|
1418
1710
|
r.onMutationUpdate(t);
|
|
1419
|
-
}), i(this,
|
|
1711
|
+
}), i(this, I).notify({
|
|
1420
1712
|
mutation: this,
|
|
1421
1713
|
type: "updated",
|
|
1422
1714
|
action: t
|
|
1423
1715
|
});
|
|
1424
1716
|
});
|
|
1425
|
-
},
|
|
1426
|
-
function
|
|
1717
|
+
}, Qe);
|
|
1718
|
+
function vs() {
|
|
1427
1719
|
return {
|
|
1428
1720
|
context: void 0,
|
|
1429
1721
|
data: void 0,
|
|
@@ -1436,115 +1728,191 @@ function Os() {
|
|
|
1436
1728
|
submittedAt: 0
|
|
1437
1729
|
};
|
|
1438
1730
|
}
|
|
1439
|
-
var
|
|
1731
|
+
var Z, B, Ut, Te, gs = (Te = class extends Nt {
|
|
1440
1732
|
constructor(t = {}) {
|
|
1441
1733
|
super();
|
|
1442
|
-
c(this,
|
|
1443
|
-
c(this,
|
|
1444
|
-
c(this,
|
|
1445
|
-
this.config = t, o(this,
|
|
1734
|
+
c(this, Z);
|
|
1735
|
+
c(this, B);
|
|
1736
|
+
c(this, Ut);
|
|
1737
|
+
this.config = t, o(this, Z, /* @__PURE__ */ new Set()), o(this, B, /* @__PURE__ */ new Map()), o(this, Ut, 0);
|
|
1446
1738
|
}
|
|
1739
|
+
/** @internal */
|
|
1447
1740
|
build(t, s, r) {
|
|
1448
|
-
const n = new
|
|
1741
|
+
const n = new ms({
|
|
1449
1742
|
client: t,
|
|
1450
1743
|
mutationCache: this,
|
|
1451
|
-
mutationId: ++
|
|
1744
|
+
mutationId: ++jt(this, Ut)._,
|
|
1452
1745
|
options: t.defaultMutationOptions(s),
|
|
1453
1746
|
state: r
|
|
1454
1747
|
});
|
|
1455
1748
|
return this.add(n), n;
|
|
1456
1749
|
}
|
|
1750
|
+
/** @internal */
|
|
1457
1751
|
add(t) {
|
|
1458
|
-
i(this,
|
|
1459
|
-
const s =
|
|
1752
|
+
i(this, Z).add(t);
|
|
1753
|
+
const s = _t(t);
|
|
1460
1754
|
if (typeof s == "string") {
|
|
1461
|
-
const r = i(this,
|
|
1462
|
-
r ? r.push(t) : i(this,
|
|
1755
|
+
const r = i(this, B).get(s);
|
|
1756
|
+
r ? r.push(t) : i(this, B).set(s, [t]);
|
|
1463
1757
|
}
|
|
1464
|
-
this.notify({
|
|
1758
|
+
this.notify({
|
|
1759
|
+
type: "added",
|
|
1760
|
+
mutation: t
|
|
1761
|
+
});
|
|
1465
1762
|
}
|
|
1763
|
+
/** @internal */
|
|
1466
1764
|
remove(t) {
|
|
1467
|
-
if (i(this,
|
|
1468
|
-
const s =
|
|
1765
|
+
if (i(this, Z).delete(t)) {
|
|
1766
|
+
const s = _t(t);
|
|
1469
1767
|
if (typeof s == "string") {
|
|
1470
|
-
const r = i(this,
|
|
1768
|
+
const r = i(this, B).get(s);
|
|
1471
1769
|
if (r)
|
|
1472
1770
|
if (r.length > 1) {
|
|
1473
1771
|
const n = r.indexOf(t);
|
|
1474
1772
|
n !== -1 && r.splice(n, 1);
|
|
1475
|
-
} else r[0] === t && i(this,
|
|
1773
|
+
} else r[0] === t && i(this, B).delete(s);
|
|
1476
1774
|
}
|
|
1477
1775
|
}
|
|
1478
|
-
this.notify({
|
|
1776
|
+
this.notify({
|
|
1777
|
+
type: "removed",
|
|
1778
|
+
mutation: t
|
|
1779
|
+
});
|
|
1479
1780
|
}
|
|
1781
|
+
/** @internal */
|
|
1480
1782
|
canRun(t) {
|
|
1481
|
-
|
|
1783
|
+
var r;
|
|
1784
|
+
const s = _t(t);
|
|
1482
1785
|
if (typeof s == "string") {
|
|
1483
|
-
const r = i(this,
|
|
1484
|
-
(a) => a.state.status === "pending"
|
|
1485
|
-
);
|
|
1786
|
+
const n = (r = i(this, B).get(s)) == null ? void 0 : r.find((a) => a.state.status === "pending");
|
|
1486
1787
|
return !n || n === t;
|
|
1487
|
-
} else
|
|
1488
|
-
return !0;
|
|
1788
|
+
} else return !0;
|
|
1489
1789
|
}
|
|
1790
|
+
/** @internal */
|
|
1490
1791
|
runNext(t) {
|
|
1491
|
-
var r;
|
|
1492
|
-
const s =
|
|
1493
|
-
|
|
1494
|
-
const n = (r = i(this, H).get(s)) == null ? void 0 : r.find((a) => a !== t && a.state.isPaused);
|
|
1495
|
-
return (n == null ? void 0 : n.continue()) ?? Promise.resolve();
|
|
1496
|
-
} else
|
|
1497
|
-
return Promise.resolve();
|
|
1792
|
+
var r, n;
|
|
1793
|
+
const s = _t(t);
|
|
1794
|
+
return typeof s == "string" ? ((n = (r = i(this, B).get(s)) == null ? void 0 : r.find((a) => a !== t && a.state.isPaused)) == null ? void 0 : n.continue()) ?? Promise.resolve() : Promise.resolve();
|
|
1498
1795
|
}
|
|
1796
|
+
/**
|
|
1797
|
+
* Removes all mutations from the cache.
|
|
1798
|
+
*
|
|
1799
|
+
* @example
|
|
1800
|
+
* ```ts
|
|
1801
|
+
* const mutationCache = queryClient.getMutationCache()
|
|
1802
|
+
*
|
|
1803
|
+
* mutationCache.clear()
|
|
1804
|
+
* ```
|
|
1805
|
+
*/
|
|
1499
1806
|
clear() {
|
|
1500
|
-
|
|
1501
|
-
i(this,
|
|
1502
|
-
this.notify({
|
|
1503
|
-
|
|
1807
|
+
A.batch(() => {
|
|
1808
|
+
i(this, Z).forEach((t) => {
|
|
1809
|
+
this.notify({
|
|
1810
|
+
type: "removed",
|
|
1811
|
+
mutation: t
|
|
1812
|
+
});
|
|
1813
|
+
}), i(this, Z).clear(), i(this, B).clear();
|
|
1504
1814
|
});
|
|
1505
1815
|
}
|
|
1816
|
+
/**
|
|
1817
|
+
* Returns all mutations within the cache.
|
|
1818
|
+
*
|
|
1819
|
+
* This is not typically needed for most applications, but can come in handy when needing more
|
|
1820
|
+
* information about a mutation in rare scenarios.
|
|
1821
|
+
*
|
|
1822
|
+
* @example
|
|
1823
|
+
* ```ts
|
|
1824
|
+
* const mutationCache = queryClient.getMutationCache()
|
|
1825
|
+
*
|
|
1826
|
+
* const mutations = mutationCache.getAll()
|
|
1827
|
+
* ```
|
|
1828
|
+
*/
|
|
1506
1829
|
getAll() {
|
|
1507
|
-
return Array.from(i(this,
|
|
1830
|
+
return Array.from(i(this, Z));
|
|
1508
1831
|
}
|
|
1832
|
+
/**
|
|
1833
|
+
* A slightly more advanced method that can be used to get an existing mutation instance from
|
|
1834
|
+
* the cache. If the mutation does not exist, `undefined` is returned.
|
|
1835
|
+
*
|
|
1836
|
+
* This is not typically needed for most applications, but can come in handy when needing more
|
|
1837
|
+
* information about a mutation in rare scenarios.
|
|
1838
|
+
*
|
|
1839
|
+
* @see {@link MutationCache#findAll}
|
|
1840
|
+
* @example
|
|
1841
|
+
* ```ts
|
|
1842
|
+
* const mutationCache = queryClient.getMutationCache()
|
|
1843
|
+
*
|
|
1844
|
+
* const mutation = mutationCache.find({ mutationKey: ['addPost'] })
|
|
1845
|
+
* ```
|
|
1846
|
+
*/
|
|
1509
1847
|
find(t) {
|
|
1510
|
-
const s = {
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1848
|
+
const s = {
|
|
1849
|
+
exact: !0,
|
|
1850
|
+
...t
|
|
1851
|
+
};
|
|
1852
|
+
return this.getAll().find((r) => pe(s, r));
|
|
1514
1853
|
}
|
|
1854
|
+
/**
|
|
1855
|
+
* An even more advanced method that can be used to get existing mutation instances from the
|
|
1856
|
+
* cache that match the given filters. If no mutations match, an empty array is returned.
|
|
1857
|
+
*
|
|
1858
|
+
* This is not typically needed for most applications, but can come in handy when needing more
|
|
1859
|
+
* information about mutations in rare scenarios.
|
|
1860
|
+
*
|
|
1861
|
+
* @see {@link MutationCache#find}
|
|
1862
|
+
* @example
|
|
1863
|
+
* ```ts
|
|
1864
|
+
* const mutationCache = queryClient.getMutationCache()
|
|
1865
|
+
*
|
|
1866
|
+
* const mutations = mutationCache.findAll({ mutationKey: ['addPost'] })
|
|
1867
|
+
* ```
|
|
1868
|
+
*/
|
|
1515
1869
|
findAll(t = {}) {
|
|
1516
|
-
return this.getAll().filter((s) =>
|
|
1870
|
+
return this.getAll().filter((s) => pe(t, s));
|
|
1517
1871
|
}
|
|
1872
|
+
/** @internal */
|
|
1518
1873
|
notify(t) {
|
|
1519
|
-
|
|
1874
|
+
A.batch(() => {
|
|
1520
1875
|
this.listeners.forEach((s) => {
|
|
1521
1876
|
s(t);
|
|
1522
1877
|
});
|
|
1523
1878
|
});
|
|
1524
1879
|
}
|
|
1880
|
+
/** @internal */
|
|
1525
1881
|
resumePausedMutations() {
|
|
1526
1882
|
const t = this.getAll().filter((s) => s.state.isPaused);
|
|
1527
|
-
return
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
);
|
|
1532
|
-
}
|
|
1533
|
-
}, J = new WeakMap(), H = new WeakMap(), _t = new WeakMap(), Ne);
|
|
1534
|
-
function Vt(e) {
|
|
1883
|
+
return A.batch(() => Promise.all(t.map((s) => s.continue().catch(k))));
|
|
1884
|
+
}
|
|
1885
|
+
}, Z = new WeakMap(), B = new WeakMap(), Ut = new WeakMap(), Te);
|
|
1886
|
+
function _t(e) {
|
|
1535
1887
|
var t;
|
|
1536
1888
|
return (t = e.options.scope) == null ? void 0 : t.id;
|
|
1537
1889
|
}
|
|
1538
|
-
var z,
|
|
1890
|
+
var z, De, bs = (De = class extends Nt {
|
|
1539
1891
|
constructor(t = {}) {
|
|
1540
1892
|
super();
|
|
1541
1893
|
c(this, z);
|
|
1542
1894
|
this.config = t, o(this, z, /* @__PURE__ */ new Map());
|
|
1543
1895
|
}
|
|
1896
|
+
/**
|
|
1897
|
+
* Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or
|
|
1898
|
+
* builds and adds a new one to the cache if none exists yet. Used by framework adapters and
|
|
1899
|
+
* plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing
|
|
1900
|
+
* the reactive `QueryObserver` machinery.
|
|
1901
|
+
*
|
|
1902
|
+
* @example
|
|
1903
|
+
* ```ts
|
|
1904
|
+
* const queryCache = queryClient.getQueryCache()
|
|
1905
|
+
*
|
|
1906
|
+
* const query = queryCache.build(queryClient, {
|
|
1907
|
+
* queryKey: ['posts'],
|
|
1908
|
+
* queryFn: fetchPosts,
|
|
1909
|
+
* })
|
|
1910
|
+
* ```
|
|
1911
|
+
*/
|
|
1544
1912
|
build(t, s, r) {
|
|
1545
|
-
const n = s.queryKey, a = s.queryHash ??
|
|
1913
|
+
const n = s.queryKey, a = s.queryHash ?? ae(n, s);
|
|
1546
1914
|
let h = this.get(a);
|
|
1547
|
-
return h || (h = new
|
|
1915
|
+
return h || (h = new fs({
|
|
1548
1916
|
client: t,
|
|
1549
1917
|
queryKey: n,
|
|
1550
1918
|
queryHash: a,
|
|
@@ -1553,424 +1921,826 @@ var z, _e, Es = (_e = class extends kt {
|
|
|
1553
1921
|
defaultOptions: t.getQueryDefaults(n)
|
|
1554
1922
|
}), this.add(h)), h;
|
|
1555
1923
|
}
|
|
1924
|
+
/** @internal */
|
|
1556
1925
|
add(t) {
|
|
1557
1926
|
i(this, z).has(t.queryHash) || (i(this, z).set(t.queryHash, t), this.notify({
|
|
1558
1927
|
type: "added",
|
|
1559
1928
|
query: t
|
|
1560
1929
|
}));
|
|
1561
1930
|
}
|
|
1931
|
+
/**
|
|
1932
|
+
* Destroys the given `Query` and removes it from the cache, notifying subscribers with a
|
|
1933
|
+
* `'removed'` event. A no-op if the query is no longer the one currently stored under its hash
|
|
1934
|
+
* (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror
|
|
1935
|
+
* removals across `QueryCache` instances.
|
|
1936
|
+
*
|
|
1937
|
+
* @example
|
|
1938
|
+
* ```ts
|
|
1939
|
+
* const queryCache = queryClient.getQueryCache()
|
|
1940
|
+
* const query = queryCache.find({ queryKey: ['posts'] })
|
|
1941
|
+
*
|
|
1942
|
+
* if (query) {
|
|
1943
|
+
* queryCache.remove(query)
|
|
1944
|
+
* }
|
|
1945
|
+
* ```
|
|
1946
|
+
*/
|
|
1562
1947
|
remove(t) {
|
|
1563
1948
|
const s = i(this, z).get(t.queryHash);
|
|
1564
|
-
s && (t.destroy(), s === t && i(this, z).delete(t.queryHash), this.notify({
|
|
1949
|
+
s && (t.destroy(), s === t && i(this, z).delete(t.queryHash), this.notify({
|
|
1950
|
+
type: "removed",
|
|
1951
|
+
query: t
|
|
1952
|
+
}));
|
|
1565
1953
|
}
|
|
1954
|
+
/**
|
|
1955
|
+
* Removes all queries from the cache.
|
|
1956
|
+
*
|
|
1957
|
+
* @example
|
|
1958
|
+
* ```ts
|
|
1959
|
+
* const queryCache = queryClient.getQueryCache()
|
|
1960
|
+
*
|
|
1961
|
+
* queryCache.clear()
|
|
1962
|
+
* ```
|
|
1963
|
+
*/
|
|
1566
1964
|
clear() {
|
|
1567
|
-
|
|
1965
|
+
A.batch(() => {
|
|
1568
1966
|
this.getAll().forEach((t) => {
|
|
1569
1967
|
this.remove(t);
|
|
1570
1968
|
});
|
|
1571
1969
|
});
|
|
1572
1970
|
}
|
|
1971
|
+
/**
|
|
1972
|
+
* Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none
|
|
1973
|
+
* exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather
|
|
1974
|
+
* than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash
|
|
1975
|
+
* to look up directly.
|
|
1976
|
+
*
|
|
1977
|
+
* @example
|
|
1978
|
+
* ```ts
|
|
1979
|
+
* const queryCache = queryClient.getQueryCache()
|
|
1980
|
+
* const queryHash = hashKey(['posts'])
|
|
1981
|
+
*
|
|
1982
|
+
* const query = queryCache.get(queryHash)
|
|
1983
|
+
* ```
|
|
1984
|
+
*/
|
|
1573
1985
|
get(t) {
|
|
1574
1986
|
return i(this, z).get(t);
|
|
1575
1987
|
}
|
|
1988
|
+
/**
|
|
1989
|
+
* Returns all queries within the cache.
|
|
1990
|
+
*
|
|
1991
|
+
* @example
|
|
1992
|
+
* ```ts
|
|
1993
|
+
* const queryCache = queryClient.getQueryCache()
|
|
1994
|
+
*
|
|
1995
|
+
* const queries = queryCache.getAll()
|
|
1996
|
+
* ```
|
|
1997
|
+
*/
|
|
1576
1998
|
getAll() {
|
|
1577
1999
|
return [...i(this, z).values()];
|
|
1578
2000
|
}
|
|
2001
|
+
/**
|
|
2002
|
+
* A slightly more advanced method that can be used to get an existing query instance from the
|
|
2003
|
+
* cache. This instance not only contains all the state for the query, but all of the instances,
|
|
2004
|
+
* and underlying guts of the query as well. If the query does not exist, `undefined` is
|
|
2005
|
+
* returned.
|
|
2006
|
+
*
|
|
2007
|
+
* This is not typically needed for most applications, but can come in handy when needing more
|
|
2008
|
+
* information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to
|
|
2009
|
+
* decide whether a query is fresh enough to be used as an initial value).
|
|
2010
|
+
*
|
|
2011
|
+
* @see {@link QueryCache#findAll}
|
|
2012
|
+
* @example
|
|
2013
|
+
* ```ts
|
|
2014
|
+
* const queryCache = queryClient.getQueryCache()
|
|
2015
|
+
*
|
|
2016
|
+
* const query = queryCache.find({ queryKey: ['posts'] })
|
|
2017
|
+
* ```
|
|
2018
|
+
*/
|
|
1579
2019
|
find(t) {
|
|
1580
|
-
const s = {
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
2020
|
+
const s = {
|
|
2021
|
+
exact: !0,
|
|
2022
|
+
...t
|
|
2023
|
+
};
|
|
2024
|
+
return this.getAll().find((r) => ye(s, r));
|
|
1584
2025
|
}
|
|
2026
|
+
/**
|
|
2027
|
+
* An even more advanced method that can be used to get existing query instances from the cache
|
|
2028
|
+
* that partially match a query key. If no queries match, an empty array is returned.
|
|
2029
|
+
*
|
|
2030
|
+
* This is not typically needed for most applications, but can come in handy when needing more
|
|
2031
|
+
* information about queries in rare scenarios.
|
|
2032
|
+
*
|
|
2033
|
+
* @see {@link QueryCache#find}
|
|
2034
|
+
* @example
|
|
2035
|
+
* ```ts
|
|
2036
|
+
* const queryCache = queryClient.getQueryCache()
|
|
2037
|
+
*
|
|
2038
|
+
* const queries = queryCache.findAll({ queryKey: ['posts'] })
|
|
2039
|
+
* ```
|
|
2040
|
+
*/
|
|
1585
2041
|
findAll(t = {}) {
|
|
1586
2042
|
const s = this.getAll();
|
|
1587
|
-
return Object.keys(t).length > 0 ? s.filter((r) =>
|
|
2043
|
+
return Object.keys(t).length > 0 ? s.filter((r) => ye(t, r)) : s;
|
|
1588
2044
|
}
|
|
2045
|
+
/** @internal */
|
|
1589
2046
|
notify(t) {
|
|
1590
|
-
|
|
2047
|
+
A.batch(() => {
|
|
1591
2048
|
this.listeners.forEach((s) => {
|
|
1592
2049
|
s(t);
|
|
1593
2050
|
});
|
|
1594
2051
|
});
|
|
1595
2052
|
}
|
|
2053
|
+
/** @internal */
|
|
1596
2054
|
onFocus() {
|
|
1597
|
-
|
|
2055
|
+
A.batch(() => {
|
|
1598
2056
|
this.getAll().forEach((t) => {
|
|
1599
2057
|
t.onFocus();
|
|
1600
2058
|
});
|
|
1601
2059
|
});
|
|
1602
2060
|
}
|
|
2061
|
+
/** @internal */
|
|
1603
2062
|
onOnline() {
|
|
1604
|
-
|
|
2063
|
+
A.batch(() => {
|
|
1605
2064
|
this.getAll().forEach((t) => {
|
|
1606
2065
|
t.onOnline();
|
|
1607
2066
|
});
|
|
1608
2067
|
});
|
|
1609
2068
|
}
|
|
1610
|
-
}, z = new WeakMap(),
|
|
2069
|
+
}, z = new WeakMap(), De), F, st, rt, Et, Ft, it, Rt, Mt, qe, ws = (qe = class {
|
|
1611
2070
|
constructor(e = {}) {
|
|
1612
|
-
c(this,
|
|
2071
|
+
c(this, F);
|
|
2072
|
+
c(this, st);
|
|
2073
|
+
c(this, rt);
|
|
2074
|
+
c(this, Et);
|
|
2075
|
+
c(this, Ft);
|
|
1613
2076
|
c(this, it);
|
|
1614
|
-
c(this, nt);
|
|
1615
2077
|
c(this, Rt);
|
|
1616
2078
|
c(this, Mt);
|
|
1617
|
-
|
|
1618
|
-
c(this, Dt);
|
|
1619
|
-
c(this, Qt);
|
|
1620
|
-
o(this, M, e.queryCache || new Es()), o(this, it, e.mutationCache || new Ps()), o(this, nt, e.defaultOptions || {}), o(this, Rt, /* @__PURE__ */ new Map()), o(this, Mt, /* @__PURE__ */ new Map()), o(this, at, 0);
|
|
2079
|
+
o(this, F, e.queryCache || new bs()), o(this, st, e.mutationCache || new gs()), o(this, rt, e.defaultOptions || {}), o(this, Et, /* @__PURE__ */ new Map()), o(this, Ft, /* @__PURE__ */ new Map()), o(this, it, 0);
|
|
1621
2080
|
}
|
|
2081
|
+
/**
|
|
2082
|
+
* Called by a framework adapter's `QueryClientProvider`-equivalent when it mounts, to start
|
|
2083
|
+
* listening for focus/online events and resume paused mutations. Ref-counted via an internal
|
|
2084
|
+
* mount count, so nested or multiple providers sharing the same `QueryClient` don't tear down
|
|
2085
|
+
* the shared listeners until the last one unmounts.
|
|
2086
|
+
*/
|
|
1622
2087
|
mount() {
|
|
1623
|
-
|
|
1624
|
-
e && (await this.resumePausedMutations(), i(this,
|
|
1625
|
-
})), o(this,
|
|
1626
|
-
e && (await this.resumePausedMutations(), i(this,
|
|
2088
|
+
jt(this, it)._++, i(this, it) === 1 && (o(this, Rt, ue.subscribe(async (e) => {
|
|
2089
|
+
e && (await this.resumePausedMutations(), i(this, F).onFocus());
|
|
2090
|
+
})), o(this, Mt, Ht.subscribe(async (e) => {
|
|
2091
|
+
e && (await this.resumePausedMutations(), i(this, F).onOnline());
|
|
1627
2092
|
})));
|
|
1628
2093
|
}
|
|
2094
|
+
/**
|
|
2095
|
+
* The inverse of {@link QueryClient#mount} — called by a framework adapter's
|
|
2096
|
+
* `QueryClientProvider`-equivalent when it unmounts. Only tears down the focus/online
|
|
2097
|
+
* listeners once the mount count returns to `0`.
|
|
2098
|
+
*/
|
|
1629
2099
|
unmount() {
|
|
1630
2100
|
var e, t;
|
|
1631
|
-
|
|
2101
|
+
jt(this, it)._--, i(this, it) === 0 && ((e = i(this, Rt)) == null || e.call(this), o(this, Rt, void 0), (t = i(this, Mt)) == null || t.call(this), o(this, Mt, void 0));
|
|
1632
2102
|
}
|
|
2103
|
+
/**
|
|
2104
|
+
* Returns the number of queries in the cache that are currently fetching, optionally
|
|
2105
|
+
* matching a set of filters. This includes background-fetching, loading new pages, and
|
|
2106
|
+
* loading more infinite query results.
|
|
2107
|
+
*
|
|
2108
|
+
* @example
|
|
2109
|
+
* ```ts
|
|
2110
|
+
* if (queryClient.isFetching()) {
|
|
2111
|
+
* console.log('At least one query is fetching!')
|
|
2112
|
+
* }
|
|
2113
|
+
* ```
|
|
2114
|
+
*/
|
|
1633
2115
|
isFetching(e) {
|
|
1634
|
-
return i(this,
|
|
2116
|
+
return i(this, F).findAll({
|
|
2117
|
+
...e,
|
|
2118
|
+
fetchStatus: "fetching"
|
|
2119
|
+
}).length;
|
|
1635
2120
|
}
|
|
2121
|
+
/**
|
|
2122
|
+
* Returns the number of mutations in the cache that are currently pending, optionally
|
|
2123
|
+
* matching a set of filters.
|
|
2124
|
+
*
|
|
2125
|
+
* @example
|
|
2126
|
+
* ```ts
|
|
2127
|
+
* if (queryClient.isMutating()) {
|
|
2128
|
+
* console.log('At least one mutation is pending!')
|
|
2129
|
+
* }
|
|
2130
|
+
* ```
|
|
2131
|
+
*/
|
|
1636
2132
|
isMutating(e) {
|
|
1637
|
-
return i(this,
|
|
2133
|
+
return i(this, st).findAll({
|
|
2134
|
+
...e,
|
|
2135
|
+
status: "pending"
|
|
2136
|
+
}).length;
|
|
1638
2137
|
}
|
|
1639
2138
|
/**
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
2139
|
+
* Imperative (non-reactive) way to retrieve data for a QueryKey.
|
|
2140
|
+
* Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.
|
|
2141
|
+
*
|
|
2142
|
+
* Hint: Do not use this function inside a component, because it won't receive updates.
|
|
2143
|
+
* Use `useQuery` to create a `QueryObserver` that subscribes to changes.
|
|
2144
|
+
*
|
|
2145
|
+
* @see {@link QueryClient#getQueriesData}
|
|
2146
|
+
*/
|
|
1646
2147
|
getQueryData(e) {
|
|
1647
2148
|
var s;
|
|
1648
2149
|
const t = this.defaultQueryOptions({ queryKey: e });
|
|
1649
|
-
return (s = i(this,
|
|
2150
|
+
return (s = i(this, F).get(t.queryHash)) == null ? void 0 : s.state.data;
|
|
1650
2151
|
}
|
|
2152
|
+
/**
|
|
2153
|
+
* @deprecated Use queryClient.query({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
|
|
2154
|
+
*/
|
|
1651
2155
|
ensureQueryData(e) {
|
|
1652
|
-
const t = this.defaultQueryOptions(e), s = i(this,
|
|
1653
|
-
return r === void 0 ? this.fetchQuery(e) : (e.revalidateIfStale && s.isStaleByTime(
|
|
2156
|
+
const t = this.defaultQueryOptions(e), s = i(this, F).build(this, t), r = s.state.data;
|
|
2157
|
+
return r === void 0 ? this.fetchQuery(e) : (e.revalidateIfStale && s.isStaleByTime(P(t.staleTime, s)) && this.prefetchQuery(t), Promise.resolve(r));
|
|
1654
2158
|
}
|
|
2159
|
+
/**
|
|
2160
|
+
* Imperative (non-reactive) way to retrieve the cached data of multiple queries at once.
|
|
2161
|
+
* Only queries matching the given filters are returned; if none match, an empty array is
|
|
2162
|
+
* returned.
|
|
2163
|
+
*
|
|
2164
|
+
* Because the matched queries can hold data of different shapes (e.g. a broad filter can match
|
|
2165
|
+
* queries with unrelated data types), the `TQueryFnData` generic defaults to `unknown` rather
|
|
2166
|
+
* than being inferred. Passing a more specific type is a convenience for call sites that know
|
|
2167
|
+
* every matched query holds the same shape — it is not checked against the actual cache
|
|
2168
|
+
* contents.
|
|
2169
|
+
*
|
|
2170
|
+
* @see {@link QueryClient#getQueryData}
|
|
2171
|
+
* @example
|
|
2172
|
+
* ```ts
|
|
2173
|
+
* const data = queryClient.getQueriesData({ queryKey: ['posts'] })
|
|
2174
|
+
* ```
|
|
2175
|
+
*/
|
|
1655
2176
|
getQueriesData(e) {
|
|
1656
|
-
return i(this,
|
|
1657
|
-
const r = s.data;
|
|
1658
|
-
return [t, r];
|
|
1659
|
-
});
|
|
2177
|
+
return i(this, F).findAll(e).map(({ queryKey: t, state: s }) => [t, s.data]);
|
|
1660
2178
|
}
|
|
2179
|
+
/**
|
|
2180
|
+
* Synchronous way to immediately update a query's cached data. If the updater (or the value
|
|
2181
|
+
* passed) resolves to `undefined`, the cache is left untouched and no query is created;
|
|
2182
|
+
* otherwise, if the query does not exist yet, it will be created. To update multiple queries
|
|
2183
|
+
* at once by partially matching query keys, use {@link QueryClient#setQueriesData} instead.
|
|
2184
|
+
*
|
|
2185
|
+
* Updates must be performed immutably: do not mutate `oldData`, or data previously retrieved
|
|
2186
|
+
* via {@link QueryClient#getQueryData}, in place.
|
|
2187
|
+
*
|
|
2188
|
+
* @param queryKey - The query key to set data for.
|
|
2189
|
+
* @param updater - Either the new data, or a function that receives the current data (which
|
|
2190
|
+
* may be `undefined`) and returns the new data.
|
|
2191
|
+
*
|
|
2192
|
+
* @example
|
|
2193
|
+
* ```ts
|
|
2194
|
+
* queryClient.setQueryData(['posts'], newPosts)
|
|
2195
|
+
*
|
|
2196
|
+
* // Or, using an updater function that receives the current data:
|
|
2197
|
+
* queryClient.setQueryData(['posts'], (oldPosts) => [...oldPosts, newPost])
|
|
2198
|
+
* ```
|
|
2199
|
+
*/
|
|
1661
2200
|
setQueryData(e, t, s) {
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
2201
|
+
var h;
|
|
2202
|
+
const r = this.defaultQueryOptions({ queryKey: e }), n = (h = i(this, F).get(r.queryHash)) == null ? void 0 : h.state.data, a = Ye(t, n);
|
|
2203
|
+
if (a !== void 0)
|
|
2204
|
+
return i(this, F).build(this, r).setData(a, {
|
|
2205
|
+
...s,
|
|
2206
|
+
manual: !0
|
|
2207
|
+
});
|
|
1667
2208
|
}
|
|
2209
|
+
/**
|
|
2210
|
+
* Synchronous way to immediately update the cached data of multiple queries at once, using
|
|
2211
|
+
* filters or partial query key matching. Only queries that already exist and match the given
|
|
2212
|
+
* filters are updated; no new cache entries are created. Internally this calls
|
|
2213
|
+
* {@link QueryClient#setQueryData} for each matching query.
|
|
2214
|
+
*
|
|
2215
|
+
* @example
|
|
2216
|
+
* ```ts
|
|
2217
|
+
* queryClient.setQueriesData({ queryKey: ['posts'] }, (oldPosts) =>
|
|
2218
|
+
* oldPosts ? oldPosts.filter((post) => post.id !== deletedId) : oldPosts,
|
|
2219
|
+
* )
|
|
2220
|
+
* ```
|
|
2221
|
+
*/
|
|
1668
2222
|
setQueriesData(e, t, s) {
|
|
1669
|
-
return
|
|
1670
|
-
() => i(this, M).findAll(e).map(({ queryKey: r }) => [
|
|
1671
|
-
r,
|
|
1672
|
-
this.setQueryData(r, t, s)
|
|
1673
|
-
])
|
|
1674
|
-
);
|
|
2223
|
+
return A.batch(() => i(this, F).findAll(e).map(({ queryKey: r }) => [r, this.setQueryData(r, t, s)]));
|
|
1675
2224
|
}
|
|
2225
|
+
/**
|
|
2226
|
+
* Imperative (non-reactive) way to retrieve an existing query's state. If the query does not
|
|
2227
|
+
* exist, `undefined` is returned.
|
|
2228
|
+
*
|
|
2229
|
+
* @example
|
|
2230
|
+
* ```ts
|
|
2231
|
+
* const state = queryClient.getQueryState(['posts'])
|
|
2232
|
+
* console.log(state?.dataUpdatedAt)
|
|
2233
|
+
* ```
|
|
2234
|
+
*/
|
|
1676
2235
|
getQueryState(e) {
|
|
1677
2236
|
var s;
|
|
1678
2237
|
const t = this.defaultQueryOptions({ queryKey: e });
|
|
1679
|
-
return (s = i(this,
|
|
1680
|
-
t.queryHash
|
|
1681
|
-
)) == null ? void 0 : s.state;
|
|
2238
|
+
return (s = i(this, F).get(t.queryHash)) == null ? void 0 : s.state;
|
|
1682
2239
|
}
|
|
2240
|
+
/**
|
|
2241
|
+
* Removes queries from the cache that match the given filters. Unlike
|
|
2242
|
+
* {@link QueryClient#invalidateQueries} or {@link QueryClient#refetchQueries}, this removes
|
|
2243
|
+
* matching queries from the cache instead of refetching them. Without filters, every query in
|
|
2244
|
+
* the cache is removed.
|
|
2245
|
+
*
|
|
2246
|
+
* @example
|
|
2247
|
+
* ```ts
|
|
2248
|
+
* queryClient.removeQueries({ queryKey: ['posts'], exact: true })
|
|
2249
|
+
* ```
|
|
2250
|
+
*/
|
|
1683
2251
|
removeQueries(e) {
|
|
1684
|
-
const t = i(this,
|
|
1685
|
-
|
|
2252
|
+
const t = i(this, F);
|
|
2253
|
+
A.batch(() => {
|
|
1686
2254
|
t.findAll(e).forEach((s) => {
|
|
1687
2255
|
t.remove(s);
|
|
1688
2256
|
});
|
|
1689
2257
|
});
|
|
1690
2258
|
}
|
|
2259
|
+
/**
|
|
2260
|
+
* Resets queries matching the given filters back to their initial state (e.g. any
|
|
2261
|
+
* `initialData`), notifying subscribers rather than removing them. Active queries among the
|
|
2262
|
+
* matched set are then refetched, and the returned promise resolves once that refetch settles.
|
|
2263
|
+
*
|
|
2264
|
+
* @example
|
|
2265
|
+
* ```ts
|
|
2266
|
+
* await queryClient.resetQueries({ queryKey: ['posts'], exact: true })
|
|
2267
|
+
* ```
|
|
2268
|
+
*/
|
|
1691
2269
|
resetQueries(e, t) {
|
|
1692
|
-
const s = i(this,
|
|
1693
|
-
return
|
|
1694
|
-
r.
|
|
1695
|
-
|
|
1696
|
-
|
|
2270
|
+
const s = i(this, F);
|
|
2271
|
+
return A.batch(() => {
|
|
2272
|
+
const r = s.findAll(e), n = new Set(r);
|
|
2273
|
+
return r.forEach((a) => {
|
|
2274
|
+
a.reset();
|
|
2275
|
+
}), this.refetchQueries({
|
|
1697
2276
|
type: "active",
|
|
1698
|
-
|
|
1699
|
-
},
|
|
1700
|
-
|
|
1701
|
-
)));
|
|
2277
|
+
predicate: (a) => n.has(a)
|
|
2278
|
+
}, t);
|
|
2279
|
+
});
|
|
1702
2280
|
}
|
|
2281
|
+
/**
|
|
2282
|
+
* Cancels outgoing fetches for queries matching the given filters. Most useful when performing
|
|
2283
|
+
* optimistic updates, since any outgoing refetch that resolves afterwards would otherwise
|
|
2284
|
+
* overwrite the optimistic update. By default (`revert: true`), a cancelled query's data is
|
|
2285
|
+
* reverted to its state before the outgoing fetch started.
|
|
2286
|
+
*
|
|
2287
|
+
* The returned promise never rejects, even if individual cancellations fail.
|
|
2288
|
+
*
|
|
2289
|
+
* @example
|
|
2290
|
+
* ```ts
|
|
2291
|
+
* await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })
|
|
2292
|
+
* ```
|
|
2293
|
+
*/
|
|
1703
2294
|
cancelQueries(e, t = {}) {
|
|
1704
|
-
const s = {
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
2295
|
+
const s = {
|
|
2296
|
+
revert: !0,
|
|
2297
|
+
...t
|
|
2298
|
+
}, r = A.batch(() => i(this, F).findAll(e).map((n) => n.cancel(s)));
|
|
2299
|
+
return Promise.all(r).then(k).catch(k);
|
|
1708
2300
|
}
|
|
2301
|
+
/**
|
|
2302
|
+
* Marks queries matching the given filters as invalidated. Unlike
|
|
2303
|
+
* {@link QueryClient#removeQueries}, invalidated queries stay in the cache.
|
|
2304
|
+
*
|
|
2305
|
+
* Unless `filters.refetchType` is `'none'`, matching queries are then refetched via
|
|
2306
|
+
* {@link QueryClient#refetchQueries}, using `filters.refetchType` if set, otherwise
|
|
2307
|
+
* `filters.type`, otherwise `'active'`.
|
|
2308
|
+
*
|
|
2309
|
+
* @example
|
|
2310
|
+
* ```ts
|
|
2311
|
+
* await queryClient.invalidateQueries({ queryKey: ['posts'], refetchType: 'active' })
|
|
2312
|
+
* ```
|
|
2313
|
+
*/
|
|
1709
2314
|
invalidateQueries(e, t = {}) {
|
|
1710
|
-
return
|
|
2315
|
+
return A.batch(() => (i(this, F).findAll(e).forEach((s) => {
|
|
1711
2316
|
s.invalidate();
|
|
1712
|
-
}), (e == null ? void 0 : e.refetchType) === "none" ? Promise.resolve() : this.refetchQueries(
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
},
|
|
1717
|
-
t
|
|
1718
|
-
)));
|
|
2317
|
+
}), (e == null ? void 0 : e.refetchType) === "none" ? Promise.resolve() : this.refetchQueries({
|
|
2318
|
+
...e,
|
|
2319
|
+
type: (e == null ? void 0 : e.refetchType) ?? (e == null ? void 0 : e.type) ?? "active"
|
|
2320
|
+
}, t)));
|
|
1719
2321
|
}
|
|
2322
|
+
/**
|
|
2323
|
+
* Refetches queries matching the given filters, regardless of whether they are stale. Without
|
|
2324
|
+
* filters, every query in the cache is refetched. Queries that are disabled, or static (only
|
|
2325
|
+
* have observers with a static `staleTime`), are never refetched.
|
|
2326
|
+
*
|
|
2327
|
+
* By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new
|
|
2328
|
+
* one starts. The returned promise resolves once all matching queries have settled; it does
|
|
2329
|
+
* not reject on individual query failures unless `throwOnError` is set.
|
|
2330
|
+
*
|
|
2331
|
+
* @example
|
|
2332
|
+
* ```ts
|
|
2333
|
+
* // refetch all active queries partially matching a query key:
|
|
2334
|
+
* await queryClient.refetchQueries({ queryKey: ['posts'], type: 'active' })
|
|
2335
|
+
* ```
|
|
2336
|
+
*/
|
|
1720
2337
|
refetchQueries(e, t = {}) {
|
|
1721
2338
|
const s = {
|
|
1722
2339
|
...t,
|
|
1723
2340
|
cancelRefetch: t.cancelRefetch ?? !0
|
|
1724
|
-
}, r =
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
2341
|
+
}, r = A.batch(() => i(this, F).findAll(e).filter((n) => !n.isDisabled() && !n.isStatic()).map((n) => {
|
|
2342
|
+
let a = n.fetch(void 0, s);
|
|
2343
|
+
return s.throwOnError || (a = a.catch(k)), n.state.fetchStatus === "paused" ? Promise.resolve() : a;
|
|
2344
|
+
}));
|
|
2345
|
+
return Promise.all(r).then(k);
|
|
2346
|
+
}
|
|
2347
|
+
/**
|
|
2348
|
+
* Asynchronous method to fetch and cache a query, resolving with the data or throwing with
|
|
2349
|
+
* the error.
|
|
2350
|
+
*
|
|
2351
|
+
* If the query already exists in the cache and its data is not stale (per the given
|
|
2352
|
+
* `staleTime`), the cached data is returned without fetching. Otherwise, the query is fetched
|
|
2353
|
+
* and the promise resolves once the fetch settles. If a `select` function is provided, it is
|
|
2354
|
+
* applied to the data in both cases (cached or freshly fetched) before it is returned.
|
|
2355
|
+
*
|
|
2356
|
+
* Unlike a reactive observer, retries are disabled by default here (`retry: false`) unless
|
|
2357
|
+
* explicitly configured, since there is no component to catch a thrown error and retry through
|
|
2358
|
+
* re-render.
|
|
2359
|
+
*
|
|
2360
|
+
* The accepted options are `QueryObserverOptions` minus the fields that only make sense for a
|
|
2361
|
+
* reactive observer — `enabled`, `refetchInterval`, `refetchIntervalInBackground`,
|
|
2362
|
+
* `refetchOnWindowFocus`, `refetchOnReconnect`, `refetchOnMount`, `retryOnMount`,
|
|
2363
|
+
* `notifyOnChangeProps`, `throwOnError`, `suspense`, and `placeholderData` are not part of this
|
|
2364
|
+
* method's options.
|
|
2365
|
+
*
|
|
2366
|
+
* This method replaces the deprecated `fetchQuery`, and — combined with
|
|
2367
|
+
* `{ staleTime: 'static' }` — the deprecated `ensureQueryData`.
|
|
2368
|
+
*
|
|
2369
|
+
* @example
|
|
2370
|
+
* ```ts
|
|
2371
|
+
* try {
|
|
2372
|
+
* const data = await queryClient.query({ queryKey, queryFn, staleTime: 10000 })
|
|
2373
|
+
* } catch (error) {
|
|
2374
|
+
* console.log(error)
|
|
2375
|
+
* }
|
|
2376
|
+
* ```
|
|
2377
|
+
*/
|
|
2378
|
+
async query(e) {
|
|
2379
|
+
const t = this.defaultQueryOptions(e);
|
|
2380
|
+
t.retry === void 0 && (t.retry = !1);
|
|
2381
|
+
const s = i(this, F).build(this, t), r = s.isStaleByTime(P(t.staleTime, s)) ? await s.fetch(t) : s.state.data, n = t.select;
|
|
2382
|
+
return n ? n(r) : r;
|
|
1731
2383
|
}
|
|
2384
|
+
/**
|
|
2385
|
+
* @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.
|
|
2386
|
+
*/
|
|
1732
2387
|
fetchQuery(e) {
|
|
1733
2388
|
const t = this.defaultQueryOptions(e);
|
|
1734
2389
|
t.retry === void 0 && (t.retry = !1);
|
|
1735
|
-
const s = i(this,
|
|
1736
|
-
return s.isStaleByTime(
|
|
1737
|
-
ot(t.staleTime, s)
|
|
1738
|
-
) ? s.fetch(t) : Promise.resolve(s.state.data);
|
|
2390
|
+
const s = i(this, F).build(this, t);
|
|
2391
|
+
return s.isStaleByTime(P(t.staleTime, s)) ? s.fetch(t) : Promise.resolve(s.state.data);
|
|
1739
2392
|
}
|
|
2393
|
+
/**
|
|
2394
|
+
* @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.
|
|
2395
|
+
*/
|
|
1740
2396
|
prefetchQuery(e) {
|
|
1741
|
-
return this.fetchQuery(e).then(
|
|
2397
|
+
return this.fetchQuery(e).then(k).catch(k);
|
|
2398
|
+
}
|
|
2399
|
+
/**
|
|
2400
|
+
* Asynchronous method to fetch and cache an infinite query, resolving with an
|
|
2401
|
+
* {@link InfiniteData} object or throwing with the error.
|
|
2402
|
+
*
|
|
2403
|
+
* Behaves like {@link QueryClient#query}, accepting the same options (minus
|
|
2404
|
+
* `initialPageParam`), plus the required `initialPageParam`, and an optional `pages` /
|
|
2405
|
+
* `getNextPageParam` pair used to refetch a fixed number of pages from the start.
|
|
2406
|
+
*
|
|
2407
|
+
* This method replaces the deprecated `fetchInfiniteQuery`, and — combined with
|
|
2408
|
+
* `{ staleTime: 'static' }` — the deprecated `ensureInfiniteQueryData`.
|
|
2409
|
+
*
|
|
2410
|
+
* @example
|
|
2411
|
+
* ```ts
|
|
2412
|
+
* try {
|
|
2413
|
+
* const data = await queryClient.infiniteQuery({ queryKey, queryFn, initialPageParam: 0 })
|
|
2414
|
+
* console.log(data.pages)
|
|
2415
|
+
* } catch (error) {
|
|
2416
|
+
* console.log(error)
|
|
2417
|
+
* }
|
|
2418
|
+
* ```
|
|
2419
|
+
*/
|
|
2420
|
+
infiniteQuery(e) {
|
|
2421
|
+
return e._type = "infinite", this.query(e);
|
|
1742
2422
|
}
|
|
2423
|
+
/**
|
|
2424
|
+
* @deprecated Use queryClient.infiniteQuery(options) instead. This method will be removed in the next major version.
|
|
2425
|
+
*/
|
|
1743
2426
|
fetchInfiniteQuery(e) {
|
|
1744
|
-
return e.
|
|
2427
|
+
return e._type = "infinite", this.fetchQuery(e);
|
|
1745
2428
|
}
|
|
2429
|
+
/**
|
|
2430
|
+
* @deprecated Use queryClient.infiniteQuery(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.
|
|
2431
|
+
*/
|
|
1746
2432
|
prefetchInfiniteQuery(e) {
|
|
1747
|
-
return this.fetchInfiniteQuery(e).then(
|
|
2433
|
+
return this.fetchInfiniteQuery(e).then(k).catch(k);
|
|
1748
2434
|
}
|
|
2435
|
+
/**
|
|
2436
|
+
* @deprecated Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
|
|
2437
|
+
*/
|
|
1749
2438
|
ensureInfiniteQueryData(e) {
|
|
1750
|
-
return e.
|
|
2439
|
+
return e._type = "infinite", this.ensureQueryData(e);
|
|
1751
2440
|
}
|
|
2441
|
+
/**
|
|
2442
|
+
* Resumes mutations that were paused because there was no network connection. Does nothing
|
|
2443
|
+
* (resolving immediately) if the client is currently offline.
|
|
2444
|
+
*
|
|
2445
|
+
* @example
|
|
2446
|
+
* ```ts
|
|
2447
|
+
* import { QueryClient } from '@tanstack/query-core'
|
|
2448
|
+
*
|
|
2449
|
+
* const queryClient = new QueryClient()
|
|
2450
|
+
* await queryClient.resumePausedMutations()
|
|
2451
|
+
* ```
|
|
2452
|
+
*/
|
|
1752
2453
|
resumePausedMutations() {
|
|
1753
|
-
return
|
|
2454
|
+
return Ht.isOnline() ? i(this, st).resumePausedMutations() : Promise.resolve();
|
|
1754
2455
|
}
|
|
2456
|
+
/**
|
|
2457
|
+
* Returns the query cache this client is connected to.
|
|
2458
|
+
*
|
|
2459
|
+
* @example
|
|
2460
|
+
* ```ts
|
|
2461
|
+
* import { QueryClient } from '@tanstack/query-core'
|
|
2462
|
+
*
|
|
2463
|
+
* const queryClient = new QueryClient()
|
|
2464
|
+
* const queryCache = queryClient.getQueryCache()
|
|
2465
|
+
* const queries = queryCache.findAll({ queryKey: ['posts'] })
|
|
2466
|
+
* ```
|
|
2467
|
+
*/
|
|
1755
2468
|
getQueryCache() {
|
|
1756
|
-
return i(this,
|
|
2469
|
+
return i(this, F);
|
|
1757
2470
|
}
|
|
2471
|
+
/**
|
|
2472
|
+
* Returns the mutation cache this client is connected to.
|
|
2473
|
+
*
|
|
2474
|
+
* @example
|
|
2475
|
+
* ```ts
|
|
2476
|
+
* import { QueryClient } from '@tanstack/query-core'
|
|
2477
|
+
*
|
|
2478
|
+
* const queryClient = new QueryClient()
|
|
2479
|
+
* const mutationCache = queryClient.getMutationCache()
|
|
2480
|
+
* const mutations = mutationCache.findAll({ status: 'pending' })
|
|
2481
|
+
* ```
|
|
2482
|
+
*/
|
|
1758
2483
|
getMutationCache() {
|
|
1759
|
-
return i(this,
|
|
2484
|
+
return i(this, st);
|
|
1760
2485
|
}
|
|
2486
|
+
/**
|
|
2487
|
+
* Returns the default options that were set when creating the client, or via
|
|
2488
|
+
* {@link QueryClient#setDefaultOptions}.
|
|
2489
|
+
*
|
|
2490
|
+
* @example
|
|
2491
|
+
* ```ts
|
|
2492
|
+
* import { QueryClient } from '@tanstack/query-core'
|
|
2493
|
+
*
|
|
2494
|
+
* const queryClient = new QueryClient()
|
|
2495
|
+
* const defaultOptions = queryClient.getDefaultOptions()
|
|
2496
|
+
* ```
|
|
2497
|
+
*/
|
|
1761
2498
|
getDefaultOptions() {
|
|
1762
|
-
return i(this,
|
|
2499
|
+
return i(this, rt);
|
|
1763
2500
|
}
|
|
2501
|
+
/**
|
|
2502
|
+
* Dynamically sets the default options for this client, overwriting any previously defined
|
|
2503
|
+
* default options.
|
|
2504
|
+
*
|
|
2505
|
+
* @see {@link QueryClient#getDefaultOptions}
|
|
2506
|
+
* @example
|
|
2507
|
+
* ```ts
|
|
2508
|
+
* import { QueryClient } from '@tanstack/query-core'
|
|
2509
|
+
*
|
|
2510
|
+
* const queryClient = new QueryClient()
|
|
2511
|
+
* queryClient.setDefaultOptions({
|
|
2512
|
+
* queries: {
|
|
2513
|
+
* staleTime: Infinity,
|
|
2514
|
+
* },
|
|
2515
|
+
* })
|
|
2516
|
+
* ```
|
|
2517
|
+
*/
|
|
1764
2518
|
setDefaultOptions(e) {
|
|
1765
|
-
o(this,
|
|
2519
|
+
o(this, rt, e);
|
|
1766
2520
|
}
|
|
2521
|
+
/**
|
|
2522
|
+
* Sets default options for queries whose query key partially matches the given `queryKey`.
|
|
2523
|
+
*
|
|
2524
|
+
* If several registered query defaults match a given query key, they are merged together in
|
|
2525
|
+
* registration order by {@link QueryClient#getQueryDefaults}, so register defaults from the
|
|
2526
|
+
* most generic key to the least generic one — more specific defaults should be registered
|
|
2527
|
+
* after more generic ones so they take precedence.
|
|
2528
|
+
*
|
|
2529
|
+
* @example
|
|
2530
|
+
* ```ts
|
|
2531
|
+
* queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts })
|
|
2532
|
+
*
|
|
2533
|
+
* await queryClient.query({ queryKey: ['posts'] })
|
|
2534
|
+
* ```
|
|
2535
|
+
*/
|
|
1767
2536
|
setQueryDefaults(e, t) {
|
|
1768
|
-
i(this,
|
|
2537
|
+
i(this, Et).set(Dt(e), {
|
|
1769
2538
|
queryKey: e,
|
|
1770
2539
|
defaultOptions: t
|
|
1771
2540
|
});
|
|
1772
2541
|
}
|
|
2542
|
+
/**
|
|
2543
|
+
* Returns the default options registered for queries whose query key partially matches the
|
|
2544
|
+
* given `queryKey`, via {@link QueryClient#setQueryDefaults}. If multiple registered defaults
|
|
2545
|
+
* match, they are merged together in registration order.
|
|
2546
|
+
*
|
|
2547
|
+
* @example
|
|
2548
|
+
* ```ts
|
|
2549
|
+
* const defaultOptions = queryClient.getQueryDefaults(['posts'])
|
|
2550
|
+
* ```
|
|
2551
|
+
*/
|
|
1773
2552
|
getQueryDefaults(e) {
|
|
1774
|
-
const t = [...i(this,
|
|
2553
|
+
const t = [...i(this, Et).values()], s = {};
|
|
1775
2554
|
return t.forEach((r) => {
|
|
1776
|
-
|
|
2555
|
+
Qt(e, r.queryKey) && Object.assign(s, r.defaultOptions);
|
|
1777
2556
|
}), s;
|
|
1778
2557
|
}
|
|
2558
|
+
/**
|
|
2559
|
+
* Sets default options for mutations whose mutation key partially matches the given
|
|
2560
|
+
* `mutationKey`. As with {@link QueryClient#setQueryDefaults}, the order of registration
|
|
2561
|
+
* matters when several registered defaults match the same mutation key.
|
|
2562
|
+
*
|
|
2563
|
+
* @see {@link QueryClient#getMutationDefaults}
|
|
2564
|
+
* @example
|
|
2565
|
+
* ```ts
|
|
2566
|
+
* queryClient.setMutationDefaults(['addPost'], { mutationFn: addPost })
|
|
2567
|
+
* ```
|
|
2568
|
+
*/
|
|
1779
2569
|
setMutationDefaults(e, t) {
|
|
1780
|
-
i(this,
|
|
2570
|
+
i(this, Ft).set(Dt(e), {
|
|
1781
2571
|
mutationKey: e,
|
|
1782
2572
|
defaultOptions: t
|
|
1783
2573
|
});
|
|
1784
2574
|
}
|
|
2575
|
+
/**
|
|
2576
|
+
* Returns the default options registered for mutations whose mutation key partially matches
|
|
2577
|
+
* the given `mutationKey`, via {@link QueryClient#setMutationDefaults}. If multiple registered
|
|
2578
|
+
* defaults match, they are merged together in registration order.
|
|
2579
|
+
*
|
|
2580
|
+
* @example
|
|
2581
|
+
* ```ts
|
|
2582
|
+
* const defaultOptions = queryClient.getMutationDefaults(['addPost'])
|
|
2583
|
+
* ```
|
|
2584
|
+
*/
|
|
1785
2585
|
getMutationDefaults(e) {
|
|
1786
|
-
const t = [...i(this,
|
|
2586
|
+
const t = [...i(this, Ft).values()], s = {};
|
|
1787
2587
|
return t.forEach((r) => {
|
|
1788
|
-
|
|
2588
|
+
Qt(e, r.mutationKey) && Object.assign(s, r.defaultOptions);
|
|
1789
2589
|
}), s;
|
|
1790
2590
|
}
|
|
2591
|
+
/**
|
|
2592
|
+
* Called by framework adapters (e.g. inside `useQuery`) to resolve the options passed by the
|
|
2593
|
+
* caller into their final, defaulted form: merging `queryClient.setQueryDefaults` for the
|
|
2594
|
+
* given `queryKey`, then the client's own `defaultOptions.queries`, then the caller's options
|
|
2595
|
+
* on top. A no-op if the options are already defaulted (`_defaulted: true`).
|
|
2596
|
+
*/
|
|
1791
2597
|
defaultQueryOptions(e) {
|
|
1792
|
-
if (e._defaulted)
|
|
1793
|
-
return e;
|
|
2598
|
+
if (e._defaulted) return e;
|
|
1794
2599
|
const t = {
|
|
1795
|
-
...i(this,
|
|
2600
|
+
...i(this, rt).queries,
|
|
1796
2601
|
...this.getQueryDefaults(e.queryKey),
|
|
1797
2602
|
...e,
|
|
1798
2603
|
_defaulted: !0
|
|
1799
2604
|
};
|
|
1800
|
-
return t.queryHash || (t.queryHash =
|
|
1801
|
-
t.queryKey,
|
|
1802
|
-
t
|
|
1803
|
-
)), t.refetchOnReconnect === void 0 && (t.refetchOnReconnect = t.networkMode !== "always"), t.throwOnError === void 0 && (t.throwOnError = !!t.suspense), !t.networkMode && t.persister && (t.networkMode = "offlineFirst"), t.queryFn === $t && (t.enabled = !1), t;
|
|
2605
|
+
return t.queryHash || (t.queryHash = ae(t.queryKey, t)), t.refetchOnReconnect === void 0 && (t.refetchOnReconnect = t.networkMode !== "always"), t.throwOnError === void 0 && (t.throwOnError = !!t.suspense), !t.networkMode && t.persister && (t.networkMode = "offlineFirst"), t.queryFn === Kt && (t.enabled = !1), t;
|
|
1804
2606
|
}
|
|
2607
|
+
/**
|
|
2608
|
+
* The mutation counterpart of {@link QueryClient#defaultQueryOptions}. Called by framework
|
|
2609
|
+
* adapters (e.g. inside `useMutation`) to merge `queryClient.setMutationDefaults` for the
|
|
2610
|
+
* given `mutationKey`, then the client's `defaultOptions.mutations`, then the caller's options
|
|
2611
|
+
* on top. A no-op if the options are already defaulted (`_defaulted: true`).
|
|
2612
|
+
*/
|
|
1805
2613
|
defaultMutationOptions(e) {
|
|
1806
2614
|
return e != null && e._defaulted ? e : {
|
|
1807
|
-
...i(this,
|
|
2615
|
+
...i(this, rt).mutations,
|
|
1808
2616
|
...(e == null ? void 0 : e.mutationKey) && this.getMutationDefaults(e.mutationKey),
|
|
1809
2617
|
...e,
|
|
1810
2618
|
_defaulted: !0
|
|
1811
2619
|
};
|
|
1812
2620
|
}
|
|
2621
|
+
/**
|
|
2622
|
+
* Clears both the query cache and the mutation cache this client is connected to.
|
|
2623
|
+
*
|
|
2624
|
+
* @example
|
|
2625
|
+
* ```ts
|
|
2626
|
+
* import { QueryClient } from '@tanstack/query-core'
|
|
2627
|
+
*
|
|
2628
|
+
* const queryClient = new QueryClient()
|
|
2629
|
+
* queryClient.clear()
|
|
2630
|
+
* ```
|
|
2631
|
+
*/
|
|
1813
2632
|
clear() {
|
|
1814
|
-
i(this,
|
|
1815
|
-
}
|
|
1816
|
-
},
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
if (!t)
|
|
1821
|
-
throw new Error("No QueryClient set, use QueryClientProvider to set one");
|
|
1822
|
-
return t;
|
|
1823
|
-
}, Ms = ({
|
|
1824
|
-
client: e,
|
|
1825
|
-
children: t
|
|
1826
|
-
}) => (K.useEffect(() => (e.mount(), () => {
|
|
1827
|
-
e.unmount();
|
|
1828
|
-
}), [e]), /* @__PURE__ */ zt(Ze.Provider, { value: e, children: t })), Xe = K.createContext(!1), Ds = () => K.useContext(Xe);
|
|
1829
|
-
Xe.Provider;
|
|
1830
|
-
function Qs() {
|
|
2633
|
+
i(this, F).clear(), i(this, st).clear();
|
|
2634
|
+
}
|
|
2635
|
+
}, F = new WeakMap(), st = new WeakMap(), rt = new WeakMap(), Et = new WeakMap(), Ft = new WeakMap(), it = new WeakMap(), Rt = new WeakMap(), Mt = new WeakMap(), qe);
|
|
2636
|
+
const He = L.createContext(!1), Ss = () => L.useContext(He);
|
|
2637
|
+
He.Provider;
|
|
2638
|
+
function Cs() {
|
|
1831
2639
|
let e = !1;
|
|
1832
2640
|
return {
|
|
2641
|
+
/**
|
|
2642
|
+
* Clears the reset state, so queries know not to try again until the boundary is reset again.
|
|
2643
|
+
*/
|
|
1833
2644
|
clearReset: () => {
|
|
1834
2645
|
e = !1;
|
|
1835
2646
|
},
|
|
2647
|
+
/**
|
|
2648
|
+
* Resets any query errors within the boundary, so queries know they can try again.
|
|
2649
|
+
*/
|
|
1836
2650
|
reset: () => {
|
|
1837
2651
|
e = !0;
|
|
1838
2652
|
},
|
|
2653
|
+
/**
|
|
2654
|
+
* Returns whether the boundary has been reset and not yet cleared.
|
|
2655
|
+
*/
|
|
1839
2656
|
isReset: () => e
|
|
1840
2657
|
};
|
|
1841
2658
|
}
|
|
1842
|
-
|
|
1843
|
-
const r = s != null && s.state.error && typeof e.throwOnError == "function" ?
|
|
1844
|
-
(e.suspense ||
|
|
1845
|
-
},
|
|
1846
|
-
|
|
2659
|
+
const Os = L.createContext(Cs()), Ps = () => L.useContext(Os), Es = (e, t, s) => {
|
|
2660
|
+
const r = s != null && s.state.error && typeof e.throwOnError == "function" ? je(e.throwOnError, [s.state.error, s]) : e.throwOnError;
|
|
2661
|
+
(e.suspense || r) && (t.isReset() || (e.retryOnMount = !1));
|
|
2662
|
+
}, Fs = (e) => {
|
|
2663
|
+
L.useEffect(() => {
|
|
1847
2664
|
e.clearReset();
|
|
1848
2665
|
}, [e]);
|
|
1849
|
-
},
|
|
1850
|
-
result: e,
|
|
1851
|
-
errorResetBoundary: t,
|
|
1852
|
-
throwOnError: s,
|
|
1853
|
-
query: r,
|
|
1854
|
-
suspense: n
|
|
1855
|
-
}) => e.isError && !t.isReset() && !e.isFetching && r && (n && e.data === void 0 || Ge(s, [e.error, r])), js = (e) => {
|
|
2666
|
+
}, Rs = ({ result: e, errorResetBoundary: t, throwOnError: s, query: r, suspense: n }) => e.isError && !t.isReset() && !e.isFetching && r && (n && e.data === void 0 || je(s, [e.error, r])), Ms = (e) => {
|
|
1856
2667
|
if (e.suspense) {
|
|
1857
2668
|
const s = (n) => n === "static" ? n : Math.max(n ?? 1e3, 1e3), r = e.staleTime;
|
|
1858
|
-
e.staleTime = typeof r == "function" ? (...n) => s(r(...n)) : s(r), typeof e.gcTime == "number" && (e.gcTime = Math.max(
|
|
1859
|
-
e.gcTime,
|
|
1860
|
-
1e3
|
|
1861
|
-
));
|
|
2669
|
+
e.staleTime = typeof r == "function" ? (...n) => s(r(...n)) : s(r), typeof e.gcTime == "number" && (e.gcTime = Math.max(e.gcTime, 1e3));
|
|
1862
2670
|
}
|
|
1863
|
-
},
|
|
2671
|
+
}, Qs = (e, t) => (e == null ? void 0 : e.suspense) && t.isPending, Ts = (e, t, s) => t.fetchOptimistic(e).catch(() => {
|
|
1864
2672
|
s.clearReset();
|
|
1865
2673
|
});
|
|
1866
|
-
function
|
|
1867
|
-
var C, y, P, v;
|
|
2674
|
+
function Ds(e, t, s) {
|
|
1868
2675
|
if (process.env.NODE_ENV !== "production" && (typeof e != "object" || Array.isArray(e)))
|
|
1869
|
-
throw new Error(
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
const
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
a,
|
|
1884
|
-
h
|
|
1885
|
-
)
|
|
1886
|
-
), w = m.getOptimisticResult(h), d = !r && e.subscribed !== !1;
|
|
1887
|
-
if (K.useSyncExternalStore(
|
|
1888
|
-
K.useCallback(
|
|
1889
|
-
(b) => {
|
|
1890
|
-
const S = d ? m.subscribe(I.batchCalls(b)) : N;
|
|
1891
|
-
return m.updateResult(), S;
|
|
1892
|
-
},
|
|
1893
|
-
[m, d]
|
|
1894
|
-
),
|
|
1895
|
-
() => m.getCurrentResult(),
|
|
1896
|
-
() => m.getCurrentResult()
|
|
1897
|
-
), K.useEffect(() => {
|
|
1898
|
-
m.setOptions(h);
|
|
1899
|
-
}, [h, m]), Ns(h, w))
|
|
1900
|
-
throw Qe(h, m, n);
|
|
1901
|
-
if (qs({
|
|
1902
|
-
result: w,
|
|
2676
|
+
throw new Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');
|
|
2677
|
+
const r = Ss(), n = Ps(), a = $e(), h = a.defaultQueryOptions(e), u = a.getQueryCache().get(h.queryHash);
|
|
2678
|
+
process.env.NODE_ENV !== "production" && (h.queryFn || console.error(`[${h.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`));
|
|
2679
|
+
const d = e.subscribed !== !1;
|
|
2680
|
+
h._optimisticResults = r ? "isRestoring" : d ? "optimistic" : void 0, Ms(h), Es(h, n, u), Fs(n);
|
|
2681
|
+
const [p] = L.useState(() => new t(a, h)), f = p.getOptimisticResult(h), C = !r && d;
|
|
2682
|
+
if (L.useSyncExternalStore(L.useCallback((y) => {
|
|
2683
|
+
const R = C ? p.subscribe(A.batchCalls(y)) : k;
|
|
2684
|
+
return p.updateResult(), R;
|
|
2685
|
+
}, [p, C]), () => p.getCurrentResult(), () => p.getCurrentResult()), L.useEffect(() => {
|
|
2686
|
+
p.setOptions(h);
|
|
2687
|
+
}, [h, p]), Qs(h, f)) throw Ts(h, p, n);
|
|
2688
|
+
if (Rs({
|
|
2689
|
+
result: f,
|
|
1903
2690
|
errorResetBoundary: n,
|
|
1904
2691
|
throwOnError: h.throwOnError,
|
|
1905
2692
|
query: u,
|
|
1906
2693
|
suspense: h.suspense
|
|
1907
|
-
}))
|
|
1908
|
-
|
|
1909
|
-
if ((v = (P = a.getDefaultOptions().queries) == null ? void 0 : P._experimental_afterQuery) == null || v.call(
|
|
1910
|
-
P,
|
|
1911
|
-
h,
|
|
1912
|
-
w
|
|
1913
|
-
), h.experimental_prefetchInRender && !xt.isServer() && Us(w, r)) {
|
|
1914
|
-
const b = f ? (
|
|
1915
|
-
// Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted
|
|
1916
|
-
Qe(h, m, n)
|
|
1917
|
-
) : (
|
|
1918
|
-
// subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in
|
|
1919
|
-
u == null ? void 0 : u.promise
|
|
1920
|
-
);
|
|
1921
|
-
b == null || b.catch(N).finally(() => {
|
|
1922
|
-
m.updateResult();
|
|
1923
|
-
});
|
|
1924
|
-
}
|
|
1925
|
-
return h.notifyOnChangeProps ? w : m.trackResult(w);
|
|
2694
|
+
})) throw f.error;
|
|
2695
|
+
return h.notifyOnChangeProps ? f : p.trackResult(f);
|
|
1926
2696
|
}
|
|
1927
|
-
function
|
|
1928
|
-
return
|
|
2697
|
+
function qs(e, t) {
|
|
2698
|
+
return Ds(e, ys);
|
|
1929
2699
|
}
|
|
1930
|
-
const
|
|
1931
|
-
function
|
|
2700
|
+
const As = Be(void 0);
|
|
2701
|
+
function Is({
|
|
1932
2702
|
fetchSchedule: e,
|
|
1933
2703
|
initialSchedule: t = [],
|
|
1934
2704
|
weeks: s,
|
|
1935
2705
|
handleDateChanged: r = () => !0,
|
|
1936
2706
|
children: n
|
|
1937
2707
|
}) {
|
|
1938
|
-
const [a, h] =
|
|
1939
|
-
|
|
1940
|
-
const
|
|
1941
|
-
const
|
|
1942
|
-
|
|
1943
|
-
}, [r]), { data:
|
|
1944
|
-
queryKey: ["schedule",
|
|
2708
|
+
const [a, h] = de(s[0][0].date), [u, d] = de(!1), p = Ae(Gt(s[0][0].date, "yyyy-MM-dd"));
|
|
2709
|
+
kt.setNamespace("NetworksUILibrary"), kt.setComponent("ScheduleContext");
|
|
2710
|
+
const f = Ge((M) => {
|
|
2711
|
+
const g = Gt(M, "yyyy-MM-dd");
|
|
2712
|
+
g !== p.current && (d(!0), p.current = g), h(M), r(M);
|
|
2713
|
+
}, [r]), { data: C, isLoading: y, isFetching: R, isError: D, error: O } = qs({
|
|
2714
|
+
queryKey: ["schedule", Gt(a, "yyyy-MM-dd")],
|
|
1945
2715
|
queryFn: () => e(a),
|
|
1946
2716
|
staleTime: 1e3 * 60 * 15,
|
|
1947
2717
|
// 15 minutes
|
|
1948
2718
|
retry: 1
|
|
1949
2719
|
});
|
|
1950
|
-
|
|
1951
|
-
if (
|
|
1952
|
-
if (!
|
|
1953
|
-
const
|
|
1954
|
-
|
|
2720
|
+
fe(() => {
|
|
2721
|
+
if (C !== void 0 && u)
|
|
2722
|
+
if (!R) {
|
|
2723
|
+
const g = setTimeout(() => {
|
|
2724
|
+
d(!1);
|
|
1955
2725
|
}, 500);
|
|
1956
|
-
return () => clearTimeout(
|
|
2726
|
+
return () => clearTimeout(g);
|
|
1957
2727
|
} else
|
|
1958
|
-
|
|
1959
|
-
}, [
|
|
1960
|
-
|
|
1961
|
-
}, [a,
|
|
1962
|
-
const
|
|
1963
|
-
schedule:
|
|
2728
|
+
d(!1);
|
|
2729
|
+
}, [C, u, R]), fe(() => {
|
|
2730
|
+
D && (kt.log("Error fetching schedule for date:", a), kt.log("Error detials: ", O));
|
|
2731
|
+
}, [a, D, O]);
|
|
2732
|
+
const q = Ve(() => ({
|
|
2733
|
+
schedule: C ?? t,
|
|
1964
2734
|
weeks: s,
|
|
1965
2735
|
currentDate: a,
|
|
1966
|
-
isLoading:
|
|
1967
|
-
isError:
|
|
1968
|
-
setCurrentDate:
|
|
1969
|
-
}), [
|
|
1970
|
-
return /* @__PURE__ */
|
|
2736
|
+
isLoading: y || u,
|
|
2737
|
+
isError: D,
|
|
2738
|
+
setCurrentDate: f
|
|
2739
|
+
}), [C, t, s, a, y, u, D, f]);
|
|
2740
|
+
return /* @__PURE__ */ Lt(As.Provider, { value: q, children: n });
|
|
1971
2741
|
}
|
|
1972
|
-
function
|
|
1973
|
-
const t =
|
|
2742
|
+
function _s(e) {
|
|
2743
|
+
const t = Ae(new ws({
|
|
1974
2744
|
defaultOptions: {
|
|
1975
2745
|
queries: {
|
|
1976
2746
|
retry: 1,
|
|
@@ -1980,10 +2750,10 @@ function $s(e) {
|
|
|
1980
2750
|
}
|
|
1981
2751
|
}
|
|
1982
2752
|
}));
|
|
1983
|
-
return /* @__PURE__ */
|
|
2753
|
+
return /* @__PURE__ */ Lt(ze, { client: t.current, children: /* @__PURE__ */ Lt(Is, { ...e }) });
|
|
1984
2754
|
}
|
|
1985
2755
|
export {
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
2756
|
+
As as ScheduleContext,
|
|
2757
|
+
_s as ScheduleProvider,
|
|
2758
|
+
_s as default
|
|
1989
2759
|
};
|