memorio 1.0.0 → 1.0.2

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 (106) hide show
  1. package/{dist/index.js → index.js} +1 -1
  2. package/package.json +1 -1
  3. package/.editorconfig +0 -31
  4. package/.gitattributes +0 -1
  5. package/.github/CHANGELOG.md +0 -10
  6. package/.github/CITATION.cff +0 -24
  7. package/.github/CODEOWNERS +0 -1
  8. package/.github/CODE_OF_CONDUCT.md +0 -108
  9. package/.github/CONTRIBUTING.md +0 -108
  10. package/.github/COPYRIGHT.md +0 -9
  11. package/.github/FUNDING.yml +0 -16
  12. package/.github/HISTORY.md +0 -1
  13. package/.github/LICENSE.md +0 -21
  14. package/.github/SECURITY.md +0 -3
  15. package/.github/SUMMARY.md +0 -21
  16. package/.github/dependabot.yml +0 -11
  17. package/.github/documents/OBSERVER.md +0 -72
  18. package/.github/documents/STATE.md +0 -72
  19. package/.github/documents/STORE.md +0 -84
  20. package/.github/pull_request_template.md +0 -27
  21. package/.private/npm +0 -1
  22. package/.vscode/extension.json +0 -15
  23. package/.vscode/settings.json +0 -90
  24. package/config/dispatch.ts +0 -49
  25. package/config/global.ts +0 -36
  26. package/coverage/clover.xml +0 -260
  27. package/coverage/coverage-final.json +0 -10
  28. package/coverage/lcov-report/a51.memorio/config/dispatch.ts.html +0 -232
  29. package/coverage/lcov-report/a51.memorio/config/global.ts.html +0 -193
  30. package/coverage/lcov-report/a51.memorio/config/index.html +0 -131
  31. package/coverage/lcov-report/a51.memorio/dist/config/dispatch.js.html +0 -157
  32. package/coverage/lcov-report/a51.memorio/dist/config/global.js.html +0 -142
  33. package/coverage/lcov-report/a51.memorio/dist/config/index.html +0 -131
  34. package/coverage/lcov-report/a51.memorio/dist/functions/cache/index.html +0 -116
  35. package/coverage/lcov-report/a51.memorio/dist/functions/cache/index.js.html +0 -103
  36. package/coverage/lcov-report/a51.memorio/dist/functions/observer/index.html +0 -116
  37. package/coverage/lcov-report/a51.memorio/dist/functions/observer/index.js.html +0 -280
  38. package/coverage/lcov-report/a51.memorio/dist/functions/state/index.html +0 -116
  39. package/coverage/lcov-report/a51.memorio/dist/functions/state/index.js.html +0 -460
  40. package/coverage/lcov-report/a51.memorio/dist/functions/store/index.html +0 -116
  41. package/coverage/lcov-report/a51.memorio/dist/functions/store/index.js.html +0 -367
  42. package/coverage/lcov-report/a51.memorio/dist/index.html +0 -116
  43. package/coverage/lcov-report/a51.memorio/dist/init.js.html +0 -106
  44. package/coverage/lcov-report/a51.memorio/functions/cache/index.html +0 -116
  45. package/coverage/lcov-report/a51.memorio/functions/cache/index.ts.html +0 -142
  46. package/coverage/lcov-report/a51.memorio/functions/observer/index.html +0 -116
  47. package/coverage/lcov-report/a51.memorio/functions/observer/index.ts.html +0 -448
  48. package/coverage/lcov-report/a51.memorio/functions/session/index.html +0 -116
  49. package/coverage/lcov-report/a51.memorio/functions/session/index.ts.html +0 -409
  50. package/coverage/lcov-report/a51.memorio/functions/state/index.html +0 -116
  51. package/coverage/lcov-report/a51.memorio/functions/state/index.ts.html +0 -682
  52. package/coverage/lcov-report/a51.memorio/functions/store/index.html +0 -116
  53. package/coverage/lcov-report/a51.memorio/functions/store/index.ts.html +0 -409
  54. package/coverage/lcov-report/a51.memorio/index.html +0 -131
  55. package/coverage/lcov-report/a51.memorio/index.ts.html +0 -88
  56. package/coverage/lcov-report/a51.memorio/init.ts.html +0 -115
  57. package/coverage/lcov-report/base.css +0 -224
  58. package/coverage/lcov-report/block-navigation.js +0 -87
  59. package/coverage/lcov-report/favicon.png +0 -0
  60. package/coverage/lcov-report/index.html +0 -206
  61. package/coverage/lcov-report/prettify.css +0 -1
  62. package/coverage/lcov-report/prettify.js +0 -2
  63. package/coverage/lcov-report/session/index.html +0 -116
  64. package/coverage/lcov-report/session/index.ts.html +0 -571
  65. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  66. package/coverage/lcov-report/sorter.js +0 -210
  67. package/coverage/lcov-report/state/index.html +0 -116
  68. package/coverage/lcov-report/state/index.ts.html +0 -1090
  69. package/coverage/lcov-report/store/index.html +0 -116
  70. package/coverage/lcov-report/store/index.ts.html +0 -556
  71. package/coverage/lcov.info +0 -518
  72. package/dist/README.md +0 -319
  73. package/dist/index.d.ts +0 -7
  74. package/dist/package.json +0 -98
  75. package/dist/types/cache.d.ts +0 -27
  76. package/dist/types/memorio.d.ts +0 -18
  77. package/dist/types/observer.d.ts +0 -47
  78. package/dist/types/session.d.ts +0 -91
  79. package/dist/types/state.d.ts +0 -71
  80. package/dist/types/store.d.ts +0 -91
  81. package/esbuild.config.mjs +0 -54
  82. package/eslint.config.mjs +0 -174
  83. package/examples/bg.jpg +0 -0
  84. package/examples/bootstrap.less +0 -92
  85. package/examples/favicon.ico +0 -0
  86. package/examples/index.htm +0 -65
  87. package/examples/javascript.js +0 -2
  88. package/examples/responsive.less +0 -47
  89. package/examples/styles.less +0 -169
  90. package/functions/cache/index.ts +0 -19
  91. package/functions/observer/index.ts +0 -121
  92. package/functions/session/index.ts +0 -108
  93. package/functions/state/index.ts +0 -199
  94. package/functions/store/index.ts +0 -108
  95. package/index.ts +0 -1
  96. package/init.ts +0 -12
  97. package/jest.config.mjs +0 -33
  98. package/jest.setup.js +0 -2
  99. package/tests/basic.test.ts +0 -50
  100. package/tests/cache.test.ts +0 -52
  101. package/tests/observer.test.ts +0 -62
  102. package/tests/setup.ts +0 -48
  103. package/tests/state.test.ts +0 -45
  104. package/tests/store.test.ts +0 -62
  105. package/tsconfig.json +0 -67
  106. /package/{.github/README.md → README.md} +0 -0
@@ -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)
@@ -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
@@ -1,108 +0,0 @@
1
-
2
- Object.defineProperty(
3
- globalThis,
4
- 'store',
5
- {
6
- value: new Proxy({}, {}),
7
- enumerable: false,
8
- configurable: false
9
- }
10
- )
11
-
12
- Object.defineProperties(
13
- store,
14
- {
15
- get: {
16
- value(name: string) {
17
- if (!name) return
18
- try {
19
- const item = localStorage.getItem(name)
20
- if (item) return JSON.parse(item)
21
- return item
22
- } catch (err) {
23
- console.error(`Error parsing store 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) localStorage.setItem(name, JSON.stringify(null))
34
- else if (typeof value === 'object' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'string') localStorage.setItem(name, JSON.stringify(value))
35
- else if (typeof value === 'function') console.error('It\'s not secure to store functions.')
36
-
37
- } catch (err) {
38
-
39
- console.error(`Error setting store item '${name}':`, err)
40
-
41
- }
42
- }
43
- },
44
-
45
- remove: {
46
- value(name: string) {
47
- if (!name) return
48
- if (localStorage.getItem(name)) {
49
- localStorage.removeItem(name)
50
- return true
51
- }
52
- }
53
- },
54
-
55
- delete: {
56
- value(name: string) {
57
- store.remove(name)
58
- }
59
-
60
- },
61
-
62
- removeAll: {
63
- value() {
64
- localStorage.clear()
65
- return true
66
- }
67
- },
68
-
69
- clearAll: {
70
- value() {
71
- store.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 localStorage) {
94
- if (localStorage.hasOwnProperty(key)) {
95
- const item = localStorage.getItem(key)
96
- if (item) {
97
- totalSize += item.length
98
- }
99
- }
100
- }
101
- return totalSize
102
- }
103
- }
104
-
105
- }
106
- )
107
-
108
- Object.freeze(store)
package/index.ts DELETED
@@ -1 +0,0 @@
1
- import "./init"
package/init.ts DELETED
@@ -1,12 +0,0 @@
1
- ///////////////////////////////////////////////////////////////////////////////
2
- // LOAD SCRIPTS
3
-
4
- import "dphelper.types"
5
-
6
- import './config/global'
7
- import './config/dispatch'
8
- import './functions/state'
9
- import './functions/observer'
10
- import './functions/store'
11
- import './functions/session'
12
- import './functions/cache'
package/jest.config.mjs DELETED
@@ -1,33 +0,0 @@
1
- /** @type {import('jest').Config} */
2
- export default {
3
- preset: 'ts-jest',
4
- testEnvironment: 'jsdom',
5
- setupFilesAfterEnv: ['./tests/setup.ts'],
6
- transform: {
7
- '^.+\\.tsx?$': ['ts-jest', {
8
- useESM: true
9
- }]
10
- },
11
- extensionsToTreatAsEsm: ['.ts'],
12
- moduleNameMapper: {
13
- '^(\\.{1,2}/.*)\\.js$': '$1'
14
- },
15
- collectCoverageFrom: [
16
- 'functions/**/*.ts',
17
- 'config/**/*.ts',
18
- '*.ts',
19
- '!**/*.d.ts',
20
- '!**/node_modules/**',
21
- '!**/dist/**'
22
- ],
23
- coverageDirectory: 'coverage',
24
- coverageReporters: ['json', 'lcov', 'text', 'clover'],
25
- coverageThreshold: {
26
- global: {
27
- branches: 80,
28
- functions: 80,
29
- lines: 80,
30
- statements: 80
31
- }
32
- }
33
- }
package/jest.setup.js DELETED
@@ -1,2 +0,0 @@
1
- // Mock the window object
2
- global.window = {}
@@ -1,50 +0,0 @@
1
- import { describe, test, expect } from '@jest/globals'
2
- import '../init'
3
-
4
- // Basic state management tests
5
- describe('Basic State Tests', () => {
6
- test('State should exist globally', () => {
7
- expect(globalThis.state).toBeDefined()
8
- })
9
-
10
- test('Should set and get a simple value', () => {
11
- state.testValue = 'hello'
12
- expect(state.testValue).toBe('hello')
13
- })
14
-
15
- test('Should handle number values', () => {
16
- state.number = 42
17
- expect(state.number).toBe(42)
18
- })
19
- })
20
-
21
- // Object state tests
22
- describe('Object State Tests', () => {
23
- test('Should handle object values', () => {
24
- state.obj = { key: 'value' }
25
- expect(state.obj.key).toBe('value')
26
- })
27
-
28
- test('Should handle nested objects', () => {
29
- state.nested = {
30
- level1: {
31
- level2: 'deep'
32
- }
33
- }
34
- expect(state.nested.level1.level2).toBe('deep')
35
- })
36
- })
37
-
38
- // Array state tests
39
- describe('Array State Tests', () => {
40
- test('Should handle array values', () => {
41
- state.array = [1, 2, 3]
42
- expect(state.array).toEqual([1, 2, 3])
43
- })
44
-
45
- test('Should allow array mutations', () => {
46
- state.array = [1, 2]
47
- state.array.push(3)
48
- expect(state.array).toEqual([1, 2, 3])
49
- })
50
- })