@k3000/store 1.4.4 → 1.5.1

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/README.md CHANGED
@@ -145,7 +145,7 @@ updateCol('user', {
145
145
  loginTime: Time().value(Time.update).remark('登录时间')
146
146
  })
147
147
 
148
- // 更名索引
148
+ // 更新索引
149
149
  updateIndex('test', {
150
150
  uid: true,
151
151
  pwd: false,
package/architect.mjs CHANGED
@@ -710,14 +710,16 @@ export class Entities extends Array {
710
710
 
711
711
  result = [index[m]]
712
712
 
713
- for (let i = m - 1; i >= 0; i--) {
713
+ let i
714
+
715
+ for (i = m - 1; i >= 0; i--) {
714
716
 
715
717
  if (!this.#storage.getValue(index[i], length).equals(buffer)) break
716
718
 
717
719
  result.unshift(index[i])
718
720
  }
719
721
 
720
- for (let i = m + 1; i < index.length; i++) {
722
+ for (i = m + 1; i < index.length; i++) {
721
723
 
722
724
  if (!this.#storage.getValue(index[i], length).equals(buffer)) break
723
725
 
@@ -727,14 +729,75 @@ export class Entities extends Array {
727
729
  return result
728
730
  }
729
731
 
730
- findByValue2(name, value, value2) {
732
+ #indexAfterPosition(index, after, length, s, e) {
733
+
734
+ if (s + 1 === e) return after.compare(this.#storage.getValue(index[s], length)) > 0 ? e : s
735
+
736
+ const m = Math.round((s + e) / 2)
737
+
738
+ const result = after.compare(this.#storage.getValue(index[m], length))
739
+
740
+ if (result > 0) return this.#indexAfterPosition(index, after, length, m, e)
741
+
742
+ return this.#indexAfterPosition(index, after, length, s, m)
743
+ }
744
+
745
+ #indexBeforePosition(index, before, length, s, e) {
746
+
747
+ if (s + 1 === e) return before.compare(this.#storage.getValue(index[e], length)) < 0 ? s : e
748
+
749
+ const m = Math.round((s + e) / 2)
750
+
751
+ const result = before.compare(this.#storage.getValue(index[m], length))
752
+
753
+ if (result < 0) return this.#indexBeforePosition(index, before, length, s, m)
754
+
755
+ return this.#indexBeforePosition(index, before, length, m, e)
756
+ }
757
+
758
+ #findByRange(index, after, before, length) {
759
+
760
+ if (index.length === 0) return []
761
+
762
+ let s = 0, e = index.length - 1
763
+
764
+ let result = this.#storage.getValue(index[s], length)
765
+
766
+ if (index.length === 1) {
767
+
768
+ if (result.compare(after) >= 0 && result.compare(before) <= 0) {
769
+
770
+ return [index[0]]
771
+ }
772
+
773
+ return []
774
+ }
775
+
776
+ if (result.compare(before) > 0) return []
777
+
778
+ result = this.#storage.getValue(index[e], length)
779
+
780
+ if (result.compare(after) < 0) return []
781
+
782
+ s = this.#indexAfterPosition(index, after, length, s, e)
783
+
784
+ e = this.#indexBeforePosition(index, before, length, s, e)
785
+
786
+ return index.slice(s, e + 1)
787
+ }
788
+
789
+ findByRange(name, value, value2) {
790
+
791
+ const index = this.#index[name]
792
+ const position = this.#positionSet[name]
731
793
 
732
794
  if (value.compare(value2) > 0) {
733
795
 
734
796
  [value, value2] = [value2, value]
735
797
  }
736
798
 
737
-
799
+ return this.#findByRange(index, value, value2, this.#lengthSet[name])
800
+ .map(index => this.#getEntity(index - position))
738
801
  }
739
802
 
740
803
  findByValue(name, value) {
package/generator.mjs CHANGED
@@ -1304,15 +1304,17 @@ ${Object.entries(value).map(([k, v]) => {
1304
1304
  return `
1305
1305
  indexBy${n}({after, before} = {}) {
1306
1306
 
1307
- return super.findByTime($${k}, {after, before})
1307
+ return super.findByRange($${k}, d2b(after || 0), d2b(before || MaxTime))
1308
1308
  }`
1309
1309
 
1310
1310
  } else {
1311
1311
 
1312
1312
  return `
1313
- indexBy${n}(${k}) {
1313
+ indexBy${n}(${k}, ${k}_2) {
1314
1314
 
1315
- return super.findByValue($${k}, ${gen.set[v.type]}(${k}, $${k}))
1315
+ if (${k}_2 === undefined) return super.findByValue($${k}, ${gen.set[v.type]}(${k}, $${k}))
1316
+
1317
+ return super.findByRange($${k}, ${gen.set[v.type]}(${k}, $${k}), ${gen.set[v.type]}(${k}_2, $${k}))
1316
1318
  }`
1317
1319
  }
1318
1320
 
@@ -1338,12 +1340,13 @@ interface ${key} {
1338
1340
  ${key}: ${gen.type[value.type]}`).join('')}
1339
1341
  }
1340
1342
 
1343
+ // @ts-ignore
1341
1344
  interface ${key}Set extends Array<${key}> {
1342
1345
  ${Object.entries(value).filter(([, value]) => value.index).map(([k, value]) => {
1343
1346
  const Key = k[0].toUpperCase() + k.substring(1)
1344
1347
  return value.type === typeMap.time ? `
1345
1348
  indexBy${Key}({after, before}): Array<${key}>` : `
1346
- indexBy${Key}(${k}: ${gen.type[value.type]}): Array<${key}>`
1349
+ indexBy${Key}(${k}: ${gen.type[value.type]}, ${k}_2?: ${gen.type[value.type]}): Array<${key}>`
1347
1350
  }).join('')}
1348
1351
  /**
1349
1352
  * 重写push方法
@@ -1384,7 +1387,7 @@ export interface Storage {${Object.keys(struct.base).map(key => {
1384
1387
 
1385
1388
  const clipIndexMjs = (path, struct) => writeFileSync(path, `
1386
1389
  import {Entities, Entity, Storage, b2d, d2b, b2s, position, uInt32BEToBuffer, int32BEToBuffer,
1387
- doubleBEToBuffer, bigint32BEToBuffer, bigUint32BEToBuffer, readInt24BE, readUint24BE, Store} from '${modulePath}'
1390
+ doubleBEToBuffer, bigint32BEToBuffer, bigUint32BEToBuffer, readInt24BE, readUint24BE, Store, MaxTime} from '${modulePath}'
1388
1391
  import {struct} from '${modulePath2}'
1389
1392
 
1390
1393
  const storage = new Storage(import.meta.url)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k3000/store",
3
- "version": "1.4.4",
3
+ "version": "1.5.1",
4
4
  "description": "storage",
5
5
  "main": "generator.mjs",
6
6
  "scripts": {
package/test/1/index CHANGED
Binary file
package/test/1/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  import {Entities, Entity, Storage, b2d, d2b, b2s, position, uInt32BEToBuffer, int32BEToBuffer,
3
- doubleBEToBuffer, bigint32BEToBuffer, bigUint32BEToBuffer, readInt24BE, readUint24BE, Store} from '../../architect.mjs'
3
+ doubleBEToBuffer, bigint32BEToBuffer, bigUint32BEToBuffer, readInt24BE, readUint24BE, Store, MaxTime} from '../../architect.mjs'
4
4
  import {struct} from '../../generator.mjs'
5
5
 
6
6
  const storage = new Storage(import.meta.url)
@@ -270,24 +270,30 @@ class AdminSet extends Entities {
270
270
  throw new TypeError('stringToBuffer is not a function')
271
271
  }
272
272
 
273
- indexById(id) {
273
+ indexById(id, id_2) {
274
274
 
275
- return super.findByValue($id, uInt32BEToBuffer(id, $id))
275
+ if (id_2 === undefined) return super.findByValue($id, uInt32BEToBuffer(id, $id))
276
+
277
+ return super.findByRange($id, super.intToBuffer(id, $id), super.intToBuffer(id_2, $id))
276
278
  }
277
279
 
278
- indexByUid(uid) {
280
+ indexByUid(uid, uid_2) {
281
+
282
+ if (uid_2 === undefined) return super.findByValue($uid, super.s2b(uid, $uid))
279
283
 
280
- return super.findByValue($uid, super.s2b(uid, $uid))
284
+ return super.findByRange($uid, super.intToBuffer(uid, $uid), super.intToBuffer(uid_2, $uid))
281
285
  }
282
286
 
283
- indexByValid(valid) {
287
+ indexByValid(valid, valid_2) {
288
+
289
+ if (valid_2 === undefined) return super.findByValue($valid, super.uintToBuffer(valid, $valid))
284
290
 
285
- return super.findByValue($valid, super.uintToBuffer(valid, $valid))
291
+ return super.findByRange($valid, super.intToBuffer(valid, $valid), super.intToBuffer(valid_2, $valid))
286
292
  }
287
293
 
288
294
  indexByTime({after, before} = {}) {
289
295
 
290
- return super.findByTime($time, {after, before})
296
+ return super.findByRange($time, d2b(after || 0), d2b(before || MaxTime))
291
297
  }
292
298
  }
293
299
 
@@ -326,19 +332,23 @@ class LogSet extends Entities {
326
332
  throw new TypeError('stringToBuffer is not a function')
327
333
  }
328
334
 
329
- indexById(id) {
335
+ indexById(id, id_2) {
330
336
 
331
- return super.findByValue($id, uInt32BEToBuffer(id, $id))
337
+ if (id_2 === undefined) return super.findByValue($id, uInt32BEToBuffer(id, $id))
338
+
339
+ return super.findByRange($id, super.intToBuffer(id, $id), super.intToBuffer(id_2, $id))
332
340
  }
333
341
 
334
- indexByUid(uid) {
342
+ indexByUid(uid, uid_2) {
343
+
344
+ if (uid_2 === undefined) return super.findByValue($uid, super.s2b(uid, $uid))
335
345
 
336
- return super.findByValue($uid, super.s2b(uid, $uid))
346
+ return super.findByRange($uid, super.intToBuffer(uid, $uid), super.intToBuffer(uid_2, $uid))
337
347
  }
338
348
 
339
349
  indexByTime({after, before} = {}) {
340
350
 
341
- return super.findByTime($time, {after, before})
351
+ return super.findByRange($time, d2b(after || 0), d2b(before || MaxTime))
342
352
  }
343
353
  }
344
354
 
@@ -377,9 +387,11 @@ class TestSet extends Entities {
377
387
  throw new TypeError('stringToBuffer is not a function')
378
388
  }
379
389
 
380
- indexById(id) {
390
+ indexById(id, id_2) {
391
+
392
+ if (id_2 === undefined) return super.findByValue($id, uInt32BEToBuffer(id, $id))
381
393
 
382
- return super.findByValue($id, uInt32BEToBuffer(id, $id))
394
+ return super.findByRange($id, super.intToBuffer(id, $id), super.intToBuffer(id_2, $id))
383
395
  }
384
396
  }
385
397
 
package/test/1/type.ts CHANGED
@@ -23,11 +23,12 @@ interface Admin {
23
23
  time: Number | Date
24
24
  }
25
25
 
26
+ // @ts-ignore
26
27
  interface AdminSet extends Array<Admin> {
27
28
 
28
- indexById(id: Number): Array<Admin>
29
- indexByUid(uid: String): Array<Admin>
30
- indexByValid(valid: Number): Array<Admin>
29
+ indexById(id: Number, id_2?: Number): Array<Admin>
30
+ indexByUid(uid: String, uid_2?: String): Array<Admin>
31
+ indexByValid(valid: Number, valid_2?: Number): Array<Admin>
31
32
  indexByTime({after, before}): Array<Admin>
32
33
  /**
33
34
  * 重写push方法
@@ -79,10 +80,11 @@ interface Log {
79
80
  content: String
80
81
  }
81
82
 
83
+ // @ts-ignore
82
84
  interface LogSet extends Array<Log> {
83
85
 
84
- indexById(id: Number): Array<Log>
85
- indexByUid(uid: String): Array<Log>
86
+ indexById(id: Number, id_2?: Number): Array<Log>
87
+ indexByUid(uid: String, uid_2?: String): Array<Log>
86
88
  indexByTime({after, before}): Array<Log>
87
89
  /**
88
90
  * 重写push方法
@@ -154,9 +156,10 @@ interface Test {
154
156
  text: String
155
157
  }
156
158
 
159
+ // @ts-ignore
157
160
  interface TestSet extends Array<Test> {
158
161
 
159
- indexById(id: Number): Array<Test>
162
+ indexById(id: Number, id_2?: Number): Array<Test>
160
163
  /**
161
164
  * 重写push方法
162
165
  */
package/test/2/data CHANGED
Binary file
package/test/2/index CHANGED
Binary file
package/test/2/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  import {Entities, Entity, Storage, b2d, d2b, b2s, position, uInt32BEToBuffer, int32BEToBuffer,
3
- doubleBEToBuffer, bigint32BEToBuffer, bigUint32BEToBuffer, readInt24BE, readUint24BE, Store} from '../../architect.mjs'
3
+ doubleBEToBuffer, bigint32BEToBuffer, bigUint32BEToBuffer, readInt24BE, readUint24BE, Store, MaxTime} from '../../architect.mjs'
4
4
  import {struct} from '../../generator.mjs'
5
5
 
6
6
  const storage = new Storage(import.meta.url)
@@ -327,24 +327,30 @@ class AdminSet extends Entities {
327
327
  throw new TypeError('stringToBuffer is not a function')
328
328
  }
329
329
 
330
- indexById(id) {
330
+ indexById(id, id_2) {
331
331
 
332
- return super.findByValue($id, uInt32BEToBuffer(id, $id))
332
+ if (id_2 === undefined) return super.findByValue($id, uInt32BEToBuffer(id, $id))
333
+
334
+ return super.findByRange($id, super.intToBuffer(id, $id), super.intToBuffer(id_2, $id))
333
335
  }
334
336
 
335
- indexByUid(uid) {
337
+ indexByUid(uid, uid_2) {
338
+
339
+ if (uid_2 === undefined) return super.findByValue($uid, super.s2b(uid, $uid))
336
340
 
337
- return super.findByValue($uid, super.s2b(uid, $uid))
341
+ return super.findByRange($uid, super.intToBuffer(uid, $uid), super.intToBuffer(uid_2, $uid))
338
342
  }
339
343
 
340
- indexByValid(valid) {
344
+ indexByValid(valid, valid_2) {
345
+
346
+ if (valid_2 === undefined) return super.findByValue($valid, super.uintToBuffer(valid, $valid))
341
347
 
342
- return super.findByValue($valid, super.uintToBuffer(valid, $valid))
348
+ return super.findByRange($valid, super.intToBuffer(valid, $valid), super.intToBuffer(valid_2, $valid))
343
349
  }
344
350
 
345
351
  indexByTime({after, before} = {}) {
346
352
 
347
- return super.findByTime($time, {after, before})
353
+ return super.findByRange($time, d2b(after || 0), d2b(before || MaxTime))
348
354
  }
349
355
  }
350
356
 
@@ -383,19 +389,23 @@ class LogSet extends Entities {
383
389
  throw new TypeError('stringToBuffer is not a function')
384
390
  }
385
391
 
386
- indexById(id) {
392
+ indexById(id, id_2) {
387
393
 
388
- return super.findByValue($id, uInt32BEToBuffer(id, $id))
394
+ if (id_2 === undefined) return super.findByValue($id, uInt32BEToBuffer(id, $id))
395
+
396
+ return super.findByRange($id, super.intToBuffer(id, $id), super.intToBuffer(id_2, $id))
389
397
  }
390
398
 
391
- indexByUid(uid) {
399
+ indexByUid(uid, uid_2) {
400
+
401
+ if (uid_2 === undefined) return super.findByValue($uid, super.s2b(uid, $uid))
392
402
 
393
- return super.findByValue($uid, super.s2b(uid, $uid))
403
+ return super.findByRange($uid, super.intToBuffer(uid, $uid), super.intToBuffer(uid_2, $uid))
394
404
  }
395
405
 
396
406
  indexByTime({after, before} = {}) {
397
407
 
398
- return super.findByTime($time, {after, before})
408
+ return super.findByRange($time, d2b(after || 0), d2b(before || MaxTime))
399
409
  }
400
410
  }
401
411
 
@@ -434,9 +444,11 @@ class TestSet extends Entities {
434
444
  throw new TypeError('stringToBuffer is not a function')
435
445
  }
436
446
 
437
- indexById(id) {
447
+ indexById(id, id_2) {
448
+
449
+ if (id_2 === undefined) return super.findByValue($id, uInt32BEToBuffer(id, $id))
438
450
 
439
- return super.findByValue($id, uInt32BEToBuffer(id, $id))
451
+ return super.findByRange($id, super.intToBuffer(id, $id), super.intToBuffer(id_2, $id))
440
452
  }
441
453
  }
442
454
 
package/test/2/type.ts CHANGED
@@ -23,11 +23,12 @@ interface Admin {
23
23
  time: Number | Date
24
24
  }
25
25
 
26
+ // @ts-ignore
26
27
  interface AdminSet extends Array<Admin> {
27
28
 
28
- indexById(id: Number): Array<Admin>
29
- indexByUid(uid: String): Array<Admin>
30
- indexByValid(valid: Number): Array<Admin>
29
+ indexById(id: Number, id_2?: Number): Array<Admin>
30
+ indexByUid(uid: String, uid_2?: String): Array<Admin>
31
+ indexByValid(valid: Number, valid_2?: Number): Array<Admin>
31
32
  indexByTime({after, before}): Array<Admin>
32
33
  /**
33
34
  * 重写push方法
@@ -79,10 +80,11 @@ interface Log {
79
80
  content: String
80
81
  }
81
82
 
83
+ // @ts-ignore
82
84
  interface LogSet extends Array<Log> {
83
85
 
84
- indexById(id: Number): Array<Log>
85
- indexByUid(uid: String): Array<Log>
86
+ indexById(id: Number, id_2?: Number): Array<Log>
87
+ indexByUid(uid: String, uid_2?: String): Array<Log>
86
88
  indexByTime({after, before}): Array<Log>
87
89
  /**
88
90
  * 重写push方法
@@ -154,9 +156,10 @@ interface Test {
154
156
  text: String
155
157
  }
156
158
 
159
+ // @ts-ignore
157
160
  interface TestSet extends Array<Test> {
158
161
 
159
- indexById(id: Number): Array<Test>
162
+ indexById(id: Number, id_2?: Number): Array<Test>
160
163
  /**
161
164
  * 重写push方法
162
165
  */
@@ -208,6 +211,7 @@ interface Test2 {
208
211
  test3: Number
209
212
  }
210
213
 
214
+ // @ts-ignore
211
215
  interface Test2Set extends Array<Test2> {
212
216
 
213
217
  /**
package/test/3/data CHANGED
Binary file
package/test/3/index CHANGED
Binary file
package/test/3/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  import {Entities, Entity, Storage, b2d, d2b, b2s, position, uInt32BEToBuffer, int32BEToBuffer,
3
- doubleBEToBuffer, bigint32BEToBuffer, bigUint32BEToBuffer, readInt24BE, readUint24BE, Store} from '../../architect.mjs'
3
+ doubleBEToBuffer, bigint32BEToBuffer, bigUint32BEToBuffer, readInt24BE, readUint24BE, Store, MaxTime} from '../../architect.mjs'
4
4
  import {struct} from '../../generator.mjs'
5
5
 
6
6
  const storage = new Storage(import.meta.url)
@@ -334,24 +334,30 @@ class AdminSet extends Entities {
334
334
  throw new TypeError('stringToBuffer is not a function')
335
335
  }
336
336
 
337
- indexById(id) {
337
+ indexById(id, id_2) {
338
338
 
339
- return super.findByValue($id, uInt32BEToBuffer(id, $id))
339
+ if (id_2 === undefined) return super.findByValue($id, uInt32BEToBuffer(id, $id))
340
+
341
+ return super.findByRange($id, super.intToBuffer(id, $id), super.intToBuffer(id_2, $id))
340
342
  }
341
343
 
342
- indexByUid(uid) {
344
+ indexByUid(uid, uid_2) {
345
+
346
+ if (uid_2 === undefined) return super.findByValue($uid, super.s2b(uid, $uid))
343
347
 
344
- return super.findByValue($uid, super.s2b(uid, $uid))
348
+ return super.findByRange($uid, super.intToBuffer(uid, $uid), super.intToBuffer(uid_2, $uid))
345
349
  }
346
350
 
347
- indexByValid(valid) {
351
+ indexByValid(valid, valid_2) {
352
+
353
+ if (valid_2 === undefined) return super.findByValue($valid, super.uintToBuffer(valid, $valid))
348
354
 
349
- return super.findByValue($valid, super.uintToBuffer(valid, $valid))
355
+ return super.findByRange($valid, super.intToBuffer(valid, $valid), super.intToBuffer(valid_2, $valid))
350
356
  }
351
357
 
352
358
  indexByTime({after, before} = {}) {
353
359
 
354
- return super.findByTime($time, {after, before})
360
+ return super.findByRange($time, d2b(after || 0), d2b(before || MaxTime))
355
361
  }
356
362
  }
357
363
 
@@ -390,19 +396,23 @@ class LogSet extends Entities {
390
396
  throw new TypeError('stringToBuffer is not a function')
391
397
  }
392
398
 
393
- indexById(id) {
399
+ indexById(id, id_2) {
394
400
 
395
- return super.findByValue($id, uInt32BEToBuffer(id, $id))
401
+ if (id_2 === undefined) return super.findByValue($id, uInt32BEToBuffer(id, $id))
402
+
403
+ return super.findByRange($id, super.intToBuffer(id, $id), super.intToBuffer(id_2, $id))
396
404
  }
397
405
 
398
- indexByUid(uid) {
406
+ indexByUid(uid, uid_2) {
407
+
408
+ if (uid_2 === undefined) return super.findByValue($uid, super.s2b(uid, $uid))
399
409
 
400
- return super.findByValue($uid, super.s2b(uid, $uid))
410
+ return super.findByRange($uid, super.intToBuffer(uid, $uid), super.intToBuffer(uid_2, $uid))
401
411
  }
402
412
 
403
413
  indexByTime({after, before} = {}) {
404
414
 
405
- return super.findByTime($time, {after, before})
415
+ return super.findByRange($time, d2b(after || 0), d2b(before || MaxTime))
406
416
  }
407
417
  }
408
418
 
@@ -441,9 +451,11 @@ class TestSet extends Entities {
441
451
  throw new TypeError('stringToBuffer is not a function')
442
452
  }
443
453
 
444
- indexById(id) {
454
+ indexById(id, id_2) {
455
+
456
+ if (id_2 === undefined) return super.findByValue($id, uInt32BEToBuffer(id, $id))
445
457
 
446
- return super.findByValue($id, uInt32BEToBuffer(id, $id))
458
+ return super.findByRange($id, super.intToBuffer(id, $id), super.intToBuffer(id_2, $id))
447
459
  }
448
460
  }
449
461
 
package/test/3/type.ts CHANGED
@@ -23,11 +23,12 @@ interface Admin {
23
23
  time: Number | Date
24
24
  }
25
25
 
26
+ // @ts-ignore
26
27
  interface AdminSet extends Array<Admin> {
27
28
 
28
- indexById(id: Number): Array<Admin>
29
- indexByUid(uid: String): Array<Admin>
30
- indexByValid(valid: Number): Array<Admin>
29
+ indexById(id: Number, id_2?: Number): Array<Admin>
30
+ indexByUid(uid: String, uid_2?: String): Array<Admin>
31
+ indexByValid(valid: Number, valid_2?: Number): Array<Admin>
31
32
  indexByTime({after, before}): Array<Admin>
32
33
  /**
33
34
  * 重写push方法
@@ -79,10 +80,11 @@ interface Log {
79
80
  content: String
80
81
  }
81
82
 
83
+ // @ts-ignore
82
84
  interface LogSet extends Array<Log> {
83
85
 
84
- indexById(id: Number): Array<Log>
85
- indexByUid(uid: String): Array<Log>
86
+ indexById(id: Number, id_2?: Number): Array<Log>
87
+ indexByUid(uid: String, uid_2?: String): Array<Log>
86
88
  indexByTime({after, before}): Array<Log>
87
89
  /**
88
90
  * 重写push方法
@@ -154,9 +156,10 @@ interface Test {
154
156
  text: String
155
157
  }
156
158
 
159
+ // @ts-ignore
157
160
  interface TestSet extends Array<Test> {
158
161
 
159
- indexById(id: Number): Array<Test>
162
+ indexById(id: Number, id_2?: Number): Array<Test>
160
163
  /**
161
164
  * 重写push方法
162
165
  */
@@ -212,6 +215,7 @@ interface Test2 {
212
215
  test2: String
213
216
  }
214
217
 
218
+ // @ts-ignore
215
219
  interface Test2Set extends Array<Test2> {
216
220
 
217
221
  /**
package/test/4/data CHANGED
Binary file
package/test/4/index CHANGED
Binary file
package/test/4/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  import {Entities, Entity, Storage, b2d, d2b, b2s, position, uInt32BEToBuffer, int32BEToBuffer,
3
- doubleBEToBuffer, bigint32BEToBuffer, bigUint32BEToBuffer, readInt24BE, readUint24BE, Store} from '../../architect.mjs'
3
+ doubleBEToBuffer, bigint32BEToBuffer, bigUint32BEToBuffer, readInt24BE, readUint24BE, Store, MaxTime} from '../../architect.mjs'
4
4
  import {struct} from '../../generator.mjs'
5
5
 
6
6
  const storage = new Storage(import.meta.url)
@@ -334,24 +334,30 @@ class AdminSet extends Entities {
334
334
  throw new TypeError('stringToBuffer is not a function')
335
335
  }
336
336
 
337
- indexById(id) {
337
+ indexById(id, id_2) {
338
338
 
339
- return super.findByValue($id, uInt32BEToBuffer(id, $id))
339
+ if (id_2 === undefined) return super.findByValue($id, uInt32BEToBuffer(id, $id))
340
+
341
+ return super.findByRange($id, super.intToBuffer(id, $id), super.intToBuffer(id_2, $id))
340
342
  }
341
343
 
342
- indexByUid(uid) {
344
+ indexByUid(uid, uid_2) {
345
+
346
+ if (uid_2 === undefined) return super.findByValue($uid, super.s2b(uid, $uid))
343
347
 
344
- return super.findByValue($uid, super.s2b(uid, $uid))
348
+ return super.findByRange($uid, super.intToBuffer(uid, $uid), super.intToBuffer(uid_2, $uid))
345
349
  }
346
350
 
347
- indexByValid(valid) {
351
+ indexByValid(valid, valid_2) {
352
+
353
+ if (valid_2 === undefined) return super.findByValue($valid, super.uintToBuffer(valid, $valid))
348
354
 
349
- return super.findByValue($valid, super.uintToBuffer(valid, $valid))
355
+ return super.findByRange($valid, super.intToBuffer(valid, $valid), super.intToBuffer(valid_2, $valid))
350
356
  }
351
357
 
352
358
  indexByTime({after, before} = {}) {
353
359
 
354
- return super.findByTime($time, {after, before})
360
+ return super.findByRange($time, d2b(after || 0), d2b(before || MaxTime))
355
361
  }
356
362
  }
357
363
 
@@ -390,19 +396,23 @@ class LogSet extends Entities {
390
396
  throw new TypeError('stringToBuffer is not a function')
391
397
  }
392
398
 
393
- indexById(id) {
399
+ indexById(id, id_2) {
394
400
 
395
- return super.findByValue($id, uInt32BEToBuffer(id, $id))
401
+ if (id_2 === undefined) return super.findByValue($id, uInt32BEToBuffer(id, $id))
402
+
403
+ return super.findByRange($id, super.intToBuffer(id, $id), super.intToBuffer(id_2, $id))
396
404
  }
397
405
 
398
- indexByUid(uid) {
406
+ indexByUid(uid, uid_2) {
407
+
408
+ if (uid_2 === undefined) return super.findByValue($uid, super.s2b(uid, $uid))
399
409
 
400
- return super.findByValue($uid, super.s2b(uid, $uid))
410
+ return super.findByRange($uid, super.intToBuffer(uid, $uid), super.intToBuffer(uid_2, $uid))
401
411
  }
402
412
 
403
413
  indexByTime({after, before} = {}) {
404
414
 
405
- return super.findByTime($time, {after, before})
415
+ return super.findByRange($time, d2b(after || 0), d2b(before || MaxTime))
406
416
  }
407
417
  }
408
418
 
@@ -441,9 +451,11 @@ class TestSet extends Entities {
441
451
  throw new TypeError('stringToBuffer is not a function')
442
452
  }
443
453
 
444
- indexById(id) {
454
+ indexById(id, id_2) {
455
+
456
+ if (id_2 === undefined) return super.findByValue($id, uInt32BEToBuffer(id, $id))
445
457
 
446
- return super.findByValue($id, uInt32BEToBuffer(id, $id))
458
+ return super.findByRange($id, super.intToBuffer(id, $id), super.intToBuffer(id_2, $id))
447
459
  }
448
460
  }
449
461