@k3000/store 1.5.4 → 1.6.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 +54 -34
- package/generator.mjs +8 -11
- package/package.json +1 -1
package/architect.mjs
CHANGED
|
@@ -221,23 +221,14 @@ export class Entity {
|
|
|
221
221
|
|
|
222
222
|
#indexPosition(index, buffer, length, s, e) {
|
|
223
223
|
|
|
224
|
-
if (
|
|
224
|
+
if (s + 1 === e) return e
|
|
225
225
|
|
|
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)
|
|
226
|
+
const m = Math.round((s + e) / 2)
|
|
236
227
|
|
|
237
|
-
result = buffer.compare(this.#storage.getValue(index[m], length))
|
|
228
|
+
const result = buffer.compare(this.#storage.getValue(index[m], length))
|
|
238
229
|
|
|
239
|
-
if (result < 0) return this.#indexPosition(index, buffer, length, s
|
|
240
|
-
if (result > 0) return this.#indexPosition(index, buffer, length, m
|
|
230
|
+
if (result < 0) return this.#indexPosition(index, buffer, length, s, m)
|
|
231
|
+
if (result > 0) return this.#indexPosition(index, buffer, length, m, e)
|
|
241
232
|
|
|
242
233
|
return m
|
|
243
234
|
}
|
|
@@ -264,21 +255,36 @@ export class Entity {
|
|
|
264
255
|
if (i >= 0) {
|
|
265
256
|
|
|
266
257
|
index.splice(i, 1)
|
|
258
|
+
}
|
|
267
259
|
|
|
268
|
-
|
|
260
|
+
let resutl = buffer.compare(this.#storage.getValue(index[0], length))
|
|
269
261
|
|
|
270
|
-
|
|
262
|
+
if (index.length === 0) {
|
|
271
263
|
|
|
272
|
-
|
|
264
|
+
i = 0
|
|
265
|
+
|
|
266
|
+
} else if (index.length === 1) {
|
|
267
|
+
|
|
268
|
+
i = resutl < 0 ? 0 : 1
|
|
273
269
|
|
|
274
|
-
|
|
270
|
+
} else if (resutl <= 0) {
|
|
271
|
+
|
|
272
|
+
i = 0
|
|
273
|
+
|
|
274
|
+
} else {
|
|
275
275
|
|
|
276
|
-
|
|
276
|
+
resutl = buffer.compare(this.#storage.getValue(index[e], length))
|
|
277
|
+
|
|
278
|
+
if (resutl >= 0) {
|
|
279
|
+
|
|
280
|
+
i = e + 1
|
|
281
|
+
|
|
282
|
+
} else {
|
|
283
|
+
|
|
284
|
+
i = this.#indexPosition(index, buffer, length, s, e)
|
|
277
285
|
}
|
|
278
286
|
}
|
|
279
287
|
|
|
280
|
-
i = index.length === 0 ? 0 : this.#indexPosition(index, buffer, length, s, e)
|
|
281
|
-
|
|
282
288
|
index.splice(i, 0, position)
|
|
283
289
|
}
|
|
284
290
|
}
|
|
@@ -463,9 +469,9 @@ export class Entities extends Array {
|
|
|
463
469
|
|
|
464
470
|
let i
|
|
465
471
|
|
|
466
|
-
for (const value of Object.
|
|
472
|
+
for (const [key, value] of Object.entries(this.#index)) {
|
|
467
473
|
|
|
468
|
-
i = value.indexOf(index)
|
|
474
|
+
i = value.indexOf(index + this.#positionSet[key])
|
|
469
475
|
|
|
470
476
|
if (i >= 0) {
|
|
471
477
|
|
|
@@ -729,6 +735,15 @@ export class Entities extends Array {
|
|
|
729
735
|
return result
|
|
730
736
|
}
|
|
731
737
|
|
|
738
|
+
findByValue(name, value) {
|
|
739
|
+
|
|
740
|
+
const index = this.#index[name]
|
|
741
|
+
const position = this.#positionSet[name]
|
|
742
|
+
|
|
743
|
+
return this.#findByValue(index, value, this.#lengthSet[name], 0, index.length - 1)
|
|
744
|
+
.map(index => this.#getEntity(index - position))
|
|
745
|
+
}
|
|
746
|
+
|
|
732
747
|
#indexAfterPosition(index, after, length, s, e) {
|
|
733
748
|
|
|
734
749
|
if (s + 1 === e) return after.compare(this.#storage.getValue(index[s], length)) > 0 ? e : s
|
|
@@ -800,15 +815,6 @@ export class Entities extends Array {
|
|
|
800
815
|
.map(index => this.#getEntity(index - position))
|
|
801
816
|
}
|
|
802
817
|
|
|
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
818
|
#findByTime(index, after, before, length, s, e) {
|
|
813
819
|
|
|
814
820
|
if (e < s) return []
|
|
@@ -1303,6 +1309,17 @@ export class Storage {
|
|
|
1303
1309
|
expired: true,
|
|
1304
1310
|
needsSave,
|
|
1305
1311
|
})
|
|
1312
|
+
|
|
1313
|
+
} else {
|
|
1314
|
+
|
|
1315
|
+
try {
|
|
1316
|
+
|
|
1317
|
+
writeSync(this.#fd_data, value, 0, length, position)
|
|
1318
|
+
|
|
1319
|
+
} catch (e) {
|
|
1320
|
+
|
|
1321
|
+
console.error(e)
|
|
1322
|
+
}
|
|
1306
1323
|
}
|
|
1307
1324
|
|
|
1308
1325
|
return needsSave
|
|
@@ -1372,9 +1389,12 @@ export class Storage {
|
|
|
1372
1389
|
|
|
1373
1390
|
updateValue(value, name, key) {
|
|
1374
1391
|
|
|
1375
|
-
if (
|
|
1392
|
+
if (value === undefined) return this.#record.value[name][key] += this.#struct.base[name][key].step
|
|
1393
|
+
|
|
1394
|
+
if (Number.isNaN(Number.parseFloat(value))) {
|
|
1376
1395
|
|
|
1377
|
-
|
|
1396
|
+
value = 1
|
|
1397
|
+
}
|
|
1378
1398
|
|
|
1379
1399
|
if (value > this.#record.value[name][key]) this.#record.value[name][key] = value
|
|
1380
1400
|
|
package/generator.mjs
CHANGED
|
@@ -938,7 +938,7 @@ function submit() {
|
|
|
938
938
|
clipTypeTs(this.typePath, this.curr.struct)
|
|
939
939
|
clipIndexMjs(this.currPath, this.curr.struct)
|
|
940
940
|
|
|
941
|
-
const version = readdirSync(this.dir).map(v => parseFloat(v) || 0).sort(
|
|
941
|
+
const version = readdirSync(this.dir).map(v => parseFloat(v) || 0).sort().pop()
|
|
942
942
|
|
|
943
943
|
writeFileSync(`${this.dir}index.mjs`, `
|
|
944
944
|
const index = import.meta.url.indexOf('?')
|
|
@@ -1195,6 +1195,7 @@ const clipIndex = (name, key, k, v) => {
|
|
|
1195
1195
|
|
|
1196
1196
|
const clipConst = struct => Array.from(new Set(Object.values(struct)
|
|
1197
1197
|
.map(struct => Object.keys(struct)).flat()))
|
|
1198
|
+
.sort()
|
|
1198
1199
|
.map(key => `const $${key} = '${key}'`)
|
|
1199
1200
|
.join('\n')
|
|
1200
1201
|
|
|
@@ -1210,11 +1211,7 @@ const clipProperties = (name, key, update, [k, v]) => `
|
|
|
1210
1211
|
}` : clipIndex(name, key, k, v)},
|
|
1211
1212
|
},`
|
|
1212
1213
|
|
|
1213
|
-
const
|
|
1214
|
-
|
|
1215
|
-
const sort2 = (a, b) => a > b ? 1 : a < b ? -1 : 0
|
|
1216
|
-
|
|
1217
|
-
const sort3 = ([a], [b]) => a > b ? 1 : a < b ? -1 : 0
|
|
1214
|
+
const sort2 = ([a], [b]) => a.localeCompare(b)
|
|
1218
1215
|
|
|
1219
1216
|
const clipEntity = ([key, value]) => {
|
|
1220
1217
|
|
|
@@ -1228,7 +1225,7 @@ class ${name} extends Entity {
|
|
|
1228
1225
|
static name = '${key}'
|
|
1229
1226
|
|
|
1230
1227
|
static create(_) {
|
|
1231
|
-
${Object.entries(value).sort(
|
|
1228
|
+
${Object.entries(value).sort(sort2).map(clipStatic.bind(null, name)).filter(str => str).join('\n')}
|
|
1232
1229
|
return _
|
|
1233
1230
|
}
|
|
1234
1231
|
|
|
@@ -1241,7 +1238,7 @@ ${Object.entries(value).sort(sort3).map(clipStatic.bind(null, name)).filter(str
|
|
|
1241
1238
|
enumerable: false,
|
|
1242
1239
|
configurable: false,
|
|
1243
1240
|
get: () => this[position],
|
|
1244
|
-
},${Object.entries(value).sort(
|
|
1241
|
+
},${Object.entries(value).sort(sort2).map(clipProperties.bind(null, name, key, update)).join('')}
|
|
1245
1242
|
})
|
|
1246
1243
|
}
|
|
1247
1244
|
${update ? `
|
|
@@ -1318,7 +1315,7 @@ ${Object.entries(value).map(([k, v]) => {
|
|
|
1318
1315
|
return `
|
|
1319
1316
|
indexBy${n}(${k}, ${k}_2) {
|
|
1320
1317
|
|
|
1321
|
-
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}))
|
|
1322
1319
|
|
|
1323
1320
|
return super.findByRange($${k}, ${gen.set[v.type]}(${k}, $${k}), ${gen.set[v.type]}(${k}_2, $${k}))
|
|
1324
1321
|
}`
|
|
@@ -1339,7 +1336,7 @@ const clipTypeTs = (path, struct) => writeFileSync(path, `${Object.entries(struc
|
|
|
1339
1336
|
|
|
1340
1337
|
return `
|
|
1341
1338
|
interface ${key} {
|
|
1342
|
-
${Object.entries(value).map(([key, value]) => `
|
|
1339
|
+
${Object.entries(value).sort(sort2).map(([key, value]) => `
|
|
1343
1340
|
/**
|
|
1344
1341
|
* ${commentRemark(value.remark)}
|
|
1345
1342
|
*/
|
|
@@ -1448,7 +1445,7 @@ export default function upgrade(name, {
|
|
|
1448
1445
|
mkdirSync(dir)
|
|
1449
1446
|
}
|
|
1450
1447
|
|
|
1451
|
-
let v = readdirSync(dir).map(v => parseFloat(v) || 0).sort(
|
|
1448
|
+
let v = readdirSync(dir).map(v => parseFloat(v) || 0).sort().pop()
|
|
1452
1449
|
|
|
1453
1450
|
let prev
|
|
1454
1451
|
|