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.cjs CHANGED
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  var e = Object.getOwnPropertyNames, t = (t, o) => function() {
4
2
  return t && (o = (0, t[e(t)[0]])(t = 0)), o;
5
3
  }, o = {}, r = t({
@@ -8,10 +6,12 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
8
6
  if (!idb.db.support()) return r(new Error("IndexedDB not supported"));
9
7
  const s = globalThis.indexedDB.open(e, t);
10
8
  s.onerror = () => {
11
- r(s.error);
9
+ console.debug(`IndexedDB error: ${s.error?.message}`), r(s.error);
12
10
  }, s.onsuccess = () => {
13
- idb.db.list(), o(s.result);
14
- }, 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
+ };
15
15
  });
16
16
  }
17
17
  }), s = {}, n = t({
@@ -22,7 +22,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
22
22
  const e = await indexedDB.databases();
23
23
  return globalThis.idbases = e || [], await idb.db.size(), globalThis.idbases;
24
24
  } catch (e) {
25
- return [];
25
+ return console.error("Error listing databases:", e), [];
26
26
  }
27
27
  }, idb.db.list();
28
28
  }
@@ -37,13 +37,16 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
37
37
  }), b = {}, u = t({
38
38
  "functions/idb/tools/db.delete.ts"() {
39
39
  idb.db.delete = e => new Promise((t, o) => {
40
+ console.debug(`Removing database ${e}...`);
40
41
  (() => {
41
42
  const r = indexedDB.deleteDatabase(e);
42
43
  r.onsuccess = () => {
43
- idb.db.list(), t();
44
+ console.debug(`${e} database removed successfully`), idb.db.list(), t();
44
45
  }, r.onerror = () => {
45
- o(r.error);
46
- }, 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
+ };
47
50
  })();
48
51
  });
49
52
  }
@@ -59,11 +62,13 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
59
62
  r += await idb.table.size(e, t);
60
63
  }
61
64
  t.size = r, e.close();
62
- } catch (e) {}
65
+ } catch (e) {
66
+ console.debug(`Could not calculate size for ${t.name}:`, e);
67
+ }
63
68
  }
64
69
  };
65
70
  }
66
- }), m = {}, h = t({
71
+ }), g = {}, h = t({
67
72
  "functions/idb/tools/db.version.ts"() {
68
73
  idb.db.version = e => {
69
74
  let t = 0;
@@ -74,11 +79,11 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
74
79
  return t;
75
80
  };
76
81
  }
77
- }), g = {}, p = t({
82
+ }), m = {}, p = t({
78
83
  "functions/idb/tools/db.support.ts"() {
79
84
  idb.db.support = () => {
80
85
  const e = "indexedDB" in globalThis;
81
- return e;
86
+ return e || console.debug("Your environment doesn't support IndexedDB"), e;
82
87
  };
83
88
  }
84
89
  }), v = {}, y = t({
@@ -86,30 +91,30 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
86
91
  idb.table.create = (e, t) => new Promise(async (o, r) => {
87
92
  try {
88
93
  const s = (Number(idb.db.version(e)) || 0) + 1, n = indexedDB.open(e, s);
89
- n.onupgradeneeded = e => {
90
- const o = e.target.result;
91
- if (!o.objectStoreNames.contains(t)) {
92
- 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, {
93
98
  keyPath: "id",
94
99
  autoIncrement: !0
95
100
  });
96
- e.createIndex("id", "id", {
101
+ o.createIndex("id", "id", {
97
102
  unique: !0
98
- }), e.createIndex("data", "data", {
103
+ }), o.createIndex("data", "data", {
99
104
  unique: !1
100
- });
105
+ }), console.debug(`Table ${t} created in ${e}`);
101
106
  }
102
107
  }, n.onsuccess = () => {
103
108
  n.result.close(), idb.db.list(), o();
104
109
  }, n.onerror = () => {
105
- r(n.error);
110
+ console.error(`Error creating table ${t}:`, n.error), r(n.error);
106
111
  };
107
112
  } catch (e) {
108
- r(e);
113
+ console.error("Critical error in table.create:", e), r(e);
109
114
  }
110
115
  });
111
116
  }
112
- }), T = {}, j = t({
117
+ }), T = {}, O = t({
113
118
  "functions/idb/tools/table.size.ts"() {
114
119
  idb.table.size = (e, t) => new Promise((o, r) => {
115
120
  if (!e) return r(new Error("Database instance is required"));
@@ -122,7 +127,9 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
122
127
  try {
123
128
  const e = t.value;
124
129
  s += JSON.stringify(e).length;
125
- } catch (e) {}
130
+ } catch (e) {
131
+ console.debug("Error stringifying IDB value tracking size:", e);
132
+ }
126
133
  n++, n % 200 == 0 && await new Promise(e => setTimeout(e, 0)), t.continue();
127
134
  } else o(s);
128
135
  }, i.onerror = () => {
@@ -130,7 +137,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
130
137
  };
131
138
  });
132
139
  }
133
- }), P = {}, O = t({
140
+ }), j = {}, w = t({
134
141
  "functions/idb/crud/data.delete.ts"() {
135
142
  idb.data.delete = (e, t, o) => new Promise((r, s) => {
136
143
  const n = indexedDB.open(e);
@@ -139,7 +146,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
139
146
  if (!e.objectStoreNames.contains(t)) return e.close(), s(new Error(`Table ${t} not found`));
140
147
  const i = e.transaction(t, "readwrite").objectStore(t).delete(o);
141
148
  i.onsuccess = () => {
142
- e.close(), r();
149
+ e.close(), console.debug(`Record ${o} deleted from ${t}`), r();
143
150
  }, i.onerror = () => {
144
151
  e.close(), s(i.error);
145
152
  };
@@ -151,14 +158,14 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
151
158
  if (!s.objectStoreNames.contains(t)) return s.close(), r(new Error(`Table ${t} not found`));
152
159
  const n = s.transaction(t, "readwrite").objectStore(t).clear();
153
160
  n.onsuccess = () => {
154
- s.close(), o();
161
+ s.close(), console.debug(`All data cleared from ${t}`), o();
155
162
  }, n.onerror = () => {
156
163
  s.close(), r(n.error);
157
164
  };
158
165
  }, s.onerror = () => r(s.error);
159
166
  });
160
167
  }
161
- }), w = {}, S = t({
168
+ }), S = {}, P = t({
162
169
  "functions/idb/crud/data.set.ts"() {
163
170
  idb.data.set = (e, t, o) => new Promise((r, s) => {
164
171
  const n = indexedDB.open(e);
@@ -167,16 +174,16 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
167
174
  if (!i.objectStoreNames.contains(t)) return i.close(), s(new Error(`Table ${t} does not exist in ${e}`));
168
175
  const l = i.transaction(t, "readwrite").objectStore(t).put(o);
169
176
  l.onsuccess = () => {
170
- i.close(), r(l.result);
177
+ i.close(), console.debug(`Data saved in ${e}.${t}`), r(l.result);
171
178
  }, l.onerror = e => {
172
- i.close(), s(l.error);
179
+ i.close(), console.debug(`Database insert error: ${l.error?.message}`), s(l.error);
173
180
  };
174
181
  }, n.onerror = () => {
175
182
  s(n.error);
176
183
  };
177
184
  });
178
185
  }
179
- }), _ = {}, k = t({
186
+ }), E = {}, k = t({
180
187
  "functions/idb/crud/data.get.ts"() {
181
188
  idb.data.get = (e, t, o) => new Promise((r, s) => {
182
189
  const n = indexedDB.open(e);
@@ -196,7 +203,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
196
203
  }
197
204
  });
198
205
 
199
- function x() {
206
+ function _() {
200
207
  const e = globalThis;
201
208
  if (void 0 !== e.crypto && e.crypto.randomUUID) return e.crypto.randomUUID();
202
209
  if (void 0 !== e.crypto && e.crypto.getRandomValues) {
@@ -206,7 +213,12 @@ function x() {
206
213
  return `session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
207
214
  }
208
215
 
209
- 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() {
210
222
  try {
211
223
  if ("undefined" != typeof sessionStorage) {
212
224
  const e = "__memorio_test__";
@@ -216,7 +228,7 @@ function E() {
216
228
  return null;
217
229
  }
218
230
 
219
- function N() {
231
+ function x() {
220
232
  try {
221
233
  if ("undefined" != typeof localStorage) {
222
234
  const e = "__memorio_test__";
@@ -230,21 +242,18 @@ function I() {
230
242
  return "undefined" != typeof indexedDB;
231
243
  }
232
244
 
233
- function D() {
234
- const e = function() {
235
- const e = globalThis;
236
- 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";
237
- }(), t = void 0 !== globalThis.isSecureContext ? globalThis.isSecureContext : "browser" === e;
245
+ function N() {
246
+ const e = $(), t = void 0 !== globalThis.isSecureContext ? globalThis.isSecureContext : "browser" === e;
238
247
  return {
239
248
  platform: e,
240
- hasSessionStorage: null !== E(),
241
- hasLocalStorage: null !== N(),
249
+ hasSessionStorage: null !== D(),
250
+ hasLocalStorage: null !== x(),
242
251
  hasIndexedDB: I(),
243
252
  hasDispatchEvent: "function" == typeof globalThis.dispatchEvent,
244
253
  hasNavigator: "undefined" != typeof navigator,
245
254
  hasProcess: "undefined" != typeof process,
246
255
  isSecureContext: t,
247
- sessionId: x()
256
+ sessionId: _()
248
257
  };
249
258
  }
250
259
 
@@ -253,7 +262,7 @@ var A = new Map;
253
262
  var z = new Map;
254
263
 
255
264
  function J(e) {
256
- const t = e || `context_${x()}`, o = {
265
+ const t = e || `context_${_()}`, o = {
257
266
  state: {},
258
267
  store: new Map,
259
268
  session: new Map,
@@ -312,13 +321,17 @@ Object.defineProperty(globalThis, "memorio", {
312
321
  }), Object.defineProperty(memorio, "version", {
313
322
  writable: !1,
314
323
  enumerable: !1,
315
- value: "3.0.1"
324
+ value: "4.0.0"
325
+ }), Object.defineProperty(memorio, "debug", {
326
+ writable: !0,
327
+ enumerable: !1,
328
+ value: !1
316
329
  });
317
330
 
318
331
  var B = [ "list", "state", "store", "idb", "observer", "useObserver", "remove", "removeAll", "_platform", "_capabilities", "_sessionId" ];
319
332
 
320
333
  !function() {
321
- const e = D(), t = globalThis;
334
+ const e = N(), t = globalThis;
322
335
  void 0 !== t.memorio && (t.memorio._platform = e.platform, t.memorio._capabilities = e),
323
336
  e.hasDispatchEvent || (t.dispatchEvent = function(e) {
324
337
  return !0;
@@ -341,22 +354,32 @@ var B = [ "list", "state", "store", "idb", "observer", "useObserver", "remove",
341
354
  return t && t.forEach(t => {
342
355
  try {
343
356
  t(e);
344
- } catch (e) {}
357
+ } catch (e) {
358
+ console.error("Event listener error:", e);
359
+ }
345
360
  }), !0;
346
361
  });
347
362
  }();
348
363
 
349
- var $ = D();
364
+ var C = N();
350
365
 
351
366
  Object.defineProperty(memorio, "_sessionId", {
352
367
  writable: !1,
353
368
  enumerable: !1,
354
- value: $.sessionId
369
+ value: C.sessionId
355
370
  }), memorio.createContext = J, memorio.listContexts = function() {
356
371
  return Array.from(z.keys());
357
372
  }, memorio.deleteContext = function(e) {
358
373
  return z.delete(e);
359
- }, 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) {
360
383
  return J(e);
361
384
  }, Object.defineProperty(memorio, "dispatch", {
362
385
  writable: !1,
@@ -386,10 +409,11 @@ Object.defineProperty(memorio, "_sessionId", {
386
409
  }), globalThis.memorio._tracking = !1, globalThis.memorio._trackedPaths = new Set,
387
410
  globalThis.memorio._locked = !1;
388
411
 
389
- var C = (e, t, o = []) => new Proxy(e, {
412
+ var M = (e, t, o = []) => new Proxy(e, {
390
413
  get(e, r) {
391
414
  if ("__path" === r) return o.length > 0 ? "state." + o.join(".") : "state";
392
- 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));
393
417
  if (globalThis.memorio._tracking && "string" == typeof r) {
394
418
  const e = o.length > 0 ? "state." + o.concat(r).join(".") : "state." + r;
395
419
  globalThis.memorio._trackedPaths?.add(e);
@@ -398,7 +422,9 @@ var C = (e, t, o = []) => new Proxy(e, {
398
422
  if ("removeAll" === r) return () => {
399
423
  try {
400
424
  for (const t in e) "function" == typeof e[t] || [ "list", "remove", "removeAll", "lock", "unlock" ].includes(t) || delete e[t];
401
- } catch (e) {}
425
+ } catch (e) {
426
+ console.error(e);
427
+ }
402
428
  };
403
429
  if (Object.isFrozen(e[r])) return e[r];
404
430
  if ("lock" === r || "unlock" === r) {
@@ -407,16 +433,19 @@ var C = (e, t, o = []) => new Proxy(e, {
407
433
  }
408
434
  try {
409
435
  const s = Reflect.get(e, r);
410
- 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;
411
437
  } catch (e) {
412
- return;
438
+ return void console.error("Error: ", e);
413
439
  }
414
440
  },
415
441
  set(e, r, s) {
416
- if (globalThis.memorio._locked) return !1;
417
- if (B.includes(r)) return !1;
418
- if (e[r] && "object" == typeof e[r] && Object.isFrozen(e[r])) return !1;
419
- 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;
420
449
  try {
421
450
  const n = globalThis.memorio.objPath?.(r, o) ?? r;
422
451
  if (t({
@@ -451,7 +480,7 @@ var C = (e, t, o = []) => new Proxy(e, {
451
480
  enumerable: !1,
452
481
  configurable: !1,
453
482
  value: !0
454
- });
483
+ }), console.info(`State '${r}' is now locked.`);
455
484
  }
456
485
  }), Object.defineProperty(t, "unlock", {
457
486
  writable: !1,
@@ -463,14 +492,14 @@ var C = (e, t, o = []) => new Proxy(e, {
463
492
  enumerable: !1,
464
493
  configurable: !1,
465
494
  value: !1
466
- });
495
+ }), console.info(`State '${r}' is now unlocked.`);
467
496
  }
468
497
  });
469
498
  } catch (e) {}
470
499
  }
471
500
  return !0;
472
501
  } catch (e) {
473
- return !1;
502
+ return console.error("Error in set trap:", e), !1;
474
503
  }
475
504
  },
476
505
  deleteProperty(e, r) {
@@ -482,17 +511,17 @@ var C = (e, t, o = []) => new Proxy(e, {
482
511
  target: e
483
512
  }), Reflect.deleteProperty(e, r);
484
513
  } catch (e) {
485
- return !1;
514
+ return console.error("Error in deleteProperty trap:", e), !1;
486
515
  }
487
516
  },
488
517
  ownKeys: e => Reflect.ownKeys(e),
489
518
  getOwnPropertyDescriptor: (e, t) => Reflect.getOwnPropertyDescriptor(e, t)
490
519
  });
491
520
 
492
- globalThis?.state || (globalThis.state = C({}, () => {})), globalThis.state.lock = () => {
493
- 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.");
494
523
  }, globalThis.state.unlock = () => {
495
- globalThis.memorio._locked = !1;
524
+ globalThis.memorio._locked = !1, console.info("State is now unlocked. Modifications are allowed.");
496
525
  }, Object.defineProperty(globalThis, "state", {
497
526
  enumerable: !1,
498
527
  configurable: !0
@@ -502,26 +531,29 @@ globalThis?.state || (globalThis.state = C({}, () => {})), globalThis.state.lock
502
531
  });
503
532
 
504
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.');
505
535
  try {
506
- 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;
507
538
  } catch (e) {
508
- return;
539
+ return void console.error(e);
509
540
  }
510
- if ((e || t) && (e || !t)) {
541
+ if (e || t) if (e || !t) {
511
542
  if (e && !t) {
512
543
  const t = {
513
544
  detail: {
514
545
  name: String(e)
515
546
  }
516
547
  }, o = globalThis.observer;
517
- 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);
518
550
  }
519
551
  if (e && t) {
520
- 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'");
521
553
  const r = globalThis.observer;
522
554
  return r?.list?.[e] && globalThis.memorio.dispatch.remove(e, t, o), void (r?.list?.[e] || globalThis.memorio.dispatch.listen(e, t, o));
523
555
  }
524
- }
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!");
525
557
  }, Object.defineProperties(globalThis.observer, {
526
558
  list: {
527
559
  get: () => globalThis.events
@@ -567,23 +599,28 @@ globalThis.observer = (e, t = null, o = !0) => {
567
599
  e();
568
600
  } catch (e) {}
569
601
  globalThis.memorio._tracking = !1, globalThis.memorio._trackedPaths?.forEach(t => {
570
- 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));
571
604
  });
572
605
  }
573
- }), 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
+ () => {
574
608
  o.forEach(e => {
575
- 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}"`));
576
611
  });
577
612
  };
578
613
  } catch (e) {
579
- return () => {};
614
+ return console.debug("useObserver Error:", e), () => {};
580
615
  }
581
616
  }, Object.freeze(globalThis.useObserver);
582
617
 
583
- 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_";
584
619
 
585
- function L(e) {
586
- 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
+ "") : "";
587
624
  }
588
625
 
589
626
  Object.defineProperty(globalThis, "store", {
@@ -594,41 +631,47 @@ Object.defineProperty(globalThis, "store", {
594
631
  get: {
595
632
  value: e => {
596
633
  if (!e) return;
597
- const t = L(e);
634
+ const t = F(e);
598
635
  try {
599
- if (M) {
600
- const e = R.getItem(t);
636
+ if (U) {
637
+ const e = W.getItem(t);
601
638
  return e ? JSON.parse(e) : e;
602
639
  }
603
640
  {
604
- const e = W.get(t);
641
+ const e = R.get(t);
605
642
  return e ? JSON.parse(e) : e;
606
643
  }
607
- } catch (e) {}
644
+ } catch (t) {
645
+ console.debug(`Error parsing store item '${e}':`, t);
646
+ }
608
647
  return null;
609
648
  }
610
649
  },
611
650
  set: {
612
651
  value: (e, t) => {
613
652
  if (!e) return;
614
- const o = L(e);
653
+ const o = F(e);
615
654
  try {
616
- if (M) {
617
- 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;
618
- } 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;
619
- } 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
+ }
620
661
  return null;
621
662
  }
622
663
  },
623
664
  remove: {
624
665
  value: e => {
625
666
  if (!e) return;
626
- const t = L(e);
667
+ const t = F(e);
627
668
  try {
628
- if (M) {
629
- if (R.getItem(t)) return R.removeItem(t), !0;
630
- } else if (W.has(t)) return W.delete(t), !0;
631
- } 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
+ }
632
675
  return !1;
633
676
  }
634
677
  },
@@ -637,14 +680,14 @@ Object.defineProperty(globalThis, "store", {
637
680
  },
638
681
  removeAll: {
639
682
  value: () => {
640
- if (M) {
683
+ if (U) {
641
684
  const e = [];
642
- for (let t = 0; t < R.length; t++) {
643
- const o = R.key(t);
644
- 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);
645
688
  }
646
- e.forEach(e => R.removeItem(e));
647
- } else W.clear();
689
+ e.forEach(e => W.removeItem(e));
690
+ } else R.clear();
648
691
  return !0;
649
692
  }
650
693
  },
@@ -657,25 +700,57 @@ Object.defineProperty(globalThis, "store", {
657
700
  size: {
658
701
  value: () => {
659
702
  let e = 0;
660
- return M ? Object.keys(R).forEach(t => {
661
- if (t.startsWith(q)) {
662
- const o = R.getItem(t);
703
+ return U ? Object.keys(W).forEach(t => {
704
+ if (t.startsWith(K)) {
705
+ const o = W.getItem(t);
663
706
  o && (e += o.length);
664
707
  }
665
- }) : W.forEach(t => {
708
+ }) : R.forEach(t => {
666
709
  e += t.length;
667
710
  }), e;
668
711
  }
669
712
  },
670
713
  isPersistent: {
671
- 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
+ }
672
745
  }
673
746
  }), Object.freeze(store);
674
747
 
675
- 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_";
676
749
 
677
- function Z(e) {
678
- 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
+ "") : "";
679
754
  }
680
755
 
681
756
  Object.defineProperty(globalThis, "session", {
@@ -686,37 +761,43 @@ Object.defineProperty(globalThis, "session", {
686
761
  get: {
687
762
  value: e => {
688
763
  if (!e) return;
689
- const t = Z(e);
764
+ const t = Y(e);
690
765
  try {
691
- if (F) {
692
- const e = U.getItem(t);
766
+ if (H) {
767
+ const e = q.getItem(t);
693
768
  return e ? JSON.parse(e) : e;
694
769
  }
695
770
  {
696
- const e = V.get(t);
771
+ const e = L.get(t);
697
772
  return e ? JSON.parse(e) : e;
698
773
  }
699
- } catch (e) {}
774
+ } catch (t) {
775
+ console.debug(`Error parsing session item '${e}':`, t);
776
+ }
700
777
  }
701
778
  },
702
779
  set: {
703
780
  value: (e, t) => {
704
781
  if (!e) return;
705
- const o = Z(e);
782
+ const o = Y(e);
706
783
  try {
707
- 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));
708
- } 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
+ }
709
788
  }
710
789
  },
711
790
  remove: {
712
791
  value: e => {
713
792
  if (!e) return;
714
- const t = Z(e);
793
+ const t = Y(e);
715
794
  try {
716
- if (F) {
717
- if (U.getItem(t)) return U.removeItem(t), !0;
718
- } else if (V.has(t)) return V.delete(t), !0;
719
- } 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
+ }
720
801
  }
721
802
  },
722
803
  delete: {
@@ -724,14 +805,14 @@ Object.defineProperty(globalThis, "session", {
724
805
  },
725
806
  removeAll: {
726
807
  value: () => {
727
- if (F) {
808
+ if (H) {
728
809
  const e = [];
729
- for (let t = 0; t < U.length; t++) {
730
- const o = U.key(t);
731
- 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);
732
813
  }
733
- e.forEach(e => U.removeItem(e));
734
- } else V.clear();
814
+ e.forEach(e => q.removeItem(e));
815
+ } else L.clear();
735
816
  return !0;
736
817
  }
737
818
  },
@@ -744,31 +825,63 @@ Object.defineProperty(globalThis, "session", {
744
825
  size: {
745
826
  value: () => {
746
827
  let e = 0;
747
- return F ? Object.keys(U).forEach(t => {
748
- if (t.startsWith(K)) {
749
- const o = U.getItem(t);
828
+ return H ? Object.keys(q).forEach(t => {
829
+ if (t.startsWith(V)) {
830
+ const o = q.getItem(t);
750
831
  o && (e += o.length);
751
832
  }
752
- }) : V.forEach(t => {
833
+ }) : L.forEach(t => {
753
834
  e += t.length;
754
835
  }), e;
755
836
  }
756
837
  },
757
838
  isPersistent: {
758
- 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
+ }
759
870
  }
760
871
  }), Object.freeze(session);
761
872
 
762
- var G = {};
873
+ var Z = {};
763
874
 
764
875
  Object.defineProperty(globalThis, "cache", {
765
876
  value: new Proxy({}, {
766
- get: (e, t) => "get" === t ? e => G[e] : "set" === t ? (e, t) => {
767
- G[e] = t;
768
- } : "remove" === t ? e => (delete G[e], !0) : "removeAll" === t || "clear" === t ? () => (Object.keys(G).forEach(e => delete G[e]),
769
- !0) : G[t],
770
- set: (e, t, o) => (G[t] = o, !0),
771
- 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)
772
885
  }),
773
886
  enumerable: !1,
774
887
  configurable: !0
@@ -790,10 +903,10 @@ Object.defineProperty(globalThis, "cache", {
790
903
  }), await Promise.all([ Promise.resolve().then(() => (r(), o)), Promise.resolve().then(() => (n(),
791
904
  s)), Promise.resolve().then(() => (l(), i)), Promise.resolve().then(() => (c(),
792
905
  a)), Promise.resolve().then(() => (u(), b)), Promise.resolve().then(() => (f(),
793
- d)), Promise.resolve().then(() => (h(), m)), Promise.resolve().then(() => (p(),
794
- g)), Promise.resolve().then(() => (y(), v)), Promise.resolve().then(() => (j(),
795
- T)), Promise.resolve().then(() => (O(), P)), Promise.resolve().then(() => (S(),
796
- 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),
797
910
  Object.freeze(idb);
798
911
  })() : (Object.defineProperty(globalThis, "idb", {
799
912
  value: {
@@ -811,4 +924,209 @@ Object.defineProperty(globalThis, "cache", {
811
924
  writable: !0,
812
925
  configurable: !0,
813
926
  enumerable: !1
814
- }));
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
+ });