memorio 5.0.0 → 5.1.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 +98 -435
- package/SECURITY.md +152 -42
- package/SUMMARY.md +1 -1
- package/adr/001-state-proxy-model.md +95 -96
- package/adr/002-observer-semantics.md +179 -180
- package/adr/003-deep-mutation-semantics.md +7 -8
- package/adr/004-array-mutation-semantics.md +127 -128
- package/adr/005-scheduler-contract.md +148 -149
- package/adr/006-context-isolation.md +91 -92
- package/adr/007-mutation-records.md +5 -6
- package/adr/008-transactions.md +6 -7
- package/adr/009-history-model.md +6 -7
- package/adr/README.md +46 -46
- package/adr/template.md +48 -49
- package/bin/cli.js +68 -0
- package/global.cjs +1462 -323
- package/global.js +1459 -324
- package/index.cjs +1462 -323
- package/index.d.ts +1 -0
- package/index.js +1459 -324
- package/llms.txt +42 -5
- package/markdown/AUDIT-REPORT.md +7 -8
- package/markdown/CACHE.md +190 -99
- package/markdown/DEVTOOLS.md +0 -1
- package/markdown/DISPATCH.md +0 -1
- package/markdown/HISTORY.md +0 -1
- package/markdown/IDB.md +0 -1
- package/markdown/IMPORT.md +0 -1
- package/markdown/INSPECT.md +0 -1
- package/markdown/LOGGER.md +0 -1
- package/markdown/MEMORY-ATTACHMENT.md +0 -1
- package/markdown/MEMORY.md +0 -1
- package/markdown/OBSERVER.md +0 -1
- package/markdown/PLATFORM.md +277 -271
- package/markdown/REDUX.md +54 -0
- package/markdown/SCHEMA.md +0 -1
- package/markdown/SESSION.md +0 -1
- package/markdown/SQLITE.md +0 -1
- package/markdown/STATE.md +0 -1
- package/markdown/STORE.md +0 -1
- package/markdown/SYNC.md +0 -1
- package/markdown/TYPED.md +0 -1
- package/markdown/USEOBSERVER.md +0 -1
- package/modules/redux.cjs +381 -10
- package/modules/redux.cjs.map +1 -1
- package/modules/redux.js +381 -10
- package/modules/redux.js.map +1 -1
- package/package.json +14 -2
- package/types/broadcast.d.ts +61 -0
- package/types/computed.d.ts +96 -0
- package/types/encryption.d.ts +129 -0
- package/types/exports.d.ts +9 -0
- package/types/memorio.d.ts +19 -12
- package/types/security.d.ts +67 -0
- package/types/session.d.ts +23 -5
- package/types/store.d.ts +19 -3
- package/vsix/memorio.vsix +0 -0
- package/markdown/CHANGELOG.md +0 -243
- package/markdown/PROJECT.md +0 -311
- package/markdown/SECURITY.md +0 -330
package/global.cjs
CHANGED
|
@@ -8,6 +8,10 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
8
8
|
var __esm = (fn, res) => function __init() {
|
|
9
9
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
10
|
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
11
15
|
|
|
12
16
|
// node_modules/tsup/assets/cjs_shims.js
|
|
13
17
|
var init_cjs_shims = __esm({
|
|
@@ -208,6 +212,241 @@ var init_message = __esm({
|
|
|
208
212
|
}
|
|
209
213
|
});
|
|
210
214
|
|
|
215
|
+
// functions/encryption/index.ts
|
|
216
|
+
function _hasWebCrypto() {
|
|
217
|
+
const g3 = globalThis;
|
|
218
|
+
return typeof g3.crypto !== "undefined" && typeof g3.crypto.subtle !== "undefined" && typeof g3.crypto.subtle.encrypt === "function";
|
|
219
|
+
}
|
|
220
|
+
function _b64encode(buf) {
|
|
221
|
+
const bytes = buf instanceof Uint8Array ? buf : new Uint8Array(buf);
|
|
222
|
+
if (typeof btoa === "function") {
|
|
223
|
+
let binary = "";
|
|
224
|
+
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
225
|
+
return btoa(binary);
|
|
226
|
+
}
|
|
227
|
+
if (typeof Buffer !== "undefined") {
|
|
228
|
+
return Buffer.from(bytes).toString("base64");
|
|
229
|
+
}
|
|
230
|
+
return "";
|
|
231
|
+
}
|
|
232
|
+
function _b64decode(b64) {
|
|
233
|
+
if (typeof Buffer !== "undefined") {
|
|
234
|
+
return new Uint8Array(Buffer.from(b64, "base64"));
|
|
235
|
+
}
|
|
236
|
+
if (typeof atob === "function") {
|
|
237
|
+
const binary = atob(b64);
|
|
238
|
+
const out = new Uint8Array(binary.length);
|
|
239
|
+
for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
|
|
240
|
+
return out;
|
|
241
|
+
}
|
|
242
|
+
throw new Error("memorio encryption: no base64 decoder available");
|
|
243
|
+
}
|
|
244
|
+
function _isEncrypted(value) {
|
|
245
|
+
return typeof value === "object" && value !== null && value.__memorio_encrypted === true && typeof value.alg === "string";
|
|
246
|
+
}
|
|
247
|
+
var AES_GCM, PBKDF2_ITERATIONS; exports.encryption = void 0;
|
|
248
|
+
var init_encryption = __esm({
|
|
249
|
+
"functions/encryption/index.ts"() {
|
|
250
|
+
init_cjs_shims();
|
|
251
|
+
init_env();
|
|
252
|
+
init_message();
|
|
253
|
+
__name(_hasWebCrypto, "_hasWebCrypto");
|
|
254
|
+
__name(_b64encode, "_b64encode");
|
|
255
|
+
__name(_b64decode, "_b64decode");
|
|
256
|
+
__name(_isEncrypted, "_isEncrypted");
|
|
257
|
+
AES_GCM = { name: "AES-GCM", length: 256 };
|
|
258
|
+
PBKDF2_ITERATIONS = 6e5;
|
|
259
|
+
exports.encryption = {
|
|
260
|
+
///
|
|
261
|
+
// Capability detection
|
|
262
|
+
///
|
|
263
|
+
isAvailable() {
|
|
264
|
+
return _hasWebCrypto();
|
|
265
|
+
},
|
|
266
|
+
///
|
|
267
|
+
// Derive a CryptoKey from a password using PBKDF2.
|
|
268
|
+
//
|
|
269
|
+
// @param password The password string.
|
|
270
|
+
// @param salt Salt (string or Uint8Array). Defaults to a static value.
|
|
271
|
+
// @param alg 'AES-GCM' (default) or 'AES-CBC'.
|
|
272
|
+
// @returns A Promise<CryptoKey>.
|
|
273
|
+
///
|
|
274
|
+
async deriveKey(password, salt, alg = "AES-GCM", iterations = PBKDF2_ITERATIONS) {
|
|
275
|
+
if (!_hasWebCrypto()) {
|
|
276
|
+
throw new Error("memorio encryption: Web Crypto API is not available in this environment");
|
|
277
|
+
}
|
|
278
|
+
const enc = new TextEncoder();
|
|
279
|
+
const saltBytes = typeof salt === "string" ? enc.encode(salt) : salt ?? enc.encode("memorio:salt");
|
|
280
|
+
const keyMaterial = await globalThis.crypto.subtle.importKey(
|
|
281
|
+
"raw",
|
|
282
|
+
enc.encode(password),
|
|
283
|
+
{ name: "PBKDF2" },
|
|
284
|
+
false,
|
|
285
|
+
["deriveKey"]
|
|
286
|
+
);
|
|
287
|
+
return globalThis.crypto.subtle.deriveKey(
|
|
288
|
+
{ name: "PBKDF2", salt: saltBytes, iterations, hash: "SHA-256" },
|
|
289
|
+
keyMaterial,
|
|
290
|
+
{ name: alg, length: 256 },
|
|
291
|
+
false,
|
|
292
|
+
["encrypt", "decrypt"]
|
|
293
|
+
);
|
|
294
|
+
},
|
|
295
|
+
///
|
|
296
|
+
// Generate a fresh random CryptoKey (AES-GCM, 256-bit).
|
|
297
|
+
///
|
|
298
|
+
async generateKey(alg = "AES-GCM") {
|
|
299
|
+
if (!_hasWebCrypto()) {
|
|
300
|
+
throw new Error("memorio encryption: Web Crypto API is not available in this environment");
|
|
301
|
+
}
|
|
302
|
+
return globalThis.crypto.subtle.generateKey(
|
|
303
|
+
{ name: alg, length: 256 },
|
|
304
|
+
true,
|
|
305
|
+
["encrypt", "decrypt"]
|
|
306
|
+
);
|
|
307
|
+
},
|
|
308
|
+
///
|
|
309
|
+
// Generate a random salt for PBKDF2 key derivation.
|
|
310
|
+
///
|
|
311
|
+
generateSalt(bytes = 16) {
|
|
312
|
+
const arr = new Uint8Array(bytes);
|
|
313
|
+
globalThis.crypto?.getRandomValues?.(arr);
|
|
314
|
+
return _b64encode(arr);
|
|
315
|
+
},
|
|
316
|
+
///
|
|
317
|
+
// Export a CryptoKey to portable base64 strings so it can be stored
|
|
318
|
+
// (e.g. in an httpOnly cookie) and re-imported later with importKey().
|
|
319
|
+
//
|
|
320
|
+
// @param cryptoKey A raw CryptoKey (not a password string).
|
|
321
|
+
// @returns { key: string, iv: string } base64-encoded.
|
|
322
|
+
///
|
|
323
|
+
async exportKey(cryptoKey) {
|
|
324
|
+
if (!_hasWebCrypto()) {
|
|
325
|
+
throw new Error("memorio encryption: Web Crypto API is not available in this environment");
|
|
326
|
+
}
|
|
327
|
+
const exported = await globalThis.crypto.subtle.exportKey("raw", cryptoKey);
|
|
328
|
+
return {
|
|
329
|
+
key: _b64encode(exported),
|
|
330
|
+
iv: ""
|
|
331
|
+
};
|
|
332
|
+
},
|
|
333
|
+
///
|
|
334
|
+
// Import a CryptoKey from base64 strings produced by exportKey().
|
|
335
|
+
//
|
|
336
|
+
// @param keyData Base64-encoded raw key bytes.
|
|
337
|
+
// @param _ivData Ignored (kept for API compatibility with exportKey return).
|
|
338
|
+
// @returns A Promise<CryptoKey>.
|
|
339
|
+
///
|
|
340
|
+
async importKey(keyData, _ivData) {
|
|
341
|
+
if (!_hasWebCrypto()) {
|
|
342
|
+
throw new Error("memorio encryption: Web Crypto API is not available in this environment");
|
|
343
|
+
}
|
|
344
|
+
const keyBytes = _b64decode(keyData);
|
|
345
|
+
if (keyBytes.length !== 32) {
|
|
346
|
+
throw new Error(`memorio encryption: AES-256 key must be exactly 32 bytes, got ${keyBytes.length}`);
|
|
347
|
+
}
|
|
348
|
+
return globalThis.crypto.subtle.importKey(
|
|
349
|
+
"raw",
|
|
350
|
+
keyBytes,
|
|
351
|
+
AES_GCM,
|
|
352
|
+
true,
|
|
353
|
+
["encrypt", "decrypt"]
|
|
354
|
+
);
|
|
355
|
+
},
|
|
356
|
+
///
|
|
357
|
+
// Encrypt a JavaScript value.
|
|
358
|
+
//
|
|
359
|
+
// @param value The value to encrypt (any JSON-serializable object).
|
|
360
|
+
// @param key A CryptoKey or a password string (password is derived via PBKDF2).
|
|
361
|
+
// @param keyId Optional label, stored in the envelope for key rotation.
|
|
362
|
+
// @returns An EncryptedEnvelope object.
|
|
363
|
+
///
|
|
364
|
+
async encrypt(value, key, keyId) {
|
|
365
|
+
const cryptoKey = typeof key === "string" ? await this.deriveKey(key, void 0, "AES-GCM") : key;
|
|
366
|
+
const data = new TextEncoder().encode(JSON.stringify(value));
|
|
367
|
+
const iv = new Uint8Array(12);
|
|
368
|
+
globalThis.crypto.getRandomValues(iv);
|
|
369
|
+
const ciphertext = await globalThis.crypto.subtle.encrypt(
|
|
370
|
+
{ name: "AES-GCM", iv },
|
|
371
|
+
cryptoKey,
|
|
372
|
+
data
|
|
373
|
+
);
|
|
374
|
+
const envelope = {
|
|
375
|
+
__memorio_encrypted: true,
|
|
376
|
+
v: 1,
|
|
377
|
+
alg: "AES-GCM",
|
|
378
|
+
iv: _b64encode(iv),
|
|
379
|
+
data: _b64encode(ciphertext)
|
|
380
|
+
};
|
|
381
|
+
if (keyId) envelope.keyId = keyId;
|
|
382
|
+
if (exports.DEV) message_default(`encryption: encrypted value (alg=${envelope.alg})`);
|
|
383
|
+
return envelope;
|
|
384
|
+
},
|
|
385
|
+
///
|
|
386
|
+
// Decrypt an EncryptedEnvelope.
|
|
387
|
+
//
|
|
388
|
+
// @param envelope The envelope object returned by encrypt().
|
|
389
|
+
// @param key A CryptoKey or a password string.
|
|
390
|
+
// @returns The original value (parsed from JSON).
|
|
391
|
+
///
|
|
392
|
+
async decrypt(envelope, key) {
|
|
393
|
+
if (!_isEncrypted(envelope)) {
|
|
394
|
+
throw new Error("memorio encryption: value is not a valid encrypted envelope");
|
|
395
|
+
}
|
|
396
|
+
const cryptoKey = typeof key === "string" ? await this.deriveKey(key, void 0, "AES-GCM") : key;
|
|
397
|
+
const iv = _b64decode(envelope.iv);
|
|
398
|
+
const data = _b64decode(envelope.data);
|
|
399
|
+
const decrypted = await globalThis.crypto.subtle.decrypt(
|
|
400
|
+
{ name: "AES-GCM", iv },
|
|
401
|
+
cryptoKey,
|
|
402
|
+
data
|
|
403
|
+
);
|
|
404
|
+
return JSON.parse(new TextDecoder().decode(new Uint8Array(decrypted)));
|
|
405
|
+
},
|
|
406
|
+
///
|
|
407
|
+
// Convenience: encrypt with a password (derives the key internally).
|
|
408
|
+
// Returns a JSON string you can store anywhere.
|
|
409
|
+
///
|
|
410
|
+
async encryptWithPassword(value, password, salt, keyId) {
|
|
411
|
+
const env = await this.encrypt(value, password, keyId);
|
|
412
|
+
return JSON.stringify(env);
|
|
413
|
+
},
|
|
414
|
+
///
|
|
415
|
+
// Convenience: decrypt a JSON envelope string with a password.
|
|
416
|
+
///
|
|
417
|
+
async decryptWithPassword(envelopeJson, password, _salt) {
|
|
418
|
+
const envelope = JSON.parse(envelopeJson);
|
|
419
|
+
return this.decrypt(envelope, password);
|
|
420
|
+
},
|
|
421
|
+
///
|
|
422
|
+
// Type guard: check whether a value is an encrypted envelope.
|
|
423
|
+
///
|
|
424
|
+
isEncrypted(value) {
|
|
425
|
+
return _isEncrypted(value);
|
|
426
|
+
},
|
|
427
|
+
///
|
|
428
|
+
// Configure a default encryption key for auto-encrypt mode.
|
|
429
|
+
// When set on `store` or `session`, all writes are encrypted and all
|
|
430
|
+
// reads attempt decryption automatically.
|
|
431
|
+
///
|
|
432
|
+
config(opts) {
|
|
433
|
+
if (opts.key !== void 0) this._defaultKey = opts.key;
|
|
434
|
+
if (opts.keyId !== void 0) this._defaultKeyId = opts.keyId;
|
|
435
|
+
return this;
|
|
436
|
+
},
|
|
437
|
+
///
|
|
438
|
+
// Internal: resolve the configured default key.
|
|
439
|
+
///
|
|
440
|
+
get _key() {
|
|
441
|
+
return this._defaultKey ?? null;
|
|
442
|
+
},
|
|
443
|
+
get _keyId() {
|
|
444
|
+
return this._defaultKeyId;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
|
|
211
450
|
// core/platform.ts
|
|
212
451
|
function generateSessionId() {
|
|
213
452
|
const anyGlobal = globalThis;
|
|
@@ -222,6 +461,9 @@ function generateSessionId() {
|
|
|
222
461
|
return `session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
223
462
|
}
|
|
224
463
|
function detectPlatform() {
|
|
464
|
+
if (_isBun()) {
|
|
465
|
+
return "bun";
|
|
466
|
+
}
|
|
225
467
|
const globalAny = globalThis;
|
|
226
468
|
if (globalAny.Deno && globalAny.Deno.version) {
|
|
227
469
|
return "deno";
|
|
@@ -237,6 +479,13 @@ function detectPlatform() {
|
|
|
237
479
|
}
|
|
238
480
|
return "unknown";
|
|
239
481
|
}
|
|
482
|
+
function _isBun() {
|
|
483
|
+
const globalAny = globalThis;
|
|
484
|
+
return typeof globalAny.Bun !== "undefined" && typeof globalAny.Bun.version === "string";
|
|
485
|
+
}
|
|
486
|
+
function isBun() {
|
|
487
|
+
return _isBun();
|
|
488
|
+
}
|
|
240
489
|
function isBrowser() {
|
|
241
490
|
const platform = detectPlatform();
|
|
242
491
|
return platform === "browser";
|
|
@@ -290,6 +539,9 @@ function hasSqlJs() {
|
|
|
290
539
|
}
|
|
291
540
|
return typeof anyGlobal.window !== "undefined";
|
|
292
541
|
}
|
|
542
|
+
function hasBunSqlite() {
|
|
543
|
+
return _isBun();
|
|
544
|
+
}
|
|
293
545
|
function hasDispatchEvent() {
|
|
294
546
|
return typeof globalThis.dispatchEvent === "function";
|
|
295
547
|
}
|
|
@@ -302,6 +554,7 @@ function getCapabilities() {
|
|
|
302
554
|
hasLocalStorage: getLocalStorage() !== null,
|
|
303
555
|
hasIndexedDB: hasIndexedDB(),
|
|
304
556
|
hasSqlJs: hasSqlJs(),
|
|
557
|
+
hasBunSqlite: hasBunSqlite(),
|
|
305
558
|
hasDispatchEvent: hasDispatchEvent(),
|
|
306
559
|
hasNavigator: typeof navigator !== "undefined",
|
|
307
560
|
hasProcess: typeof process !== "undefined",
|
|
@@ -361,8 +614,9 @@ function initializePlatform() {
|
|
|
361
614
|
};
|
|
362
615
|
}
|
|
363
616
|
}
|
|
364
|
-
function createContext(name) {
|
|
617
|
+
function createContext(name, opts) {
|
|
365
618
|
const contextId = name || `context_${generateSessionId()}`;
|
|
619
|
+
const encKey = opts?.encryptionKey;
|
|
366
620
|
setCurrentContext(contextId);
|
|
367
621
|
const contextStorage = {
|
|
368
622
|
state: {},
|
|
@@ -371,10 +625,31 @@ function createContext(name) {
|
|
|
371
625
|
cache: /* @__PURE__ */ new Map()
|
|
372
626
|
};
|
|
373
627
|
_contexts.set(contextId, contextStorage);
|
|
628
|
+
function _isEncrypted2(value) {
|
|
629
|
+
return exports.encryption.isEncrypted(value);
|
|
630
|
+
}
|
|
631
|
+
__name(_isEncrypted2, "_isEncrypted");
|
|
374
632
|
return {
|
|
375
633
|
id: contextId,
|
|
376
634
|
state: contextStorage.state,
|
|
377
|
-
store: {
|
|
635
|
+
store: encKey ? {
|
|
636
|
+
get: /* @__PURE__ */ __name(async (key) => {
|
|
637
|
+
const data = contextStorage.store.get(key);
|
|
638
|
+
if (!data) return null;
|
|
639
|
+
const parsed = JSON.parse(data);
|
|
640
|
+
if (_isEncrypted2(parsed)) return exports.encryption.decrypt(parsed, encKey);
|
|
641
|
+
return parsed;
|
|
642
|
+
}, "get"),
|
|
643
|
+
set: /* @__PURE__ */ __name(async (key, value) => {
|
|
644
|
+
const env = await exports.encryption.encrypt(value, encKey);
|
|
645
|
+
contextStorage.store.set(key, JSON.stringify(env));
|
|
646
|
+
}, "set"),
|
|
647
|
+
remove: /* @__PURE__ */ __name((key) => contextStorage.store.delete(key), "remove"),
|
|
648
|
+
removeAll: /* @__PURE__ */ __name(() => contextStorage.store.clear(), "removeAll"),
|
|
649
|
+
clearAll: /* @__PURE__ */ __name(() => contextStorage.store.clear(), "clearAll"),
|
|
650
|
+
size: /* @__PURE__ */ __name(() => contextStorage.store.size, "size"),
|
|
651
|
+
isPersistent: false
|
|
652
|
+
} : {
|
|
378
653
|
get: /* @__PURE__ */ __name((key) => {
|
|
379
654
|
const data = contextStorage.store.get(key);
|
|
380
655
|
return data ? JSON.parse(data) : null;
|
|
@@ -388,7 +663,24 @@ function createContext(name) {
|
|
|
388
663
|
size: /* @__PURE__ */ __name(() => contextStorage.store.size, "size"),
|
|
389
664
|
isPersistent: false
|
|
390
665
|
},
|
|
391
|
-
session: {
|
|
666
|
+
session: encKey ? {
|
|
667
|
+
get: /* @__PURE__ */ __name(async (key) => {
|
|
668
|
+
const data = contextStorage.session.get(key);
|
|
669
|
+
if (!data) return null;
|
|
670
|
+
const parsed = JSON.parse(data);
|
|
671
|
+
if (_isEncrypted2(parsed)) return exports.encryption.decrypt(parsed, encKey);
|
|
672
|
+
return parsed;
|
|
673
|
+
}, "get"),
|
|
674
|
+
set: /* @__PURE__ */ __name(async (key, value) => {
|
|
675
|
+
const env = await exports.encryption.encrypt(value, encKey);
|
|
676
|
+
contextStorage.session.set(key, JSON.stringify(env));
|
|
677
|
+
}, "set"),
|
|
678
|
+
remove: /* @__PURE__ */ __name((key) => contextStorage.session.delete(key), "remove"),
|
|
679
|
+
removeAll: /* @__PURE__ */ __name(() => contextStorage.session.clear(), "removeAll"),
|
|
680
|
+
clearAll: /* @__PURE__ */ __name(() => contextStorage.session.clear(), "clearAll"),
|
|
681
|
+
size: /* @__PURE__ */ __name(() => contextStorage.session.size, "size"),
|
|
682
|
+
isPersistent: false
|
|
683
|
+
} : {
|
|
392
684
|
get: /* @__PURE__ */ __name((key) => {
|
|
393
685
|
const data = contextStorage.session.get(key);
|
|
394
686
|
return data ? JSON.parse(data) : null;
|
|
@@ -408,7 +700,8 @@ function createContext(name) {
|
|
|
408
700
|
remove: /* @__PURE__ */ __name((key) => contextStorage.cache.delete(key), "remove"),
|
|
409
701
|
removeAll: /* @__PURE__ */ __name(() => contextStorage.cache.clear(), "removeAll"),
|
|
410
702
|
clear: /* @__PURE__ */ __name(() => contextStorage.cache.clear(), "clear")
|
|
411
|
-
}
|
|
703
|
+
},
|
|
704
|
+
encryptionKey: encKey
|
|
412
705
|
};
|
|
413
706
|
}
|
|
414
707
|
function listContexts() {
|
|
@@ -425,8 +718,11 @@ var init_platform = __esm({
|
|
|
425
718
|
"core/platform.ts"() {
|
|
426
719
|
init_cjs_shims();
|
|
427
720
|
init_internal();
|
|
721
|
+
init_encryption();
|
|
428
722
|
__name(generateSessionId, "generateSessionId");
|
|
429
723
|
__name(detectPlatform, "detectPlatform");
|
|
724
|
+
__name(_isBun, "_isBun");
|
|
725
|
+
__name(isBun, "isBun");
|
|
430
726
|
__name(isBrowser, "isBrowser");
|
|
431
727
|
__name(isNode, "isNode");
|
|
432
728
|
__name(isDeno, "isDeno");
|
|
@@ -435,6 +731,7 @@ var init_platform = __esm({
|
|
|
435
731
|
__name(getLocalStorage, "getLocalStorage");
|
|
436
732
|
__name(hasIndexedDB, "hasIndexedDB");
|
|
437
733
|
__name(hasSqlJs, "hasSqlJs");
|
|
734
|
+
__name(hasBunSqlite, "hasBunSqlite");
|
|
438
735
|
__name(hasDispatchEvent, "hasDispatchEvent");
|
|
439
736
|
__name(getCapabilities, "getCapabilities");
|
|
440
737
|
_eventListenerStorage = /* @__PURE__ */ new Map();
|
|
@@ -460,6 +757,9 @@ function _getFallbackStorage() {
|
|
|
460
757
|
}
|
|
461
758
|
return _fallbackStorageByContext.get(key);
|
|
462
759
|
}
|
|
760
|
+
function _isEncryptedEnvelope(value) {
|
|
761
|
+
return exports.encryption.isEncrypted(value);
|
|
762
|
+
}
|
|
463
763
|
function _getPrefix() {
|
|
464
764
|
const contextName = exports.internal.currentContext || "";
|
|
465
765
|
return contextName ? `${contextName}-` : `memorio_store_`;
|
|
@@ -496,17 +796,23 @@ function _remove(prefixedName) {
|
|
|
496
796
|
}
|
|
497
797
|
return false;
|
|
498
798
|
}
|
|
499
|
-
var _localStorage, _fallbackStorageByContext, _hasStorage, STORE_INSTANCE_KEY; exports.store = void 0;
|
|
799
|
+
var _localStorage, _fallbackStorageByContext, _hasStorage, _encryptionKey, _onError, _maxObjectSize, _maxTotalSize, STORE_INSTANCE_KEY; exports.store = void 0;
|
|
500
800
|
var init_store = __esm({
|
|
501
801
|
"functions/store/index.ts"() {
|
|
502
802
|
init_cjs_shims();
|
|
503
803
|
init_platform();
|
|
504
804
|
init_internal();
|
|
505
805
|
init_message();
|
|
806
|
+
init_encryption();
|
|
506
807
|
_localStorage = getLocalStorage();
|
|
507
808
|
_fallbackStorageByContext = /* @__PURE__ */ new Map();
|
|
508
809
|
__name(_getFallbackStorage, "_getFallbackStorage");
|
|
509
810
|
_hasStorage = _localStorage !== null;
|
|
811
|
+
_encryptionKey = null;
|
|
812
|
+
_onError = null;
|
|
813
|
+
_maxObjectSize = 0;
|
|
814
|
+
_maxTotalSize = 0;
|
|
815
|
+
__name(_isEncryptedEnvelope, "_isEncryptedEnvelope");
|
|
510
816
|
__name(_getPrefix, "_getPrefix");
|
|
511
817
|
__name(_prefixKey, "_prefixKey");
|
|
512
818
|
__name(_read, "_read");
|
|
@@ -523,16 +829,24 @@ var init_store = __esm({
|
|
|
523
829
|
/**
|
|
524
830
|
* Gets a value from storage.
|
|
525
831
|
* @param name The key to retrieve.
|
|
526
|
-
* @
|
|
832
|
+
* @param opts Optional { decrypt: key } to decrypt an encrypted envelope.
|
|
833
|
+
* When no key is passed, encrypted envelopes are returned as-is.
|
|
834
|
+
* If a default key was configured via store.config(), it is used automatically.
|
|
835
|
+
* @returns The parsed value, a Promise<parsed value> when decrypting, or null if not found.
|
|
527
836
|
*/
|
|
528
837
|
get: {
|
|
529
|
-
value: /* @__PURE__ */ __name((name) => {
|
|
838
|
+
value: /* @__PURE__ */ __name((name, opts) => {
|
|
530
839
|
if (!name) {
|
|
531
840
|
console.warn("[memorio store] store.get() called with empty or null key - returning null");
|
|
532
841
|
return null;
|
|
533
842
|
}
|
|
534
843
|
try {
|
|
535
|
-
|
|
844
|
+
const raw = _read(_prefixKey(name));
|
|
845
|
+
const key = opts?.decrypt ?? _encryptionKey;
|
|
846
|
+
if (key && _isEncryptedEnvelope(raw)) {
|
|
847
|
+
return exports.encryption.decrypt(raw, key);
|
|
848
|
+
}
|
|
849
|
+
return raw;
|
|
536
850
|
} catch (err) {
|
|
537
851
|
exports.message(`Error parsing store item '${name}': ${err}`);
|
|
538
852
|
}
|
|
@@ -557,10 +871,13 @@ var init_store = __esm({
|
|
|
557
871
|
* Sets a value in storage.
|
|
558
872
|
* @param name The key to set.
|
|
559
873
|
* @param value The value to store (objects, arrays, primitives).
|
|
560
|
-
* @
|
|
874
|
+
* @param opts Optional { encrypt: key } to encrypt the value before storage.
|
|
875
|
+
* If a default key was configured via store.config(), it is used automatically.
|
|
876
|
+
* When encryption is used, returns a Promise<boolean>.
|
|
877
|
+
* @returns true if written, false if rejected or error.
|
|
561
878
|
*/
|
|
562
879
|
set: {
|
|
563
|
-
value: /* @__PURE__ */ __name((name, value) => {
|
|
880
|
+
value: /* @__PURE__ */ __name((name, value, opts) => {
|
|
564
881
|
if (!name) {
|
|
565
882
|
console.warn("[memorio store] store.set() called with empty or null key - write aborted");
|
|
566
883
|
return false;
|
|
@@ -572,15 +889,66 @@ var init_store = __esm({
|
|
|
572
889
|
exports.message("Storing functions is not secure and is blocked for safety.");
|
|
573
890
|
return false;
|
|
574
891
|
}
|
|
892
|
+
if (_maxObjectSize > 0 || _maxTotalSize > 0) {
|
|
893
|
+
let serializedSize = 0;
|
|
894
|
+
try {
|
|
895
|
+
serializedSize = new TextEncoder().encode(JSON.stringify(value)).length;
|
|
896
|
+
} catch {
|
|
897
|
+
serializedSize = 0;
|
|
898
|
+
}
|
|
899
|
+
if (_maxObjectSize > 0 && serializedSize > _maxObjectSize) {
|
|
900
|
+
const err = new Error(`Object size (${serializedSize} bytes) exceeds maxObjectSize (${_maxObjectSize} bytes)`);
|
|
901
|
+
_onError?.(err, { operation: "set" });
|
|
902
|
+
return false;
|
|
903
|
+
}
|
|
904
|
+
if (_maxTotalSize > 0) {
|
|
905
|
+
const currentTotal = exports.store.size() * 1024;
|
|
906
|
+
const existingItemSize = _hasStorage ? _localStorage.getItem(prefixedName)?.length ?? 0 : _getFallbackStorage().get(prefixedName)?.length ?? 0;
|
|
907
|
+
const projected = currentTotal * 1024 - existingItemSize + serializedSize;
|
|
908
|
+
if (projected > _maxTotalSize) {
|
|
909
|
+
const err = new Error(`Total store size (${projected} bytes) exceeds maxTotalSize (${_maxTotalSize} bytes)`);
|
|
910
|
+
_onError?.(err, { operation: "set" });
|
|
911
|
+
return false;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
const key = opts?.encrypt ?? _encryptionKey;
|
|
916
|
+
if (key) {
|
|
917
|
+
return exports.encryption.encrypt(value, key).then((env) => {
|
|
918
|
+
_write(prefixedName, env);
|
|
919
|
+
return true;
|
|
920
|
+
}).catch((err) => {
|
|
921
|
+
exports.message(`Error encrypting store item '${name}': ${err}`);
|
|
922
|
+
_onError?.(err, { operation: "set" });
|
|
923
|
+
return false;
|
|
924
|
+
});
|
|
925
|
+
}
|
|
575
926
|
try {
|
|
576
927
|
_write(prefixedName, value);
|
|
577
928
|
} catch (err) {
|
|
578
929
|
exports.message(`Error setting store item '${name}': ${err}`);
|
|
930
|
+
_onError?.(err, { operation: "set" });
|
|
579
931
|
return false;
|
|
580
932
|
}
|
|
581
933
|
return true;
|
|
582
934
|
}, "value")
|
|
583
935
|
},
|
|
936
|
+
/**
|
|
937
|
+
* Configure store-wide behavior.
|
|
938
|
+
* @param opts Optional { encryptionKey } to enable automatic encryption
|
|
939
|
+
* for all set/get operations. When set, values are encrypted
|
|
940
|
+
* on write and decrypted on read (if the value is an envelope).
|
|
941
|
+
* @returns The store instance for chaining.
|
|
942
|
+
*/
|
|
943
|
+
config: {
|
|
944
|
+
value: /* @__PURE__ */ __name((opts) => {
|
|
945
|
+
if (opts.encryptionKey !== void 0) _encryptionKey = opts.encryptionKey;
|
|
946
|
+
if (opts.onError !== void 0) _onError = opts.onError;
|
|
947
|
+
if (opts.maxObjectSize !== void 0) _maxObjectSize = opts.maxObjectSize;
|
|
948
|
+
if (opts.maxTotalSize !== void 0) _maxTotalSize = opts.maxTotalSize;
|
|
949
|
+
return exports.store;
|
|
950
|
+
}, "value")
|
|
951
|
+
},
|
|
584
952
|
/**
|
|
585
953
|
* Removes a value from storage.
|
|
586
954
|
* @param name The key to remove.
|
|
@@ -1166,6 +1534,91 @@ var init_idb = __esm({
|
|
|
1166
1534
|
}
|
|
1167
1535
|
});
|
|
1168
1536
|
|
|
1537
|
+
// functions/sqlite/tools/bun-sqlite-adapter.ts
|
|
1538
|
+
var bun_sqlite_adapter_exports = {};
|
|
1539
|
+
__export(bun_sqlite_adapter_exports, {
|
|
1540
|
+
BunSqlJsDatabase: () => BunSqlJsDatabase,
|
|
1541
|
+
createBunSqlJs: () => createBunSqlJs
|
|
1542
|
+
});
|
|
1543
|
+
async function _loadDatabase() {
|
|
1544
|
+
if (!_DatabaseClass) {
|
|
1545
|
+
const mod = await import('bun:sqlite');
|
|
1546
|
+
_DatabaseClass = mod.Database;
|
|
1547
|
+
}
|
|
1548
|
+
return _DatabaseClass;
|
|
1549
|
+
}
|
|
1550
|
+
async function createBunSqlJs() {
|
|
1551
|
+
await _loadDatabase();
|
|
1552
|
+
return {
|
|
1553
|
+
Database: BunSqlJsDatabase,
|
|
1554
|
+
version: "bun:sqlite"
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
var _DatabaseClass, BunSqlJsDatabase;
|
|
1558
|
+
var init_bun_sqlite_adapter = __esm({
|
|
1559
|
+
"functions/sqlite/tools/bun-sqlite-adapter.ts"() {
|
|
1560
|
+
init_cjs_shims();
|
|
1561
|
+
_DatabaseClass = null;
|
|
1562
|
+
__name(_loadDatabase, "_loadDatabase");
|
|
1563
|
+
BunSqlJsDatabase = class {
|
|
1564
|
+
static {
|
|
1565
|
+
__name(this, "BunSqlJsDatabase");
|
|
1566
|
+
}
|
|
1567
|
+
_db;
|
|
1568
|
+
_lastRunChanges = 0;
|
|
1569
|
+
constructor(data) {
|
|
1570
|
+
this._lastRunChanges = 0;
|
|
1571
|
+
if (typeof data === "string") {
|
|
1572
|
+
this._db = new _DatabaseClass(data);
|
|
1573
|
+
} else {
|
|
1574
|
+
this._db = new _DatabaseClass(":memory:");
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
run(sql, params = []) {
|
|
1578
|
+
const info = this._db.run(sql, ...params);
|
|
1579
|
+
this._lastRunChanges = info?.changes ?? 0;
|
|
1580
|
+
return info;
|
|
1581
|
+
}
|
|
1582
|
+
getRowsModified() {
|
|
1583
|
+
return this._lastRunChanges;
|
|
1584
|
+
}
|
|
1585
|
+
prepare(sql, params = []) {
|
|
1586
|
+
const rows = params.length > 0 ? this._db.query(sql).all(...params) : this._db.query(sql).all();
|
|
1587
|
+
return {
|
|
1588
|
+
_rows: rows,
|
|
1589
|
+
_idx: -1,
|
|
1590
|
+
step() {
|
|
1591
|
+
this._idx++;
|
|
1592
|
+
return this._idx < this._rows.length;
|
|
1593
|
+
},
|
|
1594
|
+
getAsObject() {
|
|
1595
|
+
return this._rows[this._idx] || {};
|
|
1596
|
+
},
|
|
1597
|
+
get() {
|
|
1598
|
+
return this._rows[this._idx] ? Object.values(this._rows[this._idx]) : [];
|
|
1599
|
+
},
|
|
1600
|
+
free() {
|
|
1601
|
+
this._rows = null;
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1604
|
+
}
|
|
1605
|
+
export() {
|
|
1606
|
+
throw new Error("Bun:sqlite does not support in-memory export - use store/session for persistence, or use the sql.js backend for export/import operations");
|
|
1607
|
+
}
|
|
1608
|
+
close() {
|
|
1609
|
+
try {
|
|
1610
|
+
this._db.close();
|
|
1611
|
+
} catch {
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
get version() {
|
|
1615
|
+
return "bun:sqlite";
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1618
|
+
__name(createBunSqlJs, "createBunSqlJs");
|
|
1619
|
+
}
|
|
1620
|
+
});
|
|
1621
|
+
|
|
1169
1622
|
// functions/sqlite/tools/db.support.ts
|
|
1170
1623
|
var db_support_exports2 = {};
|
|
1171
1624
|
function _inDocument() {
|
|
@@ -1226,11 +1679,18 @@ var init_db_support2 = __esm({
|
|
|
1226
1679
|
return g3.initSqlJs || g3;
|
|
1227
1680
|
}, "_loadSqlJsFromCdn");
|
|
1228
1681
|
exports.sqlite.db.support = () => {
|
|
1229
|
-
return hasSqlJs();
|
|
1682
|
+
return hasSqlJs() || hasBunSqlite();
|
|
1230
1683
|
};
|
|
1231
1684
|
exports.sqlite.db.getSQL = async () => {
|
|
1232
1685
|
if (_SQL) return _SQL;
|
|
1233
1686
|
if (_loading) return _loading;
|
|
1687
|
+
if (hasBunSqlite()) {
|
|
1688
|
+
const { createBunSqlJs: createBunSqlJs2 } = await Promise.resolve().then(() => (init_bun_sqlite_adapter(), bun_sqlite_adapter_exports));
|
|
1689
|
+
_SQL = await createBunSqlJs2();
|
|
1690
|
+
globalThis.sqliteVersion = _SQL.version;
|
|
1691
|
+
message_default("Memorio SQLite: bun:sqlite engine loaded");
|
|
1692
|
+
return _SQL;
|
|
1693
|
+
}
|
|
1234
1694
|
const g3 = globalThis;
|
|
1235
1695
|
const cfg = g3.sqliteConfig || {};
|
|
1236
1696
|
const p = (async () => {
|
|
@@ -1257,7 +1717,7 @@ var init_db_support2 = __esm({
|
|
|
1257
1717
|
} catch (_) {
|
|
1258
1718
|
}
|
|
1259
1719
|
try {
|
|
1260
|
-
exports.sqlite._warning = "Memorio SQLite: sql.js could not be loaded. Install sql.js (npm i sql.js) and pass a loader via sqlite.config({ loader: () => <your sql.js import>() }).";
|
|
1720
|
+
exports.sqlite._warning = "Memorio SQLite: sql.js could not be loaded. Install sql.js (npm i sql.js) and pass a loader via sqlite.config({ loader: () => import(<your sql.js import>()) }).";
|
|
1261
1721
|
} catch (_) {
|
|
1262
1722
|
}
|
|
1263
1723
|
console.warn("Memorio SQLite: failed to load sql.js", err);
|
|
@@ -1280,7 +1740,7 @@ function _ns() {
|
|
|
1280
1740
|
function _key(name) {
|
|
1281
1741
|
return `memorio:sqlite:db:${_ns()}:${name}`;
|
|
1282
1742
|
}
|
|
1283
|
-
function
|
|
1743
|
+
function _b64encode2(buf) {
|
|
1284
1744
|
const bytes = buf instanceof Uint8Array ? buf : new Uint8Array(buf);
|
|
1285
1745
|
let binary = "";
|
|
1286
1746
|
const len = bytes.byteLength;
|
|
@@ -1288,7 +1748,7 @@ function _b64encode(buf) {
|
|
|
1288
1748
|
if (typeof btoa === "function") return btoa(binary);
|
|
1289
1749
|
return typeof Buffer !== "undefined" ? Buffer.from(bytes).toString("base64") : "";
|
|
1290
1750
|
}
|
|
1291
|
-
function
|
|
1751
|
+
function _b64decode2(b64) {
|
|
1292
1752
|
if (typeof Buffer !== "undefined") {
|
|
1293
1753
|
return new Uint8Array(Buffer.from(b64, "base64"));
|
|
1294
1754
|
}
|
|
@@ -1310,7 +1770,7 @@ function saveSnapshot(name) {
|
|
|
1310
1770
|
}
|
|
1311
1771
|
try {
|
|
1312
1772
|
const blob = db.export();
|
|
1313
|
-
exports.store.set(_key(name),
|
|
1773
|
+
exports.store.set(_key(name), _b64encode2(blob));
|
|
1314
1774
|
message_default(`Memorio SQLite: persisted '${name}' to store`);
|
|
1315
1775
|
resolve(true);
|
|
1316
1776
|
} catch (err) {
|
|
@@ -1323,7 +1783,7 @@ function loadSnapshot(name) {
|
|
|
1323
1783
|
const b64 = exports.store.get(_key(name));
|
|
1324
1784
|
if (!b64) return null;
|
|
1325
1785
|
try {
|
|
1326
|
-
return
|
|
1786
|
+
return _b64decode2(b64);
|
|
1327
1787
|
} catch {
|
|
1328
1788
|
return null;
|
|
1329
1789
|
}
|
|
@@ -1358,8 +1818,8 @@ var init_persist = __esm({
|
|
|
1358
1818
|
_exportTimers = {};
|
|
1359
1819
|
__name(_ns, "_ns");
|
|
1360
1820
|
__name(_key, "_key");
|
|
1361
|
-
__name(
|
|
1362
|
-
__name(
|
|
1821
|
+
__name(_b64encode2, "_b64encode");
|
|
1822
|
+
__name(_b64decode2, "_b64decode");
|
|
1363
1823
|
__name(saveSnapshot, "saveSnapshot");
|
|
1364
1824
|
__name(loadSnapshot, "loadSnapshot");
|
|
1365
1825
|
__name(removeSnapshot, "removeSnapshot");
|
|
@@ -1564,7 +2024,14 @@ var init_db_export = __esm({
|
|
|
1564
2024
|
init_sqlite();
|
|
1565
2025
|
exports.sqlite.db.export = async (name = "memorio") => {
|
|
1566
2026
|
const db = exports.sqlite.db.get(name);
|
|
1567
|
-
|
|
2027
|
+
try {
|
|
2028
|
+
return db.export();
|
|
2029
|
+
} catch (err) {
|
|
2030
|
+
if (db && db.version === "bun:sqlite") {
|
|
2031
|
+
throw new Error(`memorio sqlite: export is not supported under Bun's native sqlite. Use \`store\` or \`session\` for persistence instead. If you need a binary dump, run this code under the browser/sql.js backend.`);
|
|
2032
|
+
}
|
|
2033
|
+
throw err;
|
|
2034
|
+
}
|
|
1568
2035
|
};
|
|
1569
2036
|
}
|
|
1570
2037
|
});
|
|
@@ -1648,13 +2115,14 @@ var init_data_get2 = __esm({
|
|
|
1648
2115
|
});
|
|
1649
2116
|
|
|
1650
2117
|
// functions/sqlite/index.ts
|
|
1651
|
-
var _hasSqlJs; exports.sqlite = void 0;
|
|
2118
|
+
var _hasSqlJs, _hasBunSqlite; exports.sqlite = void 0;
|
|
1652
2119
|
var init_sqlite = __esm({
|
|
1653
2120
|
"functions/sqlite/index.ts"() {
|
|
1654
2121
|
init_cjs_shims();
|
|
1655
2122
|
init_platform();
|
|
1656
2123
|
init_env();
|
|
1657
2124
|
_hasSqlJs = hasSqlJs();
|
|
2125
|
+
_hasBunSqlite = hasBunSqlite();
|
|
1658
2126
|
exports.sqlite = {
|
|
1659
2127
|
db: {},
|
|
1660
2128
|
query: {},
|
|
@@ -1681,7 +2149,7 @@ var init_sqlite = __esm({
|
|
|
1681
2149
|
return g3.sqliteReady;
|
|
1682
2150
|
}, "get")
|
|
1683
2151
|
});
|
|
1684
|
-
if (_hasSqlJs) {
|
|
2152
|
+
if (_hasSqlJs || _hasBunSqlite) {
|
|
1685
2153
|
(async () => {
|
|
1686
2154
|
Object.defineProperty(exports.sqlite, "db", { value: {}, writable: false, configurable: true, enumerable: true });
|
|
1687
2155
|
Object.defineProperty(exports.sqlite, "query", { value: {}, writable: false, configurable: true, enumerable: true });
|
|
@@ -1709,11 +2177,11 @@ var init_sqlite = __esm({
|
|
|
1709
2177
|
})();
|
|
1710
2178
|
} else {
|
|
1711
2179
|
exports.sqlite._disabled = true;
|
|
1712
|
-
exports.sqlite._warning = 'SQLite
|
|
2180
|
+
exports.sqlite._warning = 'SQLite is not available in this environment. It requires a browser with WebAssembly (sql.js) or the Bun runtime (bun:sqlite). Install the optional "sql.js" package to enable it in browsers.';
|
|
1713
2181
|
if (exports.DEV) {
|
|
1714
2182
|
globalThis.sqliteDisabled = true;
|
|
1715
2183
|
globalThis.sqliteWarning = exports.sqlite._warning;
|
|
1716
|
-
console.warn("Memorio SQLite:
|
|
2184
|
+
console.warn("Memorio SQLite: no engine available in this environment (requires browser + WebAssembly, or Bun runtime with bun:sqlite). Use store or session for persistence.");
|
|
1717
2185
|
}
|
|
1718
2186
|
}
|
|
1719
2187
|
}
|
|
@@ -2728,6 +3196,7 @@ init_cjs_shims();
|
|
|
2728
3196
|
init_platform();
|
|
2729
3197
|
init_internal();
|
|
2730
3198
|
init_message();
|
|
3199
|
+
init_encryption();
|
|
2731
3200
|
var _sessionStorage = getSessionStorage();
|
|
2732
3201
|
var _fallbackStorageByContext2 = /* @__PURE__ */ new Map();
|
|
2733
3202
|
function _getFallbackStorage2() {
|
|
@@ -2740,6 +3209,14 @@ function _getFallbackStorage2() {
|
|
|
2740
3209
|
}
|
|
2741
3210
|
__name(_getFallbackStorage2, "_getFallbackStorage");
|
|
2742
3211
|
var _hasStorage2 = _sessionStorage !== null;
|
|
3212
|
+
var _encryptionKey2 = null;
|
|
3213
|
+
var _onError2 = null;
|
|
3214
|
+
var _maxObjectSize2 = 0;
|
|
3215
|
+
var _maxTotalSize2 = 0;
|
|
3216
|
+
function _isEncryptedEnvelope2(value) {
|
|
3217
|
+
return exports.encryption.isEncrypted(value);
|
|
3218
|
+
}
|
|
3219
|
+
__name(_isEncryptedEnvelope2, "_isEncryptedEnvelope");
|
|
2743
3220
|
function _getPrefix2() {
|
|
2744
3221
|
const contextName = exports.internal.currentContext || "";
|
|
2745
3222
|
return contextName ? `${contextName}-` : `memorio_session_`;
|
|
@@ -2793,16 +3270,22 @@ if (globalThis[SESSION_INSTANCE_KEY]) {
|
|
|
2793
3270
|
/**
|
|
2794
3271
|
* Gets a value from storage.
|
|
2795
3272
|
* @param name The key to retrieve.
|
|
2796
|
-
* @
|
|
3273
|
+
* @param opts Optional { decrypt: key } to decrypt an encrypted envelope.
|
|
3274
|
+
* @returns The parsed value, a Promise when decrypting, or null if not found.
|
|
2797
3275
|
*/
|
|
2798
3276
|
get: {
|
|
2799
|
-
value: /* @__PURE__ */ __name((name) => {
|
|
3277
|
+
value: /* @__PURE__ */ __name((name, opts) => {
|
|
2800
3278
|
if (!name) {
|
|
2801
3279
|
console.warn("[memorio session] session.get() called with empty or null key - returning null");
|
|
2802
3280
|
return null;
|
|
2803
3281
|
}
|
|
2804
3282
|
try {
|
|
2805
|
-
|
|
3283
|
+
const raw = _read2(_prefixKey2(name));
|
|
3284
|
+
const key = opts?.decrypt ?? _encryptionKey2;
|
|
3285
|
+
if (key && _isEncryptedEnvelope2(raw)) {
|
|
3286
|
+
return exports.encryption.decrypt(raw, key);
|
|
3287
|
+
}
|
|
3288
|
+
return raw;
|
|
2806
3289
|
} catch (err) {
|
|
2807
3290
|
exports.message(`Error parsing session item '${name}':${err}`);
|
|
2808
3291
|
}
|
|
@@ -2813,10 +3296,11 @@ if (globalThis[SESSION_INSTANCE_KEY]) {
|
|
|
2813
3296
|
* Sets a value in storage.
|
|
2814
3297
|
* @param name The key to set.
|
|
2815
3298
|
* @param value The value to store.
|
|
2816
|
-
* @
|
|
3299
|
+
* @param opts Optional { encrypt: key } to encrypt before storage.
|
|
3300
|
+
* @returns true if written, false if rejected. Returns a Promise when encrypting.
|
|
2817
3301
|
*/
|
|
2818
3302
|
set: {
|
|
2819
|
-
value: /* @__PURE__ */ __name((name, value) => {
|
|
3303
|
+
value: /* @__PURE__ */ __name((name, value, opts) => {
|
|
2820
3304
|
if (!name) {
|
|
2821
3305
|
console.warn("[memorio session] session.set() called with empty or null key - write aborted");
|
|
2822
3306
|
return false;
|
|
@@ -2828,15 +3312,63 @@ if (globalThis[SESSION_INSTANCE_KEY]) {
|
|
|
2828
3312
|
exports.message("It's not secure to session functions.");
|
|
2829
3313
|
return false;
|
|
2830
3314
|
}
|
|
3315
|
+
if (_maxObjectSize2 > 0 || _maxTotalSize2 > 0) {
|
|
3316
|
+
let serializedSize = 0;
|
|
3317
|
+
try {
|
|
3318
|
+
serializedSize = new TextEncoder().encode(JSON.stringify(value)).length;
|
|
3319
|
+
} catch {
|
|
3320
|
+
serializedSize = 0;
|
|
3321
|
+
}
|
|
3322
|
+
if (_maxObjectSize2 > 0 && serializedSize > _maxObjectSize2) {
|
|
3323
|
+
const err = new Error(`Object size (${serializedSize} bytes) exceeds maxObjectSize (${_maxObjectSize2} bytes)`);
|
|
3324
|
+
_onError2?.(err, { operation: "set" });
|
|
3325
|
+
return false;
|
|
3326
|
+
}
|
|
3327
|
+
if (_maxTotalSize2 > 0) {
|
|
3328
|
+
const currentTotal = exports.session.size() * 1024;
|
|
3329
|
+
const existingItemSize = _sessionStorage ? _sessionStorage.getItem(prefixedName)?.length ?? 0 : _getFallbackStorage2().get(prefixedName)?.length ?? 0;
|
|
3330
|
+
const projected = currentTotal - existingItemSize + serializedSize;
|
|
3331
|
+
if (projected > _maxTotalSize2) {
|
|
3332
|
+
const err = new Error(`Total session size (${projected} bytes) exceeds maxTotalSize (${_maxTotalSize2} bytes)`);
|
|
3333
|
+
_onError2?.(err, { operation: "set" });
|
|
3334
|
+
return false;
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
}
|
|
3338
|
+
const key = opts?.encrypt ?? _encryptionKey2;
|
|
3339
|
+
if (key) {
|
|
3340
|
+
return exports.encryption.encrypt(value, key).then((env) => {
|
|
3341
|
+
_write2(prefixedName, env);
|
|
3342
|
+
return true;
|
|
3343
|
+
}).catch((err) => {
|
|
3344
|
+
exports.message(`Error encrypting session item '${name}': ${err}`);
|
|
3345
|
+
_onError2?.(err, { operation: "set" });
|
|
3346
|
+
return false;
|
|
3347
|
+
});
|
|
3348
|
+
}
|
|
2831
3349
|
try {
|
|
2832
3350
|
_write2(prefixedName, value);
|
|
2833
3351
|
} catch (err) {
|
|
2834
3352
|
exports.message(`Error setting session item '${name}': ${err}`);
|
|
3353
|
+
_onError2?.(err, { operation: "set" });
|
|
2835
3354
|
return false;
|
|
2836
3355
|
}
|
|
2837
3356
|
return true;
|
|
2838
3357
|
}, "value")
|
|
2839
3358
|
},
|
|
3359
|
+
/**
|
|
3360
|
+
* Configure session-wide behavior.
|
|
3361
|
+
* @param opts { encryptionKey, onError, maxObjectSize, maxTotalSize }
|
|
3362
|
+
*/
|
|
3363
|
+
config: {
|
|
3364
|
+
value: /* @__PURE__ */ __name((opts) => {
|
|
3365
|
+
if (opts.encryptionKey !== void 0) _encryptionKey2 = opts.encryptionKey;
|
|
3366
|
+
if (opts.onError !== void 0) _onError2 = opts.onError;
|
|
3367
|
+
if (opts.maxObjectSize !== void 0) _maxObjectSize2 = opts.maxObjectSize;
|
|
3368
|
+
if (opts.maxTotalSize !== void 0) _maxTotalSize2 = opts.maxTotalSize;
|
|
3369
|
+
return exports.session;
|
|
3370
|
+
}, "value")
|
|
3371
|
+
},
|
|
2840
3372
|
/**
|
|
2841
3373
|
* Removes a value from storage.
|
|
2842
3374
|
* @param name The key to remove.
|
|
@@ -3203,92 +3735,685 @@ var useObserver = /* @__PURE__ */ __name(((func, deps = []) => {
|
|
|
3203
3735
|
}), "useObserver");
|
|
3204
3736
|
|
|
3205
3737
|
// index.ts
|
|
3206
|
-
|
|
3738
|
+
init_encryption();
|
|
3207
3739
|
|
|
3208
|
-
// functions/
|
|
3740
|
+
// functions/computed/index.ts
|
|
3209
3741
|
init_cjs_shims();
|
|
3210
|
-
init_internal();
|
|
3211
|
-
init_message();
|
|
3212
3742
|
init_env();
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3743
|
+
init_message();
|
|
3744
|
+
var DEFAULT_EQUALITY = /* @__PURE__ */ __name((prev, next) => {
|
|
3745
|
+
if (prev === next) return true;
|
|
3746
|
+
if (prev == null || next == null) return false;
|
|
3747
|
+
if (typeof prev !== typeof next) return false;
|
|
3748
|
+
if (typeof prev !== "object") return false;
|
|
3749
|
+
try {
|
|
3750
|
+
return JSON.stringify(prev) === JSON.stringify(next);
|
|
3751
|
+
} catch {
|
|
3752
|
+
return false;
|
|
3753
|
+
}
|
|
3754
|
+
}, "DEFAULT_EQUALITY");
|
|
3755
|
+
var computedMap = /* @__PURE__ */ new Map();
|
|
3756
|
+
function _normalizeKey(key) {
|
|
3757
|
+
if (!key || typeof key !== "string") return "";
|
|
3758
|
+
const normalized = key.startsWith("state.") ? key : `state.${key}`;
|
|
3759
|
+
return normalized;
|
|
3760
|
+
}
|
|
3761
|
+
__name(_normalizeKey, "_normalizeKey");
|
|
3762
|
+
function _invalidate(key) {
|
|
3763
|
+
const entry = computedMap.get(key);
|
|
3764
|
+
if (!entry) return;
|
|
3765
|
+
const newValue = _recompute(entry);
|
|
3766
|
+
if (entry.equality(entry.lastValue, newValue)) {
|
|
3767
|
+
return;
|
|
3768
|
+
}
|
|
3769
|
+
entry.lastValue = newValue;
|
|
3770
|
+
for (const sub of entry.subscribers) {
|
|
3771
|
+
try {
|
|
3772
|
+
sub(newValue);
|
|
3773
|
+
} catch (err) {
|
|
3774
|
+
if (exports.DEV) console.error("[memorio computed] subscriber error:", err);
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3777
|
+
dispatch.set("memorio:computed:" + key, { detail: { key, value: newValue } });
|
|
3221
3778
|
}
|
|
3222
|
-
__name(
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
}, "configure");
|
|
3228
|
-
var enable = /* @__PURE__ */ __name(() => {
|
|
3229
|
-
config.enabled = true;
|
|
3230
|
-
}, "enable");
|
|
3231
|
-
var disable = /* @__PURE__ */ __name(() => {
|
|
3232
|
-
config.enabled = false;
|
|
3233
|
-
}, "disable");
|
|
3234
|
-
var isEnabled = /* @__PURE__ */ __name((module) => {
|
|
3235
|
-
return config.enabled && config.modules.includes(module);
|
|
3236
|
-
}, "isEnabled");
|
|
3237
|
-
var log = /* @__PURE__ */ __name((module, action, path, value, previousValue) => {
|
|
3238
|
-
if (!isEnabled(module)) return;
|
|
3239
|
-
const entry = {
|
|
3240
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3241
|
-
module,
|
|
3242
|
-
action,
|
|
3243
|
-
path,
|
|
3244
|
-
value,
|
|
3245
|
-
previousValue
|
|
3246
|
-
};
|
|
3247
|
-
logHistory.push(entry);
|
|
3248
|
-
if (logHistory.length > config.maxEntries) {
|
|
3249
|
-
logHistory.shift();
|
|
3779
|
+
__name(_invalidate, "_invalidate");
|
|
3780
|
+
function _readStatePath(path) {
|
|
3781
|
+
const entry = computedMap.get(path);
|
|
3782
|
+
if (entry) {
|
|
3783
|
+
return entry.lastValue;
|
|
3250
3784
|
}
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3785
|
+
const normalized = path.startsWith("state.") ? path : `state.${path}`;
|
|
3786
|
+
const segments = normalized.replace(/^state\./, "").split(".");
|
|
3787
|
+
let current = globalThis.state;
|
|
3788
|
+
if (current) {
|
|
3789
|
+
for (const seg of segments) {
|
|
3790
|
+
if (current === null || current === void 0) break;
|
|
3791
|
+
try {
|
|
3792
|
+
current = current[seg];
|
|
3793
|
+
} catch {
|
|
3794
|
+
return void 0;
|
|
3795
|
+
}
|
|
3261
3796
|
}
|
|
3262
|
-
|
|
3263
|
-
|
|
3797
|
+
}
|
|
3798
|
+
return current === void 0 ? null : current;
|
|
3799
|
+
}
|
|
3800
|
+
__name(_readStatePath, "_readStatePath");
|
|
3801
|
+
function _recompute(entry) {
|
|
3802
|
+
const newDeps = /* @__PURE__ */ new Set();
|
|
3803
|
+
const trackerGet = /* @__PURE__ */ __name((path) => {
|
|
3804
|
+
if (!path || typeof path !== "string") return void 0;
|
|
3805
|
+
newDeps.add(path);
|
|
3806
|
+
return _readStatePath(path);
|
|
3807
|
+
}, "trackerGet");
|
|
3808
|
+
try {
|
|
3809
|
+
return entry.selector(trackerGet);
|
|
3810
|
+
} catch (err) {
|
|
3811
|
+
if (exports.DEV) console.error("[memorio computed] selector error:", err);
|
|
3812
|
+
message_default(`[memorio computed] selector error: ${err}`);
|
|
3813
|
+
return entry.lastValue;
|
|
3814
|
+
}
|
|
3815
|
+
}
|
|
3816
|
+
__name(_recompute, "_recompute");
|
|
3817
|
+
function _setupDeps(key, entry, deps) {
|
|
3818
|
+
for (const off of entry._dispatchUnsubscribers) off();
|
|
3819
|
+
entry._dispatchUnsubscribers = [];
|
|
3820
|
+
for (const dep of deps) {
|
|
3821
|
+
if (computedMap.has(dep)) {
|
|
3822
|
+
const computedEvent = "memorio:computed:" + dep;
|
|
3823
|
+
const off = dispatch.listen(computedEvent, () => _invalidate(key));
|
|
3824
|
+
if (off) entry._dispatchUnsubscribers.push(off);
|
|
3825
|
+
} else {
|
|
3826
|
+
const off = dispatch.listen(dep, () => _invalidate(key));
|
|
3827
|
+
if (off) entry._dispatchUnsubscribers.push(off);
|
|
3264
3828
|
}
|
|
3265
3829
|
}
|
|
3266
|
-
|
|
3267
|
-
|
|
3830
|
+
entry.deps = deps;
|
|
3831
|
+
}
|
|
3832
|
+
__name(_setupDeps, "_setupDeps");
|
|
3833
|
+
function _compute(key, selector, opts) {
|
|
3834
|
+
const normalizedKey = _normalizeKey(key);
|
|
3835
|
+
const cacheKey = opts?.equalityKey ? `${opts.equalityKey}:${normalizedKey}` : normalizedKey;
|
|
3836
|
+
if (computedMap.has(cacheKey)) {
|
|
3837
|
+
const entry2 = computedMap.get(cacheKey);
|
|
3838
|
+
entry2.selector = selector;
|
|
3839
|
+
entry2.equality = opts?.equality || DEFAULT_EQUALITY;
|
|
3840
|
+
const newDeps2 = /* @__PURE__ */ new Set();
|
|
3841
|
+
const wrappedGet = /* @__PURE__ */ __name((path) => {
|
|
3842
|
+
newDeps2.add(path);
|
|
3843
|
+
return _readStatePath(path);
|
|
3844
|
+
}, "wrappedGet");
|
|
3845
|
+
let newValue;
|
|
3846
|
+
try {
|
|
3847
|
+
newValue = selector(wrappedGet);
|
|
3848
|
+
} catch (err) {
|
|
3849
|
+
if (exports.DEV) console.error("[memorio computed] selector error:", err);
|
|
3850
|
+
return entry2.lastValue;
|
|
3851
|
+
}
|
|
3852
|
+
if (entry2.equality(entry2.lastValue, newValue)) {
|
|
3853
|
+
return entry2.lastValue;
|
|
3854
|
+
}
|
|
3855
|
+
entry2.lastValue = newValue;
|
|
3856
|
+
_setupDeps(cacheKey, entry2, newDeps2);
|
|
3857
|
+
for (const sub of entry2.subscribers) {
|
|
3858
|
+
try {
|
|
3859
|
+
sub(newValue);
|
|
3860
|
+
} catch (err) {
|
|
3861
|
+
if (exports.DEV) console.error("[memorio computed] subscriber error:", err);
|
|
3862
|
+
}
|
|
3863
|
+
}
|
|
3864
|
+
return newValue;
|
|
3865
|
+
}
|
|
3866
|
+
const newDeps = /* @__PURE__ */ new Set();
|
|
3867
|
+
const get = /* @__PURE__ */ __name((path) => {
|
|
3868
|
+
newDeps.add(path);
|
|
3869
|
+
return _readStatePath(path);
|
|
3870
|
+
}, "get");
|
|
3871
|
+
let lastValue;
|
|
3872
|
+
try {
|
|
3873
|
+
lastValue = selector(get);
|
|
3874
|
+
} catch (err) {
|
|
3875
|
+
if (exports.DEV) console.error("[memorio computed] selector error:", err);
|
|
3876
|
+
message_default(`[memorio computed] selector error: ${err}`);
|
|
3877
|
+
lastValue = null;
|
|
3268
3878
|
}
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
idb: "#F44336"
|
|
3879
|
+
const entry = {
|
|
3880
|
+
selector,
|
|
3881
|
+
lastValue,
|
|
3882
|
+
deps: newDeps,
|
|
3883
|
+
equality: opts?.equality || DEFAULT_EQUALITY,
|
|
3884
|
+
subscribers: /* @__PURE__ */ new Set(),
|
|
3885
|
+
_dispatchUnsubscribers: []
|
|
3277
3886
|
};
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3887
|
+
computedMap.set(cacheKey, entry);
|
|
3888
|
+
_setupDeps(cacheKey, entry, newDeps);
|
|
3889
|
+
return lastValue;
|
|
3890
|
+
}
|
|
3891
|
+
__name(_compute, "_compute");
|
|
3892
|
+
function _getValue(key) {
|
|
3893
|
+
const normalizedKey = _normalizeKey(key);
|
|
3894
|
+
const entry = computedMap.get(normalizedKey);
|
|
3895
|
+
if (!entry) return null;
|
|
3896
|
+
return entry.lastValue;
|
|
3897
|
+
}
|
|
3898
|
+
__name(_getValue, "_getValue");
|
|
3899
|
+
function _subscribe(key, cb) {
|
|
3900
|
+
const normalizedKey = _normalizeKey(key);
|
|
3901
|
+
const entry = computedMap.get(normalizedKey);
|
|
3902
|
+
if (!entry) {
|
|
3903
|
+
if (exports.DEV) console.warn(`[memorio computed] subscribe: no computed value registered for key '${key}'`);
|
|
3904
|
+
return () => {
|
|
3905
|
+
};
|
|
3906
|
+
}
|
|
3907
|
+
entry.subscribers.add(cb);
|
|
3908
|
+
return () => {
|
|
3909
|
+
entry.subscribers.delete(cb);
|
|
3910
|
+
};
|
|
3911
|
+
}
|
|
3912
|
+
__name(_subscribe, "_subscribe");
|
|
3913
|
+
function _remove3(key) {
|
|
3914
|
+
const normalizedKey = _normalizeKey(key);
|
|
3915
|
+
if (!computedMap.has(normalizedKey)) return false;
|
|
3916
|
+
const entry = computedMap.get(normalizedKey);
|
|
3917
|
+
for (const off of entry._dispatchUnsubscribers) off();
|
|
3918
|
+
computedMap.delete(normalizedKey);
|
|
3919
|
+
return true;
|
|
3920
|
+
}
|
|
3921
|
+
__name(_remove3, "_remove");
|
|
3922
|
+
function _list() {
|
|
3923
|
+
return Array.from(computedMap.keys());
|
|
3924
|
+
}
|
|
3925
|
+
__name(_list, "_list");
|
|
3926
|
+
function _clear() {
|
|
3927
|
+
for (const [, entry] of computedMap) {
|
|
3928
|
+
for (const off of entry._dispatchUnsubscribers) off();
|
|
3929
|
+
}
|
|
3930
|
+
computedMap.clear();
|
|
3931
|
+
}
|
|
3932
|
+
__name(_clear, "_clear");
|
|
3933
|
+
var computed = {
|
|
3934
|
+
compute: _compute,
|
|
3935
|
+
getValue: _getValue,
|
|
3936
|
+
subscribe: _subscribe,
|
|
3937
|
+
remove: _remove3,
|
|
3938
|
+
list: _list,
|
|
3939
|
+
clear: _clear
|
|
3940
|
+
};
|
|
3941
|
+
|
|
3942
|
+
// functions/broadcast/index.ts
|
|
3943
|
+
init_cjs_shims();
|
|
3944
|
+
init_env();
|
|
3945
|
+
init_message();
|
|
3946
|
+
var _channel = null;
|
|
3947
|
+
var _storageListener = null;
|
|
3948
|
+
var _originalDispatchSet = null;
|
|
3949
|
+
var _installed = false;
|
|
3950
|
+
var _targets = "all";
|
|
3951
|
+
var _isLocalChange = false;
|
|
3952
|
+
function _hasBroadcastChannel() {
|
|
3953
|
+
return typeof BroadcastChannel !== "undefined";
|
|
3954
|
+
}
|
|
3955
|
+
__name(_hasBroadcastChannel, "_hasBroadcastChannel");
|
|
3956
|
+
function _hasStorageEvents() {
|
|
3957
|
+
return typeof window !== "undefined" && "addEventListener" in window;
|
|
3958
|
+
}
|
|
3959
|
+
__name(_hasStorageEvents, "_hasStorageEvents");
|
|
3960
|
+
function _shouldSync(target) {
|
|
3961
|
+
if (_targets === "all") return true;
|
|
3962
|
+
return _targets === target;
|
|
3963
|
+
}
|
|
3964
|
+
__name(_shouldSync, "_shouldSync");
|
|
3965
|
+
function _onBroadcastMessage(event) {
|
|
3966
|
+
let msg;
|
|
3967
|
+
try {
|
|
3968
|
+
msg = event.data;
|
|
3969
|
+
} catch {
|
|
3970
|
+
return;
|
|
3971
|
+
}
|
|
3972
|
+
if (!msg || !msg.__memorio_sync) return;
|
|
3973
|
+
if (!_shouldSync(msg.target)) return;
|
|
3974
|
+
if (_isLocalChange) return;
|
|
3975
|
+
try {
|
|
3976
|
+
if (msg.target === "state" || msg.target === "all") {
|
|
3977
|
+
const s = globalThis.state;
|
|
3978
|
+
if (s) {
|
|
3979
|
+
_isLocalChange = true;
|
|
3980
|
+
try {
|
|
3981
|
+
const segments = msg.path.replace(/^state\./, "").split(".");
|
|
3982
|
+
let current = s;
|
|
3983
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
3984
|
+
const seg = segments[i];
|
|
3985
|
+
if (current[seg] === void 0 || current[seg] === null) {
|
|
3986
|
+
current[seg] = {};
|
|
3987
|
+
}
|
|
3988
|
+
current = current[seg];
|
|
3989
|
+
}
|
|
3990
|
+
const lastSeg = segments[segments.length - 1];
|
|
3991
|
+
if (msg.action === "set") {
|
|
3992
|
+
current[lastSeg] = msg.value;
|
|
3993
|
+
} else if (msg.action === "delete") {
|
|
3994
|
+
delete current[lastSeg];
|
|
3995
|
+
}
|
|
3996
|
+
} finally {
|
|
3997
|
+
queueMicrotask(() => {
|
|
3998
|
+
_isLocalChange = false;
|
|
3999
|
+
});
|
|
4000
|
+
}
|
|
4001
|
+
}
|
|
4002
|
+
}
|
|
4003
|
+
} catch (err) {
|
|
4004
|
+
if (exports.DEV) console.error("[memorio broadcast] apply state error:", err);
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
__name(_onBroadcastMessage, "_onBroadcastMessage");
|
|
4008
|
+
function _onStorageEvent(e) {
|
|
4009
|
+
if (!e.key) return;
|
|
4010
|
+
const prefixes = [
|
|
4011
|
+
["memorio_store_", "store"],
|
|
4012
|
+
["memorio_session_", "session"]
|
|
4013
|
+
];
|
|
4014
|
+
for (const [prefix, target] of prefixes) {
|
|
4015
|
+
if (e.key.startsWith(prefix)) {
|
|
4016
|
+
if (!_shouldSync(target)) continue;
|
|
4017
|
+
const cleanKey = e.key.slice(prefix.length);
|
|
4018
|
+
dispatch.set(`memorio:broadcast:${target}:${cleanKey}`, {
|
|
4019
|
+
detail: { key: cleanKey, oldValue: e.oldValue, newValue: e.newValue }
|
|
4020
|
+
});
|
|
4021
|
+
break;
|
|
4022
|
+
}
|
|
4023
|
+
}
|
|
4024
|
+
}
|
|
4025
|
+
__name(_onStorageEvent, "_onStorageEvent");
|
|
4026
|
+
function _wrapDispatchSet() {
|
|
4027
|
+
if (_originalDispatchSet !== null) return;
|
|
4028
|
+
_originalDispatchSet = dispatch.set;
|
|
4029
|
+
const original = dispatch.set;
|
|
4030
|
+
dispatch.set = (name, value) => {
|
|
4031
|
+
original(name, value);
|
|
4032
|
+
if (name.startsWith("state.") && _shouldSync("state") && _channel) {
|
|
4033
|
+
_isLocalChange = true;
|
|
4034
|
+
try {
|
|
4035
|
+
_channel.postMessage({
|
|
4036
|
+
__memorio_sync: true,
|
|
4037
|
+
target: "state",
|
|
4038
|
+
action: "set",
|
|
4039
|
+
path: name,
|
|
4040
|
+
value: _extractStateValue(name),
|
|
4041
|
+
timestamp: Date.now()
|
|
4042
|
+
});
|
|
4043
|
+
} finally {
|
|
4044
|
+
queueMicrotask(() => {
|
|
4045
|
+
_isLocalChange = false;
|
|
4046
|
+
});
|
|
4047
|
+
}
|
|
4048
|
+
}
|
|
4049
|
+
};
|
|
4050
|
+
}
|
|
4051
|
+
__name(_wrapDispatchSet, "_wrapDispatchSet");
|
|
4052
|
+
function _restoreDispatchSet() {
|
|
4053
|
+
if (_originalDispatchSet !== null) {
|
|
4054
|
+
dispatch.set = _originalDispatchSet;
|
|
4055
|
+
_originalDispatchSet = null;
|
|
4056
|
+
}
|
|
4057
|
+
}
|
|
4058
|
+
__name(_restoreDispatchSet, "_restoreDispatchSet");
|
|
4059
|
+
function _extractStateValue(path) {
|
|
4060
|
+
const s = globalThis.state;
|
|
4061
|
+
if (!s) return void 0;
|
|
4062
|
+
try {
|
|
4063
|
+
const segments = path.replace(/^state\./, "").split(".");
|
|
4064
|
+
let current = s;
|
|
4065
|
+
for (const seg of segments) {
|
|
4066
|
+
if (current === null || current === void 0) break;
|
|
4067
|
+
current = current[seg];
|
|
4068
|
+
}
|
|
4069
|
+
return current === void 0 ? null : current;
|
|
4070
|
+
} catch {
|
|
4071
|
+
return null;
|
|
4072
|
+
}
|
|
4073
|
+
}
|
|
4074
|
+
__name(_extractStateValue, "_extractStateValue");
|
|
4075
|
+
var broadcast = {
|
|
4076
|
+
install: /* @__PURE__ */ __name((channelName, opts) => {
|
|
4077
|
+
if (_installed) return;
|
|
4078
|
+
const name = channelName || opts?.channelName || "memorio_sync";
|
|
4079
|
+
_targets = opts?.targets || "all";
|
|
4080
|
+
if (_hasBroadcastChannel()) {
|
|
4081
|
+
_channel = new BroadcastChannel(name);
|
|
4082
|
+
_channel.addEventListener("message", _onBroadcastMessage);
|
|
4083
|
+
_installed = true;
|
|
4084
|
+
_wrapDispatchSet();
|
|
4085
|
+
if (exports.DEV) message_default(`memorio broadcast: installed (channel="${name}", targets="${_targets}")`);
|
|
4086
|
+
}
|
|
4087
|
+
if (_hasStorageEvents()) {
|
|
4088
|
+
_storageListener = _onStorageEvent;
|
|
4089
|
+
window.addEventListener("storage", _storageListener);
|
|
4090
|
+
_installed = true;
|
|
4091
|
+
if (!_hasBroadcastChannel() && exports.DEV) {
|
|
4092
|
+
message_default(`memorio broadcast: using storage event fallback (targets="${_targets}")`);
|
|
4093
|
+
}
|
|
4094
|
+
}
|
|
4095
|
+
if (!_installed) {
|
|
4096
|
+
console.warn("[memorio broadcast] Neither BroadcastChannel nor storage events are available in this environment.");
|
|
4097
|
+
}
|
|
4098
|
+
}, "install"),
|
|
4099
|
+
uninstall: /* @__PURE__ */ __name(() => {
|
|
4100
|
+
if (_channel) {
|
|
4101
|
+
_channel.removeEventListener("message", _onBroadcastMessage);
|
|
4102
|
+
_channel.close();
|
|
4103
|
+
_channel = null;
|
|
4104
|
+
}
|
|
4105
|
+
if (_storageListener && typeof window !== "undefined") {
|
|
4106
|
+
window.removeEventListener("storage", _storageListener);
|
|
4107
|
+
_storageListener = null;
|
|
4108
|
+
}
|
|
4109
|
+
_restoreDispatchSet();
|
|
4110
|
+
_installed = false;
|
|
4111
|
+
}, "uninstall"),
|
|
4112
|
+
isInstalled: /* @__PURE__ */ __name(() => _installed, "isInstalled"),
|
|
4113
|
+
broadcast: /* @__PURE__ */ __name((msg) => {
|
|
4114
|
+
if (!_channel) return;
|
|
4115
|
+
_channel.postMessage({ ...msg, timestamp: Date.now() });
|
|
4116
|
+
}, "broadcast")
|
|
4117
|
+
};
|
|
4118
|
+
|
|
4119
|
+
// functions/security/index.ts
|
|
4120
|
+
init_cjs_shims();
|
|
4121
|
+
init_env();
|
|
4122
|
+
function _safeRandomUUID() {
|
|
4123
|
+
const g3 = globalThis;
|
|
4124
|
+
if (typeof g3.crypto !== "undefined" && typeof g3.crypto.randomUUID === "function") {
|
|
4125
|
+
try {
|
|
4126
|
+
return g3.crypto.randomUUID();
|
|
4127
|
+
} catch {
|
|
4128
|
+
}
|
|
4129
|
+
}
|
|
4130
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
4131
|
+
}
|
|
4132
|
+
__name(_safeRandomUUID, "_safeRandomUUID");
|
|
4133
|
+
var REGEX_TIMEOUT_MS = 100;
|
|
4134
|
+
function _safeRegexTest(pattern, key) {
|
|
4135
|
+
if (/\(.*[+*?].*.*\)[+*?]/.test(pattern)) {
|
|
4136
|
+
if (exports.DEV) console.warn(`[memorio security] Potentially dangerous regex blocked: ${pattern}`);
|
|
4137
|
+
return false;
|
|
4138
|
+
}
|
|
4139
|
+
if (pattern.length > 500) {
|
|
4140
|
+
if (exports.DEV) console.warn("[memorio security] Regex pattern exceeds max length (500)");
|
|
4141
|
+
return false;
|
|
4142
|
+
}
|
|
4143
|
+
const startTime = Date.now();
|
|
4144
|
+
try {
|
|
4145
|
+
const regex = new RegExp(pattern);
|
|
4146
|
+
const result = regex.test(key);
|
|
4147
|
+
const elapsed = Date.now() - startTime;
|
|
4148
|
+
if (elapsed > REGEX_TIMEOUT_MS) {
|
|
4149
|
+
if (exports.DEV) console.warn(`[memorio security] Slow regex detected (${elapsed}ms): ${pattern}`);
|
|
4150
|
+
}
|
|
4151
|
+
return result;
|
|
4152
|
+
} catch {
|
|
4153
|
+
return false;
|
|
4154
|
+
}
|
|
4155
|
+
}
|
|
4156
|
+
__name(_safeRegexTest, "_safeRegexTest");
|
|
4157
|
+
function addAccessRule(rules, pattern, perms) {
|
|
4158
|
+
const key = pattern instanceof RegExp ? pattern.source : pattern;
|
|
4159
|
+
rules.set(key, perms);
|
|
4160
|
+
return rules;
|
|
4161
|
+
}
|
|
4162
|
+
__name(addAccessRule, "addAccessRule");
|
|
4163
|
+
function hasPermission(rules, key, action, userId) {
|
|
4164
|
+
if (rules.size === 0) return true;
|
|
4165
|
+
for (const [pattern, perms] of rules) {
|
|
4166
|
+
let matches;
|
|
4167
|
+
if (typeof pattern === "function") {
|
|
4168
|
+
try {
|
|
4169
|
+
matches = pattern(key, userId);
|
|
4170
|
+
} catch {
|
|
4171
|
+
matches = false;
|
|
4172
|
+
}
|
|
4173
|
+
} else {
|
|
4174
|
+
matches = _safeRegexTest(pattern, key);
|
|
4175
|
+
}
|
|
4176
|
+
if (matches) {
|
|
4177
|
+
const allowed = perms.includes(action) || perms.includes("admin");
|
|
4178
|
+
if (!allowed) {
|
|
4179
|
+
logAudit({
|
|
4180
|
+
action,
|
|
4181
|
+
key,
|
|
4182
|
+
userId,
|
|
4183
|
+
success: false,
|
|
4184
|
+
error: "RBAC Denied: insufficient permissions"
|
|
4185
|
+
});
|
|
4186
|
+
}
|
|
4187
|
+
return allowed;
|
|
4188
|
+
}
|
|
4189
|
+
}
|
|
4190
|
+
logAudit({
|
|
4191
|
+
action: "permission_check",
|
|
4192
|
+
key,
|
|
4193
|
+
userId,
|
|
4194
|
+
success: false,
|
|
4195
|
+
error: "RBAC Denied: no matching rule"
|
|
4196
|
+
});
|
|
4197
|
+
return false;
|
|
4198
|
+
}
|
|
4199
|
+
__name(hasPermission, "hasPermission");
|
|
4200
|
+
var _auditLogger = null;
|
|
4201
|
+
function isAuditActive() {
|
|
4202
|
+
return _auditLogger !== null;
|
|
4203
|
+
}
|
|
4204
|
+
__name(isAuditActive, "isAuditActive");
|
|
4205
|
+
function setAuditLogger(logger3) {
|
|
4206
|
+
_auditLogger = logger3;
|
|
4207
|
+
}
|
|
4208
|
+
__name(setAuditLogger, "setAuditLogger");
|
|
4209
|
+
function logAudit(entry) {
|
|
4210
|
+
if (!_auditLogger) return;
|
|
4211
|
+
_auditLogger({
|
|
4212
|
+
timestamp: Date.now(),
|
|
4213
|
+
success: true,
|
|
4214
|
+
...entry
|
|
4215
|
+
});
|
|
4216
|
+
}
|
|
4217
|
+
__name(logAudit, "logAudit");
|
|
4218
|
+
function sanitizeValue(value) {
|
|
4219
|
+
if (typeof value === "string") {
|
|
4220
|
+
let decoded = value.replace(/&#[xX]?[0-9a-fA-F]+;?/g, (match) => {
|
|
4221
|
+
const hexMatch = match.match(/&#x([0-9a-fA-F]+);?/i);
|
|
4222
|
+
if (hexMatch && hexMatch[1]) {
|
|
4223
|
+
return String.fromCharCode(parseInt(hexMatch[1], 16));
|
|
4224
|
+
}
|
|
4225
|
+
const decMatch = match.match(/&#([0-9]+);?/);
|
|
4226
|
+
if (decMatch && decMatch[1]) {
|
|
4227
|
+
return String.fromCharCode(parseInt(decMatch[1], 10));
|
|
4228
|
+
}
|
|
4229
|
+
return match;
|
|
4230
|
+
});
|
|
4231
|
+
try {
|
|
4232
|
+
decoded = decodeURIComponent(decoded);
|
|
4233
|
+
} catch {
|
|
4234
|
+
}
|
|
4235
|
+
decoded = decoded.replace(/(javascript|vbscript|data:text\/html|about:blank|chrome:)/gi, "[SEC-REMOVED]");
|
|
4236
|
+
return decoded.replace(/<script\b[^>]*>[\s\S]*?<\s*\/\s*script\b[^>]*>/gi, "[SEC-REMOVED]").replace(/on\w+\s*=/gi, "[SEC-REMOVED]=").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi, "[SEC-REMOVED]").replace(/<object\b[^<]*(?:(?!<\/object>)<[^<]*)*<\/object>/gi, "[SEC-REMOVED]").replace(/<embed\b[^>]*>/gi, "[SEC-REMOVED]").replace(/<svg\b[^<]*(?:(?!<\/svg>)<[^<]*)*<\/svg>/gi, "[SEC-REMOVED]").replace(/<form\b[^<]*(?:(?!<\/form>)<[^<]*)*<\/form>/gi, "[SEC-REMOVED]").replace(/<base\b[^<]*(?:(?!<\/base>)<[^<]*)*<\/base>/gi, "[SEC-REMOVED]").replace(/<link\b[^<]*(?:(?!<\/link>)<[^<]*)*<\/link>/gi, "[SEC-REMOVED]").replace(/<meta\b[^<]*(?:(?!<\/meta>)<[^<]*)*<\/meta>/gi, "[SEC-REMOVED]").replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, "[SEC-REMOVED]");
|
|
4237
|
+
}
|
|
4238
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
4239
|
+
const ctor = value.constructor?.name;
|
|
4240
|
+
if (ctor === "Object" || ctor === void 0) {
|
|
4241
|
+
const sanitized = {};
|
|
4242
|
+
for (const [k, v] of Object.entries(value)) {
|
|
4243
|
+
if (k === "__proto__" || k === "constructor" || k === "prototype") continue;
|
|
4244
|
+
sanitized[k] = sanitizeValue(v);
|
|
4245
|
+
}
|
|
4246
|
+
return sanitized;
|
|
4247
|
+
}
|
|
4248
|
+
return value;
|
|
4249
|
+
}
|
|
4250
|
+
if (Array.isArray(value)) {
|
|
4251
|
+
return value.map((v) => sanitizeValue(v));
|
|
4252
|
+
}
|
|
4253
|
+
return value;
|
|
4254
|
+
}
|
|
4255
|
+
__name(sanitizeValue, "sanitizeValue");
|
|
4256
|
+
function validateKey(key) {
|
|
4257
|
+
return /^[a-zA-Z0-9_.-]+$/.test(key) && key.length <= 256 && key.length > 0;
|
|
4258
|
+
}
|
|
4259
|
+
__name(validateKey, "validateKey");
|
|
4260
|
+
function recordConsent(consents, userId, purpose, granted) {
|
|
4261
|
+
const record = {
|
|
4262
|
+
id: _safeRandomUUID(),
|
|
4263
|
+
purpose,
|
|
4264
|
+
granted,
|
|
4265
|
+
timestamp: Date.now()
|
|
4266
|
+
};
|
|
4267
|
+
const user = consents.get(userId) || [];
|
|
4268
|
+
user.push(record);
|
|
4269
|
+
consents.set(userId, user);
|
|
4270
|
+
return record;
|
|
4271
|
+
}
|
|
4272
|
+
__name(recordConsent, "recordConsent");
|
|
4273
|
+
function hasConsent(consents, userId, purpose) {
|
|
4274
|
+
const userConsents = consents.get(userId);
|
|
4275
|
+
if (!userConsents) return false;
|
|
4276
|
+
for (let i = userConsents.length - 1; i >= 0; i--) {
|
|
4277
|
+
const record = userConsents[i];
|
|
4278
|
+
if (record && record.purpose === purpose) {
|
|
4279
|
+
return record.granted;
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
return false;
|
|
4283
|
+
}
|
|
4284
|
+
__name(hasConsent, "hasConsent");
|
|
4285
|
+
function revokeConsent(consents, userId, purpose) {
|
|
4286
|
+
return recordConsent(consents, userId, purpose, false);
|
|
4287
|
+
}
|
|
4288
|
+
__name(revokeConsent, "revokeConsent");
|
|
4289
|
+
function getConsents(consents, userId) {
|
|
4290
|
+
return consents.get(userId) || [];
|
|
4291
|
+
}
|
|
4292
|
+
__name(getConsents, "getConsents");
|
|
4293
|
+
function exportUserData(consents, userId) {
|
|
4294
|
+
return {
|
|
4295
|
+
userId,
|
|
4296
|
+
exportedAt: Date.now(),
|
|
4297
|
+
consents: consents.get(userId) || []
|
|
4298
|
+
};
|
|
4299
|
+
}
|
|
4300
|
+
__name(exportUserData, "exportUserData");
|
|
4301
|
+
function deleteUserData(consents, userId) {
|
|
4302
|
+
const count = consents.get(userId)?.length || 0;
|
|
4303
|
+
consents.delete(userId);
|
|
4304
|
+
return { success: true, deletedConsents: count };
|
|
4305
|
+
}
|
|
4306
|
+
__name(deleteUserData, "deleteUserData");
|
|
4307
|
+
var security = {
|
|
4308
|
+
// Re-exports for convenience
|
|
4309
|
+
safeRandomUUID: _safeRandomUUID,
|
|
4310
|
+
safeRegexTest: _safeRegexTest,
|
|
4311
|
+
// RBAC
|
|
4312
|
+
addAccessRule,
|
|
4313
|
+
hasPermission,
|
|
4314
|
+
// Audit logging
|
|
4315
|
+
isAuditActive,
|
|
4316
|
+
setAuditLogger,
|
|
4317
|
+
logAudit,
|
|
4318
|
+
// Input sanitization
|
|
4319
|
+
sanitizeValue,
|
|
4320
|
+
validateKey,
|
|
4321
|
+
// Consent management
|
|
4322
|
+
recordConsent,
|
|
4323
|
+
hasConsent,
|
|
4324
|
+
revokeConsent,
|
|
4325
|
+
getConsents,
|
|
4326
|
+
exportUserData,
|
|
4327
|
+
deleteUserData
|
|
4328
|
+
};
|
|
4329
|
+
|
|
4330
|
+
// index.ts
|
|
4331
|
+
init_message();
|
|
4332
|
+
|
|
4333
|
+
// functions/logger/index.ts
|
|
4334
|
+
init_cjs_shims();
|
|
4335
|
+
init_internal();
|
|
4336
|
+
init_message();
|
|
4337
|
+
init_env();
|
|
4338
|
+
var defaultConfig = {
|
|
4339
|
+
enabled: true,
|
|
4340
|
+
logToConsole: true,
|
|
4341
|
+
modules: ["state", "store", "session", "cache", "idb"],
|
|
4342
|
+
maxEntries: 1e3
|
|
4343
|
+
};
|
|
4344
|
+
function isDebugEnabled() {
|
|
4345
|
+
return exports.DEV && exports.internal.debug === true;
|
|
4346
|
+
}
|
|
4347
|
+
__name(isDebugEnabled, "isDebugEnabled");
|
|
4348
|
+
var config = { ...defaultConfig };
|
|
4349
|
+
var logHistory = [];
|
|
4350
|
+
var configure = /* @__PURE__ */ __name((options) => {
|
|
4351
|
+
config = { ...config, ...options };
|
|
4352
|
+
}, "configure");
|
|
4353
|
+
var enable = /* @__PURE__ */ __name(() => {
|
|
4354
|
+
config.enabled = true;
|
|
4355
|
+
}, "enable");
|
|
4356
|
+
var disable = /* @__PURE__ */ __name(() => {
|
|
4357
|
+
config.enabled = false;
|
|
4358
|
+
}, "disable");
|
|
4359
|
+
var isEnabled = /* @__PURE__ */ __name((module) => {
|
|
4360
|
+
return config.enabled && config.modules.includes(module);
|
|
4361
|
+
}, "isEnabled");
|
|
4362
|
+
var log = /* @__PURE__ */ __name((module, action, path, value, previousValue) => {
|
|
4363
|
+
if (!isEnabled(module)) return;
|
|
4364
|
+
const entry = {
|
|
4365
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4366
|
+
module,
|
|
4367
|
+
action,
|
|
4368
|
+
path,
|
|
4369
|
+
value,
|
|
4370
|
+
previousValue
|
|
4371
|
+
};
|
|
4372
|
+
logHistory.push(entry);
|
|
4373
|
+
if (logHistory.length > config.maxEntries) {
|
|
4374
|
+
logHistory.shift();
|
|
4375
|
+
}
|
|
4376
|
+
if (config.logToConsole && isDebugEnabled()) {
|
|
4377
|
+
const prefix = `[Memorio:${module.toUpperCase()}]`;
|
|
4378
|
+
const color = getModuleColor(module);
|
|
4379
|
+
message_default(
|
|
4380
|
+
`%c${prefix}%c ${action} ${path},
|
|
4381
|
+
color: ${color}; font-weight: bold,
|
|
4382
|
+
color: inherit`
|
|
4383
|
+
);
|
|
4384
|
+
if (value !== void 0) {
|
|
4385
|
+
message_default(` \u2192 value:${value}`);
|
|
4386
|
+
}
|
|
4387
|
+
if (previousValue !== void 0) {
|
|
4388
|
+
message_default(` \u2190 previous:${previousValue}`);
|
|
4389
|
+
}
|
|
4390
|
+
}
|
|
4391
|
+
if (config.customHandler) {
|
|
4392
|
+
config.customHandler(entry);
|
|
4393
|
+
}
|
|
4394
|
+
}, "log");
|
|
4395
|
+
var getModuleColor = /* @__PURE__ */ __name((module) => {
|
|
4396
|
+
const colors = {
|
|
4397
|
+
state: "#4CAF50",
|
|
4398
|
+
store: "#2196F3",
|
|
4399
|
+
session: "#FF9800",
|
|
4400
|
+
cache: "#9C27B0",
|
|
4401
|
+
idb: "#F44336"
|
|
4402
|
+
};
|
|
4403
|
+
return colors[module] || "#888888";
|
|
4404
|
+
}, "getModuleColor");
|
|
4405
|
+
var getHistory = /* @__PURE__ */ __name(() => {
|
|
4406
|
+
return [...logHistory];
|
|
4407
|
+
}, "getHistory");
|
|
4408
|
+
var clearHistory = /* @__PURE__ */ __name(() => {
|
|
4409
|
+
logHistory.length = 0;
|
|
4410
|
+
}, "clearHistory");
|
|
4411
|
+
var getStats = /* @__PURE__ */ __name(() => {
|
|
4412
|
+
const stats = {
|
|
4413
|
+
total: logHistory.length,
|
|
4414
|
+
state: 0,
|
|
4415
|
+
store: 0,
|
|
4416
|
+
session: 0,
|
|
3292
4417
|
cache: 0,
|
|
3293
4418
|
idb: 0,
|
|
3294
4419
|
set: 0,
|
|
@@ -3468,228 +4593,67 @@ function reorder(items, fromIndex, toIndex) {
|
|
|
3468
4593
|
if (fromIndex === toIndex) return items.map((i) => i.key);
|
|
3469
4594
|
const reordered = [...items];
|
|
3470
4595
|
const [removed] = reordered.splice(fromIndex, 1);
|
|
3471
|
-
reordered.splice(toIndex, 0, removed);
|
|
3472
|
-
return reordered.map((i) => i.key);
|
|
3473
|
-
}
|
|
3474
|
-
__name(reorder, "reorder");
|
|
3475
|
-
function reindex(items) {
|
|
3476
|
-
if (items.length === 0) return items;
|
|
3477
|
-
const result = [];
|
|
3478
|
-
let prev = null;
|
|
3479
|
-
for (let i = 0; i < items.length; i++) {
|
|
3480
|
-
const next = i < items.length - 1 ? items[i + 1].key : null;
|
|
3481
|
-
const newItem = { ...items[i] };
|
|
3482
|
-
if (prev === null) {
|
|
3483
|
-
newItem.key = before(items[0].key);
|
|
3484
|
-
} else if (next === null) {
|
|
3485
|
-
newItem.key = after(prev);
|
|
3486
|
-
} else {
|
|
3487
|
-
newItem.key = between(prev, next);
|
|
3488
|
-
}
|
|
3489
|
-
result.push(newItem);
|
|
3490
|
-
prev = newItem.key;
|
|
3491
|
-
}
|
|
3492
|
-
return result;
|
|
3493
|
-
}
|
|
3494
|
-
__name(reindex, "reindex");
|
|
3495
|
-
var fractional = {
|
|
3496
|
-
generateBetween,
|
|
3497
|
-
firstKey,
|
|
3498
|
-
after,
|
|
3499
|
-
before,
|
|
3500
|
-
between,
|
|
3501
|
-
reorder,
|
|
3502
|
-
reindex
|
|
3503
|
-
};
|
|
3504
|
-
|
|
3505
|
-
// index.ts
|
|
3506
|
-
init_internal();
|
|
3507
|
-
init_platform();
|
|
3508
|
-
|
|
3509
|
-
// core/global.ts
|
|
3510
|
-
init_cjs_shims();
|
|
3511
|
-
init_platform();
|
|
3512
|
-
init_internal();
|
|
3513
|
-
|
|
3514
|
-
// package.json
|
|
3515
|
-
var package_default = {
|
|
3516
|
-
version: "5.0.0"};
|
|
3517
|
-
|
|
3518
|
-
// core/global.ts
|
|
3519
|
-
init_env();
|
|
3520
|
-
init_store();
|
|
3521
|
-
init_idb();
|
|
3522
|
-
init_sqlite();
|
|
3523
|
-
init_message();
|
|
3524
|
-
|
|
3525
|
-
// functions/typed/index.ts
|
|
3526
|
-
init_cjs_shims();
|
|
3527
|
-
function typed() {
|
|
3528
|
-
return exports.state;
|
|
3529
|
-
}
|
|
3530
|
-
__name(typed, "typed");
|
|
3531
|
-
|
|
3532
|
-
// functions/history/index.ts
|
|
3533
|
-
init_cjs_shims();
|
|
3534
|
-
init_internal();
|
|
3535
|
-
init_env();
|
|
3536
|
-
init_message();
|
|
3537
|
-
function _clone(value) {
|
|
3538
|
-
if (value === null || typeof value !== "object") return value;
|
|
3539
|
-
try {
|
|
3540
|
-
return deepRaw(value, /* @__PURE__ */ new WeakSet());
|
|
3541
|
-
} catch (err) {
|
|
3542
|
-
if (exports.DEV) console.warn("[memorio history] deep clone failed:", err);
|
|
3543
|
-
return value;
|
|
3544
|
-
}
|
|
3545
|
-
}
|
|
3546
|
-
__name(_clone, "_clone");
|
|
3547
|
-
var snapshot = /* @__PURE__ */ __name(() => {
|
|
3548
|
-
return deepRaw(exports.state, /* @__PURE__ */ new WeakSet());
|
|
3549
|
-
}, "snapshot");
|
|
3550
|
-
var diff = /* @__PURE__ */ __name((snap) => {
|
|
3551
|
-
const changes = [];
|
|
3552
|
-
const _walk = /* @__PURE__ */ __name((oldObj, newObj, prefix) => {
|
|
3553
|
-
const oldKeys = oldObj ? Object.keys(oldObj) : [];
|
|
3554
|
-
const newKeys = newObj ? Object.keys(newObj) : [];
|
|
3555
|
-
for (const key of newKeys) {
|
|
3556
|
-
const newPath = prefix ? `${prefix}.${key}` : key;
|
|
3557
|
-
const oldVal = oldObj ? oldObj[key] : void 0;
|
|
3558
|
-
const newVal = newObj[key];
|
|
3559
|
-
if (oldVal !== newVal) {
|
|
3560
|
-
const oldType = typeof oldVal;
|
|
3561
|
-
const newType = typeof newVal;
|
|
3562
|
-
if (oldType !== newType || oldVal === void 0) {
|
|
3563
|
-
changes.push({ path: newPath, oldValue: oldVal, newValue: newVal });
|
|
3564
|
-
} else if (oldVal && typeof oldVal === "object") {
|
|
3565
|
-
_walk(oldVal, newVal, newPath);
|
|
3566
|
-
} else if (oldVal !== newVal) {
|
|
3567
|
-
changes.push({ path: newPath, oldValue: oldVal, newValue: newVal });
|
|
3568
|
-
}
|
|
3569
|
-
}
|
|
3570
|
-
}
|
|
3571
|
-
for (const key of oldKeys) {
|
|
3572
|
-
if (!(key in (newObj || {}))) {
|
|
3573
|
-
const newPath = prefix ? `${prefix}.${key}` : key;
|
|
3574
|
-
changes.push({ path: newPath, oldValue: oldObj[key], newValue: void 0 });
|
|
3575
|
-
}
|
|
3576
|
-
}
|
|
3577
|
-
}, "_walk");
|
|
3578
|
-
_walk(snap, deepRaw(exports.state), "");
|
|
3579
|
-
return changes;
|
|
3580
|
-
}, "diff");
|
|
3581
|
-
var enableHistory = /* @__PURE__ */ __name((enabled = true) => {
|
|
3582
|
-
exports.internal.historyEnabled = enabled;
|
|
3583
|
-
message_default(`[memorio history] Tracking ${enabled ? "enabled" : "disabled"}`);
|
|
3584
|
-
}, "enableHistory");
|
|
3585
|
-
var trace = /* @__PURE__ */ __name(() => {
|
|
3586
|
-
return [...exports.internal.mutations];
|
|
3587
|
-
}, "trace");
|
|
3588
|
-
var canUndo = /* @__PURE__ */ __name(() => {
|
|
3589
|
-
return exports.internal.canUndo();
|
|
3590
|
-
}, "canUndo");
|
|
3591
|
-
var canRedo = /* @__PURE__ */ __name(() => {
|
|
3592
|
-
return exports.internal.canRedo();
|
|
3593
|
-
}, "canRedo");
|
|
3594
|
-
var undo = /* @__PURE__ */ __name(() => {
|
|
3595
|
-
if (!exports.internal.historyEnabled) {
|
|
3596
|
-
message_default("[memorio history] History is not enabled");
|
|
3597
|
-
return void 0;
|
|
3598
|
-
}
|
|
3599
|
-
const record = exports.internal.popUndo();
|
|
3600
|
-
if (!record) return void 0;
|
|
3601
|
-
_applyInverse2(record);
|
|
3602
|
-
message_default(`[memorio history] Undid: ${record.action} ${record.path}`);
|
|
3603
|
-
return record;
|
|
3604
|
-
}, "undo");
|
|
3605
|
-
var redo = /* @__PURE__ */ __name(() => {
|
|
3606
|
-
if (!exports.internal.historyEnabled) {
|
|
3607
|
-
message_default("[memorio history] History is not enabled");
|
|
3608
|
-
return void 0;
|
|
3609
|
-
}
|
|
3610
|
-
const record = exports.internal.popRedo();
|
|
3611
|
-
if (!record) return void 0;
|
|
3612
|
-
_applyForward(record);
|
|
3613
|
-
message_default(`[memorio history] Redid: ${record.action} ${record.path}`);
|
|
3614
|
-
return record;
|
|
3615
|
-
}, "redo");
|
|
3616
|
-
function _applyInverse2(record) {
|
|
3617
|
-
const wasEnabled = exports.internal.historyEnabled;
|
|
3618
|
-
exports.internal.historyEnabled = false;
|
|
3619
|
-
try {
|
|
3620
|
-
if (record.action === "set") {
|
|
3621
|
-
if (record.previousValue === void 0) {
|
|
3622
|
-
_deletePath2(record.path);
|
|
3623
|
-
} else {
|
|
3624
|
-
_setPath2(record.path, record.previousValue);
|
|
3625
|
-
}
|
|
3626
|
-
} else if (record.action === "delete") {
|
|
3627
|
-
if (record.previousValue !== void 0) {
|
|
3628
|
-
_setPath2(record.path, record.previousValue);
|
|
3629
|
-
}
|
|
3630
|
-
}
|
|
3631
|
-
} finally {
|
|
3632
|
-
exports.internal.historyEnabled = wasEnabled;
|
|
3633
|
-
}
|
|
3634
|
-
}
|
|
3635
|
-
__name(_applyInverse2, "_applyInverse");
|
|
3636
|
-
function _applyForward(record) {
|
|
3637
|
-
const wasEnabled = exports.internal.historyEnabled;
|
|
3638
|
-
exports.internal.historyEnabled = false;
|
|
3639
|
-
try {
|
|
3640
|
-
if (record.action === "set") {
|
|
3641
|
-
_setPath2(record.path, record.newValue);
|
|
3642
|
-
} else if (record.action === "delete") {
|
|
3643
|
-
_deletePath2(record.path);
|
|
3644
|
-
}
|
|
3645
|
-
} finally {
|
|
3646
|
-
exports.internal.historyEnabled = wasEnabled;
|
|
3647
|
-
}
|
|
4596
|
+
reordered.splice(toIndex, 0, removed);
|
|
4597
|
+
return reordered.map((i) => i.key);
|
|
3648
4598
|
}
|
|
3649
|
-
__name(
|
|
3650
|
-
function
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
4599
|
+
__name(reorder, "reorder");
|
|
4600
|
+
function reindex(items) {
|
|
4601
|
+
if (items.length === 0) return items;
|
|
4602
|
+
const result = [];
|
|
4603
|
+
let prev = null;
|
|
4604
|
+
for (let i = 0; i < items.length; i++) {
|
|
4605
|
+
const next = i < items.length - 1 ? items[i + 1].key : null;
|
|
4606
|
+
const newItem = { ...items[i] };
|
|
4607
|
+
if (prev === null) {
|
|
4608
|
+
newItem.key = before(items[0].key);
|
|
4609
|
+
} else if (next === null) {
|
|
4610
|
+
newItem.key = after(prev);
|
|
4611
|
+
} else {
|
|
4612
|
+
newItem.key = between(prev, next);
|
|
3657
4613
|
}
|
|
3658
|
-
|
|
4614
|
+
result.push(newItem);
|
|
4615
|
+
prev = newItem.key;
|
|
3659
4616
|
}
|
|
3660
|
-
|
|
4617
|
+
return result;
|
|
3661
4618
|
}
|
|
3662
|
-
__name(
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
4619
|
+
__name(reindex, "reindex");
|
|
4620
|
+
var fractional = {
|
|
4621
|
+
generateBetween,
|
|
4622
|
+
firstKey,
|
|
4623
|
+
after,
|
|
4624
|
+
before,
|
|
4625
|
+
between,
|
|
4626
|
+
reorder,
|
|
4627
|
+
reindex
|
|
4628
|
+
};
|
|
4629
|
+
|
|
4630
|
+
// index.ts
|
|
4631
|
+
init_internal();
|
|
4632
|
+
init_platform();
|
|
4633
|
+
|
|
4634
|
+
// core/global.ts
|
|
4635
|
+
init_cjs_shims();
|
|
4636
|
+
init_platform();
|
|
4637
|
+
init_internal();
|
|
4638
|
+
|
|
4639
|
+
// package.json
|
|
4640
|
+
var package_default = {
|
|
4641
|
+
version: "5.1.1"};
|
|
4642
|
+
|
|
4643
|
+
// core/global.ts
|
|
4644
|
+
init_env();
|
|
4645
|
+
init_store();
|
|
4646
|
+
init_idb();
|
|
4647
|
+
init_sqlite();
|
|
4648
|
+
init_encryption();
|
|
4649
|
+
init_message();
|
|
4650
|
+
|
|
4651
|
+
// functions/typed/index.ts
|
|
4652
|
+
init_cjs_shims();
|
|
4653
|
+
function typed() {
|
|
4654
|
+
return exports.state;
|
|
3676
4655
|
}
|
|
3677
|
-
__name(
|
|
3678
|
-
var rollback = /* @__PURE__ */ __name((snap) => {
|
|
3679
|
-
exports.state.removeAll();
|
|
3680
|
-
for (const key of Object.keys(snap)) {
|
|
3681
|
-
exports.state[key] = _clone(snap[key]);
|
|
3682
|
-
}
|
|
3683
|
-
exports.internal.clearHistory();
|
|
3684
|
-
message_default("[memorio history] State rolled back to snapshot");
|
|
3685
|
-
}, "rollback");
|
|
3686
|
-
var clearHistory2 = /* @__PURE__ */ __name(() => {
|
|
3687
|
-
exports.internal.clearHistory();
|
|
3688
|
-
message_default("[memorio history] History cleared");
|
|
3689
|
-
}, "clearHistory");
|
|
3690
|
-
var clearRedo = /* @__PURE__ */ __name(() => {
|
|
3691
|
-
exports.internal.clearRedo();
|
|
3692
|
-
}, "clearRedo");
|
|
4656
|
+
__name(typed, "typed");
|
|
3693
4657
|
|
|
3694
4658
|
// functions/memory/index.ts
|
|
3695
4659
|
init_cjs_shims();
|
|
@@ -4382,6 +5346,168 @@ var memory = {
|
|
|
4382
5346
|
}
|
|
4383
5347
|
};
|
|
4384
5348
|
|
|
5349
|
+
// functions/history/index.ts
|
|
5350
|
+
init_cjs_shims();
|
|
5351
|
+
init_internal();
|
|
5352
|
+
init_env();
|
|
5353
|
+
init_message();
|
|
5354
|
+
function _clone(value) {
|
|
5355
|
+
if (value === null || typeof value !== "object") return value;
|
|
5356
|
+
try {
|
|
5357
|
+
return deepRaw(value, /* @__PURE__ */ new WeakSet());
|
|
5358
|
+
} catch (err) {
|
|
5359
|
+
if (exports.DEV) console.warn("[memorio history] deep clone failed:", err);
|
|
5360
|
+
return value;
|
|
5361
|
+
}
|
|
5362
|
+
}
|
|
5363
|
+
__name(_clone, "_clone");
|
|
5364
|
+
var snapshot = /* @__PURE__ */ __name(() => {
|
|
5365
|
+
return deepRaw(exports.state, /* @__PURE__ */ new WeakSet());
|
|
5366
|
+
}, "snapshot");
|
|
5367
|
+
var diff = /* @__PURE__ */ __name((snap) => {
|
|
5368
|
+
const changes = [];
|
|
5369
|
+
const _walk = /* @__PURE__ */ __name((oldObj, newObj, prefix) => {
|
|
5370
|
+
const oldKeys = oldObj ? Object.keys(oldObj) : [];
|
|
5371
|
+
const newKeys = newObj ? Object.keys(newObj) : [];
|
|
5372
|
+
for (const key of newKeys) {
|
|
5373
|
+
const newPath = prefix ? `${prefix}.${key}` : key;
|
|
5374
|
+
const oldVal = oldObj ? oldObj[key] : void 0;
|
|
5375
|
+
const newVal = newObj[key];
|
|
5376
|
+
if (oldVal !== newVal) {
|
|
5377
|
+
const oldType = typeof oldVal;
|
|
5378
|
+
const newType = typeof newVal;
|
|
5379
|
+
if (oldType !== newType || oldVal === void 0) {
|
|
5380
|
+
changes.push({ path: newPath, oldValue: oldVal, newValue: newVal });
|
|
5381
|
+
} else if (oldVal && typeof oldVal === "object") {
|
|
5382
|
+
_walk(oldVal, newVal, newPath);
|
|
5383
|
+
} else if (oldVal !== newVal) {
|
|
5384
|
+
changes.push({ path: newPath, oldValue: oldVal, newValue: newVal });
|
|
5385
|
+
}
|
|
5386
|
+
}
|
|
5387
|
+
}
|
|
5388
|
+
for (const key of oldKeys) {
|
|
5389
|
+
if (!(key in (newObj || {}))) {
|
|
5390
|
+
const newPath = prefix ? `${prefix}.${key}` : key;
|
|
5391
|
+
changes.push({ path: newPath, oldValue: oldObj[key], newValue: void 0 });
|
|
5392
|
+
}
|
|
5393
|
+
}
|
|
5394
|
+
}, "_walk");
|
|
5395
|
+
_walk(snap, deepRaw(exports.state), "");
|
|
5396
|
+
return changes;
|
|
5397
|
+
}, "diff");
|
|
5398
|
+
var enableHistory = /* @__PURE__ */ __name((enabled = true) => {
|
|
5399
|
+
exports.internal.historyEnabled = enabled;
|
|
5400
|
+
message_default(`[memorio history] Tracking ${enabled ? "enabled" : "disabled"}`);
|
|
5401
|
+
}, "enableHistory");
|
|
5402
|
+
var trace = /* @__PURE__ */ __name(() => {
|
|
5403
|
+
return [...exports.internal.mutations];
|
|
5404
|
+
}, "trace");
|
|
5405
|
+
var canUndo = /* @__PURE__ */ __name(() => {
|
|
5406
|
+
return exports.internal.canUndo();
|
|
5407
|
+
}, "canUndo");
|
|
5408
|
+
var canRedo = /* @__PURE__ */ __name(() => {
|
|
5409
|
+
return exports.internal.canRedo();
|
|
5410
|
+
}, "canRedo");
|
|
5411
|
+
var undo = /* @__PURE__ */ __name(() => {
|
|
5412
|
+
if (!exports.internal.historyEnabled) {
|
|
5413
|
+
message_default("[memorio history] History is not enabled");
|
|
5414
|
+
return void 0;
|
|
5415
|
+
}
|
|
5416
|
+
const record = exports.internal.popUndo();
|
|
5417
|
+
if (!record) return void 0;
|
|
5418
|
+
_applyInverse2(record);
|
|
5419
|
+
message_default(`[memorio history] Undid: ${record.action} ${record.path}`);
|
|
5420
|
+
return record;
|
|
5421
|
+
}, "undo");
|
|
5422
|
+
var redo = /* @__PURE__ */ __name(() => {
|
|
5423
|
+
if (!exports.internal.historyEnabled) {
|
|
5424
|
+
message_default("[memorio history] History is not enabled");
|
|
5425
|
+
return void 0;
|
|
5426
|
+
}
|
|
5427
|
+
const record = exports.internal.popRedo();
|
|
5428
|
+
if (!record) return void 0;
|
|
5429
|
+
_applyForward(record);
|
|
5430
|
+
message_default(`[memorio history] Redid: ${record.action} ${record.path}`);
|
|
5431
|
+
return record;
|
|
5432
|
+
}, "redo");
|
|
5433
|
+
function _applyInverse2(record) {
|
|
5434
|
+
const wasEnabled = exports.internal.historyEnabled;
|
|
5435
|
+
exports.internal.historyEnabled = false;
|
|
5436
|
+
try {
|
|
5437
|
+
if (record.action === "set") {
|
|
5438
|
+
if (record.previousValue === void 0) {
|
|
5439
|
+
_deletePath2(record.path);
|
|
5440
|
+
} else {
|
|
5441
|
+
_setPath2(record.path, record.previousValue);
|
|
5442
|
+
}
|
|
5443
|
+
} else if (record.action === "delete") {
|
|
5444
|
+
if (record.previousValue !== void 0) {
|
|
5445
|
+
_setPath2(record.path, record.previousValue);
|
|
5446
|
+
}
|
|
5447
|
+
}
|
|
5448
|
+
} finally {
|
|
5449
|
+
exports.internal.historyEnabled = wasEnabled;
|
|
5450
|
+
}
|
|
5451
|
+
}
|
|
5452
|
+
__name(_applyInverse2, "_applyInverse");
|
|
5453
|
+
function _applyForward(record) {
|
|
5454
|
+
const wasEnabled = exports.internal.historyEnabled;
|
|
5455
|
+
exports.internal.historyEnabled = false;
|
|
5456
|
+
try {
|
|
5457
|
+
if (record.action === "set") {
|
|
5458
|
+
_setPath2(record.path, record.newValue);
|
|
5459
|
+
} else if (record.action === "delete") {
|
|
5460
|
+
_deletePath2(record.path);
|
|
5461
|
+
}
|
|
5462
|
+
} finally {
|
|
5463
|
+
exports.internal.historyEnabled = wasEnabled;
|
|
5464
|
+
}
|
|
5465
|
+
}
|
|
5466
|
+
__name(_applyForward, "_applyForward");
|
|
5467
|
+
function _setPath2(path, value) {
|
|
5468
|
+
const parts = path.split(".");
|
|
5469
|
+
let current = exports.state;
|
|
5470
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
5471
|
+
const part = parts[i];
|
|
5472
|
+
if (current[part] === void 0) {
|
|
5473
|
+
current[part] = {};
|
|
5474
|
+
}
|
|
5475
|
+
current = current[part];
|
|
5476
|
+
}
|
|
5477
|
+
current[parts[parts.length - 1]] = value;
|
|
5478
|
+
}
|
|
5479
|
+
__name(_setPath2, "_setPath");
|
|
5480
|
+
function _deletePath2(path) {
|
|
5481
|
+
const parts = path.split(".");
|
|
5482
|
+
if (parts.length === 1) {
|
|
5483
|
+
exports.state.remove(parts[0]);
|
|
5484
|
+
return;
|
|
5485
|
+
}
|
|
5486
|
+
let current = exports.state;
|
|
5487
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
5488
|
+
const part = parts[i];
|
|
5489
|
+
if (current[part] === void 0) return;
|
|
5490
|
+
current = current[part];
|
|
5491
|
+
}
|
|
5492
|
+
delete current[parts[parts.length - 1]];
|
|
5493
|
+
}
|
|
5494
|
+
__name(_deletePath2, "_deletePath");
|
|
5495
|
+
var rollback = /* @__PURE__ */ __name((snap) => {
|
|
5496
|
+
exports.state.removeAll();
|
|
5497
|
+
for (const key of Object.keys(snap)) {
|
|
5498
|
+
exports.state[key] = _clone(snap[key]);
|
|
5499
|
+
}
|
|
5500
|
+
exports.internal.clearHistory();
|
|
5501
|
+
message_default("[memorio history] State rolled back to snapshot");
|
|
5502
|
+
}, "rollback");
|
|
5503
|
+
var clearHistory2 = /* @__PURE__ */ __name(() => {
|
|
5504
|
+
exports.internal.clearHistory();
|
|
5505
|
+
message_default("[memorio history] History cleared");
|
|
5506
|
+
}, "clearHistory");
|
|
5507
|
+
var clearRedo = /* @__PURE__ */ __name(() => {
|
|
5508
|
+
exports.internal.clearRedo();
|
|
5509
|
+
}, "clearRedo");
|
|
5510
|
+
|
|
4385
5511
|
// core/global.ts
|
|
4386
5512
|
if (!("memorio" in globalThis)) {
|
|
4387
5513
|
Object.defineProperty(
|
|
@@ -4448,16 +5574,18 @@ if (!("memorio" in globalThis)) {
|
|
|
4448
5574
|
}
|
|
4449
5575
|
);
|
|
4450
5576
|
memorio.memory = memory;
|
|
5577
|
+
memorio.encryption = exports.encryption;
|
|
4451
5578
|
initializePlatform();
|
|
4452
5579
|
memorio.isBrowser = isBrowser;
|
|
4453
5580
|
memorio.isNode = isNode;
|
|
4454
5581
|
memorio.isDeno = isDeno;
|
|
5582
|
+
memorio.isBun = isBun;
|
|
4455
5583
|
memorio.isEdge = isEdge;
|
|
4456
5584
|
memorio.getCapabilities = getCapabilities;
|
|
4457
5585
|
memorio.createContext = createContext;
|
|
4458
5586
|
memorio.listContexts = listContexts;
|
|
4459
5587
|
memorio.deleteContext = deleteContext;
|
|
4460
|
-
memorio.isolate = (name) => createContext(name);
|
|
5588
|
+
memorio.isolate = (name, opts) => createContext(name, opts);
|
|
4461
5589
|
Object.defineProperty(memorio, "setContext", { writable: false, enumerable: false, value: /* @__PURE__ */ __name((id) => setCurrentContext(id), "value") });
|
|
4462
5590
|
Object.defineProperty(memorio, "getContext", { writable: false, enumerable: false, value: /* @__PURE__ */ __name(() => exports.internal.currentContext, "value") });
|
|
4463
5591
|
memorio.registerSchema = schema.register;
|
|
@@ -4465,6 +5593,9 @@ if (!("memorio" in globalThis)) {
|
|
|
4465
5593
|
memorio.unregisterSchema = schema.unregister;
|
|
4466
5594
|
memorio.listSchemas = schema.list;
|
|
4467
5595
|
memorio.typed = typed;
|
|
5596
|
+
memorio.computed = computed;
|
|
5597
|
+
memorio.broadcast = broadcast;
|
|
5598
|
+
memorio.security = security;
|
|
4468
5599
|
memorio.snapshot = snapshot;
|
|
4469
5600
|
memorio.diff = diff;
|
|
4470
5601
|
memorio.undo = undo;
|
|
@@ -4498,7 +5629,11 @@ if (!("memorio" in globalThis)) {
|
|
|
4498
5629
|
idb: exports.idb,
|
|
4499
5630
|
sqlite: exports.sqlite,
|
|
4500
5631
|
observer,
|
|
4501
|
-
useObserver
|
|
5632
|
+
useObserver,
|
|
5633
|
+
encryption: exports.encryption,
|
|
5634
|
+
computed,
|
|
5635
|
+
broadcast,
|
|
5636
|
+
security
|
|
4502
5637
|
};
|
|
4503
5638
|
for (const key of Object.keys(globalDefinitions)) {
|
|
4504
5639
|
if (!(key in globalThis)) {
|
|
@@ -4533,6 +5668,7 @@ memorio2.global();
|
|
|
4533
5668
|
exports.abortTransaction = abortTransaction;
|
|
4534
5669
|
exports.activeTransactionId = activeTransactionId;
|
|
4535
5670
|
exports.beginTransaction = beginTransaction;
|
|
5671
|
+
exports.broadcast = broadcast;
|
|
4536
5672
|
exports.cache = cache;
|
|
4537
5673
|
exports.canMerge = canMerge;
|
|
4538
5674
|
exports.canRedo = canRedo;
|
|
@@ -4540,6 +5676,7 @@ exports.canUndo = canUndo;
|
|
|
4540
5676
|
exports.clearHistory = clearHistory2;
|
|
4541
5677
|
exports.clearRedo = clearRedo;
|
|
4542
5678
|
exports.commitTransaction = commitTransaction;
|
|
5679
|
+
exports.computed = computed;
|
|
4543
5680
|
exports.createContext = createContext;
|
|
4544
5681
|
exports.createMutation = createMutation;
|
|
4545
5682
|
exports.currentTimestamp = currentTimestamp;
|
|
@@ -4561,6 +5698,7 @@ exports.getContext = getContext;
|
|
|
4561
5698
|
exports.help = help;
|
|
4562
5699
|
exports.hlc = hlc;
|
|
4563
5700
|
exports.isBrowser = isBrowser;
|
|
5701
|
+
exports.isBun = isBun;
|
|
4564
5702
|
exports.isDeno = isDeno;
|
|
4565
5703
|
exports.isEdge = isEdge;
|
|
4566
5704
|
exports.isNode = isNode;
|
|
@@ -4580,6 +5718,7 @@ exports.redo = redo;
|
|
|
4580
5718
|
exports.registerSchema = registerSchema;
|
|
4581
5719
|
exports.rollback = rollback;
|
|
4582
5720
|
exports.schema = schema;
|
|
5721
|
+
exports.security = security;
|
|
4583
5722
|
exports.setContext = setContext;
|
|
4584
5723
|
exports.snapshot = snapshot;
|
|
4585
5724
|
exports.toPatch = toPatch;
|