nolo-cli 0.8.0 → 0.9.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/_executeModel-UD44KGZ4.js +203 -0
- package/action-ZJWE3Y5S.js +28 -0
- package/addContentAction-TVDBNJM5.js +26 -0
- package/addDialogAgentAction-EKH774VT.js +68 -0
- package/agentDeleteCommand-TCPEFJTF.js +327 -0
- package/agentEmailCommands-CZ3UILZ4.js +626 -0
- package/agentListCommands-SJKO2FFB.js +223 -0
- package/agentMachineCommands-PSNABISZ.js +425 -0
- package/agentPullCommand-O2MTUAFR.js +122 -0
- package/agentRecordCommands-MH2JKFHS.js +94 -0
- package/agentRunCommand-4KH6MIZR.js +110 -0
- package/agentRunControl-K4VKNEHF.js +57 -0
- package/agentRuntimeLocal-SKHJUWSS.js +104 -0
- package/agentSlice-3WXXN4VK.js +42 -0
- package/authCommand-PXFX6JDT.js +581 -0
- package/authCommands-356AYWEK.js +35 -0
- package/chunk-2EISRLRC.js +238 -0
- package/chunk-2FTTDCD4.js +675 -0
- package/chunk-2K2ECKSG.js +222 -0
- package/chunk-2PUGVR6E.js +19 -0
- package/chunk-3ASDTTEI.js +1774 -0
- package/chunk-3EUW3WEO.js +8 -0
- package/chunk-3LY4F7SV.js +9293 -0
- package/chunk-3TZDXYSF.js +71 -0
- package/chunk-3WYQEUBI.js +34 -0
- package/chunk-4CQLVGRV.js +50 -0
- package/chunk-4IJYA27C.js +342 -0
- package/chunk-4K2KKCSD.js +577 -0
- package/chunk-4SN6J65J.js +38 -0
- package/chunk-4VNS5WPM.js +42 -0
- package/chunk-4ZDM73SD.js +34 -0
- package/chunk-5CS33IBL.js +301 -0
- package/chunk-5KLGBAAR.js +386 -0
- package/chunk-5MIDPSSK.js +206 -0
- package/chunk-5MMAK75Q.js +15 -0
- package/chunk-5PJ3VWCS.js +360 -0
- package/chunk-63SLEOLK.js +175 -0
- package/chunk-63W5N6P3.js +150 -0
- package/chunk-6GANEXVO.js +231 -0
- package/chunk-6HYVJV7B.js +102 -0
- package/chunk-6WD3OOJS.js +20 -0
- package/chunk-7OOXPE3N.js +628 -0
- package/chunk-7QRKCBOP.js +1078 -0
- package/chunk-ATNTHIZI.js +13 -0
- package/chunk-AUQ747NZ.js +902 -0
- package/chunk-AVMKZHBC.js +85 -0
- package/chunk-AZPCASRE.js +36 -0
- package/chunk-BBYVOSU2.js +792 -0
- package/chunk-C3RUNRHT.js +51 -0
- package/chunk-CF2WZF4N.js +134 -0
- package/chunk-CF7PE763.js +10 -0
- package/chunk-CKOJQDKR.js +198 -0
- package/chunk-COMXDWNM.js +807 -0
- package/chunk-CPB2YM4D.js +171 -0
- package/chunk-CWMSB67P.js +34 -0
- package/chunk-DCOA4QSN.js +105 -0
- package/chunk-DFFIZ25G.js +30 -0
- package/chunk-DWLEOOGR.js +8 -0
- package/chunk-DZ3XJVET.js +231 -0
- package/chunk-EHLHSX7R.js +1433 -0
- package/chunk-ELRRLDWI.js +478 -0
- package/chunk-EXTIQUCI.js +482 -0
- package/chunk-EYEEHCU4.js +3066 -0
- package/chunk-G3SUCT4W.js +8 -0
- package/chunk-G43KEVSC.js +1447 -0
- package/chunk-GAKEBQD6.js +30 -0
- package/chunk-GBRG75BQ.js +86 -0
- package/chunk-GG4AJPSR.js +191 -0
- package/chunk-H33743XH.js +25 -0
- package/chunk-HNMXYYJR.js +12 -0
- package/chunk-I42VC5KR.js +15 -0
- package/chunk-IDZTNRP2.js +85 -0
- package/chunk-ISNCLGUZ.js +146 -0
- package/chunk-IWX4UW2E.js +548 -0
- package/chunk-JBTJAPUF.js +35 -0
- package/chunk-JEXVIMYZ.js +55 -0
- package/chunk-JRKKFRAV.js +537 -0
- package/chunk-JZPBVBIY.js +94 -0
- package/chunk-KKY4B2Q2.js +21 -0
- package/chunk-KOCA5FCS.js +4750 -0
- package/chunk-KQHGZWSV.js +63 -0
- package/chunk-KTVVPRJS.js +138 -0
- package/chunk-KUG52IAP.js +8 -0
- package/chunk-KX6YBIHG.js +8 -0
- package/chunk-LARL2V6G.js +9017 -0
- package/chunk-LCBAMY2M.js +60 -0
- package/chunk-LM6IYQ3F.js +16 -0
- package/chunk-M76ECQRD.js +13658 -0
- package/chunk-MGOJ5R6J.js +113 -0
- package/chunk-MKMWT7SA.js +27196 -0
- package/chunk-MRC4Q34M.js +188 -0
- package/chunk-OLZBQWZU.js +6 -0
- package/chunk-OPZYGHUC.js +89 -0
- package/chunk-OWOHNGCN.js +50 -0
- package/chunk-PAKN26FP.js +239 -0
- package/chunk-PCWC3JTN.js +91 -0
- package/chunk-PG5PNA7Y.js +939 -0
- package/chunk-Q2YZULBH.js +104 -0
- package/chunk-QSJ3HFEF.js +8 -0
- package/chunk-QYXLLLGL.js +4519 -0
- package/chunk-ROWQEJRP.js +139 -0
- package/chunk-S7Z2HMCN.js +25 -0
- package/chunk-SBR32ZZS.js +1901 -0
- package/chunk-SH2CFQOH.js +3391 -0
- package/chunk-SL35K7AH.js +226 -0
- package/chunk-TILFE6LV.js +381 -0
- package/chunk-TSS3XJY4.js +2052 -0
- package/chunk-U4TRT5V4.js +246 -0
- package/chunk-U6VC4MU4.js +8 -0
- package/chunk-UAD2WT54.js +64 -0
- package/chunk-UUJDGGAK.js +421 -0
- package/chunk-VF4K2QE6.js +21 -0
- package/chunk-VHBWHNVT.js +59 -0
- package/chunk-VIDPVFP3.js +20 -0
- package/chunk-VP4WJWKW.js +8882 -0
- package/chunk-W4NVOSFF.js +37 -0
- package/chunk-WKM6FH35.js +190 -0
- package/chunk-WWC7I6TA.js +8 -0
- package/chunk-X7W4TNB4.js +1550 -0
- package/chunk-XE635NI4.js +1948 -0
- package/chunk-XKIMRZO2.js +221 -0
- package/chunk-XS466O7S.js +933 -0
- package/chunk-Y5GCAMGP.js +9 -0
- package/chunk-YBWOP46I.js +3272 -0
- package/chunk-YPRZSPF3.js +148 -0
- package/chunk-YYUCRDOK.js +69 -0
- package/chunk-Z4NR32XR.js +50 -0
- package/chunk-ZIG5LJ7X.js +24765 -0
- package/chunk-ZNFJWEN4.js +56 -0
- package/chunk-ZQ2UM4KG.js +2878 -0
- package/cliExecutor-DNE7TCC4.js +36 -0
- package/clipboardy-BVE3LVEH.js +12001 -0
- package/createAgentAutomationAction-63OIP6X5.js +866 -0
- package/createDialogAction-ZLYZDYBB.js +54 -0
- package/createPageAction-AL5FSDCK.js +171 -0
- package/db-HCJ5PRB5.js +271 -0
- package/dbSlice-PR44QPXY.js +60 -0
- package/deleteFile-4SKGPHOZ.js +41 -0
- package/dialogCommands-F6YI5742.js +63 -0
- package/dialogSlice-JSBNZRLR.js +148 -0
- package/docCreateCommands-4CTO7ERT.js +219 -0
- package/docDeleteCommands-VBWERDRG.js +180 -0
- package/docReadCommands-KNP4MFYB.js +133 -0
- package/docStore-ADP5VYY4.js +98 -0
- package/docUpdateCommands-4BCBJQHA.js +317 -0
- package/fetchMessages-U6ZHN56A.js +17 -0
- package/getPricing-3E6UNPKL.js +30 -0
- package/handleSendMessageAction-IJDQ6ARA.js +185 -0
- package/index.js +188 -112943
- package/lib-FYYBQIXS.js +19839 -0
- package/localDialogRead-Z5UTAJPU.js +26 -0
- package/localFirstLog-DHNOY2NA.js +19 -0
- package/localRuntimeAuthority-TEGCOWX4.js +471 -0
- package/localRuntimeDb-LGDF6FQP.js +12 -0
- package/machineCommands-EA3M4XTN.js +779 -0
- package/machineInfo-M6KB6HZN.js +10 -0
- package/machineWsRunDispatch-NAPKE5ZA.js +110 -0
- package/memoryCommands-O4MIPIWQ.js +476 -0
- package/models-4OPOOLFS.js +9 -0
- package/offlineMarxistsAgentCommand-BCPJITJL.js +242 -0
- package/package.json +3 -25
- package/read-RIJCIVKX.js +17 -0
- package/readDocTool-GZD2N3LO.js +16 -0
- package/readlineWorkspace-KMWT4T4S.js +5509 -0
- package/removeDialogAgentAction-GJQJNDW6.js +73 -0
- package/runAgentClientLoop-U5Q6NDTJ.js +291 -0
- package/runtimeDoctorCommands-LRHLPDRC.js +289 -0
- package/setDialogExtraReferencesAction-M7OQG54N.js +60 -0
- package/setPrimaryDialogAgentAction-46UNFJDL.js +80 -0
- package/settingSlice-FVUUH4JA.js +199 -0
- package/skillSummaryMarker-42HKSXYY.js +9 -0
- package/slateToRenderMarkdown-Y5IYN73U.js +7 -0
- package/slateUtils-2M7MUTWX.js +19 -0
- package/spaceCommands-E2CFRPZJ.js +454 -0
- package/spaceSlice-L3R6IMXE.js +147 -0
- package/streamAgentChatTurn-UBDAOQWE.js +4528 -0
- package/tableCommands-GOFP7QKA.js +1286 -0
- package/toolApiClient-QI3YBNWB.js +26 -0
- package/tools-TMJXZTCA.js +85 -0
- package/tuiSummaryLlmCaller-RV3THLZF.js +78 -0
- package/understanding-GQKNDDWM.js +271 -0
- package/updateCommands-VOSPKXFF.js +31 -0
- package/updateDialogTitleAction-ZTWRDXI2.js +188 -0
|
@@ -0,0 +1,3066 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAllServers,
|
|
3
|
+
getIsDesktopApp,
|
|
4
|
+
isAbortError
|
|
5
|
+
} from "./chunk-QYXLLLGL.js";
|
|
6
|
+
import {
|
|
7
|
+
isLocalServerUrl
|
|
8
|
+
} from "./chunk-4SN6J65J.js";
|
|
9
|
+
import {
|
|
10
|
+
API_ENDPOINTS,
|
|
11
|
+
SERVERS,
|
|
12
|
+
normalizeKnownServerOrigin
|
|
13
|
+
} from "./chunk-LCBAMY2M.js";
|
|
14
|
+
import {
|
|
15
|
+
asTrimmedString
|
|
16
|
+
} from "./chunk-3EUW3WEO.js";
|
|
17
|
+
import {
|
|
18
|
+
asOptionalPositiveFiniteNumber
|
|
19
|
+
} from "./chunk-U6VC4MU4.js";
|
|
20
|
+
import {
|
|
21
|
+
normalizeServerOrigin
|
|
22
|
+
} from "./chunk-CF7PE763.js";
|
|
23
|
+
import {
|
|
24
|
+
asOptionalTrimmedString
|
|
25
|
+
} from "./chunk-G3SUCT4W.js";
|
|
26
|
+
import {
|
|
27
|
+
isRecord
|
|
28
|
+
} from "./chunk-KUG52IAP.js";
|
|
29
|
+
|
|
30
|
+
// node_modules/reselect/dist/reselect.mjs
|
|
31
|
+
var runIdentityFunctionCheck = (resultFunc, inputSelectorsResults, outputSelectorResult) => {
|
|
32
|
+
if (inputSelectorsResults.length === 1 && inputSelectorsResults[0] === outputSelectorResult) {
|
|
33
|
+
let isInputSameAsOutput = false;
|
|
34
|
+
try {
|
|
35
|
+
const emptyObject = {};
|
|
36
|
+
if (resultFunc(emptyObject) === emptyObject)
|
|
37
|
+
isInputSameAsOutput = true;
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
if (isInputSameAsOutput) {
|
|
41
|
+
let stack = void 0;
|
|
42
|
+
try {
|
|
43
|
+
throw new Error();
|
|
44
|
+
} catch (e) {
|
|
45
|
+
;
|
|
46
|
+
({ stack } = e);
|
|
47
|
+
}
|
|
48
|
+
console.warn(
|
|
49
|
+
"The result function returned its own inputs without modification. e.g\n`createSelector([state => state.todos], todos => todos)`\nThis could lead to inefficient memoization and unnecessary re-renders.\nEnsure transformation logic is in the result function, and extraction logic is in the input selectors.",
|
|
50
|
+
{ stack }
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var runInputStabilityCheck = (inputSelectorResultsObject, options, inputSelectorArgs) => {
|
|
56
|
+
const { memoize, memoizeOptions } = options;
|
|
57
|
+
const { inputSelectorResults, inputSelectorResultsCopy } = inputSelectorResultsObject;
|
|
58
|
+
const createAnEmptyObject = memoize(() => ({}), ...memoizeOptions);
|
|
59
|
+
const areInputSelectorResultsEqual = createAnEmptyObject.apply(null, inputSelectorResults) === createAnEmptyObject.apply(null, inputSelectorResultsCopy);
|
|
60
|
+
if (!areInputSelectorResultsEqual) {
|
|
61
|
+
let stack = void 0;
|
|
62
|
+
try {
|
|
63
|
+
throw new Error();
|
|
64
|
+
} catch (e) {
|
|
65
|
+
;
|
|
66
|
+
({ stack } = e);
|
|
67
|
+
}
|
|
68
|
+
console.warn(
|
|
69
|
+
"An input selector returned a different result when passed same arguments.\nThis means your output selector will likely run more frequently than intended.\nAvoid returning a new reference inside your input selector, e.g.\n`createSelector([state => state.todos.map(todo => todo.id)], todoIds => todoIds.length)`",
|
|
70
|
+
{
|
|
71
|
+
arguments: inputSelectorArgs,
|
|
72
|
+
firstInputs: inputSelectorResults,
|
|
73
|
+
secondInputs: inputSelectorResultsCopy,
|
|
74
|
+
stack
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var globalDevModeChecks = {
|
|
80
|
+
inputStabilityCheck: "once",
|
|
81
|
+
identityFunctionCheck: "once"
|
|
82
|
+
};
|
|
83
|
+
function assertIsFunction(func, errorMessage = `expected a function, instead received ${typeof func}`) {
|
|
84
|
+
if (typeof func !== "function") {
|
|
85
|
+
throw new TypeError(errorMessage);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function assertIsObject(object, errorMessage = `expected an object, instead received ${typeof object}`) {
|
|
89
|
+
if (typeof object !== "object") {
|
|
90
|
+
throw new TypeError(errorMessage);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function assertIsArrayOfFunctions(array, errorMessage = `expected all items to be functions, instead received the following types: `) {
|
|
94
|
+
if (!array.every((item) => typeof item === "function")) {
|
|
95
|
+
const itemTypes = array.map(
|
|
96
|
+
(item) => typeof item === "function" ? `function ${item.name || "unnamed"}()` : typeof item
|
|
97
|
+
).join(", ");
|
|
98
|
+
throw new TypeError(`${errorMessage}[${itemTypes}]`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
var ensureIsArray = (item) => {
|
|
102
|
+
return Array.isArray(item) ? item : [item];
|
|
103
|
+
};
|
|
104
|
+
function getDependencies(createSelectorArgs) {
|
|
105
|
+
const dependencies = Array.isArray(createSelectorArgs[0]) ? createSelectorArgs[0] : createSelectorArgs;
|
|
106
|
+
assertIsArrayOfFunctions(
|
|
107
|
+
dependencies,
|
|
108
|
+
`createSelector expects all input-selectors to be functions, but received the following types: `
|
|
109
|
+
);
|
|
110
|
+
return dependencies;
|
|
111
|
+
}
|
|
112
|
+
function collectInputSelectorResults(dependencies, inputSelectorArgs) {
|
|
113
|
+
const inputSelectorResults = [];
|
|
114
|
+
const { length } = dependencies;
|
|
115
|
+
for (let i = 0; i < length; i++) {
|
|
116
|
+
inputSelectorResults.push(dependencies[i].apply(null, inputSelectorArgs));
|
|
117
|
+
}
|
|
118
|
+
return inputSelectorResults;
|
|
119
|
+
}
|
|
120
|
+
var getDevModeChecksExecutionInfo = (firstRun, devModeChecks) => {
|
|
121
|
+
const { identityFunctionCheck, inputStabilityCheck } = {
|
|
122
|
+
...globalDevModeChecks,
|
|
123
|
+
...devModeChecks
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
identityFunctionCheck: {
|
|
127
|
+
shouldRun: identityFunctionCheck === "always" || identityFunctionCheck === "once" && firstRun,
|
|
128
|
+
run: runIdentityFunctionCheck
|
|
129
|
+
},
|
|
130
|
+
inputStabilityCheck: {
|
|
131
|
+
shouldRun: inputStabilityCheck === "always" || inputStabilityCheck === "once" && firstRun,
|
|
132
|
+
run: runInputStabilityCheck
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
var REDUX_PROXY_LABEL = Symbol();
|
|
137
|
+
var proto = Object.getPrototypeOf({});
|
|
138
|
+
var StrongRef = class {
|
|
139
|
+
constructor(value) {
|
|
140
|
+
this.value = value;
|
|
141
|
+
}
|
|
142
|
+
deref() {
|
|
143
|
+
return this.value;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
var Ref = typeof WeakRef !== "undefined" ? WeakRef : StrongRef;
|
|
147
|
+
var UNTERMINATED = 0;
|
|
148
|
+
var TERMINATED = 1;
|
|
149
|
+
function createCacheNode() {
|
|
150
|
+
return {
|
|
151
|
+
s: UNTERMINATED,
|
|
152
|
+
v: void 0,
|
|
153
|
+
o: null,
|
|
154
|
+
p: null
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function weakMapMemoize(func, options = {}) {
|
|
158
|
+
let fnNode = createCacheNode();
|
|
159
|
+
const { resultEqualityCheck } = options;
|
|
160
|
+
let lastResult;
|
|
161
|
+
let resultsCount = 0;
|
|
162
|
+
function memoized() {
|
|
163
|
+
let cacheNode = fnNode;
|
|
164
|
+
const { length } = arguments;
|
|
165
|
+
for (let i = 0, l = length; i < l; i++) {
|
|
166
|
+
const arg = arguments[i];
|
|
167
|
+
if (typeof arg === "function" || typeof arg === "object" && arg !== null) {
|
|
168
|
+
let objectCache = cacheNode.o;
|
|
169
|
+
if (objectCache === null) {
|
|
170
|
+
cacheNode.o = objectCache = /* @__PURE__ */ new WeakMap();
|
|
171
|
+
}
|
|
172
|
+
const objectNode = objectCache.get(arg);
|
|
173
|
+
if (objectNode === void 0) {
|
|
174
|
+
cacheNode = createCacheNode();
|
|
175
|
+
objectCache.set(arg, cacheNode);
|
|
176
|
+
} else {
|
|
177
|
+
cacheNode = objectNode;
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
let primitiveCache = cacheNode.p;
|
|
181
|
+
if (primitiveCache === null) {
|
|
182
|
+
cacheNode.p = primitiveCache = /* @__PURE__ */ new Map();
|
|
183
|
+
}
|
|
184
|
+
const primitiveNode = primitiveCache.get(arg);
|
|
185
|
+
if (primitiveNode === void 0) {
|
|
186
|
+
cacheNode = createCacheNode();
|
|
187
|
+
primitiveCache.set(arg, cacheNode);
|
|
188
|
+
} else {
|
|
189
|
+
cacheNode = primitiveNode;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const terminatedNode = cacheNode;
|
|
194
|
+
let result;
|
|
195
|
+
if (cacheNode.s === TERMINATED) {
|
|
196
|
+
result = cacheNode.v;
|
|
197
|
+
} else {
|
|
198
|
+
result = func.apply(null, arguments);
|
|
199
|
+
resultsCount++;
|
|
200
|
+
if (resultEqualityCheck) {
|
|
201
|
+
const lastResultValue = lastResult?.deref?.() ?? lastResult;
|
|
202
|
+
if (lastResultValue != null && resultEqualityCheck(lastResultValue, result)) {
|
|
203
|
+
result = lastResultValue;
|
|
204
|
+
resultsCount !== 0 && resultsCount--;
|
|
205
|
+
}
|
|
206
|
+
const needsWeakRef = typeof result === "object" && result !== null || typeof result === "function";
|
|
207
|
+
lastResult = needsWeakRef ? new Ref(result) : result;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
terminatedNode.s = TERMINATED;
|
|
211
|
+
terminatedNode.v = result;
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
memoized.clearCache = () => {
|
|
215
|
+
fnNode = createCacheNode();
|
|
216
|
+
memoized.resetResultsCount();
|
|
217
|
+
};
|
|
218
|
+
memoized.resultsCount = () => resultsCount;
|
|
219
|
+
memoized.resetResultsCount = () => {
|
|
220
|
+
resultsCount = 0;
|
|
221
|
+
};
|
|
222
|
+
return memoized;
|
|
223
|
+
}
|
|
224
|
+
function createSelectorCreator(memoizeOrOptions, ...memoizeOptionsFromArgs) {
|
|
225
|
+
const createSelectorCreatorOptions = typeof memoizeOrOptions === "function" ? {
|
|
226
|
+
memoize: memoizeOrOptions,
|
|
227
|
+
memoizeOptions: memoizeOptionsFromArgs
|
|
228
|
+
} : memoizeOrOptions;
|
|
229
|
+
const createSelector2 = (...createSelectorArgs) => {
|
|
230
|
+
let recomputations = 0;
|
|
231
|
+
let dependencyRecomputations = 0;
|
|
232
|
+
let lastResult;
|
|
233
|
+
let directlyPassedOptions = {};
|
|
234
|
+
let resultFunc = createSelectorArgs.pop();
|
|
235
|
+
if (typeof resultFunc === "object") {
|
|
236
|
+
directlyPassedOptions = resultFunc;
|
|
237
|
+
resultFunc = createSelectorArgs.pop();
|
|
238
|
+
}
|
|
239
|
+
assertIsFunction(
|
|
240
|
+
resultFunc,
|
|
241
|
+
`createSelector expects an output function after the inputs, but received: [${typeof resultFunc}]`
|
|
242
|
+
);
|
|
243
|
+
const combinedOptions = {
|
|
244
|
+
...createSelectorCreatorOptions,
|
|
245
|
+
...directlyPassedOptions
|
|
246
|
+
};
|
|
247
|
+
const {
|
|
248
|
+
memoize,
|
|
249
|
+
memoizeOptions = [],
|
|
250
|
+
argsMemoize = weakMapMemoize,
|
|
251
|
+
argsMemoizeOptions = [],
|
|
252
|
+
devModeChecks = {}
|
|
253
|
+
} = combinedOptions;
|
|
254
|
+
const finalMemoizeOptions = ensureIsArray(memoizeOptions);
|
|
255
|
+
const finalArgsMemoizeOptions = ensureIsArray(argsMemoizeOptions);
|
|
256
|
+
const dependencies = getDependencies(createSelectorArgs);
|
|
257
|
+
const memoizedResultFunc = memoize(function recomputationWrapper() {
|
|
258
|
+
recomputations++;
|
|
259
|
+
return resultFunc.apply(
|
|
260
|
+
null,
|
|
261
|
+
arguments
|
|
262
|
+
);
|
|
263
|
+
}, ...finalMemoizeOptions);
|
|
264
|
+
let firstRun = true;
|
|
265
|
+
const selector = argsMemoize(function dependenciesChecker() {
|
|
266
|
+
dependencyRecomputations++;
|
|
267
|
+
const inputSelectorResults = collectInputSelectorResults(
|
|
268
|
+
dependencies,
|
|
269
|
+
arguments
|
|
270
|
+
);
|
|
271
|
+
lastResult = memoizedResultFunc.apply(null, inputSelectorResults);
|
|
272
|
+
if (process.env.NODE_ENV !== "production") {
|
|
273
|
+
const { identityFunctionCheck, inputStabilityCheck } = getDevModeChecksExecutionInfo(firstRun, devModeChecks);
|
|
274
|
+
if (identityFunctionCheck.shouldRun) {
|
|
275
|
+
identityFunctionCheck.run(
|
|
276
|
+
resultFunc,
|
|
277
|
+
inputSelectorResults,
|
|
278
|
+
lastResult
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
if (inputStabilityCheck.shouldRun) {
|
|
282
|
+
const inputSelectorResultsCopy = collectInputSelectorResults(
|
|
283
|
+
dependencies,
|
|
284
|
+
arguments
|
|
285
|
+
);
|
|
286
|
+
inputStabilityCheck.run(
|
|
287
|
+
{ inputSelectorResults, inputSelectorResultsCopy },
|
|
288
|
+
{ memoize, memoizeOptions: finalMemoizeOptions },
|
|
289
|
+
arguments
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
if (firstRun)
|
|
293
|
+
firstRun = false;
|
|
294
|
+
}
|
|
295
|
+
return lastResult;
|
|
296
|
+
}, ...finalArgsMemoizeOptions);
|
|
297
|
+
return Object.assign(selector, {
|
|
298
|
+
resultFunc,
|
|
299
|
+
memoizedResultFunc,
|
|
300
|
+
dependencies,
|
|
301
|
+
dependencyRecomputations: () => dependencyRecomputations,
|
|
302
|
+
resetDependencyRecomputations: () => {
|
|
303
|
+
dependencyRecomputations = 0;
|
|
304
|
+
},
|
|
305
|
+
lastResult: () => lastResult,
|
|
306
|
+
recomputations: () => recomputations,
|
|
307
|
+
resetRecomputations: () => {
|
|
308
|
+
recomputations = 0;
|
|
309
|
+
},
|
|
310
|
+
memoize,
|
|
311
|
+
argsMemoize
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
Object.assign(createSelector2, {
|
|
315
|
+
withTypes: () => createSelector2
|
|
316
|
+
});
|
|
317
|
+
return createSelector2;
|
|
318
|
+
}
|
|
319
|
+
var createSelector = /* @__PURE__ */ createSelectorCreator(weakMapMemoize);
|
|
320
|
+
var createStructuredSelector = Object.assign(
|
|
321
|
+
(inputSelectorsObject, selectorCreator = createSelector) => {
|
|
322
|
+
assertIsObject(
|
|
323
|
+
inputSelectorsObject,
|
|
324
|
+
`createStructuredSelector expects first argument to be an object where each property is a selector, instead received a ${typeof inputSelectorsObject}`
|
|
325
|
+
);
|
|
326
|
+
const inputSelectorKeys = Object.keys(inputSelectorsObject);
|
|
327
|
+
const dependencies = inputSelectorKeys.map(
|
|
328
|
+
(key) => inputSelectorsObject[key]
|
|
329
|
+
);
|
|
330
|
+
const structuredSelector = selectorCreator(
|
|
331
|
+
dependencies,
|
|
332
|
+
(...inputSelectorResults) => {
|
|
333
|
+
return inputSelectorResults.reduce((composition, value, index) => {
|
|
334
|
+
composition[inputSelectorKeys[index]] = value;
|
|
335
|
+
return composition;
|
|
336
|
+
}, {});
|
|
337
|
+
}
|
|
338
|
+
);
|
|
339
|
+
return structuredSelector;
|
|
340
|
+
},
|
|
341
|
+
{ withTypes: () => createStructuredSelector }
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
// node_modules/redux/dist/redux.mjs
|
|
345
|
+
var randomString = () => Math.random().toString(36).substring(7).split("").join(".");
|
|
346
|
+
var ActionTypes = {
|
|
347
|
+
INIT: `@@redux/INIT${/* @__PURE__ */ randomString()}`,
|
|
348
|
+
REPLACE: `@@redux/REPLACE${/* @__PURE__ */ randomString()}`,
|
|
349
|
+
PROBE_UNKNOWN_ACTION: () => `@@redux/PROBE_UNKNOWN_ACTION${randomString()}`
|
|
350
|
+
};
|
|
351
|
+
function isPlainObject(obj) {
|
|
352
|
+
if (typeof obj !== "object" || obj === null)
|
|
353
|
+
return false;
|
|
354
|
+
let proto2 = obj;
|
|
355
|
+
while (Object.getPrototypeOf(proto2) !== null) {
|
|
356
|
+
proto2 = Object.getPrototypeOf(proto2);
|
|
357
|
+
}
|
|
358
|
+
return Object.getPrototypeOf(obj) === proto2 || Object.getPrototypeOf(obj) === null;
|
|
359
|
+
}
|
|
360
|
+
function compose(...funcs) {
|
|
361
|
+
if (funcs.length === 0) {
|
|
362
|
+
return (arg) => arg;
|
|
363
|
+
}
|
|
364
|
+
if (funcs.length === 1) {
|
|
365
|
+
return funcs[0];
|
|
366
|
+
}
|
|
367
|
+
return funcs.reduce((a, b) => (...args) => a(b(...args)));
|
|
368
|
+
}
|
|
369
|
+
function isAction(action) {
|
|
370
|
+
return isPlainObject(action) && "type" in action && typeof action.type === "string";
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// node_modules/immer/dist/immer.mjs
|
|
374
|
+
var NOTHING = Symbol.for("immer-nothing");
|
|
375
|
+
var DRAFTABLE = Symbol.for("immer-draftable");
|
|
376
|
+
var DRAFT_STATE = Symbol.for("immer-state");
|
|
377
|
+
var errors = process.env.NODE_ENV !== "production" ? [
|
|
378
|
+
// All error codes, starting by 0:
|
|
379
|
+
function(plugin) {
|
|
380
|
+
return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
|
|
381
|
+
},
|
|
382
|
+
function(thing) {
|
|
383
|
+
return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
|
|
384
|
+
},
|
|
385
|
+
"This object has been frozen and should not be mutated",
|
|
386
|
+
function(data) {
|
|
387
|
+
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
|
|
388
|
+
},
|
|
389
|
+
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
|
|
390
|
+
"Immer forbids circular references",
|
|
391
|
+
"The first or second argument to `produce` must be a function",
|
|
392
|
+
"The third argument to `produce` must be a function or undefined",
|
|
393
|
+
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
|
|
394
|
+
"First argument to `finishDraft` must be a draft returned by `createDraft`",
|
|
395
|
+
function(thing) {
|
|
396
|
+
return `'current' expects a draft, got: ${thing}`;
|
|
397
|
+
},
|
|
398
|
+
"Object.defineProperty() cannot be used on an Immer draft",
|
|
399
|
+
"Object.setPrototypeOf() cannot be used on an Immer draft",
|
|
400
|
+
"Immer only supports deleting array indices",
|
|
401
|
+
"Immer only supports setting array indices and the 'length' property",
|
|
402
|
+
function(thing) {
|
|
403
|
+
return `'original' expects a draft, got: ${thing}`;
|
|
404
|
+
}
|
|
405
|
+
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
|
|
406
|
+
// See Patches.ts for additional errors
|
|
407
|
+
] : [];
|
|
408
|
+
function die(error, ...args) {
|
|
409
|
+
if (process.env.NODE_ENV !== "production") {
|
|
410
|
+
const e = errors[error];
|
|
411
|
+
const msg = typeof e === "function" ? e.apply(null, args) : e;
|
|
412
|
+
throw new Error(`[Immer] ${msg}`);
|
|
413
|
+
}
|
|
414
|
+
throw new Error(
|
|
415
|
+
`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
|
419
|
+
function isDraft(value) {
|
|
420
|
+
return !!value && !!value[DRAFT_STATE];
|
|
421
|
+
}
|
|
422
|
+
function isDraftable(value) {
|
|
423
|
+
if (!value)
|
|
424
|
+
return false;
|
|
425
|
+
return isPlainObject2(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
|
|
426
|
+
}
|
|
427
|
+
var objectCtorString = Object.prototype.constructor.toString();
|
|
428
|
+
function isPlainObject2(value) {
|
|
429
|
+
if (!value || typeof value !== "object")
|
|
430
|
+
return false;
|
|
431
|
+
const proto2 = getPrototypeOf(value);
|
|
432
|
+
if (proto2 === null) {
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
const Ctor = Object.hasOwnProperty.call(proto2, "constructor") && proto2.constructor;
|
|
436
|
+
if (Ctor === Object)
|
|
437
|
+
return true;
|
|
438
|
+
return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
|
|
439
|
+
}
|
|
440
|
+
function each(obj, iter) {
|
|
441
|
+
if (getArchtype(obj) === 0) {
|
|
442
|
+
Reflect.ownKeys(obj).forEach((key) => {
|
|
443
|
+
iter(key, obj[key], obj);
|
|
444
|
+
});
|
|
445
|
+
} else {
|
|
446
|
+
obj.forEach((entry, index) => iter(index, entry, obj));
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function getArchtype(thing) {
|
|
450
|
+
const state = thing[DRAFT_STATE];
|
|
451
|
+
return state ? state.type_ : Array.isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
|
|
452
|
+
}
|
|
453
|
+
function has(thing, prop) {
|
|
454
|
+
return getArchtype(thing) === 2 ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
|
|
455
|
+
}
|
|
456
|
+
function set(thing, propOrOldValue, value) {
|
|
457
|
+
const t = getArchtype(thing);
|
|
458
|
+
if (t === 2)
|
|
459
|
+
thing.set(propOrOldValue, value);
|
|
460
|
+
else if (t === 3) {
|
|
461
|
+
thing.add(value);
|
|
462
|
+
} else
|
|
463
|
+
thing[propOrOldValue] = value;
|
|
464
|
+
}
|
|
465
|
+
function is(x, y) {
|
|
466
|
+
if (x === y) {
|
|
467
|
+
return x !== 0 || 1 / x === 1 / y;
|
|
468
|
+
} else {
|
|
469
|
+
return x !== x && y !== y;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
function isMap(target) {
|
|
473
|
+
return target instanceof Map;
|
|
474
|
+
}
|
|
475
|
+
function isSet(target) {
|
|
476
|
+
return target instanceof Set;
|
|
477
|
+
}
|
|
478
|
+
function latest(state) {
|
|
479
|
+
return state.copy_ || state.base_;
|
|
480
|
+
}
|
|
481
|
+
function shallowCopy(base, strict) {
|
|
482
|
+
if (isMap(base)) {
|
|
483
|
+
return new Map(base);
|
|
484
|
+
}
|
|
485
|
+
if (isSet(base)) {
|
|
486
|
+
return new Set(base);
|
|
487
|
+
}
|
|
488
|
+
if (Array.isArray(base))
|
|
489
|
+
return Array.prototype.slice.call(base);
|
|
490
|
+
const isPlain = isPlainObject2(base);
|
|
491
|
+
if (strict === true || strict === "class_only" && !isPlain) {
|
|
492
|
+
const descriptors = Object.getOwnPropertyDescriptors(base);
|
|
493
|
+
delete descriptors[DRAFT_STATE];
|
|
494
|
+
let keys = Reflect.ownKeys(descriptors);
|
|
495
|
+
for (let i = 0; i < keys.length; i++) {
|
|
496
|
+
const key = keys[i];
|
|
497
|
+
const desc = descriptors[key];
|
|
498
|
+
if (desc.writable === false) {
|
|
499
|
+
desc.writable = true;
|
|
500
|
+
desc.configurable = true;
|
|
501
|
+
}
|
|
502
|
+
if (desc.get || desc.set)
|
|
503
|
+
descriptors[key] = {
|
|
504
|
+
configurable: true,
|
|
505
|
+
writable: true,
|
|
506
|
+
// could live with !!desc.set as well here...
|
|
507
|
+
enumerable: desc.enumerable,
|
|
508
|
+
value: base[key]
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
return Object.create(getPrototypeOf(base), descriptors);
|
|
512
|
+
} else {
|
|
513
|
+
const proto2 = getPrototypeOf(base);
|
|
514
|
+
if (proto2 !== null && isPlain) {
|
|
515
|
+
return { ...base };
|
|
516
|
+
}
|
|
517
|
+
const obj = Object.create(proto2);
|
|
518
|
+
return Object.assign(obj, base);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
function freeze(obj, deep = false) {
|
|
522
|
+
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
|
|
523
|
+
return obj;
|
|
524
|
+
if (getArchtype(obj) > 1) {
|
|
525
|
+
obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
|
|
526
|
+
}
|
|
527
|
+
Object.freeze(obj);
|
|
528
|
+
if (deep)
|
|
529
|
+
Object.entries(obj).forEach(([key, value]) => freeze(value, true));
|
|
530
|
+
return obj;
|
|
531
|
+
}
|
|
532
|
+
function dontMutateFrozenCollections() {
|
|
533
|
+
die(2);
|
|
534
|
+
}
|
|
535
|
+
function isFrozen(obj) {
|
|
536
|
+
return Object.isFrozen(obj);
|
|
537
|
+
}
|
|
538
|
+
var plugins = {};
|
|
539
|
+
function getPlugin(pluginKey) {
|
|
540
|
+
const plugin = plugins[pluginKey];
|
|
541
|
+
if (!plugin) {
|
|
542
|
+
die(0, pluginKey);
|
|
543
|
+
}
|
|
544
|
+
return plugin;
|
|
545
|
+
}
|
|
546
|
+
var currentScope;
|
|
547
|
+
function getCurrentScope() {
|
|
548
|
+
return currentScope;
|
|
549
|
+
}
|
|
550
|
+
function createScope(parent_, immer_) {
|
|
551
|
+
return {
|
|
552
|
+
drafts_: [],
|
|
553
|
+
parent_,
|
|
554
|
+
immer_,
|
|
555
|
+
// Whenever the modified draft contains a draft from another scope, we
|
|
556
|
+
// need to prevent auto-freezing so the unowned draft can be finalized.
|
|
557
|
+
canAutoFreeze_: true,
|
|
558
|
+
unfinalizedDrafts_: 0
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
function usePatchesInScope(scope, patchListener) {
|
|
562
|
+
if (patchListener) {
|
|
563
|
+
getPlugin("Patches");
|
|
564
|
+
scope.patches_ = [];
|
|
565
|
+
scope.inversePatches_ = [];
|
|
566
|
+
scope.patchListener_ = patchListener;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function revokeScope(scope) {
|
|
570
|
+
leaveScope(scope);
|
|
571
|
+
scope.drafts_.forEach(revokeDraft);
|
|
572
|
+
scope.drafts_ = null;
|
|
573
|
+
}
|
|
574
|
+
function leaveScope(scope) {
|
|
575
|
+
if (scope === currentScope) {
|
|
576
|
+
currentScope = scope.parent_;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
function enterScope(immer2) {
|
|
580
|
+
return currentScope = createScope(currentScope, immer2);
|
|
581
|
+
}
|
|
582
|
+
function revokeDraft(draft) {
|
|
583
|
+
const state = draft[DRAFT_STATE];
|
|
584
|
+
if (state.type_ === 0 || state.type_ === 1)
|
|
585
|
+
state.revoke_();
|
|
586
|
+
else
|
|
587
|
+
state.revoked_ = true;
|
|
588
|
+
}
|
|
589
|
+
function processResult(result, scope) {
|
|
590
|
+
scope.unfinalizedDrafts_ = scope.drafts_.length;
|
|
591
|
+
const baseDraft = scope.drafts_[0];
|
|
592
|
+
const isReplaced = result !== void 0 && result !== baseDraft;
|
|
593
|
+
if (isReplaced) {
|
|
594
|
+
if (baseDraft[DRAFT_STATE].modified_) {
|
|
595
|
+
revokeScope(scope);
|
|
596
|
+
die(4);
|
|
597
|
+
}
|
|
598
|
+
if (isDraftable(result)) {
|
|
599
|
+
result = finalize(scope, result);
|
|
600
|
+
if (!scope.parent_)
|
|
601
|
+
maybeFreeze(scope, result);
|
|
602
|
+
}
|
|
603
|
+
if (scope.patches_) {
|
|
604
|
+
getPlugin("Patches").generateReplacementPatches_(
|
|
605
|
+
baseDraft[DRAFT_STATE].base_,
|
|
606
|
+
result,
|
|
607
|
+
scope.patches_,
|
|
608
|
+
scope.inversePatches_
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
} else {
|
|
612
|
+
result = finalize(scope, baseDraft, []);
|
|
613
|
+
}
|
|
614
|
+
revokeScope(scope);
|
|
615
|
+
if (scope.patches_) {
|
|
616
|
+
scope.patchListener_(scope.patches_, scope.inversePatches_);
|
|
617
|
+
}
|
|
618
|
+
return result !== NOTHING ? result : void 0;
|
|
619
|
+
}
|
|
620
|
+
function finalize(rootScope, value, path) {
|
|
621
|
+
if (isFrozen(value))
|
|
622
|
+
return value;
|
|
623
|
+
const state = value[DRAFT_STATE];
|
|
624
|
+
if (!state) {
|
|
625
|
+
each(
|
|
626
|
+
value,
|
|
627
|
+
(key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path)
|
|
628
|
+
);
|
|
629
|
+
return value;
|
|
630
|
+
}
|
|
631
|
+
if (state.scope_ !== rootScope)
|
|
632
|
+
return value;
|
|
633
|
+
if (!state.modified_) {
|
|
634
|
+
maybeFreeze(rootScope, state.base_, true);
|
|
635
|
+
return state.base_;
|
|
636
|
+
}
|
|
637
|
+
if (!state.finalized_) {
|
|
638
|
+
state.finalized_ = true;
|
|
639
|
+
state.scope_.unfinalizedDrafts_--;
|
|
640
|
+
const result = state.copy_;
|
|
641
|
+
let resultEach = result;
|
|
642
|
+
let isSet2 = false;
|
|
643
|
+
if (state.type_ === 3) {
|
|
644
|
+
resultEach = new Set(result);
|
|
645
|
+
result.clear();
|
|
646
|
+
isSet2 = true;
|
|
647
|
+
}
|
|
648
|
+
each(
|
|
649
|
+
resultEach,
|
|
650
|
+
(key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2)
|
|
651
|
+
);
|
|
652
|
+
maybeFreeze(rootScope, result, false);
|
|
653
|
+
if (path && rootScope.patches_) {
|
|
654
|
+
getPlugin("Patches").generatePatches_(
|
|
655
|
+
state,
|
|
656
|
+
path,
|
|
657
|
+
rootScope.patches_,
|
|
658
|
+
rootScope.inversePatches_
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
return state.copy_;
|
|
663
|
+
}
|
|
664
|
+
function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
|
|
665
|
+
if (process.env.NODE_ENV !== "production" && childValue === targetObject)
|
|
666
|
+
die(5);
|
|
667
|
+
if (isDraft(childValue)) {
|
|
668
|
+
const path = rootPath && parentState && parentState.type_ !== 3 && // Set objects are atomic since they have no keys.
|
|
669
|
+
!has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
|
|
670
|
+
const res = finalize(rootScope, childValue, path);
|
|
671
|
+
set(targetObject, prop, res);
|
|
672
|
+
if (isDraft(res)) {
|
|
673
|
+
rootScope.canAutoFreeze_ = false;
|
|
674
|
+
} else
|
|
675
|
+
return;
|
|
676
|
+
} else if (targetIsSet) {
|
|
677
|
+
targetObject.add(childValue);
|
|
678
|
+
}
|
|
679
|
+
if (isDraftable(childValue) && !isFrozen(childValue)) {
|
|
680
|
+
if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
finalize(rootScope, childValue);
|
|
684
|
+
if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && Object.prototype.propertyIsEnumerable.call(targetObject, prop))
|
|
685
|
+
maybeFreeze(rootScope, childValue);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
function maybeFreeze(scope, value, deep = false) {
|
|
689
|
+
if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
|
|
690
|
+
freeze(value, deep);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
function createProxyProxy(base, parent) {
|
|
694
|
+
const isArray = Array.isArray(base);
|
|
695
|
+
const state = {
|
|
696
|
+
type_: isArray ? 1 : 0,
|
|
697
|
+
// Track which produce call this is associated with.
|
|
698
|
+
scope_: parent ? parent.scope_ : getCurrentScope(),
|
|
699
|
+
// True for both shallow and deep changes.
|
|
700
|
+
modified_: false,
|
|
701
|
+
// Used during finalization.
|
|
702
|
+
finalized_: false,
|
|
703
|
+
// Track which properties have been assigned (true) or deleted (false).
|
|
704
|
+
assigned_: {},
|
|
705
|
+
// The parent draft state.
|
|
706
|
+
parent_: parent,
|
|
707
|
+
// The base state.
|
|
708
|
+
base_: base,
|
|
709
|
+
// The base proxy.
|
|
710
|
+
draft_: null,
|
|
711
|
+
// set below
|
|
712
|
+
// The base copy with any updated values.
|
|
713
|
+
copy_: null,
|
|
714
|
+
// Called by the `produce` function.
|
|
715
|
+
revoke_: null,
|
|
716
|
+
isManual_: false
|
|
717
|
+
};
|
|
718
|
+
let target = state;
|
|
719
|
+
let traps = objectTraps;
|
|
720
|
+
if (isArray) {
|
|
721
|
+
target = [state];
|
|
722
|
+
traps = arrayTraps;
|
|
723
|
+
}
|
|
724
|
+
const { revoke, proxy } = Proxy.revocable(target, traps);
|
|
725
|
+
state.draft_ = proxy;
|
|
726
|
+
state.revoke_ = revoke;
|
|
727
|
+
return proxy;
|
|
728
|
+
}
|
|
729
|
+
var objectTraps = {
|
|
730
|
+
get(state, prop) {
|
|
731
|
+
if (prop === DRAFT_STATE)
|
|
732
|
+
return state;
|
|
733
|
+
const source = latest(state);
|
|
734
|
+
if (!has(source, prop)) {
|
|
735
|
+
return readPropFromProto(state, source, prop);
|
|
736
|
+
}
|
|
737
|
+
const value = source[prop];
|
|
738
|
+
if (state.finalized_ || !isDraftable(value)) {
|
|
739
|
+
return value;
|
|
740
|
+
}
|
|
741
|
+
if (value === peek(state.base_, prop)) {
|
|
742
|
+
prepareCopy(state);
|
|
743
|
+
return state.copy_[prop] = createProxy(value, state);
|
|
744
|
+
}
|
|
745
|
+
return value;
|
|
746
|
+
},
|
|
747
|
+
has(state, prop) {
|
|
748
|
+
return prop in latest(state);
|
|
749
|
+
},
|
|
750
|
+
ownKeys(state) {
|
|
751
|
+
return Reflect.ownKeys(latest(state));
|
|
752
|
+
},
|
|
753
|
+
set(state, prop, value) {
|
|
754
|
+
const desc = getDescriptorFromProto(latest(state), prop);
|
|
755
|
+
if (desc?.set) {
|
|
756
|
+
desc.set.call(state.draft_, value);
|
|
757
|
+
return true;
|
|
758
|
+
}
|
|
759
|
+
if (!state.modified_) {
|
|
760
|
+
const current2 = peek(latest(state), prop);
|
|
761
|
+
const currentState = current2?.[DRAFT_STATE];
|
|
762
|
+
if (currentState && currentState.base_ === value) {
|
|
763
|
+
state.copy_[prop] = value;
|
|
764
|
+
state.assigned_[prop] = false;
|
|
765
|
+
return true;
|
|
766
|
+
}
|
|
767
|
+
if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
|
|
768
|
+
return true;
|
|
769
|
+
prepareCopy(state);
|
|
770
|
+
markChanged(state);
|
|
771
|
+
}
|
|
772
|
+
if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
|
|
773
|
+
(value !== void 0 || prop in state.copy_) || // special case: NaN
|
|
774
|
+
Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
|
|
775
|
+
return true;
|
|
776
|
+
state.copy_[prop] = value;
|
|
777
|
+
state.assigned_[prop] = true;
|
|
778
|
+
return true;
|
|
779
|
+
},
|
|
780
|
+
deleteProperty(state, prop) {
|
|
781
|
+
if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
|
|
782
|
+
state.assigned_[prop] = false;
|
|
783
|
+
prepareCopy(state);
|
|
784
|
+
markChanged(state);
|
|
785
|
+
} else {
|
|
786
|
+
delete state.assigned_[prop];
|
|
787
|
+
}
|
|
788
|
+
if (state.copy_) {
|
|
789
|
+
delete state.copy_[prop];
|
|
790
|
+
}
|
|
791
|
+
return true;
|
|
792
|
+
},
|
|
793
|
+
// Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
794
|
+
// the same guarantee in ES5 mode.
|
|
795
|
+
getOwnPropertyDescriptor(state, prop) {
|
|
796
|
+
const owner = latest(state);
|
|
797
|
+
const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
|
|
798
|
+
if (!desc)
|
|
799
|
+
return desc;
|
|
800
|
+
return {
|
|
801
|
+
writable: true,
|
|
802
|
+
configurable: state.type_ !== 1 || prop !== "length",
|
|
803
|
+
enumerable: desc.enumerable,
|
|
804
|
+
value: owner[prop]
|
|
805
|
+
};
|
|
806
|
+
},
|
|
807
|
+
defineProperty() {
|
|
808
|
+
die(11);
|
|
809
|
+
},
|
|
810
|
+
getPrototypeOf(state) {
|
|
811
|
+
return getPrototypeOf(state.base_);
|
|
812
|
+
},
|
|
813
|
+
setPrototypeOf() {
|
|
814
|
+
die(12);
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
var arrayTraps = {};
|
|
818
|
+
each(objectTraps, (key, fn) => {
|
|
819
|
+
arrayTraps[key] = function() {
|
|
820
|
+
arguments[0] = arguments[0][0];
|
|
821
|
+
return fn.apply(this, arguments);
|
|
822
|
+
};
|
|
823
|
+
});
|
|
824
|
+
arrayTraps.deleteProperty = function(state, prop) {
|
|
825
|
+
if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
|
|
826
|
+
die(13);
|
|
827
|
+
return arrayTraps.set.call(this, state, prop, void 0);
|
|
828
|
+
};
|
|
829
|
+
arrayTraps.set = function(state, prop, value) {
|
|
830
|
+
if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
|
|
831
|
+
die(14);
|
|
832
|
+
return objectTraps.set.call(this, state[0], prop, value, state[0]);
|
|
833
|
+
};
|
|
834
|
+
function peek(draft, prop) {
|
|
835
|
+
const state = draft[DRAFT_STATE];
|
|
836
|
+
const source = state ? latest(state) : draft;
|
|
837
|
+
return source[prop];
|
|
838
|
+
}
|
|
839
|
+
function readPropFromProto(state, source, prop) {
|
|
840
|
+
const desc = getDescriptorFromProto(source, prop);
|
|
841
|
+
return desc ? `value` in desc ? desc.value : (
|
|
842
|
+
// This is a very special case, if the prop is a getter defined by the
|
|
843
|
+
// prototype, we should invoke it with the draft as context!
|
|
844
|
+
desc.get?.call(state.draft_)
|
|
845
|
+
) : void 0;
|
|
846
|
+
}
|
|
847
|
+
function getDescriptorFromProto(source, prop) {
|
|
848
|
+
if (!(prop in source))
|
|
849
|
+
return void 0;
|
|
850
|
+
let proto2 = getPrototypeOf(source);
|
|
851
|
+
while (proto2) {
|
|
852
|
+
const desc = Object.getOwnPropertyDescriptor(proto2, prop);
|
|
853
|
+
if (desc)
|
|
854
|
+
return desc;
|
|
855
|
+
proto2 = getPrototypeOf(proto2);
|
|
856
|
+
}
|
|
857
|
+
return void 0;
|
|
858
|
+
}
|
|
859
|
+
function markChanged(state) {
|
|
860
|
+
if (!state.modified_) {
|
|
861
|
+
state.modified_ = true;
|
|
862
|
+
if (state.parent_) {
|
|
863
|
+
markChanged(state.parent_);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
function prepareCopy(state) {
|
|
868
|
+
if (!state.copy_) {
|
|
869
|
+
state.copy_ = shallowCopy(
|
|
870
|
+
state.base_,
|
|
871
|
+
state.scope_.immer_.useStrictShallowCopy_
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
var Immer2 = class {
|
|
876
|
+
constructor(config) {
|
|
877
|
+
this.autoFreeze_ = true;
|
|
878
|
+
this.useStrictShallowCopy_ = false;
|
|
879
|
+
this.produce = (base, recipe, patchListener) => {
|
|
880
|
+
if (typeof base === "function" && typeof recipe !== "function") {
|
|
881
|
+
const defaultBase = recipe;
|
|
882
|
+
recipe = base;
|
|
883
|
+
const self = this;
|
|
884
|
+
return function curriedProduce(base2 = defaultBase, ...args) {
|
|
885
|
+
return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
if (typeof recipe !== "function")
|
|
889
|
+
die(6);
|
|
890
|
+
if (patchListener !== void 0 && typeof patchListener !== "function")
|
|
891
|
+
die(7);
|
|
892
|
+
let result;
|
|
893
|
+
if (isDraftable(base)) {
|
|
894
|
+
const scope = enterScope(this);
|
|
895
|
+
const proxy = createProxy(base, void 0);
|
|
896
|
+
let hasError = true;
|
|
897
|
+
try {
|
|
898
|
+
result = recipe(proxy);
|
|
899
|
+
hasError = false;
|
|
900
|
+
} finally {
|
|
901
|
+
if (hasError)
|
|
902
|
+
revokeScope(scope);
|
|
903
|
+
else
|
|
904
|
+
leaveScope(scope);
|
|
905
|
+
}
|
|
906
|
+
usePatchesInScope(scope, patchListener);
|
|
907
|
+
return processResult(result, scope);
|
|
908
|
+
} else if (!base || typeof base !== "object") {
|
|
909
|
+
result = recipe(base);
|
|
910
|
+
if (result === void 0)
|
|
911
|
+
result = base;
|
|
912
|
+
if (result === NOTHING)
|
|
913
|
+
result = void 0;
|
|
914
|
+
if (this.autoFreeze_)
|
|
915
|
+
freeze(result, true);
|
|
916
|
+
if (patchListener) {
|
|
917
|
+
const p = [];
|
|
918
|
+
const ip = [];
|
|
919
|
+
getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
|
|
920
|
+
patchListener(p, ip);
|
|
921
|
+
}
|
|
922
|
+
return result;
|
|
923
|
+
} else
|
|
924
|
+
die(1, base);
|
|
925
|
+
};
|
|
926
|
+
this.produceWithPatches = (base, recipe) => {
|
|
927
|
+
if (typeof base === "function") {
|
|
928
|
+
return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
|
|
929
|
+
}
|
|
930
|
+
let patches, inversePatches;
|
|
931
|
+
const result = this.produce(base, recipe, (p, ip) => {
|
|
932
|
+
patches = p;
|
|
933
|
+
inversePatches = ip;
|
|
934
|
+
});
|
|
935
|
+
return [result, patches, inversePatches];
|
|
936
|
+
};
|
|
937
|
+
if (typeof config?.autoFreeze === "boolean")
|
|
938
|
+
this.setAutoFreeze(config.autoFreeze);
|
|
939
|
+
if (typeof config?.useStrictShallowCopy === "boolean")
|
|
940
|
+
this.setUseStrictShallowCopy(config.useStrictShallowCopy);
|
|
941
|
+
}
|
|
942
|
+
createDraft(base) {
|
|
943
|
+
if (!isDraftable(base))
|
|
944
|
+
die(8);
|
|
945
|
+
if (isDraft(base))
|
|
946
|
+
base = current(base);
|
|
947
|
+
const scope = enterScope(this);
|
|
948
|
+
const proxy = createProxy(base, void 0);
|
|
949
|
+
proxy[DRAFT_STATE].isManual_ = true;
|
|
950
|
+
leaveScope(scope);
|
|
951
|
+
return proxy;
|
|
952
|
+
}
|
|
953
|
+
finishDraft(draft, patchListener) {
|
|
954
|
+
const state = draft && draft[DRAFT_STATE];
|
|
955
|
+
if (!state || !state.isManual_)
|
|
956
|
+
die(9);
|
|
957
|
+
const { scope_: scope } = state;
|
|
958
|
+
usePatchesInScope(scope, patchListener);
|
|
959
|
+
return processResult(void 0, scope);
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Pass true to automatically freeze all copies created by Immer.
|
|
963
|
+
*
|
|
964
|
+
* By default, auto-freezing is enabled.
|
|
965
|
+
*/
|
|
966
|
+
setAutoFreeze(value) {
|
|
967
|
+
this.autoFreeze_ = value;
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Pass true to enable strict shallow copy.
|
|
971
|
+
*
|
|
972
|
+
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
|
|
973
|
+
*/
|
|
974
|
+
setUseStrictShallowCopy(value) {
|
|
975
|
+
this.useStrictShallowCopy_ = value;
|
|
976
|
+
}
|
|
977
|
+
applyPatches(base, patches) {
|
|
978
|
+
let i;
|
|
979
|
+
for (i = patches.length - 1; i >= 0; i--) {
|
|
980
|
+
const patch = patches[i];
|
|
981
|
+
if (patch.path.length === 0 && patch.op === "replace") {
|
|
982
|
+
base = patch.value;
|
|
983
|
+
break;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
if (i > -1) {
|
|
987
|
+
patches = patches.slice(i + 1);
|
|
988
|
+
}
|
|
989
|
+
const applyPatchesImpl = getPlugin("Patches").applyPatches_;
|
|
990
|
+
if (isDraft(base)) {
|
|
991
|
+
return applyPatchesImpl(base, patches);
|
|
992
|
+
}
|
|
993
|
+
return this.produce(
|
|
994
|
+
base,
|
|
995
|
+
(draft) => applyPatchesImpl(draft, patches)
|
|
996
|
+
);
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
function createProxy(value, parent) {
|
|
1000
|
+
const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
|
|
1001
|
+
const scope = parent ? parent.scope_ : getCurrentScope();
|
|
1002
|
+
scope.drafts_.push(draft);
|
|
1003
|
+
return draft;
|
|
1004
|
+
}
|
|
1005
|
+
function current(value) {
|
|
1006
|
+
if (!isDraft(value))
|
|
1007
|
+
die(10, value);
|
|
1008
|
+
return currentImpl(value);
|
|
1009
|
+
}
|
|
1010
|
+
function currentImpl(value) {
|
|
1011
|
+
if (!isDraftable(value) || isFrozen(value))
|
|
1012
|
+
return value;
|
|
1013
|
+
const state = value[DRAFT_STATE];
|
|
1014
|
+
let copy;
|
|
1015
|
+
if (state) {
|
|
1016
|
+
if (!state.modified_)
|
|
1017
|
+
return state.base_;
|
|
1018
|
+
state.finalized_ = true;
|
|
1019
|
+
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
|
|
1020
|
+
} else {
|
|
1021
|
+
copy = shallowCopy(value, true);
|
|
1022
|
+
}
|
|
1023
|
+
each(copy, (key, childValue) => {
|
|
1024
|
+
set(copy, key, currentImpl(childValue));
|
|
1025
|
+
});
|
|
1026
|
+
if (state) {
|
|
1027
|
+
state.finalized_ = false;
|
|
1028
|
+
}
|
|
1029
|
+
return copy;
|
|
1030
|
+
}
|
|
1031
|
+
var immer = new Immer2();
|
|
1032
|
+
var produce = immer.produce;
|
|
1033
|
+
var produceWithPatches = immer.produceWithPatches.bind(
|
|
1034
|
+
immer
|
|
1035
|
+
);
|
|
1036
|
+
var setAutoFreeze = immer.setAutoFreeze.bind(immer);
|
|
1037
|
+
var setUseStrictShallowCopy = immer.setUseStrictShallowCopy.bind(immer);
|
|
1038
|
+
var applyPatches = immer.applyPatches.bind(immer);
|
|
1039
|
+
var createDraft = immer.createDraft.bind(immer);
|
|
1040
|
+
var finishDraft = immer.finishDraft.bind(immer);
|
|
1041
|
+
|
|
1042
|
+
// node_modules/@reduxjs/toolkit/dist/redux-toolkit.modern.mjs
|
|
1043
|
+
var createDraftSafeSelectorCreator = (...args) => {
|
|
1044
|
+
const createSelector2 = createSelectorCreator(...args);
|
|
1045
|
+
const createDraftSafeSelector2 = Object.assign((...args2) => {
|
|
1046
|
+
const selector = createSelector2(...args2);
|
|
1047
|
+
const wrappedSelector = (value, ...rest) => selector(isDraft(value) ? current(value) : value, ...rest);
|
|
1048
|
+
Object.assign(wrappedSelector, selector);
|
|
1049
|
+
return wrappedSelector;
|
|
1050
|
+
}, {
|
|
1051
|
+
withTypes: () => createDraftSafeSelector2
|
|
1052
|
+
});
|
|
1053
|
+
return createDraftSafeSelector2;
|
|
1054
|
+
};
|
|
1055
|
+
var createDraftSafeSelector = /* @__PURE__ */ createDraftSafeSelectorCreator(weakMapMemoize);
|
|
1056
|
+
var composeWithDevTools = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : function() {
|
|
1057
|
+
if (arguments.length === 0) return void 0;
|
|
1058
|
+
if (typeof arguments[0] === "object") return compose;
|
|
1059
|
+
return compose.apply(null, arguments);
|
|
1060
|
+
};
|
|
1061
|
+
var devToolsEnhancer = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ : function() {
|
|
1062
|
+
return function(noop3) {
|
|
1063
|
+
return noop3;
|
|
1064
|
+
};
|
|
1065
|
+
};
|
|
1066
|
+
var hasMatchFunction = (v) => {
|
|
1067
|
+
return v && typeof v.match === "function";
|
|
1068
|
+
};
|
|
1069
|
+
function createAction(type, prepareAction) {
|
|
1070
|
+
function actionCreator(...args) {
|
|
1071
|
+
if (prepareAction) {
|
|
1072
|
+
let prepared = prepareAction(...args);
|
|
1073
|
+
if (!prepared) {
|
|
1074
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(0) : "prepareAction did not return an object");
|
|
1075
|
+
}
|
|
1076
|
+
return {
|
|
1077
|
+
type,
|
|
1078
|
+
payload: prepared.payload,
|
|
1079
|
+
..."meta" in prepared && {
|
|
1080
|
+
meta: prepared.meta
|
|
1081
|
+
},
|
|
1082
|
+
..."error" in prepared && {
|
|
1083
|
+
error: prepared.error
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
return {
|
|
1088
|
+
type,
|
|
1089
|
+
payload: args[0]
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
actionCreator.toString = () => `${type}`;
|
|
1093
|
+
actionCreator.type = type;
|
|
1094
|
+
actionCreator.match = (action) => isAction(action) && action.type === type;
|
|
1095
|
+
return actionCreator;
|
|
1096
|
+
}
|
|
1097
|
+
function isFSA(action) {
|
|
1098
|
+
return isAction(action) && Object.keys(action).every(isValidKey);
|
|
1099
|
+
}
|
|
1100
|
+
function isValidKey(key) {
|
|
1101
|
+
return ["type", "payload", "error", "meta"].indexOf(key) > -1;
|
|
1102
|
+
}
|
|
1103
|
+
function freezeDraftable(val) {
|
|
1104
|
+
return isDraftable(val) ? produce(val, () => {
|
|
1105
|
+
}) : val;
|
|
1106
|
+
}
|
|
1107
|
+
function getOrInsertComputed(map, key, compute) {
|
|
1108
|
+
if (map.has(key)) return map.get(key);
|
|
1109
|
+
return map.set(key, compute(key)).get(key);
|
|
1110
|
+
}
|
|
1111
|
+
function executeReducerBuilderCallback(builderCallback) {
|
|
1112
|
+
const actionsMap = {};
|
|
1113
|
+
const actionMatchers = [];
|
|
1114
|
+
let defaultCaseReducer;
|
|
1115
|
+
const builder = {
|
|
1116
|
+
addCase(typeOrActionCreator, reducer) {
|
|
1117
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1118
|
+
if (actionMatchers.length > 0) {
|
|
1119
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(26) : "`builder.addCase` should only be called before calling `builder.addMatcher`");
|
|
1120
|
+
}
|
|
1121
|
+
if (defaultCaseReducer) {
|
|
1122
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(27) : "`builder.addCase` should only be called before calling `builder.addDefaultCase`");
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
const type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
|
|
1126
|
+
if (!type) {
|
|
1127
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(28) : "`builder.addCase` cannot be called with an empty action type");
|
|
1128
|
+
}
|
|
1129
|
+
if (type in actionsMap) {
|
|
1130
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(29) : `\`builder.addCase\` cannot be called with two reducers for the same action type '${type}'`);
|
|
1131
|
+
}
|
|
1132
|
+
actionsMap[type] = reducer;
|
|
1133
|
+
return builder;
|
|
1134
|
+
},
|
|
1135
|
+
addMatcher(matcher, reducer) {
|
|
1136
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1137
|
+
if (defaultCaseReducer) {
|
|
1138
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(30) : "`builder.addMatcher` should only be called before calling `builder.addDefaultCase`");
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
actionMatchers.push({
|
|
1142
|
+
matcher,
|
|
1143
|
+
reducer
|
|
1144
|
+
});
|
|
1145
|
+
return builder;
|
|
1146
|
+
},
|
|
1147
|
+
addDefaultCase(reducer) {
|
|
1148
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1149
|
+
if (defaultCaseReducer) {
|
|
1150
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(31) : "`builder.addDefaultCase` can only be called once");
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
defaultCaseReducer = reducer;
|
|
1154
|
+
return builder;
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
builderCallback(builder);
|
|
1158
|
+
return [actionsMap, actionMatchers, defaultCaseReducer];
|
|
1159
|
+
}
|
|
1160
|
+
function isStateFunction(x) {
|
|
1161
|
+
return typeof x === "function";
|
|
1162
|
+
}
|
|
1163
|
+
function createReducer(initialState, mapOrBuilderCallback) {
|
|
1164
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1165
|
+
if (typeof mapOrBuilderCallback === "object") {
|
|
1166
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(8) : "The object notation for `createReducer` has been removed. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createReducer");
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
let [actionsMap, finalActionMatchers, finalDefaultCaseReducer] = executeReducerBuilderCallback(mapOrBuilderCallback);
|
|
1170
|
+
let getInitialState;
|
|
1171
|
+
if (isStateFunction(initialState)) {
|
|
1172
|
+
getInitialState = () => freezeDraftable(initialState());
|
|
1173
|
+
} else {
|
|
1174
|
+
const frozenInitialState = freezeDraftable(initialState);
|
|
1175
|
+
getInitialState = () => frozenInitialState;
|
|
1176
|
+
}
|
|
1177
|
+
function reducer(state = getInitialState(), action) {
|
|
1178
|
+
let caseReducers = [actionsMap[action.type], ...finalActionMatchers.filter(({
|
|
1179
|
+
matcher
|
|
1180
|
+
}) => matcher(action)).map(({
|
|
1181
|
+
reducer: reducer2
|
|
1182
|
+
}) => reducer2)];
|
|
1183
|
+
if (caseReducers.filter((cr) => !!cr).length === 0) {
|
|
1184
|
+
caseReducers = [finalDefaultCaseReducer];
|
|
1185
|
+
}
|
|
1186
|
+
return caseReducers.reduce((previousState, caseReducer) => {
|
|
1187
|
+
if (caseReducer) {
|
|
1188
|
+
if (isDraft(previousState)) {
|
|
1189
|
+
const draft = previousState;
|
|
1190
|
+
const result = caseReducer(draft, action);
|
|
1191
|
+
if (result === void 0) {
|
|
1192
|
+
return previousState;
|
|
1193
|
+
}
|
|
1194
|
+
return result;
|
|
1195
|
+
} else if (!isDraftable(previousState)) {
|
|
1196
|
+
const result = caseReducer(previousState, action);
|
|
1197
|
+
if (result === void 0) {
|
|
1198
|
+
if (previousState === null) {
|
|
1199
|
+
return previousState;
|
|
1200
|
+
}
|
|
1201
|
+
throw Error("A case reducer on a non-draftable value must not return undefined");
|
|
1202
|
+
}
|
|
1203
|
+
return result;
|
|
1204
|
+
} else {
|
|
1205
|
+
return produce(previousState, (draft) => {
|
|
1206
|
+
return caseReducer(draft, action);
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
return previousState;
|
|
1211
|
+
}, state);
|
|
1212
|
+
}
|
|
1213
|
+
reducer.getInitialState = getInitialState;
|
|
1214
|
+
return reducer;
|
|
1215
|
+
}
|
|
1216
|
+
var matches = (matcher, action) => {
|
|
1217
|
+
if (hasMatchFunction(matcher)) {
|
|
1218
|
+
return matcher.match(action);
|
|
1219
|
+
} else {
|
|
1220
|
+
return matcher(action);
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
function isAnyOf(...matchers) {
|
|
1224
|
+
return (action) => {
|
|
1225
|
+
return matchers.some((matcher) => matches(matcher, action));
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
var urlAlphabet = "ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW";
|
|
1229
|
+
var nanoid = (size = 21) => {
|
|
1230
|
+
let id = "";
|
|
1231
|
+
let i = size;
|
|
1232
|
+
while (i--) {
|
|
1233
|
+
id += urlAlphabet[Math.random() * 64 | 0];
|
|
1234
|
+
}
|
|
1235
|
+
return id;
|
|
1236
|
+
};
|
|
1237
|
+
var commonProperties = ["name", "message", "stack", "code"];
|
|
1238
|
+
var RejectWithValue = class {
|
|
1239
|
+
constructor(payload, meta) {
|
|
1240
|
+
this.payload = payload;
|
|
1241
|
+
this.meta = meta;
|
|
1242
|
+
}
|
|
1243
|
+
/*
|
|
1244
|
+
type-only property to distinguish between RejectWithValue and FulfillWithMeta
|
|
1245
|
+
does not exist at runtime
|
|
1246
|
+
*/
|
|
1247
|
+
_type;
|
|
1248
|
+
};
|
|
1249
|
+
var FulfillWithMeta = class {
|
|
1250
|
+
constructor(payload, meta) {
|
|
1251
|
+
this.payload = payload;
|
|
1252
|
+
this.meta = meta;
|
|
1253
|
+
}
|
|
1254
|
+
/*
|
|
1255
|
+
type-only property to distinguish between RejectWithValue and FulfillWithMeta
|
|
1256
|
+
does not exist at runtime
|
|
1257
|
+
*/
|
|
1258
|
+
_type;
|
|
1259
|
+
};
|
|
1260
|
+
var miniSerializeError = (value) => {
|
|
1261
|
+
if (typeof value === "object" && value !== null) {
|
|
1262
|
+
const simpleError = {};
|
|
1263
|
+
for (const property of commonProperties) {
|
|
1264
|
+
if (typeof value[property] === "string") {
|
|
1265
|
+
simpleError[property] = value[property];
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
return simpleError;
|
|
1269
|
+
}
|
|
1270
|
+
return {
|
|
1271
|
+
message: String(value)
|
|
1272
|
+
};
|
|
1273
|
+
};
|
|
1274
|
+
var createAsyncThunk = /* @__PURE__ */ (() => {
|
|
1275
|
+
function createAsyncThunk2(typePrefix, payloadCreator, options) {
|
|
1276
|
+
const fulfilled = createAction(typePrefix + "/fulfilled", (payload, requestId, arg, meta) => ({
|
|
1277
|
+
payload,
|
|
1278
|
+
meta: {
|
|
1279
|
+
...meta || {},
|
|
1280
|
+
arg,
|
|
1281
|
+
requestId,
|
|
1282
|
+
requestStatus: "fulfilled"
|
|
1283
|
+
}
|
|
1284
|
+
}));
|
|
1285
|
+
const pending = createAction(typePrefix + "/pending", (requestId, arg, meta) => ({
|
|
1286
|
+
payload: void 0,
|
|
1287
|
+
meta: {
|
|
1288
|
+
...meta || {},
|
|
1289
|
+
arg,
|
|
1290
|
+
requestId,
|
|
1291
|
+
requestStatus: "pending"
|
|
1292
|
+
}
|
|
1293
|
+
}));
|
|
1294
|
+
const rejected = createAction(typePrefix + "/rejected", (error, requestId, arg, payload, meta) => ({
|
|
1295
|
+
payload,
|
|
1296
|
+
error: (options && options.serializeError || miniSerializeError)(error || "Rejected"),
|
|
1297
|
+
meta: {
|
|
1298
|
+
...meta || {},
|
|
1299
|
+
arg,
|
|
1300
|
+
requestId,
|
|
1301
|
+
rejectedWithValue: !!payload,
|
|
1302
|
+
requestStatus: "rejected",
|
|
1303
|
+
aborted: error?.name === "AbortError",
|
|
1304
|
+
condition: error?.name === "ConditionError"
|
|
1305
|
+
}
|
|
1306
|
+
}));
|
|
1307
|
+
function actionCreator(arg) {
|
|
1308
|
+
return (dispatch, getState, extra) => {
|
|
1309
|
+
const requestId = options?.idGenerator ? options.idGenerator(arg) : nanoid();
|
|
1310
|
+
const abortController = new AbortController();
|
|
1311
|
+
let abortHandler;
|
|
1312
|
+
let abortReason;
|
|
1313
|
+
function abort(reason) {
|
|
1314
|
+
abortReason = reason;
|
|
1315
|
+
abortController.abort();
|
|
1316
|
+
}
|
|
1317
|
+
const promise = async function() {
|
|
1318
|
+
let finalAction;
|
|
1319
|
+
try {
|
|
1320
|
+
let conditionResult = options?.condition?.(arg, {
|
|
1321
|
+
getState,
|
|
1322
|
+
extra
|
|
1323
|
+
});
|
|
1324
|
+
if (isThenable(conditionResult)) {
|
|
1325
|
+
conditionResult = await conditionResult;
|
|
1326
|
+
}
|
|
1327
|
+
if (conditionResult === false || abortController.signal.aborted) {
|
|
1328
|
+
throw {
|
|
1329
|
+
name: "ConditionError",
|
|
1330
|
+
message: "Aborted due to condition callback returning false."
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
const abortedPromise = new Promise((_, reject) => {
|
|
1334
|
+
abortHandler = () => {
|
|
1335
|
+
reject({
|
|
1336
|
+
name: "AbortError",
|
|
1337
|
+
message: abortReason || "Aborted"
|
|
1338
|
+
});
|
|
1339
|
+
};
|
|
1340
|
+
abortController.signal.addEventListener("abort", abortHandler);
|
|
1341
|
+
});
|
|
1342
|
+
dispatch(pending(requestId, arg, options?.getPendingMeta?.({
|
|
1343
|
+
requestId,
|
|
1344
|
+
arg
|
|
1345
|
+
}, {
|
|
1346
|
+
getState,
|
|
1347
|
+
extra
|
|
1348
|
+
})));
|
|
1349
|
+
finalAction = await Promise.race([abortedPromise, Promise.resolve(payloadCreator(arg, {
|
|
1350
|
+
dispatch,
|
|
1351
|
+
getState,
|
|
1352
|
+
extra,
|
|
1353
|
+
requestId,
|
|
1354
|
+
signal: abortController.signal,
|
|
1355
|
+
abort,
|
|
1356
|
+
rejectWithValue: (value, meta) => {
|
|
1357
|
+
return new RejectWithValue(value, meta);
|
|
1358
|
+
},
|
|
1359
|
+
fulfillWithValue: (value, meta) => {
|
|
1360
|
+
return new FulfillWithMeta(value, meta);
|
|
1361
|
+
}
|
|
1362
|
+
})).then((result) => {
|
|
1363
|
+
if (result instanceof RejectWithValue) {
|
|
1364
|
+
throw result;
|
|
1365
|
+
}
|
|
1366
|
+
if (result instanceof FulfillWithMeta) {
|
|
1367
|
+
return fulfilled(result.payload, requestId, arg, result.meta);
|
|
1368
|
+
}
|
|
1369
|
+
return fulfilled(result, requestId, arg);
|
|
1370
|
+
})]);
|
|
1371
|
+
} catch (err) {
|
|
1372
|
+
finalAction = err instanceof RejectWithValue ? rejected(null, requestId, arg, err.payload, err.meta) : rejected(err, requestId, arg);
|
|
1373
|
+
} finally {
|
|
1374
|
+
if (abortHandler) {
|
|
1375
|
+
abortController.signal.removeEventListener("abort", abortHandler);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
const skipDispatch = options && !options.dispatchConditionRejection && rejected.match(finalAction) && finalAction.meta.condition;
|
|
1379
|
+
if (!skipDispatch) {
|
|
1380
|
+
dispatch(finalAction);
|
|
1381
|
+
}
|
|
1382
|
+
return finalAction;
|
|
1383
|
+
}();
|
|
1384
|
+
return Object.assign(promise, {
|
|
1385
|
+
abort,
|
|
1386
|
+
requestId,
|
|
1387
|
+
arg,
|
|
1388
|
+
unwrap() {
|
|
1389
|
+
return promise.then(unwrapResult);
|
|
1390
|
+
}
|
|
1391
|
+
});
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
return Object.assign(actionCreator, {
|
|
1395
|
+
pending,
|
|
1396
|
+
rejected,
|
|
1397
|
+
fulfilled,
|
|
1398
|
+
settled: isAnyOf(rejected, fulfilled),
|
|
1399
|
+
typePrefix
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
createAsyncThunk2.withTypes = () => createAsyncThunk2;
|
|
1403
|
+
return createAsyncThunk2;
|
|
1404
|
+
})();
|
|
1405
|
+
function unwrapResult(action) {
|
|
1406
|
+
if (action.meta && action.meta.rejectedWithValue) {
|
|
1407
|
+
throw action.payload;
|
|
1408
|
+
}
|
|
1409
|
+
if (action.error) {
|
|
1410
|
+
throw action.error;
|
|
1411
|
+
}
|
|
1412
|
+
return action.payload;
|
|
1413
|
+
}
|
|
1414
|
+
function isThenable(value) {
|
|
1415
|
+
return value !== null && typeof value === "object" && typeof value.then === "function";
|
|
1416
|
+
}
|
|
1417
|
+
var asyncThunkSymbol = /* @__PURE__ */ Symbol.for("rtk-slice-createasyncthunk");
|
|
1418
|
+
var asyncThunkCreator = {
|
|
1419
|
+
[asyncThunkSymbol]: createAsyncThunk
|
|
1420
|
+
};
|
|
1421
|
+
function getType(slice, actionKey) {
|
|
1422
|
+
return `${slice}/${actionKey}`;
|
|
1423
|
+
}
|
|
1424
|
+
function buildCreateSlice({
|
|
1425
|
+
creators
|
|
1426
|
+
} = {}) {
|
|
1427
|
+
const cAT = creators?.asyncThunk?.[asyncThunkSymbol];
|
|
1428
|
+
return function createSlice2(options) {
|
|
1429
|
+
const {
|
|
1430
|
+
name,
|
|
1431
|
+
reducerPath = name
|
|
1432
|
+
} = options;
|
|
1433
|
+
if (!name) {
|
|
1434
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(11) : "`name` is a required option for createSlice");
|
|
1435
|
+
}
|
|
1436
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|
1437
|
+
if (options.initialState === void 0) {
|
|
1438
|
+
console.error("You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`");
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
const reducers = (typeof options.reducers === "function" ? options.reducers(buildReducerCreators()) : options.reducers) || {};
|
|
1442
|
+
const reducerNames = Object.keys(reducers);
|
|
1443
|
+
const context = {
|
|
1444
|
+
sliceCaseReducersByName: {},
|
|
1445
|
+
sliceCaseReducersByType: {},
|
|
1446
|
+
actionCreators: {},
|
|
1447
|
+
sliceMatchers: []
|
|
1448
|
+
};
|
|
1449
|
+
const contextMethods = {
|
|
1450
|
+
addCase(typeOrActionCreator, reducer2) {
|
|
1451
|
+
const type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
|
|
1452
|
+
if (!type) {
|
|
1453
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(12) : "`context.addCase` cannot be called with an empty action type");
|
|
1454
|
+
}
|
|
1455
|
+
if (type in context.sliceCaseReducersByType) {
|
|
1456
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(13) : "`context.addCase` cannot be called with two reducers for the same action type: " + type);
|
|
1457
|
+
}
|
|
1458
|
+
context.sliceCaseReducersByType[type] = reducer2;
|
|
1459
|
+
return contextMethods;
|
|
1460
|
+
},
|
|
1461
|
+
addMatcher(matcher, reducer2) {
|
|
1462
|
+
context.sliceMatchers.push({
|
|
1463
|
+
matcher,
|
|
1464
|
+
reducer: reducer2
|
|
1465
|
+
});
|
|
1466
|
+
return contextMethods;
|
|
1467
|
+
},
|
|
1468
|
+
exposeAction(name2, actionCreator) {
|
|
1469
|
+
context.actionCreators[name2] = actionCreator;
|
|
1470
|
+
return contextMethods;
|
|
1471
|
+
},
|
|
1472
|
+
exposeCaseReducer(name2, reducer2) {
|
|
1473
|
+
context.sliceCaseReducersByName[name2] = reducer2;
|
|
1474
|
+
return contextMethods;
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
reducerNames.forEach((reducerName) => {
|
|
1478
|
+
const reducerDefinition = reducers[reducerName];
|
|
1479
|
+
const reducerDetails = {
|
|
1480
|
+
reducerName,
|
|
1481
|
+
type: getType(name, reducerName),
|
|
1482
|
+
createNotation: typeof options.reducers === "function"
|
|
1483
|
+
};
|
|
1484
|
+
if (isAsyncThunkSliceReducerDefinition(reducerDefinition)) {
|
|
1485
|
+
handleThunkCaseReducerDefinition(reducerDetails, reducerDefinition, contextMethods, cAT);
|
|
1486
|
+
} else {
|
|
1487
|
+
handleNormalReducerDefinition(reducerDetails, reducerDefinition, contextMethods);
|
|
1488
|
+
}
|
|
1489
|
+
});
|
|
1490
|
+
function buildReducer() {
|
|
1491
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1492
|
+
if (typeof options.extraReducers === "object") {
|
|
1493
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(14) : "The object notation for `createSlice.extraReducers` has been removed. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createSlice");
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
const [extraReducers = {}, actionMatchers = [], defaultCaseReducer = void 0] = typeof options.extraReducers === "function" ? executeReducerBuilderCallback(options.extraReducers) : [options.extraReducers];
|
|
1497
|
+
const finalCaseReducers = {
|
|
1498
|
+
...extraReducers,
|
|
1499
|
+
...context.sliceCaseReducersByType
|
|
1500
|
+
};
|
|
1501
|
+
return createReducer(options.initialState, (builder) => {
|
|
1502
|
+
for (let key in finalCaseReducers) {
|
|
1503
|
+
builder.addCase(key, finalCaseReducers[key]);
|
|
1504
|
+
}
|
|
1505
|
+
for (let sM of context.sliceMatchers) {
|
|
1506
|
+
builder.addMatcher(sM.matcher, sM.reducer);
|
|
1507
|
+
}
|
|
1508
|
+
for (let m of actionMatchers) {
|
|
1509
|
+
builder.addMatcher(m.matcher, m.reducer);
|
|
1510
|
+
}
|
|
1511
|
+
if (defaultCaseReducer) {
|
|
1512
|
+
builder.addDefaultCase(defaultCaseReducer);
|
|
1513
|
+
}
|
|
1514
|
+
});
|
|
1515
|
+
}
|
|
1516
|
+
const selectSelf = (state) => state;
|
|
1517
|
+
const injectedSelectorCache = /* @__PURE__ */ new Map();
|
|
1518
|
+
let _reducer;
|
|
1519
|
+
function reducer(state, action) {
|
|
1520
|
+
if (!_reducer) _reducer = buildReducer();
|
|
1521
|
+
return _reducer(state, action);
|
|
1522
|
+
}
|
|
1523
|
+
function getInitialState() {
|
|
1524
|
+
if (!_reducer) _reducer = buildReducer();
|
|
1525
|
+
return _reducer.getInitialState();
|
|
1526
|
+
}
|
|
1527
|
+
function makeSelectorProps(reducerPath2, injected = false) {
|
|
1528
|
+
function selectSlice(state) {
|
|
1529
|
+
let sliceState = state[reducerPath2];
|
|
1530
|
+
if (typeof sliceState === "undefined") {
|
|
1531
|
+
if (injected) {
|
|
1532
|
+
sliceState = getInitialState();
|
|
1533
|
+
} else if (process.env.NODE_ENV !== "production") {
|
|
1534
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(15) : "selectSlice returned undefined for an uninjected slice reducer");
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
return sliceState;
|
|
1538
|
+
}
|
|
1539
|
+
function getSelectors(selectState = selectSelf) {
|
|
1540
|
+
const selectorCache = getOrInsertComputed(injectedSelectorCache, injected, () => /* @__PURE__ */ new WeakMap());
|
|
1541
|
+
return getOrInsertComputed(selectorCache, selectState, () => {
|
|
1542
|
+
const map = {};
|
|
1543
|
+
for (const [name2, selector] of Object.entries(options.selectors ?? {})) {
|
|
1544
|
+
map[name2] = wrapSelector(selector, selectState, getInitialState, injected);
|
|
1545
|
+
}
|
|
1546
|
+
return map;
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
return {
|
|
1550
|
+
reducerPath: reducerPath2,
|
|
1551
|
+
getSelectors,
|
|
1552
|
+
get selectors() {
|
|
1553
|
+
return getSelectors(selectSlice);
|
|
1554
|
+
},
|
|
1555
|
+
selectSlice
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
const slice = {
|
|
1559
|
+
name,
|
|
1560
|
+
reducer,
|
|
1561
|
+
actions: context.actionCreators,
|
|
1562
|
+
caseReducers: context.sliceCaseReducersByName,
|
|
1563
|
+
getInitialState,
|
|
1564
|
+
...makeSelectorProps(reducerPath),
|
|
1565
|
+
injectInto(injectable, {
|
|
1566
|
+
reducerPath: pathOpt,
|
|
1567
|
+
...config
|
|
1568
|
+
} = {}) {
|
|
1569
|
+
const newReducerPath = pathOpt ?? reducerPath;
|
|
1570
|
+
injectable.inject({
|
|
1571
|
+
reducerPath: newReducerPath,
|
|
1572
|
+
reducer
|
|
1573
|
+
}, config);
|
|
1574
|
+
return {
|
|
1575
|
+
...slice,
|
|
1576
|
+
...makeSelectorProps(newReducerPath, true)
|
|
1577
|
+
};
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1580
|
+
return slice;
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
function wrapSelector(selector, selectState, getInitialState, injected) {
|
|
1584
|
+
function wrapper(rootState, ...args) {
|
|
1585
|
+
let sliceState = selectState(rootState);
|
|
1586
|
+
if (typeof sliceState === "undefined") {
|
|
1587
|
+
if (injected) {
|
|
1588
|
+
sliceState = getInitialState();
|
|
1589
|
+
} else if (process.env.NODE_ENV !== "production") {
|
|
1590
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(16) : "selectState returned undefined for an uninjected slice reducer");
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
return selector(sliceState, ...args);
|
|
1594
|
+
}
|
|
1595
|
+
wrapper.unwrapped = selector;
|
|
1596
|
+
return wrapper;
|
|
1597
|
+
}
|
|
1598
|
+
function buildReducerCreators() {
|
|
1599
|
+
function asyncThunk(payloadCreator, config) {
|
|
1600
|
+
return {
|
|
1601
|
+
_reducerDefinitionType: "asyncThunk",
|
|
1602
|
+
payloadCreator,
|
|
1603
|
+
...config
|
|
1604
|
+
};
|
|
1605
|
+
}
|
|
1606
|
+
asyncThunk.withTypes = () => asyncThunk;
|
|
1607
|
+
return {
|
|
1608
|
+
reducer(caseReducer) {
|
|
1609
|
+
return Object.assign({
|
|
1610
|
+
// hack so the wrapping function has the same name as the original
|
|
1611
|
+
// we need to create a wrapper so the `reducerDefinitionType` is not assigned to the original
|
|
1612
|
+
[caseReducer.name](...args) {
|
|
1613
|
+
return caseReducer(...args);
|
|
1614
|
+
}
|
|
1615
|
+
}[caseReducer.name], {
|
|
1616
|
+
_reducerDefinitionType: "reducer"
|
|
1617
|
+
/* reducer */
|
|
1618
|
+
});
|
|
1619
|
+
},
|
|
1620
|
+
preparedReducer(prepare, reducer) {
|
|
1621
|
+
return {
|
|
1622
|
+
_reducerDefinitionType: "reducerWithPrepare",
|
|
1623
|
+
prepare,
|
|
1624
|
+
reducer
|
|
1625
|
+
};
|
|
1626
|
+
},
|
|
1627
|
+
asyncThunk
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1630
|
+
function handleNormalReducerDefinition({
|
|
1631
|
+
type,
|
|
1632
|
+
reducerName,
|
|
1633
|
+
createNotation
|
|
1634
|
+
}, maybeReducerWithPrepare, context) {
|
|
1635
|
+
let caseReducer;
|
|
1636
|
+
let prepareCallback;
|
|
1637
|
+
if ("reducer" in maybeReducerWithPrepare) {
|
|
1638
|
+
if (createNotation && !isCaseReducerWithPrepareDefinition(maybeReducerWithPrepare)) {
|
|
1639
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(17) : "Please use the `create.preparedReducer` notation for prepared action creators with the `create` notation.");
|
|
1640
|
+
}
|
|
1641
|
+
caseReducer = maybeReducerWithPrepare.reducer;
|
|
1642
|
+
prepareCallback = maybeReducerWithPrepare.prepare;
|
|
1643
|
+
} else {
|
|
1644
|
+
caseReducer = maybeReducerWithPrepare;
|
|
1645
|
+
}
|
|
1646
|
+
context.addCase(type, caseReducer).exposeCaseReducer(reducerName, caseReducer).exposeAction(reducerName, prepareCallback ? createAction(type, prepareCallback) : createAction(type));
|
|
1647
|
+
}
|
|
1648
|
+
function isAsyncThunkSliceReducerDefinition(reducerDefinition) {
|
|
1649
|
+
return reducerDefinition._reducerDefinitionType === "asyncThunk";
|
|
1650
|
+
}
|
|
1651
|
+
function isCaseReducerWithPrepareDefinition(reducerDefinition) {
|
|
1652
|
+
return reducerDefinition._reducerDefinitionType === "reducerWithPrepare";
|
|
1653
|
+
}
|
|
1654
|
+
function handleThunkCaseReducerDefinition({
|
|
1655
|
+
type,
|
|
1656
|
+
reducerName
|
|
1657
|
+
}, reducerDefinition, context, cAT) {
|
|
1658
|
+
if (!cAT) {
|
|
1659
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(18) : "Cannot use `create.asyncThunk` in the built-in `createSlice`. Use `buildCreateSlice({ creators: { asyncThunk: asyncThunkCreator } })` to create a customised version of `createSlice`.");
|
|
1660
|
+
}
|
|
1661
|
+
const {
|
|
1662
|
+
payloadCreator,
|
|
1663
|
+
fulfilled,
|
|
1664
|
+
pending,
|
|
1665
|
+
rejected,
|
|
1666
|
+
settled,
|
|
1667
|
+
options
|
|
1668
|
+
} = reducerDefinition;
|
|
1669
|
+
const thunk = cAT(type, payloadCreator, options);
|
|
1670
|
+
context.exposeAction(reducerName, thunk);
|
|
1671
|
+
if (fulfilled) {
|
|
1672
|
+
context.addCase(thunk.fulfilled, fulfilled);
|
|
1673
|
+
}
|
|
1674
|
+
if (pending) {
|
|
1675
|
+
context.addCase(thunk.pending, pending);
|
|
1676
|
+
}
|
|
1677
|
+
if (rejected) {
|
|
1678
|
+
context.addCase(thunk.rejected, rejected);
|
|
1679
|
+
}
|
|
1680
|
+
if (settled) {
|
|
1681
|
+
context.addMatcher(thunk.settled, settled);
|
|
1682
|
+
}
|
|
1683
|
+
context.exposeCaseReducer(reducerName, {
|
|
1684
|
+
fulfilled: fulfilled || noop,
|
|
1685
|
+
pending: pending || noop,
|
|
1686
|
+
rejected: rejected || noop,
|
|
1687
|
+
settled: settled || noop
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
function noop() {
|
|
1691
|
+
}
|
|
1692
|
+
function getInitialEntityState() {
|
|
1693
|
+
return {
|
|
1694
|
+
ids: [],
|
|
1695
|
+
entities: {}
|
|
1696
|
+
};
|
|
1697
|
+
}
|
|
1698
|
+
function createInitialStateFactory(stateAdapter) {
|
|
1699
|
+
function getInitialState(additionalState = {}, entities) {
|
|
1700
|
+
const state = Object.assign(getInitialEntityState(), additionalState);
|
|
1701
|
+
return entities ? stateAdapter.setAll(state, entities) : state;
|
|
1702
|
+
}
|
|
1703
|
+
return {
|
|
1704
|
+
getInitialState
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
function createSelectorsFactory() {
|
|
1708
|
+
function getSelectors(selectState, options = {}) {
|
|
1709
|
+
const {
|
|
1710
|
+
createSelector: createSelector2 = createDraftSafeSelector
|
|
1711
|
+
} = options;
|
|
1712
|
+
const selectIds = (state) => state.ids;
|
|
1713
|
+
const selectEntities = (state) => state.entities;
|
|
1714
|
+
const selectAll = createSelector2(selectIds, selectEntities, (ids, entities) => ids.map((id) => entities[id]));
|
|
1715
|
+
const selectId = (_, id) => id;
|
|
1716
|
+
const selectById = (entities, id) => entities[id];
|
|
1717
|
+
const selectTotal = createSelector2(selectIds, (ids) => ids.length);
|
|
1718
|
+
if (!selectState) {
|
|
1719
|
+
return {
|
|
1720
|
+
selectIds,
|
|
1721
|
+
selectEntities,
|
|
1722
|
+
selectAll,
|
|
1723
|
+
selectTotal,
|
|
1724
|
+
selectById: createSelector2(selectEntities, selectId, selectById)
|
|
1725
|
+
};
|
|
1726
|
+
}
|
|
1727
|
+
const selectGlobalizedEntities = createSelector2(selectState, selectEntities);
|
|
1728
|
+
return {
|
|
1729
|
+
selectIds: createSelector2(selectState, selectIds),
|
|
1730
|
+
selectEntities: selectGlobalizedEntities,
|
|
1731
|
+
selectAll: createSelector2(selectState, selectAll),
|
|
1732
|
+
selectTotal: createSelector2(selectState, selectTotal),
|
|
1733
|
+
selectById: createSelector2(selectGlobalizedEntities, selectId, selectById)
|
|
1734
|
+
};
|
|
1735
|
+
}
|
|
1736
|
+
return {
|
|
1737
|
+
getSelectors
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
var isDraftTyped = isDraft;
|
|
1741
|
+
function createSingleArgumentStateOperator(mutator) {
|
|
1742
|
+
const operator = createStateOperator((_, state) => mutator(state));
|
|
1743
|
+
return function operation(state) {
|
|
1744
|
+
return operator(state, void 0);
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
function createStateOperator(mutator) {
|
|
1748
|
+
return function operation(state, arg) {
|
|
1749
|
+
function isPayloadActionArgument(arg2) {
|
|
1750
|
+
return isFSA(arg2);
|
|
1751
|
+
}
|
|
1752
|
+
const runMutator = (draft) => {
|
|
1753
|
+
if (isPayloadActionArgument(arg)) {
|
|
1754
|
+
mutator(arg.payload, draft);
|
|
1755
|
+
} else {
|
|
1756
|
+
mutator(arg, draft);
|
|
1757
|
+
}
|
|
1758
|
+
};
|
|
1759
|
+
if (isDraftTyped(state)) {
|
|
1760
|
+
runMutator(state);
|
|
1761
|
+
return state;
|
|
1762
|
+
}
|
|
1763
|
+
return produce(state, runMutator);
|
|
1764
|
+
};
|
|
1765
|
+
}
|
|
1766
|
+
function selectIdValue(entity, selectId) {
|
|
1767
|
+
const key = selectId(entity);
|
|
1768
|
+
if (process.env.NODE_ENV !== "production" && key === void 0) {
|
|
1769
|
+
console.warn("The entity passed to the `selectId` implementation returned undefined.", "You should probably provide your own `selectId` implementation.", "The entity that was passed:", entity, "The `selectId` implementation:", selectId.toString());
|
|
1770
|
+
}
|
|
1771
|
+
return key;
|
|
1772
|
+
}
|
|
1773
|
+
function ensureEntitiesArray(entities) {
|
|
1774
|
+
if (!Array.isArray(entities)) {
|
|
1775
|
+
entities = Object.values(entities);
|
|
1776
|
+
}
|
|
1777
|
+
return entities;
|
|
1778
|
+
}
|
|
1779
|
+
function getCurrent(value) {
|
|
1780
|
+
return isDraft(value) ? current(value) : value;
|
|
1781
|
+
}
|
|
1782
|
+
function splitAddedUpdatedEntities(newEntities, selectId, state) {
|
|
1783
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1784
|
+
const existingIdsArray = getCurrent(state.ids);
|
|
1785
|
+
const existingIds = new Set(existingIdsArray);
|
|
1786
|
+
const added = [];
|
|
1787
|
+
const updated = [];
|
|
1788
|
+
for (const entity of newEntities) {
|
|
1789
|
+
const id = selectIdValue(entity, selectId);
|
|
1790
|
+
if (existingIds.has(id)) {
|
|
1791
|
+
updated.push({
|
|
1792
|
+
id,
|
|
1793
|
+
changes: entity
|
|
1794
|
+
});
|
|
1795
|
+
} else {
|
|
1796
|
+
added.push(entity);
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
return [added, updated, existingIdsArray];
|
|
1800
|
+
}
|
|
1801
|
+
function createUnsortedStateAdapter(selectId) {
|
|
1802
|
+
function addOneMutably(entity, state) {
|
|
1803
|
+
const key = selectIdValue(entity, selectId);
|
|
1804
|
+
if (key in state.entities) {
|
|
1805
|
+
return;
|
|
1806
|
+
}
|
|
1807
|
+
state.ids.push(key);
|
|
1808
|
+
state.entities[key] = entity;
|
|
1809
|
+
}
|
|
1810
|
+
function addManyMutably(newEntities, state) {
|
|
1811
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1812
|
+
for (const entity of newEntities) {
|
|
1813
|
+
addOneMutably(entity, state);
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
function setOneMutably(entity, state) {
|
|
1817
|
+
const key = selectIdValue(entity, selectId);
|
|
1818
|
+
if (!(key in state.entities)) {
|
|
1819
|
+
state.ids.push(key);
|
|
1820
|
+
}
|
|
1821
|
+
;
|
|
1822
|
+
state.entities[key] = entity;
|
|
1823
|
+
}
|
|
1824
|
+
function setManyMutably(newEntities, state) {
|
|
1825
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1826
|
+
for (const entity of newEntities) {
|
|
1827
|
+
setOneMutably(entity, state);
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
function setAllMutably(newEntities, state) {
|
|
1831
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1832
|
+
state.ids = [];
|
|
1833
|
+
state.entities = {};
|
|
1834
|
+
addManyMutably(newEntities, state);
|
|
1835
|
+
}
|
|
1836
|
+
function removeOneMutably(key, state) {
|
|
1837
|
+
return removeManyMutably([key], state);
|
|
1838
|
+
}
|
|
1839
|
+
function removeManyMutably(keys, state) {
|
|
1840
|
+
let didMutate = false;
|
|
1841
|
+
keys.forEach((key) => {
|
|
1842
|
+
if (key in state.entities) {
|
|
1843
|
+
delete state.entities[key];
|
|
1844
|
+
didMutate = true;
|
|
1845
|
+
}
|
|
1846
|
+
});
|
|
1847
|
+
if (didMutate) {
|
|
1848
|
+
state.ids = state.ids.filter((id) => id in state.entities);
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
function removeAllMutably(state) {
|
|
1852
|
+
Object.assign(state, {
|
|
1853
|
+
ids: [],
|
|
1854
|
+
entities: {}
|
|
1855
|
+
});
|
|
1856
|
+
}
|
|
1857
|
+
function takeNewKey(keys, update, state) {
|
|
1858
|
+
const original3 = state.entities[update.id];
|
|
1859
|
+
if (original3 === void 0) {
|
|
1860
|
+
return false;
|
|
1861
|
+
}
|
|
1862
|
+
const updated = Object.assign({}, original3, update.changes);
|
|
1863
|
+
const newKey = selectIdValue(updated, selectId);
|
|
1864
|
+
const hasNewKey = newKey !== update.id;
|
|
1865
|
+
if (hasNewKey) {
|
|
1866
|
+
keys[update.id] = newKey;
|
|
1867
|
+
delete state.entities[update.id];
|
|
1868
|
+
}
|
|
1869
|
+
;
|
|
1870
|
+
state.entities[newKey] = updated;
|
|
1871
|
+
return hasNewKey;
|
|
1872
|
+
}
|
|
1873
|
+
function updateOneMutably(update, state) {
|
|
1874
|
+
return updateManyMutably([update], state);
|
|
1875
|
+
}
|
|
1876
|
+
function updateManyMutably(updates, state) {
|
|
1877
|
+
const newKeys = {};
|
|
1878
|
+
const updatesPerEntity = {};
|
|
1879
|
+
updates.forEach((update) => {
|
|
1880
|
+
if (update.id in state.entities) {
|
|
1881
|
+
updatesPerEntity[update.id] = {
|
|
1882
|
+
id: update.id,
|
|
1883
|
+
// Spreads ignore falsy values, so this works even if there isn't
|
|
1884
|
+
// an existing update already at this key
|
|
1885
|
+
changes: {
|
|
1886
|
+
...updatesPerEntity[update.id]?.changes,
|
|
1887
|
+
...update.changes
|
|
1888
|
+
}
|
|
1889
|
+
};
|
|
1890
|
+
}
|
|
1891
|
+
});
|
|
1892
|
+
updates = Object.values(updatesPerEntity);
|
|
1893
|
+
const didMutateEntities = updates.length > 0;
|
|
1894
|
+
if (didMutateEntities) {
|
|
1895
|
+
const didMutateIds = updates.filter((update) => takeNewKey(newKeys, update, state)).length > 0;
|
|
1896
|
+
if (didMutateIds) {
|
|
1897
|
+
state.ids = Object.values(state.entities).map((e) => selectIdValue(e, selectId));
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
function upsertOneMutably(entity, state) {
|
|
1902
|
+
return upsertManyMutably([entity], state);
|
|
1903
|
+
}
|
|
1904
|
+
function upsertManyMutably(newEntities, state) {
|
|
1905
|
+
const [added, updated] = splitAddedUpdatedEntities(newEntities, selectId, state);
|
|
1906
|
+
updateManyMutably(updated, state);
|
|
1907
|
+
addManyMutably(added, state);
|
|
1908
|
+
}
|
|
1909
|
+
return {
|
|
1910
|
+
removeAll: createSingleArgumentStateOperator(removeAllMutably),
|
|
1911
|
+
addOne: createStateOperator(addOneMutably),
|
|
1912
|
+
addMany: createStateOperator(addManyMutably),
|
|
1913
|
+
setOne: createStateOperator(setOneMutably),
|
|
1914
|
+
setMany: createStateOperator(setManyMutably),
|
|
1915
|
+
setAll: createStateOperator(setAllMutably),
|
|
1916
|
+
updateOne: createStateOperator(updateOneMutably),
|
|
1917
|
+
updateMany: createStateOperator(updateManyMutably),
|
|
1918
|
+
upsertOne: createStateOperator(upsertOneMutably),
|
|
1919
|
+
upsertMany: createStateOperator(upsertManyMutably),
|
|
1920
|
+
removeOne: createStateOperator(removeOneMutably),
|
|
1921
|
+
removeMany: createStateOperator(removeManyMutably)
|
|
1922
|
+
};
|
|
1923
|
+
}
|
|
1924
|
+
function findInsertIndex(sortedItems, item, comparisonFunction) {
|
|
1925
|
+
let lowIndex = 0;
|
|
1926
|
+
let highIndex = sortedItems.length;
|
|
1927
|
+
while (lowIndex < highIndex) {
|
|
1928
|
+
let middleIndex = lowIndex + highIndex >>> 1;
|
|
1929
|
+
const currentItem = sortedItems[middleIndex];
|
|
1930
|
+
const res = comparisonFunction(item, currentItem);
|
|
1931
|
+
if (res >= 0) {
|
|
1932
|
+
lowIndex = middleIndex + 1;
|
|
1933
|
+
} else {
|
|
1934
|
+
highIndex = middleIndex;
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
return lowIndex;
|
|
1938
|
+
}
|
|
1939
|
+
function insert(sortedItems, item, comparisonFunction) {
|
|
1940
|
+
const insertAtIndex = findInsertIndex(sortedItems, item, comparisonFunction);
|
|
1941
|
+
sortedItems.splice(insertAtIndex, 0, item);
|
|
1942
|
+
return sortedItems;
|
|
1943
|
+
}
|
|
1944
|
+
function createSortedStateAdapter(selectId, comparer) {
|
|
1945
|
+
const {
|
|
1946
|
+
removeOne,
|
|
1947
|
+
removeMany,
|
|
1948
|
+
removeAll
|
|
1949
|
+
} = createUnsortedStateAdapter(selectId);
|
|
1950
|
+
function addOneMutably(entity, state) {
|
|
1951
|
+
return addManyMutably([entity], state);
|
|
1952
|
+
}
|
|
1953
|
+
function addManyMutably(newEntities, state, existingIds) {
|
|
1954
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1955
|
+
const existingKeys = new Set(existingIds ?? getCurrent(state.ids));
|
|
1956
|
+
const models = newEntities.filter((model) => !existingKeys.has(selectIdValue(model, selectId)));
|
|
1957
|
+
if (models.length !== 0) {
|
|
1958
|
+
mergeFunction(state, models);
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
function setOneMutably(entity, state) {
|
|
1962
|
+
return setManyMutably([entity], state);
|
|
1963
|
+
}
|
|
1964
|
+
function setManyMutably(newEntities, state) {
|
|
1965
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1966
|
+
if (newEntities.length !== 0) {
|
|
1967
|
+
for (const item of newEntities) {
|
|
1968
|
+
delete state.entities[selectId(item)];
|
|
1969
|
+
}
|
|
1970
|
+
mergeFunction(state, newEntities);
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
function setAllMutably(newEntities, state) {
|
|
1974
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1975
|
+
state.entities = {};
|
|
1976
|
+
state.ids = [];
|
|
1977
|
+
addManyMutably(newEntities, state, []);
|
|
1978
|
+
}
|
|
1979
|
+
function updateOneMutably(update, state) {
|
|
1980
|
+
return updateManyMutably([update], state);
|
|
1981
|
+
}
|
|
1982
|
+
function updateManyMutably(updates, state) {
|
|
1983
|
+
let appliedUpdates = false;
|
|
1984
|
+
let replacedIds = false;
|
|
1985
|
+
for (let update of updates) {
|
|
1986
|
+
const entity = state.entities[update.id];
|
|
1987
|
+
if (!entity) {
|
|
1988
|
+
continue;
|
|
1989
|
+
}
|
|
1990
|
+
appliedUpdates = true;
|
|
1991
|
+
Object.assign(entity, update.changes);
|
|
1992
|
+
const newId = selectId(entity);
|
|
1993
|
+
if (update.id !== newId) {
|
|
1994
|
+
replacedIds = true;
|
|
1995
|
+
delete state.entities[update.id];
|
|
1996
|
+
const oldIndex = state.ids.indexOf(update.id);
|
|
1997
|
+
state.ids[oldIndex] = newId;
|
|
1998
|
+
state.entities[newId] = entity;
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
if (appliedUpdates) {
|
|
2002
|
+
mergeFunction(state, [], appliedUpdates, replacedIds);
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
function upsertOneMutably(entity, state) {
|
|
2006
|
+
return upsertManyMutably([entity], state);
|
|
2007
|
+
}
|
|
2008
|
+
function upsertManyMutably(newEntities, state) {
|
|
2009
|
+
const [added, updated, existingIdsArray] = splitAddedUpdatedEntities(newEntities, selectId, state);
|
|
2010
|
+
if (updated.length) {
|
|
2011
|
+
updateManyMutably(updated, state);
|
|
2012
|
+
}
|
|
2013
|
+
if (added.length) {
|
|
2014
|
+
addManyMutably(added, state, existingIdsArray);
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
function areArraysEqual(a, b) {
|
|
2018
|
+
if (a.length !== b.length) {
|
|
2019
|
+
return false;
|
|
2020
|
+
}
|
|
2021
|
+
for (let i = 0; i < a.length; i++) {
|
|
2022
|
+
if (a[i] === b[i]) {
|
|
2023
|
+
continue;
|
|
2024
|
+
}
|
|
2025
|
+
return false;
|
|
2026
|
+
}
|
|
2027
|
+
return true;
|
|
2028
|
+
}
|
|
2029
|
+
const mergeFunction = (state, addedItems, appliedUpdates, replacedIds) => {
|
|
2030
|
+
const currentEntities = getCurrent(state.entities);
|
|
2031
|
+
const currentIds = getCurrent(state.ids);
|
|
2032
|
+
const stateEntities = state.entities;
|
|
2033
|
+
let ids = currentIds;
|
|
2034
|
+
if (replacedIds) {
|
|
2035
|
+
ids = new Set(currentIds);
|
|
2036
|
+
}
|
|
2037
|
+
let sortedEntities = [];
|
|
2038
|
+
for (const id of ids) {
|
|
2039
|
+
const entity = currentEntities[id];
|
|
2040
|
+
if (entity) {
|
|
2041
|
+
sortedEntities.push(entity);
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
const wasPreviouslyEmpty = sortedEntities.length === 0;
|
|
2045
|
+
for (const item of addedItems) {
|
|
2046
|
+
stateEntities[selectId(item)] = item;
|
|
2047
|
+
if (!wasPreviouslyEmpty) {
|
|
2048
|
+
insert(sortedEntities, item, comparer);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
if (wasPreviouslyEmpty) {
|
|
2052
|
+
sortedEntities = addedItems.slice().sort(comparer);
|
|
2053
|
+
} else if (appliedUpdates) {
|
|
2054
|
+
sortedEntities.sort(comparer);
|
|
2055
|
+
}
|
|
2056
|
+
const newSortedIds = sortedEntities.map(selectId);
|
|
2057
|
+
if (!areArraysEqual(currentIds, newSortedIds)) {
|
|
2058
|
+
state.ids = newSortedIds;
|
|
2059
|
+
}
|
|
2060
|
+
};
|
|
2061
|
+
return {
|
|
2062
|
+
removeOne,
|
|
2063
|
+
removeMany,
|
|
2064
|
+
removeAll,
|
|
2065
|
+
addOne: createStateOperator(addOneMutably),
|
|
2066
|
+
updateOne: createStateOperator(updateOneMutably),
|
|
2067
|
+
upsertOne: createStateOperator(upsertOneMutably),
|
|
2068
|
+
setOne: createStateOperator(setOneMutably),
|
|
2069
|
+
setMany: createStateOperator(setManyMutably),
|
|
2070
|
+
setAll: createStateOperator(setAllMutably),
|
|
2071
|
+
addMany: createStateOperator(addManyMutably),
|
|
2072
|
+
updateMany: createStateOperator(updateManyMutably),
|
|
2073
|
+
upsertMany: createStateOperator(upsertManyMutably)
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2076
|
+
function createEntityAdapter(options = {}) {
|
|
2077
|
+
const {
|
|
2078
|
+
selectId,
|
|
2079
|
+
sortComparer
|
|
2080
|
+
} = {
|
|
2081
|
+
sortComparer: false,
|
|
2082
|
+
selectId: (instance) => instance.id,
|
|
2083
|
+
...options
|
|
2084
|
+
};
|
|
2085
|
+
const stateAdapter = sortComparer ? createSortedStateAdapter(selectId, sortComparer) : createUnsortedStateAdapter(selectId);
|
|
2086
|
+
const stateFactory = createInitialStateFactory(stateAdapter);
|
|
2087
|
+
const selectorsFactory = createSelectorsFactory();
|
|
2088
|
+
return {
|
|
2089
|
+
selectId,
|
|
2090
|
+
sortComparer,
|
|
2091
|
+
...stateFactory,
|
|
2092
|
+
...selectorsFactory,
|
|
2093
|
+
...stateAdapter
|
|
2094
|
+
};
|
|
2095
|
+
}
|
|
2096
|
+
var listener = "listener";
|
|
2097
|
+
var completed = "completed";
|
|
2098
|
+
var cancelled = "cancelled";
|
|
2099
|
+
var taskCancelled = `task-${cancelled}`;
|
|
2100
|
+
var taskCompleted = `task-${completed}`;
|
|
2101
|
+
var listenerCancelled = `${listener}-${cancelled}`;
|
|
2102
|
+
var listenerCompleted = `${listener}-${completed}`;
|
|
2103
|
+
var {
|
|
2104
|
+
assign
|
|
2105
|
+
} = Object;
|
|
2106
|
+
var alm = "listenerMiddleware";
|
|
2107
|
+
var addListener = /* @__PURE__ */ assign(/* @__PURE__ */ createAction(`${alm}/add`), {
|
|
2108
|
+
withTypes: () => addListener
|
|
2109
|
+
});
|
|
2110
|
+
var clearAllListeners = /* @__PURE__ */ createAction(`${alm}/removeAll`);
|
|
2111
|
+
var removeListener = /* @__PURE__ */ assign(/* @__PURE__ */ createAction(`${alm}/remove`), {
|
|
2112
|
+
withTypes: () => removeListener
|
|
2113
|
+
});
|
|
2114
|
+
var ORIGINAL_STATE = Symbol.for("rtk-state-proxy-original");
|
|
2115
|
+
function formatProdErrorMessage(code) {
|
|
2116
|
+
return `Minified Redux Toolkit error #${code}; visit https://redux-toolkit.js.org/Errors?code=${code} for the full message or use the non-minified dev environment for full errors. `;
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
// packages/identity/selectors.local.ts
|
|
2120
|
+
var LOCAL_USER_ID = process.env.NOLO_LOCAL_USER_ID || process.env.NOLO_USER_ID || "local";
|
|
2121
|
+
var LOCAL_USER = {
|
|
2122
|
+
userId: LOCAL_USER_ID,
|
|
2123
|
+
username: "Local User"
|
|
2124
|
+
};
|
|
2125
|
+
var selectIdentityUserId = (state) => LOCAL_USER_ID;
|
|
2126
|
+
var selectIdentityToken = (state) => {
|
|
2127
|
+
if (state?.auth?.currentToken) return state.auth.currentToken;
|
|
2128
|
+
return void 0;
|
|
2129
|
+
};
|
|
2130
|
+
var selectIdentityUser = (state) => LOCAL_USER;
|
|
2131
|
+
|
|
2132
|
+
// packages/app/stateViews/runtime.ts
|
|
2133
|
+
var selectCurrentToken = (state) => {
|
|
2134
|
+
if (!state?.auth) return void 0;
|
|
2135
|
+
const token = selectIdentityToken(state);
|
|
2136
|
+
return typeof token === "string" ? token : void 0;
|
|
2137
|
+
};
|
|
2138
|
+
var selectCurrentUserId = (state) => {
|
|
2139
|
+
if (!state?.auth) return void 0;
|
|
2140
|
+
const userId = selectIdentityUserId(state);
|
|
2141
|
+
return typeof userId === "string" ? userId : void 0;
|
|
2142
|
+
};
|
|
2143
|
+
var EMPTY_SYNC_SERVERS = [];
|
|
2144
|
+
var selectRuntimeRemoteServer = (state) => {
|
|
2145
|
+
const configuredServer = normalizeKnownServerOrigin(state.settings?.currentServer) ?? void 0;
|
|
2146
|
+
if (!getIsDesktopApp()) return configuredServer || SERVERS.MAIN;
|
|
2147
|
+
return isLocalServerUrl(configuredServer) ? SERVERS.MAIN : configuredServer || SERVERS.MAIN;
|
|
2148
|
+
};
|
|
2149
|
+
var selectConfiguredSyncServers = (state) => state.settings?.syncServers;
|
|
2150
|
+
var selectRuntimeRemoteSyncServers = createSelector(
|
|
2151
|
+
[selectConfiguredSyncServers],
|
|
2152
|
+
(syncServers) => {
|
|
2153
|
+
if (!Array.isArray(syncServers) || syncServers.length === 0) {
|
|
2154
|
+
return EMPTY_SYNC_SERVERS;
|
|
2155
|
+
}
|
|
2156
|
+
const normalized = syncServers.map(normalizeKnownServerOrigin).filter((server) => !!server);
|
|
2157
|
+
if (!getIsDesktopApp()) return normalized;
|
|
2158
|
+
return normalized.filter((server) => !isLocalServerUrl(server));
|
|
2159
|
+
}
|
|
2160
|
+
);
|
|
2161
|
+
var selectLocalRuntimeOrigin = () => {
|
|
2162
|
+
if (typeof window !== "undefined" && typeof window.location?.origin === "string" && /^https?:\/\//.test(window.location.origin)) {
|
|
2163
|
+
return window.location.origin.replace(/\/+$/, "");
|
|
2164
|
+
}
|
|
2165
|
+
return void 0;
|
|
2166
|
+
};
|
|
2167
|
+
var selectRuntimeSnapshot = createSelector(
|
|
2168
|
+
[
|
|
2169
|
+
selectCurrentToken,
|
|
2170
|
+
selectCurrentUserId,
|
|
2171
|
+
selectRuntimeRemoteServer,
|
|
2172
|
+
selectRuntimeRemoteSyncServers,
|
|
2173
|
+
selectLocalRuntimeOrigin
|
|
2174
|
+
],
|
|
2175
|
+
(currentToken, currentUserId, currentServer, syncServers, localRuntimeOrigin) => ({
|
|
2176
|
+
currentToken,
|
|
2177
|
+
currentUserId,
|
|
2178
|
+
currentServer,
|
|
2179
|
+
syncServers,
|
|
2180
|
+
localRuntimeOrigin
|
|
2181
|
+
})
|
|
2182
|
+
);
|
|
2183
|
+
var selectRuntimeCurrentServer = createSelector(
|
|
2184
|
+
[selectRuntimeSnapshot],
|
|
2185
|
+
(runtime) => runtime.currentServer
|
|
2186
|
+
);
|
|
2187
|
+
var selectRuntimeRemoteServers = createSelector(
|
|
2188
|
+
[selectRuntimeSnapshot],
|
|
2189
|
+
(runtime) => getAllServers(runtime.currentServer, runtime.syncServers)
|
|
2190
|
+
);
|
|
2191
|
+
|
|
2192
|
+
// packages/database/runtimeServerContext.ts
|
|
2193
|
+
var getRuntimeServerContext = (state, preferredServerOrigin) => {
|
|
2194
|
+
const {
|
|
2195
|
+
currentToken,
|
|
2196
|
+
currentUserId,
|
|
2197
|
+
currentServer,
|
|
2198
|
+
syncServers = []
|
|
2199
|
+
} = selectRuntimeSnapshot(state);
|
|
2200
|
+
return {
|
|
2201
|
+
currentToken,
|
|
2202
|
+
currentUserId,
|
|
2203
|
+
currentServer,
|
|
2204
|
+
syncServers,
|
|
2205
|
+
userAuthorityRegistry: resolveRuntimeUserAuthorityRegistry(state),
|
|
2206
|
+
remoteServers: getAllServers(
|
|
2207
|
+
currentServer,
|
|
2208
|
+
syncServers,
|
|
2209
|
+
preferredServerOrigin
|
|
2210
|
+
)
|
|
2211
|
+
};
|
|
2212
|
+
};
|
|
2213
|
+
var resolveRuntimeUserAuthorityRegistry = (state) => {
|
|
2214
|
+
const settingsRegistry = state.settings?.userAuthorityRegistry;
|
|
2215
|
+
if (settingsRegistry && typeof settingsRegistry === "object") {
|
|
2216
|
+
return settingsRegistry;
|
|
2217
|
+
}
|
|
2218
|
+
const userRegistry = state.auth?.currentUser?.authorityRegistry;
|
|
2219
|
+
if (userRegistry && typeof userRegistry === "object") {
|
|
2220
|
+
return userRegistry;
|
|
2221
|
+
}
|
|
2222
|
+
return void 0;
|
|
2223
|
+
};
|
|
2224
|
+
|
|
2225
|
+
// packages/database/requests.ts
|
|
2226
|
+
var TIMEOUT = 5e3;
|
|
2227
|
+
var logRequestFailure = (level, message) => {
|
|
2228
|
+
if (level === "silent") return;
|
|
2229
|
+
if (level === "warn") {
|
|
2230
|
+
console.warn(message);
|
|
2231
|
+
return;
|
|
2232
|
+
}
|
|
2233
|
+
if (level === "info") {
|
|
2234
|
+
console.info(message);
|
|
2235
|
+
return;
|
|
2236
|
+
}
|
|
2237
|
+
console.error(message);
|
|
2238
|
+
};
|
|
2239
|
+
var noloRequest = async (server, config, state, signal) => {
|
|
2240
|
+
const headers = config.headers || {
|
|
2241
|
+
"Content-Type": "application/json"
|
|
2242
|
+
};
|
|
2243
|
+
const token = state?.auth?.currentToken;
|
|
2244
|
+
if (token) {
|
|
2245
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
2246
|
+
}
|
|
2247
|
+
return fetch(server + config.url, {
|
|
2248
|
+
method: config.method || "GET",
|
|
2249
|
+
headers,
|
|
2250
|
+
body: config.body,
|
|
2251
|
+
signal,
|
|
2252
|
+
// 传递 AbortSignal
|
|
2253
|
+
...config.keepalive ? { keepalive: true } : {}
|
|
2254
|
+
});
|
|
2255
|
+
};
|
|
2256
|
+
var noloPatchRequest = async (server, dbKey, updates, state, signal, options) => {
|
|
2257
|
+
const failureLogLevel = options?.failureLogLevel ?? "error";
|
|
2258
|
+
try {
|
|
2259
|
+
const response = await noloRequest(
|
|
2260
|
+
server,
|
|
2261
|
+
{
|
|
2262
|
+
url: `${API_ENDPOINTS.DATABASE}/patch/${dbKey}`,
|
|
2263
|
+
method: "PATCH",
|
|
2264
|
+
body: JSON.stringify(updates)
|
|
2265
|
+
},
|
|
2266
|
+
state,
|
|
2267
|
+
signal
|
|
2268
|
+
);
|
|
2269
|
+
if (!response.ok) {
|
|
2270
|
+
logRequestFailure(
|
|
2271
|
+
failureLogLevel,
|
|
2272
|
+
`PATCH request failed for ${dbKey} on ${server}: HTTP ${response.status}`
|
|
2273
|
+
);
|
|
2274
|
+
}
|
|
2275
|
+
return response.ok;
|
|
2276
|
+
} catch (error) {
|
|
2277
|
+
if (!isAbortError(error)) {
|
|
2278
|
+
logRequestFailure(
|
|
2279
|
+
failureLogLevel,
|
|
2280
|
+
`PATCH request failed for ${dbKey} on ${server}: ${error.message || "Unknown error"}`
|
|
2281
|
+
);
|
|
2282
|
+
}
|
|
2283
|
+
return false;
|
|
2284
|
+
}
|
|
2285
|
+
};
|
|
2286
|
+
var noloWriteRequest = async (server, writeConfig, state, signal, options) => {
|
|
2287
|
+
const { data, customKey, userId, indexKeys } = writeConfig;
|
|
2288
|
+
const failureLogLevel = options?.failureLogLevel ?? "error";
|
|
2289
|
+
try {
|
|
2290
|
+
const response = await noloRequest(
|
|
2291
|
+
server,
|
|
2292
|
+
{
|
|
2293
|
+
url: `${API_ENDPOINTS.DATABASE}/write/`,
|
|
2294
|
+
method: "POST",
|
|
2295
|
+
body: JSON.stringify({ data, customKey, userId, indexKeys })
|
|
2296
|
+
},
|
|
2297
|
+
state,
|
|
2298
|
+
signal
|
|
2299
|
+
);
|
|
2300
|
+
if (!response.ok) {
|
|
2301
|
+
logRequestFailure(
|
|
2302
|
+
failureLogLevel,
|
|
2303
|
+
`Write request failed for ${customKey} on ${server}: HTTP ${response.status}`
|
|
2304
|
+
);
|
|
2305
|
+
}
|
|
2306
|
+
return response.ok;
|
|
2307
|
+
} catch (error) {
|
|
2308
|
+
if (!isAbortError(error)) {
|
|
2309
|
+
logRequestFailure(
|
|
2310
|
+
failureLogLevel,
|
|
2311
|
+
`Write request failed for ${customKey} on ${server}: ${error.message || "Unknown error"}`
|
|
2312
|
+
);
|
|
2313
|
+
}
|
|
2314
|
+
return false;
|
|
2315
|
+
}
|
|
2316
|
+
};
|
|
2317
|
+
var rnUploadAdapter = null;
|
|
2318
|
+
var noloUploadRequest = async (server, uploadConfig, state, signal) => {
|
|
2319
|
+
const { file, metadata, customKey, userId } = uploadConfig;
|
|
2320
|
+
try {
|
|
2321
|
+
const isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
|
|
2322
|
+
const isRNFile = (f) => f && typeof f.uri === "string" && typeof f.name === "string" && typeof f.type === "string";
|
|
2323
|
+
if (isReactNative && isRNFile(file)) {
|
|
2324
|
+
if (!rnUploadAdapter) {
|
|
2325
|
+
throw new Error(
|
|
2326
|
+
"React Native upload adapter is not registered. Call initRNUploadAdapter() in the RN app entry before uploading files."
|
|
2327
|
+
);
|
|
2328
|
+
}
|
|
2329
|
+
return await rnUploadAdapter(server, uploadConfig, state, signal);
|
|
2330
|
+
}
|
|
2331
|
+
const formData = new FormData();
|
|
2332
|
+
if (isRNFile(file)) {
|
|
2333
|
+
formData.append("file", {
|
|
2334
|
+
uri: file.uri,
|
|
2335
|
+
type: file.type,
|
|
2336
|
+
name: file.name
|
|
2337
|
+
});
|
|
2338
|
+
} else {
|
|
2339
|
+
formData.append("file", file);
|
|
2340
|
+
}
|
|
2341
|
+
formData.append("metadata", JSON.stringify(metadata));
|
|
2342
|
+
formData.append("customKey", customKey);
|
|
2343
|
+
if (userId) {
|
|
2344
|
+
formData.append("userId", userId);
|
|
2345
|
+
}
|
|
2346
|
+
const response = await noloRequest(
|
|
2347
|
+
server,
|
|
2348
|
+
{
|
|
2349
|
+
url: `${API_ENDPOINTS.DATABASE}/upload`,
|
|
2350
|
+
method: "POST",
|
|
2351
|
+
body: formData,
|
|
2352
|
+
// Cast to any to avoid TS mismatch with Bun/DOM FormData
|
|
2353
|
+
headers: {}
|
|
2354
|
+
// 不设置 Content-Type,让浏览器自动处理 multipart/form-data
|
|
2355
|
+
},
|
|
2356
|
+
state,
|
|
2357
|
+
signal
|
|
2358
|
+
);
|
|
2359
|
+
if (!response.ok) {
|
|
2360
|
+
console.error(
|
|
2361
|
+
`Upload request failed for ${customKey} on ${server}: HTTP ${response.status}`
|
|
2362
|
+
);
|
|
2363
|
+
}
|
|
2364
|
+
return response.ok;
|
|
2365
|
+
} catch (error) {
|
|
2366
|
+
if (!isAbortError(error)) {
|
|
2367
|
+
console.error(
|
|
2368
|
+
`Upload request failed for ${customKey} on ${server}: ${error.message || "Unknown error"}`
|
|
2369
|
+
);
|
|
2370
|
+
}
|
|
2371
|
+
return false;
|
|
2372
|
+
}
|
|
2373
|
+
};
|
|
2374
|
+
var syncWithServers = (servers, requestFn, errorMessage, ...requestArgs) => {
|
|
2375
|
+
servers.forEach((server) => {
|
|
2376
|
+
const abortController = new AbortController();
|
|
2377
|
+
const timeoutId = setTimeout(() => {
|
|
2378
|
+
abortController.abort();
|
|
2379
|
+
}, TIMEOUT);
|
|
2380
|
+
requestFn(server, ...requestArgs, abortController.signal).then((success) => {
|
|
2381
|
+
clearTimeout(timeoutId);
|
|
2382
|
+
if (!success) {
|
|
2383
|
+
console.warn(`${errorMessage} ${server}`);
|
|
2384
|
+
}
|
|
2385
|
+
}).catch((error) => {
|
|
2386
|
+
clearTimeout(timeoutId);
|
|
2387
|
+
if (!isAbortError(error)) {
|
|
2388
|
+
console.error(
|
|
2389
|
+
`Unexpected error during sync with ${server}: ${error.message || "Unknown error"}`
|
|
2390
|
+
);
|
|
2391
|
+
}
|
|
2392
|
+
});
|
|
2393
|
+
});
|
|
2394
|
+
};
|
|
2395
|
+
var noloDeleteRequest = async (server, dbKey, options, state, signal) => {
|
|
2396
|
+
const { type = "single", force = false } = options;
|
|
2397
|
+
try {
|
|
2398
|
+
const queryParts = [];
|
|
2399
|
+
if (type === "messages") queryParts.push("type=messages");
|
|
2400
|
+
else if (type === "table") queryParts.push("type=table");
|
|
2401
|
+
if (force) queryParts.push("force=true");
|
|
2402
|
+
const query = queryParts.length ? `?${queryParts.join("&")}` : "";
|
|
2403
|
+
const url = `${API_ENDPOINTS.DATABASE}/delete/${dbKey}${query}`;
|
|
2404
|
+
const response = await noloRequest(
|
|
2405
|
+
server,
|
|
2406
|
+
{
|
|
2407
|
+
url,
|
|
2408
|
+
method: "DELETE",
|
|
2409
|
+
keepalive: true
|
|
2410
|
+
},
|
|
2411
|
+
state,
|
|
2412
|
+
signal
|
|
2413
|
+
);
|
|
2414
|
+
if (!response.ok) {
|
|
2415
|
+
console.error(
|
|
2416
|
+
`DELETE request failed for ${dbKey} on ${server}: HTTP ${response.status}`
|
|
2417
|
+
);
|
|
2418
|
+
return false;
|
|
2419
|
+
}
|
|
2420
|
+
return true;
|
|
2421
|
+
} catch (error) {
|
|
2422
|
+
if (!isAbortError(error)) {
|
|
2423
|
+
console.error(
|
|
2424
|
+
`DELETE request failed for ${dbKey} on ${server}: ${error.message || "Unknown error"}`
|
|
2425
|
+
);
|
|
2426
|
+
}
|
|
2427
|
+
return false;
|
|
2428
|
+
}
|
|
2429
|
+
};
|
|
2430
|
+
|
|
2431
|
+
// packages/database/authority/ownerKey.ts
|
|
2432
|
+
var USER_OWNED_SECOND_SEGMENT_PREFIXES = /* @__PURE__ */ new Set([
|
|
2433
|
+
"agent",
|
|
2434
|
+
"dialog",
|
|
2435
|
+
"page",
|
|
2436
|
+
"doc",
|
|
2437
|
+
"notification",
|
|
2438
|
+
"email",
|
|
2439
|
+
"meta",
|
|
2440
|
+
"row",
|
|
2441
|
+
"view",
|
|
2442
|
+
"file",
|
|
2443
|
+
"job"
|
|
2444
|
+
]);
|
|
2445
|
+
var PUBLIC_OWNER_SENTINELS = /* @__PURE__ */ new Set(["pub", "id", "stats", "index"]);
|
|
2446
|
+
var cleanSegment = (value) => {
|
|
2447
|
+
const trimmed = asTrimmedString(value);
|
|
2448
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
2449
|
+
};
|
|
2450
|
+
var normalizeCandidateOwners = (candidateOwnerUserIds) => {
|
|
2451
|
+
const out = [];
|
|
2452
|
+
for (const candidate of candidateOwnerUserIds ?? []) {
|
|
2453
|
+
const normalized = cleanSegment(candidate ?? void 0);
|
|
2454
|
+
if (!normalized || PUBLIC_OWNER_SENTINELS.has(normalized)) continue;
|
|
2455
|
+
if (!out.includes(normalized)) out.push(normalized);
|
|
2456
|
+
}
|
|
2457
|
+
return out.sort((left, right) => right.length - left.length);
|
|
2458
|
+
};
|
|
2459
|
+
var resolveCandidateOwnerFromKeyRemainder = (remainder, candidateOwnerUserIds) => {
|
|
2460
|
+
const normalizedRemainder = cleanSegment(remainder);
|
|
2461
|
+
if (!normalizedRemainder) return null;
|
|
2462
|
+
for (const candidate of normalizeCandidateOwners(candidateOwnerUserIds)) {
|
|
2463
|
+
if (normalizedRemainder === candidate || normalizedRemainder.startsWith(`${candidate}-`)) {
|
|
2464
|
+
return candidate;
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
return null;
|
|
2468
|
+
};
|
|
2469
|
+
var parseOwnerUserIdFromDbKey = (dbKey, options = {}) => {
|
|
2470
|
+
const normalized = cleanSegment(dbKey);
|
|
2471
|
+
if (!normalized) return null;
|
|
2472
|
+
const parts = normalized.split("-");
|
|
2473
|
+
const [prefix] = parts;
|
|
2474
|
+
if (!prefix) return null;
|
|
2475
|
+
if (!USER_OWNED_SECOND_SEGMENT_PREFIXES.has(prefix)) {
|
|
2476
|
+
if (prefix === "grant" && parts[1] === "agent" && parts.length >= 5) {
|
|
2477
|
+
const ownerAndRest2 = normalized.slice(prefix.length + 1 + parts[1].length + 1);
|
|
2478
|
+
const [owner2] = ownerAndRest2.split("-");
|
|
2479
|
+
return cleanSegment(owner2);
|
|
2480
|
+
}
|
|
2481
|
+
return null;
|
|
2482
|
+
}
|
|
2483
|
+
if (parts[0] === "dialog" && parts[2] === "msg") {
|
|
2484
|
+
return null;
|
|
2485
|
+
}
|
|
2486
|
+
const ownerAndRest = normalized.slice(prefix.length + 1);
|
|
2487
|
+
const candidateOwner = resolveCandidateOwnerFromKeyRemainder(
|
|
2488
|
+
ownerAndRest,
|
|
2489
|
+
options.candidateOwnerUserIds
|
|
2490
|
+
);
|
|
2491
|
+
if (candidateOwner) return candidateOwner;
|
|
2492
|
+
const [owner] = ownerAndRest.split("-");
|
|
2493
|
+
const ownerUserId = cleanSegment(owner);
|
|
2494
|
+
if (!ownerUserId) return null;
|
|
2495
|
+
if (PUBLIC_OWNER_SENTINELS.has(ownerUserId)) return null;
|
|
2496
|
+
return ownerUserId;
|
|
2497
|
+
};
|
|
2498
|
+
|
|
2499
|
+
// packages/database/authority/userAuthorityRegistry.ts
|
|
2500
|
+
var normalizeAuthorityServerOrigin = (value) => {
|
|
2501
|
+
const normalized = normalizeServerOrigin(value);
|
|
2502
|
+
return /^https?:\/\//i.test(normalized) ? normalized : null;
|
|
2503
|
+
};
|
|
2504
|
+
var normalizeUserId = (value) => asOptionalTrimmedString(value) ?? null;
|
|
2505
|
+
var readEntryAuthorityServer = (entry) => {
|
|
2506
|
+
if (typeof entry === "string") {
|
|
2507
|
+
return normalizeAuthorityServerOrigin(entry);
|
|
2508
|
+
}
|
|
2509
|
+
if (!isRecord(entry)) {
|
|
2510
|
+
return null;
|
|
2511
|
+
}
|
|
2512
|
+
return normalizeAuthorityServerOrigin(entry.authorityServer) ?? normalizeAuthorityServerOrigin(entry.homeServer) ?? normalizeAuthorityServerOrigin(entry.primaryServer);
|
|
2513
|
+
};
|
|
2514
|
+
var resolveUserAuthorityServer = ({
|
|
2515
|
+
ownerUserId,
|
|
2516
|
+
registry
|
|
2517
|
+
}) => {
|
|
2518
|
+
const normalizedOwner = normalizeUserId(ownerUserId);
|
|
2519
|
+
if (!normalizedOwner || !registry || typeof registry !== "object") {
|
|
2520
|
+
return null;
|
|
2521
|
+
}
|
|
2522
|
+
return readEntryAuthorityServer(registry[normalizedOwner]);
|
|
2523
|
+
};
|
|
2524
|
+
|
|
2525
|
+
// packages/database/authority/recordAuthority.ts
|
|
2526
|
+
var normalizeUserId2 = (value) => asOptionalTrimmedString(value) ?? null;
|
|
2527
|
+
var getRegistryOwnerCandidates = (registry) => isRecord(registry) ? Object.keys(registry) : [];
|
|
2528
|
+
var resolveRecordAuthority = ({
|
|
2529
|
+
dbKey,
|
|
2530
|
+
record,
|
|
2531
|
+
currentUserId,
|
|
2532
|
+
currentServer,
|
|
2533
|
+
userAuthorityRegistry
|
|
2534
|
+
}) => {
|
|
2535
|
+
const ownerUserId = parseOwnerUserIdFromDbKey(dbKey, {
|
|
2536
|
+
candidateOwnerUserIds: [
|
|
2537
|
+
normalizeUserId2(record?.userId),
|
|
2538
|
+
normalizeUserId2(currentUserId),
|
|
2539
|
+
...getRegistryOwnerCandidates(userAuthorityRegistry)
|
|
2540
|
+
]
|
|
2541
|
+
}) ?? normalizeUserId2(record?.userId);
|
|
2542
|
+
const serverOrigin = normalizeAuthorityServerOrigin(record?.serverOrigin);
|
|
2543
|
+
const explicitAuthority = normalizeAuthorityServerOrigin(record?.authorityServer);
|
|
2544
|
+
const registryAuthority = resolveUserAuthorityServer({
|
|
2545
|
+
ownerUserId,
|
|
2546
|
+
registry: userAuthorityRegistry
|
|
2547
|
+
});
|
|
2548
|
+
const currentUserAuthority = ownerUserId && ownerUserId === normalizeUserId2(currentUserId) ? normalizeAuthorityServerOrigin(currentServer) : null;
|
|
2549
|
+
return {
|
|
2550
|
+
ownerUserId,
|
|
2551
|
+
authorityServer: explicitAuthority ?? registryAuthority ?? currentUserAuthority ?? serverOrigin,
|
|
2552
|
+
serverOrigin
|
|
2553
|
+
};
|
|
2554
|
+
};
|
|
2555
|
+
|
|
2556
|
+
// packages/database/actions/readResolution.ts
|
|
2557
|
+
var toComparableTimestamp = (data) => {
|
|
2558
|
+
if (!data || typeof data !== "object") return 0;
|
|
2559
|
+
const updatedAtMs = asOptionalPositiveFiniteNumber(
|
|
2560
|
+
new Date(data.updatedAt).getTime()
|
|
2561
|
+
);
|
|
2562
|
+
if (updatedAtMs !== void 0) return updatedAtMs;
|
|
2563
|
+
const createdAtMs = asOptionalPositiveFiniteNumber(
|
|
2564
|
+
new Date(data.createdAt).getTime()
|
|
2565
|
+
);
|
|
2566
|
+
if (createdAtMs !== void 0) return createdAtMs;
|
|
2567
|
+
return asOptionalPositiveFiniteNumber(Number(data?.meta?.createdAt)) ?? 0;
|
|
2568
|
+
};
|
|
2569
|
+
var partitionReadServers = ({
|
|
2570
|
+
allServers,
|
|
2571
|
+
preferredServerOrigin
|
|
2572
|
+
}) => {
|
|
2573
|
+
const preferredServer = typeof preferredServerOrigin === "string" && preferredServerOrigin.trim().length > 0 ? normalizeServerOrigin(preferredServerOrigin) : null;
|
|
2574
|
+
const fallbackServers = preferredServer ? allServers.filter(
|
|
2575
|
+
(server) => normalizeServerOrigin(server) !== preferredServer
|
|
2576
|
+
) : allServers;
|
|
2577
|
+
return {
|
|
2578
|
+
preferredServer,
|
|
2579
|
+
fallbackServers,
|
|
2580
|
+
orderedServersForLocalHit: preferredServer ? [preferredServer, ...fallbackServers] : fallbackServers
|
|
2581
|
+
};
|
|
2582
|
+
};
|
|
2583
|
+
var compareRemoteRecordsByComparableTime = (left, right) => toComparableTimestamp(left) - toComparableTimestamp(right);
|
|
2584
|
+
var pickBestSettledRemoteRecord = ({
|
|
2585
|
+
settledResults,
|
|
2586
|
+
isBetterCandidate
|
|
2587
|
+
}) => {
|
|
2588
|
+
const validResults = settledResults.map((result, index) => ({
|
|
2589
|
+
data: result.status === "fulfilled" ? result.value : null,
|
|
2590
|
+
index
|
|
2591
|
+
})).filter((item) => item.data !== null && typeof item.data === "object");
|
|
2592
|
+
if (validResults.length === 0) return null;
|
|
2593
|
+
const latest2 = validResults.reduce(
|
|
2594
|
+
(best, current2) => isBetterCandidate(current2.data, best.data) ? current2 : best
|
|
2595
|
+
);
|
|
2596
|
+
return { index: latest2.index, data: latest2.data };
|
|
2597
|
+
};
|
|
2598
|
+
var shouldReplaceLocalWithRemoteRecord = ({
|
|
2599
|
+
localData,
|
|
2600
|
+
remoteData,
|
|
2601
|
+
isRemoteNewer
|
|
2602
|
+
}) => {
|
|
2603
|
+
if (!remoteData || typeof remoteData !== "object") return false;
|
|
2604
|
+
if (!localData || typeof localData !== "object") return true;
|
|
2605
|
+
return isRemoteNewer(remoteData, localData);
|
|
2606
|
+
};
|
|
2607
|
+
var shouldReplicateLocalRecord = ({
|
|
2608
|
+
localData,
|
|
2609
|
+
remoteData,
|
|
2610
|
+
remoteTargetCount
|
|
2611
|
+
}) => !!localData && !remoteData && remoteTargetCount > 0;
|
|
2612
|
+
var compactUniqueServers = (servers) => {
|
|
2613
|
+
const out = [];
|
|
2614
|
+
for (const server of servers) {
|
|
2615
|
+
if (typeof server !== "string" || server.trim().length === 0) continue;
|
|
2616
|
+
const normalized = normalizeServerOrigin(server);
|
|
2617
|
+
if (!out.includes(normalized)) out.push(normalized);
|
|
2618
|
+
}
|
|
2619
|
+
return out;
|
|
2620
|
+
};
|
|
2621
|
+
var planAuthorityReadServers = ({
|
|
2622
|
+
allServers,
|
|
2623
|
+
authorityServer,
|
|
2624
|
+
serverOrigin
|
|
2625
|
+
}) => compactUniqueServers([authorityServer, serverOrigin, ...allServers]);
|
|
2626
|
+
|
|
2627
|
+
// packages/database/fileRing.ts
|
|
2628
|
+
var fnv1a32 = (str) => {
|
|
2629
|
+
let hash = 2166136261;
|
|
2630
|
+
for (let i = 0; i < str.length; i++) {
|
|
2631
|
+
hash ^= str.charCodeAt(i);
|
|
2632
|
+
hash = hash * 16777619 >>> 0;
|
|
2633
|
+
}
|
|
2634
|
+
return hash >>> 0;
|
|
2635
|
+
};
|
|
2636
|
+
var chooseServersByKey = (allServers, key, replicaCount) => {
|
|
2637
|
+
if (!allServers.length || replicaCount <= 0) return [];
|
|
2638
|
+
const uniqueServers = Array.from(new Set(allServers)).filter((s) => !!s);
|
|
2639
|
+
if (uniqueServers.length === 0) return [];
|
|
2640
|
+
const scored = uniqueServers.map((server) => ({
|
|
2641
|
+
server,
|
|
2642
|
+
score: fnv1a32(`${server}::${key}`)
|
|
2643
|
+
}));
|
|
2644
|
+
scored.sort((a, b) => a.score - b.score);
|
|
2645
|
+
const limit = Math.min(replicaCount, scored.length);
|
|
2646
|
+
return scored.slice(0, limit).map((item) => item.server);
|
|
2647
|
+
};
|
|
2648
|
+
|
|
2649
|
+
// packages/database/tenantPlacement.ts
|
|
2650
|
+
var TENANT_REPLICA_COUNT = 2;
|
|
2651
|
+
var planServersForTenant = (allServers, currentServer, tenantId) => {
|
|
2652
|
+
const uniqueServers = Array.from(new Set(allServers)).filter(Boolean);
|
|
2653
|
+
if (!uniqueServers.length) return [];
|
|
2654
|
+
const key = asOptionalTrimmedString(tenantId) ?? "default-tenant";
|
|
2655
|
+
const fromRing = chooseServersByKey(
|
|
2656
|
+
uniqueServers,
|
|
2657
|
+
key,
|
|
2658
|
+
TENANT_REPLICA_COUNT
|
|
2659
|
+
);
|
|
2660
|
+
const set2 = new Set(fromRing);
|
|
2661
|
+
if (currentServer && uniqueServers.includes(currentServer)) {
|
|
2662
|
+
set2.add(currentServer);
|
|
2663
|
+
}
|
|
2664
|
+
return Array.from(set2);
|
|
2665
|
+
};
|
|
2666
|
+
|
|
2667
|
+
// packages/database/authority/deviceLocal.ts
|
|
2668
|
+
var DEVICE_LOCAL_OWNER_ID = "local";
|
|
2669
|
+
var DEVICE_LOCAL_DB_KEY_PREFIXES = [
|
|
2670
|
+
"dialog-local-",
|
|
2671
|
+
"agent-local-"
|
|
2672
|
+
];
|
|
2673
|
+
var clean = (value) => asOptionalTrimmedString(value) ?? null;
|
|
2674
|
+
var isDeviceLocalOwnerId = (userId) => clean(userId) === DEVICE_LOCAL_OWNER_ID;
|
|
2675
|
+
var resolveEffectiveSpaceActorId = (accountUserId) => {
|
|
2676
|
+
const cleaned = clean(accountUserId);
|
|
2677
|
+
if (!cleaned || isDeviceLocalOwnerId(cleaned)) {
|
|
2678
|
+
return DEVICE_LOCAL_OWNER_ID;
|
|
2679
|
+
}
|
|
2680
|
+
return cleaned;
|
|
2681
|
+
};
|
|
2682
|
+
var isDeviceLocalSpaceMembership = (membership) => isDeviceLocalOwnerId(membership?.userId);
|
|
2683
|
+
var isDeviceLocalSpaceBody = (space) => isDeviceLocalOwnerId(space?.userId) || isDeviceLocalOwnerId(space?.ownerId);
|
|
2684
|
+
var isDeviceLocalDbKey = (dbKey) => {
|
|
2685
|
+
const key = clean(dbKey);
|
|
2686
|
+
if (!key) return false;
|
|
2687
|
+
for (const prefix of DEVICE_LOCAL_DB_KEY_PREFIXES) {
|
|
2688
|
+
if (key.startsWith(prefix)) return true;
|
|
2689
|
+
}
|
|
2690
|
+
return parseOwnerUserIdFromDbKey(key, {
|
|
2691
|
+
candidateOwnerUserIds: [DEVICE_LOCAL_OWNER_ID]
|
|
2692
|
+
}) === DEVICE_LOCAL_OWNER_ID;
|
|
2693
|
+
};
|
|
2694
|
+
var resolveRecordOwnerUserId = (record) => {
|
|
2695
|
+
if (!record) return null;
|
|
2696
|
+
const explicit = clean(record.userId);
|
|
2697
|
+
if (explicit) return explicit;
|
|
2698
|
+
if (isDeviceLocalDbKey(record.dbKey) || isDeviceLocalDbKey(record.id)) {
|
|
2699
|
+
return DEVICE_LOCAL_OWNER_ID;
|
|
2700
|
+
}
|
|
2701
|
+
const fromKey = parseOwnerUserIdFromDbKey(clean(record.dbKey) ?? "", {
|
|
2702
|
+
candidateOwnerUserIds: [DEVICE_LOCAL_OWNER_ID]
|
|
2703
|
+
}) ?? parseOwnerUserIdFromDbKey(clean(record.id) ?? "", {
|
|
2704
|
+
candidateOwnerUserIds: [DEVICE_LOCAL_OWNER_ID]
|
|
2705
|
+
});
|
|
2706
|
+
return fromKey;
|
|
2707
|
+
};
|
|
2708
|
+
|
|
2709
|
+
// packages/database/actions/replication.ts
|
|
2710
|
+
var isReadonlyPublicRecordKey = (dbKey) => dbKey.startsWith("agent-pub-");
|
|
2711
|
+
var normalizeCurrentUserId = (state) => {
|
|
2712
|
+
const userId = state?.auth?.currentUser?.userId;
|
|
2713
|
+
return asOptionalTrimmedString(userId) ?? null;
|
|
2714
|
+
};
|
|
2715
|
+
var resolveReplicationServers = (currentServer, syncServers, preferredServerOrigin) => getAllServers(currentServer, syncServers, preferredServerOrigin);
|
|
2716
|
+
var resolveAuthorityReplicationServers = ({
|
|
2717
|
+
currentServer,
|
|
2718
|
+
syncServers,
|
|
2719
|
+
preferredServerOrigin,
|
|
2720
|
+
dbKey,
|
|
2721
|
+
record,
|
|
2722
|
+
state
|
|
2723
|
+
}) => {
|
|
2724
|
+
const allServers = resolveReplicationServers(
|
|
2725
|
+
currentServer,
|
|
2726
|
+
syncServers,
|
|
2727
|
+
preferredServerOrigin
|
|
2728
|
+
);
|
|
2729
|
+
const authority = resolveRecordAuthority({
|
|
2730
|
+
dbKey,
|
|
2731
|
+
record,
|
|
2732
|
+
currentUserId: state?.auth?.currentUser?.userId,
|
|
2733
|
+
currentServer,
|
|
2734
|
+
userAuthorityRegistry: state?.settings?.userAuthorityRegistry ?? state?.auth?.currentUser?.authorityRegistry
|
|
2735
|
+
});
|
|
2736
|
+
if (isDeviceLocalOwnerId(authority.ownerUserId) || isDeviceLocalOwnerId(record?.userId) || isDeviceLocalDbKey(dbKey)) {
|
|
2737
|
+
return [];
|
|
2738
|
+
}
|
|
2739
|
+
return planAuthorityReadServers({
|
|
2740
|
+
allServers,
|
|
2741
|
+
authorityServer: preferredServerOrigin ?? authority.authorityServer,
|
|
2742
|
+
serverOrigin: authority.serverOrigin
|
|
2743
|
+
});
|
|
2744
|
+
};
|
|
2745
|
+
var scheduleWriteReplication = (servers, request, state) => {
|
|
2746
|
+
if (servers.length === 0) return;
|
|
2747
|
+
Promise.resolve().then(async () => {
|
|
2748
|
+
const [primaryServer, ...backupServers] = servers;
|
|
2749
|
+
const primarySucceeded = await noloWriteRequest(primaryServer, request, state);
|
|
2750
|
+
if (!primarySucceeded) {
|
|
2751
|
+
console.warn(`Primary write sync failed for ${request.customKey} on ${primaryServer}`);
|
|
2752
|
+
}
|
|
2753
|
+
if (backupServers.length === 0) {
|
|
2754
|
+
return;
|
|
2755
|
+
}
|
|
2756
|
+
syncWithServers(
|
|
2757
|
+
backupServers,
|
|
2758
|
+
(server, requestConfig, requestState, signal) => noloWriteRequest(server, requestConfig, requestState, signal, {
|
|
2759
|
+
failureLogLevel: "info"
|
|
2760
|
+
}),
|
|
2761
|
+
`Backup write sync failed for ${request.customKey} on`,
|
|
2762
|
+
request,
|
|
2763
|
+
state
|
|
2764
|
+
);
|
|
2765
|
+
});
|
|
2766
|
+
};
|
|
2767
|
+
var resolveTenantReplicationServers = ({
|
|
2768
|
+
currentServer,
|
|
2769
|
+
syncServers,
|
|
2770
|
+
tenantId
|
|
2771
|
+
}) => {
|
|
2772
|
+
const allServers = resolveReplicationServers(currentServer, syncServers);
|
|
2773
|
+
if (allServers.length === 0) {
|
|
2774
|
+
return [];
|
|
2775
|
+
}
|
|
2776
|
+
return planServersForTenant(allServers, currentServer, tenantId);
|
|
2777
|
+
};
|
|
2778
|
+
var resolveUploadReplicationServers = ({
|
|
2779
|
+
currentServer,
|
|
2780
|
+
syncServers,
|
|
2781
|
+
tenantId,
|
|
2782
|
+
uploadConfig,
|
|
2783
|
+
state
|
|
2784
|
+
}) => {
|
|
2785
|
+
const allServers = resolveReplicationServers(currentServer, syncServers);
|
|
2786
|
+
const authority = resolveRecordAuthority({
|
|
2787
|
+
dbKey: uploadConfig.customKey,
|
|
2788
|
+
record: uploadConfig.metadata,
|
|
2789
|
+
currentUserId: state?.auth?.currentUser?.userId,
|
|
2790
|
+
currentServer,
|
|
2791
|
+
userAuthorityRegistry: state?.settings?.userAuthorityRegistry ?? state?.auth?.currentUser?.authorityRegistry
|
|
2792
|
+
});
|
|
2793
|
+
if (authority.ownerUserId || authority.authorityServer) {
|
|
2794
|
+
return planAuthorityReadServers({
|
|
2795
|
+
allServers,
|
|
2796
|
+
authorityServer: authority.authorityServer,
|
|
2797
|
+
serverOrigin: authority.serverOrigin
|
|
2798
|
+
});
|
|
2799
|
+
}
|
|
2800
|
+
return resolveTenantReplicationServers({
|
|
2801
|
+
currentServer,
|
|
2802
|
+
syncServers,
|
|
2803
|
+
tenantId
|
|
2804
|
+
});
|
|
2805
|
+
};
|
|
2806
|
+
var scheduleExistingRecordReplication = ({
|
|
2807
|
+
currentServer,
|
|
2808
|
+
syncServers,
|
|
2809
|
+
preferredServerOrigin,
|
|
2810
|
+
dbKey,
|
|
2811
|
+
localData,
|
|
2812
|
+
state
|
|
2813
|
+
}) => {
|
|
2814
|
+
if (isReadonlyPublicRecordKey(dbKey)) {
|
|
2815
|
+
return [];
|
|
2816
|
+
}
|
|
2817
|
+
const currentUserId = normalizeCurrentUserId(state);
|
|
2818
|
+
const authority = resolveRecordAuthority({
|
|
2819
|
+
dbKey,
|
|
2820
|
+
record: localData,
|
|
2821
|
+
currentUserId,
|
|
2822
|
+
currentServer,
|
|
2823
|
+
userAuthorityRegistry: state?.settings?.userAuthorityRegistry ?? state?.auth?.currentUser?.authorityRegistry
|
|
2824
|
+
});
|
|
2825
|
+
if (authority.ownerUserId && currentUserId && authority.ownerUserId !== currentUserId) {
|
|
2826
|
+
return [];
|
|
2827
|
+
}
|
|
2828
|
+
const servers = resolveAuthorityReplicationServers({
|
|
2829
|
+
currentServer,
|
|
2830
|
+
syncServers,
|
|
2831
|
+
preferredServerOrigin,
|
|
2832
|
+
dbKey,
|
|
2833
|
+
record: localData,
|
|
2834
|
+
state
|
|
2835
|
+
});
|
|
2836
|
+
if (servers.length === 0) {
|
|
2837
|
+
return [];
|
|
2838
|
+
}
|
|
2839
|
+
scheduleWriteReplication(
|
|
2840
|
+
servers,
|
|
2841
|
+
{
|
|
2842
|
+
data: localData,
|
|
2843
|
+
customKey: dbKey,
|
|
2844
|
+
userId: typeof localData?.userId === "string" ? localData.userId : state?.auth?.currentUser?.userId
|
|
2845
|
+
},
|
|
2846
|
+
state
|
|
2847
|
+
);
|
|
2848
|
+
return servers;
|
|
2849
|
+
};
|
|
2850
|
+
var schedulePatchReplication = ({
|
|
2851
|
+
servers,
|
|
2852
|
+
dbKey,
|
|
2853
|
+
changes,
|
|
2854
|
+
state,
|
|
2855
|
+
preferredServerOrigin
|
|
2856
|
+
}) => {
|
|
2857
|
+
if (servers.length === 0) return;
|
|
2858
|
+
Promise.resolve().then(async () => {
|
|
2859
|
+
const primaryServer = typeof preferredServerOrigin === "string" && preferredServerOrigin.trim().length > 0 ? normalizeServerOrigin(preferredServerOrigin) : servers[0];
|
|
2860
|
+
const backupServers = servers.filter(
|
|
2861
|
+
(server) => normalizeServerOrigin(server) !== primaryServer
|
|
2862
|
+
);
|
|
2863
|
+
const primarySucceeded = await noloPatchRequest(primaryServer, dbKey, changes, state, void 0, {
|
|
2864
|
+
failureLogLevel: "warn"
|
|
2865
|
+
});
|
|
2866
|
+
if (!primarySucceeded) {
|
|
2867
|
+
console.warn(`Primary patch sync failed for ${dbKey} on ${primaryServer}`);
|
|
2868
|
+
}
|
|
2869
|
+
if (backupServers.length > 0) {
|
|
2870
|
+
syncWithServers(
|
|
2871
|
+
backupServers,
|
|
2872
|
+
(server, targetDbKey, nextChanges, requestState, signal) => noloPatchRequest(server, targetDbKey, nextChanges, requestState, signal, {
|
|
2873
|
+
failureLogLevel: "info"
|
|
2874
|
+
}),
|
|
2875
|
+
`Backup patch sync failed for ${dbKey} on`,
|
|
2876
|
+
dbKey,
|
|
2877
|
+
changes,
|
|
2878
|
+
state
|
|
2879
|
+
);
|
|
2880
|
+
}
|
|
2881
|
+
});
|
|
2882
|
+
};
|
|
2883
|
+
var scheduleConfiguredPatchReplication = ({
|
|
2884
|
+
currentServer,
|
|
2885
|
+
syncServers,
|
|
2886
|
+
preferredServerOrigin,
|
|
2887
|
+
dbKey,
|
|
2888
|
+
changes,
|
|
2889
|
+
state
|
|
2890
|
+
}) => {
|
|
2891
|
+
const servers = resolveAuthorityReplicationServers({
|
|
2892
|
+
currentServer,
|
|
2893
|
+
syncServers,
|
|
2894
|
+
preferredServerOrigin,
|
|
2895
|
+
dbKey,
|
|
2896
|
+
record: changes,
|
|
2897
|
+
state
|
|
2898
|
+
});
|
|
2899
|
+
if (servers.length === 0) {
|
|
2900
|
+
return [];
|
|
2901
|
+
}
|
|
2902
|
+
schedulePatchReplication({
|
|
2903
|
+
servers,
|
|
2904
|
+
dbKey,
|
|
2905
|
+
changes,
|
|
2906
|
+
state,
|
|
2907
|
+
preferredServerOrigin
|
|
2908
|
+
});
|
|
2909
|
+
return servers;
|
|
2910
|
+
};
|
|
2911
|
+
var scheduleUploadReplication = ({
|
|
2912
|
+
currentServer,
|
|
2913
|
+
syncServers,
|
|
2914
|
+
tenantId,
|
|
2915
|
+
uploadConfig,
|
|
2916
|
+
state,
|
|
2917
|
+
excludeServers = []
|
|
2918
|
+
}) => {
|
|
2919
|
+
const servers = resolveUploadReplicationServers({
|
|
2920
|
+
currentServer,
|
|
2921
|
+
syncServers,
|
|
2922
|
+
tenantId,
|
|
2923
|
+
uploadConfig,
|
|
2924
|
+
state
|
|
2925
|
+
});
|
|
2926
|
+
const excluded = new Set(
|
|
2927
|
+
excludeServers.filter((server) => typeof server === "string").map((server) => normalizeServerOrigin(server))
|
|
2928
|
+
);
|
|
2929
|
+
const remainingServers = servers.filter(
|
|
2930
|
+
(server) => !excluded.has(normalizeServerOrigin(server))
|
|
2931
|
+
);
|
|
2932
|
+
if (remainingServers.length === 0) {
|
|
2933
|
+
return [];
|
|
2934
|
+
}
|
|
2935
|
+
Promise.resolve().then(() => {
|
|
2936
|
+
syncWithServers(
|
|
2937
|
+
remainingServers,
|
|
2938
|
+
noloUploadRequest,
|
|
2939
|
+
`Upload sync failed for ${uploadConfig.customKey} on`,
|
|
2940
|
+
uploadConfig,
|
|
2941
|
+
state
|
|
2942
|
+
);
|
|
2943
|
+
});
|
|
2944
|
+
return remainingServers;
|
|
2945
|
+
};
|
|
2946
|
+
var uploadToCurrentServer = async ({
|
|
2947
|
+
currentServer,
|
|
2948
|
+
uploadConfig,
|
|
2949
|
+
state
|
|
2950
|
+
}) => {
|
|
2951
|
+
if (!currentServer) {
|
|
2952
|
+
return false;
|
|
2953
|
+
}
|
|
2954
|
+
return noloUploadRequest(currentServer, uploadConfig, state);
|
|
2955
|
+
};
|
|
2956
|
+
var deleteFromReplicationServers = async ({
|
|
2957
|
+
servers,
|
|
2958
|
+
dbKey,
|
|
2959
|
+
deleteOptions = { type: "single" },
|
|
2960
|
+
state,
|
|
2961
|
+
preferredServerOrigin
|
|
2962
|
+
}) => {
|
|
2963
|
+
if (!servers.length) {
|
|
2964
|
+
return { succeeded: [], failed: [] };
|
|
2965
|
+
}
|
|
2966
|
+
const preferredServer = typeof preferredServerOrigin === "string" && preferredServerOrigin.trim().length > 0 ? normalizeServerOrigin(preferredServerOrigin) : null;
|
|
2967
|
+
const remainingServers = preferredServer ? servers.filter((server) => normalizeServerOrigin(server) !== preferredServer) : servers;
|
|
2968
|
+
const succeeded = [];
|
|
2969
|
+
const failed = [];
|
|
2970
|
+
if (preferredServer) {
|
|
2971
|
+
const ok = await noloDeleteRequest(preferredServer, dbKey, deleteOptions, state);
|
|
2972
|
+
if (ok) {
|
|
2973
|
+
succeeded.push(preferredServer);
|
|
2974
|
+
} else {
|
|
2975
|
+
failed.push(preferredServer);
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
if (remainingServers.length > 0) {
|
|
2979
|
+
const results = await Promise.all(
|
|
2980
|
+
remainingServers.map(async (server) => ({
|
|
2981
|
+
server,
|
|
2982
|
+
ok: await noloDeleteRequest(server, dbKey, deleteOptions, state)
|
|
2983
|
+
}))
|
|
2984
|
+
);
|
|
2985
|
+
results.forEach(({ server, ok }) => {
|
|
2986
|
+
if (ok) succeeded.push(server);
|
|
2987
|
+
else failed.push(server);
|
|
2988
|
+
});
|
|
2989
|
+
}
|
|
2990
|
+
return { succeeded, failed };
|
|
2991
|
+
};
|
|
2992
|
+
var scheduleDeleteReplication = ({
|
|
2993
|
+
currentServer,
|
|
2994
|
+
syncServers,
|
|
2995
|
+
preferredServerOrigin,
|
|
2996
|
+
dbKey,
|
|
2997
|
+
deleteOptions,
|
|
2998
|
+
state,
|
|
2999
|
+
onResult,
|
|
3000
|
+
onError
|
|
3001
|
+
}) => {
|
|
3002
|
+
const servers = resolveAuthorityReplicationServers({
|
|
3003
|
+
currentServer,
|
|
3004
|
+
syncServers,
|
|
3005
|
+
preferredServerOrigin,
|
|
3006
|
+
dbKey,
|
|
3007
|
+
state
|
|
3008
|
+
});
|
|
3009
|
+
if (servers.length === 0) {
|
|
3010
|
+
return [];
|
|
3011
|
+
}
|
|
3012
|
+
void Promise.resolve().then(
|
|
3013
|
+
() => deleteFromReplicationServers({
|
|
3014
|
+
servers,
|
|
3015
|
+
dbKey,
|
|
3016
|
+
deleteOptions,
|
|
3017
|
+
state,
|
|
3018
|
+
preferredServerOrigin
|
|
3019
|
+
})
|
|
3020
|
+
).then((result) => {
|
|
3021
|
+
onResult?.(result);
|
|
3022
|
+
}).catch((error) => {
|
|
3023
|
+
onError?.(error);
|
|
3024
|
+
});
|
|
3025
|
+
return servers;
|
|
3026
|
+
};
|
|
3027
|
+
|
|
3028
|
+
export {
|
|
3029
|
+
createSelector,
|
|
3030
|
+
createAction,
|
|
3031
|
+
createAsyncThunk,
|
|
3032
|
+
asyncThunkCreator,
|
|
3033
|
+
buildCreateSlice,
|
|
3034
|
+
createEntityAdapter,
|
|
3035
|
+
selectIdentityUserId,
|
|
3036
|
+
selectIdentityToken,
|
|
3037
|
+
selectIdentityUser,
|
|
3038
|
+
selectRuntimeSnapshot,
|
|
3039
|
+
selectRuntimeCurrentServer,
|
|
3040
|
+
getRuntimeServerContext,
|
|
3041
|
+
noloWriteRequest,
|
|
3042
|
+
noloDeleteRequest,
|
|
3043
|
+
parseOwnerUserIdFromDbKey,
|
|
3044
|
+
DEVICE_LOCAL_OWNER_ID,
|
|
3045
|
+
isDeviceLocalOwnerId,
|
|
3046
|
+
resolveEffectiveSpaceActorId,
|
|
3047
|
+
isDeviceLocalSpaceMembership,
|
|
3048
|
+
isDeviceLocalSpaceBody,
|
|
3049
|
+
resolveRecordOwnerUserId,
|
|
3050
|
+
resolveRecordAuthority,
|
|
3051
|
+
partitionReadServers,
|
|
3052
|
+
compareRemoteRecordsByComparableTime,
|
|
3053
|
+
pickBestSettledRemoteRecord,
|
|
3054
|
+
shouldReplaceLocalWithRemoteRecord,
|
|
3055
|
+
shouldReplicateLocalRecord,
|
|
3056
|
+
planAuthorityReadServers,
|
|
3057
|
+
resolveReplicationServers,
|
|
3058
|
+
resolveAuthorityReplicationServers,
|
|
3059
|
+
scheduleWriteReplication,
|
|
3060
|
+
resolveUploadReplicationServers,
|
|
3061
|
+
scheduleExistingRecordReplication,
|
|
3062
|
+
scheduleConfiguredPatchReplication,
|
|
3063
|
+
scheduleUploadReplication,
|
|
3064
|
+
uploadToCurrentServer,
|
|
3065
|
+
scheduleDeleteReplication
|
|
3066
|
+
};
|