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/docs/README.md ADDED
@@ -0,0 +1,432 @@
1
+ # [memorio](https://npmjs.com/package/memorio)
2
+
3
+ > A lightweight, type-safe state management library for JavaScript applications
4
+
5
+ [![version](https://img.shields.io/npm/v/memorio.svg)](https://npmjs.org/package/memorio)
6
+ [![install size](https://img.shields.io/badge/dynamic/json?url=https://packagephobia.com/v2/api.json?p=memorio&query=$.install.pretty&label=install%20size&style=flat-square)](https://packagephobia.now.sh/result?p=memorio)
7
+ [![downloads](https://img.shields.io/npm/dm/memorio.svg)](https://npmjs.org/package/memorio)
8
+
9
+ ![Node.js](https://img.shields.io/badge/Node.js-gray?logo=node.js)
10
+ ![React](https://img.shields.io/badge/React-gray?logo=React)
11
+ ![Javascript](https://img.shields.io/badge/Javascript-gray?logo=Javascript)
12
+ ![TypeScript](https://img.shields.io/badge/TypeScript-gray?logo=typescript)
13
+ ![esbuild](https://img.shields.io/badge/esbuild-gray?logo=esbuild)
14
+
15
+ ![Jest](https://img.shields.io/badge/Jest-gray?logo=jest)
16
+ ![ESLint](https://img.shields.io/badge/Eslint-gray?logo=eslint)
17
+ ![Playwright](https://img.shields.io/badge/Playwright-gray?logo=playwright)
18
+
19
+ [![GitBook](https://img.shields.io/static/v1?message=Documented%20on%20GitBook&logo=gitbook&logoColor=ffffff&label=%20&labelColor=5c5c5c&color=3F89A1)](https://a51.gitbook.io/memorio)
20
+
21
+ ---
22
+
23
+ ## Table of Contents
24
+
25
+ - [Features](#features)
26
+ - [Installation](#installation)
27
+ - [Quick Start](#quick-start)
28
+ - [API Reference](#api-reference)
29
+ - [State Management](#state-management)
30
+ - [Observer](#observer)
31
+ - [useObserver](#useobserver)
32
+ - [Store](#store)
33
+ - [Session](#session)
34
+ - [Cache](#cache)
35
+ - [idb](#idb)
36
+ - [DevTools](#devtools)
37
+ - [Logger](#logger)
38
+ - [Testing](#testing)
39
+ - [Security](#security)
40
+ - [License](#license)
41
+ - [Cross-Platform Support](#cross-platform-support)
42
+ - [Platform & Context Isolation](docs/markdown/PLATFORM.md)
43
+
44
+ ## Features
45
+
46
+ - Reactive state management with observer pattern
47
+ - Persistent storage with Store API
48
+ - Session management for temporary data
49
+ - Type-safe with full TypeScript support
50
+ - Comprehensive test coverage
51
+ - Easy debugging with proxy-based state
52
+ - **Cross-platform**: Works in Browser, Node.js, Deno, and Edge Workers
53
+ - **Session Isolation**: Each session/request gets isolated state namespace
54
+ - **Context System**: Multi-tenant server-side isolation with `memorio.createContext()`
55
+ - **DevTools**: Browser console debugging tools
56
+ - **Logger**: Automatic logging of state changes
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ npm i -D memorio
62
+ ```
63
+
64
+ ### All test suites are passing
65
+
66
+ - Basic functionality tests
67
+ - State management tests
68
+ - Store operations tests
69
+ - Cache operations tests
70
+ - Observer pattern tests
71
+ - useObserver pattern tests
72
+ - DevTools tests
73
+ - Logger tests
74
+
75
+ Total: 71 tests passed across 8 test suites
76
+
77
+ ## Quick Start
78
+
79
+ ```javascript
80
+ /*
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
84
+ */
85
+
86
+ import 'memorio';
87
+
88
+ // State Management
89
+ state.counter = 0;
90
+ state.active = false;
91
+ state.name = "john";
92
+ state.user = { name: 'John', age: 30 };
93
+ state.hours = [2,3,10,23]
94
+
95
+ // useObserver Pattern for react app
96
+ // Example: if you change the state.counter you get a console.log
97
+ useObserver(
98
+ () => {
99
+ console.log(`Counter changed to ${state.counter}`);
100
+ },
101
+ [state.counter]
102
+ );
103
+
104
+
105
+ // Store (Persistent Storage)
106
+ store.set('preferences', { theme: 'dark' });
107
+ const preferences = store.get('preferences');
108
+
109
+ // Session Storage
110
+ session.set('token', 'user-jwt-token');
111
+ const token = session.get('token');
112
+
113
+ // DevTools
114
+ memorio.devtools.inspect();
115
+
116
+ // Logger
117
+ memorio.logger.configure({ enabled: true, logToConsole: true })
118
+ ```
119
+
120
+ ## API Reference
121
+
122
+ ### State Management
123
+
124
+ State in Memorio is globally accessible and reactive:
125
+
126
+ ```javascript
127
+ // Setting state
128
+ state.user = { name: 'John' };
129
+
130
+ // Getting state
131
+ const userName = state.user.name;
132
+
133
+ // Listing all states
134
+ console.log(state.list);
135
+
136
+ // Removing state
137
+ state.remove('user');
138
+
139
+ // Clearing all states
140
+ state.removeAll();
141
+ ```
142
+
143
+ ### useObserver
144
+
145
+ useObserver is a React hook for observing Memorio state changes with auto-discovery:
146
+
147
+ ```js
148
+ // Basic useObserver - array syntax with state path
149
+ useObserver(
150
+ () => {
151
+ console.log('User updated:', state.user);
152
+ },
153
+ [state.user]
154
+ );
155
+
156
+ // Multiple states
157
+ useObserver(
158
+ () => {
159
+ console.log('States changed:', state.user, state.counter, state.settings);
160
+ },
161
+ [state.user, state.counter, state.settings]
162
+ );
163
+
164
+ // With options
165
+ useObserver(
166
+ () => {
167
+ console.log('Value changed');
168
+ },
169
+ [state.value],
170
+ { immediate: true }
171
+ );
172
+ ```
173
+
174
+ ### Store
175
+
176
+ Persistent storage for your application:
177
+
178
+ ```javascript
179
+ // Setting values
180
+ store.set('config', { theme: 'dark', language: 'en' });
181
+
182
+ // Getting values
183
+ const config = store.get('config');
184
+
185
+ // Removing specific value
186
+ store.remove('config');
187
+
188
+ // Getting store size
189
+ const size = store.size();
190
+
191
+ // Clearing store
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
+ }
200
+ ```
201
+
202
+ ### Session
203
+
204
+ Temporary storage that persists during page sessions:
205
+
206
+ ```js
207
+ // Setting session data
208
+ session.set(
209
+ 'userSession', {
210
+ id: 'user123',
211
+ lastActive: Date.now()
212
+ }
213
+ );
214
+
215
+ // Getting session data
216
+ const userData = session.get('userSession');
217
+
218
+ // Checking session size
219
+ const activeItems = session.size();
220
+
221
+ // Removing session data
222
+ session.remove('userSession');
223
+
224
+ // Clearing all session data
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
+ }
233
+ ```
234
+
235
+ ### Cache
236
+
237
+ In-memory cache for temporary data storage:
238
+
239
+ ```js
240
+ // Setting cache data
241
+ cache.set('tempData', { computed: true, value: 42 });
242
+
243
+ // Getting cache data
244
+ const cached = cache.get('tempData');
245
+
246
+ // Checking cache size
247
+ const cacheSize = cache.size();
248
+
249
+ // Removing cache data
250
+ cache.remove('tempData');
251
+
252
+ // Clearing all cache data
253
+ cache.removeAll();
254
+ ```
255
+
256
+ **Note:** Cache data is stored in memory and will be lost on page refresh.
257
+
258
+ ### idb
259
+
260
+ Permanent storage using browser database:
261
+
262
+ #### Create database
263
+
264
+ ```js
265
+ idb.db.create("Database");
266
+ ```
267
+
268
+ #### Set data into table
269
+
270
+ ```js
271
+ idb.data.set("Database","table", { id: 1, data:{...} } );
272
+ ```
273
+
274
+ #### Get data from table
275
+
276
+ > [in development]
277
+
278
+ ```js
279
+ idb.data.get("Database","table", 1 );
280
+ ```
281
+
282
+ #### Delete database / table
283
+
284
+ > [in development]
285
+
286
+ ```js
287
+ idb.db.delete("Database") // Remove DB
288
+ idb.table.delete("Database","table") // Remove only "table"
289
+ ```
290
+
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
+ ```
351
+
352
+ ## Testing
353
+
354
+ All test suites are passing:
355
+
356
+ - Basic functionality tests
357
+ - State management tests
358
+ - Store operations tests
359
+ - Cache operations tests
360
+ - Observer pattern tests
361
+ - useObserver pattern tests
362
+ - DevTools tests
363
+ - Logger tests
364
+
365
+ Total: 71 tests passed across 8 test suites
366
+
367
+ ## Security
368
+
369
+ Security scans and reports are available at:
370
+
371
+ - [Socket.dev](https://socket.dev/npm/package/memorio)
372
+ - [Snyk.io](https://security.snyk.io/package/npm/memorio)
373
+
374
+ ## License
375
+
376
+ MIT License
377
+
378
+ Copyright (c) [Dario Passariello](https://dario.passariello.ca/)
379
+
380
+ ---
381
+
382
+ ## Cross-Platform Support
383
+
384
+ Memorio is designed to work across multiple JavaScript environments:
385
+
386
+ ### Platform Compatibility
387
+
388
+ | Feature | Browser | Node.js | Deno | Edge Workers |
389
+ |---------|---------|---------|------|---------------|
390
+ | `state` | ✅ | ✅ | ✅ | ✅ |
391
+ | `observer` | ✅ | ✅ | ✅ | ✅ |
392
+ | `useObserver` | ✅ | ⚠️ | ⚠️ | ✅ |
393
+ | `cache` | ✅ | ✅ | ✅ | ✅ |
394
+ | `store` | ✅ (localStorage) | ⚠️ (memory) | ⚠️ (memory) | ✅ (localStorage) |
395
+ | `session` | ✅ (sessionStorage) | ⚠️ (memory) | ⚠️ (memory) | ✅ (sessionStorage) |
396
+ | `idb` | ✅ | ❌ | ❌ | ⚠️ |
397
+ | `devtools` | ✅ | ❌ | ❌ | ⚠️ |
398
+ | `logger` | ✅ | ✅ | ✅ | ✅ |
399
+
400
+ - ✅ Full support
401
+ - ⚠️ Partial support (fallback to in-memory)
402
+ - ❌ Not available
403
+
404
+ ### Session Isolation
405
+
406
+ Memorio provides automatic session isolation to prevent state leakage between different requests or contexts:
407
+
408
+ - **Unique Session IDs**: Each import gets a unique session identifier
409
+ - **Namespaced Storage**: `store` and `session` keys are prefixed with session ID
410
+ - **State Isolation**: `state` is isolated per-instance
411
+
412
+ This ensures that in server-side environments (Node.js/Deno), different requests don't share state data.
413
+
414
+ ### Best Practices
415
+
416
+ 1. **For Client-Side**: Use all features freely - store, session, idb work with real browser storage
417
+ 2. **For Server-Side**: Use `state` and `cache` for in-memory data; store/session fall back to memory
418
+ 3. **For Edge Workers**: Same as browser; localStorage/sessionStorage available
419
+
420
+ ### Checking Platform
421
+
422
+ ```javascript
423
+ import { isBrowser, isNode, isDeno, getCapabilities } from 'memorio';
424
+
425
+ console.log('Browser:', isBrowser()); // true in browser
426
+ console.log('Node.js:', isNode()); // true in Node.js
427
+ console.log('Deno:', isDeno()); // true in Deno
428
+
429
+ const caps = getCapabilities();
430
+ console.log('Platform:', caps.platform); // 'browser' | 'node' | 'deno' | 'edge'
431
+ console.log('Persistent:', store.isPersistent); // true if using real storage
432
+ ```
@@ -0,0 +1,26 @@
1
+ # Table of contents
2
+
3
+ * [README](README.md)
4
+
5
+ ## Core Modules
6
+
7
+ * [State](markdown/STATE.md) - Reactive global state management
8
+ * [Observer](markdown/OBSERVER.md) - ⚠️ Deprecated (use useObserver)
9
+ * [useObserver](markdown/USEOBSERVER.md) - React hook for state observation
10
+ * [Cache](markdown/CACHE.md) - In-memory caching (lost on refresh)
11
+ * [Store](markdown/STORE.md) - Persistent localStorage management
12
+ * [Session](markdown/SESSION.md) - Temporary sessionStorage management
13
+ * [IDB](markdown/IDB.md) - IndexedDB for large data storage
14
+
15
+ ## Platform & Compatibility
16
+
17
+ * [Platform & Context Isolation](markdown/PLATFORM.md) - Cross-platform support, session isolation
18
+ * [Security](markdown/SECURITY.md) - Security measures, vulnerability prevention
19
+ * [Changelog](markdown/CHANGELOG.md) - Version history and migration guide
20
+
21
+ ## Additional Resources
22
+
23
+ * [License](../LICENSE.md)
24
+ * [Contributing](../CONTRIBUTING.md)
25
+ * [Code of Conduct](../CODE_OF_CONDUCT.md)
26
+ * [Security](../SECURITY.md)
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-modernist
@@ -0,0 +1,90 @@
1
+ # Cache - Memorio
2
+
3
+ > ✅ **Universal**: Works in Browser, Node.js, Deno, and Edge Workers
4
+
5
+ Cache provides in-memory storage with a simple API. Data is lost on page refresh or process restart.
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
+ // Save data
25
+ cache.set('username', 'Mario');
26
+ cache.set('score', 1500);
27
+
28
+ // Read data
29
+ console.log(cache.get('username')); // "Mario"
30
+ console.log(cache.get('score')); // 1500
31
+ ```
32
+
33
+ ### Example 2: Intermediate
34
+
35
+ ```javascript
36
+ // Store objects
37
+ cache.set('user', { name: 'Luigi', level: 5 });
38
+ const user = cache.get('user');
39
+ console.log(user.name); // "Luigi"
40
+
41
+ // Remove single item
42
+ cache.remove('username');
43
+
44
+ // Clear all cache
45
+ cache.removeAll();
46
+ ```
47
+
48
+ ---
49
+
50
+ ## API Reference
51
+
52
+ ### Methods
53
+
54
+ | Method | Parameters | Returns | Description |
55
+ |--------|------------|---------|-------------|
56
+ | `cache.get(name)` | `name: string` | `any` | Get value from cache |
57
+ | `cache.set(name, value)` | `name: string, value: any` | `void` | Save value to cache |
58
+ | `cache.remove(name)` | `name: string` | `boolean` | Remove single item |
59
+ | `cache.removeAll()` | `none` | `boolean` | Clear all cache |
60
+
61
+ ---
62
+
63
+ ## Storage Comparison
64
+
65
+ | Feature | Cache | Store | Session | IDB |
66
+ |---------|-------|-------|---------|-----|
67
+ | Platform Support | All (universal) | Browser/Edge | Browser/Edge | Browser only |
68
+ | Lifetime | Until refresh | Forever | Until tab closes | Forever |
69
+ | Capacity | Unlimited | ~5-10 MB | ~5-10 MB | 50+ MB |
70
+ | Use case | Temporary data | User preferences | Auth tokens | Large data |
71
+
72
+ ---
73
+
74
+ ## Platform Support
75
+
76
+ | Platform | Support | Notes |
77
+ |----------|---------|-------|
78
+ | Browser | ✅ Full | In-memory, lost on refresh |
79
+ | Node.js | ✅ Full | In-memory, lost on restart |
80
+ | Deno | ✅ Full | In-memory, lost on restart |
81
+ | Edge Workers | ✅ Full | In-memory, lost on function cold start |
82
+
83
+ ---
84
+
85
+ ## Best Practices
86
+
87
+ 1. Use for temporary data that doesn't need persistence
88
+ 2. Great for computed values or API response caching
89
+ 3. Data is lost on page refresh - don't use for important data
90
+ 4. Clear with `cache.removeAll()` when no longer needed