bson 7.0.0-alpha.1 → 7.0.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/lib/bson.cjs CHANGED
@@ -2523,14 +2523,14 @@ class MinKey extends BSONValue {
2523
2523
  }
2524
2524
 
2525
2525
  let PROCESS_UNIQUE = null;
2526
+ const __idCache = new WeakMap();
2526
2527
  class ObjectId extends BSONValue {
2527
2528
  get _bsontype() {
2528
2529
  return 'ObjectId';
2529
2530
  }
2530
2531
  static index = Math.floor(Math.random() * 0xffffff);
2531
- static cacheHexString = false;
2532
+ static cacheHexString;
2532
2533
  buffer;
2533
- #cachedHexString = null;
2534
2534
  constructor(inputId) {
2535
2535
  super();
2536
2536
  let workingId;
@@ -2558,7 +2558,7 @@ class ObjectId extends BSONValue {
2558
2558
  if (ObjectId.validateHexString(workingId)) {
2559
2559
  this.buffer = ByteUtils.fromHex(workingId);
2560
2560
  if (ObjectId.cacheHexString) {
2561
- this.#cachedHexString = workingId;
2561
+ __idCache.set(this, workingId);
2562
2562
  }
2563
2563
  }
2564
2564
  else {
@@ -2575,7 +2575,7 @@ class ObjectId extends BSONValue {
2575
2575
  set id(value) {
2576
2576
  this.buffer = value;
2577
2577
  if (ObjectId.cacheHexString) {
2578
- this.#cachedHexString = ByteUtils.toHex(value);
2578
+ __idCache.set(this, ByteUtils.toHex(value));
2579
2579
  }
2580
2580
  }
2581
2581
  static validateHexString(string) {
@@ -2593,11 +2593,14 @@ class ObjectId extends BSONValue {
2593
2593
  return true;
2594
2594
  }
2595
2595
  toHexString() {
2596
- if (this.#cachedHexString)
2597
- return this.#cachedHexString.toLowerCase();
2596
+ if (ObjectId.cacheHexString) {
2597
+ const __id = __idCache.get(this);
2598
+ if (__id)
2599
+ return __id;
2600
+ }
2598
2601
  const hexString = ByteUtils.toHex(this.id);
2599
2602
  if (ObjectId.cacheHexString) {
2600
- this.#cachedHexString = hexString;
2603
+ __idCache.set(this, hexString);
2601
2604
  }
2602
2605
  return hexString;
2603
2606
  }
@@ -2722,7 +2725,7 @@ class ObjectId extends BSONValue {
2722
2725
  return new ObjectId(doc.$oid);
2723
2726
  }
2724
2727
  isCached() {
2725
- return ObjectId.cacheHexString && this.#cachedHexString != null;
2728
+ return ObjectId.cacheHexString && __idCache.has(this);
2726
2729
  }
2727
2730
  inspect(depth, options, inspect) {
2728
2731
  inspect ??= defaultInspect;