memorio 0.2.14 โ 0.2.15
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 +244 -59
- package/index.d.ts +1 -0
- package/index.js +1 -1
- package/package.json +23 -16
- package/types/session.d.ts +91 -0
package/README.md
CHANGED
|
@@ -1,56 +1,132 @@
|
|
|
1
1
|
# Memorio
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> A lightweight, type-safe state management library for modern JavaScript applications
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+

|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
## ๐ Table of Contents
|
|
17
|
+
|
|
18
|
+
- [Features](#features)
|
|
19
|
+
- [Installation](#installation)
|
|
20
|
+
- [Quick Start](#quick-start)
|
|
21
|
+
- [API Reference](#api-reference)
|
|
22
|
+
- [State Management](#state-management)
|
|
23
|
+
- [Observer Pattern](#observer-pattern)
|
|
24
|
+
- [Store](#store)
|
|
25
|
+
- [Session](#session)
|
|
26
|
+
- [Testing](#testing)
|
|
27
|
+
- [Security](#security)
|
|
28
|
+
- [License](#license)
|
|
29
|
+
|
|
30
|
+
## โจ Features
|
|
31
|
+
|
|
32
|
+
- ๐ Reactive state management with observer pattern
|
|
33
|
+
- ๐พ Persistent storage with Store API
|
|
34
|
+
- โก Session management for temporary data
|
|
35
|
+
- ๐ Type-safe with full TypeScript support
|
|
36
|
+
- ๐งช Comprehensive test coverage
|
|
37
|
+
- ๐ฏ Zero dependencies
|
|
38
|
+
- ๐ Easy debugging with proxy-based state
|
|
39
|
+
|
|
40
|
+
## ๐ฆ Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install memorio
|
|
44
|
+
# or
|
|
45
|
+
yarn add memorio
|
|
46
|
+
# or
|
|
47
|
+
pnpm add memorio
|
|
48
|
+
```
|
|
4
49
|
|
|
5
|
-
|
|
6
|
-
*Created by Dario Passariello - Copyright (c) 2025*
|
|
50
|
+
โ
All test suites are passing:
|
|
7
51
|
|
|
8
|
-
|
|
52
|
+
- Basic functionality tests
|
|
53
|
+
- State management tests
|
|
54
|
+
- Store operations tests
|
|
55
|
+
- Cache operations tests
|
|
56
|
+
- Observer pattern tests
|
|
9
57
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
58
|
+
Total: 25 tests passed across 5 test suites
|
|
59
|
+
|
|
60
|
+
## ๐ Quick Start
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
import 'memorio';
|
|
64
|
+
|
|
65
|
+
// State Management
|
|
66
|
+
state.counter = 0;
|
|
67
|
+
state.user = { name: 'John', age: 30 };
|
|
68
|
+
|
|
69
|
+
// Observer Pattern
|
|
70
|
+
observer('state.counter', (newValue, oldValue) => {
|
|
71
|
+
console.log(`Counter changed from ${oldValue} to ${newValue}`);
|
|
72
|
+
});
|
|
13
73
|
|
|
14
|
-
//
|
|
15
|
-
|
|
74
|
+
// Store (Persistent Storage)
|
|
75
|
+
store.set('preferences', { theme: 'dark' });
|
|
76
|
+
const preferences = store.get('preferences');
|
|
77
|
+
|
|
78
|
+
// Session Storage
|
|
79
|
+
session.set('token', 'user-jwt-token');
|
|
80
|
+
const token = session.get('token');
|
|
81
|
+
```
|
|
16
82
|
|
|
17
|
-
|
|
18
|
-
state.list // or just "state" to see the proxy
|
|
83
|
+
## ๐ API Reference
|
|
19
84
|
|
|
20
|
-
|
|
21
|
-
state.test.lock() *
|
|
85
|
+
### State Management
|
|
22
86
|
|
|
23
|
-
|
|
24
|
-
state.remove("test")
|
|
87
|
+
State in Memorio is globally accessible and reactive:
|
|
25
88
|
|
|
26
|
-
|
|
27
|
-
state
|
|
89
|
+
```javascript
|
|
90
|
+
// Setting state
|
|
91
|
+
state.user = { name: 'John' };
|
|
28
92
|
|
|
29
|
-
|
|
93
|
+
// Getting state
|
|
94
|
+
const userName = state.user.name;
|
|
95
|
+
|
|
96
|
+
// Listing all states
|
|
97
|
+
console.log(state.list);
|
|
98
|
+
|
|
99
|
+
// Locking state (for Objects or Arrays)
|
|
100
|
+
state.user.lock();
|
|
101
|
+
|
|
102
|
+
// Removing state
|
|
103
|
+
state.remove('user');
|
|
104
|
+
|
|
105
|
+
// Clearing all states
|
|
106
|
+
state.removeAll();
|
|
30
107
|
|
|
31
108
|
```
|
|
32
|
-
Observer work for State like useState:
|
|
33
109
|
|
|
34
|
-
|
|
35
|
-
const [change,setChange] = useState()
|
|
110
|
+
### Observer Pattern
|
|
36
111
|
|
|
37
|
-
|
|
38
|
-
observer(
|
|
39
|
-
'myData',
|
|
40
|
-
() => {
|
|
41
|
-
console.log('myData has changed to:', state.myData);
|
|
42
|
-
setChange[state.myData];
|
|
43
|
-
}
|
|
44
|
-
);
|
|
112
|
+
Observe state changes with React-like syntax:
|
|
45
113
|
|
|
46
|
-
|
|
114
|
+
```javascript
|
|
115
|
+
// Basic observer
|
|
116
|
+
observer('state.user', (newValue, oldValue) => {
|
|
117
|
+
console.log('User updated:', newValue);
|
|
118
|
+
});
|
|
47
119
|
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
120
|
+
// With React useState
|
|
121
|
+
const [user, setUser] = useState();
|
|
122
|
+
observer('state.user', () => {
|
|
123
|
+
setUser(state.user);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// With React useEffect
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
console.log('User changed:', state.user);
|
|
129
|
+
}, [state.user]);
|
|
54
130
|
```
|
|
55
131
|
|
|
56
132
|
### Another example of use of Observer
|
|
@@ -86,31 +162,49 @@ store.remove("test") // Output: "ok"
|
|
|
86
162
|
store.removeAll() // Output: "ok"
|
|
87
163
|
```
|
|
88
164
|
|
|
89
|
-
###
|
|
165
|
+
### Store
|
|
90
166
|
|
|
91
|
-
|
|
92
|
-
import { useEffect } from 'react';
|
|
93
|
-
import 'memorio';
|
|
167
|
+
Persistent storage for your application:
|
|
94
168
|
|
|
95
|
-
|
|
169
|
+
```javascript
|
|
170
|
+
// Setting values
|
|
171
|
+
store.set('config', { theme: 'dark', language: 'en' });
|
|
96
172
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
'user',
|
|
100
|
-
{
|
|
101
|
-
name: 'John Doe',
|
|
102
|
-
age: 30
|
|
103
|
-
}
|
|
104
|
-
);
|
|
173
|
+
// Getting values
|
|
174
|
+
const config = store.get('config');
|
|
105
175
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
176
|
+
// Removing specific value
|
|
177
|
+
store.remove('config');
|
|
178
|
+
|
|
179
|
+
// Getting store size
|
|
180
|
+
const size = store.size();
|
|
181
|
+
|
|
182
|
+
// Clearing store
|
|
183
|
+
store.removeAll();
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Session
|
|
187
|
+
|
|
188
|
+
Temporary storage that persists during page sessions:
|
|
189
|
+
|
|
190
|
+
```javascript
|
|
191
|
+
// Setting session data
|
|
192
|
+
session.set('userSession', {
|
|
193
|
+
id: 'user123',
|
|
194
|
+
lastActive: Date.now()
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Getting session data
|
|
198
|
+
const userData = session.get('userSession');
|
|
199
|
+
|
|
200
|
+
// Checking session size
|
|
201
|
+
const activeItems = session.size();
|
|
202
|
+
|
|
203
|
+
// Removing session data
|
|
204
|
+
session.remove('userSession');
|
|
205
|
+
|
|
206
|
+
// Clearing all session data
|
|
207
|
+
session.removeAll();
|
|
114
208
|
|
|
115
209
|
// Remove all stored data if necessary
|
|
116
210
|
// store.removeAll();
|
|
@@ -127,8 +221,99 @@ export default App;
|
|
|
127
221
|
|
|
128
222
|
---
|
|
129
223
|
|
|
130
|
-
##
|
|
224
|
+
## SESSION
|
|
131
225
|
|
|
132
|
-
|
|
226
|
+
Session storage provides a way to store data for the duration of a page session. The data persists as long as the browser is open and survives over page reloads, but is lost when the browser tab or window is closed.
|
|
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"
|
|
133
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:
|
|
288
|
+
|
|
289
|
+
- Basic functionality tests
|
|
290
|
+
- State management tests
|
|
291
|
+
- Store operations tests
|
|
292
|
+
- Cache operations tests
|
|
293
|
+
- Observer pattern tests
|
|
294
|
+
|
|
295
|
+
Total: 25 tests passed across 5 test suites
|
|
296
|
+
|
|
297
|
+
## ๐ Security
|
|
298
|
+
|
|
299
|
+
Security scans and reports are available at:
|
|
300
|
+
- [Socket.dev](https://socket.dev/npm/package/memorio)
|
|
134
301
|
- [Snyk.io](https://security.snyk.io/package/npm/memorio)
|
|
302
|
+
|
|
303
|
+
## ๐ License
|
|
304
|
+
|
|
305
|
+
MIT ยฉ [Dario Passariello](https://dario.passariello.ca/)
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## ๐ค Contributing
|
|
310
|
+
|
|
311
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
312
|
+
|
|
313
|
+
## ๐ง Support
|
|
314
|
+
|
|
315
|
+
Need help? Feel free to [open an issue](https://github.com/a51-dev/a51.memorio/issues).
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
Created with โค๏ธ by [Dario Passariello](https://dario.passariello.ca/) - Copyright ยฉ 2025
|
package/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
/// <reference path="./types/memorio.d.ts" />
|
|
3
3
|
/// <reference path="./types/observer.d.ts" />
|
|
4
4
|
/// <reference path="./types/state.d.ts" />
|
|
5
|
+
/// <reference path="./types/session.d.ts" />
|
|
5
6
|
/// <reference path="./types/store.d.ts" />
|
|
6
7
|
/// <reference path="./types/cache.d.ts" />
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var
|
|
1
|
+
"use strict";(()=>{var c={name:"memorio",version:"0.2.15",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",deprecated:!1,preferGlobal:!0,target:"node",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"}],globals:{memorio:{}},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.18"},devDependencies:{"@eslint/js":"9.34.0","@types/jest":"30.0.0","@types/node":"^24.3.0","@typescript-eslint/eslint-plugin":"8.40.0","@typescript-eslint/parser":"8.40.0","dphelper.types":"0.0.18",esbuild:"^0.25.9","esbuild-plugin-clean":"^1.0.1","esbuild-plugin-copy":"^2.1.1",eslint:"9.34.0",jest:"30.0.5","jest-environment-jsdom":"30.0.5","ts-jest":"29.4.1","ts-loader":"^9.5.2","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 n=r=>t?setTimeout(()=>t(r),1):null;globalThis.addEventListener(e,n),globalThis.events[e]=n},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 n=r=>{let o=r.split(".");o.forEach((s,l)=>{let a=o.slice(0,l+1).join(".");globalThis.memorio.dispatch.set(a,{detail:{name:a}})})};return new Proxy(e,{get(r,o){if(o==="list"){let s={};for(let l in r)typeof r[l]!="function"&&!["list","remove","removeAll"].includes(l)&&(s[l]=r[l]);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 l=globalThis.memorio.objPath(o,i);return t({action:"set",path:l,target:r,newValue:s,previousValue:Reflect.get(r,o)}),n("state."+l),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(l){return console.error("Error in set trap:",l),!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}}})},b={};globalThis?.state?globalThis.state=state:globalThis.state=u(b,()=>{});var m=new WeakSet;m.add(state);setInterval(()=>{if(!m.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(window,"cache",{value:new Proxy({},{}),enumerable:!1,configurable:!1});})();
|
package/package.json
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memorio",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "node ./esbuild.config.mjs",
|
|
8
|
+
"watch": "esbuild init.ts --bundle --outdir=dist --serve",
|
|
9
|
+
"-----------": "",
|
|
10
|
+
"test": "set NODE_OPTIONS=--experimental-vm-modules && jest",
|
|
11
|
+
"test:watch": "set NODE_OPTIONS=--experimental-vm-modules && jest --watch",
|
|
12
|
+
"test:coverage": "set NODE_OPTIONS=--experimental-vm-modules && jest --coverage",
|
|
13
|
+
"test:watchAll": "set NODE_OPTIONS=--experimental-vm-modules && jest --watchAll",
|
|
14
|
+
"tsc": "tsc -b .",
|
|
15
|
+
"eslint": "eslint .",
|
|
16
|
+
"updates": "npx npm-check-updates -u && npm i",
|
|
17
|
+
"----------": "",
|
|
18
|
+
"publish:npm": "npm run build && npm publish ./dist"
|
|
19
|
+
},
|
|
6
20
|
"types": "index.d.ts",
|
|
7
21
|
"typings": "./types/*",
|
|
8
22
|
"description": "Memorio, State + Observer and Store for a easy life ",
|
|
@@ -62,30 +76,23 @@
|
|
|
62
76
|
"typing": [
|
|
63
77
|
"types/*"
|
|
64
78
|
],
|
|
65
|
-
"scripts": {
|
|
66
|
-
"build": "node ./esbuild.config.mjs",
|
|
67
|
-
"watch": "esbuild init.ts --bundle --outdir=dist --serve",
|
|
68
|
-
"-----------": "",
|
|
69
|
-
"tsc": "tsc -b .",
|
|
70
|
-
"eslint": "eslint .",
|
|
71
|
-
"updates": "npx npm-check-updates -u && npm i",
|
|
72
|
-
"----------": "",
|
|
73
|
-
"publish:npm": "npm run build && npm publish ./dist"
|
|
74
|
-
},
|
|
75
79
|
"dependencies": {
|
|
76
|
-
"dphelper.types": "0.0.
|
|
80
|
+
"dphelper.types": "0.0.18"
|
|
77
81
|
},
|
|
78
82
|
"devDependencies": {
|
|
79
|
-
"@eslint/js": "9.
|
|
80
|
-
"@types/jest": "
|
|
83
|
+
"@eslint/js": "9.34.0",
|
|
84
|
+
"@types/jest": "30.0.0",
|
|
81
85
|
"@types/node": "^24.3.0",
|
|
82
86
|
"@typescript-eslint/eslint-plugin": "8.40.0",
|
|
83
87
|
"@typescript-eslint/parser": "8.40.0",
|
|
84
|
-
"dphelper.types": "0.0.
|
|
88
|
+
"dphelper.types": "0.0.18",
|
|
85
89
|
"esbuild": "^0.25.9",
|
|
86
90
|
"esbuild-plugin-clean": "^1.0.1",
|
|
87
91
|
"esbuild-plugin-copy": "^2.1.1",
|
|
88
|
-
"eslint": "9.
|
|
92
|
+
"eslint": "9.34.0",
|
|
93
|
+
"jest": "30.0.5",
|
|
94
|
+
"jest-environment-jsdom": "30.0.5",
|
|
95
|
+
"ts-jest": "29.4.1",
|
|
89
96
|
"ts-loader": "^9.5.2",
|
|
90
97
|
"ts-node": "10.9.2",
|
|
91
98
|
"tslib": "^2.8.1",
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
memorio
|
|
3
|
+
Copyright (c) 2025 Dario Passariello <dariopassariello@gmail.com>
|
|
4
|
+
Licensed under MIT License, see
|
|
5
|
+
https://dario.passariello.ca
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create states using: session.set("example",{test:"test"})
|
|
10
|
+
*/
|
|
11
|
+
interface _session {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create a new session
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* session.set("test","example") // or Array, Object, Number, Functions...
|
|
18
|
+
*
|
|
19
|
+
* @since memorio 0.0.1
|
|
20
|
+
* @param name The String as name to define the session.
|
|
21
|
+
* @param param The information taht you want to session (Any).
|
|
22
|
+
* @return boolean
|
|
23
|
+
*/
|
|
24
|
+
set: (name: string, value: any) => void
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Have back the data from a session.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* session.get("test")
|
|
31
|
+
*
|
|
32
|
+
* @since memorio 0.0.1
|
|
33
|
+
* @param name The String as name to define the session.
|
|
34
|
+
*/
|
|
35
|
+
get: (name: string) => any
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Delete an existing session:
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* session.delete("test")
|
|
42
|
+
* session.remove("test")
|
|
43
|
+
*
|
|
44
|
+
* @since memorio 0.0.1
|
|
45
|
+
* @param name The String as name to define the session.
|
|
46
|
+
* @return boolean
|
|
47
|
+
*/
|
|
48
|
+
delete: (name: string) => boolean | undefined
|
|
49
|
+
remove: (name: string) => boolean | undefined
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Delete all storages
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* session.clearAll()
|
|
56
|
+
* session.removeAll()
|
|
57
|
+
*
|
|
58
|
+
* @since memorio 0.0.1
|
|
59
|
+
* @return boolean
|
|
60
|
+
*/
|
|
61
|
+
clearAll: () => boolean
|
|
62
|
+
removeAll: () => boolean
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Know how much space you have for total storages
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* session.quota()
|
|
69
|
+
*
|
|
70
|
+
* @since memorio 0.0.1
|
|
71
|
+
* @return values
|
|
72
|
+
*/
|
|
73
|
+
quota: () => void
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get the size of sessions an the total
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* session.size()
|
|
80
|
+
*
|
|
81
|
+
* @since memorio 0.0.1
|
|
82
|
+
* @return dimension in kb
|
|
83
|
+
*/
|
|
84
|
+
size: () => number
|
|
85
|
+
|
|
86
|
+
// TODO
|
|
87
|
+
// readonly increaseQuota: (value: number) => void
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare var session: _session
|
|
91
|
+
type session = _session
|