@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.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var e, t, n = require("
|
|
4
|
-
return e && (t = (0, e[
|
|
5
|
-
},
|
|
3
|
+
var e, t, n = require("react"), r = Object.defineProperty, s = Object.getOwnPropertyNames, o = (e, t) => function() {
|
|
4
|
+
return e && (t = (0, e[s(e)[0]])(e = 0)), t;
|
|
5
|
+
}, a = o({
|
|
6
6
|
"core/utils.ts"() {
|
|
7
7
|
e = e => {
|
|
8
8
|
if (null === e || "object" != typeof e) return e;
|
|
@@ -48,21 +48,21 @@ var e, t, n = require("immer"), r = require("react"), s = Object.defineProperty,
|
|
|
48
48
|
return !0;
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
}),
|
|
51
|
+
}), i = {};
|
|
52
52
|
|
|
53
53
|
((e, t) => {
|
|
54
|
-
for (var n in t)
|
|
54
|
+
for (var n in t) r(e, n, {
|
|
55
55
|
get: t[n],
|
|
56
56
|
enumerable: !0
|
|
57
57
|
});
|
|
58
|
-
})(
|
|
58
|
+
})(i, {
|
|
59
59
|
SyncEngine: () => exports.SyncEngine,
|
|
60
60
|
createSyncEngine: () => exports.createSyncEngine
|
|
61
61
|
}), exports.SyncEngine = void 0, exports.createSyncEngine = void 0;
|
|
62
62
|
|
|
63
|
-
var
|
|
63
|
+
var c = o({
|
|
64
64
|
"core/sync.ts"() {
|
|
65
|
-
|
|
65
|
+
a(), exports.SyncEngine = class {
|
|
66
66
|
store;
|
|
67
67
|
config;
|
|
68
68
|
pendingQueue=new Map;
|
|
@@ -288,7 +288,477 @@ var l = a({
|
|
|
288
288
|
}
|
|
289
289
|
}, exports.createSyncEngine = (e, t) => new exports.SyncEngine(e, t);
|
|
290
290
|
}
|
|
291
|
-
}), u = (
|
|
291
|
+
}), l = Symbol.for("immer-nothing"), u = Symbol.for("immer-draftable"), d = Symbol.for("immer-state"), y = [ 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 p(e, ...t) {
|
|
304
|
+
{
|
|
305
|
+
const n = y[e], r = z(n) ? n.apply(null, t) : n;
|
|
306
|
+
throw new Error(`[Immer] ${r}`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
var f = Object, g = f.getPrototypeOf, h = "constructor", m = "prototype", _ = "configurable", S = "enumerable", w = "writable", b = "value", v = e => !!e && !!e[d];
|
|
311
|
+
|
|
312
|
+
function E(e) {
|
|
313
|
+
return !!e && (O(e) || R(e) || !!e[u] || !!e[h]?.[u] || j(e) || T(e));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
var k = f[m][h].toString(), C = new WeakMap;
|
|
317
|
+
|
|
318
|
+
function O(e) {
|
|
319
|
+
if (!e || !I(e)) return !1;
|
|
320
|
+
const t = g(e);
|
|
321
|
+
if (null === t || t === f[m]) return !0;
|
|
322
|
+
const n = f.hasOwnProperty.call(t, h) && t[h];
|
|
323
|
+
if (n === Object) return !0;
|
|
324
|
+
if (!z(n)) return !1;
|
|
325
|
+
let r = C.get(n);
|
|
326
|
+
return void 0 === r && (r = Function.toString.call(n), C.set(n, r)), r === k;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function x(e, t, n = !0) {
|
|
330
|
+
if (0 === A(e)) {
|
|
331
|
+
(n ? Reflect.ownKeys(e) : f.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 A(e) {
|
|
338
|
+
const t = e[d];
|
|
339
|
+
return t ? t.type_ : R(e) ? 1 : j(e) ? 2 : T(e) ? 3 : 0;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
var D = (e, t, n = A(e)) => 2 === n ? e.has(t) : f[m].hasOwnProperty.call(e, t), M = (e, t, n = A(e)) => 2 === n ? e.get(t) : e[t], P = (e, t, n, r = A(e)) => {
|
|
343
|
+
2 === r ? e.set(t, n) : 3 === r ? e.add(n) : e[t] = n;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
var R = Array.isArray, j = e => e instanceof Map, T = e => e instanceof Set, I = e => "object" == typeof e, z = e => "function" == typeof e, V = e => "boolean" == typeof e;
|
|
347
|
+
|
|
348
|
+
var $ = e => e.copy_ || e.base_, N = e => e.modified_ ? e.copy_ : e.base_;
|
|
349
|
+
|
|
350
|
+
function U(e, t) {
|
|
351
|
+
if (j(e)) return new Map(e);
|
|
352
|
+
if (T(e)) return new Set(e);
|
|
353
|
+
if (R(e)) return Array[m].slice.call(e);
|
|
354
|
+
const n = O(e);
|
|
355
|
+
if (!0 === t || "class_only" === t && !n) {
|
|
356
|
+
const t = f.getOwnPropertyDescriptors(e);
|
|
357
|
+
delete t[d];
|
|
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[w] && (o[w] = !0, o[_] = !0), (o.get || o.set) && (t[s] = {
|
|
362
|
+
[_]: !0,
|
|
363
|
+
[w]: !0,
|
|
364
|
+
[S]: o[S],
|
|
365
|
+
[b]: e[s]
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
return f.create(g(e), t);
|
|
369
|
+
}
|
|
370
|
+
{
|
|
371
|
+
const t = g(e);
|
|
372
|
+
if (null !== t && n) return {
|
|
373
|
+
...e
|
|
374
|
+
};
|
|
375
|
+
const r = f.create(t);
|
|
376
|
+
return f.assign(r, e);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function L(e, t = !1) {
|
|
381
|
+
return F(e) || v(e) || !E(e) || (A(e) > 1 && f.defineProperties(e, {
|
|
382
|
+
set: K,
|
|
383
|
+
add: K,
|
|
384
|
+
clear: K,
|
|
385
|
+
delete: K
|
|
386
|
+
}), f.freeze(e), t && x(e, (e, t) => {
|
|
387
|
+
L(t, !0);
|
|
388
|
+
}, !1)), e;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
var K = {
|
|
392
|
+
[b]: function() {
|
|
393
|
+
p(2);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
function F(e) {
|
|
398
|
+
return null === e || !I(e) || f.isFrozen(e);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
var B = "MapSet", J = "Patches", W = "ArrayMethods", Q = {};
|
|
402
|
+
|
|
403
|
+
function G(e) {
|
|
404
|
+
const t = Q[e];
|
|
405
|
+
return t || p(0, e), t;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
var q, X = e => !!Q[e], Z = () => q;
|
|
409
|
+
|
|
410
|
+
function H(e, t) {
|
|
411
|
+
t && (e.patchPlugin_ = G(J), e.patches_ = [], e.inversePatches_ = [], e.patchListener_ = t);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function Y(e) {
|
|
415
|
+
ee(e), e.drafts_.forEach(ne), e.drafts_ = null;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function ee(e) {
|
|
419
|
+
e === q && (q = e.parent_);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
var te = e => q = {
|
|
423
|
+
drafts_: [],
|
|
424
|
+
parent_: q,
|
|
425
|
+
immer_: e,
|
|
426
|
+
canAutoFreeze_: !0,
|
|
427
|
+
unfinalizedDrafts_: 0,
|
|
428
|
+
handledSet_: new Set,
|
|
429
|
+
processedForPatches_: new Set,
|
|
430
|
+
mapSetPlugin_: X(B) ? G(B) : void 0,
|
|
431
|
+
arrayMethodsPlugin_: X(W) ? G(W) : void 0
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
function ne(e) {
|
|
435
|
+
const t = e[d];
|
|
436
|
+
0 === t.type_ || 1 === t.type_ ? t.revoke_() : t.revoked_ = !0;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function re(e, t) {
|
|
440
|
+
t.unfinalizedDrafts_ = t.drafts_.length;
|
|
441
|
+
const n = t.drafts_[0];
|
|
442
|
+
if (void 0 !== e && e !== n) {
|
|
443
|
+
n[d].modified_ && (Y(t), p(4)), E(e) && (e = se(t, e));
|
|
444
|
+
const {patchPlugin_: r} = t;
|
|
445
|
+
r && r.generateReplacementPatches_(n[d].base_, e, t);
|
|
446
|
+
} else e = se(t, n);
|
|
447
|
+
return function(e, t, n = !1) {
|
|
448
|
+
!e.parent_ && e.immer_.autoFreeze_ && e.canAutoFreeze_ && L(t, n);
|
|
449
|
+
}(t, e, !0), Y(t), t.patches_ && t.patchListener_(t.patches_, t.inversePatches_),
|
|
450
|
+
e !== l ? e : void 0;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function se(e, t) {
|
|
454
|
+
if (F(t)) return t;
|
|
455
|
+
const n = t[d];
|
|
456
|
+
if (!n) {
|
|
457
|
+
return ue(t, e.handledSet_, e);
|
|
458
|
+
}
|
|
459
|
+
if (!ae(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
|
+
le(n, e);
|
|
467
|
+
}
|
|
468
|
+
return n.copy_;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function oe(e) {
|
|
472
|
+
e.finalized_ = !0, e.scope_.unfinalizedDrafts_--;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
var ae = (e, t) => e.scope_ === t, ie = [];
|
|
476
|
+
|
|
477
|
+
function ce(e, t, n, r) {
|
|
478
|
+
const s = $(e), o = e.type_;
|
|
479
|
+
if (void 0 !== r) {
|
|
480
|
+
if (M(s, r, o) === t) return void P(s, r, n, o);
|
|
481
|
+
}
|
|
482
|
+
if (!e.draftLocations_) {
|
|
483
|
+
const t = e.draftLocations_ = new Map;
|
|
484
|
+
x(s, (e, n) => {
|
|
485
|
+
if (v(n)) {
|
|
486
|
+
const r = t.get(n) || [];
|
|
487
|
+
r.push(e), t.set(n, r);
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
const a = e.draftLocations_.get(t) ?? ie;
|
|
492
|
+
for (const e of a) P(s, e, n, o);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function le(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
|
+
oe(e);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function ue(e, t, n) {
|
|
507
|
+
return !n.immer_.autoFreeze_ && n.unfinalizedDrafts_ < 1 || v(e) || t.has(e) || !E(e) || F(e) || (t.add(e),
|
|
508
|
+
x(e, (r, s) => {
|
|
509
|
+
if (v(s)) {
|
|
510
|
+
const t = s[d];
|
|
511
|
+
if (ae(t, n)) {
|
|
512
|
+
const n = N(t);
|
|
513
|
+
P(e, r, n, e.type_), oe(t);
|
|
514
|
+
}
|
|
515
|
+
} else E(s) && ue(s, t, n);
|
|
516
|
+
})), e;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
var de = {
|
|
520
|
+
get(e, t) {
|
|
521
|
+
if (t === d) 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 = $(e);
|
|
526
|
+
if (!D(s, t, e.type_)) return function(e, t, n) {
|
|
527
|
+
const r = fe(t, n);
|
|
528
|
+
return r ? b in r ? r[b] : r.get?.call(e.draft_) : void 0;
|
|
529
|
+
}(e, s, t);
|
|
530
|
+
const o = s[t];
|
|
531
|
+
if (e.finalized_ || !E(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 === pe(e.base_, t)) {
|
|
537
|
+
he(e);
|
|
538
|
+
const n = 1 === e.type_ ? +t : t, r = me(e.scope_, o, e, n);
|
|
539
|
+
return e.copy_[n] = r;
|
|
540
|
+
}
|
|
541
|
+
return o;
|
|
542
|
+
},
|
|
543
|
+
has: (e, t) => t in $(e),
|
|
544
|
+
ownKeys: e => Reflect.ownKeys($(e)),
|
|
545
|
+
set(e, t, n) {
|
|
546
|
+
const r = fe($(e), t);
|
|
547
|
+
if (r?.set) return r.set.call(e.draft_, n), !0;
|
|
548
|
+
if (!e.modified_) {
|
|
549
|
+
const r = pe($(e), t), a = r?.[d];
|
|
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 || D(e.base_, t, e.type_))) return !0;
|
|
552
|
+
he(e), ge(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 (v(n)) {
|
|
559
|
+
const s = n[d];
|
|
560
|
+
ae(s, r) && s.callbacks_.push(function() {
|
|
561
|
+
he(e);
|
|
562
|
+
const r = N(s);
|
|
563
|
+
ce(e, n, r, t);
|
|
564
|
+
});
|
|
565
|
+
} else E(n) && e.callbacks_.push(function() {
|
|
566
|
+
const s = $(e);
|
|
567
|
+
3 === e.type_ ? s.has(n) && ue(n, r.handledSet_, r) : M(s, t, e.type_) === n && r.drafts_.length > 1 && !0 === (e.assigned_.get(t) ?? !1) && e.copy_ && ue(M(e.copy_, t, e.type_), r.handledSet_, r);
|
|
568
|
+
});
|
|
569
|
+
}(e, t, n)), !0;
|
|
570
|
+
},
|
|
571
|
+
deleteProperty: (e, t) => (he(e), void 0 !== pe(e.base_, t) || t in e.base_ ? (e.assigned_.set(t, !1),
|
|
572
|
+
ge(e)) : e.assigned_.delete(t), e.copy_ && delete e.copy_[t], !0),
|
|
573
|
+
getOwnPropertyDescriptor(e, t) {
|
|
574
|
+
const n = $(e), r = Reflect.getOwnPropertyDescriptor(n, t);
|
|
575
|
+
return r ? {
|
|
576
|
+
[w]: !0,
|
|
577
|
+
[_]: 1 !== e.type_ || "length" !== t,
|
|
578
|
+
[S]: r[S],
|
|
579
|
+
[b]: n[t]
|
|
580
|
+
} : r;
|
|
581
|
+
},
|
|
582
|
+
defineProperty() {
|
|
583
|
+
p(11);
|
|
584
|
+
},
|
|
585
|
+
getPrototypeOf: e => g(e.base_),
|
|
586
|
+
setPrototypeOf() {
|
|
587
|
+
p(12);
|
|
588
|
+
}
|
|
589
|
+
}, ye = {};
|
|
590
|
+
|
|
591
|
+
for (let e in de) {
|
|
592
|
+
let t = de[e];
|
|
593
|
+
ye[e] = function() {
|
|
594
|
+
const e = arguments;
|
|
595
|
+
return e[0] = e[0][0], t.apply(this, e);
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function pe(e, t) {
|
|
600
|
+
const n = e[d];
|
|
601
|
+
return (n ? $(n) : e)[t];
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function fe(e, t) {
|
|
605
|
+
if (!(t in e)) return;
|
|
606
|
+
let n = g(e);
|
|
607
|
+
for (;n; ) {
|
|
608
|
+
const e = Object.getOwnPropertyDescriptor(n, t);
|
|
609
|
+
if (e) return e;
|
|
610
|
+
n = g(n);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function ge(e) {
|
|
615
|
+
e.modified_ || (e.modified_ = !0, e.parent_ && ge(e.parent_));
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function he(e) {
|
|
619
|
+
e.copy_ || (e.assigned_ = new Map, e.copy_ = U(e.base_, e.scope_.immer_.useStrictShallowCopy_));
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
ye.deleteProperty = function(e, t) {
|
|
623
|
+
return isNaN(parseInt(t)) && p(13), ye.set.call(this, e, t, void 0);
|
|
624
|
+
}, ye.set = function(e, t, n) {
|
|
625
|
+
return "length" !== t && isNaN(parseInt(t)) && p(14), de.set.call(this, e[0], t, n, e[0]);
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
function me(e, t, n, r) {
|
|
629
|
+
const [s, o] = j(t) ? G(B).proxyMap_(t, n) : T(t) ? G(B).proxySet_(t, n) : function(e, t) {
|
|
630
|
+
const n = R(e), r = {
|
|
631
|
+
type_: n ? 1 : 0,
|
|
632
|
+
scope_: t ? t.scope_ : Z(),
|
|
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 = de;
|
|
645
|
+
n && (s = [ r ], o = ye);
|
|
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_ ?? Z()).drafts_.push(s), o.callbacks_ = n?.callbacks_ ?? [], o.key_ = r,
|
|
650
|
+
n && void 0 !== r ? function(e, t, n) {
|
|
651
|
+
e.callbacks_.push(function(r) {
|
|
652
|
+
const s = t;
|
|
653
|
+
if (!s || !ae(s, r)) return;
|
|
654
|
+
r.mapSetPlugin_?.fixSetContents(s);
|
|
655
|
+
const o = N(s);
|
|
656
|
+
ce(e, s.draft_ ?? s, o, n), le(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 _e(e) {
|
|
666
|
+
if (!E(e) || F(e)) return e;
|
|
667
|
+
const t = e[d];
|
|
668
|
+
let n, r = !0;
|
|
669
|
+
if (t) {
|
|
670
|
+
if (!t.modified_) return t.base_;
|
|
671
|
+
t.finalized_ = !0, n = U(e, t.scope_.immer_.useStrictShallowCopy_), r = t.scope_.immer_.shouldUseStrictIteration();
|
|
672
|
+
} else n = U(e, !0);
|
|
673
|
+
return x(n, (e, t) => {
|
|
674
|
+
P(n, e, _e(t));
|
|
675
|
+
}, r), t && (t.finalized_ = !1), n;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
var Se = (new class {
|
|
679
|
+
constructor(e) {
|
|
680
|
+
this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.useStrictIteration_ = !1,
|
|
681
|
+
this.produce = (e, t, n) => {
|
|
682
|
+
if (z(e) && !z(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 (z(t) || p(6), void 0 === n || z(n) || p(7), E(e)) {
|
|
692
|
+
const s = te(this), o = me(s, e, void 0);
|
|
693
|
+
let a = !0;
|
|
694
|
+
try {
|
|
695
|
+
r = t(o), a = !1;
|
|
696
|
+
} finally {
|
|
697
|
+
a ? Y(s) : ee(s);
|
|
698
|
+
}
|
|
699
|
+
return H(s, n), re(r, s);
|
|
700
|
+
}
|
|
701
|
+
if (!e || !I(e)) {
|
|
702
|
+
if (r = t(e), void 0 === r && (r = e), r === l && (r = void 0), this.autoFreeze_ && L(r, !0),
|
|
703
|
+
n) {
|
|
704
|
+
const t = [], s = [];
|
|
705
|
+
G(J).generateReplacementPatches_(e, r, {
|
|
706
|
+
patches_: t,
|
|
707
|
+
inversePatches_: s
|
|
708
|
+
}), n(t, s);
|
|
709
|
+
}
|
|
710
|
+
return r;
|
|
711
|
+
}
|
|
712
|
+
p(1, e);
|
|
713
|
+
}, this.produceWithPatches = (e, t) => {
|
|
714
|
+
if (z(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
|
+
}, V(e?.autoFreeze) && this.setAutoFreeze(e.autoFreeze), V(e?.useStrictShallowCopy) && this.setUseStrictShallowCopy(e.useStrictShallowCopy),
|
|
720
|
+
V(e?.useStrictIteration) && this.setUseStrictIteration(e.useStrictIteration);
|
|
721
|
+
}
|
|
722
|
+
createDraft(e) {
|
|
723
|
+
E(e) || p(8), v(e) && (e = function(e) {
|
|
724
|
+
v(e) || p(10, e);
|
|
725
|
+
return _e(e);
|
|
726
|
+
}(e));
|
|
727
|
+
const t = te(this), n = me(t, e, void 0);
|
|
728
|
+
return n[d].isManual_ = !0, ee(t), n;
|
|
729
|
+
}
|
|
730
|
+
finishDraft(e, t) {
|
|
731
|
+
const n = e && e[d];
|
|
732
|
+
n && n.isManual_ || p(9);
|
|
733
|
+
const {scope_: r} = n;
|
|
734
|
+
return H(r, t), re(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 = G(J).applyPatches_;
|
|
759
|
+
return v(e) ? r(e, t) : this.produce(e, e => r(e, t));
|
|
760
|
+
}
|
|
761
|
+
}).produce, we = (e, t) => {
|
|
292
762
|
const n = Date.now();
|
|
293
763
|
if (/\(\.*\+\?\)\+/.test(e) || /\(\.*\?\)\*/.test(e)) return !1;
|
|
294
764
|
if (e.length > 500) return !1;
|
|
@@ -299,35 +769,35 @@ var l = a({
|
|
|
299
769
|
} catch {
|
|
300
770
|
return !1;
|
|
301
771
|
}
|
|
302
|
-
},
|
|
772
|
+
}, be = () => {
|
|
303
773
|
if ("undefined" != typeof crypto && "function" == typeof crypto.randomUUID) try {
|
|
304
774
|
return crypto.randomUUID();
|
|
305
775
|
} catch {}
|
|
306
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.");
|
|
307
|
-
},
|
|
777
|
+
}, ve = "undefined" != typeof crypto && void 0 !== crypto.subtle && "function" == typeof crypto.subtle.generateKey, Ee = async (e, t) => {
|
|
308
778
|
const n = (new TextEncoder).encode(JSON.stringify(e)), r = await crypto.subtle.encrypt({
|
|
309
779
|
name: "AES-GCM",
|
|
310
780
|
iv: t.iv
|
|
311
781
|
}, t.key, n), s = new Uint8Array(t.iv.length + r.byteLength);
|
|
312
782
|
return s.set(t.iv), s.set(new Uint8Array(r), t.iv.length), btoa(String.fromCharCode(...s));
|
|
313
|
-
},
|
|
783
|
+
}, ke = async (e, t) => {
|
|
314
784
|
const n = Uint8Array.from(atob(e), e => e.charCodeAt(0)), r = n.slice(0, 12), s = n.slice(12), o = await crypto.subtle.decrypt({
|
|
315
785
|
name: "AES-GCM",
|
|
316
786
|
iv: r
|
|
317
787
|
}, t.key, s);
|
|
318
788
|
return JSON.parse((new TextDecoder).decode(o));
|
|
319
|
-
},
|
|
320
|
-
|
|
321
|
-
},
|
|
789
|
+
}, Ce = null, Oe = e => {
|
|
790
|
+
Ce && Ce(e);
|
|
791
|
+
}, xe = (e, t, n) => {
|
|
322
792
|
e.set(t instanceof RegExp ? t.source : t, n);
|
|
323
|
-
},
|
|
793
|
+
}, Ae = (e, t, n, r) => {
|
|
324
794
|
if (0 === e.size) return !0;
|
|
325
795
|
for (const [s, o] of e) {
|
|
326
796
|
let e;
|
|
327
|
-
if (e = "function" == typeof s ? s(t, r) :
|
|
797
|
+
if (e = "function" == typeof s ? s(t, r) : we(s, t), e) return o.includes(n) || o.includes("admin");
|
|
328
798
|
}
|
|
329
799
|
return !1;
|
|
330
|
-
},
|
|
800
|
+
}, De = e => {
|
|
331
801
|
if ("string" == typeof e) {
|
|
332
802
|
let t = e.replace(/&#[xX]?[0-9a-fA-F]+;?/g, e => {
|
|
333
803
|
const t = e.match(/&#x([0-9a-fA-F]+);?/i);
|
|
@@ -343,20 +813,20 @@ var l = a({
|
|
|
343
813
|
if (e && "object" == typeof e && !Array.isArray(e)) {
|
|
344
814
|
if (Object.getPrototypeOf(e) === Object.prototype) {
|
|
345
815
|
const t = {};
|
|
346
|
-
for (const [n, r] of Object.entries(e)) t[n] =
|
|
816
|
+
for (const [n, r] of Object.entries(e)) t[n] = De(r);
|
|
347
817
|
return t;
|
|
348
818
|
}
|
|
349
819
|
return e;
|
|
350
820
|
}
|
|
351
|
-
return Array.isArray(e) ? e.map(e =>
|
|
352
|
-
},
|
|
821
|
+
return Array.isArray(e) ? e.map(e => De(e)) : e;
|
|
822
|
+
}, Me = e => /^([a-zA-Z0-9_.-][a-zA-Z0-9_.-]*)$/.test(e) && e.length <= 256 && e.length > 0, Pe = (e, t, n, r) => {
|
|
353
823
|
const s = {
|
|
354
|
-
id:
|
|
824
|
+
id: be(),
|
|
355
825
|
purpose: n,
|
|
356
826
|
granted: r,
|
|
357
827
|
timestamp: Date.now()
|
|
358
828
|
}, o = e.get(t) || [];
|
|
359
|
-
return o.push(s), e.set(t, o),
|
|
829
|
+
return o.push(s), e.set(t, o), Oe({
|
|
360
830
|
timestamp: Date.now(),
|
|
361
831
|
action: "set",
|
|
362
832
|
key: `consent:${n}`,
|
|
@@ -365,13 +835,13 @@ var l = a({
|
|
|
365
835
|
}), s;
|
|
366
836
|
};
|
|
367
837
|
|
|
368
|
-
|
|
838
|
+
a();
|
|
369
839
|
|
|
370
|
-
var
|
|
840
|
+
var Re = e => `${e}_`;
|
|
371
841
|
|
|
372
|
-
|
|
842
|
+
a();
|
|
373
843
|
|
|
374
|
-
var
|
|
844
|
+
var je = () => {
|
|
375
845
|
try {
|
|
376
846
|
0;
|
|
377
847
|
const e = "undefined" != typeof globalThis ? globalThis : "undefined" != typeof window ? window : {};
|
|
@@ -379,31 +849,31 @@ var k = () => {
|
|
|
379
849
|
} catch {
|
|
380
850
|
return !1;
|
|
381
851
|
}
|
|
382
|
-
},
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
let
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
}),
|
|
389
|
-
store:
|
|
390
|
-
versions:
|
|
391
|
-
sizes:
|
|
392
|
-
totalSize:
|
|
393
|
-
storage:
|
|
394
|
-
config:
|
|
395
|
-
diskQueue:
|
|
396
|
-
encryptionKey:
|
|
397
|
-
audit:
|
|
398
|
-
onError:
|
|
399
|
-
silent:
|
|
400
|
-
debounceTime:
|
|
401
|
-
currentVersion:
|
|
402
|
-
}),
|
|
403
|
-
plugins:
|
|
404
|
-
onError:
|
|
405
|
-
silent:
|
|
406
|
-
}),
|
|
852
|
+
}, Te = () => "undefined" != typeof window ? window.localStorage : null, Ie = n => {
|
|
853
|
+
const r = new Map, s = new Map, o = new Map, a = new Set, l = new Map, u = new Set, d = new Map, y = new Map, p = new Map, f = new Map, g = new Map, h = new Map, m = new Map, _ = new Map, S = n?.namespace || "gstate", w = n?.silent ?? !1, b = n?.debounceTime ?? 150, v = n?.version ?? 0, E = n?.storage || Te(), k = n?.onError, C = n?.maxObjectSize ?? 0, O = n?.maxTotalSize ?? 0, x = n?.encryptionKey ?? null, A = n?.validateInput ?? !0, D = n?.auditEnabled ?? !0, M = n?.userId, P = n?.immer ?? !0, R = n?.persistByDefault ?? n?.persistence ?? n?.persist ?? !1;
|
|
854
|
+
n?.accessRules && n.accessRules.forEach(e => xe(m, e.pattern, e.permissions));
|
|
855
|
+
let j, T = !1, I = !1, z = !1, V = 0, $ = null, N = null;
|
|
856
|
+
const U = new Promise(e => {
|
|
857
|
+
j = e;
|
|
858
|
+
}), K = () => `${S}_`, F = () => ({
|
|
859
|
+
store: r,
|
|
860
|
+
versions: s,
|
|
861
|
+
sizes: o,
|
|
862
|
+
totalSize: V,
|
|
863
|
+
storage: E,
|
|
864
|
+
config: n || {},
|
|
865
|
+
diskQueue: g,
|
|
866
|
+
encryptionKey: x,
|
|
867
|
+
audit: Q,
|
|
868
|
+
onError: k,
|
|
869
|
+
silent: w,
|
|
870
|
+
debounceTime: b,
|
|
871
|
+
currentVersion: v
|
|
872
|
+
}), B = () => ({
|
|
873
|
+
plugins: f,
|
|
874
|
+
onError: k,
|
|
875
|
+
silent: w
|
|
876
|
+
}), J = e => {
|
|
407
877
|
if (null == e) return 0;
|
|
408
878
|
const t = typeof e;
|
|
409
879
|
if ("boolean" === t) return 4;
|
|
@@ -422,7 +892,7 @@ var k = () => {
|
|
|
422
892
|
}
|
|
423
893
|
}
|
|
424
894
|
return n;
|
|
425
|
-
},
|
|
895
|
+
}, W = (e, t) => {
|
|
426
896
|
((e, t, n) => {
|
|
427
897
|
if (0 !== e.plugins.size) for (const r of e.plugins.values()) {
|
|
428
898
|
const s = r.hooks?.[t];
|
|
@@ -436,71 +906,71 @@ var k = () => {
|
|
|
436
906
|
}) : e.silent;
|
|
437
907
|
}
|
|
438
908
|
}
|
|
439
|
-
})(
|
|
440
|
-
},
|
|
441
|
-
|
|
909
|
+
})(B(), e, t);
|
|
910
|
+
}, Q = (e, t, n, r) => {
|
|
911
|
+
D && null !== Ce && Oe && Oe({
|
|
442
912
|
timestamp: Date.now(),
|
|
443
913
|
action: e,
|
|
444
914
|
key: t,
|
|
445
|
-
userId:
|
|
915
|
+
userId: M,
|
|
446
916
|
success: n,
|
|
447
917
|
error: r
|
|
448
918
|
});
|
|
449
|
-
},
|
|
450
|
-
const
|
|
451
|
-
if (!
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
if (!
|
|
455
|
-
const t =
|
|
456
|
-
t && (t.delete(
|
|
919
|
+
}, G = n => {
|
|
920
|
+
const r = y.get(n);
|
|
921
|
+
if (!r) return;
|
|
922
|
+
const o = new Set, a = r.selector(e => (o.add(e), y.has(e) ? y.get(e).lastValue : H.get(e)));
|
|
923
|
+
r.deps.forEach(e => {
|
|
924
|
+
if (!o.has(e)) {
|
|
925
|
+
const t = p.get(e);
|
|
926
|
+
t && (t.delete(n), 0 === t.size && p.delete(e));
|
|
457
927
|
}
|
|
458
|
-
}),
|
|
459
|
-
|
|
460
|
-
}),
|
|
461
|
-
|
|
462
|
-
},
|
|
928
|
+
}), o.forEach(e => {
|
|
929
|
+
r.deps.has(e) || (p.has(e) || p.set(e, new Set), p.get(e).add(n));
|
|
930
|
+
}), r.deps = o, t(r.lastValue, a) || (r.lastValue = P && null !== a && "object" == typeof a ? L(e(a), !0) : a,
|
|
931
|
+
s.set(n, (s.get(n) || 0) + 1), q(n));
|
|
932
|
+
}, q = e => {
|
|
463
933
|
if (e) {
|
|
464
|
-
if (
|
|
465
|
-
const t =
|
|
466
|
-
for (const e of t)
|
|
934
|
+
if (p.has(e)) {
|
|
935
|
+
const t = p.get(e);
|
|
936
|
+
for (const e of t) G(e);
|
|
467
937
|
}
|
|
468
938
|
const t = d.get(e);
|
|
469
939
|
if (t) {
|
|
470
|
-
const n =
|
|
940
|
+
const n = H.get(e);
|
|
471
941
|
for (const r of t) try {
|
|
472
942
|
r(n);
|
|
473
943
|
} catch (t) {
|
|
474
944
|
const n = t instanceof Error ? t : new Error(String(t));
|
|
475
|
-
|
|
945
|
+
k && k(n, {
|
|
476
946
|
operation: "watcher",
|
|
477
947
|
key: e
|
|
478
948
|
});
|
|
479
949
|
}
|
|
480
950
|
}
|
|
481
|
-
const n =
|
|
951
|
+
const n = l.get(e);
|
|
482
952
|
if (n) for (const t of n) try {
|
|
483
953
|
t();
|
|
484
954
|
} catch (t) {
|
|
485
955
|
const n = t instanceof Error ? t : new Error(String(t));
|
|
486
|
-
|
|
956
|
+
k && k(n, {
|
|
487
957
|
operation: "keyListener",
|
|
488
958
|
key: e
|
|
489
959
|
});
|
|
490
960
|
}
|
|
491
961
|
}
|
|
492
|
-
if (
|
|
962
|
+
if (T) I = !0; else for (const e of a) try {
|
|
493
963
|
e();
|
|
494
964
|
} catch (e) {
|
|
495
965
|
const t = e instanceof Error ? e : new Error(String(e));
|
|
496
|
-
|
|
966
|
+
k && k(t, {
|
|
497
967
|
operation: "listener"
|
|
498
968
|
});
|
|
499
969
|
}
|
|
500
|
-
},
|
|
970
|
+
}, X = async () => {
|
|
501
971
|
(async e => {
|
|
502
972
|
if (!e.storage) return;
|
|
503
|
-
const {store: t, config: n, diskQueue: r, storage: s, encryptionKey: o, audit: a, onError: i, silent: c, currentVersion: l} = e, u =
|
|
973
|
+
const {store: t, config: n, diskQueue: r, storage: s, encryptionKey: o, audit: a, onError: i, silent: c, currentVersion: l} = e, u = Re(n.namespace || "gstate");
|
|
504
974
|
try {
|
|
505
975
|
const e = {};
|
|
506
976
|
let r;
|
|
@@ -523,15 +993,15 @@ var k = () => {
|
|
|
523
993
|
key: "FULL_STATE"
|
|
524
994
|
});
|
|
525
995
|
}
|
|
526
|
-
const
|
|
996
|
+
const d = Array.from(r.entries());
|
|
527
997
|
r.clear();
|
|
528
|
-
for (const [t, n] of
|
|
998
|
+
for (const [t, n] of d) try {
|
|
529
999
|
if (!t || !/^[a-zA-Z0-9_.-]+$/.test(t) || t.length > 256) continue;
|
|
530
1000
|
let r = n.value;
|
|
531
1001
|
const i = n.options.encoded || n.options.encrypted || n.options.secure;
|
|
532
1002
|
if (n.options.encrypted) {
|
|
533
1003
|
if (!o) throw new Error(`Encryption key missing for "${t}"`);
|
|
534
|
-
r = await
|
|
1004
|
+
r = await Ee(n.value, o);
|
|
535
1005
|
} else i ? r = btoa(JSON.stringify(n.value)) : "object" == typeof n.value && null !== n.value && (r = JSON.stringify(n.value));
|
|
536
1006
|
s.setItem(`${u}${t}`, JSON.stringify({
|
|
537
1007
|
v: e.versions.get(t) || 1,
|
|
@@ -549,83 +1019,83 @@ var k = () => {
|
|
|
549
1019
|
key: t
|
|
550
1020
|
});
|
|
551
1021
|
}
|
|
552
|
-
})(
|
|
553
|
-
},
|
|
554
|
-
_setSilently: (t,
|
|
555
|
-
const
|
|
556
|
-
|
|
1022
|
+
})(F());
|
|
1023
|
+
}, Z = {}, H = {
|
|
1024
|
+
_setSilently: (t, n) => {
|
|
1025
|
+
const a = o.get(t) || 0, i = P && null !== n && "object" == typeof n ? L(e(n), !0) : n, c = (C > 0 || O > 0) && !je() ? J(i) : 0;
|
|
1026
|
+
V = V - a + c, o.set(t, c), r.set(t, i), s.set(t, (s.get(t) || 0) + 1), N = null;
|
|
557
1027
|
},
|
|
558
1028
|
_registerMethod: (e, t, n) => {
|
|
559
1029
|
const r = e => "__proto__" === e || "constructor" === e || "prototype" === e;
|
|
560
|
-
r(e) || r(t) || (
|
|
1030
|
+
r(e) || r(t) || (Z[e] || (Z[e] = {}), Z[e][t] = n);
|
|
561
1031
|
},
|
|
562
|
-
set: (i, c
|
|
563
|
-
const
|
|
564
|
-
if (
|
|
565
|
-
if (!
|
|
566
|
-
const d =
|
|
567
|
-
|
|
568
|
-
key:
|
|
1032
|
+
set: (a, i, c = {}) => {
|
|
1033
|
+
const l = r.get(a), u = P && "function" == typeof i ? Se(l, i) : i;
|
|
1034
|
+
if (A && !Me(a)) return !1;
|
|
1035
|
+
if (!Ae(m, a, "write", M)) return Q("set", a, !1, "RBAC Denied"), !1;
|
|
1036
|
+
const d = A ? De(u) : u, y = o.get(a) || 0;
|
|
1037
|
+
W("onBeforeSet", {
|
|
1038
|
+
key: a,
|
|
569
1039
|
value: d,
|
|
570
|
-
store:
|
|
571
|
-
version:
|
|
1040
|
+
store: H,
|
|
1041
|
+
version: s.get(a) || 0
|
|
572
1042
|
});
|
|
573
|
-
const p =
|
|
574
|
-
if (!t(
|
|
575
|
-
const e = (
|
|
576
|
-
if (
|
|
577
|
-
const t = new Error(`Object size (${e} bytes) exceeds maxObjectSize (${
|
|
578
|
-
|
|
1043
|
+
const p = P && null !== d && "object" == typeof d ? L(e(d), !0) : d;
|
|
1044
|
+
if (!t(l, p)) {
|
|
1045
|
+
const e = (C > 0 || O > 0) && !je() ? J(p) : 0;
|
|
1046
|
+
if (C > 0 && e > C) {
|
|
1047
|
+
const t = new Error(`Object size (${e} bytes) exceeds maxObjectSize (${C} bytes)`);
|
|
1048
|
+
return k && k(t, {
|
|
579
1049
|
operation: "set",
|
|
580
|
-
key:
|
|
581
|
-
});
|
|
1050
|
+
key: a
|
|
1051
|
+
}), !1;
|
|
582
1052
|
}
|
|
583
|
-
if (
|
|
584
|
-
const t =
|
|
585
|
-
if (t >
|
|
586
|
-
const e = new Error(`Total store size (${t} bytes) exceeds limit (${
|
|
587
|
-
|
|
1053
|
+
if (O > 0) {
|
|
1054
|
+
const t = V - y + e;
|
|
1055
|
+
if (t > O) {
|
|
1056
|
+
const e = new Error(`Total store size (${t} bytes) exceeds limit (${O} bytes)`);
|
|
1057
|
+
return k && k(e, {
|
|
588
1058
|
operation: "set"
|
|
589
|
-
});
|
|
1059
|
+
}), !1;
|
|
590
1060
|
}
|
|
591
1061
|
}
|
|
592
|
-
|
|
593
|
-
const t =
|
|
594
|
-
return t && (
|
|
1062
|
+
V = V - y + e, o.set(a, e), r.set(a, p), s.set(a, (s.get(a) || 0) + 1), N = null;
|
|
1063
|
+
const t = c.persist ?? R;
|
|
1064
|
+
return t && (g.set(a, {
|
|
595
1065
|
value: p,
|
|
596
1066
|
options: {
|
|
597
|
-
...
|
|
1067
|
+
...c,
|
|
598
1068
|
persist: t,
|
|
599
|
-
encoded:
|
|
1069
|
+
encoded: c.encoded || n?.encoded
|
|
600
1070
|
}
|
|
601
|
-
}),
|
|
602
|
-
key:
|
|
1071
|
+
}), $ && clearTimeout($), $ = setTimeout(X, b)), W("onSet", {
|
|
1072
|
+
key: a,
|
|
603
1073
|
value: p,
|
|
604
|
-
store:
|
|
605
|
-
version:
|
|
606
|
-
}),
|
|
1074
|
+
store: H,
|
|
1075
|
+
version: s.get(a)
|
|
1076
|
+
}), Q("set", a, !0), q(a), !0;
|
|
607
1077
|
}
|
|
608
1078
|
return !1;
|
|
609
1079
|
},
|
|
610
1080
|
get: e => {
|
|
611
|
-
if (!
|
|
612
|
-
const t =
|
|
613
|
-
return
|
|
614
|
-
store:
|
|
1081
|
+
if (!Ae(m, e, "read", M)) return Q("get", e, !1, "RBAC Denied"), null;
|
|
1082
|
+
const t = r.get(e);
|
|
1083
|
+
return W("onGet", {
|
|
1084
|
+
store: H,
|
|
615
1085
|
key: e,
|
|
616
1086
|
value: t
|
|
617
|
-
}),
|
|
1087
|
+
}), Q("get", e, !0), t;
|
|
618
1088
|
},
|
|
619
1089
|
compute: (e, t) => {
|
|
620
1090
|
try {
|
|
621
|
-
return
|
|
1091
|
+
return y.has(e) || (y.set(e, {
|
|
622
1092
|
selector: t,
|
|
623
1093
|
lastValue: null,
|
|
624
1094
|
deps: new Set
|
|
625
|
-
}),
|
|
1095
|
+
}), G(e)), y.get(e).lastValue;
|
|
626
1096
|
} catch (t) {
|
|
627
1097
|
const n = t instanceof Error ? t : new Error(String(t));
|
|
628
|
-
return
|
|
1098
|
+
return k && k(n, {
|
|
629
1099
|
operation: "compute",
|
|
630
1100
|
key: e
|
|
631
1101
|
}), null;
|
|
@@ -639,50 +1109,51 @@ var k = () => {
|
|
|
639
1109
|
};
|
|
640
1110
|
},
|
|
641
1111
|
remove: e => {
|
|
642
|
-
if (!
|
|
643
|
-
const t =
|
|
644
|
-
return n && (
|
|
645
|
-
store:
|
|
1112
|
+
if (!Ae(m, e, "delete", M)) return Q("delete", e, !1, "RBAC Denied"), !1;
|
|
1113
|
+
const t = r.get(e), n = r.delete(e);
|
|
1114
|
+
return n && (V -= o.get(e) || 0, o.delete(e), W("onRemove", {
|
|
1115
|
+
store: H,
|
|
646
1116
|
key: e,
|
|
647
1117
|
value: t
|
|
648
|
-
}),
|
|
649
|
-
|
|
1118
|
+
}), N = null), s.set(e, (s.get(e) || 0) + 1), E && E.removeItem(`${K()}${e}`), Q("delete", e, !0),
|
|
1119
|
+
q(e), n;
|
|
650
1120
|
},
|
|
651
|
-
delete: e =>
|
|
1121
|
+
delete: e => H.remove(e),
|
|
652
1122
|
deleteAll: () => {
|
|
653
|
-
if (Array.from(
|
|
654
|
-
const e =
|
|
655
|
-
for (let
|
|
656
|
-
const n =
|
|
657
|
-
n
|
|
1123
|
+
if (Array.from(r.keys()).forEach(e => H.remove(e)), E) {
|
|
1124
|
+
const e = K(), t = [], n = E.length || 0;
|
|
1125
|
+
for (let r = 0; r < n; r++) {
|
|
1126
|
+
const n = E.key(r);
|
|
1127
|
+
n && n.startsWith(e) && t.push(n);
|
|
658
1128
|
}
|
|
1129
|
+
for (const e of t) E.removeItem(e);
|
|
659
1130
|
}
|
|
660
|
-
return
|
|
1131
|
+
return V = 0, o.clear(), N = null, !0;
|
|
661
1132
|
},
|
|
662
|
-
list: () => Object.fromEntries(
|
|
1133
|
+
list: () => Object.fromEntries(r.entries()),
|
|
663
1134
|
use: e => {
|
|
664
|
-
|
|
1135
|
+
u.add(e);
|
|
665
1136
|
},
|
|
666
1137
|
transaction: e => {
|
|
667
|
-
|
|
668
|
-
store:
|
|
1138
|
+
T = !0, W("onTransaction", {
|
|
1139
|
+
store: H,
|
|
669
1140
|
key: "START"
|
|
670
1141
|
});
|
|
671
1142
|
try {
|
|
672
1143
|
e();
|
|
673
1144
|
} finally {
|
|
674
|
-
|
|
675
|
-
store:
|
|
1145
|
+
T = !1, W("onTransaction", {
|
|
1146
|
+
store: H,
|
|
676
1147
|
key: "END"
|
|
677
|
-
}),
|
|
1148
|
+
}), I && (I = !1, q());
|
|
678
1149
|
}
|
|
679
1150
|
},
|
|
680
1151
|
destroy: () => {
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
store:
|
|
684
|
-
}),
|
|
685
|
-
|
|
1152
|
+
$ && (clearTimeout($), $ = null), g.clear(), "undefined" != typeof window && window.removeEventListener("beforeunload", Y),
|
|
1153
|
+
W("onDestroy", {
|
|
1154
|
+
store: H
|
|
1155
|
+
}), a.clear(), l.clear(), d.clear(), y.clear(), p.clear(), f.clear(), r.clear(),
|
|
1156
|
+
o.clear(), V = 0, m.clear(), _.clear(), s.clear(), h.clear(), u.clear();
|
|
686
1157
|
},
|
|
687
1158
|
_addPlugin: e => {
|
|
688
1159
|
((e, t, n) => {
|
|
@@ -697,25 +1168,25 @@ var k = () => {
|
|
|
697
1168
|
key: t.name
|
|
698
1169
|
}) : e.silent;
|
|
699
1170
|
}
|
|
700
|
-
})(
|
|
1171
|
+
})(B(), e, H);
|
|
701
1172
|
},
|
|
702
1173
|
_removePlugin: e => {
|
|
703
|
-
|
|
1174
|
+
f.delete(e);
|
|
704
1175
|
},
|
|
705
1176
|
_subscribe: (e, t) => {
|
|
706
1177
|
if (t) {
|
|
707
|
-
|
|
708
|
-
const n =
|
|
1178
|
+
l.has(t) || l.set(t, new Set);
|
|
1179
|
+
const n = l.get(t);
|
|
709
1180
|
return n.add(e), () => {
|
|
710
|
-
n.delete(e), 0 === n.size &&
|
|
1181
|
+
n.delete(e), 0 === n.size && l.delete(t);
|
|
711
1182
|
};
|
|
712
1183
|
}
|
|
713
|
-
return
|
|
1184
|
+
return a.add(e), () => a.delete(e);
|
|
714
1185
|
},
|
|
715
|
-
_getVersion: e =>
|
|
716
|
-
addAccessRule: (e, t) => m
|
|
717
|
-
hasPermission: (e, t, n) =>
|
|
718
|
-
recordConsent: (e, t, n) =>
|
|
1186
|
+
_getVersion: e => s.get(e) ?? 0,
|
|
1187
|
+
addAccessRule: (e, t) => xe(m, e, t),
|
|
1188
|
+
hasPermission: (e, t, n) => Ae(m, e, t, n),
|
|
1189
|
+
recordConsent: (e, t, n) => Pe(_, e, t, n),
|
|
719
1190
|
hasConsent: (e, t) => ((e, t, n) => {
|
|
720
1191
|
const r = e.get(t);
|
|
721
1192
|
if (!r) return !1;
|
|
@@ -724,117 +1195,117 @@ var k = () => {
|
|
|
724
1195
|
if (t && t.purpose === n) return t.granted;
|
|
725
1196
|
}
|
|
726
1197
|
return !1;
|
|
727
|
-
})(
|
|
728
|
-
getConsents: e => ((e, t) => e.get(t) || [])(
|
|
729
|
-
revokeConsent: (e, t) => ((e, t, n) =>
|
|
1198
|
+
})(_, e, t),
|
|
1199
|
+
getConsents: e => ((e, t) => e.get(t) || [])(_, e),
|
|
1200
|
+
revokeConsent: (e, t) => ((e, t, n) => Pe(e, t, n, !1))(_, e, t),
|
|
730
1201
|
exportUserData: e => ((e, t) => ({
|
|
731
1202
|
userId: t,
|
|
732
1203
|
exportedAt: Date.now(),
|
|
733
1204
|
consents: e.get(t) || []
|
|
734
|
-
}))(
|
|
1205
|
+
}))(_, e),
|
|
735
1206
|
deleteUserData: e => ((e, t) => {
|
|
736
1207
|
const n = e.get(t)?.length || 0;
|
|
737
1208
|
return e.delete(t), {
|
|
738
1209
|
success: !0,
|
|
739
1210
|
deletedConsents: n
|
|
740
1211
|
};
|
|
741
|
-
})(
|
|
742
|
-
getSnapshot: () => (
|
|
1212
|
+
})(_, e),
|
|
1213
|
+
getSnapshot: () => (N || (N = Object.fromEntries(r.entries())), N),
|
|
743
1214
|
get plugins() {
|
|
744
|
-
return
|
|
1215
|
+
return Z;
|
|
745
1216
|
},
|
|
746
1217
|
get isReady() {
|
|
747
|
-
return
|
|
1218
|
+
return z;
|
|
748
1219
|
},
|
|
749
1220
|
get namespace() {
|
|
750
|
-
return
|
|
1221
|
+
return S;
|
|
751
1222
|
},
|
|
752
1223
|
get userId() {
|
|
753
|
-
return
|
|
1224
|
+
return M;
|
|
754
1225
|
},
|
|
755
|
-
whenReady: () =>
|
|
1226
|
+
whenReady: () => U
|
|
756
1227
|
};
|
|
757
1228
|
[ "addAccessRule", "recordConsent", "hasConsent", "getConsents", "revokeConsent", "exportUserData", "deleteUserData" ].forEach(e => {
|
|
758
|
-
const t =
|
|
759
|
-
t &&
|
|
1229
|
+
const t = H[e];
|
|
1230
|
+
t && H._registerMethod("security", e, t);
|
|
760
1231
|
});
|
|
761
|
-
const
|
|
762
|
-
|
|
1232
|
+
const Y = () => {
|
|
1233
|
+
g.size > 0 && X();
|
|
763
1234
|
};
|
|
764
|
-
if ("undefined" != typeof window && window.addEventListener("beforeunload",
|
|
765
|
-
|
|
766
|
-
const {storage:
|
|
767
|
-
if (
|
|
768
|
-
const
|
|
769
|
-
let
|
|
770
|
-
for (let e = 0; e < (
|
|
771
|
-
const t =
|
|
772
|
-
if (!t || !t.startsWith(
|
|
773
|
-
const n =
|
|
1235
|
+
if ("undefined" != typeof window && window.addEventListener("beforeunload", Y),
|
|
1236
|
+
E ? (async (t, n, r) => {
|
|
1237
|
+
const {storage: s, config: o, encryptionKey: a, audit: i, onError: c, silent: l, currentVersion: u, store: d, sizes: y, versions: p} = t, f = Re(o.namespace || "gstate"), g = o.immer ?? !0;
|
|
1238
|
+
if (s) try {
|
|
1239
|
+
const l = {};
|
|
1240
|
+
let h = 0;
|
|
1241
|
+
for (let e = 0; e < (s.length || 0); e++) {
|
|
1242
|
+
const t = s.key(e);
|
|
1243
|
+
if (!t || !t.startsWith(f)) continue;
|
|
1244
|
+
const n = s.getItem(t);
|
|
774
1245
|
if (n) try {
|
|
775
|
-
const r = JSON.parse(n),
|
|
776
|
-
if (
|
|
777
|
-
|
|
1246
|
+
const r = JSON.parse(n), o = t.substring(f.length);
|
|
1247
|
+
if (h = Math.max(h, void 0 !== r._sys_v ? r._sys_v : r.v || 0), r.e && Date.now() > r.e) {
|
|
1248
|
+
s.removeItem(t), e--;
|
|
778
1249
|
continue;
|
|
779
1250
|
}
|
|
780
|
-
let
|
|
781
|
-
if (r._enc &&
|
|
782
|
-
|
|
783
|
-
} catch (e) {} else if (
|
|
784
|
-
|
|
1251
|
+
let c = r.d;
|
|
1252
|
+
if (r._enc && a) c = await ke(c, a); else if ("string" == typeof c) if (r._b64) try {
|
|
1253
|
+
c = JSON.parse(atob(c));
|
|
1254
|
+
} catch (e) {} else if (c.startsWith("{") || c.startsWith("[")) try {
|
|
1255
|
+
c = JSON.parse(c);
|
|
785
1256
|
} catch (e) {}
|
|
786
|
-
|
|
1257
|
+
l[o] = c, i("hydrate", o, !0);
|
|
787
1258
|
} catch (e) {
|
|
788
|
-
|
|
1259
|
+
i("hydrate", t, !1, String(e));
|
|
789
1260
|
const n = e instanceof Error ? e : new Error(String(e));
|
|
790
|
-
|
|
1261
|
+
c && c(n, {
|
|
791
1262
|
operation: "hydration",
|
|
792
1263
|
key: t
|
|
793
1264
|
});
|
|
794
1265
|
}
|
|
795
1266
|
}
|
|
796
|
-
const
|
|
797
|
-
Object.entries(
|
|
798
|
-
const
|
|
799
|
-
t.totalSize = t.totalSize -
|
|
800
|
-
}),
|
|
1267
|
+
const m = h < u && o.migrate ? o.migrate(l, h) : l;
|
|
1268
|
+
Object.entries(m).forEach(([r, s]) => {
|
|
1269
|
+
const o = g && null !== s && "object" == typeof s ? L(e(s), !0) : s, a = n(o), i = y.get(r) || 0;
|
|
1270
|
+
t.totalSize = t.totalSize - i + a, y.set(r, a), d.set(r, o), p.set(r, 1);
|
|
1271
|
+
}), r();
|
|
801
1272
|
} catch (e) {
|
|
802
1273
|
const t = e instanceof Error ? e : new Error(String(e));
|
|
803
|
-
|
|
1274
|
+
c && c(t, {
|
|
804
1275
|
operation: "hydration"
|
|
805
1276
|
});
|
|
806
1277
|
}
|
|
807
|
-
})(
|
|
808
|
-
|
|
809
|
-
}).then(() => {}) : (
|
|
810
|
-
const e =
|
|
811
|
-
const {SyncEngine: t} = await Promise.resolve().then(() => (
|
|
812
|
-
return new t(
|
|
1278
|
+
})(F(), e => (C > 0 || O > 0) && !je() ? J(e) : 0, () => {
|
|
1279
|
+
z = !0, N = null, j(), q();
|
|
1280
|
+
}).then(() => {}) : (z = !0, j()), n?.sync) {
|
|
1281
|
+
const e = n.sync, t = async () => {
|
|
1282
|
+
const {SyncEngine: t} = await Promise.resolve().then(() => (c(), i));
|
|
1283
|
+
return new t(H, e);
|
|
813
1284
|
};
|
|
814
|
-
let
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
return (await
|
|
818
|
-
}),
|
|
819
|
-
|
|
820
|
-
return (await
|
|
821
|
-
}),
|
|
822
|
-
|
|
823
|
-
return (await
|
|
824
|
-
}),
|
|
825
|
-
|
|
826
|
-
return (await
|
|
1285
|
+
let r = null;
|
|
1286
|
+
H._registerMethod("sync", "flush", async () => {
|
|
1287
|
+
r || (r = t());
|
|
1288
|
+
return (await r).flush();
|
|
1289
|
+
}), H._registerMethod("sync", "getState", async () => {
|
|
1290
|
+
r || (r = t());
|
|
1291
|
+
return (await r).getState();
|
|
1292
|
+
}), H._registerMethod("sync", "onStateChange", async e => {
|
|
1293
|
+
r || (r = t());
|
|
1294
|
+
return (await r).onStateChange(e);
|
|
1295
|
+
}), H._registerMethod("sync", "forceSync", async () => {
|
|
1296
|
+
r || (r = t());
|
|
1297
|
+
return (await r).sync();
|
|
827
1298
|
});
|
|
828
1299
|
}
|
|
829
|
-
return
|
|
1300
|
+
return H;
|
|
830
1301
|
};
|
|
831
1302
|
|
|
832
|
-
|
|
1303
|
+
c();
|
|
833
1304
|
|
|
834
|
-
var
|
|
1305
|
+
var ze = null, Ve = () => ze;
|
|
835
1306
|
|
|
836
|
-
function
|
|
837
|
-
const
|
|
1307
|
+
function $e(e, t) {
|
|
1308
|
+
const r = n.useMemo(() => t || ze, [ t ]), s = n.useMemo(() => {
|
|
838
1309
|
const e = () => {}, t = () => !1, n = () => null;
|
|
839
1310
|
return {
|
|
840
1311
|
set: t,
|
|
@@ -867,23 +1338,23 @@ function A(e, t) {
|
|
|
867
1338
|
},
|
|
868
1339
|
get userId() {}
|
|
869
1340
|
};
|
|
870
|
-
}, []), o =
|
|
1341
|
+
}, []), o = r || s, a = "function" == typeof e, i = a ? null : e, c = a ? e : null, l = n.useCallback(e => a ? o._subscribe(e) : o._subscribe(e, i), [ o, a, i ]), u = n.useCallback(() => a ? c(o.getSnapshot()) : o.get(i) ?? void 0, [ o, a, i, c ]), d = n.useCallback(() => {
|
|
871
1342
|
if (a) try {
|
|
872
1343
|
return c({});
|
|
873
1344
|
} catch {
|
|
874
1345
|
return;
|
|
875
1346
|
}
|
|
876
|
-
}, [ c, a ]),
|
|
1347
|
+
}, [ c, a ]), y = n.useSyncExternalStore(l, u, d), p = n.useCallback((e, t) => a ? (je(),
|
|
877
1348
|
!1) : o.set(i, e, t), [ o, a, i ]);
|
|
878
|
-
return
|
|
879
|
-
a ?
|
|
1349
|
+
return n.useDebugValue(y, e => a ? `Selector: ${JSON.stringify(e)}` : `${i}: ${JSON.stringify(e)}`),
|
|
1350
|
+
a ? y : [ y, p ];
|
|
880
1351
|
}
|
|
881
1352
|
|
|
882
|
-
var
|
|
1353
|
+
var Ne = new Map;
|
|
883
1354
|
|
|
884
|
-
|
|
1355
|
+
c();
|
|
885
1356
|
|
|
886
|
-
exports.addAccessRule = (e, t) =>
|
|
1357
|
+
exports.addAccessRule = (e, t) => Ve()?.addAccessRule(e, t), exports.analyticsPlugin = e => ({
|
|
887
1358
|
name: "gstate-analytics",
|
|
888
1359
|
hooks: {
|
|
889
1360
|
onSet: ({key: t, value: n}) => {
|
|
@@ -956,7 +1427,7 @@ exports.addAccessRule = (e, t) => x()?.addAccessRule(e, t), exports.analyticsPlu
|
|
|
956
1427
|
}
|
|
957
1428
|
};
|
|
958
1429
|
}, exports.createAsyncStore = (e, t) => {
|
|
959
|
-
const n = t?.key || "async_data", r = t?.store ||
|
|
1430
|
+
const n = t?.key || "async_data", r = t?.store || Ie({
|
|
960
1431
|
namespace: `async_${n}`,
|
|
961
1432
|
silent: !0
|
|
962
1433
|
});
|
|
@@ -1013,7 +1484,7 @@ exports.addAccessRule = (e, t) => x()?.addAccessRule(e, t), exports.analyticsPlu
|
|
|
1013
1484
|
name: "Firebase-Firestore",
|
|
1014
1485
|
save: async e => {
|
|
1015
1486
|
try {
|
|
1016
|
-
|
|
1487
|
+
je();
|
|
1017
1488
|
return (() => {})("[Mock] Firestore Syncing:", e), !0;
|
|
1018
1489
|
} catch (e) {
|
|
1019
1490
|
return !1;
|
|
@@ -1058,12 +1529,12 @@ exports.addAccessRule = (e, t) => x()?.addAccessRule(e, t), exports.analyticsPlu
|
|
|
1058
1529
|
credentials: "same-origin"
|
|
1059
1530
|
})).ok;
|
|
1060
1531
|
}
|
|
1061
|
-
}), exports.createStore =
|
|
1062
|
-
if (
|
|
1532
|
+
}), exports.createStore = Ie, exports.debugPlugin = () => {
|
|
1533
|
+
if (je()) return {
|
|
1063
1534
|
name: "gstate-debug-noop",
|
|
1064
1535
|
hooks: {}
|
|
1065
1536
|
};
|
|
1066
|
-
|
|
1537
|
+
je();
|
|
1067
1538
|
return {
|
|
1068
1539
|
name: "gstate-debug",
|
|
1069
1540
|
hooks: {
|
|
@@ -1097,11 +1568,11 @@ exports.addAccessRule = (e, t) => x()?.addAccessRule(e, t), exports.analyticsPlu
|
|
|
1097
1568
|
}
|
|
1098
1569
|
};
|
|
1099
1570
|
}, exports.deleteUserData = e => {
|
|
1100
|
-
const t =
|
|
1571
|
+
const t = Ve();
|
|
1101
1572
|
if (!t) throw new Error("[gstate] deleteUserData failed: No store found.");
|
|
1102
1573
|
return t.deleteUserData(e);
|
|
1103
1574
|
}, exports.deriveKeyFromPassword = async (e, t, n = 6e5) => {
|
|
1104
|
-
if (!
|
|
1575
|
+
if (!ve) throw new Error("Web Crypto API not available");
|
|
1105
1576
|
const r = await crypto.subtle.importKey("raw", (new TextEncoder).encode(e), "PBKDF2", !1, [ "deriveKey" ]);
|
|
1106
1577
|
return {
|
|
1107
1578
|
key: await crypto.subtle.deriveKey({
|
|
@@ -1116,10 +1587,10 @@ exports.addAccessRule = (e, t) => x()?.addAccessRule(e, t), exports.analyticsPlu
|
|
|
1116
1587
|
iv: crypto.getRandomValues(new Uint8Array(12))
|
|
1117
1588
|
};
|
|
1118
1589
|
}, exports.destroyState = () => {
|
|
1119
|
-
|
|
1590
|
+
ze && (ze.destroy(), ze = null);
|
|
1120
1591
|
}, exports.destroySync = e => {
|
|
1121
|
-
const t =
|
|
1122
|
-
t && (t.destroy(),
|
|
1592
|
+
const t = Ne.get(e);
|
|
1593
|
+
t && (t.destroy(), Ne.delete(e));
|
|
1123
1594
|
}, exports.devToolsPlugin = e => {
|
|
1124
1595
|
const t = globalThis.__REDUX_DEVTOOLS_EXTENSION__;
|
|
1125
1596
|
if (!t?.connect) return {
|
|
@@ -1150,11 +1621,11 @@ exports.addAccessRule = (e, t) => x()?.addAccessRule(e, t), exports.analyticsPlu
|
|
|
1150
1621
|
iv: btoa(String.fromCharCode(...e.iv))
|
|
1151
1622
|
};
|
|
1152
1623
|
}, exports.exportUserData = e => {
|
|
1153
|
-
const t =
|
|
1624
|
+
const t = Ve();
|
|
1154
1625
|
if (!t) throw new Error("[gstate] exportUserData failed: No store found.");
|
|
1155
1626
|
return t.exportUserData(e);
|
|
1156
1627
|
}, exports.generateEncryptionKey = async () => {
|
|
1157
|
-
if (!
|
|
1628
|
+
if (!ve) throw new Error("Web Crypto API not available");
|
|
1158
1629
|
return {
|
|
1159
1630
|
key: await crypto.subtle.generateKey({
|
|
1160
1631
|
name: "AES-GCM",
|
|
@@ -1163,15 +1634,15 @@ exports.addAccessRule = (e, t) => x()?.addAccessRule(e, t), exports.analyticsPlu
|
|
|
1163
1634
|
iv: crypto.getRandomValues(new Uint8Array(12))
|
|
1164
1635
|
};
|
|
1165
1636
|
}, exports.generateSalt = (e = 32) => crypto.getRandomValues(new Uint8Array(e)),
|
|
1166
|
-
exports.getConsents = e =>
|
|
1167
|
-
const n =
|
|
1637
|
+
exports.getConsents = e => Ve()?.getConsents(e) ?? [], exports.getStore = Ve, exports.gstate = (e, t) => {
|
|
1638
|
+
const n = Ie("string" == typeof t ? {
|
|
1168
1639
|
namespace: t
|
|
1169
1640
|
} : t);
|
|
1170
1641
|
e && Object.entries(e).forEach(([e, t]) => {
|
|
1171
1642
|
null === n.get(e) && n._setSilently(e, t);
|
|
1172
1643
|
});
|
|
1173
|
-
return "undefined" == typeof window ||
|
|
1174
|
-
window.rgs = n), Object.assign(e =>
|
|
1644
|
+
return "undefined" == typeof window || je() || (window.gstate = n, window.gState = n,
|
|
1645
|
+
window.rgs = n), Object.assign(e => $e(e, n), n);
|
|
1175
1646
|
}, exports.guardPlugin = e => ({
|
|
1176
1647
|
name: "gstate-guard",
|
|
1177
1648
|
hooks: {
|
|
@@ -1181,7 +1652,7 @@ exports.getConsents = e => x()?.getConsents(e) ?? [], exports.getStore = x, expo
|
|
|
1181
1652
|
s && s(n);
|
|
1182
1653
|
}
|
|
1183
1654
|
}
|
|
1184
|
-
}), exports.hasConsent = (e, t) =>
|
|
1655
|
+
}), exports.hasConsent = (e, t) => Ve()?.hasConsent(e, t) ?? !1, exports.hasPermission = (e, t, n) => Ve()?.hasPermission(e, t, n) ?? !0,
|
|
1185
1656
|
exports.immerPlugin = () => ({
|
|
1186
1657
|
name: "gstate-immer",
|
|
1187
1658
|
hooks: {
|
|
@@ -1267,14 +1738,14 @@ exports.immerPlugin = () => ({
|
|
|
1267
1738
|
}
|
|
1268
1739
|
};
|
|
1269
1740
|
}, exports.initState = e => {
|
|
1270
|
-
const t =
|
|
1271
|
-
return
|
|
1741
|
+
const t = Ie(e);
|
|
1742
|
+
return ze = t, t;
|
|
1272
1743
|
}, exports.initSync = (e, t) => {
|
|
1273
1744
|
const n = e.namespace;
|
|
1274
|
-
if (
|
|
1745
|
+
if (Ne.has(n)) return Ne.get(n);
|
|
1275
1746
|
const r = new exports.SyncEngine(e, t);
|
|
1276
|
-
return
|
|
1277
|
-
}, exports.isCryptoAvailable =
|
|
1747
|
+
return Ne.set(n, r), r;
|
|
1748
|
+
}, exports.isCryptoAvailable = ve, exports.logAudit = Oe, exports.loggerPlugin = e => ({
|
|
1278
1749
|
name: "gstate-logger",
|
|
1279
1750
|
hooks: {
|
|
1280
1751
|
onSet: ({key: e, value: t, version: n}) => {
|
|
@@ -1284,10 +1755,10 @@ exports.immerPlugin = () => ({
|
|
|
1284
1755
|
onTransaction: ({key: e}) => {}
|
|
1285
1756
|
}
|
|
1286
1757
|
}), exports.recordConsent = (e, t, n) => {
|
|
1287
|
-
const r =
|
|
1758
|
+
const r = Ve();
|
|
1288
1759
|
if (!r) throw new Error("[gstate] recordConsent failed: No store found. call initState() first.");
|
|
1289
1760
|
return r.recordConsent(e, t, n);
|
|
1290
|
-
}, exports.revokeConsent = (e, t) =>
|
|
1761
|
+
}, exports.revokeConsent = (e, t) => Ve()?.revokeConsent(e, t), exports.sanitizeValue = De,
|
|
1291
1762
|
exports.schemaPlugin = e => ({
|
|
1292
1763
|
name: "gstate-schema",
|
|
1293
1764
|
hooks: {
|
|
@@ -1301,7 +1772,7 @@ exports.schemaPlugin = e => ({
|
|
|
1301
1772
|
}
|
|
1302
1773
|
}
|
|
1303
1774
|
}), exports.setAuditLogger = e => {
|
|
1304
|
-
|
|
1775
|
+
Ce = e;
|
|
1305
1776
|
}, exports.snapshotPlugin = () => {
|
|
1306
1777
|
const e = new Map;
|
|
1307
1778
|
return {
|
|
@@ -1353,9 +1824,9 @@ exports.schemaPlugin = e => ({
|
|
|
1353
1824
|
}
|
|
1354
1825
|
};
|
|
1355
1826
|
}, exports.triggerSync = async e => {
|
|
1356
|
-
const t = e ||
|
|
1827
|
+
const t = e || ze?.namespace;
|
|
1357
1828
|
if (!t) return;
|
|
1358
|
-
const n =
|
|
1829
|
+
const n = Ne.get(t);
|
|
1359
1830
|
n && await n.flush();
|
|
1360
1831
|
}, exports.undoRedoPlugin = e => {
|
|
1361
1832
|
let t = [], n = -1, r = !1;
|
|
@@ -1389,21 +1860,21 @@ exports.schemaPlugin = e => ({
|
|
|
1389
1860
|
}
|
|
1390
1861
|
}
|
|
1391
1862
|
};
|
|
1392
|
-
}, exports.useGState =
|
|
1393
|
-
const t = e ||
|
|
1394
|
-
return
|
|
1395
|
-
}, exports.useSimpleState =
|
|
1396
|
-
const [e, t] =
|
|
1863
|
+
}, exports.useGState = $e, exports.useIsStoreReady = e => {
|
|
1864
|
+
const t = e || ze, r = n.useMemo(() => e => t ? t._subscribe(e) : () => {}, [ t ]);
|
|
1865
|
+
return n.useSyncExternalStore(r, () => !!t && t.isReady, () => !0);
|
|
1866
|
+
}, exports.useSimpleState = $e, exports.useStore = $e, exports.useSyncStatus = () => {
|
|
1867
|
+
const [e, t] = n.useState({
|
|
1397
1868
|
isOnline: !0,
|
|
1398
1869
|
isSyncing: !1,
|
|
1399
1870
|
lastSyncTimestamp: null,
|
|
1400
1871
|
pendingChanges: 0,
|
|
1401
1872
|
conflicts: 0
|
|
1402
1873
|
});
|
|
1403
|
-
return
|
|
1874
|
+
return n.useEffect(() => {
|
|
1404
1875
|
const e = () => {
|
|
1405
1876
|
let e = !0, n = !1, r = 0, s = 0;
|
|
1406
|
-
|
|
1877
|
+
Ne.forEach(t => {
|
|
1407
1878
|
const o = t.getState();
|
|
1408
1879
|
e = e && o.isOnline, n = n || o.isSyncing, r += o.pendingChanges, s += o.conflicts;
|
|
1409
1880
|
}), t({
|
|
@@ -1415,26 +1886,26 @@ exports.schemaPlugin = e => ({
|
|
|
1415
1886
|
});
|
|
1416
1887
|
};
|
|
1417
1888
|
e();
|
|
1418
|
-
const n = Array.from(
|
|
1889
|
+
const n = Array.from(Ne.values()).map(t => t.onStateChange(e));
|
|
1419
1890
|
return () => n.forEach(e => e());
|
|
1420
1891
|
}, []), e;
|
|
1421
1892
|
}, exports.useSyncedState = function(e, t) {
|
|
1422
|
-
const
|
|
1893
|
+
const r = t || ze, s = r?.namespace || "default", o = Ne.get(s), a = $e(e, r), i = a[0], c = a[1], [l, u] = n.useState(() => o?.getState() || {
|
|
1423
1894
|
isOnline: !0,
|
|
1424
1895
|
isSyncing: !1,
|
|
1425
1896
|
lastSyncTimestamp: null,
|
|
1426
1897
|
pendingChanges: 0,
|
|
1427
1898
|
conflicts: 0
|
|
1428
1899
|
});
|
|
1429
|
-
return
|
|
1900
|
+
return n.useEffect(() => {
|
|
1430
1901
|
if (!o) return;
|
|
1431
1902
|
return o.onStateChange(u);
|
|
1432
|
-
}, [ o ]), [ i,
|
|
1433
|
-
const s = c(t,
|
|
1903
|
+
}, [ o ]), [ i, n.useCallback((t, n) => {
|
|
1904
|
+
const s = c(t, n);
|
|
1434
1905
|
if (s && o) {
|
|
1435
|
-
const t =
|
|
1906
|
+
const t = r?.get(e);
|
|
1436
1907
|
o.queueChange(e, t);
|
|
1437
1908
|
}
|
|
1438
1909
|
return s;
|
|
1439
|
-
}, [ c, o, e,
|
|
1440
|
-
}, exports.validateKey =
|
|
1910
|
+
}, [ c, o, e, r ]), l ];
|
|
1911
|
+
}, exports.validateKey = Me;
|