@biglogic/rgs 3.9.6 → 3.9.7
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/docs/README.md +479 -0
- package/docs/SUMMARY.md +55 -0
- package/docs/_config.yml +1 -0
- package/docs/markdown/api.md +381 -0
- package/docs/markdown/case-studies.md +69 -0
- package/docs/markdown/faq.md +53 -0
- package/docs/markdown/getting-started.md +68 -0
- package/docs/markdown/local-first-sync.md +146 -0
- package/docs/markdown/migration-guide.md +284 -0
- package/docs/markdown/persistence-and-safety.md +125 -0
- package/docs/markdown/philosophy.md +54 -0
- package/docs/markdown/plugin-sdk.md +161 -0
- package/docs/markdown/plugins-and-extensibility.md +82 -0
- package/docs/markdown/security-architecture.md +50 -0
- package/docs/markdown/the-magnetar-way.md +69 -0
- package/index.cjs +752 -281
- package/index.js +951 -482
- package/package.json +2 -1
package/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMemo as e, useSyncExternalStore as t, useCallback as n, useDebugValue as r, useState as s, useEffect as o } from "react";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return e && (t = (0, e[g(e)[0]])(e = 0)), t;
|
|
7
|
-
}, h = f({
|
|
3
|
+
var a, i, c, l, u = Object.defineProperty, d = Object.getOwnPropertyNames, f = (e, t) => function() {
|
|
4
|
+
return e && (t = (0, e[d(e)[0]])(e = 0)), t;
|
|
5
|
+
}, y = f({
|
|
8
6
|
"core/utils.ts"() {
|
|
9
|
-
|
|
7
|
+
a = e => {
|
|
10
8
|
if (null === e || "object" != typeof e) return e;
|
|
11
9
|
if ("function" == typeof structuredClone) try {
|
|
12
10
|
return structuredClone(e);
|
|
@@ -18,34 +16,34 @@ var c, l, u, y, d = Object.defineProperty, g = Object.getOwnPropertyNames, f = (
|
|
|
18
16
|
if (e instanceof Date) return new Date(e.getTime());
|
|
19
17
|
if (e instanceof RegExp) return new RegExp(e.source, e.flags);
|
|
20
18
|
if (e instanceof Map) {
|
|
21
|
-
const
|
|
22
|
-
return t.set(e,
|
|
19
|
+
const r = new Map;
|
|
20
|
+
return t.set(e, r), e.forEach((e, t) => r.set(n(t), n(e))), r;
|
|
23
21
|
}
|
|
24
22
|
if (e instanceof Set) {
|
|
25
|
-
const
|
|
26
|
-
return t.set(e,
|
|
23
|
+
const r = new Set;
|
|
24
|
+
return t.set(e, r), e.forEach(e => r.add(n(e))), r;
|
|
27
25
|
}
|
|
28
|
-
const
|
|
29
|
-
t.set(e,
|
|
30
|
-
const
|
|
31
|
-
for (const t of
|
|
32
|
-
return
|
|
26
|
+
const r = Array.isArray(e) ? [] : Object.create(Object.getPrototypeOf(e));
|
|
27
|
+
t.set(e, r);
|
|
28
|
+
const s = [ ...Object.keys(e), ...Object.getOwnPropertySymbols(e) ];
|
|
29
|
+
for (const t of s) r[t] = n(e[t]);
|
|
30
|
+
return r;
|
|
33
31
|
};
|
|
34
32
|
return n(e);
|
|
35
|
-
},
|
|
33
|
+
}, i = (e, t) => {
|
|
36
34
|
if (e === t) return !0;
|
|
37
35
|
if (null === e || null === t) return e === t;
|
|
38
36
|
if ("object" != typeof e || "object" != typeof t) return e === t;
|
|
39
37
|
if (Array.isArray(e) && Array.isArray(t)) {
|
|
40
38
|
if (e.length !== t.length) return !1;
|
|
41
|
-
for (let n = 0; n < e.length; n++) if (!
|
|
39
|
+
for (let n = 0; n < e.length; n++) if (!i(e[n], t[n])) return !1;
|
|
42
40
|
return !0;
|
|
43
41
|
}
|
|
44
|
-
const n = Object.keys(e),
|
|
45
|
-
if (n.length !==
|
|
46
|
-
for (let
|
|
47
|
-
const
|
|
48
|
-
if (!(
|
|
42
|
+
const n = Object.keys(e), r = Object.keys(t);
|
|
43
|
+
if (n.length !== r.length) return !1;
|
|
44
|
+
for (let r = 0; r < n.length; r++) {
|
|
45
|
+
const s = n[r];
|
|
46
|
+
if (!(s in t) || !i(e[s], t[s])) return !1;
|
|
49
47
|
}
|
|
50
48
|
return !0;
|
|
51
49
|
};
|
|
@@ -53,18 +51,18 @@ var c, l, u, y, d = Object.defineProperty, g = Object.getOwnPropertyNames, f = (
|
|
|
53
51
|
}), p = {};
|
|
54
52
|
|
|
55
53
|
((e, t) => {
|
|
56
|
-
for (var n in t)
|
|
54
|
+
for (var n in t) u(e, n, {
|
|
57
55
|
get: t[n],
|
|
58
56
|
enumerable: !0
|
|
59
57
|
});
|
|
60
58
|
})(p, {
|
|
61
|
-
SyncEngine: () =>
|
|
62
|
-
createSyncEngine: () =>
|
|
59
|
+
SyncEngine: () => c,
|
|
60
|
+
createSyncEngine: () => l
|
|
63
61
|
});
|
|
64
62
|
|
|
65
|
-
var
|
|
63
|
+
var h = f({
|
|
66
64
|
"core/sync.ts"() {
|
|
67
|
-
|
|
65
|
+
y(), c = class {
|
|
68
66
|
store;
|
|
69
67
|
config;
|
|
70
68
|
pendingQueue=new Map;
|
|
@@ -121,7 +119,7 @@ var m = f({
|
|
|
121
119
|
const n = this.store._getVersion(e) || 1;
|
|
122
120
|
this.pendingQueue.set(e, {
|
|
123
121
|
key: e,
|
|
124
|
-
value:
|
|
122
|
+
value: a(t),
|
|
125
123
|
timestamp: Date.now(),
|
|
126
124
|
version: n
|
|
127
125
|
}), this._notifyStateChange(), this.syncTimer && clearTimeout(this.syncTimer), this.syncTimer = setTimeout(() => {
|
|
@@ -138,10 +136,10 @@ var m = f({
|
|
|
138
136
|
duration: 0
|
|
139
137
|
};
|
|
140
138
|
this._isSyncing = !0, this._notifyStateChange();
|
|
141
|
-
const e = Date.now(), t = [], n = [],
|
|
139
|
+
const e = Date.now(), t = [], n = [], r = [];
|
|
142
140
|
try {
|
|
143
|
-
const
|
|
144
|
-
if (0 ===
|
|
141
|
+
const s = Array.from(this.pendingQueue.values());
|
|
142
|
+
if (0 === s.length) return this._isSyncing = !1, this._notifyStateChange(), {
|
|
145
143
|
success: !0,
|
|
146
144
|
syncedKeys: [],
|
|
147
145
|
conflicts: [],
|
|
@@ -149,42 +147,42 @@ var m = f({
|
|
|
149
147
|
timestamp: Date.now(),
|
|
150
148
|
duration: Date.now() - e
|
|
151
149
|
};
|
|
152
|
-
await this._fetchRemoteVersions(
|
|
153
|
-
for (const e of
|
|
154
|
-
const
|
|
155
|
-
if (
|
|
156
|
-
const
|
|
150
|
+
await this._fetchRemoteVersions(s.map(e => e.key));
|
|
151
|
+
for (const e of s) try {
|
|
152
|
+
const r = this.remoteVersions.get(e.key);
|
|
153
|
+
if (r) if (r.version >= e.version) {
|
|
154
|
+
const s = {
|
|
157
155
|
key: e.key,
|
|
158
156
|
localValue: e.value,
|
|
159
|
-
remoteValue:
|
|
157
|
+
remoteValue: r.value,
|
|
160
158
|
localVersion: e.version,
|
|
161
|
-
remoteVersion:
|
|
159
|
+
remoteVersion: r.version,
|
|
162
160
|
timestamp: e.timestamp
|
|
163
161
|
};
|
|
164
|
-
n.push(
|
|
165
|
-
const o = this.config.onConflict(
|
|
166
|
-
await this._resolveConflict(e,
|
|
162
|
+
n.push(s);
|
|
163
|
+
const o = this.config.onConflict(s);
|
|
164
|
+
await this._resolveConflict(e, r, o), t.push(e.key), this.pendingQueue.delete(e.key);
|
|
167
165
|
} else await this._pushChange(e), t.push(e.key), this.pendingQueue.delete(e.key); else await this._pushChange(e),
|
|
168
166
|
t.push(e.key), this.pendingQueue.delete(e.key);
|
|
169
167
|
} catch (t) {
|
|
170
|
-
|
|
168
|
+
r.push(`Failed to sync "${e.key}": ${t}`);
|
|
171
169
|
}
|
|
172
170
|
const o = {
|
|
173
|
-
success: 0 ===
|
|
171
|
+
success: 0 === r.length,
|
|
174
172
|
syncedKeys: t,
|
|
175
173
|
conflicts: n,
|
|
176
|
-
errors:
|
|
174
|
+
errors: r,
|
|
177
175
|
timestamp: Date.now(),
|
|
178
176
|
duration: Date.now() - e
|
|
179
177
|
};
|
|
180
178
|
return this.config.onSync(o), o;
|
|
181
|
-
} catch (
|
|
182
|
-
const o = `Sync failed: ${
|
|
183
|
-
return
|
|
179
|
+
} catch (s) {
|
|
180
|
+
const o = `Sync failed: ${s}`;
|
|
181
|
+
return r.push(o), {
|
|
184
182
|
success: !1,
|
|
185
183
|
syncedKeys: t,
|
|
186
184
|
conflicts: n,
|
|
187
|
-
errors:
|
|
185
|
+
errors: r,
|
|
188
186
|
timestamp: Date.now(),
|
|
189
187
|
duration: Date.now() - e
|
|
190
188
|
};
|
|
@@ -215,7 +213,7 @@ var m = f({
|
|
|
215
213
|
async _pushChange(e) {
|
|
216
214
|
let t = 0;
|
|
217
215
|
for (;t < this.config.maxRetries; ) try {
|
|
218
|
-
const n = this._getAuthToken(),
|
|
216
|
+
const n = this._getAuthToken(), r = await this.config.fetch(`${this.config.endpoint}/sync`, {
|
|
219
217
|
method: "POST",
|
|
220
218
|
headers: {
|
|
221
219
|
"Content-Type": "application/json",
|
|
@@ -230,8 +228,8 @@ var m = f({
|
|
|
230
228
|
timestamp: e.timestamp
|
|
231
229
|
})
|
|
232
230
|
});
|
|
233
|
-
if (
|
|
234
|
-
const t = await
|
|
231
|
+
if (r.ok) {
|
|
232
|
+
const t = await r.json();
|
|
235
233
|
return void (t.version && this.remoteVersions.set(e.key, {
|
|
236
234
|
version: t.version,
|
|
237
235
|
timestamp: t.timestamp || Date.now(),
|
|
@@ -288,9 +286,479 @@ var m = f({
|
|
|
288
286
|
this.syncTimer && clearTimeout(this.syncTimer), this.pendingQueue.clear(), this.onlineStatusListeners.clear(),
|
|
289
287
|
this.syncStateListeners.clear();
|
|
290
288
|
}
|
|
291
|
-
},
|
|
289
|
+
}, l = (e, t) => new c(e, t);
|
|
290
|
+
}
|
|
291
|
+
}), g = Symbol.for("immer-nothing"), m = Symbol.for("immer-draftable"), _ = Symbol.for("immer-state"), S = [ function(e) {
|
|
292
|
+
return `The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`;
|
|
293
|
+
}, function(e) {
|
|
294
|
+
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 '${e}'`;
|
|
295
|
+
}, "This object has been frozen and should not be mutated", function(e) {
|
|
296
|
+
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + e;
|
|
297
|
+
}, "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.", "Immer forbids circular references", "The first or second argument to `produce` must be a function", "The third argument to `produce` must be a function or undefined", "First argument to `createDraft` must be a plain object, an array, or an immerable object", "First argument to `finishDraft` must be a draft returned by `createDraft`", function(e) {
|
|
298
|
+
return `'current' expects a draft, got: ${e}`;
|
|
299
|
+
}, "Object.defineProperty() cannot be used on an Immer draft", "Object.setPrototypeOf() cannot be used on an Immer draft", "Immer only supports deleting array indices", "Immer only supports setting array indices and the 'length' property", function(e) {
|
|
300
|
+
return `'original' expects a draft, got: ${e}`;
|
|
301
|
+
} ];
|
|
302
|
+
|
|
303
|
+
function w(e, ...t) {
|
|
304
|
+
{
|
|
305
|
+
const n = S[e], r = K(n) ? n.apply(null, t) : n;
|
|
306
|
+
throw new Error(`[Immer] ${r}`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
var b = Object, v = b.getPrototypeOf, k = "constructor", E = "prototype", O = "configurable", C = "enumerable", D = "writable", M = "value", A = e => !!e && !!e[_];
|
|
311
|
+
|
|
312
|
+
function R(e) {
|
|
313
|
+
return !!e && (T(e) || N(e) || !!e[m] || !!e[k]?.[m] || U(e) || L(e));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
var j = b[E][k].toString(), P = new WeakMap;
|
|
317
|
+
|
|
318
|
+
function T(e) {
|
|
319
|
+
if (!e || !F(e)) return !1;
|
|
320
|
+
const t = v(e);
|
|
321
|
+
if (null === t || t === b[E]) return !0;
|
|
322
|
+
const n = b.hasOwnProperty.call(t, k) && t[k];
|
|
323
|
+
if (n === Object) return !0;
|
|
324
|
+
if (!K(n)) return !1;
|
|
325
|
+
let r = P.get(n);
|
|
326
|
+
return void 0 === r && (r = Function.toString.call(n), P.set(n, r)), r === j;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function I(e, t, n = !0) {
|
|
330
|
+
if (0 === z(e)) {
|
|
331
|
+
(n ? Reflect.ownKeys(e) : b.keys(e)).forEach(n => {
|
|
332
|
+
t(n, e[n], e);
|
|
333
|
+
});
|
|
334
|
+
} else e.forEach((n, r) => t(r, n, e));
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function z(e) {
|
|
338
|
+
const t = e[_];
|
|
339
|
+
return t ? t.type_ : N(e) ? 1 : U(e) ? 2 : L(e) ? 3 : 0;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
var V = (e, t, n = z(e)) => 2 === n ? e.has(t) : b[E].hasOwnProperty.call(e, t), $ = (e, t, n = z(e)) => 2 === n ? e.get(t) : e[t], x = (e, t, n, r = z(e)) => {
|
|
343
|
+
2 === r ? e.set(t, n) : 3 === r ? e.add(n) : e[t] = n;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
var N = Array.isArray, U = e => e instanceof Map, L = e => e instanceof Set, F = e => "object" == typeof e, K = e => "function" == typeof e, J = e => "boolean" == typeof e;
|
|
347
|
+
|
|
348
|
+
var B = e => e.copy_ || e.base_, W = e => e.modified_ ? e.copy_ : e.base_;
|
|
349
|
+
|
|
350
|
+
function Q(e, t) {
|
|
351
|
+
if (U(e)) return new Map(e);
|
|
352
|
+
if (L(e)) return new Set(e);
|
|
353
|
+
if (N(e)) return Array[E].slice.call(e);
|
|
354
|
+
const n = T(e);
|
|
355
|
+
if (!0 === t || "class_only" === t && !n) {
|
|
356
|
+
const t = b.getOwnPropertyDescriptors(e);
|
|
357
|
+
delete t[_];
|
|
358
|
+
let n = Reflect.ownKeys(t);
|
|
359
|
+
for (let r = 0; r < n.length; r++) {
|
|
360
|
+
const s = n[r], o = t[s];
|
|
361
|
+
!1 === o[D] && (o[D] = !0, o[O] = !0), (o.get || o.set) && (t[s] = {
|
|
362
|
+
[O]: !0,
|
|
363
|
+
[D]: !0,
|
|
364
|
+
[C]: o[C],
|
|
365
|
+
[M]: e[s]
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
return b.create(v(e), t);
|
|
369
|
+
}
|
|
370
|
+
{
|
|
371
|
+
const t = v(e);
|
|
372
|
+
if (null !== t && n) return {
|
|
373
|
+
...e
|
|
374
|
+
};
|
|
375
|
+
const r = b.create(t);
|
|
376
|
+
return b.assign(r, e);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function G(e, t = !1) {
|
|
381
|
+
return X(e) || A(e) || !R(e) || (z(e) > 1 && b.defineProperties(e, {
|
|
382
|
+
set: q,
|
|
383
|
+
add: q,
|
|
384
|
+
clear: q,
|
|
385
|
+
delete: q
|
|
386
|
+
}), b.freeze(e), t && I(e, (e, t) => {
|
|
387
|
+
G(t, !0);
|
|
388
|
+
}, !1)), e;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
var q = {
|
|
392
|
+
[M]: function() {
|
|
393
|
+
w(2);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
function X(e) {
|
|
398
|
+
return null === e || !F(e) || b.isFrozen(e);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
var Z = "MapSet", H = "Patches", Y = "ArrayMethods", ee = {};
|
|
402
|
+
|
|
403
|
+
function te(e) {
|
|
404
|
+
const t = ee[e];
|
|
405
|
+
return t || w(0, e), t;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
var ne, re = e => !!ee[e], se = () => ne;
|
|
409
|
+
|
|
410
|
+
function oe(e, t) {
|
|
411
|
+
t && (e.patchPlugin_ = te(H), e.patches_ = [], e.inversePatches_ = [], e.patchListener_ = t);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function ae(e) {
|
|
415
|
+
ie(e), e.drafts_.forEach(le), e.drafts_ = null;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function ie(e) {
|
|
419
|
+
e === ne && (ne = e.parent_);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
var ce = e => ne = {
|
|
423
|
+
drafts_: [],
|
|
424
|
+
parent_: ne,
|
|
425
|
+
immer_: e,
|
|
426
|
+
canAutoFreeze_: !0,
|
|
427
|
+
unfinalizedDrafts_: 0,
|
|
428
|
+
handledSet_: new Set,
|
|
429
|
+
processedForPatches_: new Set,
|
|
430
|
+
mapSetPlugin_: re(Z) ? te(Z) : void 0,
|
|
431
|
+
arrayMethodsPlugin_: re(Y) ? te(Y) : void 0
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
function le(e) {
|
|
435
|
+
const t = e[_];
|
|
436
|
+
0 === t.type_ || 1 === t.type_ ? t.revoke_() : t.revoked_ = !0;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function ue(e, t) {
|
|
440
|
+
t.unfinalizedDrafts_ = t.drafts_.length;
|
|
441
|
+
const n = t.drafts_[0];
|
|
442
|
+
if (void 0 !== e && e !== n) {
|
|
443
|
+
n[_].modified_ && (ae(t), w(4)), R(e) && (e = de(t, e));
|
|
444
|
+
const {patchPlugin_: r} = t;
|
|
445
|
+
r && r.generateReplacementPatches_(n[_].base_, e, t);
|
|
446
|
+
} else e = de(t, n);
|
|
447
|
+
return function(e, t, n = !1) {
|
|
448
|
+
!e.parent_ && e.immer_.autoFreeze_ && e.canAutoFreeze_ && G(t, n);
|
|
449
|
+
}(t, e, !0), ae(t), t.patches_ && t.patchListener_(t.patches_, t.inversePatches_),
|
|
450
|
+
e !== g ? e : void 0;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function de(e, t) {
|
|
454
|
+
if (X(t)) return t;
|
|
455
|
+
const n = t[_];
|
|
456
|
+
if (!n) {
|
|
457
|
+
return me(t, e.handledSet_, e);
|
|
458
|
+
}
|
|
459
|
+
if (!ye(n, e)) return t;
|
|
460
|
+
if (!n.modified_) return n.base_;
|
|
461
|
+
if (!n.finalized_) {
|
|
462
|
+
const {callbacks_: t} = n;
|
|
463
|
+
if (t) for (;t.length > 0; ) {
|
|
464
|
+
t.pop()(e);
|
|
465
|
+
}
|
|
466
|
+
ge(n, e);
|
|
467
|
+
}
|
|
468
|
+
return n.copy_;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function fe(e) {
|
|
472
|
+
e.finalized_ = !0, e.scope_.unfinalizedDrafts_--;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
var ye = (e, t) => e.scope_ === t, pe = [];
|
|
476
|
+
|
|
477
|
+
function he(e, t, n, r) {
|
|
478
|
+
const s = B(e), o = e.type_;
|
|
479
|
+
if (void 0 !== r) {
|
|
480
|
+
if ($(s, r, o) === t) return void x(s, r, n, o);
|
|
481
|
+
}
|
|
482
|
+
if (!e.draftLocations_) {
|
|
483
|
+
const t = e.draftLocations_ = new Map;
|
|
484
|
+
I(s, (e, n) => {
|
|
485
|
+
if (A(n)) {
|
|
486
|
+
const r = t.get(n) || [];
|
|
487
|
+
r.push(e), t.set(n, r);
|
|
488
|
+
}
|
|
489
|
+
});
|
|
292
490
|
}
|
|
293
|
-
|
|
491
|
+
const a = e.draftLocations_.get(t) ?? pe;
|
|
492
|
+
for (const e of a) x(s, e, n, o);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function ge(e, t) {
|
|
496
|
+
if (e.modified_ && !e.finalized_ && (3 === e.type_ || 1 === e.type_ && e.allIndicesReassigned_ || (e.assigned_?.size ?? 0) > 0)) {
|
|
497
|
+
const {patchPlugin_: n} = t;
|
|
498
|
+
if (n) {
|
|
499
|
+
const r = n.getPath(e);
|
|
500
|
+
r && n.generatePatches_(e, r, t);
|
|
501
|
+
}
|
|
502
|
+
fe(e);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function me(e, t, n) {
|
|
507
|
+
return !n.immer_.autoFreeze_ && n.unfinalizedDrafts_ < 1 || A(e) || t.has(e) || !R(e) || X(e) || (t.add(e),
|
|
508
|
+
I(e, (r, s) => {
|
|
509
|
+
if (A(s)) {
|
|
510
|
+
const t = s[_];
|
|
511
|
+
if (ye(t, n)) {
|
|
512
|
+
const n = W(t);
|
|
513
|
+
x(e, r, n, e.type_), fe(t);
|
|
514
|
+
}
|
|
515
|
+
} else R(s) && me(s, t, n);
|
|
516
|
+
})), e;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
var _e = {
|
|
520
|
+
get(e, t) {
|
|
521
|
+
if (t === _) return e;
|
|
522
|
+
let n = e.scope_.arrayMethodsPlugin_;
|
|
523
|
+
const r = 1 === e.type_ && "string" == typeof t;
|
|
524
|
+
if (r && n?.isArrayOperationMethod(t)) return n.createMethodInterceptor(e, t);
|
|
525
|
+
const s = B(e);
|
|
526
|
+
if (!V(s, t, e.type_)) return function(e, t, n) {
|
|
527
|
+
const r = be(t, n);
|
|
528
|
+
return r ? M in r ? r[M] : r.get?.call(e.draft_) : void 0;
|
|
529
|
+
}(e, s, t);
|
|
530
|
+
const o = s[t];
|
|
531
|
+
if (e.finalized_ || !R(o)) return o;
|
|
532
|
+
if (r && e.operationMethod && n?.isMutatingArrayMethod(e.operationMethod) && function(e) {
|
|
533
|
+
const t = +e;
|
|
534
|
+
return Number.isInteger(t) && String(t) === e;
|
|
535
|
+
}(t)) return o;
|
|
536
|
+
if (o === we(e.base_, t)) {
|
|
537
|
+
ke(e);
|
|
538
|
+
const n = 1 === e.type_ ? +t : t, r = Ee(e.scope_, o, e, n);
|
|
539
|
+
return e.copy_[n] = r;
|
|
540
|
+
}
|
|
541
|
+
return o;
|
|
542
|
+
},
|
|
543
|
+
has: (e, t) => t in B(e),
|
|
544
|
+
ownKeys: e => Reflect.ownKeys(B(e)),
|
|
545
|
+
set(e, t, n) {
|
|
546
|
+
const r = be(B(e), t);
|
|
547
|
+
if (r?.set) return r.set.call(e.draft_, n), !0;
|
|
548
|
+
if (!e.modified_) {
|
|
549
|
+
const r = we(B(e), t), a = r?.[_];
|
|
550
|
+
if (a && a.base_ === n) return e.copy_[t] = n, e.assigned_.set(t, !1), !0;
|
|
551
|
+
if (((s = n) === (o = r) ? 0 !== s || 1 / s == 1 / o : s != s && o != o) && (void 0 !== n || V(e.base_, t, e.type_))) return !0;
|
|
552
|
+
ke(e), ve(e);
|
|
553
|
+
}
|
|
554
|
+
var s, o;
|
|
555
|
+
return e.copy_[t] === n && (void 0 !== n || t in e.copy_) || Number.isNaN(n) && Number.isNaN(e.copy_[t]) || (e.copy_[t] = n,
|
|
556
|
+
e.assigned_.set(t, !0), function(e, t, n) {
|
|
557
|
+
const {scope_: r} = e;
|
|
558
|
+
if (A(n)) {
|
|
559
|
+
const s = n[_];
|
|
560
|
+
ye(s, r) && s.callbacks_.push(function() {
|
|
561
|
+
ke(e);
|
|
562
|
+
const r = W(s);
|
|
563
|
+
he(e, n, r, t);
|
|
564
|
+
});
|
|
565
|
+
} else R(n) && e.callbacks_.push(function() {
|
|
566
|
+
const s = B(e);
|
|
567
|
+
3 === e.type_ ? s.has(n) && me(n, r.handledSet_, r) : $(s, t, e.type_) === n && r.drafts_.length > 1 && !0 === (e.assigned_.get(t) ?? !1) && e.copy_ && me($(e.copy_, t, e.type_), r.handledSet_, r);
|
|
568
|
+
});
|
|
569
|
+
}(e, t, n)), !0;
|
|
570
|
+
},
|
|
571
|
+
deleteProperty: (e, t) => (ke(e), void 0 !== we(e.base_, t) || t in e.base_ ? (e.assigned_.set(t, !1),
|
|
572
|
+
ve(e)) : e.assigned_.delete(t), e.copy_ && delete e.copy_[t], !0),
|
|
573
|
+
getOwnPropertyDescriptor(e, t) {
|
|
574
|
+
const n = B(e), r = Reflect.getOwnPropertyDescriptor(n, t);
|
|
575
|
+
return r ? {
|
|
576
|
+
[D]: !0,
|
|
577
|
+
[O]: 1 !== e.type_ || "length" !== t,
|
|
578
|
+
[C]: r[C],
|
|
579
|
+
[M]: n[t]
|
|
580
|
+
} : r;
|
|
581
|
+
},
|
|
582
|
+
defineProperty() {
|
|
583
|
+
w(11);
|
|
584
|
+
},
|
|
585
|
+
getPrototypeOf: e => v(e.base_),
|
|
586
|
+
setPrototypeOf() {
|
|
587
|
+
w(12);
|
|
588
|
+
}
|
|
589
|
+
}, Se = {};
|
|
590
|
+
|
|
591
|
+
for (let e in _e) {
|
|
592
|
+
let t = _e[e];
|
|
593
|
+
Se[e] = function() {
|
|
594
|
+
const e = arguments;
|
|
595
|
+
return e[0] = e[0][0], t.apply(this, e);
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function we(e, t) {
|
|
600
|
+
const n = e[_];
|
|
601
|
+
return (n ? B(n) : e)[t];
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function be(e, t) {
|
|
605
|
+
if (!(t in e)) return;
|
|
606
|
+
let n = v(e);
|
|
607
|
+
for (;n; ) {
|
|
608
|
+
const e = Object.getOwnPropertyDescriptor(n, t);
|
|
609
|
+
if (e) return e;
|
|
610
|
+
n = v(n);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function ve(e) {
|
|
615
|
+
e.modified_ || (e.modified_ = !0, e.parent_ && ve(e.parent_));
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function ke(e) {
|
|
619
|
+
e.copy_ || (e.assigned_ = new Map, e.copy_ = Q(e.base_, e.scope_.immer_.useStrictShallowCopy_));
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
Se.deleteProperty = function(e, t) {
|
|
623
|
+
return isNaN(parseInt(t)) && w(13), Se.set.call(this, e, t, void 0);
|
|
624
|
+
}, Se.set = function(e, t, n) {
|
|
625
|
+
return "length" !== t && isNaN(parseInt(t)) && w(14), _e.set.call(this, e[0], t, n, e[0]);
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
function Ee(e, t, n, r) {
|
|
629
|
+
const [s, o] = U(t) ? te(Z).proxyMap_(t, n) : L(t) ? te(Z).proxySet_(t, n) : function(e, t) {
|
|
630
|
+
const n = N(e), r = {
|
|
631
|
+
type_: n ? 1 : 0,
|
|
632
|
+
scope_: t ? t.scope_ : se(),
|
|
633
|
+
modified_: !1,
|
|
634
|
+
finalized_: !1,
|
|
635
|
+
assigned_: void 0,
|
|
636
|
+
parent_: t,
|
|
637
|
+
base_: e,
|
|
638
|
+
draft_: null,
|
|
639
|
+
copy_: null,
|
|
640
|
+
revoke_: null,
|
|
641
|
+
isManual_: !1,
|
|
642
|
+
callbacks_: void 0
|
|
643
|
+
};
|
|
644
|
+
let s = r, o = _e;
|
|
645
|
+
n && (s = [ r ], o = Se);
|
|
646
|
+
const {revoke: a, proxy: i} = Proxy.revocable(s, o);
|
|
647
|
+
return r.draft_ = i, r.revoke_ = a, [ i, r ];
|
|
648
|
+
}(t, n);
|
|
649
|
+
return (n?.scope_ ?? se()).drafts_.push(s), o.callbacks_ = n?.callbacks_ ?? [],
|
|
650
|
+
o.key_ = r, n && void 0 !== r ? function(e, t, n) {
|
|
651
|
+
e.callbacks_.push(function(r) {
|
|
652
|
+
const s = t;
|
|
653
|
+
if (!s || !ye(s, r)) return;
|
|
654
|
+
r.mapSetPlugin_?.fixSetContents(s);
|
|
655
|
+
const o = W(s);
|
|
656
|
+
he(e, s.draft_ ?? s, o, n), ge(s, r);
|
|
657
|
+
});
|
|
658
|
+
}(n, o, r) : o.callbacks_.push(function(e) {
|
|
659
|
+
e.mapSetPlugin_?.fixSetContents(o);
|
|
660
|
+
const {patchPlugin_: t} = e;
|
|
661
|
+
o.modified_ && t && t.generatePatches_(o, [], e);
|
|
662
|
+
}), s;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
function Oe(e) {
|
|
666
|
+
if (!R(e) || X(e)) return e;
|
|
667
|
+
const t = e[_];
|
|
668
|
+
let n, r = !0;
|
|
669
|
+
if (t) {
|
|
670
|
+
if (!t.modified_) return t.base_;
|
|
671
|
+
t.finalized_ = !0, n = Q(e, t.scope_.immer_.useStrictShallowCopy_), r = t.scope_.immer_.shouldUseStrictIteration();
|
|
672
|
+
} else n = Q(e, !0);
|
|
673
|
+
return I(n, (e, t) => {
|
|
674
|
+
x(n, e, Oe(t));
|
|
675
|
+
}, r), t && (t.finalized_ = !1), n;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
var Ce = (new class {
|
|
679
|
+
constructor(e) {
|
|
680
|
+
this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.useStrictIteration_ = !1,
|
|
681
|
+
this.produce = (e, t, n) => {
|
|
682
|
+
if (K(e) && !K(t)) {
|
|
683
|
+
const n = t;
|
|
684
|
+
t = e;
|
|
685
|
+
const r = this;
|
|
686
|
+
return function(e = n, ...s) {
|
|
687
|
+
return r.produce(e, e => t.call(this, e, ...s));
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
let r;
|
|
691
|
+
if (K(t) || w(6), void 0 === n || K(n) || w(7), R(e)) {
|
|
692
|
+
const s = ce(this), o = Ee(s, e, void 0);
|
|
693
|
+
let a = !0;
|
|
694
|
+
try {
|
|
695
|
+
r = t(o), a = !1;
|
|
696
|
+
} finally {
|
|
697
|
+
a ? ae(s) : ie(s);
|
|
698
|
+
}
|
|
699
|
+
return oe(s, n), ue(r, s);
|
|
700
|
+
}
|
|
701
|
+
if (!e || !F(e)) {
|
|
702
|
+
if (r = t(e), void 0 === r && (r = e), r === g && (r = void 0), this.autoFreeze_ && G(r, !0),
|
|
703
|
+
n) {
|
|
704
|
+
const t = [], s = [];
|
|
705
|
+
te(H).generateReplacementPatches_(e, r, {
|
|
706
|
+
patches_: t,
|
|
707
|
+
inversePatches_: s
|
|
708
|
+
}), n(t, s);
|
|
709
|
+
}
|
|
710
|
+
return r;
|
|
711
|
+
}
|
|
712
|
+
w(1, e);
|
|
713
|
+
}, this.produceWithPatches = (e, t) => {
|
|
714
|
+
if (K(e)) return (t, ...n) => this.produceWithPatches(t, t => e(t, ...n));
|
|
715
|
+
let n, r;
|
|
716
|
+
return [ this.produce(e, t, (e, t) => {
|
|
717
|
+
n = e, r = t;
|
|
718
|
+
}), n, r ];
|
|
719
|
+
}, J(e?.autoFreeze) && this.setAutoFreeze(e.autoFreeze), J(e?.useStrictShallowCopy) && this.setUseStrictShallowCopy(e.useStrictShallowCopy),
|
|
720
|
+
J(e?.useStrictIteration) && this.setUseStrictIteration(e.useStrictIteration);
|
|
721
|
+
}
|
|
722
|
+
createDraft(e) {
|
|
723
|
+
R(e) || w(8), A(e) && (e = function(e) {
|
|
724
|
+
A(e) || w(10, e);
|
|
725
|
+
return Oe(e);
|
|
726
|
+
}(e));
|
|
727
|
+
const t = ce(this), n = Ee(t, e, void 0);
|
|
728
|
+
return n[_].isManual_ = !0, ie(t), n;
|
|
729
|
+
}
|
|
730
|
+
finishDraft(e, t) {
|
|
731
|
+
const n = e && e[_];
|
|
732
|
+
n && n.isManual_ || w(9);
|
|
733
|
+
const {scope_: r} = n;
|
|
734
|
+
return oe(r, t), ue(void 0, r);
|
|
735
|
+
}
|
|
736
|
+
setAutoFreeze(e) {
|
|
737
|
+
this.autoFreeze_ = e;
|
|
738
|
+
}
|
|
739
|
+
setUseStrictShallowCopy(e) {
|
|
740
|
+
this.useStrictShallowCopy_ = e;
|
|
741
|
+
}
|
|
742
|
+
setUseStrictIteration(e) {
|
|
743
|
+
this.useStrictIteration_ = e;
|
|
744
|
+
}
|
|
745
|
+
shouldUseStrictIteration() {
|
|
746
|
+
return this.useStrictIteration_;
|
|
747
|
+
}
|
|
748
|
+
applyPatches(e, t) {
|
|
749
|
+
let n;
|
|
750
|
+
for (n = t.length - 1; n >= 0; n--) {
|
|
751
|
+
const r = t[n];
|
|
752
|
+
if (0 === r.path.length && "replace" === r.op) {
|
|
753
|
+
e = r.value;
|
|
754
|
+
break;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
n > -1 && (t = t.slice(n + 1));
|
|
758
|
+
const r = te(H).applyPatches_;
|
|
759
|
+
return A(e) ? r(e, t) : this.produce(e, e => r(e, t));
|
|
760
|
+
}
|
|
761
|
+
}).produce, De = (e, t) => {
|
|
294
762
|
const n = Date.now();
|
|
295
763
|
if (/\(\.*\+\?\)\+/.test(e) || /\(\.*\?\)\*/.test(e)) return !1;
|
|
296
764
|
if (e.length > 500) return !1;
|
|
@@ -301,28 +769,28 @@ var m = f({
|
|
|
301
769
|
} catch {
|
|
302
770
|
return !1;
|
|
303
771
|
}
|
|
304
|
-
},
|
|
772
|
+
}, Me = () => {
|
|
305
773
|
if ("undefined" != typeof crypto && "function" == typeof crypto.randomUUID) try {
|
|
306
774
|
return crypto.randomUUID();
|
|
307
775
|
} catch {}
|
|
308
776
|
throw new Error("Cryptographically secure random UUID generation is required but crypto.randomUUID is unavailable. Please use a browser or environment with Web Crypto API support.");
|
|
309
|
-
},
|
|
310
|
-
if (!
|
|
311
|
-
const
|
|
777
|
+
}, Ae = "undefined" != typeof crypto && void 0 !== crypto.subtle && "function" == typeof crypto.subtle.generateKey, Re = async (e, t, n = 6e5) => {
|
|
778
|
+
if (!Ae) throw new Error("Web Crypto API not available");
|
|
779
|
+
const r = await crypto.subtle.importKey("raw", (new TextEncoder).encode(e), "PBKDF2", !1, [ "deriveKey" ]);
|
|
312
780
|
return {
|
|
313
781
|
key: await crypto.subtle.deriveKey({
|
|
314
782
|
name: "PBKDF2",
|
|
315
783
|
salt: new Uint8Array(t),
|
|
316
784
|
iterations: n,
|
|
317
785
|
hash: "SHA-256"
|
|
318
|
-
},
|
|
786
|
+
}, r, {
|
|
319
787
|
name: "AES-GCM",
|
|
320
788
|
length: 256
|
|
321
789
|
}, !0, [ "encrypt", "decrypt" ]),
|
|
322
790
|
iv: crypto.getRandomValues(new Uint8Array(12))
|
|
323
791
|
};
|
|
324
|
-
},
|
|
325
|
-
if (!
|
|
792
|
+
}, je = (e = 32) => crypto.getRandomValues(new Uint8Array(e)), Pe = async () => {
|
|
793
|
+
if (!Ae) throw new Error("Web Crypto API not available");
|
|
326
794
|
return {
|
|
327
795
|
key: await crypto.subtle.generateKey({
|
|
328
796
|
name: "AES-GCM",
|
|
@@ -330,47 +798,47 @@ var m = f({
|
|
|
330
798
|
}, !0, [ "encrypt", "decrypt" ]),
|
|
331
799
|
iv: crypto.getRandomValues(new Uint8Array(12))
|
|
332
800
|
};
|
|
333
|
-
},
|
|
801
|
+
}, Te = async e => {
|
|
334
802
|
const t = await crypto.subtle.exportKey("raw", e.key);
|
|
335
803
|
return {
|
|
336
804
|
key: btoa(String.fromCharCode(...new Uint8Array(t))),
|
|
337
805
|
iv: btoa(String.fromCharCode(...e.iv))
|
|
338
806
|
};
|
|
339
|
-
},
|
|
340
|
-
const n = Uint8Array.from(atob(e), e => e.charCodeAt(0)),
|
|
807
|
+
}, Ie = async (e, t) => {
|
|
808
|
+
const n = Uint8Array.from(atob(e), e => e.charCodeAt(0)), r = Uint8Array.from(atob(t), e => e.charCodeAt(0));
|
|
341
809
|
return {
|
|
342
810
|
key: await crypto.subtle.importKey("raw", n, {
|
|
343
811
|
name: "AES-GCM",
|
|
344
812
|
length: 256
|
|
345
813
|
}, !0, [ "encrypt", "decrypt" ]),
|
|
346
|
-
iv:
|
|
814
|
+
iv: r
|
|
347
815
|
};
|
|
348
|
-
},
|
|
349
|
-
const n = (new TextEncoder).encode(JSON.stringify(e)),
|
|
816
|
+
}, ze = async (e, t) => {
|
|
817
|
+
const n = (new TextEncoder).encode(JSON.stringify(e)), r = await crypto.subtle.encrypt({
|
|
350
818
|
name: "AES-GCM",
|
|
351
819
|
iv: t.iv
|
|
352
|
-
}, t.key, n),
|
|
353
|
-
return
|
|
354
|
-
},
|
|
355
|
-
const n = Uint8Array.from(atob(e), e => e.charCodeAt(0)),
|
|
820
|
+
}, t.key, n), s = new Uint8Array(t.iv.length + r.byteLength);
|
|
821
|
+
return s.set(t.iv), s.set(new Uint8Array(r), t.iv.length), btoa(String.fromCharCode(...s));
|
|
822
|
+
}, Ve = async (e, t) => {
|
|
823
|
+
const n = Uint8Array.from(atob(e), e => e.charCodeAt(0)), r = n.slice(0, 12), s = n.slice(12), o = await crypto.subtle.decrypt({
|
|
356
824
|
name: "AES-GCM",
|
|
357
|
-
iv:
|
|
358
|
-
}, t.key,
|
|
825
|
+
iv: r
|
|
826
|
+
}, t.key, s);
|
|
359
827
|
return JSON.parse((new TextDecoder).decode(o));
|
|
360
|
-
},
|
|
361
|
-
|
|
362
|
-
},
|
|
363
|
-
|
|
364
|
-
},
|
|
828
|
+
}, $e = null, xe = e => {
|
|
829
|
+
$e = e;
|
|
830
|
+
}, Ne = e => {
|
|
831
|
+
$e && $e(e);
|
|
832
|
+
}, Ue = (e, t, n) => {
|
|
365
833
|
e.set(t instanceof RegExp ? t.source : t, n);
|
|
366
|
-
},
|
|
834
|
+
}, Le = (e, t, n, r) => {
|
|
367
835
|
if (0 === e.size) return !0;
|
|
368
|
-
for (const [
|
|
836
|
+
for (const [s, o] of e) {
|
|
369
837
|
let e;
|
|
370
|
-
if (e = "function" == typeof
|
|
838
|
+
if (e = "function" == typeof s ? s(t, r) : De(s, t), e) return o.includes(n) || o.includes("admin");
|
|
371
839
|
}
|
|
372
840
|
return !1;
|
|
373
|
-
},
|
|
841
|
+
}, Fe = e => {
|
|
374
842
|
if ("string" == typeof e) {
|
|
375
843
|
let t = e.replace(/&#[xX]?[0-9a-fA-F]+;?/g, e => {
|
|
376
844
|
const t = e.match(/&#x([0-9a-fA-F]+);?/i);
|
|
@@ -386,35 +854,35 @@ var m = f({
|
|
|
386
854
|
if (e && "object" == typeof e && !Array.isArray(e)) {
|
|
387
855
|
if (Object.getPrototypeOf(e) === Object.prototype) {
|
|
388
856
|
const t = {};
|
|
389
|
-
for (const [n,
|
|
857
|
+
for (const [n, r] of Object.entries(e)) t[n] = Fe(r);
|
|
390
858
|
return t;
|
|
391
859
|
}
|
|
392
860
|
return e;
|
|
393
861
|
}
|
|
394
|
-
return Array.isArray(e) ? e.map(e =>
|
|
395
|
-
},
|
|
396
|
-
const
|
|
397
|
-
id:
|
|
862
|
+
return Array.isArray(e) ? e.map(e => Fe(e)) : e;
|
|
863
|
+
}, Ke = e => /^([a-zA-Z0-9_.-][a-zA-Z0-9_.-]*)$/.test(e) && e.length <= 256 && e.length > 0, Je = (e, t, n, r) => {
|
|
864
|
+
const s = {
|
|
865
|
+
id: Me(),
|
|
398
866
|
purpose: n,
|
|
399
|
-
granted:
|
|
867
|
+
granted: r,
|
|
400
868
|
timestamp: Date.now()
|
|
401
869
|
}, o = e.get(t) || [];
|
|
402
|
-
return o.push(
|
|
870
|
+
return o.push(s), e.set(t, o), Ne({
|
|
403
871
|
timestamp: Date.now(),
|
|
404
872
|
action: "set",
|
|
405
873
|
key: `consent:${n}`,
|
|
406
874
|
userId: t,
|
|
407
875
|
success: !0
|
|
408
|
-
}),
|
|
876
|
+
}), s;
|
|
409
877
|
};
|
|
410
878
|
|
|
411
|
-
|
|
879
|
+
y();
|
|
412
880
|
|
|
413
|
-
var
|
|
881
|
+
var Be = e => `${e}_`;
|
|
414
882
|
|
|
415
|
-
|
|
883
|
+
y();
|
|
416
884
|
|
|
417
|
-
var
|
|
885
|
+
var We = () => {
|
|
418
886
|
try {
|
|
419
887
|
0;
|
|
420
888
|
const e = "undefined" != typeof globalThis ? globalThis : "undefined" != typeof window ? window : {};
|
|
@@ -422,31 +890,31 @@ var x = () => {
|
|
|
422
890
|
} catch {
|
|
423
891
|
return !1;
|
|
424
892
|
}
|
|
425
|
-
},
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
let
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
}),
|
|
432
|
-
store:
|
|
433
|
-
versions:
|
|
434
|
-
sizes:
|
|
435
|
-
totalSize:
|
|
436
|
-
storage:
|
|
437
|
-
config:
|
|
438
|
-
diskQueue:
|
|
439
|
-
encryptionKey:
|
|
440
|
-
audit:
|
|
441
|
-
onError:
|
|
442
|
-
silent:
|
|
443
|
-
debounceTime:
|
|
444
|
-
currentVersion:
|
|
445
|
-
}),
|
|
893
|
+
}, Qe = () => "undefined" != typeof window ? window.localStorage : null, Ge = e => {
|
|
894
|
+
const t = new Map, n = new Map, r = new Map, s = new Set, o = new Map, c = new Set, l = new Map, u = new Map, d = new Map, f = new Map, y = new Map, g = new Map, m = new Map, _ = new Map, S = e?.namespace || "gstate", w = e?.silent ?? !1, b = e?.debounceTime ?? 150, v = e?.version ?? 0, k = e?.storage || Qe(), E = e?.onError, O = e?.maxObjectSize ?? 0, C = e?.maxTotalSize ?? 0, D = e?.encryptionKey ?? null, M = e?.validateInput ?? !0, A = e?.auditEnabled ?? !0, R = e?.userId, j = e?.immer ?? !0, P = e?.persistByDefault ?? e?.persistence ?? e?.persist ?? !1;
|
|
895
|
+
e?.accessRules && e.accessRules.forEach(e => Ue(m, e.pattern, e.permissions));
|
|
896
|
+
let T, I = !1, z = !1, V = !1, $ = 0, x = null, N = null;
|
|
897
|
+
const U = new Promise(e => {
|
|
898
|
+
T = e;
|
|
899
|
+
}), L = () => `${S}_`, F = () => ({
|
|
900
|
+
store: t,
|
|
901
|
+
versions: n,
|
|
902
|
+
sizes: r,
|
|
903
|
+
totalSize: $,
|
|
904
|
+
storage: k,
|
|
905
|
+
config: e || {},
|
|
906
|
+
diskQueue: y,
|
|
907
|
+
encryptionKey: D,
|
|
908
|
+
audit: W,
|
|
909
|
+
onError: E,
|
|
910
|
+
silent: w,
|
|
911
|
+
debounceTime: b,
|
|
912
|
+
currentVersion: v
|
|
913
|
+
}), K = () => ({
|
|
446
914
|
plugins: f,
|
|
447
|
-
onError:
|
|
448
|
-
silent:
|
|
449
|
-
}),
|
|
915
|
+
onError: E,
|
|
916
|
+
silent: w
|
|
917
|
+
}), J = e => {
|
|
450
918
|
if (null == e) return 0;
|
|
451
919
|
const t = typeof e;
|
|
452
920
|
if ("boolean" === t) return 4;
|
|
@@ -454,108 +922,108 @@ var x = () => {
|
|
|
454
922
|
if ("string" === t) return 2 * e.length;
|
|
455
923
|
if ("object" !== t) return 0;
|
|
456
924
|
let n = 0;
|
|
457
|
-
const
|
|
458
|
-
for (;
|
|
459
|
-
const e =
|
|
925
|
+
const r = [ e ], s = new WeakSet;
|
|
926
|
+
for (;r.length > 0; ) {
|
|
927
|
+
const e = r.pop();
|
|
460
928
|
if ("boolean" == typeof e) n += 4; else if ("number" == typeof e) n += 8; else if ("string" == typeof e) n += 2 * e.length; else if ("object" == typeof e && null !== e) {
|
|
461
929
|
const t = e;
|
|
462
|
-
if (
|
|
463
|
-
if (
|
|
464
|
-
|
|
930
|
+
if (s.has(t)) continue;
|
|
931
|
+
if (s.add(t), Array.isArray(t)) for (let e = 0; e < t.length; e++) r.push(t[e]); else for (const e of Object.keys(t)) n += 2 * e.length,
|
|
932
|
+
r.push(t[e]);
|
|
465
933
|
}
|
|
466
934
|
}
|
|
467
935
|
return n;
|
|
468
|
-
},
|
|
936
|
+
}, B = (e, t) => {
|
|
469
937
|
((e, t, n) => {
|
|
470
|
-
if (0 !== e.plugins.size) for (const
|
|
471
|
-
const
|
|
472
|
-
if (
|
|
473
|
-
|
|
474
|
-
} catch (
|
|
475
|
-
const o =
|
|
938
|
+
if (0 !== e.plugins.size) for (const r of e.plugins.values()) {
|
|
939
|
+
const s = r.hooks?.[t];
|
|
940
|
+
if (s) try {
|
|
941
|
+
s(n);
|
|
942
|
+
} catch (s) {
|
|
943
|
+
const o = s instanceof Error ? s : new Error(String(s));
|
|
476
944
|
e.onError ? e.onError(o, {
|
|
477
|
-
operation: `plugin:${
|
|
945
|
+
operation: `plugin:${r.name}:${t}`,
|
|
478
946
|
key: n.key
|
|
479
947
|
}) : e.silent;
|
|
480
948
|
}
|
|
481
949
|
}
|
|
482
|
-
})(
|
|
483
|
-
},
|
|
484
|
-
|
|
950
|
+
})(K(), e, t);
|
|
951
|
+
}, W = (e, t, n, r) => {
|
|
952
|
+
A && null !== $e && Ne && Ne({
|
|
485
953
|
timestamp: Date.now(),
|
|
486
954
|
action: e,
|
|
487
955
|
key: t,
|
|
488
|
-
userId:
|
|
956
|
+
userId: R,
|
|
489
957
|
success: n,
|
|
490
|
-
error:
|
|
958
|
+
error: r
|
|
491
959
|
});
|
|
492
|
-
},
|
|
493
|
-
const
|
|
494
|
-
if (!
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
if (!
|
|
498
|
-
const n =
|
|
499
|
-
n && (n.delete(e), 0 === n.size &&
|
|
960
|
+
}, Q = e => {
|
|
961
|
+
const t = u.get(e);
|
|
962
|
+
if (!t) return;
|
|
963
|
+
const r = new Set, s = t.selector(e => (r.add(e), u.has(e) ? u.get(e).lastValue : H.get(e)));
|
|
964
|
+
t.deps.forEach(t => {
|
|
965
|
+
if (!r.has(t)) {
|
|
966
|
+
const n = d.get(t);
|
|
967
|
+
n && (n.delete(e), 0 === n.size && d.delete(t));
|
|
500
968
|
}
|
|
501
|
-
}),
|
|
502
|
-
|
|
503
|
-
}),
|
|
504
|
-
|
|
505
|
-
},
|
|
969
|
+
}), r.forEach(n => {
|
|
970
|
+
t.deps.has(n) || (d.has(n) || d.set(n, new Set), d.get(n).add(e));
|
|
971
|
+
}), t.deps = r, i(t.lastValue, s) || (t.lastValue = j && null !== s && "object" == typeof s ? G(a(s), !0) : s,
|
|
972
|
+
n.set(e, (n.get(e) || 0) + 1), q(e));
|
|
973
|
+
}, q = e => {
|
|
506
974
|
if (e) {
|
|
507
|
-
if (
|
|
508
|
-
const t =
|
|
509
|
-
for (const e of t)
|
|
975
|
+
if (d.has(e)) {
|
|
976
|
+
const t = d.get(e);
|
|
977
|
+
for (const e of t) Q(e);
|
|
510
978
|
}
|
|
511
|
-
const t =
|
|
979
|
+
const t = l.get(e);
|
|
512
980
|
if (t) {
|
|
513
|
-
const n =
|
|
514
|
-
for (const
|
|
515
|
-
|
|
981
|
+
const n = H.get(e);
|
|
982
|
+
for (const r of t) try {
|
|
983
|
+
r(n);
|
|
516
984
|
} catch (t) {
|
|
517
985
|
const n = t instanceof Error ? t : new Error(String(t));
|
|
518
|
-
|
|
986
|
+
E && E(n, {
|
|
519
987
|
operation: "watcher",
|
|
520
988
|
key: e
|
|
521
989
|
});
|
|
522
990
|
}
|
|
523
991
|
}
|
|
524
|
-
const n =
|
|
992
|
+
const n = o.get(e);
|
|
525
993
|
if (n) for (const t of n) try {
|
|
526
994
|
t();
|
|
527
995
|
} catch (t) {
|
|
528
996
|
const n = t instanceof Error ? t : new Error(String(t));
|
|
529
|
-
|
|
997
|
+
E && E(n, {
|
|
530
998
|
operation: "keyListener",
|
|
531
999
|
key: e
|
|
532
1000
|
});
|
|
533
1001
|
}
|
|
534
1002
|
}
|
|
535
|
-
if (
|
|
1003
|
+
if (I) z = !0; else for (const e of s) try {
|
|
536
1004
|
e();
|
|
537
1005
|
} catch (e) {
|
|
538
1006
|
const t = e instanceof Error ? e : new Error(String(e));
|
|
539
|
-
|
|
1007
|
+
E && E(t, {
|
|
540
1008
|
operation: "listener"
|
|
541
1009
|
});
|
|
542
1010
|
}
|
|
543
|
-
},
|
|
1011
|
+
}, X = async () => {
|
|
544
1012
|
(async e => {
|
|
545
1013
|
if (!e.storage) return;
|
|
546
|
-
const {store: t, config: n, diskQueue:
|
|
1014
|
+
const {store: t, config: n, diskQueue: r, storage: s, encryptionKey: o, audit: a, onError: i, silent: c, currentVersion: l} = e, u = Be(n.namespace || "gstate");
|
|
547
1015
|
try {
|
|
548
1016
|
const e = {};
|
|
549
|
-
let
|
|
1017
|
+
let r;
|
|
550
1018
|
t.forEach((t, n) => {
|
|
551
1019
|
e[n] = t;
|
|
552
1020
|
});
|
|
553
1021
|
const o = n?.encoded;
|
|
554
|
-
|
|
1022
|
+
r = o ? btoa(JSON.stringify(e)) : JSON.stringify(e), s.setItem(u.replace("_", ""), JSON.stringify({
|
|
555
1023
|
v: 1,
|
|
556
1024
|
t: Date.now(),
|
|
557
1025
|
e: null,
|
|
558
|
-
d:
|
|
1026
|
+
d: r,
|
|
559
1027
|
_sys_v: l,
|
|
560
1028
|
_b64: !!o || void 0
|
|
561
1029
|
})), a("set", "FULL_STATE", !0);
|
|
@@ -566,21 +1034,21 @@ var x = () => {
|
|
|
566
1034
|
key: "FULL_STATE"
|
|
567
1035
|
});
|
|
568
1036
|
}
|
|
569
|
-
const
|
|
570
|
-
|
|
571
|
-
for (const [t, n] of
|
|
1037
|
+
const d = Array.from(r.entries());
|
|
1038
|
+
r.clear();
|
|
1039
|
+
for (const [t, n] of d) try {
|
|
572
1040
|
if (!t || !/^[a-zA-Z0-9_.-]+$/.test(t) || t.length > 256) continue;
|
|
573
|
-
let
|
|
1041
|
+
let r = n.value;
|
|
574
1042
|
const i = n.options.encoded || n.options.encrypted || n.options.secure;
|
|
575
1043
|
if (n.options.encrypted) {
|
|
576
1044
|
if (!o) throw new Error(`Encryption key missing for "${t}"`);
|
|
577
|
-
|
|
578
|
-
} else i ?
|
|
579
|
-
|
|
1045
|
+
r = await ze(n.value, o);
|
|
1046
|
+
} else i ? r = btoa(JSON.stringify(n.value)) : "object" == typeof n.value && null !== n.value && (r = JSON.stringify(n.value));
|
|
1047
|
+
s.setItem(`${u}${t}`, JSON.stringify({
|
|
580
1048
|
v: e.versions.get(t) || 1,
|
|
581
1049
|
t: Date.now(),
|
|
582
1050
|
e: n.options.ttl ? Date.now() + n.options.ttl : null,
|
|
583
|
-
d:
|
|
1051
|
+
d: r,
|
|
584
1052
|
_sys_v: l,
|
|
585
1053
|
_enc: !!n.options.encrypted || void 0,
|
|
586
1054
|
_b64: !(!n.options.encoded && !n.options.secure) || void 0
|
|
@@ -592,140 +1060,141 @@ var x = () => {
|
|
|
592
1060
|
key: t
|
|
593
1061
|
});
|
|
594
1062
|
}
|
|
595
|
-
})(
|
|
596
|
-
},
|
|
597
|
-
_setSilently: (e,
|
|
598
|
-
const
|
|
599
|
-
|
|
1063
|
+
})(F());
|
|
1064
|
+
}, Z = {}, H = {
|
|
1065
|
+
_setSilently: (e, s) => {
|
|
1066
|
+
const o = r.get(e) || 0, i = j && null !== s && "object" == typeof s ? G(a(s), !0) : s, c = (O > 0 || C > 0) && !We() ? J(i) : 0;
|
|
1067
|
+
$ = $ - o + c, r.set(e, c), t.set(e, i), n.set(e, (n.get(e) || 0) + 1), N = null;
|
|
600
1068
|
},
|
|
601
1069
|
_registerMethod: (e, t, n) => {
|
|
602
|
-
const
|
|
603
|
-
|
|
1070
|
+
const r = e => "__proto__" === e || "constructor" === e || "prototype" === e;
|
|
1071
|
+
r(e) || r(t) || (Z[e] || (Z[e] = {}), Z[e][t] = n);
|
|
604
1072
|
},
|
|
605
|
-
set: (
|
|
606
|
-
const
|
|
607
|
-
if (
|
|
608
|
-
if (!
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
key:
|
|
612
|
-
value:
|
|
613
|
-
store:
|
|
614
|
-
version:
|
|
1073
|
+
set: (s, o, c = {}) => {
|
|
1074
|
+
const l = t.get(s), u = j && "function" == typeof o ? Ce(l, o) : o;
|
|
1075
|
+
if (M && !Ke(s)) return !1;
|
|
1076
|
+
if (!Le(m, s, "write", R)) return W("set", s, !1, "RBAC Denied"), !1;
|
|
1077
|
+
const d = M ? Fe(u) : u, f = r.get(s) || 0;
|
|
1078
|
+
B("onBeforeSet", {
|
|
1079
|
+
key: s,
|
|
1080
|
+
value: d,
|
|
1081
|
+
store: H,
|
|
1082
|
+
version: n.get(s) || 0
|
|
615
1083
|
});
|
|
616
|
-
const p =
|
|
617
|
-
if (!l
|
|
618
|
-
const
|
|
619
|
-
if (
|
|
620
|
-
const
|
|
621
|
-
|
|
1084
|
+
const p = j && null !== d && "object" == typeof d ? G(a(d), !0) : d;
|
|
1085
|
+
if (!i(l, p)) {
|
|
1086
|
+
const o = (O > 0 || C > 0) && !We() ? J(p) : 0;
|
|
1087
|
+
if (O > 0 && o > O) {
|
|
1088
|
+
const e = new Error(`Object size (${o} bytes) exceeds maxObjectSize (${O} bytes)`);
|
|
1089
|
+
return E && E(e, {
|
|
622
1090
|
operation: "set",
|
|
623
|
-
key:
|
|
624
|
-
});
|
|
1091
|
+
key: s
|
|
1092
|
+
}), !1;
|
|
625
1093
|
}
|
|
626
|
-
if (
|
|
627
|
-
const
|
|
628
|
-
if (
|
|
629
|
-
const
|
|
630
|
-
|
|
1094
|
+
if (C > 0) {
|
|
1095
|
+
const e = $ - f + o;
|
|
1096
|
+
if (e > C) {
|
|
1097
|
+
const t = new Error(`Total store size (${e} bytes) exceeds limit (${C} bytes)`);
|
|
1098
|
+
return E && E(t, {
|
|
631
1099
|
operation: "set"
|
|
632
|
-
});
|
|
1100
|
+
}), !1;
|
|
633
1101
|
}
|
|
634
1102
|
}
|
|
635
|
-
|
|
636
|
-
const
|
|
637
|
-
return
|
|
1103
|
+
$ = $ - f + o, r.set(s, o), t.set(s, p), n.set(s, (n.get(s) || 0) + 1), N = null;
|
|
1104
|
+
const a = c.persist ?? P;
|
|
1105
|
+
return a && (y.set(s, {
|
|
638
1106
|
value: p,
|
|
639
1107
|
options: {
|
|
640
|
-
...
|
|
641
|
-
persist:
|
|
642
|
-
encoded:
|
|
1108
|
+
...c,
|
|
1109
|
+
persist: a,
|
|
1110
|
+
encoded: c.encoded || e?.encoded
|
|
643
1111
|
}
|
|
644
|
-
}),
|
|
645
|
-
key:
|
|
1112
|
+
}), x && clearTimeout(x), x = setTimeout(X, b)), B("onSet", {
|
|
1113
|
+
key: s,
|
|
646
1114
|
value: p,
|
|
647
|
-
store:
|
|
648
|
-
version:
|
|
649
|
-
}),
|
|
1115
|
+
store: H,
|
|
1116
|
+
version: n.get(s)
|
|
1117
|
+
}), W("set", s, !0), q(s), !0;
|
|
650
1118
|
}
|
|
651
1119
|
return !1;
|
|
652
1120
|
},
|
|
653
1121
|
get: e => {
|
|
654
|
-
if (!
|
|
655
|
-
const
|
|
656
|
-
return
|
|
657
|
-
store:
|
|
1122
|
+
if (!Le(m, e, "read", R)) return W("get", e, !1, "RBAC Denied"), null;
|
|
1123
|
+
const n = t.get(e);
|
|
1124
|
+
return B("onGet", {
|
|
1125
|
+
store: H,
|
|
658
1126
|
key: e,
|
|
659
|
-
value:
|
|
660
|
-
}),
|
|
1127
|
+
value: n
|
|
1128
|
+
}), W("get", e, !0), n;
|
|
661
1129
|
},
|
|
662
1130
|
compute: (e, t) => {
|
|
663
1131
|
try {
|
|
664
|
-
return
|
|
1132
|
+
return u.has(e) || (u.set(e, {
|
|
665
1133
|
selector: t,
|
|
666
1134
|
lastValue: null,
|
|
667
1135
|
deps: new Set
|
|
668
|
-
}),
|
|
1136
|
+
}), Q(e)), u.get(e).lastValue;
|
|
669
1137
|
} catch (t) {
|
|
670
1138
|
const n = t instanceof Error ? t : new Error(String(t));
|
|
671
|
-
return
|
|
1139
|
+
return E && E(n, {
|
|
672
1140
|
operation: "compute",
|
|
673
1141
|
key: e
|
|
674
1142
|
}), null;
|
|
675
1143
|
}
|
|
676
1144
|
},
|
|
677
1145
|
watch: (e, t) => {
|
|
678
|
-
|
|
679
|
-
const n =
|
|
1146
|
+
l.has(e) || l.set(e, new Set);
|
|
1147
|
+
const n = l.get(e);
|
|
680
1148
|
return n.add(t), () => {
|
|
681
|
-
n.delete(t), 0 === n.size &&
|
|
1149
|
+
n.delete(t), 0 === n.size && l.delete(e);
|
|
682
1150
|
};
|
|
683
1151
|
},
|
|
684
1152
|
remove: e => {
|
|
685
|
-
if (!
|
|
686
|
-
const
|
|
687
|
-
return
|
|
688
|
-
store:
|
|
1153
|
+
if (!Le(m, e, "delete", R)) return W("delete", e, !1, "RBAC Denied"), !1;
|
|
1154
|
+
const s = t.get(e), o = t.delete(e);
|
|
1155
|
+
return o && ($ -= r.get(e) || 0, r.delete(e), B("onRemove", {
|
|
1156
|
+
store: H,
|
|
689
1157
|
key: e,
|
|
690
|
-
value:
|
|
691
|
-
}),
|
|
692
|
-
|
|
1158
|
+
value: s
|
|
1159
|
+
}), N = null), n.set(e, (n.get(e) || 0) + 1), k && k.removeItem(`${L()}${e}`), W("delete", e, !0),
|
|
1160
|
+
q(e), o;
|
|
693
1161
|
},
|
|
694
|
-
delete: e =>
|
|
1162
|
+
delete: e => H.remove(e),
|
|
695
1163
|
deleteAll: () => {
|
|
696
|
-
if (Array.from(
|
|
697
|
-
const e =
|
|
698
|
-
for (let
|
|
699
|
-
const n =
|
|
700
|
-
n
|
|
1164
|
+
if (Array.from(t.keys()).forEach(e => H.remove(e)), k) {
|
|
1165
|
+
const e = L(), t = [], n = k.length || 0;
|
|
1166
|
+
for (let r = 0; r < n; r++) {
|
|
1167
|
+
const n = k.key(r);
|
|
1168
|
+
n && n.startsWith(e) && t.push(n);
|
|
701
1169
|
}
|
|
1170
|
+
for (const e of t) k.removeItem(e);
|
|
702
1171
|
}
|
|
703
|
-
return
|
|
1172
|
+
return $ = 0, r.clear(), N = null, !0;
|
|
704
1173
|
},
|
|
705
|
-
list: () => Object.fromEntries(
|
|
1174
|
+
list: () => Object.fromEntries(t.entries()),
|
|
706
1175
|
use: e => {
|
|
707
|
-
|
|
1176
|
+
c.add(e);
|
|
708
1177
|
},
|
|
709
1178
|
transaction: e => {
|
|
710
|
-
|
|
711
|
-
store:
|
|
1179
|
+
I = !0, B("onTransaction", {
|
|
1180
|
+
store: H,
|
|
712
1181
|
key: "START"
|
|
713
1182
|
});
|
|
714
1183
|
try {
|
|
715
1184
|
e();
|
|
716
1185
|
} finally {
|
|
717
|
-
|
|
718
|
-
store:
|
|
1186
|
+
I = !1, B("onTransaction", {
|
|
1187
|
+
store: H,
|
|
719
1188
|
key: "END"
|
|
720
|
-
}),
|
|
1189
|
+
}), z && (z = !1, q());
|
|
721
1190
|
}
|
|
722
1191
|
},
|
|
723
1192
|
destroy: () => {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
store:
|
|
727
|
-
}),
|
|
728
|
-
|
|
1193
|
+
x && (clearTimeout(x), x = null), y.clear(), "undefined" != typeof window && window.removeEventListener("beforeunload", Y),
|
|
1194
|
+
B("onDestroy", {
|
|
1195
|
+
store: H
|
|
1196
|
+
}), s.clear(), o.clear(), l.clear(), u.clear(), d.clear(), f.clear(), t.clear(),
|
|
1197
|
+
r.clear(), $ = 0, m.clear(), _.clear(), n.clear(), g.clear(), c.clear();
|
|
729
1198
|
},
|
|
730
1199
|
_addPlugin: e => {
|
|
731
1200
|
((e, t, n) => {
|
|
@@ -734,158 +1203,158 @@ var x = () => {
|
|
|
734
1203
|
store: n
|
|
735
1204
|
});
|
|
736
1205
|
} catch (n) {
|
|
737
|
-
const
|
|
738
|
-
e.onError ? e.onError(
|
|
1206
|
+
const r = n instanceof Error ? n : new Error(String(n));
|
|
1207
|
+
e.onError ? e.onError(r, {
|
|
739
1208
|
operation: "plugin:install",
|
|
740
1209
|
key: t.name
|
|
741
1210
|
}) : e.silent;
|
|
742
1211
|
}
|
|
743
|
-
})(
|
|
1212
|
+
})(K(), e, H);
|
|
744
1213
|
},
|
|
745
1214
|
_removePlugin: e => {
|
|
746
1215
|
f.delete(e);
|
|
747
1216
|
},
|
|
748
1217
|
_subscribe: (e, t) => {
|
|
749
1218
|
if (t) {
|
|
750
|
-
|
|
751
|
-
const n =
|
|
1219
|
+
o.has(t) || o.set(t, new Set);
|
|
1220
|
+
const n = o.get(t);
|
|
752
1221
|
return n.add(e), () => {
|
|
753
|
-
n.delete(e), 0 === n.size &&
|
|
1222
|
+
n.delete(e), 0 === n.size && o.delete(t);
|
|
754
1223
|
};
|
|
755
1224
|
}
|
|
756
|
-
return
|
|
1225
|
+
return s.add(e), () => s.delete(e);
|
|
757
1226
|
},
|
|
758
|
-
_getVersion: e =>
|
|
759
|
-
addAccessRule: (e, t) =>
|
|
760
|
-
hasPermission: (e, t, n) =>
|
|
761
|
-
recordConsent: (e, t, n) =>
|
|
1227
|
+
_getVersion: e => n.get(e) ?? 0,
|
|
1228
|
+
addAccessRule: (e, t) => Ue(m, e, t),
|
|
1229
|
+
hasPermission: (e, t, n) => Le(m, e, t, n),
|
|
1230
|
+
recordConsent: (e, t, n) => Je(_, e, t, n),
|
|
762
1231
|
hasConsent: (e, t) => ((e, t, n) => {
|
|
763
|
-
const
|
|
764
|
-
if (!
|
|
765
|
-
for (let e =
|
|
766
|
-
const t =
|
|
1232
|
+
const r = e.get(t);
|
|
1233
|
+
if (!r) return !1;
|
|
1234
|
+
for (let e = r.length - 1; e >= 0; e--) {
|
|
1235
|
+
const t = r[e];
|
|
767
1236
|
if (t && t.purpose === n) return t.granted;
|
|
768
1237
|
}
|
|
769
1238
|
return !1;
|
|
770
|
-
})(
|
|
771
|
-
getConsents: e => ((e, t) => e.get(t) || [])(
|
|
772
|
-
revokeConsent: (e, t) => ((e, t, n) =>
|
|
1239
|
+
})(_, e, t),
|
|
1240
|
+
getConsents: e => ((e, t) => e.get(t) || [])(_, e),
|
|
1241
|
+
revokeConsent: (e, t) => ((e, t, n) => Je(e, t, n, !1))(_, e, t),
|
|
773
1242
|
exportUserData: e => ((e, t) => ({
|
|
774
1243
|
userId: t,
|
|
775
1244
|
exportedAt: Date.now(),
|
|
776
1245
|
consents: e.get(t) || []
|
|
777
|
-
}))(
|
|
1246
|
+
}))(_, e),
|
|
778
1247
|
deleteUserData: e => ((e, t) => {
|
|
779
1248
|
const n = e.get(t)?.length || 0;
|
|
780
1249
|
return e.delete(t), {
|
|
781
1250
|
success: !0,
|
|
782
1251
|
deletedConsents: n
|
|
783
1252
|
};
|
|
784
|
-
})(
|
|
785
|
-
getSnapshot: () => (
|
|
1253
|
+
})(_, e),
|
|
1254
|
+
getSnapshot: () => (N || (N = Object.fromEntries(t.entries())), N),
|
|
786
1255
|
get plugins() {
|
|
787
|
-
return
|
|
1256
|
+
return Z;
|
|
788
1257
|
},
|
|
789
1258
|
get isReady() {
|
|
790
|
-
return
|
|
1259
|
+
return V;
|
|
791
1260
|
},
|
|
792
1261
|
get namespace() {
|
|
793
|
-
return
|
|
1262
|
+
return S;
|
|
794
1263
|
},
|
|
795
1264
|
get userId() {
|
|
796
|
-
return
|
|
1265
|
+
return R;
|
|
797
1266
|
},
|
|
798
|
-
whenReady: () =>
|
|
1267
|
+
whenReady: () => U
|
|
799
1268
|
};
|
|
800
1269
|
[ "addAccessRule", "recordConsent", "hasConsent", "getConsents", "revokeConsent", "exportUserData", "deleteUserData" ].forEach(e => {
|
|
801
|
-
const t =
|
|
802
|
-
t &&
|
|
1270
|
+
const t = H[e];
|
|
1271
|
+
t && H._registerMethod("security", e, t);
|
|
803
1272
|
});
|
|
804
|
-
const
|
|
805
|
-
|
|
1273
|
+
const Y = () => {
|
|
1274
|
+
y.size > 0 && X();
|
|
806
1275
|
};
|
|
807
|
-
if ("undefined" != typeof window && window.addEventListener("beforeunload",
|
|
808
|
-
|
|
809
|
-
const {storage: r, config:
|
|
1276
|
+
if ("undefined" != typeof window && window.addEventListener("beforeunload", Y),
|
|
1277
|
+
k ? (async (e, t, n) => {
|
|
1278
|
+
const {storage: r, config: s, encryptionKey: o, audit: i, onError: c, silent: l, currentVersion: u, store: d, sizes: f, versions: y} = e, p = Be(s.namespace || "gstate"), h = s.immer ?? !0;
|
|
810
1279
|
if (r) try {
|
|
811
|
-
const
|
|
812
|
-
let
|
|
1280
|
+
const l = {};
|
|
1281
|
+
let g = 0;
|
|
813
1282
|
for (let e = 0; e < (r.length || 0); e++) {
|
|
814
1283
|
const t = r.key(e);
|
|
815
|
-
if (!t || !t.startsWith(
|
|
1284
|
+
if (!t || !t.startsWith(p)) continue;
|
|
816
1285
|
const n = r.getItem(t);
|
|
817
1286
|
if (n) try {
|
|
818
|
-
const s = JSON.parse(n),
|
|
819
|
-
if (
|
|
1287
|
+
const s = JSON.parse(n), a = t.substring(p.length);
|
|
1288
|
+
if (g = Math.max(g, void 0 !== s._sys_v ? s._sys_v : s.v || 0), s.e && Date.now() > s.e) {
|
|
820
1289
|
r.removeItem(t), e--;
|
|
821
1290
|
continue;
|
|
822
1291
|
}
|
|
823
1292
|
let c = s.d;
|
|
824
|
-
if (s._enc &&
|
|
1293
|
+
if (s._enc && o) c = await Ve(c, o); else if ("string" == typeof c) if (s._b64) try {
|
|
825
1294
|
c = JSON.parse(atob(c));
|
|
826
1295
|
} catch (e) {} else if (c.startsWith("{") || c.startsWith("[")) try {
|
|
827
1296
|
c = JSON.parse(c);
|
|
828
1297
|
} catch (e) {}
|
|
829
|
-
|
|
1298
|
+
l[a] = c, i("hydrate", a, !0);
|
|
830
1299
|
} catch (e) {
|
|
831
1300
|
i("hydrate", t, !1, String(e));
|
|
832
1301
|
const n = e instanceof Error ? e : new Error(String(e));
|
|
833
|
-
|
|
1302
|
+
c && c(n, {
|
|
834
1303
|
operation: "hydration",
|
|
835
1304
|
key: t
|
|
836
1305
|
});
|
|
837
1306
|
}
|
|
838
1307
|
}
|
|
839
|
-
const
|
|
840
|
-
Object.entries(
|
|
841
|
-
const
|
|
842
|
-
e.totalSize = e.totalSize - i +
|
|
843
|
-
}),
|
|
1308
|
+
const m = g < u && s.migrate ? s.migrate(l, g) : l;
|
|
1309
|
+
Object.entries(m).forEach(([n, r]) => {
|
|
1310
|
+
const s = h && null !== r && "object" == typeof r ? G(a(r), !0) : r, o = t(s), i = f.get(n) || 0;
|
|
1311
|
+
e.totalSize = e.totalSize - i + o, f.set(n, o), d.set(n, s), y.set(n, 1);
|
|
1312
|
+
}), n();
|
|
844
1313
|
} catch (e) {
|
|
845
1314
|
const t = e instanceof Error ? e : new Error(String(e));
|
|
846
|
-
|
|
1315
|
+
c && c(t, {
|
|
847
1316
|
operation: "hydration"
|
|
848
1317
|
});
|
|
849
1318
|
}
|
|
850
|
-
})(
|
|
851
|
-
|
|
852
|
-
}).then(() => {}) : (
|
|
853
|
-
const
|
|
854
|
-
const {SyncEngine:
|
|
855
|
-
return new
|
|
1319
|
+
})(F(), e => (O > 0 || C > 0) && !We() ? J(e) : 0, () => {
|
|
1320
|
+
V = !0, N = null, T(), q();
|
|
1321
|
+
}).then(() => {}) : (V = !0, T()), e?.sync) {
|
|
1322
|
+
const t = e.sync, n = async () => {
|
|
1323
|
+
const {SyncEngine: e} = await Promise.resolve().then(() => (h(), p));
|
|
1324
|
+
return new e(H, t);
|
|
856
1325
|
};
|
|
857
|
-
let
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
return (await
|
|
861
|
-
}),
|
|
862
|
-
|
|
863
|
-
return (await
|
|
864
|
-
}),
|
|
865
|
-
|
|
866
|
-
return (await
|
|
867
|
-
}),
|
|
868
|
-
|
|
869
|
-
return (await
|
|
1326
|
+
let r = null;
|
|
1327
|
+
H._registerMethod("sync", "flush", async () => {
|
|
1328
|
+
r || (r = n());
|
|
1329
|
+
return (await r).flush();
|
|
1330
|
+
}), H._registerMethod("sync", "getState", async () => {
|
|
1331
|
+
r || (r = n());
|
|
1332
|
+
return (await r).getState();
|
|
1333
|
+
}), H._registerMethod("sync", "onStateChange", async e => {
|
|
1334
|
+
r || (r = n());
|
|
1335
|
+
return (await r).onStateChange(e);
|
|
1336
|
+
}), H._registerMethod("sync", "forceSync", async () => {
|
|
1337
|
+
r || (r = n());
|
|
1338
|
+
return (await r).sync();
|
|
870
1339
|
});
|
|
871
1340
|
}
|
|
872
|
-
return
|
|
1341
|
+
return H;
|
|
873
1342
|
};
|
|
874
1343
|
|
|
875
|
-
|
|
1344
|
+
h();
|
|
876
1345
|
|
|
877
|
-
var
|
|
878
|
-
const t =
|
|
879
|
-
return
|
|
880
|
-
},
|
|
881
|
-
|
|
882
|
-
},
|
|
883
|
-
const
|
|
884
|
-
return s
|
|
885
|
-
},
|
|
1346
|
+
var qe = null, Xe = e => {
|
|
1347
|
+
const t = Ge(e);
|
|
1348
|
+
return qe = t, t;
|
|
1349
|
+
}, Ze = () => {
|
|
1350
|
+
qe && (qe.destroy(), qe = null);
|
|
1351
|
+
}, He = n => {
|
|
1352
|
+
const r = n || qe, s = e(() => e => r ? r._subscribe(e) : () => {}, [ r ]);
|
|
1353
|
+
return t(s, () => !!r && r.isReady, () => !0);
|
|
1354
|
+
}, Ye = () => qe;
|
|
886
1355
|
|
|
887
|
-
function
|
|
888
|
-
const a =
|
|
1356
|
+
function et(s, o) {
|
|
1357
|
+
const a = e(() => o || qe, [ o ]), i = e(() => {
|
|
889
1358
|
const e = () => {}, t = () => !1, n = () => null;
|
|
890
1359
|
return {
|
|
891
1360
|
set: t,
|
|
@@ -918,96 +1387,96 @@ function Q(e, t) {
|
|
|
918
1387
|
},
|
|
919
1388
|
get userId() {}
|
|
920
1389
|
};
|
|
921
|
-
}, []), c = a || i, l = "function" == typeof
|
|
1390
|
+
}, []), c = a || i, l = "function" == typeof s, u = l ? null : s, d = l ? s : null, f = n(e => l ? c._subscribe(e) : c._subscribe(e, u), [ c, l, u ]), y = n(() => l ? d(c.getSnapshot()) : c.get(u) ?? void 0, [ c, l, u, d ]), p = n(() => {
|
|
922
1391
|
if (l) try {
|
|
923
|
-
return
|
|
1392
|
+
return d({});
|
|
924
1393
|
} catch {
|
|
925
1394
|
return;
|
|
926
1395
|
}
|
|
927
|
-
}, [
|
|
928
|
-
return
|
|
929
|
-
l ? h : [ h,
|
|
1396
|
+
}, [ d, l ]), h = t(f, y, p), g = n((e, t) => l ? (We(), !1) : c.set(u, e, t), [ c, l, u ]);
|
|
1397
|
+
return r(h, e => l ? `Selector: ${JSON.stringify(e)}` : `${u}: ${JSON.stringify(e)}`),
|
|
1398
|
+
l ? h : [ h, g ];
|
|
930
1399
|
}
|
|
931
1400
|
|
|
932
|
-
var
|
|
1401
|
+
var tt = new Map, nt = (e, t) => {
|
|
933
1402
|
const n = e.namespace;
|
|
934
|
-
if (
|
|
935
|
-
const
|
|
936
|
-
return
|
|
937
|
-
},
|
|
938
|
-
const t =
|
|
939
|
-
t && (t.destroy(),
|
|
1403
|
+
if (tt.has(n)) return tt.get(n);
|
|
1404
|
+
const r = new c(e, t);
|
|
1405
|
+
return tt.set(n, r), r;
|
|
1406
|
+
}, rt = e => {
|
|
1407
|
+
const t = tt.get(e);
|
|
1408
|
+
t && (t.destroy(), tt.delete(e));
|
|
940
1409
|
};
|
|
941
1410
|
|
|
942
|
-
function
|
|
943
|
-
const
|
|
1411
|
+
function st(e, t) {
|
|
1412
|
+
const r = t || qe, a = r?.namespace || "default", i = tt.get(a), c = et(e, r), l = c[0], u = c[1], [d, f] = s(() => i?.getState() || {
|
|
944
1413
|
isOnline: !0,
|
|
945
1414
|
isSyncing: !1,
|
|
946
1415
|
lastSyncTimestamp: null,
|
|
947
1416
|
pendingChanges: 0,
|
|
948
1417
|
conflicts: 0
|
|
949
1418
|
});
|
|
950
|
-
|
|
951
|
-
if (!
|
|
952
|
-
return
|
|
953
|
-
}, [
|
|
954
|
-
return [ l,
|
|
955
|
-
const
|
|
956
|
-
if (
|
|
957
|
-
const t =
|
|
958
|
-
|
|
1419
|
+
o(() => {
|
|
1420
|
+
if (!i) return;
|
|
1421
|
+
return i.onStateChange(f);
|
|
1422
|
+
}, [ i ]);
|
|
1423
|
+
return [ l, n((t, n) => {
|
|
1424
|
+
const s = u(t, n);
|
|
1425
|
+
if (s && i) {
|
|
1426
|
+
const t = r?.get(e);
|
|
1427
|
+
i.queueChange(e, t);
|
|
959
1428
|
}
|
|
960
|
-
return
|
|
961
|
-
}, [ u,
|
|
1429
|
+
return s;
|
|
1430
|
+
}, [ u, i, e, r ]), d ];
|
|
962
1431
|
}
|
|
963
1432
|
|
|
964
|
-
var
|
|
965
|
-
const [e, t] =
|
|
1433
|
+
var ot = () => {
|
|
1434
|
+
const [e, t] = s({
|
|
966
1435
|
isOnline: !0,
|
|
967
1436
|
isSyncing: !1,
|
|
968
1437
|
lastSyncTimestamp: null,
|
|
969
1438
|
pendingChanges: 0,
|
|
970
1439
|
conflicts: 0
|
|
971
1440
|
});
|
|
972
|
-
return
|
|
1441
|
+
return o(() => {
|
|
973
1442
|
const e = () => {
|
|
974
|
-
let e = !0, n = !1,
|
|
975
|
-
|
|
1443
|
+
let e = !0, n = !1, r = 0, s = 0;
|
|
1444
|
+
tt.forEach(t => {
|
|
976
1445
|
const o = t.getState();
|
|
977
|
-
e = e && o.isOnline, n = n || o.isSyncing,
|
|
1446
|
+
e = e && o.isOnline, n = n || o.isSyncing, r += o.pendingChanges, s += o.conflicts;
|
|
978
1447
|
}), t({
|
|
979
1448
|
isOnline: e,
|
|
980
1449
|
isSyncing: n,
|
|
981
1450
|
lastSyncTimestamp: null,
|
|
982
|
-
pendingChanges:
|
|
983
|
-
conflicts:
|
|
1451
|
+
pendingChanges: r,
|
|
1452
|
+
conflicts: s
|
|
984
1453
|
});
|
|
985
1454
|
};
|
|
986
1455
|
e();
|
|
987
|
-
const n = Array.from(
|
|
1456
|
+
const n = Array.from(tt.values()).map(t => t.onStateChange(e));
|
|
988
1457
|
return () => n.forEach(e => e());
|
|
989
1458
|
}, []), e;
|
|
990
|
-
},
|
|
991
|
-
const t = e ||
|
|
1459
|
+
}, at = async e => {
|
|
1460
|
+
const t = e || qe?.namespace;
|
|
992
1461
|
if (!t) return;
|
|
993
|
-
const n =
|
|
1462
|
+
const n = tt.get(t);
|
|
994
1463
|
n && await n.flush();
|
|
995
|
-
},
|
|
996
|
-
const n = t?.key || "async_data",
|
|
1464
|
+
}, it = (e, t) => {
|
|
1465
|
+
const n = t?.key || "async_data", r = t?.store || Ge({
|
|
997
1466
|
namespace: `async_${n}`,
|
|
998
1467
|
silent: !0
|
|
999
1468
|
});
|
|
1000
|
-
null ==
|
|
1469
|
+
null == r.get(n) && r.set(n, {
|
|
1001
1470
|
data: null,
|
|
1002
1471
|
loading: !1,
|
|
1003
1472
|
error: null,
|
|
1004
1473
|
updatedAt: null
|
|
1005
1474
|
});
|
|
1006
|
-
return Object.assign(
|
|
1475
|
+
return Object.assign(r, {
|
|
1007
1476
|
execute: async () => {
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1010
|
-
...
|
|
1477
|
+
const s = r.get(n);
|
|
1478
|
+
r.set(n, {
|
|
1479
|
+
...s || {
|
|
1011
1480
|
data: null,
|
|
1012
1481
|
loading: !1,
|
|
1013
1482
|
error: null,
|
|
@@ -1015,25 +1484,25 @@ var X = () => {
|
|
|
1015
1484
|
},
|
|
1016
1485
|
loading: !0,
|
|
1017
1486
|
error: null
|
|
1018
|
-
}), "whenReady" in
|
|
1487
|
+
}), "whenReady" in r && !r.isReady && await r.whenReady();
|
|
1019
1488
|
try {
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1489
|
+
const s = await e(), o = r.get(n);
|
|
1490
|
+
r.set(n, {
|
|
1022
1491
|
...o || {
|
|
1023
1492
|
data: null,
|
|
1024
1493
|
loading: !1,
|
|
1025
1494
|
error: null,
|
|
1026
1495
|
updatedAt: null
|
|
1027
1496
|
},
|
|
1028
|
-
data:
|
|
1497
|
+
data: s,
|
|
1029
1498
|
loading: !1,
|
|
1030
1499
|
updatedAt: Date.now()
|
|
1031
1500
|
}, {
|
|
1032
1501
|
persist: t?.persist
|
|
1033
1502
|
});
|
|
1034
1503
|
} catch (e) {
|
|
1035
|
-
const t =
|
|
1036
|
-
|
|
1504
|
+
const t = r.get(n);
|
|
1505
|
+
r.set(n, {
|
|
1037
1506
|
...t || {
|
|
1038
1507
|
data: null,
|
|
1039
1508
|
loading: !1,
|
|
@@ -1048,60 +1517,60 @@ var X = () => {
|
|
|
1048
1517
|
});
|
|
1049
1518
|
};
|
|
1050
1519
|
|
|
1051
|
-
|
|
1520
|
+
h();
|
|
1052
1521
|
|
|
1053
|
-
var
|
|
1522
|
+
var ct = () => ({
|
|
1054
1523
|
name: "gstate-immer",
|
|
1055
1524
|
hooks: {
|
|
1056
1525
|
onInstall: ({store: e}) => {
|
|
1057
1526
|
e._registerMethod("immer", "setWithProduce", (t, n) => e.set(t, n));
|
|
1058
1527
|
}
|
|
1059
1528
|
}
|
|
1060
|
-
}),
|
|
1061
|
-
let t = [], n = -1,
|
|
1062
|
-
const
|
|
1529
|
+
}), lt = e => {
|
|
1530
|
+
let t = [], n = -1, r = !1;
|
|
1531
|
+
const s = e?.limit || 50;
|
|
1063
1532
|
return {
|
|
1064
1533
|
name: "gstate-undo-redo",
|
|
1065
1534
|
hooks: {
|
|
1066
1535
|
onInstall: ({store: e}) => {
|
|
1067
1536
|
t.push(e.list()), n = 0, e._registerMethod("undoRedo", "undo", () => {
|
|
1068
1537
|
if (n > 0) {
|
|
1069
|
-
|
|
1070
|
-
const
|
|
1071
|
-
return !!
|
|
1538
|
+
r = !0, n--;
|
|
1539
|
+
const s = t[n];
|
|
1540
|
+
return !!s && (Object.entries(s).forEach(([t, n]) => {
|
|
1072
1541
|
e._setSilently(t, n);
|
|
1073
|
-
}),
|
|
1542
|
+
}), r = !1, !0);
|
|
1074
1543
|
}
|
|
1075
1544
|
return !1;
|
|
1076
1545
|
}), e._registerMethod("undoRedo", "redo", () => {
|
|
1077
1546
|
if (n < t.length - 1) {
|
|
1078
|
-
|
|
1079
|
-
const
|
|
1080
|
-
return !!
|
|
1547
|
+
r = !0, n++;
|
|
1548
|
+
const s = t[n];
|
|
1549
|
+
return !!s && (Object.entries(s).forEach(([t, n]) => {
|
|
1081
1550
|
e._setSilently(t, n);
|
|
1082
|
-
}),
|
|
1551
|
+
}), r = !1, !0);
|
|
1083
1552
|
}
|
|
1084
1553
|
return !1;
|
|
1085
1554
|
}), e._registerMethod("undoRedo", "canUndo", () => n > 0), e._registerMethod("undoRedo", "canRedo", () => n < t.length - 1);
|
|
1086
1555
|
},
|
|
1087
1556
|
onSet: ({store: e}) => {
|
|
1088
|
-
|
|
1557
|
+
r || (n < t.length - 1 && (t = t.slice(0, n + 1)), t.push(e.list()), t.length > s ? t.shift() : n++);
|
|
1089
1558
|
}
|
|
1090
1559
|
}
|
|
1091
1560
|
};
|
|
1092
|
-
},
|
|
1561
|
+
}, ut = e => ({
|
|
1093
1562
|
name: "gstate-schema",
|
|
1094
1563
|
hooks: {
|
|
1095
1564
|
onSet: ({key: t, value: n}) => {
|
|
1096
1565
|
if (!t) return;
|
|
1097
|
-
const
|
|
1098
|
-
if (
|
|
1099
|
-
const e =
|
|
1566
|
+
const r = e[t];
|
|
1567
|
+
if (r) {
|
|
1568
|
+
const e = r(n);
|
|
1100
1569
|
if (!0 !== e) throw new Error(`[Schema Error] Validation failed for key "${t}": ${!1 === e ? "Invalid type" : e}`);
|
|
1101
1570
|
}
|
|
1102
1571
|
}
|
|
1103
1572
|
}
|
|
1104
|
-
}),
|
|
1573
|
+
}), dt = e => {
|
|
1105
1574
|
const t = globalThis.__REDUX_DEVTOOLS_EXTENSION__;
|
|
1106
1575
|
if (!t?.connect) return {
|
|
1107
1576
|
name: "gstate-devtools-noop",
|
|
@@ -1111,10 +1580,10 @@ var Y = () => ({
|
|
|
1111
1580
|
return {
|
|
1112
1581
|
name: "gstate-devtools",
|
|
1113
1582
|
hooks: {
|
|
1114
|
-
onInstall: ({store:
|
|
1583
|
+
onInstall: ({store: r}) => {
|
|
1115
1584
|
n = t.connect({
|
|
1116
1585
|
name: e?.name || "Magnetar Store"
|
|
1117
|
-
}), n.init(
|
|
1586
|
+
}), n.init(r.list());
|
|
1118
1587
|
},
|
|
1119
1588
|
onSet: ({key: e, store: t}) => {
|
|
1120
1589
|
e && n && n.send(`SET_${e.toUpperCase()}`, t.list());
|
|
@@ -1124,7 +1593,7 @@ var Y = () => ({
|
|
|
1124
1593
|
}
|
|
1125
1594
|
}
|
|
1126
1595
|
};
|
|
1127
|
-
},
|
|
1596
|
+
}, ft = () => {
|
|
1128
1597
|
const e = new Map;
|
|
1129
1598
|
return {
|
|
1130
1599
|
name: "gstate-snapshot",
|
|
@@ -1133,9 +1602,9 @@ var Y = () => ({
|
|
|
1133
1602
|
t._registerMethod("snapshot", "takeSnapshot", n => {
|
|
1134
1603
|
e.set(n, t.list());
|
|
1135
1604
|
}), t._registerMethod("snapshot", "restoreSnapshot", n => {
|
|
1136
|
-
const
|
|
1137
|
-
return !!
|
|
1138
|
-
Object.entries(
|
|
1605
|
+
const r = e.get(n);
|
|
1606
|
+
return !!r && (t.transaction(() => {
|
|
1607
|
+
Object.entries(r).forEach(([e, n]) => {
|
|
1139
1608
|
t.set(e, n);
|
|
1140
1609
|
});
|
|
1141
1610
|
}), !0);
|
|
@@ -1144,16 +1613,16 @@ var Y = () => ({
|
|
|
1144
1613
|
}
|
|
1145
1614
|
}
|
|
1146
1615
|
};
|
|
1147
|
-
},
|
|
1616
|
+
}, yt = e => ({
|
|
1148
1617
|
name: "gstate-guard",
|
|
1149
1618
|
hooks: {
|
|
1150
|
-
onBeforeSet: ({key: t, value: n, store:
|
|
1619
|
+
onBeforeSet: ({key: t, value: n, store: r}) => {
|
|
1151
1620
|
if (!t) return;
|
|
1152
|
-
const
|
|
1153
|
-
|
|
1621
|
+
const s = e[t];
|
|
1622
|
+
s && s(n);
|
|
1154
1623
|
}
|
|
1155
1624
|
}
|
|
1156
|
-
}),
|
|
1625
|
+
}), pt = e => ({
|
|
1157
1626
|
name: "gstate-analytics",
|
|
1158
1627
|
hooks: {
|
|
1159
1628
|
onSet: ({key: t, value: n}) => {
|
|
@@ -1171,7 +1640,7 @@ var Y = () => ({
|
|
|
1171
1640
|
}));
|
|
1172
1641
|
}
|
|
1173
1642
|
}
|
|
1174
|
-
}),
|
|
1643
|
+
}), ht = e => {
|
|
1175
1644
|
const t = new BroadcastChannel(e?.channelName || "gstate_sync");
|
|
1176
1645
|
let n = !1;
|
|
1177
1646
|
return {
|
|
@@ -1179,14 +1648,14 @@ var Y = () => ({
|
|
|
1179
1648
|
hooks: {
|
|
1180
1649
|
onInstall: ({store: e}) => {
|
|
1181
1650
|
t.onmessage = t => {
|
|
1182
|
-
const {key:
|
|
1183
|
-
|
|
1651
|
+
const {key: r, value: s, action: o} = t.data;
|
|
1652
|
+
r && (n = !0, "REMOVE" === o ? e.remove(r) : e.set(r, s), n = !1);
|
|
1184
1653
|
};
|
|
1185
1654
|
},
|
|
1186
|
-
onSet: ({key: e, value:
|
|
1655
|
+
onSet: ({key: e, value: r}) => {
|
|
1187
1656
|
e && !n && t.postMessage({
|
|
1188
1657
|
key: e,
|
|
1189
|
-
value:
|
|
1658
|
+
value: r,
|
|
1190
1659
|
action: "SET"
|
|
1191
1660
|
});
|
|
1192
1661
|
},
|
|
@@ -1201,12 +1670,12 @@ var Y = () => ({
|
|
|
1201
1670
|
}
|
|
1202
1671
|
}
|
|
1203
1672
|
};
|
|
1204
|
-
},
|
|
1205
|
-
if (
|
|
1673
|
+
}, gt = () => {
|
|
1674
|
+
if (We()) return {
|
|
1206
1675
|
name: "gstate-debug-noop",
|
|
1207
1676
|
hooks: {}
|
|
1208
1677
|
};
|
|
1209
|
-
|
|
1678
|
+
We();
|
|
1210
1679
|
return {
|
|
1211
1680
|
name: "gstate-debug",
|
|
1212
1681
|
hooks: {
|
|
@@ -1218,8 +1687,8 @@ var Y = () => ({
|
|
|
1218
1687
|
return n;
|
|
1219
1688
|
},
|
|
1220
1689
|
set: (t, n) => {
|
|
1221
|
-
const
|
|
1222
|
-
return JSON.stringify(n),
|
|
1690
|
+
const r = e.set(t, n);
|
|
1691
|
+
return JSON.stringify(n), r;
|
|
1223
1692
|
},
|
|
1224
1693
|
watch: (t, n) => e.watch(t, n),
|
|
1225
1694
|
info: () => {
|
|
@@ -1239,23 +1708,23 @@ var Y = () => ({
|
|
|
1239
1708
|
}
|
|
1240
1709
|
}
|
|
1241
1710
|
};
|
|
1242
|
-
},
|
|
1243
|
-
const t = e.dbName || "rgs-db", n = e.storeName || "states",
|
|
1244
|
-
let
|
|
1711
|
+
}, mt = (e = {}) => {
|
|
1712
|
+
const t = e.dbName || "rgs-db", n = e.storeName || "states", r = e.version || 1;
|
|
1713
|
+
let s = null;
|
|
1245
1714
|
const o = () => new Promise((e, o) => {
|
|
1246
|
-
if (
|
|
1247
|
-
const a = indexedDB.open(t,
|
|
1715
|
+
if (s) return e(s);
|
|
1716
|
+
const a = indexedDB.open(t, r);
|
|
1248
1717
|
a.onerror = () => o(a.error), a.onsuccess = () => {
|
|
1249
|
-
|
|
1718
|
+
s = a.result, e(s);
|
|
1250
1719
|
}, a.onupgradeneeded = e => {
|
|
1251
1720
|
const t = e.target.result;
|
|
1252
1721
|
t.objectStoreNames.contains(n) || t.createObjectStore(n);
|
|
1253
1722
|
};
|
|
1254
1723
|
}), a = async e => {
|
|
1255
1724
|
const t = await o();
|
|
1256
|
-
return new Promise((
|
|
1725
|
+
return new Promise((r, s) => {
|
|
1257
1726
|
const o = t.transaction(n, "readonly").objectStore(n).get(e);
|
|
1258
|
-
o.onsuccess = () =>
|
|
1727
|
+
o.onsuccess = () => r(o.result), o.onerror = () => s(o.error);
|
|
1259
1728
|
});
|
|
1260
1729
|
};
|
|
1261
1730
|
return {
|
|
@@ -1269,46 +1738,46 @@ var Y = () => ({
|
|
|
1269
1738
|
onInit: async ({store: e}) => {
|
|
1270
1739
|
const t = (await o()).transaction(n, "readonly").objectStore(n).getAllKeys();
|
|
1271
1740
|
t.onsuccess = async () => {
|
|
1272
|
-
const n = t.result,
|
|
1273
|
-
for (const t of n) if (t.startsWith(
|
|
1741
|
+
const n = t.result, r = e.namespace + "_";
|
|
1742
|
+
for (const t of n) if (t.startsWith(r)) {
|
|
1274
1743
|
const n = await a(t);
|
|
1275
1744
|
if (n) {
|
|
1276
|
-
const
|
|
1277
|
-
e._setSilently(
|
|
1745
|
+
const s = t.substring(r.length);
|
|
1746
|
+
e._setSilently(s, n.d);
|
|
1278
1747
|
}
|
|
1279
1748
|
}
|
|
1280
1749
|
};
|
|
1281
1750
|
},
|
|
1282
|
-
onSet: async ({key: e, value: t, store:
|
|
1751
|
+
onSet: async ({key: e, value: t, store: r}) => {
|
|
1283
1752
|
if (!e) return;
|
|
1284
|
-
const
|
|
1753
|
+
const s = r.namespace + "_", a = {
|
|
1285
1754
|
d: t,
|
|
1286
1755
|
t: Date.now(),
|
|
1287
|
-
v:
|
|
1756
|
+
v: r._getVersion?.(e) || 1
|
|
1288
1757
|
};
|
|
1289
1758
|
await (async (e, t) => {
|
|
1290
|
-
const
|
|
1291
|
-
return new Promise((
|
|
1292
|
-
const a =
|
|
1293
|
-
a.onsuccess = () =>
|
|
1759
|
+
const r = await o();
|
|
1760
|
+
return new Promise((s, o) => {
|
|
1761
|
+
const a = r.transaction(n, "readwrite").objectStore(n).put(t, e);
|
|
1762
|
+
a.onsuccess = () => s(), a.onerror = () => o(a.error);
|
|
1294
1763
|
});
|
|
1295
|
-
})(`${
|
|
1764
|
+
})(`${s}${e}`, a);
|
|
1296
1765
|
},
|
|
1297
1766
|
onRemove: async ({key: e, store: t}) => {
|
|
1298
1767
|
if (!e) return;
|
|
1299
|
-
const
|
|
1768
|
+
const r = t.namespace + "_";
|
|
1300
1769
|
await (async e => {
|
|
1301
1770
|
const t = await o();
|
|
1302
|
-
return new Promise((
|
|
1771
|
+
return new Promise((r, s) => {
|
|
1303
1772
|
const o = t.transaction(n, "readwrite").objectStore(n).delete(e);
|
|
1304
|
-
o.onsuccess = () =>
|
|
1773
|
+
o.onsuccess = () => r(), o.onerror = () => s(o.error);
|
|
1305
1774
|
});
|
|
1306
|
-
})(`${
|
|
1775
|
+
})(`${r}${e}`);
|
|
1307
1776
|
}
|
|
1308
1777
|
}
|
|
1309
1778
|
};
|
|
1310
|
-
},
|
|
1311
|
-
const {adapter: t, autoSyncInterval: n} = e,
|
|
1779
|
+
}, _t = e => {
|
|
1780
|
+
const {adapter: t, autoSyncInterval: n} = e, r = new Map, s = {
|
|
1312
1781
|
lastSyncTimestamp: null,
|
|
1313
1782
|
totalKeysSynced: 0,
|
|
1314
1783
|
totalBytesSynced: 0,
|
|
@@ -1328,30 +1797,30 @@ var Y = () => ({
|
|
|
1328
1797
|
const c = a.list(), l = Object.keys(c);
|
|
1329
1798
|
for (const e of l) {
|
|
1330
1799
|
const t = a._getVersion?.(e) || 0;
|
|
1331
|
-
if (t > (
|
|
1800
|
+
if (t > (r.get(e) || 0)) {
|
|
1332
1801
|
const n = c[e];
|
|
1333
|
-
o[e] = n, i += JSON.stringify(n).length,
|
|
1802
|
+
o[e] = n, i += JSON.stringify(n).length, r.set(e, t);
|
|
1334
1803
|
}
|
|
1335
1804
|
}
|
|
1336
1805
|
if (0 === Object.keys(o).length) return {
|
|
1337
1806
|
status: "no-change",
|
|
1338
|
-
stats:
|
|
1807
|
+
stats: s
|
|
1339
1808
|
};
|
|
1340
|
-
if (await t.save(o)) return
|
|
1341
|
-
|
|
1342
|
-
e.onSync && e.onSync(
|
|
1809
|
+
if (await t.save(o)) return s.lastSyncTimestamp = Date.now(), s.totalKeysSynced += Object.keys(o).length,
|
|
1810
|
+
s.totalBytesSynced += i, s.syncCount++, s.lastDuration = performance.now() - n,
|
|
1811
|
+
e.onSync && e.onSync(s), {
|
|
1343
1812
|
status: "success",
|
|
1344
|
-
stats:
|
|
1813
|
+
stats: s
|
|
1345
1814
|
};
|
|
1346
1815
|
throw new Error(`Adapter ${t.name} failed to save.`);
|
|
1347
1816
|
} catch (e) {
|
|
1348
|
-
return
|
|
1817
|
+
return s.errors++, {
|
|
1349
1818
|
status: "error",
|
|
1350
1819
|
error: String(e),
|
|
1351
|
-
stats:
|
|
1820
|
+
stats: s
|
|
1352
1821
|
};
|
|
1353
1822
|
}
|
|
1354
|
-
}), a._registerMethod("cloudSync", "getStats", () =>
|
|
1823
|
+
}), a._registerMethod("cloudSync", "getStats", () => s), n && n > 0 && (o = setInterval(() => {
|
|
1355
1824
|
const e = a.plugins.cloudSync;
|
|
1356
1825
|
e && e.sync();
|
|
1357
1826
|
}, n));
|
|
@@ -1361,7 +1830,7 @@ var Y = () => ({
|
|
|
1361
1830
|
}
|
|
1362
1831
|
}
|
|
1363
1832
|
};
|
|
1364
|
-
},
|
|
1833
|
+
}, St = (e, t) => ({
|
|
1365
1834
|
name: "MongoDB-Atlas",
|
|
1366
1835
|
save: async n => (await fetch(`${e}/action/updateOne`, {
|
|
1367
1836
|
method: "POST",
|
|
@@ -1385,32 +1854,32 @@ var Y = () => ({
|
|
|
1385
1854
|
upsert: !0
|
|
1386
1855
|
})
|
|
1387
1856
|
})).ok
|
|
1388
|
-
}),
|
|
1857
|
+
}), wt = (e, t) => ({
|
|
1389
1858
|
name: "Firebase-Firestore",
|
|
1390
1859
|
save: async e => {
|
|
1391
1860
|
try {
|
|
1392
|
-
|
|
1861
|
+
We();
|
|
1393
1862
|
return (() => {})("[Mock] Firestore Syncing:", e), !0;
|
|
1394
1863
|
} catch (e) {
|
|
1395
1864
|
return !1;
|
|
1396
1865
|
}
|
|
1397
1866
|
}
|
|
1398
|
-
}),
|
|
1867
|
+
}), bt = (e, t) => ({
|
|
1399
1868
|
name: "SQL-REST-API",
|
|
1400
1869
|
save: async n => {
|
|
1401
|
-
const
|
|
1402
|
-
if (!
|
|
1870
|
+
const r = t();
|
|
1871
|
+
if (!r) return !1;
|
|
1403
1872
|
return (await fetch(e, {
|
|
1404
1873
|
method: "PATCH",
|
|
1405
1874
|
headers: {
|
|
1406
1875
|
"Content-Type": "application/json",
|
|
1407
|
-
Authorization: `Bearer ${
|
|
1876
|
+
Authorization: `Bearer ${r}`
|
|
1408
1877
|
},
|
|
1409
1878
|
body: JSON.stringify(n),
|
|
1410
1879
|
credentials: "same-origin"
|
|
1411
1880
|
})).ok;
|
|
1412
1881
|
}
|
|
1413
|
-
}),
|
|
1882
|
+
}), vt = e => ({
|
|
1414
1883
|
name: "gstate-logger",
|
|
1415
1884
|
hooks: {
|
|
1416
1885
|
onSet: ({key: e, value: t, version: n}) => {
|
|
@@ -1419,27 +1888,27 @@ var Y = () => ({
|
|
|
1419
1888
|
onRemove: ({key: e}) => {},
|
|
1420
1889
|
onTransaction: ({key: e}) => {}
|
|
1421
1890
|
}
|
|
1422
|
-
}),
|
|
1423
|
-
const n =
|
|
1891
|
+
}), kt = (e, t) => {
|
|
1892
|
+
const n = Ge("string" == typeof t ? {
|
|
1424
1893
|
namespace: t
|
|
1425
1894
|
} : t);
|
|
1426
1895
|
e && Object.entries(e).forEach(([e, t]) => {
|
|
1427
1896
|
null === n.get(e) && n._setSilently(e, t);
|
|
1428
1897
|
});
|
|
1429
|
-
return "undefined" == typeof window ||
|
|
1430
|
-
window.rgs = n), Object.assign(e =>
|
|
1431
|
-
},
|
|
1432
|
-
const
|
|
1433
|
-
if (!
|
|
1434
|
-
return
|
|
1435
|
-
},
|
|
1436
|
-
const t =
|
|
1898
|
+
return "undefined" == typeof window || We() || (window.gstate = n, window.gState = n,
|
|
1899
|
+
window.rgs = n), Object.assign(e => et(e, n), n);
|
|
1900
|
+
}, Et = (e, t) => Ye()?.addAccessRule(e, t), Ot = (e, t, n) => Ye()?.hasPermission(e, t, n) ?? !0, Ct = (e, t, n) => {
|
|
1901
|
+
const r = Ye();
|
|
1902
|
+
if (!r) throw new Error("[gstate] recordConsent failed: No store found. call initState() first.");
|
|
1903
|
+
return r.recordConsent(e, t, n);
|
|
1904
|
+
}, Dt = (e, t) => Ye()?.hasConsent(e, t) ?? !1, Mt = e => Ye()?.getConsents(e) ?? [], At = (e, t) => Ye()?.revokeConsent(e, t), Rt = e => {
|
|
1905
|
+
const t = Ye();
|
|
1437
1906
|
if (!t) throw new Error("[gstate] exportUserData failed: No store found.");
|
|
1438
1907
|
return t.exportUserData(e);
|
|
1439
|
-
},
|
|
1440
|
-
const t =
|
|
1908
|
+
}, jt = e => {
|
|
1909
|
+
const t = Ye();
|
|
1441
1910
|
if (!t) throw new Error("[gstate] deleteUserData failed: No store found.");
|
|
1442
1911
|
return t.deleteUserData(e);
|
|
1443
|
-
},
|
|
1912
|
+
}, Pt = () => {}, Tt = () => {};
|
|
1444
1913
|
|
|
1445
|
-
export {
|
|
1914
|
+
export { c as SyncEngine, Et as addAccessRule, pt as analyticsPlugin, Pt as clearAccessRules, Tt as clearAllConsents, _t as cloudSyncPlugin, it as createAsyncStore, wt as createFirestoreAdapter, St as createMongoAdapter, bt as createSqlRestAdapter, Ge as createStore, l as createSyncEngine, gt as debugPlugin, jt as deleteUserData, Re as deriveKeyFromPassword, Ze as destroyState, rt as destroySync, dt as devToolsPlugin, Te as exportKey, Rt as exportUserData, Pe as generateEncryptionKey, je as generateSalt, Mt as getConsents, Ye as getStore, kt as gstate, yt as guardPlugin, Dt as hasConsent, Ot as hasPermission, ct as immerPlugin, Ie as importKey, mt as indexedDBPlugin, Xe as initState, nt as initSync, Ae as isCryptoAvailable, Ne as logAudit, vt as loggerPlugin, Ct as recordConsent, At as revokeConsent, Fe as sanitizeValue, ut as schemaPlugin, xe as setAuditLogger, ft as snapshotPlugin, ht as syncPlugin, at as triggerSync, lt as undoRedoPlugin, et as useGState, He as useIsStoreReady, et as useSimpleState, et as useStore, ot as useSyncStatus, st as useSyncedState, Ke as validateKey };
|