memorio 3.0.2 → 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 = {}, g = 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
- }), h = {}, 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 E() {
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,12 +213,12 @@ function E() {
204
213
  return `session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
205
214
  }
206
215
 
207
- function x() {
216
+ function $() {
208
217
  const e = globalThis;
209
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";
210
219
  }
211
220
 
212
- function N() {
221
+ function D() {
213
222
  try {
214
223
  if ("undefined" != typeof sessionStorage) {
215
224
  const e = "__memorio_test__";
@@ -219,7 +228,7 @@ function N() {
219
228
  return null;
220
229
  }
221
230
 
222
- function I() {
231
+ function x() {
223
232
  try {
224
233
  if ("undefined" != typeof localStorage) {
225
234
  const e = "__memorio_test__";
@@ -229,37 +238,37 @@ function I() {
229
238
  return null;
230
239
  }
231
240
 
232
- function D() {
241
+ function I() {
233
242
  return "undefined" != typeof indexedDB;
234
243
  }
235
244
 
236
- function A() {
237
- const e = x(), 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 !== N(),
241
- hasLocalStorage: null !== I(),
242
- hasIndexedDB: D(),
249
+ hasSessionStorage: null !== D(),
250
+ hasLocalStorage: null !== x(),
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: E()
256
+ sessionId: _()
248
257
  };
249
258
  }
250
259
 
251
- var z = new Map;
260
+ var A = new Map;
252
261
 
253
- var J = new Map;
262
+ var z = new Map;
254
263
 
255
- function B(e) {
256
- const t = e || `context_${E()}`, o = {
264
+ function J(e) {
265
+ const t = e || `context_${_()}`, o = {
257
266
  state: {},
258
267
  store: new Map,
259
268
  session: new Map,
260
269
  cache: new Map
261
270
  };
262
- return J.set(t, o), {
271
+ return z.set(t, o), {
263
272
  id: t,
264
273
  state: o.state,
265
274
  store: {
@@ -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.2"
324
+ value: "4.0.0"
325
+ }), Object.defineProperty(memorio, "debug", {
326
+ writable: !0,
327
+ enumerable: !1,
328
+ value: !1
316
329
  });
317
330
 
318
- var C = [ "list", "state", "store", "idb", "observer", "useObserver", "remove", "removeAll", "_platform", "_capabilities", "_sessionId" ];
331
+ var B = [ "list", "state", "store", "idb", "observer", "useObserver", "remove", "removeAll", "_platform", "_capabilities", "_sessionId" ];
319
332
 
320
333
  !function() {
321
- const e = A(), 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;
@@ -329,43 +342,45 @@ var C = [ "list", "state", "store", "idb", "observer", "useObserver", "remove",
329
342
  this.type = e, this.detail = t;
330
343
  }
331
344
  })), "function" != typeof t.addEventListener && (t.addEventListener = function(e, t) {
332
- z.has(e) || z.set(e, []), z.get(e).push(t);
345
+ A.has(e) || A.set(e, []), A.get(e).push(t);
333
346
  }, t.removeEventListener = function(e, t) {
334
- const o = z.get(e);
347
+ const o = A.get(e);
335
348
  if (o) {
336
349
  const e = o.indexOf(t);
337
350
  e > -1 && o.splice(e, 1);
338
351
  }
339
352
  }, t.dispatchEvent = function(e) {
340
- const t = z.get(e.type);
353
+ const t = A.get(e.type);
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 $ = A();
364
+ var C = N();
350
365
 
351
366
  Object.defineProperty(memorio, "_sessionId", {
352
367
  writable: !1,
353
368
  enumerable: !1,
354
- value: $.sessionId
355
- }), memorio.createContext = B, memorio.listContexts = function() {
356
- return Array.from(J.keys());
369
+ value: C.sessionId
370
+ }), memorio.createContext = J, memorio.listContexts = function() {
371
+ return Array.from(z.keys());
357
372
  }, memorio.deleteContext = function(e) {
358
- return J.delete(e);
373
+ return z.delete(e);
359
374
  }, memorio.isBrowser = function() {
360
- return "browser" === x();
375
+ return "browser" === $();
361
376
  }, memorio.isNode = function() {
362
- return "node" === x();
377
+ return "node" === $();
363
378
  }, memorio.isDeno = function() {
364
- return "deno" === x();
379
+ return "deno" === $();
365
380
  }, memorio.isEdge = function() {
366
- return "edge" === x();
367
- }, memorio.getCapabilities = A, memorio.isolate = function(e) {
368
- return B(e);
381
+ return "edge" === $();
382
+ }, memorio.getCapabilities = N, memorio.isolate = function(e) {
383
+ return J(e);
369
384
  }, Object.defineProperty(memorio, "dispatch", {
370
385
  writable: !1,
371
386
  enumerable: !1,
@@ -394,10 +409,11 @@ Object.defineProperty(memorio, "_sessionId", {
394
409
  }), globalThis.memorio._tracking = !1, globalThis.memorio._trackedPaths = new Set,
395
410
  globalThis.memorio._locked = !1;
396
411
 
397
- var R = (e, t, o = []) => new Proxy(e, {
412
+ var M = (e, t, o = []) => new Proxy(e, {
398
413
  get(e, r) {
399
414
  if ("__path" === r) return o.length > 0 ? "state." + o.join(".") : "state";
400
- 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));
401
417
  if (globalThis.memorio._tracking && "string" == typeof r) {
402
418
  const e = o.length > 0 ? "state." + o.concat(r).join(".") : "state." + r;
403
419
  globalThis.memorio._trackedPaths?.add(e);
@@ -406,7 +422,9 @@ var R = (e, t, o = []) => new Proxy(e, {
406
422
  if ("removeAll" === r) return () => {
407
423
  try {
408
424
  for (const t in e) "function" == typeof e[t] || [ "list", "remove", "removeAll", "lock", "unlock" ].includes(t) || delete e[t];
409
- } catch (e) {}
425
+ } catch (e) {
426
+ console.error(e);
427
+ }
410
428
  };
411
429
  if (Object.isFrozen(e[r])) return e[r];
412
430
  if ("lock" === r || "unlock" === r) {
@@ -415,16 +433,19 @@ var R = (e, t, o = []) => new Proxy(e, {
415
433
  }
416
434
  try {
417
435
  const s = Reflect.get(e, r);
418
- return s && "object" == typeof s && [ "Array", "Object" ].includes(s.constructor.name) ? R(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;
419
437
  } catch (e) {
420
- return;
438
+ return void console.error("Error: ", e);
421
439
  }
422
440
  },
423
441
  set(e, r, s) {
424
- if (globalThis.memorio._locked) return !1;
425
- if (C.includes(r)) return !1;
426
- if (e[r] && "object" == typeof e[r] && Object.isFrozen(e[r])) return !1;
427
- 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;
428
449
  try {
429
450
  const n = globalThis.memorio.objPath?.(r, o) ?? r;
430
451
  if (t({
@@ -459,7 +480,7 @@ var R = (e, t, o = []) => new Proxy(e, {
459
480
  enumerable: !1,
460
481
  configurable: !1,
461
482
  value: !0
462
- });
483
+ }), console.info(`State '${r}' is now locked.`);
463
484
  }
464
485
  }), Object.defineProperty(t, "unlock", {
465
486
  writable: !1,
@@ -471,14 +492,14 @@ var R = (e, t, o = []) => new Proxy(e, {
471
492
  enumerable: !1,
472
493
  configurable: !1,
473
494
  value: !1
474
- });
495
+ }), console.info(`State '${r}' is now unlocked.`);
475
496
  }
476
497
  });
477
498
  } catch (e) {}
478
499
  }
479
500
  return !0;
480
501
  } catch (e) {
481
- return !1;
502
+ return console.error("Error in set trap:", e), !1;
482
503
  }
483
504
  },
484
505
  deleteProperty(e, r) {
@@ -490,17 +511,17 @@ var R = (e, t, o = []) => new Proxy(e, {
490
511
  target: e
491
512
  }), Reflect.deleteProperty(e, r);
492
513
  } catch (e) {
493
- return !1;
514
+ return console.error("Error in deleteProperty trap:", e), !1;
494
515
  }
495
516
  },
496
517
  ownKeys: e => Reflect.ownKeys(e),
497
518
  getOwnPropertyDescriptor: (e, t) => Reflect.getOwnPropertyDescriptor(e, t)
498
519
  });
499
520
 
500
- globalThis?.state || (globalThis.state = R({}, () => {})), globalThis.state.lock = () => {
501
- 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.");
502
523
  }, globalThis.state.unlock = () => {
503
- globalThis.memorio._locked = !1;
524
+ globalThis.memorio._locked = !1, console.info("State is now unlocked. Modifications are allowed.");
504
525
  }, Object.defineProperty(globalThis, "state", {
505
526
  enumerable: !1,
506
527
  configurable: !0
@@ -510,26 +531,29 @@ globalThis?.state || (globalThis.state = R({}, () => {})), globalThis.state.lock
510
531
  });
511
532
 
512
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.');
513
535
  try {
514
- 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;
515
538
  } catch (e) {
516
- return;
539
+ return void console.error(e);
517
540
  }
518
- if ((e || t) && (e || !t)) {
541
+ if (e || t) if (e || !t) {
519
542
  if (e && !t) {
520
543
  const t = {
521
544
  detail: {
522
545
  name: String(e)
523
546
  }
524
547
  }, o = globalThis.observer;
525
- 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);
526
550
  }
527
551
  if (e && t) {
528
- 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'");
529
553
  const r = globalThis.observer;
530
554
  return r?.list?.[e] && globalThis.memorio.dispatch.remove(e, t, o), void (r?.list?.[e] || globalThis.memorio.dispatch.listen(e, t, o));
531
555
  }
532
- }
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!");
533
557
  }, Object.defineProperties(globalThis.observer, {
534
558
  list: {
535
559
  get: () => globalThis.events
@@ -575,23 +599,28 @@ globalThis.observer = (e, t = null, o = !0) => {
575
599
  e();
576
600
  } catch (e) {}
577
601
  globalThis.memorio._tracking = !1, globalThis.memorio._trackedPaths?.forEach(t => {
578
- 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));
579
604
  });
580
605
  }
581
- }), 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
+ () => {
582
608
  o.forEach(e => {
583
- 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}"`));
584
611
  });
585
612
  };
586
613
  } catch (e) {
587
- return () => {};
614
+ return console.debug("useObserver Error:", e), () => {};
588
615
  }
589
616
  }, Object.freeze(globalThis.useObserver);
590
617
 
591
- var W = I(), M = new Map, q = null !== W, L = "memorio_store_";
618
+ var W = x(), R = new Map, U = null !== W, K = "memorio_store_";
592
619
 
593
- function U(e) {
594
- return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ? L + 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
+ "") : "";
595
624
  }
596
625
 
597
626
  Object.defineProperty(globalThis, "store", {
@@ -602,41 +631,47 @@ Object.defineProperty(globalThis, "store", {
602
631
  get: {
603
632
  value: e => {
604
633
  if (!e) return;
605
- const t = U(e);
634
+ const t = F(e);
606
635
  try {
607
- if (q) {
636
+ if (U) {
608
637
  const e = W.getItem(t);
609
638
  return e ? JSON.parse(e) : e;
610
639
  }
611
640
  {
612
- const e = M.get(t);
641
+ const e = R.get(t);
613
642
  return e ? JSON.parse(e) : e;
614
643
  }
615
- } catch (e) {}
644
+ } catch (t) {
645
+ console.debug(`Error parsing store item '${e}':`, t);
646
+ }
616
647
  return null;
617
648
  }
618
649
  },
619
650
  set: {
620
651
  value: (e, t) => {
621
652
  if (!e) return;
622
- const o = U(e);
653
+ const o = F(e);
623
654
  try {
624
- if (q) {
625
- if (null == t) W.setItem(o, JSON.stringify(null)); else if ("object" == typeof t || "number" == typeof t || "boolean" == typeof t || "string" == typeof t) W.setItem(o, JSON.stringify(t)); else if ("function" == typeof t) return;
626
- } else if (null == t) M.set(o, JSON.stringify(null)); else if ("object" == typeof t || "number" == typeof t || "boolean" == typeof t || "string" == typeof t) M.set(o, JSON.stringify(t)); else if ("function" == typeof t) return;
627
- } 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
+ }
628
661
  return null;
629
662
  }
630
663
  },
631
664
  remove: {
632
665
  value: e => {
633
666
  if (!e) return;
634
- const t = U(e);
667
+ const t = F(e);
635
668
  try {
636
- if (q) {
669
+ if (U) {
637
670
  if (W.getItem(t)) return W.removeItem(t), !0;
638
- } else if (M.has(t)) return M.delete(t), !0;
639
- } catch (e) {}
671
+ } else if (R.has(t)) return R.delete(t), !0;
672
+ } catch (t) {
673
+ console.debug(`Error removing store item '${e}':`, t);
674
+ }
640
675
  return !1;
641
676
  }
642
677
  },
@@ -645,14 +680,14 @@ Object.defineProperty(globalThis, "store", {
645
680
  },
646
681
  removeAll: {
647
682
  value: () => {
648
- if (q) {
683
+ if (U) {
649
684
  const e = [];
650
685
  for (let t = 0; t < W.length; t++) {
651
686
  const o = W.key(t);
652
- o?.startsWith(L) && e.push(o);
687
+ o?.startsWith(K) && e.push(o);
653
688
  }
654
689
  e.forEach(e => W.removeItem(e));
655
- } else M.clear();
690
+ } else R.clear();
656
691
  return !0;
657
692
  }
658
693
  },
@@ -665,25 +700,57 @@ Object.defineProperty(globalThis, "store", {
665
700
  size: {
666
701
  value: () => {
667
702
  let e = 0;
668
- return q ? Object.keys(W).forEach(t => {
669
- if (t.startsWith(L)) {
703
+ return U ? Object.keys(W).forEach(t => {
704
+ if (t.startsWith(K)) {
670
705
  const o = W.getItem(t);
671
706
  o && (e += o.length);
672
707
  }
673
- }) : M.forEach(t => {
708
+ }) : R.forEach(t => {
674
709
  e += t.length;
675
710
  }), e;
676
711
  }
677
712
  },
678
713
  isPersistent: {
679
- get: () => q
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
+ }
680
745
  }
681
746
  }), Object.freeze(store);
682
747
 
683
- var V = N(), F = new Map, K = null !== V, Z = "memorio_session_";
748
+ var q = D(), L = new Map, H = null !== q, V = "memorio_session_";
684
749
 
685
- function G(e) {
686
- return e && "string" == typeof e ? e.length > 512 ? "" : /^[a-zA-Z0-9_.-]+$/.test(e) ? Z + 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
+ "") : "";
687
754
  }
688
755
 
689
756
  Object.defineProperty(globalThis, "session", {
@@ -694,37 +761,43 @@ Object.defineProperty(globalThis, "session", {
694
761
  get: {
695
762
  value: e => {
696
763
  if (!e) return;
697
- const t = G(e);
764
+ const t = Y(e);
698
765
  try {
699
- if (K) {
700
- const e = V.getItem(t);
766
+ if (H) {
767
+ const e = q.getItem(t);
701
768
  return e ? JSON.parse(e) : e;
702
769
  }
703
770
  {
704
- const e = F.get(t);
771
+ const e = L.get(t);
705
772
  return e ? JSON.parse(e) : e;
706
773
  }
707
- } catch (e) {}
774
+ } catch (t) {
775
+ console.debug(`Error parsing session item '${e}':`, t);
776
+ }
708
777
  }
709
778
  },
710
779
  set: {
711
780
  value: (e, t) => {
712
781
  if (!e) return;
713
- const o = G(e);
782
+ const o = Y(e);
714
783
  try {
715
- K ? null == t ? V.setItem(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || V.setItem(o, JSON.stringify(t)) : null == t ? F.set(o, JSON.stringify(null)) : "object" != typeof t && "number" != typeof t && "boolean" != typeof t && "string" != typeof t || F.set(o, JSON.stringify(t));
716
- } 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
+ }
717
788
  }
718
789
  },
719
790
  remove: {
720
791
  value: e => {
721
792
  if (!e) return;
722
- const t = G(e);
793
+ const t = Y(e);
723
794
  try {
724
- if (K) {
725
- if (V.getItem(t)) return V.removeItem(t), !0;
726
- } else if (F.has(t)) return F.delete(t), !0;
727
- } 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
+ }
728
801
  }
729
802
  },
730
803
  delete: {
@@ -732,14 +805,14 @@ Object.defineProperty(globalThis, "session", {
732
805
  },
733
806
  removeAll: {
734
807
  value: () => {
735
- if (K) {
808
+ if (H) {
736
809
  const e = [];
737
- for (let t = 0; t < V.length; t++) {
738
- const o = V.key(t);
739
- o?.startsWith(Z) && 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);
740
813
  }
741
- e.forEach(e => V.removeItem(e));
742
- } else F.clear();
814
+ e.forEach(e => q.removeItem(e));
815
+ } else L.clear();
743
816
  return !0;
744
817
  }
745
818
  },
@@ -752,35 +825,67 @@ Object.defineProperty(globalThis, "session", {
752
825
  size: {
753
826
  value: () => {
754
827
  let e = 0;
755
- return K ? Object.keys(V).forEach(t => {
756
- if (t.startsWith(Z)) {
757
- const o = V.getItem(t);
828
+ return H ? Object.keys(q).forEach(t => {
829
+ if (t.startsWith(V)) {
830
+ const o = q.getItem(t);
758
831
  o && (e += o.length);
759
832
  }
760
- }) : F.forEach(t => {
833
+ }) : L.forEach(t => {
761
834
  e += t.length;
762
835
  }), e;
763
836
  }
764
837
  },
765
838
  isPersistent: {
766
- get: () => K
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
+ }
767
870
  }
768
871
  }), Object.freeze(session);
769
872
 
770
- var H = {};
873
+ var Z = {};
771
874
 
772
875
  Object.defineProperty(globalThis, "cache", {
773
876
  value: new Proxy({}, {
774
- get: (e, t) => "get" === t ? e => H[e] : "set" === t ? (e, t) => {
775
- H[e] = t;
776
- } : "remove" === t ? e => (delete H[e], !0) : "removeAll" === t || "clear" === t ? () => (Object.keys(H).forEach(e => delete H[e]),
777
- !0) : H[t],
778
- set: (e, t, o) => (H[t] = o, !0),
779
- deleteProperty: (e, t) => (delete H[t], !0)
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)
780
885
  }),
781
886
  enumerable: !1,
782
887
  configurable: !0
783
- }), Object.freeze(cache), D() ? (async () => {
888
+ }), Object.freeze(cache), I() ? (async () => {
784
889
  Object.defineProperty(globalThis, "idb", {
785
890
  value: {
786
891
  db: {},
@@ -798,10 +903,10 @@ Object.defineProperty(globalThis, "cache", {
798
903
  }), await Promise.all([ Promise.resolve().then(() => (r(), o)), Promise.resolve().then(() => (n(),
799
904
  s)), Promise.resolve().then(() => (l(), i)), Promise.resolve().then(() => (c(),
800
905
  a)), Promise.resolve().then(() => (u(), b)), Promise.resolve().then(() => (f(),
801
- d)), Promise.resolve().then(() => (g(), m)), Promise.resolve().then(() => (p(),
802
- h)), Promise.resolve().then(() => (y(), v)), Promise.resolve().then(() => (j(),
803
- T)), Promise.resolve().then(() => (O(), P)), Promise.resolve().then(() => (S(),
804
- 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),
805
910
  Object.freeze(idb);
806
911
  })() : (Object.defineProperty(globalThis, "idb", {
807
912
  value: {
@@ -819,4 +924,209 @@ Object.defineProperty(globalThis, "cache", {
819
924
  writable: !0,
820
925
  configurable: !0,
821
926
  enumerable: !1
822
- }));
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
+ });