serializable-bptree 4.0.1 → 4.0.2

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.
@@ -61,371 +61,6 @@ var StringComparator = class extends ValueComparator {
61
61
  }
62
62
  };
63
63
 
64
- // node_modules/cachebranch/dist/esm/index.mjs
65
- var CacheBranch = class {
66
- data;
67
- branches;
68
- constructor(data) {
69
- this.data = data;
70
- this.branches = /* @__PURE__ */ new Map();
71
- }
72
- /**
73
- * The method splits the provided key value into tokens and returns them as an array.
74
- * For instance, if you pass `'user/name/middle'` as the parameter, it will return `['user', 'name', 'middle']` as the split values.
75
- * @param key The key value to split.
76
- */
77
- tokens(key) {
78
- return key.split("/");
79
- }
80
- to(key, getNextBranch) {
81
- const tokens = this.tokens(key);
82
- let current = this;
83
- for (let i = 0, len = tokens.length; i < len; i++) {
84
- const last = i === len - 1;
85
- const key2 = tokens[i];
86
- const next = getNextBranch(current, key2, i, last);
87
- if (next === null) {
88
- return void 0;
89
- }
90
- current = next;
91
- }
92
- return current;
93
- }
94
- };
95
- var VOID = -1;
96
- var PRIMITIVE = 0;
97
- var ARRAY = 1;
98
- var OBJECT = 2;
99
- var DATE = 3;
100
- var REGEXP = 4;
101
- var MAP = 5;
102
- var SET = 6;
103
- var ERROR = 7;
104
- var BIGINT = 8;
105
- var env = typeof self === "object" ? self : globalThis;
106
- var deserializer = ($, _) => {
107
- const as = (out, index) => {
108
- $.set(index, out);
109
- return out;
110
- };
111
- const unpair = (index) => {
112
- if ($.has(index))
113
- return $.get(index);
114
- const [type, value] = _[index];
115
- switch (type) {
116
- case PRIMITIVE:
117
- case VOID:
118
- return as(value, index);
119
- case ARRAY: {
120
- const arr = as([], index);
121
- for (const index2 of value)
122
- arr.push(unpair(index2));
123
- return arr;
124
- }
125
- case OBJECT: {
126
- const object = as({}, index);
127
- for (const [key, index2] of value)
128
- object[unpair(key)] = unpair(index2);
129
- return object;
130
- }
131
- case DATE:
132
- return as(new Date(value), index);
133
- case REGEXP: {
134
- const { source, flags } = value;
135
- return as(new RegExp(source, flags), index);
136
- }
137
- case MAP: {
138
- const map = as(/* @__PURE__ */ new Map(), index);
139
- for (const [key, index2] of value)
140
- map.set(unpair(key), unpair(index2));
141
- return map;
142
- }
143
- case SET: {
144
- const set = as(/* @__PURE__ */ new Set(), index);
145
- for (const index2 of value)
146
- set.add(unpair(index2));
147
- return set;
148
- }
149
- case ERROR: {
150
- const { name, message } = value;
151
- return as(new env[name](message), index);
152
- }
153
- case BIGINT:
154
- return as(BigInt(value), index);
155
- case "BigInt":
156
- return as(Object(BigInt(value)), index);
157
- }
158
- return as(new env[type](value), index);
159
- };
160
- return unpair;
161
- };
162
- var deserialize = (serialized) => deserializer(/* @__PURE__ */ new Map(), serialized)(0);
163
- var EMPTY = "";
164
- var { toString } = {};
165
- var { keys } = Object;
166
- var typeOf = (value) => {
167
- const type = typeof value;
168
- if (type !== "object" || !value)
169
- return [PRIMITIVE, type];
170
- const asString = toString.call(value).slice(8, -1);
171
- switch (asString) {
172
- case "Array":
173
- return [ARRAY, EMPTY];
174
- case "Object":
175
- return [OBJECT, EMPTY];
176
- case "Date":
177
- return [DATE, EMPTY];
178
- case "RegExp":
179
- return [REGEXP, EMPTY];
180
- case "Map":
181
- return [MAP, EMPTY];
182
- case "Set":
183
- return [SET, EMPTY];
184
- }
185
- if (asString.includes("Array"))
186
- return [ARRAY, asString];
187
- if (asString.includes("Error"))
188
- return [ERROR, asString];
189
- return [OBJECT, asString];
190
- };
191
- var shouldSkip = ([TYPE, type]) => TYPE === PRIMITIVE && (type === "function" || type === "symbol");
192
- var serializer = (strict, json, $, _) => {
193
- const as = (out, value) => {
194
- const index = _.push(out) - 1;
195
- $.set(value, index);
196
- return index;
197
- };
198
- const pair = (value) => {
199
- if ($.has(value))
200
- return $.get(value);
201
- let [TYPE, type] = typeOf(value);
202
- switch (TYPE) {
203
- case PRIMITIVE: {
204
- let entry = value;
205
- switch (type) {
206
- case "bigint":
207
- TYPE = BIGINT;
208
- entry = value.toString();
209
- break;
210
- case "function":
211
- case "symbol":
212
- if (strict)
213
- throw new TypeError("unable to serialize " + type);
214
- entry = null;
215
- break;
216
- case "undefined":
217
- return as([VOID], value);
218
- }
219
- return as([TYPE, entry], value);
220
- }
221
- case ARRAY: {
222
- if (type)
223
- return as([type, [...value]], value);
224
- const arr = [];
225
- const index = as([TYPE, arr], value);
226
- for (const entry of value)
227
- arr.push(pair(entry));
228
- return index;
229
- }
230
- case OBJECT: {
231
- if (type) {
232
- switch (type) {
233
- case "BigInt":
234
- return as([type, value.toString()], value);
235
- case "Boolean":
236
- case "Number":
237
- case "String":
238
- return as([type, value.valueOf()], value);
239
- }
240
- }
241
- if (json && "toJSON" in value)
242
- return pair(value.toJSON());
243
- const entries = [];
244
- const index = as([TYPE, entries], value);
245
- for (const key of keys(value)) {
246
- if (strict || !shouldSkip(typeOf(value[key])))
247
- entries.push([pair(key), pair(value[key])]);
248
- }
249
- return index;
250
- }
251
- case DATE:
252
- return as([TYPE, value.toISOString()], value);
253
- case REGEXP: {
254
- const { source, flags } = value;
255
- return as([TYPE, { source, flags }], value);
256
- }
257
- case MAP: {
258
- const entries = [];
259
- const index = as([TYPE, entries], value);
260
- for (const [key, entry] of value) {
261
- if (strict || !(shouldSkip(typeOf(key)) || shouldSkip(typeOf(entry))))
262
- entries.push([pair(key), pair(entry)]);
263
- }
264
- return index;
265
- }
266
- case SET: {
267
- const entries = [];
268
- const index = as([TYPE, entries], value);
269
- for (const entry of value) {
270
- if (strict || !shouldSkip(typeOf(entry)))
271
- entries.push(pair(entry));
272
- }
273
- return index;
274
- }
275
- }
276
- const { message } = value;
277
- return as([TYPE, { name: type, message }], value);
278
- };
279
- return pair;
280
- };
281
- var serialize = (value, { json, lossy } = {}) => {
282
- const _ = [];
283
- return serializer(!(json || lossy), !!json, /* @__PURE__ */ new Map(), _)(value), _;
284
- };
285
- var esm_default = typeof structuredClone === "function" ? (
286
- /* c8 ignore start */
287
- (any, options) => options && ("json" in options || "lossy" in options) ? deserialize(serialize(any, options)) : structuredClone(any)
288
- ) : (any, options) => deserialize(serialize(any, options));
289
- var CacheData = class _CacheData {
290
- static IsDirty(data) {
291
- return data.dirty;
292
- }
293
- static SetDirty(data, value) {
294
- data.dirty = value;
295
- return data;
296
- }
297
- static StructuredClone = globalThis.structuredClone ?? esm_default;
298
- _raw;
299
- generator;
300
- dirty;
301
- constructor(generator) {
302
- this._raw = void 0;
303
- this.dirty = false;
304
- this.generator = generator;
305
- }
306
- /**
307
- * This is cached data.
308
- * It was generated at the time of caching, so there is a risk of modification if it's an object due to shallow copying.
309
- * Therefore, if it's not a primitive type, please avoid using this value directly and use the `clone` method to use a copied version of the data.
310
- */
311
- get raw() {
312
- if (!this.dirty) {
313
- throw new Error(`The data is not initialized and cannot be accessed. Please use the 'ensure' or 'set' method to create the data first.`);
314
- }
315
- return this._raw;
316
- }
317
- /**
318
- * The method returns a copied value of the cached data.
319
- * You can pass a function as a parameter to copy the value. This parameter function should return the copied value.
320
- *
321
- * If no parameter is passed, it defaults to using Javascript's or \@ungap/structured-clone's `structuredClone` function to copy the value.
322
- * If you prefer shallow copying instead of deep copying,
323
- * you can use the default options `array-shallow-copy`, `object-shallow-copy` and `deep-copy`,
324
- * which are replaced with functions to shallow copy arrays and objects, respectively. This is a syntactic sugar.
325
- * @param strategy The function that returns the copied value.
326
- * If you want to perform a shallow copy, simply pass the strings `array-shallow-copy` or `object-shallow-copy` for easy use.
327
- * The default is `structuredClone`.
328
- */
329
- clone(strategy = "deep-copy") {
330
- if (strategy && typeof strategy !== "string") {
331
- return strategy(this.raw);
332
- }
333
- switch (strategy) {
334
- case "array-shallow-copy":
335
- return [].concat(this.raw);
336
- case "object-shallow-copy":
337
- return Object.assign({}, this.raw);
338
- case "deep-copy":
339
- default:
340
- return _CacheData.StructuredClone(this.raw);
341
- }
342
- }
343
- };
344
- var CacheDataSync = class extends CacheData {
345
- static EmptyDataGenerator = () => void 0;
346
- static Update(branch, data, generator) {
347
- data._raw = generator(branch);
348
- data.generator = generator;
349
- data.dirty = true;
350
- return data;
351
- }
352
- static Cache(branch, data) {
353
- data._raw = data.generator(branch);
354
- return data;
355
- }
356
- };
357
- var CacheBranchSync = class _CacheBranchSync extends CacheBranch {
358
- root;
359
- constructor(generator = CacheDataSync.EmptyDataGenerator, root) {
360
- super(new CacheDataSync(generator));
361
- this.root = root ?? this;
362
- }
363
- ensureBranch(key, generator) {
364
- return this.to(key, (b, k) => {
365
- const branch = b;
366
- if (!branch.branches.has(k)) {
367
- branch.branches.set(k, new _CacheBranchSync(generator, this.root));
368
- }
369
- return branch.branches.get(k);
370
- });
371
- }
372
- getBranch(key) {
373
- return this.to(key, (b, k) => {
374
- const branch = b;
375
- if (!branch.branches.has(k)) {
376
- return null;
377
- }
378
- return branch.branches.get(k);
379
- });
380
- }
381
- cache(key, recursive) {
382
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
383
- if (!branch) {
384
- return this;
385
- }
386
- if (recursive === "bottom-up") {
387
- for (const key2 of branch.branches.keys()) {
388
- branch.cache(key2, recursive);
389
- }
390
- }
391
- CacheDataSync.Cache(this.root, branch.data);
392
- if (recursive === "top-down") {
393
- for (const key2 of branch.branches.keys()) {
394
- branch.cache(key2, recursive);
395
- }
396
- }
397
- return this;
398
- }
399
- ensure(key, generator) {
400
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
401
- if (!CacheDataSync.IsDirty(branch.data)) {
402
- CacheDataSync.Update(this.root, branch.data, generator);
403
- }
404
- return branch.data;
405
- }
406
- get(key) {
407
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
408
- if (!CacheDataSync.IsDirty(branch.data)) {
409
- return void 0;
410
- }
411
- return branch.data;
412
- }
413
- set(key, generator) {
414
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
415
- CacheDataSync.Update(this.root, branch.data, generator);
416
- return this;
417
- }
418
- delete(key) {
419
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
420
- if (branch) {
421
- branch.branches.clear();
422
- CacheDataSync.Update(this.root, branch.data, CacheDataSync.EmptyDataGenerator);
423
- CacheDataSync.SetDirty(branch.data, false);
424
- }
425
- return this;
426
- }
427
- };
428
-
429
64
  // src/utils/InvertedWeakMap.ts
430
65
  var InvertedWeakMap = class {
431
66
  _map;
@@ -480,10 +115,12 @@ var BPTree = class {
480
115
  like: (nv, v) => {
481
116
  const nodeValue = this.comparator.match(nv);
482
117
  const value = this.comparator.match(v);
483
- const regexp = this._cachedRegexp.ensure(value, () => {
118
+ if (!this._cachedRegexp.has(value)) {
484
119
  const pattern = value.replace(/%/g, ".*").replace(/_/g, ".");
485
- return new RegExp(`^${pattern}$`, "i");
486
- }).raw;
120
+ const regexp2 = new RegExp(`^${pattern}$`, "i");
121
+ this._cachedRegexp.set(value, regexp2);
122
+ }
123
+ const regexp = this._cachedRegexp.get(value);
487
124
  return regexp.test(nodeValue);
488
125
  }
489
126
  };
@@ -515,7 +152,7 @@ var BPTree = class {
515
152
  like: true
516
153
  };
517
154
  constructor(strategy, comparator) {
518
- this._cachedRegexp = new CacheBranchSync();
155
+ this._cachedRegexp = new InvertedWeakMap();
519
156
  this._nodeCreateBuffer = /* @__PURE__ */ new Map();
520
157
  this._nodeUpdateBuffer = /* @__PURE__ */ new Map();
521
158
  this._nodeDeleteBuffer = /* @__PURE__ */ new Map();
@@ -528,8 +165,8 @@ var BPTree = class {
528
165
  for (let i = 0, len = node.values.length; i < len; i++) {
529
166
  const nValue = node.values[i];
530
167
  if (this.comparator.isSame(value, nValue)) {
531
- const keys2 = node.keys[i];
532
- keys2.push(key);
168
+ const keys = node.keys[i];
169
+ keys.push(key);
533
170
  this.bufferForNodeUpdate(node);
534
171
  break;
535
172
  } else if (this.comparator.isLower(value, nValue)) {
@@ -583,12 +220,12 @@ var BPTreeSync = class extends BPTree {
583
220
  let i = node.values.length;
584
221
  while (i--) {
585
222
  const nValue = node.values[i];
586
- const keys2 = node.keys[i];
223
+ const keys = node.keys[i];
587
224
  if (comparator(nValue, value)) {
588
225
  found = true;
589
- let j = keys2.length;
226
+ let j = keys.length;
590
227
  while (j--) {
591
- pairs.push({ key: keys2[j], value: nValue });
228
+ pairs.push({ key: keys[j], value: nValue });
592
229
  }
593
230
  } else if (found && !fullScan) {
594
231
  done = true;
@@ -611,10 +248,10 @@ var BPTreeSync = class extends BPTree {
611
248
  while (!done) {
612
249
  for (let i = 0, len = node.values.length; i < len; i++) {
613
250
  const nValue = node.values[i];
614
- const keys2 = node.keys[i];
251
+ const keys = node.keys[i];
615
252
  if (comparator(nValue, value)) {
616
253
  found = true;
617
- for (const key of keys2) {
254
+ for (const key of keys) {
618
255
  pairs.push({ key, value: nValue });
619
256
  }
620
257
  } else if (found && !fullScan) {
@@ -647,11 +284,11 @@ var BPTreeSync = class extends BPTree {
647
284
  }
648
285
  return id;
649
286
  }
650
- _createNode(isLeaf, keys2, values, leaf = false, parent = null, next = null, prev = null) {
287
+ _createNode(isLeaf, keys, values, leaf = false, parent = null, next = null, prev = null) {
651
288
  const id = this._createNodeId(isLeaf);
652
289
  const node = {
653
290
  id,
654
- keys: keys2,
291
+ keys,
655
292
  values,
656
293
  leaf,
657
294
  parent,
@@ -681,9 +318,9 @@ var BPTreeSync = class extends BPTree {
681
318
  }
682
319
  }
683
320
  if (this.root === node && node.keys.length === 1) {
684
- const keys2 = node.keys;
321
+ const keys = node.keys;
685
322
  this.bufferForNodeDelete(this.root);
686
- this.root = this.getNode(keys2[0]);
323
+ this.root = this.getNode(keys[0]);
687
324
  this.root.parent = null;
688
325
  this.strategy.head.root = this.root.id;
689
326
  this.bufferForNodeUpdate(this.root);
@@ -757,8 +394,8 @@ var BPTreeSync = class extends BPTree {
757
394
  }
758
395
  pointer.values.push(...node.values);
759
396
  if (!pointer.leaf) {
760
- const keys2 = pointer.keys;
761
- for (const key2 of keys2) {
397
+ const keys = pointer.keys;
398
+ for (const key2 of keys) {
762
399
  const node2 = this.getNode(key2);
763
400
  node2.parent = pointer.id;
764
401
  this.bufferForNodeUpdate(node2);
@@ -958,8 +595,8 @@ var BPTreeSync = class extends BPTree {
958
595
  leftestNode() {
959
596
  let node = this.root;
960
597
  while (!node.leaf) {
961
- const keys2 = node.keys;
962
- node = this.getNode(keys2[0]);
598
+ const keys = node.keys;
599
+ node = this.getNode(keys[0]);
963
600
  }
964
601
  return node;
965
602
  }
@@ -1070,17 +707,17 @@ var BPTreeSync = class extends BPTree {
1070
707
  while (i--) {
1071
708
  const nValue = node.values[i];
1072
709
  if (this.comparator.isSame(value, nValue)) {
1073
- const keys2 = node.keys[i];
1074
- if (keys2.includes(key)) {
1075
- if (keys2.length > 1) {
1076
- keys2.splice(keys2.indexOf(key), 1);
710
+ const keys = node.keys[i];
711
+ if (keys.includes(key)) {
712
+ if (keys.length > 1) {
713
+ keys.splice(keys.indexOf(key), 1);
1077
714
  this.bufferForNodeUpdate(node);
1078
715
  } else if (node === this.root) {
1079
716
  node.values.splice(i, 1);
1080
717
  node.keys.splice(i, 1);
1081
718
  this.bufferForNodeUpdate(node);
1082
719
  } else {
1083
- keys2.splice(keys2.indexOf(key), 1);
720
+ keys.splice(keys.indexOf(key), 1);
1084
721
  node.keys.splice(i, 1);
1085
722
  node.values.splice(node.values.indexOf(value), 1);
1086
723
  this._deleteEntry(node, key, value);
@@ -1099,8 +736,8 @@ var BPTreeSync = class extends BPTree {
1099
736
  for (let i = 0, len = node.values.length; i < len; i++) {
1100
737
  const nValue = node.values[i];
1101
738
  if (this.comparator.isSame(value, nValue)) {
1102
- const keys2 = node.keys[i];
1103
- return keys2.includes(key);
739
+ const keys = node.keys[i];
740
+ return keys.includes(key);
1104
741
  }
1105
742
  }
1106
743
  return false;
@@ -1110,13 +747,13 @@ var BPTreeSync = class extends BPTree {
1110
747
  this.commitHeadBuffer();
1111
748
  }
1112
749
  forceUpdate() {
1113
- const keys2 = [...this.nodes.keys()];
750
+ const keys = [...this.nodes.keys()];
1114
751
  this.nodes.clear();
1115
752
  this.init();
1116
- for (const key of keys2) {
753
+ for (const key of keys) {
1117
754
  this.getNode(key);
1118
755
  }
1119
- return keys2.length;
756
+ return keys.length;
1120
757
  }
1121
758
  };
1122
759
 
@@ -1134,12 +771,12 @@ var BPTreeAsync = class extends BPTree {
1134
771
  let i = node.values.length;
1135
772
  while (i--) {
1136
773
  const nValue = node.values[i];
1137
- const keys2 = node.keys[i];
774
+ const keys = node.keys[i];
1138
775
  if (comparator(nValue, value)) {
1139
776
  found = true;
1140
- let j = keys2.length;
777
+ let j = keys.length;
1141
778
  while (j--) {
1142
- pairs.push({ key: keys2[j], value: nValue });
779
+ pairs.push({ key: keys[j], value: nValue });
1143
780
  }
1144
781
  } else if (found && !fullScan) {
1145
782
  done = true;
@@ -1162,10 +799,10 @@ var BPTreeAsync = class extends BPTree {
1162
799
  while (!done) {
1163
800
  for (let i = 0, len = node.values.length; i < len; i++) {
1164
801
  const nValue = node.values[i];
1165
- const keys2 = node.keys[i];
802
+ const keys = node.keys[i];
1166
803
  if (comparator(nValue, value)) {
1167
804
  found = true;
1168
- for (const key of keys2) {
805
+ for (const key of keys) {
1169
806
  pairs.push({ key, value: nValue });
1170
807
  }
1171
808
  } else if (found && !fullScan) {
@@ -1198,11 +835,11 @@ var BPTreeAsync = class extends BPTree {
1198
835
  }
1199
836
  return id;
1200
837
  }
1201
- async _createNode(isLeaf, keys2, values, leaf = false, parent = null, next = null, prev = null) {
838
+ async _createNode(isLeaf, keys, values, leaf = false, parent = null, next = null, prev = null) {
1202
839
  const id = await this._createNodeId(isLeaf);
1203
840
  const node = {
1204
841
  id,
1205
- keys: keys2,
842
+ keys,
1206
843
  values,
1207
844
  leaf,
1208
845
  parent,
@@ -1232,9 +869,9 @@ var BPTreeAsync = class extends BPTree {
1232
869
  }
1233
870
  }
1234
871
  if (this.root === node && node.keys.length === 1) {
1235
- const keys2 = node.keys;
872
+ const keys = node.keys;
1236
873
  this.bufferForNodeDelete(this.root);
1237
- this.root = await this.getNode(keys2[0]);
874
+ this.root = await this.getNode(keys[0]);
1238
875
  this.root.parent = null;
1239
876
  this.strategy.head.root = this.root.id;
1240
877
  this.bufferForNodeUpdate(this.root);
@@ -1308,8 +945,8 @@ var BPTreeAsync = class extends BPTree {
1308
945
  }
1309
946
  pointer.values.push(...node.values);
1310
947
  if (!pointer.leaf) {
1311
- const keys2 = pointer.keys;
1312
- for (const key2 of keys2) {
948
+ const keys = pointer.keys;
949
+ for (const key2 of keys) {
1313
950
  const node2 = await this.getNode(key2);
1314
951
  node2.parent = pointer.id;
1315
952
  this.bufferForNodeUpdate(node2);
@@ -1509,8 +1146,8 @@ var BPTreeAsync = class extends BPTree {
1509
1146
  async leftestNode() {
1510
1147
  let node = this.root;
1511
1148
  while (!node.leaf) {
1512
- const keys2 = node.keys;
1513
- node = await this.getNode(keys2[0]);
1149
+ const keys = node.keys;
1150
+ node = await this.getNode(keys[0]);
1514
1151
  }
1515
1152
  return node;
1516
1153
  }
@@ -1621,17 +1258,17 @@ var BPTreeAsync = class extends BPTree {
1621
1258
  while (i--) {
1622
1259
  const nValue = node.values[i];
1623
1260
  if (this.comparator.isSame(value, nValue)) {
1624
- const keys2 = node.keys[i];
1625
- if (keys2.includes(key)) {
1626
- if (keys2.length > 1) {
1627
- keys2.splice(keys2.indexOf(key), 1);
1261
+ const keys = node.keys[i];
1262
+ if (keys.includes(key)) {
1263
+ if (keys.length > 1) {
1264
+ keys.splice(keys.indexOf(key), 1);
1628
1265
  this.bufferForNodeUpdate(node);
1629
1266
  } else if (node === this.root) {
1630
1267
  node.values.splice(i, 1);
1631
1268
  node.keys.splice(i, 1);
1632
1269
  this.bufferForNodeUpdate(node);
1633
1270
  } else {
1634
- keys2.splice(keys2.indexOf(key), 1);
1271
+ keys.splice(keys.indexOf(key), 1);
1635
1272
  node.keys.splice(i, 1);
1636
1273
  node.values.splice(node.values.indexOf(value), 1);
1637
1274
  await this._deleteEntry(node, key, value);
@@ -1650,8 +1287,8 @@ var BPTreeAsync = class extends BPTree {
1650
1287
  for (let i = 0, len = node.values.length; i < len; i++) {
1651
1288
  const nValue = node.values[i];
1652
1289
  if (this.comparator.isSame(value, nValue)) {
1653
- const keys2 = node.keys[i];
1654
- return keys2.includes(key);
1290
+ const keys = node.keys[i];
1291
+ return keys.includes(key);
1655
1292
  }
1656
1293
  }
1657
1294
  return false;
@@ -1661,13 +1298,13 @@ var BPTreeAsync = class extends BPTree {
1661
1298
  await this.commitHeadBuffer();
1662
1299
  }
1663
1300
  async forceUpdate() {
1664
- const keys2 = [...this.nodes.keys()];
1301
+ const keys = [...this.nodes.keys()];
1665
1302
  this.nodes.clear();
1666
1303
  await this.init();
1667
- for (const key of keys2) {
1304
+ for (const key of keys) {
1668
1305
  await this.getNode(key);
1669
1306
  }
1670
- return keys2.length;
1307
+ return keys.length;
1671
1308
  }
1672
1309
  };
1673
1310
 
@@ -27,371 +27,6 @@ var StringComparator = class extends ValueComparator {
27
27
  }
28
28
  };
29
29
 
30
- // node_modules/cachebranch/dist/esm/index.mjs
31
- var CacheBranch = class {
32
- data;
33
- branches;
34
- constructor(data) {
35
- this.data = data;
36
- this.branches = /* @__PURE__ */ new Map();
37
- }
38
- /**
39
- * The method splits the provided key value into tokens and returns them as an array.
40
- * For instance, if you pass `'user/name/middle'` as the parameter, it will return `['user', 'name', 'middle']` as the split values.
41
- * @param key The key value to split.
42
- */
43
- tokens(key) {
44
- return key.split("/");
45
- }
46
- to(key, getNextBranch) {
47
- const tokens = this.tokens(key);
48
- let current = this;
49
- for (let i = 0, len = tokens.length; i < len; i++) {
50
- const last = i === len - 1;
51
- const key2 = tokens[i];
52
- const next = getNextBranch(current, key2, i, last);
53
- if (next === null) {
54
- return void 0;
55
- }
56
- current = next;
57
- }
58
- return current;
59
- }
60
- };
61
- var VOID = -1;
62
- var PRIMITIVE = 0;
63
- var ARRAY = 1;
64
- var OBJECT = 2;
65
- var DATE = 3;
66
- var REGEXP = 4;
67
- var MAP = 5;
68
- var SET = 6;
69
- var ERROR = 7;
70
- var BIGINT = 8;
71
- var env = typeof self === "object" ? self : globalThis;
72
- var deserializer = ($, _) => {
73
- const as = (out, index) => {
74
- $.set(index, out);
75
- return out;
76
- };
77
- const unpair = (index) => {
78
- if ($.has(index))
79
- return $.get(index);
80
- const [type, value] = _[index];
81
- switch (type) {
82
- case PRIMITIVE:
83
- case VOID:
84
- return as(value, index);
85
- case ARRAY: {
86
- const arr = as([], index);
87
- for (const index2 of value)
88
- arr.push(unpair(index2));
89
- return arr;
90
- }
91
- case OBJECT: {
92
- const object = as({}, index);
93
- for (const [key, index2] of value)
94
- object[unpair(key)] = unpair(index2);
95
- return object;
96
- }
97
- case DATE:
98
- return as(new Date(value), index);
99
- case REGEXP: {
100
- const { source, flags } = value;
101
- return as(new RegExp(source, flags), index);
102
- }
103
- case MAP: {
104
- const map = as(/* @__PURE__ */ new Map(), index);
105
- for (const [key, index2] of value)
106
- map.set(unpair(key), unpair(index2));
107
- return map;
108
- }
109
- case SET: {
110
- const set = as(/* @__PURE__ */ new Set(), index);
111
- for (const index2 of value)
112
- set.add(unpair(index2));
113
- return set;
114
- }
115
- case ERROR: {
116
- const { name, message } = value;
117
- return as(new env[name](message), index);
118
- }
119
- case BIGINT:
120
- return as(BigInt(value), index);
121
- case "BigInt":
122
- return as(Object(BigInt(value)), index);
123
- }
124
- return as(new env[type](value), index);
125
- };
126
- return unpair;
127
- };
128
- var deserialize = (serialized) => deserializer(/* @__PURE__ */ new Map(), serialized)(0);
129
- var EMPTY = "";
130
- var { toString } = {};
131
- var { keys } = Object;
132
- var typeOf = (value) => {
133
- const type = typeof value;
134
- if (type !== "object" || !value)
135
- return [PRIMITIVE, type];
136
- const asString = toString.call(value).slice(8, -1);
137
- switch (asString) {
138
- case "Array":
139
- return [ARRAY, EMPTY];
140
- case "Object":
141
- return [OBJECT, EMPTY];
142
- case "Date":
143
- return [DATE, EMPTY];
144
- case "RegExp":
145
- return [REGEXP, EMPTY];
146
- case "Map":
147
- return [MAP, EMPTY];
148
- case "Set":
149
- return [SET, EMPTY];
150
- }
151
- if (asString.includes("Array"))
152
- return [ARRAY, asString];
153
- if (asString.includes("Error"))
154
- return [ERROR, asString];
155
- return [OBJECT, asString];
156
- };
157
- var shouldSkip = ([TYPE, type]) => TYPE === PRIMITIVE && (type === "function" || type === "symbol");
158
- var serializer = (strict, json, $, _) => {
159
- const as = (out, value) => {
160
- const index = _.push(out) - 1;
161
- $.set(value, index);
162
- return index;
163
- };
164
- const pair = (value) => {
165
- if ($.has(value))
166
- return $.get(value);
167
- let [TYPE, type] = typeOf(value);
168
- switch (TYPE) {
169
- case PRIMITIVE: {
170
- let entry = value;
171
- switch (type) {
172
- case "bigint":
173
- TYPE = BIGINT;
174
- entry = value.toString();
175
- break;
176
- case "function":
177
- case "symbol":
178
- if (strict)
179
- throw new TypeError("unable to serialize " + type);
180
- entry = null;
181
- break;
182
- case "undefined":
183
- return as([VOID], value);
184
- }
185
- return as([TYPE, entry], value);
186
- }
187
- case ARRAY: {
188
- if (type)
189
- return as([type, [...value]], value);
190
- const arr = [];
191
- const index = as([TYPE, arr], value);
192
- for (const entry of value)
193
- arr.push(pair(entry));
194
- return index;
195
- }
196
- case OBJECT: {
197
- if (type) {
198
- switch (type) {
199
- case "BigInt":
200
- return as([type, value.toString()], value);
201
- case "Boolean":
202
- case "Number":
203
- case "String":
204
- return as([type, value.valueOf()], value);
205
- }
206
- }
207
- if (json && "toJSON" in value)
208
- return pair(value.toJSON());
209
- const entries = [];
210
- const index = as([TYPE, entries], value);
211
- for (const key of keys(value)) {
212
- if (strict || !shouldSkip(typeOf(value[key])))
213
- entries.push([pair(key), pair(value[key])]);
214
- }
215
- return index;
216
- }
217
- case DATE:
218
- return as([TYPE, value.toISOString()], value);
219
- case REGEXP: {
220
- const { source, flags } = value;
221
- return as([TYPE, { source, flags }], value);
222
- }
223
- case MAP: {
224
- const entries = [];
225
- const index = as([TYPE, entries], value);
226
- for (const [key, entry] of value) {
227
- if (strict || !(shouldSkip(typeOf(key)) || shouldSkip(typeOf(entry))))
228
- entries.push([pair(key), pair(entry)]);
229
- }
230
- return index;
231
- }
232
- case SET: {
233
- const entries = [];
234
- const index = as([TYPE, entries], value);
235
- for (const entry of value) {
236
- if (strict || !shouldSkip(typeOf(entry)))
237
- entries.push(pair(entry));
238
- }
239
- return index;
240
- }
241
- }
242
- const { message } = value;
243
- return as([TYPE, { name: type, message }], value);
244
- };
245
- return pair;
246
- };
247
- var serialize = (value, { json, lossy } = {}) => {
248
- const _ = [];
249
- return serializer(!(json || lossy), !!json, /* @__PURE__ */ new Map(), _)(value), _;
250
- };
251
- var esm_default = typeof structuredClone === "function" ? (
252
- /* c8 ignore start */
253
- (any, options) => options && ("json" in options || "lossy" in options) ? deserialize(serialize(any, options)) : structuredClone(any)
254
- ) : (any, options) => deserialize(serialize(any, options));
255
- var CacheData = class _CacheData {
256
- static IsDirty(data) {
257
- return data.dirty;
258
- }
259
- static SetDirty(data, value) {
260
- data.dirty = value;
261
- return data;
262
- }
263
- static StructuredClone = globalThis.structuredClone ?? esm_default;
264
- _raw;
265
- generator;
266
- dirty;
267
- constructor(generator) {
268
- this._raw = void 0;
269
- this.dirty = false;
270
- this.generator = generator;
271
- }
272
- /**
273
- * This is cached data.
274
- * It was generated at the time of caching, so there is a risk of modification if it's an object due to shallow copying.
275
- * Therefore, if it's not a primitive type, please avoid using this value directly and use the `clone` method to use a copied version of the data.
276
- */
277
- get raw() {
278
- if (!this.dirty) {
279
- throw new Error(`The data is not initialized and cannot be accessed. Please use the 'ensure' or 'set' method to create the data first.`);
280
- }
281
- return this._raw;
282
- }
283
- /**
284
- * The method returns a copied value of the cached data.
285
- * You can pass a function as a parameter to copy the value. This parameter function should return the copied value.
286
- *
287
- * If no parameter is passed, it defaults to using Javascript's or \@ungap/structured-clone's `structuredClone` function to copy the value.
288
- * If you prefer shallow copying instead of deep copying,
289
- * you can use the default options `array-shallow-copy`, `object-shallow-copy` and `deep-copy`,
290
- * which are replaced with functions to shallow copy arrays and objects, respectively. This is a syntactic sugar.
291
- * @param strategy The function that returns the copied value.
292
- * If you want to perform a shallow copy, simply pass the strings `array-shallow-copy` or `object-shallow-copy` for easy use.
293
- * The default is `structuredClone`.
294
- */
295
- clone(strategy = "deep-copy") {
296
- if (strategy && typeof strategy !== "string") {
297
- return strategy(this.raw);
298
- }
299
- switch (strategy) {
300
- case "array-shallow-copy":
301
- return [].concat(this.raw);
302
- case "object-shallow-copy":
303
- return Object.assign({}, this.raw);
304
- case "deep-copy":
305
- default:
306
- return _CacheData.StructuredClone(this.raw);
307
- }
308
- }
309
- };
310
- var CacheDataSync = class extends CacheData {
311
- static EmptyDataGenerator = () => void 0;
312
- static Update(branch, data, generator) {
313
- data._raw = generator(branch);
314
- data.generator = generator;
315
- data.dirty = true;
316
- return data;
317
- }
318
- static Cache(branch, data) {
319
- data._raw = data.generator(branch);
320
- return data;
321
- }
322
- };
323
- var CacheBranchSync = class _CacheBranchSync extends CacheBranch {
324
- root;
325
- constructor(generator = CacheDataSync.EmptyDataGenerator, root) {
326
- super(new CacheDataSync(generator));
327
- this.root = root ?? this;
328
- }
329
- ensureBranch(key, generator) {
330
- return this.to(key, (b, k) => {
331
- const branch = b;
332
- if (!branch.branches.has(k)) {
333
- branch.branches.set(k, new _CacheBranchSync(generator, this.root));
334
- }
335
- return branch.branches.get(k);
336
- });
337
- }
338
- getBranch(key) {
339
- return this.to(key, (b, k) => {
340
- const branch = b;
341
- if (!branch.branches.has(k)) {
342
- return null;
343
- }
344
- return branch.branches.get(k);
345
- });
346
- }
347
- cache(key, recursive) {
348
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
349
- if (!branch) {
350
- return this;
351
- }
352
- if (recursive === "bottom-up") {
353
- for (const key2 of branch.branches.keys()) {
354
- branch.cache(key2, recursive);
355
- }
356
- }
357
- CacheDataSync.Cache(this.root, branch.data);
358
- if (recursive === "top-down") {
359
- for (const key2 of branch.branches.keys()) {
360
- branch.cache(key2, recursive);
361
- }
362
- }
363
- return this;
364
- }
365
- ensure(key, generator) {
366
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
367
- if (!CacheDataSync.IsDirty(branch.data)) {
368
- CacheDataSync.Update(this.root, branch.data, generator);
369
- }
370
- return branch.data;
371
- }
372
- get(key) {
373
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
374
- if (!CacheDataSync.IsDirty(branch.data)) {
375
- return void 0;
376
- }
377
- return branch.data;
378
- }
379
- set(key, generator) {
380
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
381
- CacheDataSync.Update(this.root, branch.data, generator);
382
- return this;
383
- }
384
- delete(key) {
385
- const branch = this.ensureBranch(key, CacheDataSync.EmptyDataGenerator);
386
- if (branch) {
387
- branch.branches.clear();
388
- CacheDataSync.Update(this.root, branch.data, CacheDataSync.EmptyDataGenerator);
389
- CacheDataSync.SetDirty(branch.data, false);
390
- }
391
- return this;
392
- }
393
- };
394
-
395
30
  // src/utils/InvertedWeakMap.ts
396
31
  var InvertedWeakMap = class {
397
32
  _map;
@@ -446,10 +81,12 @@ var BPTree = class {
446
81
  like: (nv, v) => {
447
82
  const nodeValue = this.comparator.match(nv);
448
83
  const value = this.comparator.match(v);
449
- const regexp = this._cachedRegexp.ensure(value, () => {
84
+ if (!this._cachedRegexp.has(value)) {
450
85
  const pattern = value.replace(/%/g, ".*").replace(/_/g, ".");
451
- return new RegExp(`^${pattern}$`, "i");
452
- }).raw;
86
+ const regexp2 = new RegExp(`^${pattern}$`, "i");
87
+ this._cachedRegexp.set(value, regexp2);
88
+ }
89
+ const regexp = this._cachedRegexp.get(value);
453
90
  return regexp.test(nodeValue);
454
91
  }
455
92
  };
@@ -481,7 +118,7 @@ var BPTree = class {
481
118
  like: true
482
119
  };
483
120
  constructor(strategy, comparator) {
484
- this._cachedRegexp = new CacheBranchSync();
121
+ this._cachedRegexp = new InvertedWeakMap();
485
122
  this._nodeCreateBuffer = /* @__PURE__ */ new Map();
486
123
  this._nodeUpdateBuffer = /* @__PURE__ */ new Map();
487
124
  this._nodeDeleteBuffer = /* @__PURE__ */ new Map();
@@ -494,8 +131,8 @@ var BPTree = class {
494
131
  for (let i = 0, len = node.values.length; i < len; i++) {
495
132
  const nValue = node.values[i];
496
133
  if (this.comparator.isSame(value, nValue)) {
497
- const keys2 = node.keys[i];
498
- keys2.push(key);
134
+ const keys = node.keys[i];
135
+ keys.push(key);
499
136
  this.bufferForNodeUpdate(node);
500
137
  break;
501
138
  } else if (this.comparator.isLower(value, nValue)) {
@@ -549,12 +186,12 @@ var BPTreeSync = class extends BPTree {
549
186
  let i = node.values.length;
550
187
  while (i--) {
551
188
  const nValue = node.values[i];
552
- const keys2 = node.keys[i];
189
+ const keys = node.keys[i];
553
190
  if (comparator(nValue, value)) {
554
191
  found = true;
555
- let j = keys2.length;
192
+ let j = keys.length;
556
193
  while (j--) {
557
- pairs.push({ key: keys2[j], value: nValue });
194
+ pairs.push({ key: keys[j], value: nValue });
558
195
  }
559
196
  } else if (found && !fullScan) {
560
197
  done = true;
@@ -577,10 +214,10 @@ var BPTreeSync = class extends BPTree {
577
214
  while (!done) {
578
215
  for (let i = 0, len = node.values.length; i < len; i++) {
579
216
  const nValue = node.values[i];
580
- const keys2 = node.keys[i];
217
+ const keys = node.keys[i];
581
218
  if (comparator(nValue, value)) {
582
219
  found = true;
583
- for (const key of keys2) {
220
+ for (const key of keys) {
584
221
  pairs.push({ key, value: nValue });
585
222
  }
586
223
  } else if (found && !fullScan) {
@@ -613,11 +250,11 @@ var BPTreeSync = class extends BPTree {
613
250
  }
614
251
  return id;
615
252
  }
616
- _createNode(isLeaf, keys2, values, leaf = false, parent = null, next = null, prev = null) {
253
+ _createNode(isLeaf, keys, values, leaf = false, parent = null, next = null, prev = null) {
617
254
  const id = this._createNodeId(isLeaf);
618
255
  const node = {
619
256
  id,
620
- keys: keys2,
257
+ keys,
621
258
  values,
622
259
  leaf,
623
260
  parent,
@@ -647,9 +284,9 @@ var BPTreeSync = class extends BPTree {
647
284
  }
648
285
  }
649
286
  if (this.root === node && node.keys.length === 1) {
650
- const keys2 = node.keys;
287
+ const keys = node.keys;
651
288
  this.bufferForNodeDelete(this.root);
652
- this.root = this.getNode(keys2[0]);
289
+ this.root = this.getNode(keys[0]);
653
290
  this.root.parent = null;
654
291
  this.strategy.head.root = this.root.id;
655
292
  this.bufferForNodeUpdate(this.root);
@@ -723,8 +360,8 @@ var BPTreeSync = class extends BPTree {
723
360
  }
724
361
  pointer.values.push(...node.values);
725
362
  if (!pointer.leaf) {
726
- const keys2 = pointer.keys;
727
- for (const key2 of keys2) {
363
+ const keys = pointer.keys;
364
+ for (const key2 of keys) {
728
365
  const node2 = this.getNode(key2);
729
366
  node2.parent = pointer.id;
730
367
  this.bufferForNodeUpdate(node2);
@@ -924,8 +561,8 @@ var BPTreeSync = class extends BPTree {
924
561
  leftestNode() {
925
562
  let node = this.root;
926
563
  while (!node.leaf) {
927
- const keys2 = node.keys;
928
- node = this.getNode(keys2[0]);
564
+ const keys = node.keys;
565
+ node = this.getNode(keys[0]);
929
566
  }
930
567
  return node;
931
568
  }
@@ -1036,17 +673,17 @@ var BPTreeSync = class extends BPTree {
1036
673
  while (i--) {
1037
674
  const nValue = node.values[i];
1038
675
  if (this.comparator.isSame(value, nValue)) {
1039
- const keys2 = node.keys[i];
1040
- if (keys2.includes(key)) {
1041
- if (keys2.length > 1) {
1042
- keys2.splice(keys2.indexOf(key), 1);
676
+ const keys = node.keys[i];
677
+ if (keys.includes(key)) {
678
+ if (keys.length > 1) {
679
+ keys.splice(keys.indexOf(key), 1);
1043
680
  this.bufferForNodeUpdate(node);
1044
681
  } else if (node === this.root) {
1045
682
  node.values.splice(i, 1);
1046
683
  node.keys.splice(i, 1);
1047
684
  this.bufferForNodeUpdate(node);
1048
685
  } else {
1049
- keys2.splice(keys2.indexOf(key), 1);
686
+ keys.splice(keys.indexOf(key), 1);
1050
687
  node.keys.splice(i, 1);
1051
688
  node.values.splice(node.values.indexOf(value), 1);
1052
689
  this._deleteEntry(node, key, value);
@@ -1065,8 +702,8 @@ var BPTreeSync = class extends BPTree {
1065
702
  for (let i = 0, len = node.values.length; i < len; i++) {
1066
703
  const nValue = node.values[i];
1067
704
  if (this.comparator.isSame(value, nValue)) {
1068
- const keys2 = node.keys[i];
1069
- return keys2.includes(key);
705
+ const keys = node.keys[i];
706
+ return keys.includes(key);
1070
707
  }
1071
708
  }
1072
709
  return false;
@@ -1076,13 +713,13 @@ var BPTreeSync = class extends BPTree {
1076
713
  this.commitHeadBuffer();
1077
714
  }
1078
715
  forceUpdate() {
1079
- const keys2 = [...this.nodes.keys()];
716
+ const keys = [...this.nodes.keys()];
1080
717
  this.nodes.clear();
1081
718
  this.init();
1082
- for (const key of keys2) {
719
+ for (const key of keys) {
1083
720
  this.getNode(key);
1084
721
  }
1085
- return keys2.length;
722
+ return keys.length;
1086
723
  }
1087
724
  };
1088
725
 
@@ -1100,12 +737,12 @@ var BPTreeAsync = class extends BPTree {
1100
737
  let i = node.values.length;
1101
738
  while (i--) {
1102
739
  const nValue = node.values[i];
1103
- const keys2 = node.keys[i];
740
+ const keys = node.keys[i];
1104
741
  if (comparator(nValue, value)) {
1105
742
  found = true;
1106
- let j = keys2.length;
743
+ let j = keys.length;
1107
744
  while (j--) {
1108
- pairs.push({ key: keys2[j], value: nValue });
745
+ pairs.push({ key: keys[j], value: nValue });
1109
746
  }
1110
747
  } else if (found && !fullScan) {
1111
748
  done = true;
@@ -1128,10 +765,10 @@ var BPTreeAsync = class extends BPTree {
1128
765
  while (!done) {
1129
766
  for (let i = 0, len = node.values.length; i < len; i++) {
1130
767
  const nValue = node.values[i];
1131
- const keys2 = node.keys[i];
768
+ const keys = node.keys[i];
1132
769
  if (comparator(nValue, value)) {
1133
770
  found = true;
1134
- for (const key of keys2) {
771
+ for (const key of keys) {
1135
772
  pairs.push({ key, value: nValue });
1136
773
  }
1137
774
  } else if (found && !fullScan) {
@@ -1164,11 +801,11 @@ var BPTreeAsync = class extends BPTree {
1164
801
  }
1165
802
  return id;
1166
803
  }
1167
- async _createNode(isLeaf, keys2, values, leaf = false, parent = null, next = null, prev = null) {
804
+ async _createNode(isLeaf, keys, values, leaf = false, parent = null, next = null, prev = null) {
1168
805
  const id = await this._createNodeId(isLeaf);
1169
806
  const node = {
1170
807
  id,
1171
- keys: keys2,
808
+ keys,
1172
809
  values,
1173
810
  leaf,
1174
811
  parent,
@@ -1198,9 +835,9 @@ var BPTreeAsync = class extends BPTree {
1198
835
  }
1199
836
  }
1200
837
  if (this.root === node && node.keys.length === 1) {
1201
- const keys2 = node.keys;
838
+ const keys = node.keys;
1202
839
  this.bufferForNodeDelete(this.root);
1203
- this.root = await this.getNode(keys2[0]);
840
+ this.root = await this.getNode(keys[0]);
1204
841
  this.root.parent = null;
1205
842
  this.strategy.head.root = this.root.id;
1206
843
  this.bufferForNodeUpdate(this.root);
@@ -1274,8 +911,8 @@ var BPTreeAsync = class extends BPTree {
1274
911
  }
1275
912
  pointer.values.push(...node.values);
1276
913
  if (!pointer.leaf) {
1277
- const keys2 = pointer.keys;
1278
- for (const key2 of keys2) {
914
+ const keys = pointer.keys;
915
+ for (const key2 of keys) {
1279
916
  const node2 = await this.getNode(key2);
1280
917
  node2.parent = pointer.id;
1281
918
  this.bufferForNodeUpdate(node2);
@@ -1475,8 +1112,8 @@ var BPTreeAsync = class extends BPTree {
1475
1112
  async leftestNode() {
1476
1113
  let node = this.root;
1477
1114
  while (!node.leaf) {
1478
- const keys2 = node.keys;
1479
- node = await this.getNode(keys2[0]);
1115
+ const keys = node.keys;
1116
+ node = await this.getNode(keys[0]);
1480
1117
  }
1481
1118
  return node;
1482
1119
  }
@@ -1587,17 +1224,17 @@ var BPTreeAsync = class extends BPTree {
1587
1224
  while (i--) {
1588
1225
  const nValue = node.values[i];
1589
1226
  if (this.comparator.isSame(value, nValue)) {
1590
- const keys2 = node.keys[i];
1591
- if (keys2.includes(key)) {
1592
- if (keys2.length > 1) {
1593
- keys2.splice(keys2.indexOf(key), 1);
1227
+ const keys = node.keys[i];
1228
+ if (keys.includes(key)) {
1229
+ if (keys.length > 1) {
1230
+ keys.splice(keys.indexOf(key), 1);
1594
1231
  this.bufferForNodeUpdate(node);
1595
1232
  } else if (node === this.root) {
1596
1233
  node.values.splice(i, 1);
1597
1234
  node.keys.splice(i, 1);
1598
1235
  this.bufferForNodeUpdate(node);
1599
1236
  } else {
1600
- keys2.splice(keys2.indexOf(key), 1);
1237
+ keys.splice(keys.indexOf(key), 1);
1601
1238
  node.keys.splice(i, 1);
1602
1239
  node.values.splice(node.values.indexOf(value), 1);
1603
1240
  await this._deleteEntry(node, key, value);
@@ -1616,8 +1253,8 @@ var BPTreeAsync = class extends BPTree {
1616
1253
  for (let i = 0, len = node.values.length; i < len; i++) {
1617
1254
  const nValue = node.values[i];
1618
1255
  if (this.comparator.isSame(value, nValue)) {
1619
- const keys2 = node.keys[i];
1620
- return keys2.includes(key);
1256
+ const keys = node.keys[i];
1257
+ return keys.includes(key);
1621
1258
  }
1622
1259
  }
1623
1260
  return false;
@@ -1627,13 +1264,13 @@ var BPTreeAsync = class extends BPTree {
1627
1264
  await this.commitHeadBuffer();
1628
1265
  }
1629
1266
  async forceUpdate() {
1630
- const keys2 = [...this.nodes.keys()];
1267
+ const keys = [...this.nodes.keys()];
1631
1268
  this.nodes.clear();
1632
1269
  await this.init();
1633
- for (const key of keys2) {
1270
+ for (const key of keys) {
1634
1271
  await this.getNode(key);
1635
1272
  }
1636
- return keys2.length;
1273
+ return keys.length;
1637
1274
  }
1638
1275
  };
1639
1276
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serializable-bptree",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "Store the B+tree flexibly, not only in-memory.",
5
5
  "main": "dist/cjs/index.cjs",
6
6
  "module": "dist/esm/index.mjs",
@@ -8,8 +8,7 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "import": "./dist/esm/index.mjs",
11
- "require": "./dist/cjs/index.cjs",
12
- "types": "./dist/typings/index.d.ts"
11
+ "require": "./dist/cjs/index.cjs"
13
12
  }
14
13
  },
15
14
  "files": [
@@ -36,13 +35,10 @@
36
35
  },
37
36
  "license": "MIT",
38
37
  "devDependencies": {
39
- "@types/jest": "^29.5.8",
40
- "esbuild": "^0.19.5",
38
+ "@types/jest": "^29.5.13",
39
+ "esbuild": "^0.23.1",
41
40
  "jest": "^29.7.0",
42
- "ts-jest": "^29.1.1",
43
- "typescript": "^5.2.2"
44
- },
45
- "dependencies": {
46
- "cachebranch": "^1.2.0"
41
+ "ts-jest": "^29.2.5",
42
+ "typescript": "^5.6.2"
47
43
  }
48
44
  }