memorio 1.0.2 โ 1.1.0
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 +27 -88
- package/index.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,18 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
> A lightweight, type-safe state management library for modern JavaScript applications
|
|
4
4
|
|
|
5
|
-

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
10
|

|
|
11
|
-

|
|
12
11
|
|
|
13
12
|

|
|
14
13
|

|
|
15
14
|
|
|
16
|
-
##
|
|
15
|
+
## Table of Contents
|
|
17
16
|
|
|
18
17
|
- [Features](#features)
|
|
19
18
|
- [Installation](#installation)
|
|
@@ -27,17 +26,17 @@
|
|
|
27
26
|
- [Security](#security)
|
|
28
27
|
- [License](#license)
|
|
29
28
|
|
|
30
|
-
##
|
|
29
|
+
## Features
|
|
31
30
|
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
31
|
+
- Reactive state management with observer pattern
|
|
32
|
+
- Persistent storage with Store API
|
|
33
|
+
- Session management for temporary data
|
|
34
|
+
- Type-safe with full TypeScript support
|
|
35
|
+
- Comprehensive test coverage
|
|
36
|
+
- Zero dependencies
|
|
37
|
+
- Easy debugging with proxy-based state
|
|
39
38
|
|
|
40
|
-
##
|
|
39
|
+
## Installation
|
|
41
40
|
|
|
42
41
|
```bash
|
|
43
42
|
npm install memorio
|
|
@@ -47,7 +46,7 @@ yarn add memorio
|
|
|
47
46
|
pnpm add memorio
|
|
48
47
|
```
|
|
49
48
|
|
|
50
|
-
|
|
49
|
+
### All test suites are passing
|
|
51
50
|
|
|
52
51
|
- Basic functionality tests
|
|
53
52
|
- State management tests
|
|
@@ -57,7 +56,7 @@ pnpm add memorio
|
|
|
57
56
|
|
|
58
57
|
Total: 25 tests passed across 5 test suites
|
|
59
58
|
|
|
60
|
-
##
|
|
59
|
+
## Quick Start
|
|
61
60
|
|
|
62
61
|
```javascript
|
|
63
62
|
import 'memorio';
|
|
@@ -80,7 +79,7 @@ session.set('token', 'user-jwt-token');
|
|
|
80
79
|
const token = session.get('token');
|
|
81
80
|
```
|
|
82
81
|
|
|
83
|
-
##
|
|
82
|
+
## API Reference
|
|
84
83
|
|
|
85
84
|
### State Management
|
|
86
85
|
|
|
@@ -221,70 +220,9 @@ export default App;
|
|
|
221
220
|
|
|
222
221
|
---
|
|
223
222
|
|
|
224
|
-
##
|
|
223
|
+
## Testing
|
|
225
224
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
```js
|
|
229
|
-
// Set a session value:
|
|
230
|
-
session.set("userId", "12345")
|
|
231
|
-
|
|
232
|
-
// Get a session value:
|
|
233
|
-
session.get("userId") // Output: "12345"
|
|
234
|
-
|
|
235
|
-
// Remove a specific session value:
|
|
236
|
-
session.remove("userId")
|
|
237
|
-
|
|
238
|
-
// Get the number of items in session:
|
|
239
|
-
session.size() // Output: number of stored items
|
|
240
|
-
|
|
241
|
-
// Remove all session values:
|
|
242
|
-
session.removeAll()
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
### Example use Session in React
|
|
246
|
-
|
|
247
|
-
```js
|
|
248
|
-
import { useEffect } from 'react';
|
|
249
|
-
import 'memorio';
|
|
250
|
-
|
|
251
|
-
function UserSession() {
|
|
252
|
-
useEffect(() => {
|
|
253
|
-
// Store user session data
|
|
254
|
-
session.set('userSession', {
|
|
255
|
-
id: '12345',
|
|
256
|
-
lastActive: Date.now(),
|
|
257
|
-
preferences: {
|
|
258
|
-
theme: 'dark',
|
|
259
|
-
language: 'en'
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
// Retrieve session data
|
|
264
|
-
const userData = session.get('userSession');
|
|
265
|
-
console.log('User session:', userData);
|
|
266
|
-
|
|
267
|
-
// Clean up on component unmount
|
|
268
|
-
return () => {
|
|
269
|
-
session.remove('userSession');
|
|
270
|
-
};
|
|
271
|
-
}, []);
|
|
272
|
-
|
|
273
|
-
return (
|
|
274
|
-
<div>
|
|
275
|
-
{/* Your component JSX */}
|
|
276
|
-
</div>
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
export default UserSession;
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
---
|
|
284
|
-
|
|
285
|
-
## ๐งช Testing
|
|
286
|
-
|
|
287
|
-
โ
All test suites are passing:
|
|
225
|
+
## Test suites are passing
|
|
288
226
|
|
|
289
227
|
- Basic functionality tests
|
|
290
228
|
- State management tests
|
|
@@ -294,26 +232,27 @@ export default UserSession;
|
|
|
294
232
|
|
|
295
233
|
Total: 25 tests passed across 5 test suites
|
|
296
234
|
|
|
297
|
-
##
|
|
235
|
+
## Security
|
|
298
236
|
|
|
299
237
|
Security scans and reports are available at:
|
|
238
|
+
|
|
300
239
|
- [Socket.dev](https://socket.dev/npm/package/memorio)
|
|
301
240
|
- [Snyk.io](https://security.snyk.io/package/npm/memorio)
|
|
302
241
|
|
|
303
|
-
##
|
|
242
|
+
## License
|
|
304
243
|
|
|
305
|
-
MIT
|
|
244
|
+
MIT (c) [Dario Passariello](https://dario.passariello.ca/)
|
|
306
245
|
|
|
307
246
|
---
|
|
308
247
|
|
|
309
|
-
##
|
|
248
|
+
## Contributing
|
|
310
249
|
|
|
311
250
|
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
312
251
|
|
|
313
|
-
##
|
|
252
|
+
## Support
|
|
314
253
|
|
|
315
254
|
Need help? Feel free to [open an issue](https://github.com/a51-dev/a51.memorio/issues).
|
|
316
255
|
|
|
317
256
|
---
|
|
318
257
|
|
|
319
|
-
Created with
|
|
258
|
+
Created with by [Dario Passariello](https://dario.passariello.ca/) - Copyright (c) 2025
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var c={name:"memorio",version:"1.0
|
|
1
|
+
"use strict";(()=>{var c={name:"memorio",version:"1.1.0",type:"module",main:"index.js",scripts:{build:"node ./esbuild.config.mjs",watch:"esbuild init.ts --bundle --outdir=dist --serve","-----------":"",test:"set NODE_OPTIONS=--experimental-vm-modules && jest","test:watch":"set NODE_OPTIONS=--experimental-vm-modules && jest --watch","test:coverage":"set NODE_OPTIONS=--experimental-vm-modules && jest --coverage","test:watchAll":"set NODE_OPTIONS=--experimental-vm-modules && jest --watchAll",tsc:"tsc -b .",eslint:"eslint .",updates:"npx npm-check-updates -u && npm i","----------":"","publish:npm":"npm run build && npm publish ./dist"},types:"index.d.ts",typings:"./types/*",description:"Memorio, State + Observer and Store for a easy life ",license:"MIT",copyright:"Dario Passariello, BigLogic ca - a51.dev is a BigLogic project",homepage:"https://a51.gitbook.io/memorio",author:{name:"Dario Passariello",url:"https://dario.passariello.ca/",email:"dariopassariello@gmail.com"},support:{name:"Dario Passariello",url:"https://github.com/passariello/",email:"dariopassariello@gmail.com"},contributors:[{name:"Dario Passariello",email:"dariopassarielloa@gmail.com"},{name:"Valeria Cala Scaglitta",email:"valeriacalascaglitta@gmail.com"}],keywords:["biglogic","a51","memorio","state","store","observer","dario","passariello"],repository:{type:"git",url:"git+https://github.com/a51-dev/a51.memorio.git",help:"https://github.com/a51-dev/a51.memorio#readme"},bugs:{url:"https://github.com/a51-dev/a51.memorio/issues"},funding:[{type:"patreon",url:"https://www.patreon.com/passariello"}],typing:["types/*"],dependencies:{"dphelper.types":"0.0.19"},devDependencies:{"@eslint/js":"9.34.0","@types/jest":"30.0.0","@types/node":"^24.3.0","@typescript-eslint/eslint-plugin":"8.41.0","@typescript-eslint/parser":"8.41.0","dphelper.types":"0.0.19",esbuild:"^0.25.9","esbuild-plugin-clean":"^1.0.1","esbuild-plugin-copy":"^2.1.1",eslint:"9.34.0",jest:"30.1.2","jest-environment-jsdom":"30.1.2","ts-jest":"29.4.1","ts-loader":"^9.5.4","ts-node":"10.9.2",tslib:"^2.8.1",typescript:"5.9.2"}};Object.defineProperty(globalThis,"memorio",{value:{},writable:!1,configurable:!1,enumerable:!1});Object.defineProperty(globalThis,"events",{value:{},writable:!0,configurable:!1,enumerable:!1});Object.defineProperty(memorio,"version",{writable:!1,configurable:!1,enumerable:!1,value:c.version});Object.defineProperty(memorio,"dispatch",{writable:!1,configurable:!1,enumerable:!1,value:{set:(e,t={})=>{dispatchEvent(new CustomEvent(String(e),t))},listen:(e,t=null,i=!1)=>{observer.list?.[e]?.length>0&&observer.remove(e);let l=r=>t?setTimeout(()=>t(r),1):null;globalThis.addEventListener(e,l),globalThis.events[e]=l},remove:e=>{globalThis.removeEventListener(e,globalThis.events[e]),delete globalThis.events[e]}}});Object.defineProperty(memorio,"objPath",{writable:!1,configurable:!1,enumerable:!1,value:(e,t,i=".")=>t.concat(e).join(i)});var u=(e,t,i=[])=>{let l=r=>{let o=r.split(".");o.forEach((s,n)=>{let a=o.slice(0,n+1).join(".");globalThis.memorio.dispatch.set(a,{detail:{name:a}})})};return new Proxy(e,{get(r,o){if(o==="list"){let s={};for(let n in r)typeof r[n]!="function"&&!["list","remove","removeAll"].includes(n)&&(s[n]=r[n]);return s}if(o==="remove")return function(s){return s in r&&!["list","remove","removeAll"].includes(s)?(delete r[s],!0):!1};if(o==="removeAll")return function(){for(let s in r)typeof r[s]!="function"&&!["list","remove","removeAll"].includes(s)&&delete r[s];return!0};if(Object.isFrozen(r[o]))return r[o];try{let s=Reflect.get(r,o);return s&&typeof s=="object"&&["Array","Object"].includes(s.constructor.name)?u(s,t,i.concat(o)):s}catch(s){console.error("Error: ",s);return}},set(r,o,s){if(r[o]&&typeof r[o]=="object"&&Object.isFrozen(r[o])){console.error(`Error: state '${o}' is locked`);return}try{let n=globalThis.memorio.objPath(o,i);return t({action:"set",path:n,target:r,newValue:s,previousValue:Reflect.get(r,o)}),l("state."+n),Reflect.set(r,o,s),r[o]&&typeof r[o]=="object"&&Reflect.defineProperty(r[o],"lock",{value(){Object.defineProperty(r,o,{writable:!1,enumerable:!1}),Object.freeze(r[o])}}),!0}catch(n){return console.error("Error in set trap:",n),!1}},deleteProperty(r,o){try{let s=globalThis.memorio.objPath(o,i);return t({action:"delete",path:s,target:r}),Reflect.deleteProperty(r,o)}catch(s){return console.error("Error in deleteProperty trap:",s),!1}}})},g={};globalThis?.state?globalThis.state=state:globalThis.state=u(g,()=>{});var f=new WeakSet;f.add(state);setInterval(()=>{if(!f.has(state)){alert("memorio State is compromised, check if you override it and please reload the page");for(let e=1;e<99999;e++)clearInterval(e);stop()}},1e3);Object.defineProperty(globalThis,"state",{enumerable:!1,configurable:!1});globalThis.observer||(globalThis.observer=null);Object.defineProperty(globalThis,"observer",{enumerable:!1});observer=(e,t=null,i=!0)=>{if((r=>r.split(".")[0]!=="state"?(console.error(`Observer Error: You need to declare 'state.' or 'store.'. The '${r}' string is incorrect!`),!1):!0)(e)){if(!e&&!t){console.error("Observer Error: You need to setup observer correctly, Some parameters are missed!");return}if(!e&&t){console.error("Observer Error: You need to declare what state need to be monitored as string like 'state.test'.");return}if(e&&!t){globalThis.memorio.dispatch.listen(String(e),{detail:{name:String(e)}}),console.debug("called: ",e);return}if(e&&t){if(typeof e!="string"||typeof t!="function"){console.error("Observer Error: name of state need to be a 'string' like 'state.test' and the callback need to be a 'function'");return}globalThis.memorio.dispatch.listen(e,t,i);return}}};Object.defineProperties(observer,{list:{get:()=>globalThis.events},remove:{value:e=>{e&&(globalThis.events[e]="")}},removeAll:{get:()=>{Object.entries(observer.list).forEach(e=>{globalThis.events[e[0]]})}}});Object.freeze(observer);Object.defineProperty(globalThis,"store",{value:new Proxy({},{}),enumerable:!1,configurable:!1});Object.defineProperties(store,{get:{value(e){if(e)try{let t=localStorage.getItem(e);return t&&JSON.parse(t)}catch(t){console.error(`Error parsing store item '${e}':`,t)}}},set:{value(e,t){if(e)try{t==null?localStorage.setItem(e,JSON.stringify(null)):typeof t=="object"||typeof t=="number"||typeof t=="boolean"||typeof t=="string"?localStorage.setItem(e,JSON.stringify(t)):typeof t=="function"&&console.error("It's not secure to store functions.")}catch(i){console.error(`Error setting store item '${e}':`,i)}}},remove:{value(e){if(e&&localStorage.getItem(e))return localStorage.removeItem(e),!0}},delete:{value(e){store.remove(e)}},removeAll:{value(){return localStorage.clear(),!0}},clearAll:{value(){return store.removeAll(),!0}},quota:{value(){"storage"in navigator&&"estimate"in navigator.storage&&navigator.storage.estimate().then(({usage:e,quota:t})=>{e&&t&&console.debug(`Using ${e/1024} out of ${t/1024} Mb.`)}).catch(e=>{console.error("Error estimating quota:",e)})}},size:{value(){let e=0;for(let t in localStorage)if(localStorage.hasOwnProperty(t)){let i=localStorage.getItem(t);i&&(e+=i.length)}return e}}});Object.freeze(store);Object.defineProperty(globalThis,"session",{value:new Proxy({},{}),enumerable:!1,configurable:!1});Object.defineProperties(session,{get:{value(e){if(e)try{let t=sessionStorage.getItem(e);return t&&JSON.parse(t)}catch(t){console.error(`Error parsing session item '${e}':`,t)}}},set:{value(e,t){if(e)try{t==null?sessionStorage.setItem(e,JSON.stringify(null)):typeof t=="object"||typeof t=="number"||typeof t=="boolean"||typeof t=="string"?sessionStorage.setItem(e,JSON.stringify(t)):typeof t=="function"&&console.error("It's not secure to session functions.")}catch(i){console.error(`Error setting session item '${e}':`,i)}}},remove:{value(e){if(e&&sessionStorage.getItem(e))return sessionStorage.removeItem(e),!0}},delete:{value(e){session.remove(e)}},removeAll:{value(){return sessionStorage.clear(),!0}},clearAll:{value(){return session.removeAll(),!0}},quota:{value(){"storage"in navigator&&"estimate"in navigator.storage&&navigator.storage.estimate().then(({usage:e,quota:t})=>{e&&t&&console.debug(`Using ${e/1024} out of ${t/1024} Mb.`)}).catch(e=>{console.error("Error estimating quota:",e)})}},size:{value(){let e=0;for(let t in sessionStorage)if(sessionStorage.hasOwnProperty(t)){let i=sessionStorage.getItem(t);i&&(e+=i.length)}return e}}});Object.freeze(session);Object.defineProperty(window,"cache",{value:new Proxy({},{}),enumerable:!1,configurable:!1});})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memorio",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -84,8 +84,8 @@
|
|
|
84
84
|
"esbuild-plugin-clean": "^1.0.1",
|
|
85
85
|
"esbuild-plugin-copy": "^2.1.1",
|
|
86
86
|
"eslint": "9.34.0",
|
|
87
|
-
"jest": "30.
|
|
88
|
-
"jest-environment-jsdom": "30.
|
|
87
|
+
"jest": "30.1.2",
|
|
88
|
+
"jest-environment-jsdom": "30.1.2",
|
|
89
89
|
"ts-jest": "29.4.1",
|
|
90
90
|
"ts-loader": "^9.5.4",
|
|
91
91
|
"ts-node": "10.9.2",
|