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/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "vendor"
15
15
  ],
16
16
  "types": "bson.d.ts",
17
- "version": "7.0.0-alpha",
17
+ "version": "7.0.0-alpha.2",
18
18
  "author": {
19
19
  "name": "The MongoDB NodeJS Team",
20
20
  "email": "dbx-node@mongodb.com"
@@ -57,7 +57,6 @@
57
57
  "tar": "^7.4.3",
58
58
  "ts-node": "^10.9.2",
59
59
  "tsd": "^0.33.0",
60
- "tslib": "^2.8.1",
61
60
  "typescript": "^5.8.3",
62
61
  "typescript-cached-transpile": "0.0.6",
63
62
  "uuid": "^11.1.0"
package/src/constants.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** @internal */
2
- export const BSON_MAJOR_VERSION = 6;
2
+ export const BSON_MAJOR_VERSION = 7;
3
3
 
4
4
  /** @internal */
5
5
  export const BSON_VERSION_SYMBOL = Symbol.for('@@mdb.bson.version');
package/src/objectid.ts CHANGED
@@ -7,6 +7,9 @@ import { NumberUtils } from './utils/number_utils';
7
7
  // Unique sequence for the current process (initialized on first use)
8
8
  let PROCESS_UNIQUE: Uint8Array | null = null;
9
9
 
10
+ /** ObjectId hexString cache @internal */
11
+ const __idCache = new WeakMap(); // TODO(NODE-6549): convert this to #__id private field when target updated to ES2022
12
+
10
13
  /** @public */
11
14
  export interface ObjectIdLike {
12
15
  id: string | Uint8Array;
@@ -32,20 +35,11 @@ export class ObjectId extends BSONValue {
32
35
  /** @internal */
33
36
  private static index = Math.floor(Math.random() * 0xffffff);
34
37
 
35
- static cacheHexString: boolean = false;
38
+ static cacheHexString: boolean;
36
39
 
37
40
  /** ObjectId Bytes @internal */
38
41
  private buffer!: Uint8Array;
39
42
 
40
- /**
41
- * If hex string caching is enabled, contains the cached hex string. Otherwise, is null.
42
- *
43
- * Note that #hexString is populated lazily, and as a result simply checking `this.#hexString != null` is
44
- * not sufficient to determine if caching is enabled. `ObjectId.prototype.isCached()` can be used to
45
- * determine if the hex string has been cached yet for an ObjectId.
46
- */
47
- #cachedHexString: string | null = null;
48
-
49
43
  /** To generate a new ObjectId, use ObjectId() with no argument. */
50
44
  constructor();
51
45
  /**
@@ -113,7 +107,7 @@ export class ObjectId extends BSONValue {
113
107
  this.buffer = ByteUtils.fromHex(workingId);
114
108
  // If we are caching the hex string
115
109
  if (ObjectId.cacheHexString) {
116
- this.#cachedHexString = workingId;
110
+ __idCache.set(this, workingId);
117
111
  }
118
112
  } else {
119
113
  throw new BSONError(
@@ -136,7 +130,7 @@ export class ObjectId extends BSONValue {
136
130
  set id(value: Uint8Array) {
137
131
  this.buffer = value;
138
132
  if (ObjectId.cacheHexString) {
139
- this.#cachedHexString = ByteUtils.toHex(value);
133
+ __idCache.set(this, ByteUtils.toHex(value));
140
134
  }
141
135
  }
142
136
 
@@ -165,12 +159,15 @@ export class ObjectId extends BSONValue {
165
159
 
166
160
  /** Returns the ObjectId id as a 24 lowercase character hex string representation */
167
161
  toHexString(): string {
168
- if (this.#cachedHexString) return this.#cachedHexString.toLowerCase();
162
+ if (ObjectId.cacheHexString) {
163
+ const __id = __idCache.get(this);
164
+ if (__id) return __id;
165
+ }
169
166
 
170
167
  const hexString = ByteUtils.toHex(this.id);
171
168
 
172
169
  if (ObjectId.cacheHexString) {
173
- this.#cachedHexString = hexString;
170
+ __idCache.set(this, hexString);
174
171
  }
175
172
 
176
173
  return hexString;
@@ -368,13 +365,9 @@ export class ObjectId extends BSONValue {
368
365
  return new ObjectId(doc.$oid);
369
366
  }
370
367
 
371
- /**
372
- * @internal
373
- *
374
- * used for testing
375
- */
368
+ /** @internal */
376
369
  private isCached(): boolean {
377
- return ObjectId.cacheHexString && this.#cachedHexString != null;
370
+ return ObjectId.cacheHexString && __idCache.has(this);
378
371
  }
379
372
 
380
373
  /**