memorio 5.0.0 β†’ 5.1.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.
Files changed (60) hide show
  1. package/README.md +98 -435
  2. package/SECURITY.md +152 -42
  3. package/SUMMARY.md +1 -1
  4. package/adr/001-state-proxy-model.md +95 -96
  5. package/adr/002-observer-semantics.md +179 -180
  6. package/adr/003-deep-mutation-semantics.md +7 -8
  7. package/adr/004-array-mutation-semantics.md +127 -128
  8. package/adr/005-scheduler-contract.md +148 -149
  9. package/adr/006-context-isolation.md +91 -92
  10. package/adr/007-mutation-records.md +5 -6
  11. package/adr/008-transactions.md +6 -7
  12. package/adr/009-history-model.md +6 -7
  13. package/adr/README.md +46 -46
  14. package/adr/template.md +48 -49
  15. package/bin/cli.js +68 -0
  16. package/global.cjs +1462 -323
  17. package/global.js +1459 -324
  18. package/index.cjs +1462 -323
  19. package/index.d.ts +1 -0
  20. package/index.js +1459 -324
  21. package/llms.txt +42 -5
  22. package/markdown/AUDIT-REPORT.md +7 -8
  23. package/markdown/CACHE.md +190 -99
  24. package/markdown/DEVTOOLS.md +0 -1
  25. package/markdown/DISPATCH.md +0 -1
  26. package/markdown/HISTORY.md +0 -1
  27. package/markdown/IDB.md +0 -1
  28. package/markdown/IMPORT.md +0 -1
  29. package/markdown/INSPECT.md +0 -1
  30. package/markdown/LOGGER.md +0 -1
  31. package/markdown/MEMORY-ATTACHMENT.md +0 -1
  32. package/markdown/MEMORY.md +0 -1
  33. package/markdown/OBSERVER.md +0 -1
  34. package/markdown/PLATFORM.md +277 -271
  35. package/markdown/REDUX.md +54 -0
  36. package/markdown/SCHEMA.md +0 -1
  37. package/markdown/SESSION.md +0 -1
  38. package/markdown/SQLITE.md +0 -1
  39. package/markdown/STATE.md +0 -1
  40. package/markdown/STORE.md +0 -1
  41. package/markdown/SYNC.md +0 -1
  42. package/markdown/TYPED.md +0 -1
  43. package/markdown/USEOBSERVER.md +0 -1
  44. package/modules/redux.cjs +381 -10
  45. package/modules/redux.cjs.map +1 -1
  46. package/modules/redux.js +381 -10
  47. package/modules/redux.js.map +1 -1
  48. package/package.json +14 -2
  49. package/types/broadcast.d.ts +61 -0
  50. package/types/computed.d.ts +96 -0
  51. package/types/encryption.d.ts +129 -0
  52. package/types/exports.d.ts +9 -0
  53. package/types/memorio.d.ts +19 -12
  54. package/types/security.d.ts +67 -0
  55. package/types/session.d.ts +23 -5
  56. package/types/store.d.ts +19 -3
  57. package/vsix/memorio.vsix +0 -0
  58. package/markdown/CHANGELOG.md +0 -243
  59. package/markdown/PROJECT.md +0 -311
  60. package/markdown/SECURITY.md +0 -330
@@ -1,243 +0,0 @@
1
- > **Status:** Published
2
- > **Date:** 2026-09-12
3
- > **Deciders:** Memorio 5.x Core Team, BigLogic
4
- > **Scope**: Project Documentation
5
- > **Standard**: Memorio Documentation Standard v5
6
- >
7
- ---
8
- # Changelog - Memorio
9
-
10
- All notable changes to this project will be documented in this file.
11
-
12
- ---
13
-
14
- ## Unreleased - Module Duplication Fix & Architecture Cleanup
15
-
16
- ### πŸ› Bug Fixes
17
-
18
- - **Module duplication / state reset**: Fixed issue where importing memorio via different paths (ESM `dist/index.js`, CJS `index.cjs`, package name `memorio`, absolute file path) created separate module instances, each with its own empty proxy. This caused `globalThis.state` to be overwritten with a fresh empty proxy on second import, resetting all state data.
19
- - All modules (`state`, `store`, `session`, `cache`) now use private `globalThis` singleton keys (`__memorio_state_instance__`, `__memorio_store_instance__`, `__memorio_session_instance__`, `__memorio_cache_instance__`) to guarantee a single shared instance across all import paths.
20
- - `memorio.global()` in `core/global.ts` now guards with `if (!(key in globalThis))` to prevent overwriting existing dev globals - protecting against module duplication resetting state.
21
- - **Removed `__DEV__` build-time constant**: Replaced all bare `__DEV__` references with `DEV`/`PROD` from `core/env.ts` (runtime detection via `process.env.NODE_ENV`). Eliminates `ReferenceError: __DEV__ is not defined` in browser environments without bundler `define` config. Production builds now have **0** `__DEV__` references.
22
-
23
- ### πŸ”§ Code Refactoring
24
-
25
- - **Script organization**: Moved debug/verification scripts from root to `tests/scripts/`:
26
- - `check-dev-mode.mjs` β†’ `tests/scripts/check-dev-mode.mjs`
27
- - `update-node-modules-memorio.cjs` β†’ `tests/scripts/update-node-modules-memorio.cjs`
28
- - `test-state-persist.ts` β†’ `tests/scripts/test-state-persist.ts`
29
- - `tests/test-nav.mjs` β†’ `tests/playwright/test-nav.mjs`
30
-
31
- ### πŸ“ Documentation Updates
32
-
33
- - `docs/README.md`: Documented the singleton pattern and module deduplication strategy in the "How it works" section.
34
-
35
- ### 🧹 Code Quality
36
-
37
- - **Removed dead code**: `serialize` function in `functions/memory/journal.ts` (unused)
38
- - **Fixed unused parameter**: `tick(incoming)` in `core/hlc.ts` renamed to `tick(_incoming)`
39
- - **Fixed regex escapes**: Removed unnecessary `\.` escapes in `functions/memory/index.ts` path regexes
40
- - **DevTools reliability**: Replaced `globalThis.state/store/session/cache` access with singleton instance keys (`__memorio_*_instance__`) to prevent `ReferenceError` in production and avoid circular imports
41
- - **Console consistency**: Changed `console.error` to `console.debug` in devtools error handling, removed emoji prefixes
42
-
43
- ### πŸ”’ Security - Supply Chain
44
-
45
- - **Removed hardcoded CDN URL**: `functions/sqlite/tools/db.support.ts` no longer references `https://cdn.jsdelivr.net/npm/sql.js/dist/` hardcoded. SQLite now requires explicit loader configuration via `sqlite.config({ loader, scriptUrl })` or fails gracefully with a clear error message.
46
- - **Eliminated external script injection risk**: No external URL strings in the bundle - prevents socket.dev supply-chain warnings for "URL string literals"
47
- - **Added `browser` field** in `package.json` for explicit browser/Node resolution
48
- - **Added `.oxlintrc.json`**: Lint configuration with ignore patterns and rule overrides
49
- - **tsup config**: Disabled minification (`minifyWhitespace`, `minifyIdentifiers`, `minifySyntax` β†’ `false`), enabled sourcemaps (`sourcemap: true`) and `keepNames: true` to produce readable bundles and eliminate socket.dev "minified code" false positives
50
-
51
- ---
52
-
53
- ## v4.9.0 - 2026-09-06
54
-
55
- ### πŸ› Bug Fixes
56
-
57
- - **Module duplication / state reset across import paths**: Fixed issue where importing memorio via different paths (ESM `dist/index.js`, CJS `index.cjs`, package name `memorio`, absolute file path) created separate module instances, each with its own empty proxy. This caused `globalThis.state` to be overwritten with a fresh empty proxy on second import, resetting all state data.
58
- - All modules (`state`, `store`, `session`, `cache`) now use private `globalThis` singleton keys (`__memorio_state_instance__`, `__memorio_store_instance__`, `__memorio_session_instance__`, `__memorio_cache_instance__`) to guarantee a single shared instance across all import paths.
59
- - `memorio.global()` in `core/global.ts` now guards with `if (!(key in globalThis))` to prevent overwriting existing dev globals - protecting against module duplication resetting state.
60
-
61
- ### πŸ”§ Code Refactoring
62
-
63
- - **Removed `__DEV__` build-time constant**: Replaced all bare `__DEV__` references with `DEV`/`PROD` from `core/env.ts` (runtime detection via `process.env.NODE_ENV`). Eliminates `ReferenceError: __DEV__ is not defined` in browser environments without bundler `define` config. Production builds verified to have **0** `__DEV__` references in both ESM and CJS outputs.
64
- - `core/env.ts`: Rewrote from `__DEV__`-based to pure runtime detection. `DEV` = `process.env.NODE_ENV !== 'production'` (or `true` in browser without `process` polyfill).
65
- - All `if (__DEV__)` guards across `core/global.ts`, `functions/state/`, `functions/store/`, `functions/session/`, `functions/cache/`, `functions/idb/`, `functions/sqlite/`, `functions/observer/`, `functions/useObserver/`, `functions/message/`, `functions/logger/`, and `functions/devtools/` now use `if (DEV)` with an explicit `import { DEV } from '../../core/env'`.
66
- - `core/global.ts`: `memorio.global()` auto-call is gated behind `if (isDev)` (sourced from `DEV`), not `if (__DEV__)`.
67
- - `tsup.config.ts`: Removed `'__DEV__'` from `define`. Only `process.env.NODE_ENV` is defined.
68
- - `vitest.config.ts`: Removed `__DEV__: true` define. Uses `'process.env.NODE_ENV': '"development"'` instead.
69
- - `types/env.d.ts`: Removed `declare const __DEV__: boolean`. Documents runtime `DEV`/`PROD` imports from `core/env.ts`.
70
-
71
- ### ✨ API Additions
72
-
73
- - **`memorio.env.isDev` / `memorio.env.isProd`**: Runtime environment detection properties on the `memorio` namespace. Returns `true`/`false` based on `process.env.NODE_ENV` - no build-time `__DEV__` define required.
74
- - **`memorio.global()` method**: Manually sets dev-only globals (`state`, `store`, `session`, `cache`, `idb`, `sqlite`, `observer`, `useObserver`) on `globalThis`. Auto-called in development; idempotent and safe to call multiple times.
75
-
76
- ### πŸ†• API - Typed Stores & Schema Validation
77
-
78
- - **Typed Stores**: `memorio.typed<T>()` returns the global `state` proxy cast to a TypeScript type `T`, providing compile-time type safety, IntelliSense autocomplete, and static property checking on state access and mutation. Zero runtime cost - the returned object is the exact same Proxy as `globalThis.state`.
79
- - **Schema Validation**: `memorio.registerSchema(path, schema)` registers runtime validators for state paths. Writes that violate a registered schema are rejected before storage. Supports type checking, required fields, min/max, regex patterns, enums, nested property schemas, and custom validator functions. Includes `memorio.validate(path, value)`, `memorio.unregisterSchema(path)`, and `memorio.listSchemas()`.
80
-
81
- ### πŸ“ Documentation Updates
82
-
83
- - `docs/README.md`: Added "Typed Stores" and "Schema Validation" sections. Updated "Is this for you?" to reference the new type-safe options.
84
- - `docs/llms.txt`: Added typed stores and schema validation sections.
85
- - `docs/SUMMARY.md`: Added links to new doc pages.
86
-
87
- ---
88
-
89
- ## v4.6.1 (Security Patch) - 2026-08-14 - CRITICAL Security Fix
90
-
91
- ### πŸ” Security NOTICE (v4.6.0)
92
-
93
- **CRITICAL**: A Gitea Personal Access Token was accidentally committed to `.npmrc` in v4.6.0
94
-
95
- **Affected**: `v4.6.0` tag and all builds from that version
96
-
97
- **Action Required**:
98
- - **IMMEDIATE**: Revoke ALL tokens on Gitea Packages by admin access
99
- - **GENERATE**: Create new PAT with scope `write:package` only
100
- - **CONFIGURE**: Add as secret `PAT` in GitHub Actions or Gitea Actions
101
- - **UPGRADE**: Use v4.6.1 where the token is replaced with `${PAT}` environment variable
102
-
103
- The hardcoded token `2f398d5d7a734781e96108fdd0dbbabad41ef77a` has been removed in v4.6.1.
104
-
105
- ### πŸ› Bug Fixes
106
-
107
- - **SECURITY**: Removed hardcoded Gitea PAT from `.npmrc` (exposed token remediated)
108
- - Replaced with environment variable `${PAT}` for secure authentication
109
-
110
- ### πŸ“ Documentation Updates
111
-
112
- - `.npmrc`: Token replaced with environment variable reference
113
- - `.gitea/workflows/npm.yml`: Configured to use secrets `GITEA_USER` and `PAT`
114
-
115
- ---
116
-
117
- ## v4.6.0 (Previous - SECURITY ISSUE) - 2026-08-13 - Refactoring & Documentation
118
-
119
- **⚠️ WARNING**: This version had a hardcoded PAT token that was later remediated in v4.6.1**
120
-
121
- ### πŸ› Bug Fixes
122
-
123
- - Fixed circular import in `idb/index.ts` β†’ `core/global`
124
- - Fixed dead `globalThis._propertyAccessLog` reference in `observer`
125
- - Fixed `dispatch.remove(f)` tuple bug in `functions/dispatch.ts`
126
- - Fixed `logger.isDebugEnabled` using wrong module reference
127
- - Removed dead `propertyAccessLog` / `pushPropertyAccess` from `core/internal.ts`
128
- - Removed duplicate path-tracking block in `state` get handler
129
- - Removed redundant `?? key` fallback in `state` set handler
130
-
131
- ### πŸ”§ Code Refactoring
132
-
133
- - **Self-contained modules**: All modules now work independently without internal `globalThis.memorio.*` reads/writes
134
- - **Module-local state**: Created `core/internal.ts` for module-local singletons
135
- - **Bootstrap-only global**: `core/global.ts` now only publishes to `globalThis.memorio` at initialization
136
- - **Removed dead code**: `core/constructor.ts` deleted (unused)
137
- - **Extracted helpers**: `_read`/`_write`/`_remove` in `store` and `session` to eliminate duplication
138
- - **Fixed circular imports**: `dispatch` β†’ `observer` via `globalThis.events`
139
-
140
- ### πŸ“ Documentation Updates
141
-
142
- - `docs/README.md`: Added Classic `import { state } from 'memorio'` section, improved badges layout, enhanced "Why memorio?" comparison table
143
- - `docs/markdown/STORE.md`: Added classic import note
144
- - `docs/markdown/IMPORT.md`: New file for named export guide
145
- - `docs/SUMMARY.md`: Updated to include `IMPORT.md`
146
- - `README.md`: Badge corrections, header cleanup, removed unverified bundle size claims
147
-
148
- ### πŸ†• GitHub Actions / Gitea Workflows
149
-
150
- - Added `.gitea/workflows/npm.yml` for automatic npm package publishing to Gitea Packages on `v*` tags
151
- - Requires `GITEA_USER` and `PAT` secrets
152
-
153
- ### πŸ§ͺ Tests
154
-
155
- - **Result: 9 suites Β· 101 passed Β· 4 skipped Β· 1 todo**
156
- - All lint and typecheck clean
157
-
158
- ---
159
-
160
- ## v3.0.2 - 2026-05-19 - Bug Fix, Security & API Expansion
161
-
162
- ### πŸ› Bug Fixes
163
-
164
- - Removed dead code: `buildPathTracker` from `functions/state/index.ts` (unused Proxy builder, exported nowhere)
165
- - Removed double `delete` in state `removeAll` handler (redundant null-check + delete on same key)
166
- - Removed unbound `globalThis.state` reference in state init (would throw `ReferenceError` in strict mode)
167
- - Removed `Object.freeze(observer)` referencing undeclared variable (`ReferenceError` on module load)
168
- - Removed `confirm()` synchronous blocking call from `idb.db.delete` (library must not block main thread)
169
-
170
- ### πŸ”’ Security Improvements
171
-
172
- - Removed `esbuild-sass-plugin` and `esbuild-scss-modules-plugin` from `devDependencies` (unnecessary for a library with no styles)
173
- - Removed `injectStyle: true`, `sassPlugin()` and `.css` loader from `tsup.config.ts`
174
- - Deleted `tsup.plugin.injectCss.ts` (code injection vector completely removed from build pipeline)
175
- - `console.error`/`console.warn` β†’ `console.debug` in `devtools` and `idb` error handlers (consistent debug-only logging policy)
176
- - `store.set()` now blocks function values instead of silently logging and continuing
177
- - All `PRIVATE License` headers in `functions/idb/` replaced with `MIT License`
178
-
179
- ### πŸ”§ Code Quality
180
-
181
- - Added JSDoc to `observerFunction` in `functions/observer/index.ts`
182
- - Added JSDoc to `cache` global in `functions/cache/index.ts`
183
- - `lint` and `tsc` pass clean - 0 vulnerabilities from `npm audit`
184
-
185
- ### πŸ†• API - New in 3.0.2
186
-
187
- | Function | Description |
188
- |----------|-------------|
189
- | `memorio.isBrowser()` | Returns `true` when running in a browser |
190
- | `memorio.isNode()` | Returns `true` when running in Node.js |
191
- | `memorio.isDeno()` | Returns `true` when running in Deno |
192
- | `memorio.isEdge()` | Returns `true` in Cloudflare Workers, Vercel Edge, etc. |
193
- | `memorio.getCapabilities()` | Full capabilities object (`platform`, `hasLocalStorage`, `hasIndexedDB`, …) |
194
- | `memorio.createContext(name?)` | Create multi-tenant isolated context |
195
- | `memorio.listContexts()` | List all active isolated contexts |
196
- | `memorio.deleteContext(id)` | Delete isolated context by ID |
197
- | `memorio.isolate(name?)` | Shorthand alias for `createContext` |
198
-
199
- ### πŸ§ͺ Tests
200
- - **Result: 8 suites Β· 95 passed Β· 3 skipped Β· 0 failed**
201
-
202
- ### πŸ—‘οΈ Dependency Changes
203
-
204
- | Removed | Reason |
205
- |---------|--------|
206
- | `esbuild-sass-plugin@3.7.0` | No SCSS in a library |
207
- | `esbuild-scss-modules-plugin@1.1.1` | No SCSS in a library |
208
- | 36 transitive packages | Removed from `node_modules` |
209
-
210
- ### πŸ“ Documentation Updates
211
-
212
- - `docs/README.md`: replaced `console.debug` with `console.debug` in usage examples; fixed `esbuild` badge β†’ `tsup`
213
- - `.github/CHANGELOG.md`: restructured with fix / security / changed sections
214
- - `.github/HISTORY.md`: complete rewrite through v3.0.2
215
- - `.github/SECURITY.md`: NIST/NSA standard + OWASP Top 10 mapping
216
- - `.github/CITATION.cff`: license PRIVATE β†’ MIT to match `package.json`
217
- - `.project/*`: all context documents updated to v3.0.2
218
-
219
- ---
220
-
221
- ## v2.9.0 - 2026-05-13
222
-
223
- ### Added
224
- - DevTools - `memorio.devtools.inspect()`, `stats()`, `exportData()`
225
- - Logger with full history, stats and export
226
- - Platform detection (`isBrowser`, `isNode`, `isDeno`, `isEdge`, `getCapabilities`)
227
- - Session isolation via `crypto.randomUUID()`
228
-
229
- ### Changed
230
- - Updated dependencies to latest versions
231
- - Improved cross-platform support (Deno, Edge Workers, Node.js)
232
-
233
- ### Security
234
- - Secure random session IDs replaced `Math.random()`
235
- - Key validation (max 512 chars + character whitelist)
236
-
237
- ---
238
-
239
- ## v2.5.0 - 2026-02-17
240
-
241
- - Initial release of memorio (state, store, session, cache, idb)
242
- - Observer pattern (`observer`)
243
- - `useObserver` React hook
@@ -1,311 +0,0 @@
1
- > **Status:** Published
2
- > **Date:** 2026-09-12
3
- > **Deciders:** Memorio 5.x Core Team, BigLogic
4
- > **Scope**: Project Documentation
5
- > **Standard**: Memorio Documentation Standard v5
6
- >
7
- ---
8
- # Memorio - NPM Package
9
-
10
- ## Versione
11
-
12
- **4.9.5** - Current: `4.9.5` branch
13
-
14
- ## Chi Siamo
15
-
16
- - **Jo**: AI assistant, amico di Dario, professionale e diretto
17
- - **Dario Passariello**: CTO e fondatore di BigLogic
18
- - **BigLogic**: Azienda specializzata in soluzioni SaaS artigianali, AI e design ad alta precisione
19
-
20
- ## Progetto Attuale
21
-
22
- **Memorio** Γ¨ un NPM package leggero e semplice per piccoli progetti dove servono soluzioni veloci senza complessitΓ  enterprise:
23
-
24
- - **State** - memoria volatile reattiva (Proxy-based)
25
- - **Store** - localStorage persistenza
26
- - **Session** - sessionStorage
27
- - **IDB** - IndexedDB storage strutturato
28
- - **Cache** - in-memory cache
29
- - **Observer** - pattern observer per vanilla JS
30
- - **UseObserver** - React hook per observer
31
- - **DevTools** - Browser console debugging tools
32
- - **Logger** - utility di logging
33
- - **Dispatch** - vanilla JS event system
34
- - **Schema** - runtime validation per state paths
35
- - **Typed** - compile-time type safety su state proxy
36
- - **History** - time-travel (undo/redo/snapshot/diff/trace)
37
- - **Inspect** - introspection utilities
38
- - **Memory** - AI memory system con persistence e TTL
39
-
40
- **Target**: Progetti piccoli/medi
41
- **Confronto**: @Biglogic/rgs = enterprise, Memorio = piccoli progetti
42
-
43
- ## Stack Tecnologico
44
-
45
- - TypeScript 6.0.3 (strict mode)
46
- - tsup 8.5.1 per build (ESM + CJS)
47
- - ES2022 target
48
- - ESM (`"type": "module"`)
49
- - vitest per test (browser + node)
50
- - Playwright per test end-to-end
51
- - Peer dependencies: React >=16.8.0 (opzionale)
52
- - Nessuna UI (Γ¨ una libreria)
53
- - Production: dependency-free (zero runtime dependencies)
54
-
55
- ## Struttura File
56
-
57
- ```
58
- memorio/
59
- β”œβ”€β”€ index.ts # Entry point (named exports + memorio namespace)
60
- β”œβ”€β”€ core/ # Core modules (bootstrap, platform, internal)
61
- β”‚ β”œβ”€β”€ global.ts # Bootstrap: publishes to globalThis
62
- β”‚ β”œβ”€β”€ env.ts # Runtime DEV/PROD detection
63
- β”‚ β”œβ”€β”€ internal.ts # Module-local internal state singleton
64
- β”‚ β”œβ”€β”€ platform.ts # Browser/Node/Deno/Edge detection
65
- β”‚ β”œβ”€β”€ dispatch.ts # Event dispatch system
66
- β”‚ β”œβ”€β”€ hlc.ts # Hybrid Logical Clock
67
- β”‚ └── fractional.ts # Fractional indexing
68
- β”œβ”€β”€ types/ # TypeScript declarations
69
- β”‚ └── memorio.d.ts
70
- β”œβ”€β”€ functions/ # Feature modules
71
- β”‚ β”œβ”€β”€ state/ # Reactive state (Proxy)
72
- β”‚ β”œβ”€β”€ store/ # LocalStorage
73
- β”‚ β”œβ”€β”€ session/ # SessionStorage
74
- β”‚ β”œβ”€β”€ cache/ # In-memory cache
75
- β”‚ β”œβ”€β”€ idb/ # IndexedDB (browser)
76
- β”‚ β”œβ”€β”€ sqlite/ # SQLite (sql.js, optional)
77
- β”‚ β”œβ”€β”€ observer/ # Observer pattern
78
- β”‚ β”œβ”€β”€ useObserver/ # React hook
79
- β”‚ β”œβ”€β”€ logger/ # Logging
80
- β”‚ β”œβ”€β”€ devtools/ # DevTools (dev-only)
81
- β”‚ β”œβ”€β”€ schema/ # Runtime validation
82
- β”‚ β”œβ”€β”€ typed/ # Type-safe state views
83
- β”‚ β”œβ”€β”€ history/ # Time-travel undo/redo
84
- β”‚ β”œβ”€β”€ inspect/ # Introspection
85
- β”‚ β”œβ”€β”€ memory/ # AI memory system
86
- β”‚ β”œβ”€β”€ message/ # User messages
87
- β”‚ └── dispatch/ # Event dispatch
88
- β”œβ”€β”€ tests/ # Vitest + Playwright tests
89
- β”‚ β”œβ”€β”€ vitest/ # Vitest config + test files
90
- β”‚ └── playwright/ # E2E test specs
91
- β”œβ”€β”€ .project/markdown/ # Project context & documentation
92
- β”‚ β”œβ”€β”€ CHANGELOG.md
93
- β”‚ β”œβ”€β”€ PROJECT.md
94
- β”‚ └── ... (module docs)
95
- β”œβ”€β”€ docs/ # Published documentation
96
- β”œβ”€β”€ package.json
97
- β”œβ”€β”€ tsconfig.json
98
- β”œβ”€β”€ tsup.config.ts
99
- └── .kilo/ # Kilo AI agent memory
100
- ```
101
-
102
- ## API Pubbliche
103
-
104
- ### Core Namespace
105
-
106
- ```typescript
107
- import memorio, { state, store, session, cache, idb, sqlite, observer, useObserver, dispatch, message } from 'memorio'
108
- // or for global access:
109
- // import 'memorio/global'
110
-
111
- // Runtime environment detection
112
- memorio.env.isDev // true in development, false in production
113
- memorio.env.isProd // inverse of isDev
114
-
115
- // Global API (opt-in via memorio/global entry)
116
- memorio.global() // Force-expose dev globals on globalThis (idempotent)
117
- ```
118
-
119
- ### State
120
-
121
- ```typescript
122
- // Via named import (or global entrypoint if opted in)
123
- state.key = 'value' // Set
124
- state.key // Get (reactive)
125
- state.remove('key') // Delete
126
- state.removeAll() // Clear all
127
- state.lock() // Lock all modifications
128
- state.unlock() // Unlock
129
- state.list // Deep clone of all state
130
- state.typed<T>() // Type-safe view
131
- ```
132
-
133
- ### Store (localStorage)
134
-
135
- ```typescript
136
- store.set('key', { value: 42 })
137
- store.get('key') // { value: 42 }
138
- store.remove('key')
139
- store.removeAll()
140
- store.isPersistent // boolean
141
- store.size() // character count
142
- store.quota() // [used, quota]
143
- store.list() // all memorio keys
144
- ```
145
-
146
- ### Session (sessionStorage)
147
-
148
- ```typescript
149
- session.set('key', 'value')
150
- session.get('key')
151
- session.remove('key')
152
- session.removeAll()
153
- session.isPersistent
154
- ```
155
-
156
- ### Cache (in-memory)
157
-
158
- ```typescript
159
- cache.set('key', 'value')
160
- cache.get('key')
161
- cache.remove('key')
162
- cache.list() // all cached items
163
- cache.clear() // alias for removeAll
164
- ```
165
-
166
- ### Schema Validation
167
-
168
- ```typescript
169
- memorio.registerSchema('user.name', {
170
- type: 'string',
171
- required: true,
172
- min: 1,
173
- pattern: /^[a-zA-Z]+$/
174
- })
175
-
176
- memorio.validate('user.name', 'Jo') // { valid: true, errors: [] }
177
- memorio.listSchemas() // registered paths
178
- memorio.unregisterSchema('user.name')
179
- ```
180
-
181
- ### History / Time Travel
182
-
183
- ```typescript
184
- memorio.enableHistory() // Start tracking mutations
185
- const snap = memorio.snapshot() // Deep clone of state
186
- memorio.undo() // Revert last mutation
187
- memorio.redo() // Re-apply
188
- memorio.canUndo() // boolean
189
- memorio.canRedo() // boolean
190
- memorio.rollback(snap) // Restore to snapshot
191
- memorio.trace() // List all mutations
192
- memorio.clearHistory() // Clear undo/redo/trace
193
- ```
194
-
195
- ### Platform Detection
196
-
197
- ```typescript
198
- memorio.isBrowser() // boolean
199
- memorio.isNode() // boolean
200
- memorio.isDeno() // boolean
201
- memorio.isEdge() // boolean
202
- memorio.getCapabilities() // { platform, hasLocalStorage, hasIndexedDB, ... }
203
- ```
204
-
205
- ### Context (multi-tenant)
206
-
207
- ```typescript
208
- memorio.createContext('tenant-name') // Isolate state by context
209
- memorio.listContexts() // List all contexts
210
- memorio.deleteContext('context-id') // Delete a context
211
- memorio.isolate('tenant-name') // Shorthand for createContext
212
- ```
213
-
214
- ## NPM Scripts
215
-
216
- | Comando | Descrizione |
217
- |---------|-------------|
218
- | `npm run build` | Build con tsup (ESM + CJS) |
219
- | `npm run watch` | Watch mode con tsup |
220
- | `npm test` | Esegui vitest test suite |
221
- | `npm run lint` | Lint con oxlint |
222
- | `npm run tsc` | TypeScript type check |
223
-
224
- ## Test Suite
225
-
226
- | Suite | Tests | Stato |
227
- |-------|-------|-------|
228
- | State | 24 | βœ… |
229
- | Store | 17 | βœ… |
230
- | Session | 12 | βœ… |
231
- | Cache | 5 | βœ… |
232
- | Observer | 12 | βœ… |
233
- | useObserver | 12 | βœ… |
234
- | DevTools | 8 | βœ… |
235
- | Schema | 10 | βœ… |
236
- | History | 8 | βœ… |
237
- | Inspect | 6 | βœ… |
238
- | ID | 3 | βœ… |
239
- | Dispatch | 5 | βœ… |
240
- | Message | 4 | βœ… |
241
- | Logger | 3 | βœ… |
242
- | Memory | 5 | βœ… |
243
- | **Totale** | **~120+** | βœ… |
244
-
245
- ## Regole Importanti
246
-
247
- 1. Documentazione in `.project/markdown/`, non nella root
248
- 2. Usare `console.debug()` per il debugging
249
- - Nei blocchi `catch` e codice di gestione errori operativi Γ¨ consentito `console.error()` e `console.warn`
250
- 3. Arrow functions obbligatorie
251
- 4. JSDoc obbligatorio su tutte le funzioni pubbliche
252
- 5. Peer dependency React >=16.8.0 opzionale
253
- 6. Nessuno stile CSS/SCSS (Γ¨ una libreria)
254
- 7. Nessun database embedded
255
- 8. Tutti i moduli usano singleton keys su `globalThis` per prevenire module duplication
256
-
257
- ## Dipendenze
258
-
259
- ### Produzione
260
- - Nessuna (dependency-free)
261
-
262
- ### Sviluppo
263
- - `typescript: 6.0.3`
264
- - `tsup: 8.5.1`
265
- - `vitest: 5.0.0`
266
- - `playwright: chromium`
267
- - `@types/node: ^25.9.1`
268
- - `react: ^19.2.6` (peer)
269
- - `react-dom: ^19.2.6` (peer)
270
-
271
- ### Peer
272
- - `react: >=16.8.0` (opzionale)
273
- - `react-dom: >=16.8.0` (opzionale)
274
-
275
- ## Module Duplication Strategy
276
-
277
- Memorio can be imported via multiple paths (ESM `dist/index.js`, CJS `dist/index.cjs`, package name `memorio`). Each path may resolve to a separate module instance in the bundler. To prevent duplicate proxies:
278
-
279
- | Module | Singleton Key |
280
- |--------|--------------|
281
- | `state` | `__memorio_state_instance__` |
282
- | `store` | `__memorio_store_instance__` |
283
- | `session` | `__memorio_session_instance__` |
284
- | `cache` | `__memorio_cache_instance__` |
285
- | internal state | `__memorio_internal_state` |
286
-
287
- The first import path to execute creates the instance and stores it on `globalThis`. Subsequent imports find the existing instance and reuse it - guaranteeing all named exports point to the **same** proxy object.
288
-
289
- ## Valutazione Attuale
290
-
291
- ### Punti di Forza
292
-
293
- - Struttura NPM corretta
294
- - Build con tsup moderno (ESM + CJS)
295
- - Testing setup (vitest + Playwright)
296
- - Auto-detection React per reattivitΓ 
297
- - Multi-storage support (state, store, session, idb, cache, sqlite, devtools, logger)
298
- - Totalmente dependency-free in produzione
299
- - Cross-platform: Browser, Node.js, Deno, Edge Workers
300
- - Session isolation e Context system per multi-tenant
301
- - Module duplication protection via singleton keys
302
- - Schema validation e typed stores per type safety
303
-
304
- ### Critica
305
-
306
- - Coverage test non verificato
307
- - Socket.dev Supply Chain Security da monitorare
308
-
309
- ---
310
-
311
- *Ultimo aggiornamento: 2026-09-06*