@k3000/store 0.1.2 → 0.2.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 CHANGED
@@ -769,6 +769,9 @@ export default storage
769
769
  return Promise.all([import(this.prevPath + this.prevUrlParams), import(this.currPath + this.currUrlParams)])
770
770
  .then(([prev, curr]) => {
771
771
 
772
+ const prevClose = prev.close
773
+ const currClose = curr.close
774
+
772
775
  prev = prev.default
773
776
  curr = curr.default
774
777
 
@@ -781,8 +784,8 @@ export default storage
781
784
  curr[name].push(...prev[name])
782
785
  }
783
786
 
784
- prev.close()
785
- curr.close()
787
+ prevClose()
788
+ currClose()
786
789
  })
787
790
 
788
791
  } else {
@@ -932,11 +935,11 @@ const gen = {
932
935
 
933
936
  const clipStatic = (name, [key, value]) => {
934
937
 
935
- if (!Reflect.has(value, 'value')) return `\t\t\t${key},`
938
+ if (!Reflect.has(value, 'value')) return ''
936
939
 
937
940
  let valueStr = ''
938
941
 
939
- if (Reflect.has(value, 'step')) return `\t\t\t${key}: storage.updateValue(${key}, ${name}.name, $${key}),`
942
+ if (Reflect.has(value, 'step')) return `\t\t_.${key} = storage.updateValue(_.${key}, ${name}.name, $${key})`
940
943
 
941
944
  switch (value.type) {
942
945
 
@@ -968,7 +971,7 @@ const clipStatic = (name, [key, value]) => {
968
971
  valueStr = ' || ' + value.value
969
972
  }
970
973
 
971
- return `\t\t\t${key}${valueStr ? `: ${key}${valueStr}` : ''},`
974
+ return valueStr ? `\t\t_.${key} = _.${key}${valueStr}` : ''
972
975
  }
973
976
 
974
977
  const clipIndex = (name, key, k, v) => {
@@ -977,15 +980,15 @@ const clipIndex = (name, key, k, v) => {
977
980
 
978
981
  if (v.type === typeMap.int) {
979
982
 
980
- main = `super.intToBuffer(${k}, $${k})`
983
+ main = `super.intToBuffer(value, $${k})`
981
984
 
982
985
  } else if (v.type === typeMap.uint) {
983
986
 
984
- main = `super.uintToBuffer(${k}, $${k})`
987
+ main = `super.uintToBuffer(value, $${k})`
985
988
 
986
989
  } else {
987
990
 
988
- main = `${gen.set[v.type]}(${k}${v.type === typeMap.buffer
991
+ main = `${gen.set[v.type]}(value${v.type === typeMap.buffer
989
992
  || v.type === typeMap.text ? `, $${k}` : v.type === typeMap.string
990
993
  ? `, $${k}` : ''})`
991
994
  }
@@ -1011,7 +1014,7 @@ const clipProperties = (name, key, update, [k, v]) => `
1011
1014
  configurable: false,
1012
1015
  get: () => ${gen.get[v.type](`super.get($${k})`, v.type === typeMap.buffer
1013
1016
  || v.type === typeMap.text ? `$${k}` : v.length)},
1014
- set: ${k} => ${update && k !== update[0] ? `{
1017
+ set: value => ${update && k !== update[0] ? `{
1015
1018
  ${clipIndex(name, key, k, v)}
1016
1019
  this.#update()
1017
1020
  }` : clipIndex(name, key, k, v)},
@@ -1034,13 +1037,9 @@ class ${name} extends Entity {
1034
1037
 
1035
1038
  static name = '${key}'
1036
1039
 
1037
- static create({
1038
- ${Object.keys(value).sort(sort2).join(',\n\t\t\t')}
1039
- }) {
1040
-
1041
- return {
1042
- ${Object.entries(value).sort(sort3).map(clipStatic.bind(null, name)).join('\n')}
1043
- }
1040
+ static create(_) {
1041
+ ${Object.entries(value).sort(sort3).map(clipStatic.bind(null, name)).filter(str => str).join('\n')}
1042
+ return _
1044
1043
  }
1045
1044
 
1046
1045
  constructor(...arg) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k3000/store",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "storage",
5
5
  "main": "generator.mjs",
6
6
  "scripts": {
package/test/0/index.mjs CHANGED
@@ -6,14 +6,10 @@ const storage = new Storage(import.meta.url)
6
6
 
7
7
  export const remark = Symbol('remark')
8
8
 
9
- export function getStruct() {
9
+ export const close = () => storage.close()
10
10
 
11
- return struct(storage, remark)
12
- }
11
+ export const getStruct = () => struct(storage, remark)
13
12
 
14
13
  export default new class extends Store {
15
14
 
16
- close() {
17
- storage.close()
18
- }
19
15
  }
package/test/1/index CHANGED
Binary file
package/test/1/index.mjs CHANGED
@@ -25,21 +25,12 @@ class Admin extends Entity {
25
25
 
26
26
  static name = 'admin'
27
27
 
28
- static create({
29
- id,
30
- pwd,
31
- time,
32
- uid,
33
- valid
34
- }) {
35
-
36
- return {
37
- id: storage.updateValue(id, Admin.name, $id),
38
- pwd: pwd || '123456',
39
- time: time || new Date(),
40
- uid,
41
- valid: valid || 0,
42
- }
28
+ static create(_) {
29
+ _.id = storage.updateValue(_.id, Admin.name, $id)
30
+ _.pwd = _.pwd || '123456'
31
+ _.time = _.time || new Date()
32
+ _.valid = _.valid || 0
33
+ return _
43
34
  }
44
35
 
45
36
  constructor(...arg) {
@@ -56,8 +47,8 @@ class Admin extends Entity {
56
47
  enumerable: true,
57
48
  configurable: false,
58
49
  get: () => super.get($id).readUInt32BE(0),
59
- set: id => {
60
- super.set2($id, uInt32BEToBuffer(id))
50
+ set: value => {
51
+ super.set2($id, uInt32BEToBuffer(value))
61
52
  this.#update()
62
53
  },
63
54
  },
@@ -65,8 +56,8 @@ class Admin extends Entity {
65
56
  enumerable: true,
66
57
  configurable: false,
67
58
  get: () => b2s(super.get($pwd)),
68
- set: pwd => {
69
- super.set($pwd, super.s2b(pwd, $pwd))
59
+ set: value => {
60
+ super.set($pwd, super.s2b(value, $pwd))
70
61
  this.#update()
71
62
  },
72
63
  },
@@ -74,14 +65,14 @@ class Admin extends Entity {
74
65
  enumerable: true,
75
66
  configurable: false,
76
67
  get: () => b2d(super.get($time)),
77
- set: time => super.set2($time, d2b(time)),
68
+ set: value => super.set2($time, d2b(value)),
78
69
  },
79
70
  uid: {
80
71
  enumerable: true,
81
72
  configurable: false,
82
73
  get: () => b2s(super.get($uid)),
83
- set: uid => {
84
- super.set2($uid, super.s2b(uid, $uid))
74
+ set: value => {
75
+ super.set2($uid, super.s2b(value, $uid))
85
76
  this.#update()
86
77
  },
87
78
  },
@@ -89,8 +80,8 @@ class Admin extends Entity {
89
80
  enumerable: true,
90
81
  configurable: false,
91
82
  get: () => super.get($valid).readUint8(0),
92
- set: valid => {
93
- super.set2($valid, super.uintToBuffer(valid, $valid))
83
+ set: value => {
84
+ super.set2($valid, super.uintToBuffer(value, $valid))
94
85
  this.#update()
95
86
  },
96
87
  },
@@ -108,21 +99,10 @@ class Log extends Entity {
108
99
 
109
100
  static name = 'log'
110
101
 
111
- static create({
112
- content,
113
- id,
114
- time,
115
- type,
116
- uid
117
- }) {
118
-
119
- return {
120
- content,
121
- id: storage.updateValue(id, Log.name, $id),
122
- time: time || new Date(),
123
- type,
124
- uid,
125
- }
102
+ static create(_) {
103
+ _.id = storage.updateValue(_.id, Log.name, $id)
104
+ _.time = _.time || new Date()
105
+ return _
126
106
  }
127
107
 
128
108
  constructor(...arg) {
@@ -139,31 +119,31 @@ class Log extends Entity {
139
119
  enumerable: true,
140
120
  configurable: false,
141
121
  get: () => b2s(super.get($content)),
142
- set: content => super.set($content, super.s2b(content, $content)),
122
+ set: value => super.set($content, super.s2b(value, $content)),
143
123
  },
144
124
  id: {
145
125
  enumerable: true,
146
126
  configurable: false,
147
127
  get: () => super.get($id).readUInt32BE(0),
148
- set: id => super.set2($id, uInt32BEToBuffer(id)),
128
+ set: value => super.set2($id, uInt32BEToBuffer(value)),
149
129
  },
150
130
  time: {
151
131
  enumerable: true,
152
132
  configurable: false,
153
133
  get: () => b2d(super.get($time)),
154
- set: time => super.set2($time, d2b(time)),
134
+ set: value => super.set2($time, d2b(value)),
155
135
  },
156
136
  type: {
157
137
  enumerable: true,
158
138
  configurable: false,
159
139
  get: () => super.get($type).readUint16BE(0),
160
- set: type => super.set($type, super.uintToBuffer(type, $type)),
140
+ set: value => super.set($type, super.uintToBuffer(value, $type)),
161
141
  },
162
142
  uid: {
163
143
  enumerable: true,
164
144
  configurable: false,
165
145
  get: () => b2s(super.get($uid)),
166
- set: uid => super.set2($uid, super.s2b(uid, $uid)),
146
+ set: value => super.set2($uid, super.s2b(value, $uid)),
167
147
  },
168
148
  })
169
149
  }
@@ -174,31 +154,9 @@ class Test extends Entity {
174
154
 
175
155
  static name = 'test'
176
156
 
177
- static create({
178
- bigUint,
179
- bigint,
180
- buffer,
181
- float,
182
- id,
183
- int,
184
- string,
185
- text,
186
- time,
187
- uint
188
- }) {
189
-
190
- return {
191
- bigUint,
192
- bigint,
193
- buffer,
194
- float,
195
- id: storage.updateValue(id, Test.name, $id),
196
- int,
197
- string,
198
- text,
199
- time,
200
- uint,
201
- }
157
+ static create(_) {
158
+ _.id = storage.updateValue(_.id, Test.name, $id)
159
+ return _
202
160
  }
203
161
 
204
162
  constructor(...arg) {
@@ -215,61 +173,61 @@ class Test extends Entity {
215
173
  enumerable: true,
216
174
  configurable: false,
217
175
  get: () => super.get($bigUint).readBigUInt64BE(0),
218
- set: bigUint => super.set($bigUint, bigUint32BEToBuffer(bigUint)),
176
+ set: value => super.set($bigUint, bigUint32BEToBuffer(value)),
219
177
  },
220
178
  bigint: {
221
179
  enumerable: true,
222
180
  configurable: false,
223
181
  get: () => super.get($bigint).readBigInt64BE(0),
224
- set: bigint => super.set($bigint, bigint32BEToBuffer(bigint)),
182
+ set: value => super.set($bigint, bigint32BEToBuffer(value)),
225
183
  },
226
184
  buffer: {
227
185
  enumerable: true,
228
186
  configurable: false,
229
187
  get: () => super.get($buffer)[0] ? super.readFileSync($buffer) : null,
230
- set: buffer => super.set($buffer, super.buffer(buffer, $buffer)),
188
+ set: value => super.set($buffer, super.buffer(value, $buffer)),
231
189
  },
232
190
  float: {
233
191
  enumerable: true,
234
192
  configurable: false,
235
193
  get: () => super.get($float).readDoubleBE(0),
236
- set: float => super.set($float, doubleBEToBuffer(float)),
194
+ set: value => super.set($float, doubleBEToBuffer(value)),
237
195
  },
238
196
  id: {
239
197
  enumerable: true,
240
198
  configurable: false,
241
199
  get: () => super.get($id).readUInt32BE(0),
242
- set: id => super.set2($id, uInt32BEToBuffer(id)),
200
+ set: value => super.set2($id, uInt32BEToBuffer(value)),
243
201
  },
244
202
  int: {
245
203
  enumerable: true,
246
204
  configurable: false,
247
205
  get: () => readInt24BE(super.get($int)),
248
- set: int => super.set($int, super.intToBuffer(int, $int)),
206
+ set: value => super.set($int, super.intToBuffer(value, $int)),
249
207
  },
250
208
  string: {
251
209
  enumerable: true,
252
210
  configurable: false,
253
211
  get: () => b2s(super.get($string)),
254
- set: string => super.set($string, super.s2b(string, $string)),
212
+ set: value => super.set($string, super.s2b(value, $string)),
255
213
  },
256
214
  text: {
257
215
  enumerable: true,
258
216
  configurable: false,
259
217
  get: () => super.get($text)[0] ? super.readFileSync($text).toString() : '',
260
- set: text => super.set($text, super.textToBuffer(text, $text)),
218
+ set: value => super.set($text, super.textToBuffer(value, $text)),
261
219
  },
262
220
  time: {
263
221
  enumerable: true,
264
222
  configurable: false,
265
223
  get: () => b2d(super.get($time)),
266
- set: time => super.set($time, d2b(time)),
224
+ set: value => super.set($time, d2b(value)),
267
225
  },
268
226
  uint: {
269
227
  enumerable: true,
270
228
  configurable: false,
271
229
  get: () => super.get($uint).readUInt32BE(0),
272
- set: uint => super.set($uint, super.uintToBuffer(uint, $uint)),
230
+ set: value => super.set($uint, super.uintToBuffer(value, $uint)),
273
231
  },
274
232
  })
275
233
  }
@@ -427,18 +385,14 @@ class TestSet extends Entities {
427
385
 
428
386
  export const remark = Symbol('remark')
429
387
 
430
- export function getStruct() {
388
+ export const close = () => storage.close()
431
389
 
432
- return struct(storage, remark)
433
- }
390
+ export const getStruct = () => struct(storage, remark)
434
391
 
435
392
  /**
436
393
  * @type {import('./type').Storage}
437
394
  */
438
395
  const store = Object.freeze({
439
- close() {
440
- storage.close()
441
- },
442
396
  admin: new Proxy([], {
443
397
  get: new AdminSet()
444
398
  }),
package/test/1/type.ts CHANGED
@@ -1,5 +1,3 @@
1
- interface BigInt {}
2
- interface Buffer {}
3
1
 
4
2
  interface Admin {
5
3
 
@@ -163,7 +161,6 @@ interface TestSet extends Array<Test> {
163
161
 
164
162
 
165
163
  export interface Storage {
166
- close(): void
167
164
  admin: AdminSet,
168
165
  log: LogSet,
169
166
  test: TestSet
package/test/2/index CHANGED
Binary file