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
package/README.md
CHANGED
|
@@ -27,11 +27,14 @@
|
|
|
27
27
|
- [Quick Start](#quick-start)
|
|
28
28
|
- [API Reference](#api-reference)
|
|
29
29
|
- [State Management](#state-management)
|
|
30
|
+
- [Observer](#observer)
|
|
30
31
|
- [useObserver](#useobserver)
|
|
31
32
|
- [Store](#store)
|
|
32
33
|
- [Session](#session)
|
|
33
34
|
- [Cache](#cache)
|
|
34
35
|
- [idb](#idb)
|
|
36
|
+
- [DevTools](#devtools)
|
|
37
|
+
- [Logger](#logger)
|
|
35
38
|
- [Testing](#testing)
|
|
36
39
|
- [Security](#security)
|
|
37
40
|
- [License](#license)
|
|
@@ -49,18 +52,8 @@
|
|
|
49
52
|
- **Cross-platform**: Works in Browser, Node.js, Deno, and Edge Workers
|
|
50
53
|
- **Session Isolation**: Each session/request gets isolated state namespace
|
|
51
54
|
- **Context System**: Multi-tenant server-side isolation with `memorio.createContext()`
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
For **enterprise-level applications** requiring advanced state management, we recommend using **[@biglogic/rgs](https://npmjs.com/package/@biglogic/rgs)** instead of Memorio.
|
|
56
|
-
|
|
57
|
-
RGS provides:
|
|
58
|
-
- Enhanced scalability for large applications
|
|
59
|
-
- Advanced middleware support
|
|
60
|
-
- Enterprise-grade security features
|
|
61
|
-
- Professional support and maintenance
|
|
62
|
-
|
|
63
|
-
Memorio is ideal for small to medium projects, prototypes, and learning purposes.
|
|
55
|
+
- **DevTools**: Browser console debugging tools
|
|
56
|
+
- **Logger**: Automatic logging of state changes
|
|
64
57
|
|
|
65
58
|
## Installation
|
|
66
59
|
|
|
@@ -76,16 +69,18 @@ npm i -D memorio
|
|
|
76
69
|
- Cache operations tests
|
|
77
70
|
- Observer pattern tests
|
|
78
71
|
- useObserver pattern tests
|
|
72
|
+
- DevTools tests
|
|
73
|
+
- Logger tests
|
|
79
74
|
|
|
80
|
-
Total:
|
|
75
|
+
Total: 71 tests passed across 8 test suites
|
|
81
76
|
|
|
82
77
|
## Quick Start
|
|
83
78
|
|
|
84
79
|
```javascript
|
|
85
80
|
/*
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
IMPORTANT!
|
|
82
|
+
Add import only at first start of your SPA. Became global!.
|
|
83
|
+
You don't need to import any time you need to use memorio
|
|
89
84
|
*/
|
|
90
85
|
|
|
91
86
|
import 'memorio';
|
|
@@ -97,20 +92,11 @@ state.name = "john";
|
|
|
97
92
|
state.user = { name: 'John', age: 30 };
|
|
98
93
|
state.hours = [2,3,10,23]
|
|
99
94
|
|
|
100
|
-
//
|
|
101
|
-
// Example: if you change the state.counter you get a console.log
|
|
102
|
-
observer(
|
|
103
|
-
'state.counter',
|
|
104
|
-
(newValue, oldValue) => {
|
|
105
|
-
console.log(`Counter changed from ${oldValue} to ${newValue}`);
|
|
106
|
-
}
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
// useObserver Pattern
|
|
95
|
+
// useObserver Pattern for react app
|
|
110
96
|
// Example: if you change the state.counter you get a console.log
|
|
111
97
|
useObserver(
|
|
112
|
-
(
|
|
113
|
-
console.log(`Counter changed
|
|
98
|
+
() => {
|
|
99
|
+
console.log(`Counter changed to ${state.counter}`);
|
|
114
100
|
},
|
|
115
101
|
[state.counter]
|
|
116
102
|
);
|
|
@@ -123,6 +109,12 @@ const preferences = store.get('preferences');
|
|
|
123
109
|
// Session Storage
|
|
124
110
|
session.set('token', 'user-jwt-token');
|
|
125
111
|
const token = session.get('token');
|
|
112
|
+
|
|
113
|
+
// DevTools
|
|
114
|
+
memorio.devtools.inspect();
|
|
115
|
+
|
|
116
|
+
// Logger
|
|
117
|
+
memorio.logger.configure({ enabled: true, logToConsole: true })
|
|
126
118
|
```
|
|
127
119
|
|
|
128
120
|
## API Reference
|
|
@@ -146,44 +138,40 @@ state.remove('user');
|
|
|
146
138
|
|
|
147
139
|
// Clearing all states
|
|
148
140
|
state.removeAll();
|
|
149
|
-
|
|
150
141
|
```
|
|
151
142
|
|
|
152
|
-
###
|
|
153
|
-
|
|
154
|
-
> ⚠️ **Deprecated**: For React applications, use [`useObserver`](#useobserver-pattern) instead. The `observer` function is kept for non-React contexts.
|
|
155
|
-
|
|
156
|
-
## useObserver
|
|
143
|
+
### useObserver
|
|
157
144
|
|
|
158
145
|
useObserver is a React hook for observing Memorio state changes with auto-discovery:
|
|
159
146
|
|
|
160
147
|
```js
|
|
161
|
-
|
|
162
148
|
// Basic useObserver - array syntax with state path
|
|
163
149
|
useObserver(
|
|
164
|
-
(
|
|
165
|
-
console.log('User updated:',
|
|
150
|
+
() => {
|
|
151
|
+
console.log('User updated:', state.user);
|
|
166
152
|
},
|
|
167
153
|
[state.user]
|
|
168
154
|
);
|
|
169
155
|
|
|
170
156
|
// Multiple states
|
|
171
157
|
useObserver(
|
|
172
|
-
(
|
|
173
|
-
console.log('
|
|
158
|
+
() => {
|
|
159
|
+
console.log('States changed:', state.user, state.counter, state.settings);
|
|
174
160
|
},
|
|
175
161
|
[state.user, state.counter, state.settings]
|
|
176
162
|
);
|
|
177
163
|
|
|
164
|
+
// With options
|
|
165
|
+
useObserver(
|
|
166
|
+
() => {
|
|
167
|
+
console.log('Value changed');
|
|
168
|
+
},
|
|
169
|
+
[state.value],
|
|
170
|
+
{ immediate: true }
|
|
171
|
+
);
|
|
178
172
|
```
|
|
179
173
|
|
|
180
|
-
|
|
181
|
-
1. Uses **array syntax** `[state.property]` instead of string path `'state.property'`
|
|
182
|
-
2. Automatically cleans up on component unmount
|
|
183
|
-
3. Works only inside React components
|
|
184
|
-
4. Callback receives `(newValue, oldValue)` parameters
|
|
185
|
-
|
|
186
|
-
## Store
|
|
174
|
+
### Store
|
|
187
175
|
|
|
188
176
|
Persistent storage for your application:
|
|
189
177
|
|
|
@@ -202,9 +190,16 @@ const size = store.size();
|
|
|
202
190
|
|
|
203
191
|
// Clearing store
|
|
204
192
|
store.removeAll();
|
|
193
|
+
|
|
194
|
+
// Check if using persistent storage
|
|
195
|
+
if (store.isPersistent) {
|
|
196
|
+
console.log('Using real localStorage');
|
|
197
|
+
} else {
|
|
198
|
+
console.log('Using memory fallback (server environment)');
|
|
199
|
+
}
|
|
205
200
|
```
|
|
206
201
|
|
|
207
|
-
|
|
202
|
+
### Session
|
|
208
203
|
|
|
209
204
|
Temporary storage that persists during page sessions:
|
|
210
205
|
|
|
@@ -228,9 +223,16 @@ session.remove('userSession');
|
|
|
228
223
|
|
|
229
224
|
// Clearing all session data
|
|
230
225
|
session.removeAll();
|
|
226
|
+
|
|
227
|
+
// Check if using persistent storage
|
|
228
|
+
if (session.isPersistent) {
|
|
229
|
+
console.log('Using real sessionStorage');
|
|
230
|
+
} else {
|
|
231
|
+
console.log('Using memory fallback (server environment)');
|
|
232
|
+
}
|
|
231
233
|
```
|
|
232
234
|
|
|
233
|
-
|
|
235
|
+
### Cache
|
|
234
236
|
|
|
235
237
|
In-memory cache for temporary data storage:
|
|
236
238
|
|
|
@@ -253,31 +255,31 @@ cache.removeAll();
|
|
|
253
255
|
|
|
254
256
|
**Note:** Cache data is stored in memory and will be lost on page refresh.
|
|
255
257
|
|
|
256
|
-
|
|
258
|
+
### idb
|
|
257
259
|
|
|
258
260
|
Permanent storage using browser database:
|
|
259
261
|
|
|
260
|
-
|
|
262
|
+
#### Create database
|
|
261
263
|
|
|
262
264
|
```js
|
|
263
|
-
idb.db.create("Database")
|
|
265
|
+
idb.db.create("Database");
|
|
264
266
|
```
|
|
265
267
|
|
|
266
|
-
|
|
268
|
+
#### Set data into table
|
|
267
269
|
|
|
268
270
|
```js
|
|
269
|
-
idb.data.set("Database","table", { id: 1, data:{...} } )
|
|
271
|
+
idb.data.set("Database","table", { id: 1, data:{...} } );
|
|
270
272
|
```
|
|
271
273
|
|
|
272
|
-
|
|
274
|
+
#### Get data from table
|
|
273
275
|
|
|
274
276
|
> [in development]
|
|
275
277
|
|
|
276
278
|
```js
|
|
277
|
-
idb.data.get("Database","table", 1 )
|
|
279
|
+
idb.data.get("Database","table", 1 );
|
|
278
280
|
```
|
|
279
281
|
|
|
280
|
-
|
|
282
|
+
#### Delete database / table
|
|
281
283
|
|
|
282
284
|
> [in development]
|
|
283
285
|
|
|
@@ -286,19 +288,81 @@ idb.db.delete("Database") // Remove DB
|
|
|
286
288
|
idb.table.delete("Database","table") // Remove only "table"
|
|
287
289
|
```
|
|
288
290
|
|
|
289
|
-
|
|
291
|
+
### DevTools
|
|
292
|
+
|
|
293
|
+
Browser console debugging tools for inspecting state, store, session, cache:
|
|
294
|
+
|
|
295
|
+
```javascript
|
|
296
|
+
// Inspect all state modules
|
|
297
|
+
memorio.devtools.inspect();
|
|
298
|
+
|
|
299
|
+
// Get statistics
|
|
300
|
+
memorio.devtools.stats();
|
|
301
|
+
|
|
302
|
+
// Clear specific module
|
|
303
|
+
memorio.devtools.clear('state');
|
|
304
|
+
|
|
305
|
+
// Clear all modules
|
|
306
|
+
memorio.devtools.clearAll();
|
|
307
|
+
|
|
308
|
+
// Watch a path for changes
|
|
309
|
+
memorio.devtools.watch('state', 'user.name');
|
|
310
|
+
|
|
311
|
+
// Export all data as JSON
|
|
312
|
+
memorio.devtools.exportData();
|
|
313
|
+
|
|
314
|
+
// Import data from JSON
|
|
315
|
+
memorio.devtools.importData(jsonString);
|
|
316
|
+
|
|
317
|
+
// Get help
|
|
318
|
+
memorio.devtools.help();
|
|
319
|
+
|
|
320
|
+
// Console shortcuts (available in browser console)
|
|
321
|
+
$state // globalThis.state
|
|
322
|
+
$store // globalThis.store
|
|
323
|
+
$session // globalThis.session
|
|
324
|
+
$cache // globalThis.cache
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Logger
|
|
328
|
+
|
|
329
|
+
Logging middleware for tracking all state changes:
|
|
330
|
+
|
|
331
|
+
```javascript
|
|
332
|
+
// Configure logger
|
|
333
|
+
memorio.logger.configure({ enabled: true, logToConsole: true });
|
|
334
|
+
|
|
335
|
+
// Enable/disable logging
|
|
336
|
+
memorio.logger.enable();
|
|
337
|
+
memorio.logger.disable();
|
|
338
|
+
|
|
339
|
+
// Get log history
|
|
340
|
+
memorio.logger.getHistory();
|
|
341
|
+
|
|
342
|
+
// Get statistics
|
|
343
|
+
memorio.logger.getStats();
|
|
344
|
+
|
|
345
|
+
// Clear history
|
|
346
|
+
memorio.logger.clearHistory();
|
|
347
|
+
|
|
348
|
+
// Export logs as JSON
|
|
349
|
+
memorio.logger.exportLogs();
|
|
350
|
+
```
|
|
290
351
|
|
|
291
352
|
## Testing
|
|
292
353
|
|
|
293
|
-
|
|
354
|
+
All test suites are passing:
|
|
294
355
|
|
|
295
356
|
- Basic functionality tests
|
|
296
357
|
- State management tests
|
|
297
358
|
- Store operations tests
|
|
298
359
|
- Cache operations tests
|
|
299
360
|
- Observer pattern tests
|
|
361
|
+
- useObserver pattern tests
|
|
362
|
+
- DevTools tests
|
|
363
|
+
- Logger tests
|
|
300
364
|
|
|
301
|
-
Total:
|
|
365
|
+
Total: 71 tests passed across 8 test suites
|
|
302
366
|
|
|
303
367
|
## Security
|
|
304
368
|
|
|
@@ -311,7 +375,7 @@ Security scans and reports are available at:
|
|
|
311
375
|
|
|
312
376
|
MIT License
|
|
313
377
|
|
|
314
|
-
|
|
378
|
+
Copyright (c) [Dario Passariello](https://dario.passariello.ca/)
|
|
315
379
|
|
|
316
380
|
---
|
|
317
381
|
|
|
@@ -330,6 +394,8 @@ Memorio is designed to work across multiple JavaScript environments:
|
|
|
330
394
|
| `store` | ✅ (localStorage) | ⚠️ (memory) | ⚠️ (memory) | ✅ (localStorage) |
|
|
331
395
|
| `session` | ✅ (sessionStorage) | ⚠️ (memory) | ⚠️ (memory) | ✅ (sessionStorage) |
|
|
332
396
|
| `idb` | ✅ | ❌ | ❌ | ⚠️ |
|
|
397
|
+
| `devtools` | ✅ | ❌ | ❌ | ⚠️ |
|
|
398
|
+
| `logger` | ✅ | ✅ | ✅ | ✅ |
|
|
333
399
|
|
|
334
400
|
- ✅ Full support
|
|
335
401
|
- ⚠️ Partial support (fallback to in-memory)
|