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/index.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
|
}
|
|
@@ -2725,6 +3193,7 @@ init_cjs_shims();
|
|
|
2725
3193
|
init_platform();
|
|
2726
3194
|
init_internal();
|
|
2727
3195
|
init_message();
|
|
3196
|
+
init_encryption();
|
|
2728
3197
|
var _sessionStorage = getSessionStorage();
|
|
2729
3198
|
var _fallbackStorageByContext2 = /* @__PURE__ */ new Map();
|
|
2730
3199
|
function _getFallbackStorage2() {
|
|
@@ -2737,6 +3206,14 @@ function _getFallbackStorage2() {
|
|
|
2737
3206
|
}
|
|
2738
3207
|
__name(_getFallbackStorage2, "_getFallbackStorage");
|
|
2739
3208
|
var _hasStorage2 = _sessionStorage !== null;
|
|
3209
|
+
var _encryptionKey2 = null;
|
|
3210
|
+
var _onError2 = null;
|
|
3211
|
+
var _maxObjectSize2 = 0;
|
|
3212
|
+
var _maxTotalSize2 = 0;
|
|
3213
|
+
function _isEncryptedEnvelope2(value) {
|
|
3214
|
+
return exports.encryption.isEncrypted(value);
|
|
3215
|
+
}
|
|
3216
|
+
__name(_isEncryptedEnvelope2, "_isEncryptedEnvelope");
|
|
2740
3217
|
function _getPrefix2() {
|
|
2741
3218
|
const contextName = exports.internal.currentContext || "";
|
|
2742
3219
|
return contextName ? `${contextName}-` : `memorio_session_`;
|
|
@@ -2790,16 +3267,22 @@ if (globalThis[SESSION_INSTANCE_KEY]) {
|
|
|
2790
3267
|
/**
|
|
2791
3268
|
* Gets a value from storage.
|
|
2792
3269
|
* @param name The key to retrieve.
|
|
2793
|
-
* @
|
|
3270
|
+
* @param opts Optional { decrypt: key } to decrypt an encrypted envelope.
|
|
3271
|
+
* @returns The parsed value, a Promise when decrypting, or null if not found.
|
|
2794
3272
|
*/
|
|
2795
3273
|
get: {
|
|
2796
|
-
value: /* @__PURE__ */ __name((name) => {
|
|
3274
|
+
value: /* @__PURE__ */ __name((name, opts) => {
|
|
2797
3275
|
if (!name) {
|
|
2798
3276
|
console.warn("[memorio session] session.get() called with empty or null key - returning null");
|
|
2799
3277
|
return null;
|
|
2800
3278
|
}
|
|
2801
3279
|
try {
|
|
2802
|
-
|
|
3280
|
+
const raw = _read2(_prefixKey2(name));
|
|
3281
|
+
const key = opts?.decrypt ?? _encryptionKey2;
|
|
3282
|
+
if (key && _isEncryptedEnvelope2(raw)) {
|
|
3283
|
+
return exports.encryption.decrypt(raw, key);
|
|
3284
|
+
}
|
|
3285
|
+
return raw;
|
|
2803
3286
|
} catch (err) {
|
|
2804
3287
|
exports.message(`Error parsing session item '${name}':${err}`);
|
|
2805
3288
|
}
|
|
@@ -2810,10 +3293,11 @@ if (globalThis[SESSION_INSTANCE_KEY]) {
|
|
|
2810
3293
|
* Sets a value in storage.
|
|
2811
3294
|
* @param name The key to set.
|
|
2812
3295
|
* @param value The value to store.
|
|
2813
|
-
* @
|
|
3296
|
+
* @param opts Optional { encrypt: key } to encrypt before storage.
|
|
3297
|
+
* @returns true if written, false if rejected. Returns a Promise when encrypting.
|
|
2814
3298
|
*/
|
|
2815
3299
|
set: {
|
|
2816
|
-
value: /* @__PURE__ */ __name((name, value) => {
|
|
3300
|
+
value: /* @__PURE__ */ __name((name, value, opts) => {
|
|
2817
3301
|
if (!name) {
|
|
2818
3302
|
console.warn("[memorio session] session.set() called with empty or null key - write aborted");
|
|
2819
3303
|
return false;
|
|
@@ -2825,15 +3309,63 @@ if (globalThis[SESSION_INSTANCE_KEY]) {
|
|
|
2825
3309
|
exports.message("It's not secure to session functions.");
|
|
2826
3310
|
return false;
|
|
2827
3311
|
}
|
|
3312
|
+
if (_maxObjectSize2 > 0 || _maxTotalSize2 > 0) {
|
|
3313
|
+
let serializedSize = 0;
|
|
3314
|
+
try {
|
|
3315
|
+
serializedSize = new TextEncoder().encode(JSON.stringify(value)).length;
|
|
3316
|
+
} catch {
|
|
3317
|
+
serializedSize = 0;
|
|
3318
|
+
}
|
|
3319
|
+
if (_maxObjectSize2 > 0 && serializedSize > _maxObjectSize2) {
|
|
3320
|
+
const err = new Error(`Object size (${serializedSize} bytes) exceeds maxObjectSize (${_maxObjectSize2} bytes)`);
|
|
3321
|
+
_onError2?.(err, { operation: "set" });
|
|
3322
|
+
return false;
|
|
3323
|
+
}
|
|
3324
|
+
if (_maxTotalSize2 > 0) {
|
|
3325
|
+
const currentTotal = exports.session.size() * 1024;
|
|
3326
|
+
const existingItemSize = _sessionStorage ? _sessionStorage.getItem(prefixedName)?.length ?? 0 : _getFallbackStorage2().get(prefixedName)?.length ?? 0;
|
|
3327
|
+
const projected = currentTotal - existingItemSize + serializedSize;
|
|
3328
|
+
if (projected > _maxTotalSize2) {
|
|
3329
|
+
const err = new Error(`Total session size (${projected} bytes) exceeds maxTotalSize (${_maxTotalSize2} bytes)`);
|
|
3330
|
+
_onError2?.(err, { operation: "set" });
|
|
3331
|
+
return false;
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3335
|
+
const key = opts?.encrypt ?? _encryptionKey2;
|
|
3336
|
+
if (key) {
|
|
3337
|
+
return exports.encryption.encrypt(value, key).then((env) => {
|
|
3338
|
+
_write2(prefixedName, env);
|
|
3339
|
+
return true;
|
|
3340
|
+
}).catch((err) => {
|
|
3341
|
+
exports.message(`Error encrypting session item '${name}': ${err}`);
|
|
3342
|
+
_onError2?.(err, { operation: "set" });
|
|
3343
|
+
return false;
|
|
3344
|
+
});
|
|
3345
|
+
}
|
|
2828
3346
|
try {
|
|
2829
3347
|
_write2(prefixedName, value);
|
|
2830
3348
|
} catch (err) {
|
|
2831
3349
|
exports.message(`Error setting session item '${name}': ${err}`);
|
|
3350
|
+
_onError2?.(err, { operation: "set" });
|
|
2832
3351
|
return false;
|
|
2833
3352
|
}
|
|
2834
3353
|
return true;
|
|
2835
3354
|
}, "value")
|
|
2836
3355
|
},
|
|
3356
|
+
/**
|
|
3357
|
+
* Configure session-wide behavior.
|
|
3358
|
+
* @param opts { encryptionKey, onError, maxObjectSize, maxTotalSize }
|
|
3359
|
+
*/
|
|
3360
|
+
config: {
|
|
3361
|
+
value: /* @__PURE__ */ __name((opts) => {
|
|
3362
|
+
if (opts.encryptionKey !== void 0) _encryptionKey2 = opts.encryptionKey;
|
|
3363
|
+
if (opts.onError !== void 0) _onError2 = opts.onError;
|
|
3364
|
+
if (opts.maxObjectSize !== void 0) _maxObjectSize2 = opts.maxObjectSize;
|
|
3365
|
+
if (opts.maxTotalSize !== void 0) _maxTotalSize2 = opts.maxTotalSize;
|
|
3366
|
+
return exports.session;
|
|
3367
|
+
}, "value")
|
|
3368
|
+
},
|
|
2837
3369
|
/**
|
|
2838
3370
|
* Removes a value from storage.
|
|
2839
3371
|
* @param name The key to remove.
|
|
@@ -3200,92 +3732,685 @@ var useObserver = /* @__PURE__ */ __name(((func, deps = []) => {
|
|
|
3200
3732
|
}), "useObserver");
|
|
3201
3733
|
|
|
3202
3734
|
// index.ts
|
|
3203
|
-
|
|
3735
|
+
init_encryption();
|
|
3204
3736
|
|
|
3205
|
-
// functions/
|
|
3737
|
+
// functions/computed/index.ts
|
|
3206
3738
|
init_cjs_shims();
|
|
3207
|
-
init_internal();
|
|
3208
|
-
init_message();
|
|
3209
3739
|
init_env();
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3740
|
+
init_message();
|
|
3741
|
+
var DEFAULT_EQUALITY = /* @__PURE__ */ __name((prev, next) => {
|
|
3742
|
+
if (prev === next) return true;
|
|
3743
|
+
if (prev == null || next == null) return false;
|
|
3744
|
+
if (typeof prev !== typeof next) return false;
|
|
3745
|
+
if (typeof prev !== "object") return false;
|
|
3746
|
+
try {
|
|
3747
|
+
return JSON.stringify(prev) === JSON.stringify(next);
|
|
3748
|
+
} catch {
|
|
3749
|
+
return false;
|
|
3750
|
+
}
|
|
3751
|
+
}, "DEFAULT_EQUALITY");
|
|
3752
|
+
var computedMap = /* @__PURE__ */ new Map();
|
|
3753
|
+
function _normalizeKey(key) {
|
|
3754
|
+
if (!key || typeof key !== "string") return "";
|
|
3755
|
+
const normalized = key.startsWith("state.") ? key : `state.${key}`;
|
|
3756
|
+
return normalized;
|
|
3757
|
+
}
|
|
3758
|
+
__name(_normalizeKey, "_normalizeKey");
|
|
3759
|
+
function _invalidate(key) {
|
|
3760
|
+
const entry = computedMap.get(key);
|
|
3761
|
+
if (!entry) return;
|
|
3762
|
+
const newValue = _recompute(entry);
|
|
3763
|
+
if (entry.equality(entry.lastValue, newValue)) {
|
|
3764
|
+
return;
|
|
3765
|
+
}
|
|
3766
|
+
entry.lastValue = newValue;
|
|
3767
|
+
for (const sub of entry.subscribers) {
|
|
3768
|
+
try {
|
|
3769
|
+
sub(newValue);
|
|
3770
|
+
} catch (err) {
|
|
3771
|
+
if (exports.DEV) console.error("[memorio computed] subscriber error:", err);
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
dispatch.set("memorio:computed:" + key, { detail: { key, value: newValue } });
|
|
3218
3775
|
}
|
|
3219
|
-
__name(
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
}, "configure");
|
|
3225
|
-
var enable = /* @__PURE__ */ __name(() => {
|
|
3226
|
-
config.enabled = true;
|
|
3227
|
-
}, "enable");
|
|
3228
|
-
var disable = /* @__PURE__ */ __name(() => {
|
|
3229
|
-
config.enabled = false;
|
|
3230
|
-
}, "disable");
|
|
3231
|
-
var isEnabled = /* @__PURE__ */ __name((module) => {
|
|
3232
|
-
return config.enabled && config.modules.includes(module);
|
|
3233
|
-
}, "isEnabled");
|
|
3234
|
-
var log = /* @__PURE__ */ __name((module, action, path, value, previousValue) => {
|
|
3235
|
-
if (!isEnabled(module)) return;
|
|
3236
|
-
const entry = {
|
|
3237
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3238
|
-
module,
|
|
3239
|
-
action,
|
|
3240
|
-
path,
|
|
3241
|
-
value,
|
|
3242
|
-
previousValue
|
|
3243
|
-
};
|
|
3244
|
-
logHistory.push(entry);
|
|
3245
|
-
if (logHistory.length > config.maxEntries) {
|
|
3246
|
-
logHistory.shift();
|
|
3776
|
+
__name(_invalidate, "_invalidate");
|
|
3777
|
+
function _readStatePath(path) {
|
|
3778
|
+
const entry = computedMap.get(path);
|
|
3779
|
+
if (entry) {
|
|
3780
|
+
return entry.lastValue;
|
|
3247
3781
|
}
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3782
|
+
const normalized = path.startsWith("state.") ? path : `state.${path}`;
|
|
3783
|
+
const segments = normalized.replace(/^state\./, "").split(".");
|
|
3784
|
+
let current = globalThis.state;
|
|
3785
|
+
if (current) {
|
|
3786
|
+
for (const seg of segments) {
|
|
3787
|
+
if (current === null || current === void 0) break;
|
|
3788
|
+
try {
|
|
3789
|
+
current = current[seg];
|
|
3790
|
+
} catch {
|
|
3791
|
+
return void 0;
|
|
3792
|
+
}
|
|
3258
3793
|
}
|
|
3259
|
-
|
|
3260
|
-
|
|
3794
|
+
}
|
|
3795
|
+
return current === void 0 ? null : current;
|
|
3796
|
+
}
|
|
3797
|
+
__name(_readStatePath, "_readStatePath");
|
|
3798
|
+
function _recompute(entry) {
|
|
3799
|
+
const newDeps = /* @__PURE__ */ new Set();
|
|
3800
|
+
const trackerGet = /* @__PURE__ */ __name((path) => {
|
|
3801
|
+
if (!path || typeof path !== "string") return void 0;
|
|
3802
|
+
newDeps.add(path);
|
|
3803
|
+
return _readStatePath(path);
|
|
3804
|
+
}, "trackerGet");
|
|
3805
|
+
try {
|
|
3806
|
+
return entry.selector(trackerGet);
|
|
3807
|
+
} catch (err) {
|
|
3808
|
+
if (exports.DEV) console.error("[memorio computed] selector error:", err);
|
|
3809
|
+
message_default(`[memorio computed] selector error: ${err}`);
|
|
3810
|
+
return entry.lastValue;
|
|
3811
|
+
}
|
|
3812
|
+
}
|
|
3813
|
+
__name(_recompute, "_recompute");
|
|
3814
|
+
function _setupDeps(key, entry, deps) {
|
|
3815
|
+
for (const off of entry._dispatchUnsubscribers) off();
|
|
3816
|
+
entry._dispatchUnsubscribers = [];
|
|
3817
|
+
for (const dep of deps) {
|
|
3818
|
+
if (computedMap.has(dep)) {
|
|
3819
|
+
const computedEvent = "memorio:computed:" + dep;
|
|
3820
|
+
const off = dispatch.listen(computedEvent, () => _invalidate(key));
|
|
3821
|
+
if (off) entry._dispatchUnsubscribers.push(off);
|
|
3822
|
+
} else {
|
|
3823
|
+
const off = dispatch.listen(dep, () => _invalidate(key));
|
|
3824
|
+
if (off) entry._dispatchUnsubscribers.push(off);
|
|
3261
3825
|
}
|
|
3262
3826
|
}
|
|
3263
|
-
|
|
3264
|
-
|
|
3827
|
+
entry.deps = deps;
|
|
3828
|
+
}
|
|
3829
|
+
__name(_setupDeps, "_setupDeps");
|
|
3830
|
+
function _compute(key, selector, opts) {
|
|
3831
|
+
const normalizedKey = _normalizeKey(key);
|
|
3832
|
+
const cacheKey = opts?.equalityKey ? `${opts.equalityKey}:${normalizedKey}` : normalizedKey;
|
|
3833
|
+
if (computedMap.has(cacheKey)) {
|
|
3834
|
+
const entry2 = computedMap.get(cacheKey);
|
|
3835
|
+
entry2.selector = selector;
|
|
3836
|
+
entry2.equality = opts?.equality || DEFAULT_EQUALITY;
|
|
3837
|
+
const newDeps2 = /* @__PURE__ */ new Set();
|
|
3838
|
+
const wrappedGet = /* @__PURE__ */ __name((path) => {
|
|
3839
|
+
newDeps2.add(path);
|
|
3840
|
+
return _readStatePath(path);
|
|
3841
|
+
}, "wrappedGet");
|
|
3842
|
+
let newValue;
|
|
3843
|
+
try {
|
|
3844
|
+
newValue = selector(wrappedGet);
|
|
3845
|
+
} catch (err) {
|
|
3846
|
+
if (exports.DEV) console.error("[memorio computed] selector error:", err);
|
|
3847
|
+
return entry2.lastValue;
|
|
3848
|
+
}
|
|
3849
|
+
if (entry2.equality(entry2.lastValue, newValue)) {
|
|
3850
|
+
return entry2.lastValue;
|
|
3851
|
+
}
|
|
3852
|
+
entry2.lastValue = newValue;
|
|
3853
|
+
_setupDeps(cacheKey, entry2, newDeps2);
|
|
3854
|
+
for (const sub of entry2.subscribers) {
|
|
3855
|
+
try {
|
|
3856
|
+
sub(newValue);
|
|
3857
|
+
} catch (err) {
|
|
3858
|
+
if (exports.DEV) console.error("[memorio computed] subscriber error:", err);
|
|
3859
|
+
}
|
|
3860
|
+
}
|
|
3861
|
+
return newValue;
|
|
3862
|
+
}
|
|
3863
|
+
const newDeps = /* @__PURE__ */ new Set();
|
|
3864
|
+
const get = /* @__PURE__ */ __name((path) => {
|
|
3865
|
+
newDeps.add(path);
|
|
3866
|
+
return _readStatePath(path);
|
|
3867
|
+
}, "get");
|
|
3868
|
+
let lastValue;
|
|
3869
|
+
try {
|
|
3870
|
+
lastValue = selector(get);
|
|
3871
|
+
} catch (err) {
|
|
3872
|
+
if (exports.DEV) console.error("[memorio computed] selector error:", err);
|
|
3873
|
+
message_default(`[memorio computed] selector error: ${err}`);
|
|
3874
|
+
lastValue = null;
|
|
3265
3875
|
}
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
idb: "#F44336"
|
|
3876
|
+
const entry = {
|
|
3877
|
+
selector,
|
|
3878
|
+
lastValue,
|
|
3879
|
+
deps: newDeps,
|
|
3880
|
+
equality: opts?.equality || DEFAULT_EQUALITY,
|
|
3881
|
+
subscribers: /* @__PURE__ */ new Set(),
|
|
3882
|
+
_dispatchUnsubscribers: []
|
|
3274
3883
|
};
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3884
|
+
computedMap.set(cacheKey, entry);
|
|
3885
|
+
_setupDeps(cacheKey, entry, newDeps);
|
|
3886
|
+
return lastValue;
|
|
3887
|
+
}
|
|
3888
|
+
__name(_compute, "_compute");
|
|
3889
|
+
function _getValue(key) {
|
|
3890
|
+
const normalizedKey = _normalizeKey(key);
|
|
3891
|
+
const entry = computedMap.get(normalizedKey);
|
|
3892
|
+
if (!entry) return null;
|
|
3893
|
+
return entry.lastValue;
|
|
3894
|
+
}
|
|
3895
|
+
__name(_getValue, "_getValue");
|
|
3896
|
+
function _subscribe(key, cb) {
|
|
3897
|
+
const normalizedKey = _normalizeKey(key);
|
|
3898
|
+
const entry = computedMap.get(normalizedKey);
|
|
3899
|
+
if (!entry) {
|
|
3900
|
+
if (exports.DEV) console.warn(`[memorio computed] subscribe: no computed value registered for key '${key}'`);
|
|
3901
|
+
return () => {
|
|
3902
|
+
};
|
|
3903
|
+
}
|
|
3904
|
+
entry.subscribers.add(cb);
|
|
3905
|
+
return () => {
|
|
3906
|
+
entry.subscribers.delete(cb);
|
|
3907
|
+
};
|
|
3908
|
+
}
|
|
3909
|
+
__name(_subscribe, "_subscribe");
|
|
3910
|
+
function _remove3(key) {
|
|
3911
|
+
const normalizedKey = _normalizeKey(key);
|
|
3912
|
+
if (!computedMap.has(normalizedKey)) return false;
|
|
3913
|
+
const entry = computedMap.get(normalizedKey);
|
|
3914
|
+
for (const off of entry._dispatchUnsubscribers) off();
|
|
3915
|
+
computedMap.delete(normalizedKey);
|
|
3916
|
+
return true;
|
|
3917
|
+
}
|
|
3918
|
+
__name(_remove3, "_remove");
|
|
3919
|
+
function _list() {
|
|
3920
|
+
return Array.from(computedMap.keys());
|
|
3921
|
+
}
|
|
3922
|
+
__name(_list, "_list");
|
|
3923
|
+
function _clear() {
|
|
3924
|
+
for (const [, entry] of computedMap) {
|
|
3925
|
+
for (const off of entry._dispatchUnsubscribers) off();
|
|
3926
|
+
}
|
|
3927
|
+
computedMap.clear();
|
|
3928
|
+
}
|
|
3929
|
+
__name(_clear, "_clear");
|
|
3930
|
+
var computed = {
|
|
3931
|
+
compute: _compute,
|
|
3932
|
+
getValue: _getValue,
|
|
3933
|
+
subscribe: _subscribe,
|
|
3934
|
+
remove: _remove3,
|
|
3935
|
+
list: _list,
|
|
3936
|
+
clear: _clear
|
|
3937
|
+
};
|
|
3938
|
+
|
|
3939
|
+
// functions/broadcast/index.ts
|
|
3940
|
+
init_cjs_shims();
|
|
3941
|
+
init_env();
|
|
3942
|
+
init_message();
|
|
3943
|
+
var _channel = null;
|
|
3944
|
+
var _storageListener = null;
|
|
3945
|
+
var _originalDispatchSet = null;
|
|
3946
|
+
var _installed = false;
|
|
3947
|
+
var _targets = "all";
|
|
3948
|
+
var _isLocalChange = false;
|
|
3949
|
+
function _hasBroadcastChannel() {
|
|
3950
|
+
return typeof BroadcastChannel !== "undefined";
|
|
3951
|
+
}
|
|
3952
|
+
__name(_hasBroadcastChannel, "_hasBroadcastChannel");
|
|
3953
|
+
function _hasStorageEvents() {
|
|
3954
|
+
return typeof window !== "undefined" && "addEventListener" in window;
|
|
3955
|
+
}
|
|
3956
|
+
__name(_hasStorageEvents, "_hasStorageEvents");
|
|
3957
|
+
function _shouldSync(target) {
|
|
3958
|
+
if (_targets === "all") return true;
|
|
3959
|
+
return _targets === target;
|
|
3960
|
+
}
|
|
3961
|
+
__name(_shouldSync, "_shouldSync");
|
|
3962
|
+
function _onBroadcastMessage(event) {
|
|
3963
|
+
let msg;
|
|
3964
|
+
try {
|
|
3965
|
+
msg = event.data;
|
|
3966
|
+
} catch {
|
|
3967
|
+
return;
|
|
3968
|
+
}
|
|
3969
|
+
if (!msg || !msg.__memorio_sync) return;
|
|
3970
|
+
if (!_shouldSync(msg.target)) return;
|
|
3971
|
+
if (_isLocalChange) return;
|
|
3972
|
+
try {
|
|
3973
|
+
if (msg.target === "state" || msg.target === "all") {
|
|
3974
|
+
const s = globalThis.state;
|
|
3975
|
+
if (s) {
|
|
3976
|
+
_isLocalChange = true;
|
|
3977
|
+
try {
|
|
3978
|
+
const segments = msg.path.replace(/^state\./, "").split(".");
|
|
3979
|
+
let current = s;
|
|
3980
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
3981
|
+
const seg = segments[i];
|
|
3982
|
+
if (current[seg] === void 0 || current[seg] === null) {
|
|
3983
|
+
current[seg] = {};
|
|
3984
|
+
}
|
|
3985
|
+
current = current[seg];
|
|
3986
|
+
}
|
|
3987
|
+
const lastSeg = segments[segments.length - 1];
|
|
3988
|
+
if (msg.action === "set") {
|
|
3989
|
+
current[lastSeg] = msg.value;
|
|
3990
|
+
} else if (msg.action === "delete") {
|
|
3991
|
+
delete current[lastSeg];
|
|
3992
|
+
}
|
|
3993
|
+
} finally {
|
|
3994
|
+
queueMicrotask(() => {
|
|
3995
|
+
_isLocalChange = false;
|
|
3996
|
+
});
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
}
|
|
4000
|
+
} catch (err) {
|
|
4001
|
+
if (exports.DEV) console.error("[memorio broadcast] apply state error:", err);
|
|
4002
|
+
}
|
|
4003
|
+
}
|
|
4004
|
+
__name(_onBroadcastMessage, "_onBroadcastMessage");
|
|
4005
|
+
function _onStorageEvent(e) {
|
|
4006
|
+
if (!e.key) return;
|
|
4007
|
+
const prefixes = [
|
|
4008
|
+
["memorio_store_", "store"],
|
|
4009
|
+
["memorio_session_", "session"]
|
|
4010
|
+
];
|
|
4011
|
+
for (const [prefix, target] of prefixes) {
|
|
4012
|
+
if (e.key.startsWith(prefix)) {
|
|
4013
|
+
if (!_shouldSync(target)) continue;
|
|
4014
|
+
const cleanKey = e.key.slice(prefix.length);
|
|
4015
|
+
dispatch.set(`memorio:broadcast:${target}:${cleanKey}`, {
|
|
4016
|
+
detail: { key: cleanKey, oldValue: e.oldValue, newValue: e.newValue }
|
|
4017
|
+
});
|
|
4018
|
+
break;
|
|
4019
|
+
}
|
|
4020
|
+
}
|
|
4021
|
+
}
|
|
4022
|
+
__name(_onStorageEvent, "_onStorageEvent");
|
|
4023
|
+
function _wrapDispatchSet() {
|
|
4024
|
+
if (_originalDispatchSet !== null) return;
|
|
4025
|
+
_originalDispatchSet = dispatch.set;
|
|
4026
|
+
const original = dispatch.set;
|
|
4027
|
+
dispatch.set = (name, value) => {
|
|
4028
|
+
original(name, value);
|
|
4029
|
+
if (name.startsWith("state.") && _shouldSync("state") && _channel) {
|
|
4030
|
+
_isLocalChange = true;
|
|
4031
|
+
try {
|
|
4032
|
+
_channel.postMessage({
|
|
4033
|
+
__memorio_sync: true,
|
|
4034
|
+
target: "state",
|
|
4035
|
+
action: "set",
|
|
4036
|
+
path: name,
|
|
4037
|
+
value: _extractStateValue(name),
|
|
4038
|
+
timestamp: Date.now()
|
|
4039
|
+
});
|
|
4040
|
+
} finally {
|
|
4041
|
+
queueMicrotask(() => {
|
|
4042
|
+
_isLocalChange = false;
|
|
4043
|
+
});
|
|
4044
|
+
}
|
|
4045
|
+
}
|
|
4046
|
+
};
|
|
4047
|
+
}
|
|
4048
|
+
__name(_wrapDispatchSet, "_wrapDispatchSet");
|
|
4049
|
+
function _restoreDispatchSet() {
|
|
4050
|
+
if (_originalDispatchSet !== null) {
|
|
4051
|
+
dispatch.set = _originalDispatchSet;
|
|
4052
|
+
_originalDispatchSet = null;
|
|
4053
|
+
}
|
|
4054
|
+
}
|
|
4055
|
+
__name(_restoreDispatchSet, "_restoreDispatchSet");
|
|
4056
|
+
function _extractStateValue(path) {
|
|
4057
|
+
const s = globalThis.state;
|
|
4058
|
+
if (!s) return void 0;
|
|
4059
|
+
try {
|
|
4060
|
+
const segments = path.replace(/^state\./, "").split(".");
|
|
4061
|
+
let current = s;
|
|
4062
|
+
for (const seg of segments) {
|
|
4063
|
+
if (current === null || current === void 0) break;
|
|
4064
|
+
current = current[seg];
|
|
4065
|
+
}
|
|
4066
|
+
return current === void 0 ? null : current;
|
|
4067
|
+
} catch {
|
|
4068
|
+
return null;
|
|
4069
|
+
}
|
|
4070
|
+
}
|
|
4071
|
+
__name(_extractStateValue, "_extractStateValue");
|
|
4072
|
+
var broadcast = {
|
|
4073
|
+
install: /* @__PURE__ */ __name((channelName, opts) => {
|
|
4074
|
+
if (_installed) return;
|
|
4075
|
+
const name = channelName || opts?.channelName || "memorio_sync";
|
|
4076
|
+
_targets = opts?.targets || "all";
|
|
4077
|
+
if (_hasBroadcastChannel()) {
|
|
4078
|
+
_channel = new BroadcastChannel(name);
|
|
4079
|
+
_channel.addEventListener("message", _onBroadcastMessage);
|
|
4080
|
+
_installed = true;
|
|
4081
|
+
_wrapDispatchSet();
|
|
4082
|
+
if (exports.DEV) message_default(`memorio broadcast: installed (channel="${name}", targets="${_targets}")`);
|
|
4083
|
+
}
|
|
4084
|
+
if (_hasStorageEvents()) {
|
|
4085
|
+
_storageListener = _onStorageEvent;
|
|
4086
|
+
window.addEventListener("storage", _storageListener);
|
|
4087
|
+
_installed = true;
|
|
4088
|
+
if (!_hasBroadcastChannel() && exports.DEV) {
|
|
4089
|
+
message_default(`memorio broadcast: using storage event fallback (targets="${_targets}")`);
|
|
4090
|
+
}
|
|
4091
|
+
}
|
|
4092
|
+
if (!_installed) {
|
|
4093
|
+
console.warn("[memorio broadcast] Neither BroadcastChannel nor storage events are available in this environment.");
|
|
4094
|
+
}
|
|
4095
|
+
}, "install"),
|
|
4096
|
+
uninstall: /* @__PURE__ */ __name(() => {
|
|
4097
|
+
if (_channel) {
|
|
4098
|
+
_channel.removeEventListener("message", _onBroadcastMessage);
|
|
4099
|
+
_channel.close();
|
|
4100
|
+
_channel = null;
|
|
4101
|
+
}
|
|
4102
|
+
if (_storageListener && typeof window !== "undefined") {
|
|
4103
|
+
window.removeEventListener("storage", _storageListener);
|
|
4104
|
+
_storageListener = null;
|
|
4105
|
+
}
|
|
4106
|
+
_restoreDispatchSet();
|
|
4107
|
+
_installed = false;
|
|
4108
|
+
}, "uninstall"),
|
|
4109
|
+
isInstalled: /* @__PURE__ */ __name(() => _installed, "isInstalled"),
|
|
4110
|
+
broadcast: /* @__PURE__ */ __name((msg) => {
|
|
4111
|
+
if (!_channel) return;
|
|
4112
|
+
_channel.postMessage({ ...msg, timestamp: Date.now() });
|
|
4113
|
+
}, "broadcast")
|
|
4114
|
+
};
|
|
4115
|
+
|
|
4116
|
+
// functions/security/index.ts
|
|
4117
|
+
init_cjs_shims();
|
|
4118
|
+
init_env();
|
|
4119
|
+
function _safeRandomUUID() {
|
|
4120
|
+
const g3 = globalThis;
|
|
4121
|
+
if (typeof g3.crypto !== "undefined" && typeof g3.crypto.randomUUID === "function") {
|
|
4122
|
+
try {
|
|
4123
|
+
return g3.crypto.randomUUID();
|
|
4124
|
+
} catch {
|
|
4125
|
+
}
|
|
4126
|
+
}
|
|
4127
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
4128
|
+
}
|
|
4129
|
+
__name(_safeRandomUUID, "_safeRandomUUID");
|
|
4130
|
+
var REGEX_TIMEOUT_MS = 100;
|
|
4131
|
+
function _safeRegexTest(pattern, key) {
|
|
4132
|
+
if (/\(.*[+*?].*.*\)[+*?]/.test(pattern)) {
|
|
4133
|
+
if (exports.DEV) console.warn(`[memorio security] Potentially dangerous regex blocked: ${pattern}`);
|
|
4134
|
+
return false;
|
|
4135
|
+
}
|
|
4136
|
+
if (pattern.length > 500) {
|
|
4137
|
+
if (exports.DEV) console.warn("[memorio security] Regex pattern exceeds max length (500)");
|
|
4138
|
+
return false;
|
|
4139
|
+
}
|
|
4140
|
+
const startTime = Date.now();
|
|
4141
|
+
try {
|
|
4142
|
+
const regex = new RegExp(pattern);
|
|
4143
|
+
const result = regex.test(key);
|
|
4144
|
+
const elapsed = Date.now() - startTime;
|
|
4145
|
+
if (elapsed > REGEX_TIMEOUT_MS) {
|
|
4146
|
+
if (exports.DEV) console.warn(`[memorio security] Slow regex detected (${elapsed}ms): ${pattern}`);
|
|
4147
|
+
}
|
|
4148
|
+
return result;
|
|
4149
|
+
} catch {
|
|
4150
|
+
return false;
|
|
4151
|
+
}
|
|
4152
|
+
}
|
|
4153
|
+
__name(_safeRegexTest, "_safeRegexTest");
|
|
4154
|
+
function addAccessRule(rules, pattern, perms) {
|
|
4155
|
+
const key = pattern instanceof RegExp ? pattern.source : pattern;
|
|
4156
|
+
rules.set(key, perms);
|
|
4157
|
+
return rules;
|
|
4158
|
+
}
|
|
4159
|
+
__name(addAccessRule, "addAccessRule");
|
|
4160
|
+
function hasPermission(rules, key, action, userId) {
|
|
4161
|
+
if (rules.size === 0) return true;
|
|
4162
|
+
for (const [pattern, perms] of rules) {
|
|
4163
|
+
let matches;
|
|
4164
|
+
if (typeof pattern === "function") {
|
|
4165
|
+
try {
|
|
4166
|
+
matches = pattern(key, userId);
|
|
4167
|
+
} catch {
|
|
4168
|
+
matches = false;
|
|
4169
|
+
}
|
|
4170
|
+
} else {
|
|
4171
|
+
matches = _safeRegexTest(pattern, key);
|
|
4172
|
+
}
|
|
4173
|
+
if (matches) {
|
|
4174
|
+
const allowed = perms.includes(action) || perms.includes("admin");
|
|
4175
|
+
if (!allowed) {
|
|
4176
|
+
logAudit({
|
|
4177
|
+
action,
|
|
4178
|
+
key,
|
|
4179
|
+
userId,
|
|
4180
|
+
success: false,
|
|
4181
|
+
error: "RBAC Denied: insufficient permissions"
|
|
4182
|
+
});
|
|
4183
|
+
}
|
|
4184
|
+
return allowed;
|
|
4185
|
+
}
|
|
4186
|
+
}
|
|
4187
|
+
logAudit({
|
|
4188
|
+
action: "permission_check",
|
|
4189
|
+
key,
|
|
4190
|
+
userId,
|
|
4191
|
+
success: false,
|
|
4192
|
+
error: "RBAC Denied: no matching rule"
|
|
4193
|
+
});
|
|
4194
|
+
return false;
|
|
4195
|
+
}
|
|
4196
|
+
__name(hasPermission, "hasPermission");
|
|
4197
|
+
var _auditLogger = null;
|
|
4198
|
+
function isAuditActive() {
|
|
4199
|
+
return _auditLogger !== null;
|
|
4200
|
+
}
|
|
4201
|
+
__name(isAuditActive, "isAuditActive");
|
|
4202
|
+
function setAuditLogger(logger3) {
|
|
4203
|
+
_auditLogger = logger3;
|
|
4204
|
+
}
|
|
4205
|
+
__name(setAuditLogger, "setAuditLogger");
|
|
4206
|
+
function logAudit(entry) {
|
|
4207
|
+
if (!_auditLogger) return;
|
|
4208
|
+
_auditLogger({
|
|
4209
|
+
timestamp: Date.now(),
|
|
4210
|
+
success: true,
|
|
4211
|
+
...entry
|
|
4212
|
+
});
|
|
4213
|
+
}
|
|
4214
|
+
__name(logAudit, "logAudit");
|
|
4215
|
+
function sanitizeValue(value) {
|
|
4216
|
+
if (typeof value === "string") {
|
|
4217
|
+
let decoded = value.replace(/&#[xX]?[0-9a-fA-F]+;?/g, (match) => {
|
|
4218
|
+
const hexMatch = match.match(/&#x([0-9a-fA-F]+);?/i);
|
|
4219
|
+
if (hexMatch && hexMatch[1]) {
|
|
4220
|
+
return String.fromCharCode(parseInt(hexMatch[1], 16));
|
|
4221
|
+
}
|
|
4222
|
+
const decMatch = match.match(/&#([0-9]+);?/);
|
|
4223
|
+
if (decMatch && decMatch[1]) {
|
|
4224
|
+
return String.fromCharCode(parseInt(decMatch[1], 10));
|
|
4225
|
+
}
|
|
4226
|
+
return match;
|
|
4227
|
+
});
|
|
4228
|
+
try {
|
|
4229
|
+
decoded = decodeURIComponent(decoded);
|
|
4230
|
+
} catch {
|
|
4231
|
+
}
|
|
4232
|
+
decoded = decoded.replace(/(javascript|vbscript|data:text\/html|about:blank|chrome:)/gi, "[SEC-REMOVED]");
|
|
4233
|
+
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]");
|
|
4234
|
+
}
|
|
4235
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
4236
|
+
const ctor = value.constructor?.name;
|
|
4237
|
+
if (ctor === "Object" || ctor === void 0) {
|
|
4238
|
+
const sanitized = {};
|
|
4239
|
+
for (const [k, v] of Object.entries(value)) {
|
|
4240
|
+
if (k === "__proto__" || k === "constructor" || k === "prototype") continue;
|
|
4241
|
+
sanitized[k] = sanitizeValue(v);
|
|
4242
|
+
}
|
|
4243
|
+
return sanitized;
|
|
4244
|
+
}
|
|
4245
|
+
return value;
|
|
4246
|
+
}
|
|
4247
|
+
if (Array.isArray(value)) {
|
|
4248
|
+
return value.map((v) => sanitizeValue(v));
|
|
4249
|
+
}
|
|
4250
|
+
return value;
|
|
4251
|
+
}
|
|
4252
|
+
__name(sanitizeValue, "sanitizeValue");
|
|
4253
|
+
function validateKey(key) {
|
|
4254
|
+
return /^[a-zA-Z0-9_.-]+$/.test(key) && key.length <= 256 && key.length > 0;
|
|
4255
|
+
}
|
|
4256
|
+
__name(validateKey, "validateKey");
|
|
4257
|
+
function recordConsent(consents, userId, purpose, granted) {
|
|
4258
|
+
const record = {
|
|
4259
|
+
id: _safeRandomUUID(),
|
|
4260
|
+
purpose,
|
|
4261
|
+
granted,
|
|
4262
|
+
timestamp: Date.now()
|
|
4263
|
+
};
|
|
4264
|
+
const user = consents.get(userId) || [];
|
|
4265
|
+
user.push(record);
|
|
4266
|
+
consents.set(userId, user);
|
|
4267
|
+
return record;
|
|
4268
|
+
}
|
|
4269
|
+
__name(recordConsent, "recordConsent");
|
|
4270
|
+
function hasConsent(consents, userId, purpose) {
|
|
4271
|
+
const userConsents = consents.get(userId);
|
|
4272
|
+
if (!userConsents) return false;
|
|
4273
|
+
for (let i = userConsents.length - 1; i >= 0; i--) {
|
|
4274
|
+
const record = userConsents[i];
|
|
4275
|
+
if (record && record.purpose === purpose) {
|
|
4276
|
+
return record.granted;
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
4279
|
+
return false;
|
|
4280
|
+
}
|
|
4281
|
+
__name(hasConsent, "hasConsent");
|
|
4282
|
+
function revokeConsent(consents, userId, purpose) {
|
|
4283
|
+
return recordConsent(consents, userId, purpose, false);
|
|
4284
|
+
}
|
|
4285
|
+
__name(revokeConsent, "revokeConsent");
|
|
4286
|
+
function getConsents(consents, userId) {
|
|
4287
|
+
return consents.get(userId) || [];
|
|
4288
|
+
}
|
|
4289
|
+
__name(getConsents, "getConsents");
|
|
4290
|
+
function exportUserData(consents, userId) {
|
|
4291
|
+
return {
|
|
4292
|
+
userId,
|
|
4293
|
+
exportedAt: Date.now(),
|
|
4294
|
+
consents: consents.get(userId) || []
|
|
4295
|
+
};
|
|
4296
|
+
}
|
|
4297
|
+
__name(exportUserData, "exportUserData");
|
|
4298
|
+
function deleteUserData(consents, userId) {
|
|
4299
|
+
const count = consents.get(userId)?.length || 0;
|
|
4300
|
+
consents.delete(userId);
|
|
4301
|
+
return { success: true, deletedConsents: count };
|
|
4302
|
+
}
|
|
4303
|
+
__name(deleteUserData, "deleteUserData");
|
|
4304
|
+
var security = {
|
|
4305
|
+
// Re-exports for convenience
|
|
4306
|
+
safeRandomUUID: _safeRandomUUID,
|
|
4307
|
+
safeRegexTest: _safeRegexTest,
|
|
4308
|
+
// RBAC
|
|
4309
|
+
addAccessRule,
|
|
4310
|
+
hasPermission,
|
|
4311
|
+
// Audit logging
|
|
4312
|
+
isAuditActive,
|
|
4313
|
+
setAuditLogger,
|
|
4314
|
+
logAudit,
|
|
4315
|
+
// Input sanitization
|
|
4316
|
+
sanitizeValue,
|
|
4317
|
+
validateKey,
|
|
4318
|
+
// Consent management
|
|
4319
|
+
recordConsent,
|
|
4320
|
+
hasConsent,
|
|
4321
|
+
revokeConsent,
|
|
4322
|
+
getConsents,
|
|
4323
|
+
exportUserData,
|
|
4324
|
+
deleteUserData
|
|
4325
|
+
};
|
|
4326
|
+
|
|
4327
|
+
// index.ts
|
|
4328
|
+
init_message();
|
|
4329
|
+
|
|
4330
|
+
// functions/logger/index.ts
|
|
4331
|
+
init_cjs_shims();
|
|
4332
|
+
init_internal();
|
|
4333
|
+
init_message();
|
|
4334
|
+
init_env();
|
|
4335
|
+
var defaultConfig = {
|
|
4336
|
+
enabled: true,
|
|
4337
|
+
logToConsole: true,
|
|
4338
|
+
modules: ["state", "store", "session", "cache", "idb"],
|
|
4339
|
+
maxEntries: 1e3
|
|
4340
|
+
};
|
|
4341
|
+
function isDebugEnabled() {
|
|
4342
|
+
return exports.DEV && exports.internal.debug === true;
|
|
4343
|
+
}
|
|
4344
|
+
__name(isDebugEnabled, "isDebugEnabled");
|
|
4345
|
+
var config = { ...defaultConfig };
|
|
4346
|
+
var logHistory = [];
|
|
4347
|
+
var configure = /* @__PURE__ */ __name((options) => {
|
|
4348
|
+
config = { ...config, ...options };
|
|
4349
|
+
}, "configure");
|
|
4350
|
+
var enable = /* @__PURE__ */ __name(() => {
|
|
4351
|
+
config.enabled = true;
|
|
4352
|
+
}, "enable");
|
|
4353
|
+
var disable = /* @__PURE__ */ __name(() => {
|
|
4354
|
+
config.enabled = false;
|
|
4355
|
+
}, "disable");
|
|
4356
|
+
var isEnabled = /* @__PURE__ */ __name((module) => {
|
|
4357
|
+
return config.enabled && config.modules.includes(module);
|
|
4358
|
+
}, "isEnabled");
|
|
4359
|
+
var log = /* @__PURE__ */ __name((module, action, path, value, previousValue) => {
|
|
4360
|
+
if (!isEnabled(module)) return;
|
|
4361
|
+
const entry = {
|
|
4362
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4363
|
+
module,
|
|
4364
|
+
action,
|
|
4365
|
+
path,
|
|
4366
|
+
value,
|
|
4367
|
+
previousValue
|
|
4368
|
+
};
|
|
4369
|
+
logHistory.push(entry);
|
|
4370
|
+
if (logHistory.length > config.maxEntries) {
|
|
4371
|
+
logHistory.shift();
|
|
4372
|
+
}
|
|
4373
|
+
if (config.logToConsole && isDebugEnabled()) {
|
|
4374
|
+
const prefix = `[Memorio:${module.toUpperCase()}]`;
|
|
4375
|
+
const color = getModuleColor(module);
|
|
4376
|
+
message_default(
|
|
4377
|
+
`%c${prefix}%c ${action} ${path},
|
|
4378
|
+
color: ${color}; font-weight: bold,
|
|
4379
|
+
color: inherit`
|
|
4380
|
+
);
|
|
4381
|
+
if (value !== void 0) {
|
|
4382
|
+
message_default(` \u2192 value:${value}`);
|
|
4383
|
+
}
|
|
4384
|
+
if (previousValue !== void 0) {
|
|
4385
|
+
message_default(` \u2190 previous:${previousValue}`);
|
|
4386
|
+
}
|
|
4387
|
+
}
|
|
4388
|
+
if (config.customHandler) {
|
|
4389
|
+
config.customHandler(entry);
|
|
4390
|
+
}
|
|
4391
|
+
}, "log");
|
|
4392
|
+
var getModuleColor = /* @__PURE__ */ __name((module) => {
|
|
4393
|
+
const colors = {
|
|
4394
|
+
state: "#4CAF50",
|
|
4395
|
+
store: "#2196F3",
|
|
4396
|
+
session: "#FF9800",
|
|
4397
|
+
cache: "#9C27B0",
|
|
4398
|
+
idb: "#F44336"
|
|
4399
|
+
};
|
|
4400
|
+
return colors[module] || "#888888";
|
|
4401
|
+
}, "getModuleColor");
|
|
4402
|
+
var getHistory = /* @__PURE__ */ __name(() => {
|
|
4403
|
+
return [...logHistory];
|
|
4404
|
+
}, "getHistory");
|
|
4405
|
+
var clearHistory = /* @__PURE__ */ __name(() => {
|
|
4406
|
+
logHistory.length = 0;
|
|
4407
|
+
}, "clearHistory");
|
|
4408
|
+
var getStats = /* @__PURE__ */ __name(() => {
|
|
4409
|
+
const stats = {
|
|
4410
|
+
total: logHistory.length,
|
|
4411
|
+
state: 0,
|
|
4412
|
+
store: 0,
|
|
4413
|
+
session: 0,
|
|
3289
4414
|
cache: 0,
|
|
3290
4415
|
idb: 0,
|
|
3291
4416
|
set: 0,
|
|
@@ -3465,228 +4590,67 @@ function reorder(items, fromIndex, toIndex) {
|
|
|
3465
4590
|
if (fromIndex === toIndex) return items.map((i) => i.key);
|
|
3466
4591
|
const reordered = [...items];
|
|
3467
4592
|
const [removed] = reordered.splice(fromIndex, 1);
|
|
3468
|
-
reordered.splice(toIndex, 0, removed);
|
|
3469
|
-
return reordered.map((i) => i.key);
|
|
3470
|
-
}
|
|
3471
|
-
__name(reorder, "reorder");
|
|
3472
|
-
function reindex(items) {
|
|
3473
|
-
if (items.length === 0) return items;
|
|
3474
|
-
const result = [];
|
|
3475
|
-
let prev = null;
|
|
3476
|
-
for (let i = 0; i < items.length; i++) {
|
|
3477
|
-
const next = i < items.length - 1 ? items[i + 1].key : null;
|
|
3478
|
-
const newItem = { ...items[i] };
|
|
3479
|
-
if (prev === null) {
|
|
3480
|
-
newItem.key = before(items[0].key);
|
|
3481
|
-
} else if (next === null) {
|
|
3482
|
-
newItem.key = after(prev);
|
|
3483
|
-
} else {
|
|
3484
|
-
newItem.key = between(prev, next);
|
|
3485
|
-
}
|
|
3486
|
-
result.push(newItem);
|
|
3487
|
-
prev = newItem.key;
|
|
3488
|
-
}
|
|
3489
|
-
return result;
|
|
3490
|
-
}
|
|
3491
|
-
__name(reindex, "reindex");
|
|
3492
|
-
var fractional = {
|
|
3493
|
-
generateBetween,
|
|
3494
|
-
firstKey,
|
|
3495
|
-
after,
|
|
3496
|
-
before,
|
|
3497
|
-
between,
|
|
3498
|
-
reorder,
|
|
3499
|
-
reindex
|
|
3500
|
-
};
|
|
3501
|
-
|
|
3502
|
-
// index.ts
|
|
3503
|
-
init_internal();
|
|
3504
|
-
init_platform();
|
|
3505
|
-
|
|
3506
|
-
// core/global.ts
|
|
3507
|
-
init_cjs_shims();
|
|
3508
|
-
init_platform();
|
|
3509
|
-
init_internal();
|
|
3510
|
-
|
|
3511
|
-
// package.json
|
|
3512
|
-
var package_default = {
|
|
3513
|
-
version: "5.0.0"};
|
|
3514
|
-
|
|
3515
|
-
// core/global.ts
|
|
3516
|
-
init_env();
|
|
3517
|
-
init_store();
|
|
3518
|
-
init_idb();
|
|
3519
|
-
init_sqlite();
|
|
3520
|
-
init_message();
|
|
3521
|
-
|
|
3522
|
-
// functions/typed/index.ts
|
|
3523
|
-
init_cjs_shims();
|
|
3524
|
-
function typed() {
|
|
3525
|
-
return exports.state;
|
|
3526
|
-
}
|
|
3527
|
-
__name(typed, "typed");
|
|
3528
|
-
|
|
3529
|
-
// functions/history/index.ts
|
|
3530
|
-
init_cjs_shims();
|
|
3531
|
-
init_internal();
|
|
3532
|
-
init_env();
|
|
3533
|
-
init_message();
|
|
3534
|
-
function _clone(value) {
|
|
3535
|
-
if (value === null || typeof value !== "object") return value;
|
|
3536
|
-
try {
|
|
3537
|
-
return deepRaw(value, /* @__PURE__ */ new WeakSet());
|
|
3538
|
-
} catch (err) {
|
|
3539
|
-
if (exports.DEV) console.warn("[memorio history] deep clone failed:", err);
|
|
3540
|
-
return value;
|
|
3541
|
-
}
|
|
3542
|
-
}
|
|
3543
|
-
__name(_clone, "_clone");
|
|
3544
|
-
var snapshot = /* @__PURE__ */ __name(() => {
|
|
3545
|
-
return deepRaw(exports.state, /* @__PURE__ */ new WeakSet());
|
|
3546
|
-
}, "snapshot");
|
|
3547
|
-
var diff = /* @__PURE__ */ __name((snap) => {
|
|
3548
|
-
const changes = [];
|
|
3549
|
-
const _walk = /* @__PURE__ */ __name((oldObj, newObj, prefix) => {
|
|
3550
|
-
const oldKeys = oldObj ? Object.keys(oldObj) : [];
|
|
3551
|
-
const newKeys = newObj ? Object.keys(newObj) : [];
|
|
3552
|
-
for (const key of newKeys) {
|
|
3553
|
-
const newPath = prefix ? `${prefix}.${key}` : key;
|
|
3554
|
-
const oldVal = oldObj ? oldObj[key] : void 0;
|
|
3555
|
-
const newVal = newObj[key];
|
|
3556
|
-
if (oldVal !== newVal) {
|
|
3557
|
-
const oldType = typeof oldVal;
|
|
3558
|
-
const newType = typeof newVal;
|
|
3559
|
-
if (oldType !== newType || oldVal === void 0) {
|
|
3560
|
-
changes.push({ path: newPath, oldValue: oldVal, newValue: newVal });
|
|
3561
|
-
} else if (oldVal && typeof oldVal === "object") {
|
|
3562
|
-
_walk(oldVal, newVal, newPath);
|
|
3563
|
-
} else if (oldVal !== newVal) {
|
|
3564
|
-
changes.push({ path: newPath, oldValue: oldVal, newValue: newVal });
|
|
3565
|
-
}
|
|
3566
|
-
}
|
|
3567
|
-
}
|
|
3568
|
-
for (const key of oldKeys) {
|
|
3569
|
-
if (!(key in (newObj || {}))) {
|
|
3570
|
-
const newPath = prefix ? `${prefix}.${key}` : key;
|
|
3571
|
-
changes.push({ path: newPath, oldValue: oldObj[key], newValue: void 0 });
|
|
3572
|
-
}
|
|
3573
|
-
}
|
|
3574
|
-
}, "_walk");
|
|
3575
|
-
_walk(snap, deepRaw(exports.state), "");
|
|
3576
|
-
return changes;
|
|
3577
|
-
}, "diff");
|
|
3578
|
-
var enableHistory = /* @__PURE__ */ __name((enabled = true) => {
|
|
3579
|
-
exports.internal.historyEnabled = enabled;
|
|
3580
|
-
message_default(`[memorio history] Tracking ${enabled ? "enabled" : "disabled"}`);
|
|
3581
|
-
}, "enableHistory");
|
|
3582
|
-
var trace = /* @__PURE__ */ __name(() => {
|
|
3583
|
-
return [...exports.internal.mutations];
|
|
3584
|
-
}, "trace");
|
|
3585
|
-
var canUndo = /* @__PURE__ */ __name(() => {
|
|
3586
|
-
return exports.internal.canUndo();
|
|
3587
|
-
}, "canUndo");
|
|
3588
|
-
var canRedo = /* @__PURE__ */ __name(() => {
|
|
3589
|
-
return exports.internal.canRedo();
|
|
3590
|
-
}, "canRedo");
|
|
3591
|
-
var undo = /* @__PURE__ */ __name(() => {
|
|
3592
|
-
if (!exports.internal.historyEnabled) {
|
|
3593
|
-
message_default("[memorio history] History is not enabled");
|
|
3594
|
-
return void 0;
|
|
3595
|
-
}
|
|
3596
|
-
const record = exports.internal.popUndo();
|
|
3597
|
-
if (!record) return void 0;
|
|
3598
|
-
_applyInverse2(record);
|
|
3599
|
-
message_default(`[memorio history] Undid: ${record.action} ${record.path}`);
|
|
3600
|
-
return record;
|
|
3601
|
-
}, "undo");
|
|
3602
|
-
var redo = /* @__PURE__ */ __name(() => {
|
|
3603
|
-
if (!exports.internal.historyEnabled) {
|
|
3604
|
-
message_default("[memorio history] History is not enabled");
|
|
3605
|
-
return void 0;
|
|
3606
|
-
}
|
|
3607
|
-
const record = exports.internal.popRedo();
|
|
3608
|
-
if (!record) return void 0;
|
|
3609
|
-
_applyForward(record);
|
|
3610
|
-
message_default(`[memorio history] Redid: ${record.action} ${record.path}`);
|
|
3611
|
-
return record;
|
|
3612
|
-
}, "redo");
|
|
3613
|
-
function _applyInverse2(record) {
|
|
3614
|
-
const wasEnabled = exports.internal.historyEnabled;
|
|
3615
|
-
exports.internal.historyEnabled = false;
|
|
3616
|
-
try {
|
|
3617
|
-
if (record.action === "set") {
|
|
3618
|
-
if (record.previousValue === void 0) {
|
|
3619
|
-
_deletePath2(record.path);
|
|
3620
|
-
} else {
|
|
3621
|
-
_setPath2(record.path, record.previousValue);
|
|
3622
|
-
}
|
|
3623
|
-
} else if (record.action === "delete") {
|
|
3624
|
-
if (record.previousValue !== void 0) {
|
|
3625
|
-
_setPath2(record.path, record.previousValue);
|
|
3626
|
-
}
|
|
3627
|
-
}
|
|
3628
|
-
} finally {
|
|
3629
|
-
exports.internal.historyEnabled = wasEnabled;
|
|
3630
|
-
}
|
|
3631
|
-
}
|
|
3632
|
-
__name(_applyInverse2, "_applyInverse");
|
|
3633
|
-
function _applyForward(record) {
|
|
3634
|
-
const wasEnabled = exports.internal.historyEnabled;
|
|
3635
|
-
exports.internal.historyEnabled = false;
|
|
3636
|
-
try {
|
|
3637
|
-
if (record.action === "set") {
|
|
3638
|
-
_setPath2(record.path, record.newValue);
|
|
3639
|
-
} else if (record.action === "delete") {
|
|
3640
|
-
_deletePath2(record.path);
|
|
3641
|
-
}
|
|
3642
|
-
} finally {
|
|
3643
|
-
exports.internal.historyEnabled = wasEnabled;
|
|
3644
|
-
}
|
|
4593
|
+
reordered.splice(toIndex, 0, removed);
|
|
4594
|
+
return reordered.map((i) => i.key);
|
|
3645
4595
|
}
|
|
3646
|
-
__name(
|
|
3647
|
-
function
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
4596
|
+
__name(reorder, "reorder");
|
|
4597
|
+
function reindex(items) {
|
|
4598
|
+
if (items.length === 0) return items;
|
|
4599
|
+
const result = [];
|
|
4600
|
+
let prev = null;
|
|
4601
|
+
for (let i = 0; i < items.length; i++) {
|
|
4602
|
+
const next = i < items.length - 1 ? items[i + 1].key : null;
|
|
4603
|
+
const newItem = { ...items[i] };
|
|
4604
|
+
if (prev === null) {
|
|
4605
|
+
newItem.key = before(items[0].key);
|
|
4606
|
+
} else if (next === null) {
|
|
4607
|
+
newItem.key = after(prev);
|
|
4608
|
+
} else {
|
|
4609
|
+
newItem.key = between(prev, next);
|
|
3654
4610
|
}
|
|
3655
|
-
|
|
4611
|
+
result.push(newItem);
|
|
4612
|
+
prev = newItem.key;
|
|
3656
4613
|
}
|
|
3657
|
-
|
|
4614
|
+
return result;
|
|
3658
4615
|
}
|
|
3659
|
-
__name(
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
4616
|
+
__name(reindex, "reindex");
|
|
4617
|
+
var fractional = {
|
|
4618
|
+
generateBetween,
|
|
4619
|
+
firstKey,
|
|
4620
|
+
after,
|
|
4621
|
+
before,
|
|
4622
|
+
between,
|
|
4623
|
+
reorder,
|
|
4624
|
+
reindex
|
|
4625
|
+
};
|
|
4626
|
+
|
|
4627
|
+
// index.ts
|
|
4628
|
+
init_internal();
|
|
4629
|
+
init_platform();
|
|
4630
|
+
|
|
4631
|
+
// core/global.ts
|
|
4632
|
+
init_cjs_shims();
|
|
4633
|
+
init_platform();
|
|
4634
|
+
init_internal();
|
|
4635
|
+
|
|
4636
|
+
// package.json
|
|
4637
|
+
var package_default = {
|
|
4638
|
+
version: "5.1.1"};
|
|
4639
|
+
|
|
4640
|
+
// core/global.ts
|
|
4641
|
+
init_env();
|
|
4642
|
+
init_store();
|
|
4643
|
+
init_idb();
|
|
4644
|
+
init_sqlite();
|
|
4645
|
+
init_encryption();
|
|
4646
|
+
init_message();
|
|
4647
|
+
|
|
4648
|
+
// functions/typed/index.ts
|
|
4649
|
+
init_cjs_shims();
|
|
4650
|
+
function typed() {
|
|
4651
|
+
return exports.state;
|
|
3673
4652
|
}
|
|
3674
|
-
__name(
|
|
3675
|
-
var rollback = /* @__PURE__ */ __name((snap) => {
|
|
3676
|
-
exports.state.removeAll();
|
|
3677
|
-
for (const key of Object.keys(snap)) {
|
|
3678
|
-
exports.state[key] = _clone(snap[key]);
|
|
3679
|
-
}
|
|
3680
|
-
exports.internal.clearHistory();
|
|
3681
|
-
message_default("[memorio history] State rolled back to snapshot");
|
|
3682
|
-
}, "rollback");
|
|
3683
|
-
var clearHistory2 = /* @__PURE__ */ __name(() => {
|
|
3684
|
-
exports.internal.clearHistory();
|
|
3685
|
-
message_default("[memorio history] History cleared");
|
|
3686
|
-
}, "clearHistory");
|
|
3687
|
-
var clearRedo = /* @__PURE__ */ __name(() => {
|
|
3688
|
-
exports.internal.clearRedo();
|
|
3689
|
-
}, "clearRedo");
|
|
4653
|
+
__name(typed, "typed");
|
|
3690
4654
|
|
|
3691
4655
|
// functions/memory/index.ts
|
|
3692
4656
|
init_cjs_shims();
|
|
@@ -4379,6 +5343,168 @@ var memory = {
|
|
|
4379
5343
|
}
|
|
4380
5344
|
};
|
|
4381
5345
|
|
|
5346
|
+
// functions/history/index.ts
|
|
5347
|
+
init_cjs_shims();
|
|
5348
|
+
init_internal();
|
|
5349
|
+
init_env();
|
|
5350
|
+
init_message();
|
|
5351
|
+
function _clone(value) {
|
|
5352
|
+
if (value === null || typeof value !== "object") return value;
|
|
5353
|
+
try {
|
|
5354
|
+
return deepRaw(value, /* @__PURE__ */ new WeakSet());
|
|
5355
|
+
} catch (err) {
|
|
5356
|
+
if (exports.DEV) console.warn("[memorio history] deep clone failed:", err);
|
|
5357
|
+
return value;
|
|
5358
|
+
}
|
|
5359
|
+
}
|
|
5360
|
+
__name(_clone, "_clone");
|
|
5361
|
+
var snapshot = /* @__PURE__ */ __name(() => {
|
|
5362
|
+
return deepRaw(exports.state, /* @__PURE__ */ new WeakSet());
|
|
5363
|
+
}, "snapshot");
|
|
5364
|
+
var diff = /* @__PURE__ */ __name((snap) => {
|
|
5365
|
+
const changes = [];
|
|
5366
|
+
const _walk = /* @__PURE__ */ __name((oldObj, newObj, prefix) => {
|
|
5367
|
+
const oldKeys = oldObj ? Object.keys(oldObj) : [];
|
|
5368
|
+
const newKeys = newObj ? Object.keys(newObj) : [];
|
|
5369
|
+
for (const key of newKeys) {
|
|
5370
|
+
const newPath = prefix ? `${prefix}.${key}` : key;
|
|
5371
|
+
const oldVal = oldObj ? oldObj[key] : void 0;
|
|
5372
|
+
const newVal = newObj[key];
|
|
5373
|
+
if (oldVal !== newVal) {
|
|
5374
|
+
const oldType = typeof oldVal;
|
|
5375
|
+
const newType = typeof newVal;
|
|
5376
|
+
if (oldType !== newType || oldVal === void 0) {
|
|
5377
|
+
changes.push({ path: newPath, oldValue: oldVal, newValue: newVal });
|
|
5378
|
+
} else if (oldVal && typeof oldVal === "object") {
|
|
5379
|
+
_walk(oldVal, newVal, newPath);
|
|
5380
|
+
} else if (oldVal !== newVal) {
|
|
5381
|
+
changes.push({ path: newPath, oldValue: oldVal, newValue: newVal });
|
|
5382
|
+
}
|
|
5383
|
+
}
|
|
5384
|
+
}
|
|
5385
|
+
for (const key of oldKeys) {
|
|
5386
|
+
if (!(key in (newObj || {}))) {
|
|
5387
|
+
const newPath = prefix ? `${prefix}.${key}` : key;
|
|
5388
|
+
changes.push({ path: newPath, oldValue: oldObj[key], newValue: void 0 });
|
|
5389
|
+
}
|
|
5390
|
+
}
|
|
5391
|
+
}, "_walk");
|
|
5392
|
+
_walk(snap, deepRaw(exports.state), "");
|
|
5393
|
+
return changes;
|
|
5394
|
+
}, "diff");
|
|
5395
|
+
var enableHistory = /* @__PURE__ */ __name((enabled = true) => {
|
|
5396
|
+
exports.internal.historyEnabled = enabled;
|
|
5397
|
+
message_default(`[memorio history] Tracking ${enabled ? "enabled" : "disabled"}`);
|
|
5398
|
+
}, "enableHistory");
|
|
5399
|
+
var trace = /* @__PURE__ */ __name(() => {
|
|
5400
|
+
return [...exports.internal.mutations];
|
|
5401
|
+
}, "trace");
|
|
5402
|
+
var canUndo = /* @__PURE__ */ __name(() => {
|
|
5403
|
+
return exports.internal.canUndo();
|
|
5404
|
+
}, "canUndo");
|
|
5405
|
+
var canRedo = /* @__PURE__ */ __name(() => {
|
|
5406
|
+
return exports.internal.canRedo();
|
|
5407
|
+
}, "canRedo");
|
|
5408
|
+
var undo = /* @__PURE__ */ __name(() => {
|
|
5409
|
+
if (!exports.internal.historyEnabled) {
|
|
5410
|
+
message_default("[memorio history] History is not enabled");
|
|
5411
|
+
return void 0;
|
|
5412
|
+
}
|
|
5413
|
+
const record = exports.internal.popUndo();
|
|
5414
|
+
if (!record) return void 0;
|
|
5415
|
+
_applyInverse2(record);
|
|
5416
|
+
message_default(`[memorio history] Undid: ${record.action} ${record.path}`);
|
|
5417
|
+
return record;
|
|
5418
|
+
}, "undo");
|
|
5419
|
+
var redo = /* @__PURE__ */ __name(() => {
|
|
5420
|
+
if (!exports.internal.historyEnabled) {
|
|
5421
|
+
message_default("[memorio history] History is not enabled");
|
|
5422
|
+
return void 0;
|
|
5423
|
+
}
|
|
5424
|
+
const record = exports.internal.popRedo();
|
|
5425
|
+
if (!record) return void 0;
|
|
5426
|
+
_applyForward(record);
|
|
5427
|
+
message_default(`[memorio history] Redid: ${record.action} ${record.path}`);
|
|
5428
|
+
return record;
|
|
5429
|
+
}, "redo");
|
|
5430
|
+
function _applyInverse2(record) {
|
|
5431
|
+
const wasEnabled = exports.internal.historyEnabled;
|
|
5432
|
+
exports.internal.historyEnabled = false;
|
|
5433
|
+
try {
|
|
5434
|
+
if (record.action === "set") {
|
|
5435
|
+
if (record.previousValue === void 0) {
|
|
5436
|
+
_deletePath2(record.path);
|
|
5437
|
+
} else {
|
|
5438
|
+
_setPath2(record.path, record.previousValue);
|
|
5439
|
+
}
|
|
5440
|
+
} else if (record.action === "delete") {
|
|
5441
|
+
if (record.previousValue !== void 0) {
|
|
5442
|
+
_setPath2(record.path, record.previousValue);
|
|
5443
|
+
}
|
|
5444
|
+
}
|
|
5445
|
+
} finally {
|
|
5446
|
+
exports.internal.historyEnabled = wasEnabled;
|
|
5447
|
+
}
|
|
5448
|
+
}
|
|
5449
|
+
__name(_applyInverse2, "_applyInverse");
|
|
5450
|
+
function _applyForward(record) {
|
|
5451
|
+
const wasEnabled = exports.internal.historyEnabled;
|
|
5452
|
+
exports.internal.historyEnabled = false;
|
|
5453
|
+
try {
|
|
5454
|
+
if (record.action === "set") {
|
|
5455
|
+
_setPath2(record.path, record.newValue);
|
|
5456
|
+
} else if (record.action === "delete") {
|
|
5457
|
+
_deletePath2(record.path);
|
|
5458
|
+
}
|
|
5459
|
+
} finally {
|
|
5460
|
+
exports.internal.historyEnabled = wasEnabled;
|
|
5461
|
+
}
|
|
5462
|
+
}
|
|
5463
|
+
__name(_applyForward, "_applyForward");
|
|
5464
|
+
function _setPath2(path, value) {
|
|
5465
|
+
const parts = path.split(".");
|
|
5466
|
+
let current = exports.state;
|
|
5467
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
5468
|
+
const part = parts[i];
|
|
5469
|
+
if (current[part] === void 0) {
|
|
5470
|
+
current[part] = {};
|
|
5471
|
+
}
|
|
5472
|
+
current = current[part];
|
|
5473
|
+
}
|
|
5474
|
+
current[parts[parts.length - 1]] = value;
|
|
5475
|
+
}
|
|
5476
|
+
__name(_setPath2, "_setPath");
|
|
5477
|
+
function _deletePath2(path) {
|
|
5478
|
+
const parts = path.split(".");
|
|
5479
|
+
if (parts.length === 1) {
|
|
5480
|
+
exports.state.remove(parts[0]);
|
|
5481
|
+
return;
|
|
5482
|
+
}
|
|
5483
|
+
let current = exports.state;
|
|
5484
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
5485
|
+
const part = parts[i];
|
|
5486
|
+
if (current[part] === void 0) return;
|
|
5487
|
+
current = current[part];
|
|
5488
|
+
}
|
|
5489
|
+
delete current[parts[parts.length - 1]];
|
|
5490
|
+
}
|
|
5491
|
+
__name(_deletePath2, "_deletePath");
|
|
5492
|
+
var rollback = /* @__PURE__ */ __name((snap) => {
|
|
5493
|
+
exports.state.removeAll();
|
|
5494
|
+
for (const key of Object.keys(snap)) {
|
|
5495
|
+
exports.state[key] = _clone(snap[key]);
|
|
5496
|
+
}
|
|
5497
|
+
exports.internal.clearHistory();
|
|
5498
|
+
message_default("[memorio history] State rolled back to snapshot");
|
|
5499
|
+
}, "rollback");
|
|
5500
|
+
var clearHistory2 = /* @__PURE__ */ __name(() => {
|
|
5501
|
+
exports.internal.clearHistory();
|
|
5502
|
+
message_default("[memorio history] History cleared");
|
|
5503
|
+
}, "clearHistory");
|
|
5504
|
+
var clearRedo = /* @__PURE__ */ __name(() => {
|
|
5505
|
+
exports.internal.clearRedo();
|
|
5506
|
+
}, "clearRedo");
|
|
5507
|
+
|
|
4382
5508
|
// core/global.ts
|
|
4383
5509
|
if (!("memorio" in globalThis)) {
|
|
4384
5510
|
Object.defineProperty(
|
|
@@ -4445,16 +5571,18 @@ if (!("memorio" in globalThis)) {
|
|
|
4445
5571
|
}
|
|
4446
5572
|
);
|
|
4447
5573
|
memorio.memory = memory;
|
|
5574
|
+
memorio.encryption = exports.encryption;
|
|
4448
5575
|
initializePlatform();
|
|
4449
5576
|
memorio.isBrowser = isBrowser;
|
|
4450
5577
|
memorio.isNode = isNode;
|
|
4451
5578
|
memorio.isDeno = isDeno;
|
|
5579
|
+
memorio.isBun = isBun;
|
|
4452
5580
|
memorio.isEdge = isEdge;
|
|
4453
5581
|
memorio.getCapabilities = getCapabilities;
|
|
4454
5582
|
memorio.createContext = createContext;
|
|
4455
5583
|
memorio.listContexts = listContexts;
|
|
4456
5584
|
memorio.deleteContext = deleteContext;
|
|
4457
|
-
memorio.isolate = (name) => createContext(name);
|
|
5585
|
+
memorio.isolate = (name, opts) => createContext(name, opts);
|
|
4458
5586
|
Object.defineProperty(memorio, "setContext", { writable: false, enumerable: false, value: /* @__PURE__ */ __name((id) => setCurrentContext(id), "value") });
|
|
4459
5587
|
Object.defineProperty(memorio, "getContext", { writable: false, enumerable: false, value: /* @__PURE__ */ __name(() => exports.internal.currentContext, "value") });
|
|
4460
5588
|
memorio.registerSchema = schema.register;
|
|
@@ -4462,6 +5590,9 @@ if (!("memorio" in globalThis)) {
|
|
|
4462
5590
|
memorio.unregisterSchema = schema.unregister;
|
|
4463
5591
|
memorio.listSchemas = schema.list;
|
|
4464
5592
|
memorio.typed = typed;
|
|
5593
|
+
memorio.computed = computed;
|
|
5594
|
+
memorio.broadcast = broadcast;
|
|
5595
|
+
memorio.security = security;
|
|
4465
5596
|
memorio.snapshot = snapshot;
|
|
4466
5597
|
memorio.diff = diff;
|
|
4467
5598
|
memorio.undo = undo;
|
|
@@ -4495,7 +5626,11 @@ if (!("memorio" in globalThis)) {
|
|
|
4495
5626
|
idb: exports.idb,
|
|
4496
5627
|
sqlite: exports.sqlite,
|
|
4497
5628
|
observer,
|
|
4498
|
-
useObserver
|
|
5629
|
+
useObserver,
|
|
5630
|
+
encryption: exports.encryption,
|
|
5631
|
+
computed,
|
|
5632
|
+
broadcast,
|
|
5633
|
+
security
|
|
4499
5634
|
};
|
|
4500
5635
|
for (const key of Object.keys(globalDefinitions)) {
|
|
4501
5636
|
if (!(key in globalThis)) {
|
|
@@ -4527,6 +5662,7 @@ var index_default = memorio2;
|
|
|
4527
5662
|
exports.abortTransaction = abortTransaction;
|
|
4528
5663
|
exports.activeTransactionId = activeTransactionId;
|
|
4529
5664
|
exports.beginTransaction = beginTransaction;
|
|
5665
|
+
exports.broadcast = broadcast;
|
|
4530
5666
|
exports.cache = cache;
|
|
4531
5667
|
exports.canMerge = canMerge;
|
|
4532
5668
|
exports.canRedo = canRedo;
|
|
@@ -4534,6 +5670,7 @@ exports.canUndo = canUndo;
|
|
|
4534
5670
|
exports.clearHistory = clearHistory2;
|
|
4535
5671
|
exports.clearRedo = clearRedo;
|
|
4536
5672
|
exports.commitTransaction = commitTransaction;
|
|
5673
|
+
exports.computed = computed;
|
|
4537
5674
|
exports.createContext = createContext;
|
|
4538
5675
|
exports.createMutation = createMutation;
|
|
4539
5676
|
exports.currentTimestamp = currentTimestamp;
|
|
@@ -4555,6 +5692,7 @@ exports.getContext = getContext;
|
|
|
4555
5692
|
exports.help = help;
|
|
4556
5693
|
exports.hlc = hlc;
|
|
4557
5694
|
exports.isBrowser = isBrowser;
|
|
5695
|
+
exports.isBun = isBun;
|
|
4558
5696
|
exports.isDeno = isDeno;
|
|
4559
5697
|
exports.isEdge = isEdge;
|
|
4560
5698
|
exports.isNode = isNode;
|
|
@@ -4574,6 +5712,7 @@ exports.redo = redo;
|
|
|
4574
5712
|
exports.registerSchema = registerSchema;
|
|
4575
5713
|
exports.rollback = rollback;
|
|
4576
5714
|
exports.schema = schema;
|
|
5715
|
+
exports.security = security;
|
|
4577
5716
|
exports.setContext = setContext;
|
|
4578
5717
|
exports.snapshot = snapshot;
|
|
4579
5718
|
exports.toPatch = toPatch;
|