memorio 4.9.35 → 5.1.0
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/AGENTS.md +3 -3
- package/README.md +95 -516
- package/SECURITY.md +159 -33
- package/SUMMARY.md +59 -45
- package/adr/001-state-proxy-model.md +95 -0
- package/adr/002-observer-semantics.md +179 -0
- package/adr/003-deep-mutation-semantics.md +128 -0
- package/adr/004-array-mutation-semantics.md +127 -0
- package/adr/005-scheduler-contract.md +148 -0
- package/adr/006-context-isolation.md +91 -0
- package/adr/007-mutation-records.md +117 -0
- package/adr/008-transactions.md +105 -0
- package/adr/009-history-model.md +109 -0
- package/adr/README.md +46 -0
- package/adr/template.md +48 -0
- package/bin/cli.js +68 -0
- package/examples/basic.ts +115 -115
- package/examples/browser-vanilla.html +358 -358
- package/examples/cache.ts +72 -72
- package/examples/cross-platform-guards.ts +57 -57
- package/examples/history.ts +104 -0
- package/examples/idb.ts +109 -109
- package/examples/multi-tenant-context.ts +44 -44
- package/examples/node-server.ts +308 -308
- package/examples/observer.ts +60 -60
- package/examples/platform.ts +115 -115
- package/examples/react-app.tsx +362 -362
- package/examples/react-observer.tsx +63 -63
- package/examples/semantic-memory.ts +60 -60
- package/examples/session-advanced.ts +91 -91
- package/examples/sqlite-batched-writes.ts +57 -57
- package/examples/state-advanced.ts +89 -89
- package/examples/store-advanced.ts +117 -117
- package/examples/sync.ts +90 -0
- package/examples/typed-and-schema.ts +102 -100
- package/examples/useObserver.tsx +140 -141
- package/global.cjs +5733 -0
- package/global.d.ts +8 -0
- package/global.js +5667 -0
- package/index.cjs +2202 -1041
- package/index.d.ts +2 -0
- package/index.js +2178 -1040
- package/llms.txt +113 -8
- package/markdown/AUDIT-REPORT.md +134 -0
- package/markdown/CACHE.md +191 -0
- package/markdown/DEVTOOLS.md +128 -0
- package/markdown/DISPATCH.md +176 -0
- package/markdown/HISTORY.md +198 -0
- package/markdown/IDB.md +177 -0
- package/markdown/IMPORT.md +152 -0
- package/markdown/INSPECT.md +122 -0
- package/markdown/LOGGER.md +153 -0
- package/markdown/MEMORY-ATTACHMENT.md +95 -0
- package/markdown/MEMORY.md +161 -0
- package/markdown/OBSERVER.md +208 -0
- package/markdown/PLATFORM.md +277 -0
- package/markdown/REDUX.md +54 -0
- package/markdown/SCHEMA.md +175 -0
- package/markdown/SESSION.md +164 -0
- package/markdown/SQLITE.md +189 -0
- package/markdown/STATE.md +159 -0
- package/markdown/STORE.md +170 -0
- package/markdown/SYNC.md +318 -0
- package/markdown/TYPED.md +164 -0
- package/markdown/USEOBSERVER.md +256 -0
- package/modules/redux.cjs +701 -177
- package/modules/redux.cjs.map +1 -1
- package/modules/redux.js +701 -177
- package/modules/redux.js.map +1 -1
- package/package.json +26 -4
- package/types/broadcast.d.ts +61 -0
- package/types/computed.d.ts +96 -0
- package/types/encryption.d.ts +129 -0
- package/types/env.d.ts +19 -9
- package/types/exports.d.ts +29 -0
- package/types/history.d.ts +13 -1
- package/types/memorio.d.ts +25 -6
- package/types/mutation.d.ts +75 -0
- 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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memorio",
|
|
3
3
|
"codeName": "memorio",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.1.0",
|
|
5
5
|
"description": "Memorio, State + Observer, Store and iDB for an easy life - Cross-platform compatible",
|
|
6
6
|
"main": "./index.cjs",
|
|
7
7
|
"browser": {
|
|
@@ -25,6 +25,13 @@
|
|
|
25
25
|
"email": "valeriacalascaglitta@gmail.com"
|
|
26
26
|
}
|
|
27
27
|
],
|
|
28
|
+
"bin": {
|
|
29
|
+
"memorio": "./bin/cli.js"
|
|
30
|
+
},
|
|
31
|
+
"workspaces": [
|
|
32
|
+
"tests",
|
|
33
|
+
"extension/vscode"
|
|
34
|
+
],
|
|
28
35
|
"keywords": [
|
|
29
36
|
"memorio",
|
|
30
37
|
"state",
|
|
@@ -40,6 +47,8 @@
|
|
|
40
47
|
"sqlite",
|
|
41
48
|
"sql.js",
|
|
42
49
|
"wasm",
|
|
50
|
+
"bun",
|
|
51
|
+
"cross-runtime",
|
|
43
52
|
"browser",
|
|
44
53
|
"frontend"
|
|
45
54
|
],
|
|
@@ -50,24 +59,32 @@
|
|
|
50
59
|
}
|
|
51
60
|
],
|
|
52
61
|
"engines": {
|
|
53
|
-
"node": ">=18.0.0"
|
|
62
|
+
"node": ">=18.0.0",
|
|
63
|
+
"bun": ">=1.4.0"
|
|
54
64
|
},
|
|
55
65
|
"files": [
|
|
66
|
+
"bin",
|
|
67
|
+
"vsix",
|
|
56
68
|
"markdown/**/*",
|
|
57
69
|
"types/**/*",
|
|
58
70
|
"examples/**/*",
|
|
71
|
+
"modules/**/*",
|
|
72
|
+
"adr/**/*",
|
|
59
73
|
"AGENTS.md",
|
|
60
74
|
"COPYRIGHT.md",
|
|
61
75
|
"README.md",
|
|
62
76
|
"FUNDING.yml",
|
|
63
77
|
"SECURITY.md",
|
|
78
|
+
"SECURITY-HARDENING.md",
|
|
64
79
|
"SUMMARY.md",
|
|
65
80
|
"LICENSE.md",
|
|
66
81
|
"index.d.ts",
|
|
82
|
+
"global.d.ts",
|
|
83
|
+
"global.cjs",
|
|
84
|
+
"global.js",
|
|
67
85
|
"index.cjs",
|
|
68
86
|
"index.js",
|
|
69
|
-
"llms.txt"
|
|
70
|
-
"modules/**/*"
|
|
87
|
+
"llms.txt"
|
|
71
88
|
],
|
|
72
89
|
"publishConfig": {
|
|
73
90
|
"access": "public"
|
|
@@ -89,6 +106,11 @@
|
|
|
89
106
|
"require": "./index.cjs",
|
|
90
107
|
"types": "./index.d.ts"
|
|
91
108
|
},
|
|
109
|
+
"./global": {
|
|
110
|
+
"import": "./global.js",
|
|
111
|
+
"require": "./global.cjs",
|
|
112
|
+
"types": "./global.d.ts"
|
|
113
|
+
},
|
|
92
114
|
"./types/*": "./types/*",
|
|
93
115
|
"./redux": {
|
|
94
116
|
"import": "./modules/redux.js",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
memorio
|
|
3
|
+
Copyright (c) 2025 Dario Passariello <dariopassariello@gmail.com>
|
|
4
|
+
Licensed under MIT License, see
|
|
5
|
+
dario.passariello.ca
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type SyncTarget = 'store' | 'session' | 'state' | 'all'
|
|
9
|
+
|
|
10
|
+
interface BroadcastConfig {
|
|
11
|
+
channelName?: string
|
|
12
|
+
targets?: SyncTarget
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface BroadcastMessage {
|
|
16
|
+
__memorio_sync: true
|
|
17
|
+
target: SyncTarget
|
|
18
|
+
action: 'set' | 'remove' | 'delete' | 'clearAll'
|
|
19
|
+
path: string
|
|
20
|
+
value?: any
|
|
21
|
+
oldValue?: any
|
|
22
|
+
timestamp: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface _broadcast {
|
|
26
|
+
/**
|
|
27
|
+
* Install cross-tab synchronization.
|
|
28
|
+
*
|
|
29
|
+
* @param channelName Name for the BroadcastChannel (default: `memorio_sync`).
|
|
30
|
+
* @param opts Optional configuration.
|
|
31
|
+
* @param opts.targets Which layers to sync: `store`, `session`, `state`, or `all` (default).
|
|
32
|
+
*
|
|
33
|
+
* @since memorio 5.1
|
|
34
|
+
*/
|
|
35
|
+
install: (channelName?: string, opts?: BroadcastConfig) => void
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Uninstall cross-tab synchronization and close the channel.
|
|
39
|
+
* @since memorio 5.1
|
|
40
|
+
*/
|
|
41
|
+
uninstall: () => void
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether cross-tab sync is currently installed.
|
|
45
|
+
* @since memorio 5.1
|
|
46
|
+
*/
|
|
47
|
+
isInstalled: () => boolean
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Broadcast a message to all other tabs (internal / advanced use).
|
|
51
|
+
* @since memorio 5.1
|
|
52
|
+
*/
|
|
53
|
+
broadcast: (msg: Omit<BroadcastMessage, 'timestamp'>) => void
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare var broadcast: _broadcast | undefined
|
|
57
|
+
type broadcast = _broadcast
|
|
58
|
+
|
|
59
|
+
declare global {
|
|
60
|
+
var broadcast: _broadcast | undefined
|
|
61
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
memorio
|
|
3
|
+
Copyright (c) 2025 Dario Passariello <dariopassariello@gmail.com>
|
|
4
|
+
Licensed under MIT License, see
|
|
5
|
+
dario.passariello.ca
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type ComputeGetter = (path: string) => any
|
|
9
|
+
type ComputeSelector = (get: ComputeGetter) => any
|
|
10
|
+
type EqualityFn = (prev: any, next: any) => boolean
|
|
11
|
+
|
|
12
|
+
interface ComputedEntry {
|
|
13
|
+
selector: ComputeSelector
|
|
14
|
+
lastValue: any
|
|
15
|
+
deps: Set<string>
|
|
16
|
+
equality: EqualityFn
|
|
17
|
+
subscribers: Set<(value: any) => void>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface ComputeOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Custom equality function to determine if the computed value changed.
|
|
23
|
+
* Defaults to deep equality (JSON.stringify comparison).
|
|
24
|
+
*/
|
|
25
|
+
equality?: EqualityFn
|
|
26
|
+
/**
|
|
27
|
+
* Custom cache key (for multiple computations of the same path
|
|
28
|
+
* with different selectors).
|
|
29
|
+
*/
|
|
30
|
+
equalityKey?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface _computed {
|
|
34
|
+
/**
|
|
35
|
+
* Register a computed/derived value.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* memorio.computed.compute('state.user.fullName', (get) => {
|
|
39
|
+
* const first = get('state.user.firstName')
|
|
40
|
+
* const last = get('state.user.lastName')
|
|
41
|
+
* return `${first} ${last}`
|
|
42
|
+
* })
|
|
43
|
+
*
|
|
44
|
+
* @since memorio 5.1
|
|
45
|
+
*/
|
|
46
|
+
compute: (
|
|
47
|
+
key: string,
|
|
48
|
+
selector: ComputeSelector,
|
|
49
|
+
opts?: ComputeOptions
|
|
50
|
+
) => any
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Retrieve the cached value of a computed key.
|
|
54
|
+
* Recomputes lazily if dependencies have changed.
|
|
55
|
+
*
|
|
56
|
+
* @since memorio 5.1
|
|
57
|
+
*/
|
|
58
|
+
getValue: (key: string) => any
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Subscribe to changes on a computed key.
|
|
62
|
+
*
|
|
63
|
+
* @param key The state path of the computed value.
|
|
64
|
+
* @param cb Callback invoked with the new value when it changes.
|
|
65
|
+
* @returns Unsubscribe function.
|
|
66
|
+
*
|
|
67
|
+
* @since memorio 5.1
|
|
68
|
+
*/
|
|
69
|
+
subscribe: (key: string, cb: (value: any) => void) => (() => void)
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Remove a computed value registration and clean up its dependency listeners.
|
|
73
|
+
*
|
|
74
|
+
* @since memorio 5.1
|
|
75
|
+
*/
|
|
76
|
+
remove: (key: string) => boolean
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* List all registered computed keys.
|
|
80
|
+
* @since memorio 5.1
|
|
81
|
+
*/
|
|
82
|
+
list: () => string[]
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Clear all computed registrations and their dependency listeners.
|
|
86
|
+
* @since memorio 5.1
|
|
87
|
+
*/
|
|
88
|
+
clear: () => void
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
declare var computed: _computed
|
|
92
|
+
type computed = _computed
|
|
93
|
+
|
|
94
|
+
declare global {
|
|
95
|
+
var computed: _computed | undefined
|
|
96
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
memorio
|
|
3
|
+
Copyright (c) 2025 Dario Passariello <dariopassariello@gmail.com>
|
|
4
|
+
Licensed under MIT License, see
|
|
5
|
+
dario.passariello.ca
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface EncryptedEnvelope {
|
|
9
|
+
__memorio_encrypted: true
|
|
10
|
+
v: number
|
|
11
|
+
alg: 'AES-GCM'
|
|
12
|
+
iv: string
|
|
13
|
+
data: string
|
|
14
|
+
keyId?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface _encryption {
|
|
18
|
+
/** Check whether the Web Crypto API is available in this environment. */
|
|
19
|
+
isAvailable: () => boolean
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Derive a CryptoKey from a password using PBKDF2.
|
|
23
|
+
* @param password The password to derive the key from.
|
|
24
|
+
* @param salt Optional salt (string or Uint8Array).
|
|
25
|
+
* @param alg Key algorithm: `'AES-GCM'` (default) or `'AES-CBC'`.
|
|
26
|
+
* @param iterations PBKDF2 iteration count (default 600000, NIST SP 800-132).
|
|
27
|
+
* @returns A Promise that resolves to a CryptoKey.
|
|
28
|
+
*/
|
|
29
|
+
deriveKey: (
|
|
30
|
+
password: string,
|
|
31
|
+
salt?: string | Uint8Array,
|
|
32
|
+
alg?: 'AES-GCM' | 'AES-CBC'
|
|
33
|
+
iterations?: number
|
|
34
|
+
) => Promise<CryptoKey>
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Generate a fresh random CryptoKey (AES-GCM, 256-bit).
|
|
38
|
+
* @param alg `'AES-GCM'` (default) or `'AES-CBC'`.
|
|
39
|
+
*/
|
|
40
|
+
generateKey: (alg?: 'AES-GCM' | 'AES-CBC') => Promise<CryptoKey>
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Generate a random salt string (base64-encoded).
|
|
44
|
+
* @param bytes Number of random bytes (default 16).
|
|
45
|
+
*/
|
|
46
|
+
generateSalt: (bytes?: number) => string
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Export a CryptoKey to portable base64 strings for secure storage.
|
|
50
|
+
* @param cryptoKey A raw CryptoKey (not a password string).
|
|
51
|
+
* @returns { key, iv } base64-encoded key material and IV (if any).
|
|
52
|
+
*/
|
|
53
|
+
exportKey: (cryptoKey: CryptoKey) => Promise<{ key: string; iv: string }>
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Import a CryptoKey from base64 strings produced by exportKey().
|
|
57
|
+
* @param keyData Base64-encoded raw key bytes.
|
|
58
|
+
* @param _ivData Ignored (kept for API compatibility).
|
|
59
|
+
* @returns A Promise that resolves to a CryptoKey.
|
|
60
|
+
*/
|
|
61
|
+
importKey: (keyData: string, _ivData?: string) => Promise<CryptoKey>
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Encrypt a value with AES-GCM.
|
|
65
|
+
* @param value Any JSON-serializable value.
|
|
66
|
+
* @param key A CryptoKey or a password string (derived via PBKDF2).
|
|
67
|
+
* @param keyId Optional label for key rotation.
|
|
68
|
+
* @returns An EncryptedEnvelope object.
|
|
69
|
+
*/
|
|
70
|
+
encrypt: (value: any, key: CryptoKey | string, keyId?: string) => Promise<EncryptedEnvelope>
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Decrypt an EncryptedEnvelope.
|
|
74
|
+
* @param envelope The envelope returned by encrypt().
|
|
75
|
+
* @param key A CryptoKey or a password string.
|
|
76
|
+
* @returns The original decrypted value.
|
|
77
|
+
*/
|
|
78
|
+
decrypt: (envelope: EncryptedEnvelope, key: CryptoKey | string) => Promise<any>
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Encrypt with a password and return a JSON string (for direct persistence).
|
|
82
|
+
* @param value The value to encrypt.
|
|
83
|
+
* @param password The password to derive the key from.
|
|
84
|
+
* @param salt Optional salt string.
|
|
85
|
+
* @param keyId Optional key label.
|
|
86
|
+
*/
|
|
87
|
+
encryptWithPassword: (
|
|
88
|
+
value: any,
|
|
89
|
+
password: string,
|
|
90
|
+
salt?: string,
|
|
91
|
+
keyId?: string
|
|
92
|
+
) => Promise<string>
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Decrypt a JSON envelope string with a password.
|
|
96
|
+
* @param envelopeJson The JSON string from encryptWithPassword().
|
|
97
|
+
* @param password The password to derive the key from.
|
|
98
|
+
* @param salt Optional salt (must match the one used for encryption).
|
|
99
|
+
*/
|
|
100
|
+
decryptWithPassword: (
|
|
101
|
+
envelopeJson: string,
|
|
102
|
+
password: string,
|
|
103
|
+
salt?: string
|
|
104
|
+
) => Promise<any>
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Type guard: check whether a value is an encrypted envelope.
|
|
108
|
+
*/
|
|
109
|
+
isEncrypted: (value: any) => boolean
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Configure a default encryption key for auto-encrypt mode.
|
|
113
|
+
* When a default key is set, store/session operations automatically
|
|
114
|
+
* encrypt on write and attempt decryption on read.
|
|
115
|
+
*/
|
|
116
|
+
config: (opts: { key?: CryptoKey | string; keyId?: string }) => _encryption
|
|
117
|
+
|
|
118
|
+
/** Internal: the configured default key. */
|
|
119
|
+
_key?: CryptoKey | string | null
|
|
120
|
+
/** Internal: the configured default key ID. */
|
|
121
|
+
_keyId?: string
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
declare var encryption: _encryption
|
|
125
|
+
type encryption = _encryption
|
|
126
|
+
|
|
127
|
+
declare global {
|
|
128
|
+
var encryption: _encryption | null | undefined
|
|
129
|
+
}
|
package/types/env.d.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runtime environment detection.
|
|
3
|
-
*
|
|
4
|
-
* `DEV` and `PROD` are derived
|
|
5
|
-
* (
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Runtime environment detection.
|
|
3
|
+
*
|
|
4
|
+
* `DEV` and `PROD` are derived from a build-time `__DEV__` constant
|
|
5
|
+
* (injected by tsup/esbuild via `define`) when available, falling back
|
|
6
|
+
* to `process.env.NODE_ENV` for raw source imports in Node.js, and
|
|
7
|
+
* defaulting to `true` for raw browser environments.
|
|
8
|
+
* Import from `core/env.ts`:
|
|
9
|
+
*
|
|
10
|
+
* import { DEV, PROD } from './core/env'
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Build-time constant injected by tsup/esbuild. When present, it's a
|
|
15
|
+
* boolean literal that enables dead-code elimination of dev-only blocks
|
|
16
|
+
* (devtools, introspection, etc.). Not defined for raw source imports
|
|
17
|
+
* (no build step) - falls back to runtime detection.
|
|
18
|
+
*/
|
|
19
|
+
declare const __DEV__: boolean | undefined
|
package/types/exports.d.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
/// <reference path="./schema.d.ts" />
|
|
12
12
|
/// <reference path="./history.d.ts" />
|
|
13
|
+
/// <reference path="./mutation.d.ts" />
|
|
13
14
|
/// <reference path="./inspect.d.ts" />
|
|
14
15
|
/// <reference path="./memorio.d.ts" />
|
|
15
16
|
/// <reference path="./state.d.ts" />
|
|
@@ -20,6 +21,10 @@
|
|
|
20
21
|
/// <reference path="./sqlite.d.ts" />
|
|
21
22
|
/// <reference path="./observer.d.ts" />
|
|
22
23
|
/// <reference path="./useObserver.d.ts" />
|
|
24
|
+
/// <reference path="./encryption.d.ts" />
|
|
25
|
+
/// <reference path="./computed.d.ts" />
|
|
26
|
+
/// <reference path="./broadcast.d.ts" />
|
|
27
|
+
/// <reference path="./security.d.ts" />
|
|
23
28
|
|
|
24
29
|
export const memorio: _memorio
|
|
25
30
|
export const state: _state
|
|
@@ -30,6 +35,10 @@ export const idb: _idb
|
|
|
30
35
|
export const sqlite: _sqlite
|
|
31
36
|
export const observer: _observer
|
|
32
37
|
export const useObserver: _useObserver
|
|
38
|
+
export const encryption: _encryption
|
|
39
|
+
export const computed: _computed
|
|
40
|
+
export const broadcast: _broadcast
|
|
41
|
+
export const security: _security
|
|
33
42
|
export const dispatch: _dispatch
|
|
34
43
|
export const events: Record<string, any>
|
|
35
44
|
|
|
@@ -58,6 +67,7 @@ export const fractional: {
|
|
|
58
67
|
export const isBrowser: () => boolean
|
|
59
68
|
export const isNode: () => boolean
|
|
60
69
|
export const isDeno: () => boolean
|
|
70
|
+
export const isBun: () => boolean
|
|
61
71
|
export const isEdge: () => boolean
|
|
62
72
|
export const getCapabilities: (...args: unknown[]) => any
|
|
63
73
|
export const createContext: _memorio['createContext']
|
|
@@ -110,6 +120,25 @@ export const enableHistory: (enabled?: boolean) => void
|
|
|
110
120
|
export const clearHistory: () => void
|
|
111
121
|
export const clearRedo: () => void
|
|
112
122
|
|
|
123
|
+
// ── Mutation Engine (Memorio 5) ───────────────────────────────────────
|
|
124
|
+
export const createMutation: (path: string, operation: _operation, before: any, after: any, opts?: { context?: string; source?: string; transactionId?: string }) => _mutation
|
|
125
|
+
export const recordMutation: (mutation: _mutation) => void
|
|
126
|
+
export const toPatch: (mutation: _mutation) => _patch | null
|
|
127
|
+
export const mutate: (path: string, value: any, opts?: { source?: string; transactionId?: string }) => _mutation
|
|
128
|
+
export const beginTransaction: (source?: string, message?: string, metadata?: Record<string, any>) => _transaction
|
|
129
|
+
export const transaction: (source?: string, message?: string, metadata?: Record<string, any>) => _transaction
|
|
130
|
+
export const commitTransaction: () => _transaction | null
|
|
131
|
+
export const abortTransaction: () => _transaction | null
|
|
132
|
+
export const currentTransaction: () => _transaction | null
|
|
133
|
+
export const listTransactions: () => _transaction[]
|
|
134
|
+
export const generateMutationId: () => string
|
|
135
|
+
export const generateTransactionId: () => string
|
|
136
|
+
export const generateCommitId: () => string
|
|
137
|
+
export const mutationToPatch: (mutation: _mutation) => _patch | null
|
|
138
|
+
export const diffToPatch: (path: string, before: any, after: any) => _patch | null
|
|
139
|
+
export const canMerge: (p1: _patch, p2: _patch) => boolean
|
|
140
|
+
export const mergePatches: (p1: _patch, p2: _patch) => _patch
|
|
141
|
+
|
|
113
142
|
// ── Introspection (development-only) ─────────────────────────────────
|
|
114
143
|
export const stateKeys: () => string[]
|
|
115
144
|
export const pathExists: (path: string) => boolean
|
package/types/history.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// Ambient declarations for the snapshot / undo / redo / trace API.
|
|
3
3
|
|
|
4
4
|
///
|
|
5
|
-
// A single recorded state mutation.
|
|
5
|
+
// A single recorded state mutation (extended for Memorio 5).
|
|
6
6
|
///
|
|
7
7
|
interface _mutationRecord {
|
|
8
8
|
/** Dotted state path (e.g. 'user.name'). */
|
|
@@ -15,6 +15,18 @@ interface _mutationRecord {
|
|
|
15
15
|
previousValue: any
|
|
16
16
|
/** Epoch timestamp (ms) when the mutation occurred. */
|
|
17
17
|
timestamp: number
|
|
18
|
+
/** Unique mutation ID (Memorio 5). */
|
|
19
|
+
id?: string
|
|
20
|
+
/** Normalized operation type (Memorio 5). */
|
|
21
|
+
operation?: 'set' | 'delete' | 'insert' | 'remove' | 'replace' | 'length'
|
|
22
|
+
/** HLC timestamp string for causal ordering (Memorio 5). */
|
|
23
|
+
hlc?: string
|
|
24
|
+
/** Context ID for server-side isolation (Memorio 5). */
|
|
25
|
+
context?: string
|
|
26
|
+
/** Source attribution (Memorio 5). */
|
|
27
|
+
source?: string
|
|
28
|
+
/** Transaction group ID (Memorio 5). */
|
|
29
|
+
transactionId?: string
|
|
18
30
|
}
|
|
19
31
|
|
|
20
32
|
///
|
package/types/memorio.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ import type {
|
|
|
20
20
|
|
|
21
21
|
interface _dispatch {
|
|
22
22
|
set: (name: string, value?: any) => void
|
|
23
|
-
|
|
23
|
+
listen: (name: string, cb?: ((e: Event) => void) | null, flag?: boolean) => (() => void) | void
|
|
24
24
|
remove: (name: string, cb?: any, flag?: boolean) => void
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -47,6 +47,7 @@ interface _memorio {
|
|
|
47
47
|
isBrowser: () => boolean
|
|
48
48
|
isNode: () => boolean
|
|
49
49
|
isDeno: () => boolean
|
|
50
|
+
isBun: () => boolean
|
|
50
51
|
isEdge: () => boolean
|
|
51
52
|
getCapabilities: (...args: unknown[]) => any
|
|
52
53
|
// Platform properties
|
|
@@ -55,25 +56,27 @@ interface _memorio {
|
|
|
55
56
|
_sessionId?: string
|
|
56
57
|
_currentContext?: string
|
|
57
58
|
// Context management (for server-side isolation)
|
|
58
|
-
createContext?: (name?: string) => {
|
|
59
|
+
createContext?: (name?: string, opts?: { encryptionKey?: any }) => {
|
|
59
60
|
id: string
|
|
60
61
|
state: any
|
|
61
62
|
store: any
|
|
62
63
|
session: any
|
|
63
64
|
cache: any
|
|
65
|
+
encryptionKey?: any
|
|
64
66
|
}
|
|
65
67
|
listContexts?: () => string[]
|
|
66
68
|
deleteContext?: (id: string) => boolean
|
|
67
|
-
isolate?: (name?: string) => {
|
|
69
|
+
isolate?: (name?: string, opts?: { encryptionKey?: any }) => {
|
|
68
70
|
id: string
|
|
69
71
|
state: any
|
|
70
72
|
store: any
|
|
71
73
|
session: any
|
|
72
74
|
cache: any
|
|
75
|
+
encryptionKey?: any
|
|
73
76
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
help?: () => void
|
|
78
|
+
global?: () => void
|
|
79
|
+
env?: { isDev: boolean; isProd: boolean }
|
|
77
80
|
// Schema validation
|
|
78
81
|
registerSchema?: (path: string, schema: any) => void
|
|
79
82
|
validate?: (path: string, value: any) => { valid: boolean; errors?: string[] }
|
|
@@ -93,6 +96,15 @@ interface _memorio {
|
|
|
93
96
|
enableHistory?: (enabled?: boolean) => void
|
|
94
97
|
clearHistory?: () => void
|
|
95
98
|
clearRedo?: () => void
|
|
99
|
+
// Mutation Engine (Memorio 5)
|
|
100
|
+
mutate?: (path: string, value: any, opts?: { source?: string; transactionId?: string }) => _mutation
|
|
101
|
+
createMutation?: (path: string, operation: _operation, before: any, after: any, opts?: { context?: string; source?: string; transactionId?: string }) => _mutation
|
|
102
|
+
recordMutation?: (mutation: _mutation) => void
|
|
103
|
+
toPatch?: (mutation: _mutation) => _patch | null
|
|
104
|
+
transaction?: (source?: string, message?: string, metadata?: Record<string, any>) => _transaction
|
|
105
|
+
commitTransaction?: () => _transaction | null
|
|
106
|
+
abortTransaction?: () => _transaction | null
|
|
107
|
+
currentTransaction?: () => _transaction | null
|
|
96
108
|
// Introspection
|
|
97
109
|
stateKeys?: () => string[]
|
|
98
110
|
pathExists?: (path: string) => boolean
|
|
@@ -100,6 +112,10 @@ interface _memorio {
|
|
|
100
112
|
stateGet?: (path: string) => any
|
|
101
113
|
stateSchema?: () => Array<{ path: string; type: string; defined: boolean }>
|
|
102
114
|
memory?: MemoryAPI
|
|
115
|
+
encryption?: _encryption
|
|
116
|
+
computed?: _computed
|
|
117
|
+
broadcast?: _broadcast
|
|
118
|
+
security?: _security
|
|
103
119
|
// Development-only surfaces (excluded from production builds via `if (DEV)`).
|
|
104
120
|
// Not a security boundary on its own - rely on your backend for auth.
|
|
105
121
|
devtools?: any
|
|
@@ -166,4 +182,7 @@ interface globalThis {
|
|
|
166
182
|
[key: string]: any
|
|
167
183
|
}
|
|
168
184
|
|
|
185
|
+
declare var memorio: memorio
|
|
186
|
+
type memorio = memorio
|
|
187
|
+
|
|
169
188
|
export { }
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/// MEMORIO MUTATION ENGINE TYPES
|
|
2
|
+
/// Ambient declarations for the Memorio 5 mutation pipeline.
|
|
3
|
+
|
|
4
|
+
///
|
|
5
|
+
// Normalized mutation operations.
|
|
6
|
+
///
|
|
7
|
+
type _operation = 'set' | 'delete' | 'insert' | 'remove' | 'replace' | 'length'
|
|
8
|
+
|
|
9
|
+
///
|
|
10
|
+
// RFC 6902 patch operations.
|
|
11
|
+
///
|
|
12
|
+
type _patchOp = 'replace' | 'remove' | 'add' | 'test'
|
|
13
|
+
|
|
14
|
+
///
|
|
15
|
+
// A single mutation as recorded by the engine (extends MutationRecord).
|
|
16
|
+
///
|
|
17
|
+
interface _mutation {
|
|
18
|
+
id: string
|
|
19
|
+
path: string
|
|
20
|
+
operation: _operation
|
|
21
|
+
after: any
|
|
22
|
+
before: any
|
|
23
|
+
timestamp: number
|
|
24
|
+
hlc: string
|
|
25
|
+
context?: string
|
|
26
|
+
source?: string
|
|
27
|
+
transactionId?: string
|
|
28
|
+
action?: 'set' | 'delete'
|
|
29
|
+
newValue?: any
|
|
30
|
+
previousValue?: any
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
///
|
|
34
|
+
// Compact patch representation.
|
|
35
|
+
///
|
|
36
|
+
interface _patch {
|
|
37
|
+
op: _patchOp
|
|
38
|
+
path: string
|
|
39
|
+
value?: any
|
|
40
|
+
oldValue?: any
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
///
|
|
44
|
+
// A transaction grouping related mutations.
|
|
45
|
+
///
|
|
46
|
+
interface _transaction {
|
|
47
|
+
id: string
|
|
48
|
+
mutations: string[]
|
|
49
|
+
startedAt: string
|
|
50
|
+
committedAt?: string
|
|
51
|
+
source?: string
|
|
52
|
+
message?: string
|
|
53
|
+
metadata?: Record<string, any>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
///
|
|
57
|
+
// A commit - immutable record of a logical state change.
|
|
58
|
+
///
|
|
59
|
+
interface _commit {
|
|
60
|
+
id: string
|
|
61
|
+
parent: string | null
|
|
62
|
+
timestamp: string
|
|
63
|
+
patches: _patch[]
|
|
64
|
+
source?: string
|
|
65
|
+
message?: string
|
|
66
|
+
metadata?: Record<string, any>
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
///
|
|
70
|
+
// Options for explicit mutation.
|
|
71
|
+
///
|
|
72
|
+
interface _mutateOptions {
|
|
73
|
+
source?: string
|
|
74
|
+
transactionId?: string
|
|
75
|
+
}
|