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.
Files changed (106) hide show
  1. package/{dist/README.md → README.md} +27 -88
  2. package/{dist/index.js → index.js} +1 -1
  3. package/package.json +3 -3
  4. package/.editorconfig +0 -31
  5. package/.gitattributes +0 -1
  6. package/.github/CHANGELOG.md +0 -10
  7. package/.github/CITATION.cff +0 -24
  8. package/.github/CODEOWNERS +0 -1
  9. package/.github/CODE_OF_CONDUCT.md +0 -108
  10. package/.github/CONTRIBUTING.md +0 -108
  11. package/.github/COPYRIGHT.md +0 -9
  12. package/.github/FUNDING.yml +0 -16
  13. package/.github/HISTORY.md +0 -1
  14. package/.github/LICENSE.md +0 -21
  15. package/.github/README.md +0 -319
  16. package/.github/SECURITY.md +0 -3
  17. package/.github/SUMMARY.md +0 -21
  18. package/.github/dependabot.yml +0 -11
  19. package/.github/documents/OBSERVER.md +0 -72
  20. package/.github/documents/STATE.md +0 -72
  21. package/.github/documents/STORE.md +0 -84
  22. package/.github/pull_request_template.md +0 -27
  23. package/.private/npm +0 -1
  24. package/.vscode/extension.json +0 -15
  25. package/.vscode/settings.json +0 -90
  26. package/config/dispatch.ts +0 -49
  27. package/config/global.ts +0 -36
  28. package/coverage/clover.xml +0 -260
  29. package/coverage/coverage-final.json +0 -10
  30. package/coverage/lcov-report/a51.memorio/config/dispatch.ts.html +0 -232
  31. package/coverage/lcov-report/a51.memorio/config/global.ts.html +0 -193
  32. package/coverage/lcov-report/a51.memorio/config/index.html +0 -131
  33. package/coverage/lcov-report/a51.memorio/dist/config/dispatch.js.html +0 -157
  34. package/coverage/lcov-report/a51.memorio/dist/config/global.js.html +0 -142
  35. package/coverage/lcov-report/a51.memorio/dist/config/index.html +0 -131
  36. package/coverage/lcov-report/a51.memorio/dist/functions/cache/index.html +0 -116
  37. package/coverage/lcov-report/a51.memorio/dist/functions/cache/index.js.html +0 -103
  38. package/coverage/lcov-report/a51.memorio/dist/functions/observer/index.html +0 -116
  39. package/coverage/lcov-report/a51.memorio/dist/functions/observer/index.js.html +0 -280
  40. package/coverage/lcov-report/a51.memorio/dist/functions/state/index.html +0 -116
  41. package/coverage/lcov-report/a51.memorio/dist/functions/state/index.js.html +0 -460
  42. package/coverage/lcov-report/a51.memorio/dist/functions/store/index.html +0 -116
  43. package/coverage/lcov-report/a51.memorio/dist/functions/store/index.js.html +0 -367
  44. package/coverage/lcov-report/a51.memorio/dist/index.html +0 -116
  45. package/coverage/lcov-report/a51.memorio/dist/init.js.html +0 -106
  46. package/coverage/lcov-report/a51.memorio/functions/cache/index.html +0 -116
  47. package/coverage/lcov-report/a51.memorio/functions/cache/index.ts.html +0 -142
  48. package/coverage/lcov-report/a51.memorio/functions/observer/index.html +0 -116
  49. package/coverage/lcov-report/a51.memorio/functions/observer/index.ts.html +0 -448
  50. package/coverage/lcov-report/a51.memorio/functions/session/index.html +0 -116
  51. package/coverage/lcov-report/a51.memorio/functions/session/index.ts.html +0 -409
  52. package/coverage/lcov-report/a51.memorio/functions/state/index.html +0 -116
  53. package/coverage/lcov-report/a51.memorio/functions/state/index.ts.html +0 -682
  54. package/coverage/lcov-report/a51.memorio/functions/store/index.html +0 -116
  55. package/coverage/lcov-report/a51.memorio/functions/store/index.ts.html +0 -409
  56. package/coverage/lcov-report/a51.memorio/index.html +0 -131
  57. package/coverage/lcov-report/a51.memorio/index.ts.html +0 -88
  58. package/coverage/lcov-report/a51.memorio/init.ts.html +0 -115
  59. package/coverage/lcov-report/base.css +0 -224
  60. package/coverage/lcov-report/block-navigation.js +0 -87
  61. package/coverage/lcov-report/favicon.png +0 -0
  62. package/coverage/lcov-report/index.html +0 -206
  63. package/coverage/lcov-report/prettify.css +0 -1
  64. package/coverage/lcov-report/prettify.js +0 -2
  65. package/coverage/lcov-report/session/index.html +0 -116
  66. package/coverage/lcov-report/session/index.ts.html +0 -571
  67. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  68. package/coverage/lcov-report/sorter.js +0 -210
  69. package/coverage/lcov-report/state/index.html +0 -116
  70. package/coverage/lcov-report/state/index.ts.html +0 -1090
  71. package/coverage/lcov-report/store/index.html +0 -116
  72. package/coverage/lcov-report/store/index.ts.html +0 -556
  73. package/coverage/lcov.info +0 -518
  74. package/dist/index.d.ts +0 -7
  75. package/dist/package.json +0 -98
  76. package/dist/types/cache.d.ts +0 -27
  77. package/dist/types/memorio.d.ts +0 -18
  78. package/dist/types/observer.d.ts +0 -47
  79. package/dist/types/session.d.ts +0 -91
  80. package/dist/types/state.d.ts +0 -71
  81. package/dist/types/store.d.ts +0 -91
  82. package/esbuild.config.mjs +0 -54
  83. package/eslint.config.mjs +0 -174
  84. package/examples/bg.jpg +0 -0
  85. package/examples/bootstrap.less +0 -92
  86. package/examples/favicon.ico +0 -0
  87. package/examples/index.htm +0 -65
  88. package/examples/javascript.js +0 -2
  89. package/examples/responsive.less +0 -47
  90. package/examples/styles.less +0 -169
  91. package/functions/cache/index.ts +0 -19
  92. package/functions/observer/index.ts +0 -121
  93. package/functions/session/index.ts +0 -108
  94. package/functions/state/index.ts +0 -199
  95. package/functions/store/index.ts +0 -108
  96. package/index.ts +0 -1
  97. package/init.ts +0 -12
  98. package/jest.config.mjs +0 -33
  99. package/jest.setup.js +0 -2
  100. package/tests/basic.test.ts +0 -50
  101. package/tests/cache.test.ts +0 -52
  102. package/tests/observer.test.ts +0 -62
  103. package/tests/setup.ts +0 -48
  104. package/tests/state.test.ts +0 -45
  105. package/tests/store.test.ts +0 -62
  106. package/tsconfig.json +0 -67
@@ -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
- })
@@ -1,52 +0,0 @@
1
- import { describe, test, expect, beforeEach } from '@jest/globals'
2
- import '../config/global.js'
3
- import '../init'
4
-
5
- describe('Cache Tests', () => {
6
- beforeEach(() => {
7
- // Clear cache if possible
8
- try {
9
- cache.clear()
10
- } catch (e) {
11
- // Ignore if clear is not available
12
- }
13
- })
14
-
15
- test('should set and get cache values', () => {
16
- cache.test = 'value'
17
- expect(cache.test).toBe('value')
18
- })
19
-
20
- test('should handle object values', () => {
21
- const testObj = { key: 'value' }
22
- cache.testObj = testObj
23
- expect(cache.testObj).toEqual(testObj)
24
- })
25
-
26
- test('should handle array values', () => {
27
- const testArray = [1, 2, 3]
28
- cache.testArray = testArray
29
- expect(cache.testArray).toEqual(testArray)
30
- })
31
-
32
- test('should handle nested objects', () => {
33
- const nested = {
34
- level1: {
35
- level2: {
36
- data: 'test'
37
- }
38
- }
39
- }
40
- cache.nested = nested
41
- expect(cache.nested.level1.level2.data).toBe('test')
42
- })
43
-
44
- test('should handle persistence', () => {
45
- cache.persistent = 'persist'
46
- expect(cache.persistent).toBe('persist')
47
-
48
- // Test removal
49
- delete cache.persistent
50
- expect(cache.persistent).toBeUndefined()
51
- })
52
- })
@@ -1,62 +0,0 @@
1
- import { describe, test, expect, jest, beforeEach } from '@jest/globals'
2
- import '../config/global.js'
3
-
4
- // Initialize memorio object first
5
- if (!globalThis.memorio) {
6
- Object.defineProperty(globalThis, 'memorio', {
7
- value: {},
8
- writable: false,
9
- configurable: false,
10
- enumerable: false
11
- })
12
- }
13
-
14
- // Then import other modules
15
- import { buildProxy } from '../functions/state/index.js'
16
- import '../init'
17
-
18
- describe('Observer Tests', () => {
19
- beforeEach(() => {
20
- // Reset state for each test
21
- globalThis.state = buildProxy({}, () => { })
22
- })
23
-
24
- test('should observe state changes', async () => {
25
- const mockCallback = jest.fn()
26
- observer('state.test', mockCallback)
27
-
28
- state.test = 'value'
29
-
30
- // Observer events are async, so we need to wait
31
- await new Promise(resolve => setTimeout(resolve, 100))
32
- expect(mockCallback).toHaveBeenCalled()
33
- })
34
-
35
- test('should handle multiple observers', async () => {
36
- const mockCallback1 = jest.fn()
37
- const mockCallback2 = jest.fn()
38
-
39
- observer('state.test', mockCallback1)
40
- observer('state.test', mockCallback2)
41
-
42
- state.test = 'value'
43
-
44
- await new Promise(resolve => setTimeout(resolve, 100))
45
- expect(mockCallback1).toHaveBeenCalled()
46
- expect(mockCallback2).toHaveBeenCalled()
47
- })
48
-
49
- test('should observe nested state changes', async () => {
50
- const mockCallback = jest.fn()
51
-
52
- // Initialize nested state structure first
53
- state.nested = {}
54
- observer('state.nested.deep', mockCallback)
55
-
56
- // Then set the deep value
57
- state.nested.deep = 'value'
58
-
59
- await new Promise(resolve => setTimeout(resolve, 100))
60
- expect(mockCallback).toHaveBeenCalled()
61
- })
62
- })
package/tests/setup.ts DELETED
@@ -1,48 +0,0 @@
1
-
2
- import { jest } from '@jest/globals'
3
-
4
- // Mock localStorage and sessionStorage
5
- const localStorageMock = {
6
- getItem: jest.fn(),
7
- setItem: jest.fn(),
8
- removeItem: jest.fn(),
9
- clear: jest.fn(),
10
- length: 0,
11
- key: jest.fn()
12
- }
13
-
14
- const sessionStorageMock = {
15
- getItem: jest.fn(),
16
- setItem: jest.fn(),
17
- removeItem: jest.fn(),
18
- clear: jest.fn(),
19
- length: 0,
20
- key: jest.fn()
21
- }
22
-
23
- Object.defineProperty(globalThis, 'localStorage', { value: localStorageMock })
24
- Object.defineProperty(globalThis, 'sessionStorage', { value: sessionStorageMock })
25
-
26
- // Mock navigator.storage
27
- Object.defineProperty(globalThis, 'navigator', {
28
- value: {
29
- storage: {
30
- estimate: () => Promise.resolve({ usage: 0, quota: 1000000 })
31
- }
32
- }
33
- })
34
-
35
- // Initialize global objects
36
- globalThis.state = {}
37
- globalThis.store = {
38
- get: jest.fn(key => null),
39
- set: jest.fn((key, value) => true),
40
- remove: jest.fn(() => true),
41
- removeAll: jest.fn(() => true),
42
- delete: jest.fn(() => true),
43
- clearAll: jest.fn(() => true),
44
- quota: jest.fn(() => ({ usage: 0, quota: 1000000 })),
45
- size: jest.fn(() => 0)
46
- }
47
- globalThis.cache = {}
48
- globalThis.observer = jest.fn()
@@ -1,45 +0,0 @@
1
- import { describe, test, expect, beforeEach } from '@jest/globals'
2
- import '../config/global.js'
3
- import { buildProxy } from '../functions/state/index.js'
4
- import '../init'
5
-
6
- describe('State Management', () => {
7
- beforeEach(() => {
8
- // Reset state by creating a new proxy
9
- globalThis.state = buildProxy({}, () => { })
10
- })
11
-
12
- test('should set and get state value', () => {
13
- state.test = 'value'
14
- expect(state.test).toBe('value')
15
- })
16
-
17
- test('should list all states', () => {
18
- state.test1 = 'value1'
19
- state.test2 = 'value2'
20
- const list = state.list
21
- expect(list).toHaveProperty('test1')
22
- expect(list).toHaveProperty('test2')
23
- })
24
-
25
- test('should remove state', () => {
26
- state.test = 'value'
27
- state.remove('test')
28
- expect(state.test).toBeUndefined()
29
- })
30
-
31
- test('should remove all states', () => {
32
- state.test1 = 'value1'
33
- state.test2 = 'value2'
34
- state.removeAll()
35
- expect(state.list).toEqual({})
36
- })
37
-
38
- test('should lock object state', () => {
39
- state.test = { prop: 'value' }
40
- state.test.lock()
41
- expect(() => {
42
- state.test.newProp = 'value'
43
- }).toThrow()
44
- })
45
- })
@@ -1,62 +0,0 @@
1
- import { describe, test, expect, jest, beforeEach } from '@jest/globals'
2
- import '../config/global.js'
3
- import '../init'
4
-
5
- describe('Store Tests', () => {
6
- let mockStore = {}
7
-
8
- beforeEach(() => {
9
- mockStore = {}
10
- localStorage.clear()
11
- jest.spyOn(localStorage, 'getItem').mockImplementation(key => mockStore[key] || null)
12
- jest.spyOn(localStorage, 'setItem').mockImplementation((key, value) => {
13
- mockStore[key] = value
14
- })
15
- jest.spyOn(localStorage, 'removeItem').mockImplementation(key => {
16
- delete mockStore[key]
17
- })
18
- jest.spyOn(localStorage, 'clear').mockImplementation(() => {
19
- mockStore = {}
20
- })
21
- })
22
-
23
- test('should set and get store values', () => {
24
- const testValue = 'test value'
25
- store.set('test', testValue)
26
- expect(localStorage.setItem).toHaveBeenCalledWith('test', JSON.stringify(testValue))
27
- expect(store.get('test')).toBe(testValue)
28
- })
29
-
30
- test('should handle object values', () => {
31
- const testObj = { key: 'value' }
32
- store.set('test', testObj)
33
- expect(localStorage.setItem).toHaveBeenCalledWith('test', JSON.stringify(testObj))
34
- expect(store.get('test')).toEqual(testObj)
35
- })
36
-
37
- test('should remove store item', () => {
38
- store.set('test', 'value')
39
- store.remove('test')
40
- expect(localStorage.removeItem).toHaveBeenCalledWith('test')
41
- expect(store.get('test')).toBeNull()
42
- })
43
-
44
- test('should remove all store items', () => {
45
- store.set('test1', 'value1')
46
- store.set('test2', 'value2')
47
- store.removeAll()
48
- expect(localStorage.clear).toHaveBeenCalled()
49
- expect(store.get('test1')).toBeNull()
50
- expect(store.get('test2')).toBeNull()
51
- })
52
-
53
- test('should get store size', () => {
54
- mockStore = {}
55
- store.removeAll()
56
- store.set('test1', 'value1')
57
- store.set('test2', 'value2')
58
- const size = Object.keys(mockStore).length
59
- expect(typeof size).toBe('number')
60
- expect(size).toBe(2)
61
- })
62
- })
package/tsconfig.json DELETED
@@ -1,67 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "lib": [
4
- "es2022",
5
- "dom"
6
- ],
7
- "module": "NodeNext",
8
- "moduleResolution": "NodeNext",
9
- "types": [
10
- "node"
11
- ],
12
- "strict": true,
13
- "noEmit": false,
14
- "noImplicitThis": true,
15
- "noUnusedLocals": true,
16
- "importHelpers": true,
17
- "skipLibCheck": true,
18
- "allowSyntheticDefaultImports": true,
19
- "forceConsistentCasingInFileNames": true,
20
- "resolveJsonModule": true,
21
- "isolatedModules": true,
22
- "noImplicitAny": false,
23
- "preserveConstEnums": true,
24
- "removeComments": true,
25
- "sourceMap": false,
26
- "allowJs": true,
27
- "esModuleInterop": true,
28
- "strictNullChecks": false,
29
- "strictPropertyInitialization": false,
30
- "jsx": "react",
31
- "moduleDetection": "force",
32
- "baseUrl": ".",
33
- "outDir": "./dist/",
34
- "target": "es2022",
35
- "rootDirs": [
36
- "./"
37
- ],
38
- "paths": {
39
- "/*": [
40
- "./*"
41
- ]
42
- }
43
- },
44
- "include": [
45
- "index.d.ts",
46
- "./types/memorio.d.ts",
47
- "./**/*.ts",
48
- "./**/*.tsx"
49
- ],
50
- "types": [
51
- "node"
52
- ],
53
- "typeRoots": [
54
- "./types/*"
55
- ],
56
- "exclude": [
57
- "node_modules",
58
- "private",
59
- "archive",
60
- "*backup",
61
- "dist",
62
- ".old*",
63
- ".OLD*",
64
- "#OLD*",
65
- "@OLD*",
66
- ]
67
- }