@k3000/store 1.1.0 → 1.1.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.
- package/architect.mjs +6 -7
- package/generator.mjs +22 -0
- package/package.json +1 -1
- package/test/1/data +0 -0
- package/test/1/index +0 -0
- package/test/2/data +0 -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 +0 -15
- package/test2/1/data +0 -0
- package/test2/1/index +0 -0
- package/test2/1/index.mjs +0 -111
- package/test2/1/type.ts +0 -50
- package/test2/2/data +0 -0
- package/test2/2/index +0 -0
- package/test2/2/index.mjs +0 -111
- package/test2/2/type.ts +0 -50
- package/test2/index.mjs +0 -16
- package/test2.mjs +0 -43
package/architect.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {dirname
|
|
1
|
+
import {dirname} from "node:path"
|
|
2
|
+
import {fileURLToPath} from "node:url"
|
|
2
3
|
import {openSync, closeSync, readFileSync, writeFileSync, readSync, writeSync, unlinkSync} from "node:fs"
|
|
3
4
|
import {createCipheriv, createDecipheriv, createHash, scryptSync} from "node:crypto"
|
|
4
5
|
|
|
@@ -820,15 +821,13 @@ export class Storage {
|
|
|
820
821
|
|
|
821
822
|
constructor(url, password, newPwd) {
|
|
822
823
|
|
|
823
|
-
|
|
824
|
+
let dir = url.startsWith('file:///') ? dirname(fileURLToPath(url)) : url
|
|
824
825
|
|
|
825
|
-
|
|
826
|
+
dir = dir.replace(/\\/g, '/')
|
|
826
827
|
|
|
827
|
-
|
|
828
|
+
if (!dir.endsWith('/')) {
|
|
828
829
|
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
dir = root.length > 1 ? dir.substring(7 + root.length) : dir.substring(7)
|
|
830
|
+
dir += '/'
|
|
832
831
|
}
|
|
833
832
|
|
|
834
833
|
this.#fd_data = openSync(dir + 'data', 'r+')
|
package/generator.mjs
CHANGED
|
@@ -579,6 +579,17 @@ function appendSet(name, set, remark = '') {
|
|
|
579
579
|
} else if (this.types.includes(value)) {
|
|
580
580
|
|
|
581
581
|
value = value().toJSON()
|
|
582
|
+
|
|
583
|
+
} else if (typeof value.type === "string" || value.type instanceof String) {
|
|
584
|
+
|
|
585
|
+
value.length = value.length || TypeLen[value.type]
|
|
586
|
+
|
|
587
|
+
value.type = typeMap[value.type]
|
|
588
|
+
|
|
589
|
+
if (value.index) {
|
|
590
|
+
|
|
591
|
+
value.index = []
|
|
592
|
+
}
|
|
582
593
|
}
|
|
583
594
|
|
|
584
595
|
console.log(' append col:', key)
|
|
@@ -615,6 +626,17 @@ function updateCol(name, set) {
|
|
|
615
626
|
} else if (this.types.includes(value)) {
|
|
616
627
|
|
|
617
628
|
value = value().toJSON()
|
|
629
|
+
|
|
630
|
+
} else if (typeof value.type === "string" || value.type instanceof String) {
|
|
631
|
+
|
|
632
|
+
value.length = value.length || TypeLen[value.type]
|
|
633
|
+
|
|
634
|
+
value.type = typeMap[value.type]
|
|
635
|
+
|
|
636
|
+
if (value.index) {
|
|
637
|
+
|
|
638
|
+
value.index = []
|
|
639
|
+
}
|
|
618
640
|
}
|
|
619
641
|
|
|
620
642
|
console.log(` ${Reflect.has(this.curr.struct.base[name], key) ? 'update' : 'append'} col:`, key)
|
package/package.json
CHANGED
package/test/1/data
CHANGED
|
Binary file
|
package/test/1/index
CHANGED
|
Binary file
|
package/test/2/data
CHANGED
|
Binary file
|
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
DELETED
|
File without changes
|
package/test2/0/index
DELETED
|
Binary file
|
package/test2/0/index.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
DELETED
|
Binary file
|
package/test2/1/index
DELETED
|
Binary file
|
package/test2/1/index.mjs
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
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
DELETED
|
Binary file
|
package/test2/2/index
DELETED
|
Binary file
|
package/test2/2/index.mjs
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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()
|