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.rn.cjs
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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 (
|
|
2605
|
-
|
|
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
|
|
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
|
|
2736
|
+
return ObjectId.cacheHexString && __idCache.has(this);
|
|
2734
2737
|
}
|
|
2735
2738
|
inspect(depth, options, inspect) {
|
|
2736
2739
|
inspect ??= defaultInspect;
|