memorio 3.0.0 → 3.0.2
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/CODE_OF_CONDUCT.md +1 -1
- package/README.md +209 -328
- package/SECURITY.md +48 -3
- package/docs/README.md +209 -328
- package/docs/markdown/CACHE.md +3 -3
- package/docs/markdown/CHANGELOG.md +63 -154
- package/docs/markdown/DEVTOOLS.md +1 -1
- package/docs/markdown/IDB.md +3 -3
- package/docs/markdown/LOGGER.md +2 -2
- package/docs/markdown/OBSERVER.md +4 -4
- package/docs/markdown/PLATFORM.md +5 -5
- package/docs/markdown/SECURITY.md +16 -4
- package/docs/markdown/SESSION.md +4 -4
- package/docs/markdown/STATE.md +7 -7
- package/docs/markdown/STORE.md +7 -7
- package/docs/markdown/USEOBSERVER.md +1 -1
- package/examples/basic.ts +22 -22
- package/examples/browser-vanilla.html +2 -2
- package/examples/cache.ts +9 -9
- package/examples/idb.ts +8 -8
- package/examples/node-server.ts +39 -39
- package/examples/observer.ts +5 -5
- package/examples/platform.ts +37 -37
- package/examples/react-app.tsx +9 -4
- package/examples/session-advanced.ts +8 -8
- package/examples/state-advanced.ts +10 -10
- package/examples/store-advanced.ts +9 -9
- package/examples/useObserver.tsx +1 -1
- package/index.cjs +126 -117
- package/index.js +126 -117
- package/package.json +3 -3
- package/types/cache.d.ts +1 -1
- package/types/idb.d.ts +1 -1
- package/types/memorio.d.ts +6 -0
- package/types/observer.d.ts +1 -1
- package/types/store.d.ts +10 -10
- package/types/useObserver.d.ts +1 -1
package/index.js
CHANGED
|
@@ -24,25 +24,25 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
24
24
|
}
|
|
25
25
|
}, idb.db.list();
|
|
26
26
|
}
|
|
27
|
-
}), i = {},
|
|
27
|
+
}), i = {}, l = t({
|
|
28
28
|
"functions/idb/tools/db.exist.ts"() {
|
|
29
29
|
idb.db.exist = e => idbases?.some(t => t.name === e);
|
|
30
30
|
}
|
|
31
|
-
}),
|
|
31
|
+
}), a = {}, c = t({
|
|
32
32
|
"functions/idb/tools/db.quota.ts"() {
|
|
33
33
|
idb.db.quota = () => navigator.storage.estimate();
|
|
34
34
|
}
|
|
35
35
|
}), b = {}, u = t({
|
|
36
36
|
"functions/idb/tools/db.delete.ts"() {
|
|
37
37
|
idb.db.delete = e => new Promise((t, o) => {
|
|
38
|
-
|
|
38
|
+
(() => {
|
|
39
39
|
const r = indexedDB.deleteDatabase(e);
|
|
40
40
|
r.onsuccess = () => {
|
|
41
41
|
idb.db.list(), t();
|
|
42
42
|
}, r.onerror = () => {
|
|
43
43
|
o(r.error);
|
|
44
44
|
}, r.onblocked = () => {};
|
|
45
|
-
})()
|
|
45
|
+
})();
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
}), d = {}, f = t({
|
|
@@ -61,7 +61,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
}), m = {},
|
|
64
|
+
}), m = {}, g = t({
|
|
65
65
|
"functions/idb/tools/db.version.ts"() {
|
|
66
66
|
idb.db.version = e => {
|
|
67
67
|
let t = 0;
|
|
@@ -72,7 +72,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
72
72
|
return t;
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
}),
|
|
75
|
+
}), h = {}, p = t({
|
|
76
76
|
"functions/idb/tools/db.support.ts"() {
|
|
77
77
|
idb.db.support = () => {
|
|
78
78
|
const e = "indexedDB" in globalThis;
|
|
@@ -128,7 +128,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
128
128
|
};
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
|
-
}),
|
|
131
|
+
}), P = {}, O = t({
|
|
132
132
|
"functions/idb/crud/data.delete.ts"() {
|
|
133
133
|
idb.data.delete = (e, t, o) => new Promise((r, s) => {
|
|
134
134
|
const n = indexedDB.open(e);
|
|
@@ -163,11 +163,11 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
163
163
|
n.onsuccess = () => {
|
|
164
164
|
const i = n.result;
|
|
165
165
|
if (!i.objectStoreNames.contains(t)) return i.close(), s(new Error(`Table ${t} does not exist in ${e}`));
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
i.close(), r(
|
|
169
|
-
},
|
|
170
|
-
i.close(), s(
|
|
166
|
+
const l = i.transaction(t, "readwrite").objectStore(t).put(o);
|
|
167
|
+
l.onsuccess = () => {
|
|
168
|
+
i.close(), r(l.result);
|
|
169
|
+
}, l.onerror = e => {
|
|
170
|
+
i.close(), s(l.error);
|
|
171
171
|
};
|
|
172
172
|
}, n.onerror = () => {
|
|
173
173
|
s(n.error);
|
|
@@ -181,11 +181,11 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
181
181
|
n.onsuccess = n => {
|
|
182
182
|
const i = n.target.result;
|
|
183
183
|
if (!i.objectStoreNames.contains(t)) return i.close(), s(new Error(`Table ${t} not found in ${e}`));
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
i.close(), r(
|
|
187
|
-
},
|
|
188
|
-
i.close(), s(
|
|
184
|
+
const l = i.transaction(t, "readonly").objectStore(t).get(o);
|
|
185
|
+
l.onsuccess = () => {
|
|
186
|
+
i.close(), r(l.result);
|
|
187
|
+
}, l.onerror = () => {
|
|
188
|
+
i.close(), s(l.error);
|
|
189
189
|
};
|
|
190
190
|
}, n.onerror = () => {
|
|
191
191
|
s(n.error);
|
|
@@ -194,7 +194,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
194
194
|
}
|
|
195
195
|
});
|
|
196
196
|
|
|
197
|
-
function
|
|
197
|
+
function E() {
|
|
198
198
|
const e = globalThis;
|
|
199
199
|
if (void 0 !== e.crypto && e.crypto.randomUUID) return e.crypto.randomUUID();
|
|
200
200
|
if (void 0 !== e.crypto && e.crypto.getRandomValues) {
|
|
@@ -204,7 +204,12 @@ function x() {
|
|
|
204
204
|
return `session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
function
|
|
207
|
+
function x() {
|
|
208
|
+
const e = globalThis;
|
|
209
|
+
return e.Deno && e.Deno.version ? "deno" : "undefined" != typeof process && process.versions && process.versions.node ? "node" : "undefined" != typeof globalThis && void 0 !== globalThis.ServiceWorkerGlobalScope ? "edge" : "undefined" != typeof window && "undefined" != typeof document ? "browser" : "unknown";
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function N() {
|
|
208
213
|
try {
|
|
209
214
|
if ("undefined" != typeof sessionStorage) {
|
|
210
215
|
const e = "__memorio_test__";
|
|
@@ -214,7 +219,7 @@ function E() {
|
|
|
214
219
|
return null;
|
|
215
220
|
}
|
|
216
221
|
|
|
217
|
-
function
|
|
222
|
+
function I() {
|
|
218
223
|
try {
|
|
219
224
|
if ("undefined" != typeof localStorage) {
|
|
220
225
|
const e = "__memorio_test__";
|
|
@@ -224,40 +229,37 @@ function N() {
|
|
|
224
229
|
return null;
|
|
225
230
|
}
|
|
226
231
|
|
|
227
|
-
function
|
|
232
|
+
function D() {
|
|
228
233
|
return "undefined" != typeof indexedDB;
|
|
229
234
|
}
|
|
230
235
|
|
|
231
|
-
function
|
|
232
|
-
const e =
|
|
233
|
-
const e = globalThis;
|
|
234
|
-
return e.Deno && e.Deno.version ? "deno" : "undefined" != typeof process && process.versions && process.versions.node ? "node" : "undefined" != typeof globalThis && void 0 !== globalThis.ServiceWorkerGlobalScope ? "edge" : "undefined" != typeof window && "undefined" != typeof document ? "browser" : "unknown";
|
|
235
|
-
}(), t = void 0 !== globalThis.isSecureContext ? globalThis.isSecureContext : "browser" === e;
|
|
236
|
+
function A() {
|
|
237
|
+
const e = x(), t = void 0 !== globalThis.isSecureContext ? globalThis.isSecureContext : "browser" === e;
|
|
236
238
|
return {
|
|
237
239
|
platform: e,
|
|
238
|
-
hasSessionStorage: null !==
|
|
239
|
-
hasLocalStorage: null !==
|
|
240
|
-
hasIndexedDB:
|
|
240
|
+
hasSessionStorage: null !== N(),
|
|
241
|
+
hasLocalStorage: null !== I(),
|
|
242
|
+
hasIndexedDB: D(),
|
|
241
243
|
hasDispatchEvent: "function" == typeof globalThis.dispatchEvent,
|
|
242
244
|
hasNavigator: "undefined" != typeof navigator,
|
|
243
245
|
hasProcess: "undefined" != typeof process,
|
|
244
246
|
isSecureContext: t,
|
|
245
|
-
sessionId:
|
|
247
|
+
sessionId: E()
|
|
246
248
|
};
|
|
247
249
|
}
|
|
248
250
|
|
|
249
|
-
var A = new Map;
|
|
250
|
-
|
|
251
251
|
var z = new Map;
|
|
252
252
|
|
|
253
|
-
|
|
254
|
-
|
|
253
|
+
var J = new Map;
|
|
254
|
+
|
|
255
|
+
function B(e) {
|
|
256
|
+
const t = e || `context_${E()}`, o = {
|
|
255
257
|
state: {},
|
|
256
258
|
store: new Map,
|
|
257
259
|
session: new Map,
|
|
258
260
|
cache: new Map
|
|
259
261
|
};
|
|
260
|
-
return
|
|
262
|
+
return J.set(t, o), {
|
|
261
263
|
id: t,
|
|
262
264
|
state: o.state,
|
|
263
265
|
store: {
|
|
@@ -310,13 +312,13 @@ Object.defineProperty(globalThis, "memorio", {
|
|
|
310
312
|
}), Object.defineProperty(memorio, "version", {
|
|
311
313
|
writable: !1,
|
|
312
314
|
enumerable: !1,
|
|
313
|
-
value: "3.0.
|
|
315
|
+
value: "3.0.2"
|
|
314
316
|
});
|
|
315
317
|
|
|
316
|
-
var
|
|
318
|
+
var C = [ "list", "state", "store", "idb", "observer", "useObserver", "remove", "removeAll", "_platform", "_capabilities", "_sessionId" ];
|
|
317
319
|
|
|
318
320
|
!function() {
|
|
319
|
-
const e =
|
|
321
|
+
const e = A(), t = globalThis;
|
|
320
322
|
void 0 !== t.memorio && (t.memorio._platform = e.platform, t.memorio._capabilities = e),
|
|
321
323
|
e.hasDispatchEvent || (t.dispatchEvent = function(e) {
|
|
322
324
|
return !0;
|
|
@@ -327,15 +329,15 @@ var B = [ "list", "state", "store", "idb", "observer", "useObserver", "remove",
|
|
|
327
329
|
this.type = e, this.detail = t;
|
|
328
330
|
}
|
|
329
331
|
})), "function" != typeof t.addEventListener && (t.addEventListener = function(e, t) {
|
|
330
|
-
|
|
332
|
+
z.has(e) || z.set(e, []), z.get(e).push(t);
|
|
331
333
|
}, t.removeEventListener = function(e, t) {
|
|
332
|
-
const o =
|
|
334
|
+
const o = z.get(e);
|
|
333
335
|
if (o) {
|
|
334
336
|
const e = o.indexOf(t);
|
|
335
337
|
e > -1 && o.splice(e, 1);
|
|
336
338
|
}
|
|
337
339
|
}, t.dispatchEvent = function(e) {
|
|
338
|
-
const t =
|
|
340
|
+
const t = z.get(e.type);
|
|
339
341
|
return t && t.forEach(t => {
|
|
340
342
|
try {
|
|
341
343
|
t(e);
|
|
@@ -344,18 +346,26 @@ var B = [ "list", "state", "store", "idb", "observer", "useObserver", "remove",
|
|
|
344
346
|
});
|
|
345
347
|
}();
|
|
346
348
|
|
|
347
|
-
var $ =
|
|
349
|
+
var $ = A();
|
|
348
350
|
|
|
349
351
|
Object.defineProperty(memorio, "_sessionId", {
|
|
350
352
|
writable: !1,
|
|
351
353
|
enumerable: !1,
|
|
352
354
|
value: $.sessionId
|
|
353
|
-
}), memorio.createContext =
|
|
354
|
-
return Array.from(
|
|
355
|
+
}), memorio.createContext = B, memorio.listContexts = function() {
|
|
356
|
+
return Array.from(J.keys());
|
|
355
357
|
}, memorio.deleteContext = function(e) {
|
|
356
|
-
return
|
|
357
|
-
}, memorio.
|
|
358
|
-
return
|
|
358
|
+
return J.delete(e);
|
|
359
|
+
}, memorio.isBrowser = function() {
|
|
360
|
+
return "browser" === x();
|
|
361
|
+
}, memorio.isNode = function() {
|
|
362
|
+
return "node" === x();
|
|
363
|
+
}, memorio.isDeno = function() {
|
|
364
|
+
return "deno" === x();
|
|
365
|
+
}, memorio.isEdge = function() {
|
|
366
|
+
return "edge" === x();
|
|
367
|
+
}, memorio.getCapabilities = A, memorio.isolate = function(e) {
|
|
368
|
+
return B(e);
|
|
359
369
|
}, Object.defineProperty(memorio, "dispatch", {
|
|
360
370
|
writable: !1,
|
|
361
371
|
enumerable: !1,
|
|
@@ -384,7 +394,7 @@ Object.defineProperty(memorio, "_sessionId", {
|
|
|
384
394
|
}), globalThis.memorio._tracking = !1, globalThis.memorio._trackedPaths = new Set,
|
|
385
395
|
globalThis.memorio._locked = !1;
|
|
386
396
|
|
|
387
|
-
var
|
|
397
|
+
var R = (e, t, o = []) => new Proxy(e, {
|
|
388
398
|
get(e, r) {
|
|
389
399
|
if ("__path" === r) return o.length > 0 ? "state." + o.join(".") : "state";
|
|
390
400
|
if ("list" === r) return JSON.parse(JSON.stringify(globalThis.state));
|
|
@@ -395,8 +405,7 @@ var C = (e, t, o = []) => new Proxy(e, {
|
|
|
395
405
|
if ("remove" === r) return t => (delete e[t], !0);
|
|
396
406
|
if ("removeAll" === r) return () => {
|
|
397
407
|
try {
|
|
398
|
-
for (const t in e) "function" == typeof e[t] || [ "list", "remove", "removeAll" ].includes(t) ||
|
|
399
|
-
delete e[t]);
|
|
408
|
+
for (const t in e) "function" == typeof e[t] || [ "list", "remove", "removeAll", "lock", "unlock" ].includes(t) || delete e[t];
|
|
400
409
|
} catch (e) {}
|
|
401
410
|
};
|
|
402
411
|
if (Object.isFrozen(e[r])) return e[r];
|
|
@@ -406,14 +415,14 @@ var C = (e, t, o = []) => new Proxy(e, {
|
|
|
406
415
|
}
|
|
407
416
|
try {
|
|
408
417
|
const s = Reflect.get(e, r);
|
|
409
|
-
return s && "object" == typeof s && [ "Array", "Object" ].includes(s.constructor.name) ?
|
|
418
|
+
return s && "object" == typeof s && [ "Array", "Object" ].includes(s.constructor.name) ? R(s, t, o.concat(r)) : s;
|
|
410
419
|
} catch (e) {
|
|
411
420
|
return;
|
|
412
421
|
}
|
|
413
422
|
},
|
|
414
423
|
set(e, r, s) {
|
|
415
424
|
if (globalThis.memorio._locked) return !1;
|
|
416
|
-
if (
|
|
425
|
+
if (C.includes(r)) return !1;
|
|
417
426
|
if (e[r] && "object" == typeof e[r] && Object.isFrozen(e[r])) return !1;
|
|
418
427
|
if (e[r] && "object" == typeof e[r] && e[r].__locked) return !1;
|
|
419
428
|
try {
|
|
@@ -488,8 +497,7 @@ var C = (e, t, o = []) => new Proxy(e, {
|
|
|
488
497
|
getOwnPropertyDescriptor: (e, t) => Reflect.getOwnPropertyDescriptor(e, t)
|
|
489
498
|
});
|
|
490
499
|
|
|
491
|
-
globalThis?.state
|
|
492
|
-
globalThis.state.lock = () => {
|
|
500
|
+
globalThis?.state || (globalThis.state = R({}, () => {})), globalThis.state.lock = () => {
|
|
493
501
|
globalThis.memorio._locked = !0;
|
|
494
502
|
}, globalThis.state.unlock = () => {
|
|
495
503
|
globalThis.memorio._locked = !1;
|
|
@@ -539,8 +547,7 @@ globalThis.observer = (e, t = null, o = !0) => {
|
|
|
539
547
|
}), !0;
|
|
540
548
|
}
|
|
541
549
|
}
|
|
542
|
-
}),
|
|
543
|
-
Object.defineProperty(globalThis, "useObserver", {
|
|
550
|
+
}), globalThis.useObserver || (globalThis.useObserver = null), Object.defineProperty(globalThis, "useObserver", {
|
|
544
551
|
value: null,
|
|
545
552
|
writable: !0,
|
|
546
553
|
enumerable: !1,
|
|
@@ -581,10 +588,10 @@ Object.defineProperty(globalThis, "useObserver", {
|
|
|
581
588
|
}
|
|
582
589
|
}, Object.freeze(globalThis.useObserver);
|
|
583
590
|
|
|
584
|
-
var
|
|
591
|
+
var W = I(), M = new Map, q = null !== W, L = "memorio_store_";
|
|
585
592
|
|
|
586
|
-
function
|
|
587
|
-
return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ?
|
|
593
|
+
function U(e) {
|
|
594
|
+
return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ? L + e : "" : "";
|
|
588
595
|
}
|
|
589
596
|
|
|
590
597
|
Object.defineProperty(globalThis, "store", {
|
|
@@ -595,14 +602,14 @@ Object.defineProperty(globalThis, "store", {
|
|
|
595
602
|
get: {
|
|
596
603
|
value: e => {
|
|
597
604
|
if (!e) return;
|
|
598
|
-
const t =
|
|
605
|
+
const t = U(e);
|
|
599
606
|
try {
|
|
600
|
-
if (
|
|
601
|
-
const e =
|
|
607
|
+
if (q) {
|
|
608
|
+
const e = W.getItem(t);
|
|
602
609
|
return e ? JSON.parse(e) : e;
|
|
603
610
|
}
|
|
604
611
|
{
|
|
605
|
-
const e =
|
|
612
|
+
const e = M.get(t);
|
|
606
613
|
return e ? JSON.parse(e) : e;
|
|
607
614
|
}
|
|
608
615
|
} catch (e) {}
|
|
@@ -612,9 +619,11 @@ Object.defineProperty(globalThis, "store", {
|
|
|
612
619
|
set: {
|
|
613
620
|
value: (e, t) => {
|
|
614
621
|
if (!e) return;
|
|
615
|
-
const o =
|
|
622
|
+
const o = U(e);
|
|
616
623
|
try {
|
|
617
|
-
|
|
624
|
+
if (q) {
|
|
625
|
+
if (null == t) W.setItem(o, JSON.stringify(null)); else if ("object" == typeof t || "number" == typeof t || "boolean" == typeof t || "string" == typeof t) W.setItem(o, JSON.stringify(t)); else if ("function" == typeof t) return;
|
|
626
|
+
} else if (null == t) M.set(o, JSON.stringify(null)); else if ("object" == typeof t || "number" == typeof t || "boolean" == typeof t || "string" == typeof t) M.set(o, JSON.stringify(t)); else if ("function" == typeof t) return;
|
|
618
627
|
} catch (e) {}
|
|
619
628
|
return null;
|
|
620
629
|
}
|
|
@@ -622,11 +631,11 @@ Object.defineProperty(globalThis, "store", {
|
|
|
622
631
|
remove: {
|
|
623
632
|
value: e => {
|
|
624
633
|
if (!e) return;
|
|
625
|
-
const t =
|
|
634
|
+
const t = U(e);
|
|
626
635
|
try {
|
|
627
|
-
if (
|
|
628
|
-
if (
|
|
629
|
-
} else if (
|
|
636
|
+
if (q) {
|
|
637
|
+
if (W.getItem(t)) return W.removeItem(t), !0;
|
|
638
|
+
} else if (M.has(t)) return M.delete(t), !0;
|
|
630
639
|
} catch (e) {}
|
|
631
640
|
return !1;
|
|
632
641
|
}
|
|
@@ -636,14 +645,14 @@ Object.defineProperty(globalThis, "store", {
|
|
|
636
645
|
},
|
|
637
646
|
removeAll: {
|
|
638
647
|
value: () => {
|
|
639
|
-
if (
|
|
648
|
+
if (q) {
|
|
640
649
|
const e = [];
|
|
641
|
-
for (let t = 0; t <
|
|
642
|
-
const o =
|
|
643
|
-
o?.startsWith(
|
|
650
|
+
for (let t = 0; t < W.length; t++) {
|
|
651
|
+
const o = W.key(t);
|
|
652
|
+
o?.startsWith(L) && e.push(o);
|
|
644
653
|
}
|
|
645
|
-
e.forEach(e =>
|
|
646
|
-
} else
|
|
654
|
+
e.forEach(e => W.removeItem(e));
|
|
655
|
+
} else M.clear();
|
|
647
656
|
return !0;
|
|
648
657
|
}
|
|
649
658
|
},
|
|
@@ -656,25 +665,25 @@ Object.defineProperty(globalThis, "store", {
|
|
|
656
665
|
size: {
|
|
657
666
|
value: () => {
|
|
658
667
|
let e = 0;
|
|
659
|
-
return
|
|
660
|
-
if (t.startsWith(
|
|
661
|
-
const o =
|
|
668
|
+
return q ? Object.keys(W).forEach(t => {
|
|
669
|
+
if (t.startsWith(L)) {
|
|
670
|
+
const o = W.getItem(t);
|
|
662
671
|
o && (e += o.length);
|
|
663
672
|
}
|
|
664
|
-
}) :
|
|
673
|
+
}) : M.forEach(t => {
|
|
665
674
|
e += t.length;
|
|
666
675
|
}), e;
|
|
667
676
|
}
|
|
668
677
|
},
|
|
669
678
|
isPersistent: {
|
|
670
|
-
get: () =>
|
|
679
|
+
get: () => q
|
|
671
680
|
}
|
|
672
681
|
}), Object.freeze(store);
|
|
673
682
|
|
|
674
|
-
var
|
|
683
|
+
var V = N(), F = new Map, K = null !== V, Z = "memorio_session_";
|
|
675
684
|
|
|
676
|
-
function
|
|
677
|
-
return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ?
|
|
685
|
+
function G(e) {
|
|
686
|
+
return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ? Z + e : "" : "";
|
|
678
687
|
}
|
|
679
688
|
|
|
680
689
|
Object.defineProperty(globalThis, "session", {
|
|
@@ -685,14 +694,14 @@ Object.defineProperty(globalThis, "session", {
|
|
|
685
694
|
get: {
|
|
686
695
|
value: e => {
|
|
687
696
|
if (!e) return;
|
|
688
|
-
const t =
|
|
697
|
+
const t = G(e);
|
|
689
698
|
try {
|
|
690
|
-
if (
|
|
691
|
-
const e =
|
|
699
|
+
if (K) {
|
|
700
|
+
const e = V.getItem(t);
|
|
692
701
|
return e ? JSON.parse(e) : e;
|
|
693
702
|
}
|
|
694
703
|
{
|
|
695
|
-
const e =
|
|
704
|
+
const e = F.get(t);
|
|
696
705
|
return e ? JSON.parse(e) : e;
|
|
697
706
|
}
|
|
698
707
|
} catch (e) {}
|
|
@@ -701,20 +710,20 @@ Object.defineProperty(globalThis, "session", {
|
|
|
701
710
|
set: {
|
|
702
711
|
value: (e, t) => {
|
|
703
712
|
if (!e) return;
|
|
704
|
-
const o =
|
|
713
|
+
const o = G(e);
|
|
705
714
|
try {
|
|
706
|
-
|
|
715
|
+
K ? null == t ? V.setItem(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || V.setItem(o, JSON.stringify(t)) : null == t ? F.set(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || F.set(o, JSON.stringify(t));
|
|
707
716
|
} catch (e) {}
|
|
708
717
|
}
|
|
709
718
|
},
|
|
710
719
|
remove: {
|
|
711
720
|
value: e => {
|
|
712
721
|
if (!e) return;
|
|
713
|
-
const t =
|
|
722
|
+
const t = G(e);
|
|
714
723
|
try {
|
|
715
|
-
if (
|
|
716
|
-
if (
|
|
717
|
-
} else if (
|
|
724
|
+
if (K) {
|
|
725
|
+
if (V.getItem(t)) return V.removeItem(t), !0;
|
|
726
|
+
} else if (F.has(t)) return F.delete(t), !0;
|
|
718
727
|
} catch (e) {}
|
|
719
728
|
}
|
|
720
729
|
},
|
|
@@ -723,14 +732,14 @@ Object.defineProperty(globalThis, "session", {
|
|
|
723
732
|
},
|
|
724
733
|
removeAll: {
|
|
725
734
|
value: () => {
|
|
726
|
-
if (
|
|
735
|
+
if (K) {
|
|
727
736
|
const e = [];
|
|
728
|
-
for (let t = 0; t <
|
|
729
|
-
const o =
|
|
730
|
-
o?.startsWith(
|
|
737
|
+
for (let t = 0; t < V.length; t++) {
|
|
738
|
+
const o = V.key(t);
|
|
739
|
+
o?.startsWith(Z) && e.push(o);
|
|
731
740
|
}
|
|
732
|
-
e.forEach(e =>
|
|
733
|
-
} else
|
|
741
|
+
e.forEach(e => V.removeItem(e));
|
|
742
|
+
} else F.clear();
|
|
734
743
|
return !0;
|
|
735
744
|
}
|
|
736
745
|
},
|
|
@@ -743,35 +752,35 @@ Object.defineProperty(globalThis, "session", {
|
|
|
743
752
|
size: {
|
|
744
753
|
value: () => {
|
|
745
754
|
let e = 0;
|
|
746
|
-
return
|
|
747
|
-
if (t.startsWith(
|
|
748
|
-
const o =
|
|
755
|
+
return K ? Object.keys(V).forEach(t => {
|
|
756
|
+
if (t.startsWith(Z)) {
|
|
757
|
+
const o = V.getItem(t);
|
|
749
758
|
o && (e += o.length);
|
|
750
759
|
}
|
|
751
|
-
}) :
|
|
760
|
+
}) : F.forEach(t => {
|
|
752
761
|
e += t.length;
|
|
753
762
|
}), e;
|
|
754
763
|
}
|
|
755
764
|
},
|
|
756
765
|
isPersistent: {
|
|
757
|
-
get: () =>
|
|
766
|
+
get: () => K
|
|
758
767
|
}
|
|
759
768
|
}), Object.freeze(session);
|
|
760
769
|
|
|
761
|
-
var
|
|
770
|
+
var H = {};
|
|
762
771
|
|
|
763
772
|
Object.defineProperty(globalThis, "cache", {
|
|
764
773
|
value: new Proxy({}, {
|
|
765
|
-
get: (e, t) => "get" === t ? e =>
|
|
766
|
-
|
|
767
|
-
} : "remove" === t ? e => (delete
|
|
768
|
-
!0) :
|
|
769
|
-
set: (e, t, o) => (
|
|
770
|
-
deleteProperty: (e, t) => (delete
|
|
774
|
+
get: (e, t) => "get" === t ? e => H[e] : "set" === t ? (e, t) => {
|
|
775
|
+
H[e] = t;
|
|
776
|
+
} : "remove" === t ? e => (delete H[e], !0) : "removeAll" === t || "clear" === t ? () => (Object.keys(H).forEach(e => delete H[e]),
|
|
777
|
+
!0) : H[t],
|
|
778
|
+
set: (e, t, o) => (H[t] = o, !0),
|
|
779
|
+
deleteProperty: (e, t) => (delete H[t], !0)
|
|
771
780
|
}),
|
|
772
781
|
enumerable: !1,
|
|
773
782
|
configurable: !0
|
|
774
|
-
}), Object.freeze(cache),
|
|
783
|
+
}), Object.freeze(cache), D() ? (async () => {
|
|
775
784
|
Object.defineProperty(globalThis, "idb", {
|
|
776
785
|
value: {
|
|
777
786
|
db: {},
|
|
@@ -787,11 +796,11 @@ Object.defineProperty(globalThis, "cache", {
|
|
|
787
796
|
configurable: !0,
|
|
788
797
|
enumerable: !1
|
|
789
798
|
}), await Promise.all([ Promise.resolve().then(() => (r(), o)), Promise.resolve().then(() => (n(),
|
|
790
|
-
s)), Promise.resolve().then(() => (
|
|
791
|
-
|
|
792
|
-
d)), Promise.resolve().then(() => (
|
|
793
|
-
|
|
794
|
-
T)), Promise.resolve().then(() => (
|
|
799
|
+
s)), Promise.resolve().then(() => (l(), i)), Promise.resolve().then(() => (c(),
|
|
800
|
+
a)), Promise.resolve().then(() => (u(), b)), Promise.resolve().then(() => (f(),
|
|
801
|
+
d)), Promise.resolve().then(() => (g(), m)), Promise.resolve().then(() => (p(),
|
|
802
|
+
h)), Promise.resolve().then(() => (y(), v)), Promise.resolve().then(() => (j(),
|
|
803
|
+
T)), Promise.resolve().then(() => (O(), P)), Promise.resolve().then(() => (S(),
|
|
795
804
|
w)), Promise.resolve().then(() => (k(), _)) ]), Object.preventExtensions(idb), Object.seal(idb),
|
|
796
805
|
Object.freeze(idb);
|
|
797
806
|
})() : (Object.defineProperty(globalThis, "idb", {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memorio",
|
|
3
3
|
"code": "memorio",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.2",
|
|
5
5
|
"description": "Memorio, State + Observer, Store and iDB for an easy life - Cross-platform compatible",
|
|
6
6
|
"main": "./index.cjs",
|
|
7
7
|
"browser": "./index.cjs",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"types": "./index.d.ts",
|
|
10
10
|
"typing": "./types/*",
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"copyright": "Dario Passariello",
|
|
13
|
-
"author": "Dario Passariello",
|
|
12
|
+
"copyright": "Dario Passariello - BigLogic Inc",
|
|
13
|
+
"author": "Dario Passariello - BigLogic Inc <info@biglogic.ca> (https://biglogic.ca)",
|
|
14
14
|
"contributors": [
|
|
15
15
|
{
|
|
16
16
|
"name": "Dario Passariello",
|
package/types/cache.d.ts
CHANGED
package/types/idb.d.ts
CHANGED
package/types/memorio.d.ts
CHANGED
|
@@ -25,6 +25,12 @@ interface _memorio {
|
|
|
25
25
|
_tracking?: boolean
|
|
26
26
|
_trackedPaths?: Set<string>
|
|
27
27
|
_locked?: boolean
|
|
28
|
+
// Platform detection
|
|
29
|
+
isBrowser: () => boolean
|
|
30
|
+
isNode: () => boolean
|
|
31
|
+
isDeno: () => boolean
|
|
32
|
+
isEdge: () => boolean
|
|
33
|
+
getCapabilities: (...args: unknown[]) => any
|
|
28
34
|
// Platform properties
|
|
29
35
|
_platform?: string
|
|
30
36
|
_capabilities?: any
|
package/types/observer.d.ts
CHANGED
package/types/store.d.ts
CHANGED
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
interface _store {
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
* Create a new store
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* store.set("test","example") // Array, Object, Number, Boolean, String or null
|
|
11
|
+
*
|
|
12
|
+
* @since memorio 0.0.1
|
|
13
|
+
* @param name The String as name to define the store.
|
|
14
|
+
* @param value The information you want to store. Functions are blocked for security.
|
|
15
|
+
* @return void
|
|
16
|
+
*/
|
|
17
17
|
set: (name: string, value: any) => void
|
|
18
18
|
|
|
19
19
|
/**
|