memorio 4.8.0 → 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 +232 -527
- package/SUMMARY.md +1 -5
- package/index.cjs +84 -152
- package/index.js +44 -107
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/types/env.d.ts +9 -0
- package/types/exports.d.ts +50 -1
- package/types/memorio.d.ts +15 -11
- package/types/memory.d.ts +40 -2
- package/types/schema.d.ts +53 -53
- 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-ATTACHMENT.md +0 -95
- 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/SQLITE.md +0 -181
- package/markdown/STATE.md +0 -153
- package/markdown/STORE.md +0 -164
- package/markdown/SYNC.md +0 -170
- package/markdown/TYPED.md +0 -158
- package/markdown/USEOBSERVER.md +0 -259
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
|
-
```
|
package/markdown/IMPORT.md
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
# Classic `import` support
|
|
2
|
-
|
|
3
|
-
Memorio supports two equivalent styles: the original global side-effect import,
|
|
4
|
-
and the new named exports. Both share the same instances (one source of truth).
|
|
5
|
-
|
|
6
|
-
```typescript
|
|
7
|
-
// Global style (original)
|
|
8
|
-
import 'memorio'
|
|
9
|
-
state.user = { name: 'Sara' }
|
|
10
|
-
|
|
11
|
-
// Classic import style (new)
|
|
12
|
-
import { state } from 'memorio'
|
|
13
|
-
state.user = { name: 'Sara' }
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
`state` in both examples is the exact same Proxy object.
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
## Why two styles?
|
|
21
|
-
|
|
22
|
-
| Style | When to use |
|
|
23
|
-
|-------|-------------|
|
|
24
|
-
| `import 'memorio'` | Zero-config, global access everywhere, legacy scripts |
|
|
25
|
-
| `import { state } from 'memorio'` | Explicit dependencies, tree-shakeable bundles, TypeScript IntelliSense |
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
## ESM named imports
|
|
30
|
-
|
|
31
|
-
All modules are available as named exports:
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
import {
|
|
35
|
-
state,
|
|
36
|
-
store,
|
|
37
|
-
session,
|
|
38
|
-
cache,
|
|
39
|
-
idb,
|
|
40
|
-
observer,
|
|
41
|
-
useObserver,
|
|
42
|
-
dispatch,
|
|
43
|
-
message,
|
|
44
|
-
devtools,
|
|
45
|
-
logger
|
|
46
|
-
} from 'memorio'
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Platform helpers:
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
import {
|
|
53
|
-
isBrowser,
|
|
54
|
-
isNode,
|
|
55
|
-
isDeno,
|
|
56
|
-
isEdge,
|
|
57
|
-
getCapabilities,
|
|
58
|
-
createContext,
|
|
59
|
-
listContexts,
|
|
60
|
-
deleteContext
|
|
61
|
-
} from 'memorio'
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
Internal utilities (for tests/debug):
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
import internal, { propertyName } from 'memorio'
|
|
68
|
-
import { setContext, getContext } from 'memorio'
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Default export (the public `memorio` namespace):
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
import memorio from 'memorio'
|
|
75
|
-
memorio.help()
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
---
|
|
79
|
-
|
|
80
|
-
## CJS usage
|
|
81
|
-
|
|
82
|
-
```javascript
|
|
83
|
-
const { state, store, memorio } = require('memorio')
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
---
|
|
87
|
-
|
|
88
|
-
## React / useObserver
|
|
89
|
-
|
|
90
|
-
`useObserver` works the same way via named import:
|
|
91
|
-
|
|
92
|
-
```tsx
|
|
93
|
-
import { useObserver, state } from 'memorio'
|
|
94
|
-
|
|
95
|
-
function Counter() {
|
|
96
|
-
const [, forceUpdate] = useReducer(x => x + 1, 0)
|
|
97
|
-
|
|
98
|
-
useObserver(forceUpdate, [state.counter])
|
|
99
|
-
|
|
100
|
-
return <div>Count: {state.counter}</div>
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-
|
|
106
|
-
## Context isolation
|
|
107
|
-
|
|
108
|
-
```typescript
|
|
109
|
-
import { createContext, listContexts, deleteContext, isolate } from 'memorio'
|
|
110
|
-
|
|
111
|
-
const ctx = createContext('tenant-123')
|
|
112
|
-
ctx.state.user = { name: 'Isolated' }
|
|
113
|
-
ctx.store.set('settings', { theme: 'dark' })
|
|
114
|
-
|
|
115
|
-
listContexts() // ['tenant-123']
|
|
116
|
-
deleteContext('tenant-123')
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
121
|
-
## Same-instance guarantee
|
|
122
|
-
|
|
123
|
-
Named exports point to the same instances published on `globalThis` by
|
|
124
|
-
`core/global` at bootstrap. Mutating via named export mutates the global,
|
|
125
|
-
and vice versa.
|
|
126
|
-
|
|
127
|
-
```typescript
|
|
128
|
-
import { state } from 'memorio'
|
|
129
|
-
|
|
130
|
-
state.importedFlag = true
|
|
131
|
-
console.debug(globalThis.state.importedFlag) // true
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
## Migration from global-only
|
|
137
|
-
|
|
138
|
-
No code changes required. Existing `import 'memorio'` + `state.foo = 1`
|
|
139
|
-
continues to work unchanged. Named exports are additive.
|