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