bson 6.10.4 → 7.0.0-alpha
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 +11 -1
- package/bson.d.ts +21 -14
- package/lib/bson.bundle.js +83 -52
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +83 -52
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +88 -51
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.node.mjs +92 -53
- package/lib/bson.node.mjs.map +1 -1
- package/lib/bson.rn.cjs +82 -54
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +9 -10
- package/src/binary.ts +4 -1
- package/src/bson.ts +1 -1
- package/src/bson_value.ts +24 -1
- package/src/extended_json.ts +0 -3
- package/src/long.ts +4 -9
- package/src/objectid.ts +25 -25
- package/src/timestamp.ts +10 -1
- package/src/utils/node_byte_utils.ts +15 -22
- package/src/utils/number_utils.ts +4 -13
- package/vendor/base64/LICENSE-MIT.txt +0 -20
- package/vendor/base64/README.md +0 -112
- package/vendor/base64/base64.js +0 -157
- package/vendor/base64/package.json +0 -43
- package/vendor/text-encoding/LICENSE.md +0 -237
- package/vendor/text-encoding/README.md +0 -111
- package/vendor/text-encoding/index.js +0 -9
- package/vendor/text-encoding/lib/encoding-indexes.js +0 -47
- package/vendor/text-encoding/lib/encoding.js +0 -3301
- package/vendor/text-encoding/package.json +0 -37
package/README.md
CHANGED
|
@@ -230,7 +230,17 @@ try {
|
|
|
230
230
|
|
|
231
231
|
## React Native
|
|
232
232
|
|
|
233
|
-
|
|
233
|
+
js-bson requires the `atob`, `btoa` and `TextEncoder` globals. Older versions of React Native did not support these global objects, and so
|
|
234
|
+
[js-bson v5.4.0](https://github.com/mongodb/js-bson/releases/tag/v5.4.0) added support for bundled polyfills for these globals. Newer versions
|
|
235
|
+
of Hermes includes these globals, and so the polyfills for are no longer needed in the js-bson package.
|
|
236
|
+
|
|
237
|
+
If you find yourself on a version of React Native that does not have these globals, either:
|
|
238
|
+
|
|
239
|
+
1. polyfill them yourself
|
|
240
|
+
2. upgrade to a later version of hermes
|
|
241
|
+
3. use a version of js-bson `>=5.4.0` and `<7.0.0`
|
|
242
|
+
|
|
243
|
+
One additional polyfill, `crypto.getRandomValues` is recommended and can be installed with the following command:
|
|
234
244
|
|
|
235
245
|
```sh
|
|
236
246
|
npm install --save react-native-get-random-values
|
package/bson.d.ts
CHANGED
|
@@ -12,7 +12,10 @@ export declare class Binary extends BSONValue {
|
|
|
12
12
|
static readonly SUBTYPE_DEFAULT = 0;
|
|
13
13
|
/** Function BSON type */
|
|
14
14
|
static readonly SUBTYPE_FUNCTION = 1;
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Legacy default BSON Binary type
|
|
17
|
+
* @deprecated BSON Binary subtype 2 is deprecated in the BSON specification
|
|
18
|
+
*/
|
|
16
19
|
static readonly SUBTYPE_BYTE_ARRAY = 2;
|
|
17
20
|
/** Deprecated UUID BSON type @deprecated Please use SUBTYPE_UUID */
|
|
18
21
|
static readonly SUBTYPE_UUID_OLD = 3;
|
|
@@ -234,6 +237,8 @@ declare namespace BSON {
|
|
|
234
237
|
BSONRegExp,
|
|
235
238
|
Decimal128,
|
|
236
239
|
BSONValue,
|
|
240
|
+
bsonType,
|
|
241
|
+
BSONTypeTag,
|
|
237
242
|
BSONError,
|
|
238
243
|
BSONVersionError,
|
|
239
244
|
BSONRuntimeError,
|
|
@@ -408,10 +413,17 @@ export declare const BSONType: Readonly<{
|
|
|
408
413
|
/** @public */
|
|
409
414
|
export declare type BSONType = (typeof BSONType)[keyof typeof BSONType];
|
|
410
415
|
|
|
416
|
+
/** @public */
|
|
417
|
+
export declare const bsonType: unique symbol;
|
|
418
|
+
|
|
419
|
+
/** @public */
|
|
420
|
+
export declare type BSONTypeTag = 'BSONRegExp' | 'BSONSymbol' | 'ObjectId' | 'Binary' | 'Decimal128' | 'Double' | 'Int32' | 'Long' | 'MaxKey' | 'MinKey' | 'Timestamp' | 'Code' | 'DBRef';
|
|
421
|
+
|
|
411
422
|
/** @public */
|
|
412
423
|
export declare abstract class BSONValue {
|
|
413
424
|
/** @public */
|
|
414
|
-
abstract get _bsontype():
|
|
425
|
+
abstract get _bsontype(): BSONTypeTag;
|
|
426
|
+
get [bsonType](): this['_bsontype'];
|
|
415
427
|
/* Excluded from this release type: [BSON_VERSION_SYMBOL] */
|
|
416
428
|
/**
|
|
417
429
|
* @public
|
|
@@ -1341,17 +1353,13 @@ declare const NumberUtils: NumberUtils;
|
|
|
1341
1353
|
* @category BSONType
|
|
1342
1354
|
*/
|
|
1343
1355
|
export declare class ObjectId extends BSONValue {
|
|
1356
|
+
#private;
|
|
1344
1357
|
get _bsontype(): 'ObjectId';
|
|
1345
1358
|
/* Excluded from this release type: index */
|
|
1346
1359
|
static cacheHexString: boolean;
|
|
1347
1360
|
/* Excluded from this release type: buffer */
|
|
1348
|
-
/**
|
|
1349
|
-
|
|
1350
|
-
*
|
|
1351
|
-
* @param inputId - A number.
|
|
1352
|
-
* @deprecated Instead, use `static createFromTime()` to set a numeric value for the new ObjectId.
|
|
1353
|
-
*/
|
|
1354
|
-
constructor(inputId: number);
|
|
1361
|
+
/** To generate a new ObjectId, use ObjectId() with no argument. */
|
|
1362
|
+
constructor();
|
|
1355
1363
|
/**
|
|
1356
1364
|
* Create ObjectId from a 24 character hex string.
|
|
1357
1365
|
*
|
|
@@ -1376,14 +1384,12 @@ export declare class ObjectId extends BSONValue {
|
|
|
1376
1384
|
* @param inputId - A 12 byte binary Buffer.
|
|
1377
1385
|
*/
|
|
1378
1386
|
constructor(inputId: Uint8Array);
|
|
1379
|
-
/** To generate a new ObjectId, use ObjectId() with no argument. */
|
|
1380
|
-
constructor();
|
|
1381
1387
|
/**
|
|
1382
1388
|
* Implementation overload.
|
|
1383
1389
|
*
|
|
1384
1390
|
* @param inputId - All input types that are used in the constructor implementation.
|
|
1385
1391
|
*/
|
|
1386
|
-
constructor(inputId?: string |
|
|
1392
|
+
constructor(inputId?: string | ObjectId | ObjectIdLike | Uint8Array);
|
|
1387
1393
|
/**
|
|
1388
1394
|
* The ObjectId bytes
|
|
1389
1395
|
* @readonly
|
|
@@ -1436,7 +1442,7 @@ export declare class ObjectId extends BSONValue {
|
|
|
1436
1442
|
* Checks if a value can be used to create a valid bson ObjectId
|
|
1437
1443
|
* @param id - any JS value
|
|
1438
1444
|
*/
|
|
1439
|
-
static isValid(id: string |
|
|
1445
|
+
static isValid(id: string | ObjectId | ObjectIdLike | Uint8Array): boolean;
|
|
1440
1446
|
/* Excluded from this release type: toExtendedJSON */
|
|
1441
1447
|
/* Excluded from this release type: fromExtendedJSON */
|
|
1442
1448
|
/* Excluded from this release type: isCached */
|
|
@@ -1584,6 +1590,7 @@ declare function stringify(value: any, replacer?: (number | string)[] | ((this:
|
|
|
1584
1590
|
*/
|
|
1585
1591
|
export declare class Timestamp extends LongWithoutOverridesClass {
|
|
1586
1592
|
get _bsontype(): 'Timestamp';
|
|
1593
|
+
get [bsonType](): 'Timestamp';
|
|
1587
1594
|
static readonly MAX_VALUE: Long;
|
|
1588
1595
|
/**
|
|
1589
1596
|
* An incrementing ordinal for operations within a given second.
|
|
@@ -1643,7 +1650,7 @@ export declare interface TimestampExtended {
|
|
|
1643
1650
|
}
|
|
1644
1651
|
|
|
1645
1652
|
/** @public */
|
|
1646
|
-
export declare type TimestampOverrides = '_bsontype' | 'toExtendedJSON' | 'fromExtendedJSON' | 'inspect';
|
|
1653
|
+
export declare type TimestampOverrides = '_bsontype' | 'toExtendedJSON' | 'fromExtendedJSON' | 'inspect' | typeof bsonType;
|
|
1647
1654
|
|
|
1648
1655
|
/**
|
|
1649
1656
|
* A class representation of the BSON UUID type.
|
package/lib/bson.bundle.js
CHANGED
|
@@ -143,6 +143,7 @@ class BSONOffsetError extends BSONError {
|
|
|
143
143
|
get name() {
|
|
144
144
|
return 'BSONOffsetError';
|
|
145
145
|
}
|
|
146
|
+
offset;
|
|
146
147
|
constructor(message, offset, options) {
|
|
147
148
|
super(`${message}. offset: ${offset}`, options);
|
|
148
149
|
this.offset = offset;
|
|
@@ -219,11 +220,15 @@ function tryWriteBasicLatin(destination, source, offset) {
|
|
|
219
220
|
function nodejsMathRandomBytes(byteLength) {
|
|
220
221
|
return nodeJsByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
|
|
221
222
|
}
|
|
223
|
+
function nodejsSecureRandomBytes(byteLength) {
|
|
224
|
+
return crypto.getRandomValues(nodeJsByteUtils.allocate(byteLength));
|
|
225
|
+
}
|
|
222
226
|
const nodejsRandomBytes = (() => {
|
|
223
|
-
|
|
224
|
-
|
|
227
|
+
const { crypto } = globalThis;
|
|
228
|
+
if (crypto != null && typeof crypto.getRandomValues === 'function') {
|
|
229
|
+
return nodejsSecureRandomBytes;
|
|
225
230
|
}
|
|
226
|
-
|
|
231
|
+
else {
|
|
227
232
|
return nodejsMathRandomBytes;
|
|
228
233
|
}
|
|
229
234
|
})();
|
|
@@ -442,7 +447,11 @@ const webByteUtils = {
|
|
|
442
447
|
const hasGlobalBuffer = typeof Buffer === 'function' && Buffer.prototype?._isBuffer !== true;
|
|
443
448
|
const ByteUtils = hasGlobalBuffer ? nodeJsByteUtils : webByteUtils;
|
|
444
449
|
|
|
450
|
+
const bsonType = Symbol.for('@@mdb.bson.type');
|
|
445
451
|
class BSONValue {
|
|
452
|
+
get [bsonType]() {
|
|
453
|
+
return this._bsontype;
|
|
454
|
+
}
|
|
446
455
|
get [BSON_VERSION_SYMBOL]() {
|
|
447
456
|
return BSON_MAJOR_VERSION;
|
|
448
457
|
}
|
|
@@ -493,7 +502,7 @@ const NumberUtils = {
|
|
|
493
502
|
source[offset + 1] * 256 +
|
|
494
503
|
source[offset + 2] * 65536 +
|
|
495
504
|
source[offset + 3] * 16777216);
|
|
496
|
-
return (hi <<
|
|
505
|
+
return (hi << 32n) + lo;
|
|
497
506
|
},
|
|
498
507
|
getFloat64LE: isBigEndian
|
|
499
508
|
? (source, offset) => {
|
|
@@ -539,7 +548,7 @@ const NumberUtils = {
|
|
|
539
548
|
return 4;
|
|
540
549
|
},
|
|
541
550
|
setBigInt64LE(destination, offset, value) {
|
|
542
|
-
const mask32bits =
|
|
551
|
+
const mask32bits = 0xffffffffn;
|
|
543
552
|
let lo = Number(value & mask32bits);
|
|
544
553
|
destination[offset] = lo;
|
|
545
554
|
lo >>= 8;
|
|
@@ -548,7 +557,7 @@ const NumberUtils = {
|
|
|
548
557
|
destination[offset + 2] = lo;
|
|
549
558
|
lo >>= 8;
|
|
550
559
|
destination[offset + 3] = lo;
|
|
551
|
-
let hi = Number((value >>
|
|
560
|
+
let hi = Number((value >> 32n) & mask32bits);
|
|
552
561
|
destination[offset + 4] = hi;
|
|
553
562
|
hi >>= 8;
|
|
554
563
|
destination[offset + 5] = hi;
|
|
@@ -589,6 +598,27 @@ class Binary extends BSONValue {
|
|
|
589
598
|
get _bsontype() {
|
|
590
599
|
return 'Binary';
|
|
591
600
|
}
|
|
601
|
+
static BSON_BINARY_SUBTYPE_DEFAULT = 0;
|
|
602
|
+
static BUFFER_SIZE = 256;
|
|
603
|
+
static SUBTYPE_DEFAULT = 0;
|
|
604
|
+
static SUBTYPE_FUNCTION = 1;
|
|
605
|
+
static SUBTYPE_BYTE_ARRAY = 2;
|
|
606
|
+
static SUBTYPE_UUID_OLD = 3;
|
|
607
|
+
static SUBTYPE_UUID = 4;
|
|
608
|
+
static SUBTYPE_MD5 = 5;
|
|
609
|
+
static SUBTYPE_ENCRYPTED = 6;
|
|
610
|
+
static SUBTYPE_COLUMN = 7;
|
|
611
|
+
static SUBTYPE_SENSITIVE = 8;
|
|
612
|
+
static SUBTYPE_VECTOR = 9;
|
|
613
|
+
static SUBTYPE_USER_DEFINED = 128;
|
|
614
|
+
static VECTOR_TYPE = Object.freeze({
|
|
615
|
+
Int8: 0x03,
|
|
616
|
+
Float32: 0x27,
|
|
617
|
+
PackedBit: 0x10
|
|
618
|
+
});
|
|
619
|
+
buffer;
|
|
620
|
+
sub_type;
|
|
621
|
+
position;
|
|
592
622
|
constructor(buffer, subType) {
|
|
593
623
|
super();
|
|
594
624
|
if (!(buffer == null) &&
|
|
@@ -848,24 +878,6 @@ class Binary extends BSONValue {
|
|
|
848
878
|
return new this(bytes, Binary.SUBTYPE_VECTOR);
|
|
849
879
|
}
|
|
850
880
|
}
|
|
851
|
-
Binary.BSON_BINARY_SUBTYPE_DEFAULT = 0;
|
|
852
|
-
Binary.BUFFER_SIZE = 256;
|
|
853
|
-
Binary.SUBTYPE_DEFAULT = 0;
|
|
854
|
-
Binary.SUBTYPE_FUNCTION = 1;
|
|
855
|
-
Binary.SUBTYPE_BYTE_ARRAY = 2;
|
|
856
|
-
Binary.SUBTYPE_UUID_OLD = 3;
|
|
857
|
-
Binary.SUBTYPE_UUID = 4;
|
|
858
|
-
Binary.SUBTYPE_MD5 = 5;
|
|
859
|
-
Binary.SUBTYPE_ENCRYPTED = 6;
|
|
860
|
-
Binary.SUBTYPE_COLUMN = 7;
|
|
861
|
-
Binary.SUBTYPE_SENSITIVE = 8;
|
|
862
|
-
Binary.SUBTYPE_VECTOR = 9;
|
|
863
|
-
Binary.SUBTYPE_USER_DEFINED = 128;
|
|
864
|
-
Binary.VECTOR_TYPE = Object.freeze({
|
|
865
|
-
Int8: 0x03,
|
|
866
|
-
Float32: 0x27,
|
|
867
|
-
PackedBit: 0x10
|
|
868
|
-
});
|
|
869
881
|
function validateBinaryVector(vector) {
|
|
870
882
|
if (vector.sub_type !== Binary.SUBTYPE_VECTOR)
|
|
871
883
|
return;
|
|
@@ -1002,6 +1014,8 @@ class Code extends BSONValue {
|
|
|
1002
1014
|
get _bsontype() {
|
|
1003
1015
|
return 'Code';
|
|
1004
1016
|
}
|
|
1017
|
+
code;
|
|
1018
|
+
scope;
|
|
1005
1019
|
constructor(code, scope) {
|
|
1006
1020
|
super();
|
|
1007
1021
|
this.code = code.toString();
|
|
@@ -1047,6 +1061,10 @@ class DBRef extends BSONValue {
|
|
|
1047
1061
|
get _bsontype() {
|
|
1048
1062
|
return 'DBRef';
|
|
1049
1063
|
}
|
|
1064
|
+
collection;
|
|
1065
|
+
oid;
|
|
1066
|
+
db;
|
|
1067
|
+
fields;
|
|
1050
1068
|
constructor(collection, oid, db, fields) {
|
|
1051
1069
|
super();
|
|
1052
1070
|
const parts = collection.split('.');
|
|
@@ -1156,6 +1174,9 @@ class Long extends BSONValue {
|
|
|
1156
1174
|
get __isLong__() {
|
|
1157
1175
|
return true;
|
|
1158
1176
|
}
|
|
1177
|
+
high;
|
|
1178
|
+
low;
|
|
1179
|
+
unsigned;
|
|
1159
1180
|
constructor(lowOrValue = 0, highOrUnsigned, unsigned) {
|
|
1160
1181
|
super();
|
|
1161
1182
|
const unsignedBool = typeof highOrUnsigned === 'boolean' ? highOrUnsigned : Boolean(unsigned);
|
|
@@ -1169,6 +1190,15 @@ class Long extends BSONValue {
|
|
|
1169
1190
|
this.high = res.high;
|
|
1170
1191
|
this.unsigned = res.unsigned;
|
|
1171
1192
|
}
|
|
1193
|
+
static TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
|
|
1194
|
+
static MAX_UNSIGNED_VALUE = Long.fromBits(0xffffffff | 0, 0xffffffff | 0, true);
|
|
1195
|
+
static ZERO = Long.fromInt(0);
|
|
1196
|
+
static UZERO = Long.fromInt(0, true);
|
|
1197
|
+
static ONE = Long.fromInt(1);
|
|
1198
|
+
static UONE = Long.fromInt(1, true);
|
|
1199
|
+
static NEG_ONE = Long.fromInt(-1);
|
|
1200
|
+
static MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
|
|
1201
|
+
static MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false);
|
|
1172
1202
|
static fromBits(lowBits, highBits, unsigned) {
|
|
1173
1203
|
return new Long(lowBits, highBits, unsigned);
|
|
1174
1204
|
}
|
|
@@ -1209,7 +1239,7 @@ class Long extends BSONValue {
|
|
|
1209
1239
|
return Long.MAX_UNSIGNED_VALUE;
|
|
1210
1240
|
}
|
|
1211
1241
|
else {
|
|
1212
|
-
if (value <= -
|
|
1242
|
+
if (value <= -TWO_PWR_63_DBL)
|
|
1213
1243
|
return Long.MIN_VALUE;
|
|
1214
1244
|
if (value + 1 >= TWO_PWR_63_DBL)
|
|
1215
1245
|
return Long.MAX_VALUE;
|
|
@@ -1219,8 +1249,8 @@ class Long extends BSONValue {
|
|
|
1219
1249
|
return Long.fromBits(value % TWO_PWR_32_DBL | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
|
|
1220
1250
|
}
|
|
1221
1251
|
static fromBigInt(value, unsigned) {
|
|
1222
|
-
const FROM_BIGINT_BIT_MASK =
|
|
1223
|
-
const FROM_BIGINT_BIT_SHIFT =
|
|
1252
|
+
const FROM_BIGINT_BIT_MASK = 0xffffffffn;
|
|
1253
|
+
const FROM_BIGINT_BIT_SHIFT = 32n;
|
|
1224
1254
|
return new Long(Number(value & FROM_BIGINT_BIT_MASK), Number((value >> FROM_BIGINT_BIT_SHIFT) & FROM_BIGINT_BIT_MASK), unsigned);
|
|
1225
1255
|
}
|
|
1226
1256
|
static _fromString(str, unsigned, radix) {
|
|
@@ -1253,7 +1283,7 @@ class Long extends BSONValue {
|
|
|
1253
1283
|
static fromStringStrict(str, unsignedOrRadix, radix) {
|
|
1254
1284
|
let unsigned = false;
|
|
1255
1285
|
if (typeof unsignedOrRadix === 'number') {
|
|
1256
|
-
(radix = unsignedOrRadix), (unsignedOrRadix = false);
|
|
1286
|
+
((radix = unsignedOrRadix), (unsignedOrRadix = false));
|
|
1257
1287
|
}
|
|
1258
1288
|
else {
|
|
1259
1289
|
unsigned = !!unsignedOrRadix;
|
|
@@ -1275,7 +1305,7 @@ class Long extends BSONValue {
|
|
|
1275
1305
|
static fromString(str, unsignedOrRadix, radix) {
|
|
1276
1306
|
let unsigned = false;
|
|
1277
1307
|
if (typeof unsignedOrRadix === 'number') {
|
|
1278
|
-
(radix = unsignedOrRadix), (unsignedOrRadix = false);
|
|
1308
|
+
((radix = unsignedOrRadix), (unsignedOrRadix = false));
|
|
1279
1309
|
}
|
|
1280
1310
|
else {
|
|
1281
1311
|
unsigned = !!unsignedOrRadix;
|
|
@@ -1795,15 +1825,6 @@ class Long extends BSONValue {
|
|
|
1795
1825
|
return `new Long(${longVal}${unsignedVal})`;
|
|
1796
1826
|
}
|
|
1797
1827
|
}
|
|
1798
|
-
Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
|
|
1799
|
-
Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xffffffff | 0, 0xffffffff | 0, true);
|
|
1800
|
-
Long.ZERO = Long.fromInt(0);
|
|
1801
|
-
Long.UZERO = Long.fromInt(0, true);
|
|
1802
|
-
Long.ONE = Long.fromInt(1);
|
|
1803
|
-
Long.UONE = Long.fromInt(1, true);
|
|
1804
|
-
Long.NEG_ONE = Long.fromInt(-1);
|
|
1805
|
-
Long.MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
|
|
1806
|
-
Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false);
|
|
1807
1828
|
|
|
1808
1829
|
const PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
|
|
1809
1830
|
const PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i;
|
|
@@ -1884,6 +1905,7 @@ class Decimal128 extends BSONValue {
|
|
|
1884
1905
|
get _bsontype() {
|
|
1885
1906
|
return 'Decimal128';
|
|
1886
1907
|
}
|
|
1908
|
+
bytes;
|
|
1887
1909
|
constructor(bytes) {
|
|
1888
1910
|
super();
|
|
1889
1911
|
if (typeof bytes === 'string') {
|
|
@@ -2359,6 +2381,7 @@ class Double extends BSONValue {
|
|
|
2359
2381
|
get _bsontype() {
|
|
2360
2382
|
return 'Double';
|
|
2361
2383
|
}
|
|
2384
|
+
value;
|
|
2362
2385
|
constructor(value) {
|
|
2363
2386
|
super();
|
|
2364
2387
|
if (value instanceof Number) {
|
|
@@ -2422,6 +2445,7 @@ class Int32 extends BSONValue {
|
|
|
2422
2445
|
get _bsontype() {
|
|
2423
2446
|
return 'Int32';
|
|
2424
2447
|
}
|
|
2448
|
+
value;
|
|
2425
2449
|
constructor(value) {
|
|
2426
2450
|
super();
|
|
2427
2451
|
if (value instanceof Number) {
|
|
@@ -2500,11 +2524,14 @@ class MinKey extends BSONValue {
|
|
|
2500
2524
|
}
|
|
2501
2525
|
|
|
2502
2526
|
let PROCESS_UNIQUE = null;
|
|
2503
|
-
const __idCache = new WeakMap();
|
|
2504
2527
|
class ObjectId extends BSONValue {
|
|
2505
2528
|
get _bsontype() {
|
|
2506
2529
|
return 'ObjectId';
|
|
2507
2530
|
}
|
|
2531
|
+
static index = Math.floor(Math.random() * 0xffffff);
|
|
2532
|
+
static cacheHexString = false;
|
|
2533
|
+
buffer;
|
|
2534
|
+
#cachedHexString = null;
|
|
2508
2535
|
constructor(inputId) {
|
|
2509
2536
|
super();
|
|
2510
2537
|
let workingId;
|
|
@@ -2522,8 +2549,8 @@ class ObjectId extends BSONValue {
|
|
|
2522
2549
|
else {
|
|
2523
2550
|
workingId = inputId;
|
|
2524
2551
|
}
|
|
2525
|
-
if (workingId == null
|
|
2526
|
-
this.buffer = ObjectId.generate(
|
|
2552
|
+
if (workingId == null) {
|
|
2553
|
+
this.buffer = ObjectId.generate();
|
|
2527
2554
|
}
|
|
2528
2555
|
else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
|
|
2529
2556
|
this.buffer = ByteUtils.toLocalBufferType(workingId);
|
|
@@ -2532,7 +2559,7 @@ class ObjectId extends BSONValue {
|
|
|
2532
2559
|
if (ObjectId.validateHexString(workingId)) {
|
|
2533
2560
|
this.buffer = ByteUtils.fromHex(workingId);
|
|
2534
2561
|
if (ObjectId.cacheHexString) {
|
|
2535
|
-
|
|
2562
|
+
this.#cachedHexString = workingId;
|
|
2536
2563
|
}
|
|
2537
2564
|
}
|
|
2538
2565
|
else {
|
|
@@ -2549,7 +2576,7 @@ class ObjectId extends BSONValue {
|
|
|
2549
2576
|
set id(value) {
|
|
2550
2577
|
this.buffer = value;
|
|
2551
2578
|
if (ObjectId.cacheHexString) {
|
|
2552
|
-
|
|
2579
|
+
this.#cachedHexString = ByteUtils.toHex(value);
|
|
2553
2580
|
}
|
|
2554
2581
|
}
|
|
2555
2582
|
static validateHexString(string) {
|
|
@@ -2567,14 +2594,11 @@ class ObjectId extends BSONValue {
|
|
|
2567
2594
|
return true;
|
|
2568
2595
|
}
|
|
2569
2596
|
toHexString() {
|
|
2570
|
-
if (
|
|
2571
|
-
|
|
2572
|
-
if (__id)
|
|
2573
|
-
return __id;
|
|
2574
|
-
}
|
|
2597
|
+
if (this.#cachedHexString)
|
|
2598
|
+
return this.#cachedHexString.toLowerCase();
|
|
2575
2599
|
const hexString = ByteUtils.toHex(this.id);
|
|
2576
2600
|
if (ObjectId.cacheHexString) {
|
|
2577
|
-
|
|
2601
|
+
this.#cachedHexString = hexString;
|
|
2578
2602
|
}
|
|
2579
2603
|
return hexString;
|
|
2580
2604
|
}
|
|
@@ -2699,14 +2723,13 @@ class ObjectId extends BSONValue {
|
|
|
2699
2723
|
return new ObjectId(doc.$oid);
|
|
2700
2724
|
}
|
|
2701
2725
|
isCached() {
|
|
2702
|
-
return ObjectId.cacheHexString &&
|
|
2726
|
+
return ObjectId.cacheHexString && this.#cachedHexString != null;
|
|
2703
2727
|
}
|
|
2704
2728
|
inspect(depth, options, inspect) {
|
|
2705
2729
|
inspect ??= defaultInspect;
|
|
2706
2730
|
return `new ObjectId(${inspect(this.toHexString(), options)})`;
|
|
2707
2731
|
}
|
|
2708
2732
|
}
|
|
2709
|
-
ObjectId.index = Math.floor(Math.random() * 0xffffff);
|
|
2710
2733
|
|
|
2711
2734
|
function internalCalculateObjectSize(object, serializeFunctions, ignoreUndefined) {
|
|
2712
2735
|
let totalLength = 4 + 1;
|
|
@@ -2875,6 +2898,8 @@ class BSONRegExp extends BSONValue {
|
|
|
2875
2898
|
get _bsontype() {
|
|
2876
2899
|
return 'BSONRegExp';
|
|
2877
2900
|
}
|
|
2901
|
+
pattern;
|
|
2902
|
+
options;
|
|
2878
2903
|
constructor(pattern, options) {
|
|
2879
2904
|
super();
|
|
2880
2905
|
this.pattern = pattern;
|
|
@@ -2935,6 +2960,7 @@ class BSONSymbol extends BSONValue {
|
|
|
2935
2960
|
get _bsontype() {
|
|
2936
2961
|
return 'BSONSymbol';
|
|
2937
2962
|
}
|
|
2963
|
+
value;
|
|
2938
2964
|
constructor(value) {
|
|
2939
2965
|
super();
|
|
2940
2966
|
this.value = value;
|
|
@@ -2965,6 +2991,10 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
2965
2991
|
get _bsontype() {
|
|
2966
2992
|
return 'Timestamp';
|
|
2967
2993
|
}
|
|
2994
|
+
get [bsonType]() {
|
|
2995
|
+
return 'Timestamp';
|
|
2996
|
+
}
|
|
2997
|
+
static MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
|
|
2968
2998
|
get i() {
|
|
2969
2999
|
return this.low >>> 0;
|
|
2970
3000
|
}
|
|
@@ -3044,7 +3074,6 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
3044
3074
|
return `new Timestamp({ t: ${t}, i: ${i} })`;
|
|
3045
3075
|
}
|
|
3046
3076
|
}
|
|
3047
|
-
Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
|
|
3048
3077
|
|
|
3049
3078
|
const JS_INT_MAX_LONG = Long.fromNumber(JS_INT_MAX);
|
|
3050
3079
|
const JS_INT_MIN_LONG = Long.fromNumber(JS_INT_MIN);
|
|
@@ -4596,6 +4625,7 @@ MinKey: MinKey,
|
|
|
4596
4625
|
ObjectId: ObjectId,
|
|
4597
4626
|
Timestamp: Timestamp,
|
|
4598
4627
|
UUID: UUID,
|
|
4628
|
+
bsonType: bsonType,
|
|
4599
4629
|
calculateObjectSize: calculateObjectSize,
|
|
4600
4630
|
deserialize: deserialize,
|
|
4601
4631
|
deserializeStream: deserializeStream,
|
|
@@ -4627,6 +4657,7 @@ exports.MinKey = MinKey;
|
|
|
4627
4657
|
exports.ObjectId = ObjectId;
|
|
4628
4658
|
exports.Timestamp = Timestamp;
|
|
4629
4659
|
exports.UUID = UUID;
|
|
4660
|
+
exports.bsonType = bsonType;
|
|
4630
4661
|
exports.calculateObjectSize = calculateObjectSize;
|
|
4631
4662
|
exports.deserialize = deserialize;
|
|
4632
4663
|
exports.deserializeStream = deserializeStream;
|