memorio 1.0.0 → 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/{dist/README.md → README.md} +27 -88
- package/{dist/index.js → index.js} +1 -1
- package/package.json +3 -3
- package/.editorconfig +0 -31
- package/.gitattributes +0 -1
- package/.github/CHANGELOG.md +0 -10
- package/.github/CITATION.cff +0 -24
- package/.github/CODEOWNERS +0 -1
- package/.github/CODE_OF_CONDUCT.md +0 -108
- package/.github/CONTRIBUTING.md +0 -108
- package/.github/COPYRIGHT.md +0 -9
- package/.github/FUNDING.yml +0 -16
- package/.github/HISTORY.md +0 -1
- package/.github/LICENSE.md +0 -21
- package/.github/README.md +0 -319
- package/.github/SECURITY.md +0 -3
- package/.github/SUMMARY.md +0 -21
- package/.github/dependabot.yml +0 -11
- package/.github/documents/OBSERVER.md +0 -72
- package/.github/documents/STATE.md +0 -72
- package/.github/documents/STORE.md +0 -84
- package/.github/pull_request_template.md +0 -27
- package/.private/npm +0 -1
- package/.vscode/extension.json +0 -15
- package/.vscode/settings.json +0 -90
- package/config/dispatch.ts +0 -49
- package/config/global.ts +0 -36
- package/coverage/clover.xml +0 -260
- package/coverage/coverage-final.json +0 -10
- package/coverage/lcov-report/a51.memorio/config/dispatch.ts.html +0 -232
- package/coverage/lcov-report/a51.memorio/config/global.ts.html +0 -193
- package/coverage/lcov-report/a51.memorio/config/index.html +0 -131
- package/coverage/lcov-report/a51.memorio/dist/config/dispatch.js.html +0 -157
- package/coverage/lcov-report/a51.memorio/dist/config/global.js.html +0 -142
- package/coverage/lcov-report/a51.memorio/dist/config/index.html +0 -131
- package/coverage/lcov-report/a51.memorio/dist/functions/cache/index.html +0 -116
- package/coverage/lcov-report/a51.memorio/dist/functions/cache/index.js.html +0 -103
- package/coverage/lcov-report/a51.memorio/dist/functions/observer/index.html +0 -116
- package/coverage/lcov-report/a51.memorio/dist/functions/observer/index.js.html +0 -280
- package/coverage/lcov-report/a51.memorio/dist/functions/state/index.html +0 -116
- package/coverage/lcov-report/a51.memorio/dist/functions/state/index.js.html +0 -460
- package/coverage/lcov-report/a51.memorio/dist/functions/store/index.html +0 -116
- package/coverage/lcov-report/a51.memorio/dist/functions/store/index.js.html +0 -367
- package/coverage/lcov-report/a51.memorio/dist/index.html +0 -116
- package/coverage/lcov-report/a51.memorio/dist/init.js.html +0 -106
- package/coverage/lcov-report/a51.memorio/functions/cache/index.html +0 -116
- package/coverage/lcov-report/a51.memorio/functions/cache/index.ts.html +0 -142
- package/coverage/lcov-report/a51.memorio/functions/observer/index.html +0 -116
- package/coverage/lcov-report/a51.memorio/functions/observer/index.ts.html +0 -448
- package/coverage/lcov-report/a51.memorio/functions/session/index.html +0 -116
- package/coverage/lcov-report/a51.memorio/functions/session/index.ts.html +0 -409
- package/coverage/lcov-report/a51.memorio/functions/state/index.html +0 -116
- package/coverage/lcov-report/a51.memorio/functions/state/index.ts.html +0 -682
- package/coverage/lcov-report/a51.memorio/functions/store/index.html +0 -116
- package/coverage/lcov-report/a51.memorio/functions/store/index.ts.html +0 -409
- package/coverage/lcov-report/a51.memorio/index.html +0 -131
- package/coverage/lcov-report/a51.memorio/index.ts.html +0 -88
- package/coverage/lcov-report/a51.memorio/init.ts.html +0 -115
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -206
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/session/index.html +0 -116
- package/coverage/lcov-report/session/index.ts.html +0 -571
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/state/index.html +0 -116
- package/coverage/lcov-report/state/index.ts.html +0 -1090
- package/coverage/lcov-report/store/index.html +0 -116
- package/coverage/lcov-report/store/index.ts.html +0 -556
- package/coverage/lcov.info +0 -518
- package/dist/index.d.ts +0 -7
- package/dist/package.json +0 -98
- package/dist/types/cache.d.ts +0 -27
- package/dist/types/memorio.d.ts +0 -18
- package/dist/types/observer.d.ts +0 -47
- package/dist/types/session.d.ts +0 -91
- package/dist/types/state.d.ts +0 -71
- package/dist/types/store.d.ts +0 -91
- package/esbuild.config.mjs +0 -54
- package/eslint.config.mjs +0 -174
- package/examples/bg.jpg +0 -0
- package/examples/bootstrap.less +0 -92
- package/examples/favicon.ico +0 -0
- package/examples/index.htm +0 -65
- package/examples/javascript.js +0 -2
- package/examples/responsive.less +0 -47
- package/examples/styles.less +0 -169
- package/functions/cache/index.ts +0 -19
- package/functions/observer/index.ts +0 -121
- package/functions/session/index.ts +0 -108
- package/functions/state/index.ts +0 -199
- package/functions/store/index.ts +0 -108
- package/index.ts +0 -1
- package/init.ts +0 -12
- package/jest.config.mjs +0 -33
- package/jest.setup.js +0 -2
- package/tests/basic.test.ts +0 -50
- package/tests/cache.test.ts +0 -52
- package/tests/observer.test.ts +0 -62
- package/tests/setup.ts +0 -48
- package/tests/state.test.ts +0 -45
- package/tests/store.test.ts +0 -62
- package/tsconfig.json +0 -67
package/examples/styles.less
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
@import url('https://fonts.googleapis.com/css2?family=Lato');
|
|
2
|
-
|
|
3
|
-
// Copyright (c) 2024 Dario Passariello
|
|
4
|
-
|
|
5
|
-
:root {
|
|
6
|
-
--header-height: 30px;
|
|
7
|
-
--aside: 300px;
|
|
8
|
-
--w1: 15px;
|
|
9
|
-
--w2: 35px;
|
|
10
|
-
--h1: 20px;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// html{
|
|
14
|
-
// display: none;
|
|
15
|
-
// }
|
|
16
|
-
|
|
17
|
-
* {
|
|
18
|
-
font-family: 'Lato', sans-serif;
|
|
19
|
-
|
|
20
|
-
&::backdrop {
|
|
21
|
-
background-color: rgba(255, 255, 255, 0);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
html,
|
|
26
|
-
body {
|
|
27
|
-
cursor: default;
|
|
28
|
-
margin: 0;
|
|
29
|
-
padding: 0;
|
|
30
|
-
font-size: 1em;
|
|
31
|
-
position: absolute;
|
|
32
|
-
top: 0;
|
|
33
|
-
left: 0;
|
|
34
|
-
right: 0;
|
|
35
|
-
bottom: 0;
|
|
36
|
-
overflow: hidden;
|
|
37
|
-
|
|
38
|
-
&:before {
|
|
39
|
-
content: '';
|
|
40
|
-
position: absolute;
|
|
41
|
-
top: 0;
|
|
42
|
-
left: 0;
|
|
43
|
-
right: 0;
|
|
44
|
-
bottom: 0;
|
|
45
|
-
background-image: url('bg.jpg');
|
|
46
|
-
background-size: cover;
|
|
47
|
-
filter: blur(4px);
|
|
48
|
-
z-index: 0
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
header {
|
|
52
|
-
position: absolute;
|
|
53
|
-
top: 0;
|
|
54
|
-
height: var(--header-height);
|
|
55
|
-
left: 0;
|
|
56
|
-
right: 0;
|
|
57
|
-
background: black;
|
|
58
|
-
color: white;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
aside {
|
|
62
|
-
padding: 15px 0;
|
|
63
|
-
display: flex;
|
|
64
|
-
flex-direction: column;
|
|
65
|
-
align-items: center;
|
|
66
|
-
position: absolute;
|
|
67
|
-
top: var(--header-height);
|
|
68
|
-
left: 0;
|
|
69
|
-
bottom: 0;
|
|
70
|
-
width: var(--aside);
|
|
71
|
-
border-right: 1px solid #bbb;
|
|
72
|
-
overflow: auto;
|
|
73
|
-
background: #eee;
|
|
74
|
-
|
|
75
|
-
section {
|
|
76
|
-
display: flex
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
hr {
|
|
80
|
-
width: 150px;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
.table {
|
|
84
|
-
.title {
|
|
85
|
-
display: flex;
|
|
86
|
-
padding-left: var(--w1);
|
|
87
|
-
display: flex;
|
|
88
|
-
|
|
89
|
-
span {
|
|
90
|
-
color: cornflowerblue;
|
|
91
|
-
text-align: center;
|
|
92
|
-
font-size: .65em;
|
|
93
|
-
width: var(--w2);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
.row {
|
|
98
|
-
display: flex;
|
|
99
|
-
|
|
100
|
-
>span {
|
|
101
|
-
color: cornflowerblue;
|
|
102
|
-
font-size: .65em;
|
|
103
|
-
width: var(--w1);
|
|
104
|
-
text-align: right;
|
|
105
|
-
padding-right: 3px;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
input {
|
|
109
|
-
width: var(--w2);
|
|
110
|
-
height: var(--h1);
|
|
111
|
-
padding: 1px;
|
|
112
|
-
text-align: center;
|
|
113
|
-
font-size: .65em;
|
|
114
|
-
border: 1px solid #ddd;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
main {
|
|
121
|
-
display: flex;
|
|
122
|
-
flex-direction: column;
|
|
123
|
-
align-items: center;
|
|
124
|
-
position: absolute;
|
|
125
|
-
top: var(--header-height);
|
|
126
|
-
left: var(--aside);
|
|
127
|
-
right: 0;
|
|
128
|
-
bottom: 0;
|
|
129
|
-
overflow: auto;
|
|
130
|
-
|
|
131
|
-
>span {
|
|
132
|
-
position: absolute;
|
|
133
|
-
top: 10px;
|
|
134
|
-
right: 10px;
|
|
135
|
-
width: unset
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
button {
|
|
139
|
-
font-size: 1em;
|
|
140
|
-
margin: 3px;
|
|
141
|
-
padding: 8px;
|
|
142
|
-
width: 390px;
|
|
143
|
-
border-radius: 10px;
|
|
144
|
-
border: 1px solid #AAA;
|
|
145
|
-
color: #AAA;
|
|
146
|
-
text-shadow: black 0 -1px, white 0 1px;
|
|
147
|
-
|
|
148
|
-
&:hover {
|
|
149
|
-
background: #CCC;
|
|
150
|
-
cursor: pointer;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
hr {
|
|
155
|
-
background: gray;
|
|
156
|
-
height: 1px;
|
|
157
|
-
width: 350px;
|
|
158
|
-
margin: 10px;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
footer {
|
|
163
|
-
position: absolute;
|
|
164
|
-
bottom: 10px;
|
|
165
|
-
right: 20px;
|
|
166
|
-
font-size: .8em;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
}
|
package/functions/cache/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(
|
|
2
|
-
window,
|
|
3
|
-
"cache",
|
|
4
|
-
{
|
|
5
|
-
value: new Proxy({}, {}),
|
|
6
|
-
enumerable: false,
|
|
7
|
-
configurable: false
|
|
8
|
-
}
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
// Object.defineProperties(
|
|
12
|
-
// cache,
|
|
13
|
-
// {
|
|
14
|
-
// get: {},
|
|
15
|
-
// set: {}
|
|
16
|
-
// }
|
|
17
|
-
// )
|
|
18
|
-
|
|
19
|
-
export { }
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
if (!globalThis.observer) globalThis.observer = null
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(
|
|
4
|
-
globalThis,
|
|
5
|
-
'observer',
|
|
6
|
-
{
|
|
7
|
-
enumerable: false
|
|
8
|
-
}
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
12
|
-
// START OBSERVER FUNCTION
|
|
13
|
-
|
|
14
|
-
observer = (s, cb = null, option = true) => {
|
|
15
|
-
|
|
16
|
-
// CHECK IF 'STATE.' OR 'STORE.' EXIST
|
|
17
|
-
const checkStateOrStore = (s: string) => {
|
|
18
|
-
const t = s.split('.')
|
|
19
|
-
if (t[0] !== 'state') {
|
|
20
|
-
console.error(`Observer Error: You need to declare 'state.' or 'store.'. The '${s}' string is incorrect!`)
|
|
21
|
-
return false
|
|
22
|
-
}
|
|
23
|
-
return true
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!checkStateOrStore(s)) return
|
|
27
|
-
|
|
28
|
-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
29
|
-
|
|
30
|
-
// LIST ALL ARRAY FROM STATE
|
|
31
|
-
if (!s && !cb) {
|
|
32
|
-
console.error('Observer Error: You need to setup observer correctly, Some parameters are missed!')
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
////////////////////////////
|
|
37
|
-
|
|
38
|
-
// CHECK
|
|
39
|
-
if (!s && cb) {
|
|
40
|
-
console.error(`Observer Error: You need to declare what state need to be monitored as string like 'state.test'.`)
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
////////////////////////////
|
|
45
|
-
|
|
46
|
-
// RECALL
|
|
47
|
-
if (s && !cb) {
|
|
48
|
-
globalThis.memorio.dispatch.listen(
|
|
49
|
-
String(s),
|
|
50
|
-
{
|
|
51
|
-
detail: {
|
|
52
|
-
name: String(s)
|
|
53
|
-
}
|
|
54
|
-
} as any
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
console.debug('called: ', s)
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
////////////////////////////
|
|
62
|
-
|
|
63
|
-
// SETUP
|
|
64
|
-
if (s && cb) {
|
|
65
|
-
if (typeof s !== 'string' || typeof cb !== 'function') {
|
|
66
|
-
console.error(`Observer Error: name of state need to be a 'string' like 'state.test' and the callback need to be a 'function'`)
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
globalThis.memorio.dispatch.listen(s, cb, option)
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
76
|
-
|
|
77
|
-
Object.defineProperties(
|
|
78
|
-
observer,
|
|
79
|
-
{
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* See the list of all your observer (eventListener) actually installed.
|
|
83
|
-
* @returns The list of all installed observers.
|
|
84
|
-
*/
|
|
85
|
-
list: {
|
|
86
|
-
get: () => globalThis.events
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
/////////////////////////////////////////////////////
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Remove an observer.
|
|
93
|
-
* @param name The name of the observer to remove.
|
|
94
|
-
*/
|
|
95
|
-
remove: {
|
|
96
|
-
value: (name: any) => {
|
|
97
|
-
if (!name) return
|
|
98
|
-
globalThis.events[name] = ''
|
|
99
|
-
return
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
/////////////////////////////////////////////////////
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Remove all observers.
|
|
107
|
-
* @returns void
|
|
108
|
-
*/
|
|
109
|
-
removeAll: {
|
|
110
|
-
get: () => {
|
|
111
|
-
Object.entries(observer.list).forEach((el: any) => {
|
|
112
|
-
globalThis.events[el[0]]
|
|
113
|
-
})
|
|
114
|
-
return
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
Object.freeze(observer)
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(
|
|
3
|
-
globalThis,
|
|
4
|
-
'session',
|
|
5
|
-
{
|
|
6
|
-
value: new Proxy({}, {}),
|
|
7
|
-
enumerable: false,
|
|
8
|
-
configurable: false
|
|
9
|
-
}
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
Object.defineProperties(
|
|
13
|
-
session,
|
|
14
|
-
{
|
|
15
|
-
get: {
|
|
16
|
-
value(name: string) {
|
|
17
|
-
if (!name) return
|
|
18
|
-
try {
|
|
19
|
-
const item = sessionStorage.getItem(name)
|
|
20
|
-
if (item) return JSON.parse(item)
|
|
21
|
-
return item
|
|
22
|
-
} catch (err) {
|
|
23
|
-
console.error(`Error parsing session item '${name}':`, err)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
set: {
|
|
29
|
-
value(name: string, value: any) {
|
|
30
|
-
if (!name) return
|
|
31
|
-
try {
|
|
32
|
-
|
|
33
|
-
if (value === null || value === undefined) sessionStorage.setItem(name, JSON.stringify(null))
|
|
34
|
-
else if (typeof value === 'object' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'string') sessionStorage.setItem(name, JSON.stringify(value))
|
|
35
|
-
else if (typeof value === 'function') console.error('It\'s not secure to session functions.')
|
|
36
|
-
|
|
37
|
-
} catch (err) {
|
|
38
|
-
|
|
39
|
-
console.error(`Error setting session item '${name}':`, err)
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
remove: {
|
|
46
|
-
value(name: string) {
|
|
47
|
-
if (!name) return
|
|
48
|
-
if (sessionStorage.getItem(name)) {
|
|
49
|
-
sessionStorage.removeItem(name)
|
|
50
|
-
return true
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
delete: {
|
|
56
|
-
value(name: string) {
|
|
57
|
-
session.remove(name)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
removeAll: {
|
|
63
|
-
value() {
|
|
64
|
-
sessionStorage.clear()
|
|
65
|
-
return true
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
clearAll: {
|
|
70
|
-
value() {
|
|
71
|
-
session.removeAll()
|
|
72
|
-
return true
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
quota: {
|
|
77
|
-
value() {
|
|
78
|
-
if ('storage' in navigator && 'estimate' in navigator.storage) {
|
|
79
|
-
navigator.storage.estimate()
|
|
80
|
-
.then(
|
|
81
|
-
({ usage, quota }) => {
|
|
82
|
-
if (usage && quota) console.debug(`Using ${usage / 1024} out of ${quota / 1024} Mb.`)
|
|
83
|
-
}
|
|
84
|
-
)
|
|
85
|
-
.catch(err => { console.error('Error estimating quota:', err) })
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
size: {
|
|
91
|
-
value() {
|
|
92
|
-
let totalSize = 0
|
|
93
|
-
for (const key in sessionStorage) {
|
|
94
|
-
if (sessionStorage.hasOwnProperty(key)) {
|
|
95
|
-
const item = sessionStorage.getItem(key)
|
|
96
|
-
if (item) {
|
|
97
|
-
totalSize += item.length
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return totalSize
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
Object.freeze(session)
|
package/functions/state/index.ts
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(
|
|
2
|
-
memorio,
|
|
3
|
-
'objPath',
|
|
4
|
-
{
|
|
5
|
-
writable: false,
|
|
6
|
-
configurable: false,
|
|
7
|
-
enumerable: false,
|
|
8
|
-
value: (prop: string, object: string[], separator: string = '.'): string => {
|
|
9
|
-
return object.concat(prop).join(separator)
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
/////////////////////////////////////////////////////
|
|
15
|
-
|
|
16
|
-
export const buildProxy = (obj: Record<string, any>, callback: (props: any) => void, tree: string[] = []): any => {
|
|
17
|
-
|
|
18
|
-
// EVENT FUNCTION FOR OBSERVER
|
|
19
|
-
const event = (name: string) => {
|
|
20
|
-
const array = name.split('.')
|
|
21
|
-
array.forEach(
|
|
22
|
-
(x, i) => {
|
|
23
|
-
const command = array.slice(0, i + 1).join('.')
|
|
24
|
-
globalThis.memorio.dispatch.set(command, { detail: { name: command } })
|
|
25
|
-
}
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
///////////////////////////////////////////////
|
|
30
|
-
|
|
31
|
-
// CREATE THE PROXY
|
|
32
|
-
return new Proxy(
|
|
33
|
-
obj,
|
|
34
|
-
{
|
|
35
|
-
get(target: any, prop: any) {
|
|
36
|
-
// Handle special methods first
|
|
37
|
-
if (prop === 'list') {
|
|
38
|
-
const result = {}
|
|
39
|
-
for (const key in target) {
|
|
40
|
-
if (typeof target[key] !== 'function' && !['list', 'remove', 'removeAll'].includes(key)) {
|
|
41
|
-
result[key] = target[key]
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return result
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (prop === 'remove') {
|
|
48
|
-
return function (key: string) {
|
|
49
|
-
if (key in target && !['list', 'remove', 'removeAll'].includes(key)) {
|
|
50
|
-
delete target[key]
|
|
51
|
-
return true
|
|
52
|
-
}
|
|
53
|
-
return false
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (prop === 'removeAll') {
|
|
58
|
-
return function () {
|
|
59
|
-
for (const key in target) {
|
|
60
|
-
if (typeof target[key] !== 'function' && !['list', 'remove', 'removeAll'].includes(key)) {
|
|
61
|
-
delete target[key]
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return true
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (Object.isFrozen(target[prop])) return target[prop]
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
const value = Reflect.get(target, prop)
|
|
72
|
-
if (value && typeof value === 'object' && ['Array', 'Object'].includes(value.constructor.name)) {
|
|
73
|
-
return buildProxy(value, callback, tree.concat(prop as string))
|
|
74
|
-
}
|
|
75
|
-
return value
|
|
76
|
-
} catch (error) {
|
|
77
|
-
console.error('Error: ', error)
|
|
78
|
-
return undefined
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
set(target: any, prop: string, value: any): boolean {
|
|
83
|
-
|
|
84
|
-
if (target[prop] && typeof target[prop] === 'object' && Object.isFrozen(target[prop])) {
|
|
85
|
-
console.error(`Error: state '${prop}' is locked`)
|
|
86
|
-
return
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
|
|
91
|
-
const path = globalThis.memorio.objPath(prop as string, tree)
|
|
92
|
-
|
|
93
|
-
callback(
|
|
94
|
-
{
|
|
95
|
-
action: 'set',
|
|
96
|
-
path,
|
|
97
|
-
target,
|
|
98
|
-
newValue: value,
|
|
99
|
-
previousValue: Reflect.get(target, prop)
|
|
100
|
-
}
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
event('state.' + path)
|
|
104
|
-
|
|
105
|
-
Reflect.set(target, prop, value)
|
|
106
|
-
|
|
107
|
-
// DEFINE LOCK PROPERTY FUNCTION
|
|
108
|
-
if (target[prop] && typeof target[prop] === 'object') {
|
|
109
|
-
|
|
110
|
-
Reflect.defineProperty(
|
|
111
|
-
target[prop],
|
|
112
|
-
'lock',
|
|
113
|
-
{
|
|
114
|
-
value() {
|
|
115
|
-
Object.defineProperty(
|
|
116
|
-
target,
|
|
117
|
-
prop,
|
|
118
|
-
{
|
|
119
|
-
writable: false,
|
|
120
|
-
enumerable: false
|
|
121
|
-
// configurable: false
|
|
122
|
-
}
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
Object.freeze(target[prop])
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return true
|
|
133
|
-
|
|
134
|
-
} catch (error) {
|
|
135
|
-
|
|
136
|
-
console.error('Error in set trap:', error)
|
|
137
|
-
return false
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
deleteProperty(target: any, prop: string | symbol): boolean {
|
|
144
|
-
try {
|
|
145
|
-
const path = globalThis.memorio.objPath(prop as string, tree)
|
|
146
|
-
callback({ action: 'delete', path, target })
|
|
147
|
-
return Reflect.deleteProperty(target, prop)
|
|
148
|
-
} catch (error) {
|
|
149
|
-
console.error('Error in deleteProperty trap:', error)
|
|
150
|
-
return false
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Initialize base state object
|
|
161
|
-
const baseState = {}
|
|
162
|
-
|
|
163
|
-
// SET STATE AS PROXY
|
|
164
|
-
!globalThis?.state
|
|
165
|
-
? globalThis.state = buildProxy(baseState, () => { })
|
|
166
|
-
: globalThis.state = state
|
|
167
|
-
|
|
168
|
-
///////////////////////////////////////////////
|
|
169
|
-
|
|
170
|
-
// TEST IF STATE IS A PROXY
|
|
171
|
-
const testProxy = new WeakSet()
|
|
172
|
-
|
|
173
|
-
testProxy.add(state)
|
|
174
|
-
|
|
175
|
-
setInterval(
|
|
176
|
-
() => {
|
|
177
|
-
if (!testProxy.has(state)) {
|
|
178
|
-
alert('memorio State is compromised, check if you override it and please reload the page')
|
|
179
|
-
for (let i = 1; i < 99999; i++) clearInterval(i)
|
|
180
|
-
stop()
|
|
181
|
-
}
|
|
182
|
-
}, 1000
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
///////////////////////////////////////////////
|
|
186
|
-
|
|
187
|
-
// DEFINE THE STATE IN GLOBAL
|
|
188
|
-
Object.defineProperty(
|
|
189
|
-
globalThis,
|
|
190
|
-
'state',
|
|
191
|
-
{
|
|
192
|
-
enumerable: false,
|
|
193
|
-
configurable: false
|
|
194
|
-
}
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
///////////////////////////////////////////////
|
|
198
|
-
|
|
199
|
-
// END
|