memorio 4.1.6 → 4.2.1

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