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.
- package/AGENTS.md +3 -3
- package/README.md +307 -359
- 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 +700 -678
- package/index.d.ts +1 -0
- package/index.js +680 -677
- 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 +320 -167
- package/modules/redux.cjs.map +1 -1
- package/modules/redux.js +320 -167
- 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/examples/basic.ts
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memorio Basic Example
|
|
3
|
-
*
|
|
4
|
-
* This example shows the fundamental features of Memorio:
|
|
5
|
-
* - State management
|
|
6
|
-
* - Store (localStorage)
|
|
7
|
-
* - Session storage
|
|
8
|
-
* - Platform detection
|
|
9
|
-
*
|
|
10
|
-
* Run: npx ts-node examples/basic.ts
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import 'memorio'
|
|
14
|
-
|
|
15
|
-
// ============================================
|
|
16
|
-
// PLATFORM DETECTION
|
|
17
|
-
// ============================================
|
|
18
|
-
|
|
19
|
-
console.debug('=== Platform Detection ===')
|
|
20
|
-
console.debug('Memorio version:', memorio.version)
|
|
21
|
-
|
|
22
|
-
// Check platform
|
|
23
|
-
if (memorio.isBrowser()) {
|
|
24
|
-
console.debug('Platform: Browser')
|
|
25
|
-
} else if (memorio.isNode()) {
|
|
26
|
-
console.debug('Platform: Node.js')
|
|
27
|
-
} else if (memorio.isDeno()) {
|
|
28
|
-
console.debug('Platform: Deno')
|
|
29
|
-
} else if (memorio.isEdge()) {
|
|
30
|
-
console.debug('Platform: Edge Worker')
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Get capabilities
|
|
34
|
-
const caps = memorio.getCapabilities()
|
|
35
|
-
console.debug('Capabilities:', {
|
|
36
|
-
platform: caps.platform,
|
|
37
|
-
hasLocalStorage: caps.hasLocalStorage,
|
|
38
|
-
hasSessionStorage: caps.hasSessionStorage,
|
|
39
|
-
hasIndexedDB: caps.hasIndexedDB
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
// ============================================
|
|
43
|
-
// STATE - In-memory reactive state
|
|
44
|
-
// ============================================
|
|
45
|
-
|
|
46
|
-
console.debug('\n=== State Management ===')
|
|
47
|
-
|
|
48
|
-
// Set some state values
|
|
49
|
-
state.name = 'Mario'
|
|
50
|
-
state.age = 30
|
|
51
|
-
state.isActive = true
|
|
52
|
-
state.profile = {
|
|
53
|
-
email: 'mario@example.com',
|
|
54
|
-
avatar: 'https://example.com/mario.png'
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Get state values
|
|
58
|
-
console.debug('Name:', state.name)
|
|
59
|
-
console.debug('Age:', state.age)
|
|
60
|
-
console.debug('Profile:', state.profile)
|
|
61
|
-
|
|
62
|
-
// List all states
|
|
63
|
-
console.debug('All states:', state.list)
|
|
64
|
-
|
|
65
|
-
// ============================================
|
|
66
|
-
// STORE - Persistent localStorage
|
|
67
|
-
// ============================================
|
|
68
|
-
|
|
69
|
-
console.debug('\n=== Store (Persistent Storage) ===')
|
|
70
|
-
|
|
71
|
-
// Check persistence
|
|
72
|
-
console.debug('Is persistent:', store.isPersistent) // true in browser, false in Node.js/Deno
|
|
73
|
-
|
|
74
|
-
// Save to localStorage
|
|
75
|
-
store.set('username', 'mario')
|
|
76
|
-
store.set('preferences', { theme: 'dark', language: 'en' })
|
|
77
|
-
store.set('lastLogin', Date.now())
|
|
78
|
-
|
|
79
|
-
// Read from localStorage
|
|
80
|
-
console.debug('Username:', store.get('username'))
|
|
81
|
-
console.debug('Preferences:', store.get('preferences'))
|
|
82
|
-
|
|
83
|
-
// Get storage size
|
|
84
|
-
console.debug('Storage size:', store.size(), 'kilobytes')
|
|
85
|
-
|
|
86
|
-
// ============================================
|
|
87
|
-
// SESSION - Temporary session storage
|
|
88
|
-
// ============================================
|
|
89
|
-
|
|
90
|
-
console.debug('\n=== Session (Temporary Storage) ===')
|
|
91
|
-
|
|
92
|
-
// Check persistence
|
|
93
|
-
console.debug('Is persistent:', session.isPersistent) // true in browser, false in Node.js/Deno
|
|
94
|
-
|
|
95
|
-
// Save session data (cleared when tab closes)
|
|
96
|
-
session.set('token', 'abc123xyz')
|
|
97
|
-
session.set('userId', 42)
|
|
98
|
-
|
|
99
|
-
// Read session data
|
|
100
|
-
console.debug('Token:', session.get('token'))
|
|
101
|
-
console.debug('User ID:', session.get('userId'))
|
|
102
|
-
|
|
103
|
-
// ============================================
|
|
104
|
-
// CLEANUP
|
|
105
|
-
// ============================================
|
|
106
|
-
|
|
107
|
-
// Clear specific items
|
|
108
|
-
store.remove('username')
|
|
109
|
-
session.remove('token')
|
|
110
|
-
|
|
111
|
-
// Clear all
|
|
112
|
-
store.removeAll()
|
|
113
|
-
session.removeAll()
|
|
114
|
-
|
|
115
|
-
console.debug('\nExample complete!')
|
|
1
|
+
/**
|
|
2
|
+
* Memorio Basic Example
|
|
3
|
+
*
|
|
4
|
+
* This example shows the fundamental features of Memorio:
|
|
5
|
+
* - State management
|
|
6
|
+
* - Store (localStorage)
|
|
7
|
+
* - Session storage
|
|
8
|
+
* - Platform detection
|
|
9
|
+
*
|
|
10
|
+
* Run: npx ts-node examples/basic.ts
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { memorio, state, store, session } from 'memorio'
|
|
14
|
+
|
|
15
|
+
// ============================================
|
|
16
|
+
// PLATFORM DETECTION
|
|
17
|
+
// ============================================
|
|
18
|
+
|
|
19
|
+
console.debug('=== Platform Detection ===')
|
|
20
|
+
console.debug('Memorio version:', memorio.version)
|
|
21
|
+
|
|
22
|
+
// Check platform
|
|
23
|
+
if (memorio.isBrowser()) {
|
|
24
|
+
console.debug('Platform: Browser')
|
|
25
|
+
} else if (memorio.isNode()) {
|
|
26
|
+
console.debug('Platform: Node.js')
|
|
27
|
+
} else if (memorio.isDeno()) {
|
|
28
|
+
console.debug('Platform: Deno')
|
|
29
|
+
} else if (memorio.isEdge()) {
|
|
30
|
+
console.debug('Platform: Edge Worker')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Get capabilities
|
|
34
|
+
const caps = memorio.getCapabilities()
|
|
35
|
+
console.debug('Capabilities:', {
|
|
36
|
+
platform: caps.platform,
|
|
37
|
+
hasLocalStorage: caps.hasLocalStorage,
|
|
38
|
+
hasSessionStorage: caps.hasSessionStorage,
|
|
39
|
+
hasIndexedDB: caps.hasIndexedDB
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// ============================================
|
|
43
|
+
// STATE - In-memory reactive state
|
|
44
|
+
// ============================================
|
|
45
|
+
|
|
46
|
+
console.debug('\n=== State Management ===')
|
|
47
|
+
|
|
48
|
+
// Set some state values
|
|
49
|
+
state.name = 'Mario'
|
|
50
|
+
state.age = 30
|
|
51
|
+
state.isActive = true
|
|
52
|
+
state.profile = {
|
|
53
|
+
email: 'mario@example.com',
|
|
54
|
+
avatar: 'https://example.com/mario.png'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Get state values
|
|
58
|
+
console.debug('Name:', state.name)
|
|
59
|
+
console.debug('Age:', state.age)
|
|
60
|
+
console.debug('Profile:', state.profile)
|
|
61
|
+
|
|
62
|
+
// List all states
|
|
63
|
+
console.debug('All states:', state.list)
|
|
64
|
+
|
|
65
|
+
// ============================================
|
|
66
|
+
// STORE - Persistent localStorage
|
|
67
|
+
// ============================================
|
|
68
|
+
|
|
69
|
+
console.debug('\n=== Store (Persistent Storage) ===')
|
|
70
|
+
|
|
71
|
+
// Check persistence
|
|
72
|
+
console.debug('Is persistent:', store.isPersistent) // true in browser, false in Node.js/Deno
|
|
73
|
+
|
|
74
|
+
// Save to localStorage
|
|
75
|
+
store.set('username', 'mario')
|
|
76
|
+
store.set('preferences', { theme: 'dark', language: 'en' })
|
|
77
|
+
store.set('lastLogin', Date.now())
|
|
78
|
+
|
|
79
|
+
// Read from localStorage
|
|
80
|
+
console.debug('Username:', store.get('username'))
|
|
81
|
+
console.debug('Preferences:', store.get('preferences'))
|
|
82
|
+
|
|
83
|
+
// Get storage size
|
|
84
|
+
console.debug('Storage size:', store.size(), 'kilobytes')
|
|
85
|
+
|
|
86
|
+
// ============================================
|
|
87
|
+
// SESSION - Temporary session storage
|
|
88
|
+
// ============================================
|
|
89
|
+
|
|
90
|
+
console.debug('\n=== Session (Temporary Storage) ===')
|
|
91
|
+
|
|
92
|
+
// Check persistence
|
|
93
|
+
console.debug('Is persistent:', session.isPersistent) // true in browser, false in Node.js/Deno
|
|
94
|
+
|
|
95
|
+
// Save session data (cleared when tab closes)
|
|
96
|
+
session.set('token', 'abc123xyz')
|
|
97
|
+
session.set('userId', 42)
|
|
98
|
+
|
|
99
|
+
// Read session data
|
|
100
|
+
console.debug('Token:', session.get('token'))
|
|
101
|
+
console.debug('User ID:', session.get('userId'))
|
|
102
|
+
|
|
103
|
+
// ============================================
|
|
104
|
+
// CLEANUP
|
|
105
|
+
// ============================================
|
|
106
|
+
|
|
107
|
+
// Clear specific items
|
|
108
|
+
store.remove('username')
|
|
109
|
+
session.remove('token')
|
|
110
|
+
|
|
111
|
+
// Clear all
|
|
112
|
+
store.removeAll()
|
|
113
|
+
session.removeAll()
|
|
114
|
+
|
|
115
|
+
console.debug('\nExample complete!')
|