memorio 4.0.0 ā 4.1.5
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 +140 -135
- package/index.js +140 -135
- package/llms.txt +405 -0
- package/package.json +12 -3
- package/types/memorio.d.ts +1 -0
- package/types/observer.d.ts +1 -1
package/index.js
CHANGED
|
@@ -6,15 +6,15 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
6
6
|
if (!idb.db.support()) return r(new Error("IndexedDB not supported"));
|
|
7
7
|
const s = globalThis.indexedDB.open(e, t);
|
|
8
8
|
s.onerror = () => {
|
|
9
|
-
|
|
9
|
+
memorio.message(`IndexedDB error: ${s.error?.message}`), r(s.error);
|
|
10
10
|
}, s.onsuccess = () => {
|
|
11
|
-
|
|
11
|
+
memorio.message(`Database ${e} connected successfully`), o(s.result);
|
|
12
12
|
}, s.onupgradeneeded = () => {
|
|
13
|
-
|
|
13
|
+
memorio.message(`Database ${e} upgrade/creation initiated`);
|
|
14
14
|
};
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
-
}), s = {},
|
|
17
|
+
}), s = {}, i = t({
|
|
18
18
|
"functions/idb/tools/db.list.ts"() {
|
|
19
19
|
idb.db.list = async () => {
|
|
20
20
|
if (!("indexedDB" in globalThis) || !indexedDB.databases) return [];
|
|
@@ -24,24 +24,24 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
24
24
|
} catch (e) {
|
|
25
25
|
return console.error("Error listing databases:", e), [];
|
|
26
26
|
}
|
|
27
|
-
}
|
|
27
|
+
};
|
|
28
28
|
}
|
|
29
|
-
}),
|
|
29
|
+
}), n = {}, a = t({
|
|
30
30
|
"functions/idb/tools/db.exist.ts"() {
|
|
31
31
|
idb.db.exist = e => idbases?.some(t => t.name === e);
|
|
32
32
|
}
|
|
33
|
-
}),
|
|
33
|
+
}), l = {}, c = t({
|
|
34
34
|
"functions/idb/tools/db.quota.ts"() {
|
|
35
35
|
idb.db.quota = () => navigator.storage.estimate();
|
|
36
36
|
}
|
|
37
|
-
}),
|
|
37
|
+
}), m = {}, b = t({
|
|
38
38
|
"functions/idb/tools/db.delete.ts"() {
|
|
39
39
|
idb.db.delete = e => new Promise((t, o) => {
|
|
40
|
-
|
|
40
|
+
memorio.message(`Removing database ${e}...`);
|
|
41
41
|
(() => {
|
|
42
42
|
const r = indexedDB.deleteDatabase(e);
|
|
43
43
|
r.onsuccess = () => {
|
|
44
|
-
|
|
44
|
+
memorio.message(`${e} database removed successfully`), idb.db.list(), t();
|
|
45
45
|
}, r.onerror = () => {
|
|
46
46
|
console.error(`Error removing ${e}:`, r.error), o(r.error);
|
|
47
47
|
}, r.onblocked = () => {
|
|
@@ -50,7 +50,7 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
50
50
|
})();
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
}),
|
|
53
|
+
}), u = {}, d = t({
|
|
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++) {
|
|
@@ -63,12 +63,12 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
63
63
|
}
|
|
64
64
|
t.size = r, e.close();
|
|
65
65
|
} catch (e) {
|
|
66
|
-
|
|
66
|
+
memorio.message(`Could not calculate size for ${t.name}:${e}`);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
}), g = {},
|
|
71
|
+
}), g = {}, f = t({
|
|
72
72
|
"functions/idb/tools/db.version.ts"() {
|
|
73
73
|
idb.db.version = e => {
|
|
74
74
|
let t = 0;
|
|
@@ -79,19 +79,19 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
79
79
|
return t;
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
}),
|
|
82
|
+
}), h = {}, p = t({
|
|
83
83
|
"functions/idb/tools/db.support.ts"() {
|
|
84
84
|
idb.db.support = () => {
|
|
85
85
|
const e = "indexedDB" in globalThis;
|
|
86
|
-
return e ||
|
|
86
|
+
return e || memorio.message("Your environment doesn't support IndexedDB"), e;
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
}), v = {}, y = t({
|
|
90
90
|
"functions/idb/tools/table.create.ts"() {
|
|
91
91
|
idb.table.create = (e, t) => new Promise(async (o, r) => {
|
|
92
92
|
try {
|
|
93
|
-
const s = (Number(idb.db.version(e)) || 0) + 1,
|
|
94
|
-
|
|
93
|
+
const s = (Number(idb.db.version(e)) || 0) + 1, i = indexedDB.open(e, s);
|
|
94
|
+
i.onupgradeneeded = o => {
|
|
95
95
|
const r = o.target.result;
|
|
96
96
|
if (!r.objectStoreNames.contains(t)) {
|
|
97
97
|
const o = r.createObjectStore(t, {
|
|
@@ -102,12 +102,12 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
102
102
|
unique: !0
|
|
103
103
|
}), o.createIndex("data", "data", {
|
|
104
104
|
unique: !1
|
|
105
|
-
}),
|
|
105
|
+
}), memorio.message(`Table ${t} created in ${e}`);
|
|
106
106
|
}
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
},
|
|
110
|
-
console.error(`Error creating table ${t}:`,
|
|
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);
|
|
111
111
|
};
|
|
112
112
|
} catch (e) {
|
|
113
113
|
console.error("Critical error in table.create:", e), r(e);
|
|
@@ -119,48 +119,48 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
119
119
|
idb.table.size = (e, t) => new Promise((o, r) => {
|
|
120
120
|
if (!e) return r(new Error("Database instance is required"));
|
|
121
121
|
if (!e.objectStoreNames.contains(t)) return o(0);
|
|
122
|
-
let s = 0,
|
|
123
|
-
const
|
|
124
|
-
|
|
122
|
+
let s = 0, i = 0;
|
|
123
|
+
const n = e.transaction([ t ], "readonly").objectStore(t).openCursor();
|
|
124
|
+
n.onsuccess = async e => {
|
|
125
125
|
const t = e.target.result;
|
|
126
126
|
if (t) {
|
|
127
127
|
try {
|
|
128
128
|
const e = t.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
|
-
|
|
133
|
+
i++, i % 200 == 0 && await new Promise(e => setTimeout(e, 0)), t.continue();
|
|
134
134
|
} else o(s);
|
|
135
|
-
},
|
|
136
|
-
r(
|
|
135
|
+
}, n.onerror = () => {
|
|
136
|
+
r(n.error);
|
|
137
137
|
};
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
}), j = {}, w = t({
|
|
141
141
|
"functions/idb/crud/data.delete.ts"() {
|
|
142
142
|
idb.data.delete = (e, t, o) => new Promise((r, s) => {
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
const e =
|
|
143
|
+
const i = indexedDB.open(e);
|
|
144
|
+
i.onsuccess = () => {
|
|
145
|
+
const e = i.result;
|
|
146
146
|
if (!e.objectStoreNames.contains(t)) return e.close(), s(new Error(`Table ${t} not found`));
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
e.close(),
|
|
150
|
-
},
|
|
151
|
-
e.close(), s(
|
|
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);
|
|
152
152
|
};
|
|
153
|
-
},
|
|
153
|
+
}, i.onerror = () => s(i.error);
|
|
154
154
|
}), idb.data.delete.all = (e, t) => new Promise((o, r) => {
|
|
155
155
|
const s = indexedDB.open(e);
|
|
156
156
|
s.onsuccess = e => {
|
|
157
157
|
const s = e.target.result;
|
|
158
158
|
if (!s.objectStoreNames.contains(t)) return s.close(), r(new Error(`Table ${t} not found`));
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
s.close(),
|
|
162
|
-
},
|
|
163
|
-
s.close(), r(
|
|
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);
|
|
164
164
|
};
|
|
165
165
|
}, s.onerror = () => r(s.error);
|
|
166
166
|
});
|
|
@@ -168,42 +168,42 @@ var e = Object.getOwnPropertyNames, t = (t, o) => function() {
|
|
|
168
168
|
}), S = {}, P = t({
|
|
169
169
|
"functions/idb/crud/data.set.ts"() {
|
|
170
170
|
idb.data.set = (e, t, o) => new Promise((r, s) => {
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
if (!
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
},
|
|
179
|
-
|
|
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);
|
|
176
|
+
a.onsuccess = () => {
|
|
177
|
+
n.close(), memorio.message(`Data saved in ${e}.${t}`), r(a.result);
|
|
178
|
+
}, a.onerror = e => {
|
|
179
|
+
n.close(), memorio.message(`Database insert error: ${a.error?.message}`), s(a.error);
|
|
180
180
|
};
|
|
181
|
-
},
|
|
182
|
-
s(
|
|
181
|
+
}, i.onerror = () => {
|
|
182
|
+
s(i.error);
|
|
183
183
|
};
|
|
184
184
|
});
|
|
185
185
|
}
|
|
186
|
-
}), E = {},
|
|
186
|
+
}), E = {}, $ = t({
|
|
187
187
|
"functions/idb/crud/data.get.ts"() {
|
|
188
188
|
idb.data.get = (e, t, o) => new Promise((r, s) => {
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
if (!
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
},
|
|
197
|
-
|
|
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);
|
|
194
|
+
a.onsuccess = () => {
|
|
195
|
+
n.close(), r(a.result);
|
|
196
|
+
}, a.onerror = () => {
|
|
197
|
+
n.close(), s(a.error);
|
|
198
198
|
};
|
|
199
|
-
},
|
|
200
|
-
s(
|
|
199
|
+
}, i.onerror = () => {
|
|
200
|
+
s(i.error);
|
|
201
201
|
};
|
|
202
202
|
});
|
|
203
203
|
}
|
|
204
204
|
});
|
|
205
205
|
|
|
206
|
-
function
|
|
206
|
+
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) {
|
|
@@ -213,7 +213,7 @@ function _() {
|
|
|
213
213
|
return `session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
function
|
|
216
|
+
function _() {
|
|
217
217
|
const e = globalThis;
|
|
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
|
}
|
|
@@ -243,7 +243,7 @@ function I() {
|
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
function N() {
|
|
246
|
-
const e =
|
|
246
|
+
const e = _(), t = void 0 !== globalThis.isSecureContext ? globalThis.isSecureContext : "browser" === e;
|
|
247
247
|
return {
|
|
248
248
|
platform: e,
|
|
249
249
|
hasSessionStorage: null !== D(),
|
|
@@ -253,7 +253,7 @@ function N() {
|
|
|
253
253
|
hasNavigator: "undefined" != typeof navigator,
|
|
254
254
|
hasProcess: "undefined" != typeof process,
|
|
255
255
|
isSecureContext: t,
|
|
256
|
-
sessionId:
|
|
256
|
+
sessionId: k()
|
|
257
257
|
};
|
|
258
258
|
}
|
|
259
259
|
|
|
@@ -262,7 +262,7 @@ var A = new Map;
|
|
|
262
262
|
var z = new Map;
|
|
263
263
|
|
|
264
264
|
function J(e) {
|
|
265
|
-
const t = e || `context_${
|
|
265
|
+
const t = e || `context_${k()}`, o = {
|
|
266
266
|
state: {},
|
|
267
267
|
store: new Map,
|
|
268
268
|
session: new Map,
|
|
@@ -321,7 +321,7 @@ Object.defineProperty(globalThis, "memorio", {
|
|
|
321
321
|
}), Object.defineProperty(memorio, "version", {
|
|
322
322
|
writable: !1,
|
|
323
323
|
enumerable: !1,
|
|
324
|
-
value: "4.
|
|
324
|
+
value: "4.1.5"
|
|
325
325
|
}), Object.defineProperty(memorio, "debug", {
|
|
326
326
|
writable: !0,
|
|
327
327
|
enumerable: !1,
|
|
@@ -372,13 +372,13 @@ Object.defineProperty(memorio, "_sessionId", {
|
|
|
372
372
|
}, memorio.deleteContext = function(e) {
|
|
373
373
|
return z.delete(e);
|
|
374
374
|
}, memorio.isBrowser = function() {
|
|
375
|
-
return "browser" ===
|
|
375
|
+
return "browser" === _();
|
|
376
376
|
}, memorio.isNode = function() {
|
|
377
|
-
return "node" ===
|
|
377
|
+
return "node" === _();
|
|
378
378
|
}, memorio.isDeno = function() {
|
|
379
|
-
return "deno" ===
|
|
379
|
+
return "deno" === _();
|
|
380
380
|
}, memorio.isEdge = function() {
|
|
381
|
-
return "edge" ===
|
|
381
|
+
return "edge" === _();
|
|
382
382
|
}, memorio.getCapabilities = N, memorio.isolate = function(e) {
|
|
383
383
|
return J(e);
|
|
384
384
|
}, Object.defineProperty(memorio, "dispatch", {
|
|
@@ -390,7 +390,10 @@ Object.defineProperty(memorio, "_sessionId", {
|
|
|
390
390
|
},
|
|
391
391
|
listen: (e, t = null, o = !1) => {
|
|
392
392
|
globalThis.observer?.list?.[e]?.length > 0 && globalThis.observer?.remove?.(e);
|
|
393
|
-
const r = t ? e =>
|
|
393
|
+
const r = t ? e => {
|
|
394
|
+
const o = e;
|
|
395
|
+
return globalThis.queueMicrotask ? globalThis.queueMicrotask(() => t(o)) : Promise.resolve().then(() => t(o));
|
|
396
|
+
} : void 0;
|
|
394
397
|
r && globalThis.addEventListener(e, r), r && (globalThis.events[e] = r);
|
|
395
398
|
},
|
|
396
399
|
remove: e => {
|
|
@@ -398,7 +401,9 @@ Object.defineProperty(memorio, "_sessionId", {
|
|
|
398
401
|
t && (globalThis.removeEventListener(e, t), delete globalThis.events[e]);
|
|
399
402
|
}
|
|
400
403
|
}
|
|
401
|
-
}), memorio.propertyName = (e, t) => String(t).replace("() => ", ""),
|
|
404
|
+
}), memorio.propertyName = (e, t) => String(t).replace("() => ", ""), memorio.message = (...e) => {
|
|
405
|
+
!0 === memorio.debug && console.debug(...e);
|
|
406
|
+
}, Object.defineProperty(memorio, "objPath", {
|
|
402
407
|
writable: !1,
|
|
403
408
|
enumerable: !1,
|
|
404
409
|
value: (e, t, o = ".") => {
|
|
@@ -412,7 +417,7 @@ globalThis.memorio._locked = !1;
|
|
|
412
417
|
var M = (e, t, o = []) => new Proxy(e, {
|
|
413
418
|
get(e, r) {
|
|
414
419
|
if ("__path" === r) return o.length > 0 ? "state." + o.join(".") : "state";
|
|
415
|
-
if ("list" === r) return
|
|
420
|
+
if ("list" === r) return memorio.message('Some state could be hidden when you use "state.list". Use "state" to see the complete list '),
|
|
416
421
|
JSON.parse(JSON.stringify(globalThis.state));
|
|
417
422
|
if (globalThis.memorio._tracking && "string" == typeof r) {
|
|
418
423
|
const e = o.length > 0 ? "state." + o.concat(r).join(".") : "state." + r;
|
|
@@ -447,10 +452,10 @@ var M = (e, t, o = []) => new Proxy(e, {
|
|
|
447
452
|
if (e[r] && "object" == typeof e[r] && e[r].__locked) return console.error(`Error: state '${r}' is locked. Use state.${r}.unlock() to enable modifications.`),
|
|
448
453
|
!1;
|
|
449
454
|
try {
|
|
450
|
-
const
|
|
455
|
+
const i = globalThis.memorio.objPath?.(r, o) ?? r;
|
|
451
456
|
if (t({
|
|
452
457
|
action: "set",
|
|
453
|
-
path:
|
|
458
|
+
path: i,
|
|
454
459
|
target: e,
|
|
455
460
|
newValue: s,
|
|
456
461
|
previousValue: Reflect.get(e, r)
|
|
@@ -462,7 +467,7 @@ var M = (e, t, o = []) => new Proxy(e, {
|
|
|
462
467
|
}
|
|
463
468
|
});
|
|
464
469
|
} catch (e) {}
|
|
465
|
-
})("state." +
|
|
470
|
+
})("state." + i), Reflect.set(e, r, s), e[r] && "object" == typeof e[r]) {
|
|
466
471
|
const t = e[r];
|
|
467
472
|
if (t && "object" == typeof t) try {
|
|
468
473
|
Object.defineProperty(t, "__locked", {
|
|
@@ -480,7 +485,7 @@ var M = (e, t, o = []) => new Proxy(e, {
|
|
|
480
485
|
enumerable: !1,
|
|
481
486
|
configurable: !1,
|
|
482
487
|
value: !0
|
|
483
|
-
}),
|
|
488
|
+
}), memorio.message(`State '${r}' is now locked.`);
|
|
484
489
|
}
|
|
485
490
|
}), Object.defineProperty(t, "unlock", {
|
|
486
491
|
writable: !1,
|
|
@@ -492,7 +497,7 @@ var M = (e, t, o = []) => new Proxy(e, {
|
|
|
492
497
|
enumerable: !1,
|
|
493
498
|
configurable: !1,
|
|
494
499
|
value: !1
|
|
495
|
-
}),
|
|
500
|
+
}), memorio.message(`State '${r}' is now unlocked.`);
|
|
496
501
|
}
|
|
497
502
|
});
|
|
498
503
|
} catch (e) {}
|
|
@@ -519,9 +524,9 @@ var M = (e, t, o = []) => new Proxy(e, {
|
|
|
519
524
|
});
|
|
520
525
|
|
|
521
526
|
globalThis?.state || (globalThis.state = M({}, () => {})), globalThis.state.lock = () => {
|
|
522
|
-
globalThis.memorio._locked = !0,
|
|
527
|
+
globalThis.memorio._locked = !0, memorio.message("State is now locked. All modifications are blocked.");
|
|
523
528
|
}, globalThis.state.unlock = () => {
|
|
524
|
-
globalThis.memorio._locked = !1,
|
|
529
|
+
globalThis.memorio._locked = !1, memorio.message("State is now unlocked. Modifications are allowed.");
|
|
525
530
|
}, Object.defineProperty(globalThis, "state", {
|
|
526
531
|
enumerable: !1,
|
|
527
532
|
configurable: !0
|
|
@@ -546,7 +551,7 @@ globalThis.observer = (e, t = null, o = !0) => {
|
|
|
546
551
|
}
|
|
547
552
|
}, o = globalThis.observer;
|
|
548
553
|
return o?.list?.[e] && globalThis.memorio.dispatch.remove(t), o?.list?.[e] || globalThis.memorio.dispatch.listen(t),
|
|
549
|
-
void
|
|
554
|
+
void memorio.message(`called: ${e}`);
|
|
550
555
|
}
|
|
551
556
|
if (e && t) {
|
|
552
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'");
|
|
@@ -599,27 +604,27 @@ globalThis.observer = (e, t = null, o = !0) => {
|
|
|
599
604
|
e();
|
|
600
605
|
} catch (e) {}
|
|
601
606
|
globalThis.memorio._tracking = !1, globalThis.memorio._trackedPaths?.forEach(t => {
|
|
602
|
-
o.includes(t) || (
|
|
607
|
+
o.includes(t) || (memorio.message(`useObserver: [Auto-Discovery] -> "${t}"`), globalThis.memorio.dispatch.listen(t, () => e()),
|
|
603
608
|
o.push(t));
|
|
604
609
|
});
|
|
605
610
|
}
|
|
606
|
-
}), o.length > 0 ?
|
|
611
|
+
}), o.length > 0 ? memorio.message(`useObserver: Monitoring ${o.length} paths.`) : console.warn("useObserver: No paths resolved for monitoring. Check your dependencies!"),
|
|
607
612
|
() => {
|
|
608
613
|
o.forEach(e => {
|
|
609
614
|
globalThis.memorio.dispatch && "function" == typeof globalThis.memorio.dispatch.remove && (globalThis.memorio.dispatch.remove(e),
|
|
610
|
-
|
|
615
|
+
memorio.message(`useObserver: Stopped monitoring "${e}"`));
|
|
611
616
|
});
|
|
612
617
|
};
|
|
613
618
|
} catch (e) {
|
|
614
|
-
return
|
|
619
|
+
return memorio.message(`useObserver Error: ${e}`), () => {};
|
|
615
620
|
}
|
|
616
621
|
}, Object.freeze(globalThis.useObserver);
|
|
617
622
|
|
|
618
623
|
var W = x(), R = new Map, U = null !== W, K = "memorio_store_";
|
|
619
624
|
|
|
620
|
-
function
|
|
621
|
-
return e && "string" == typeof e ? e.length > 512 ? (
|
|
622
|
-
"") : /^[a-zA-Z0-9_.-]+$/.test(e) ? K + e : (
|
|
625
|
+
function q(e) {
|
|
626
|
+
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)"),
|
|
623
628
|
"") : "";
|
|
624
629
|
}
|
|
625
630
|
|
|
@@ -631,7 +636,7 @@ Object.defineProperty(globalThis, "store", {
|
|
|
631
636
|
get: {
|
|
632
637
|
value: e => {
|
|
633
638
|
if (!e) return;
|
|
634
|
-
const t =
|
|
639
|
+
const t = q(e);
|
|
635
640
|
try {
|
|
636
641
|
if (U) {
|
|
637
642
|
const e = W.getItem(t);
|
|
@@ -642,7 +647,7 @@ Object.defineProperty(globalThis, "store", {
|
|
|
642
647
|
return e ? JSON.parse(e) : e;
|
|
643
648
|
}
|
|
644
649
|
} catch (t) {
|
|
645
|
-
|
|
650
|
+
memorio.message(`Error parsing store item '${e}': ${t}`);
|
|
646
651
|
}
|
|
647
652
|
return null;
|
|
648
653
|
}
|
|
@@ -650,13 +655,13 @@ Object.defineProperty(globalThis, "store", {
|
|
|
650
655
|
set: {
|
|
651
656
|
value: (e, t) => {
|
|
652
657
|
if (!e) return;
|
|
653
|
-
const o =
|
|
658
|
+
const o = q(e);
|
|
654
659
|
try {
|
|
655
660
|
if (U) {
|
|
656
|
-
if (null == t) W.setItem(o, JSON.stringify(null)); else if ("object" == typeof t || "number" == typeof t || "boolean" == typeof t || "string" == typeof t) W.setItem(o, JSON.stringify(t)); else if ("function" == typeof t) return void
|
|
657
|
-
} else if (null == t) R.set(o, JSON.stringify(null)); else if ("object" == typeof t || "number" == typeof t || "boolean" == typeof t || "string" == typeof t) R.set(o, JSON.stringify(t)); else if ("function" == typeof t) return void
|
|
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.");
|
|
658
663
|
} catch (t) {
|
|
659
|
-
|
|
664
|
+
memorio.message(`Error setting store item '${e}': ${t}`);
|
|
660
665
|
}
|
|
661
666
|
return null;
|
|
662
667
|
}
|
|
@@ -664,13 +669,13 @@ Object.defineProperty(globalThis, "store", {
|
|
|
664
669
|
remove: {
|
|
665
670
|
value: e => {
|
|
666
671
|
if (!e) return;
|
|
667
|
-
const t =
|
|
672
|
+
const t = q(e);
|
|
668
673
|
try {
|
|
669
674
|
if (U) {
|
|
670
675
|
if (W.getItem(t)) return W.removeItem(t), !0;
|
|
671
676
|
} else if (R.has(t)) return R.delete(t), !0;
|
|
672
677
|
} catch (t) {
|
|
673
|
-
|
|
678
|
+
memorio.message(`Error removing store item '${e}': ${t}`);
|
|
674
679
|
}
|
|
675
680
|
return !1;
|
|
676
681
|
}
|
|
@@ -738,18 +743,18 @@ Object.defineProperty(globalThis, "store", {
|
|
|
738
743
|
}
|
|
739
744
|
});
|
|
740
745
|
} catch (e) {
|
|
741
|
-
|
|
746
|
+
memorio.message(`Error listing store items: ${e}`);
|
|
742
747
|
}
|
|
743
748
|
return e;
|
|
744
749
|
}
|
|
745
750
|
}
|
|
746
751
|
}), Object.freeze(store);
|
|
747
752
|
|
|
748
|
-
var
|
|
753
|
+
var F = D(), L = new Map, H = null !== F, V = "memorio_session_";
|
|
749
754
|
|
|
750
755
|
function Y(e) {
|
|
751
|
-
return e && "string" == typeof e ? e.length > 512 ? (
|
|
752
|
-
"") : /^[a-zA-Z0-9_.-]+$/.test(e) ? V + e : (
|
|
756
|
+
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)"),
|
|
753
758
|
"") : "";
|
|
754
759
|
}
|
|
755
760
|
|
|
@@ -764,7 +769,7 @@ Object.defineProperty(globalThis, "session", {
|
|
|
764
769
|
const t = Y(e);
|
|
765
770
|
try {
|
|
766
771
|
if (H) {
|
|
767
|
-
const e =
|
|
772
|
+
const e = F.getItem(t);
|
|
768
773
|
return e ? JSON.parse(e) : e;
|
|
769
774
|
}
|
|
770
775
|
{
|
|
@@ -772,7 +777,7 @@ Object.defineProperty(globalThis, "session", {
|
|
|
772
777
|
return e ? JSON.parse(e) : e;
|
|
773
778
|
}
|
|
774
779
|
} catch (t) {
|
|
775
|
-
|
|
780
|
+
memorio.message(`Error parsing session item '${e}':${t}`);
|
|
776
781
|
}
|
|
777
782
|
}
|
|
778
783
|
},
|
|
@@ -781,9 +786,9 @@ Object.defineProperty(globalThis, "session", {
|
|
|
781
786
|
if (!e) return;
|
|
782
787
|
const o = Y(e);
|
|
783
788
|
try {
|
|
784
|
-
H ? null == t ?
|
|
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.");
|
|
785
790
|
} catch (t) {
|
|
786
|
-
|
|
791
|
+
memorio.message(`Error setting session item '${e}': ${t}`);
|
|
787
792
|
}
|
|
788
793
|
}
|
|
789
794
|
},
|
|
@@ -793,10 +798,10 @@ Object.defineProperty(globalThis, "session", {
|
|
|
793
798
|
const t = Y(e);
|
|
794
799
|
try {
|
|
795
800
|
if (H) {
|
|
796
|
-
if (
|
|
801
|
+
if (F.getItem(t)) return F.removeItem(t), !0;
|
|
797
802
|
} else if (L.has(t)) return L.delete(t), !0;
|
|
798
803
|
} catch (t) {
|
|
799
|
-
|
|
804
|
+
memorio.message(`Error removing session item '${e}': ${t}`);
|
|
800
805
|
}
|
|
801
806
|
}
|
|
802
807
|
},
|
|
@@ -807,11 +812,11 @@ Object.defineProperty(globalThis, "session", {
|
|
|
807
812
|
value: () => {
|
|
808
813
|
if (H) {
|
|
809
814
|
const e = [];
|
|
810
|
-
for (let t = 0; t <
|
|
811
|
-
const o =
|
|
815
|
+
for (let t = 0; t < F.length; t++) {
|
|
816
|
+
const o = F.key(t);
|
|
812
817
|
o?.startsWith(V) && e.push(o);
|
|
813
818
|
}
|
|
814
|
-
e.forEach(e =>
|
|
819
|
+
e.forEach(e => F.removeItem(e));
|
|
815
820
|
} else L.clear();
|
|
816
821
|
return !0;
|
|
817
822
|
}
|
|
@@ -825,9 +830,9 @@ Object.defineProperty(globalThis, "session", {
|
|
|
825
830
|
size: {
|
|
826
831
|
value: () => {
|
|
827
832
|
let e = 0;
|
|
828
|
-
return H ? Object.keys(
|
|
833
|
+
return H ? Object.keys(F).forEach(t => {
|
|
829
834
|
if (t.startsWith(V)) {
|
|
830
|
-
const o =
|
|
835
|
+
const o = F.getItem(t);
|
|
831
836
|
o && (e += o.length);
|
|
832
837
|
}
|
|
833
838
|
}) : L.forEach(t => {
|
|
@@ -842,10 +847,10 @@ Object.defineProperty(globalThis, "session", {
|
|
|
842
847
|
value: () => {
|
|
843
848
|
const e = {};
|
|
844
849
|
try {
|
|
845
|
-
if (H) for (let t = 0; t <
|
|
846
|
-
const o =
|
|
850
|
+
if (H) for (let t = 0; t < F.length; t++) {
|
|
851
|
+
const o = F.key(t);
|
|
847
852
|
if (o?.startsWith(V)) {
|
|
848
|
-
const t = o.replace(V, ""), r =
|
|
853
|
+
const t = o.replace(V, ""), r = F.getItem(o);
|
|
849
854
|
if (null !== r) try {
|
|
850
855
|
e[t] = JSON.parse(r);
|
|
851
856
|
} catch {
|
|
@@ -863,7 +868,7 @@ Object.defineProperty(globalThis, "session", {
|
|
|
863
868
|
}
|
|
864
869
|
});
|
|
865
870
|
} catch (e) {
|
|
866
|
-
|
|
871
|
+
memorio.message(`Error listing session items: ${e}`);
|
|
867
872
|
}
|
|
868
873
|
return e;
|
|
869
874
|
}
|
|
@@ -900,13 +905,13 @@ Object.defineProperty(globalThis, "cache", {
|
|
|
900
905
|
writable: !0,
|
|
901
906
|
configurable: !0,
|
|
902
907
|
enumerable: !1
|
|
903
|
-
}), await Promise.all([ Promise.resolve().then(() => (r(), o)), Promise.resolve().then(() => (
|
|
904
|
-
s)), Promise.resolve().then(() => (
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
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(),
|
|
912
|
+
h)), Promise.resolve().then(() => (y(), v)), Promise.resolve().then(() => (O(),
|
|
908
913
|
T)), Promise.resolve().then(() => (w(), j)), Promise.resolve().then(() => (P(),
|
|
909
|
-
S)), Promise.resolve().then(() => (
|
|
914
|
+
S)), Promise.resolve().then(() => ($(), E)) ]), Object.preventExtensions(idb), Object.seal(idb),
|
|
910
915
|
Object.freeze(idb);
|
|
911
916
|
})() : (Object.defineProperty(globalThis, "idb", {
|
|
912
917
|
value: {
|
|
@@ -1040,7 +1045,7 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "devt
|
|
|
1040
1045
|
}
|
|
1041
1046
|
},
|
|
1042
1047
|
help: () => {
|
|
1043
|
-
console.log("\nš§ Memorio DevTools Help\n\nAvailable commands:\n memorio.devtools.inspect()
|
|
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");
|
|
1044
1049
|
}
|
|
1045
1050
|
}
|
|
1046
1051
|
}), ee = "devtools", !1 === G || G && "object" == typeof G && !1 === G[ee] || (Object.defineProperty(globalThis, "$state", {
|
|
@@ -1062,7 +1067,7 @@ var oe = {
|
|
|
1062
1067
|
logToConsole: !0,
|
|
1063
1068
|
modules: [ "state", "store", "session", "cache", "idb" ],
|
|
1064
1069
|
maxEntries: 1e3
|
|
1065
|
-
}, re = [], se = e => oe.enabled && oe.modules.includes(e),
|
|
1070
|
+
}, re = [], se = e => oe.enabled && oe.modules.includes(e), ie = e => ({
|
|
1066
1071
|
state: "#4CAF50",
|
|
1067
1072
|
store: "#2196F3",
|
|
1068
1073
|
session: "#FF9800",
|
|
@@ -1089,7 +1094,7 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "logg
|
|
|
1089
1094
|
isEnabled: se,
|
|
1090
1095
|
log: (e, t, o, r, s) => {
|
|
1091
1096
|
if (!se(e)) return;
|
|
1092
|
-
const
|
|
1097
|
+
const i = {
|
|
1093
1098
|
timestamp: (new Date).toISOString(),
|
|
1094
1099
|
module: e,
|
|
1095
1100
|
action: t,
|
|
@@ -1097,12 +1102,12 @@ void 0 !== globalThis.memorio && Object.defineProperty(globalThis.memorio, "logg
|
|
|
1097
1102
|
value: r,
|
|
1098
1103
|
previousValue: s
|
|
1099
1104
|
};
|
|
1100
|
-
if (re.push(
|
|
1101
|
-
const
|
|
1102
|
-
|
|
1103
|
-
void 0 !== r &&
|
|
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`),
|
|
1108
|
+
void 0 !== r && memorio.message(` ā value:${r}`), void 0 !== s && memorio.message(` ā previous:${s}`);
|
|
1104
1109
|
}
|
|
1105
|
-
oe.customHandler && oe.customHandler(
|
|
1110
|
+
oe.customHandler && oe.customHandler(i);
|
|
1106
1111
|
},
|
|
1107
1112
|
getHistory: () => [ ...re ],
|
|
1108
1113
|
clearHistory: () => {
|