@k3000/store 1.1.3 → 1.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.
Files changed (2) hide show
  1. package/architect.mjs +29 -17
  2. package/package.json +1 -1
package/architect.mjs CHANGED
@@ -7,6 +7,7 @@ import {createCipheriv, createDecipheriv, createHash, scryptSync} from "node:cry
7
7
  *
8
8
  * @param {Array} array
9
9
  * @param {Function | String} predicate
10
+ * @param {Function} map
10
11
  * @return {Array}
11
12
  */
12
13
  Array.prototype.eachFlat = function (array, predicate, map) {
@@ -48,6 +49,7 @@ Array.prototype.eachFlat = function (array, predicate, map) {
48
49
  *
49
50
  * @param {Array} array
50
51
  * @param {Function | String} predicate
52
+ * @param {Function} map
51
53
  * @return {Array}
52
54
  */
53
55
  Array.prototype.filterFlat = function (array, predicate, map) {
@@ -75,6 +77,7 @@ Array.prototype.filterFlat = function (array, predicate, map) {
75
77
  }
76
78
  }
77
79
 
80
+ const MaxSize = 99999
78
81
  /**
79
82
  * 时间筛选的最大值
80
83
  * @type {number}
@@ -341,14 +344,17 @@ export class Entity {
341
344
  return buffer
342
345
  }
343
346
 
344
- textToBuffer(value = '', name) {
347
+ textToBuffer(value, name) {
345
348
 
346
349
  const buffer = Buffer.alloc(TypeLen.text)
347
350
 
348
- writeFileSync(this.#storage.bufferDir + (this.#position + this.#positionSet[name]),
349
- typeof value === "string" ? value : String(value))
351
+ if (value) {
350
352
 
351
- buffer[0] = 1
353
+ writeFileSync(this.#storage.bufferDir + (this.#position + this.#positionSet[name]),
354
+ typeof value === "string" ? value : String(value))
355
+
356
+ buffer[0] = 1
357
+ }
352
358
 
353
359
  return buffer
354
360
  }
@@ -617,7 +623,7 @@ export class Entities extends Array {
617
623
  /**
618
624
  * 分页
619
625
  * @param {Function} predicate
620
- * @param index
626
+ * @param page
621
627
  * @param size
622
628
  * @param params
623
629
  * @return {*[]|*|*[]}
@@ -1104,11 +1110,14 @@ export class Storage {
1104
1110
  console.error(e)
1105
1111
  }
1106
1112
 
1107
- this.#values.set(position, {
1108
- value,
1109
- expired: false,
1110
- needsSave: true,
1111
- })
1113
+ if (this.#values.size < MaxSize) {
1114
+
1115
+ this.#values.set(position, {
1116
+ value,
1117
+ expired: false,
1118
+ needsSave: false,
1119
+ })
1120
+ }
1112
1121
 
1113
1122
  return value
1114
1123
  }
@@ -1149,11 +1158,14 @@ export class Storage {
1149
1158
 
1150
1159
  const needsSave = !val.equals(value)
1151
1160
 
1152
- this.#values.set(position, {
1153
- value,
1154
- expired: true,
1155
- needsSave,
1156
- })
1161
+ if (this.#values.size < MaxSize) {
1162
+
1163
+ this.#values.set(position, {
1164
+ value,
1165
+ expired: true,
1166
+ needsSave,
1167
+ })
1168
+ }
1157
1169
 
1158
1170
  return needsSave
1159
1171
  }
@@ -1451,7 +1463,7 @@ export const bigUint32BEToBuffer = value => {
1451
1463
 
1452
1464
  const buffer = Buffer.alloc(TypeLen.bigUint)
1453
1465
 
1454
- buffer.writeBigUint64BE(value, 0)
1466
+ buffer.writeBigUint64BE(BigInt(value || 0), 0)
1455
1467
 
1456
1468
  return buffer
1457
1469
  }
@@ -1460,7 +1472,7 @@ export const bigint32BEToBuffer = value => {
1460
1472
 
1461
1473
  const buffer = Buffer.alloc(TypeLen.bigint)
1462
1474
 
1463
- buffer.writeBigInt64BE(value, 0)
1475
+ buffer.writeBigInt64BE(BigInt(value || 0), 0)
1464
1476
 
1465
1477
  return buffer
1466
1478
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k3000/store",
3
- "version": "1.1.3",
3
+ "version": "1.2.0",
4
4
  "description": "storage",
5
5
  "main": "generator.mjs",
6
6
  "scripts": {