memorio 4.1.6 → 4.2.1

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