memorio 2.8.0 → 2.9.1
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 +126 -60
- package/docs/README.md +432 -0
- package/docs/SUMMARY.md +26 -0
- package/docs/_config.yml +1 -0
- package/docs/markdown/CACHE.md +90 -0
- package/docs/markdown/CHANGELOG.md +184 -0
- package/docs/markdown/DEVTOOLS.md +122 -0
- package/docs/markdown/IDB.md +169 -0
- package/docs/markdown/LOGGER.md +147 -0
- package/docs/markdown/OBSERVER.md +180 -0
- package/docs/markdown/PLATFORM.md +260 -0
- package/docs/markdown/SECURITY.md +306 -0
- package/docs/markdown/SESSION.md +154 -0
- package/docs/markdown/STATE.md +150 -0
- package/docs/markdown/STORE.md +161 -0
- package/docs/markdown/USEOBSERVER.md +160 -0
- package/examples/basic.ts +1 -1
- package/examples/cache.ts +1 -1
- package/examples/idb.ts +1 -1
- package/examples/node-server.ts +1 -1
- package/examples/observer.ts +1 -1
- package/examples/platform.ts +1 -1
- package/examples/react-app.tsx +1 -1
- package/examples/session-advanced.ts +1 -1
- package/examples/state-advanced.ts +1 -1
- package/examples/store-advanced.ts +1 -1
- package/examples/{useObserver.ts → useObserver.tsx} +35 -35
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Changelog - Memorio
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## v2.7.0 (Current) - Cross-Platform & Security Update
|
|
8
|
+
|
|
9
|
+
### 🚀 New Features
|
|
10
|
+
|
|
11
|
+
#### 1. Platform Compatibility Layer
|
|
12
|
+
- **Auto-detection**: Automatically detects Browser, Node.js, Deno, Edge Workers
|
|
13
|
+
- **Polyfills**: Automatic fallback for server environments
|
|
14
|
+
- **New exports**:
|
|
15
|
+
- `memorio.isBrowser()` - Check if running in browser
|
|
16
|
+
- `memorio.isNode()` - Check if running in Node.js
|
|
17
|
+
- `memorio.isDeno()` - Check if running in Deno
|
|
18
|
+
- `memorio.isEdge()` - Check if running in Edge Worker
|
|
19
|
+
- `memorio.getCapabilities()` - Get platform capabilities
|
|
20
|
+
|
|
21
|
+
#### 2. Session Isolation
|
|
22
|
+
- **Unique Session IDs**: Each import/session gets unique ID via `crypto.randomUUID()`
|
|
23
|
+
- **Namespaced Storage**: Keys prefixed with session ID to prevent cross-contamination
|
|
24
|
+
- **Format**: `memorio_store_[session-uuid]_keyname`
|
|
25
|
+
|
|
26
|
+
#### 3. Context Isolation (Multi-Tenant Support)
|
|
27
|
+
- **New API**:
|
|
28
|
+
- `memorio.createContext(name?)` - Create isolated context
|
|
29
|
+
- `memorio.listContexts()` - List all contexts
|
|
30
|
+
- `memorio.deleteContext(id)` - Delete context
|
|
31
|
+
- `memorio.isolate(name?)` - Alias for createContext
|
|
32
|
+
|
|
33
|
+
#### 4. Persistence Detection
|
|
34
|
+
- **New Properties**:
|
|
35
|
+
- `store.isPersistent` - Check if using real localStorage
|
|
36
|
+
- `session.isPersistent` - Check if using real sessionStorage
|
|
37
|
+
|
|
38
|
+
### 🔒 Security Improvements
|
|
39
|
+
|
|
40
|
+
| Feature | Before v2.7.0 | After v2.7.0 |
|
|
41
|
+
|---------|---------------|--------------|
|
|
42
|
+
| Session ID | `Math.random()` | `crypto.randomUUID()` |
|
|
43
|
+
| Key Validation | None | Max 512 chars + whitelist |
|
|
44
|
+
| Server Isolation | None | Context system |
|
|
45
|
+
| Fallback Security | Basic | `crypto.getRandomValues()` |
|
|
46
|
+
|
|
47
|
+
### 📝 Documentation Updates
|
|
48
|
+
|
|
49
|
+
- **New Documents**:
|
|
50
|
+
- [`PLATFORM.md`](PLATFORM.md) - Platform compatibility guide
|
|
51
|
+
- [`SECURITY.md`](SECURITY.md) - Security documentation
|
|
52
|
+
|
|
53
|
+
- **Updated Documents**:
|
|
54
|
+
- All module docs now have platform labels (✅ Universal, 🖥️ Browser, ⚛️ React)
|
|
55
|
+
- Platform comparison tables added
|
|
56
|
+
- Client vs Server usage clarified
|
|
57
|
+
|
|
58
|
+
### 🔧 Examples
|
|
59
|
+
|
|
60
|
+
- **New Examples**:
|
|
61
|
+
- [`examples/platform.ts`](../examples/platform.ts) - Platform detection + Context demo
|
|
62
|
+
|
|
63
|
+
- **Updated Examples**:
|
|
64
|
+
- [`examples/basic.ts`](../examples/basic.ts) - Platform detection added
|
|
65
|
+
- [`examples/store-advanced.ts`](../examples/store-advanced.ts) - isPersistent check
|
|
66
|
+
- [`examples/session-advanced.ts`](../examples/session-advanced.ts) - isPersistent check
|
|
67
|
+
|
|
68
|
+
### ⚠️ Breaking Changes
|
|
69
|
+
|
|
70
|
+
| Change | Impact | Migration |
|
|
71
|
+
|--------|--------|-----------|
|
|
72
|
+
| Key validation | Low | Invalid keys now rejected with debug message |
|
|
73
|
+
| Storage key format | Low | Keys now prefixed with session ID |
|
|
74
|
+
|
|
75
|
+
### 🏗️ Internal Changes
|
|
76
|
+
|
|
77
|
+
- **New files**:
|
|
78
|
+
- `config/platform.ts` - Platform detection + Context system
|
|
79
|
+
|
|
80
|
+
- **Modified files**:
|
|
81
|
+
- `config/global.ts` - Added context exports
|
|
82
|
+
- `functions/store/index.ts` - Added validation + isPersistent
|
|
83
|
+
- `functions/session/index.ts` - Added validation + isPersistent
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## v2.6.x - Previous Versions
|
|
88
|
+
|
|
89
|
+
*(Documentation for versions prior to v2.7.0 is not included in this changelog)*
|
|
90
|
+
|
|
91
|
+
### Typical v2.6.x Features:
|
|
92
|
+
- State management with Proxy
|
|
93
|
+
- Observer pattern
|
|
94
|
+
- useObserver React hook
|
|
95
|
+
- Store (localStorage wrapper)
|
|
96
|
+
- Session (sessionStorage wrapper)
|
|
97
|
+
- Cache (in-memory)
|
|
98
|
+
- IDB (IndexedDB wrapper)
|
|
99
|
+
- DevTools
|
|
100
|
+
- Logger
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Migration Guide: v2.6.x → v2.7.0
|
|
105
|
+
|
|
106
|
+
### 1. Platform Detection (Optional)
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
// NEW: Check platform
|
|
110
|
+
if (memorio.isNode()) {
|
|
111
|
+
console.log('Running on server')
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### 2. Persistence Check (Optional)
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
// NEW: Check if data persists
|
|
119
|
+
if (!store.isPersistent) {
|
|
120
|
+
console.warn('Data will be lost on restart!')
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 3. Server-Side Isolation (Recommended for Node.js)
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
// NEW: Create isolated context per request
|
|
128
|
+
app.use((req, res, next) => {
|
|
129
|
+
req.ctx = memorio.createContext(`req-${req.id}`)
|
|
130
|
+
next()
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
app.get('/data', (req, res) => {
|
|
134
|
+
req.ctx.state.user = getUser()
|
|
135
|
+
// Each request has isolated state
|
|
136
|
+
})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 4. Key Validation (Automatic)
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
// Keys are now validated - invalid keys rejected
|
|
143
|
+
store.set('valid-key', 'value') // ✅ Works
|
|
144
|
+
store.set('key with spaces', 'x') // ❌ Rejected (debug message)
|
|
145
|
+
store.set('key>1000chars', 'x') // ❌ Rejected if >512 chars
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Comparison Table: v2.6.x vs v2.7.0
|
|
151
|
+
|
|
152
|
+
| Feature | v2.6.x | v2.7.0 |
|
|
153
|
+
|---------|--------|--------|
|
|
154
|
+
| **Platform Support** | | |
|
|
155
|
+
| Browser | ✅ | ✅ |
|
|
156
|
+
| Node.js | ⚠️ Partial | ✅ Full |
|
|
157
|
+
| Deno | ❌ | ✅ Full |
|
|
158
|
+
| Edge Workers | ❌ | ✅ |
|
|
159
|
+
| **Security** | | |
|
|
160
|
+
| Secure Random | ❌ | ✅ |
|
|
161
|
+
| Key Validation | ❌ | ✅ |
|
|
162
|
+
| Session Isolation | ❌ | ✅ |
|
|
163
|
+
| Context Isolation | ❌ | ✅ |
|
|
164
|
+
| **API** | | |
|
|
165
|
+
| isPersistent | ❌ | ✅ |
|
|
166
|
+
| createContext | ❌ | ✅ |
|
|
167
|
+
| Platform APIs | ❌ | ✅ |
|
|
168
|
+
| **Documentation** | | |
|
|
169
|
+
| Platform Guide | ❌ | ✅ |
|
|
170
|
+
| Security Docs | ❌ | ✅ |
|
|
171
|
+
| Platform Tables | ❌ | ✅ |
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Deprecations
|
|
176
|
+
|
|
177
|
+
| Feature | Status | Alternative |
|
|
178
|
+
|---------|--------|---------|
|
|
179
|
+
| `observer()` | ⚠️ Deprecated | Use `useObserver()` in React |
|
|
180
|
+
| Global state in Node.js | ⚡ Discouraged | Use `memorio.createContext()` |
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
*For older versions, please refer to the git history or npm package versions.*
|
|
@@ -0,0 +1,122 @@
|
|
|
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.log(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
|
+
```
|
|
@@ -0,0 +1,169 @@
|
|
|
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.log(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.log(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.log(`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
|
+
```
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Memorio Logger
|
|
2
|
+
|
|
3
|
+
> 🖥️ **Browser Only**: This feature is only available in browser console
|
|
4
|
+
|
|
5
|
+
Automatic logging middleware for tracking all state changes in Memorio.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The logger automatically tracks all operations (set, delete, clear) across all modules:
|
|
10
|
+
- State
|
|
11
|
+
- Store
|
|
12
|
+
- Session
|
|
13
|
+
- Cache
|
|
14
|
+
|
|
15
|
+
## Configuration
|
|
16
|
+
|
|
17
|
+
### configure(options)
|
|
18
|
+
|
|
19
|
+
Configure the logger.
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
memorio.logger.configure({
|
|
23
|
+
enabled: true, // Enable/disable logging
|
|
24
|
+
logToConsole: true, // Log to browser console
|
|
25
|
+
customHandler: function(entry) { ... }, // Custom handler
|
|
26
|
+
modules: ['state', 'store', 'session', 'cache'], // Modules to log
|
|
27
|
+
maxEntries: 1000 // Maximum log history size
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### enable()
|
|
32
|
+
|
|
33
|
+
Enable logging.
|
|
34
|
+
|
|
35
|
+
```javascript
|
|
36
|
+
memorio.logger.enable()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### disable()
|
|
40
|
+
|
|
41
|
+
Disable logging.
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
memorio.logger.disable()
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Methods
|
|
48
|
+
|
|
49
|
+
### getHistory()
|
|
50
|
+
|
|
51
|
+
Get all log entries.
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
const history = memorio.logger.getHistory()
|
|
55
|
+
// Returns array of LogEntry objects
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### getStats()
|
|
59
|
+
|
|
60
|
+
Get statistics about logged operations.
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
const stats = memorio.logger.getStats()
|
|
64
|
+
// Returns: { total, state, store, session, cache, set, get, delete, clear }
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### clearHistory()
|
|
68
|
+
|
|
69
|
+
Clear log history.
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
memorio.logger.clearHistory()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### exportLogs()
|
|
76
|
+
|
|
77
|
+
Export logs as JSON string.
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
const json = memorio.logger.exportLogs()
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Log Entry Structure
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
{
|
|
87
|
+
timestamp: "2026-02-18T12:00:00.000Z",
|
|
88
|
+
module: "state",
|
|
89
|
+
action: "set",
|
|
90
|
+
path: "user.name",
|
|
91
|
+
value: "John",
|
|
92
|
+
previousValue: "Jane"
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Examples
|
|
97
|
+
|
|
98
|
+
### Basic usage
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
// Logging is enabled by default
|
|
102
|
+
state.user = { name: 'John' }
|
|
103
|
+
// Console: [Memorio:STATE] set user → value: { name: 'John' }
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Get statistics
|
|
107
|
+
|
|
108
|
+
```javascript
|
|
109
|
+
const stats = memorio.logger.getStats()
|
|
110
|
+
console.log(stats)
|
|
111
|
+
// { total: 15, state: 5, store: 3, session: 2, cache: 5, set: 10, get: 0, delete: 3, clear: 2 }
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Disable specific modules
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
memorio.logger.configure({
|
|
118
|
+
modules: ['state'] // Only log state changes
|
|
119
|
+
})
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Custom handler
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
memorio.logger.configure({
|
|
126
|
+
customHandler: (entry) => {
|
|
127
|
+
// Send to analytics
|
|
128
|
+
analytics.track('memorio_change', entry)
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Export and analyze
|
|
134
|
+
|
|
135
|
+
```javascript
|
|
136
|
+
// Get all logs
|
|
137
|
+
const logs = memorio.logger.getHistory()
|
|
138
|
+
|
|
139
|
+
// Filter by module
|
|
140
|
+
const stateLogs = logs.filter(l => l.module === 'state')
|
|
141
|
+
|
|
142
|
+
// Filter by action
|
|
143
|
+
const setOperations = logs.filter(l => l.action === 'set')
|
|
144
|
+
|
|
145
|
+
// Export for debugging
|
|
146
|
+
console.log(memorio.logger.exportLogs())
|
|
147
|
+
```
|