memorio 4.1.5 → 4.2.0

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