memorio 0.2.10 → 0.2.12
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.d.ts +6 -0
- package/index.js +1 -1
- package/package.json +6 -1
- package/types/cache.d.ts +27 -0
- package/types/memorio.d.ts +23 -0
- package/types/observer.d.ts +47 -0
- package/types/state.d.ts +71 -0
- package/types/store.d.ts +91 -0
package/index.d.ts
ADDED
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var f=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var n=(e,r)=>()=>(e&&(r=e(e=0)),r);var T=(e,r,s,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of P(r))!S.call(e,t)&&t!==s&&f(e,t,{get:()=>r[t],enumerable:!(l=O(r,t))||l.enumerable});return e};var c=e=>T(f({},"__esModule",{value:!0}),e);var g,b=n(()=>{g={name:"memorio",version:"0.2.
|
|
1
|
+
"use strict";(()=>{var f=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var n=(e,r)=>()=>(e&&(r=e(e=0)),r);var T=(e,r,s,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of P(r))!S.call(e,t)&&t!==s&&f(e,t,{get:()=>r[t],enumerable:!(l=O(r,t))||l.enumerable});return e};var c=e=>T(f({},"__esModule",{value:!0}),e);var g,b=n(()=>{g={name:"memorio",version:"0.2.12",type:"module",main:"index.js",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/*"],scripts:{build:"node ./esbuild.config.mjs",watch:"esbuild init.ts --bundle --outdir=dist --serve","-----------":"",tsc:"tsc -b .",eslint:"eslint .",updates:"npx npm-check-updates -u && npm i","----------":"","publish:npm":"npm run build && npm publish ./dist"},dependencies:{"dphelper.types":"0.0.14"},devDependencies:{"@eslint/js":"9.33.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.14",esbuild:"^0.25.9","esbuild-plugin-clean":"^1.0.1","esbuild-plugin-copy":"^2.1.1",eslint:"9.33.0","ts-loader":"^9.5.2","ts-node":"10.9.2",tslib:"^2.8.1",typescript:"5.9.2"}}});var E={};var m=n(()=>{"use strict";b();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:g.version})});var k={};var d=n(()=>{"use strict";Object.defineProperty(memorio,"dispatch",{writable:!1,configurable:!1,enumerable:!1,value:{set:(e,r={})=>{dispatchEvent(new CustomEvent(String(e),r))},listen:(e,r=null,s=!1)=>{observer.list?.[e]?.length>0&&observer.remove(e);let l=t=>r?setTimeout(()=>r(t),1):null;globalThis.addEventListener(e,l),globalThis.events[e]=l},remove:e=>{globalThis.removeEventListener(e,globalThis.events[e]),delete globalThis.events[e]}}})});var x={};var p,h,y=n(()=>{"use strict";Object.defineProperty(memorio,"objPath",{writable:!1,configurable:!1,enumerable:!1,value:(e,r,s=".")=>r.concat(e).join(s)});p=(e,r,s=[])=>{let l=t=>{let o=t.split(".");o.forEach((i,a)=>{let u=o.slice(0,a+1).join(".");globalThis.memorio.dispatch.set(u,{detail:{name:u}})})};return new Proxy(e,{get(t,o){if(Object.isFrozen(t[o]))return t[o];try{let i=Reflect.get(t,o);return i&&typeof i=="object"&&["Array","Object"].includes(i.constructor.name)?p(i,r,s.concat(o)):i}catch(i){return console.error("Error: ",i),!1}},set(t,o,i){if(t[o]&&typeof t[o]=="object"&&Object.isFrozen(t[o])){console.error(`Error: state '${o}' is locked`);return}try{let a=globalThis.memorio.objPath(o,s);return r({action:"set",path:a,target:t,newValue:i,previousValue:Reflect.get(t,o)}),l("state."+a),Reflect.set(t,o,i),t[o]&&typeof t[o]=="object"&&Reflect.defineProperty(t[o],"lock",{value(){Object.defineProperty(t,o,{writable:!1,enumerable:!1}),Object.freeze(t[o])}}),!0}catch(a){return console.error("Error in set trap:",a),!1}},deleteProperty(t,o){try{let i=globalThis.memorio.objPath(o,s);return r({action:"delete",path:i,target:t}),Reflect.deleteProperty(t,o)}catch(i){return console.error("Error in deleteProperty trap:",i),!1}}})};globalThis?.state?globalThis.state=state:globalThis.state=p({},()=>{});h=new WeakSet;h.add(state);setInterval(()=>{if(!h.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});Object.defineProperties(state,{list:{get(){let e=globalThis.memorio.array.deepClone(state);return console.log(e)}},remove:{value(e){e in state?(delete state[e],console.debug(`State '${e}' deleted`)):console.error(`'${e}' not exist`)},writable:!1,configurable:!1},removeAll:{value(){state.forEach(e=>{delete state[e[0]]})},writable:!1,configurable:!1}})});var I={};var v=n(()=>{"use strict";globalThis.observer||(globalThis.observer=null);Object.defineProperty(globalThis,"observer",{enumerable:!1});observer=(e,r=null,s=!0)=>{if((t=>t.split(".")[0]!=="state"?(console.error(`Observer Error: You need to declare 'state.' or 'store.'. The '${t}' string is incorrect!`),!1):!0)(e)){if(!e&&!r){console.error("Observer Error: You need to setup observer correctly, Some parameters are missed!");return}if(!e&&r){console.error("Observer Error: You need to declare what state need to be monitored as string like 'state.test'.");return}if(e&&!r){globalThis.memorio.dispatch.listen(String(e),{detail:{name:String(e)}}),console.debug("called: ",e);return}if(e&&r){if(typeof e!="string"||typeof r!="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,r,s);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)});var $={};var j=n(()=>{"use strict";Object.defineProperty(globalThis,"store",{value:new Proxy({},{}),enumerable:!1,configurable:!1});Object.defineProperties(store,{get:{value(e){if(e)try{let r=localStorage.getItem(e);return r&&JSON.parse(r)}catch(r){console.error(`Error parsing store item '${e}':`,r)}}},set:{value(e,r){if(e)try{r==null?localStorage.setItem(e,JSON.stringify(null)):typeof r=="object"||typeof r=="number"||typeof r=="boolean"||typeof r=="string"?localStorage.setItem(e,JSON.stringify(r)):typeof r=="function"&&console.error("It's not secure to store functions.")}catch(s){console.error(`Error setting store item '${e}':`,s)}}},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:r})=>{e&&r&&console.debug(`Using ${e/1024} out of ${r/1024} Mb.`)}).catch(e=>{console.error("Error estimating quota:",e)})}},size:{value(){let e=0;for(let r in localStorage)if(localStorage.hasOwnProperty(r)){let s=localStorage.getItem(r);s&&(e+=s.length)}return e}}});Object.freeze(store)});m();d();y();v();j();})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memorio",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -59,6 +59,9 @@
|
|
|
59
59
|
"url": "https://www.patreon.com/passariello"
|
|
60
60
|
}
|
|
61
61
|
],
|
|
62
|
+
"typing": [
|
|
63
|
+
"types/*"
|
|
64
|
+
],
|
|
62
65
|
"scripts": {
|
|
63
66
|
"build": "node ./esbuild.config.mjs",
|
|
64
67
|
"watch": "esbuild init.ts --bundle --outdir=dist --serve",
|
|
@@ -76,6 +79,8 @@
|
|
|
76
79
|
"@eslint/js": "9.33.0",
|
|
77
80
|
"@types/jest": "^30.0.0",
|
|
78
81
|
"@types/node": "^24.3.0",
|
|
82
|
+
"@typescript-eslint/eslint-plugin": "8.40.0",
|
|
83
|
+
"@typescript-eslint/parser": "8.40.0",
|
|
79
84
|
"dphelper.types": "0.0.14",
|
|
80
85
|
"esbuild": "^0.25.9",
|
|
81
86
|
"esbuild-plugin-clean": "^1.0.1",
|
package/types/cache.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
dphelper
|
|
3
|
+
Copyright (c) 2019 Dario Passariello <dariopassariello@gmail.com>
|
|
4
|
+
Licensed under MIT License, see
|
|
5
|
+
https://dario.passariello.ca
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Cache is used for internal use only... but you can use if you need.
|
|
10
|
+
* @return Some stuff you cache... usually used for dynamic imports from dphelper.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
interface _cache {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Create a cache, please use state instead!
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* cache.myCache = any
|
|
20
|
+
*
|
|
21
|
+
* @since dphelper 1.0.6
|
|
22
|
+
*/
|
|
23
|
+
[key: string]: any
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare var cache: _cache
|
|
27
|
+
type cache = _cache
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
declare module 'memorio' {
|
|
3
|
+
const resource: { [key: string]: any }
|
|
4
|
+
export = resource
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface _memorio {
|
|
8
|
+
setProps: any,
|
|
9
|
+
obj: any,
|
|
10
|
+
array: any,
|
|
11
|
+
dispatch: any,
|
|
12
|
+
setDescription: any
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type memorio = _memorio
|
|
16
|
+
declare var memorio: any
|
|
17
|
+
|
|
18
|
+
type arguments = any
|
|
19
|
+
declare var arguments: any
|
|
20
|
+
|
|
21
|
+
global.memorio = global.memorio
|
|
22
|
+
? global.memorio
|
|
23
|
+
: globalThis.memorio
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
* Observer run a callback anytime the associated state going to change
|
|
10
|
+
* @return Execution of function after state change.
|
|
11
|
+
*/
|
|
12
|
+
interface _observer {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Generate your observer
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* observer("myState", Function)
|
|
19
|
+
*
|
|
20
|
+
* @since memorio 1.0.6
|
|
21
|
+
*/
|
|
22
|
+
(stateName: string, callBack: any): any
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* List of active observers
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* observer.list()
|
|
29
|
+
*
|
|
30
|
+
* @since memorio 1.0.6
|
|
31
|
+
*/
|
|
32
|
+
readonly list?: () => void
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Remove the active observer (not the state)
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* observer.remove("myState")
|
|
39
|
+
*
|
|
40
|
+
* @since memorio 1.0.6
|
|
41
|
+
*/
|
|
42
|
+
readonly remove?: (name: string, callBack?: any, flag?: boolean) => void
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare var observer: _observer
|
|
47
|
+
type observer = _observer
|
package/types/state.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
* If you use only "state" you get the entire Proxy object
|
|
10
|
+
* @return Proxy Object of all states.
|
|
11
|
+
*/
|
|
12
|
+
interface _state {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create states using: state.test = "example"
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* state.myStuff = any
|
|
19
|
+
*
|
|
20
|
+
* @since memorio 0.0.1
|
|
21
|
+
* @param key The name of the state for which you want to modify the action.
|
|
22
|
+
* @return The previous values (Any).
|
|
23
|
+
* Important: Object is a Proxy.
|
|
24
|
+
*/
|
|
25
|
+
[key: string]: any
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Delete entire state using: state.remove("test")
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* state.remove(stateName)
|
|
32
|
+
*
|
|
33
|
+
* @since memorio 0.0.1
|
|
34
|
+
* @param stateName The name of the state for which you want to delete.
|
|
35
|
+
* @return boolean.
|
|
36
|
+
*/
|
|
37
|
+
readonly remove?: (stateName: string) => any
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* List all states using: state.list
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* state.removeAll()
|
|
44
|
+
*
|
|
45
|
+
* @since memorio 1.8.92
|
|
46
|
+
* @return Remove all states.
|
|
47
|
+
*/
|
|
48
|
+
readonly removeAll?: () => any
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* List all states using: state.list
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* state.list
|
|
55
|
+
*
|
|
56
|
+
* @since memorio 0.0.1
|
|
57
|
+
* @return Object of all states (Not the Proxy).
|
|
58
|
+
*/
|
|
59
|
+
readonly list?: (stateName: string) => any
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Generate a message for "memorio"
|
|
63
|
+
* Note: FOR INTERNAL USE ONLY.
|
|
64
|
+
* @since memorio 0.0.1
|
|
65
|
+
*/
|
|
66
|
+
readonly mex?: any
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare var state: _state
|
|
71
|
+
type state = _state
|
package/types/store.d.ts
ADDED
|
@@ -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: store.set("example",{test:"test"})
|
|
10
|
+
*/
|
|
11
|
+
interface _store {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create a new store
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* store.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 store.
|
|
21
|
+
* @param param The information taht you want to store (Any).
|
|
22
|
+
* @return boolean
|
|
23
|
+
*/
|
|
24
|
+
set: (name: string, value: any) => void
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Have back the data from a store.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* store.get("test")
|
|
31
|
+
*
|
|
32
|
+
* @since memorio 0.0.1
|
|
33
|
+
* @param name The String as name to define the store.
|
|
34
|
+
*/
|
|
35
|
+
get: (name: string) => any
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Delete an existing store:
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* store.delete("test")
|
|
42
|
+
* store.remove("test")
|
|
43
|
+
*
|
|
44
|
+
* @since memorio 0.0.1
|
|
45
|
+
* @param name The String as name to define the store.
|
|
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
|
+
* store.clearAll()
|
|
56
|
+
* store.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
|
+
* store.quota()
|
|
69
|
+
*
|
|
70
|
+
* @since memorio 0.0.1
|
|
71
|
+
* @return values
|
|
72
|
+
*/
|
|
73
|
+
quota: () => void
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get the size of stores an the total
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* store.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 store: _store
|
|
91
|
+
type store = _store
|