@k3000/store 1.5.5 → 1.7.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/architect.mjs +55 -37
- package/generator.mjs +1 -1
- package/package.json +1 -1
package/architect.mjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import {dirname} from "node:path"
|
|
2
|
-
import {fileURLToPath} from "node:url"
|
|
3
1
|
import {openSync, closeSync, readFileSync, writeFileSync, readSync, writeSync, unlinkSync} from "node:fs"
|
|
4
2
|
import {createCipheriv, createDecipheriv, createHash, scryptSync} from "node:crypto"
|
|
5
3
|
|
|
@@ -221,23 +219,14 @@ export class Entity {
|
|
|
221
219
|
|
|
222
220
|
#indexPosition(index, buffer, length, s, e) {
|
|
223
221
|
|
|
224
|
-
if (
|
|
222
|
+
if (s + 1 === e) return e
|
|
225
223
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (s === e) return result < 0 ? s : s + 1
|
|
229
|
-
if (result <= 0) return s
|
|
230
|
-
|
|
231
|
-
result = buffer.compare(this.#storage.getValue(index[e], length))
|
|
232
|
-
|
|
233
|
-
if (result >= 0) return e + 1
|
|
234
|
-
|
|
235
|
-
let m = Math.floor((s + e) / 2)
|
|
224
|
+
const m = Math.round((s + e) / 2)
|
|
236
225
|
|
|
237
|
-
result = buffer.compare(this.#storage.getValue(index[m], length))
|
|
226
|
+
const result = buffer.compare(this.#storage.getValue(index[m], length))
|
|
238
227
|
|
|
239
|
-
if (result < 0) return this.#indexPosition(index, buffer, length, s
|
|
240
|
-
if (result > 0) return this.#indexPosition(index, buffer, length, m
|
|
228
|
+
if (result < 0) return this.#indexPosition(index, buffer, length, s, m)
|
|
229
|
+
if (result > 0) return this.#indexPosition(index, buffer, length, m, e)
|
|
241
230
|
|
|
242
231
|
return m
|
|
243
232
|
}
|
|
@@ -264,21 +253,36 @@ export class Entity {
|
|
|
264
253
|
if (i >= 0) {
|
|
265
254
|
|
|
266
255
|
index.splice(i, 1)
|
|
256
|
+
}
|
|
267
257
|
|
|
268
|
-
|
|
258
|
+
let resutl = buffer.compare(this.#storage.getValue(index[0], length))
|
|
269
259
|
|
|
270
|
-
|
|
260
|
+
if (index.length === 0) {
|
|
271
261
|
|
|
272
|
-
|
|
262
|
+
i = 0
|
|
263
|
+
|
|
264
|
+
} else if (index.length === 1) {
|
|
265
|
+
|
|
266
|
+
i = resutl < 0 ? 0 : 1
|
|
273
267
|
|
|
274
|
-
|
|
268
|
+
} else if (resutl <= 0) {
|
|
269
|
+
|
|
270
|
+
i = 0
|
|
271
|
+
|
|
272
|
+
} else {
|
|
275
273
|
|
|
276
|
-
|
|
274
|
+
resutl = buffer.compare(this.#storage.getValue(index[e], length))
|
|
275
|
+
|
|
276
|
+
if (resutl >= 0) {
|
|
277
|
+
|
|
278
|
+
i = e + 1
|
|
279
|
+
|
|
280
|
+
} else {
|
|
281
|
+
|
|
282
|
+
i = this.#indexPosition(index, buffer, length, s, e)
|
|
277
283
|
}
|
|
278
284
|
}
|
|
279
285
|
|
|
280
|
-
i = index.length === 0 ? 0 : this.#indexPosition(index, buffer, length, s, e)
|
|
281
|
-
|
|
282
286
|
index.splice(i, 0, position)
|
|
283
287
|
}
|
|
284
288
|
}
|
|
@@ -463,9 +467,9 @@ export class Entities extends Array {
|
|
|
463
467
|
|
|
464
468
|
let i
|
|
465
469
|
|
|
466
|
-
for (const value of Object.
|
|
470
|
+
for (const [key, value] of Object.entries(this.#index)) {
|
|
467
471
|
|
|
468
|
-
i = value.indexOf(index)
|
|
472
|
+
i = value.indexOf(index + this.#positionSet[key])
|
|
469
473
|
|
|
470
474
|
if (i >= 0) {
|
|
471
475
|
|
|
@@ -729,6 +733,15 @@ export class Entities extends Array {
|
|
|
729
733
|
return result
|
|
730
734
|
}
|
|
731
735
|
|
|
736
|
+
findByValue(name, value) {
|
|
737
|
+
|
|
738
|
+
const index = this.#index[name]
|
|
739
|
+
const position = this.#positionSet[name]
|
|
740
|
+
|
|
741
|
+
return this.#findByValue(index, value, this.#lengthSet[name], 0, index.length - 1)
|
|
742
|
+
.map(index => this.#getEntity(index - position))
|
|
743
|
+
}
|
|
744
|
+
|
|
732
745
|
#indexAfterPosition(index, after, length, s, e) {
|
|
733
746
|
|
|
734
747
|
if (s + 1 === e) return after.compare(this.#storage.getValue(index[s], length)) > 0 ? e : s
|
|
@@ -800,15 +813,6 @@ export class Entities extends Array {
|
|
|
800
813
|
.map(index => this.#getEntity(index - position))
|
|
801
814
|
}
|
|
802
815
|
|
|
803
|
-
findByValue(name, value) {
|
|
804
|
-
|
|
805
|
-
const index = this.#index[name]
|
|
806
|
-
const position = this.#positionSet[name]
|
|
807
|
-
|
|
808
|
-
return this.#findByValue(index, value, this.#lengthSet[name], 0, index.length - 1)
|
|
809
|
-
.map(index => this.#getEntity(index - position))
|
|
810
|
-
}
|
|
811
|
-
|
|
812
816
|
#findByTime(index, after, before, length, s, e) {
|
|
813
817
|
|
|
814
818
|
if (e < s) return []
|
|
@@ -960,7 +964,7 @@ export class Storage {
|
|
|
960
964
|
|
|
961
965
|
constructor(url, password, newPwd) {
|
|
962
966
|
|
|
963
|
-
let dir = url.startsWith('file:///') ?
|
|
967
|
+
let dir = url.startsWith('file:///') ? process.cwd() : url
|
|
964
968
|
|
|
965
969
|
dir = dir.replace(/\\/g, '/')
|
|
966
970
|
|
|
@@ -1303,6 +1307,17 @@ export class Storage {
|
|
|
1303
1307
|
expired: true,
|
|
1304
1308
|
needsSave,
|
|
1305
1309
|
})
|
|
1310
|
+
|
|
1311
|
+
} else {
|
|
1312
|
+
|
|
1313
|
+
try {
|
|
1314
|
+
|
|
1315
|
+
writeSync(this.#fd_data, value, 0, length, position)
|
|
1316
|
+
|
|
1317
|
+
} catch (e) {
|
|
1318
|
+
|
|
1319
|
+
console.error(e)
|
|
1320
|
+
}
|
|
1306
1321
|
}
|
|
1307
1322
|
|
|
1308
1323
|
return needsSave
|
|
@@ -1372,9 +1387,12 @@ export class Storage {
|
|
|
1372
1387
|
|
|
1373
1388
|
updateValue(value, name, key) {
|
|
1374
1389
|
|
|
1375
|
-
if (
|
|
1390
|
+
if (value === undefined) return this.#record.value[name][key] += this.#struct.base[name][key].step
|
|
1391
|
+
|
|
1392
|
+
if (Number.isNaN(Number.parseFloat(value))) {
|
|
1376
1393
|
|
|
1377
|
-
|
|
1394
|
+
value = 1
|
|
1395
|
+
}
|
|
1378
1396
|
|
|
1379
1397
|
if (value > this.#record.value[name][key]) this.#record.value[name][key] = value
|
|
1380
1398
|
|
package/generator.mjs
CHANGED
|
@@ -1315,7 +1315,7 @@ ${Object.entries(value).map(([k, v]) => {
|
|
|
1315
1315
|
return `
|
|
1316
1316
|
indexBy${n}(${k}, ${k}_2) {
|
|
1317
1317
|
|
|
1318
|
-
if (${k}_2 === undefined) return super.findByValue($${k}, ${gen.set[v.type]}(${k}, $${k}))
|
|
1318
|
+
if (${k}_2 === undefined || ${k} == ${k}_2) return super.findByValue($${k}, ${gen.set[v.type]}(${k}, $${k}))
|
|
1319
1319
|
|
|
1320
1320
|
return super.findByRange($${k}, ${gen.set[v.type]}(${k}, $${k}), ${gen.set[v.type]}(${k}_2, $${k}))
|
|
1321
1321
|
}`
|