@k3000/store 0.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/test/5/type.ts ADDED
@@ -0,0 +1,214 @@
1
+
2
+ interface Admin {
3
+
4
+ /**
5
+ *
6
+ */
7
+ id: Number
8
+ /**
9
+ * 账号
10
+ */
11
+ uid: String
12
+ /**
13
+ * 密码
14
+ */
15
+ pwd: String
16
+ /**
17
+ * 是否有效
18
+ */
19
+ valid: Number
20
+ /**
21
+ * 登录时间
22
+ */
23
+ time: Number | Date
24
+ }
25
+
26
+ interface AdminSet extends Array<Admin> {
27
+
28
+ indexById(id: Number): Array<Admin>
29
+ indexByUid(uid: String): Array<Admin>
30
+ indexByValid(valid: Number): Array<Admin>
31
+ indexByTime({after, before}): Array<Admin>
32
+ /**
33
+ * 分页查询
34
+ */
35
+ page(predicate: Function, index: Number | String, size: Number | String, params: Object): Array<Admin>
36
+ /**
37
+ * 移除数据
38
+ */
39
+ remove(...items: Array<Admin>): void
40
+ /**
41
+ * 联合查询,类似LEFT JOIN
42
+ */
43
+ eachFlat(array: Array<Object>, predicate: Function | String): Array<Object>
44
+ /**
45
+ * 联合查询,类似INNER JOIN
46
+ */
47
+ filterFlat(array: Array<Object>, predicate: Function | String): Array<Object>
48
+ }
49
+
50
+ interface Log {
51
+
52
+ /**
53
+ *
54
+ */
55
+ id: Number
56
+ /**
57
+ * 账号
58
+ */
59
+ uid: String
60
+ /**
61
+ * 类型
62
+ */
63
+ type: Number
64
+ /**
65
+ * 创建时间
66
+ */
67
+ time: Number | Date
68
+ /**
69
+ * 内容
70
+ */
71
+ content: String
72
+ }
73
+
74
+ interface LogSet extends Array<Log> {
75
+
76
+ indexById(id: Number): Array<Log>
77
+ indexByUid(uid: String): Array<Log>
78
+ indexByTime({after, before}): Array<Log>
79
+ /**
80
+ * 分页查询
81
+ */
82
+ page(predicate: Function, index: Number | String, size: Number | String, params: Object): Array<Log>
83
+ /**
84
+ * 移除数据
85
+ */
86
+ remove(...items: Array<Log>): void
87
+ /**
88
+ * 联合查询,类似LEFT JOIN
89
+ */
90
+ eachFlat(array: Array<Object>, predicate: Function | String): Array<Object>
91
+ /**
92
+ * 联合查询,类似INNER JOIN
93
+ */
94
+ filterFlat(array: Array<Object>, predicate: Function | String): Array<Object>
95
+ }
96
+
97
+ interface Test {
98
+
99
+ /**
100
+ *
101
+ */
102
+ id: Number
103
+ /**
104
+ *
105
+ */
106
+ uint: Number
107
+ /**
108
+ *
109
+ */
110
+ int: Number
111
+ /**
112
+ *
113
+ */
114
+ bigint: Number | BigInt
115
+ /**
116
+ *
117
+ */
118
+ bigUint: Number | BigInt
119
+ /**
120
+ *
121
+ */
122
+ time: Number | Date
123
+ /**
124
+ *
125
+ */
126
+ float: Number
127
+ /**
128
+ *
129
+ */
130
+ string: String
131
+ /**
132
+ *
133
+ */
134
+ buffer: Buffer
135
+ /**
136
+ *
137
+ */
138
+ text: String
139
+ }
140
+
141
+ interface TestSet extends Array<Test> {
142
+
143
+ indexById(id: Number): Array<Test>
144
+ /**
145
+ * 分页查询
146
+ */
147
+ page(predicate: Function, index: Number | String, size: Number | String, params: Object): Array<Test>
148
+ /**
149
+ * 移除数据
150
+ */
151
+ remove(...items: Array<Test>): void
152
+ /**
153
+ * 联合查询,类似LEFT JOIN
154
+ */
155
+ eachFlat(array: Array<Object>, predicate: Function | String): Array<Object>
156
+ /**
157
+ * 联合查询,类似INNER JOIN
158
+ */
159
+ filterFlat(array: Array<Object>, predicate: Function | String): Array<Object>
160
+ }
161
+
162
+ interface Test3 {
163
+
164
+ /**
165
+ * 账
166
+ * 户
167
+ */
168
+ uid: String
169
+ /**
170
+ *
171
+ */
172
+ pwd: String
173
+ /**
174
+ *
175
+ */
176
+ test: String
177
+ /**
178
+ *
179
+ */
180
+ test3: Number
181
+ /**
182
+ *
183
+ */
184
+ test2: String
185
+ }
186
+
187
+ interface Test3Set extends Array<Test3> {
188
+
189
+ /**
190
+ * 分页查询
191
+ */
192
+ page(predicate: Function, index: Number | String, size: Number | String, params: Object): Array<Test3>
193
+ /**
194
+ * 移除数据
195
+ */
196
+ remove(...items: Array<Test3>): void
197
+ /**
198
+ * 联合查询,类似LEFT JOIN
199
+ */
200
+ eachFlat(array: Array<Object>, predicate: Function | String): Array<Object>
201
+ /**
202
+ * 联合查询,类似INNER JOIN
203
+ */
204
+ filterFlat(array: Array<Object>, predicate: Function | String): Array<Object>
205
+ }
206
+
207
+
208
+ export interface Storage {
209
+ close(): void
210
+ admin: AdminSet,
211
+ log: LogSet,
212
+ test: TestSet,
213
+ test3: Test3Set
214
+ }
package/test/6/data ADDED
Binary file
package/test/6/index ADDED
Binary file
@@ -0,0 +1,395 @@
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 $id = 'id'
9
+ const $uid = 'uid'
10
+ const $pwd = 'pwd'
11
+ const $valid = 'valid'
12
+ const $time = 'time'
13
+ const $type = 'type'
14
+ const $content = 'content'
15
+ const $test = 'test'
16
+ const $test2 = 'test2'
17
+
18
+ class Admin extends Entity {
19
+
20
+ static name = 'admin'
21
+
22
+ static create({
23
+ id,
24
+ pwd,
25
+ time,
26
+ uid,
27
+ valid
28
+ }) {
29
+
30
+ return {
31
+ id: storage.updateValue(id, Admin.name, $id),
32
+ pwd: pwd || '123456',
33
+ time: time || new Date(),
34
+ uid,
35
+ valid: valid || 0,
36
+ }
37
+ }
38
+
39
+ constructor(...arg) {
40
+
41
+ super(storage, ...arg)
42
+
43
+ return Object.defineProperties({}, {
44
+ [position]: {
45
+ enumerable: false,
46
+ configurable: false,
47
+ get: () => this[position],
48
+ },
49
+ id: {
50
+ enumerable: true,
51
+ configurable: false,
52
+ get: () => super.get($id).readUInt32BE(0),
53
+ set: id => {
54
+ super.set2($id, uInt32BEToBuffer(id))
55
+ this.#update()
56
+ },
57
+ },
58
+ pwd: {
59
+ enumerable: true,
60
+ configurable: false,
61
+ get: () => b2s(super.get($pwd)),
62
+ set: pwd => {
63
+ super.set($pwd, super.s2b(pwd, $pwd))
64
+ this.#update()
65
+ },
66
+ },
67
+ time: {
68
+ enumerable: true,
69
+ configurable: false,
70
+ get: () => b2d(super.get($time)),
71
+ set: time => super.set2($time, d2b(time)),
72
+ },
73
+ uid: {
74
+ enumerable: true,
75
+ configurable: false,
76
+ get: () => b2s(super.get($uid)),
77
+ set: uid => {
78
+ super.set2($uid, super.s2b(uid, $uid))
79
+ this.#update()
80
+ },
81
+ },
82
+ valid: {
83
+ enumerable: true,
84
+ configurable: false,
85
+ get: () => super.get($valid).readUint8(0),
86
+ set: valid => {
87
+ super.set2($valid, super.uintToBuffer(valid, $valid))
88
+ this.#update()
89
+ },
90
+ },
91
+ })
92
+ }
93
+
94
+
95
+ #update() {
96
+
97
+ this.time = Date.now()
98
+ }
99
+ }
100
+
101
+ class Log extends Entity {
102
+
103
+ static name = 'log'
104
+
105
+ static create({
106
+ content,
107
+ id,
108
+ time,
109
+ type,
110
+ uid
111
+ }) {
112
+
113
+ return {
114
+ content,
115
+ id: storage.updateValue(id, Log.name, $id),
116
+ time: time || new Date(),
117
+ type,
118
+ uid,
119
+ }
120
+ }
121
+
122
+ constructor(...arg) {
123
+
124
+ super(storage, ...arg)
125
+
126
+ return Object.defineProperties({}, {
127
+ [position]: {
128
+ enumerable: false,
129
+ configurable: false,
130
+ get: () => this[position],
131
+ },
132
+ content: {
133
+ enumerable: true,
134
+ configurable: false,
135
+ get: () => b2s(super.get($content)),
136
+ set: content => super.set($content, super.s2b(content, $content)),
137
+ },
138
+ id: {
139
+ enumerable: true,
140
+ configurable: false,
141
+ get: () => super.get($id).readUInt32BE(0),
142
+ set: id => super.set2($id, uInt32BEToBuffer(id)),
143
+ },
144
+ time: {
145
+ enumerable: true,
146
+ configurable: false,
147
+ get: () => b2d(super.get($time)),
148
+ set: time => super.set2($time, d2b(time)),
149
+ },
150
+ type: {
151
+ enumerable: true,
152
+ configurable: false,
153
+ get: () => super.get($type).readUint16BE(0),
154
+ set: type => super.set($type, super.uintToBuffer(type, $type)),
155
+ },
156
+ uid: {
157
+ enumerable: true,
158
+ configurable: false,
159
+ get: () => b2s(super.get($uid)),
160
+ set: uid => super.set2($uid, super.s2b(uid, $uid)),
161
+ },
162
+ })
163
+ }
164
+
165
+ }
166
+
167
+ class Test3 extends Entity {
168
+
169
+ static name = 'test3'
170
+
171
+ static create({
172
+ pwd,
173
+ test,
174
+ test2,
175
+ uid
176
+ }) {
177
+
178
+ return {
179
+ pwd,
180
+ test,
181
+ test2,
182
+ uid,
183
+ }
184
+ }
185
+
186
+ constructor(...arg) {
187
+
188
+ super(storage, ...arg)
189
+
190
+ return Object.defineProperties({}, {
191
+ [position]: {
192
+ enumerable: false,
193
+ configurable: false,
194
+ get: () => this[position],
195
+ },
196
+ pwd: {
197
+ enumerable: true,
198
+ configurable: false,
199
+ get: () => b2s(super.get($pwd)),
200
+ set: pwd => super.set($pwd, super.s2b(pwd, $pwd)),
201
+ },
202
+ test: {
203
+ enumerable: true,
204
+ configurable: false,
205
+ get: () => b2s(super.get($test)),
206
+ set: test => super.set($test, super.s2b(test, $test)),
207
+ },
208
+ test2: {
209
+ enumerable: true,
210
+ configurable: false,
211
+ get: () => b2s(super.get($test2)),
212
+ set: test2 => super.set($test2, super.s2b(test2, $test2)),
213
+ },
214
+ uid: {
215
+ enumerable: true,
216
+ configurable: false,
217
+ get: () => b2s(super.get($uid)),
218
+ set: uid => super.set($uid, super.s2b(uid, $uid)),
219
+ },
220
+ })
221
+ }
222
+
223
+ }
224
+
225
+
226
+ class AdminSet extends Entities {
227
+
228
+ constructor() {
229
+
230
+ super(storage, Admin)
231
+ }
232
+ /**
233
+ * 内部方法
234
+ */
235
+ s2b() {
236
+
237
+ throw new TypeError('s2b is not a function')
238
+ }
239
+ /**
240
+ * 内部方法
241
+ */
242
+ findByValue() {
243
+
244
+ throw new TypeError('findByValue is not a function')
245
+ }
246
+ /**
247
+ * 内部方法
248
+ */
249
+ findByTime() {
250
+
251
+ throw new TypeError('findByTime is not a function')
252
+ }
253
+ /**
254
+ * 内部方法
255
+ */
256
+ stringToBuffer() {
257
+
258
+ throw new TypeError('stringToBuffer is not a function')
259
+ }
260
+
261
+ indexById(id) {
262
+
263
+ return super.findByValue($id, uInt32BEToBuffer(id, $id))
264
+ }
265
+
266
+ indexByUid(uid) {
267
+
268
+ return super.findByValue($uid, super.s2b(uid, $uid))
269
+ }
270
+
271
+ indexByValid(valid) {
272
+
273
+ return super.findByValue($valid, super.uintToBuffer(valid, $valid))
274
+ }
275
+
276
+ indexByTime({after, before} = {}) {
277
+
278
+ return super.findByTime($time, {after, before})
279
+ }
280
+ }
281
+
282
+ class LogSet extends Entities {
283
+
284
+ constructor() {
285
+
286
+ super(storage, Log)
287
+ }
288
+ /**
289
+ * 内部方法
290
+ */
291
+ s2b() {
292
+
293
+ throw new TypeError('s2b is not a function')
294
+ }
295
+ /**
296
+ * 内部方法
297
+ */
298
+ findByValue() {
299
+
300
+ throw new TypeError('findByValue is not a function')
301
+ }
302
+ /**
303
+ * 内部方法
304
+ */
305
+ findByTime() {
306
+
307
+ throw new TypeError('findByTime is not a function')
308
+ }
309
+ /**
310
+ * 内部方法
311
+ */
312
+ stringToBuffer() {
313
+
314
+ throw new TypeError('stringToBuffer is not a function')
315
+ }
316
+
317
+ indexById(id) {
318
+
319
+ return super.findByValue($id, uInt32BEToBuffer(id, $id))
320
+ }
321
+
322
+ indexByUid(uid) {
323
+
324
+ return super.findByValue($uid, super.s2b(uid, $uid))
325
+ }
326
+
327
+ indexByTime({after, before} = {}) {
328
+
329
+ return super.findByTime($time, {after, before})
330
+ }
331
+ }
332
+
333
+ class Test3Set extends Entities {
334
+
335
+ constructor() {
336
+
337
+ super(storage, Test3)
338
+ }
339
+ /**
340
+ * 内部方法
341
+ */
342
+ s2b() {
343
+
344
+ throw new TypeError('s2b is not a function')
345
+ }
346
+ /**
347
+ * 内部方法
348
+ */
349
+ findByValue() {
350
+
351
+ throw new TypeError('findByValue is not a function')
352
+ }
353
+ /**
354
+ * 内部方法
355
+ */
356
+ findByTime() {
357
+
358
+ throw new TypeError('findByTime is not a function')
359
+ }
360
+ /**
361
+ * 内部方法
362
+ */
363
+ stringToBuffer() {
364
+
365
+ throw new TypeError('stringToBuffer is not a function')
366
+ }
367
+
368
+ }
369
+
370
+ export const remark = Symbol('remark')
371
+
372
+ export function getStruct() {
373
+
374
+ return struct(storage, remark)
375
+ }
376
+
377
+ /**
378
+ * @type {import('./type').Storage}
379
+ */
380
+ const store = Object.freeze({
381
+ close() {
382
+ storage.close()
383
+ },
384
+ admin: new Proxy([], {
385
+ get: new AdminSet()
386
+ }),
387
+ log: new Proxy([], {
388
+ get: new LogSet()
389
+ }),
390
+ test3: new Proxy([], {
391
+ get: new Test3Set()
392
+ }),
393
+ })
394
+
395
+ export default store