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 CHANGED
@@ -1,68 +1,67 @@
1
- # [memorio](https://npmjs.com/package/memorio)
1
+ # 🧠 memorio
2
2
 
3
3
  ![image](https://raw.githubusercontent.com/passariello/container/refs/heads/main/memorio/banner.svg)
4
4
 
5
- ![version](https://img.shields.io/npm/v/memorio.svg)
6
- ![downloads](https://img.shields.io/npm/dm/memorio.svg)
5
+ [![npm version](https://img.shields.io/npm/v/memorio.svg)](https://npmjs.com/package/memorio)
6
+ [![npm downloads](https://img.shields.io/npm/dm/memorio.svg)](https://npmjs.com/package/memorio)
7
+ [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D18-gray?logo=node.js)](https://nodejs.org)
8
+ ![Browser](https://img.shields.io/badge/Browser-Chrome%20/%20Firefox%20/%20Safari-gray?logo=google-chrome)
9
+ ![Deno](https://img.shields.io/badge/Deno-compatible-gray?logo=deno)
10
+ ![Edge Workers](https://img.shields.io/badge/Edge%20Workers-compatible-gray)
11
+ ![TypeScript](https://img.shields.io/badge/TypeScript-native-gray?logo=typescript)
12
+ ![React](https://img.shields.io/badge/React-compatible-gray?logo=react)
13
+ ![Tests](https://img.shields.io/badge/tests-101%20passed-green)
14
+ ![License](https://img.shields.io/badge/License-MIT-gray)
7
15
 
8
- ![Snyk](https://img.shields.io/badge/Snyk-gray?logo=Snyk)
9
- ![Socket](https://img.shields.io/badge/Socket-gray?logo=Socket)
16
+ **State + Observer + Store + IDB. One import. Zero config.**
10
17
 
11
- ![Node.js](https://img.shields.io/badge/Node.js-gray?logo=node.js)
12
- ![Browser](https://img.shields.io/badge/Browser-gray?logo=google-chrome)
13
- ![Deno](https://img.shields.io/badge/Deno-gray?logo=deno)
14
- ![tsup](https://img.shields.io/badge/tsup-gray?logo=esbuild)
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
- ![React](https://img.shields.io/badge/React-gray?logo=React)
17
- ![TypeScript](https://img.shields.io/badge/TypeScript-gray?logo=typescript)
18
- ![Javascript](https://img.shields.io/badge/Javascript-gray?logo=Javascript)
19
- ![Jquery](https://img.shields.io/badge/jquery-gray?logo=jquery)
20
-
21
- ![Vitest](https://img.shields.io/badge/Vitest-gray?logo=vitest)
22
- ![OXlint](https://img.shields.io/badge/Oxlint-gray?logo=oxc)
23
- ![Playwright](https://img.shields.io/badge/Playwright-gray?logo=playwright)
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 extension | Extension | |
35
- | **Running on the edge** | ✅ Workers, Deno | ⚠️ Limited | ⚠️ Limited |
36
-
37
- If you need a `store` on the server. A `cache` in the edge worker.
38
- Session isolation in Next.js. IndexedDB in a Service Worker.
39
- All from one import, zero configuration.
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 — observe with `useObserver` (React) or `dispatch.listen` (vanilla JS) |
48
- | **`store`** | localStorage persistence survives refresh |
49
- | **`session`** | sessionStorage dies with the tab |
50
- | **`cache`** | In-memory cache — fastest read possible |
51
- | **`idb`** | IndexedDB with typed tables structured, persistent, async |
52
- | **`observer`** | Object watcher - legacy API for vanilla JS |
53
- | **`useObserver`** | React hook with auto-discovery — drops in |
54
- | **`dispatch`** | Event system for vanilla JS — listen, emit, subscribe |
55
- | **`devtools`** | `memorio.devtools.inspect()` — see everything in console |
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
- | **Session Isolation** | Every browser tab, every request: isolated namespace |
58
- | **Platform Detection** | `isBrowser`, `isNode`, `isDeno`, `isEdge` |
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
- Just import it and start storing.
60
+ **Import assign done.**
62
61
 
63
62
  ---
64
63
 
65
- ## Installation options
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 16.8)
76
+ # React peer dep (optional, React >= 16.8)
78
77
  npm i react react-dom
79
78
  ```
80
79
 
81
- ## **Setup**
80
+ ---
82
81
 
83
- ```typescript
84
- // IMPORT ONCE AT YOUR APP ENTRY POINT
82
+ ## 🎯 Quick Start
85
83
 
86
- import 'memorio'
87
- ```
84
+ ### Global style (original)
88
85
 
89
86
  ```typescript
90
- // Memory
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
- That is it.
108
- No context providers. No `<Store>` wrappers. No action creators.
109
- Import assign done.
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` — Volatile reactive 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 — lock/unlock available for frozen objects
169
+ // Clear all
134
170
  state.removeAll()
135
- state.lock() // freeze everything
136
- state.unlock() // unfreeze
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` — survives refresh
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 real localStorage
187
+ console.debug(store.isPersistent) // true -> real localStorage
148
188
  ```
149
189
 
150
- ### `session` — dies with tab
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` — structured & typed
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
- globalThis.observer('state.user', (newVal, oldVal) => {
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
- ### `devtools` — inspect everything in one call
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 same as globalThis.state
259
+ $state // console shortcut -> globalThis.state
208
260
  ```
209
261
 
210
- > **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.
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` — track every change
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
- ### Platform detection
273
+ ---
222
274
 
223
- Access via `memorio.*`:
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
- ### Context (multi-tenant)
287
+ Named exports work too:
236
288
 
237
- ```javascript
238
- memorio.createContext('tenant-name')
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
- ## Browser Extension (Chrome/Edge)
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
- ![dphelper Banner](https://raw.githubusercontent.com/passariello/container/refs/heads/main/dphelper/assets/images/screenshot.png)
306
+ // Context is completely isolated from global state
307
+ console.debug(state.user) // undefined
249
308
 
250
- Manage your `Memorio` on `dphelper Manager Browser Extension*` environment, monitor memory usage, and access documentation directly from your browser.
309
+ // Manage contexts
310
+ memorio.listContexts() // ['tenant-123']
311
+ memorio.deleteContext('tenant-123')
312
+ ```
251
313
 
252
- *Need to install dphelper npm
314
+ Named exports:
253
315
 
254
- - [Download for Chrome](https://chrome.google.com/webstore/detail/dphelper-manager-dev-tool/oppppldaoknfddeikfloonnialijngbk)
255
- - [Download for Edge](https://microsoftedge.microsoft.com/addons/detail/dphelper-manager-dev-to/kphabkbdpaljlfagldhojilhfammepnk)
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` | localStorage | ⚠️ memory | ⚠️ memory | localStorage |
269
- | `session` | sessionStorage | ⚠️ memory | ⚠️ memory | sessionStorage |
270
- | `idb` | IndexedDB | ❌ | ❌ | ⚠️ |
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