memorio 4.2.0 → 4.2.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/index.cjs +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/docs/README.md +0 -266
- package/docs/_config.yml +0 -1
- /package/{docs/SUMMARY.md → SUMMARY.md} +0 -0
- /package/{docs/markdown → markdown}/CACHE.md +0 -0
- /package/{docs/markdown → markdown}/CHANGELOG.md +0 -0
- /package/{docs/markdown → markdown}/DEVTOOLS.md +0 -0
- /package/{docs/markdown → markdown}/IDB.md +0 -0
- /package/{docs/markdown → markdown}/LOGGER.md +0 -0
- /package/{docs/markdown → markdown}/OBSERVER.md +0 -0
- /package/{docs/markdown → markdown}/PLATFORM.md +0 -0
- /package/{docs/markdown → markdown}/SECURITY.md +0 -0
- /package/{docs/markdown → markdown}/SESSION.md +0 -0
- /package/{docs/markdown → markdown}/STATE.md +0 -0
- /package/{docs/markdown → markdown}/STORE.md +0 -0
- /package/{docs/markdown → markdown}/USEOBSERVER.md +0 -0
package/index.cjs
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
package/docs/README.md
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
# [memorio](https://npmjs.com/package/memorio)
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-
|
|
5
|
-

|
|
6
|
-

|
|
7
|
-

|
|
8
|
-
|
|
9
|
-

|
|
10
|
-

|
|
11
|
-

|
|
12
|
-

|
|
13
|
-

|
|
14
|
-

|
|
15
|
-
|
|
16
|
-
**State management that actually makes your life easier.**
|
|
17
|
-
Zero friction. Zero bloat. Single import. Works everywhere JavaScript runs.
|
|
18
|
-
|
|
19
|
-
[Get Started](#-quick-start) · [API Reference](#-api-reference) · [License: MIT](https://opensource.org/licenses/MIT)
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## Why memorio?
|
|
24
|
-
|
|
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 + dphelper-manager extension | ❌ Extension | ❌ |
|
|
33
|
-
| **Running on the edge** | ✅ Workers, Deno | ⚠️ Limited | ⚠️ Limited |
|
|
34
|
-
|
|
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.
|
|
38
|
-
|
|
39
|
-
---
|
|
40
|
-
|
|
41
|
-
## Features
|
|
42
|
-
|
|
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.
|
|
59
|
-
|
|
60
|
-
---
|
|
61
|
-
|
|
62
|
-
## Installation options
|
|
63
|
-
|
|
64
|
-
```bash
|
|
65
|
-
# npm
|
|
66
|
-
npm i memorio
|
|
67
|
-
|
|
68
|
-
# pnpm
|
|
69
|
-
pnpm add memorio
|
|
70
|
-
|
|
71
|
-
# yarn
|
|
72
|
-
yarn add memorio
|
|
73
|
-
|
|
74
|
-
# React peer dep (optional, React ≥ 16.8)
|
|
75
|
-
npm i react react-dom
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## **Setup**
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
// memorio/index.ts — import once at your app entry point
|
|
82
|
-
import 'memorio'
|
|
83
|
-
|
|
84
|
-
// Memory
|
|
85
|
-
state.user = { name: 'Sara', role: 'admin' }
|
|
86
|
-
state.counter++
|
|
87
|
-
state.settings = { theme: 'dark', lang: 'it' }
|
|
88
|
-
|
|
89
|
-
// Call it "a store" but make it observe automatically
|
|
90
|
-
useObserver(
|
|
91
|
-
() => { console.debug('user changed:', state.user) },
|
|
92
|
-
[state.user]
|
|
93
|
-
)
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
That is it.
|
|
97
|
-
No context providers. No `<Store>` wrappers. No action creators.
|
|
98
|
-
Import → assign → done.
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
## API Reference
|
|
103
|
-
|
|
104
|
-
### `state` — Volatile reactive state
|
|
105
|
-
|
|
106
|
-
Global, Proxy-based, reactive. Access anywhere.
|
|
107
|
-
|
|
108
|
-
```javascript
|
|
109
|
-
// Set
|
|
110
|
-
state.user = { name: 'Sara', role: 'admin' }
|
|
111
|
-
state.items = [1, 2, 3]
|
|
112
|
-
|
|
113
|
-
// Get
|
|
114
|
-
const name = state.user.name // 'Sara'
|
|
115
|
-
|
|
116
|
-
// List all keys
|
|
117
|
-
console.debug(state.list) // ['user', 'items']
|
|
118
|
-
|
|
119
|
-
// Remove one key
|
|
120
|
-
state.remove('items')
|
|
121
|
-
|
|
122
|
-
// Clear all — lock/unlock available for frozen objects
|
|
123
|
-
state.removeAll()
|
|
124
|
-
state.lock() // freeze everything
|
|
125
|
-
state.unlock() // unfreeze
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### `store` — survives refresh
|
|
129
|
-
|
|
130
|
-
```javascript
|
|
131
|
-
store.set('preferences', { theme: 'dark' })
|
|
132
|
-
const prefs = store.get('preferences') // { theme: 'dark' } or null
|
|
133
|
-
store.remove('preferences')
|
|
134
|
-
store.removeAll()
|
|
135
|
-
console.debug(store.size(), 'chars stored')
|
|
136
|
-
console.debug(store.isPersistent) // true → real localStorage
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### `session` — dies with tab
|
|
140
|
-
|
|
141
|
-
```javascript
|
|
142
|
-
session.set('token', 'user-abc-123')
|
|
143
|
-
const token = session.get('token') // 'user-abc-123' or null
|
|
144
|
-
session.removeAll()
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### `cache` — In-memory, disappears on refresh
|
|
148
|
-
|
|
149
|
-
```javascript
|
|
150
|
-
cache.set('temp', computeExpensiveResult())
|
|
151
|
-
const result = cache.get('temp') // undefined or the value
|
|
152
|
-
cache.clear() // empty it all
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### `idb` — structured & typed
|
|
156
|
-
|
|
157
|
-
```javascript
|
|
158
|
-
await idb.db.create('my-db')
|
|
159
|
-
await idb.table.create('my-db', 'users')
|
|
160
|
-
await idb.data.set('my-db', 'users', { id: 1, name: 'Sara' })
|
|
161
|
-
const user = await idb.data.get('my-db', 'users', 1)
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### `observer` — Object watcher (DEPRECATED)
|
|
165
|
-
|
|
166
|
-
```javascript
|
|
167
|
-
globalThis.observer('state.user', (newVal, oldVal) => {
|
|
168
|
-
console.debug('user changed:', newVal, oldVal)
|
|
169
|
-
})
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### `useObserver` — React observer hook
|
|
173
|
-
|
|
174
|
-
Available globally after `import 'memorio'`.
|
|
175
|
-
|
|
176
|
-
```jsx
|
|
177
|
-
import 'memorio'
|
|
178
|
-
|
|
179
|
-
function Counter() {
|
|
180
|
-
const [, forceUpdate] = useReducer(x => x + 1, 0)
|
|
181
|
-
|
|
182
|
-
useObserver(forceUpdate, [state.counter])
|
|
183
|
-
// State path auto-discovered during render — no manual deps needed
|
|
184
|
-
|
|
185
|
-
return <div>Count: {state.counter}</div>
|
|
186
|
-
}
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
### `devtools` — inspect everything in one call
|
|
190
|
-
|
|
191
|
-
```javascript
|
|
192
|
-
memorio.devtools.inspect() // pretty-prints state, store, session, cache
|
|
193
|
-
memorio.devtools.stats() // { stateKeys, storeKeys, sessionKeys, ... }
|
|
194
|
-
memorio.devtools.clear('state')
|
|
195
|
-
memorio.devtools.exportData() // JSON snapshot
|
|
196
|
-
$state // console shortcut — same as globalThis.state
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
> **Browser Extension Integration:** When used with dphelper-manager browser extension, memorio's global state namespace is automatically detected and visualized through a dedicated DevTools panel, providing time-travel debugging and structural guardrails.
|
|
200
|
-
|
|
201
|
-
### `logger` — track every change
|
|
202
|
-
|
|
203
|
-
```javascript
|
|
204
|
-
memorio.logger.configure({ enabled: true, logToConsole: true })
|
|
205
|
-
memorio.logger.getHistory() // [{ timestamp, module, action, path, value }, ...]
|
|
206
|
-
memorio.logger.getStats() // { total, state, set, get, ... }
|
|
207
|
-
memorio.logger.exportLogs() // JSON string of all history
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
### Platform detection
|
|
211
|
-
|
|
212
|
-
Access via `memorio.*`:
|
|
213
|
-
|
|
214
|
-
```javascript
|
|
215
|
-
memorio.isBrowser() // true in Chrome, Firefox, Safari
|
|
216
|
-
memorio.isNode() // true in Node.js
|
|
217
|
-
memorio.isDeno() // true in Deno
|
|
218
|
-
memorio.isEdge() // true in Cloudflare Workers, Vercel Edge
|
|
219
|
-
|
|
220
|
-
const caps = memorio.getCapabilities()
|
|
221
|
-
// { platform: 'browser', hasLocalStorage: true, hasIndexedDB: true, ... }
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
### Context (multi-tenant)
|
|
225
|
-
|
|
226
|
-
```javascript
|
|
227
|
-
memorio.createContext('tenant-name')
|
|
228
|
-
memorio.listContexts()
|
|
229
|
-
memorio.deleteContext('context-id')
|
|
230
|
-
memorio.isolate('tenant-name')
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
---
|
|
234
|
-
|
|
235
|
-
## Cross-Platform
|
|
236
|
-
|
|
237
|
-
Memorio runs in every JavaScript environment, with automatic fallbacks.
|
|
238
|
-
|
|
239
|
-
| | Browser | Node.js | Deno | Edge / Workers |
|
|
240
|
-
|---|---|---|---|---|
|
|
241
|
-
| `state` | ✅ | ✅ | ✅ | ✅ |
|
|
242
|
-
| `observer` / `useObserver` | ✅ | ✅ | ✅ | ✅ |
|
|
243
|
-
| `cache` | ✅ | ✅ | ✅ | ✅ |
|
|
244
|
-
| `store` | ✅ localStorage | ⚠️ memory | ⚠️ memory | ✅ localStorage |
|
|
245
|
-
| `session` | ✅ sessionStorage | ⚠️ memory | ⚠️ memory | ✅ sessionStorage |
|
|
246
|
-
| `idb` | ✅ IndexedDB | ❌ | ❌ | ⚠️ |
|
|
247
|
-
| `devtools` | ✅ | ❌ | ❌ | ⚠️ |
|
|
248
|
-
|
|
249
|
-
> **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.
|
|
250
|
-
|
|
251
|
-
---
|
|
252
|
-
|
|
253
|
-
## Security
|
|
254
|
-
|
|
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)
|
|
261
|
-
|
|
262
|
-
---
|
|
263
|
-
|
|
264
|
-
## License
|
|
265
|
-
|
|
266
|
-
MIT © [Dario Passariello](https://dario.passariello.ca)
|
package/docs/_config.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
theme: jekyll-theme-modernist
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|