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 +0 -1
- package/lib/bson.bundle.js +12 -9
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +12 -9
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +12 -9
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.node.mjs +12 -9
- package/lib/bson.node.mjs.map +1 -1
- package/lib/bson.rn.cjs +12 -9
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +1 -2
- package/src/constants.ts +1 -1
- package/src/objectid.ts +13 -20
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
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
|
|
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
|
|
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
|
|
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 (
|
|
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
|
|
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
|
|
370
|
+
return ObjectId.cacheHexString && __idCache.has(this);
|
|
378
371
|
}
|
|
379
372
|
|
|
380
373
|
/**
|