@tanstack/query-core 5.101.4 → 5.102.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/legacy/classPrivateFieldSet2-Bo0ZyOIv.cjs +56 -0
- package/build/legacy/classPrivateFieldSet2-CV7wyte-.js +27 -0
- package/build/legacy/classPrivateMethodInitSpec-CBwa_Y7C.js +7 -0
- package/build/legacy/classPrivateMethodInitSpec-DVhcLejn.cjs +12 -0
- package/build/legacy/environmentManager.cjs +25 -46
- package/build/legacy/environmentManager.cjs.map +1 -1
- package/build/legacy/environmentManager.d.cts +18 -2
- package/build/legacy/environmentManager.d.cts.map +1 -0
- package/build/legacy/environmentManager.d.ts +18 -2
- package/build/legacy/environmentManager.d.ts.map +1 -0
- package/build/legacy/environmentManager.js +23 -22
- package/build/legacy/environmentManager.js.map +1 -1
- package/build/legacy/focusManager.cjs +63 -104
- package/build/legacy/focusManager.cjs.map +1 -1
- package/build/legacy/focusManager.d.cts +18 -2
- package/build/legacy/focusManager.d.cts.map +1 -0
- package/build/legacy/focusManager.d.ts +18 -2
- package/build/legacy/focusManager.d.ts.map +1 -0
- package/build/legacy/focusManager.js +60 -76
- package/build/legacy/focusManager.js.map +1 -1
- package/build/legacy/hydration-D1E7ZbjZ.d.ts +1374 -0
- package/build/legacy/hydration-D1E7ZbjZ.d.ts.map +1 -0
- package/build/legacy/hydration-NBquRCHe.d.cts +1374 -0
- package/build/legacy/hydration-NBquRCHe.d.cts.map +1 -0
- package/build/legacy/hydration.cjs +114 -194
- package/build/legacy/hydration.cjs.map +1 -1
- package/build/legacy/hydration.d.cts +2 -7
- package/build/legacy/hydration.d.ts +2 -7
- package/build/legacy/hydration.js +108 -167
- package/build/legacy/hydration.js.map +1 -1
- package/build/legacy/index.cjs +59 -111
- package/build/legacy/index.cjs.map +1 -1
- package/build/legacy/index.d.cts +10 -141
- package/build/legacy/index.d.ts +10 -141
- package/build/legacy/index.js +16 -66
- package/build/legacy/index.js.map +1 -1
- package/build/legacy/infiniteQueryBehavior.cjs +92 -135
- package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +14 -3
- package/build/legacy/infiniteQueryBehavior.d.cts.map +1 -0
- package/build/legacy/infiniteQueryBehavior.d.ts +14 -3
- package/build/legacy/infiniteQueryBehavior.d.ts.map +1 -0
- package/build/legacy/infiniteQueryBehavior.js +89 -115
- package/build/legacy/infiniteQueryBehavior.js.map +1 -1
- package/build/legacy/infiniteQueryObserver.cjs +59 -88
- package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +20 -1
- package/build/legacy/infiniteQueryObserver.d.cts.map +1 -0
- package/build/legacy/infiniteQueryObserver.d.ts +20 -1
- package/build/legacy/infiniteQueryObserver.d.ts.map +1 -0
- package/build/legacy/infiniteQueryObserver.js +57 -64
- package/build/legacy/infiniteQueryObserver.js.map +1 -1
- package/build/legacy/mutation.cjs +236 -329
- package/build/legacy/mutation.cjs.map +1 -1
- package/build/legacy/mutation.d.cts +2 -4
- package/build/legacy/mutation.d.ts +2 -4
- package/build/legacy/mutation.js +231 -299
- package/build/legacy/mutation.js.map +1 -1
- package/build/legacy/mutationCache.cjs +121 -166
- package/build/legacy/mutationCache.cjs.map +1 -1
- package/build/legacy/mutationCache.d.cts +2 -2
- package/build/legacy/mutationCache.d.ts +2 -2
- package/build/legacy/mutationCache.js +117 -130
- package/build/legacy/mutationCache.js.map +1 -1
- package/build/legacy/mutationObserver.cjs +134 -187
- package/build/legacy/mutationObserver.cjs.map +1 -1
- package/build/legacy/mutationObserver.d.cts +2 -1
- package/build/legacy/mutationObserver.d.ts +2 -1
- package/build/legacy/mutationObserver.js +132 -160
- package/build/legacy/mutationObserver.js.map +1 -1
- package/build/legacy/notifyManager.cjs +76 -110
- package/build/legacy/notifyManager.cjs.map +1 -1
- package/build/legacy/notifyManager.d.cts +48 -3
- package/build/legacy/notifyManager.d.cts.map +1 -0
- package/build/legacy/notifyManager.d.ts +48 -3
- package/build/legacy/notifyManager.d.ts.map +1 -0
- package/build/legacy/notifyManager.js +73 -84
- package/build/legacy/notifyManager.js.map +1 -1
- package/build/legacy/onlineManager.cjs +57 -93
- package/build/legacy/onlineManager.cjs.map +1 -1
- package/build/legacy/onlineManager.d.cts +17 -2
- package/build/legacy/onlineManager.d.cts.map +1 -0
- package/build/legacy/onlineManager.d.ts +17 -2
- package/build/legacy/onlineManager.d.ts.map +1 -0
- package/build/legacy/onlineManager.js +54 -65
- package/build/legacy/onlineManager.js.map +1 -1
- package/build/legacy/queriesObserver.cjs +203 -262
- package/build/legacy/queriesObserver.cjs.map +1 -1
- package/build/legacy/queriesObserver.d.cts +23 -2
- package/build/legacy/queriesObserver.d.cts.map +1 -0
- package/build/legacy/queriesObserver.d.ts +23 -2
- package/build/legacy/queriesObserver.d.ts.map +1 -0
- package/build/legacy/queriesObserver.js +199 -233
- package/build/legacy/queriesObserver.js.map +1 -1
- package/build/legacy/query.cjs +409 -491
- package/build/legacy/query.cjs.map +1 -1
- package/build/legacy/query.d.cts +2 -9
- package/build/legacy/query.d.ts +2 -9
- package/build/legacy/query.js +402 -467
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryCache.cjs +99 -128
- package/build/legacy/queryCache.cjs.map +1 -1
- package/build/legacy/queryCache.d.cts +2 -3
- package/build/legacy/queryCache.d.ts +2 -3
- package/build/legacy/queryCache.js +96 -100
- package/build/legacy/queryCache.js.map +1 -1
- package/build/legacy/queryClient.cjs +295 -345
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.d.cts +2 -1
- package/build/legacy/queryClient.d.ts +2 -1
- package/build/legacy/queryClient.js +292 -318
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryObserver.cjs +350 -502
- package/build/legacy/queryObserver.cjs.map +1 -1
- package/build/legacy/queryObserver.d.cts +2 -1
- package/build/legacy/queryObserver.d.ts +2 -1
- package/build/legacy/queryObserver.js +345 -480
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/legacy/removable-DeMjhW5M.d.cts +13 -0
- package/build/legacy/removable-DeMjhW5M.d.cts.map +1 -0
- package/build/legacy/removable-DeMjhW5M.d.ts +13 -0
- package/build/legacy/removable-DeMjhW5M.d.ts.map +1 -0
- package/build/legacy/removable.cjs +31 -67
- package/build/legacy/removable.cjs.map +1 -1
- package/build/legacy/removable.d.cts +2 -1
- package/build/legacy/removable.d.ts +2 -1
- package/build/legacy/removable.js +28 -39
- package/build/legacy/removable.js.map +1 -1
- package/build/legacy/retryer.cjs +127 -155
- package/build/legacy/retryer.cjs.map +1 -1
- package/build/legacy/retryer.d.cts +2 -7
- package/build/legacy/retryer.d.ts +2 -7
- package/build/legacy/retryer.js +121 -127
- package/build/legacy/retryer.js.map +1 -1
- package/build/legacy/streamedQuery.cjs +49 -78
- package/build/legacy/streamedQuery.cjs.map +1 -1
- package/build/legacy/streamedQuery.d.cts +33 -1
- package/build/legacy/streamedQuery.d.cts.map +1 -0
- package/build/legacy/streamedQuery.d.ts +33 -1
- package/build/legacy/streamedQuery.d.ts.map +1 -0
- package/build/legacy/streamedQuery.js +47 -54
- package/build/legacy/streamedQuery.js.map +1 -1
- package/build/legacy/subscribable-CbifVTKz.d.cts +12 -0
- package/build/legacy/subscribable-CbifVTKz.d.cts.map +1 -0
- package/build/legacy/subscribable-CbifVTKz.d.ts +12 -0
- package/build/legacy/subscribable-CbifVTKz.d.ts.map +1 -0
- package/build/legacy/subscribable.cjs +22 -48
- package/build/legacy/subscribable.cjs.map +1 -1
- package/build/legacy/subscribable.d.cts +2 -1
- package/build/legacy/subscribable.d.ts +2 -1
- package/build/legacy/subscribable.js +21 -25
- package/build/legacy/subscribable.js.map +1 -1
- package/build/legacy/timeoutManager.cjs +64 -105
- package/build/legacy/timeoutManager.cjs.map +1 -1
- package/build/legacy/timeoutManager.d.cts +60 -7
- package/build/legacy/timeoutManager.d.cts.map +1 -0
- package/build/legacy/timeoutManager.d.ts +60 -7
- package/build/legacy/timeoutManager.d.ts.map +1 -0
- package/build/legacy/timeoutManager.js +60 -76
- package/build/legacy/timeoutManager.js.map +1 -1
- package/build/legacy/types.cjs +10 -35
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +2 -94
- package/build/legacy/types.d.ts +2 -94
- package/build/legacy/types.js +7 -10
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/utils.cjs +175 -300
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +2 -30
- package/build/legacy/utils.d.ts +2 -30
- package/build/legacy/utils.js +149 -252
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/environmentManager.cjs +25 -46
- package/build/modern/environmentManager.cjs.map +1 -1
- package/build/modern/environmentManager.d.cts +18 -2
- package/build/modern/environmentManager.d.cts.map +1 -0
- package/build/modern/environmentManager.d.ts +18 -2
- package/build/modern/environmentManager.d.ts.map +1 -0
- package/build/modern/environmentManager.js +23 -20
- package/build/modern/environmentManager.js.map +1 -1
- package/build/modern/focusManager.cjs +56 -90
- package/build/modern/focusManager.cjs.map +1 -1
- package/build/modern/focusManager.d.cts +18 -2
- package/build/modern/focusManager.d.cts.map +1 -0
- package/build/modern/focusManager.d.ts +18 -2
- package/build/modern/focusManager.d.ts.map +1 -0
- package/build/modern/focusManager.js +53 -63
- package/build/modern/focusManager.js.map +1 -1
- package/build/modern/hydration-D1E7ZbjZ.d.ts +1374 -0
- package/build/modern/hydration-D1E7ZbjZ.d.ts.map +1 -0
- package/build/modern/hydration-NBquRCHe.d.cts +1374 -0
- package/build/modern/hydration-NBquRCHe.d.cts.map +1 -0
- package/build/modern/hydration.cjs +105 -189
- package/build/modern/hydration.cjs.map +1 -1
- package/build/modern/hydration.d.cts +2 -7
- package/build/modern/hydration.d.ts +2 -7
- package/build/modern/hydration.js +99 -160
- package/build/modern/hydration.js.map +1 -1
- package/build/modern/index.cjs +59 -111
- package/build/modern/index.cjs.map +1 -1
- package/build/modern/index.d.cts +10 -141
- package/build/modern/index.d.ts +10 -141
- package/build/modern/index.js +16 -64
- package/build/modern/index.js.map +1 -1
- package/build/modern/infiniteQueryBehavior.cjs +89 -131
- package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +14 -3
- package/build/modern/infiniteQueryBehavior.d.cts.map +1 -0
- package/build/modern/infiniteQueryBehavior.d.ts +14 -3
- package/build/modern/infiniteQueryBehavior.d.ts.map +1 -0
- package/build/modern/infiniteQueryBehavior.js +86 -109
- package/build/modern/infiniteQueryBehavior.js.map +1 -1
- package/build/modern/infiniteQueryObserver.cjs +58 -87
- package/build/modern/infiniteQueryObserver.cjs.map +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +20 -1
- package/build/modern/infiniteQueryObserver.d.cts.map +1 -0
- package/build/modern/infiniteQueryObserver.d.ts +20 -1
- package/build/modern/infiniteQueryObserver.d.ts.map +1 -0
- package/build/modern/infiniteQueryObserver.js +56 -61
- package/build/modern/infiniteQueryObserver.js.map +1 -1
- package/build/modern/mutation.cjs +221 -303
- package/build/modern/mutation.cjs.map +1 -1
- package/build/modern/mutation.d.cts +2 -4
- package/build/modern/mutation.d.ts +2 -4
- package/build/modern/mutation.js +216 -274
- package/build/modern/mutation.js.map +1 -1
- package/build/modern/mutationCache.cjs +111 -145
- package/build/modern/mutationCache.cjs.map +1 -1
- package/build/modern/mutationCache.d.cts +2 -2
- package/build/modern/mutationCache.d.ts +2 -2
- package/build/modern/mutationCache.js +107 -117
- package/build/modern/mutationCache.js.map +1 -1
- package/build/modern/mutationObserver.cjs +115 -162
- package/build/modern/mutationObserver.cjs.map +1 -1
- package/build/modern/mutationObserver.d.cts +2 -1
- package/build/modern/mutationObserver.d.ts +2 -1
- package/build/modern/mutationObserver.js +113 -136
- package/build/modern/mutationObserver.js.map +1 -1
- package/build/modern/notifyManager.cjs +76 -110
- package/build/modern/notifyManager.cjs.map +1 -1
- package/build/modern/notifyManager.d.cts +48 -3
- package/build/modern/notifyManager.d.cts.map +1 -0
- package/build/modern/notifyManager.d.ts +48 -3
- package/build/modern/notifyManager.d.ts.map +1 -0
- package/build/modern/notifyManager.js +73 -82
- package/build/modern/notifyManager.js.map +1 -1
- package/build/modern/onlineManager.cjs +51 -80
- package/build/modern/onlineManager.cjs.map +1 -1
- package/build/modern/onlineManager.d.cts +17 -2
- package/build/modern/onlineManager.d.cts.map +1 -0
- package/build/modern/onlineManager.d.ts +17 -2
- package/build/modern/onlineManager.d.ts.map +1 -0
- package/build/modern/onlineManager.js +48 -53
- package/build/modern/onlineManager.js.map +1 -1
- package/build/modern/queriesObserver.cjs +185 -237
- package/build/modern/queriesObserver.cjs.map +1 -1
- package/build/modern/queriesObserver.d.cts +23 -2
- package/build/modern/queriesObserver.d.cts.map +1 -0
- package/build/modern/queriesObserver.d.ts +23 -2
- package/build/modern/queriesObserver.d.ts.map +1 -0
- package/build/modern/queriesObserver.js +181 -209
- package/build/modern/queriesObserver.js.map +1 -1
- package/build/modern/query.cjs +384 -464
- package/build/modern/query.cjs.map +1 -1
- package/build/modern/query.d.cts +2 -9
- package/build/modern/query.d.ts +2 -9
- package/build/modern/query.js +377 -441
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryCache.cjs +97 -119
- package/build/modern/queryCache.cjs.map +1 -1
- package/build/modern/queryCache.d.cts +2 -3
- package/build/modern/queryCache.d.ts +2 -3
- package/build/modern/queryCache.js +94 -92
- package/build/modern/queryCache.js.map +1 -1
- package/build/modern/queryClient.cjs +281 -318
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.d.cts +2 -1
- package/build/modern/queryClient.d.ts +2 -1
- package/build/modern/queryClient.js +278 -299
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryObserver.cjs +329 -475
- package/build/modern/queryObserver.cjs.map +1 -1
- package/build/modern/queryObserver.d.cts +2 -1
- package/build/modern/queryObserver.d.ts +2 -1
- package/build/modern/queryObserver.js +324 -454
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/removable-DeMjhW5M.d.cts +13 -0
- package/build/modern/removable-DeMjhW5M.d.cts.map +1 -0
- package/build/modern/removable-DeMjhW5M.d.ts +13 -0
- package/build/modern/removable-DeMjhW5M.d.ts.map +1 -0
- package/build/modern/removable.cjs +27 -56
- package/build/modern/removable.cjs.map +1 -1
- package/build/modern/removable.d.cts +2 -1
- package/build/modern/removable.d.ts +2 -1
- package/build/modern/removable.js +24 -29
- package/build/modern/removable.js.map +1 -1
- package/build/modern/retryer.cjs +121 -151
- package/build/modern/retryer.cjs.map +1 -1
- package/build/modern/retryer.d.cts +2 -7
- package/build/modern/retryer.d.ts +2 -7
- package/build/modern/retryer.js +115 -121
- package/build/modern/retryer.js.map +1 -1
- package/build/modern/streamedQuery.cjs +49 -78
- package/build/modern/streamedQuery.cjs.map +1 -1
- package/build/modern/streamedQuery.d.cts +33 -1
- package/build/modern/streamedQuery.d.cts.map +1 -0
- package/build/modern/streamedQuery.d.ts +33 -1
- package/build/modern/streamedQuery.d.ts.map +1 -0
- package/build/modern/streamedQuery.js +47 -52
- package/build/modern/streamedQuery.js.map +1 -1
- package/build/modern/subscribable-CbifVTKz.d.cts +12 -0
- package/build/modern/subscribable-CbifVTKz.d.cts.map +1 -0
- package/build/modern/subscribable-CbifVTKz.d.ts +12 -0
- package/build/modern/subscribable-CbifVTKz.d.ts.map +1 -0
- package/build/modern/subscribable.cjs +22 -48
- package/build/modern/subscribable.cjs.map +1 -1
- package/build/modern/subscribable.d.cts +2 -1
- package/build/modern/subscribable.d.ts +2 -1
- package/build/modern/subscribable.js +21 -23
- package/build/modern/subscribable.js.map +1 -1
- package/build/modern/timeoutManager.cjs +59 -93
- package/build/modern/timeoutManager.cjs.map +1 -1
- package/build/modern/timeoutManager.d.cts +60 -7
- package/build/modern/timeoutManager.d.cts.map +1 -0
- package/build/modern/timeoutManager.d.ts +60 -7
- package/build/modern/timeoutManager.d.ts.map +1 -0
- package/build/modern/timeoutManager.js +55 -65
- package/build/modern/timeoutManager.js.map +1 -1
- package/build/modern/types.cjs +10 -35
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +2 -94
- package/build/modern/types.d.ts +2 -94
- package/build/modern/types.js +8 -9
- package/build/modern/types.js.map +1 -1
- package/build/modern/utils.cjs +175 -300
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +2 -30
- package/build/modern/utils.d.ts +2 -30
- package/build/modern/utils.js +149 -250
- package/build/modern/utils.js.map +1 -1
- package/package.json +3 -5
- package/src/hydration.ts +62 -44
- package/src/index.ts +1 -0
- package/src/mutation.ts +14 -6
- package/src/mutationObserver.ts +8 -0
- package/src/queriesObserver.ts +14 -8
- package/src/query.ts +14 -6
- package/src/queryClient.ts +90 -2
- package/src/queryObserver.ts +41 -64
- package/src/retryer.ts +20 -12
- package/src/types.ts +70 -58
- package/build/legacy/_tsup-dts-rollup.d.cts +0 -2188
- package/build/legacy/_tsup-dts-rollup.d.ts +0 -2188
- package/build/legacy/chunk-PXG64RU4.js +0 -25
- package/build/legacy/chunk-PXG64RU4.js.map +0 -1
- package/build/legacy/thenable.cjs +0 -76
- package/build/legacy/thenable.cjs.map +0 -1
- package/build/legacy/thenable.d.cts +0 -6
- package/build/legacy/thenable.d.ts +0 -6
- package/build/legacy/thenable.js +0 -52
- package/build/legacy/thenable.js.map +0 -1
- package/build/modern/_tsup-dts-rollup.d.cts +0 -2188
- package/build/modern/_tsup-dts-rollup.d.ts +0 -2188
- package/build/modern/thenable.cjs +0 -75
- package/build/modern/thenable.cjs.map +0 -1
- package/build/modern/thenable.d.cts +0 -6
- package/build/modern/thenable.d.ts +0 -6
- package/build/modern/thenable.js +0 -49
- package/build/modern/thenable.js.map +0 -1
- package/src/thenable.ts +0 -111
package/build/modern/query.js
CHANGED
|
@@ -1,454 +1,390 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
ensureQueryFn,
|
|
4
|
-
noop,
|
|
5
|
-
replaceData,
|
|
6
|
-
resolveQueryBoolean,
|
|
7
|
-
resolveStaleTime,
|
|
8
|
-
skipToken,
|
|
9
|
-
timeUntilStale
|
|
10
|
-
} from "./utils.js";
|
|
1
|
+
import { ensureQueryFn, noop, replaceData, resolveQueryBoolean, resolveStaleTime, skipToken, timeUntilStale } from "./utils.js";
|
|
11
2
|
import { notifyManager } from "./notifyManager.js";
|
|
12
3
|
import { CancelledError, canFetch, createRetryer } from "./retryer.js";
|
|
13
4
|
import { Removable } from "./removable.js";
|
|
14
5
|
import { infiniteQueryBehavior } from "./infiniteQueryBehavior.js";
|
|
6
|
+
//#region src/query.ts
|
|
15
7
|
var Query = class extends Removable {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
};
|
|
356
|
-
case "fetch":
|
|
357
|
-
return {
|
|
358
|
-
...state,
|
|
359
|
-
...fetchState(state.data, this.options),
|
|
360
|
-
fetchMeta: action.meta ?? null
|
|
361
|
-
};
|
|
362
|
-
case "success":
|
|
363
|
-
const newState = {
|
|
364
|
-
...state,
|
|
365
|
-
...successState(action.data, action.dataUpdatedAt),
|
|
366
|
-
dataUpdateCount: state.dataUpdateCount + 1,
|
|
367
|
-
...!action.manual && {
|
|
368
|
-
fetchStatus: "idle",
|
|
369
|
-
fetchFailureCount: 0,
|
|
370
|
-
fetchFailureReason: null
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
this.#revertState = action.manual ? newState : void 0;
|
|
374
|
-
return newState;
|
|
375
|
-
case "error":
|
|
376
|
-
const error = action.error;
|
|
377
|
-
return {
|
|
378
|
-
...state,
|
|
379
|
-
error,
|
|
380
|
-
errorUpdateCount: state.errorUpdateCount + 1,
|
|
381
|
-
errorUpdatedAt: Date.now(),
|
|
382
|
-
fetchFailureCount: state.fetchFailureCount + 1,
|
|
383
|
-
fetchFailureReason: error,
|
|
384
|
-
fetchStatus: "idle",
|
|
385
|
-
status: "error",
|
|
386
|
-
// flag existing data as invalidated if we get a background error
|
|
387
|
-
// note that "no data" always means stale so we can set unconditionally here
|
|
388
|
-
isInvalidated: true
|
|
389
|
-
};
|
|
390
|
-
case "invalidate":
|
|
391
|
-
return {
|
|
392
|
-
...state,
|
|
393
|
-
isInvalidated: true
|
|
394
|
-
};
|
|
395
|
-
case "setState":
|
|
396
|
-
return {
|
|
397
|
-
...state,
|
|
398
|
-
...action.state
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
this.state = reducer(this.state);
|
|
403
|
-
notifyManager.batch(() => {
|
|
404
|
-
this.observers.forEach((observer) => {
|
|
405
|
-
observer.onQueryUpdate();
|
|
406
|
-
});
|
|
407
|
-
this.#cache.notify({ query: this, type: "updated", action });
|
|
408
|
-
});
|
|
409
|
-
}
|
|
8
|
+
#queryType;
|
|
9
|
+
#initialState;
|
|
10
|
+
#revertState;
|
|
11
|
+
#cache;
|
|
12
|
+
#client;
|
|
13
|
+
#retryer;
|
|
14
|
+
#defaultOptions;
|
|
15
|
+
#abortSignalConsumed;
|
|
16
|
+
constructor(config) {
|
|
17
|
+
super();
|
|
18
|
+
this.#abortSignalConsumed = false;
|
|
19
|
+
this.#defaultOptions = config.defaultOptions;
|
|
20
|
+
this.setOptions(config.options);
|
|
21
|
+
this.observers = [];
|
|
22
|
+
this.#client = config.client;
|
|
23
|
+
this.#cache = this.#client.getQueryCache();
|
|
24
|
+
this.queryKey = config.queryKey;
|
|
25
|
+
this.queryHash = config.queryHash;
|
|
26
|
+
this.#initialState = getDefaultState(this.options);
|
|
27
|
+
this.state = config.state ?? this.#initialState;
|
|
28
|
+
this.scheduleGc();
|
|
29
|
+
}
|
|
30
|
+
get meta() {
|
|
31
|
+
return this.options.meta;
|
|
32
|
+
}
|
|
33
|
+
get queryType() {
|
|
34
|
+
return this.#queryType;
|
|
35
|
+
}
|
|
36
|
+
get promise() {
|
|
37
|
+
return this.#retryer?.promise;
|
|
38
|
+
}
|
|
39
|
+
setOptions(options) {
|
|
40
|
+
this.options = {
|
|
41
|
+
...this.#defaultOptions,
|
|
42
|
+
...options
|
|
43
|
+
};
|
|
44
|
+
if (options?._type) this.#queryType = options._type;
|
|
45
|
+
this.updateGcTime(this.options.gcTime);
|
|
46
|
+
if (this.state && this.state.data === void 0) {
|
|
47
|
+
const defaultState = getDefaultState(this.options);
|
|
48
|
+
if (defaultState.data !== void 0) {
|
|
49
|
+
this.setState(successState(defaultState.data, defaultState.dataUpdatedAt));
|
|
50
|
+
this.#initialState = defaultState;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
optionalRemove() {
|
|
55
|
+
if (!this.observers.length && this.state.fetchStatus === "idle") this.#cache.remove(this);
|
|
56
|
+
}
|
|
57
|
+
setData(newData, options) {
|
|
58
|
+
const data = replaceData(this.state.data, newData, this.options);
|
|
59
|
+
this.#dispatch({
|
|
60
|
+
data,
|
|
61
|
+
type: "success",
|
|
62
|
+
dataUpdatedAt: options?.updatedAt,
|
|
63
|
+
manual: options?.manual
|
|
64
|
+
});
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
setState(state) {
|
|
68
|
+
this.#dispatch({
|
|
69
|
+
type: "setState",
|
|
70
|
+
state
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
cancel(options) {
|
|
74
|
+
const promise = this.#retryer?.promise;
|
|
75
|
+
this.#retryer?.cancel(options);
|
|
76
|
+
return promise ? promise.then(noop).catch(noop) : Promise.resolve();
|
|
77
|
+
}
|
|
78
|
+
destroy() {
|
|
79
|
+
super.destroy();
|
|
80
|
+
this.cancel({ silent: true });
|
|
81
|
+
}
|
|
82
|
+
get resetState() {
|
|
83
|
+
return this.#initialState;
|
|
84
|
+
}
|
|
85
|
+
reset() {
|
|
86
|
+
this.destroy();
|
|
87
|
+
this.setState(this.resetState);
|
|
88
|
+
}
|
|
89
|
+
isActive() {
|
|
90
|
+
return this.observers.some((observer) => resolveQueryBoolean(observer.options.enabled, this) !== false);
|
|
91
|
+
}
|
|
92
|
+
isDisabled() {
|
|
93
|
+
if (this.getObserversCount() > 0) return !this.isActive();
|
|
94
|
+
return this.options.queryFn === skipToken || !this.isFetched();
|
|
95
|
+
}
|
|
96
|
+
isFetched() {
|
|
97
|
+
return this.state.dataUpdateCount + this.state.errorUpdateCount > 0;
|
|
98
|
+
}
|
|
99
|
+
isStatic() {
|
|
100
|
+
if (this.getObserversCount() > 0) return this.observers.some((observer) => resolveStaleTime(observer.options.staleTime, this) === "static");
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
isStale() {
|
|
104
|
+
if (this.getObserversCount() > 0) return this.observers.some((observer) => observer.getCurrentResult().isStale);
|
|
105
|
+
return this.state.data === void 0 || this.state.isInvalidated;
|
|
106
|
+
}
|
|
107
|
+
isStaleByTime(staleTime = 0) {
|
|
108
|
+
if (this.state.data === void 0) return true;
|
|
109
|
+
if (staleTime === "static") return false;
|
|
110
|
+
if (this.state.isInvalidated) return true;
|
|
111
|
+
return !timeUntilStale(this.state.dataUpdatedAt, staleTime);
|
|
112
|
+
}
|
|
113
|
+
onFocus() {
|
|
114
|
+
this.observers.find((x) => x.shouldFetchOnWindowFocus())?.refetch({ cancelRefetch: false });
|
|
115
|
+
this.#retryer?.continue();
|
|
116
|
+
}
|
|
117
|
+
onOnline() {
|
|
118
|
+
this.observers.find((x) => x.shouldFetchOnReconnect())?.refetch({ cancelRefetch: false });
|
|
119
|
+
this.#retryer?.continue();
|
|
120
|
+
}
|
|
121
|
+
addObserver(observer) {
|
|
122
|
+
if (!this.observers.includes(observer)) {
|
|
123
|
+
this.observers.push(observer);
|
|
124
|
+
this.clearGcTimeout();
|
|
125
|
+
this.#cache.notify({
|
|
126
|
+
type: "observerAdded",
|
|
127
|
+
query: this,
|
|
128
|
+
observer
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
removeObserver(observer) {
|
|
133
|
+
const index = this.observers.indexOf(observer);
|
|
134
|
+
if (index !== -1) {
|
|
135
|
+
this.observers.splice(index, 1);
|
|
136
|
+
if (!this.observers.length) {
|
|
137
|
+
if (this.#retryer) {
|
|
138
|
+
if (this.#abortSignalConsumed || this.#isInitialPausedFetch()) this.#retryer.cancel({ revert: true });
|
|
139
|
+
else this.#retryer.cancelRetry();
|
|
140
|
+
}
|
|
141
|
+
this.scheduleGc();
|
|
142
|
+
}
|
|
143
|
+
this.#cache.notify({
|
|
144
|
+
type: "observerRemoved",
|
|
145
|
+
query: this,
|
|
146
|
+
observer
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
getObserversCount() {
|
|
151
|
+
return this.observers.length;
|
|
152
|
+
}
|
|
153
|
+
#isInitialPausedFetch() {
|
|
154
|
+
return this.state.fetchStatus === "paused" && this.state.status === "pending";
|
|
155
|
+
}
|
|
156
|
+
invalidate() {
|
|
157
|
+
if (!this.state.isInvalidated) this.#dispatch({ type: "invalidate" });
|
|
158
|
+
}
|
|
159
|
+
async fetch(options, fetchOptions) {
|
|
160
|
+
if (this.state.fetchStatus !== "idle" && this.#retryer?.status() !== "rejected") {
|
|
161
|
+
if (this.state.data !== void 0 && fetchOptions?.cancelRefetch) this.cancel({ silent: true });
|
|
162
|
+
else if (this.#retryer) {
|
|
163
|
+
this.#retryer.continueRetry();
|
|
164
|
+
return this.#retryer.promise;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (options) this.setOptions(options);
|
|
168
|
+
if (!this.options.queryFn) {
|
|
169
|
+
const observer = this.observers.find((x) => x.options.queryFn);
|
|
170
|
+
if (observer) this.setOptions(observer.options);
|
|
171
|
+
}
|
|
172
|
+
if (process.env.NODE_ENV !== "production") {
|
|
173
|
+
if (!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']`);
|
|
174
|
+
}
|
|
175
|
+
const abortController = new AbortController();
|
|
176
|
+
const addSignalProperty = (object) => {
|
|
177
|
+
Object.defineProperty(object, "signal", {
|
|
178
|
+
enumerable: true,
|
|
179
|
+
get: () => {
|
|
180
|
+
this.#abortSignalConsumed = true;
|
|
181
|
+
return abortController.signal;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
const fetchFn = () => {
|
|
186
|
+
const queryFn = ensureQueryFn(this.options, fetchOptions);
|
|
187
|
+
const createQueryFnContext = () => {
|
|
188
|
+
const queryFnContext = {
|
|
189
|
+
client: this.#client,
|
|
190
|
+
queryKey: this.queryKey,
|
|
191
|
+
meta: this.meta
|
|
192
|
+
};
|
|
193
|
+
addSignalProperty(queryFnContext);
|
|
194
|
+
return queryFnContext;
|
|
195
|
+
};
|
|
196
|
+
const queryFnContext = createQueryFnContext();
|
|
197
|
+
this.#abortSignalConsumed = false;
|
|
198
|
+
if (this.options.persister) return this.options.persister(queryFn, queryFnContext, this);
|
|
199
|
+
return queryFn(queryFnContext);
|
|
200
|
+
};
|
|
201
|
+
const createFetchContext = () => {
|
|
202
|
+
const context = {
|
|
203
|
+
fetchOptions,
|
|
204
|
+
options: this.options,
|
|
205
|
+
queryKey: this.queryKey,
|
|
206
|
+
client: this.#client,
|
|
207
|
+
state: this.state,
|
|
208
|
+
fetchFn
|
|
209
|
+
};
|
|
210
|
+
addSignalProperty(context);
|
|
211
|
+
return context;
|
|
212
|
+
};
|
|
213
|
+
const context = createFetchContext();
|
|
214
|
+
(this.#queryType === "infinite" ? infiniteQueryBehavior(this.options.pages) : this.options.behavior)?.onFetch(context, this);
|
|
215
|
+
this.#revertState = this.state;
|
|
216
|
+
if (this.state.fetchStatus === "idle" || this.state.fetchMeta !== context.fetchOptions?.meta) this.#dispatch({
|
|
217
|
+
type: "fetch",
|
|
218
|
+
meta: context.fetchOptions?.meta
|
|
219
|
+
});
|
|
220
|
+
const retryer = this.#retryer = createRetryer({
|
|
221
|
+
initialPromise: fetchOptions?.initialPromise,
|
|
222
|
+
fn: context.fetchFn,
|
|
223
|
+
onCancel: (error) => {
|
|
224
|
+
if (error instanceof CancelledError && error.revert) this.setState({
|
|
225
|
+
...this.#revertState,
|
|
226
|
+
fetchStatus: "idle"
|
|
227
|
+
});
|
|
228
|
+
abortController.abort();
|
|
229
|
+
},
|
|
230
|
+
onFail: (failureCount, error) => {
|
|
231
|
+
this.#dispatch({
|
|
232
|
+
type: "failed",
|
|
233
|
+
failureCount,
|
|
234
|
+
error
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
onPause: () => {
|
|
238
|
+
this.#dispatch({ type: "pause" });
|
|
239
|
+
},
|
|
240
|
+
onContinue: () => {
|
|
241
|
+
this.#dispatch({ type: "continue" });
|
|
242
|
+
},
|
|
243
|
+
retry: context.options.retry,
|
|
244
|
+
retryDelay: context.options.retryDelay,
|
|
245
|
+
networkMode: context.options.networkMode,
|
|
246
|
+
canRun: () => true
|
|
247
|
+
});
|
|
248
|
+
try {
|
|
249
|
+
const data = await retryer.start();
|
|
250
|
+
if (data === void 0) {
|
|
251
|
+
if (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}`);
|
|
252
|
+
throw new Error(`${this.queryHash} data is undefined`);
|
|
253
|
+
}
|
|
254
|
+
this.setData(data);
|
|
255
|
+
this.#cache.config.onSuccess?.(data, this);
|
|
256
|
+
this.#cache.config.onSettled?.(data, this.state.error, this);
|
|
257
|
+
return data;
|
|
258
|
+
} catch (error) {
|
|
259
|
+
if (error instanceof CancelledError) {
|
|
260
|
+
if (error.silent) return this.#retryer.promise;
|
|
261
|
+
else if (error.revert) {
|
|
262
|
+
if (this.state.data === void 0) throw error;
|
|
263
|
+
return this.state.data;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
this.#dispatch({
|
|
267
|
+
type: "error",
|
|
268
|
+
error
|
|
269
|
+
});
|
|
270
|
+
this.#cache.config.onError?.(error, this);
|
|
271
|
+
this.#cache.config.onSettled?.(this.state.data, error, this);
|
|
272
|
+
throw error;
|
|
273
|
+
} finally {
|
|
274
|
+
if (this.#retryer === retryer) this.#retryer = void 0;
|
|
275
|
+
this.scheduleGc();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
#dispatch(action) {
|
|
279
|
+
const reducer = (state) => {
|
|
280
|
+
switch (action.type) {
|
|
281
|
+
case "failed": return {
|
|
282
|
+
...state,
|
|
283
|
+
fetchFailureCount: action.failureCount,
|
|
284
|
+
fetchFailureReason: action.error
|
|
285
|
+
};
|
|
286
|
+
case "pause": return {
|
|
287
|
+
...state,
|
|
288
|
+
fetchStatus: "paused"
|
|
289
|
+
};
|
|
290
|
+
case "continue": return {
|
|
291
|
+
...state,
|
|
292
|
+
fetchStatus: "fetching"
|
|
293
|
+
};
|
|
294
|
+
case "fetch": return {
|
|
295
|
+
...state,
|
|
296
|
+
...fetchState(state.data, this.options),
|
|
297
|
+
fetchMeta: action.meta ?? null
|
|
298
|
+
};
|
|
299
|
+
case "success":
|
|
300
|
+
const newState = {
|
|
301
|
+
...state,
|
|
302
|
+
...successState(action.data, action.dataUpdatedAt),
|
|
303
|
+
dataUpdateCount: state.dataUpdateCount + 1,
|
|
304
|
+
...!action.manual && {
|
|
305
|
+
fetchStatus: "idle",
|
|
306
|
+
fetchFailureCount: 0,
|
|
307
|
+
fetchFailureReason: null
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
this.#revertState = action.manual ? newState : void 0;
|
|
311
|
+
return newState;
|
|
312
|
+
case "error":
|
|
313
|
+
const error = action.error;
|
|
314
|
+
return {
|
|
315
|
+
...state,
|
|
316
|
+
error,
|
|
317
|
+
errorUpdateCount: state.errorUpdateCount + 1,
|
|
318
|
+
errorUpdatedAt: Date.now(),
|
|
319
|
+
fetchFailureCount: state.fetchFailureCount + 1,
|
|
320
|
+
fetchFailureReason: error,
|
|
321
|
+
fetchStatus: "idle",
|
|
322
|
+
status: "error",
|
|
323
|
+
isInvalidated: true
|
|
324
|
+
};
|
|
325
|
+
case "invalidate": return {
|
|
326
|
+
...state,
|
|
327
|
+
isInvalidated: true
|
|
328
|
+
};
|
|
329
|
+
case "setState": return {
|
|
330
|
+
...state,
|
|
331
|
+
...action.state
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
this.state = reducer(this.state);
|
|
336
|
+
notifyManager.batch(() => {
|
|
337
|
+
this.observers.slice().forEach((observer) => {
|
|
338
|
+
observer.onQueryUpdate();
|
|
339
|
+
});
|
|
340
|
+
this.#cache.notify({
|
|
341
|
+
query: this,
|
|
342
|
+
type: "updated",
|
|
343
|
+
action
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
}
|
|
410
347
|
};
|
|
411
348
|
function fetchState(data, options) {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
349
|
+
return {
|
|
350
|
+
fetchFailureCount: 0,
|
|
351
|
+
fetchFailureReason: null,
|
|
352
|
+
fetchStatus: canFetch(options.networkMode) ? "fetching" : "paused",
|
|
353
|
+
...data === void 0 && {
|
|
354
|
+
error: null,
|
|
355
|
+
status: "pending"
|
|
356
|
+
}
|
|
357
|
+
};
|
|
421
358
|
}
|
|
422
359
|
function successState(data, dataUpdatedAt) {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
360
|
+
return {
|
|
361
|
+
data,
|
|
362
|
+
dataUpdatedAt: dataUpdatedAt ?? Date.now(),
|
|
363
|
+
error: null,
|
|
364
|
+
isInvalidated: false,
|
|
365
|
+
status: "success"
|
|
366
|
+
};
|
|
430
367
|
}
|
|
431
368
|
function getDefaultState(options) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
369
|
+
const data = typeof options.initialData === "function" ? options.initialData() : options.initialData;
|
|
370
|
+
const hasData = data !== void 0;
|
|
371
|
+
const initialDataUpdatedAt = hasData ? typeof options.initialDataUpdatedAt === "function" ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
|
|
372
|
+
return {
|
|
373
|
+
data,
|
|
374
|
+
dataUpdateCount: 0,
|
|
375
|
+
dataUpdatedAt: hasData ? initialDataUpdatedAt ?? Date.now() : 0,
|
|
376
|
+
error: null,
|
|
377
|
+
errorUpdateCount: 0,
|
|
378
|
+
errorUpdatedAt: 0,
|
|
379
|
+
fetchFailureCount: 0,
|
|
380
|
+
fetchFailureReason: null,
|
|
381
|
+
fetchMeta: null,
|
|
382
|
+
isInvalidated: false,
|
|
383
|
+
status: hasData ? "success" : "pending",
|
|
384
|
+
fetchStatus: "idle"
|
|
385
|
+
};
|
|
449
386
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
};
|
|
387
|
+
//#endregion
|
|
388
|
+
export { Query, fetchState };
|
|
389
|
+
|
|
454
390
|
//# sourceMappingURL=query.js.map
|