memorio 3.0.1 → 4.0.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/index.js CHANGED
@@ -6,10 +6,12 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
6
6
  if (!idb.db.support()) return r(new Error("IndexedDB not supported"));
7
7
  const s = globalThis.indexedDB.open(e, t);
8
8
  s.onerror = () => {
9
- r(s.error);
9
+ console.debug(`IndexedDB error: ${s.error?.message}`), r(s.error);
10
10
  }, s.onsuccess = () => {
11
- idb.db.list(), o(s.result);
12
- }, s.onupgradeneeded = () => {};
11
+ console.debug(`Database ${e} connected successfully`), idb.db.list(), o(s.result);
12
+ }, s.onupgradeneeded = () => {
13
+ console.debug(`Database ${e} upgrade/creation initiated`);
14
+ };
13
15
  });
14
16
  }
15
17
  }), s = {}, n = t({
@@ -20,7 +22,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
20
22
  const e = await indexedDB.databases();
21
23
  return globalThis.idbases = e || [], await idb.db.size(), globalThis.idbases;
22
24
  } catch (e) {
23
- return [];
25
+ return console.error("Error listing databases:", e), [];
24
26
  }
25
27
  }, idb.db.list();
26
28
  }
@@ -35,13 +37,16 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
35
37
  }), b = {}, u = t({
36
38
  "functions/idb/tools/db.delete.ts"() {
37
39
  idb.db.delete = e => new Promise((t, o) => {
40
+ console.debug(`Removing database ${e}...`);
38
41
  (() => {
39
42
  const r = indexedDB.deleteDatabase(e);
40
43
  r.onsuccess = () => {
41
- idb.db.list(), t();
44
+ console.debug(`${e} database removed successfully`), idb.db.list(), t();
42
45
  }, r.onerror = () => {
43
- o(r.error);
44
- }, r.onblocked = () => {};
46
+ console.error(`Error removing ${e}:`, r.error), o(r.error);
47
+ }, r.onblocked = () => {
48
+ console.warn(`Deletion of ${e} is blocked. Please close other tabs.`);
49
+ };
45
50
  })();
46
51
  });
47
52
  }
@@ -57,11 +62,13 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
57
62
  r += await idb.table.size(e, t);
58
63
  }
59
64
  t.size = r, e.close();
60
- } catch (e) {}
65
+ } catch (e) {
66
+ console.debug(`Could not calculate size for ${t.name}:`, e);
67
+ }
61
68
  }
62
69
  };
63
70
  }
64
- }), m = {}, h = t({
71
+ }), g = {}, h = t({
65
72
  "functions/idb/tools/db.version.ts"() {
66
73
  idb.db.version = e => {
67
74
  let t = 0;
@@ -72,11 +79,11 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
72
79
  return t;
73
80
  };
74
81
  }
75
- }), g = {}, p = t({
82
+ }), m = {}, p = t({
76
83
  "functions/idb/tools/db.support.ts"() {
77
84
  idb.db.support = () => {
78
85
  const e = "indexedDB" in globalThis;
79
- return e;
86
+ return e || console.debug("Your environment doesn't support IndexedDB"), e;
80
87
  };
81
88
  }
82
89
  }), v = {}, y = t({
@@ -84,30 +91,30 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
84
91
  idb.table.create = (e, t) => new Promise(async (o, r) => {
85
92
  try {
86
93
  const s = (Number(idb.db.version(e)) || 0) + 1, n = indexedDB.open(e, s);
87
- n.onupgradeneeded = e => {
88
- const o = e.target.result;
89
- if (!o.objectStoreNames.contains(t)) {
90
- const e = o.createObjectStore(t, {
94
+ n.onupgradeneeded = o => {
95
+ const r = o.target.result;
96
+ if (!r.objectStoreNames.contains(t)) {
97
+ const o = r.createObjectStore(t, {
91
98
  keyPath: "id",
92
99
  autoIncrement: !0
93
100
  });
94
- e.createIndex("id", "id", {
101
+ o.createIndex("id", "id", {
95
102
  unique: !0
96
- }), e.createIndex("data", "data", {
103
+ }), o.createIndex("data", "data", {
97
104
  unique: !1
98
- });
105
+ }), console.debug(`Table ${t} created in ${e}`);
99
106
  }
100
107
  }, n.onsuccess = () => {
101
108
  n.result.close(), idb.db.list(), o();
102
109
  }, n.onerror = () => {
103
- r(n.error);
110
+ console.error(`Error creating table ${t}:`, n.error), r(n.error);
104
111
  };
105
112
  } catch (e) {
106
- r(e);
113
+ console.error("Critical error in table.create:", e), r(e);
107
114
  }
108
115
  });
109
116
  }
110
- }), T = {}, j = t({
117
+ }), T = {}, O = t({
111
118
  "functions/idb/tools/table.size.ts"() {
112
119
  idb.table.size = (e, t) => new Promise((o, r) => {
113
120
  if (!e) return r(new Error("Database instance is required"));
@@ -120,7 +127,9 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
120
127
  try {
121
128
  const e = t.value;
122
129
  s += JSON.stringify(e).length;
123
- } catch (e) {}
130
+ } catch (e) {
131
+ console.debug("Error stringifying IDB value tracking size:", e);
132
+ }
124
133
  n++, n % 200 == 0 && await new Promise(e => setTimeout(e, 0)), t.continue();
125
134
  } else o(s);
126
135
  }, i.onerror = () => {
@@ -128,7 +137,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
128
137
  };
129
138
  });
130
139
  }
131
- }), P = {}, O = t({
140
+ }), j = {}, w = t({
132
141
  "functions/idb/crud/data.delete.ts"() {
133
142
  idb.data.delete = (e, t, o) => new Promise((r, s) => {
134
143
  const n = indexedDB.open(e);
@@ -137,7 +146,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
137
146
  if (!e.objectStoreNames.contains(t)) return e.close(), s(new Error(`Table ${t} not found`));
138
147
  const i = e.transaction(t, "readwrite").objectStore(t).delete(o);
139
148
  i.onsuccess = () => {
140
- e.close(), r();
149
+ e.close(), console.debug(`Record ${o} deleted from ${t}`), r();
141
150
  }, i.onerror = () => {
142
151
  e.close(), s(i.error);
143
152
  };
@@ -149,14 +158,14 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
149
158
  if (!s.objectStoreNames.contains(t)) return s.close(), r(new Error(`Table ${t} not found`));
150
159
  const n = s.transaction(t, "readwrite").objectStore(t).clear();
151
160
  n.onsuccess = () => {
152
- s.close(), o();
161
+ s.close(), console.debug(`All data cleared from ${t}`), o();
153
162
  }, n.onerror = () => {
154
163
  s.close(), r(n.error);
155
164
  };
156
165
  }, s.onerror = () => r(s.error);
157
166
  });
158
167
  }
159
- }), w = {}, S = t({
168
+ }), S = {}, P = t({
160
169
  "functions/idb/crud/data.set.ts"() {
161
170
  idb.data.set = (e, t, o) => new Promise((r, s) => {
162
171
  const n = indexedDB.open(e);
@@ -165,16 +174,16 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
165
174
  if (!i.objectStoreNames.contains(t)) return i.close(), s(new Error(`Table ${t} does not exist in ${e}`));
166
175
  const l = i.transaction(t, "readwrite").objectStore(t).put(o);
167
176
  l.onsuccess = () => {
168
- i.close(), r(l.result);
177
+ i.close(), console.debug(`Data saved in ${e}.${t}`), r(l.result);
169
178
  }, l.onerror = e => {
170
- i.close(), s(l.error);
179
+ i.close(), console.debug(`Database insert error: ${l.error?.message}`), s(l.error);
171
180
  };
172
181
  }, n.onerror = () => {
173
182
  s(n.error);
174
183
  };
175
184
  });
176
185
  }
177
- }), _ = {}, k = t({
186
+ }), E = {}, k = t({
178
187
  "functions/idb/crud/data.get.ts"() {
179
188
  idb.data.get = (e, t, o) => new Promise((r, s) => {
180
189
  const n = indexedDB.open(e);
@@ -194,7 +203,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
194
203
  }
195
204
  });
196
205
 
197
- function x() {
206
+ function _() {
198
207
  const e = globalThis;
199
208
  if (void 0 !== e.crypto && e.crypto.randomUUID) return e.crypto.randomUUID();
200
209
  if (void 0 !== e.crypto && e.crypto.getRandomValues) {
@@ -204,7 +213,12 @@ function x() {
204
213
  return `session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
205
214
  }
206
215
 
207
- function E() {
216
+ function $() {
217
+ const e = globalThis;
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
+ }
220
+
221
+ function D() {
208
222
  try {
209
223
  if ("undefined" != typeof sessionStorage) {
210
224
  const e = "__memorio_test__";
@@ -214,7 +228,7 @@ function E() {
214
228
  return null;
215
229
  }
216
230
 
217
- function N() {
231
+ function x() {
218
232
  try {
219
233
  if ("undefined" != typeof localStorage) {
220
234
  const e = "__memorio_test__";
@@ -228,21 +242,18 @@ function I() {
228
242
  return "undefined" != typeof indexedDB;
229
243
  }
230
244
 
231
- function D() {
232
- const e = function() {
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;
245
+ function N() {
246
+ const e = $(), t = void 0 !== globalThis.isSecureContext ? globalThis.isSecureContext : "browser" === e;
236
247
  return {
237
248
  platform: e,
238
- hasSessionStorage: null !== E(),
239
- hasLocalStorage: null !== N(),
249
+ hasSessionStorage: null !== D(),
250
+ hasLocalStorage: null !== x(),
240
251
  hasIndexedDB: I(),
241
252
  hasDispatchEvent: "function" == typeof globalThis.dispatchEvent,
242
253
  hasNavigator: "undefined" != typeof navigator,
243
254
  hasProcess: "undefined" != typeof process,
244
255
  isSecureContext: t,
245
- sessionId: x()
256
+ sessionId: _()
246
257
  };
247
258
  }
248
259
 
@@ -251,7 +262,7 @@ var A = new Map;
251
262
  var z = new Map;
252
263
 
253
264
  function J(e) {
254
- const t = e || `context_${x()}`, o = {
265
+ const t = e || `context_${_()}`, o = {
255
266
  state: {},
256
267
  store: new Map,
257
268
  session: new Map,
@@ -310,13 +321,17 @@ Object.defineProperty(globalThis, "memorio", {
310
321
  }), Object.defineProperty(memorio, "version", {
311
322
  writable: !1,
312
323
  enumerable: !1,
313
- value: "3.0.1"
324
+ value: "4.0.0"
325
+ }), Object.defineProperty(memorio, "debug", {
326
+ writable: !0,
327
+ enumerable: !1,
328
+ value: !1
314
329
  });
315
330
 
316
331
  var B = [ "list", "state", "store", "idb", "observer", "useObserver", "remove", "removeAll", "_platform", "_capabilities", "_sessionId" ];
317
332
 
318
333
  !function() {
319
- const e = D(), t = globalThis;
334
+ const e = N(), t = globalThis;
320
335
  void 0 !== t.memorio && (t.memorio._platform = e.platform, t.memorio._capabilities = e),
321
336
  e.hasDispatchEvent || (t.dispatchEvent = function(e) {
322
337
  return !0;
@@ -339,22 +354,32 @@ var B = [ "list", "state", "store", "idb", "observer", "useObserver", "remove",
339
354
  return t && t.forEach(t => {
340
355
  try {
341
356
  t(e);
342
- } catch (e) {}
357
+ } catch (e) {
358
+ console.error("Event listener error:", e);
359
+ }
343
360
  }), !0;
344
361
  });
345
362
  }();
346
363
 
347
- var $ = D();
364
+ var C = N();
348
365
 
349
366
  Object.defineProperty(memorio, "_sessionId", {
350
367
  writable: !1,
351
368
  enumerable: !1,
352
- value: $.sessionId
369
+ value: C.sessionId
353
370
  }), memorio.createContext = J, memorio.listContexts = function() {
354
371
  return Array.from(z.keys());
355
372
  }, memorio.deleteContext = function(e) {
356
373
  return z.delete(e);
357
- }, memorio.isolate = function(e) {
374
+ }, memorio.isBrowser = function() {
375
+ return "browser" === $();
376
+ }, memorio.isNode = function() {
377
+ return "node" === $();
378
+ }, memorio.isDeno = function() {
379
+ return "deno" === $();
380
+ }, memorio.isEdge = function() {
381
+ return "edge" === $();
382
+ }, memorio.getCapabilities = N, memorio.isolate = function(e) {
358
383
  return J(e);
359
384
  }, Object.defineProperty(memorio, "dispatch", {
360
385
  writable: !1,
@@ -384,10 +409,11 @@ Object.defineProperty(memorio, "_sessionId", {
384
409
  }), globalThis.memorio._tracking = !1, globalThis.memorio._trackedPaths = new Set,
385
410
  globalThis.memorio._locked = !1;
386
411
 
387
- var C = (e, t, o = []) => new Proxy(e, {
412
+ var M = (e, t, o = []) => new Proxy(e, {
388
413
  get(e, r) {
389
414
  if ("__path" === r) return o.length > 0 ? "state." + o.join(".") : "state";
390
- if ("list" === r) return JSON.parse(JSON.stringify(globalThis.state));
415
+ if ("list" === r) return console.debug('Some state could be hidden when you use "state.list". Use "state" to see the complete list '),
416
+ JSON.parse(JSON.stringify(globalThis.state));
391
417
  if (globalThis.memorio._tracking && "string" == typeof r) {
392
418
  const e = o.length > 0 ? "state." + o.concat(r).join(".") : "state." + r;
393
419
  globalThis.memorio._trackedPaths?.add(e);
@@ -396,7 +422,9 @@ var C = (e, t, o = []) => new Proxy(e, {
396
422
  if ("removeAll" === r) return () => {
397
423
  try {
398
424
  for (const t in e) "function" == typeof e[t] || [ "list", "remove", "removeAll", "lock", "unlock" ].includes(t) || delete e[t];
399
- } catch (e) {}
425
+ } catch (e) {
426
+ console.error(e);
427
+ }
400
428
  };
401
429
  if (Object.isFrozen(e[r])) return e[r];
402
430
  if ("lock" === r || "unlock" === r) {
@@ -405,16 +433,19 @@ var C = (e, t, o = []) => new Proxy(e, {
405
433
  }
406
434
  try {
407
435
  const s = Reflect.get(e, r);
408
- return s && "object" == typeof s && [ "Array", "Object" ].includes(s.constructor.name) ? C(s, t, o.concat(r)) : s;
436
+ return s && "object" == typeof s && [ "Array", "Object" ].includes(s.constructor.name) ? M(s, t, o.concat(r)) : s;
409
437
  } catch (e) {
410
- return;
438
+ return void console.error("Error: ", e);
411
439
  }
412
440
  },
413
441
  set(e, r, s) {
414
- if (globalThis.memorio._locked) return !1;
415
- if (B.includes(r)) return !1;
416
- if (e[r] && "object" == typeof e[r] && Object.isFrozen(e[r])) return !1;
417
- if (e[r] && "object" == typeof e[r] && e[r].__locked) return !1;
442
+ if (globalThis.memorio._locked) return console.error("Error: state is locked. Use state.unlock() to enable modifications."),
443
+ !1;
444
+ if (B.includes(r)) return console.error("key " + r + " is protected"), !1;
445
+ if (e[r] && "object" == typeof e[r] && Object.isFrozen(e[r])) return console.error(`Error: state '${r}' is locked`),
446
+ !1;
447
+ if (e[r] && "object" == typeof e[r] && e[r].__locked) return console.error(`Error: state '${r}' is locked. Use state.${r}.unlock() to enable modifications.`),
448
+ !1;
418
449
  try {
419
450
  const n = globalThis.memorio.objPath?.(r, o) ?? r;
420
451
  if (t({
@@ -449,7 +480,7 @@ var C = (e, t, o = []) => new Proxy(e, {
449
480
  enumerable: !1,
450
481
  configurable: !1,
451
482
  value: !0
452
- });
483
+ }), console.info(`State '${r}' is now locked.`);
453
484
  }
454
485
  }), Object.defineProperty(t, "unlock", {
455
486
  writable: !1,
@@ -461,14 +492,14 @@ var C = (e, t, o = []) => new Proxy(e, {
461
492
  enumerable: !1,
462
493
  configurable: !1,
463
494
  value: !1
464
- });
495
+ }), console.info(`State '${r}' is now unlocked.`);
465
496
  }
466
497
  });
467
498
  } catch (e) {}
468
499
  }
469
500
  return !0;
470
501
  } catch (e) {
471
- return !1;
502
+ return console.error("Error in set trap:", e), !1;
472
503
  }
473
504
  },
474
505
  deleteProperty(e, r) {
@@ -480,17 +511,17 @@ var C = (e, t, o = []) => new Proxy(e, {
480
511
  target: e
481
512
  }), Reflect.deleteProperty(e, r);
482
513
  } catch (e) {
483
- return !1;
514
+ return console.error("Error in deleteProperty trap:", e), !1;
484
515
  }
485
516
  },
486
517
  ownKeys: e => Reflect.ownKeys(e),
487
518
  getOwnPropertyDescriptor: (e, t) => Reflect.getOwnPropertyDescriptor(e, t)
488
519
  });
489
520
 
490
- globalThis?.state || (globalThis.state = C({}, () => {})), globalThis.state.lock = () => {
491
- globalThis.memorio._locked = !0;
521
+ globalThis?.state || (globalThis.state = M({}, () => {})), globalThis.state.lock = () => {
522
+ globalThis.memorio._locked = !0, console.info("State is now locked. All modifications are blocked.");
492
523
  }, globalThis.state.unlock = () => {
493
- globalThis.memorio._locked = !1;
524
+ globalThis.memorio._locked = !1, console.info("State is now unlocked. Modifications are allowed.");
494
525
  }, Object.defineProperty(globalThis, "state", {
495
526
  enumerable: !1,
496
527
  configurable: !0
@@ -500,26 +531,29 @@ globalThis?.state || (globalThis.state = C({}, () => {})), globalThis.state.lock
500
531
  });
501
532
 
502
533
  globalThis.observer = (e, t = null, o = !0) => {
534
+ console.warn('DEPRECATED: "observer" is deprecated and will be removed in future versions. Please use "useObserver" instead.');
503
535
  try {
504
- if (!(e => "state" === e.split(".")[0])(e)) return;
536
+ if (!(e => "state" === e.split(".")[0] || (console.error(`Observer Error: You need to declare 'state.' or 'store.'. The '${e}' string is incorrect!`),
537
+ !1))(e)) return;
505
538
  } catch (e) {
506
- return;
539
+ return void console.error(e);
507
540
  }
508
- if ((e || t) && (e || !t)) {
541
+ if (e || t) if (e || !t) {
509
542
  if (e && !t) {
510
543
  const t = {
511
544
  detail: {
512
545
  name: String(e)
513
546
  }
514
547
  }, o = globalThis.observer;
515
- return o?.list?.[e] && globalThis.memorio.dispatch.remove(t), void (o?.list?.[e] || globalThis.memorio.dispatch.listen(t));
548
+ return o?.list?.[e] && globalThis.memorio.dispatch.remove(t), o?.list?.[e] || globalThis.memorio.dispatch.listen(t),
549
+ void console.debug("called: ", e);
516
550
  }
517
551
  if (e && t) {
518
- if ("string" != typeof e || "function" != typeof t) return;
552
+ if ("string" != typeof e || "function" != typeof t) return void console.error("Observer Error: name of state need to be a 'string' like 'state.test' and the callback need to be a 'function'");
519
553
  const r = globalThis.observer;
520
554
  return r?.list?.[e] && globalThis.memorio.dispatch.remove(e, t, o), void (r?.list?.[e] || globalThis.memorio.dispatch.listen(e, t, o));
521
555
  }
522
- }
556
+ } 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!");
523
557
  }, Object.defineProperties(globalThis.observer, {
524
558
  list: {
525
559
  get: () => globalThis.events
@@ -565,23 +599,28 @@ globalThis.observer = (e, t = null, o = !0) => {
565
599
  e();
566
600
  } catch (e) {}
567
601
  globalThis.memorio._tracking = !1, globalThis.memorio._trackedPaths?.forEach(t => {
568
- o.includes(t) || (globalThis.memorio.dispatch.listen(t, () => e()), o.push(t));
602
+ o.includes(t) || (console.info(`useObserver: [Auto-Discovery] -> "${t}"`), globalThis.memorio.dispatch.listen(t, () => e()),
603
+ o.push(t));
569
604
  });
570
605
  }
571
- }), o.length, () => {
606
+ }), o.length > 0 ? console.info(`useObserver: Monitoring ${o.length} paths.`) : console.warn("useObserver: No paths resolved for monitoring. Check your dependencies!"),
607
+ () => {
572
608
  o.forEach(e => {
573
- globalThis.memorio.dispatch && "function" == typeof globalThis.memorio.dispatch.remove && globalThis.memorio.dispatch.remove(e);
609
+ globalThis.memorio.dispatch && "function" == typeof globalThis.memorio.dispatch.remove && (globalThis.memorio.dispatch.remove(e),
610
+ console.debug(`useObserver: Stopped monitoring "${e}"`));
574
611
  });
575
612
  };
576
613
  } catch (e) {
577
- return () => {};
614
+ return console.debug("useObserver Error:", e), () => {};
578
615
  }
579
616
  }, Object.freeze(globalThis.useObserver);
580
617
 
581
- var R = N(), W = new Map, M = null !== R, q = "memorio_store_";
618
+ var W = x(), R = new Map, U = null !== W, K = "memorio_store_";
582
619
 
583
- function L(e) {
584
- return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ? q + e : "" : "";
620
+ function F(e) {
621
+ return e && "string" == typeof e ? e.length > 512 ? (console.debug("Key too long (max 512 characters)"),
622
+ "") : /^[a-zA-Z0-9_.-]+$/.test(e) ? K + e : (console.debug("Key contains invalid characters (only a-z, A-Z, 0-9, _, ., - allowed)"),
623
+ "") : "";
585
624
  }
586
625
 
587
626
  Object.defineProperty(globalThis, "store", {
@@ -592,41 +631,47 @@ Object.defineProperty(globalThis, "store", {
592
631
  get: {
593
632
  value: e => {
594
633
  if (!e) return;
595
- const t = L(e);
634
+ const t = F(e);
596
635
  try {
597
- if (M) {
598
- const e = R.getItem(t);
636
+ if (U) {
637
+ const e = W.getItem(t);
599
638
  return e ? JSON.parse(e) : e;
600
639
  }
601
640
  {
602
- const e = W.get(t);
641
+ const e = R.get(t);
603
642
  return e ? JSON.parse(e) : e;
604
643
  }
605
- } catch (e) {}
644
+ } catch (t) {
645
+ console.debug(`Error parsing store item '${e}':`, t);
646
+ }
606
647
  return null;
607
648
  }
608
649
  },
609
650
  set: {
610
651
  value: (e, t) => {
611
652
  if (!e) return;
612
- const o = L(e);
653
+ const o = F(e);
613
654
  try {
614
- if (M) {
615
- if (null == t) R.setItem(o, JSON.stringify(null)); else if ("object" == typeof t || "number" == typeof t || "boolean" == typeof t || "string" == typeof t) R.setItem(o, JSON.stringify(t)); else if ("function" == typeof t) return;
616
- } else if (null == t) W.set(o, JSON.stringify(null)); else if ("object" == typeof t || "number" == typeof t || "boolean" == typeof t || "string" == typeof t) W.set(o, JSON.stringify(t)); else if ("function" == typeof t) return;
617
- } catch (e) {}
655
+ if (U) {
656
+ 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 void console.debug("Storing functions is not secure and is blocked for safety.");
657
+ } else if (null == t) R.set(o, JSON.stringify(null)); else if ("object" == typeof t || "number" == typeof t || "boolean" == typeof t || "string" == typeof t) R.set(o, JSON.stringify(t)); else if ("function" == typeof t) return void console.debug("Storing functions is not secure and is blocked for safety.");
658
+ } catch (t) {
659
+ console.debug(`Error setting store item '${e}':`, t);
660
+ }
618
661
  return null;
619
662
  }
620
663
  },
621
664
  remove: {
622
665
  value: e => {
623
666
  if (!e) return;
624
- const t = L(e);
667
+ const t = F(e);
625
668
  try {
626
- if (M) {
627
- if (R.getItem(t)) return R.removeItem(t), !0;
628
- } else if (W.has(t)) return W.delete(t), !0;
629
- } catch (e) {}
669
+ if (U) {
670
+ if (W.getItem(t)) return W.removeItem(t), !0;
671
+ } else if (R.has(t)) return R.delete(t), !0;
672
+ } catch (t) {
673
+ console.debug(`Error removing store item '${e}':`, t);
674
+ }
630
675
  return !1;
631
676
  }
632
677
  },
@@ -635,14 +680,14 @@ Object.defineProperty(globalThis, "store", {
635
680
  },
636
681
  removeAll: {
637
682
  value: () => {
638
- if (M) {
683
+ if (U) {
639
684
  const e = [];
640
- for (let t = 0; t < R.length; t++) {
641
- const o = R.key(t);
642
- o?.startsWith(q) && e.push(o);
685
+ for (let t = 0; t < W.length; t++) {
686
+ const o = W.key(t);
687
+ o?.startsWith(K) && e.push(o);
643
688
  }
644
- e.forEach(e => R.removeItem(e));
645
- } else W.clear();
689
+ e.forEach(e => W.removeItem(e));
690
+ } else R.clear();
646
691
  return !0;
647
692
  }
648
693
  },
@@ -655,25 +700,57 @@ Object.defineProperty(globalThis, "store", {
655
700
  size: {
656
701
  value: () => {
657
702
  let e = 0;
658
- return M ? Object.keys(R).forEach(t => {
659
- if (t.startsWith(q)) {
660
- const o = R.getItem(t);
703
+ return U ? Object.keys(W).forEach(t => {
704
+ if (t.startsWith(K)) {
705
+ const o = W.getItem(t);
661
706
  o && (e += o.length);
662
707
  }
663
- }) : W.forEach(t => {
708
+ }) : R.forEach(t => {
664
709
  e += t.length;
665
710
  }), e;
666
711
  }
667
712
  },
668
713
  isPersistent: {
669
- get: () => M
714
+ get: () => U
715
+ },
716
+ list: {
717
+ value: () => {
718
+ const e = {};
719
+ try {
720
+ if (U) for (let t = 0; t < W.length; t++) {
721
+ const o = W.key(t);
722
+ if (o?.startsWith(K)) {
723
+ const t = o.replace(K, ""), r = W.getItem(o);
724
+ if (null !== r) try {
725
+ e[t] = JSON.parse(r);
726
+ } catch {
727
+ e[t] = r;
728
+ }
729
+ }
730
+ } else R.forEach((t, o) => {
731
+ if (o.startsWith(K)) {
732
+ const r = o.replace(K, "");
733
+ try {
734
+ e[r] = JSON.parse(t);
735
+ } catch {
736
+ e[r] = t;
737
+ }
738
+ }
739
+ });
740
+ } catch (e) {
741
+ console.debug("Error listing store items:", e);
742
+ }
743
+ return e;
744
+ }
670
745
  }
671
746
  }), Object.freeze(store);
672
747
 
673
- var U = E(), V = new Map, F = null !== U, K = "memorio_session_";
748
+ var q = D(), L = new Map, H = null !== q, V = "memorio_session_";
674
749
 
675
- function Z(e) {
676
- return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ? K + e : "" : "";
750
+ function Y(e) {
751
+ return e && "string" == typeof e ? e.length > 512 ? (console.debug("Key too long (max 512 characters)"),
752
+ "") : /^[a-zA-Z0-9_.-]+$/.test(e) ? V + e : (console.debug("Key contains invalid characters (only a-z, A-Z, 0-9, _, ., - allowed)"),
753
+ "") : "";
677
754
  }
678
755
 
679
756
  Object.defineProperty(globalThis, "session", {
@@ -684,37 +761,43 @@ Object.defineProperty(globalThis, "session", {
684
761
  get: {
685
762
  value: e => {
686
763
  if (!e) return;
687
- const t = Z(e);
764
+ const t = Y(e);
688
765
  try {
689
- if (F) {
690
- const e = U.getItem(t);
766
+ if (H) {
767
+ const e = q.getItem(t);
691
768
  return e ? JSON.parse(e) : e;
692
769
  }
693
770
  {
694
- const e = V.get(t);
771
+ const e = L.get(t);
695
772
  return e ? JSON.parse(e) : e;
696
773
  }
697
- } catch (e) {}
774
+ } catch (t) {
775
+ console.debug(`Error parsing session item '${e}':`, t);
776
+ }
698
777
  }
699
778
  },
700
779
  set: {
701
780
  value: (e, t) => {
702
781
  if (!e) return;
703
- const o = Z(e);
782
+ const o = Y(e);
704
783
  try {
705
- F ? null == t ? U.setItem(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || U.setItem(o, JSON.stringify(t)) : null == t ? V.set(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || V.set(o, JSON.stringify(t));
706
- } catch (e) {}
784
+ H ? null == t ? q.setItem(o, JSON.stringify(null)) : "object" == typeof t || "number" == typeof t || "boolean" == typeof t || "string" == typeof t ? q.setItem(o, JSON.stringify(t)) : "function" == typeof t && console.debug("It's not secure to session functions.") : null == t ? L.set(o, JSON.stringify(null)) : "object" == typeof t || "number" == typeof t || "boolean" == typeof t || "string" == typeof t ? L.set(o, JSON.stringify(t)) : "function" == typeof t && console.debug("It's not secure to session functions.");
785
+ } catch (t) {
786
+ console.debug(`Error setting session item '${e}':`, t);
787
+ }
707
788
  }
708
789
  },
709
790
  remove: {
710
791
  value: e => {
711
792
  if (!e) return;
712
- const t = Z(e);
793
+ const t = Y(e);
713
794
  try {
714
- if (F) {
715
- if (U.getItem(t)) return U.removeItem(t), !0;
716
- } else if (V.has(t)) return V.delete(t), !0;
717
- } catch (e) {}
795
+ if (H) {
796
+ if (q.getItem(t)) return q.removeItem(t), !0;
797
+ } else if (L.has(t)) return L.delete(t), !0;
798
+ } catch (t) {
799
+ console.debug(`Error removing session item '${e}':`, t);
800
+ }
718
801
  }
719
802
  },
720
803
  delete: {
@@ -722,14 +805,14 @@ Object.defineProperty(globalThis, "session", {
722
805
  },
723
806
  removeAll: {
724
807
  value: () => {
725
- if (F) {
808
+ if (H) {
726
809
  const e = [];
727
- for (let t = 0; t < U.length; t++) {
728
- const o = U.key(t);
729
- o?.startsWith(K) && e.push(o);
810
+ for (let t = 0; t < q.length; t++) {
811
+ const o = q.key(t);
812
+ o?.startsWith(V) && e.push(o);
730
813
  }
731
- e.forEach(e => U.removeItem(e));
732
- } else V.clear();
814
+ e.forEach(e => q.removeItem(e));
815
+ } else L.clear();
733
816
  return !0;
734
817
  }
735
818
  },
@@ -742,31 +825,63 @@ Object.defineProperty(globalThis, "session", {
742
825
  size: {
743
826
  value: () => {
744
827
  let e = 0;
745
- return F ? Object.keys(U).forEach(t => {
746
- if (t.startsWith(K)) {
747
- const o = U.getItem(t);
828
+ return H ? Object.keys(q).forEach(t => {
829
+ if (t.startsWith(V)) {
830
+ const o = q.getItem(t);
748
831
  o && (e += o.length);
749
832
  }
750
- }) : V.forEach(t => {
833
+ }) : L.forEach(t => {
751
834
  e += t.length;
752
835
  }), e;
753
836
  }
754
837
  },
755
838
  isPersistent: {
756
- get: () => F
839
+ get: () => H
840
+ },
841
+ list: {
842
+ value: () => {
843
+ const e = {};
844
+ try {
845
+ if (H) for (let t = 0; t < q.length; t++) {
846
+ const o = q.key(t);
847
+ if (o?.startsWith(V)) {
848
+ const t = o.replace(V, ""), r = q.getItem(o);
849
+ if (null !== r) try {
850
+ e[t] = JSON.parse(r);
851
+ } catch {
852
+ e[t] = r;
853
+ }
854
+ }
855
+ } else L.forEach((t, o) => {
856
+ if (o.startsWith(V)) {
857
+ const r = o.replace(V, "");
858
+ try {
859
+ e[r] = JSON.parse(t);
860
+ } catch {
861
+ e[r] = t;
862
+ }
863
+ }
864
+ });
865
+ } catch (e) {
866
+ console.debug("Error listing session items:", e);
867
+ }
868
+ return e;
869
+ }
757
870
  }
758
871
  }), Object.freeze(session);
759
872
 
760
- var G = {};
873
+ var Z = {};
761
874
 
762
875
  Object.defineProperty(globalThis, "cache", {
763
876
  value: new Proxy({}, {
764
- get: (e, t) => "get" === t ? e => G[e] : "set" === t ? (e, t) => {
765
- G[e] = t;
766
- } : "remove" === t ? e => (delete G[e], !0) : "removeAll" === t || "clear" === t ? () => (Object.keys(G).forEach(e => delete G[e]),
767
- !0) : G[t],
768
- set: (e, t, o) => (G[t] = o, !0),
769
- deleteProperty: (e, t) => (delete G[t], !0)
877
+ get: (e, t) => "get" === t ? e => Z[e] : "set" === t ? (e, t) => {
878
+ Z[e] = t;
879
+ } : "remove" === t ? e => (delete Z[e], !0) : "removeAll" === t || "clear" === t ? () => (Object.keys(Z).forEach(e => delete Z[e]),
880
+ !0) : "list" === t ? () => ({
881
+ ...Z
882
+ }) : Z[t],
883
+ set: (e, t, o) => (Z[t] = o, !0),
884
+ deleteProperty: (e, t) => (delete Z[t], !0)
770
885
  }),
771
886
  enumerable: !1,
772
887
  configurable: !0
@@ -788,10 +903,10 @@ Object.defineProperty(globalThis, "cache", {
788
903
  }), await Promise.all([ Promise.resolve().then(() => (r(), o)), Promise.resolve().then(() => (n(),
789
904
  s)), Promise.resolve().then(() => (l(), i)), Promise.resolve().then(() => (c(),
790
905
  a)), Promise.resolve().then(() => (u(), b)), Promise.resolve().then(() => (f(),
791
- d)), Promise.resolve().then(() => (h(), m)), Promise.resolve().then(() => (p(),
792
- g)), Promise.resolve().then(() => (y(), v)), Promise.resolve().then(() => (j(),
793
- T)), Promise.resolve().then(() => (O(), P)), Promise.resolve().then(() => (S(),
794
- w)), Promise.resolve().then(() => (k(), _)) ]), Object.preventExtensions(idb), Object.seal(idb),
906
+ d)), Promise.resolve().then(() => (h(), g)), Promise.resolve().then(() => (p(),
907
+ m)), Promise.resolve().then(() => (y(), v)), Promise.resolve().then(() => (O(),
908
+ T)), Promise.resolve().then(() => (w(), j)), Promise.resolve().then(() => (P(),
909
+ S)), Promise.resolve().then(() => (k(), E)) ]), Object.preventExtensions(idb), Object.seal(idb),
795
910
  Object.freeze(idb);
796
911
  })() : (Object.defineProperty(globalThis, "idb", {
797
912
  value: {
@@ -809,4 +924,209 @@ Object.defineProperty(globalThis, "cache", {
809
924
  writable: !0,
810
925
  configurable: !0,
811
926
  enumerable: !1
812
- }));
927
+ }), console.warn("Memorio IDB: IndexedDB is not available in this environment. Use store or session for data persistence."));
928
+
929
+ var G = (globalThis.memorio || {}).globals;
930
+
931
+ function Q() {
932
+ if (!globalThis.store) return {};
933
+ const e = {}, t = globalThis.store;
934
+ if ("function" == typeof t.list) try {
935
+ return t.list();
936
+ } catch {}
937
+ if ("function" == typeof t.get) for (const o of Object.keys(t)) if (![ "get", "set", "remove", "delete", "removeAll", "clearAll", "size", "isPersistent", "list" ].includes(o)) try {
938
+ const r = t.get(o);
939
+ null != r && (e[o] = r);
940
+ } catch {}
941
+ return e;
942
+ }
943
+
944
+ function X() {
945
+ if (!globalThis.session) return {};
946
+ const e = {}, t = globalThis.session;
947
+ if ("function" == typeof t.list) try {
948
+ return t.list();
949
+ } catch {}
950
+ if ("function" == typeof t.get) for (const o of Object.keys(t)) if (![ "get", "set", "remove", "delete", "removeAll", "clearAll", "size", "isPersistent", "list" ].includes(o)) try {
951
+ const r = t.get(o);
952
+ null != r && (e[o] = r);
953
+ } catch {}
954
+ return e;
955
+ }
956
+
957
+ var ee, te = e => {
958
+ globalThis[e] && "function" == typeof globalThis[e].clear ? globalThis[e].clear() : console.error(`Module ${e} not found or does not support clear()`);
959
+ };
960
+
961
+ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "devtools", {
962
+ enumerable: !1,
963
+ configurable: !0,
964
+ value: {
965
+ inspect: () => {
966
+ if (!0 === globalThis.memorio?.debug) {
967
+ if (globalThis.state) {
968
+ const e = globalThis.state.list;
969
+ let t;
970
+ t = "function" == typeof e ? e() : "object" == typeof e && null !== e ? e : globalThis.state,
971
+ console.table(t);
972
+ }
973
+ if (globalThis.store && console.table(Q()), globalThis.session && console.table(X()),
974
+ globalThis.cache) {
975
+ const e = globalThis.cache.list;
976
+ let t;
977
+ t = "function" == typeof e ? e() : "object" == typeof e && null !== e ? e : globalThis.cache,
978
+ console.table(t);
979
+ }
980
+ }
981
+ },
982
+ stats: () => {
983
+ const e = e => {
984
+ if (!e) return 0;
985
+ if ("function" == typeof e.list) try {
986
+ const t = e.list();
987
+ return Object.keys(t).length;
988
+ } catch {}
989
+ return Object.keys(e).length;
990
+ };
991
+ return {
992
+ stateKeys: e(globalThis.state),
993
+ storeKeys: e(globalThis.store),
994
+ sessionKeys: e(globalThis.session),
995
+ cacheKeys: e(globalThis.cache),
996
+ idbDatabases: 0,
997
+ lastUpdate: (new Date).toISOString()
998
+ };
999
+ },
1000
+ clear: te,
1001
+ clearAll: () => {
1002
+ te("state"), te("store"), te("session"), te("cache");
1003
+ },
1004
+ exportData: () => {
1005
+ const e = {
1006
+ state: (() => {
1007
+ if (globalThis.state) try {
1008
+ return "function" == typeof globalThis.state.list ? globalThis.state.list() : globalThis.state;
1009
+ } catch {
1010
+ return;
1011
+ }
1012
+ })(),
1013
+ store: Q(),
1014
+ session: X(),
1015
+ cache: (() => {
1016
+ if (globalThis.cache) try {
1017
+ return "function" == typeof globalThis.cache.list ? globalThis.cache.list() : globalThis.cache;
1018
+ } catch {
1019
+ return;
1020
+ }
1021
+ })(),
1022
+ exportedAt: (new Date).toISOString()
1023
+ };
1024
+ return JSON.stringify(e, null, 2);
1025
+ },
1026
+ importData: e => {
1027
+ try {
1028
+ const t = JSON.parse(e);
1029
+ t.state && Object.entries(t.state).forEach(([e, t]) => {
1030
+ globalThis.state && "list" !== e && "remove" !== e && "removeAll" !== e && (globalThis.state[e] = t);
1031
+ }), t.store && globalThis.store && "function" == typeof globalThis.store.set && Object.entries(t.store).forEach(([e, t]) => {
1032
+ globalThis.store.set(e, t);
1033
+ }), t.session && globalThis.session && "function" == typeof globalThis.session.set && Object.entries(t.session).forEach(([e, t]) => {
1034
+ globalThis.session.set(e, t);
1035
+ }), t.cache && globalThis.cache && Object.entries(t.cache).forEach(([e, t]) => {
1036
+ globalThis.cache && "get" !== e && "set" !== e && "remove" !== e && "clear" !== e && (globalThis.cache[e] = t);
1037
+ });
1038
+ } catch (e) {
1039
+ console.error("%cāœ— Import failed:", "color: #F44336", e);
1040
+ }
1041
+ },
1042
+ help: () => {
1043
+ console.log("\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.help() - Show this help\n\nShortcuts:\n state - globalThis.state\n store - globalThis.store\n session - globalThis.session\n cache - globalThis.cache\n");
1044
+ }
1045
+ }
1046
+ }), ee = "devtools", !1 === G || G && "object" == typeof G && !1 === G[ee] || (Object.defineProperty(globalThis, "$state", {
1047
+ get: () => globalThis.state,
1048
+ configurable: !0
1049
+ }), Object.defineProperty(globalThis, "$store", {
1050
+ get: () => globalThis.store,
1051
+ configurable: !0
1052
+ }), Object.defineProperty(globalThis, "$session", {
1053
+ get: () => globalThis.session,
1054
+ configurable: !0
1055
+ }), Object.defineProperty(globalThis, "$cache", {
1056
+ get: () => globalThis.cache,
1057
+ configurable: !0
1058
+ }));
1059
+
1060
+ var oe = {
1061
+ enabled: !0,
1062
+ logToConsole: !0,
1063
+ modules: [ "state", "store", "session", "cache", "idb" ],
1064
+ maxEntries: 1e3
1065
+ }, re = [], se = e => oe.enabled && oe.modules.includes(e), ne = e => ({
1066
+ state: "#4CAF50",
1067
+ store: "#2196F3",
1068
+ session: "#FF9800",
1069
+ cache: "#9C27B0",
1070
+ idb: "#F44336"
1071
+ }[e] || "#888888");
1072
+
1073
+ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "logger", {
1074
+ enumerable: !1,
1075
+ configurable: !0,
1076
+ value: {
1077
+ configure: e => {
1078
+ oe = {
1079
+ ...oe,
1080
+ ...e
1081
+ };
1082
+ },
1083
+ enable: () => {
1084
+ oe.enabled = !0;
1085
+ },
1086
+ disable: () => {
1087
+ oe.enabled = !1;
1088
+ },
1089
+ isEnabled: se,
1090
+ log: (e, t, o, r, s) => {
1091
+ if (!se(e)) return;
1092
+ const n = {
1093
+ timestamp: (new Date).toISOString(),
1094
+ module: e,
1095
+ action: t,
1096
+ path: o,
1097
+ value: r,
1098
+ previousValue: s
1099
+ };
1100
+ if (re.push(n), re.length > oe.maxEntries && re.shift(), oe.logToConsole && !0 === globalThis.memorio?.debug) {
1101
+ const n = `[Memorio:${e.toUpperCase()}]`, i = ne(e);
1102
+ console.debug(`%c${n}%c ${t} ${o}`, `color: ${i}; font-weight: bold`, "color: inherit"),
1103
+ void 0 !== r && console.debug(" → value:", r), void 0 !== s && console.debug(" ← previous:", s);
1104
+ }
1105
+ oe.customHandler && oe.customHandler(n);
1106
+ },
1107
+ getHistory: () => [ ...re ],
1108
+ clearHistory: () => {
1109
+ re.length = 0;
1110
+ },
1111
+ getStats: () => {
1112
+ const e = {
1113
+ total: re.length,
1114
+ state: 0,
1115
+ store: 0,
1116
+ session: 0,
1117
+ cache: 0,
1118
+ idb: 0,
1119
+ set: 0,
1120
+ get: 0,
1121
+ delete: 0,
1122
+ clear: 0
1123
+ };
1124
+ for (const t of re) if (t) {
1125
+ const o = t.module, r = t.action;
1126
+ o && "number" == typeof e[o] && e[o]++, r && "number" == typeof e[r] && e[r]++;
1127
+ }
1128
+ return e;
1129
+ },
1130
+ exportLogs: () => JSON.stringify(re, null, 2)
1131
+ }
1132
+ });