memorio 4.9.35 → 5.0.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.
Files changed (76) hide show
  1. package/AGENTS.md +3 -3
  2. package/README.md +307 -359
  3. package/SECURITY.md +17 -1
  4. package/SUMMARY.md +59 -45
  5. package/adr/001-state-proxy-model.md +96 -0
  6. package/adr/002-observer-semantics.md +180 -0
  7. package/adr/003-deep-mutation-semantics.md +129 -0
  8. package/adr/004-array-mutation-semantics.md +128 -0
  9. package/adr/005-scheduler-contract.md +149 -0
  10. package/adr/006-context-isolation.md +92 -0
  11. package/adr/007-mutation-records.md +118 -0
  12. package/adr/008-transactions.md +106 -0
  13. package/adr/009-history-model.md +110 -0
  14. package/adr/README.md +46 -0
  15. package/adr/template.md +49 -0
  16. package/examples/basic.ts +115 -115
  17. package/examples/browser-vanilla.html +358 -358
  18. package/examples/cache.ts +72 -72
  19. package/examples/cross-platform-guards.ts +57 -57
  20. package/examples/history.ts +104 -0
  21. package/examples/idb.ts +109 -109
  22. package/examples/multi-tenant-context.ts +44 -44
  23. package/examples/node-server.ts +308 -308
  24. package/examples/observer.ts +60 -60
  25. package/examples/platform.ts +115 -115
  26. package/examples/react-app.tsx +362 -362
  27. package/examples/react-observer.tsx +63 -63
  28. package/examples/semantic-memory.ts +60 -60
  29. package/examples/session-advanced.ts +91 -91
  30. package/examples/sqlite-batched-writes.ts +57 -57
  31. package/examples/state-advanced.ts +89 -89
  32. package/examples/store-advanced.ts +117 -117
  33. package/examples/sync.ts +90 -0
  34. package/examples/typed-and-schema.ts +102 -100
  35. package/examples/useObserver.tsx +140 -141
  36. package/global.cjs +4594 -0
  37. package/global.d.ts +8 -0
  38. package/global.js +4532 -0
  39. package/index.cjs +700 -678
  40. package/index.d.ts +1 -0
  41. package/index.js +680 -677
  42. package/llms.txt +72 -4
  43. package/markdown/AUDIT-REPORT.md +135 -0
  44. package/markdown/CACHE.md +100 -0
  45. package/markdown/CHANGELOG.md +243 -0
  46. package/markdown/DEVTOOLS.md +129 -0
  47. package/markdown/DISPATCH.md +177 -0
  48. package/markdown/HISTORY.md +199 -0
  49. package/markdown/IDB.md +178 -0
  50. package/markdown/IMPORT.md +153 -0
  51. package/markdown/INSPECT.md +123 -0
  52. package/markdown/LOGGER.md +154 -0
  53. package/markdown/MEMORY-ATTACHMENT.md +96 -0
  54. package/markdown/MEMORY.md +162 -0
  55. package/markdown/OBSERVER.md +209 -0
  56. package/markdown/PLATFORM.md +271 -0
  57. package/markdown/PROJECT.md +311 -0
  58. package/markdown/SCHEMA.md +176 -0
  59. package/markdown/SECURITY.md +330 -0
  60. package/markdown/SESSION.md +165 -0
  61. package/markdown/SQLITE.md +190 -0
  62. package/markdown/STATE.md +160 -0
  63. package/markdown/STORE.md +171 -0
  64. package/markdown/SYNC.md +319 -0
  65. package/markdown/TYPED.md +165 -0
  66. package/markdown/USEOBSERVER.md +257 -0
  67. package/modules/redux.cjs +320 -167
  68. package/modules/redux.cjs.map +1 -1
  69. package/modules/redux.js +320 -167
  70. package/modules/redux.js.map +1 -1
  71. package/package.json +13 -3
  72. package/types/env.d.ts +19 -9
  73. package/types/exports.d.ts +20 -0
  74. package/types/history.d.ts +13 -1
  75. package/types/memorio.d.ts +17 -5
  76. package/types/mutation.d.ts +75 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "memorio",
3
3
  "codeName": "memorio",
4
- "version": "4.9.35",
4
+ "version": "5.0.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": {
@@ -56,18 +56,23 @@
56
56
  "markdown/**/*",
57
57
  "types/**/*",
58
58
  "examples/**/*",
59
+ "modules/**/*",
60
+ "adr/**/*",
59
61
  "AGENTS.md",
60
62
  "COPYRIGHT.md",
61
63
  "README.md",
62
64
  "FUNDING.yml",
63
65
  "SECURITY.md",
66
+ "SECURITY-HARDENING.md",
64
67
  "SUMMARY.md",
65
68
  "LICENSE.md",
66
69
  "index.d.ts",
70
+ "global.d.ts",
71
+ "global.cjs",
72
+ "global.js",
67
73
  "index.cjs",
68
74
  "index.js",
69
- "llms.txt",
70
- "modules/**/*"
75
+ "llms.txt"
71
76
  ],
72
77
  "publishConfig": {
73
78
  "access": "public"
@@ -89,6 +94,11 @@
89
94
  "require": "./index.cjs",
90
95
  "types": "./index.d.ts"
91
96
  },
97
+ "./global": {
98
+ "import": "./global.js",
99
+ "require": "./global.cjs",
100
+ "types": "./global.d.ts"
101
+ },
92
102
  "./types/*": "./types/*",
93
103
  "./redux": {
94
104
  "import": "./modules/redux.js",
package/types/env.d.ts CHANGED
@@ -1,9 +1,19 @@
1
- /**
2
- * Runtime environment detection.
3
- *
4
- * `DEV` and `PROD` are derived at runtime from `process.env.NODE_ENV`
5
- * (polyfilled by Vite/Webpack in browsers). No build-time environment
6
- * constant is required. Import from `core/env.ts`:
7
- *
8
- * import { DEV, PROD } from './core/env'
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
@@ -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" />
@@ -110,6 +111,25 @@ export const enableHistory: (enabled?: boolean) => void
110
111
  export const clearHistory: () => void
111
112
  export const clearRedo: () => void
112
113
 
114
+ // ── Mutation Engine (Memorio 5) ───────────────────────────────────────
115
+ export const createMutation: (path: string, operation: _operation, before: any, after: any, opts?: { context?: string; source?: string; transactionId?: string }) => _mutation
116
+ export const recordMutation: (mutation: _mutation) => void
117
+ export const toPatch: (mutation: _mutation) => _patch | null
118
+ export const mutate: (path: string, value: any, opts?: { source?: string; transactionId?: string }) => _mutation
119
+ export const beginTransaction: (source?: string, message?: string, metadata?: Record<string, any>) => _transaction
120
+ export const transaction: (source?: string, message?: string, metadata?: Record<string, any>) => _transaction
121
+ export const commitTransaction: () => _transaction | null
122
+ export const abortTransaction: () => _transaction | null
123
+ export const currentTransaction: () => _transaction | null
124
+ export const listTransactions: () => _transaction[]
125
+ export const generateMutationId: () => string
126
+ export const generateTransactionId: () => string
127
+ export const generateCommitId: () => string
128
+ export const mutationToPatch: (mutation: _mutation) => _patch | null
129
+ export const diffToPatch: (path: string, before: any, after: any) => _patch | null
130
+ export const canMerge: (p1: _patch, p2: _patch) => boolean
131
+ export const mergePatches: (p1: _patch, p2: _patch) => _patch
132
+
113
133
  // ── Introspection (development-only) ─────────────────────────────────
114
134
  export const stateKeys: () => string[]
115
135
  export const pathExists: (path: string) => boolean
@@ -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
  ///
@@ -20,7 +20,7 @@ import type {
20
20
 
21
21
  interface _dispatch {
22
22
  set: (name: string, value?: any) => void
23
- listen: (name: string, cb?: ((e: Event) => void) | null, flag?: boolean) => (() => void) | void
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
 
@@ -71,9 +71,9 @@ interface _memorio {
71
71
  session: any
72
72
  cache: any
73
73
  }
74
- help?: () => void
75
- global?: () => void
76
- env?: { isDev: boolean; isProd: boolean }
74
+ help?: () => void
75
+ global?: () => void
76
+ env?: { isDev: boolean; isProd: boolean }
77
77
  // Schema validation
78
78
  registerSchema?: (path: string, schema: any) => void
79
79
  validate?: (path: string, value: any) => { valid: boolean; errors?: string[] }
@@ -92,7 +92,16 @@ interface _memorio {
92
92
  trace?: () => _mutationRecord[]
93
93
  enableHistory?: (enabled?: boolean) => void
94
94
  clearHistory?: () => void
95
- clearRedo?: () => void
95
+ clearRedo?: () => void
96
+ // Mutation Engine (Memorio 5)
97
+ mutate?: (path: string, value: any, opts?: { source?: string; transactionId?: string }) => _mutation
98
+ createMutation?: (path: string, operation: _operation, before: any, after: any, opts?: { context?: string; source?: string; transactionId?: string }) => _mutation
99
+ recordMutation?: (mutation: _mutation) => void
100
+ toPatch?: (mutation: _mutation) => _patch | null
101
+ transaction?: (source?: string, message?: string, metadata?: Record<string, any>) => _transaction
102
+ commitTransaction?: () => _transaction | null
103
+ abortTransaction?: () => _transaction | null
104
+ currentTransaction?: () => _transaction | null
96
105
  // Introspection
97
106
  stateKeys?: () => string[]
98
107
  pathExists?: (path: string) => boolean
@@ -166,4 +175,7 @@ interface globalThis {
166
175
  [key: string]: any
167
176
  }
168
177
 
178
+ declare var memorio: memorio
179
+ type memorio = memorio
180
+
169
181
  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
+ }