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.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.0";
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.5"
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
+ }
639
+
640
+ var q = null !== R;
641
+
642
+ function F() {
643
+ const e = memorio._currentContext || "";
644
+ return e ? `${e}-` : "memorio_store_";
645
+ }
624
646
 
625
- function q(e) {
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,32 +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
  },
677
+ getMultiple: {
678
+ value: e => {
679
+ const o = {};
680
+ for (const t of e) try {
681
+ const e = store.get(t);
682
+ e && (o[t] = e);
683
+ } catch {}
684
+ return o;
685
+ }
686
+ },
655
687
  set: {
656
- value: (e, t) => {
688
+ value: (e, o) => {
657
689
  if (!e) return;
658
- const o = q(e);
690
+ const t = L(e);
659
691
  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}`);
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}`);
665
700
  }
666
701
  return null;
667
702
  }
@@ -669,13 +704,13 @@ Object.defineProperty(globalThis, "store", {
669
704
  remove: {
670
705
  value: e => {
671
706
  if (!e) return;
672
- const t = q(e);
707
+ const o = L(e);
673
708
  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}`);
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}`);
679
714
  }
680
715
  return !1;
681
716
  }
@@ -685,14 +720,14 @@ Object.defineProperty(globalThis, "store", {
685
720
  },
686
721
  removeAll: {
687
722
  value: () => {
688
- if (U) {
723
+ if (q) {
689
724
  const e = [];
690
- for (let t = 0; t < W.length; t++) {
691
- const o = W.key(t);
692
- 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);
693
728
  }
694
- e.forEach(e => W.removeItem(e));
695
- } else R.clear();
729
+ e.forEach(e => R.removeItem(e));
730
+ } else K().clear();
696
731
  return !0;
697
732
  }
698
733
  },
@@ -705,40 +740,40 @@ Object.defineProperty(globalThis, "store", {
705
740
  size: {
706
741
  value: () => {
707
742
  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);
743
+ return q ? Object.keys(R).forEach(o => {
744
+ if (o.startsWith(F())) {
745
+ const t = R.getItem(o);
746
+ t && (e += t.length);
712
747
  }
713
- }) : R.forEach(t => {
714
- e += t.length;
748
+ }) : K().forEach(o => {
749
+ e += o.length;
715
750
  }), e;
716
751
  }
717
752
  },
718
753
  isPersistent: {
719
- get: () => U
754
+ get: () => q
720
755
  },
721
756
  list: {
722
757
  value: () => {
723
758
  const e = {};
724
759
  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);
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);
729
764
  if (null !== r) try {
730
- e[t] = JSON.parse(r);
765
+ e[o] = JSON.parse(r);
731
766
  } catch {
732
- e[t] = r;
767
+ e[o] = r;
733
768
  }
734
769
  }
735
- } else R.forEach((t, o) => {
736
- if (o.startsWith(K)) {
737
- const r = o.replace(K, "");
770
+ } else K().forEach((o, t) => {
771
+ if (t.startsWith(F())) {
772
+ const r = t.replace(F(), "");
738
773
  try {
739
- e[r] = JSON.parse(t);
774
+ e[r] = JSON.parse(o);
740
775
  } catch {
741
- e[r] = t;
776
+ e[r] = o;
742
777
  }
743
778
  }
744
779
  });
@@ -750,11 +785,23 @@ Object.defineProperty(globalThis, "store", {
750
785
  }
751
786
  }), Object.freeze(store);
752
787
 
753
- var F = D(), L = new Map, H = null !== F, V = "memorio_session_";
788
+ var H = x(), V = new Map;
754
789
 
755
- 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) {
756
803
  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)"),
804
+ "") : /^[a-zA-Z0-9_.-]+$/.test(e) ? G() + e : (memorio.message("Key contains invalid characters (only a-z, A-Z, 0-9, _, ., - allowed)"),
758
805
  "") : "";
759
806
  }
760
807
 
@@ -766,42 +813,45 @@ Object.defineProperty(globalThis, "session", {
766
813
  get: {
767
814
  value: e => {
768
815
  if (!e) return;
769
- const t = Y(e);
816
+ const o = Q(e);
770
817
  try {
771
- if (H) {
772
- const e = F.getItem(t);
818
+ if (Z) {
819
+ const e = H.getItem(o);
773
820
  return e ? JSON.parse(e) : e;
774
821
  }
775
822
  {
776
- const e = L.get(t);
823
+ const e = Y().get(o);
777
824
  return e ? JSON.parse(e) : e;
778
825
  }
779
- } catch (t) {
780
- memorio.message(`Error parsing session item '${e}':${t}`);
826
+ } catch (o) {
827
+ memorio.message(`Error parsing session item '${e}':${o}`);
781
828
  }
782
829
  }
783
830
  },
784
831
  set: {
785
- value: (e, t) => {
832
+ value: (e, o) => {
786
833
  if (!e) return;
787
- const o = Y(e);
834
+ const t = Q(e);
788
835
  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}`);
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}`);
792
842
  }
793
843
  }
794
844
  },
795
845
  remove: {
796
846
  value: e => {
797
847
  if (!e) return;
798
- const t = Y(e);
848
+ const o = Q(e);
799
849
  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}`);
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}`);
805
855
  }
806
856
  }
807
857
  },
@@ -810,14 +860,14 @@ Object.defineProperty(globalThis, "session", {
810
860
  },
811
861
  removeAll: {
812
862
  value: () => {
813
- if (H) {
863
+ if (Z) {
814
864
  const e = [];
815
- for (let t = 0; t < F.length; t++) {
816
- const o = F.key(t);
817
- 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);
818
868
  }
819
- e.forEach(e => F.removeItem(e));
820
- } else L.clear();
869
+ e.forEach(e => H.removeItem(e));
870
+ } else Y().clear();
821
871
  return !0;
822
872
  }
823
873
  },
@@ -830,40 +880,40 @@ Object.defineProperty(globalThis, "session", {
830
880
  size: {
831
881
  value: () => {
832
882
  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);
883
+ return Z ? Object.keys(H).forEach(o => {
884
+ if (o.startsWith(G())) {
885
+ const t = H.getItem(o);
886
+ t && (e += t.length);
837
887
  }
838
- }) : L.forEach(t => {
839
- e += t.length;
888
+ }) : Y().forEach(o => {
889
+ e += o.length;
840
890
  }), e;
841
891
  }
842
892
  },
843
893
  isPersistent: {
844
- get: () => H
894
+ get: () => Z
845
895
  },
846
896
  list: {
847
897
  value: () => {
848
898
  const e = {};
849
899
  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);
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);
854
904
  if (null !== r) try {
855
- e[t] = JSON.parse(r);
905
+ e[o] = JSON.parse(r);
856
906
  } catch {
857
- e[t] = r;
907
+ e[o] = r;
858
908
  }
859
909
  }
860
- } else L.forEach((t, o) => {
861
- if (o.startsWith(V)) {
862
- const r = o.replace(V, "");
910
+ } else Y().forEach((o, t) => {
911
+ if (t.startsWith(G())) {
912
+ const r = t.replace(G(), "");
863
913
  try {
864
- e[r] = JSON.parse(t);
914
+ e[r] = JSON.parse(o);
865
915
  } catch {
866
- e[r] = t;
916
+ e[r] = o;
867
917
  }
868
918
  }
869
919
  });
@@ -875,18 +925,18 @@ Object.defineProperty(globalThis, "session", {
875
925
  }
876
926
  }), Object.freeze(session);
877
927
 
878
- var Z = {};
928
+ var X = {};
879
929
 
880
930
  Object.defineProperty(globalThis, "cache", {
881
931
  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)
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)
890
940
  }),
891
941
  enumerable: !1,
892
942
  configurable: !0
@@ -905,13 +955,13 @@ Object.defineProperty(globalThis, "cache", {
905
955
  writable: !0,
906
956
  configurable: !0,
907
957
  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(),
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(),
912
962
  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),
963
+ T)), Promise.resolve().then(() => (S(), w)), Promise.resolve().then(() => (P(),
964
+ j)), Promise.resolve().then(() => (E(), $)) ]), Object.preventExtensions(idb), Object.seal(idb),
915
965
  Object.freeze(idb);
916
966
  })() : (Object.defineProperty(globalThis, "idb", {
917
967
  value: {
@@ -931,35 +981,35 @@ Object.defineProperty(globalThis, "cache", {
931
981
  enumerable: !1
932
982
  }), console.warn("Memorio IDB: IndexedDB is not available in this environment. Use store or session for data persistence."));
933
983
 
934
- var G = (globalThis.memorio || {}).globals;
984
+ var ee = (globalThis.memorio || {}).globals;
935
985
 
936
- function Q() {
986
+ function oe() {
937
987
  if (!globalThis.store) return {};
938
- const e = {}, t = globalThis.store;
939
- if ("function" == typeof t.list) try {
940
- return t.list();
988
+ const e = {}, o = globalThis.store;
989
+ if ("function" == typeof o.list) try {
990
+ return o.list();
941
991
  } 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);
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);
945
995
  } catch {}
946
996
  return e;
947
997
  }
948
998
 
949
- function X() {
999
+ function te() {
950
1000
  if (!globalThis.session) return {};
951
- const e = {}, t = globalThis.session;
952
- if ("function" == typeof t.list) try {
953
- return t.list();
1001
+ const e = {}, o = globalThis.session;
1002
+ if ("function" == typeof o.list) try {
1003
+ return o.list();
954
1004
  } 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);
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);
958
1008
  } catch {}
959
1009
  return e;
960
1010
  }
961
1011
 
962
- var ee, te = e => {
1012
+ var re, se = e => {
963
1013
  globalThis[e] && "function" == typeof globalThis[e].clear ? globalThis[e].clear() : console.error(`Module ${e} not found or does not support clear()`);
964
1014
  };
965
1015
 
@@ -971,16 +1021,16 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "devt
971
1021
  if (!0 === globalThis.memorio?.debug) {
972
1022
  if (globalThis.state) {
973
1023
  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);
1024
+ let o;
1025
+ o = "function" == typeof e ? e() : "object" == typeof e && null !== e ? e : globalThis.state,
1026
+ console.table(o);
977
1027
  }
978
- if (globalThis.store && console.table(Q()), globalThis.session && console.table(X()),
1028
+ if (globalThis.store && console.table(oe()), globalThis.session && console.table(te()),
979
1029
  globalThis.cache) {
980
1030
  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);
1031
+ let o;
1032
+ o = "function" == typeof e ? e() : "object" == typeof e && null !== e ? e : globalThis.cache,
1033
+ console.table(o);
984
1034
  }
985
1035
  }
986
1036
  },
@@ -988,8 +1038,8 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "devt
988
1038
  const e = e => {
989
1039
  if (!e) return 0;
990
1040
  if ("function" == typeof e.list) try {
991
- const t = e.list();
992
- return Object.keys(t).length;
1041
+ const o = e.list();
1042
+ return Object.keys(o).length;
993
1043
  } catch {}
994
1044
  return Object.keys(e).length;
995
1045
  };
@@ -1002,9 +1052,9 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "devt
1002
1052
  lastUpdate: (new Date).toISOString()
1003
1053
  };
1004
1054
  },
1005
- clear: te,
1055
+ clear: se,
1006
1056
  clearAll: () => {
1007
- te("state"), te("store"), te("session"), te("cache");
1057
+ se("state"), se("store"), se("session"), se("cache");
1008
1058
  },
1009
1059
  exportData: () => {
1010
1060
  const e = {
@@ -1015,8 +1065,8 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "devt
1015
1065
  return;
1016
1066
  }
1017
1067
  })(),
1018
- store: Q(),
1019
- session: X(),
1068
+ store: oe(),
1069
+ session: te(),
1020
1070
  cache: (() => {
1021
1071
  if (globalThis.cache) try {
1022
1072
  return "function" == typeof globalThis.cache.list ? globalThis.cache.list() : globalThis.cache;
@@ -1030,25 +1080,36 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "devt
1030
1080
  },
1031
1081
  importData: e => {
1032
1082
  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);
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);
1042
1092
  });
1043
1093
  } catch (e) {
1044
1094
  console.error("%cāœ— Import failed:", "color: #F44336", e);
1045
1095
  }
1046
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
+ },
1047
1108
  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");
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");
1049
1110
  }
1050
1111
  }
1051
- }), 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", {
1052
1113
  get: () => globalThis.state,
1053
1114
  configurable: !0
1054
1115
  }), Object.defineProperty(globalThis, "$store", {
@@ -1062,12 +1123,12 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "devt
1062
1123
  configurable: !0
1063
1124
  }));
1064
1125
 
1065
- var oe = {
1126
+ var ne = {
1066
1127
  enabled: !0,
1067
1128
  logToConsole: !0,
1068
1129
  modules: [ "state", "store", "session", "cache", "idb" ],
1069
1130
  maxEntries: 1e3
1070
- }, re = [], se = e => oe.enabled && oe.modules.includes(e), ie = e => ({
1131
+ }, ie = [], ae = e => ne.enabled && ne.modules.includes(e), le = e => ({
1071
1132
  state: "#4CAF50",
1072
1133
  store: "#2196F3",
1073
1134
  session: "#FF9800",
@@ -1080,42 +1141,42 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "logg
1080
1141
  configurable: !0,
1081
1142
  value: {
1082
1143
  configure: e => {
1083
- oe = {
1084
- ...oe,
1144
+ ne = {
1145
+ ...ne,
1085
1146
  ...e
1086
1147
  };
1087
1148
  },
1088
1149
  enable: () => {
1089
- oe.enabled = !0;
1150
+ ne.enabled = !0;
1090
1151
  },
1091
1152
  disable: () => {
1092
- oe.enabled = !1;
1153
+ ne.enabled = !1;
1093
1154
  },
1094
- isEnabled: se,
1095
- log: (e, t, o, r, s) => {
1096
- if (!se(e)) return;
1097
- const i = {
1155
+ isEnabled: ae,
1156
+ log: (e, o, t, r, s) => {
1157
+ if (!ae(e)) return;
1158
+ const n = {
1098
1159
  timestamp: (new Date).toISOString(),
1099
1160
  module: e,
1100
- action: t,
1101
- path: o,
1161
+ action: o,
1162
+ path: t,
1102
1163
  value: r,
1103
1164
  previousValue: s
1104
1165
  };
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`),
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`),
1108
1169
  void 0 !== r && memorio.message(` → value:${r}`), void 0 !== s && memorio.message(` ← previous:${s}`);
1109
1170
  }
1110
- oe.customHandler && oe.customHandler(i);
1171
+ ne.customHandler && ne.customHandler(n);
1111
1172
  },
1112
- getHistory: () => [ ...re ],
1173
+ getHistory: () => [ ...ie ],
1113
1174
  clearHistory: () => {
1114
- re.length = 0;
1175
+ ie.length = 0;
1115
1176
  },
1116
1177
  getStats: () => {
1117
1178
  const e = {
1118
- total: re.length,
1179
+ total: ie.length,
1119
1180
  state: 0,
1120
1181
  store: 0,
1121
1182
  session: 0,
@@ -1126,12 +1187,12 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "logg
1126
1187
  delete: 0,
1127
1188
  clear: 0
1128
1189
  };
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]++;
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]++;
1132
1193
  }
1133
1194
  return e;
1134
1195
  },
1135
- exportLogs: () => JSON.stringify(re, null, 2)
1196
+ exportLogs: () => JSON.stringify(ie, null, 2)
1136
1197
  }
1137
1198
  });