@k3000/store 1.0.2 → 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/generator.mjs +11 -4
- package/package.json +1 -1
- package/test/1/index +0 -0
- package/test/1/type.ts +24 -0
- package/test/2/index +0 -0
- package/test/3/data +0 -0
- package/test/3/index +0 -0
- package/test/4/data +0 -0
- package/test/4/index +0 -0
- package/test/5/data +0 -0
- package/test/5/index +0 -0
- package/test/6/data +0 -0
- package/test/6/index +0 -0
- package/test/7/data +0 -0
- package/test/7/index +0 -0
- package/test2/0/data +0 -0
- package/test2/0/index +0 -0
- package/test2/0/index.mjs +15 -0
- package/test2/1/data +0 -0
- package/test2/1/index +0 -0
- package/test2/1/index.mjs +111 -0
- package/test2/1/type.ts +50 -0
- package/test2/2/data +0 -0
- package/test2/2/index +0 -0
- package/test2/2/index.mjs +111 -0
- package/test2/2/type.ts +50 -0
- package/test2/index.mjs +16 -0
- package/test2.mjs +43 -0
package/generator.mjs
CHANGED
|
@@ -761,6 +761,17 @@ const commentRemark = (remark = '') => remark.replace(/\n/g, '\n\t * ')
|
|
|
761
761
|
|
|
762
762
|
function submit() {
|
|
763
763
|
|
|
764
|
+
for (const name of this.updateSet.values()) {
|
|
765
|
+
|
|
766
|
+
this.curr.record.idle[name] = []
|
|
767
|
+
this.curr.record.record[name] = []
|
|
768
|
+
|
|
769
|
+
for (const key of Object.keys(this.curr.record.index[name])) {
|
|
770
|
+
|
|
771
|
+
this.curr.record.index[name][key] = []
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
764
775
|
this.curr.updateStruct(this.curr.struct)
|
|
765
776
|
this.curr.updateRecord(this.curr.record)
|
|
766
777
|
|
|
@@ -803,10 +814,6 @@ export default storage
|
|
|
803
814
|
|
|
804
815
|
for (const name of this.updateSet.values()) {
|
|
805
816
|
|
|
806
|
-
curr[name].remove(...curr[name])
|
|
807
|
-
|
|
808
|
-
this.curr.record.idle[name] = []
|
|
809
|
-
|
|
810
817
|
curr[name].push(...prev[name])
|
|
811
818
|
}
|
|
812
819
|
|
package/package.json
CHANGED
package/test/1/index
CHANGED
|
Binary file
|
package/test/1/type.ts
CHANGED
|
@@ -29,6 +29,14 @@ interface AdminSet extends Array<Admin> {
|
|
|
29
29
|
indexByUid(uid: String): Array<Admin>
|
|
30
30
|
indexByValid(valid: Number): Array<Admin>
|
|
31
31
|
indexByTime({after, before}): Array<Admin>
|
|
32
|
+
/**
|
|
33
|
+
* 重写push方法
|
|
34
|
+
*/
|
|
35
|
+
push(...item: Array<Admin>): Array<Admin>
|
|
36
|
+
/**
|
|
37
|
+
* 重写unshift方法
|
|
38
|
+
*/
|
|
39
|
+
unshift(...item: Array<Admin>): Array<Admin>
|
|
32
40
|
/**
|
|
33
41
|
* 分页查询
|
|
34
42
|
*/
|
|
@@ -76,6 +84,14 @@ interface LogSet extends Array<Log> {
|
|
|
76
84
|
indexById(id: Number): Array<Log>
|
|
77
85
|
indexByUid(uid: String): Array<Log>
|
|
78
86
|
indexByTime({after, before}): Array<Log>
|
|
87
|
+
/**
|
|
88
|
+
* 重写push方法
|
|
89
|
+
*/
|
|
90
|
+
push(...item: Array<Log>): Array<Log>
|
|
91
|
+
/**
|
|
92
|
+
* 重写unshift方法
|
|
93
|
+
*/
|
|
94
|
+
unshift(...item: Array<Log>): Array<Log>
|
|
79
95
|
/**
|
|
80
96
|
* 分页查询
|
|
81
97
|
*/
|
|
@@ -141,6 +157,14 @@ interface Test {
|
|
|
141
157
|
interface TestSet extends Array<Test> {
|
|
142
158
|
|
|
143
159
|
indexById(id: Number): Array<Test>
|
|
160
|
+
/**
|
|
161
|
+
* 重写push方法
|
|
162
|
+
*/
|
|
163
|
+
push(...item: Array<Test>): Array<Test>
|
|
164
|
+
/**
|
|
165
|
+
* 重写unshift方法
|
|
166
|
+
*/
|
|
167
|
+
unshift(...item: Array<Test>): Array<Test>
|
|
144
168
|
/**
|
|
145
169
|
* 分页查询
|
|
146
170
|
*/
|
package/test/2/index
CHANGED
|
Binary file
|
package/test/3/data
CHANGED
|
Binary file
|
package/test/3/index
CHANGED
|
Binary file
|
package/test/4/data
CHANGED
|
Binary file
|
package/test/4/index
CHANGED
|
Binary file
|
package/test/5/data
CHANGED
|
Binary file
|
package/test/5/index
CHANGED
|
Binary file
|
package/test/6/data
CHANGED
|
Binary file
|
package/test/6/index
CHANGED
|
Binary file
|
package/test/7/data
CHANGED
|
Binary file
|
package/test/7/index
CHANGED
|
Binary file
|
package/test2/0/data
ADDED
|
File without changes
|
package/test2/0/index
ADDED
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
import {Storage, Store} from '../../architect.mjs'
|
|
3
|
+
import {struct} from '../../generator.mjs'
|
|
4
|
+
|
|
5
|
+
const storage = new Storage(import.meta.url)
|
|
6
|
+
|
|
7
|
+
export const remark = Symbol('remark')
|
|
8
|
+
|
|
9
|
+
export const close = () => storage.close()
|
|
10
|
+
|
|
11
|
+
export const getStruct = name => struct(storage, remark, name)
|
|
12
|
+
|
|
13
|
+
export default new class extends Store {
|
|
14
|
+
|
|
15
|
+
}
|
package/test2/1/data
ADDED
|
Binary file
|
package/test2/1/index
ADDED
|
Binary file
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
|
|
2
|
+
import {Entities, Entity, Storage, b2d, d2b, b2s, position, uInt32BEToBuffer, int32BEToBuffer,
|
|
3
|
+
doubleBEToBuffer, bigint32BEToBuffer, bigUint32BEToBuffer, readInt24BE, readUint24BE, Store} from '../../architect.mjs'
|
|
4
|
+
import {struct} from '../../generator.mjs'
|
|
5
|
+
|
|
6
|
+
const storage = new Storage(import.meta.url)
|
|
7
|
+
|
|
8
|
+
const $a1 = 'a1'
|
|
9
|
+
const $a2 = 'a2'
|
|
10
|
+
const $a3 = 'a3'
|
|
11
|
+
|
|
12
|
+
class Qwe extends Entity {
|
|
13
|
+
|
|
14
|
+
static name = 'qwe'
|
|
15
|
+
|
|
16
|
+
static create(_) {
|
|
17
|
+
_.a1 = storage.updateValue(_.a1, Qwe.name, $a1)
|
|
18
|
+
return _
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor(...arg) {
|
|
22
|
+
|
|
23
|
+
super(storage, ...arg)
|
|
24
|
+
|
|
25
|
+
return Object.defineProperties({}, {
|
|
26
|
+
[position]: {
|
|
27
|
+
enumerable: false,
|
|
28
|
+
configurable: false,
|
|
29
|
+
get: () => this[position],
|
|
30
|
+
},
|
|
31
|
+
a1: {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: false,
|
|
34
|
+
get: () => super.get($a1).readUInt32BE(0),
|
|
35
|
+
set: value => super.set2($a1, uInt32BEToBuffer(value)),
|
|
36
|
+
},
|
|
37
|
+
a2: {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: false,
|
|
40
|
+
get: () => b2s(super.get($a2)),
|
|
41
|
+
set: value => super.set($a2, super.s2b(value, $a2)),
|
|
42
|
+
},
|
|
43
|
+
a3: {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: false,
|
|
46
|
+
get: () => super.get($a3).readUInt32BE(0),
|
|
47
|
+
set: value => super.set($a3, super.uintToBuffer(value, $a3)),
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class QweSet extends Entities {
|
|
56
|
+
|
|
57
|
+
constructor() {
|
|
58
|
+
|
|
59
|
+
super(storage, Qwe)
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 内部方法
|
|
63
|
+
*/
|
|
64
|
+
s2b() {
|
|
65
|
+
|
|
66
|
+
throw new TypeError('s2b is not a function')
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 内部方法
|
|
70
|
+
*/
|
|
71
|
+
findByValue() {
|
|
72
|
+
|
|
73
|
+
throw new TypeError('findByValue is not a function')
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 内部方法
|
|
77
|
+
*/
|
|
78
|
+
findByTime() {
|
|
79
|
+
|
|
80
|
+
throw new TypeError('findByTime is not a function')
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 内部方法
|
|
84
|
+
*/
|
|
85
|
+
stringToBuffer() {
|
|
86
|
+
|
|
87
|
+
throw new TypeError('stringToBuffer is not a function')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
indexByA1(a1) {
|
|
91
|
+
|
|
92
|
+
return super.findByValue($a1, uInt32BEToBuffer(a1, $a1))
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const remark = Symbol('remark')
|
|
97
|
+
|
|
98
|
+
export const close = () => storage.close()
|
|
99
|
+
|
|
100
|
+
export const getStruct = name => struct(storage, remark, name)
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @type {import('./type').Storage}
|
|
104
|
+
*/
|
|
105
|
+
const store = Object.freeze({
|
|
106
|
+
qwe: new Proxy([], {
|
|
107
|
+
get: new QweSet()
|
|
108
|
+
}),
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
export default store
|
package/test2/1/type.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
interface Qwe {
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
a1: Number
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
a2: String
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
a3: Number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface QweSet extends Array<Qwe> {
|
|
19
|
+
|
|
20
|
+
indexByA1(a1: Number): Array<Qwe>
|
|
21
|
+
/**
|
|
22
|
+
* 重写push方法
|
|
23
|
+
*/
|
|
24
|
+
push(...item: Array<Qwe>): Array<Qwe>
|
|
25
|
+
/**
|
|
26
|
+
* 重写unshift方法
|
|
27
|
+
*/
|
|
28
|
+
unshift(...item: Array<Qwe>): Array<Qwe>
|
|
29
|
+
/**
|
|
30
|
+
* 分页查询
|
|
31
|
+
*/
|
|
32
|
+
page(predicate: Function, index: Number | String, size: Number | String, params: Object): Array<Qwe>
|
|
33
|
+
/**
|
|
34
|
+
* 移除数据
|
|
35
|
+
*/
|
|
36
|
+
remove(...items: Array<Qwe>): void
|
|
37
|
+
/**
|
|
38
|
+
* 联合查询,类似LEFT JOIN
|
|
39
|
+
*/
|
|
40
|
+
eachFlat(array: Array<Object>, predicate: Function | String): Array<Object>
|
|
41
|
+
/**
|
|
42
|
+
* 联合查询,类似INNER JOIN
|
|
43
|
+
*/
|
|
44
|
+
filterFlat(array: Array<Object>, predicate: Function | String): Array<Object>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
export interface Storage {
|
|
49
|
+
qwe: QweSet
|
|
50
|
+
}
|
package/test2/2/data
ADDED
|
Binary file
|
package/test2/2/index
ADDED
|
Binary file
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
|
|
2
|
+
import {Entities, Entity, Storage, b2d, d2b, b2s, position, uInt32BEToBuffer, int32BEToBuffer,
|
|
3
|
+
doubleBEToBuffer, bigint32BEToBuffer, bigUint32BEToBuffer, readInt24BE, readUint24BE, Store} from '../../architect.mjs'
|
|
4
|
+
import {struct} from '../../generator.mjs'
|
|
5
|
+
|
|
6
|
+
const storage = new Storage(import.meta.url)
|
|
7
|
+
|
|
8
|
+
const $a1 = 'a1'
|
|
9
|
+
const $a2 = 'a2'
|
|
10
|
+
const $a3 = 'a3'
|
|
11
|
+
|
|
12
|
+
class Qwe extends Entity {
|
|
13
|
+
|
|
14
|
+
static name = 'qwe'
|
|
15
|
+
|
|
16
|
+
static create(_) {
|
|
17
|
+
_.a1 = storage.updateValue(_.a1, Qwe.name, $a1)
|
|
18
|
+
return _
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor(...arg) {
|
|
22
|
+
|
|
23
|
+
super(storage, ...arg)
|
|
24
|
+
|
|
25
|
+
return Object.defineProperties({}, {
|
|
26
|
+
[position]: {
|
|
27
|
+
enumerable: false,
|
|
28
|
+
configurable: false,
|
|
29
|
+
get: () => this[position],
|
|
30
|
+
},
|
|
31
|
+
a1: {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: false,
|
|
34
|
+
get: () => super.get($a1).readUInt32BE(0),
|
|
35
|
+
set: value => super.set2($a1, uInt32BEToBuffer(value)),
|
|
36
|
+
},
|
|
37
|
+
a2: {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: false,
|
|
40
|
+
get: () => b2s(super.get($a2)),
|
|
41
|
+
set: value => super.set($a2, super.s2b(value, $a2)),
|
|
42
|
+
},
|
|
43
|
+
a3: {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: false,
|
|
46
|
+
get: () => super.get($a3).readUInt32BE(0),
|
|
47
|
+
set: value => super.set($a3, super.uintToBuffer(value, $a3)),
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class QweSet extends Entities {
|
|
56
|
+
|
|
57
|
+
constructor() {
|
|
58
|
+
|
|
59
|
+
super(storage, Qwe)
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 内部方法
|
|
63
|
+
*/
|
|
64
|
+
s2b() {
|
|
65
|
+
|
|
66
|
+
throw new TypeError('s2b is not a function')
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 内部方法
|
|
70
|
+
*/
|
|
71
|
+
findByValue() {
|
|
72
|
+
|
|
73
|
+
throw new TypeError('findByValue is not a function')
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 内部方法
|
|
77
|
+
*/
|
|
78
|
+
findByTime() {
|
|
79
|
+
|
|
80
|
+
throw new TypeError('findByTime is not a function')
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 内部方法
|
|
84
|
+
*/
|
|
85
|
+
stringToBuffer() {
|
|
86
|
+
|
|
87
|
+
throw new TypeError('stringToBuffer is not a function')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
indexByA1(a1) {
|
|
91
|
+
|
|
92
|
+
return super.findByValue($a1, uInt32BEToBuffer(a1, $a1))
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const remark = Symbol('remark')
|
|
97
|
+
|
|
98
|
+
export const close = () => storage.close()
|
|
99
|
+
|
|
100
|
+
export const getStruct = name => struct(storage, remark, name)
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @type {import('./type').Storage}
|
|
104
|
+
*/
|
|
105
|
+
const store = Object.freeze({
|
|
106
|
+
qwe: new Proxy([], {
|
|
107
|
+
get: new QweSet()
|
|
108
|
+
}),
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
export default store
|
package/test2/2/type.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
interface Qwe {
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
a1: Number
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
a2: String
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
a3: Number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface QweSet extends Array<Qwe> {
|
|
19
|
+
|
|
20
|
+
indexByA1(a1: Number): Array<Qwe>
|
|
21
|
+
/**
|
|
22
|
+
* 重写push方法
|
|
23
|
+
*/
|
|
24
|
+
push(...item: Array<Qwe>): Array<Qwe>
|
|
25
|
+
/**
|
|
26
|
+
* 重写unshift方法
|
|
27
|
+
*/
|
|
28
|
+
unshift(...item: Array<Qwe>): Array<Qwe>
|
|
29
|
+
/**
|
|
30
|
+
* 分页查询
|
|
31
|
+
*/
|
|
32
|
+
page(predicate: Function, index: Number | String, size: Number | String, params: Object): Array<Qwe>
|
|
33
|
+
/**
|
|
34
|
+
* 移除数据
|
|
35
|
+
*/
|
|
36
|
+
remove(...items: Array<Qwe>): void
|
|
37
|
+
/**
|
|
38
|
+
* 联合查询,类似LEFT JOIN
|
|
39
|
+
*/
|
|
40
|
+
eachFlat(array: Array<Object>, predicate: Function | String): Array<Object>
|
|
41
|
+
/**
|
|
42
|
+
* 联合查询,类似INNER JOIN
|
|
43
|
+
*/
|
|
44
|
+
filterFlat(array: Array<Object>, predicate: Function | String): Array<Object>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
export interface Storage {
|
|
49
|
+
qwe: QweSet
|
|
50
|
+
}
|
package/test2/index.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
const index = import.meta.url.indexOf('?')
|
|
3
|
+
|
|
4
|
+
export const modules = await import(`./2/index.mjs${index > -1 ? import.meta.url.substring(index) : ''}`)
|
|
5
|
+
|
|
6
|
+
export const close = modules.close
|
|
7
|
+
export const remark = modules.remark
|
|
8
|
+
export const version = 2
|
|
9
|
+
export const getStruct = modules.getStruct
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @type {import('./2/type').Storage}
|
|
13
|
+
*/
|
|
14
|
+
export const storage = modules.default
|
|
15
|
+
|
|
16
|
+
export default storage
|
package/test2.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*import upgrade, {Id, String, Uint} from "./generator.mjs?test=true";
|
|
2
|
+
|
|
3
|
+
const {appendSet, submit} = upgrade('test2')
|
|
4
|
+
|
|
5
|
+
appendSet('qwe', {
|
|
6
|
+
a1: Id,
|
|
7
|
+
a2: String(16),
|
|
8
|
+
a3: Uint,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
submit()*/
|
|
12
|
+
|
|
13
|
+
/*import store, {close} from './test2/index.mjs'
|
|
14
|
+
|
|
15
|
+
// store.qwe.push({
|
|
16
|
+
// a2: '00000000000000000000',
|
|
17
|
+
// a3: 10001,
|
|
18
|
+
// })
|
|
19
|
+
//
|
|
20
|
+
// store.qwe.push({
|
|
21
|
+
// a2: '00000000000000000000',
|
|
22
|
+
// a3: 10001,
|
|
23
|
+
// })
|
|
24
|
+
|
|
25
|
+
console.log(JSON.stringify(store.qwe, null, 2))
|
|
26
|
+
|
|
27
|
+
close()*/
|
|
28
|
+
|
|
29
|
+
/*import upgrade, {String} from "./generator.mjs?test=true";
|
|
30
|
+
|
|
31
|
+
const {updateCol, submit} = upgrade('test2')
|
|
32
|
+
|
|
33
|
+
updateCol('qwe', {
|
|
34
|
+
a2: String(32),
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
submit()*/
|
|
38
|
+
|
|
39
|
+
import store, {close} from './test2/index.mjs'
|
|
40
|
+
|
|
41
|
+
console.log(JSON.stringify(store.qwe, null, 2))
|
|
42
|
+
|
|
43
|
+
close()
|