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.rn.cjs CHANGED
@@ -47,7 +47,7 @@ function getStylizeFunction(options) {
47
47
  }
48
48
  }
49
49
 
50
- const BSON_MAJOR_VERSION = 6;
50
+ const BSON_MAJOR_VERSION = 7;
51
51
  const BSON_VERSION_SYMBOL = Symbol.for('@@mdb.bson.version');
52
52
  const BSON_INT32_MAX = 0x7fffffff;
53
53
  const BSON_INT32_MIN = -0x80000000;
@@ -2531,14 +2531,14 @@ class MinKey extends BSONValue {
2531
2531
  }
2532
2532
 
2533
2533
  let PROCESS_UNIQUE = null;
2534
+ const __idCache = new WeakMap();
2534
2535
  class ObjectId extends BSONValue {
2535
2536
  get _bsontype() {
2536
2537
  return 'ObjectId';
2537
2538
  }
2538
2539
  static index = Math.floor(Math.random() * 0xffffff);
2539
- static cacheHexString = false;
2540
+ static cacheHexString;
2540
2541
  buffer;
2541
- #cachedHexString = null;
2542
2542
  constructor(inputId) {
2543
2543
  super();
2544
2544
  let workingId;
@@ -2566,7 +2566,7 @@ class ObjectId extends BSONValue {
2566
2566
  if (ObjectId.validateHexString(workingId)) {
2567
2567
  this.buffer = ByteUtils.fromHex(workingId);
2568
2568
  if (ObjectId.cacheHexString) {
2569
- this.#cachedHexString = workingId;
2569
+ __idCache.set(this, workingId);
2570
2570
  }
2571
2571
  }
2572
2572
  else {
@@ -2583,7 +2583,7 @@ class ObjectId extends BSONValue {
2583
2583
  set id(value) {
2584
2584
  this.buffer = value;
2585
2585
  if (ObjectId.cacheHexString) {
2586
- this.#cachedHexString = ByteUtils.toHex(value);
2586
+ __idCache.set(this, ByteUtils.toHex(value));
2587
2587
  }
2588
2588
  }
2589
2589
  static validateHexString(string) {
@@ -2601,11 +2601,14 @@ class ObjectId extends BSONValue {
2601
2601
  return true;
2602
2602
  }
2603
2603
  toHexString() {
2604
- if (this.#cachedHexString)
2605
- return this.#cachedHexString.toLowerCase();
2604
+ if (ObjectId.cacheHexString) {
2605
+ const __id = __idCache.get(this);
2606
+ if (__id)
2607
+ return __id;
2608
+ }
2606
2609
  const hexString = ByteUtils.toHex(this.id);
2607
2610
  if (ObjectId.cacheHexString) {
2608
- this.#cachedHexString = hexString;
2611
+ __idCache.set(this, hexString);
2609
2612
  }
2610
2613
  return hexString;
2611
2614
  }
@@ -2730,7 +2733,7 @@ class ObjectId extends BSONValue {
2730
2733
  return new ObjectId(doc.$oid);
2731
2734
  }
2732
2735
  isCached() {
2733
- return ObjectId.cacheHexString && this.#cachedHexString != null;
2736
+ return ObjectId.cacheHexString && __idCache.has(this);
2734
2737
  }
2735
2738
  inspect(depth, options, inspect) {
2736
2739
  inspect ??= defaultInspect;