bson 7.0.0-alpha.1 → 7.0.0
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/README.md +7 -6
- package/bson.d.ts +0 -1
- package/lib/bson.bundle.js +11 -8
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +11 -8
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +11 -8
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.node.mjs +11 -8
- package/lib/bson.node.mjs.map +1 -1
- package/lib/bson.rn.cjs +11 -8
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +2 -3
- package/src/objectid.ts +13 -20
package/lib/bson.node.mjs
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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 (
|
|
2595
|
-
|
|
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
|
|
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
|
|
2726
|
+
return ObjectId.cacheHexString && __idCache.has(this);
|
|
2724
2727
|
}
|
|
2725
2728
|
inspect(depth, options, inspect) {
|
|
2726
2729
|
inspect ??= defaultInspect;
|