memorio 4.7.3 → 4.9.5
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 +242 -331
- package/SUMMARY.md +3 -0
- package/index.cjs +87 -147
- package/index.d.ts +1 -0
- package/index.js +46 -100
- package/llms.txt +1 -1
- package/package.json +9 -3
- package/types/env.d.ts +9 -0
- package/types/exports.d.ts +52 -1
- package/types/memorio.d.ts +43 -10
- package/types/memory.d.ts +95 -0
- package/types/schema.d.ts +53 -53
- package/types/sqlite.d.ts +35 -0
- package/markdown/CACHE.md +0 -90
- package/markdown/CHANGELOG.md +0 -161
- package/markdown/DEVTOOLS.md +0 -122
- package/markdown/DISPATCH.md +0 -168
- package/markdown/HISTORY.md +0 -192
- package/markdown/IDB.md +0 -169
- package/markdown/IMPORT.md +0 -139
- package/markdown/INSPECT.md +0 -116
- package/markdown/LOGGER.md +0 -147
- package/markdown/MEMORY.md +0 -155
- package/markdown/OBSERVER.md +0 -200
- package/markdown/PLATFORM.md +0 -265
- package/markdown/SCHEMA.md +0 -169
- package/markdown/SECURITY.md +0 -323
- package/markdown/SESSION.md +0 -154
- package/markdown/STATE.md +0 -153
- package/markdown/STORE.md +0 -164
- package/markdown/TYPED.md +0 -158
- package/markdown/USEOBSERVER.md +0 -259
package/markdown/DEVTOOLS.md
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
# Memorio DevTools
|
|
2
|
-
|
|
3
|
-
> 🖥️ **Browser Only**: This feature is only available in browser console
|
|
4
|
-
|
|
5
|
-
Browser console debugging tools for inspecting and managing Memorio state.
|
|
6
|
-
|
|
7
|
-
## Quick Start
|
|
8
|
-
|
|
9
|
-
```javascript
|
|
10
|
-
// Load memorio first
|
|
11
|
-
import 'memorio'
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Available Methods
|
|
15
|
-
|
|
16
|
-
### inspect()
|
|
17
|
-
|
|
18
|
-
Inspect all Memorio modules in the console.
|
|
19
|
-
|
|
20
|
-
```javascript
|
|
21
|
-
memorio.devtools.inspect()
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### stats()
|
|
25
|
-
|
|
26
|
-
Get statistics about all modules.
|
|
27
|
-
|
|
28
|
-
```javascript
|
|
29
|
-
memorio.devtools.stats()
|
|
30
|
-
// Returns: { stateKeys, storeKeys, sessionKeys, cacheKeys, idbDatabases, lastUpdate }
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### clear(module)
|
|
34
|
-
|
|
35
|
-
Clear data from a specific module.
|
|
36
|
-
|
|
37
|
-
```javascript
|
|
38
|
-
memorio.devtools.clear('state')
|
|
39
|
-
memorio.devtools.clear('store')
|
|
40
|
-
memorio.devtools.clear('session')
|
|
41
|
-
memorio.devtools.clear('cache')
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### clearAll()
|
|
45
|
-
|
|
46
|
-
Clear all Memorio data.
|
|
47
|
-
|
|
48
|
-
```javascript
|
|
49
|
-
memorio.devtools.clearAll()
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### watch(module, path)
|
|
53
|
-
|
|
54
|
-
Watch a specific path for changes.
|
|
55
|
-
|
|
56
|
-
```javascript
|
|
57
|
-
memorio.devtools.watch('state', 'user.name')
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### exportData()
|
|
61
|
-
|
|
62
|
-
Export all data as JSON.
|
|
63
|
-
|
|
64
|
-
```javascript
|
|
65
|
-
const json = memorio.devtools.exportData()
|
|
66
|
-
console.debug(json)
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### importData(jsonString)
|
|
70
|
-
|
|
71
|
-
Import data from JSON.
|
|
72
|
-
|
|
73
|
-
```javascript
|
|
74
|
-
memorio.devtools.importData('{"state":{"key":"value"}}')
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### help()
|
|
78
|
-
|
|
79
|
-
Show help information.
|
|
80
|
-
|
|
81
|
-
```javascript
|
|
82
|
-
memorio.devtools.help()
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## Console Shortcuts
|
|
86
|
-
|
|
87
|
-
Memorio provides global shortcuts for quick access:
|
|
88
|
-
|
|
89
|
-
```javascript
|
|
90
|
-
$state // globalThis.state
|
|
91
|
-
$store // globalThis.store
|
|
92
|
-
$session // globalThis.session
|
|
93
|
-
$cache // globalThis.cache
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## Examples
|
|
97
|
-
|
|
98
|
-
### Inspect current state
|
|
99
|
-
|
|
100
|
-
```javascript
|
|
101
|
-
memorio.devtools.inspect()
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### Export and restore state
|
|
105
|
-
|
|
106
|
-
```javascript
|
|
107
|
-
// Export
|
|
108
|
-
const backup = memorio.devtools.exportData()
|
|
109
|
-
|
|
110
|
-
// Later... import
|
|
111
|
-
memorio.devtools.importData(backup)
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### Monitor changes
|
|
115
|
-
|
|
116
|
-
```javascript
|
|
117
|
-
// Watch a specific path
|
|
118
|
-
memorio.devtools.watch('state', 'counter')
|
|
119
|
-
|
|
120
|
-
// Now changes will be logged to console
|
|
121
|
-
state.counter = 42 // Console shows: 👁 Change: state.counter = 42
|
|
122
|
-
```
|
package/markdown/DISPATCH.md
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
# Dispatch - Memorio
|
|
2
|
-
|
|
3
|
-
> ⚛️ **Vanilla JS**: This is for non-React applications. For React, use [`useObserver`](USEOBSERVER.md).
|
|
4
|
-
|
|
5
|
-
`memorio.dispatch` is an event system for vanilla JavaScript applications. It enables pub/sub patterns without React hooks.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install memorio
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
```javascript
|
|
14
|
-
import 'memorio';
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## Quick Examples
|
|
20
|
-
|
|
21
|
-
### Example 1: Basic Event Listening
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
// Listen for an event
|
|
25
|
-
memorio.dispatch.listen('my:event', (event) => {
|
|
26
|
-
console.debug('Event triggered:', event.detail);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// Trigger the event
|
|
30
|
-
memorio.dispatch.set('my:event', { detail: { data: 'Hello World' } });
|
|
31
|
-
// Output: "Event triggered: { data: 'Hello World' }"
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Example 2: State Reactivity (Vanilla JS)
|
|
35
|
-
|
|
36
|
-
```javascript
|
|
37
|
-
// React to state changes without React
|
|
38
|
-
memorio.dispatch.listen('state.counter', (event) => {
|
|
39
|
-
console.debug('Counter is now:', event.detail);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// Update state
|
|
43
|
-
state.counter = 1;
|
|
44
|
-
// Output: "Counter is now: 1"
|
|
45
|
-
|
|
46
|
-
state.counter = 5;
|
|
47
|
-
// Output: "Counter is now: 5"
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### Example 3: Remove Listener
|
|
51
|
-
|
|
52
|
-
```javascript
|
|
53
|
-
// Remove a specific event listener
|
|
54
|
-
memorio.dispatch.remove('my:event');
|
|
55
|
-
|
|
56
|
-
// Or remove all listeners for state changes
|
|
57
|
-
memorio.dispatch.remove('state.user');
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
---
|
|
61
|
-
|
|
62
|
-
## API Reference
|
|
63
|
-
|
|
64
|
-
### memorio.dispatch.set(name, value)
|
|
65
|
-
|
|
66
|
-
Dispatches a custom event with the specified name and value.
|
|
67
|
-
|
|
68
|
-
| Parameter | Type | Description |
|
|
69
|
-
|-----------|------|-------------|
|
|
70
|
-
| `name` | `string` | Event name (e.g., `'my:event'`, `'state.counter'`) |
|
|
71
|
-
| `value` | `object` | Object with `detail` property (default: `{}`) |
|
|
72
|
-
|
|
73
|
-
```javascript
|
|
74
|
-
memorio.dispatch.set('custom:event', { detail: { data: 'value' } });
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### memorio.dispatch.listen(name, callback)
|
|
78
|
-
|
|
79
|
-
Listens for the specified event and executes the callback when triggered.
|
|
80
|
-
|
|
81
|
-
| Parameter | Type | Description |
|
|
82
|
-
|-----------|------|-------------|
|
|
83
|
-
| `name` | `string` | Event name to listen for |
|
|
84
|
-
| `callback` | `function` | Function called with the event object |
|
|
85
|
-
|
|
86
|
-
```javascript
|
|
87
|
-
memorio.dispatch.listen('state.user', (event) => {
|
|
88
|
-
console.debug('User changed:', event.detail);
|
|
89
|
-
});
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### memorio.dispatch.remove(name)
|
|
93
|
-
|
|
94
|
-
Removes the event listener for the specified event name.
|
|
95
|
-
|
|
96
|
-
| Parameter | Type | Description |
|
|
97
|
-
|-----------|------|-------------|
|
|
98
|
-
| `name` | `string` | Event name to stop listening |
|
|
99
|
-
|
|
100
|
-
```javascript
|
|
101
|
-
memorio.dispatch.remove('state.counter');
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-
|
|
106
|
-
## Common Patterns
|
|
107
|
-
|
|
108
|
-
### Form Validation
|
|
109
|
-
|
|
110
|
-
```javascript
|
|
111
|
-
memorio.dispatch.listen('state.form.email', (event) => {
|
|
112
|
-
const email = event.detail;
|
|
113
|
-
const isValid = email.includes('@');
|
|
114
|
-
state.form.isValid = isValid;
|
|
115
|
-
});
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### Analytics Tracking
|
|
119
|
-
|
|
120
|
-
```javascript
|
|
121
|
-
memorio.dispatch.listen('state.page', (event) => {
|
|
122
|
-
const page = event.detail;
|
|
123
|
-
analytics.track('page_view', { page });
|
|
124
|
-
});
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### Auto-save
|
|
128
|
-
|
|
129
|
-
```javascript
|
|
130
|
-
memorio.dispatch.listen('state.draft', (event) => {
|
|
131
|
-
const content = event.detail;
|
|
132
|
-
store.set('autosave', content);
|
|
133
|
-
});
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
### Multiple Listeners
|
|
137
|
-
|
|
138
|
-
```javascript
|
|
139
|
-
// Listen for multiple state changes
|
|
140
|
-
memorio.dispatch.listen('state.user', (e) => console.log('User:', e.detail));
|
|
141
|
-
memorio.dispatch.listen('state.settings', (e) => console.log('Settings:', e.detail));
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
---
|
|
145
|
-
|
|
146
|
-
## Migration from observer()
|
|
147
|
-
|
|
148
|
-
The `observer()` Replace it with `memorio.dispatch.listen()`:
|
|
149
|
-
|
|
150
|
-
```javascript
|
|
151
|
-
observer('state.counter', (newValue) => {
|
|
152
|
-
console.debug('Counter:', newValue);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
// NEW (recommended for vanilla JS)
|
|
156
|
-
memorio.dispatch.listen('state.counter', (event) => {
|
|
157
|
-
console.debug('Counter:', event.detail);
|
|
158
|
-
});
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
---
|
|
162
|
-
|
|
163
|
-
## Best Practices
|
|
164
|
-
|
|
165
|
-
1. Use specific event names: `'state.user.name'` not `'state'`
|
|
166
|
-
2. Clean up listeners when no longer needed with `memorio.dispatch.remove()`
|
|
167
|
-
3. Use `event.detail` to access the value
|
|
168
|
-
4. For React applications, use [`useObserver`](USEOBSERVER.md) instead
|
package/markdown/HISTORY.md
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
# History, Undo / Redo, Snapshot, Diff, Trace - Memorio
|
|
2
|
-
|
|
3
|
-
> ✅ **Universal**: Works in Browser, Node.js, Deno, and Edge Workers
|
|
4
|
-
|
|
5
|
-
Memorio provides a lightweight time-travel system for `state` mutations: snapshots, diffs, undo/redo, and a full mutation trace log.
|
|
6
|
-
|
|
7
|
-
History tracking is **opt-in** — it is disabled by default to avoid overhead. Enable it when you need undo/redo or trace capabilities.
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## Enable History
|
|
12
|
-
|
|
13
|
-
```javascript
|
|
14
|
-
import 'memorio'
|
|
15
|
-
|
|
16
|
-
memorio.enableHistory() // enable tracking
|
|
17
|
-
// ... mutate state ...
|
|
18
|
-
memorio.state.user = { name: 'Sara' }
|
|
19
|
-
memorio.state.counter = 42
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
> Without `enableHistory()`, mutations are not recorded and `undo()`/`redo()`/`trace()` return empty results.
|
|
23
|
-
|
|
24
|
-
---
|
|
25
|
-
|
|
26
|
-
## Snapshot & Diff
|
|
27
|
-
|
|
28
|
-
Snapshot captures the entire `state` tree at a point in time. Diff compares a snapshot against current state to see what changed.
|
|
29
|
-
|
|
30
|
-
```javascript
|
|
31
|
-
// Enable history (snapshots work regardless, but trace/undo need it)
|
|
32
|
-
memorio.enableHistory()
|
|
33
|
-
|
|
34
|
-
// Take a snapshot
|
|
35
|
-
state.user = { name: 'Sara', age: 30 }
|
|
36
|
-
const snap = memorio.snapshot()
|
|
37
|
-
|
|
38
|
-
// Make changes
|
|
39
|
-
state.user.name = 'Luigi'
|
|
40
|
-
state.counter = 100
|
|
41
|
-
state.items = ['a', 'b']
|
|
42
|
-
|
|
43
|
-
// Diff against the snapshot
|
|
44
|
-
const changes = memorio.diff(snap)
|
|
45
|
-
console.debug(changes)
|
|
46
|
-
// [
|
|
47
|
-
// { path: 'user.name', oldValue: 'Sara', newValue: 'Luigi' },
|
|
48
|
-
// { path: 'counter', oldValue: undefined, newValue: 100 },
|
|
49
|
-
// { path: 'items', oldValue: undefined, newValue: ['a', 'b'] }
|
|
50
|
-
// ]
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
This is essential for AI agents: take a snapshot, make changes, inspect the diff, and decide whether to commit or rollback.
|
|
54
|
-
|
|
55
|
-
---
|
|
56
|
-
|
|
57
|
-
## Undo / Redo
|
|
58
|
-
|
|
59
|
-
```javascript
|
|
60
|
-
state.user = { name: 'Sara' }
|
|
61
|
-
state.counter = 100
|
|
62
|
-
state.items = ['a', 'b']
|
|
63
|
-
|
|
64
|
-
memorio.undo() // removes state.items
|
|
65
|
-
memorio.undo() // counter → undefined
|
|
66
|
-
memorio.redo() // counter → 100 again
|
|
67
|
-
|
|
68
|
-
memorio.canUndo() // true
|
|
69
|
-
memorio.canRedo() // true (after above undo + redo cycle)
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
- `undo()`: Restores the previous state by inverting the most recent mutation.
|
|
73
|
-
- `redo()`: Re-applies the most recently undone mutation.
|
|
74
|
-
- `canUndo()` / `canRedo()`: Check availability before calling.
|
|
75
|
-
|
|
76
|
-
### Max history depth
|
|
77
|
-
|
|
78
|
-
```javascript
|
|
79
|
-
memorio.setMaxHistory(50) // keep at most 50 mutations per stack (default: 100)
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
---
|
|
83
|
-
|
|
84
|
-
## Rollback (full state restore)
|
|
85
|
-
|
|
86
|
-
Unlike undo (which works one step at a time), `rollback` replaces the entire state from a snapshot:
|
|
87
|
-
|
|
88
|
-
```javascript
|
|
89
|
-
const snap = memorio.snapshot()
|
|
90
|
-
|
|
91
|
-
state.experiment = { result: 'failed' }
|
|
92
|
-
state.counter = 999
|
|
93
|
-
|
|
94
|
-
// Discard everything and restore to snapshot
|
|
95
|
-
memorio.rollback(snap)
|
|
96
|
-
// state.experiment is now gone
|
|
97
|
-
// state.counter is back to its snapshot value
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
## Trace (mutation log)
|
|
103
|
-
|
|
104
|
-
The trace log records every mutation with timestamp, path, action, and before/after values:
|
|
105
|
-
|
|
106
|
-
```javascript
|
|
107
|
-
memorio.enableHistory()
|
|
108
|
-
|
|
109
|
-
state.user.name = 'Sara'
|
|
110
|
-
state.counter = 1
|
|
111
|
-
state.counter = 2
|
|
112
|
-
|
|
113
|
-
const log = memorio.trace()
|
|
114
|
-
console.debug(log)
|
|
115
|
-
// [
|
|
116
|
-
// { path: 'user.name', action: 'set', newValue: 'Sara', previousValue: undefined, timestamp: 1725... },
|
|
117
|
-
// { path: 'counter', action: 'set', newValue: 1, previousValue: undefined, timestamp: 1725... },
|
|
118
|
-
// { path: 'counter', action: 'set', newValue: 2, previousValue: 1, timestamp: 1725... }
|
|
119
|
-
// ]
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
This is useful for:
|
|
123
|
-
- **AI debugging**: inspect what changed and when
|
|
124
|
-
- **Event sourcing**: export the log and replay state from scratch
|
|
125
|
-
- **Audit trails**: log all mutations for compliance
|
|
126
|
-
|
|
127
|
-
### Export / import trace
|
|
128
|
-
|
|
129
|
-
```javascript
|
|
130
|
-
const log = memorio.trace()
|
|
131
|
-
localStorage.setItem('memorio-trace', JSON.stringify(log))
|
|
132
|
-
|
|
133
|
-
// Later, replay:
|
|
134
|
-
const saved = JSON.parse(localStorage.getItem('memorio-trace'))
|
|
135
|
-
for (const record of saved) {
|
|
136
|
-
if (record.action === 'set') {
|
|
137
|
-
state[record.path] = record.newValue
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
---
|
|
143
|
-
|
|
144
|
-
## Clear History
|
|
145
|
-
|
|
146
|
-
```javascript
|
|
147
|
-
memorio.clearHistory() // wipe undo/redo stacks + trace log
|
|
148
|
-
memorio.clearRedo() // clear only the redo stack (undo stack preserved)
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
> `clearHistory()` does NOT reset the current `state` — only the history tracking data.
|
|
152
|
-
|
|
153
|
-
---
|
|
154
|
-
|
|
155
|
-
## Full API
|
|
156
|
-
|
|
157
|
-
| Method | Parameters | Returns | Description |
|
|
158
|
-
|--------|-----------|---------|-------------|
|
|
159
|
-
| `memorio.snapshot()` | none | `Record<string, any>` | Deep clone of current state |
|
|
160
|
-
| `memorio.diff(snap)` | `snap` | `DiffEntry[]` | Changed paths with old/new values |
|
|
161
|
-
| `memorio.undo()` | none | `MutationRecord \| undefined` | Undo last mutation |
|
|
162
|
-
| `memorio.redo()` | none | `MutationRecord \| undefined` | Redo last undone mutation |
|
|
163
|
-
| `memorio.canUndo()` | none | `boolean` | Whether undo is available |
|
|
164
|
-
| `memorio.canRedo()` | none | `boolean` | Whether redo is available |
|
|
165
|
-
| `memorio.rollback(snap)` | `snap` | `void` | Restore full state from snapshot |
|
|
166
|
-
| `memorio.trace()` | none | `MutationRecord[]` | List of all recorded mutations |
|
|
167
|
-
| `memorio.enableHistory(enabled?)` | `boolean` | `void` | Enable/disable tracking |
|
|
168
|
-
| `memorio.clearHistory()` | none | `void` | Clear all history stacks |
|
|
169
|
-
| `memorio.clearRedo()` | none | `void` | Clear only redo stack |
|
|
170
|
-
| `memorio.setMaxHistory(max)` | `number` | `void` | Set max stack depth |
|
|
171
|
-
| `memorio.getMaxHistory()` | none | `number` | Get current max depth |
|
|
172
|
-
|
|
173
|
-
---
|
|
174
|
-
|
|
175
|
-
## How It Works
|
|
176
|
-
|
|
177
|
-
1. When `historyEnabled` is true, the state proxy's callback (`buildProxy` callback) fires on every `set`/`delete` trap, recording a `MutationRecord` with path, action, oldValue, newValue, and timestamp.
|
|
178
|
-
2. Records are pushed to both a trace log (`mutations`) and an undo stack.
|
|
179
|
-
3. Any new mutation clears the redo stack.
|
|
180
|
-
4. `undo()` pops from the undo stack, pushes to the redo stack, and applies the inverse operation (restoring the previous value, or deleting if it was new).
|
|
181
|
-
5. `redo()` pops from the redo stack, pushes back to the undo stack, and re-applies the original mutation.
|
|
182
|
-
6. During undo/redo, history tracking is temporarily disabled to prevent recursive recording.
|
|
183
|
-
7. `diff()` does a recursive key-by-key comparison between the snapshot and current `deepRaw(state)`.
|
|
184
|
-
|
|
185
|
-
---
|
|
186
|
-
|
|
187
|
-
## Best Practices
|
|
188
|
-
|
|
189
|
-
1. **Always snapshot before AI experimentation** — `const snap = memorio.snapshot()` gives you a safe rollback point.
|
|
190
|
-
2. **Call `diff()` before `rollback()`** — inspect what changed first; sometimes you only need to revert one key.
|
|
191
|
-
3. **Keep `maxHistory` reasonable** — the default (100) is fine for most apps. Lower it for memory-constrained environments.
|
|
192
|
-
4. **Don't rely on trace for sensitive data** — the trace log records *all* values written, including tokens/PII. Clear it or disable tracing in production paths.
|
package/markdown/IDB.md
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
# IDB - Memorio
|
|
2
|
-
|
|
3
|
-
> 🖥️ **Browser Only**: Requires IndexedDB (not available in Node.js/Deno)
|
|
4
|
-
|
|
5
|
-
IDB provides access to browser IndexedDB for large data storage. Unlike localStorage, IDB can store large amounts of structured data.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install memorio
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
```javascript
|
|
14
|
-
import 'memorio';
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## Quick Examples
|
|
20
|
-
|
|
21
|
-
### Example 1: Basic Usage
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
// Create a database
|
|
25
|
-
idb.db.create('myApp');
|
|
26
|
-
|
|
27
|
-
// Add data
|
|
28
|
-
idb.data.set('myApp', 'users', { id: 1, name: 'Mario' });
|
|
29
|
-
|
|
30
|
-
// Get data
|
|
31
|
-
const user = idb.data.get('myApp', 'users', 1);
|
|
32
|
-
console.debug(user.name); // "Mario"
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Example 2: Intermediate
|
|
36
|
-
|
|
37
|
-
```javascript
|
|
38
|
-
// Create database with tables
|
|
39
|
-
idb.db.create('store');
|
|
40
|
-
idb.table.create('store', 'products');
|
|
41
|
-
|
|
42
|
-
// Add multiple records
|
|
43
|
-
idb.data.set('store', 'products', { id: 1, name: 'Apple', price: 1.5 });
|
|
44
|
-
idb.data.set('store', 'products', { id: 2, name: 'Banana', price: 0.8 });
|
|
45
|
-
|
|
46
|
-
// List databases
|
|
47
|
-
const databases = idb.db.list();
|
|
48
|
-
console.debug(databases); // ['myApp', 'store']
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Example 3: Advanced
|
|
52
|
-
|
|
53
|
-
```javascript
|
|
54
|
-
// Check database support
|
|
55
|
-
if (idb.db.support()) {
|
|
56
|
-
// Use IDB
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Get database info
|
|
60
|
-
const version = idb.db.version('store');
|
|
61
|
-
const size = idb.db.size('store');
|
|
62
|
-
|
|
63
|
-
// Delete database
|
|
64
|
-
idb.db.delete('store');
|
|
65
|
-
|
|
66
|
-
// Handle quota
|
|
67
|
-
const quota = idb.db.quota();
|
|
68
|
-
console.debug(`Using ${quota.used} of ${quota.total} bytes`);
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
---
|
|
72
|
-
|
|
73
|
-
## API Reference
|
|
74
|
-
|
|
75
|
-
### Database Methods
|
|
76
|
-
|
|
77
|
-
| Method | Parameters | Returns | Description |
|
|
78
|
-
|--------|------------|---------|-------------|
|
|
79
|
-
| `idb.db.create(name)` | `name: string` | `void` | Create database |
|
|
80
|
-
| `idb.db.delete(name)` | `name: string` | `void` | Delete database |
|
|
81
|
-
| `idb.db.list()` | none | `string[]` | List all databases |
|
|
82
|
-
| `idb.db.exist(name)` | `name: string` | `boolean` | Check if exists |
|
|
83
|
-
| `idb.db.size(name)` | `name: string` | `number` | Get database size |
|
|
84
|
-
| `idb.db.version(name)` | `name: string` | `number` | Get version |
|
|
85
|
-
| `idb.db.support()` | none | `boolean` | Check browser support |
|
|
86
|
-
| `idb.db.quota()` | none | `object` | Get storage quota |
|
|
87
|
-
|
|
88
|
-
### Table Methods
|
|
89
|
-
|
|
90
|
-
| Method | Parameters | Returns | Description |
|
|
91
|
-
|--------|------------|---------|-------------|
|
|
92
|
-
| `idb.table.create(db, table)` | `db: string, table: string` | `void` | Create table |
|
|
93
|
-
| `idb.table.size(db, table)` | `db: string, table: string` | `number` | Get table size |
|
|
94
|
-
|
|
95
|
-
### Data Methods
|
|
96
|
-
|
|
97
|
-
| Method | Parameters | Returns | Description |
|
|
98
|
-
|--------|------------|---------|-------------|
|
|
99
|
-
| `idb.data.get(db, table, id)` | `db, table, id` | `any` | Get single record |
|
|
100
|
-
| `idb.data.set(db, table, data)` | `db, table, data` | `void` | Set record |
|
|
101
|
-
| `idb.data.delete(db, table, id)` | `db, table, id` | `void` | Delete record |
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
## Data Structure
|
|
106
|
-
|
|
107
|
-
Each record needs an `id` field:
|
|
108
|
-
|
|
109
|
-
```javascript
|
|
110
|
-
idb.data.set('myDB', 'users', {
|
|
111
|
-
id: 1, // Required!
|
|
112
|
-
name: 'Mario',
|
|
113
|
-
email: 'm@test.com'
|
|
114
|
-
});
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
---
|
|
118
|
-
|
|
119
|
-
## Platform Support
|
|
120
|
-
|
|
121
|
-
| Platform | Support | Notes |
|
|
122
|
-
|----------|---------|-------|
|
|
123
|
-
| Browser | ✅ Full | Full IndexedDB support |
|
|
124
|
-
| Edge Worker | ⚠️ Limited | May not be available in all workers |
|
|
125
|
-
| Node.js | ❌ Not available | Use store or session instead |
|
|
126
|
-
| Deno | ❌ Not available | Use store or session instead |
|
|
127
|
-
|
|
128
|
-
---
|
|
129
|
-
|
|
130
|
-
## Storage Limits
|
|
131
|
-
|
|
132
|
-
- **Desktop browsers**: 50+ MB (often unlimited)
|
|
133
|
-
- **Mobile browsers**: 50-100 MB
|
|
134
|
-
- **More than localStorage**: Much higher limits
|
|
135
|
-
|
|
136
|
-
---
|
|
137
|
-
|
|
138
|
-
## Best Practices
|
|
139
|
-
|
|
140
|
-
1. Always include `id` in records
|
|
141
|
-
2. Use for large data: images, caches, offline data
|
|
142
|
-
3. Check support: `idb.db.support()`
|
|
143
|
-
4. Clean up: `idb.db.delete('tempDB')`
|
|
144
|
-
|
|
145
|
-
---
|
|
146
|
-
|
|
147
|
-
## Use Cases
|
|
148
|
-
|
|
149
|
-
### Offline Data
|
|
150
|
-
|
|
151
|
-
```javascript
|
|
152
|
-
// Cache API response
|
|
153
|
-
idb.data.set('cache', 'apiResponse', {
|
|
154
|
-
id: 'users',
|
|
155
|
-
data: usersArray,
|
|
156
|
-
timestamp: Date.now()
|
|
157
|
-
});
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
### Large User Data
|
|
161
|
-
|
|
162
|
-
```javascript
|
|
163
|
-
// Store user-generated content
|
|
164
|
-
idb.data.set('app', 'uploads', {
|
|
165
|
-
id: Date.now(),
|
|
166
|
-
file: fileData,
|
|
167
|
-
userId: currentUser.id
|
|
168
|
-
});
|
|
169
|
-
```
|