memorio 4.3.2 ā 4.4.0
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/README.md +10 -4
- package/SUMMARY.md +2 -1
- package/index.cjs +155 -124
- package/index.js +153 -124
- package/llms.txt +16 -16
- package/markdown/CHANGELOG.md +1 -1
- package/markdown/DISPATCH.md +168 -0
- package/markdown/OBSERVER.md +33 -13
- package/markdown/USEOBSERVER.md +112 -13
- package/package.json +4 -7
- package/types/memorio.d.ts +3 -0
package/index.js
CHANGED
|
@@ -88,7 +88,7 @@ var e = Object.getOwnPropertyNames, o = (o, t) => function() {
|
|
|
88
88
|
}
|
|
89
89
|
}), v = {}, y = o({
|
|
90
90
|
"functions/idb/tools/table.create.ts"() {
|
|
91
|
-
idb.table.create = (e, o) => new Promise(
|
|
91
|
+
idb.table.create = (e, o) => new Promise((t, r) => {
|
|
92
92
|
try {
|
|
93
93
|
const s = (Number(idb.db.version(e)) || 0) + 1, n = indexedDB.open(e, s);
|
|
94
94
|
n.onupgradeneeded = t => {
|
|
@@ -137,7 +137,7 @@ var e = Object.getOwnPropertyNames, o = (o, t) => function() {
|
|
|
137
137
|
};
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
|
-
}), w = {},
|
|
140
|
+
}), w = {}, j = o({
|
|
141
141
|
"functions/idb/crud/data.delete.ts"() {
|
|
142
142
|
idb.data.delete = (e, o, t) => new Promise((r, s) => {
|
|
143
143
|
const n = indexedDB.open(e);
|
|
@@ -165,7 +165,7 @@ var e = Object.getOwnPropertyNames, o = (o, t) => function() {
|
|
|
165
165
|
}, s.onerror = () => r(s.error);
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
|
-
}),
|
|
168
|
+
}), S = {}, P = o({
|
|
169
169
|
"functions/idb/crud/data.set.ts"() {
|
|
170
170
|
idb.data.set = (e, o, t) => new Promise((r, s) => {
|
|
171
171
|
const n = indexedDB.open(e);
|
|
@@ -183,7 +183,7 @@ var e = Object.getOwnPropertyNames, o = (o, t) => function() {
|
|
|
183
183
|
};
|
|
184
184
|
});
|
|
185
185
|
}
|
|
186
|
-
}),
|
|
186
|
+
}), _ = {}, E = o({
|
|
187
187
|
"functions/idb/crud/data.get.ts"() {
|
|
188
188
|
idb.data.get = (e, o, t) => new Promise((r, s) => {
|
|
189
189
|
const n = indexedDB.open(e);
|
|
@@ -203,7 +203,7 @@ var e = Object.getOwnPropertyNames, o = (o, t) => function() {
|
|
|
203
203
|
}
|
|
204
204
|
});
|
|
205
205
|
|
|
206
|
-
function
|
|
206
|
+
function $() {
|
|
207
207
|
const e = globalThis;
|
|
208
208
|
if (void 0 !== e.crypto && e.crypto.randomUUID) return e.crypto.randomUUID();
|
|
209
209
|
if (void 0 !== e.crypto && e.crypto.getRandomValues) {
|
|
@@ -213,7 +213,7 @@ function k() {
|
|
|
213
213
|
return `session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
function
|
|
216
|
+
function k() {
|
|
217
217
|
const e = globalThis;
|
|
218
218
|
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";
|
|
219
219
|
}
|
|
@@ -238,31 +238,31 @@ function D() {
|
|
|
238
238
|
return null;
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
function
|
|
241
|
+
function A() {
|
|
242
242
|
return "undefined" != typeof indexedDB;
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
function
|
|
246
|
-
const e =
|
|
245
|
+
function I() {
|
|
246
|
+
const e = k(), o = void 0 !== globalThis.isSecureContext ? globalThis.isSecureContext : "browser" === e;
|
|
247
247
|
return {
|
|
248
248
|
platform: e,
|
|
249
249
|
hasSessionStorage: null !== x(),
|
|
250
250
|
hasLocalStorage: null !== D(),
|
|
251
|
-
hasIndexedDB:
|
|
251
|
+
hasIndexedDB: A(),
|
|
252
252
|
hasDispatchEvent: "function" == typeof globalThis.dispatchEvent,
|
|
253
253
|
hasNavigator: "undefined" != typeof navigator,
|
|
254
254
|
hasProcess: "undefined" != typeof process,
|
|
255
255
|
isSecureContext: o,
|
|
256
|
-
sessionId:
|
|
256
|
+
sessionId: $()
|
|
257
257
|
};
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
var
|
|
260
|
+
var N = new Map;
|
|
261
261
|
|
|
262
262
|
var C = new Map;
|
|
263
263
|
|
|
264
264
|
function J(e) {
|
|
265
|
-
const o = e || `context_${
|
|
265
|
+
const o = e || `context_${$()}`;
|
|
266
266
|
!function(e) {
|
|
267
267
|
const o = globalThis;
|
|
268
268
|
o.memorio || (o.memorio = {});
|
|
@@ -315,7 +315,7 @@ function J(e) {
|
|
|
315
315
|
};
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
-
var z = "4.
|
|
318
|
+
var z = "4.4.0";
|
|
319
319
|
|
|
320
320
|
Object.defineProperty(globalThis, "memorio", {
|
|
321
321
|
value: {
|
|
@@ -349,7 +349,7 @@ Object.defineProperty(globalThis, "memorio", {
|
|
|
349
349
|
var B = [ "list", "state", "store", "idb", "observer", "useObserver", "remove", "removeAll", "_platform", "_capabilities", "_sessionId" ];
|
|
350
350
|
|
|
351
351
|
!function() {
|
|
352
|
-
const e =
|
|
352
|
+
const e = I(), o = globalThis;
|
|
353
353
|
void 0 !== o.memorio && (o.memorio._platform = e.platform, o.memorio._capabilities = e),
|
|
354
354
|
e.hasDispatchEvent || (o.dispatchEvent = function(e) {
|
|
355
355
|
return !0;
|
|
@@ -360,15 +360,15 @@ var B = [ "list", "state", "store", "idb", "observer", "useObserver", "remove",
|
|
|
360
360
|
this.type = e, this.detail = o;
|
|
361
361
|
}
|
|
362
362
|
})), "function" != typeof o.addEventListener && (o.addEventListener = function(e, o) {
|
|
363
|
-
|
|
363
|
+
N.has(e) || N.set(e, []), N.get(e).push(o);
|
|
364
364
|
}, o.removeEventListener = function(e, o) {
|
|
365
|
-
const t =
|
|
365
|
+
const t = N.get(e);
|
|
366
366
|
if (t) {
|
|
367
367
|
const e = t.indexOf(o);
|
|
368
368
|
e > -1 && t.splice(e, 1);
|
|
369
369
|
}
|
|
370
370
|
}, o.dispatchEvent = function(e) {
|
|
371
|
-
const o =
|
|
371
|
+
const o = N.get(e.type);
|
|
372
372
|
return o && o.forEach(o => {
|
|
373
373
|
try {
|
|
374
374
|
o(e);
|
|
@@ -379,7 +379,7 @@ var B = [ "list", "state", "store", "idb", "observer", "useObserver", "remove",
|
|
|
379
379
|
});
|
|
380
380
|
}();
|
|
381
381
|
|
|
382
|
-
var M =
|
|
382
|
+
var M = I();
|
|
383
383
|
|
|
384
384
|
Object.defineProperty(memorio, "_sessionId", {
|
|
385
385
|
writable: !1,
|
|
@@ -390,17 +390,17 @@ Object.defineProperty(memorio, "_sessionId", {
|
|
|
390
390
|
}, memorio.deleteContext = function(e) {
|
|
391
391
|
return C.delete(e);
|
|
392
392
|
}, memorio.isBrowser = function() {
|
|
393
|
-
return "browser" ===
|
|
393
|
+
return "browser" === k();
|
|
394
394
|
}, memorio.isNode = function() {
|
|
395
|
-
return "node" ===
|
|
395
|
+
return "node" === k();
|
|
396
396
|
}, memorio.isDeno = function() {
|
|
397
|
-
return "deno" ===
|
|
397
|
+
return "deno" === k();
|
|
398
398
|
}, memorio.isEdge = function() {
|
|
399
|
-
return "edge" ===
|
|
400
|
-
}, memorio.getCapabilities =
|
|
399
|
+
return "edge" === k();
|
|
400
|
+
}, memorio.getCapabilities = I, memorio.isolate = function(e) {
|
|
401
401
|
return J(e);
|
|
402
402
|
}, memorio.help = function() {
|
|
403
|
-
console.
|
|
403
|
+
console.debug(`\nš§ Memorio ${z} - Help\n\nCore Modules:\n state - Reactive state management\n store - Persistent storage (localStorage/Map)\n session - Session storage (sessionStorage/Map)\n cache - In-memory cache\n idb - IndexedDB (browser only)\n\nContext Management:\n memorio.isolate(name) - Create isolated context\n memorio.listContexts() - List all contexts\n memorio.deleteContext(id) - Delete a context\n\nPlatform Detection:\n memorio.isBrowser() - Browser environment\n memorio.isNode() - Node.js environment\n memorio.isDeno() - Deno environment\n memorio.isEdge() - Edge/Worker environment\n memorio.getCapabilities() - Full capabilities object\n\nDevTools:\n memorio.devtools.inspect() - Inspect all modules\n memorio.devtools.stats() - Show statistics\n memorio.devtools.watch() - Watch a path\n memorio.devtools.exportData() - Export as JSON\n memorio.devtools.importData() - Import from JSON\n memorio.devtools.clear() - Clear specific module\n memorio.devtools.clearAll() - Clear all modules\n\nShortcuts:\n state, store, session, cache, idb - direct access to modules\n`);
|
|
404
404
|
}, Object.defineProperty(memorio, "dispatch", {
|
|
405
405
|
writable: !1,
|
|
406
406
|
enumerable: !1,
|
|
@@ -409,12 +409,13 @@ Object.defineProperty(memorio, "_sessionId", {
|
|
|
409
409
|
globalThis.dispatchEvent(new CustomEvent(String(e), o));
|
|
410
410
|
},
|
|
411
411
|
listen: (e, o = null) => {
|
|
412
|
-
globalThis.observer?.list?.[e]
|
|
413
|
-
|
|
412
|
+
const t = globalThis.observer?.list?.[e];
|
|
413
|
+
t && t.length > 0 && globalThis.observer?.remove?.(e);
|
|
414
|
+
const r = o ? e => {
|
|
414
415
|
const t = e;
|
|
415
416
|
return globalThis.queueMicrotask ? globalThis.queueMicrotask(() => o(t)) : Promise.resolve().then(() => o(t));
|
|
416
417
|
} : void 0;
|
|
417
|
-
|
|
418
|
+
r && globalThis.addEventListener(e, r), r && (globalThis.events[e] = r);
|
|
418
419
|
},
|
|
419
420
|
remove: e => {
|
|
420
421
|
const o = globalThis.events?.[e];
|
|
@@ -432,17 +433,19 @@ Object.defineProperty(memorio, "_sessionId", {
|
|
|
432
433
|
r;
|
|
433
434
|
}
|
|
434
435
|
}), globalThis.memorio._tracking = !1, globalThis.memorio._trackedPaths = new Set,
|
|
435
|
-
globalThis.memorio._locked = !1
|
|
436
|
+
globalThis.memorio._locked = !1, globalThis.memorio._lastAccessedPath = "", globalThis.memorio._stateVersion = 0,
|
|
437
|
+
globalThis.memorio._propertyAccessLog = [];
|
|
436
438
|
|
|
437
|
-
var
|
|
439
|
+
var L = (e, o, t = []) => new Proxy(e, {
|
|
438
440
|
get(e, r) {
|
|
439
441
|
if ("__path" === r) return t.length > 0 ? "state." + t.join(".") : "state";
|
|
440
442
|
if ("list" === r) return memorio.message('Some state could be hidden when you use "state.list". Use "state" to see the complete list '),
|
|
441
443
|
JSON.parse(JSON.stringify(globalThis.state));
|
|
442
|
-
if (
|
|
444
|
+
if ("string" == typeof r) {
|
|
443
445
|
const e = t.length > 0 ? "state." + t.concat(r).join(".") : "state." + r;
|
|
444
|
-
globalThis.memorio._trackedPaths?.add(e);
|
|
446
|
+
globalThis.memorio._lastAccessedPath = e, globalThis.memorio._tracking && globalThis.memorio._trackedPaths?.add(e);
|
|
445
447
|
}
|
|
448
|
+
if ("_lastPath" === r) return globalThis.memorio._lastAccessedPath;
|
|
446
449
|
if ("remove" === r) return o => (delete e[o], !0);
|
|
447
450
|
if ("removeAll" === r) return () => {
|
|
448
451
|
try {
|
|
@@ -458,7 +461,12 @@ var W = (e, o, t = []) => new Proxy(e, {
|
|
|
458
461
|
}
|
|
459
462
|
try {
|
|
460
463
|
const s = Reflect.get(e, r);
|
|
461
|
-
|
|
464
|
+
if (s && "object" == typeof s && [ "Array", "Object" ].includes(s.constructor.name)) return L(s, o, t.concat(r));
|
|
465
|
+
if ("string" == typeof r) {
|
|
466
|
+
const e = t.length > 0 ? "state." + t.concat(r).join(".") : "state." + r;
|
|
467
|
+
globalThis.memorio._lastAccessedPath = e, globalThis.memorio._tracking || globalThis.memorio._propertyAccessLog.push(e);
|
|
468
|
+
}
|
|
469
|
+
return s;
|
|
462
470
|
} catch (e) {
|
|
463
471
|
return void console.error("Error: ", e);
|
|
464
472
|
}
|
|
@@ -487,7 +495,8 @@ var W = (e, o, t = []) => new Proxy(e, {
|
|
|
487
495
|
}
|
|
488
496
|
});
|
|
489
497
|
} catch (e) {}
|
|
490
|
-
})("state." + n), Reflect.set(e, r, s),
|
|
498
|
+
})("state." + n), Reflect.set(e, r, s), globalThis.memorio._stateVersion = (globalThis.memorio._stateVersion || 0) + 1,
|
|
499
|
+
e[r] && "object" == typeof e[r]) {
|
|
491
500
|
const o = e[r];
|
|
492
501
|
if (o && "object" == typeof o) try {
|
|
493
502
|
Object.defineProperty(o, "__locked", {
|
|
@@ -543,7 +552,7 @@ var W = (e, o, t = []) => new Proxy(e, {
|
|
|
543
552
|
getOwnPropertyDescriptor: (e, o) => Reflect.getOwnPropertyDescriptor(e, o)
|
|
544
553
|
});
|
|
545
554
|
|
|
546
|
-
globalThis?.state || (globalThis.state =
|
|
555
|
+
globalThis?.state || (globalThis.state = L({}, () => {})), globalThis.state.lock = () => {
|
|
547
556
|
globalThis.memorio._locked = !0, memorio.message("State is now locked. All modifications are blocked.");
|
|
548
557
|
}, globalThis.state.unlock = () => {
|
|
549
558
|
globalThis.memorio._locked = !1, memorio.message("State is now unlocked. Modifications are allowed.");
|
|
@@ -555,28 +564,42 @@ globalThis?.state || (globalThis.state = W({}, () => {})), globalThis.state.lock
|
|
|
555
564
|
configurable: !0
|
|
556
565
|
});
|
|
557
566
|
|
|
567
|
+
var W = !1;
|
|
568
|
+
|
|
558
569
|
globalThis.observer = (e, o = null, t = !0) => {
|
|
559
|
-
console.warn('DEPRECATED: "observer" is deprecated and will be removed in future versions. Please use "useObserver" instead.')
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
570
|
+
W || (console.warn('DEPRECATED: "observer" is deprecated and will be removed in future versions. Please use "useObserver" instead.'),
|
|
571
|
+
W = !0);
|
|
572
|
+
const r = e => {
|
|
573
|
+
if ("string" == typeof e) return e;
|
|
574
|
+
if (e && "object" == typeof e && e.__path) return e.__path;
|
|
575
|
+
if ("object" == typeof e && globalThis._propertyAccessLog && globalThis._propertyAccessLog.length > 0) {
|
|
576
|
+
return globalThis._propertyAccessLog[globalThis._propertyAccessLog.length - 1].path || null;
|
|
577
|
+
}
|
|
578
|
+
return null;
|
|
579
|
+
}, s = r(e);
|
|
566
580
|
if (e || o) if (e || !o) {
|
|
581
|
+
if (s) {
|
|
582
|
+
const e = s.split(".");
|
|
583
|
+
if ("state" !== e[0] && "store" !== e[0]) return void console.error(`Observer Error: You need to declare 'state.' or 'store.'. The '${s}' string is incorrect!`);
|
|
584
|
+
}
|
|
567
585
|
if (e && !o) {
|
|
568
|
-
const o =
|
|
586
|
+
const o = r(e);
|
|
587
|
+
if (!o) return;
|
|
588
|
+
const t = {
|
|
569
589
|
detail: {
|
|
570
|
-
name: String(
|
|
590
|
+
name: String(o)
|
|
571
591
|
}
|
|
572
|
-
},
|
|
573
|
-
return
|
|
574
|
-
void memorio.message(`called: ${e}`);
|
|
592
|
+
}, s = globalThis.observer;
|
|
593
|
+
return s?.list?.[o] && globalThis.memorio.dispatch.remove(t), void memorio.message(`called: ${o}`);
|
|
575
594
|
}
|
|
576
595
|
if (e && o) {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
596
|
+
const s = r(e);
|
|
597
|
+
if (!s) return;
|
|
598
|
+
if ("string" != typeof e && (!e || "object" != typeof e)) return void console.error("Observer Error: name of state need to be a 'string' like 'state.test' or a direct state value");
|
|
599
|
+
const n = Array.isArray(o) ? o : [ o ], i = globalThis.observer;
|
|
600
|
+
return i?.list?.[s] && globalThis.memorio.dispatch.remove(s), void n.forEach(e => {
|
|
601
|
+
"function" == typeof e && globalThis.memorio.dispatch.listen(s, e, t);
|
|
602
|
+
});
|
|
580
603
|
}
|
|
581
604
|
} else console.error("Observer Error: You need to declare what state need to be monitored as string like 'state.test'."); else console.error("Observer Error: You need to setup observer correctly, Some parameters are missed!");
|
|
582
605
|
}, Object.defineProperties(globalThis.observer, {
|
|
@@ -595,6 +618,12 @@ globalThis.observer = (e, o = null, t = !0) => {
|
|
|
595
618
|
e?.remove?.(o);
|
|
596
619
|
}), !0;
|
|
597
620
|
}
|
|
621
|
+
},
|
|
622
|
+
has: {
|
|
623
|
+
value: e => {
|
|
624
|
+
const o = globalThis.observer;
|
|
625
|
+
return !!o?.list?.[e];
|
|
626
|
+
}
|
|
598
627
|
}
|
|
599
628
|
}), globalThis.useObserver || (globalThis.useObserver = null), Object.defineProperty(globalThis, "useObserver", {
|
|
600
629
|
value: null,
|
|
@@ -613,7 +642,7 @@ globalThis.observer = (e, o = null, t = !0) => {
|
|
|
613
642
|
const t = e(globalThis.state, o);
|
|
614
643
|
t && (r = t);
|
|
615
644
|
}
|
|
616
|
-
} else "object" == typeof o && null !== o
|
|
645
|
+
} else "object" == typeof o && null !== o && (r = o.__path || ("function" == typeof o.toString && "[object Object]" !== o.toString() ? o.toString() : ""));
|
|
617
646
|
if (r) {
|
|
618
647
|
r = r.replace(/^(\(\)\s*=>\s*)/, "").replace(/^globalThis\./, "").replace(/^state\./, "");
|
|
619
648
|
const o = r.startsWith("store.") || r.startsWith("state.") ? r : "state." + r;
|
|
@@ -654,7 +683,7 @@ function F() {
|
|
|
654
683
|
return e ? `${e}-` : "memorio_store_";
|
|
655
684
|
}
|
|
656
685
|
|
|
657
|
-
function
|
|
686
|
+
function V(e) {
|
|
658
687
|
return e && "string" == typeof e ? e.length > 512 ? (memorio.message("Key too long (max 512 characters)"),
|
|
659
688
|
"") : /^[a-zA-Z0-9_.-]+$/.test(e) ? F() + e : (memorio.message("Key contains invalid characters (only a-z, A-Z, 0-9, _, ., - allowed)"),
|
|
660
689
|
"") : "";
|
|
@@ -668,7 +697,7 @@ Object.defineProperty(globalThis, "store", {
|
|
|
668
697
|
get: {
|
|
669
698
|
value: e => {
|
|
670
699
|
if (!e) return;
|
|
671
|
-
const o =
|
|
700
|
+
const o = V(e);
|
|
672
701
|
try {
|
|
673
702
|
if (q) {
|
|
674
703
|
const e = R.getItem(o);
|
|
@@ -697,7 +726,7 @@ Object.defineProperty(globalThis, "store", {
|
|
|
697
726
|
set: {
|
|
698
727
|
value: (e, o) => {
|
|
699
728
|
if (!e) return;
|
|
700
|
-
const t =
|
|
729
|
+
const t = V(e);
|
|
701
730
|
try {
|
|
702
731
|
if (q) {
|
|
703
732
|
if (null == o) R.setItem(t, JSON.stringify(null)); else if ("object" == typeof o || "number" == typeof o || "boolean" == typeof o || "string" == typeof o) R.setItem(t, JSON.stringify(o)); else if ("function" == typeof o) return void memorio.message("Storing functions is not secure and is blocked for safety.");
|
|
@@ -714,7 +743,7 @@ Object.defineProperty(globalThis, "store", {
|
|
|
714
743
|
remove: {
|
|
715
744
|
value: e => {
|
|
716
745
|
if (!e) return;
|
|
717
|
-
const o =
|
|
746
|
+
const o = V(e);
|
|
718
747
|
try {
|
|
719
748
|
if (q) {
|
|
720
749
|
if (R.getItem(o)) return R.removeItem(o), !0;
|
|
@@ -795,23 +824,23 @@ Object.defineProperty(globalThis, "store", {
|
|
|
795
824
|
}
|
|
796
825
|
}), Object.freeze(store);
|
|
797
826
|
|
|
798
|
-
var H = x(),
|
|
827
|
+
var H = x(), Y = new Map;
|
|
799
828
|
|
|
800
|
-
function
|
|
829
|
+
function Z() {
|
|
801
830
|
const e = memorio._currentContext || "" || "default";
|
|
802
|
-
return
|
|
831
|
+
return Y.has(e) || Y.set(e, new Map), Y.get(e);
|
|
803
832
|
}
|
|
804
833
|
|
|
805
|
-
var
|
|
834
|
+
var G = null !== H;
|
|
806
835
|
|
|
807
|
-
function
|
|
836
|
+
function Q() {
|
|
808
837
|
const e = memorio._currentContext || "";
|
|
809
838
|
return e ? `${e}-` : "memorio_session_";
|
|
810
839
|
}
|
|
811
840
|
|
|
812
|
-
function
|
|
841
|
+
function X(e) {
|
|
813
842
|
return e && "string" == typeof e ? e.length > 512 ? (memorio.message("Key too long (max 512 characters)"),
|
|
814
|
-
"") : /^[a-zA-Z0-9_.-]+$/.test(e) ?
|
|
843
|
+
"") : /^[a-zA-Z0-9_.-]+$/.test(e) ? Q() + e : (memorio.message("Key contains invalid characters (only a-z, A-Z, 0-9, _, ., - allowed)"),
|
|
815
844
|
"") : "";
|
|
816
845
|
}
|
|
817
846
|
|
|
@@ -823,14 +852,14 @@ Object.defineProperty(globalThis, "session", {
|
|
|
823
852
|
get: {
|
|
824
853
|
value: e => {
|
|
825
854
|
if (!e) return;
|
|
826
|
-
const o =
|
|
855
|
+
const o = X(e);
|
|
827
856
|
try {
|
|
828
|
-
if (
|
|
857
|
+
if (G) {
|
|
829
858
|
const e = H.getItem(o);
|
|
830
859
|
return e ? JSON.parse(e) : e;
|
|
831
860
|
}
|
|
832
861
|
{
|
|
833
|
-
const e =
|
|
862
|
+
const e = Z().get(o);
|
|
834
863
|
return e ? JSON.parse(e) : e;
|
|
835
864
|
}
|
|
836
865
|
} catch (o) {
|
|
@@ -841,10 +870,10 @@ Object.defineProperty(globalThis, "session", {
|
|
|
841
870
|
set: {
|
|
842
871
|
value: (e, o) => {
|
|
843
872
|
if (!e) return;
|
|
844
|
-
const t =
|
|
873
|
+
const t = X(e);
|
|
845
874
|
try {
|
|
846
|
-
if (
|
|
847
|
-
const e =
|
|
875
|
+
if (G) null == o ? H.setItem(t, JSON.stringify(null)) : "object" == typeof o || "number" == typeof o || "boolean" == typeof o || "string" == typeof o ? H.setItem(t, JSON.stringify(o)) : "function" == typeof o && memorio.message("It's not secure to session functions."); else {
|
|
876
|
+
const e = Z();
|
|
848
877
|
null == o ? e.set(t, JSON.stringify(null)) : "object" == typeof o || "number" == typeof o || "boolean" == typeof o || "string" == typeof o ? e.set(t, JSON.stringify(o)) : "function" == typeof o && memorio.message("It's not secure to session functions.");
|
|
849
878
|
}
|
|
850
879
|
} catch (o) {
|
|
@@ -855,11 +884,11 @@ Object.defineProperty(globalThis, "session", {
|
|
|
855
884
|
remove: {
|
|
856
885
|
value: e => {
|
|
857
886
|
if (!e) return;
|
|
858
|
-
const o =
|
|
887
|
+
const o = X(e);
|
|
859
888
|
try {
|
|
860
|
-
if (
|
|
889
|
+
if (G) {
|
|
861
890
|
if (H.getItem(o)) return H.removeItem(o), !0;
|
|
862
|
-
} else if (
|
|
891
|
+
} else if (Z().has(o)) return Z().delete(o), !0;
|
|
863
892
|
} catch (o) {
|
|
864
893
|
memorio.message(`Error removing session item '${e}': ${o}`);
|
|
865
894
|
}
|
|
@@ -870,14 +899,14 @@ Object.defineProperty(globalThis, "session", {
|
|
|
870
899
|
},
|
|
871
900
|
removeAll: {
|
|
872
901
|
value: () => {
|
|
873
|
-
if (
|
|
902
|
+
if (G) {
|
|
874
903
|
const e = [];
|
|
875
904
|
for (let o = 0; o < H.length; o++) {
|
|
876
905
|
const t = H.key(o);
|
|
877
|
-
t?.startsWith(
|
|
906
|
+
t?.startsWith(Q()) && e.push(t);
|
|
878
907
|
}
|
|
879
908
|
e.forEach(e => H.removeItem(e));
|
|
880
|
-
} else
|
|
909
|
+
} else Z().clear();
|
|
881
910
|
return !0;
|
|
882
911
|
}
|
|
883
912
|
},
|
|
@@ -890,36 +919,36 @@ Object.defineProperty(globalThis, "session", {
|
|
|
890
919
|
size: {
|
|
891
920
|
value: () => {
|
|
892
921
|
let e = 0;
|
|
893
|
-
return
|
|
894
|
-
if (o.startsWith(
|
|
922
|
+
return G ? Object.keys(H).forEach(o => {
|
|
923
|
+
if (o.startsWith(Q())) {
|
|
895
924
|
const t = H.getItem(o);
|
|
896
925
|
t && (e += t.length);
|
|
897
926
|
}
|
|
898
|
-
}) :
|
|
927
|
+
}) : Z().forEach(o => {
|
|
899
928
|
e += o.length;
|
|
900
929
|
}), e;
|
|
901
930
|
}
|
|
902
931
|
},
|
|
903
932
|
isPersistent: {
|
|
904
|
-
get: () =>
|
|
933
|
+
get: () => G
|
|
905
934
|
},
|
|
906
935
|
list: {
|
|
907
936
|
value: () => {
|
|
908
937
|
const e = {};
|
|
909
938
|
try {
|
|
910
|
-
if (
|
|
939
|
+
if (G) for (let o = 0; o < H.length; o++) {
|
|
911
940
|
const t = H.key(o);
|
|
912
|
-
if (t?.startsWith(
|
|
913
|
-
const o = t.replace(
|
|
941
|
+
if (t?.startsWith(Q())) {
|
|
942
|
+
const o = t.replace(Q(), ""), r = H.getItem(t);
|
|
914
943
|
if (null !== r) try {
|
|
915
944
|
e[o] = JSON.parse(r);
|
|
916
945
|
} catch {
|
|
917
946
|
e[o] = r;
|
|
918
947
|
}
|
|
919
948
|
}
|
|
920
|
-
} else
|
|
921
|
-
if (t.startsWith(
|
|
922
|
-
const r = t.replace(
|
|
949
|
+
} else Z().forEach((o, t) => {
|
|
950
|
+
if (t.startsWith(Q())) {
|
|
951
|
+
const r = t.replace(Q(), "");
|
|
923
952
|
try {
|
|
924
953
|
e[r] = JSON.parse(o);
|
|
925
954
|
} catch {
|
|
@@ -935,22 +964,22 @@ Object.defineProperty(globalThis, "session", {
|
|
|
935
964
|
}
|
|
936
965
|
}), Object.freeze(session);
|
|
937
966
|
|
|
938
|
-
var
|
|
967
|
+
var ee = {};
|
|
939
968
|
|
|
940
969
|
Object.defineProperty(globalThis, "cache", {
|
|
941
970
|
value: new Proxy({}, {
|
|
942
|
-
get: (e, o) => "get" === o ? e =>
|
|
943
|
-
|
|
944
|
-
} : "remove" === o ? e => (delete
|
|
971
|
+
get: (e, o) => "get" === o ? e => ee[e] : "set" === o ? (e, o) => {
|
|
972
|
+
ee[e] = o;
|
|
973
|
+
} : "remove" === o ? e => (delete ee[e], !0) : "removeAll" === o || "clear" === o ? () => (Object.keys(ee).forEach(e => delete ee[e]),
|
|
945
974
|
!0) : "list" === o ? () => ({
|
|
946
|
-
...
|
|
947
|
-
}) :
|
|
948
|
-
set: (e, o, t) => (
|
|
949
|
-
deleteProperty: (e, o) => (delete
|
|
975
|
+
...ee
|
|
976
|
+
}) : ee[o],
|
|
977
|
+
set: (e, o, t) => (ee[o] = t, !0),
|
|
978
|
+
deleteProperty: (e, o) => (delete ee[o], !0)
|
|
950
979
|
}),
|
|
951
980
|
enumerable: !1,
|
|
952
981
|
configurable: !0
|
|
953
|
-
}), Object.freeze(cache),
|
|
982
|
+
}), Object.freeze(cache), A() ? (async () => {
|
|
954
983
|
Object.defineProperty(globalThis, "idb", {
|
|
955
984
|
value: {
|
|
956
985
|
db: {},
|
|
@@ -970,8 +999,8 @@ Object.defineProperty(globalThis, "cache", {
|
|
|
970
999
|
l)), Promise.resolve().then(() => (u(), m)), Promise.resolve().then(() => (d(),
|
|
971
1000
|
b)), Promise.resolve().then(() => (f(), g)), Promise.resolve().then(() => (p(),
|
|
972
1001
|
h)), Promise.resolve().then(() => (y(), v)), Promise.resolve().then(() => (O(),
|
|
973
|
-
T)), Promise.resolve().then(() => (
|
|
974
|
-
|
|
1002
|
+
T)), Promise.resolve().then(() => (j(), w)), Promise.resolve().then(() => (P(),
|
|
1003
|
+
S)), Promise.resolve().then(() => (E(), _)) ]), Object.preventExtensions(idb), Object.seal(idb),
|
|
975
1004
|
Object.freeze(idb);
|
|
976
1005
|
})() : (Object.defineProperty(globalThis, "idb", {
|
|
977
1006
|
value: {
|
|
@@ -986,9 +1015,9 @@ Object.defineProperty(globalThis, "cache", {
|
|
|
986
1015
|
enumerable: !1
|
|
987
1016
|
}), console.warn("Memorio IDB: IndexedDB is not available in this environment. Use store or session for data persistence."));
|
|
988
1017
|
|
|
989
|
-
var
|
|
1018
|
+
var oe = (globalThis.memorio || {}).globals;
|
|
990
1019
|
|
|
991
|
-
function
|
|
1020
|
+
function te() {
|
|
992
1021
|
if (!globalThis.store) return {};
|
|
993
1022
|
const e = {}, o = globalThis.store;
|
|
994
1023
|
if ("function" == typeof o.list) try {
|
|
@@ -1001,7 +1030,7 @@ function oe() {
|
|
|
1001
1030
|
return e;
|
|
1002
1031
|
}
|
|
1003
1032
|
|
|
1004
|
-
function
|
|
1033
|
+
function re() {
|
|
1005
1034
|
if (!globalThis.session) return {};
|
|
1006
1035
|
const e = {}, o = globalThis.session;
|
|
1007
1036
|
if ("function" == typeof o.list) try {
|
|
@@ -1014,7 +1043,7 @@ function te() {
|
|
|
1014
1043
|
return e;
|
|
1015
1044
|
}
|
|
1016
1045
|
|
|
1017
|
-
var
|
|
1046
|
+
var se, ne = e => {
|
|
1018
1047
|
globalThis[e] && "function" == typeof globalThis[e].clear ? globalThis[e].clear() : console.error(`Module ${e} not found or does not support clear()`);
|
|
1019
1048
|
};
|
|
1020
1049
|
|
|
@@ -1030,7 +1059,7 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "devt
|
|
|
1030
1059
|
o = "function" == typeof e ? e() : "object" == typeof e && null !== e ? e : globalThis.state,
|
|
1031
1060
|
console.table(o);
|
|
1032
1061
|
}
|
|
1033
|
-
if (globalThis.store && console.table(
|
|
1062
|
+
if (globalThis.store && console.table(te()), globalThis.session && console.table(re()),
|
|
1034
1063
|
globalThis.cache) {
|
|
1035
1064
|
const e = globalThis.cache.list;
|
|
1036
1065
|
let o;
|
|
@@ -1057,9 +1086,9 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "devt
|
|
|
1057
1086
|
lastUpdate: (new Date).toISOString()
|
|
1058
1087
|
};
|
|
1059
1088
|
},
|
|
1060
|
-
clear:
|
|
1089
|
+
clear: ne,
|
|
1061
1090
|
clearAll: () => {
|
|
1062
|
-
|
|
1091
|
+
ne("state"), ne("store"), ne("session"), ne("cache");
|
|
1063
1092
|
},
|
|
1064
1093
|
exportData: () => {
|
|
1065
1094
|
const e = {
|
|
@@ -1070,8 +1099,8 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "devt
|
|
|
1070
1099
|
return;
|
|
1071
1100
|
}
|
|
1072
1101
|
})(),
|
|
1073
|
-
store:
|
|
1074
|
-
session:
|
|
1102
|
+
store: te(),
|
|
1103
|
+
session: re(),
|
|
1075
1104
|
cache: (() => {
|
|
1076
1105
|
if (globalThis.cache) try {
|
|
1077
1106
|
return "function" == typeof globalThis.cache.list ? globalThis.cache.list() : globalThis.cache;
|
|
@@ -1102,19 +1131,19 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "devt
|
|
|
1102
1131
|
watch: (e, o) => {
|
|
1103
1132
|
if (!globalThis[e]) return void console.error(`Module ${e} not found`);
|
|
1104
1133
|
const t = globalThis[e], r = t[o];
|
|
1105
|
-
if (console.
|
|
1134
|
+
if (console.debug(`š Watching ${e}.${o} (initial: ${JSON.stringify(r)})`), "state" === e && globalThis.memorio?.dispatch) {
|
|
1106
1135
|
const r = t => {
|
|
1107
1136
|
const r = t.detail;
|
|
1108
|
-
r?.name?.includes(o) && console.
|
|
1137
|
+
r?.name?.includes(o) && console.debug(`š Change: ${e}.${o} =`, t.detail.value);
|
|
1109
1138
|
};
|
|
1110
1139
|
t.addEventListener?.("memorio-change", r);
|
|
1111
1140
|
}
|
|
1112
1141
|
},
|
|
1113
1142
|
help: () => {
|
|
1114
|
-
console.
|
|
1143
|
+
console.debug("\nš§ Memorio DevTools Help\n\nAvailable commands:\n memorio.devtools.inspect() - Inspect all state modules\n memorio.devtools.stats() - Show statistics\n memorio.devtools.clear('module') - Clear specific module\n memorio.devtools.clearAll() - Clear all modules\n memorio.devtools.exportData() - Export all data as JSON\n memorio.devtools.importData(json) - Import data from JSON\n memorio.devtools.watch(module, path) - Watch a path for changes\n memorio.devtools.help() - Show this help\n\nShortcuts:\n state - globalThis.state\n store - globalThis.store\n session - globalThis.session\n cache - globalThis.cache\n");
|
|
1115
1144
|
}
|
|
1116
1145
|
}
|
|
1117
|
-
}),
|
|
1146
|
+
}), se = "devtools", !1 === oe || oe && "object" == typeof oe && !1 === oe[se] || (Object.defineProperty(globalThis, "$state", {
|
|
1118
1147
|
get: () => globalThis.state,
|
|
1119
1148
|
configurable: !0
|
|
1120
1149
|
}), Object.defineProperty(globalThis, "$store", {
|
|
@@ -1128,12 +1157,12 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "devt
|
|
|
1128
1157
|
configurable: !0
|
|
1129
1158
|
}));
|
|
1130
1159
|
|
|
1131
|
-
var
|
|
1160
|
+
var ie = {
|
|
1132
1161
|
enabled: !0,
|
|
1133
1162
|
logToConsole: !0,
|
|
1134
1163
|
modules: [ "state", "store", "session", "cache", "idb" ],
|
|
1135
1164
|
maxEntries: 1e3
|
|
1136
|
-
},
|
|
1165
|
+
}, ae = [], le = e => ie.enabled && ie.modules.includes(e), ce = e => ({
|
|
1137
1166
|
state: "#4CAF50",
|
|
1138
1167
|
store: "#2196F3",
|
|
1139
1168
|
session: "#FF9800",
|
|
@@ -1146,20 +1175,20 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "logg
|
|
|
1146
1175
|
configurable: !0,
|
|
1147
1176
|
value: {
|
|
1148
1177
|
configure: e => {
|
|
1149
|
-
|
|
1150
|
-
...
|
|
1178
|
+
ie = {
|
|
1179
|
+
...ie,
|
|
1151
1180
|
...e
|
|
1152
1181
|
};
|
|
1153
1182
|
},
|
|
1154
1183
|
enable: () => {
|
|
1155
|
-
|
|
1184
|
+
ie.enabled = !0;
|
|
1156
1185
|
},
|
|
1157
1186
|
disable: () => {
|
|
1158
|
-
|
|
1187
|
+
ie.enabled = !1;
|
|
1159
1188
|
},
|
|
1160
|
-
isEnabled:
|
|
1189
|
+
isEnabled: le,
|
|
1161
1190
|
log: (e, o, t, r, s) => {
|
|
1162
|
-
if (!
|
|
1191
|
+
if (!le(e)) return;
|
|
1163
1192
|
const n = {
|
|
1164
1193
|
timestamp: (new Date).toISOString(),
|
|
1165
1194
|
module: e,
|
|
@@ -1168,20 +1197,20 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "logg
|
|
|
1168
1197
|
value: r,
|
|
1169
1198
|
previousValue: s
|
|
1170
1199
|
};
|
|
1171
|
-
if (
|
|
1172
|
-
const n = `[Memorio:${e.toUpperCase()}]`, i =
|
|
1200
|
+
if (ae.push(n), ae.length > ie.maxEntries && ae.shift(), ie.logToConsole && !0 === globalThis.memorio?.debug) {
|
|
1201
|
+
const n = `[Memorio:${e.toUpperCase()}]`, i = ce(e);
|
|
1173
1202
|
memorio.message(`%c${n}%c ${o} ${t},\n color: ${i}; font-weight: bold,\n color: inherit`),
|
|
1174
1203
|
void 0 !== r && memorio.message(` ā value:${r}`), void 0 !== s && memorio.message(` ā previous:${s}`);
|
|
1175
1204
|
}
|
|
1176
|
-
|
|
1205
|
+
ie.customHandler && ie.customHandler(n);
|
|
1177
1206
|
},
|
|
1178
|
-
getHistory: () => [ ...
|
|
1207
|
+
getHistory: () => [ ...ae ],
|
|
1179
1208
|
clearHistory: () => {
|
|
1180
|
-
|
|
1209
|
+
ae.length = 0;
|
|
1181
1210
|
},
|
|
1182
1211
|
getStats: () => {
|
|
1183
1212
|
const e = {
|
|
1184
|
-
total:
|
|
1213
|
+
total: ae.length,
|
|
1185
1214
|
state: 0,
|
|
1186
1215
|
store: 0,
|
|
1187
1216
|
session: 0,
|
|
@@ -1192,12 +1221,12 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "logg
|
|
|
1192
1221
|
delete: 0,
|
|
1193
1222
|
clear: 0
|
|
1194
1223
|
};
|
|
1195
|
-
for (const o of
|
|
1224
|
+
for (const o of ae) if (o) {
|
|
1196
1225
|
const t = o.module, r = o.action;
|
|
1197
1226
|
t && "number" == typeof e[t] && e[t]++, r && "number" == typeof e[r] && e[r]++;
|
|
1198
1227
|
}
|
|
1199
1228
|
return e;
|
|
1200
1229
|
},
|
|
1201
|
-
exportLogs: () => JSON.stringify(
|
|
1230
|
+
exportLogs: () => JSON.stringify(ae, null, 2)
|
|
1202
1231
|
}
|
|
1203
1232
|
});
|