serializable-bptree 5.1.1 → 5.1.3

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.
@@ -292,6 +292,7 @@ var CacheEntanglement = class {
292
292
  caches;
293
293
  assignments;
294
294
  parameters;
295
+ dependencyProperties;
295
296
  constructor(creation, option) {
296
297
  option = option ?? {};
297
298
  const {
@@ -306,6 +307,7 @@ var CacheEntanglement = class {
306
307
  this.assignments = [];
307
308
  this.caches = new InvertedWeakMap({ lifespan: this.lifespan });
308
309
  this.dependencies = dependencies ?? {};
310
+ this.dependencyProperties = Object.keys(this.dependencies);
309
311
  this.parameters = {};
310
312
  for (const name in this.dependencies) {
311
313
  const dependency = this.dependencies[name];
@@ -356,13 +358,6 @@ var CacheEntanglement = class {
356
358
  }
357
359
  return this.caches.get(key);
358
360
  }
359
- /**
360
- * Deletes the cache value stored in the key within the instance.
361
- * @param key The key to delete.
362
- */
363
- delete(key) {
364
- this.caches.delete(key);
365
- }
366
361
  };
367
362
  var CacheData = class _CacheData {
368
363
  static StructuredClone = globalThis.structuredClone.bind(globalThis);
@@ -382,13 +377,16 @@ var CacheData = class _CacheData {
382
377
  * The method returns a copied value of the cached data.
383
378
  * You can pass a function as a parameter to copy the value. This parameter function should return the copied value.
384
379
  *
385
- * If no parameter is passed, it defaults to using Javascript's or \@ungap/structured-clone's `structuredClone` function to copy the value.
380
+ * If no parameter is passed, it defaults to using `structuredClone` function to copy the value.
386
381
  * If you prefer shallow copying instead of deep copying,
387
382
  * you can use the default options `array-shallow-copy`, `object-shallow-copy` and `deep-copy`,
388
383
  * which are replaced with functions to shallow copy arrays and objects, respectively. This is a syntactic sugar.
389
384
  * @param strategy The function that returns the copied value.
390
- * If you want to perform a shallow copy, simply pass the strings `array-shallow-copy` or `object-shallow-copy` for easy use.
391
- * The default is `structuredClone`.
385
+ * If you want to perform a shallow copy, simply pass the strings `array-shallow-copy` or `object-shallow-copy` for easy use.
386
+ * The `array-shallow-copy` strategy performs a shallow copy of an array.
387
+ * The `object-shallow-copy` strategy performs a shallow copy of an object.
388
+ * The `deep-copy` strategy performs a deep copy of the value using `structuredClone`.
389
+ * The default is `deep-copy`.
392
390
  */
393
391
  clone(strategy = "deep-copy") {
394
392
  if (strategy && typeof strategy !== "string") {
@@ -413,10 +411,11 @@ var CacheEntanglementSync = class extends CacheEntanglement {
413
411
  const resolved = {};
414
412
  const dependencyKey = this.dependencyKey(key);
415
413
  this.beforeUpdateHook(key, dependencyKey, ...parameter);
416
- for (const name in this.dependencies) {
414
+ for (let i = 0, len = this.dependencyProperties.length; i < len; i++) {
415
+ const name = this.dependencyProperties[i];
417
416
  const dependency = this.dependencies[name];
418
417
  if (!dependency.caches.has(key) && !dependency.caches.has(dependencyKey)) {
419
- throw new Error(`The key '${key}' or '${dependencyKey}' has not been assigned yet in dependency '${name}'.`, {
418
+ throw new Error(`The key '${key}' or '${dependencyKey}' has not been assigned yet in dependency '${name.toString()}'.`, {
420
419
  cause: {
421
420
  from: this
422
421
  }
@@ -432,7 +431,7 @@ var CacheEntanglementSync = class extends CacheEntanglement {
432
431
  }
433
432
  cache(key, ...parameter) {
434
433
  if (!this.caches.has(key)) {
435
- this.resolve(key, ...parameter);
434
+ this.update(key, ...parameter);
436
435
  } else {
437
436
  this.caches.extendExpire(key);
438
437
  }
@@ -440,7 +439,8 @@ var CacheEntanglementSync = class extends CacheEntanglement {
440
439
  }
441
440
  update(key, ...parameter) {
442
441
  this.resolve(key, ...parameter);
443
- for (const t of this.assignments) {
442
+ for (let i = 0, len = this.assignments.length; i < len; i++) {
443
+ const t = this.assignments[i];
444
444
  const instance = t;
445
445
  for (const cacheKey of instance.caches.keys()) {
446
446
  if (cacheKey === key || cacheKey.startsWith(`${key}/`)) {
@@ -450,6 +450,18 @@ var CacheEntanglementSync = class extends CacheEntanglement {
450
450
  }
451
451
  return this.caches.get(key);
452
452
  }
453
+ delete(key) {
454
+ this.caches.delete(key);
455
+ for (let i = 0, len = this.assignments.length; i < len; i++) {
456
+ const t = this.assignments[i];
457
+ const instance = t;
458
+ for (const cacheKey of instance.caches.keys()) {
459
+ if (cacheKey === key || cacheKey.startsWith(`${key}/`)) {
460
+ instance.delete(cacheKey);
461
+ }
462
+ }
463
+ }
464
+ }
453
465
  };
454
466
  var CacheEntanglementAsync = class extends CacheEntanglement {
455
467
  constructor(creation, option) {
@@ -459,10 +471,11 @@ var CacheEntanglementAsync = class extends CacheEntanglement {
459
471
  const resolved = {};
460
472
  const dependencyKey = this.dependencyKey(key);
461
473
  await this.beforeUpdateHook(key, dependencyKey, ...parameter);
462
- for (const name in this.dependencies) {
474
+ for (let i = 0, len = this.dependencyProperties.length; i < len; i++) {
475
+ const name = this.dependencyProperties[i];
463
476
  const dependency = this.dependencies[name];
464
477
  if (!dependency.caches.has(key) && !dependency.caches.has(dependencyKey)) {
465
- throw new Error(`The key '${key}' or '${dependencyKey}' has not been assigned yet in dependency '${name}'.`, {
478
+ throw new Error(`The key '${key}' or '${dependencyKey}' has not been assigned yet in dependency '${name.toString()}'.`, {
466
479
  cause: {
467
480
  from: this
468
481
  }
@@ -478,7 +491,7 @@ var CacheEntanglementAsync = class extends CacheEntanglement {
478
491
  }
479
492
  async cache(key, ...parameter) {
480
493
  if (!this.caches.has(key)) {
481
- await this.resolve(key, ...parameter);
494
+ await this.update(key, ...parameter);
482
495
  } else {
483
496
  this.caches.extendExpire(key);
484
497
  }
@@ -486,7 +499,8 @@ var CacheEntanglementAsync = class extends CacheEntanglement {
486
499
  }
487
500
  async update(key, ...parameter) {
488
501
  await this.resolve(key, ...parameter);
489
- for (const t of this.assignments) {
502
+ for (let i = 0, len = this.assignments.length; i < len; i++) {
503
+ const t = this.assignments[i];
490
504
  const instance = t;
491
505
  for (const cacheKey of instance.caches.keys()) {
492
506
  if (cacheKey === key || cacheKey.startsWith(`${key}/`)) {
@@ -496,6 +510,18 @@ var CacheEntanglementAsync = class extends CacheEntanglement {
496
510
  }
497
511
  return this.caches.get(key);
498
512
  }
513
+ async delete(key) {
514
+ this.caches.delete(key);
515
+ for (let i = 0, len = this.assignments.length; i < len; i++) {
516
+ const t = this.assignments[i];
517
+ const instance = t;
518
+ for (const cacheKey of instance.caches.keys()) {
519
+ if (cacheKey === key || cacheKey.startsWith(`${key}/`)) {
520
+ await instance.delete(cacheKey);
521
+ }
522
+ }
523
+ }
524
+ }
499
525
  };
500
526
 
501
527
  // src/base/BPTree.ts
@@ -258,6 +258,7 @@ var CacheEntanglement = class {
258
258
  caches;
259
259
  assignments;
260
260
  parameters;
261
+ dependencyProperties;
261
262
  constructor(creation, option) {
262
263
  option = option ?? {};
263
264
  const {
@@ -272,6 +273,7 @@ var CacheEntanglement = class {
272
273
  this.assignments = [];
273
274
  this.caches = new InvertedWeakMap({ lifespan: this.lifespan });
274
275
  this.dependencies = dependencies ?? {};
276
+ this.dependencyProperties = Object.keys(this.dependencies);
275
277
  this.parameters = {};
276
278
  for (const name in this.dependencies) {
277
279
  const dependency = this.dependencies[name];
@@ -322,13 +324,6 @@ var CacheEntanglement = class {
322
324
  }
323
325
  return this.caches.get(key);
324
326
  }
325
- /**
326
- * Deletes the cache value stored in the key within the instance.
327
- * @param key The key to delete.
328
- */
329
- delete(key) {
330
- this.caches.delete(key);
331
- }
332
327
  };
333
328
  var CacheData = class _CacheData {
334
329
  static StructuredClone = globalThis.structuredClone.bind(globalThis);
@@ -348,13 +343,16 @@ var CacheData = class _CacheData {
348
343
  * The method returns a copied value of the cached data.
349
344
  * You can pass a function as a parameter to copy the value. This parameter function should return the copied value.
350
345
  *
351
- * If no parameter is passed, it defaults to using Javascript's or \@ungap/structured-clone's `structuredClone` function to copy the value.
346
+ * If no parameter is passed, it defaults to using `structuredClone` function to copy the value.
352
347
  * If you prefer shallow copying instead of deep copying,
353
348
  * you can use the default options `array-shallow-copy`, `object-shallow-copy` and `deep-copy`,
354
349
  * which are replaced with functions to shallow copy arrays and objects, respectively. This is a syntactic sugar.
355
350
  * @param strategy The function that returns the copied value.
356
- * If you want to perform a shallow copy, simply pass the strings `array-shallow-copy` or `object-shallow-copy` for easy use.
357
- * The default is `structuredClone`.
351
+ * If you want to perform a shallow copy, simply pass the strings `array-shallow-copy` or `object-shallow-copy` for easy use.
352
+ * The `array-shallow-copy` strategy performs a shallow copy of an array.
353
+ * The `object-shallow-copy` strategy performs a shallow copy of an object.
354
+ * The `deep-copy` strategy performs a deep copy of the value using `structuredClone`.
355
+ * The default is `deep-copy`.
358
356
  */
359
357
  clone(strategy = "deep-copy") {
360
358
  if (strategy && typeof strategy !== "string") {
@@ -379,10 +377,11 @@ var CacheEntanglementSync = class extends CacheEntanglement {
379
377
  const resolved = {};
380
378
  const dependencyKey = this.dependencyKey(key);
381
379
  this.beforeUpdateHook(key, dependencyKey, ...parameter);
382
- for (const name in this.dependencies) {
380
+ for (let i = 0, len = this.dependencyProperties.length; i < len; i++) {
381
+ const name = this.dependencyProperties[i];
383
382
  const dependency = this.dependencies[name];
384
383
  if (!dependency.caches.has(key) && !dependency.caches.has(dependencyKey)) {
385
- throw new Error(`The key '${key}' or '${dependencyKey}' has not been assigned yet in dependency '${name}'.`, {
384
+ throw new Error(`The key '${key}' or '${dependencyKey}' has not been assigned yet in dependency '${name.toString()}'.`, {
386
385
  cause: {
387
386
  from: this
388
387
  }
@@ -398,7 +397,7 @@ var CacheEntanglementSync = class extends CacheEntanglement {
398
397
  }
399
398
  cache(key, ...parameter) {
400
399
  if (!this.caches.has(key)) {
401
- this.resolve(key, ...parameter);
400
+ this.update(key, ...parameter);
402
401
  } else {
403
402
  this.caches.extendExpire(key);
404
403
  }
@@ -406,7 +405,8 @@ var CacheEntanglementSync = class extends CacheEntanglement {
406
405
  }
407
406
  update(key, ...parameter) {
408
407
  this.resolve(key, ...parameter);
409
- for (const t of this.assignments) {
408
+ for (let i = 0, len = this.assignments.length; i < len; i++) {
409
+ const t = this.assignments[i];
410
410
  const instance = t;
411
411
  for (const cacheKey of instance.caches.keys()) {
412
412
  if (cacheKey === key || cacheKey.startsWith(`${key}/`)) {
@@ -416,6 +416,18 @@ var CacheEntanglementSync = class extends CacheEntanglement {
416
416
  }
417
417
  return this.caches.get(key);
418
418
  }
419
+ delete(key) {
420
+ this.caches.delete(key);
421
+ for (let i = 0, len = this.assignments.length; i < len; i++) {
422
+ const t = this.assignments[i];
423
+ const instance = t;
424
+ for (const cacheKey of instance.caches.keys()) {
425
+ if (cacheKey === key || cacheKey.startsWith(`${key}/`)) {
426
+ instance.delete(cacheKey);
427
+ }
428
+ }
429
+ }
430
+ }
419
431
  };
420
432
  var CacheEntanglementAsync = class extends CacheEntanglement {
421
433
  constructor(creation, option) {
@@ -425,10 +437,11 @@ var CacheEntanglementAsync = class extends CacheEntanglement {
425
437
  const resolved = {};
426
438
  const dependencyKey = this.dependencyKey(key);
427
439
  await this.beforeUpdateHook(key, dependencyKey, ...parameter);
428
- for (const name in this.dependencies) {
440
+ for (let i = 0, len = this.dependencyProperties.length; i < len; i++) {
441
+ const name = this.dependencyProperties[i];
429
442
  const dependency = this.dependencies[name];
430
443
  if (!dependency.caches.has(key) && !dependency.caches.has(dependencyKey)) {
431
- throw new Error(`The key '${key}' or '${dependencyKey}' has not been assigned yet in dependency '${name}'.`, {
444
+ throw new Error(`The key '${key}' or '${dependencyKey}' has not been assigned yet in dependency '${name.toString()}'.`, {
432
445
  cause: {
433
446
  from: this
434
447
  }
@@ -444,7 +457,7 @@ var CacheEntanglementAsync = class extends CacheEntanglement {
444
457
  }
445
458
  async cache(key, ...parameter) {
446
459
  if (!this.caches.has(key)) {
447
- await this.resolve(key, ...parameter);
460
+ await this.update(key, ...parameter);
448
461
  } else {
449
462
  this.caches.extendExpire(key);
450
463
  }
@@ -452,7 +465,8 @@ var CacheEntanglementAsync = class extends CacheEntanglement {
452
465
  }
453
466
  async update(key, ...parameter) {
454
467
  await this.resolve(key, ...parameter);
455
- for (const t of this.assignments) {
468
+ for (let i = 0, len = this.assignments.length; i < len; i++) {
469
+ const t = this.assignments[i];
456
470
  const instance = t;
457
471
  for (const cacheKey of instance.caches.keys()) {
458
472
  if (cacheKey === key || cacheKey.startsWith(`${key}/`)) {
@@ -462,6 +476,18 @@ var CacheEntanglementAsync = class extends CacheEntanglement {
462
476
  }
463
477
  return this.caches.get(key);
464
478
  }
479
+ async delete(key) {
480
+ this.caches.delete(key);
481
+ for (let i = 0, len = this.assignments.length; i < len; i++) {
482
+ const t = this.assignments[i];
483
+ const instance = t;
484
+ for (const cacheKey of instance.caches.keys()) {
485
+ if (cacheKey === key || cacheKey.startsWith(`${key}/`)) {
486
+ await instance.delete(cacheKey);
487
+ }
488
+ }
489
+ }
490
+ }
465
491
  };
466
492
 
467
493
  // src/base/BPTree.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serializable-bptree",
3
- "version": "5.1.1",
3
+ "version": "5.1.3",
4
4
  "description": "Store the B+tree flexibly, not only in-memory.",
5
5
  "types": "./dist/types/index.d.ts",
6
6
  "main": "./dist/cjs/index.cjs",
@@ -16,10 +16,10 @@
16
16
  "dist/**/*"
17
17
  ],
18
18
  "scripts": {
19
- "test": "jest",
19
+ "test": "jest -t",
20
20
  "build": "node build/index.js && tsc"
21
21
  },
22
- "author": "izure1 <admin@izure.org>",
22
+ "author": "izure <admin@izure.org>",
23
23
  "keywords": [
24
24
  "serializable-bptree",
25
25
  "b-plus-tree",
@@ -37,12 +37,12 @@
37
37
  "license": "MIT",
38
38
  "devDependencies": {
39
39
  "@types/jest": "^29.5.14",
40
- "esbuild": "^0.25.4",
40
+ "esbuild": "^0.25.5",
41
41
  "jest": "^29.7.0",
42
42
  "ts-jest": "^29.3.4",
43
43
  "typescript": "^5.8.3"
44
44
  },
45
45
  "dependencies": {
46
- "cache-entanglement": "^1.5.2"
46
+ "cache-entanglement": "^1.5.5"
47
47
  }
48
48
  }