@biglogic/rgs 3.9.4 → 3.9.5
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/index.cjs +715 -661
- package/index.js +553 -498
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2,7 +2,295 @@ import { produce as e, freeze as t } from "immer";
|
|
|
2
2
|
|
|
3
3
|
import { useMemo as n, useSyncExternalStore as s, useCallback as r, useDebugValue as o, useState as a, useEffect as i } from "react";
|
|
4
4
|
|
|
5
|
-
var c = (e, t) => {
|
|
5
|
+
var c, l, u, y, d = Object.defineProperty, g = Object.getOwnPropertyNames, f = (e, t) => function() {
|
|
6
|
+
return e && (t = (0, e[g(e)[0]])(e = 0)), t;
|
|
7
|
+
}, h = f({
|
|
8
|
+
"core/utils.ts"() {
|
|
9
|
+
c = e => {
|
|
10
|
+
if (null === e || "object" != typeof e) return e;
|
|
11
|
+
if ("function" == typeof structuredClone) try {
|
|
12
|
+
return structuredClone(e);
|
|
13
|
+
} catch (e) {}
|
|
14
|
+
const t = new WeakMap, n = e => {
|
|
15
|
+
if (null === e || "object" != typeof e) return e;
|
|
16
|
+
if ("function" == typeof e) return e;
|
|
17
|
+
if (t.has(e)) return t.get(e);
|
|
18
|
+
if (e instanceof Date) return new Date(e.getTime());
|
|
19
|
+
if (e instanceof RegExp) return new RegExp(e.source, e.flags);
|
|
20
|
+
if (e instanceof Map) {
|
|
21
|
+
const s = new Map;
|
|
22
|
+
return t.set(e, s), e.forEach((e, t) => s.set(n(t), n(e))), s;
|
|
23
|
+
}
|
|
24
|
+
if (e instanceof Set) {
|
|
25
|
+
const s = new Set;
|
|
26
|
+
return t.set(e, s), e.forEach(e => s.add(n(e))), s;
|
|
27
|
+
}
|
|
28
|
+
const s = Array.isArray(e) ? [] : Object.create(Object.getPrototypeOf(e));
|
|
29
|
+
t.set(e, s);
|
|
30
|
+
const r = [ ...Object.keys(e), ...Object.getOwnPropertySymbols(e) ];
|
|
31
|
+
for (const t of r) s[t] = n(e[t]);
|
|
32
|
+
return s;
|
|
33
|
+
};
|
|
34
|
+
return n(e);
|
|
35
|
+
}, l = (e, t) => {
|
|
36
|
+
if (e === t) return !0;
|
|
37
|
+
if (null === e || null === t) return e === t;
|
|
38
|
+
if ("object" != typeof e || "object" != typeof t) return e === t;
|
|
39
|
+
if (Array.isArray(e) && Array.isArray(t)) {
|
|
40
|
+
if (e.length !== t.length) return !1;
|
|
41
|
+
for (let n = 0; n < e.length; n++) if (!l(e[n], t[n])) return !1;
|
|
42
|
+
return !0;
|
|
43
|
+
}
|
|
44
|
+
const n = Object.keys(e), s = Object.keys(t);
|
|
45
|
+
if (n.length !== s.length) return !1;
|
|
46
|
+
for (let s = 0; s < n.length; s++) {
|
|
47
|
+
const r = n[s];
|
|
48
|
+
if (!(r in t) || !l(e[r], t[r])) return !1;
|
|
49
|
+
}
|
|
50
|
+
return !0;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}), p = {};
|
|
54
|
+
|
|
55
|
+
((e, t) => {
|
|
56
|
+
for (var n in t) d(e, n, {
|
|
57
|
+
get: t[n],
|
|
58
|
+
enumerable: !0
|
|
59
|
+
});
|
|
60
|
+
})(p, {
|
|
61
|
+
SyncEngine: () => u,
|
|
62
|
+
createSyncEngine: () => y
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
var m = f({
|
|
66
|
+
"core/sync.ts"() {
|
|
67
|
+
h(), u = class {
|
|
68
|
+
store;
|
|
69
|
+
config;
|
|
70
|
+
pendingQueue=new Map;
|
|
71
|
+
remoteVersions=new Map;
|
|
72
|
+
syncTimer=null;
|
|
73
|
+
onlineStatusListeners=new Set;
|
|
74
|
+
syncStateListeners=new Set;
|
|
75
|
+
_isOnline=!0;
|
|
76
|
+
_isSyncing=!1;
|
|
77
|
+
constructor(e, t) {
|
|
78
|
+
this.store = e, this.config = {
|
|
79
|
+
endpoint: t.endpoint,
|
|
80
|
+
authToken: t.authToken || "",
|
|
81
|
+
strategy: t.strategy || "last-write-wins",
|
|
82
|
+
autoSyncInterval: t.autoSyncInterval ?? 3e4,
|
|
83
|
+
syncOnReconnect: t.syncOnReconnect ?? !0,
|
|
84
|
+
debounceTime: t.debounceTime ?? 1e3,
|
|
85
|
+
fetch: t.fetch || fetch,
|
|
86
|
+
onSync: t.onSync || (() => {}),
|
|
87
|
+
onConflict: t.onConflict || (() => ({
|
|
88
|
+
action: "accept-local"
|
|
89
|
+
})),
|
|
90
|
+
maxRetries: t.maxRetries ?? 3
|
|
91
|
+
}, this._isOnline = "undefined" == typeof navigator || navigator.onLine, this._setupOnlineListener(),
|
|
92
|
+
this._setupStoreListener(), this.config.autoSyncInterval > 0 && this._startAutoSync();
|
|
93
|
+
}
|
|
94
|
+
_getAuthToken() {
|
|
95
|
+
const e = this.config.authToken;
|
|
96
|
+
return "function" == typeof e ? e() || "" : e || "";
|
|
97
|
+
}
|
|
98
|
+
_setupOnlineListener() {
|
|
99
|
+
"undefined" != typeof window && (window.addEventListener("online", () => {
|
|
100
|
+
this._isOnline = !0, this._notifyOnlineChange(!0), this.config.syncOnReconnect && this.sync();
|
|
101
|
+
}), window.addEventListener("offline", () => {
|
|
102
|
+
this._isOnline = !1, this._notifyOnlineChange(!1);
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
_setupStoreListener() {
|
|
106
|
+
this.store._subscribe(() => {});
|
|
107
|
+
}
|
|
108
|
+
_startAutoSync() {
|
|
109
|
+
setInterval(() => {
|
|
110
|
+
this._isOnline && !this._isSyncing && this.pendingQueue.size > 0 && this.sync();
|
|
111
|
+
}, this.config.autoSyncInterval);
|
|
112
|
+
}
|
|
113
|
+
_notifyOnlineChange(e) {
|
|
114
|
+
this.onlineStatusListeners.forEach(t => t(e)), this._notifyStateChange();
|
|
115
|
+
}
|
|
116
|
+
_notifyStateChange() {
|
|
117
|
+
const e = this.getState();
|
|
118
|
+
this.syncStateListeners.forEach(t => t(e));
|
|
119
|
+
}
|
|
120
|
+
queueChange(e, t) {
|
|
121
|
+
const n = this.store._getVersion(e) || 1;
|
|
122
|
+
this.pendingQueue.set(e, {
|
|
123
|
+
key: e,
|
|
124
|
+
value: c(t),
|
|
125
|
+
timestamp: Date.now(),
|
|
126
|
+
version: n
|
|
127
|
+
}), this._notifyStateChange(), this.syncTimer && clearTimeout(this.syncTimer), this.syncTimer = setTimeout(() => {
|
|
128
|
+
this._isOnline && this.sync();
|
|
129
|
+
}, this.config.debounceTime);
|
|
130
|
+
}
|
|
131
|
+
async sync() {
|
|
132
|
+
if (this._isSyncing) return {
|
|
133
|
+
success: !1,
|
|
134
|
+
syncedKeys: [],
|
|
135
|
+
conflicts: [],
|
|
136
|
+
errors: [ "Sync already in progress" ],
|
|
137
|
+
timestamp: Date.now(),
|
|
138
|
+
duration: 0
|
|
139
|
+
};
|
|
140
|
+
this._isSyncing = !0, this._notifyStateChange();
|
|
141
|
+
const e = Date.now(), t = [], n = [], s = [];
|
|
142
|
+
try {
|
|
143
|
+
const r = Array.from(this.pendingQueue.values());
|
|
144
|
+
if (0 === r.length) return this._isSyncing = !1, this._notifyStateChange(), {
|
|
145
|
+
success: !0,
|
|
146
|
+
syncedKeys: [],
|
|
147
|
+
conflicts: [],
|
|
148
|
+
errors: [],
|
|
149
|
+
timestamp: Date.now(),
|
|
150
|
+
duration: Date.now() - e
|
|
151
|
+
};
|
|
152
|
+
await this._fetchRemoteVersions(r.map(e => e.key));
|
|
153
|
+
for (const e of r) try {
|
|
154
|
+
const s = this.remoteVersions.get(e.key);
|
|
155
|
+
if (s) if (s.version >= e.version) {
|
|
156
|
+
const r = {
|
|
157
|
+
key: e.key,
|
|
158
|
+
localValue: e.value,
|
|
159
|
+
remoteValue: s.value,
|
|
160
|
+
localVersion: e.version,
|
|
161
|
+
remoteVersion: s.version,
|
|
162
|
+
timestamp: e.timestamp
|
|
163
|
+
};
|
|
164
|
+
n.push(r);
|
|
165
|
+
const o = this.config.onConflict(r);
|
|
166
|
+
await this._resolveConflict(e, s, o), t.push(e.key), this.pendingQueue.delete(e.key);
|
|
167
|
+
} else await this._pushChange(e), t.push(e.key), this.pendingQueue.delete(e.key); else await this._pushChange(e),
|
|
168
|
+
t.push(e.key), this.pendingQueue.delete(e.key);
|
|
169
|
+
} catch (t) {
|
|
170
|
+
s.push(`Failed to sync "${e.key}": ${t}`);
|
|
171
|
+
}
|
|
172
|
+
const o = {
|
|
173
|
+
success: 0 === s.length,
|
|
174
|
+
syncedKeys: t,
|
|
175
|
+
conflicts: n,
|
|
176
|
+
errors: s,
|
|
177
|
+
timestamp: Date.now(),
|
|
178
|
+
duration: Date.now() - e
|
|
179
|
+
};
|
|
180
|
+
return this.config.onSync(o), o;
|
|
181
|
+
} catch (r) {
|
|
182
|
+
const o = `Sync failed: ${r}`;
|
|
183
|
+
return s.push(o), {
|
|
184
|
+
success: !1,
|
|
185
|
+
syncedKeys: t,
|
|
186
|
+
conflicts: n,
|
|
187
|
+
errors: s,
|
|
188
|
+
timestamp: Date.now(),
|
|
189
|
+
duration: Date.now() - e
|
|
190
|
+
};
|
|
191
|
+
} finally {
|
|
192
|
+
this._isSyncing = !1, this._notifyStateChange();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async _fetchRemoteVersions(e) {
|
|
196
|
+
try {
|
|
197
|
+
const t = this._getAuthToken(), n = await this.config.fetch(`${this.config.endpoint}/versions`, {
|
|
198
|
+
method: "POST",
|
|
199
|
+
headers: {
|
|
200
|
+
"Content-Type": "application/json",
|
|
201
|
+
...t && {
|
|
202
|
+
Authorization: `Bearer ${t}`
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
body: JSON.stringify({
|
|
206
|
+
keys: e
|
|
207
|
+
})
|
|
208
|
+
});
|
|
209
|
+
if (n.ok) {
|
|
210
|
+
const e = await n.json();
|
|
211
|
+
if (e.versions) for (const [t, n] of Object.entries(e.versions)) this.remoteVersions.set(t, n);
|
|
212
|
+
}
|
|
213
|
+
} catch (e) {}
|
|
214
|
+
}
|
|
215
|
+
async _pushChange(e) {
|
|
216
|
+
let t = 0;
|
|
217
|
+
for (;t < this.config.maxRetries; ) try {
|
|
218
|
+
const n = this._getAuthToken(), s = await this.config.fetch(`${this.config.endpoint}/sync`, {
|
|
219
|
+
method: "POST",
|
|
220
|
+
headers: {
|
|
221
|
+
"Content-Type": "application/json",
|
|
222
|
+
...n && {
|
|
223
|
+
Authorization: `Bearer ${n}`
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
body: JSON.stringify({
|
|
227
|
+
key: e.key,
|
|
228
|
+
value: e.value,
|
|
229
|
+
version: e.version,
|
|
230
|
+
timestamp: e.timestamp
|
|
231
|
+
})
|
|
232
|
+
});
|
|
233
|
+
if (s.ok) {
|
|
234
|
+
const t = await s.json();
|
|
235
|
+
return void (t.version && this.remoteVersions.set(e.key, {
|
|
236
|
+
version: t.version,
|
|
237
|
+
timestamp: t.timestamp || Date.now(),
|
|
238
|
+
value: e.value
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
241
|
+
t++;
|
|
242
|
+
} catch (e) {
|
|
243
|
+
if (t++, t >= this.config.maxRetries) throw e;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async _resolveConflict(e, t, n) {
|
|
247
|
+
switch (n.action) {
|
|
248
|
+
case "accept-local":
|
|
249
|
+
await this._pushChange({
|
|
250
|
+
...e,
|
|
251
|
+
version: t.version + 1,
|
|
252
|
+
timestamp: Date.now()
|
|
253
|
+
});
|
|
254
|
+
break;
|
|
255
|
+
|
|
256
|
+
case "accept-remote":
|
|
257
|
+
this.store.set(e.key, t.value);
|
|
258
|
+
break;
|
|
259
|
+
|
|
260
|
+
case "merge":
|
|
261
|
+
this.store.set(e.key, n.value), await this._pushChange({
|
|
262
|
+
key: e.key,
|
|
263
|
+
value: n.value,
|
|
264
|
+
version: Math.max(e.version, t.version) + 1,
|
|
265
|
+
timestamp: Date.now()
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
getState() {
|
|
270
|
+
return {
|
|
271
|
+
isOnline: this._isOnline,
|
|
272
|
+
isSyncing: this._isSyncing,
|
|
273
|
+
lastSyncTimestamp: null,
|
|
274
|
+
pendingChanges: this.pendingQueue.size,
|
|
275
|
+
conflicts: 0
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
onOnlineChange(e) {
|
|
279
|
+
return this.onlineStatusListeners.add(e), () => this.onlineStatusListeners.delete(e);
|
|
280
|
+
}
|
|
281
|
+
onStateChange(e) {
|
|
282
|
+
return this.syncStateListeners.add(e), () => this.syncStateListeners.delete(e);
|
|
283
|
+
}
|
|
284
|
+
async flush() {
|
|
285
|
+
return this.sync();
|
|
286
|
+
}
|
|
287
|
+
destroy() {
|
|
288
|
+
this.syncTimer && clearTimeout(this.syncTimer), this.pendingQueue.clear(), this.onlineStatusListeners.clear(),
|
|
289
|
+
this.syncStateListeners.clear();
|
|
290
|
+
}
|
|
291
|
+
}, y = (e, t) => new u(e, t);
|
|
292
|
+
}
|
|
293
|
+
}), w = (e, t) => {
|
|
6
294
|
const n = Date.now();
|
|
7
295
|
if (/\(\.*\+\?\)\+/.test(e) || /\(\.*\?\)\*/.test(e)) return !1;
|
|
8
296
|
if (e.length > 500) return !1;
|
|
@@ -13,13 +301,13 @@ var c = (e, t) => {
|
|
|
13
301
|
} catch {
|
|
14
302
|
return !1;
|
|
15
303
|
}
|
|
16
|
-
},
|
|
304
|
+
}, S = () => {
|
|
17
305
|
if ("undefined" != typeof crypto && "function" == typeof crypto.randomUUID) try {
|
|
18
306
|
return crypto.randomUUID();
|
|
19
307
|
} catch {}
|
|
20
308
|
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.");
|
|
21
|
-
},
|
|
22
|
-
if (!
|
|
309
|
+
}, v = "undefined" != typeof crypto && void 0 !== crypto.subtle && "function" == typeof crypto.subtle.generateKey, b = async (e, t, n = 6e5) => {
|
|
310
|
+
if (!v) throw new Error("Web Crypto API not available");
|
|
23
311
|
const s = await crypto.subtle.importKey("raw", (new TextEncoder).encode(e), "PBKDF2", !1, [ "deriveKey" ]);
|
|
24
312
|
return {
|
|
25
313
|
key: await crypto.subtle.deriveKey({
|
|
@@ -33,8 +321,8 @@ var c = (e, t) => {
|
|
|
33
321
|
}, !0, [ "encrypt", "decrypt" ]),
|
|
34
322
|
iv: crypto.getRandomValues(new Uint8Array(12))
|
|
35
323
|
};
|
|
36
|
-
},
|
|
37
|
-
if (!
|
|
324
|
+
}, E = (e = 32) => crypto.getRandomValues(new Uint8Array(e)), _ = async () => {
|
|
325
|
+
if (!v) throw new Error("Web Crypto API not available");
|
|
38
326
|
return {
|
|
39
327
|
key: await crypto.subtle.generateKey({
|
|
40
328
|
name: "AES-GCM",
|
|
@@ -42,13 +330,13 @@ var c = (e, t) => {
|
|
|
42
330
|
}, !0, [ "encrypt", "decrypt" ]),
|
|
43
331
|
iv: crypto.getRandomValues(new Uint8Array(12))
|
|
44
332
|
};
|
|
45
|
-
},
|
|
333
|
+
}, k = async e => {
|
|
46
334
|
const t = await crypto.subtle.exportKey("raw", e.key);
|
|
47
335
|
return {
|
|
48
336
|
key: btoa(String.fromCharCode(...new Uint8Array(t))),
|
|
49
337
|
iv: btoa(String.fromCharCode(...e.iv))
|
|
50
338
|
};
|
|
51
|
-
},
|
|
339
|
+
}, C = async (e, t) => {
|
|
52
340
|
const n = Uint8Array.from(atob(e), e => e.charCodeAt(0)), s = Uint8Array.from(atob(t), e => e.charCodeAt(0));
|
|
53
341
|
return {
|
|
54
342
|
key: await crypto.subtle.importKey("raw", n, {
|
|
@@ -57,32 +345,32 @@ var c = (e, t) => {
|
|
|
57
345
|
}, !0, [ "encrypt", "decrypt" ]),
|
|
58
346
|
iv: s
|
|
59
347
|
};
|
|
60
|
-
},
|
|
348
|
+
}, O = async (e, t) => {
|
|
61
349
|
const n = (new TextEncoder).encode(JSON.stringify(e)), s = await crypto.subtle.encrypt({
|
|
62
350
|
name: "AES-GCM",
|
|
63
351
|
iv: t.iv
|
|
64
352
|
}, t.key, n), r = new Uint8Array(t.iv.length + s.byteLength);
|
|
65
353
|
return r.set(t.iv), r.set(new Uint8Array(s), t.iv.length), btoa(String.fromCharCode(...r));
|
|
66
|
-
},
|
|
354
|
+
}, D = async (e, t) => {
|
|
67
355
|
const n = Uint8Array.from(atob(e), e => e.charCodeAt(0)), s = n.slice(0, 12), r = n.slice(12), o = await crypto.subtle.decrypt({
|
|
68
356
|
name: "AES-GCM",
|
|
69
357
|
iv: s
|
|
70
358
|
}, t.key, r);
|
|
71
359
|
return JSON.parse((new TextDecoder).decode(o));
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
},
|
|
360
|
+
}, A = null, M = e => {
|
|
361
|
+
A = e;
|
|
362
|
+
}, R = e => {
|
|
363
|
+
A && A(e);
|
|
364
|
+
}, T = (e, t, n) => {
|
|
77
365
|
e.set(t instanceof RegExp ? t.source : t, n);
|
|
78
|
-
},
|
|
366
|
+
}, j = (e, t, n, s) => {
|
|
79
367
|
if (0 === e.size) return !0;
|
|
80
368
|
for (const [r, o] of e) {
|
|
81
369
|
let e;
|
|
82
|
-
if (e = "function" == typeof r ? r(t, s) :
|
|
370
|
+
if (e = "function" == typeof r ? r(t, s) : w(r, t), e) return o.includes(n) || o.includes("admin");
|
|
83
371
|
}
|
|
84
372
|
return !1;
|
|
85
|
-
},
|
|
373
|
+
}, V = e => {
|
|
86
374
|
if ("string" == typeof e) {
|
|
87
375
|
let t = e.replace(/&#[xX]?[0-9a-fA-F]+;?/g, e => {
|
|
88
376
|
const t = e.match(/&#x([0-9a-fA-F]+);?/i);
|
|
@@ -98,293 +386,35 @@ var c = (e, t) => {
|
|
|
98
386
|
if (e && "object" == typeof e && !Array.isArray(e)) {
|
|
99
387
|
if (Object.getPrototypeOf(e) === Object.prototype) {
|
|
100
388
|
const t = {};
|
|
101
|
-
for (const [n, s] of Object.entries(e)) t[n] =
|
|
389
|
+
for (const [n, s] of Object.entries(e)) t[n] = V(s);
|
|
102
390
|
return t;
|
|
103
391
|
}
|
|
104
392
|
return e;
|
|
105
393
|
}
|
|
106
|
-
return Array.isArray(e) ? e.map(e =>
|
|
107
|
-
},
|
|
394
|
+
return Array.isArray(e) ? e.map(e => V(e)) : e;
|
|
395
|
+
}, I = e => /^([a-zA-Z0-9_.-][a-zA-Z0-9_.-]*)$/.test(e) && e.length <= 256 && e.length > 0, $ = (e, t, n, s) => {
|
|
108
396
|
const r = {
|
|
109
|
-
id:
|
|
397
|
+
id: S(),
|
|
110
398
|
purpose: n,
|
|
111
399
|
granted: s,
|
|
112
400
|
timestamp: Date.now()
|
|
113
401
|
}, o = e.get(t) || [];
|
|
114
|
-
return o.push(r), e.set(t, o),
|
|
402
|
+
return o.push(r), e.set(t, o), R({
|
|
115
403
|
timestamp: Date.now(),
|
|
116
404
|
action: "set",
|
|
117
405
|
key: `consent:${n}`,
|
|
118
406
|
userId: t,
|
|
119
407
|
success: !0
|
|
120
408
|
}), r;
|
|
121
|
-
}
|
|
122
|
-
if (null === e || "object" != typeof e) return e;
|
|
123
|
-
if ("function" == typeof structuredClone) try {
|
|
124
|
-
return structuredClone(e);
|
|
125
|
-
} catch (e) {}
|
|
126
|
-
const t = new WeakMap, n = e => {
|
|
127
|
-
if (null === e || "object" != typeof e) return e;
|
|
128
|
-
if ("function" == typeof e) return e;
|
|
129
|
-
if (t.has(e)) return t.get(e);
|
|
130
|
-
if (e instanceof Date) return new Date(e.getTime());
|
|
131
|
-
if (e instanceof RegExp) return new RegExp(e.source, e.flags);
|
|
132
|
-
if (e instanceof Map) {
|
|
133
|
-
const s = new Map;
|
|
134
|
-
return t.set(e, s), e.forEach((e, t) => s.set(n(t), n(e))), s;
|
|
135
|
-
}
|
|
136
|
-
if (e instanceof Set) {
|
|
137
|
-
const s = new Set;
|
|
138
|
-
return t.set(e, s), e.forEach(e => s.add(n(e))), s;
|
|
139
|
-
}
|
|
140
|
-
const s = Array.isArray(e) ? [] : Object.create(Object.getPrototypeOf(e));
|
|
141
|
-
t.set(e, s);
|
|
142
|
-
const r = [ ...Object.keys(e), ...Object.getOwnPropertySymbols(e) ];
|
|
143
|
-
for (const t of r) s[t] = n(e[t]);
|
|
144
|
-
return s;
|
|
145
|
-
};
|
|
146
|
-
return n(e);
|
|
147
|
-
}, D = (e, t) => {
|
|
148
|
-
if (e === t) return !0;
|
|
149
|
-
if (null === e || null === t) return e === t;
|
|
150
|
-
if ("object" != typeof e || "object" != typeof t) return e === t;
|
|
151
|
-
if (Array.isArray(e) && Array.isArray(t)) {
|
|
152
|
-
if (e.length !== t.length) return !1;
|
|
153
|
-
for (let n = 0; n < e.length; n++) if (!D(e[n], t[n])) return !1;
|
|
154
|
-
return !0;
|
|
155
|
-
}
|
|
156
|
-
const n = Object.keys(e), s = Object.keys(t);
|
|
157
|
-
if (n.length !== s.length) return !1;
|
|
158
|
-
for (let s = 0; s < n.length; s++) {
|
|
159
|
-
const r = n[s];
|
|
160
|
-
if (!(r in t) || !D(e[r], t[r])) return !1;
|
|
161
|
-
}
|
|
162
|
-
return !0;
|
|
163
|
-
}, A = e => `${e}_`, M = class {
|
|
164
|
-
store;
|
|
165
|
-
config;
|
|
166
|
-
pendingQueue=new Map;
|
|
167
|
-
remoteVersions=new Map;
|
|
168
|
-
syncTimer=null;
|
|
169
|
-
onlineStatusListeners=new Set;
|
|
170
|
-
syncStateListeners=new Set;
|
|
171
|
-
_isOnline=!0;
|
|
172
|
-
_isSyncing=!1;
|
|
173
|
-
constructor(e, t) {
|
|
174
|
-
this.store = e, this.config = {
|
|
175
|
-
endpoint: t.endpoint,
|
|
176
|
-
authToken: t.authToken || "",
|
|
177
|
-
strategy: t.strategy || "last-write-wins",
|
|
178
|
-
autoSyncInterval: t.autoSyncInterval ?? 3e4,
|
|
179
|
-
syncOnReconnect: t.syncOnReconnect ?? !0,
|
|
180
|
-
debounceTime: t.debounceTime ?? 1e3,
|
|
181
|
-
fetch: t.fetch || fetch,
|
|
182
|
-
onSync: t.onSync || (() => {}),
|
|
183
|
-
onConflict: t.onConflict || (() => ({
|
|
184
|
-
action: "accept-local"
|
|
185
|
-
})),
|
|
186
|
-
maxRetries: t.maxRetries ?? 3
|
|
187
|
-
}, this._isOnline = "undefined" == typeof navigator || navigator.onLine, this._setupOnlineListener(),
|
|
188
|
-
this._setupStoreListener(), this.config.autoSyncInterval > 0 && this._startAutoSync();
|
|
189
|
-
}
|
|
190
|
-
_getAuthToken() {
|
|
191
|
-
const e = this.config.authToken;
|
|
192
|
-
return "function" == typeof e ? e() || "" : e || "";
|
|
193
|
-
}
|
|
194
|
-
_setupOnlineListener() {
|
|
195
|
-
"undefined" != typeof window && (window.addEventListener("online", () => {
|
|
196
|
-
this._isOnline = !0, this._notifyOnlineChange(!0), this.config.syncOnReconnect && this.sync();
|
|
197
|
-
}), window.addEventListener("offline", () => {
|
|
198
|
-
this._isOnline = !1, this._notifyOnlineChange(!1);
|
|
199
|
-
}));
|
|
200
|
-
}
|
|
201
|
-
_setupStoreListener() {
|
|
202
|
-
this.store._subscribe(() => {});
|
|
203
|
-
}
|
|
204
|
-
_startAutoSync() {
|
|
205
|
-
setInterval(() => {
|
|
206
|
-
this._isOnline && !this._isSyncing && this.pendingQueue.size > 0 && this.sync();
|
|
207
|
-
}, this.config.autoSyncInterval);
|
|
208
|
-
}
|
|
209
|
-
_notifyOnlineChange(e) {
|
|
210
|
-
this.onlineStatusListeners.forEach(t => t(e)), this._notifyStateChange();
|
|
211
|
-
}
|
|
212
|
-
_notifyStateChange() {
|
|
213
|
-
const e = this.getState();
|
|
214
|
-
this.syncStateListeners.forEach(t => t(e));
|
|
215
|
-
}
|
|
216
|
-
queueChange(e, t) {
|
|
217
|
-
const n = this.store._getVersion(e) || 1;
|
|
218
|
-
this.pendingQueue.set(e, {
|
|
219
|
-
key: e,
|
|
220
|
-
value: O(t),
|
|
221
|
-
timestamp: Date.now(),
|
|
222
|
-
version: n
|
|
223
|
-
}), this._notifyStateChange(), this.syncTimer && clearTimeout(this.syncTimer), this.syncTimer = setTimeout(() => {
|
|
224
|
-
this._isOnline && this.sync();
|
|
225
|
-
}, this.config.debounceTime);
|
|
226
|
-
}
|
|
227
|
-
async sync() {
|
|
228
|
-
if (this._isSyncing) return {
|
|
229
|
-
success: !1,
|
|
230
|
-
syncedKeys: [],
|
|
231
|
-
conflicts: [],
|
|
232
|
-
errors: [ "Sync already in progress" ],
|
|
233
|
-
timestamp: Date.now(),
|
|
234
|
-
duration: 0
|
|
235
|
-
};
|
|
236
|
-
this._isSyncing = !0, this._notifyStateChange();
|
|
237
|
-
const e = Date.now(), t = [], n = [], s = [];
|
|
238
|
-
try {
|
|
239
|
-
const r = Array.from(this.pendingQueue.values());
|
|
240
|
-
if (0 === r.length) return this._isSyncing = !1, this._notifyStateChange(), {
|
|
241
|
-
success: !0,
|
|
242
|
-
syncedKeys: [],
|
|
243
|
-
conflicts: [],
|
|
244
|
-
errors: [],
|
|
245
|
-
timestamp: Date.now(),
|
|
246
|
-
duration: Date.now() - e
|
|
247
|
-
};
|
|
248
|
-
await this._fetchRemoteVersions(r.map(e => e.key));
|
|
249
|
-
for (const e of r) try {
|
|
250
|
-
const s = this.remoteVersions.get(e.key);
|
|
251
|
-
if (s) if (s.version >= e.version) {
|
|
252
|
-
const r = {
|
|
253
|
-
key: e.key,
|
|
254
|
-
localValue: e.value,
|
|
255
|
-
remoteValue: s.value,
|
|
256
|
-
localVersion: e.version,
|
|
257
|
-
remoteVersion: s.version,
|
|
258
|
-
timestamp: e.timestamp
|
|
259
|
-
};
|
|
260
|
-
n.push(r);
|
|
261
|
-
const o = this.config.onConflict(r);
|
|
262
|
-
await this._resolveConflict(e, s, o), t.push(e.key), this.pendingQueue.delete(e.key);
|
|
263
|
-
} else await this._pushChange(e), t.push(e.key), this.pendingQueue.delete(e.key); else await this._pushChange(e),
|
|
264
|
-
t.push(e.key), this.pendingQueue.delete(e.key);
|
|
265
|
-
} catch (t) {
|
|
266
|
-
s.push(`Failed to sync "${e.key}": ${t}`);
|
|
267
|
-
}
|
|
268
|
-
const o = {
|
|
269
|
-
success: 0 === s.length,
|
|
270
|
-
syncedKeys: t,
|
|
271
|
-
conflicts: n,
|
|
272
|
-
errors: s,
|
|
273
|
-
timestamp: Date.now(),
|
|
274
|
-
duration: Date.now() - e
|
|
275
|
-
};
|
|
276
|
-
return this.config.onSync(o), o;
|
|
277
|
-
} catch (r) {
|
|
278
|
-
const o = `Sync failed: ${r}`;
|
|
279
|
-
return s.push(o), {
|
|
280
|
-
success: !1,
|
|
281
|
-
syncedKeys: t,
|
|
282
|
-
conflicts: n,
|
|
283
|
-
errors: s,
|
|
284
|
-
timestamp: Date.now(),
|
|
285
|
-
duration: Date.now() - e
|
|
286
|
-
};
|
|
287
|
-
} finally {
|
|
288
|
-
this._isSyncing = !1, this._notifyStateChange();
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
async _fetchRemoteVersions(e) {
|
|
292
|
-
try {
|
|
293
|
-
const t = this._getAuthToken(), n = await this.config.fetch(`${this.config.endpoint}/versions`, {
|
|
294
|
-
method: "POST",
|
|
295
|
-
headers: {
|
|
296
|
-
"Content-Type": "application/json",
|
|
297
|
-
...t && {
|
|
298
|
-
Authorization: `Bearer ${t}`
|
|
299
|
-
}
|
|
300
|
-
},
|
|
301
|
-
body: JSON.stringify({
|
|
302
|
-
keys: e
|
|
303
|
-
})
|
|
304
|
-
});
|
|
305
|
-
if (n.ok) {
|
|
306
|
-
const e = await n.json();
|
|
307
|
-
if (e.versions) for (const [t, n] of Object.entries(e.versions)) this.remoteVersions.set(t, n);
|
|
308
|
-
}
|
|
309
|
-
} catch (e) {}
|
|
310
|
-
}
|
|
311
|
-
async _pushChange(e) {
|
|
312
|
-
let t = 0;
|
|
313
|
-
for (;t < this.config.maxRetries; ) try {
|
|
314
|
-
const n = this._getAuthToken(), s = await this.config.fetch(`${this.config.endpoint}/sync`, {
|
|
315
|
-
method: "POST",
|
|
316
|
-
headers: {
|
|
317
|
-
"Content-Type": "application/json",
|
|
318
|
-
...n && {
|
|
319
|
-
Authorization: `Bearer ${n}`
|
|
320
|
-
}
|
|
321
|
-
},
|
|
322
|
-
body: JSON.stringify({
|
|
323
|
-
key: e.key,
|
|
324
|
-
value: e.value,
|
|
325
|
-
version: e.version,
|
|
326
|
-
timestamp: e.timestamp
|
|
327
|
-
})
|
|
328
|
-
});
|
|
329
|
-
if (s.ok) {
|
|
330
|
-
const t = await s.json();
|
|
331
|
-
return void (t.version && this.remoteVersions.set(e.key, {
|
|
332
|
-
version: t.version,
|
|
333
|
-
timestamp: t.timestamp || Date.now(),
|
|
334
|
-
value: e.value
|
|
335
|
-
}));
|
|
336
|
-
}
|
|
337
|
-
t++;
|
|
338
|
-
} catch (e) {
|
|
339
|
-
if (t++, t >= this.config.maxRetries) throw e;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
async _resolveConflict(e, t, n) {
|
|
343
|
-
switch (n.action) {
|
|
344
|
-
case "accept-local":
|
|
345
|
-
await this._pushChange({
|
|
346
|
-
...e,
|
|
347
|
-
version: t.version + 1,
|
|
348
|
-
timestamp: Date.now()
|
|
349
|
-
});
|
|
350
|
-
break;
|
|
409
|
+
};
|
|
351
410
|
|
|
352
|
-
|
|
353
|
-
this.store.set(e.key, t.value);
|
|
354
|
-
break;
|
|
411
|
+
h();
|
|
355
412
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
timestamp: Date.now()
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
getState() {
|
|
366
|
-
return {
|
|
367
|
-
isOnline: this._isOnline,
|
|
368
|
-
isSyncing: this._isSyncing,
|
|
369
|
-
lastSyncTimestamp: null,
|
|
370
|
-
pendingChanges: this.pendingQueue.size,
|
|
371
|
-
conflicts: 0
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
onOnlineChange(e) {
|
|
375
|
-
return this.onlineStatusListeners.add(e), () => this.onlineStatusListeners.delete(e);
|
|
376
|
-
}
|
|
377
|
-
onStateChange(e) {
|
|
378
|
-
return this.syncStateListeners.add(e), () => this.syncStateListeners.delete(e);
|
|
379
|
-
}
|
|
380
|
-
async flush() {
|
|
381
|
-
return this.sync();
|
|
382
|
-
}
|
|
383
|
-
destroy() {
|
|
384
|
-
this.syncTimer && clearTimeout(this.syncTimer), this.pendingQueue.clear(), this.onlineStatusListeners.clear(),
|
|
385
|
-
this.syncStateListeners.clear();
|
|
386
|
-
}
|
|
387
|
-
}, R = (e, t) => new M(e, t), T = () => {
|
|
413
|
+
var U = e => `${e}_`;
|
|
414
|
+
|
|
415
|
+
h();
|
|
416
|
+
|
|
417
|
+
var x = () => {
|
|
388
418
|
try {
|
|
389
419
|
if ("undefined" != typeof process && "production" === process.env?.NODE_ENV) return !0;
|
|
390
420
|
const e = "undefined" != typeof globalThis ? globalThis : "undefined" != typeof window ? window : {};
|
|
@@ -392,31 +422,31 @@ var c = (e, t) => {
|
|
|
392
422
|
} catch {
|
|
393
423
|
return !1;
|
|
394
424
|
}
|
|
395
|
-
},
|
|
396
|
-
const s = new Map, r = new Map, o = new Map, a = new Set, i = new Map,
|
|
397
|
-
n?.accessRules && n.accessRules.forEach(e =>
|
|
398
|
-
let
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
}),
|
|
425
|
+
}, N = () => "undefined" != typeof window ? window.localStorage : null, P = n => {
|
|
426
|
+
const s = new Map, r = new Map, o = new Map, a = new Set, i = new Map, u = new Set, y = new Map, d = new Map, g = new Map, f = new Map, h = new Map, w = new Map, S = new Map, v = new Map, b = n?.namespace || "gstate", E = n?.silent ?? !1, _ = n?.debounceTime ?? 150, k = n?.version ?? 0, C = n?.storage || N(), M = n?.onError, P = n?.maxObjectSize ?? 0, L = n?.maxTotalSize ?? 0, z = n?.encryptionKey ?? null, K = n?.validateInput ?? !0, J = n?.auditEnabled ?? !0, B = n?.userId, Q = n?.immer ?? !0, W = n?.persistByDefault ?? n?.persistence ?? n?.persist ?? !1;
|
|
427
|
+
n?.accessRules && n.accessRules.forEach(e => T(S, e.pattern, e.permissions));
|
|
428
|
+
let F, G = !1, q = !1, X = !1, Z = 0, H = null, Y = null;
|
|
429
|
+
const ee = new Promise(e => {
|
|
430
|
+
F = e;
|
|
431
|
+
}), te = () => ({
|
|
402
432
|
store: s,
|
|
403
433
|
versions: r,
|
|
404
434
|
sizes: o,
|
|
405
|
-
totalSize:
|
|
406
|
-
storage:
|
|
435
|
+
totalSize: Z,
|
|
436
|
+
storage: C,
|
|
407
437
|
config: n || {},
|
|
408
|
-
diskQueue:
|
|
409
|
-
encryptionKey:
|
|
410
|
-
audit:
|
|
411
|
-
onError:
|
|
412
|
-
silent:
|
|
413
|
-
debounceTime:
|
|
414
|
-
currentVersion:
|
|
415
|
-
}),
|
|
416
|
-
plugins:
|
|
417
|
-
onError:
|
|
418
|
-
silent:
|
|
419
|
-
}),
|
|
438
|
+
diskQueue: h,
|
|
439
|
+
encryptionKey: z,
|
|
440
|
+
audit: oe,
|
|
441
|
+
onError: M,
|
|
442
|
+
silent: E,
|
|
443
|
+
debounceTime: _,
|
|
444
|
+
currentVersion: k
|
|
445
|
+
}), ne = () => ({
|
|
446
|
+
plugins: f,
|
|
447
|
+
onError: M,
|
|
448
|
+
silent: E
|
|
449
|
+
}), se = e => {
|
|
420
450
|
if (null == e) return 0;
|
|
421
451
|
const t = typeof e;
|
|
422
452
|
if ("boolean" === t) return 4;
|
|
@@ -435,7 +465,7 @@ var c = (e, t) => {
|
|
|
435
465
|
}
|
|
436
466
|
}
|
|
437
467
|
return n;
|
|
438
|
-
},
|
|
468
|
+
}, re = (e, t) => {
|
|
439
469
|
((e, t, n) => {
|
|
440
470
|
if (0 !== e.plugins.size) for (const s of e.plugins.values()) {
|
|
441
471
|
const r = s.hooks?.[t];
|
|
@@ -449,43 +479,43 @@ var c = (e, t) => {
|
|
|
449
479
|
}) : e.silent;
|
|
450
480
|
}
|
|
451
481
|
}
|
|
452
|
-
})(
|
|
453
|
-
},
|
|
454
|
-
|
|
482
|
+
})(ne(), e, t);
|
|
483
|
+
}, oe = (e, t, n, s) => {
|
|
484
|
+
J && null !== A && R && R({
|
|
455
485
|
timestamp: Date.now(),
|
|
456
486
|
action: e,
|
|
457
487
|
key: t,
|
|
458
|
-
userId:
|
|
488
|
+
userId: B,
|
|
459
489
|
success: n,
|
|
460
490
|
error: s
|
|
461
491
|
});
|
|
462
|
-
},
|
|
463
|
-
const n =
|
|
492
|
+
}, ae = e => {
|
|
493
|
+
const n = d.get(e);
|
|
464
494
|
if (!n) return;
|
|
465
|
-
const s = new Set, o = n.selector(e => (s.add(e),
|
|
495
|
+
const s = new Set, o = n.selector(e => (s.add(e), d.has(e) ? d.get(e).lastValue : ue.get(e)));
|
|
466
496
|
n.deps.forEach(t => {
|
|
467
497
|
if (!s.has(t)) {
|
|
468
|
-
const n =
|
|
469
|
-
n && (n.delete(e), 0 === n.size &&
|
|
498
|
+
const n = g.get(t);
|
|
499
|
+
n && (n.delete(e), 0 === n.size && g.delete(t));
|
|
470
500
|
}
|
|
471
501
|
}), s.forEach(t => {
|
|
472
|
-
n.deps.has(t) || (
|
|
473
|
-
}), n.deps = s,
|
|
474
|
-
r.set(e, (r.get(e) || 0) + 1),
|
|
475
|
-
},
|
|
502
|
+
n.deps.has(t) || (g.has(t) || g.set(t, new Set), g.get(t).add(e));
|
|
503
|
+
}), n.deps = s, l(n.lastValue, o) || (n.lastValue = Q && null !== o && "object" == typeof o ? t(c(o), !0) : o,
|
|
504
|
+
r.set(e, (r.get(e) || 0) + 1), ie(e));
|
|
505
|
+
}, ie = e => {
|
|
476
506
|
if (e) {
|
|
477
|
-
if (
|
|
478
|
-
const t =
|
|
479
|
-
for (const e of t)
|
|
507
|
+
if (g.has(e)) {
|
|
508
|
+
const t = g.get(e);
|
|
509
|
+
for (const e of t) ae(e);
|
|
480
510
|
}
|
|
481
|
-
const t =
|
|
511
|
+
const t = y.get(e);
|
|
482
512
|
if (t) {
|
|
483
|
-
const n =
|
|
513
|
+
const n = ue.get(e);
|
|
484
514
|
for (const s of t) try {
|
|
485
515
|
s(n);
|
|
486
516
|
} catch (t) {
|
|
487
517
|
const n = t instanceof Error ? t : new Error(String(t));
|
|
488
|
-
|
|
518
|
+
M && M(n, {
|
|
489
519
|
operation: "watcher",
|
|
490
520
|
key: e
|
|
491
521
|
});
|
|
@@ -496,24 +526,24 @@ var c = (e, t) => {
|
|
|
496
526
|
t();
|
|
497
527
|
} catch (t) {
|
|
498
528
|
const n = t instanceof Error ? t : new Error(String(t));
|
|
499
|
-
|
|
529
|
+
M && M(n, {
|
|
500
530
|
operation: "keyListener",
|
|
501
531
|
key: e
|
|
502
532
|
});
|
|
503
533
|
}
|
|
504
534
|
}
|
|
505
|
-
if (
|
|
535
|
+
if (G) q = !0; else for (const e of a) try {
|
|
506
536
|
e();
|
|
507
537
|
} catch (e) {
|
|
508
538
|
const t = e instanceof Error ? e : new Error(String(e));
|
|
509
|
-
|
|
539
|
+
M && M(t, {
|
|
510
540
|
operation: "listener"
|
|
511
541
|
});
|
|
512
542
|
}
|
|
513
|
-
},
|
|
543
|
+
}, ce = async () => {
|
|
514
544
|
(async e => {
|
|
515
545
|
if (!e.storage) return;
|
|
516
|
-
const {store: t, config: n, diskQueue: s, storage: r, encryptionKey: o, audit: a, onError: i, silent: c, currentVersion: l} = e, u =
|
|
546
|
+
const {store: t, config: n, diskQueue: s, storage: r, encryptionKey: o, audit: a, onError: i, silent: c, currentVersion: l} = e, u = U(n.namespace || "gstate");
|
|
517
547
|
try {
|
|
518
548
|
const e = {};
|
|
519
549
|
let s;
|
|
@@ -544,7 +574,7 @@ var c = (e, t) => {
|
|
|
544
574
|
const i = n.options.encoded || n.options.encrypted || n.options.secure;
|
|
545
575
|
if (n.options.encrypted) {
|
|
546
576
|
if (!o) throw new Error(`Encryption key missing for "${t}"`);
|
|
547
|
-
s = await
|
|
577
|
+
s = await O(n.value, o);
|
|
548
578
|
} else i ? s = btoa(JSON.stringify(n.value)) : "object" == typeof n.value && null !== n.value && (s = JSON.stringify(n.value));
|
|
549
579
|
r.setItem(`${u}${t}`, JSON.stringify({
|
|
550
580
|
v: e.versions.get(t) || 1,
|
|
@@ -562,140 +592,140 @@ var c = (e, t) => {
|
|
|
562
592
|
key: t
|
|
563
593
|
});
|
|
564
594
|
}
|
|
565
|
-
})(
|
|
566
|
-
},
|
|
595
|
+
})(te());
|
|
596
|
+
}, le = {}, ue = {
|
|
567
597
|
_setSilently: (e, n) => {
|
|
568
|
-
const a = o.get(e) || 0, i =
|
|
569
|
-
|
|
598
|
+
const a = o.get(e) || 0, i = Q && null !== n && "object" == typeof n ? t(c(n), !0) : n, l = (P > 0 || L > 0) && !x() ? se(i) : 0;
|
|
599
|
+
Z = Z - a + l, o.set(e, l), s.set(e, i), r.set(e, (r.get(e) || 0) + 1), Y = null;
|
|
570
600
|
},
|
|
571
601
|
_registerMethod: (e, t, n) => {
|
|
572
602
|
const s = e => "__proto__" === e || "constructor" === e || "prototype" === e;
|
|
573
|
-
s(e) || s(t) || (
|
|
603
|
+
s(e) || s(t) || (le[e] || (le[e] = {}), le[e][t] = n);
|
|
574
604
|
},
|
|
575
|
-
set: (a, i,
|
|
576
|
-
const
|
|
577
|
-
if (
|
|
578
|
-
if (!
|
|
579
|
-
const
|
|
580
|
-
|
|
605
|
+
set: (a, i, u = {}) => {
|
|
606
|
+
const y = s.get(a), d = Q && "function" == typeof i ? e(y, i) : i;
|
|
607
|
+
if (K && !I(a)) return !1;
|
|
608
|
+
if (!j(S, a, "write", B)) return oe("set", a, !1, "RBAC Denied"), !1;
|
|
609
|
+
const g = K ? V(d) : d, f = o.get(a) || 0;
|
|
610
|
+
re("onBeforeSet", {
|
|
581
611
|
key: a,
|
|
582
|
-
value:
|
|
583
|
-
store:
|
|
612
|
+
value: g,
|
|
613
|
+
store: ue,
|
|
584
614
|
version: r.get(a) || 0
|
|
585
615
|
});
|
|
586
|
-
const
|
|
587
|
-
if (!
|
|
588
|
-
const e = (
|
|
589
|
-
if (
|
|
590
|
-
const t = new Error(`Object size (${e} bytes) exceeds maxObjectSize (${
|
|
591
|
-
|
|
616
|
+
const p = Q && null !== g && "object" == typeof g ? t(c(g), !0) : g;
|
|
617
|
+
if (!l(y, p)) {
|
|
618
|
+
const e = (P > 0 || L > 0) && !x() ? se(p) : 0;
|
|
619
|
+
if (P > 0 && e > P) {
|
|
620
|
+
const t = new Error(`Object size (${e} bytes) exceeds maxObjectSize (${P} bytes)`);
|
|
621
|
+
M && M(t, {
|
|
592
622
|
operation: "set",
|
|
593
623
|
key: a
|
|
594
624
|
});
|
|
595
625
|
}
|
|
596
626
|
if (L > 0) {
|
|
597
|
-
const t =
|
|
627
|
+
const t = Z - f + e;
|
|
598
628
|
if (t > L) {
|
|
599
629
|
const e = new Error(`Total store size (${t} bytes) exceeds limit (${L} bytes)`);
|
|
600
|
-
|
|
630
|
+
M && M(e, {
|
|
601
631
|
operation: "set"
|
|
602
632
|
});
|
|
603
633
|
}
|
|
604
634
|
}
|
|
605
|
-
|
|
606
|
-
const t =
|
|
607
|
-
return t && (
|
|
608
|
-
value:
|
|
635
|
+
Z = Z - f + e, o.set(a, e), s.set(a, p), r.set(a, (r.get(a) || 0) + 1), Y = null;
|
|
636
|
+
const t = u.persist ?? W;
|
|
637
|
+
return t && (h.set(a, {
|
|
638
|
+
value: p,
|
|
609
639
|
options: {
|
|
610
|
-
...
|
|
640
|
+
...u,
|
|
611
641
|
persist: t,
|
|
612
|
-
encoded:
|
|
642
|
+
encoded: u.encoded || n?.encoded
|
|
613
643
|
}
|
|
614
|
-
}),
|
|
644
|
+
}), H && clearTimeout(H), H = setTimeout(ce, _)), re("onSet", {
|
|
615
645
|
key: a,
|
|
616
|
-
value:
|
|
617
|
-
store:
|
|
646
|
+
value: p,
|
|
647
|
+
store: ue,
|
|
618
648
|
version: r.get(a)
|
|
619
|
-
}),
|
|
649
|
+
}), oe("set", a, !0), ie(a), !0;
|
|
620
650
|
}
|
|
621
651
|
return !1;
|
|
622
652
|
},
|
|
623
653
|
get: e => {
|
|
624
|
-
if (!
|
|
654
|
+
if (!j(S, e, "read", B)) return oe("get", e, !1, "RBAC Denied"), null;
|
|
625
655
|
const t = s.get(e);
|
|
626
|
-
return
|
|
627
|
-
store:
|
|
656
|
+
return re("onGet", {
|
|
657
|
+
store: ue,
|
|
628
658
|
key: e,
|
|
629
659
|
value: t
|
|
630
|
-
}),
|
|
660
|
+
}), oe("get", e, !0), t;
|
|
631
661
|
},
|
|
632
662
|
compute: (e, t) => {
|
|
633
663
|
try {
|
|
634
|
-
return
|
|
664
|
+
return d.has(e) || (d.set(e, {
|
|
635
665
|
selector: t,
|
|
636
666
|
lastValue: null,
|
|
637
667
|
deps: new Set
|
|
638
|
-
}),
|
|
668
|
+
}), ae(e)), d.get(e).lastValue;
|
|
639
669
|
} catch (t) {
|
|
640
670
|
const n = t instanceof Error ? t : new Error(String(t));
|
|
641
|
-
return
|
|
671
|
+
return M && M(n, {
|
|
642
672
|
operation: "compute",
|
|
643
673
|
key: e
|
|
644
674
|
}), null;
|
|
645
675
|
}
|
|
646
676
|
},
|
|
647
677
|
watch: (e, t) => {
|
|
648
|
-
|
|
649
|
-
const n =
|
|
678
|
+
y.has(e) || y.set(e, new Set);
|
|
679
|
+
const n = y.get(e);
|
|
650
680
|
return n.add(t), () => {
|
|
651
|
-
n.delete(t), 0 === n.size &&
|
|
681
|
+
n.delete(t), 0 === n.size && y.delete(e);
|
|
652
682
|
};
|
|
653
683
|
},
|
|
654
684
|
remove: e => {
|
|
655
|
-
if (!
|
|
685
|
+
if (!j(S, e, "delete", B)) return oe("delete", e, !1, "RBAC Denied"), !1;
|
|
656
686
|
const t = s.get(e), n = s.delete(e);
|
|
657
|
-
return n && (
|
|
658
|
-
store:
|
|
687
|
+
return n && (Z -= o.get(e) || 0, o.delete(e), re("onRemove", {
|
|
688
|
+
store: ue,
|
|
659
689
|
key: e,
|
|
660
690
|
value: t
|
|
661
|
-
}),
|
|
662
|
-
|
|
691
|
+
}), Y = null), r.set(e, (r.get(e) || 0) + 1), C && C.removeItem(`${b}_${e}`), oe("delete", e, !0),
|
|
692
|
+
ie(e), n;
|
|
663
693
|
},
|
|
664
|
-
delete: e =>
|
|
694
|
+
delete: e => ue.remove(e),
|
|
665
695
|
deleteAll: () => {
|
|
666
|
-
if (Array.from(s.keys()).forEach(e =>
|
|
667
|
-
const e =
|
|
668
|
-
for (let t = 0; t < (
|
|
669
|
-
const n =
|
|
670
|
-
n?.startsWith(e) && (
|
|
696
|
+
if (Array.from(s.keys()).forEach(e => ue.remove(e)), C) {
|
|
697
|
+
const e = b + "_";
|
|
698
|
+
for (let t = 0; t < (C.length || 0); t++) {
|
|
699
|
+
const n = C.key(t);
|
|
700
|
+
n?.startsWith(e) && (C.removeItem(n), t--);
|
|
671
701
|
}
|
|
672
702
|
}
|
|
673
|
-
return
|
|
703
|
+
return Z = 0, o.clear(), Y = null, !0;
|
|
674
704
|
},
|
|
675
705
|
list: () => Object.fromEntries(s.entries()),
|
|
676
706
|
use: e => {
|
|
677
|
-
|
|
707
|
+
u.add(e);
|
|
678
708
|
},
|
|
679
709
|
transaction: e => {
|
|
680
|
-
|
|
681
|
-
store:
|
|
710
|
+
G = !0, re("onTransaction", {
|
|
711
|
+
store: ue,
|
|
682
712
|
key: "START"
|
|
683
713
|
});
|
|
684
714
|
try {
|
|
685
715
|
e();
|
|
686
716
|
} finally {
|
|
687
|
-
|
|
688
|
-
store:
|
|
717
|
+
G = !1, re("onTransaction", {
|
|
718
|
+
store: ue,
|
|
689
719
|
key: "END"
|
|
690
|
-
}),
|
|
720
|
+
}), q && (q = !1, ie());
|
|
691
721
|
}
|
|
692
722
|
},
|
|
693
723
|
destroy: () => {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
store:
|
|
697
|
-
}), a.clear(), i.clear(),
|
|
698
|
-
o.clear(),
|
|
724
|
+
H && (clearTimeout(H), H = null), h.clear(), "undefined" != typeof window && window.removeEventListener("beforeunload", ye),
|
|
725
|
+
re("onDestroy", {
|
|
726
|
+
store: ue
|
|
727
|
+
}), a.clear(), i.clear(), y.clear(), d.clear(), g.clear(), f.clear(), s.clear(),
|
|
728
|
+
o.clear(), Z = 0, S.clear(), v.clear(), r.clear(), w.clear(), u.clear();
|
|
699
729
|
},
|
|
700
730
|
_addPlugin: e => {
|
|
701
731
|
((e, t, n) => {
|
|
@@ -710,10 +740,10 @@ var c = (e, t) => {
|
|
|
710
740
|
key: t.name
|
|
711
741
|
}) : e.silent;
|
|
712
742
|
}
|
|
713
|
-
})(
|
|
743
|
+
})(ne(), e, ue);
|
|
714
744
|
},
|
|
715
745
|
_removePlugin: e => {
|
|
716
|
-
|
|
746
|
+
f.delete(e);
|
|
717
747
|
},
|
|
718
748
|
_subscribe: (e, t) => {
|
|
719
749
|
if (t) {
|
|
@@ -726,9 +756,9 @@ var c = (e, t) => {
|
|
|
726
756
|
return a.add(e), () => a.delete(e);
|
|
727
757
|
},
|
|
728
758
|
_getVersion: e => r.get(e) ?? 0,
|
|
729
|
-
addAccessRule: (e, t) =>
|
|
730
|
-
hasPermission: (e, t, n) =>
|
|
731
|
-
recordConsent: (e, t, n) =>
|
|
759
|
+
addAccessRule: (e, t) => T(S, e, t),
|
|
760
|
+
hasPermission: (e, t, n) => j(S, e, t, n),
|
|
761
|
+
recordConsent: (e, t, n) => $(v, e, t, n),
|
|
732
762
|
hasConsent: (e, t) => ((e, t, n) => {
|
|
733
763
|
const s = e.get(t);
|
|
734
764
|
if (!s) return !1;
|
|
@@ -737,104 +767,125 @@ var c = (e, t) => {
|
|
|
737
767
|
if (t && t.purpose === n) return t.granted;
|
|
738
768
|
}
|
|
739
769
|
return !1;
|
|
740
|
-
})(
|
|
741
|
-
getConsents: e => ((e, t) => e.get(t) || [])(
|
|
742
|
-
revokeConsent: (e, t) => ((e, t, n) =>
|
|
770
|
+
})(v, e, t),
|
|
771
|
+
getConsents: e => ((e, t) => e.get(t) || [])(v, e),
|
|
772
|
+
revokeConsent: (e, t) => ((e, t, n) => $(e, t, n, !1))(v, e, t),
|
|
743
773
|
exportUserData: e => ((e, t) => ({
|
|
744
774
|
userId: t,
|
|
745
775
|
exportedAt: Date.now(),
|
|
746
776
|
consents: e.get(t) || []
|
|
747
|
-
}))(
|
|
777
|
+
}))(v, e),
|
|
748
778
|
deleteUserData: e => ((e, t) => {
|
|
749
779
|
const n = e.get(t)?.length || 0;
|
|
750
780
|
return e.delete(t), {
|
|
751
781
|
success: !0,
|
|
752
782
|
deletedConsents: n
|
|
753
783
|
};
|
|
754
|
-
})(
|
|
755
|
-
getSnapshot: () => (
|
|
784
|
+
})(v, e),
|
|
785
|
+
getSnapshot: () => (Y || (Y = Object.fromEntries(s.entries())), Y),
|
|
756
786
|
get plugins() {
|
|
757
|
-
return
|
|
787
|
+
return le;
|
|
758
788
|
},
|
|
759
789
|
get isReady() {
|
|
760
|
-
return
|
|
790
|
+
return X;
|
|
761
791
|
},
|
|
762
792
|
get namespace() {
|
|
763
|
-
return
|
|
793
|
+
return b;
|
|
764
794
|
},
|
|
765
795
|
get userId() {
|
|
766
|
-
return
|
|
796
|
+
return B;
|
|
767
797
|
},
|
|
768
|
-
whenReady: () =>
|
|
798
|
+
whenReady: () => ee
|
|
769
799
|
};
|
|
770
800
|
[ "addAccessRule", "recordConsent", "hasConsent", "getConsents", "revokeConsent", "exportUserData", "deleteUserData" ].forEach(e => {
|
|
771
|
-
const t =
|
|
772
|
-
t &&
|
|
801
|
+
const t = ue[e];
|
|
802
|
+
t && ue._registerMethod("security", e, t);
|
|
773
803
|
});
|
|
774
|
-
const
|
|
775
|
-
|
|
804
|
+
const ye = () => {
|
|
805
|
+
h.size > 0 && ce();
|
|
776
806
|
};
|
|
777
|
-
"undefined" != typeof window && window.addEventListener("beforeunload",
|
|
778
|
-
|
|
807
|
+
if ("undefined" != typeof window && window.addEventListener("beforeunload", ye),
|
|
808
|
+
C ? (async (e, n, s) => {
|
|
809
|
+
const {storage: r, config: o, encryptionKey: a, audit: i, onError: l, silent: u, currentVersion: y, store: d, sizes: g, versions: f} = e, h = U(o.namespace || "gstate"), p = o.immer ?? !0;
|
|
779
810
|
if (r) try {
|
|
780
|
-
const
|
|
781
|
-
let
|
|
811
|
+
const u = {};
|
|
812
|
+
let m = 0;
|
|
782
813
|
for (let e = 0; e < (r.length || 0); e++) {
|
|
783
814
|
const t = r.key(e);
|
|
784
|
-
if (!t || !t.startsWith(
|
|
815
|
+
if (!t || !t.startsWith(h)) continue;
|
|
785
816
|
const n = r.getItem(t);
|
|
786
817
|
if (n) try {
|
|
787
|
-
const s = JSON.parse(n), o = t.substring(
|
|
788
|
-
if (
|
|
818
|
+
const s = JSON.parse(n), o = t.substring(h.length);
|
|
819
|
+
if (m = Math.max(m, void 0 !== s._sys_v ? s._sys_v : s.v || 0), s.e && Date.now() > s.e) {
|
|
789
820
|
r.removeItem(t), e--;
|
|
790
821
|
continue;
|
|
791
822
|
}
|
|
792
823
|
let c = s.d;
|
|
793
|
-
if (s._enc && a) c = await
|
|
824
|
+
if (s._enc && a) c = await D(c, a); else if ("string" == typeof c) if (s._b64) try {
|
|
794
825
|
c = JSON.parse(atob(c));
|
|
795
826
|
} catch (e) {} else if (c.startsWith("{") || c.startsWith("[")) try {
|
|
796
827
|
c = JSON.parse(c);
|
|
797
828
|
} catch (e) {}
|
|
798
|
-
|
|
829
|
+
u[o] = c, i("hydrate", o, !0);
|
|
799
830
|
} catch (e) {
|
|
800
831
|
i("hydrate", t, !1, String(e));
|
|
801
832
|
const n = e instanceof Error ? e : new Error(String(e));
|
|
802
|
-
|
|
833
|
+
l && l(n, {
|
|
803
834
|
operation: "hydration",
|
|
804
835
|
key: t
|
|
805
836
|
});
|
|
806
837
|
}
|
|
807
838
|
}
|
|
808
|
-
const w =
|
|
839
|
+
const w = m < y && o.migrate ? o.migrate(u, m) : u;
|
|
809
840
|
Object.entries(w).forEach(([s, r]) => {
|
|
810
|
-
const o =
|
|
811
|
-
e.totalSize = e.totalSize - i + a,
|
|
841
|
+
const o = p && null !== r && "object" == typeof r ? t(c(r), !0) : r, a = n(o), i = g.get(s) || 0;
|
|
842
|
+
e.totalSize = e.totalSize - i + a, g.set(s, a), d.set(s, o), f.set(s, 1);
|
|
812
843
|
}), s();
|
|
813
844
|
} catch (e) {
|
|
814
845
|
const t = e instanceof Error ? e : new Error(String(e));
|
|
815
|
-
|
|
846
|
+
l && l(t, {
|
|
816
847
|
operation: "hydration"
|
|
817
848
|
});
|
|
818
849
|
}
|
|
819
|
-
})(
|
|
820
|
-
|
|
821
|
-
}).then(() => {}) : (
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
850
|
+
})(te(), e => (P > 0 || L > 0) && !x() ? se(e) : 0, () => {
|
|
851
|
+
X = !0, Y = null, F(), ie();
|
|
852
|
+
}).then(() => {}) : (X = !0, F()), n?.sync) {
|
|
853
|
+
const e = n.sync, t = async () => {
|
|
854
|
+
const {SyncEngine: t} = await Promise.resolve().then(() => (m(), p));
|
|
855
|
+
return new t(ue, e);
|
|
856
|
+
};
|
|
857
|
+
let s = null;
|
|
858
|
+
ue._registerMethod("sync", "flush", async () => {
|
|
859
|
+
s || (s = t());
|
|
860
|
+
return (await s).flush();
|
|
861
|
+
}), ue._registerMethod("sync", "getState", async () => {
|
|
862
|
+
s || (s = t());
|
|
863
|
+
return (await s).getState();
|
|
864
|
+
}), ue._registerMethod("sync", "onStateChange", async e => {
|
|
865
|
+
s || (s = t());
|
|
866
|
+
return (await s).onStateChange(e);
|
|
867
|
+
}), ue._registerMethod("sync", "forceSync", async () => {
|
|
868
|
+
s || (s = t());
|
|
869
|
+
return (await s).sync();
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
return ue;
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
m();
|
|
876
|
+
|
|
877
|
+
var L = null, z = e => {
|
|
878
|
+
const t = P(e);
|
|
879
|
+
return L = t, t;
|
|
880
|
+
}, K = () => {
|
|
881
|
+
L && (L.destroy(), L = null);
|
|
882
|
+
}, J = e => {
|
|
883
|
+
const t = e || L, r = n(() => e => t ? t._subscribe(e) : () => {}, [ t ]);
|
|
833
884
|
return s(r, () => !!t && t.isReady, () => !0);
|
|
834
|
-
},
|
|
885
|
+
}, B = () => L;
|
|
835
886
|
|
|
836
|
-
function
|
|
837
|
-
const a = n(() => t ||
|
|
887
|
+
function Q(e, t) {
|
|
888
|
+
const a = n(() => t || L, [ t ]), i = n(() => {
|
|
838
889
|
const e = () => {}, t = () => !1, n = () => null;
|
|
839
890
|
return {
|
|
840
891
|
set: t,
|
|
@@ -873,23 +924,23 @@ function L(e, t) {
|
|
|
873
924
|
} catch {
|
|
874
925
|
return;
|
|
875
926
|
}
|
|
876
|
-
}, [ y, l ]), h = s(d, g, f), p = r((e, t) => l ? (
|
|
927
|
+
}, [ y, l ]), h = s(d, g, f), p = r((e, t) => l ? (x(), !1) : c.set(u, e, t), [ c, l, u ]);
|
|
877
928
|
return o(h, e => l ? `Selector: ${JSON.stringify(e)}` : `${u}: ${JSON.stringify(e)}`),
|
|
878
929
|
l ? h : [ h, p ];
|
|
879
930
|
}
|
|
880
931
|
|
|
881
|
-
var
|
|
932
|
+
var W = new Map, F = (e, t) => {
|
|
882
933
|
const n = e.namespace;
|
|
883
|
-
if (
|
|
884
|
-
const s = new
|
|
885
|
-
return
|
|
886
|
-
},
|
|
887
|
-
const t =
|
|
888
|
-
t && (t.destroy(),
|
|
934
|
+
if (W.has(n)) return W.get(n);
|
|
935
|
+
const s = new u(e, t);
|
|
936
|
+
return W.set(n, s), s;
|
|
937
|
+
}, G = e => {
|
|
938
|
+
const t = W.get(e);
|
|
939
|
+
t && (t.destroy(), W.delete(e));
|
|
889
940
|
};
|
|
890
941
|
|
|
891
|
-
function
|
|
892
|
-
const n = t ||
|
|
942
|
+
function q(e, t) {
|
|
943
|
+
const n = t || L, s = n?.namespace || "default", o = W.get(s), c = Q(e, n), l = c[0], u = c[1], [y, d] = a(() => o?.getState() || {
|
|
893
944
|
isOnline: !0,
|
|
894
945
|
isSyncing: !1,
|
|
895
946
|
lastSyncTimestamp: null,
|
|
@@ -910,7 +961,7 @@ function J(e, t) {
|
|
|
910
961
|
}, [ u, o, e, n ]), y ];
|
|
911
962
|
}
|
|
912
963
|
|
|
913
|
-
var
|
|
964
|
+
var X = () => {
|
|
914
965
|
const [e, t] = a({
|
|
915
966
|
isOnline: !0,
|
|
916
967
|
isSyncing: !1,
|
|
@@ -921,7 +972,7 @@ var B = () => {
|
|
|
921
972
|
return i(() => {
|
|
922
973
|
const e = () => {
|
|
923
974
|
let e = !0, n = !1, s = 0, r = 0;
|
|
924
|
-
|
|
975
|
+
W.forEach(t => {
|
|
925
976
|
const o = t.getState();
|
|
926
977
|
e = e && o.isOnline, n = n || o.isSyncing, s += o.pendingChanges, r += o.conflicts;
|
|
927
978
|
}), t({
|
|
@@ -933,16 +984,16 @@ var B = () => {
|
|
|
933
984
|
});
|
|
934
985
|
};
|
|
935
986
|
e();
|
|
936
|
-
const n = Array.from(
|
|
987
|
+
const n = Array.from(W.values()).map(t => t.onStateChange(e));
|
|
937
988
|
return () => n.forEach(e => e());
|
|
938
989
|
}, []), e;
|
|
939
|
-
},
|
|
940
|
-
const t = e ||
|
|
990
|
+
}, Z = async e => {
|
|
991
|
+
const t = e || L?.namespace;
|
|
941
992
|
if (!t) return;
|
|
942
|
-
const n =
|
|
993
|
+
const n = W.get(t);
|
|
943
994
|
n && await n.flush();
|
|
944
|
-
},
|
|
945
|
-
const n = t?.key || "async_data", s = t?.store ||
|
|
995
|
+
}, H = (e, t) => {
|
|
996
|
+
const n = t?.key || "async_data", s = t?.store || P({
|
|
946
997
|
namespace: `async_${n}`,
|
|
947
998
|
silent: !0
|
|
948
999
|
});
|
|
@@ -995,14 +1046,18 @@ var B = () => {
|
|
|
995
1046
|
}
|
|
996
1047
|
}
|
|
997
1048
|
});
|
|
998
|
-
}
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
m();
|
|
1052
|
+
|
|
1053
|
+
var Y = () => ({
|
|
999
1054
|
name: "gstate-immer",
|
|
1000
1055
|
hooks: {
|
|
1001
1056
|
onInstall: ({store: e}) => {
|
|
1002
1057
|
e._registerMethod("immer", "setWithProduce", (t, n) => e.set(t, n));
|
|
1003
1058
|
}
|
|
1004
1059
|
}
|
|
1005
|
-
}),
|
|
1060
|
+
}), ee = e => {
|
|
1006
1061
|
let t = [], n = -1, s = !1;
|
|
1007
1062
|
const r = e?.limit || 50;
|
|
1008
1063
|
return {
|
|
@@ -1034,7 +1089,7 @@ var B = () => {
|
|
|
1034
1089
|
}
|
|
1035
1090
|
}
|
|
1036
1091
|
};
|
|
1037
|
-
},
|
|
1092
|
+
}, te = e => ({
|
|
1038
1093
|
name: "gstate-schema",
|
|
1039
1094
|
hooks: {
|
|
1040
1095
|
onSet: ({key: t, value: n}) => {
|
|
@@ -1046,7 +1101,7 @@ var B = () => {
|
|
|
1046
1101
|
}
|
|
1047
1102
|
}
|
|
1048
1103
|
}
|
|
1049
|
-
}),
|
|
1104
|
+
}), ne = e => {
|
|
1050
1105
|
const t = globalThis.__REDUX_DEVTOOLS_EXTENSION__;
|
|
1051
1106
|
if (!t?.connect) return {
|
|
1052
1107
|
name: "gstate-devtools-noop",
|
|
@@ -1069,7 +1124,7 @@ var B = () => {
|
|
|
1069
1124
|
}
|
|
1070
1125
|
}
|
|
1071
1126
|
};
|
|
1072
|
-
},
|
|
1127
|
+
}, se = () => {
|
|
1073
1128
|
const e = new Map;
|
|
1074
1129
|
return {
|
|
1075
1130
|
name: "gstate-snapshot",
|
|
@@ -1089,7 +1144,7 @@ var B = () => {
|
|
|
1089
1144
|
}
|
|
1090
1145
|
}
|
|
1091
1146
|
};
|
|
1092
|
-
},
|
|
1147
|
+
}, re = e => ({
|
|
1093
1148
|
name: "gstate-guard",
|
|
1094
1149
|
hooks: {
|
|
1095
1150
|
onBeforeSet: ({key: t, value: n, store: s}) => {
|
|
@@ -1098,7 +1153,7 @@ var B = () => {
|
|
|
1098
1153
|
r && r(n);
|
|
1099
1154
|
}
|
|
1100
1155
|
}
|
|
1101
|
-
}),
|
|
1156
|
+
}), oe = e => ({
|
|
1102
1157
|
name: "gstate-analytics",
|
|
1103
1158
|
hooks: {
|
|
1104
1159
|
onSet: ({key: t, value: n}) => {
|
|
@@ -1116,7 +1171,7 @@ var B = () => {
|
|
|
1116
1171
|
}));
|
|
1117
1172
|
}
|
|
1118
1173
|
}
|
|
1119
|
-
}),
|
|
1174
|
+
}), ae = e => {
|
|
1120
1175
|
const t = new BroadcastChannel(e?.channelName || "gstate_sync");
|
|
1121
1176
|
let n = !1;
|
|
1122
1177
|
return {
|
|
@@ -1146,12 +1201,12 @@ var B = () => {
|
|
|
1146
1201
|
}
|
|
1147
1202
|
}
|
|
1148
1203
|
};
|
|
1149
|
-
},
|
|
1150
|
-
if (
|
|
1204
|
+
}, ie = () => {
|
|
1205
|
+
if (x()) return {
|
|
1151
1206
|
name: "gstate-debug-noop",
|
|
1152
1207
|
hooks: {}
|
|
1153
1208
|
};
|
|
1154
|
-
|
|
1209
|
+
x();
|
|
1155
1210
|
return {
|
|
1156
1211
|
name: "gstate-debug",
|
|
1157
1212
|
hooks: {
|
|
@@ -1184,7 +1239,7 @@ var B = () => {
|
|
|
1184
1239
|
}
|
|
1185
1240
|
}
|
|
1186
1241
|
};
|
|
1187
|
-
},
|
|
1242
|
+
}, ce = (e = {}) => {
|
|
1188
1243
|
const t = e.dbName || "rgs-db", n = e.storeName || "states", s = e.version || 1;
|
|
1189
1244
|
let r = null;
|
|
1190
1245
|
const o = () => new Promise((e, o) => {
|
|
@@ -1252,7 +1307,7 @@ var B = () => {
|
|
|
1252
1307
|
}
|
|
1253
1308
|
}
|
|
1254
1309
|
};
|
|
1255
|
-
},
|
|
1310
|
+
}, le = e => {
|
|
1256
1311
|
const {adapter: t, autoSyncInterval: n} = e, s = new Map, r = {
|
|
1257
1312
|
lastSyncTimestamp: null,
|
|
1258
1313
|
totalKeysSynced: 0,
|
|
@@ -1306,7 +1361,7 @@ var B = () => {
|
|
|
1306
1361
|
}
|
|
1307
1362
|
}
|
|
1308
1363
|
};
|
|
1309
|
-
},
|
|
1364
|
+
}, ue = (e, t) => ({
|
|
1310
1365
|
name: "MongoDB-Atlas",
|
|
1311
1366
|
save: async n => (await fetch(`${e}/action/updateOne`, {
|
|
1312
1367
|
method: "POST",
|
|
@@ -1330,17 +1385,17 @@ var B = () => {
|
|
|
1330
1385
|
upsert: !0
|
|
1331
1386
|
})
|
|
1332
1387
|
})).ok
|
|
1333
|
-
}),
|
|
1388
|
+
}), ye = (e, t) => ({
|
|
1334
1389
|
name: "Firebase-Firestore",
|
|
1335
1390
|
save: async e => {
|
|
1336
1391
|
try {
|
|
1337
|
-
|
|
1392
|
+
x();
|
|
1338
1393
|
return (() => {})("[Mock] Firestore Syncing:", e), !0;
|
|
1339
1394
|
} catch (e) {
|
|
1340
1395
|
return !1;
|
|
1341
1396
|
}
|
|
1342
1397
|
}
|
|
1343
|
-
}),
|
|
1398
|
+
}), de = (e, t) => ({
|
|
1344
1399
|
name: "SQL-REST-API",
|
|
1345
1400
|
save: async n => {
|
|
1346
1401
|
const s = t();
|
|
@@ -1355,7 +1410,7 @@ var B = () => {
|
|
|
1355
1410
|
credentials: "same-origin"
|
|
1356
1411
|
})).ok;
|
|
1357
1412
|
}
|
|
1358
|
-
}),
|
|
1413
|
+
}), ge = e => ({
|
|
1359
1414
|
name: "gstate-logger",
|
|
1360
1415
|
hooks: {
|
|
1361
1416
|
onSet: ({key: e, value: t, version: n}) => {
|
|
@@ -1364,27 +1419,27 @@ var B = () => {
|
|
|
1364
1419
|
onRemove: ({key: e}) => {},
|
|
1365
1420
|
onTransaction: ({key: e}) => {}
|
|
1366
1421
|
}
|
|
1367
|
-
}),
|
|
1368
|
-
const n =
|
|
1422
|
+
}), fe = (e, t) => {
|
|
1423
|
+
const n = P("string" == typeof t ? {
|
|
1369
1424
|
namespace: t
|
|
1370
1425
|
} : t);
|
|
1371
1426
|
e && Object.entries(e).forEach(([e, t]) => {
|
|
1372
1427
|
null === n.get(e) && n._setSilently(e, t);
|
|
1373
1428
|
});
|
|
1374
|
-
return "undefined" == typeof window ||
|
|
1375
|
-
window.rgs = n), Object.assign(e =>
|
|
1376
|
-
},
|
|
1377
|
-
const s =
|
|
1429
|
+
return "undefined" == typeof window || x() || (window.gstate = n, window.gState = n,
|
|
1430
|
+
window.rgs = n), Object.assign(e => Q(e, n), n);
|
|
1431
|
+
}, he = (e, t) => B()?.addAccessRule(e, t), pe = (e, t, n) => B()?.hasPermission(e, t, n) ?? !0, me = (e, t, n) => {
|
|
1432
|
+
const s = B();
|
|
1378
1433
|
if (!s) throw new Error("[gstate] recordConsent failed: No store found. call initState() first.");
|
|
1379
1434
|
return s.recordConsent(e, t, n);
|
|
1380
|
-
},
|
|
1381
|
-
const t =
|
|
1435
|
+
}, we = (e, t) => B()?.hasConsent(e, t) ?? !1, Se = e => B()?.getConsents(e) ?? [], ve = (e, t) => B()?.revokeConsent(e, t), be = e => {
|
|
1436
|
+
const t = B();
|
|
1382
1437
|
if (!t) throw new Error("[gstate] exportUserData failed: No store found.");
|
|
1383
1438
|
return t.exportUserData(e);
|
|
1384
|
-
},
|
|
1385
|
-
const t =
|
|
1439
|
+
}, Ee = e => {
|
|
1440
|
+
const t = B();
|
|
1386
1441
|
if (!t) throw new Error("[gstate] deleteUserData failed: No store found.");
|
|
1387
1442
|
return t.deleteUserData(e);
|
|
1388
|
-
},
|
|
1443
|
+
}, _e = () => {}, ke = () => {};
|
|
1389
1444
|
|
|
1390
|
-
export {
|
|
1445
|
+
export { u as SyncEngine, he as addAccessRule, oe as analyticsPlugin, _e as clearAccessRules, ke as clearAllConsents, le as cloudSyncPlugin, H as createAsyncStore, ye as createFirestoreAdapter, ue as createMongoAdapter, de as createSqlRestAdapter, P as createStore, y as createSyncEngine, ie as debugPlugin, Ee as deleteUserData, b as deriveKeyFromPassword, K as destroyState, G as destroySync, ne as devToolsPlugin, k as exportKey, be as exportUserData, _ as generateEncryptionKey, E as generateSalt, Se as getConsents, B as getStore, fe as gstate, re as guardPlugin, we as hasConsent, pe as hasPermission, Y as immerPlugin, C as importKey, ce as indexedDBPlugin, z as initState, F as initSync, v as isCryptoAvailable, R as logAudit, ge as loggerPlugin, me as recordConsent, ve as revokeConsent, V as sanitizeValue, te as schemaPlugin, M as setAuditLogger, se as snapshotPlugin, ae as syncPlugin, Z as triggerSync, ee as undoRedoPlugin, Q as useGState, J as useIsStoreReady, Q as useSimpleState, Q as useStore, X as useSyncStatus, q as useSyncedState, I as validateKey };
|