memorio 4.5.3 → 4.6.4
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 +157 -94
- package/SUMMARY.md +1 -0
- package/index.cjs +999 -893
- package/index.d.ts +18 -8
- package/index.js +970 -887
- package/markdown/CHANGELOG.md +71 -0
- package/markdown/IMPORT.md +139 -0
- package/markdown/PLATFORM.md +7 -3
- package/markdown/STATE.md +3 -0
- package/markdown/STORE.md +3 -0
- package/package.json +1 -1
- package/types/exports.d.ts +58 -0
- package/CODE_OF_CONDUCT.md +0 -108
- package/CONTRIBUTING.md +0 -105
- package/COPYRIGHT.md +0 -6
- package/LICENSE.md +0 -21
- package/SECURITY.md +0 -48
- package/llms.txt +0 -405
package/README.md
CHANGED
|
@@ -1,68 +1,67 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 🧠 memorio
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
|
-

|
|
6
|
-

|
|
5
|
+
[](https://npmjs.com/package/memorio)
|
|
6
|
+
[](https://npmjs.com/package/memorio)
|
|
7
|
+
[](https://nodejs.org)
|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+

|
|
14
|
+

|
|
7
15
|
|
|
8
|
-
|
|
9
|
-

|
|
16
|
+
**State + Observer + Store + IDB. One import. Zero config.**
|
|
10
17
|
|
|
11
|
-
|
|
12
|
-

|
|
13
|
-

|
|
14
|
-

|
|
18
|
+
Memorio is a universal, cross-platform state management library for JavaScript and TypeScript. Reactive state, persistent store, session cache, IndexedDB, observer system, React hook, devtools, and logger — all from one import, zero dependencies.
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-

|
|
18
|
-

|
|
19
|
-

|
|
20
|
-
|
|
21
|
-

|
|
22
|
-

|
|
23
|
-

|
|
20
|
+
---
|
|
24
21
|
|
|
25
|
-
## Why memorio?
|
|
22
|
+
## ✨ Why memorio?
|
|
26
23
|
|
|
27
|
-
| | memorio | Redux | Zustand |
|
|
24
|
+
| Feature | 🔥 memorio | Redux | Zustand |
|
|
28
25
|
|---|---|---|---|
|
|
29
|
-
| **Setup** | 1 import | Boilerplate hell | Moderate |
|
|
30
|
-
| **Dependencies** | **Zero** | Many | Few |
|
|
31
|
-
| **TypeScript** | ✅ Native | ✅ | ✅ |
|
|
32
|
-
| **Binary storage** | ✅ Built-in IDB | ❌ Add-on | ❌ |
|
|
33
|
-
| **Observer** | ✅ Built-in | ❌ Add-on | ❌ |
|
|
34
|
-
| **DevTools** | ✅ Built-in + dphelper-manager
|
|
35
|
-
| **
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
| **Setup** | ✅ **1 import** | ❌ Boilerplate hell | ⚠️ Moderate |
|
|
27
|
+
| **Dependencies** | ✅ **Zero** | ❌ Many | ⚠️ Few |
|
|
28
|
+
| **TypeScript** | ✅ Native | ✅ Yes | ✅ Yes |
|
|
29
|
+
| **Binary storage** | ✅ Built-in IDB | ❌ Add-on | ❌ Add-on |
|
|
30
|
+
| **Observer** | ✅ Built-in | ❌ Add-on | ❌ Add-on |
|
|
31
|
+
| **DevTools** | ✅ Built-in + dphelper-manager | ⚠️ Extension | ⚠️ Extension |
|
|
32
|
+
| **Edge runtime** | ✅ Workers, Deno | ❌ Limited | ❌ Limited |
|
|
33
|
+
| **Learning curve** | ✅ **5 minutes** | ❌ Hours | ⚠️ 30 min |
|
|
34
|
+
| **Boilerplate** | ✅ **None** | ❌ Tons | ⚠️ Some |
|
|
35
|
+
| **React support** | ✅ `useObserver` hook | ✅ `connect` | ✅ `useSyncExternalStore` |
|
|
36
|
+
| **Context isolation** | ✅ Multi-tenant | ⚠️ Manual | ⚠️ Manual |
|
|
37
|
+
|
|
38
|
+
Zero dependencies. Lightweight. One import.
|
|
40
39
|
|
|
41
40
|
---
|
|
42
41
|
|
|
43
|
-
## Features
|
|
42
|
+
## 🚀 Features
|
|
44
43
|
|
|
45
44
|
| | |
|
|
46
45
|
|---|---|
|
|
47
|
-
| **`state`** | Reactive, volatile state
|
|
48
|
-
| **`store`** | localStorage persistence
|
|
49
|
-
| **`session`** | sessionStorage
|
|
50
|
-
| **`cache`** | In-memory
|
|
51
|
-
| **`idb`** | IndexedDB with typed tables
|
|
52
|
-
| **`observer`** |
|
|
53
|
-
| **`useObserver`** | React hook with auto-discovery
|
|
54
|
-
| **`dispatch`** | Event system
|
|
55
|
-
| **`devtools`** |
|
|
46
|
+
| **`state`** | Reactive, Proxy-based volatile state |
|
|
47
|
+
| **`store`** | localStorage persistence (survives refresh) |
|
|
48
|
+
| **`session`** | sessionStorage (dies with tab) |
|
|
49
|
+
| **`cache`** | In-memory fastest cache |
|
|
50
|
+
| **`idb`** | IndexedDB with typed tables, structured and async |
|
|
51
|
+
| **`observer`** | Legacy object watcher for vanilla JS |
|
|
52
|
+
| **`useObserver`** | React hook with auto-discovery |
|
|
53
|
+
| **`dispatch`** | Event system: listen, emit, subscribe |
|
|
54
|
+
| **`devtools`** | Inspect everything in console |
|
|
56
55
|
| **`logger`** | Auto-log every state change with timestamps |
|
|
57
|
-
| **
|
|
58
|
-
| **Platform
|
|
56
|
+
| **Context isolation** | Per-request / multi-tenant namespace |
|
|
57
|
+
| **Platform detection** | `isBrowser`, `isNode`, `isDeno`, `isEdge` |
|
|
59
58
|
|
|
60
59
|
No Zustand. No Redux. No provider boilerplate.
|
|
61
|
-
|
|
60
|
+
**Import → assign → done.**
|
|
62
61
|
|
|
63
62
|
---
|
|
64
63
|
|
|
65
|
-
## Installation
|
|
64
|
+
## 📦 Installation
|
|
66
65
|
|
|
67
66
|
```bash
|
|
68
67
|
# npm
|
|
@@ -74,20 +73,21 @@ pnpm add memorio
|
|
|
74
73
|
# yarn
|
|
75
74
|
yarn add memorio
|
|
76
75
|
|
|
77
|
-
# React peer dep (optional, React
|
|
76
|
+
# React peer dep (optional, React >= 16.8)
|
|
78
77
|
npm i react react-dom
|
|
79
78
|
```
|
|
80
79
|
|
|
81
|
-
|
|
80
|
+
---
|
|
82
81
|
|
|
83
|
-
|
|
84
|
-
// IMPORT ONCE AT YOUR APP ENTRY POINT
|
|
82
|
+
## 🎯 Quick Start
|
|
85
83
|
|
|
86
|
-
|
|
87
|
-
```
|
|
84
|
+
### Global style (original)
|
|
88
85
|
|
|
89
86
|
```typescript
|
|
90
|
-
//
|
|
87
|
+
// import 'memorio' once at your app entry point
|
|
88
|
+
import 'memorio'
|
|
89
|
+
|
|
90
|
+
// state is now available everywhere
|
|
91
91
|
state.user = { name: 'Sara', role: 'admin' }
|
|
92
92
|
state.counter++
|
|
93
93
|
state.settings = { theme: 'dark', lang: 'it' }
|
|
@@ -100,19 +100,55 @@ useObserver(
|
|
|
100
100
|
|
|
101
101
|
// Vanilla JS - event system
|
|
102
102
|
memorio.dispatch.listen('state.user', (event) => {
|
|
103
|
-
console.debug('user changed:', event.detail)
|
|
103
|
+
console.debug('user changed:', event.detail)
|
|
104
104
|
})
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
### Classic `import` style (new)
|
|
108
|
+
|
|
109
|
+
Every module is also a named export. Same instances, explicit dependencies.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// ESM
|
|
113
|
+
import {
|
|
114
|
+
state,
|
|
115
|
+
store,
|
|
116
|
+
session,
|
|
117
|
+
cache,
|
|
118
|
+
idb,
|
|
119
|
+
observer,
|
|
120
|
+
useObserver,
|
|
121
|
+
dispatch,
|
|
122
|
+
memorio
|
|
123
|
+
} from 'memorio'
|
|
124
|
+
|
|
125
|
+
state.user = { name: 'Sara' }
|
|
126
|
+
store.set('theme', 'dark')
|
|
127
|
+
|
|
128
|
+
// CJS
|
|
129
|
+
const { state, store, memorio } = require('memorio')
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
// React with named imports
|
|
134
|
+
import { useObserver, state } from 'memorio'
|
|
135
|
+
|
|
136
|
+
function Counter() {
|
|
137
|
+
const [, forceUpdate] = useReducer(x => x + 1, 0)
|
|
138
|
+
|
|
139
|
+
useObserver(forceUpdate, [state.counter])
|
|
140
|
+
|
|
141
|
+
return <div>Count: {state.counter}</div>
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Both styles share the exact same instances. Pick whichever fits your project.
|
|
110
146
|
|
|
111
147
|
---
|
|
112
148
|
|
|
113
|
-
## API Reference
|
|
149
|
+
## 📚 API Reference
|
|
114
150
|
|
|
115
|
-
### `state` —
|
|
151
|
+
### `state` — Reactive volatile state
|
|
116
152
|
|
|
117
153
|
Global, Proxy-based, reactive. Access anywhere.
|
|
118
154
|
|
|
@@ -130,13 +166,17 @@ console.debug(state.list) // ['user', 'items']
|
|
|
130
166
|
// Remove one key
|
|
131
167
|
state.remove('items')
|
|
132
168
|
|
|
133
|
-
// Clear all
|
|
169
|
+
// Clear all
|
|
134
170
|
state.removeAll()
|
|
135
|
-
|
|
136
|
-
|
|
171
|
+
|
|
172
|
+
// Lock/unlock (prevents modifications)
|
|
173
|
+
state.config = { maxUsers: 100 }
|
|
174
|
+
state.config.lock()
|
|
175
|
+
state.config.maxUsers = 200 // Error: state 'config' is locked
|
|
176
|
+
state.config.unlock()
|
|
137
177
|
```
|
|
138
178
|
|
|
139
|
-
### `store` —
|
|
179
|
+
### `store` — Survives refresh
|
|
140
180
|
|
|
141
181
|
```javascript
|
|
142
182
|
store.set('preferences', { theme: 'dark' })
|
|
@@ -144,10 +184,10 @@ const prefs = store.get('preferences') // { theme: 'dark' } or null
|
|
|
144
184
|
store.remove('preferences')
|
|
145
185
|
store.removeAll()
|
|
146
186
|
console.debug(store.size(), 'chars stored')
|
|
147
|
-
console.debug(store.isPersistent) // true
|
|
187
|
+
console.debug(store.isPersistent) // true -> real localStorage
|
|
148
188
|
```
|
|
149
189
|
|
|
150
|
-
### `session` —
|
|
190
|
+
### `session` — Dies with tab
|
|
151
191
|
|
|
152
192
|
```javascript
|
|
153
193
|
session.set('token', 'user-abc-123')
|
|
@@ -163,7 +203,7 @@ const result = cache.get('temp') // undefined or the value
|
|
|
163
203
|
cache.clear() // empty it all
|
|
164
204
|
```
|
|
165
205
|
|
|
166
|
-
### `idb` —
|
|
206
|
+
### `idb` — Structured & typed
|
|
167
207
|
|
|
168
208
|
```javascript
|
|
169
209
|
await idb.db.create('my-db')
|
|
@@ -172,44 +212,56 @@ await idb.data.set('my-db', 'users', { id: 1, name: 'Sara' })
|
|
|
172
212
|
const user = await idb.data.get('my-db', 'users', 1)
|
|
173
213
|
```
|
|
174
214
|
|
|
175
|
-
### `observer` — Object watcher
|
|
215
|
+
### `observer` — Object watcher (legacy)
|
|
176
216
|
|
|
177
217
|
```javascript
|
|
178
|
-
|
|
218
|
+
observer('state.user', (newVal, oldVal) => {
|
|
179
219
|
console.debug('user changed:', newVal, oldVal)
|
|
180
220
|
})
|
|
181
221
|
```
|
|
182
222
|
|
|
183
223
|
### `useObserver` — React observer hook
|
|
184
224
|
|
|
185
|
-
Available globally after `import 'memorio'`.
|
|
186
|
-
|
|
187
225
|
```jsx
|
|
188
|
-
import 'memorio'
|
|
226
|
+
import { useObserver, state } from 'memorio'
|
|
189
227
|
|
|
190
228
|
function Counter() {
|
|
191
229
|
const [, forceUpdate] = useReducer(x => x + 1, 0)
|
|
192
230
|
|
|
193
231
|
useObserver(forceUpdate, [state.counter])
|
|
194
|
-
// State path auto-discovered during render — no manual deps needed
|
|
195
232
|
|
|
196
233
|
return <div>Count: {state.counter}</div>
|
|
197
234
|
}
|
|
198
235
|
```
|
|
199
236
|
|
|
200
|
-
### `
|
|
237
|
+
### `dispatch` — Event system
|
|
238
|
+
|
|
239
|
+
```javascript
|
|
240
|
+
// Listen
|
|
241
|
+
memorio.dispatch.listen('state.user', (event) => {
|
|
242
|
+
console.debug('user changed:', event.detail)
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
// Emit
|
|
246
|
+
memorio.dispatch.set('state.user', { detail: { name: 'state.user' } })
|
|
247
|
+
|
|
248
|
+
// Remove
|
|
249
|
+
memorio.dispatch.remove('state.user')
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### `devtools` — Inspect everything
|
|
201
253
|
|
|
202
254
|
```javascript
|
|
203
255
|
memorio.devtools.inspect() // pretty-prints state, store, session, cache
|
|
204
256
|
memorio.devtools.stats() // { stateKeys, storeKeys, sessionKeys, ... }
|
|
205
257
|
memorio.devtools.clear('state')
|
|
206
258
|
memorio.devtools.exportData() // JSON snapshot
|
|
207
|
-
$state // console shortcut
|
|
259
|
+
$state // console shortcut -> globalThis.state
|
|
208
260
|
```
|
|
209
261
|
|
|
210
|
-
> **Browser Extension
|
|
262
|
+
> 💡 **Browser Extension**: When used with [dphelper-manager](https://chrome.google.com/webstore/detail/dphelper-manager-dev-tool/oppppldaoknfddeikfloonnialijngbk), Memorio's global state is automatically detected and visualized with time-travel debugging.
|
|
211
263
|
|
|
212
|
-
### `logger` —
|
|
264
|
+
### `logger` — Track every change
|
|
213
265
|
|
|
214
266
|
```javascript
|
|
215
267
|
memorio.logger.configure({ enabled: true, logToConsole: true })
|
|
@@ -218,9 +270,9 @@ memorio.logger.getStats() // { total, state, set, get, ... }
|
|
|
218
270
|
memorio.logger.exportLogs() // JSON string of all history
|
|
219
271
|
```
|
|
220
272
|
|
|
221
|
-
|
|
273
|
+
---
|
|
222
274
|
|
|
223
|
-
|
|
275
|
+
## 🌍 Platform detection
|
|
224
276
|
|
|
225
277
|
```javascript
|
|
226
278
|
memorio.isBrowser() // true in Chrome, Firefox, Safari
|
|
@@ -232,31 +284,42 @@ const caps = memorio.getCapabilities()
|
|
|
232
284
|
// { platform: 'browser', hasLocalStorage: true, hasIndexedDB: true, ... }
|
|
233
285
|
```
|
|
234
286
|
|
|
235
|
-
|
|
287
|
+
Named exports work too:
|
|
236
288
|
|
|
237
|
-
```
|
|
238
|
-
memorio
|
|
239
|
-
memorio.listContexts()
|
|
240
|
-
memorio.deleteContext('context-id')
|
|
241
|
-
memorio.isolate('tenant-name')
|
|
289
|
+
```typescript
|
|
290
|
+
import { isBrowser, isNode, getCapabilities } from 'memorio'
|
|
242
291
|
```
|
|
243
292
|
|
|
244
293
|
---
|
|
245
294
|
|
|
246
|
-
##
|
|
295
|
+
## 🏢 Context isolation (multi-tenant)
|
|
296
|
+
|
|
297
|
+
```javascript
|
|
298
|
+
// Create isolated context
|
|
299
|
+
const ctx = memorio.createContext('tenant-123')
|
|
300
|
+
|
|
301
|
+
// Use context storage (prefix: 'tenant-123-key')
|
|
302
|
+
ctx.state.user = { name: 'Isolated' }
|
|
303
|
+
ctx.store.set('settings', { theme: 'dark' })
|
|
304
|
+
ctx.session.set('token', 'abc123')
|
|
247
305
|
|
|
248
|
-
|
|
306
|
+
// Context is completely isolated from global state
|
|
307
|
+
console.debug(state.user) // undefined
|
|
249
308
|
|
|
250
|
-
Manage
|
|
309
|
+
// Manage contexts
|
|
310
|
+
memorio.listContexts() // ['tenant-123']
|
|
311
|
+
memorio.deleteContext('tenant-123')
|
|
312
|
+
```
|
|
251
313
|
|
|
252
|
-
|
|
314
|
+
Named exports:
|
|
253
315
|
|
|
254
|
-
|
|
255
|
-
|
|
316
|
+
```typescript
|
|
317
|
+
import { createContext, listContexts, deleteContext, isolate } from 'memorio'
|
|
318
|
+
```
|
|
256
319
|
|
|
257
320
|
---
|
|
258
321
|
|
|
259
|
-
## Cross-Platform
|
|
322
|
+
## 🖥️ Cross-Platform
|
|
260
323
|
|
|
261
324
|
Memorio runs in every JavaScript environment, with automatic fallbacks.
|
|
262
325
|
|
|
@@ -265,16 +328,16 @@ Memorio runs in every JavaScript environment, with automatic fallbacks.
|
|
|
265
328
|
| `state` | ✅ | ✅ | ✅ | ✅ |
|
|
266
329
|
| `observer` / `useObserver` | ✅ | ✅ | ✅ | ✅ |
|
|
267
330
|
| `cache` | ✅ | ✅ | ✅ | ✅ |
|
|
268
|
-
| `store` |
|
|
269
|
-
| `session` |
|
|
270
|
-
| `idb` |
|
|
331
|
+
| `store` | localStorage | memory | memory | localStorage |
|
|
332
|
+
| `session` | sessionStorage | memory | memory | sessionStorage |
|
|
333
|
+
| `idb` | IndexedDB | ❌ | ❌ | ⚠️ |
|
|
271
334
|
| `devtools` | ✅ | ❌ | ❌ | ⚠️ |
|
|
272
335
|
|
|
273
336
|
> **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.
|
|
274
337
|
|
|
275
338
|
---
|
|
276
339
|
|
|
277
|
-
## Security
|
|
340
|
+
## 🔒 Security
|
|
278
341
|
|
|
279
342
|
- Zero production dependencies — no supply chain surprises
|
|
280
343
|
- NIST & NSA aligned — enterprise-grade security standards
|
|
@@ -284,6 +347,6 @@ Memorio runs in every JavaScript environment, with automatic fallbacks.
|
|
|
284
347
|
|
|
285
348
|
---
|
|
286
349
|
|
|
287
|
-
## License
|
|
350
|
+
## 📄 License
|
|
288
351
|
|
|
289
352
|
MIT © [Dario Passariello](https://dario.passariello.ca)
|
package/SUMMARY.md
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* [Platform & Context Isolation](markdown/PLATFORM.md) - Cross-platform support, session isolation
|
|
19
19
|
* [Security](markdown/SECURITY.md) - Security measures, vulnerability prevention
|
|
20
20
|
* [Changelog](markdown/CHANGELOG.md) - Version history and migration guide
|
|
21
|
+
* [Classic Import](markdown/IMPORT.md) - Named export guide for `import { state } from 'memorio'`
|
|
21
22
|
|
|
22
23
|
## Additional Resources
|
|
23
24
|
|