bson 6.10.0 → 6.10.1
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 +1 -1
- package/lib/bson.bundle.js +34 -43
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +34 -43
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +34 -43
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.rn.cjs +34 -51
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +1 -2
- package/src/objectid.ts +18 -11
- package/src/parser/utils.ts +30 -51
package/lib/bson.rn.cjs
CHANGED
|
@@ -1,53 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Uint8Array: '[object Uint8Array]',
|
|
8
|
-
BigInt64Array: '[object BigInt64Array]',
|
|
9
|
-
BigUint64Array: '[object BigUint64Array]',
|
|
10
|
-
RegExp: '[object RegExp]',
|
|
11
|
-
Map: '[object Map]',
|
|
12
|
-
Date: '[object Date]'
|
|
13
|
-
};
|
|
14
|
-
function getPrototypeString(value) {
|
|
15
|
-
let str = map.get(value);
|
|
16
|
-
if (!str) {
|
|
17
|
-
str = Object.prototype.toString.call(value);
|
|
18
|
-
if (value !== null && typeof value === 'object') {
|
|
19
|
-
map.set(value, str);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return str;
|
|
23
|
-
}
|
|
24
|
-
function isAnyArrayBuffer(value) {
|
|
25
|
-
const type = getPrototypeString(value);
|
|
26
|
-
return type === TYPES.ArrayBuffer || type === TYPES.SharedArrayBuffer;
|
|
27
|
-
}
|
|
3
|
+
const TypedArrayPrototypeGetSymbolToStringTag = (() => {
|
|
4
|
+
const g = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag).get;
|
|
5
|
+
return (value) => g.call(value);
|
|
6
|
+
})();
|
|
28
7
|
function isUint8Array(value) {
|
|
29
|
-
|
|
30
|
-
return type === TYPES.Uint8Array;
|
|
31
|
-
}
|
|
32
|
-
function isBigInt64Array(value) {
|
|
33
|
-
const type = getPrototypeString(value);
|
|
34
|
-
return type === TYPES.BigInt64Array;
|
|
8
|
+
return TypedArrayPrototypeGetSymbolToStringTag(value) === 'Uint8Array';
|
|
35
9
|
}
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
|
|
10
|
+
function isAnyArrayBuffer(value) {
|
|
11
|
+
return (typeof value === 'object' &&
|
|
12
|
+
value != null &&
|
|
13
|
+
Symbol.toStringTag in value &&
|
|
14
|
+
(value[Symbol.toStringTag] === 'ArrayBuffer' ||
|
|
15
|
+
value[Symbol.toStringTag] === 'SharedArrayBuffer'));
|
|
39
16
|
}
|
|
40
|
-
function isRegExp(
|
|
41
|
-
|
|
42
|
-
return type === TYPES.RegExp;
|
|
17
|
+
function isRegExp(regexp) {
|
|
18
|
+
return regexp instanceof RegExp || Object.prototype.toString.call(regexp) === '[object RegExp]';
|
|
43
19
|
}
|
|
44
|
-
function isMap(
|
|
45
|
-
|
|
46
|
-
|
|
20
|
+
function isMap(value) {
|
|
21
|
+
return (typeof value === 'object' &&
|
|
22
|
+
value != null &&
|
|
23
|
+
Symbol.toStringTag in value &&
|
|
24
|
+
value[Symbol.toStringTag] === 'Map');
|
|
47
25
|
}
|
|
48
|
-
function isDate(
|
|
49
|
-
|
|
50
|
-
return type === TYPES.Date;
|
|
26
|
+
function isDate(date) {
|
|
27
|
+
return date instanceof Date || Object.prototype.toString.call(date) === '[object Date]';
|
|
51
28
|
}
|
|
52
29
|
function defaultInspect(x, _options) {
|
|
53
30
|
return JSON.stringify(x, (k, v) => {
|
|
@@ -2512,6 +2489,7 @@ class MinKey extends BSONValue {
|
|
|
2512
2489
|
}
|
|
2513
2490
|
|
|
2514
2491
|
let PROCESS_UNIQUE = null;
|
|
2492
|
+
const __idCache = new WeakMap();
|
|
2515
2493
|
class ObjectId extends BSONValue {
|
|
2516
2494
|
get _bsontype() {
|
|
2517
2495
|
return 'ObjectId';
|
|
@@ -2542,6 +2520,9 @@ class ObjectId extends BSONValue {
|
|
|
2542
2520
|
else if (typeof workingId === 'string') {
|
|
2543
2521
|
if (ObjectId.validateHexString(workingId)) {
|
|
2544
2522
|
this.buffer = ByteUtils.fromHex(workingId);
|
|
2523
|
+
if (ObjectId.cacheHexString) {
|
|
2524
|
+
__idCache.set(this, workingId);
|
|
2525
|
+
}
|
|
2545
2526
|
}
|
|
2546
2527
|
else {
|
|
2547
2528
|
throw new BSONError('input must be a 24 character hex string, 12 byte Uint8Array, or an integer');
|
|
@@ -2550,9 +2531,6 @@ class ObjectId extends BSONValue {
|
|
|
2550
2531
|
else {
|
|
2551
2532
|
throw new BSONError('Argument passed in does not match the accepted types');
|
|
2552
2533
|
}
|
|
2553
|
-
if (ObjectId.cacheHexString) {
|
|
2554
|
-
this.__id = ByteUtils.toHex(this.id);
|
|
2555
|
-
}
|
|
2556
2534
|
}
|
|
2557
2535
|
get id() {
|
|
2558
2536
|
return this.buffer;
|
|
@@ -2560,7 +2538,7 @@ class ObjectId extends BSONValue {
|
|
|
2560
2538
|
set id(value) {
|
|
2561
2539
|
this.buffer = value;
|
|
2562
2540
|
if (ObjectId.cacheHexString) {
|
|
2563
|
-
this
|
|
2541
|
+
__idCache.set(this, ByteUtils.toHex(value));
|
|
2564
2542
|
}
|
|
2565
2543
|
}
|
|
2566
2544
|
static validateHexString(string) {
|
|
@@ -2578,12 +2556,14 @@ class ObjectId extends BSONValue {
|
|
|
2578
2556
|
return true;
|
|
2579
2557
|
}
|
|
2580
2558
|
toHexString() {
|
|
2581
|
-
if (ObjectId.cacheHexString
|
|
2582
|
-
|
|
2559
|
+
if (ObjectId.cacheHexString) {
|
|
2560
|
+
const __id = __idCache.get(this);
|
|
2561
|
+
if (__id)
|
|
2562
|
+
return __id;
|
|
2583
2563
|
}
|
|
2584
2564
|
const hexString = ByteUtils.toHex(this.id);
|
|
2585
|
-
if (ObjectId.cacheHexString
|
|
2586
|
-
this
|
|
2565
|
+
if (ObjectId.cacheHexString) {
|
|
2566
|
+
__idCache.set(this, hexString);
|
|
2587
2567
|
}
|
|
2588
2568
|
return hexString;
|
|
2589
2569
|
}
|
|
@@ -2707,6 +2687,9 @@ class ObjectId extends BSONValue {
|
|
|
2707
2687
|
static fromExtendedJSON(doc) {
|
|
2708
2688
|
return new ObjectId(doc.$oid);
|
|
2709
2689
|
}
|
|
2690
|
+
isCached() {
|
|
2691
|
+
return ObjectId.cacheHexString && __idCache.has(this);
|
|
2692
|
+
}
|
|
2710
2693
|
inspect(depth, options, inspect) {
|
|
2711
2694
|
inspect ??= defaultInspect;
|
|
2712
2695
|
return `new ObjectId(${inspect(this.toHexString(), options)})`;
|