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/bson.d.ts CHANGED
@@ -1353,7 +1353,6 @@ declare const NumberUtils: NumberUtils;
1353
1353
  * @category BSONType
1354
1354
  */
1355
1355
  export declare class ObjectId extends BSONValue {
1356
- #private;
1357
1356
  get _bsontype(): 'ObjectId';
1358
1357
  /* Excluded from this release type: index */
1359
1358
  static cacheHexString: boolean;
@@ -48,7 +48,7 @@ function getStylizeFunction(options) {
48
48
  }
49
49
  }
50
50
 
51
- const BSON_MAJOR_VERSION = 6;
51
+ const BSON_MAJOR_VERSION = 7;
52
52
  const BSON_VERSION_SYMBOL = Symbol.for('@@mdb.bson.version');
53
53
  const BSON_INT32_MAX = 0x7fffffff;
54
54
  const BSON_INT32_MIN = -2147483648;
@@ -2524,14 +2524,14 @@ class MinKey extends BSONValue {
2524
2524
  }
2525
2525
 
2526
2526
  let PROCESS_UNIQUE = null;
2527
+ const __idCache = new WeakMap();
2527
2528
  class ObjectId extends BSONValue {
2528
2529
  get _bsontype() {
2529
2530
  return 'ObjectId';
2530
2531
  }
2531
2532
  static index = Math.floor(Math.random() * 0xffffff);
2532
- static cacheHexString = false;
2533
+ static cacheHexString;
2533
2534
  buffer;
2534
- #cachedHexString = null;
2535
2535
  constructor(inputId) {
2536
2536
  super();
2537
2537
  let workingId;
@@ -2559,7 +2559,7 @@ class ObjectId extends BSONValue {
2559
2559
  if (ObjectId.validateHexString(workingId)) {
2560
2560
  this.buffer = ByteUtils.fromHex(workingId);
2561
2561
  if (ObjectId.cacheHexString) {
2562
- this.#cachedHexString = workingId;
2562
+ __idCache.set(this, workingId);
2563
2563
  }
2564
2564
  }
2565
2565
  else {
@@ -2576,7 +2576,7 @@ class ObjectId extends BSONValue {
2576
2576
  set id(value) {
2577
2577
  this.buffer = value;
2578
2578
  if (ObjectId.cacheHexString) {
2579
- this.#cachedHexString = ByteUtils.toHex(value);
2579
+ __idCache.set(this, ByteUtils.toHex(value));
2580
2580
  }
2581
2581
  }
2582
2582
  static validateHexString(string) {
@@ -2594,11 +2594,14 @@ class ObjectId extends BSONValue {
2594
2594
  return true;
2595
2595
  }
2596
2596
  toHexString() {
2597
- if (this.#cachedHexString)
2598
- return this.#cachedHexString.toLowerCase();
2597
+ if (ObjectId.cacheHexString) {
2598
+ const __id = __idCache.get(this);
2599
+ if (__id)
2600
+ return __id;
2601
+ }
2599
2602
  const hexString = ByteUtils.toHex(this.id);
2600
2603
  if (ObjectId.cacheHexString) {
2601
- this.#cachedHexString = hexString;
2604
+ __idCache.set(this, hexString);
2602
2605
  }
2603
2606
  return hexString;
2604
2607
  }
@@ -2723,7 +2726,7 @@ class ObjectId extends BSONValue {
2723
2726
  return new ObjectId(doc.$oid);
2724
2727
  }
2725
2728
  isCached() {
2726
- return ObjectId.cacheHexString && this.#cachedHexString != null;
2729
+ return ObjectId.cacheHexString && __idCache.has(this);
2727
2730
  }
2728
2731
  inspect(depth, options, inspect) {
2729
2732
  inspect ??= defaultInspect;