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/README.md +16 -57
- package/index.cjs +436 -385
- package/index.js +436 -385
- package/{docs/markdown → markdown}/PLATFORM.md +10 -9
- package/{docs/markdown → markdown}/SECURITY.md +15 -10
- package/package.json +1 -1
- package/types/memorio.d.ts +1 -0
- package/docs/README.md +0 -307
- package/docs/_config.yml +0 -1
- /package/{docs/SUMMARY.md → SUMMARY.md} +0 -0
- /package/{docs/markdown → markdown}/CACHE.md +0 -0
- /package/{docs/markdown → markdown}/CHANGELOG.md +0 -0
- /package/{docs/markdown → markdown}/DEVTOOLS.md +0 -0
- /package/{docs/markdown → markdown}/IDB.md +0 -0
- /package/{docs/markdown → markdown}/LOGGER.md +0 -0
- /package/{docs/markdown → markdown}/OBSERVER.md +0 -0
- /package/{docs/markdown → markdown}/SESSION.md +0 -0
- /package/{docs/markdown → markdown}/STATE.md +0 -0
- /package/{docs/markdown → markdown}/STORE.md +0 -0
- /package/{docs/markdown → markdown}/USEOBSERVER.md +0 -0
package/index.cjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var e = Object.getOwnPropertyNames,
|
|
4
|
-
return
|
|
5
|
-
},
|
|
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,
|
|
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,
|
|
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`),
|
|
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 = {},
|
|
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
|
-
}),
|
|
31
|
+
}), i = {}, a = o({
|
|
32
32
|
"functions/idb/tools/db.exist.ts"() {
|
|
33
|
-
idb.db.exist = e => idbases?.some(
|
|
33
|
+
idb.db.exist = e => idbases?.some(o => o.name === e);
|
|
34
34
|
}
|
|
35
|
-
}), l = {}, c =
|
|
35
|
+
}), l = {}, c = o({
|
|
36
36
|
"functions/idb/tools/db.quota.ts"() {
|
|
37
37
|
idb.db.quota = () => navigator.storage.estimate();
|
|
38
38
|
}
|
|
39
|
-
}), m = {},
|
|
39
|
+
}), m = {}, u = o({
|
|
40
40
|
"functions/idb/tools/db.delete.ts"() {
|
|
41
|
-
idb.db.delete = e => new Promise((
|
|
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(),
|
|
46
|
+
memorio.message(`${e} database removed successfully`), idb.db.list(), o();
|
|
47
47
|
}, r.onerror = () => {
|
|
48
|
-
console.error(`Error removing ${e}:`, 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
|
-
}),
|
|
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
|
|
59
|
+
const o = idbases[e];
|
|
60
60
|
try {
|
|
61
|
-
const e = await idb.db.create(
|
|
61
|
+
const e = await idb.db.create(o.name, o.version), t = Array.from(e.objectStoreNames);
|
|
62
62
|
let r = 0;
|
|
63
|
-
for (const
|
|
64
|
-
r += await idb.table.size(e,
|
|
63
|
+
for (const o of t) {
|
|
64
|
+
r += await idb.table.size(e, o);
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
o.size = r, e.close();
|
|
67
67
|
} catch (e) {
|
|
68
|
-
memorio.message(`Could not calculate size for ${
|
|
68
|
+
memorio.message(`Could not calculate size for ${o.name}:${e}`);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
}), g = {}, f =
|
|
73
|
+
}), g = {}, f = o({
|
|
74
74
|
"functions/idb/tools/db.version.ts"() {
|
|
75
75
|
idb.db.version = e => {
|
|
76
|
-
let
|
|
77
|
-
for (const
|
|
78
|
-
|
|
76
|
+
let o = 0;
|
|
77
|
+
for (const t of idbases) {
|
|
78
|
+
t.name === e && (o = t.version);
|
|
79
79
|
break;
|
|
80
80
|
}
|
|
81
|
-
return
|
|
81
|
+
return o;
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
-
}), h = {}, p =
|
|
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 =
|
|
91
|
+
}), v = {}, y = o({
|
|
92
92
|
"functions/idb/tools/table.create.ts"() {
|
|
93
|
-
idb.table.create = (e,
|
|
93
|
+
idb.table.create = (e, o) => new Promise(async (t, r) => {
|
|
94
94
|
try {
|
|
95
|
-
const s = (Number(idb.db.version(e)) || 0) + 1,
|
|
96
|
-
|
|
97
|
-
const r =
|
|
98
|
-
if (!r.objectStoreNames.contains(
|
|
99
|
-
const
|
|
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
|
-
|
|
103
|
+
t.createIndex("id", "id", {
|
|
104
104
|
unique: !0
|
|
105
|
-
}),
|
|
105
|
+
}), t.createIndex("data", "data", {
|
|
106
106
|
unique: !1
|
|
107
|
-
}), memorio.message(`Table ${
|
|
107
|
+
}), memorio.message(`Table ${o} created in ${e}`);
|
|
108
108
|
}
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
},
|
|
112
|
-
console.error(`Error creating table ${
|
|
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 =
|
|
119
|
+
}), T = {}, O = o({
|
|
120
120
|
"functions/idb/tools/table.size.ts"() {
|
|
121
|
-
idb.table.size = (e,
|
|
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(
|
|
124
|
-
let s = 0,
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
if (
|
|
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 =
|
|
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
|
-
|
|
136
|
-
} else
|
|
137
|
-
},
|
|
138
|
-
r(
|
|
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
|
-
}),
|
|
142
|
+
}), w = {}, S = o({
|
|
143
143
|
"functions/idb/crud/data.delete.ts"() {
|
|
144
|
-
idb.data.delete = (e,
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
const e =
|
|
148
|
-
if (!e.objectStoreNames.contains(
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
e.close(), memorio.message(`Record ${
|
|
152
|
-
},
|
|
153
|
-
e.close(), s(
|
|
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
|
-
},
|
|
156
|
-
}), idb.data.delete.all = (e,
|
|
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(
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
s.close(), memorio.message(`All data cleared from ${
|
|
164
|
-
},
|
|
165
|
-
s.close(), r(
|
|
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
|
-
}),
|
|
170
|
+
}), j = {}, P = o({
|
|
171
171
|
"functions/idb/crud/data.set.ts"() {
|
|
172
|
-
idb.data.set = (e,
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
if (!
|
|
177
|
-
const a =
|
|
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
|
-
|
|
179
|
+
i.close(), memorio.message(`Data saved in ${e}.${o}`), r(a.result);
|
|
180
180
|
}, a.onerror = e => {
|
|
181
|
-
|
|
181
|
+
i.close(), memorio.message(`Database insert error: ${a.error?.message}`), s(a.error);
|
|
182
182
|
};
|
|
183
|
-
},
|
|
184
|
-
s(
|
|
183
|
+
}, n.onerror = () => {
|
|
184
|
+
s(n.error);
|
|
185
185
|
};
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
|
-
}),
|
|
188
|
+
}), $ = {}, E = o({
|
|
189
189
|
"functions/idb/crud/data.get.ts"() {
|
|
190
|
-
idb.data.get = (e,
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
if (!
|
|
195
|
-
const a =
|
|
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
|
-
|
|
197
|
+
i.close(), r(a.result);
|
|
198
198
|
}, a.onerror = () => {
|
|
199
|
-
|
|
199
|
+
i.close(), s(a.error);
|
|
200
200
|
};
|
|
201
|
-
},
|
|
202
|
-
s(
|
|
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
|
|
213
|
-
return e.crypto.getRandomValues(
|
|
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
|
|
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
|
|
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 = _(),
|
|
248
|
+
const e = _(), o = void 0 !== globalThis.isSecureContext ? globalThis.isSecureContext : "browser" === e;
|
|
249
249
|
return {
|
|
250
250
|
platform: e,
|
|
251
|
-
hasSessionStorage: null !==
|
|
252
|
-
hasLocalStorage: null !==
|
|
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:
|
|
257
|
+
isSecureContext: o,
|
|
258
258
|
sessionId: k()
|
|
259
259
|
};
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
var A = new Map;
|
|
263
263
|
|
|
264
|
-
var
|
|
264
|
+
var C = new Map;
|
|
265
265
|
|
|
266
266
|
function J(e) {
|
|
267
|
-
const
|
|
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
|
|
274
|
-
id:
|
|
275
|
-
state:
|
|
279
|
+
return C.set(o, t), {
|
|
280
|
+
id: o,
|
|
281
|
+
state: t.state,
|
|
276
282
|
store: {
|
|
277
283
|
get: e => {
|
|
278
|
-
const
|
|
279
|
-
return
|
|
284
|
+
const o = t.store.get(e);
|
|
285
|
+
return o ? JSON.parse(o) : null;
|
|
280
286
|
},
|
|
281
|
-
set: (e,
|
|
282
|
-
|
|
287
|
+
set: (e, o) => {
|
|
288
|
+
t.store.set(e, JSON.stringify(o));
|
|
283
289
|
},
|
|
284
|
-
remove: e =>
|
|
285
|
-
removeAll: () =>
|
|
286
|
-
clearAll: () =>
|
|
287
|
-
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
|
|
293
|
-
return
|
|
298
|
+
const o = t.session.get(e);
|
|
299
|
+
return o ? JSON.parse(o) : null;
|
|
294
300
|
},
|
|
295
|
-
set: (e,
|
|
296
|
-
|
|
301
|
+
set: (e, o) => {
|
|
302
|
+
t.session.set(e, JSON.stringify(o));
|
|
297
303
|
},
|
|
298
|
-
remove: e =>
|
|
299
|
-
removeAll: () =>
|
|
300
|
-
clearAll: () =>
|
|
301
|
-
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 =>
|
|
306
|
-
set: (e,
|
|
307
|
-
remove: e =>
|
|
308
|
-
removeAll: () =>
|
|
309
|
-
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:
|
|
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(),
|
|
337
|
-
void 0 !==
|
|
338
|
-
e.hasDispatchEvent || (
|
|
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 && (
|
|
348
|
+
}, "undefined" == typeof CustomEvent && (o.CustomEvent = class {
|
|
341
349
|
type;
|
|
342
350
|
detail;
|
|
343
|
-
constructor(e,
|
|
344
|
-
this.type = e, this.detail =
|
|
351
|
+
constructor(e, o = {}) {
|
|
352
|
+
this.type = e, this.detail = o;
|
|
345
353
|
}
|
|
346
|
-
})), "function" != typeof
|
|
347
|
-
A.has(e) || A.set(e, []), A.get(e).push(
|
|
348
|
-
},
|
|
349
|
-
const
|
|
350
|
-
if (
|
|
351
|
-
const e =
|
|
352
|
-
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
|
-
},
|
|
355
|
-
const
|
|
356
|
-
return
|
|
362
|
+
}, o.dispatchEvent = function(e) {
|
|
363
|
+
const o = A.get(e.type);
|
|
364
|
+
return o && o.forEach(o => {
|
|
357
365
|
try {
|
|
358
|
-
|
|
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
|
|
374
|
+
var M = N();
|
|
367
375
|
|
|
368
376
|
Object.defineProperty(memorio, "_sessionId", {
|
|
369
377
|
writable: !1,
|
|
370
378
|
enumerable: !1,
|
|
371
|
-
value:
|
|
379
|
+
value: M.sessionId
|
|
372
380
|
}), memorio.createContext = J, memorio.listContexts = function() {
|
|
373
|
-
return Array.from(
|
|
381
|
+
return Array.from(C.keys());
|
|
374
382
|
}, memorio.deleteContext = function(e) {
|
|
375
|
-
return
|
|
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,
|
|
391
|
-
globalThis.dispatchEvent(new CustomEvent(String(e),
|
|
400
|
+
set: (e, o = {}) => {
|
|
401
|
+
globalThis.dispatchEvent(new CustomEvent(String(e), o));
|
|
392
402
|
},
|
|
393
|
-
listen: (e,
|
|
403
|
+
listen: (e, o = null, t = !1) => {
|
|
394
404
|
globalThis.observer?.list?.[e]?.length > 0 && globalThis.observer?.remove?.(e);
|
|
395
|
-
const r =
|
|
396
|
-
const
|
|
397
|
-
return globalThis.queueMicrotask ? globalThis.queueMicrotask(() => t
|
|
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
|
|
403
|
-
|
|
412
|
+
const o = globalThis.events?.[e];
|
|
413
|
+
o && (globalThis.removeEventListener(e, o), delete globalThis.events[e]);
|
|
404
414
|
}
|
|
405
415
|
}
|
|
406
|
-
}), memorio.propertyName = (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,
|
|
412
|
-
const r =
|
|
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
|
|
429
|
+
var W = (e, o, t = []) => new Proxy(e, {
|
|
420
430
|
get(e, r) {
|
|
421
|
-
if ("__path" === r) return
|
|
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 =
|
|
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
|
|
438
|
+
if ("remove" === r) return o => (delete e[o], !0);
|
|
429
439
|
if ("removeAll" === r) return () => {
|
|
430
440
|
try {
|
|
431
|
-
for (const
|
|
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
|
|
439
|
-
if (
|
|
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) ?
|
|
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
|
|
458
|
-
if (
|
|
467
|
+
const n = globalThis.memorio.objPath?.(r, t) ?? r;
|
|
468
|
+
if (o({
|
|
459
469
|
action: "set",
|
|
460
|
-
path:
|
|
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." +
|
|
473
|
-
const
|
|
474
|
-
if (
|
|
475
|
-
Object.defineProperty(
|
|
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(
|
|
490
|
+
}), Object.defineProperty(o, "lock", {
|
|
481
491
|
writable: !1,
|
|
482
492
|
enumerable: !1,
|
|
483
493
|
configurable: !1,
|
|
484
494
|
value: () => {
|
|
485
|
-
Object.defineProperty(
|
|
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(
|
|
502
|
+
}), Object.defineProperty(o, "unlock", {
|
|
493
503
|
writable: !1,
|
|
494
504
|
enumerable: !1,
|
|
495
505
|
configurable: !1,
|
|
496
506
|
value: () => {
|
|
497
|
-
Object.defineProperty(
|
|
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,
|
|
515
|
-
return
|
|
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,
|
|
535
|
+
getOwnPropertyDescriptor: (e, o) => Reflect.getOwnPropertyDescriptor(e, o)
|
|
526
536
|
});
|
|
527
537
|
|
|
528
|
-
globalThis?.state || (globalThis.state =
|
|
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,
|
|
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 ||
|
|
549
|
-
if (e && !
|
|
550
|
-
const
|
|
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
|
-
},
|
|
555
|
-
return
|
|
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 &&
|
|
559
|
-
if ("string" != typeof e || "function" != typeof
|
|
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,
|
|
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,
|
|
576
|
-
return
|
|
577
|
-
e?.remove?.(
|
|
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,
|
|
587
|
-
if (!
|
|
588
|
-
const
|
|
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(
|
|
600
|
+
return r.forEach(o => {
|
|
591
601
|
let r = "";
|
|
592
|
-
if ("function" == typeof
|
|
602
|
+
if ("function" == typeof o) {
|
|
593
603
|
const e = globalThis.memorio.propertyName;
|
|
594
604
|
if ("function" == typeof e) {
|
|
595
|
-
const
|
|
596
|
-
|
|
605
|
+
const t = e(globalThis.state, o);
|
|
606
|
+
t && (r = t);
|
|
597
607
|
}
|
|
598
|
-
} else "object" == typeof
|
|
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
|
|
602
|
-
globalThis.memorio.dispatch.listen(
|
|
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(
|
|
609
|
-
|
|
610
|
-
|
|
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
|
-
}),
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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) ?
|
|
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
|
|
663
|
+
const o = L(e);
|
|
642
664
|
try {
|
|
643
|
-
if (
|
|
644
|
-
const e =
|
|
665
|
+
if (q) {
|
|
666
|
+
const e = R.getItem(o);
|
|
645
667
|
return e ? JSON.parse(e) : e;
|
|
646
668
|
}
|
|
647
669
|
{
|
|
648
|
-
const e =
|
|
670
|
+
const e = K().get(o);
|
|
649
671
|
return e ? JSON.parse(e) : e;
|
|
650
672
|
}
|
|
651
|
-
} catch (
|
|
652
|
-
memorio.message(`Error parsing store item '${e}': ${
|
|
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
|
|
660
|
-
for (const
|
|
661
|
-
const e = store.get(
|
|
662
|
-
e && (t
|
|
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
|
|
686
|
+
return o;
|
|
665
687
|
}
|
|
666
688
|
},
|
|
667
689
|
set: {
|
|
668
|
-
value: (e,
|
|
690
|
+
value: (e, o) => {
|
|
669
691
|
if (!e) return;
|
|
670
|
-
const
|
|
692
|
+
const t = L(e);
|
|
671
693
|
try {
|
|
672
|
-
if (
|
|
673
|
-
if (null ==
|
|
674
|
-
} else
|
|
675
|
-
|
|
676
|
-
|
|
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
|
|
709
|
+
const o = L(e);
|
|
685
710
|
try {
|
|
686
|
-
if (
|
|
687
|
-
if (
|
|
688
|
-
} else if (
|
|
689
|
-
} catch (
|
|
690
|
-
memorio.message(`Error removing store item '${e}': ${
|
|
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 (
|
|
725
|
+
if (q) {
|
|
701
726
|
const e = [];
|
|
702
|
-
for (let
|
|
703
|
-
const
|
|
704
|
-
|
|
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 =>
|
|
707
|
-
} else
|
|
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
|
|
721
|
-
if (
|
|
722
|
-
const
|
|
723
|
-
|
|
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
|
-
}) :
|
|
726
|
-
e +=
|
|
750
|
+
}) : K().forEach(o => {
|
|
751
|
+
e += o.length;
|
|
727
752
|
}), e;
|
|
728
753
|
}
|
|
729
754
|
},
|
|
730
755
|
isPersistent: {
|
|
731
|
-
get: () =>
|
|
756
|
+
get: () => q
|
|
732
757
|
},
|
|
733
758
|
list: {
|
|
734
759
|
value: () => {
|
|
735
760
|
const e = {};
|
|
736
761
|
try {
|
|
737
|
-
if (
|
|
738
|
-
const
|
|
739
|
-
if (
|
|
740
|
-
const
|
|
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[
|
|
767
|
+
e[o] = JSON.parse(r);
|
|
743
768
|
} catch {
|
|
744
|
-
e[
|
|
769
|
+
e[o] = r;
|
|
745
770
|
}
|
|
746
771
|
}
|
|
747
|
-
} else
|
|
748
|
-
if (
|
|
749
|
-
const r =
|
|
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(
|
|
776
|
+
e[r] = JSON.parse(o);
|
|
752
777
|
} catch {
|
|
753
|
-
e[r] =
|
|
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
|
|
790
|
+
var H = x(), V = new Map;
|
|
766
791
|
|
|
767
|
-
function Y(
|
|
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) ?
|
|
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
|
|
818
|
+
const o = Q(e);
|
|
782
819
|
try {
|
|
783
|
-
if (
|
|
784
|
-
const e =
|
|
820
|
+
if (Z) {
|
|
821
|
+
const e = H.getItem(o);
|
|
785
822
|
return e ? JSON.parse(e) : e;
|
|
786
823
|
}
|
|
787
824
|
{
|
|
788
|
-
const e =
|
|
825
|
+
const e = Y().get(o);
|
|
789
826
|
return e ? JSON.parse(e) : e;
|
|
790
827
|
}
|
|
791
|
-
} catch (
|
|
792
|
-
memorio.message(`Error parsing session item '${e}':${
|
|
828
|
+
} catch (o) {
|
|
829
|
+
memorio.message(`Error parsing session item '${e}':${o}`);
|
|
793
830
|
}
|
|
794
831
|
}
|
|
795
832
|
},
|
|
796
833
|
set: {
|
|
797
|
-
value: (e,
|
|
834
|
+
value: (e, o) => {
|
|
798
835
|
if (!e) return;
|
|
799
|
-
const
|
|
836
|
+
const t = Q(e);
|
|
800
837
|
try {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
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
|
|
850
|
+
const o = Q(e);
|
|
811
851
|
try {
|
|
812
|
-
if (
|
|
813
|
-
if (
|
|
814
|
-
} else if (
|
|
815
|
-
} catch (
|
|
816
|
-
memorio.message(`Error removing session item '${e}': ${
|
|
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 (
|
|
865
|
+
if (Z) {
|
|
826
866
|
const e = [];
|
|
827
|
-
for (let
|
|
828
|
-
const
|
|
829
|
-
|
|
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 =>
|
|
832
|
-
} else
|
|
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
|
|
846
|
-
if (
|
|
847
|
-
const
|
|
848
|
-
|
|
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
|
-
}) :
|
|
851
|
-
e +=
|
|
890
|
+
}) : Y().forEach(o => {
|
|
891
|
+
e += o.length;
|
|
852
892
|
}), e;
|
|
853
893
|
}
|
|
854
894
|
},
|
|
855
895
|
isPersistent: {
|
|
856
|
-
get: () =>
|
|
896
|
+
get: () => Z
|
|
857
897
|
},
|
|
858
898
|
list: {
|
|
859
899
|
value: () => {
|
|
860
900
|
const e = {};
|
|
861
901
|
try {
|
|
862
|
-
if (
|
|
863
|
-
const
|
|
864
|
-
if (
|
|
865
|
-
const
|
|
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[
|
|
907
|
+
e[o] = JSON.parse(r);
|
|
868
908
|
} catch {
|
|
869
|
-
e[
|
|
909
|
+
e[o] = r;
|
|
870
910
|
}
|
|
871
911
|
}
|
|
872
|
-
} else
|
|
873
|
-
if (
|
|
874
|
-
const r =
|
|
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(
|
|
916
|
+
e[r] = JSON.parse(o);
|
|
877
917
|
} catch {
|
|
878
|
-
e[r] =
|
|
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
|
|
930
|
+
var X = {};
|
|
891
931
|
|
|
892
932
|
Object.defineProperty(globalThis, "cache", {
|
|
893
933
|
value: new Proxy({}, {
|
|
894
|
-
get: (e,
|
|
895
|
-
|
|
896
|
-
} : "remove" ===
|
|
897
|
-
!0) : "list" ===
|
|
898
|
-
...
|
|
899
|
-
}) :
|
|
900
|
-
set: (e,
|
|
901
|
-
deleteProperty: (e,
|
|
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(),
|
|
921
|
-
s)), Promise.resolve().then(() => (a(),
|
|
922
|
-
l)), Promise.resolve().then(() => (
|
|
923
|
-
|
|
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(() => (
|
|
926
|
-
|
|
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
|
|
986
|
+
var ee = (globalThis.memorio || {}).globals;
|
|
947
987
|
|
|
948
|
-
function
|
|
988
|
+
function oe() {
|
|
949
989
|
if (!globalThis.store) return {};
|
|
950
|
-
const e = {},
|
|
951
|
-
if ("function" == typeof
|
|
952
|
-
return
|
|
990
|
+
const e = {}, o = globalThis.store;
|
|
991
|
+
if ("function" == typeof o.list) try {
|
|
992
|
+
return o.list();
|
|
953
993
|
} catch {}
|
|
954
|
-
if ("function" == typeof
|
|
955
|
-
const r =
|
|
956
|
-
null != r && (e[
|
|
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
|
|
1001
|
+
function te() {
|
|
962
1002
|
if (!globalThis.session) return {};
|
|
963
|
-
const e = {},
|
|
964
|
-
if ("function" == typeof
|
|
965
|
-
return
|
|
1003
|
+
const e = {}, o = globalThis.session;
|
|
1004
|
+
if ("function" == typeof o.list) try {
|
|
1005
|
+
return o.list();
|
|
966
1006
|
} catch {}
|
|
967
|
-
if ("function" == typeof
|
|
968
|
-
const r =
|
|
969
|
-
null != r && (e[
|
|
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
|
|
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
|
|
987
|
-
|
|
988
|
-
console.table(
|
|
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(
|
|
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
|
|
994
|
-
|
|
995
|
-
console.table(
|
|
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
|
|
1004
|
-
return Object.keys(
|
|
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:
|
|
1057
|
+
clear: se,
|
|
1018
1058
|
clearAll: () => {
|
|
1019
|
-
|
|
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:
|
|
1031
|
-
session:
|
|
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
|
|
1046
|
-
|
|
1047
|
-
globalThis.state && "list" !== e && "remove" !== e && "removeAll" !== e && (globalThis.state[e] =
|
|
1048
|
-
}),
|
|
1049
|
-
globalThis.store.set(e,
|
|
1050
|
-
}),
|
|
1051
|
-
globalThis.session.set(e,
|
|
1052
|
-
}),
|
|
1053
|
-
globalThis.cache && "get" !== e && "set" !== e && "remove" !== e && "clear" !== e && (globalThis.cache[e] =
|
|
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
|
-
}),
|
|
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
|
|
1128
|
+
var ne = {
|
|
1078
1129
|
enabled: !0,
|
|
1079
1130
|
logToConsole: !0,
|
|
1080
1131
|
modules: [ "state", "store", "session", "cache", "idb" ],
|
|
1081
1132
|
maxEntries: 1e3
|
|
1082
|
-
},
|
|
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
|
-
|
|
1096
|
-
...
|
|
1146
|
+
ne = {
|
|
1147
|
+
...ne,
|
|
1097
1148
|
...e
|
|
1098
1149
|
};
|
|
1099
1150
|
},
|
|
1100
1151
|
enable: () => {
|
|
1101
|
-
|
|
1152
|
+
ne.enabled = !0;
|
|
1102
1153
|
},
|
|
1103
1154
|
disable: () => {
|
|
1104
|
-
|
|
1155
|
+
ne.enabled = !1;
|
|
1105
1156
|
},
|
|
1106
|
-
isEnabled:
|
|
1107
|
-
log: (e,
|
|
1108
|
-
if (!
|
|
1109
|
-
const
|
|
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:
|
|
1113
|
-
path:
|
|
1163
|
+
action: o,
|
|
1164
|
+
path: t,
|
|
1114
1165
|
value: r,
|
|
1115
1166
|
previousValue: s
|
|
1116
1167
|
};
|
|
1117
|
-
if (
|
|
1118
|
-
const
|
|
1119
|
-
memorio.message(`%c${
|
|
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
|
-
|
|
1173
|
+
ne.customHandler && ne.customHandler(n);
|
|
1123
1174
|
},
|
|
1124
|
-
getHistory: () => [ ...
|
|
1175
|
+
getHistory: () => [ ...ie ],
|
|
1125
1176
|
clearHistory: () => {
|
|
1126
|
-
|
|
1177
|
+
ie.length = 0;
|
|
1127
1178
|
},
|
|
1128
1179
|
getStats: () => {
|
|
1129
1180
|
const e = {
|
|
1130
|
-
total:
|
|
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
|
|
1142
|
-
const
|
|
1143
|
-
|
|
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(
|
|
1198
|
+
exportLogs: () => JSON.stringify(ie, null, 2)
|
|
1148
1199
|
}
|
|
1149
1200
|
});
|