bson 7.0.0-alpha → 7.0.0-alpha.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.
package/lib/bson.mjs CHANGED
@@ -45,7 +45,7 @@ function getStylizeFunction(options) {
45
45
  }
46
46
  }
47
47
 
48
- const BSON_MAJOR_VERSION = 6;
48
+ const BSON_MAJOR_VERSION = 7;
49
49
  const BSON_VERSION_SYMBOL = Symbol.for('@@mdb.bson.version');
50
50
  const BSON_INT32_MAX = 0x7fffffff;
51
51
  const BSON_INT32_MIN = -2147483648;
@@ -2521,14 +2521,14 @@ class MinKey extends BSONValue {
2521
2521
  }
2522
2522
 
2523
2523
  let PROCESS_UNIQUE = null;
2524
+ const __idCache = new WeakMap();
2524
2525
  class ObjectId extends BSONValue {
2525
2526
  get _bsontype() {
2526
2527
  return 'ObjectId';
2527
2528
  }
2528
2529
  static index = Math.floor(Math.random() * 0xffffff);
2529
- static cacheHexString = false;
2530
+ static cacheHexString;
2530
2531
  buffer;
2531
- #cachedHexString = null;
2532
2532
  constructor(inputId) {
2533
2533
  super();
2534
2534
  let workingId;
@@ -2556,7 +2556,7 @@ class ObjectId extends BSONValue {
2556
2556
  if (ObjectId.validateHexString(workingId)) {
2557
2557
  this.buffer = ByteUtils.fromHex(workingId);
2558
2558
  if (ObjectId.cacheHexString) {
2559
- this.#cachedHexString = workingId;
2559
+ __idCache.set(this, workingId);
2560
2560
  }
2561
2561
  }
2562
2562
  else {
@@ -2573,7 +2573,7 @@ class ObjectId extends BSONValue {
2573
2573
  set id(value) {
2574
2574
  this.buffer = value;
2575
2575
  if (ObjectId.cacheHexString) {
2576
- this.#cachedHexString = ByteUtils.toHex(value);
2576
+ __idCache.set(this, ByteUtils.toHex(value));
2577
2577
  }
2578
2578
  }
2579
2579
  static validateHexString(string) {
@@ -2591,11 +2591,14 @@ class ObjectId extends BSONValue {
2591
2591
  return true;
2592
2592
  }
2593
2593
  toHexString() {
2594
- if (this.#cachedHexString)
2595
- return this.#cachedHexString.toLowerCase();
2594
+ if (ObjectId.cacheHexString) {
2595
+ const __id = __idCache.get(this);
2596
+ if (__id)
2597
+ return __id;
2598
+ }
2596
2599
  const hexString = ByteUtils.toHex(this.id);
2597
2600
  if (ObjectId.cacheHexString) {
2598
- this.#cachedHexString = hexString;
2601
+ __idCache.set(this, hexString);
2599
2602
  }
2600
2603
  return hexString;
2601
2604
  }
@@ -2720,7 +2723,7 @@ class ObjectId extends BSONValue {
2720
2723
  return new ObjectId(doc.$oid);
2721
2724
  }
2722
2725
  isCached() {
2723
- return ObjectId.cacheHexString && this.#cachedHexString != null;
2726
+ return ObjectId.cacheHexString && __idCache.has(this);
2724
2727
  }
2725
2728
  inspect(depth, options, inspect) {
2726
2729
  inspect ??= defaultInspect;