memorio 3.0.0 → 3.0.2
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/CODE_OF_CONDUCT.md +1 -1
- package/README.md +209 -328
- package/SECURITY.md +48 -3
- package/docs/README.md +209 -328
- package/docs/markdown/CACHE.md +3 -3
- package/docs/markdown/CHANGELOG.md +63 -154
- package/docs/markdown/DEVTOOLS.md +1 -1
- package/docs/markdown/IDB.md +3 -3
- package/docs/markdown/LOGGER.md +2 -2
- package/docs/markdown/OBSERVER.md +4 -4
- package/docs/markdown/PLATFORM.md +5 -5
- package/docs/markdown/SECURITY.md +16 -4
- package/docs/markdown/SESSION.md +4 -4
- package/docs/markdown/STATE.md +7 -7
- package/docs/markdown/STORE.md +7 -7
- package/docs/markdown/USEOBSERVER.md +1 -1
- package/examples/basic.ts +22 -22
- package/examples/browser-vanilla.html +2 -2
- package/examples/cache.ts +9 -9
- package/examples/idb.ts +8 -8
- package/examples/node-server.ts +39 -39
- package/examples/observer.ts +5 -5
- package/examples/platform.ts +37 -37
- package/examples/react-app.tsx +9 -4
- package/examples/session-advanced.ts +8 -8
- package/examples/state-advanced.ts +10 -10
- package/examples/store-advanced.ts +9 -9
- package/examples/useObserver.tsx +1 -1
- package/index.cjs +126 -117
- package/index.js +126 -117
- package/package.json +3 -3
- package/types/cache.d.ts +1 -1
- package/types/idb.d.ts +1 -1
- package/types/memorio.d.ts +6 -0
- package/types/observer.d.ts +1 -1
- package/types/store.d.ts +10 -10
- package/types/useObserver.d.ts +1 -1
package/docs/README.md
CHANGED
|
@@ -1,430 +1,311 @@
|
|
|
1
1
|
# [memorio](https://npmjs.com/package/memorio)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
8
|
|
|
9
9
|

|
|
10
|
-

|
|
11
|
+

|
|
12
12
|

|
|
13
|
-

|
|
14
|
+

|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-

|
|
16
|
+
**State management that actually makes your life easier.**
|
|
17
|
+
Zero friction. Zero bloat. Single import. Works everywhere JavaScript runs.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
[Get Started](#-quick-start) · [API Reference](#-api-reference) · [License: MIT](https://opensource.org/licenses/MIT)
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
- [Features](#features)
|
|
24
|
-
- [Installation](#installation)
|
|
25
|
-
- [Quick Start](#quick-start)
|
|
26
|
-
- [API Reference](#api-reference)
|
|
27
|
-
- [State Management](#state-management)
|
|
28
|
-
- [Observer](#observer)
|
|
29
|
-
- [useObserver](#useobserver)
|
|
30
|
-
- [Store](#store)
|
|
31
|
-
- [Session](#session)
|
|
32
|
-
- [Cache](#cache)
|
|
33
|
-
- [idb](#idb)
|
|
34
|
-
- [DevTools](#devtools)
|
|
35
|
-
- [Logger](#logger)
|
|
36
|
-
- [Testing](#testing)
|
|
37
|
-
- [Security](#security)
|
|
38
|
-
- [License](#license)
|
|
39
|
-
- [Cross-Platform Support](#cross-platform-support)
|
|
40
|
-
- [Platform & Context Isolation](docs/markdown/PLATFORM.md)
|
|
21
|
+
---
|
|
41
22
|
|
|
42
|
-
##
|
|
23
|
+
## Why memorio?
|
|
43
24
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
- **DevTools**: Browser console debugging tools
|
|
54
|
-
- **Logger**: Automatic logging of state changes
|
|
25
|
+
| | memorio | Redux | Zustand |
|
|
26
|
+
|---|---|---|---|
|
|
27
|
+
| **Setup** | 1 import | Boilerplate hell | Moderate |
|
|
28
|
+
| **Dependencies** | **Zero** | Many | Few |
|
|
29
|
+
| **TypeScript** | ✅ Native | ✅ | ✅ |
|
|
30
|
+
| **Binary storage** | ✅ Built-in IDB | ❌ Add-on | ❌ |
|
|
31
|
+
| **Observer** | ✅ Built-in | ❌ Add-on | ❌ |
|
|
32
|
+
| **DevTools** | ✅ Built-in | ❌ Extension | ❌ |
|
|
33
|
+
| **Running on the edge** | ✅ Workers, Deno | ⚠️ Limited | ⚠️ Limited |
|
|
55
34
|
|
|
56
|
-
|
|
35
|
+
If you need a `store` on the server. A `cache` in the edge worker.
|
|
36
|
+
Session isolation in Next.js. IndexedDB in a Service Worker.
|
|
37
|
+
All from one import, zero configuration.
|
|
57
38
|
|
|
58
|
-
|
|
59
|
-
npm i -D memorio
|
|
60
|
-
```
|
|
39
|
+
---
|
|
61
40
|
|
|
62
|
-
|
|
41
|
+
## Features
|
|
63
42
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
-
|
|
70
|
-
|
|
71
|
-
|
|
43
|
+
| | |
|
|
44
|
+
|---|---|
|
|
45
|
+
| **`state`** | Reactive, volatile state — listen with `useObserver` |
|
|
46
|
+
| **`store`** | localStorage persistence — survives refresh |
|
|
47
|
+
| **`session`** | sessionStorage — dies with the tab |
|
|
48
|
+
| **`cache`** | In-memory cache — fastest read possible |
|
|
49
|
+
| **`idb`** | IndexedDB with typed tables — structured, persistent, async |
|
|
50
|
+
| **`observer`** | Object watcher — legacy, still works |
|
|
51
|
+
| **`useObserver`** | React hook with auto-discovery — drops in |
|
|
52
|
+
| **`devtools`** | `memorio.devtools.inspect()` — see everything in console |
|
|
53
|
+
| **`logger`** | Auto-log every state change with timestamps |
|
|
54
|
+
| **Session Isolation** | Every browser tab, every request: isolated namespace |
|
|
55
|
+
| **Platform Detection** | `isBrowser`, `isNode`, `isDeno`, `isEdge` |
|
|
56
|
+
|
|
57
|
+
No Zustand. No Redux. No provider boilerplate.
|
|
58
|
+
Just import it and start storing.
|
|
72
59
|
|
|
73
|
-
|
|
60
|
+
---
|
|
74
61
|
|
|
75
62
|
## Quick Start
|
|
76
63
|
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
Add import only at first start of your SPA. Became global!.
|
|
81
|
-
You don't need to import any time you need to use memorio
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
import 'memorio';
|
|
85
|
-
|
|
86
|
-
// State Management
|
|
87
|
-
state.counter = 0;
|
|
88
|
-
state.active = false;
|
|
89
|
-
state.name = "john";
|
|
90
|
-
state.user = { name: 'John', age: 30 };
|
|
91
|
-
state.hours = [2,3,10,23]
|
|
92
|
-
|
|
93
|
-
// useObserver Pattern for react app
|
|
94
|
-
// Example: if you change the state.counter you get a console.log
|
|
95
|
-
useObserver(
|
|
96
|
-
() => {
|
|
97
|
-
console.log(`Counter changed to ${state.counter}`);
|
|
98
|
-
},
|
|
99
|
-
[state.counter]
|
|
100
|
-
);
|
|
64
|
+
```bash
|
|
65
|
+
npm i memorio
|
|
66
|
+
```
|
|
101
67
|
|
|
68
|
+
```typescript
|
|
69
|
+
// memorio/index.ts — import once at your app entry point
|
|
70
|
+
import 'memorio'
|
|
102
71
|
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
|
|
72
|
+
// Memory
|
|
73
|
+
state.user = { name: 'Sara', role: 'admin' }
|
|
74
|
+
state.counter++
|
|
75
|
+
state.settings = { theme: 'dark', lang: 'it' }
|
|
106
76
|
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
|
|
77
|
+
// Call it "a store" but make it observe automatically
|
|
78
|
+
useObserver(
|
|
79
|
+
() => { console.debug('user changed:', state.user) },
|
|
80
|
+
[state.user]
|
|
81
|
+
)
|
|
82
|
+
```
|
|
110
83
|
|
|
111
|
-
|
|
112
|
-
|
|
84
|
+
That is it.
|
|
85
|
+
No context providers. No `<Store>` wrappers. No action creators.
|
|
86
|
+
Import → assign → done.
|
|
113
87
|
|
|
114
|
-
|
|
115
|
-
memorio.logger.configure({ enabled: true, logToConsole: true })
|
|
116
|
-
```
|
|
88
|
+
---
|
|
117
89
|
|
|
118
90
|
## API Reference
|
|
119
91
|
|
|
120
|
-
###
|
|
92
|
+
### `state` — Volatile reactive state
|
|
121
93
|
|
|
122
|
-
|
|
94
|
+
Global, Proxy-based, reactive. Access anywhere.
|
|
123
95
|
|
|
124
96
|
```javascript
|
|
125
|
-
//
|
|
126
|
-
state.user = { name: '
|
|
97
|
+
// Set
|
|
98
|
+
state.user = { name: 'Sara', role: 'admin' }
|
|
99
|
+
state.items = [1, 2, 3]
|
|
127
100
|
|
|
128
|
-
//
|
|
129
|
-
const
|
|
101
|
+
// Get
|
|
102
|
+
const name = state.user.name // 'Sara'
|
|
130
103
|
|
|
131
|
-
//
|
|
132
|
-
console.
|
|
104
|
+
// List all keys
|
|
105
|
+
console.debug(state.list) // ['user', 'items']
|
|
133
106
|
|
|
134
|
-
//
|
|
135
|
-
state.remove('
|
|
107
|
+
// Remove one key
|
|
108
|
+
state.remove('items')
|
|
136
109
|
|
|
137
|
-
//
|
|
138
|
-
state.removeAll()
|
|
110
|
+
// Clear all — lock/unlock available for frozen objects
|
|
111
|
+
state.removeAll()
|
|
112
|
+
state.lock() // freeze everything
|
|
113
|
+
state.unlock() // unfreeze
|
|
139
114
|
```
|
|
140
115
|
|
|
141
|
-
###
|
|
142
|
-
|
|
143
|
-
useObserver is a React hook for observing Memorio state changes with auto-discovery:
|
|
144
|
-
|
|
145
|
-
```js
|
|
146
|
-
// Basic useObserver - array syntax with state path
|
|
147
|
-
useObserver(
|
|
148
|
-
() => {
|
|
149
|
-
console.log('User updated:', state.user);
|
|
150
|
-
},
|
|
151
|
-
[state.user]
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
// Multiple states
|
|
155
|
-
useObserver(
|
|
156
|
-
() => {
|
|
157
|
-
console.log('States changed:', state.user, state.counter, state.settings);
|
|
158
|
-
},
|
|
159
|
-
[state.user, state.counter, state.settings]
|
|
160
|
-
);
|
|
116
|
+
### `store` — localStorage, survives refresh
|
|
161
117
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
);
|
|
118
|
+
```javascript
|
|
119
|
+
store.set('preferences', { theme: 'dark' })
|
|
120
|
+
const prefs = store.get('preferences') // { theme: 'dark' } or null
|
|
121
|
+
store.remove('preferences')
|
|
122
|
+
store.removeAll()
|
|
123
|
+
console.debug(store.size(), 'chars stored')
|
|
124
|
+
console.debug(store.isPersistent) // true → real localStorage
|
|
170
125
|
```
|
|
171
126
|
|
|
172
|
-
###
|
|
173
|
-
|
|
174
|
-
Persistent storage for your application:
|
|
127
|
+
### `session` — sessionStorage, dies with tab
|
|
175
128
|
|
|
176
129
|
```javascript
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
// Getting values
|
|
181
|
-
const config = store.get('config');
|
|
182
|
-
|
|
183
|
-
// Removing specific value
|
|
184
|
-
store.remove('config');
|
|
185
|
-
|
|
186
|
-
// Getting store size
|
|
187
|
-
const size = store.size();
|
|
188
|
-
|
|
189
|
-
// Clearing store
|
|
190
|
-
store.removeAll();
|
|
191
|
-
|
|
192
|
-
// Check if using persistent storage
|
|
193
|
-
if (store.isPersistent) {
|
|
194
|
-
console.log('Using real localStorage');
|
|
195
|
-
} else {
|
|
196
|
-
console.log('Using memory fallback (server environment)');
|
|
197
|
-
}
|
|
130
|
+
session.set('token', 'user-abc-123')
|
|
131
|
+
const token = session.get('token') // 'user-abc-123' or null
|
|
132
|
+
session.removeAll()
|
|
198
133
|
```
|
|
199
134
|
|
|
200
|
-
###
|
|
201
|
-
|
|
202
|
-
Temporary storage that persists during page sessions:
|
|
203
|
-
|
|
204
|
-
```js
|
|
205
|
-
// Setting session data
|
|
206
|
-
session.set(
|
|
207
|
-
'userSession', {
|
|
208
|
-
id: 'user123',
|
|
209
|
-
lastActive: Date.now()
|
|
210
|
-
}
|
|
211
|
-
);
|
|
135
|
+
### `cache` — In-memory, disappears on refresh
|
|
212
136
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
//
|
|
217
|
-
const activeItems = session.size();
|
|
218
|
-
|
|
219
|
-
// Removing session data
|
|
220
|
-
session.remove('userSession');
|
|
221
|
-
|
|
222
|
-
// Clearing all session data
|
|
223
|
-
session.removeAll();
|
|
224
|
-
|
|
225
|
-
// Check if using persistent storage
|
|
226
|
-
if (session.isPersistent) {
|
|
227
|
-
console.log('Using real sessionStorage');
|
|
228
|
-
} else {
|
|
229
|
-
console.log('Using memory fallback (server environment)');
|
|
230
|
-
}
|
|
137
|
+
```javascript
|
|
138
|
+
cache.set('temp', computeExpensiveResult())
|
|
139
|
+
const result = cache.get('temp') // undefined or the value
|
|
140
|
+
cache.clear() // empty it all
|
|
231
141
|
```
|
|
232
142
|
|
|
233
|
-
###
|
|
143
|
+
### `idb` — IndexedDB, structured & typed
|
|
234
144
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
// Getting cache data
|
|
242
|
-
const cached = cache.get('tempData');
|
|
243
|
-
|
|
244
|
-
// Checking cache size
|
|
245
|
-
const cacheSize = cache.size();
|
|
145
|
+
```javascript
|
|
146
|
+
await idb.db.create('my-db')
|
|
147
|
+
await idb.table.create('my-db', 'users')
|
|
148
|
+
await idb.data.set('my-db', 'users', { id: 1, name: 'Sara' })
|
|
149
|
+
const user = await idb.data.get('my-db', 'users', 1)
|
|
150
|
+
```
|
|
246
151
|
|
|
247
|
-
|
|
248
|
-
cache.remove('tempData');
|
|
152
|
+
### `observer` — Object watcher (DEPRECATED)
|
|
249
153
|
|
|
250
|
-
|
|
251
|
-
|
|
154
|
+
```javascript
|
|
155
|
+
globalThis.observer('state.user', (newVal, oldVal) => {
|
|
156
|
+
console.debug('user changed:', newVal, oldVal)
|
|
157
|
+
})
|
|
252
158
|
```
|
|
253
159
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
### idb
|
|
160
|
+
### `useObserver` — React observer hook
|
|
257
161
|
|
|
258
|
-
|
|
162
|
+
Available globally after `import 'memorio'`.
|
|
259
163
|
|
|
260
|
-
|
|
164
|
+
```jsx
|
|
165
|
+
import 'memorio'
|
|
261
166
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
```
|
|
167
|
+
function Counter() {
|
|
168
|
+
const [, forceUpdate] = useReducer(x => x + 1, 0)
|
|
265
169
|
|
|
266
|
-
|
|
170
|
+
useObserver(forceUpdate, [state.counter])
|
|
171
|
+
// State path auto-discovered during render — no manual deps needed
|
|
267
172
|
|
|
268
|
-
|
|
269
|
-
|
|
173
|
+
return <div>Count: {state.counter}</div>
|
|
174
|
+
}
|
|
270
175
|
```
|
|
271
176
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
> [in development]
|
|
177
|
+
### `devtools` — inspect everything in one call
|
|
275
178
|
|
|
276
|
-
```
|
|
277
|
-
|
|
179
|
+
```javascript
|
|
180
|
+
memorio.devtools.inspect() // pretty-prints state, store, session, cache
|
|
181
|
+
memorio.devtools.stats() // { stateKeys, storeKeys, sessionKeys, ... }
|
|
182
|
+
memorio.devtools.clear('state')
|
|
183
|
+
memorio.devtools.exportData() // JSON snapshot
|
|
184
|
+
$state // console shortcut — same as globalThis.state
|
|
278
185
|
```
|
|
279
186
|
|
|
280
|
-
|
|
187
|
+
### `logger` — track every change
|
|
281
188
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
189
|
+
```javascript
|
|
190
|
+
memorio.logger.configure({ enabled: true, logToConsole: true })
|
|
191
|
+
memorio.logger.getHistory() // [{ timestamp, module, action, path, value }, ...]
|
|
192
|
+
memorio.logger.getStats() // { total, state, set, get, ... }
|
|
193
|
+
memorio.logger.exportLogs() // JSON string of all history
|
|
287
194
|
```
|
|
288
195
|
|
|
289
|
-
###
|
|
196
|
+
### Platform detection
|
|
290
197
|
|
|
291
|
-
|
|
198
|
+
Access via `memorio.*`:
|
|
292
199
|
|
|
293
200
|
```javascript
|
|
294
|
-
//
|
|
295
|
-
memorio.
|
|
201
|
+
memorio.isBrowser() // true in Chrome, Firefox, Safari
|
|
202
|
+
memorio.isNode() // true in Node.js
|
|
203
|
+
memorio.isDeno() // true in Deno
|
|
204
|
+
memorio.isEdge() // true in Cloudflare Workers, Vercel Edge
|
|
296
205
|
|
|
297
|
-
|
|
298
|
-
|
|
206
|
+
const caps = memorio.getCapabilities()
|
|
207
|
+
// { platform: 'browser', hasLocalStorage: true, hasIndexedDB: true, ... }
|
|
208
|
+
```
|
|
299
209
|
|
|
300
|
-
|
|
301
|
-
memorio.devtools.clear('state');
|
|
210
|
+
### Context (multi-tenant)
|
|
302
211
|
|
|
303
|
-
|
|
304
|
-
memorio.
|
|
212
|
+
```javascript
|
|
213
|
+
memorio.createContext('tenant-name')
|
|
214
|
+
memorio.listContexts()
|
|
215
|
+
memorio.deleteContext('context-id')
|
|
216
|
+
memorio.isolate('tenant-name')
|
|
217
|
+
```
|
|
305
218
|
|
|
306
|
-
|
|
307
|
-
memorio.devtools.watch('state', 'user.name');
|
|
219
|
+
---
|
|
308
220
|
|
|
309
|
-
|
|
310
|
-
memorio.devtools.exportData();
|
|
221
|
+
## Cross-Platform
|
|
311
222
|
|
|
312
|
-
|
|
313
|
-
memorio.devtools.importData(jsonString);
|
|
223
|
+
Memorio runs in every JavaScript environment, with automatic fallbacks.
|
|
314
224
|
|
|
315
|
-
|
|
316
|
-
|
|
225
|
+
| | Browser | Node.js | Deno | Edge / Workers |
|
|
226
|
+
|---|---|---|---|---|
|
|
227
|
+
| `state` | ✅ | ✅ | ✅ | ✅ |
|
|
228
|
+
| `observer` / `useObserver` | ✅ | ✅ | ✅ | ✅ |
|
|
229
|
+
| `cache` | ✅ | ✅ | ✅ | ✅ |
|
|
230
|
+
| `store` | ✅ localStorage | ⚠️ memory | ⚠️ memory | ✅ localStorage |
|
|
231
|
+
| `session` | ✅ sessionStorage | ⚠️ memory | ⚠️ memory | ✅ sessionStorage |
|
|
232
|
+
| `idb` | ✅ IndexedDB | ❌ | ❌ | ⚠️ |
|
|
233
|
+
| `devtools` | ✅ | ❌ | ❌ | ⚠️ |
|
|
317
234
|
|
|
318
|
-
|
|
319
|
-
$state // globalThis.state
|
|
320
|
-
$store // globalThis.store
|
|
321
|
-
$session // globalThis.session
|
|
322
|
-
$cache // globalThis.cache
|
|
323
|
-
```
|
|
235
|
+
> **Why memory fallbacks on the server?** There is no browser. `store` and `session` gracefully fall back to `Map`. You still get the same API. Same `state`, same `cache`, same `useObserver`. No extra config required.
|
|
324
236
|
|
|
325
|
-
###
|
|
237
|
+
### Platform detection
|
|
326
238
|
|
|
327
|
-
|
|
239
|
+
Access via `memorio.*` after `import 'memorio'`:
|
|
328
240
|
|
|
329
241
|
```javascript
|
|
330
|
-
//
|
|
331
|
-
memorio.
|
|
332
|
-
|
|
333
|
-
//
|
|
334
|
-
memorio.logger.enable();
|
|
335
|
-
memorio.logger.disable();
|
|
242
|
+
memorio.isBrowser() // true in Chrome, Firefox, Safari
|
|
243
|
+
memorio.isNode() // true in Node.js
|
|
244
|
+
memorio.isDeno() // true in Deno
|
|
245
|
+
memorio.isEdge() // true in Cloudflare Workers, Vercel Edge
|
|
336
246
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
// Get statistics
|
|
341
|
-
memorio.logger.getStats();
|
|
342
|
-
|
|
343
|
-
// Clear history
|
|
344
|
-
memorio.logger.clearHistory();
|
|
345
|
-
|
|
346
|
-
// Export logs as JSON
|
|
347
|
-
memorio.logger.exportLogs();
|
|
247
|
+
const c = memorio.getCapabilities()
|
|
248
|
+
// { platform: 'browser', hasLocalStorage: true, hasIndexedDB: true, ... }
|
|
348
249
|
```
|
|
349
250
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
All test suites are passing:
|
|
353
|
-
|
|
354
|
-
- Basic functionality tests
|
|
355
|
-
- State management tests
|
|
356
|
-
- Store operations tests
|
|
357
|
-
- Cache operations tests
|
|
358
|
-
- Observer pattern tests
|
|
359
|
-
- useObserver pattern tests
|
|
360
|
-
- DevTools tests
|
|
361
|
-
- Logger tests
|
|
362
|
-
|
|
363
|
-
Total: 71 tests passed across 8 test suites
|
|
251
|
+
---
|
|
364
252
|
|
|
365
253
|
## Security
|
|
366
254
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
-
|
|
370
|
-
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
MIT License
|
|
375
|
-
|
|
376
|
-
Copyright (c) [Dario Passariello](https://dario.passariello.ca/)
|
|
255
|
+
- Zero production dependencies — no supply chain surprises
|
|
256
|
+
- NIST & NSA aligned — enterprise-grade security standards
|
|
257
|
+
- No `eval`, no obfuscation, no hardcoded secrets
|
|
258
|
+
- All inputs validated, keys sanitized, errors caught
|
|
259
|
+
- Secure random session IDs via `crypto.randomUUID`
|
|
260
|
+
- MIT license — full audit trail on [`SECURITY.md`](.github/SECURITY.md)
|
|
377
261
|
|
|
378
262
|
---
|
|
379
263
|
|
|
380
|
-
##
|
|
264
|
+
## Installation options
|
|
381
265
|
|
|
382
|
-
|
|
266
|
+
```bash
|
|
267
|
+
# npm
|
|
268
|
+
npm i memorio
|
|
383
269
|
|
|
384
|
-
|
|
270
|
+
# pnpm
|
|
271
|
+
pnpm add memorio
|
|
385
272
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
| `state` | ✅ | ✅ | ✅ | ✅ |
|
|
389
|
-
| `observer` | ✅ | ✅ | ✅ | ✅ |
|
|
390
|
-
| `useObserver` | ✅ | ⚠️ | ⚠️ | ✅ |
|
|
391
|
-
| `cache` | ✅ | ✅ | ✅ | ✅ |
|
|
392
|
-
| `store` | ✅ (localStorage) | ⚠️ (memory) | ⚠️ (memory) | ✅ (localStorage) |
|
|
393
|
-
| `session` | ✅ (sessionStorage) | ⚠️ (memory) | ⚠️ (memory) | ✅ (sessionStorage) |
|
|
394
|
-
| `idb` | ✅ | ❌ | ❌ | ⚠️ |
|
|
395
|
-
| `devtools` | ✅ | ❌ | ❌ | ⚠️ |
|
|
396
|
-
| `logger` | ✅ | ✅ | ✅ | ✅ |
|
|
273
|
+
# yarn
|
|
274
|
+
yarn add memorio
|
|
397
275
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
276
|
+
# React peer dep (optional, React ≥ 16.8)
|
|
277
|
+
npm i react react-dom
|
|
278
|
+
```
|
|
401
279
|
|
|
402
|
-
|
|
280
|
+
---
|
|
403
281
|
|
|
404
|
-
|
|
282
|
+
## Testing
|
|
405
283
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
- **State Isolation**: `state` is isolated per-instance
|
|
284
|
+
```
|
|
285
|
+
95 tests · 8 suites · all passing
|
|
409
286
|
|
|
410
|
-
|
|
287
|
+
basic | state | store | session | cache | idb | observer | useObserver
|
|
288
|
+
```
|
|
411
289
|
|
|
412
|
-
|
|
290
|
+
| Suite | Tests | Status |
|
|
291
|
+
|-------|-------|--------|
|
|
292
|
+
| Basic | 7 | ✅ |
|
|
293
|
+
| State | 24 | ✅ |
|
|
294
|
+
| Store | 17 | ✅ |
|
|
295
|
+
| Session | 12 | ✅ |
|
|
296
|
+
| IDB | 7 | ✅ |
|
|
297
|
+
| Cache | 5 | ✅ |
|
|
298
|
+
| Observer | 12 | ✅ |
|
|
299
|
+
| useObserver | 12 | ✅ |
|
|
413
300
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
301
|
+
```bash
|
|
302
|
+
npm test
|
|
303
|
+
```
|
|
417
304
|
|
|
418
|
-
|
|
305
|
+
---
|
|
419
306
|
|
|
420
|
-
|
|
421
|
-
import { isBrowser, isNode, isDeno, getCapabilities } from 'memorio';
|
|
307
|
+
## License
|
|
422
308
|
|
|
423
|
-
|
|
424
|
-
console.log('Node.js:', isNode()); // true in Node.js
|
|
425
|
-
console.log('Deno:', isDeno()); // true in Deno
|
|
309
|
+
MIT © [Dario Passariello](https://dario.passariello.ca)
|
|
426
310
|
|
|
427
|
-
|
|
428
|
-
console.log('Platform:', caps.platform); // 'browser' | 'node' | 'deno' | 'edge'
|
|
429
|
-
console.log('Persistent:', store.isPersistent); // true if using real storage
|
|
430
|
-
```
|
|
311
|
+
© [BigLogic Inc Canada](https://biglogic.ca)
|
package/docs/markdown/CACHE.md
CHANGED
|
@@ -26,8 +26,8 @@ cache.set('username', 'Mario');
|
|
|
26
26
|
cache.set('score', 1500);
|
|
27
27
|
|
|
28
28
|
// Read data
|
|
29
|
-
console.
|
|
30
|
-
console.
|
|
29
|
+
console.debug(cache.get('username')); // "Mario"
|
|
30
|
+
console.debug(cache.get('score')); // 1500
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
### Example 2: Intermediate
|
|
@@ -36,7 +36,7 @@ console.log(cache.get('score')); // 1500
|
|
|
36
36
|
// Store objects
|
|
37
37
|
cache.set('user', { name: 'Luigi', level: 5 });
|
|
38
38
|
const user = cache.get('user');
|
|
39
|
-
console.
|
|
39
|
+
console.debug(user.name); // "Luigi"
|
|
40
40
|
|
|
41
41
|
// Remove single item
|
|
42
42
|
cache.remove('username');
|