memorio 4.9.31 โ 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.
- package/AGENTS.md +3 -3
- package/README.md +327 -330
- package/SECURITY.md +17 -1
- package/SUMMARY.md +59 -45
- package/adr/001-state-proxy-model.md +96 -0
- package/adr/002-observer-semantics.md +180 -0
- package/adr/003-deep-mutation-semantics.md +129 -0
- package/adr/004-array-mutation-semantics.md +128 -0
- package/adr/005-scheduler-contract.md +149 -0
- package/adr/006-context-isolation.md +92 -0
- package/adr/007-mutation-records.md +118 -0
- package/adr/008-transactions.md +106 -0
- package/adr/009-history-model.md +110 -0
- package/adr/README.md +46 -0
- package/adr/template.md +49 -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 +4594 -0
- package/global.d.ts +8 -0
- package/global.js +4532 -0
- package/index.cjs +706 -649
- package/index.d.ts +1 -0
- package/index.js +686 -648
- package/llms.txt +72 -4
- package/markdown/AUDIT-REPORT.md +135 -0
- package/markdown/CACHE.md +100 -0
- package/markdown/CHANGELOG.md +243 -0
- package/markdown/DEVTOOLS.md +129 -0
- package/markdown/DISPATCH.md +177 -0
- package/markdown/HISTORY.md +199 -0
- package/markdown/IDB.md +178 -0
- package/markdown/IMPORT.md +153 -0
- package/markdown/INSPECT.md +123 -0
- package/markdown/LOGGER.md +154 -0
- package/markdown/MEMORY-ATTACHMENT.md +96 -0
- package/markdown/MEMORY.md +162 -0
- package/markdown/OBSERVER.md +209 -0
- package/markdown/PLATFORM.md +271 -0
- package/markdown/PROJECT.md +311 -0
- package/markdown/SCHEMA.md +176 -0
- package/markdown/SECURITY.md +330 -0
- package/markdown/SESSION.md +165 -0
- package/markdown/SQLITE.md +190 -0
- package/markdown/STATE.md +160 -0
- package/markdown/STORE.md +171 -0
- package/markdown/SYNC.md +319 -0
- package/markdown/TYPED.md +165 -0
- package/markdown/USEOBSERVER.md +257 -0
- package/modules/redux.cjs +561 -374
- package/modules/redux.cjs.map +1 -1
- package/modules/redux.js +561 -374
- package/modules/redux.js.map +1 -1
- package/package.json +13 -3
- package/types/env.d.ts +19 -9
- package/types/exports.d.ts +20 -0
- package/types/history.d.ts +13 -1
- package/types/memorio.d.ts +17 -5
- package/types/mutation.d.ts +75 -0
package/llms.txt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
**Memorio** is
|
|
5
|
+
**Memorio** is an application state intelligence runtime. It manages application state, remembers how it changed, understands causal relationships, enables deterministic replay, and can simulate the impact of future changes. It provides reactive state, persistence, and observation capabilities with zero dependencies. It works in Node.js, Deno, browsers, and edge environments.
|
|
6
6
|
|
|
7
7
|
```
|
|
8
8
|
npm i memorio
|
|
@@ -26,8 +26,10 @@ Memorio provides 6 storage modules plus utilities:
|
|
|
26
26
|
|
|
27
27
|
## Quick Start
|
|
28
28
|
|
|
29
|
+
Memorio does not expose APIs on `globalThis` by default. Use explicit named imports for normal application code:
|
|
30
|
+
|
|
29
31
|
```javascript
|
|
30
|
-
import 'memorio'
|
|
32
|
+
import { state, useObserver } from 'memorio'
|
|
31
33
|
|
|
32
34
|
// Set reactive state
|
|
33
35
|
state.user = { name: 'Sara', role: 'admin' }
|
|
@@ -40,6 +42,15 @@ useObserver(
|
|
|
40
42
|
)
|
|
41
43
|
```
|
|
42
44
|
|
|
45
|
+
```note
|
|
46
|
+
To opt in to global access (state, store, session, cache, idb, sqlite, observer, useObserver on `globalThis`), use the explicit global entrypoint:
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
import 'memorio/global'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
This is independent of bundler environment detection (no `import.meta.env.DEV`, no `process.env.NODE_ENV` checks).
|
|
53
|
+
|
|
43
54
|
## API Reference
|
|
44
55
|
|
|
45
56
|
### `state` - Reactive State
|
|
@@ -238,7 +249,7 @@ observer.removeAll()
|
|
|
238
249
|
Primary way to observe state changes in React components.
|
|
239
250
|
|
|
240
251
|
```jsx
|
|
241
|
-
import 'memorio'
|
|
252
|
+
import { useObserver, state } from 'memorio'
|
|
242
253
|
import { useReducer } from 'react'
|
|
243
254
|
|
|
244
255
|
function Counter() {
|
|
@@ -305,7 +316,7 @@ memorio.logger.exportLogs() // JSON string of all history
|
|
|
305
316
|
|
|
306
317
|
## Platform Detection
|
|
307
318
|
|
|
308
|
-
Access via `memorio.*` after `
|
|
319
|
+
Access via `memorio.*` after importing from `memorio`:
|
|
309
320
|
|
|
310
321
|
```javascript
|
|
311
322
|
memorio.isBrowser() // true in Chrome, Firefox, Safari
|
|
@@ -429,6 +440,63 @@ memorio.canRedo() // true
|
|
|
429
440
|
|
|
430
441
|
### `memorio.trace()` - Mutation Log
|
|
431
442
|
|
|
443
|
+
Every mutation is recorded as a structured `Mutation` with a unique ID, HLC timestamp, operation, before/after values, source attribution, and optional transaction ID:
|
|
444
|
+
|
|
445
|
+
```javascript
|
|
446
|
+
memorio.enableHistory(true)
|
|
447
|
+
state.user.name = 'Sara'
|
|
448
|
+
|
|
449
|
+
const log = memorio.trace()
|
|
450
|
+
// [{
|
|
451
|
+
// id: 'm_01h...', path: 'user.name', operation: 'set',
|
|
452
|
+
// before: undefined, after: 'Sara',
|
|
453
|
+
// timestamp: 1780000000, hlc: 'hlc:1780000000:00:abc1',
|
|
454
|
+
// action: 'set', newValue: 'Sara', previousValue: undefined,
|
|
455
|
+
// source: undefined, transactionId: undefined
|
|
456
|
+
// }]
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
### Mutation Engine (Memorio 5)
|
|
460
|
+
|
|
461
|
+
`memorio.mutate()` records a mutation with source attribution:
|
|
462
|
+
|
|
463
|
+
```javascript
|
|
464
|
+
import { memorio } from 'memorio'
|
|
465
|
+
|
|
466
|
+
memorio.enableHistory(true)
|
|
467
|
+
|
|
468
|
+
const m = memorio.mutate('state.user.role', 'admin', {
|
|
469
|
+
source: 'permissions.enableAdmin'
|
|
470
|
+
})
|
|
471
|
+
console.log(m.id) // "m_01h4f2k7..."
|
|
472
|
+
console.log(m.operation) // "set"
|
|
473
|
+
console.log(m.before) // undefined
|
|
474
|
+
console.log(m.after) // "admin"
|
|
475
|
+
console.log(m.source) // "permissions.enableAdmin"
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
Transactions group related mutations atomically:
|
|
479
|
+
|
|
480
|
+
```javascript
|
|
481
|
+
const tx = memorio.transaction('user.migration', 'Migrate to v2')
|
|
482
|
+
|
|
483
|
+
state.user.role = 'admin'
|
|
484
|
+
state.user.v2 = true
|
|
485
|
+
|
|
486
|
+
memorio.commitTransaction() // or memorio.abortTransaction() to roll back
|
|
487
|
+
|
|
488
|
+
// Named imports for fine-grained control:
|
|
489
|
+
import { beginTransaction, commitTransaction, abortTransaction, currentTransaction } from 'memorio'
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
Patch utilities convert mutations to RFC 6902-style patches for replay, sync, and simulation:
|
|
493
|
+
|
|
494
|
+
```javascript
|
|
495
|
+
import { mutationToPatch, diffToPatch, canMerge, mergePatches } from 'memorio'
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### `memorio.trace()` - Mutation Log
|
|
499
|
+
|
|
432
500
|
```javascript
|
|
433
501
|
memorio.trace()
|
|
434
502
|
// [{ path, action, newValue, previousValue, timestamp }, ...]
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
> **Status:** Accepted
|
|
2
|
+
> **Date:** 2026-09-12
|
|
3
|
+
> **Deciders:** Memorio 5.x Core Team
|
|
4
|
+
> **Scope**: Security (NIST/OWASP/NSA), Performance, Reliability, Code Quality
|
|
5
|
+
> **Standard**: NIST SP 800-53, OWASP ASVS, NSA Cybersecurity Guidelines
|
|
6
|
+
>
|
|
7
|
+
---
|
|
8
|
+
# Audit Report - Memorio v4.9.5
|
|
9
|
+
|
|
10
|
+
## 1. Security Audit
|
|
11
|
+
|
|
12
|
+
### Findings
|
|
13
|
+
|
|
14
|
+
| Severity | Issue | Status |
|
|
15
|
+
|----------|-------|--------|
|
|
16
|
+
| None | Secrets/credentials in source | โ
Clean - all "token"/"secret" are in examples/test fixtures |
|
|
17
|
+
| None | Dynamic code execution (`eval`, `new Function`) | โ
Not present |
|
|
18
|
+
| None | Prototype pollution (`__proto__`, `constructor.prototype`) | โ
Not present |
|
|
19
|
+
| None | XSS vectors (`innerHTML`, `document.write`) | โ
Not present |
|
|
20
|
+
| None | SQL injection (sqlite module) | โ
Uses parameterized statements via sql.js `stmt.bind()` |
|
|
21
|
+
| Low | `console.warn`/`console.error` used outside catch blocks | โ ๏ธ Present in `functions/state/index.ts` guard clauses (state locked/protected) |
|
|
22
|
+
| None | Namespace isolation in memory system | โ
Documented trust model with per-namespace storage keys |
|
|
23
|
+
|
|
24
|
+
### Actions Taken
|
|
25
|
+
- **Removed `__DEV__` references**: All bare `__DEV__` references removed from source code and documentation
|
|
26
|
+
- **Updated comments**: Replaced `__DEV__` mentions in JSDoc comments with `DEV`/runtime detection references
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 2. Performance Audit
|
|
31
|
+
|
|
32
|
+
### Findings
|
|
33
|
+
|
|
34
|
+
| Issue | Impact | Status |
|
|
35
|
+
|-------|--------|--------|
|
|
36
|
+
| `wrapperCache` in `state/index.ts` uses `WeakMap` | โ
No memory leak - GC cleans up orphaned wrappers |
|
|
37
|
+
| `JSON.parse(JSON.stringify())` in 3 locations | Low - only for snapshot/list/inspect operations, not hot loops | โ
Acceptable |
|
|
38
|
+
| `setTimeout` in sqlite persistence | โ
Async, doesn't block main thread |
|
|
39
|
+
| No `console.log` in hot paths | โ
All logging uses `console.debug` |
|
|
40
|
+
|
|
41
|
+
### Actions Taken
|
|
42
|
+
- **No performance changes needed**: Architecture is already optimized for the use case
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 3. Reliability Audit
|
|
47
|
+
|
|
48
|
+
### Findings
|
|
49
|
+
|
|
50
|
+
| Issue | Location | Risk | Status |
|
|
51
|
+
|-------|----------|------|--------|
|
|
52
|
+
| DevTools using `globalThis.state/store/session/cache` | `functions/devtools/index.ts` | High - fails when globals not initialized (prod mode) | โ
Fixed |
|
|
53
|
+
| `console.error` in non-catch contexts | `functions/state/index.ts:182,188,194,200` | Low - noisy console in strict mode | โ ๏ธ Deferred (UX choice) |
|
|
54
|
+
|
|
55
|
+
### Actions Taken
|
|
56
|
+
|
|
57
|
+
**DevTools module deduplication (critical fix)**:
|
|
58
|
+
- Removed direct `globalThis.state/store/session/cache` access from `functions/devtools/index.ts`
|
|
59
|
+
- Replaced with singleton access via private `globalThis` keys (`__memorio_state_instance__`, `__memorio_store_instance__`, `__memorio_session_instance__`, `__memorio_cache_instance__`)
|
|
60
|
+
- These keys are the same ones used by the modules themselves for singleton deduplication
|
|
61
|
+
- This also fixes a **circular import issue** that arose from naive direct imports (state โ dispatch โ ... โ devtools cycle)
|
|
62
|
+
- Access via private singleton keys is safe because they are set at module initialization, before `core/global.ts` runs
|
|
63
|
+
- Updated 3 functions: `inspect()`, `stats()`, `exportData()`/`importData()`/`clear()`/`watch()`/`help()`
|
|
64
|
+
- Removed emoji prefixes from console output for cleaner logs
|
|
65
|
+
- Changed `console.error` to `console.debug` for consistency
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 4. Code Quality Audit
|
|
70
|
+
|
|
71
|
+
### Findings
|
|
72
|
+
|
|
73
|
+
| Issue | Status |
|
|
74
|
+
|-------|--------|
|
|
75
|
+
| Duplicate storage pattern in `store` and `session` | โ
Pre-existing - same `_getPrefix/_prefixKey/_read/_write/_remove` pattern (acceptable) |
|
|
76
|
+
| `console.warn` vs `console.debug` inconsistency in `state/index.ts` | โ ๏ธ Present - state lock/protected uses `console.error` |
|
|
77
|
+
| JSDoc coverage on public functions | โ
Complete |
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 5. Documentation Audit
|
|
82
|
+
|
|
83
|
+
### Actions Taken
|
|
84
|
+
- **Merged changelogs**: Combined `.project/CHANGELOG.md` (v4.9.5 detailed) into `.project/markdown/CHANGELOG.md`
|
|
85
|
+
- **Updated version references**: Changed v3.0.2 โ v4.9.5 throughout
|
|
86
|
+
- **Updated stack**: Jest โ vitest, `config/` โ `core/`
|
|
87
|
+
- **Removed `__DEV__` mentions**: All documentation comments updated
|
|
88
|
+
- **Added "Module deduplication strategy"** section to `docs/README.md`
|
|
89
|
+
- **Updated CHANGELOG** with v4.9.5 entry documenting all fixes
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 6. Lint & Build Verification
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
โ
oxlint: 0 warnings, 0 errors (60 files, 92 rules, 8 threads)
|
|
97
|
+
โ
Production build: 0 __DEV__ references in dist/index.js and dist/index.cjs
|
|
98
|
+
โ
Tests: 200 passed, 4 skipped, 1 todo (0 failures)
|
|
99
|
+
โ
Files deployed to A:/Gitea/picla.app.examplepage/node_modules/memorio/
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 7. Additional Code Quality Fixes
|
|
105
|
+
|
|
106
|
+
| File | Issue | Fix |
|
|
107
|
+
|------|-------|-----|
|
|
108
|
+
| `functions/memory/journal.ts:62` | Unused `serialize` function | Removed |
|
|
109
|
+
| `core/hlc.ts:83` | Unused `incoming` parameter | Renamed to `_incoming` |
|
|
110
|
+
| `functions/memory/index.ts:553,556` | Unnecessary regex escapes `\.` | Changed to `.` |
|
|
111
|
+
| `functions/devtools/index.ts` | Used `globalThis.state` instead of imports | Replaced with singleton keys |
|
|
112
|
+
| `.oxlintrc.json` | Missing lint config | Created with ignore patterns + rule overrides |
|
|
113
|
+
| All files | `__DEV__` references in comments | Removed/replaced |
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Summary of Files Modified
|
|
118
|
+
|
|
119
|
+
| File | Change |
|
|
120
|
+
|------|--------|
|
|
121
|
+
| `core/env.ts` | Removed `__DEV__` from comments |
|
|
122
|
+
| `core/global.ts` | Updated comments: `__DEV__` โ runtime detection |
|
|
123
|
+
| `functions/devtools/index.ts` | Fixed circular imports + globalThis access; removed `__DEV__`; use singleton keys |
|
|
124
|
+
| `functions/memory/journal.ts` | Removed unused `serialize` function |
|
|
125
|
+
| `core/hlc.ts` | Fixed unused parameter `_incoming` |
|
|
126
|
+
| `functions/memory/index.ts` | Fixed regex escapes |
|
|
127
|
+
| `functions/devtools/index.ts` | Fixed circular imports + globalThis access; use singleton keys |
|
|
128
|
+
| `tests/vitest/vitest.config.ts` | Removed `__DEV__` from comments |
|
|
129
|
+
| `types/env.d.ts` | Removed `__DEV__` from comments |
|
|
130
|
+
| `.oxlintrc.json` | New lint configuration |
|
|
131
|
+
| `tsup.config.ts` | Disabled minification + enabled sourcemaps to avoid socket.dev false positives |
|
|
132
|
+
| `.project/markdown/CHANGELOG.md` | Merged changelogs, added v4.9.5 entry |
|
|
133
|
+
| `.project/markdown/PROJECT.md` | Updated version, stack, structure (was memorio.md) |
|
|
134
|
+
| `docs/README.md` | Added module deduplication strategy section |
|
|
135
|
+
| `tests/scripts/update-node-modules-memorio.cjs` | New deploy script for user app |
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
> **Status:** Published
|
|
2
|
+
> **Date:** 2026-09-12
|
|
3
|
+
> **Deciders:** Memorio 5.x Core Team
|
|
4
|
+
> **Scope**: API Reference
|
|
5
|
+
> **Standard**: Memorio API Specification v5
|
|
6
|
+
>
|
|
7
|
+
---
|
|
8
|
+
# Cache - Memorio
|
|
9
|
+
|
|
10
|
+
> โ
**Universal**: Works in Browser, Node.js, Deno, and Edge Workers
|
|
11
|
+
|
|
12
|
+
Cache provides in-memory storage with a simple API. Data is lost on page refresh or process restart.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install memorio
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
import { cache } from 'memorio';
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
> **Classic `import`**: `cache` is also available via the global entrypoint.
|
|
25
|
+
> `import 'memorio/global'` exposes the same instance as `globalThis.cache`.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Quick Examples
|
|
30
|
+
|
|
31
|
+
### Example 1: Basic Usage
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
// Save data
|
|
35
|
+
cache.set('username', 'Mario');
|
|
36
|
+
cache.set('score', 1500);
|
|
37
|
+
|
|
38
|
+
// Read data
|
|
39
|
+
console.debug(cache.get('username')); // "Mario"
|
|
40
|
+
console.debug(cache.get('score')); // 1500
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Example 2: Intermediate
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
// Store objects
|
|
47
|
+
cache.set('user', { name: 'Luigi', level: 5 });
|
|
48
|
+
const user = cache.get('user');
|
|
49
|
+
console.debug(user.name); // "Luigi"
|
|
50
|
+
|
|
51
|
+
// Remove single item
|
|
52
|
+
cache.remove('username');
|
|
53
|
+
|
|
54
|
+
// Clear all cache
|
|
55
|
+
cache.removeAll();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## API Reference
|
|
61
|
+
|
|
62
|
+
### Methods
|
|
63
|
+
|
|
64
|
+
| Method | Parameters | Returns | Description |
|
|
65
|
+
|--------|------------|---------|-------------|
|
|
66
|
+
| `cache.get(name)` | `name: string` | `any` | Get value from cache |
|
|
67
|
+
| `cache.set(name, value)` | `name: string, value: any` | `void` | Save value to cache |
|
|
68
|
+
| `cache.remove(name)` | `name: string` | `boolean` | Remove single item |
|
|
69
|
+
| `cache.removeAll()` | `none` | `boolean` | Clear all cache |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Storage Comparison
|
|
74
|
+
|
|
75
|
+
| Feature | Cache | Store | Session | IDB |
|
|
76
|
+
|---------|-------|-------|---------|-----|
|
|
77
|
+
| Platform Support | All (universal) | Browser/Edge | Browser/Edge | Browser only |
|
|
78
|
+
| Lifetime | Until refresh | Forever | Until tab closes | Forever |
|
|
79
|
+
| Capacity | Unlimited | ~5-10 MB | ~5-10 MB | 50+ MB |
|
|
80
|
+
| Use case | Temporary data | User preferences | Auth tokens | Large data |
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Platform Support
|
|
85
|
+
|
|
86
|
+
| Platform | Support | Notes |
|
|
87
|
+
|----------|---------|-------|
|
|
88
|
+
| Browser | โ
Full | In-memory, lost on refresh |
|
|
89
|
+
| Node.js | โ
Full | In-memory, lost on restart |
|
|
90
|
+
| Deno | โ
Full | In-memory, lost on restart |
|
|
91
|
+
| Edge Workers | โ
Full | In-memory, lost on function cold start |
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Best Practices
|
|
96
|
+
|
|
97
|
+
1. Use for temporary data that doesn't need persistence
|
|
98
|
+
2. Great for computed values or API response caching
|
|
99
|
+
3. Data is lost on page refresh - don't use for important data
|
|
100
|
+
4. Clear with `cache.removeAll()` when no longer needed
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
> **Status:** Published
|
|
2
|
+
> **Date:** 2026-09-12
|
|
3
|
+
> **Deciders:** Memorio 5.x Core Team, BigLogic
|
|
4
|
+
> **Scope**: Project Documentation
|
|
5
|
+
> **Standard**: Memorio Documentation Standard v5
|
|
6
|
+
>
|
|
7
|
+
---
|
|
8
|
+
# Changelog - Memorio
|
|
9
|
+
|
|
10
|
+
All notable changes to this project will be documented in this file.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Unreleased - Module Duplication Fix & Architecture Cleanup
|
|
15
|
+
|
|
16
|
+
### ๐ Bug Fixes
|
|
17
|
+
|
|
18
|
+
- **Module duplication / state reset**: Fixed issue where importing memorio via different paths (ESM `dist/index.js`, CJS `index.cjs`, package name `memorio`, absolute file path) created separate module instances, each with its own empty proxy. This caused `globalThis.state` to be overwritten with a fresh empty proxy on second import, resetting all state data.
|
|
19
|
+
- All modules (`state`, `store`, `session`, `cache`) now use private `globalThis` singleton keys (`__memorio_state_instance__`, `__memorio_store_instance__`, `__memorio_session_instance__`, `__memorio_cache_instance__`) to guarantee a single shared instance across all import paths.
|
|
20
|
+
- `memorio.global()` in `core/global.ts` now guards with `if (!(key in globalThis))` to prevent overwriting existing dev globals - protecting against module duplication resetting state.
|
|
21
|
+
- **Removed `__DEV__` build-time constant**: Replaced all bare `__DEV__` references with `DEV`/`PROD` from `core/env.ts` (runtime detection via `process.env.NODE_ENV`). Eliminates `ReferenceError: __DEV__ is not defined` in browser environments without bundler `define` config. Production builds now have **0** `__DEV__` references.
|
|
22
|
+
|
|
23
|
+
### ๐ง Code Refactoring
|
|
24
|
+
|
|
25
|
+
- **Script organization**: Moved debug/verification scripts from root to `tests/scripts/`:
|
|
26
|
+
- `check-dev-mode.mjs` โ `tests/scripts/check-dev-mode.mjs`
|
|
27
|
+
- `update-node-modules-memorio.cjs` โ `tests/scripts/update-node-modules-memorio.cjs`
|
|
28
|
+
- `test-state-persist.ts` โ `tests/scripts/test-state-persist.ts`
|
|
29
|
+
- `tests/test-nav.mjs` โ `tests/playwright/test-nav.mjs`
|
|
30
|
+
|
|
31
|
+
### ๐ Documentation Updates
|
|
32
|
+
|
|
33
|
+
- `docs/README.md`: Documented the singleton pattern and module deduplication strategy in the "How it works" section.
|
|
34
|
+
|
|
35
|
+
### ๐งน Code Quality
|
|
36
|
+
|
|
37
|
+
- **Removed dead code**: `serialize` function in `functions/memory/journal.ts` (unused)
|
|
38
|
+
- **Fixed unused parameter**: `tick(incoming)` in `core/hlc.ts` renamed to `tick(_incoming)`
|
|
39
|
+
- **Fixed regex escapes**: Removed unnecessary `\.` escapes in `functions/memory/index.ts` path regexes
|
|
40
|
+
- **DevTools reliability**: Replaced `globalThis.state/store/session/cache` access with singleton instance keys (`__memorio_*_instance__`) to prevent `ReferenceError` in production and avoid circular imports
|
|
41
|
+
- **Console consistency**: Changed `console.error` to `console.debug` in devtools error handling, removed emoji prefixes
|
|
42
|
+
|
|
43
|
+
### ๐ Security - Supply Chain
|
|
44
|
+
|
|
45
|
+
- **Removed hardcoded CDN URL**: `functions/sqlite/tools/db.support.ts` no longer references `https://cdn.jsdelivr.net/npm/sql.js/dist/` hardcoded. SQLite now requires explicit loader configuration via `sqlite.config({ loader, scriptUrl })` or fails gracefully with a clear error message.
|
|
46
|
+
- **Eliminated external script injection risk**: No external URL strings in the bundle - prevents socket.dev supply-chain warnings for "URL string literals"
|
|
47
|
+
- **Added `browser` field** in `package.json` for explicit browser/Node resolution
|
|
48
|
+
- **Added `.oxlintrc.json`**: Lint configuration with ignore patterns and rule overrides
|
|
49
|
+
- **tsup config**: Disabled minification (`minifyWhitespace`, `minifyIdentifiers`, `minifySyntax` โ `false`), enabled sourcemaps (`sourcemap: true`) and `keepNames: true` to produce readable bundles and eliminate socket.dev "minified code" false positives
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## v4.9.0 - 2026-09-06
|
|
54
|
+
|
|
55
|
+
### ๐ Bug Fixes
|
|
56
|
+
|
|
57
|
+
- **Module duplication / state reset across import paths**: Fixed issue where importing memorio via different paths (ESM `dist/index.js`, CJS `index.cjs`, package name `memorio`, absolute file path) created separate module instances, each with its own empty proxy. This caused `globalThis.state` to be overwritten with a fresh empty proxy on second import, resetting all state data.
|
|
58
|
+
- All modules (`state`, `store`, `session`, `cache`) now use private `globalThis` singleton keys (`__memorio_state_instance__`, `__memorio_store_instance__`, `__memorio_session_instance__`, `__memorio_cache_instance__`) to guarantee a single shared instance across all import paths.
|
|
59
|
+
- `memorio.global()` in `core/global.ts` now guards with `if (!(key in globalThis))` to prevent overwriting existing dev globals - protecting against module duplication resetting state.
|
|
60
|
+
|
|
61
|
+
### ๐ง Code Refactoring
|
|
62
|
+
|
|
63
|
+
- **Removed `__DEV__` build-time constant**: Replaced all bare `__DEV__` references with `DEV`/`PROD` from `core/env.ts` (runtime detection via `process.env.NODE_ENV`). Eliminates `ReferenceError: __DEV__ is not defined` in browser environments without bundler `define` config. Production builds verified to have **0** `__DEV__` references in both ESM and CJS outputs.
|
|
64
|
+
- `core/env.ts`: Rewrote from `__DEV__`-based to pure runtime detection. `DEV` = `process.env.NODE_ENV !== 'production'` (or `true` in browser without `process` polyfill).
|
|
65
|
+
- All `if (__DEV__)` guards across `core/global.ts`, `functions/state/`, `functions/store/`, `functions/session/`, `functions/cache/`, `functions/idb/`, `functions/sqlite/`, `functions/observer/`, `functions/useObserver/`, `functions/message/`, `functions/logger/`, and `functions/devtools/` now use `if (DEV)` with an explicit `import { DEV } from '../../core/env'`.
|
|
66
|
+
- `core/global.ts`: `memorio.global()` auto-call is gated behind `if (isDev)` (sourced from `DEV`), not `if (__DEV__)`.
|
|
67
|
+
- `tsup.config.ts`: Removed `'__DEV__'` from `define`. Only `process.env.NODE_ENV` is defined.
|
|
68
|
+
- `vitest.config.ts`: Removed `__DEV__: true` define. Uses `'process.env.NODE_ENV': '"development"'` instead.
|
|
69
|
+
- `types/env.d.ts`: Removed `declare const __DEV__: boolean`. Documents runtime `DEV`/`PROD` imports from `core/env.ts`.
|
|
70
|
+
|
|
71
|
+
### โจ API Additions
|
|
72
|
+
|
|
73
|
+
- **`memorio.env.isDev` / `memorio.env.isProd`**: Runtime environment detection properties on the `memorio` namespace. Returns `true`/`false` based on `process.env.NODE_ENV` - no build-time `__DEV__` define required.
|
|
74
|
+
- **`memorio.global()` method**: Manually sets dev-only globals (`state`, `store`, `session`, `cache`, `idb`, `sqlite`, `observer`, `useObserver`) on `globalThis`. Auto-called in development; idempotent and safe to call multiple times.
|
|
75
|
+
|
|
76
|
+
### ๐ API - Typed Stores & Schema Validation
|
|
77
|
+
|
|
78
|
+
- **Typed Stores**: `memorio.typed<T>()` returns the global `state` proxy cast to a TypeScript type `T`, providing compile-time type safety, IntelliSense autocomplete, and static property checking on state access and mutation. Zero runtime cost - the returned object is the exact same Proxy as `globalThis.state`.
|
|
79
|
+
- **Schema Validation**: `memorio.registerSchema(path, schema)` registers runtime validators for state paths. Writes that violate a registered schema are rejected before storage. Supports type checking, required fields, min/max, regex patterns, enums, nested property schemas, and custom validator functions. Includes `memorio.validate(path, value)`, `memorio.unregisterSchema(path)`, and `memorio.listSchemas()`.
|
|
80
|
+
|
|
81
|
+
### ๐ Documentation Updates
|
|
82
|
+
|
|
83
|
+
- `docs/README.md`: Added "Typed Stores" and "Schema Validation" sections. Updated "Is this for you?" to reference the new type-safe options.
|
|
84
|
+
- `docs/llms.txt`: Added typed stores and schema validation sections.
|
|
85
|
+
- `docs/SUMMARY.md`: Added links to new doc pages.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## v4.6.1 (Security Patch) - 2026-08-14 - CRITICAL Security Fix
|
|
90
|
+
|
|
91
|
+
### ๐ Security NOTICE (v4.6.0)
|
|
92
|
+
|
|
93
|
+
**CRITICAL**: A Gitea Personal Access Token was accidentally committed to `.npmrc` in v4.6.0
|
|
94
|
+
|
|
95
|
+
**Affected**: `v4.6.0` tag and all builds from that version
|
|
96
|
+
|
|
97
|
+
**Action Required**:
|
|
98
|
+
- **IMMEDIATE**: Revoke ALL tokens on Gitea Packages by admin access
|
|
99
|
+
- **GENERATE**: Create new PAT with scope `write:package` only
|
|
100
|
+
- **CONFIGURE**: Add as secret `PAT` in GitHub Actions or Gitea Actions
|
|
101
|
+
- **UPGRADE**: Use v4.6.1 where the token is replaced with `${PAT}` environment variable
|
|
102
|
+
|
|
103
|
+
The hardcoded token `2f398d5d7a734781e96108fdd0dbbabad41ef77a` has been removed in v4.6.1.
|
|
104
|
+
|
|
105
|
+
### ๐ Bug Fixes
|
|
106
|
+
|
|
107
|
+
- **SECURITY**: Removed hardcoded Gitea PAT from `.npmrc` (exposed token remediated)
|
|
108
|
+
- Replaced with environment variable `${PAT}` for secure authentication
|
|
109
|
+
|
|
110
|
+
### ๐ Documentation Updates
|
|
111
|
+
|
|
112
|
+
- `.npmrc`: Token replaced with environment variable reference
|
|
113
|
+
- `.gitea/workflows/npm.yml`: Configured to use secrets `GITEA_USER` and `PAT`
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## v4.6.0 (Previous - SECURITY ISSUE) - 2026-08-13 - Refactoring & Documentation
|
|
118
|
+
|
|
119
|
+
**โ ๏ธ WARNING**: This version had a hardcoded PAT token that was later remediated in v4.6.1**
|
|
120
|
+
|
|
121
|
+
### ๐ Bug Fixes
|
|
122
|
+
|
|
123
|
+
- Fixed circular import in `idb/index.ts` โ `core/global`
|
|
124
|
+
- Fixed dead `globalThis._propertyAccessLog` reference in `observer`
|
|
125
|
+
- Fixed `dispatch.remove(f)` tuple bug in `functions/dispatch.ts`
|
|
126
|
+
- Fixed `logger.isDebugEnabled` using wrong module reference
|
|
127
|
+
- Removed dead `propertyAccessLog` / `pushPropertyAccess` from `core/internal.ts`
|
|
128
|
+
- Removed duplicate path-tracking block in `state` get handler
|
|
129
|
+
- Removed redundant `?? key` fallback in `state` set handler
|
|
130
|
+
|
|
131
|
+
### ๐ง Code Refactoring
|
|
132
|
+
|
|
133
|
+
- **Self-contained modules**: All modules now work independently without internal `globalThis.memorio.*` reads/writes
|
|
134
|
+
- **Module-local state**: Created `core/internal.ts` for module-local singletons
|
|
135
|
+
- **Bootstrap-only global**: `core/global.ts` now only publishes to `globalThis.memorio` at initialization
|
|
136
|
+
- **Removed dead code**: `core/constructor.ts` deleted (unused)
|
|
137
|
+
- **Extracted helpers**: `_read`/`_write`/`_remove` in `store` and `session` to eliminate duplication
|
|
138
|
+
- **Fixed circular imports**: `dispatch` โ `observer` via `globalThis.events`
|
|
139
|
+
|
|
140
|
+
### ๐ Documentation Updates
|
|
141
|
+
|
|
142
|
+
- `docs/README.md`: Added Classic `import { state } from 'memorio'` section, improved badges layout, enhanced "Why memorio?" comparison table
|
|
143
|
+
- `docs/markdown/STORE.md`: Added classic import note
|
|
144
|
+
- `docs/markdown/IMPORT.md`: New file for named export guide
|
|
145
|
+
- `docs/SUMMARY.md`: Updated to include `IMPORT.md`
|
|
146
|
+
- `README.md`: Badge corrections, header cleanup, removed unverified bundle size claims
|
|
147
|
+
|
|
148
|
+
### ๐ GitHub Actions / Gitea Workflows
|
|
149
|
+
|
|
150
|
+
- Added `.gitea/workflows/npm.yml` for automatic npm package publishing to Gitea Packages on `v*` tags
|
|
151
|
+
- Requires `GITEA_USER` and `PAT` secrets
|
|
152
|
+
|
|
153
|
+
### ๐งช Tests
|
|
154
|
+
|
|
155
|
+
- **Result: 9 suites ยท 101 passed ยท 4 skipped ยท 1 todo**
|
|
156
|
+
- All lint and typecheck clean
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## v3.0.2 - 2026-05-19 - Bug Fix, Security & API Expansion
|
|
161
|
+
|
|
162
|
+
### ๐ Bug Fixes
|
|
163
|
+
|
|
164
|
+
- Removed dead code: `buildPathTracker` from `functions/state/index.ts` (unused Proxy builder, exported nowhere)
|
|
165
|
+
- Removed double `delete` in state `removeAll` handler (redundant null-check + delete on same key)
|
|
166
|
+
- Removed unbound `globalThis.state` reference in state init (would throw `ReferenceError` in strict mode)
|
|
167
|
+
- Removed `Object.freeze(observer)` referencing undeclared variable (`ReferenceError` on module load)
|
|
168
|
+
- Removed `confirm()` synchronous blocking call from `idb.db.delete` (library must not block main thread)
|
|
169
|
+
|
|
170
|
+
### ๐ Security Improvements
|
|
171
|
+
|
|
172
|
+
- Removed `esbuild-sass-plugin` and `esbuild-scss-modules-plugin` from `devDependencies` (unnecessary for a library with no styles)
|
|
173
|
+
- Removed `injectStyle: true`, `sassPlugin()` and `.css` loader from `tsup.config.ts`
|
|
174
|
+
- Deleted `tsup.plugin.injectCss.ts` (code injection vector completely removed from build pipeline)
|
|
175
|
+
- `console.error`/`console.warn` โ `console.debug` in `devtools` and `idb` error handlers (consistent debug-only logging policy)
|
|
176
|
+
- `store.set()` now blocks function values instead of silently logging and continuing
|
|
177
|
+
- All `PRIVATE License` headers in `functions/idb/` replaced with `MIT License`
|
|
178
|
+
|
|
179
|
+
### ๐ง Code Quality
|
|
180
|
+
|
|
181
|
+
- Added JSDoc to `observerFunction` in `functions/observer/index.ts`
|
|
182
|
+
- Added JSDoc to `cache` global in `functions/cache/index.ts`
|
|
183
|
+
- `lint` and `tsc` pass clean - 0 vulnerabilities from `npm audit`
|
|
184
|
+
|
|
185
|
+
### ๐ API - New in 3.0.2
|
|
186
|
+
|
|
187
|
+
| Function | Description |
|
|
188
|
+
|----------|-------------|
|
|
189
|
+
| `memorio.isBrowser()` | Returns `true` when running in a browser |
|
|
190
|
+
| `memorio.isNode()` | Returns `true` when running in Node.js |
|
|
191
|
+
| `memorio.isDeno()` | Returns `true` when running in Deno |
|
|
192
|
+
| `memorio.isEdge()` | Returns `true` in Cloudflare Workers, Vercel Edge, etc. |
|
|
193
|
+
| `memorio.getCapabilities()` | Full capabilities object (`platform`, `hasLocalStorage`, `hasIndexedDB`, โฆ) |
|
|
194
|
+
| `memorio.createContext(name?)` | Create multi-tenant isolated context |
|
|
195
|
+
| `memorio.listContexts()` | List all active isolated contexts |
|
|
196
|
+
| `memorio.deleteContext(id)` | Delete isolated context by ID |
|
|
197
|
+
| `memorio.isolate(name?)` | Shorthand alias for `createContext` |
|
|
198
|
+
|
|
199
|
+
### ๐งช Tests
|
|
200
|
+
- **Result: 8 suites ยท 95 passed ยท 3 skipped ยท 0 failed**
|
|
201
|
+
|
|
202
|
+
### ๐๏ธ Dependency Changes
|
|
203
|
+
|
|
204
|
+
| Removed | Reason |
|
|
205
|
+
|---------|--------|
|
|
206
|
+
| `esbuild-sass-plugin@3.7.0` | No SCSS in a library |
|
|
207
|
+
| `esbuild-scss-modules-plugin@1.1.1` | No SCSS in a library |
|
|
208
|
+
| 36 transitive packages | Removed from `node_modules` |
|
|
209
|
+
|
|
210
|
+
### ๐ Documentation Updates
|
|
211
|
+
|
|
212
|
+
- `docs/README.md`: replaced `console.debug` with `console.debug` in usage examples; fixed `esbuild` badge โ `tsup`
|
|
213
|
+
- `.github/CHANGELOG.md`: restructured with fix / security / changed sections
|
|
214
|
+
- `.github/HISTORY.md`: complete rewrite through v3.0.2
|
|
215
|
+
- `.github/SECURITY.md`: NIST/NSA standard + OWASP Top 10 mapping
|
|
216
|
+
- `.github/CITATION.cff`: license PRIVATE โ MIT to match `package.json`
|
|
217
|
+
- `.project/*`: all context documents updated to v3.0.2
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## v2.9.0 - 2026-05-13
|
|
222
|
+
|
|
223
|
+
### Added
|
|
224
|
+
- DevTools - `memorio.devtools.inspect()`, `stats()`, `exportData()`
|
|
225
|
+
- Logger with full history, stats and export
|
|
226
|
+
- Platform detection (`isBrowser`, `isNode`, `isDeno`, `isEdge`, `getCapabilities`)
|
|
227
|
+
- Session isolation via `crypto.randomUUID()`
|
|
228
|
+
|
|
229
|
+
### Changed
|
|
230
|
+
- Updated dependencies to latest versions
|
|
231
|
+
- Improved cross-platform support (Deno, Edge Workers, Node.js)
|
|
232
|
+
|
|
233
|
+
### Security
|
|
234
|
+
- Secure random session IDs replaced `Math.random()`
|
|
235
|
+
- Key validation (max 512 chars + character whitelist)
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## v2.5.0 - 2026-02-17
|
|
240
|
+
|
|
241
|
+
- Initial release of memorio (state, store, session, cache, idb)
|
|
242
|
+
- Observer pattern (`observer`)
|
|
243
|
+
- `useObserver` React hook
|