@tanstack/query-core 5.101.3 → 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,170 +1,125 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_classPrivateFieldSet2 = require("./classPrivateFieldSet2-Bo0ZyOIv.cjs");
|
|
3
|
+
const require_utils = require("./utils.cjs");
|
|
4
|
+
const require_subscribable = require("./subscribable.cjs");
|
|
5
|
+
const require_notifyManager = require("./notifyManager.cjs");
|
|
6
|
+
const require_mutation = require("./mutation.cjs");
|
|
7
|
+
//#region src/mutationCache.ts
|
|
8
|
+
var _mutations = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
var _scopes = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
var _mutationId = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
var MutationCache = class extends require_subscribable.Subscribable {
|
|
12
|
+
constructor(config = {}) {
|
|
13
|
+
super();
|
|
14
|
+
this.config = config;
|
|
15
|
+
require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _mutations, void 0);
|
|
16
|
+
require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _scopes, void 0);
|
|
17
|
+
require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _mutationId, void 0);
|
|
18
|
+
require_classPrivateFieldSet2._classPrivateFieldSet2(_mutations, this, /* @__PURE__ */ new Set());
|
|
19
|
+
require_classPrivateFieldSet2._classPrivateFieldSet2(_scopes, this, /* @__PURE__ */ new Map());
|
|
20
|
+
require_classPrivateFieldSet2._classPrivateFieldSet2(_mutationId, this, 0);
|
|
21
|
+
}
|
|
22
|
+
build(client, options, state) {
|
|
23
|
+
var _this$mutationId;
|
|
24
|
+
const mutation = new require_mutation.Mutation({
|
|
25
|
+
client,
|
|
26
|
+
mutationCache: this,
|
|
27
|
+
mutationId: require_classPrivateFieldSet2._classPrivateFieldSet2(_mutationId, this, (_this$mutationId = require_classPrivateFieldSet2._classPrivateFieldGet2(_mutationId, this), ++_this$mutationId)),
|
|
28
|
+
options: client.defaultMutationOptions(options),
|
|
29
|
+
state
|
|
30
|
+
});
|
|
31
|
+
this.add(mutation);
|
|
32
|
+
return mutation;
|
|
33
|
+
}
|
|
34
|
+
add(mutation) {
|
|
35
|
+
require_classPrivateFieldSet2._classPrivateFieldGet2(_mutations, this).add(mutation);
|
|
36
|
+
const scope = scopeFor(mutation);
|
|
37
|
+
if (typeof scope === "string") {
|
|
38
|
+
const scopedMutations = require_classPrivateFieldSet2._classPrivateFieldGet2(_scopes, this).get(scope);
|
|
39
|
+
if (scopedMutations) scopedMutations.push(mutation);
|
|
40
|
+
else require_classPrivateFieldSet2._classPrivateFieldGet2(_scopes, this).set(scope, [mutation]);
|
|
41
|
+
}
|
|
42
|
+
this.notify({
|
|
43
|
+
type: "added",
|
|
44
|
+
mutation
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
remove(mutation) {
|
|
48
|
+
if (require_classPrivateFieldSet2._classPrivateFieldGet2(_mutations, this).delete(mutation)) {
|
|
49
|
+
const scope = scopeFor(mutation);
|
|
50
|
+
if (typeof scope === "string") {
|
|
51
|
+
const scopedMutations = require_classPrivateFieldSet2._classPrivateFieldGet2(_scopes, this).get(scope);
|
|
52
|
+
if (scopedMutations) {
|
|
53
|
+
if (scopedMutations.length > 1) {
|
|
54
|
+
const index = scopedMutations.indexOf(mutation);
|
|
55
|
+
if (index !== -1) scopedMutations.splice(index, 1);
|
|
56
|
+
} else if (scopedMutations[0] === mutation) require_classPrivateFieldSet2._classPrivateFieldGet2(_scopes, this).delete(scope);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
this.notify({
|
|
61
|
+
type: "removed",
|
|
62
|
+
mutation
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
canRun(mutation) {
|
|
66
|
+
const scope = scopeFor(mutation);
|
|
67
|
+
if (typeof scope === "string") {
|
|
68
|
+
const mutationsWithSameScope = require_classPrivateFieldSet2._classPrivateFieldGet2(_scopes, this).get(scope);
|
|
69
|
+
const firstPendingMutation = mutationsWithSameScope === null || mutationsWithSameScope === void 0 ? void 0 : mutationsWithSameScope.find((m) => m.state.status === "pending");
|
|
70
|
+
return !firstPendingMutation || firstPendingMutation === mutation;
|
|
71
|
+
} else return true;
|
|
72
|
+
}
|
|
73
|
+
runNext(mutation) {
|
|
74
|
+
const scope = scopeFor(mutation);
|
|
75
|
+
if (typeof scope === "string") {
|
|
76
|
+
var _classPrivateFieldGet2$1;
|
|
77
|
+
const foundMutation = (_classPrivateFieldGet2$1 = require_classPrivateFieldSet2._classPrivateFieldGet2(_scopes, this).get(scope)) === null || _classPrivateFieldGet2$1 === void 0 ? void 0 : _classPrivateFieldGet2$1.find((m) => m !== mutation && m.state.isPaused);
|
|
78
|
+
return (foundMutation === null || foundMutation === void 0 ? void 0 : foundMutation.continue()) ?? Promise.resolve();
|
|
79
|
+
} else return Promise.resolve();
|
|
80
|
+
}
|
|
81
|
+
clear() {
|
|
82
|
+
require_notifyManager.notifyManager.batch(() => {
|
|
83
|
+
require_classPrivateFieldSet2._classPrivateFieldGet2(_mutations, this).forEach((mutation) => {
|
|
84
|
+
this.notify({
|
|
85
|
+
type: "removed",
|
|
86
|
+
mutation
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
require_classPrivateFieldSet2._classPrivateFieldGet2(_mutations, this).clear();
|
|
90
|
+
require_classPrivateFieldSet2._classPrivateFieldGet2(_scopes, this).clear();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
getAll() {
|
|
94
|
+
return Array.from(require_classPrivateFieldSet2._classPrivateFieldGet2(_mutations, this));
|
|
95
|
+
}
|
|
96
|
+
find(filters) {
|
|
97
|
+
const defaultedFilters = {
|
|
98
|
+
exact: true,
|
|
99
|
+
...filters
|
|
100
|
+
};
|
|
101
|
+
return this.getAll().find((mutation) => require_utils.matchMutation(defaultedFilters, mutation));
|
|
102
|
+
}
|
|
103
|
+
findAll(filters = {}) {
|
|
104
|
+
return this.getAll().filter((mutation) => require_utils.matchMutation(filters, mutation));
|
|
105
|
+
}
|
|
106
|
+
notify(event) {
|
|
107
|
+
require_notifyManager.notifyManager.batch(() => {
|
|
108
|
+
this.listeners.forEach((listener) => {
|
|
109
|
+
listener(event);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
resumePausedMutations() {
|
|
114
|
+
const pausedMutations = this.getAll().filter((x) => x.state.isPaused);
|
|
115
|
+
return require_notifyManager.notifyManager.batch(() => Promise.all(pausedMutations.map((mutation) => mutation.continue().catch(require_utils.noop))));
|
|
116
|
+
}
|
|
8
117
|
};
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
|
-
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
27
|
-
set _(value) {
|
|
28
|
-
__privateSet(obj, member, value, setter);
|
|
29
|
-
},
|
|
30
|
-
get _() {
|
|
31
|
-
return __privateGet(obj, member, getter);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// src/mutationCache.ts
|
|
36
|
-
var mutationCache_exports = {};
|
|
37
|
-
__export(mutationCache_exports, {
|
|
38
|
-
MutationCache: () => MutationCache
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(mutationCache_exports);
|
|
41
|
-
var import_notifyManager = require("./notifyManager.cjs");
|
|
42
|
-
var import_mutation = require("./mutation.cjs");
|
|
43
|
-
var import_utils = require("./utils.cjs");
|
|
44
|
-
var import_subscribable = require("./subscribable.cjs");
|
|
45
|
-
var _mutations, _scopes, _mutationId;
|
|
46
|
-
var MutationCache = class extends import_subscribable.Subscribable {
|
|
47
|
-
constructor(config = {}) {
|
|
48
|
-
super();
|
|
49
|
-
this.config = config;
|
|
50
|
-
__privateAdd(this, _mutations);
|
|
51
|
-
__privateAdd(this, _scopes);
|
|
52
|
-
__privateAdd(this, _mutationId);
|
|
53
|
-
__privateSet(this, _mutations, /* @__PURE__ */ new Set());
|
|
54
|
-
__privateSet(this, _scopes, /* @__PURE__ */ new Map());
|
|
55
|
-
__privateSet(this, _mutationId, 0);
|
|
56
|
-
}
|
|
57
|
-
build(client, options, state) {
|
|
58
|
-
const mutation = new import_mutation.Mutation({
|
|
59
|
-
client,
|
|
60
|
-
mutationCache: this,
|
|
61
|
-
mutationId: ++__privateWrapper(this, _mutationId)._,
|
|
62
|
-
options: client.defaultMutationOptions(options),
|
|
63
|
-
state
|
|
64
|
-
});
|
|
65
|
-
this.add(mutation);
|
|
66
|
-
return mutation;
|
|
67
|
-
}
|
|
68
|
-
add(mutation) {
|
|
69
|
-
__privateGet(this, _mutations).add(mutation);
|
|
70
|
-
const scope = scopeFor(mutation);
|
|
71
|
-
if (typeof scope === "string") {
|
|
72
|
-
const scopedMutations = __privateGet(this, _scopes).get(scope);
|
|
73
|
-
if (scopedMutations) {
|
|
74
|
-
scopedMutations.push(mutation);
|
|
75
|
-
} else {
|
|
76
|
-
__privateGet(this, _scopes).set(scope, [mutation]);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
this.notify({ type: "added", mutation });
|
|
80
|
-
}
|
|
81
|
-
remove(mutation) {
|
|
82
|
-
if (__privateGet(this, _mutations).delete(mutation)) {
|
|
83
|
-
const scope = scopeFor(mutation);
|
|
84
|
-
if (typeof scope === "string") {
|
|
85
|
-
const scopedMutations = __privateGet(this, _scopes).get(scope);
|
|
86
|
-
if (scopedMutations) {
|
|
87
|
-
if (scopedMutations.length > 1) {
|
|
88
|
-
const index = scopedMutations.indexOf(mutation);
|
|
89
|
-
if (index !== -1) {
|
|
90
|
-
scopedMutations.splice(index, 1);
|
|
91
|
-
}
|
|
92
|
-
} else if (scopedMutations[0] === mutation) {
|
|
93
|
-
__privateGet(this, _scopes).delete(scope);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
this.notify({ type: "removed", mutation });
|
|
99
|
-
}
|
|
100
|
-
canRun(mutation) {
|
|
101
|
-
const scope = scopeFor(mutation);
|
|
102
|
-
if (typeof scope === "string") {
|
|
103
|
-
const mutationsWithSameScope = __privateGet(this, _scopes).get(scope);
|
|
104
|
-
const firstPendingMutation = mutationsWithSameScope == null ? void 0 : mutationsWithSameScope.find(
|
|
105
|
-
(m) => m.state.status === "pending"
|
|
106
|
-
);
|
|
107
|
-
return !firstPendingMutation || firstPendingMutation === mutation;
|
|
108
|
-
} else {
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
runNext(mutation) {
|
|
113
|
-
var _a;
|
|
114
|
-
const scope = scopeFor(mutation);
|
|
115
|
-
if (typeof scope === "string") {
|
|
116
|
-
const foundMutation = (_a = __privateGet(this, _scopes).get(scope)) == null ? void 0 : _a.find((m) => m !== mutation && m.state.isPaused);
|
|
117
|
-
return (foundMutation == null ? void 0 : foundMutation.continue()) ?? Promise.resolve();
|
|
118
|
-
} else {
|
|
119
|
-
return Promise.resolve();
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
clear() {
|
|
123
|
-
import_notifyManager.notifyManager.batch(() => {
|
|
124
|
-
__privateGet(this, _mutations).forEach((mutation) => {
|
|
125
|
-
this.notify({ type: "removed", mutation });
|
|
126
|
-
});
|
|
127
|
-
__privateGet(this, _mutations).clear();
|
|
128
|
-
__privateGet(this, _scopes).clear();
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
getAll() {
|
|
132
|
-
return Array.from(__privateGet(this, _mutations));
|
|
133
|
-
}
|
|
134
|
-
find(filters) {
|
|
135
|
-
const defaultedFilters = { exact: true, ...filters };
|
|
136
|
-
return this.getAll().find(
|
|
137
|
-
(mutation) => (0, import_utils.matchMutation)(defaultedFilters, mutation)
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
findAll(filters = {}) {
|
|
141
|
-
return this.getAll().filter((mutation) => (0, import_utils.matchMutation)(filters, mutation));
|
|
142
|
-
}
|
|
143
|
-
notify(event) {
|
|
144
|
-
import_notifyManager.notifyManager.batch(() => {
|
|
145
|
-
this.listeners.forEach((listener) => {
|
|
146
|
-
listener(event);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
resumePausedMutations() {
|
|
151
|
-
const pausedMutations = this.getAll().filter((x) => x.state.isPaused);
|
|
152
|
-
return import_notifyManager.notifyManager.batch(
|
|
153
|
-
() => Promise.all(
|
|
154
|
-
pausedMutations.map((mutation) => mutation.continue().catch(import_utils.noop))
|
|
155
|
-
)
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
_mutations = new WeakMap();
|
|
160
|
-
_scopes = new WeakMap();
|
|
161
|
-
_mutationId = new WeakMap();
|
|
162
118
|
function scopeFor(mutation) {
|
|
163
|
-
|
|
164
|
-
|
|
119
|
+
var _mutation$options$sco;
|
|
120
|
+
return (_mutation$options$sco = mutation.options.scope) === null || _mutation$options$sco === void 0 ? void 0 : _mutation$options$sco.id;
|
|
165
121
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
122
|
+
//#endregion
|
|
123
|
+
exports.MutationCache = MutationCache;
|
|
124
|
+
|
|
170
125
|
//# sourceMappingURL=mutationCache.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mutationCache.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Mutation } from './mutation'\nimport { matchMutation, noop } from './utils'\nimport { Subscribable } from './subscribable'\nimport type { MutationObserver } from './mutationObserver'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationOptions,\n NotifyEvent,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Action, MutationState } from './mutation'\nimport type { MutationFilters } from './utils'\n\n// TYPES\n\ninterface MutationCacheConfig {\n onError?: (\n error: DefaultError,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onSuccess?: (\n data: unknown,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onMutate?: (\n variables: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n}\n\ninterface NotifyEventMutationAdded extends NotifyEvent {\n type: 'added'\n mutation: Mutation<any, any, any, any>\n}\ninterface NotifyEventMutationRemoved extends NotifyEvent {\n type: 'removed'\n mutation: Mutation<any, any, any, any>\n}\n\ninterface NotifyEventMutationObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n mutation?: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any, any>\n}\n\ninterface NotifyEventMutationUpdated extends NotifyEvent {\n type: 'updated'\n mutation: Mutation<any, any, any, any>\n action: Action<any, any, any, any>\n}\n\nexport type MutationCacheNotifyEvent =\n | NotifyEventMutationAdded\n | NotifyEventMutationRemoved\n | NotifyEventMutationObserverAdded\n | NotifyEventMutationObserverRemoved\n | NotifyEventMutationObserverOptionsUpdated\n | NotifyEventMutationUpdated\n\ntype MutationCacheListener = (event: MutationCacheNotifyEvent) => void\n\n// CLASS\n\nexport class MutationCache extends Subscribable<MutationCacheListener> {\n #mutations: Set<Mutation<any, any, any, any>>\n #scopes: Map<string, Array<Mutation<any, any, any, any>>>\n #mutationId: number\n\n constructor(public config: MutationCacheConfig = {}) {\n super()\n this.#mutations = new Set()\n this.#scopes = new Map()\n this.#mutationId = 0\n }\n\n build<TData, TError, TVariables, TOnMutateResult>(\n client: QueryClient,\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> {\n const mutation = new Mutation({\n client,\n mutationCache: this,\n mutationId: ++this.#mutationId,\n options: client.defaultMutationOptions(options),\n state,\n })\n\n this.add(mutation)\n\n return mutation\n }\n\n add(mutation: Mutation<any, any, any, any>): void {\n this.#mutations.add(mutation)\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n scopedMutations.push(mutation)\n } else {\n this.#scopes.set(scope, [mutation])\n }\n }\n this.notify({ type: 'added', mutation })\n }\n\n remove(mutation: Mutation<any, any, any, any>): void {\n if (this.#mutations.delete(mutation)) {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n if (scopedMutations.length > 1) {\n const index = scopedMutations.indexOf(mutation)\n if (index !== -1) {\n scopedMutations.splice(index, 1)\n }\n } else if (scopedMutations[0] === mutation) {\n this.#scopes.delete(scope)\n }\n }\n }\n }\n\n // Currently we notify the removal even if the mutation was already removed.\n // Consider making this an error or not notifying of the removal depending on the desired semantics.\n this.notify({ type: 'removed', mutation })\n }\n\n canRun(mutation: Mutation<any, any, any, any>): boolean {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const mutationsWithSameScope = this.#scopes.get(scope)\n const firstPendingMutation = mutationsWithSameScope?.find(\n (m) => m.state.status === 'pending',\n )\n // we can run if there is no current pending mutation (start use-case)\n // or if WE are the first pending mutation (continue use-case)\n return !firstPendingMutation || firstPendingMutation === mutation\n } else {\n // For unscoped mutations there are never any pending mutations in front of the\n // current mutation\n return true\n }\n }\n\n runNext(mutation: Mutation<any, any, any, any>): Promise<unknown> {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const foundMutation = this.#scopes\n .get(scope)\n ?.find((m) => m !== mutation && m.state.isPaused)\n\n return foundMutation?.continue() ?? Promise.resolve()\n } else {\n return Promise.resolve()\n }\n }\n\n clear(): void {\n notifyManager.batch(() => {\n this.#mutations.forEach((mutation) => {\n this.notify({ type: 'removed', mutation })\n })\n this.#mutations.clear()\n this.#scopes.clear()\n })\n }\n\n getAll(): Array<Mutation> {\n return Array.from(this.#mutations)\n }\n\n find<\n TData = unknown,\n TError = DefaultError,\n TVariables = any,\n TOnMutateResult = unknown,\n >(\n filters: MutationFilters,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((mutation) =>\n matchMutation(defaultedFilters, mutation),\n ) as Mutation<TData, TError, TVariables, TOnMutateResult> | undefined\n }\n\n findAll(filters: MutationFilters = {}): Array<Mutation> {\n return this.getAll().filter((mutation) => matchMutation(filters, mutation))\n }\n\n notify(event: MutationCacheNotifyEvent) {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n resumePausedMutations(): Promise<unknown> {\n const pausedMutations = this.getAll().filter((x) => x.state.isPaused)\n\n return notifyManager.batch(() =>\n Promise.all(\n pausedMutations.map((mutation) => mutation.continue().catch(noop)),\n ),\n )\n }\n}\n\nfunction scopeFor(mutation: Mutation<any, any, any, any>) {\n return mutation.options.scope?.id\n}\n"],"mappings":"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","names":[]}
|
|
1
|
+
{"version":3,"file":"mutationCache.cjs","names":["Subscribable","Mutation","matchMutation","notifyManager","noop"],"sources":["../../src/mutationCache.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Mutation } from './mutation'\nimport { matchMutation, noop } from './utils'\nimport { Subscribable } from './subscribable'\nimport type { MutationObserver } from './mutationObserver'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationOptions,\n NotifyEvent,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Action, MutationState } from './mutation'\nimport type { MutationFilters } from './utils'\n\n// TYPES\n\ninterface MutationCacheConfig {\n onError?: (\n error: DefaultError,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onSuccess?: (\n data: unknown,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onMutate?: (\n variables: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n}\n\ninterface NotifyEventMutationAdded extends NotifyEvent {\n type: 'added'\n mutation: Mutation<any, any, any, any>\n}\ninterface NotifyEventMutationRemoved extends NotifyEvent {\n type: 'removed'\n mutation: Mutation<any, any, any, any>\n}\n\ninterface NotifyEventMutationObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n mutation?: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any, any>\n}\n\ninterface NotifyEventMutationUpdated extends NotifyEvent {\n type: 'updated'\n mutation: Mutation<any, any, any, any>\n action: Action<any, any, any, any>\n}\n\nexport type MutationCacheNotifyEvent =\n | NotifyEventMutationAdded\n | NotifyEventMutationRemoved\n | NotifyEventMutationObserverAdded\n | NotifyEventMutationObserverRemoved\n | NotifyEventMutationObserverOptionsUpdated\n | NotifyEventMutationUpdated\n\ntype MutationCacheListener = (event: MutationCacheNotifyEvent) => void\n\n// CLASS\n\nexport class MutationCache extends Subscribable<MutationCacheListener> {\n #mutations: Set<Mutation<any, any, any, any>>\n #scopes: Map<string, Array<Mutation<any, any, any, any>>>\n #mutationId: number\n\n constructor(public config: MutationCacheConfig = {}) {\n super()\n this.#mutations = new Set()\n this.#scopes = new Map()\n this.#mutationId = 0\n }\n\n build<TData, TError, TVariables, TOnMutateResult>(\n client: QueryClient,\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> {\n const mutation = new Mutation({\n client,\n mutationCache: this,\n mutationId: ++this.#mutationId,\n options: client.defaultMutationOptions(options),\n state,\n })\n\n this.add(mutation)\n\n return mutation\n }\n\n add(mutation: Mutation<any, any, any, any>): void {\n this.#mutations.add(mutation)\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n scopedMutations.push(mutation)\n } else {\n this.#scopes.set(scope, [mutation])\n }\n }\n this.notify({ type: 'added', mutation })\n }\n\n remove(mutation: Mutation<any, any, any, any>): void {\n if (this.#mutations.delete(mutation)) {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n if (scopedMutations.length > 1) {\n const index = scopedMutations.indexOf(mutation)\n if (index !== -1) {\n scopedMutations.splice(index, 1)\n }\n } else if (scopedMutations[0] === mutation) {\n this.#scopes.delete(scope)\n }\n }\n }\n }\n\n // Currently we notify the removal even if the mutation was already removed.\n // Consider making this an error or not notifying of the removal depending on the desired semantics.\n this.notify({ type: 'removed', mutation })\n }\n\n canRun(mutation: Mutation<any, any, any, any>): boolean {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const mutationsWithSameScope = this.#scopes.get(scope)\n const firstPendingMutation = mutationsWithSameScope?.find(\n (m) => m.state.status === 'pending',\n )\n // we can run if there is no current pending mutation (start use-case)\n // or if WE are the first pending mutation (continue use-case)\n return !firstPendingMutation || firstPendingMutation === mutation\n } else {\n // For unscoped mutations there are never any pending mutations in front of the\n // current mutation\n return true\n }\n }\n\n runNext(mutation: Mutation<any, any, any, any>): Promise<unknown> {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const foundMutation = this.#scopes\n .get(scope)\n ?.find((m) => m !== mutation && m.state.isPaused)\n\n return foundMutation?.continue() ?? Promise.resolve()\n } else {\n return Promise.resolve()\n }\n }\n\n clear(): void {\n notifyManager.batch(() => {\n this.#mutations.forEach((mutation) => {\n this.notify({ type: 'removed', mutation })\n })\n this.#mutations.clear()\n this.#scopes.clear()\n })\n }\n\n getAll(): Array<Mutation> {\n return Array.from(this.#mutations)\n }\n\n find<\n TData = unknown,\n TError = DefaultError,\n TVariables = any,\n TOnMutateResult = unknown,\n >(\n filters: MutationFilters,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((mutation) =>\n matchMutation(defaultedFilters, mutation),\n ) as Mutation<TData, TError, TVariables, TOnMutateResult> | undefined\n }\n\n findAll(filters: MutationFilters = {}): Array<Mutation> {\n return this.getAll().filter((mutation) => matchMutation(filters, mutation))\n }\n\n notify(event: MutationCacheNotifyEvent) {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n resumePausedMutations(): Promise<unknown> {\n const pausedMutations = this.getAll().filter((x) => x.state.isPaused)\n\n return notifyManager.batch(() =>\n Promise.all(\n pausedMutations.map((mutation) => mutation.continue().catch(noop)),\n ),\n )\n }\n}\n\nfunction scopeFor(mutation: Mutation<any, any, any, any>) {\n return mutation.options.scope?.id\n}\n"],"mappings":"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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
1
|
+
import { Gn as MutationCacheNotifyEvent, Wn as MutationCache } from "./hydration-NBquRCHe.cjs";
|
|
2
|
+
export { MutationCache, MutationCacheNotifyEvent };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
1
|
+
import { Gn as MutationCacheNotifyEvent, Wn as MutationCache } from "./hydration-D1E7ZbjZ.js";
|
|
2
|
+
export { MutationCache, MutationCacheNotifyEvent };
|
|
@@ -1,137 +1,124 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__privateAdd,
|
|
3
|
-
__privateGet,
|
|
4
|
-
__privateSet,
|
|
5
|
-
__privateWrapper
|
|
6
|
-
} from "./chunk-PXG64RU4.js";
|
|
7
|
-
|
|
8
|
-
// src/mutationCache.ts
|
|
9
|
-
import { notifyManager } from "./notifyManager.js";
|
|
10
|
-
import { Mutation } from "./mutation.js";
|
|
1
|
+
import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldGet2, t as _classPrivateFieldSet2 } from "./classPrivateFieldSet2-CV7wyte-.js";
|
|
11
2
|
import { matchMutation, noop } from "./utils.js";
|
|
12
3
|
import { Subscribable } from "./subscribable.js";
|
|
13
|
-
|
|
4
|
+
import { notifyManager } from "./notifyManager.js";
|
|
5
|
+
import { Mutation } from "./mutation.js";
|
|
6
|
+
//#region src/mutationCache.ts
|
|
7
|
+
var _mutations = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
var _scopes = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
var _mutationId = /* @__PURE__ */ new WeakMap();
|
|
14
10
|
var MutationCache = class extends Subscribable {
|
|
15
|
-
|
|
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
|
-
return notifyManager.batch(
|
|
121
|
-
() => Promise.all(
|
|
122
|
-
pausedMutations.map((mutation) => mutation.continue().catch(noop))
|
|
123
|
-
)
|
|
124
|
-
);
|
|
125
|
-
}
|
|
11
|
+
constructor(config = {}) {
|
|
12
|
+
super();
|
|
13
|
+
this.config = config;
|
|
14
|
+
_classPrivateFieldInitSpec(this, _mutations, void 0);
|
|
15
|
+
_classPrivateFieldInitSpec(this, _scopes, void 0);
|
|
16
|
+
_classPrivateFieldInitSpec(this, _mutationId, void 0);
|
|
17
|
+
_classPrivateFieldSet2(_mutations, this, /* @__PURE__ */ new Set());
|
|
18
|
+
_classPrivateFieldSet2(_scopes, this, /* @__PURE__ */ new Map());
|
|
19
|
+
_classPrivateFieldSet2(_mutationId, this, 0);
|
|
20
|
+
}
|
|
21
|
+
build(client, options, state) {
|
|
22
|
+
var _this$mutationId;
|
|
23
|
+
const mutation = new Mutation({
|
|
24
|
+
client,
|
|
25
|
+
mutationCache: this,
|
|
26
|
+
mutationId: _classPrivateFieldSet2(_mutationId, this, (_this$mutationId = _classPrivateFieldGet2(_mutationId, this), ++_this$mutationId)),
|
|
27
|
+
options: client.defaultMutationOptions(options),
|
|
28
|
+
state
|
|
29
|
+
});
|
|
30
|
+
this.add(mutation);
|
|
31
|
+
return mutation;
|
|
32
|
+
}
|
|
33
|
+
add(mutation) {
|
|
34
|
+
_classPrivateFieldGet2(_mutations, this).add(mutation);
|
|
35
|
+
const scope = scopeFor(mutation);
|
|
36
|
+
if (typeof scope === "string") {
|
|
37
|
+
const scopedMutations = _classPrivateFieldGet2(_scopes, this).get(scope);
|
|
38
|
+
if (scopedMutations) scopedMutations.push(mutation);
|
|
39
|
+
else _classPrivateFieldGet2(_scopes, this).set(scope, [mutation]);
|
|
40
|
+
}
|
|
41
|
+
this.notify({
|
|
42
|
+
type: "added",
|
|
43
|
+
mutation
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
remove(mutation) {
|
|
47
|
+
if (_classPrivateFieldGet2(_mutations, this).delete(mutation)) {
|
|
48
|
+
const scope = scopeFor(mutation);
|
|
49
|
+
if (typeof scope === "string") {
|
|
50
|
+
const scopedMutations = _classPrivateFieldGet2(_scopes, this).get(scope);
|
|
51
|
+
if (scopedMutations) {
|
|
52
|
+
if (scopedMutations.length > 1) {
|
|
53
|
+
const index = scopedMutations.indexOf(mutation);
|
|
54
|
+
if (index !== -1) scopedMutations.splice(index, 1);
|
|
55
|
+
} else if (scopedMutations[0] === mutation) _classPrivateFieldGet2(_scopes, this).delete(scope);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
this.notify({
|
|
60
|
+
type: "removed",
|
|
61
|
+
mutation
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
canRun(mutation) {
|
|
65
|
+
const scope = scopeFor(mutation);
|
|
66
|
+
if (typeof scope === "string") {
|
|
67
|
+
const mutationsWithSameScope = _classPrivateFieldGet2(_scopes, this).get(scope);
|
|
68
|
+
const firstPendingMutation = mutationsWithSameScope === null || mutationsWithSameScope === void 0 ? void 0 : mutationsWithSameScope.find((m) => m.state.status === "pending");
|
|
69
|
+
return !firstPendingMutation || firstPendingMutation === mutation;
|
|
70
|
+
} else return true;
|
|
71
|
+
}
|
|
72
|
+
runNext(mutation) {
|
|
73
|
+
const scope = scopeFor(mutation);
|
|
74
|
+
if (typeof scope === "string") {
|
|
75
|
+
var _classPrivateFieldGet2$1;
|
|
76
|
+
const foundMutation = (_classPrivateFieldGet2$1 = _classPrivateFieldGet2(_scopes, this).get(scope)) === null || _classPrivateFieldGet2$1 === void 0 ? void 0 : _classPrivateFieldGet2$1.find((m) => m !== mutation && m.state.isPaused);
|
|
77
|
+
return (foundMutation === null || foundMutation === void 0 ? void 0 : foundMutation.continue()) ?? Promise.resolve();
|
|
78
|
+
} else return Promise.resolve();
|
|
79
|
+
}
|
|
80
|
+
clear() {
|
|
81
|
+
notifyManager.batch(() => {
|
|
82
|
+
_classPrivateFieldGet2(_mutations, this).forEach((mutation) => {
|
|
83
|
+
this.notify({
|
|
84
|
+
type: "removed",
|
|
85
|
+
mutation
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
_classPrivateFieldGet2(_mutations, this).clear();
|
|
89
|
+
_classPrivateFieldGet2(_scopes, this).clear();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
getAll() {
|
|
93
|
+
return Array.from(_classPrivateFieldGet2(_mutations, this));
|
|
94
|
+
}
|
|
95
|
+
find(filters) {
|
|
96
|
+
const defaultedFilters = {
|
|
97
|
+
exact: true,
|
|
98
|
+
...filters
|
|
99
|
+
};
|
|
100
|
+
return this.getAll().find((mutation) => matchMutation(defaultedFilters, mutation));
|
|
101
|
+
}
|
|
102
|
+
findAll(filters = {}) {
|
|
103
|
+
return this.getAll().filter((mutation) => matchMutation(filters, mutation));
|
|
104
|
+
}
|
|
105
|
+
notify(event) {
|
|
106
|
+
notifyManager.batch(() => {
|
|
107
|
+
this.listeners.forEach((listener) => {
|
|
108
|
+
listener(event);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
resumePausedMutations() {
|
|
113
|
+
const pausedMutations = this.getAll().filter((x) => x.state.isPaused);
|
|
114
|
+
return notifyManager.batch(() => Promise.all(pausedMutations.map((mutation) => mutation.continue().catch(noop))));
|
|
115
|
+
}
|
|
126
116
|
};
|
|
127
|
-
_mutations = new WeakMap();
|
|
128
|
-
_scopes = new WeakMap();
|
|
129
|
-
_mutationId = new WeakMap();
|
|
130
117
|
function scopeFor(mutation) {
|
|
131
|
-
|
|
132
|
-
|
|
118
|
+
var _mutation$options$sco;
|
|
119
|
+
return (_mutation$options$sco = mutation.options.scope) === null || _mutation$options$sco === void 0 ? void 0 : _mutation$options$sco.id;
|
|
133
120
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
121
|
+
//#endregion
|
|
122
|
+
export { MutationCache };
|
|
123
|
+
|
|
137
124
|
//# sourceMappingURL=mutationCache.js.map
|