@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
|
@@ -1,472 +1,342 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { timeoutManager } from "./timeoutManager.js";
|
|
2
|
+
import { isValidTimeout, noop, replaceData, resolveQueryBoolean, resolveStaleTime, shallowEqualObjects, timeUntilStale } from "./utils.js";
|
|
3
3
|
import { environmentManager } from "./environmentManager.js";
|
|
4
|
+
import { Subscribable } from "./subscribable.js";
|
|
5
|
+
import { focusManager } from "./focusManager.js";
|
|
4
6
|
import { notifyManager } from "./notifyManager.js";
|
|
5
7
|
import { fetchState } from "./query.js";
|
|
6
|
-
|
|
7
|
-
import { pendingThenable } from "./thenable.js";
|
|
8
|
-
import {
|
|
9
|
-
isValidTimeout,
|
|
10
|
-
noop,
|
|
11
|
-
replaceData,
|
|
12
|
-
resolveQueryBoolean,
|
|
13
|
-
resolveStaleTime,
|
|
14
|
-
shallowEqualObjects,
|
|
15
|
-
timeUntilStale
|
|
16
|
-
} from "./utils.js";
|
|
17
|
-
import { timeoutManager } from "./timeoutManager.js";
|
|
8
|
+
//#region src/queryObserver.ts
|
|
18
9
|
var QueryObserver = class extends Subscribable {
|
|
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
|
-
failureCount: newState.fetchFailureCount,
|
|
325
|
-
failureReason: newState.fetchFailureReason,
|
|
326
|
-
errorUpdateCount: newState.errorUpdateCount,
|
|
327
|
-
isFetched: query.isFetched(),
|
|
328
|
-
isFetchedAfterMount: newState.dataUpdateCount > queryInitialState.dataUpdateCount || newState.errorUpdateCount > queryInitialState.errorUpdateCount,
|
|
329
|
-
isFetching,
|
|
330
|
-
isRefetching: isFetching && !isPending,
|
|
331
|
-
isLoadingError: isError && !hasData,
|
|
332
|
-
isPaused: newState.fetchStatus === "paused",
|
|
333
|
-
isPlaceholderData,
|
|
334
|
-
isRefetchError: isError && hasData,
|
|
335
|
-
isStale: isStale(query, options),
|
|
336
|
-
refetch: this.refetch,
|
|
337
|
-
promise: this.#currentThenable,
|
|
338
|
-
isEnabled: resolveQueryBoolean(options.enabled, query) !== false
|
|
339
|
-
};
|
|
340
|
-
const nextResult = result;
|
|
341
|
-
if (this.options.experimental_prefetchInRender) {
|
|
342
|
-
const hasResultData = nextResult.data !== void 0;
|
|
343
|
-
const isErrorWithoutData = nextResult.status === "error" && !hasResultData;
|
|
344
|
-
const finalizeThenableIfPossible = (thenable) => {
|
|
345
|
-
if (isErrorWithoutData) {
|
|
346
|
-
thenable.reject(nextResult.error);
|
|
347
|
-
} else if (hasResultData) {
|
|
348
|
-
thenable.resolve(nextResult.data);
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
const recreateThenable = () => {
|
|
352
|
-
const pending = this.#currentThenable = nextResult.promise = pendingThenable();
|
|
353
|
-
finalizeThenableIfPossible(pending);
|
|
354
|
-
};
|
|
355
|
-
const prevThenable = this.#currentThenable;
|
|
356
|
-
switch (prevThenable.status) {
|
|
357
|
-
case "pending":
|
|
358
|
-
if (query.queryHash === prevQuery.queryHash) {
|
|
359
|
-
finalizeThenableIfPossible(prevThenable);
|
|
360
|
-
}
|
|
361
|
-
break;
|
|
362
|
-
case "fulfilled":
|
|
363
|
-
if (isErrorWithoutData || nextResult.data !== prevThenable.value) {
|
|
364
|
-
recreateThenable();
|
|
365
|
-
}
|
|
366
|
-
break;
|
|
367
|
-
case "rejected":
|
|
368
|
-
if (!isErrorWithoutData || nextResult.error !== prevThenable.reason) {
|
|
369
|
-
recreateThenable();
|
|
370
|
-
}
|
|
371
|
-
break;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
return nextResult;
|
|
375
|
-
}
|
|
376
|
-
updateResult() {
|
|
377
|
-
const prevResult = this.#currentResult;
|
|
378
|
-
const nextResult = this.createResult(this.#currentQuery, this.options);
|
|
379
|
-
this.#currentResultState = this.#currentQuery.state;
|
|
380
|
-
this.#currentResultOptions = this.options;
|
|
381
|
-
if (this.#currentResultState.data !== void 0) {
|
|
382
|
-
this.#lastQueryWithDefinedData = this.#currentQuery;
|
|
383
|
-
}
|
|
384
|
-
if (shallowEqualObjects(nextResult, prevResult)) {
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
this.#currentResult = nextResult;
|
|
388
|
-
const shouldNotifyListeners = () => {
|
|
389
|
-
if (!prevResult) {
|
|
390
|
-
return true;
|
|
391
|
-
}
|
|
392
|
-
const { notifyOnChangeProps } = this.options;
|
|
393
|
-
const notifyOnChangePropsValue = typeof notifyOnChangeProps === "function" ? notifyOnChangeProps() : notifyOnChangeProps;
|
|
394
|
-
if (notifyOnChangePropsValue === "all" || !notifyOnChangePropsValue && !this.#trackedProps.size) {
|
|
395
|
-
return true;
|
|
396
|
-
}
|
|
397
|
-
const includedProps = new Set(
|
|
398
|
-
notifyOnChangePropsValue ?? this.#trackedProps
|
|
399
|
-
);
|
|
400
|
-
if (this.options.throwOnError) {
|
|
401
|
-
includedProps.add("error");
|
|
402
|
-
}
|
|
403
|
-
return Object.keys(this.#currentResult).some((key) => {
|
|
404
|
-
const typedKey = key;
|
|
405
|
-
const changed = this.#currentResult[typedKey] !== prevResult[typedKey];
|
|
406
|
-
return changed && includedProps.has(typedKey);
|
|
407
|
-
});
|
|
408
|
-
};
|
|
409
|
-
this.#notify({ listeners: shouldNotifyListeners() });
|
|
410
|
-
}
|
|
411
|
-
#updateQuery() {
|
|
412
|
-
const query = this.#client.getQueryCache().build(this.#client, this.options);
|
|
413
|
-
if (query === this.#currentQuery) {
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
const prevQuery = this.#currentQuery;
|
|
417
|
-
this.#currentQuery = query;
|
|
418
|
-
this.#currentQueryInitialState = query.state;
|
|
419
|
-
if (this.hasListeners()) {
|
|
420
|
-
prevQuery?.removeObserver(this);
|
|
421
|
-
query.addObserver(this);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
onQueryUpdate() {
|
|
425
|
-
this.updateResult();
|
|
426
|
-
if (this.hasListeners()) {
|
|
427
|
-
this.#updateTimers();
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
#notify(notifyOptions) {
|
|
431
|
-
notifyManager.batch(() => {
|
|
432
|
-
if (notifyOptions.listeners) {
|
|
433
|
-
this.listeners.forEach((listener) => {
|
|
434
|
-
listener(this.#currentResult);
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
this.#client.getQueryCache().notify({
|
|
438
|
-
query: this.#currentQuery,
|
|
439
|
-
type: "observerResultsUpdated"
|
|
440
|
-
});
|
|
441
|
-
});
|
|
442
|
-
}
|
|
10
|
+
#client;
|
|
11
|
+
#currentQuery = void 0;
|
|
12
|
+
#currentQueryInitialState = void 0;
|
|
13
|
+
#currentResult = void 0;
|
|
14
|
+
#currentResultState;
|
|
15
|
+
#currentResultOptions;
|
|
16
|
+
#selectError;
|
|
17
|
+
#selectFn;
|
|
18
|
+
#selectResult;
|
|
19
|
+
#lastQueryWithDefinedData;
|
|
20
|
+
#staleTimeoutId;
|
|
21
|
+
#refetchIntervalId;
|
|
22
|
+
#currentRefetchInterval;
|
|
23
|
+
#trackedProps = /* @__PURE__ */ new Set();
|
|
24
|
+
constructor(client, options) {
|
|
25
|
+
super();
|
|
26
|
+
this.options = options;
|
|
27
|
+
this.#client = client;
|
|
28
|
+
this.#selectError = null;
|
|
29
|
+
this.bindMethods();
|
|
30
|
+
this.setOptions(options);
|
|
31
|
+
}
|
|
32
|
+
bindMethods() {
|
|
33
|
+
this.refetch = this.refetch.bind(this);
|
|
34
|
+
}
|
|
35
|
+
onSubscribe() {
|
|
36
|
+
if (this.listeners.size === 1) {
|
|
37
|
+
this.#currentQuery.addObserver(this);
|
|
38
|
+
if (shouldFetchOnMount(this.#currentQuery, this.options)) this.#executeFetch();
|
|
39
|
+
else this.updateResult();
|
|
40
|
+
this.#updateTimers();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
onUnsubscribe() {
|
|
44
|
+
if (!this.hasListeners()) this.destroy();
|
|
45
|
+
}
|
|
46
|
+
shouldFetchOnReconnect() {
|
|
47
|
+
return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnReconnect);
|
|
48
|
+
}
|
|
49
|
+
shouldFetchOnWindowFocus() {
|
|
50
|
+
return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
|
|
51
|
+
}
|
|
52
|
+
destroy() {
|
|
53
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
54
|
+
this.#clearStaleTimeout();
|
|
55
|
+
this.#clearRefetchInterval();
|
|
56
|
+
this.#currentQuery.removeObserver(this);
|
|
57
|
+
}
|
|
58
|
+
setOptions(options) {
|
|
59
|
+
const prevOptions = this.options;
|
|
60
|
+
const prevQuery = this.#currentQuery;
|
|
61
|
+
this.options = this.#client.defaultQueryOptions(options);
|
|
62
|
+
if (this.options.enabled !== void 0 && typeof this.options.enabled !== "boolean" && typeof this.options.enabled !== "function" && typeof resolveQueryBoolean(this.options.enabled, this.#currentQuery) !== "boolean") throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");
|
|
63
|
+
this.#updateQuery();
|
|
64
|
+
this.#currentQuery.setOptions(this.options);
|
|
65
|
+
if (prevOptions._defaulted && !shallowEqualObjects(this.options, prevOptions)) this.#client.getQueryCache().notify({
|
|
66
|
+
type: "observerOptionsUpdated",
|
|
67
|
+
query: this.#currentQuery,
|
|
68
|
+
observer: this
|
|
69
|
+
});
|
|
70
|
+
const mounted = this.hasListeners();
|
|
71
|
+
if (mounted && shouldFetchOptionally(this.#currentQuery, prevQuery, this.options, prevOptions)) this.#executeFetch();
|
|
72
|
+
this.updateResult();
|
|
73
|
+
if (mounted && (this.#currentQuery !== prevQuery || resolveQueryBoolean(this.options.enabled, this.#currentQuery) !== resolveQueryBoolean(prevOptions.enabled, this.#currentQuery) || resolveStaleTime(this.options.staleTime, this.#currentQuery) !== resolveStaleTime(prevOptions.staleTime, this.#currentQuery))) this.#updateStaleTimeout();
|
|
74
|
+
const nextRefetchInterval = this.#computeRefetchInterval();
|
|
75
|
+
if (mounted && (this.#currentQuery !== prevQuery || resolveQueryBoolean(this.options.enabled, this.#currentQuery) !== resolveQueryBoolean(prevOptions.enabled, this.#currentQuery) || nextRefetchInterval !== this.#currentRefetchInterval)) this.#updateRefetchInterval(nextRefetchInterval);
|
|
76
|
+
}
|
|
77
|
+
getOptimisticResult(options) {
|
|
78
|
+
const query = this.#client.getQueryCache().build(this.#client, options);
|
|
79
|
+
const result = this.createResult(query, options);
|
|
80
|
+
if (shouldAssignObserverCurrentProperties(this, result)) {
|
|
81
|
+
this.#currentResult = result;
|
|
82
|
+
this.#currentResultOptions = this.options;
|
|
83
|
+
this.#currentResultState = this.#currentQuery.state;
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
getCurrentResult() {
|
|
88
|
+
return this.#currentResult;
|
|
89
|
+
}
|
|
90
|
+
trackResult(result, onPropTracked) {
|
|
91
|
+
return new Proxy(result, { get: (target, key) => {
|
|
92
|
+
this.trackProp(key);
|
|
93
|
+
onPropTracked?.(key);
|
|
94
|
+
return Reflect.get(target, key);
|
|
95
|
+
} });
|
|
96
|
+
}
|
|
97
|
+
trackProp(key) {
|
|
98
|
+
this.#trackedProps.add(key);
|
|
99
|
+
}
|
|
100
|
+
getCurrentQuery() {
|
|
101
|
+
return this.#currentQuery;
|
|
102
|
+
}
|
|
103
|
+
refetch({ ...options } = {}) {
|
|
104
|
+
return this.fetch({ ...options });
|
|
105
|
+
}
|
|
106
|
+
fetchOptimistic(options) {
|
|
107
|
+
const defaultedOptions = this.#client.defaultQueryOptions(options);
|
|
108
|
+
const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
|
|
109
|
+
let unsubscribe = () => {};
|
|
110
|
+
let resolveEarly;
|
|
111
|
+
const cachePromise = new Promise((resolve) => {
|
|
112
|
+
resolveEarly = resolve;
|
|
113
|
+
unsubscribe = this.#client.getQueryCache().subscribe((event) => {
|
|
114
|
+
if (event.type === "updated" && event.query.queryHash === query.queryHash && query.state.data !== void 0) {
|
|
115
|
+
unsubscribe();
|
|
116
|
+
resolve(this.createResult(query, defaultedOptions));
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
return Promise.race([query.fetch().then(() => {
|
|
121
|
+
const result = this.createResult(query, defaultedOptions);
|
|
122
|
+
resolveEarly?.(result);
|
|
123
|
+
return result;
|
|
124
|
+
}).finally(() => {
|
|
125
|
+
unsubscribe();
|
|
126
|
+
}), cachePromise]);
|
|
127
|
+
}
|
|
128
|
+
fetch(fetchOptions) {
|
|
129
|
+
return this.#executeFetch({
|
|
130
|
+
...fetchOptions,
|
|
131
|
+
cancelRefetch: fetchOptions.cancelRefetch ?? true
|
|
132
|
+
}).then(() => {
|
|
133
|
+
this.updateResult();
|
|
134
|
+
return this.#currentResult;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
#executeFetch(fetchOptions) {
|
|
138
|
+
this.#updateQuery();
|
|
139
|
+
let promise = this.#currentQuery.fetch(this.options, fetchOptions);
|
|
140
|
+
if (!fetchOptions?.throwOnError) promise = promise.catch(noop);
|
|
141
|
+
return promise;
|
|
142
|
+
}
|
|
143
|
+
#updateStaleTimeout() {
|
|
144
|
+
this.#clearStaleTimeout();
|
|
145
|
+
const staleTime = resolveStaleTime(this.options.staleTime, this.#currentQuery);
|
|
146
|
+
if (environmentManager.isServer() || this.#currentResult.isStale || !isValidTimeout(staleTime)) return;
|
|
147
|
+
const timeout = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime) + 1;
|
|
148
|
+
this.#staleTimeoutId = timeoutManager.setTimeout(() => {
|
|
149
|
+
if (!this.#currentResult.isStale) this.updateResult();
|
|
150
|
+
}, timeout);
|
|
151
|
+
}
|
|
152
|
+
#computeRefetchInterval() {
|
|
153
|
+
return (typeof this.options.refetchInterval === "function" ? this.options.refetchInterval(this.#currentQuery) : this.options.refetchInterval) ?? false;
|
|
154
|
+
}
|
|
155
|
+
#updateRefetchInterval(nextInterval) {
|
|
156
|
+
this.#clearRefetchInterval();
|
|
157
|
+
this.#currentRefetchInterval = nextInterval;
|
|
158
|
+
if (environmentManager.isServer() || resolveQueryBoolean(this.options.enabled, this.#currentQuery) === false || !isValidTimeout(this.#currentRefetchInterval) || this.#currentRefetchInterval === 0) return;
|
|
159
|
+
this.#refetchIntervalId = timeoutManager.setInterval(() => {
|
|
160
|
+
if (this.options.refetchIntervalInBackground || focusManager.isFocused()) this.#executeFetch();
|
|
161
|
+
}, this.#currentRefetchInterval);
|
|
162
|
+
}
|
|
163
|
+
#updateTimers() {
|
|
164
|
+
this.#updateStaleTimeout();
|
|
165
|
+
this.#updateRefetchInterval(this.#computeRefetchInterval());
|
|
166
|
+
}
|
|
167
|
+
#clearStaleTimeout() {
|
|
168
|
+
if (this.#staleTimeoutId !== void 0) {
|
|
169
|
+
timeoutManager.clearTimeout(this.#staleTimeoutId);
|
|
170
|
+
this.#staleTimeoutId = void 0;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
#clearRefetchInterval() {
|
|
174
|
+
if (this.#refetchIntervalId !== void 0) {
|
|
175
|
+
timeoutManager.clearInterval(this.#refetchIntervalId);
|
|
176
|
+
this.#refetchIntervalId = void 0;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
createResult(query, options) {
|
|
180
|
+
const prevQuery = this.#currentQuery;
|
|
181
|
+
const prevOptions = this.options;
|
|
182
|
+
const prevResult = this.#currentResult;
|
|
183
|
+
const prevResultState = this.#currentResultState;
|
|
184
|
+
const prevResultOptions = this.#currentResultOptions;
|
|
185
|
+
const queryInitialState = query !== prevQuery ? query.state : this.#currentQueryInitialState;
|
|
186
|
+
const { state } = query;
|
|
187
|
+
let newState = { ...state };
|
|
188
|
+
let isPlaceholderData = false;
|
|
189
|
+
let data;
|
|
190
|
+
if (options._optimisticResults) {
|
|
191
|
+
const mounted = this.hasListeners();
|
|
192
|
+
const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
|
|
193
|
+
const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
|
|
194
|
+
if (fetchOnMount || fetchOptionally) newState = {
|
|
195
|
+
...newState,
|
|
196
|
+
...fetchState(state.data, query.options)
|
|
197
|
+
};
|
|
198
|
+
if (options._optimisticResults === "isRestoring") newState.fetchStatus = "idle";
|
|
199
|
+
}
|
|
200
|
+
let { error, errorUpdatedAt, status } = newState;
|
|
201
|
+
data = newState.data;
|
|
202
|
+
let skipSelect = false;
|
|
203
|
+
if (options.placeholderData !== void 0 && data === void 0 && status === "pending") {
|
|
204
|
+
let placeholderData;
|
|
205
|
+
if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
|
|
206
|
+
placeholderData = prevResult.data;
|
|
207
|
+
skipSelect = true;
|
|
208
|
+
} else placeholderData = typeof options.placeholderData === "function" ? options.placeholderData(this.#lastQueryWithDefinedData?.state.data, this.#lastQueryWithDefinedData) : options.placeholderData;
|
|
209
|
+
if (placeholderData !== void 0) {
|
|
210
|
+
status = "success";
|
|
211
|
+
data = replaceData(prevResult?.data, placeholderData, options);
|
|
212
|
+
isPlaceholderData = true;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (options.select && data !== void 0 && !skipSelect) {
|
|
216
|
+
if (prevResult && data === prevResultState?.data && options.select === this.#selectFn) data = this.#selectResult;
|
|
217
|
+
else try {
|
|
218
|
+
this.#selectFn = options.select;
|
|
219
|
+
data = options.select(data);
|
|
220
|
+
data = replaceData(prevResult?.data, data, options);
|
|
221
|
+
this.#selectResult = data;
|
|
222
|
+
this.#selectError = null;
|
|
223
|
+
} catch (selectError) {
|
|
224
|
+
this.#selectError = selectError;
|
|
225
|
+
}
|
|
226
|
+
} else if (data === void 0) this.#selectError = null;
|
|
227
|
+
if (this.#selectError) {
|
|
228
|
+
error = this.#selectError;
|
|
229
|
+
data = this.#selectResult;
|
|
230
|
+
errorUpdatedAt = Date.now();
|
|
231
|
+
status = "error";
|
|
232
|
+
isPlaceholderData = false;
|
|
233
|
+
}
|
|
234
|
+
const isFetching = newState.fetchStatus === "fetching";
|
|
235
|
+
const isPending = status === "pending";
|
|
236
|
+
const isError = status === "error";
|
|
237
|
+
const isLoading = isPending && isFetching;
|
|
238
|
+
const hasData = data !== void 0;
|
|
239
|
+
return {
|
|
240
|
+
status,
|
|
241
|
+
fetchStatus: newState.fetchStatus,
|
|
242
|
+
isPending,
|
|
243
|
+
isSuccess: status === "success",
|
|
244
|
+
isError,
|
|
245
|
+
isInitialLoading: isLoading,
|
|
246
|
+
isLoading,
|
|
247
|
+
data,
|
|
248
|
+
dataUpdatedAt: newState.dataUpdatedAt,
|
|
249
|
+
error,
|
|
250
|
+
errorUpdatedAt,
|
|
251
|
+
failureCount: newState.fetchFailureCount,
|
|
252
|
+
failureReason: newState.fetchFailureReason,
|
|
253
|
+
errorUpdateCount: newState.errorUpdateCount,
|
|
254
|
+
isFetched: query.isFetched(),
|
|
255
|
+
isFetchedAfterMount: newState.dataUpdateCount > queryInitialState.dataUpdateCount || newState.errorUpdateCount > queryInitialState.errorUpdateCount,
|
|
256
|
+
isFetching,
|
|
257
|
+
isRefetching: isFetching && !isPending,
|
|
258
|
+
isLoadingError: isError && !hasData,
|
|
259
|
+
isPaused: newState.fetchStatus === "paused",
|
|
260
|
+
isPlaceholderData,
|
|
261
|
+
isRefetchError: isError && hasData,
|
|
262
|
+
isStale: isStale(query, options),
|
|
263
|
+
refetch: this.refetch,
|
|
264
|
+
isEnabled: resolveQueryBoolean(options.enabled, query) !== false
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
updateResult() {
|
|
268
|
+
const prevResult = this.#currentResult;
|
|
269
|
+
const nextResult = this.createResult(this.#currentQuery, this.options);
|
|
270
|
+
this.#currentResultState = this.#currentQuery.state;
|
|
271
|
+
this.#currentResultOptions = this.options;
|
|
272
|
+
if (this.#currentResultState.data !== void 0) this.#lastQueryWithDefinedData = this.#currentQuery;
|
|
273
|
+
if (shallowEqualObjects(nextResult, prevResult)) return;
|
|
274
|
+
this.#currentResult = nextResult;
|
|
275
|
+
const shouldNotifyListeners = () => {
|
|
276
|
+
if (!prevResult) return true;
|
|
277
|
+
const { notifyOnChangeProps } = this.options;
|
|
278
|
+
const notifyOnChangePropsValue = typeof notifyOnChangeProps === "function" ? notifyOnChangeProps() : notifyOnChangeProps;
|
|
279
|
+
if (notifyOnChangePropsValue === "all" || !notifyOnChangePropsValue && !this.#trackedProps.size) return true;
|
|
280
|
+
const includedProps = new Set(notifyOnChangePropsValue ?? this.#trackedProps);
|
|
281
|
+
if (this.options.throwOnError) includedProps.add("error");
|
|
282
|
+
return Object.keys(this.#currentResult).some((key) => {
|
|
283
|
+
const typedKey = key;
|
|
284
|
+
return this.#currentResult[typedKey] !== prevResult[typedKey] && includedProps.has(typedKey);
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
this.#notify({ listeners: shouldNotifyListeners() });
|
|
288
|
+
}
|
|
289
|
+
#updateQuery() {
|
|
290
|
+
const query = this.#client.getQueryCache().build(this.#client, this.options);
|
|
291
|
+
if (query === this.#currentQuery) return;
|
|
292
|
+
const prevQuery = this.#currentQuery;
|
|
293
|
+
this.#currentQuery = query;
|
|
294
|
+
this.#currentQueryInitialState = query.state;
|
|
295
|
+
if (this.hasListeners()) {
|
|
296
|
+
prevQuery?.removeObserver(this);
|
|
297
|
+
query.addObserver(this);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
onQueryUpdate() {
|
|
301
|
+
this.updateResult();
|
|
302
|
+
if (this.hasListeners()) this.#updateTimers();
|
|
303
|
+
}
|
|
304
|
+
#notify(notifyOptions) {
|
|
305
|
+
notifyManager.batch(() => {
|
|
306
|
+
if (notifyOptions.listeners) this.listeners.forEach((listener) => {
|
|
307
|
+
listener(this.#currentResult);
|
|
308
|
+
});
|
|
309
|
+
this.#client.getQueryCache().notify({
|
|
310
|
+
query: this.#currentQuery,
|
|
311
|
+
type: "observerResultsUpdated"
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
}
|
|
443
315
|
};
|
|
444
316
|
function shouldLoadOnMount(query, options) {
|
|
445
|
-
|
|
317
|
+
return resolveQueryBoolean(options.enabled, query) !== false && query.state.data === void 0 && !(query.state.status === "error" && resolveQueryBoolean(options.retryOnMount, query) === false);
|
|
446
318
|
}
|
|
447
319
|
function shouldFetchOnMount(query, options) {
|
|
448
|
-
|
|
320
|
+
return shouldLoadOnMount(query, options) || query.state.data !== void 0 && shouldFetchOn(query, options, options.refetchOnMount);
|
|
449
321
|
}
|
|
450
322
|
function shouldFetchOn(query, options, field) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
323
|
+
if (resolveQueryBoolean(options.enabled, query) !== false && resolveStaleTime(options.staleTime, query) !== "static") {
|
|
324
|
+
const value = typeof field === "function" ? field(query) : field;
|
|
325
|
+
return value === "always" || value !== false && isStale(query, options);
|
|
326
|
+
}
|
|
327
|
+
return false;
|
|
456
328
|
}
|
|
457
329
|
function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
|
|
458
|
-
|
|
330
|
+
return (query !== prevQuery || resolveQueryBoolean(prevOptions.enabled, query) === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
|
|
459
331
|
}
|
|
460
332
|
function isStale(query, options) {
|
|
461
|
-
|
|
333
|
+
return resolveQueryBoolean(options.enabled, query) !== false && query.isStaleByTime(resolveStaleTime(options.staleTime, query));
|
|
462
334
|
}
|
|
463
335
|
function shouldAssignObserverCurrentProperties(observer, optimisticResult) {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
}
|
|
467
|
-
return false;
|
|
336
|
+
if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) return true;
|
|
337
|
+
return false;
|
|
468
338
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
339
|
+
//#endregion
|
|
340
|
+
export { QueryObserver };
|
|
341
|
+
|
|
472
342
|
//# sourceMappingURL=queryObserver.js.map
|