bson 6.0.0 → 6.2.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/bson.d.ts +51 -14
- package/lib/bson.bundle.js +197 -102
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +197 -102
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +197 -102
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.rn.cjs +197 -102
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +1 -1
- package/src/binary.ts +10 -15
- package/src/bson_value.ts +15 -2
- package/src/code.ts +10 -10
- package/src/db_ref.ts +13 -11
- package/src/decimal128.ts +158 -48
- package/src/double.ts +4 -8
- package/src/error.ts +1 -3
- package/src/int_32.ts +4 -7
- package/src/long.ts +6 -7
- package/src/max_key.ts +0 -5
- package/src/min_key.ts +0 -5
- package/src/objectid.ts +4 -7
- package/src/parser/serializer.ts +7 -3
- package/src/parser/utils.ts +27 -0
- package/src/regexp.ts +7 -7
- package/src/symbol.ts +4 -7
- package/src/timestamp.ts +6 -7
package/bson.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ export declare class Binary extends BSONValue {
|
|
|
68
68
|
/** Creates an Binary instance from a base64 string */
|
|
69
69
|
static createFromBase64(base64: string, subType?: number): Binary;
|
|
70
70
|
/* Excluded from this release type: fromExtendedJSON */
|
|
71
|
-
inspect(): string;
|
|
71
|
+
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/** @public */
|
|
@@ -187,7 +187,7 @@ export declare class BSONRegExp extends BSONValue {
|
|
|
187
187
|
static parseOptions(options?: string): string;
|
|
188
188
|
/* Excluded from this release type: toExtendedJSON */
|
|
189
189
|
/* Excluded from this release type: fromExtendedJSON */
|
|
190
|
-
inspect(): string;
|
|
190
|
+
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
/** @public */
|
|
@@ -232,10 +232,10 @@ export declare class BSONSymbol extends BSONValue {
|
|
|
232
232
|
/** Access the wrapped string value. */
|
|
233
233
|
valueOf(): string;
|
|
234
234
|
toString(): string;
|
|
235
|
-
inspect(): string;
|
|
236
235
|
toJSON(): string;
|
|
237
236
|
/* Excluded from this release type: toExtendedJSON */
|
|
238
237
|
/* Excluded from this release type: fromExtendedJSON */
|
|
238
|
+
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
/** @public */
|
|
@@ -275,8 +275,12 @@ export declare type BSONType = (typeof BSONType)[keyof typeof BSONType];
|
|
|
275
275
|
export declare abstract class BSONValue {
|
|
276
276
|
/** @public */
|
|
277
277
|
abstract get _bsontype(): string;
|
|
278
|
-
/**
|
|
279
|
-
|
|
278
|
+
/**
|
|
279
|
+
* @public
|
|
280
|
+
* Prints a human-readable string of BSON value information
|
|
281
|
+
* If invoked manually without node.js.inspect function, this will default to a modified JSON.stringify
|
|
282
|
+
*/
|
|
283
|
+
abstract inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
280
284
|
/* Excluded from this release type: toExtendedJSON */
|
|
281
285
|
}
|
|
282
286
|
|
|
@@ -321,7 +325,7 @@ export declare class Code extends BSONValue {
|
|
|
321
325
|
};
|
|
322
326
|
/* Excluded from this release type: toExtendedJSON */
|
|
323
327
|
/* Excluded from this release type: fromExtendedJSON */
|
|
324
|
-
inspect(): string;
|
|
328
|
+
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
325
329
|
}
|
|
326
330
|
|
|
327
331
|
/** @public */
|
|
@@ -352,7 +356,7 @@ export declare class DBRef extends BSONValue {
|
|
|
352
356
|
toJSON(): DBRefLike & Document;
|
|
353
357
|
/* Excluded from this release type: toExtendedJSON */
|
|
354
358
|
/* Excluded from this release type: fromExtendedJSON */
|
|
355
|
-
inspect(): string;
|
|
359
|
+
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
356
360
|
}
|
|
357
361
|
|
|
358
362
|
/** @public */
|
|
@@ -381,12 +385,32 @@ export declare class Decimal128 extends BSONValue {
|
|
|
381
385
|
* @param representation - a numeric string representation.
|
|
382
386
|
*/
|
|
383
387
|
static fromString(representation: string): Decimal128;
|
|
388
|
+
/**
|
|
389
|
+
* Create a Decimal128 instance from a string representation, allowing for rounding to 34
|
|
390
|
+
* significant digits
|
|
391
|
+
*
|
|
392
|
+
* @example Example of a number that will be rounded
|
|
393
|
+
* ```ts
|
|
394
|
+
* > let d = Decimal128.fromString('37.499999999999999196428571428571375')
|
|
395
|
+
* Uncaught:
|
|
396
|
+
* BSONError: "37.499999999999999196428571428571375" is not a valid Decimal128 string - inexact rounding
|
|
397
|
+
* at invalidErr (/home/wajames/js-bson/lib/bson.cjs:1402:11)
|
|
398
|
+
* at Decimal128.fromStringInternal (/home/wajames/js-bson/lib/bson.cjs:1633:25)
|
|
399
|
+
* at Decimal128.fromString (/home/wajames/js-bson/lib/bson.cjs:1424:27)
|
|
400
|
+
*
|
|
401
|
+
* > d = Decimal128.fromStringWithRounding('37.499999999999999196428571428571375')
|
|
402
|
+
* new Decimal128("37.49999999999999919642857142857138")
|
|
403
|
+
* ```
|
|
404
|
+
* @param representation - a numeric string representation.
|
|
405
|
+
*/
|
|
406
|
+
static fromStringWithRounding(representation: string): Decimal128;
|
|
407
|
+
private static _fromString;
|
|
384
408
|
/** Create a string representation of the raw Decimal128 value */
|
|
385
409
|
toString(): string;
|
|
386
410
|
toJSON(): Decimal128Extended;
|
|
387
411
|
/* Excluded from this release type: toExtendedJSON */
|
|
388
412
|
/* Excluded from this release type: fromExtendedJSON */
|
|
389
|
-
inspect(): string;
|
|
413
|
+
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
390
414
|
}
|
|
391
415
|
|
|
392
416
|
/** @public */
|
|
@@ -509,7 +533,7 @@ export declare class Double extends BSONValue {
|
|
|
509
533
|
toString(radix?: number): string;
|
|
510
534
|
/* Excluded from this release type: toExtendedJSON */
|
|
511
535
|
/* Excluded from this release type: fromExtendedJSON */
|
|
512
|
-
inspect(): string;
|
|
536
|
+
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
513
537
|
}
|
|
514
538
|
|
|
515
539
|
/** @public */
|
|
@@ -559,6 +583,8 @@ export declare type EJSONOptions = {
|
|
|
559
583
|
*/
|
|
560
584
|
declare function EJSONserialize(value: any, options?: EJSONOptions): Document;
|
|
561
585
|
|
|
586
|
+
declare type InspectFn = (x: unknown, options?: unknown) => string;
|
|
587
|
+
|
|
562
588
|
/**
|
|
563
589
|
* A class representation of a BSON Int32 type.
|
|
564
590
|
* @public
|
|
@@ -583,7 +609,7 @@ export declare class Int32 extends BSONValue {
|
|
|
583
609
|
toJSON(): number;
|
|
584
610
|
/* Excluded from this release type: toExtendedJSON */
|
|
585
611
|
/* Excluded from this release type: fromExtendedJSON */
|
|
586
|
-
inspect(): string;
|
|
612
|
+
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
587
613
|
}
|
|
588
614
|
|
|
589
615
|
/** @public */
|
|
@@ -906,7 +932,7 @@ export declare class Long extends BSONValue {
|
|
|
906
932
|
static fromExtendedJSON(doc: {
|
|
907
933
|
$numberLong: string;
|
|
908
934
|
}, options?: EJSONOptions): number | Long | bigint;
|
|
909
|
-
inspect(): string;
|
|
935
|
+
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
910
936
|
}
|
|
911
937
|
|
|
912
938
|
/** @public */
|
|
@@ -1026,7 +1052,12 @@ export declare class ObjectId extends BSONValue {
|
|
|
1026
1052
|
static isValid(id: string | number | ObjectId | ObjectIdLike | Uint8Array): boolean;
|
|
1027
1053
|
/* Excluded from this release type: toExtendedJSON */
|
|
1028
1054
|
/* Excluded from this release type: fromExtendedJSON */
|
|
1029
|
-
|
|
1055
|
+
/**
|
|
1056
|
+
* Converts to a string representation of this Id.
|
|
1057
|
+
*
|
|
1058
|
+
* @returns return the 24 character hex string representation.
|
|
1059
|
+
*/
|
|
1060
|
+
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
1030
1061
|
}
|
|
1031
1062
|
|
|
1032
1063
|
/** @public */
|
|
@@ -1183,7 +1214,7 @@ export declare class Timestamp extends LongWithoutOverridesClass {
|
|
|
1183
1214
|
static fromString(str: string, optRadix: number): Timestamp;
|
|
1184
1215
|
/* Excluded from this release type: toExtendedJSON */
|
|
1185
1216
|
/* Excluded from this release type: fromExtendedJSON */
|
|
1186
|
-
inspect(): string;
|
|
1217
|
+
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
1187
1218
|
}
|
|
1188
1219
|
|
|
1189
1220
|
/** @public */
|
|
@@ -1258,7 +1289,13 @@ export declare class UUID extends Binary {
|
|
|
1258
1289
|
static createFromBase64(base64: string): UUID;
|
|
1259
1290
|
/* Excluded from this release type: bytesFromString */
|
|
1260
1291
|
/* Excluded from this release type: isValidUUIDString */
|
|
1261
|
-
|
|
1292
|
+
/**
|
|
1293
|
+
* Converts to a string representation of this Id.
|
|
1294
|
+
*
|
|
1295
|
+
* @returns return the 36 character hex string representation.
|
|
1296
|
+
*
|
|
1297
|
+
*/
|
|
1298
|
+
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
1262
1299
|
}
|
|
1263
1300
|
|
|
1264
1301
|
/** @public */
|
package/lib/bson.bundle.js
CHANGED
|
@@ -16,6 +16,26 @@ function isMap(d) {
|
|
|
16
16
|
function isDate(d) {
|
|
17
17
|
return Object.prototype.toString.call(d) === '[object Date]';
|
|
18
18
|
}
|
|
19
|
+
function defaultInspect(x, _options) {
|
|
20
|
+
return JSON.stringify(x, (k, v) => {
|
|
21
|
+
if (typeof v === 'bigint') {
|
|
22
|
+
return { $numberLong: `${v}` };
|
|
23
|
+
}
|
|
24
|
+
else if (isMap(v)) {
|
|
25
|
+
return Object.fromEntries(v);
|
|
26
|
+
}
|
|
27
|
+
return v;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function getStylizeFunction(options) {
|
|
31
|
+
const stylizeExists = options != null &&
|
|
32
|
+
typeof options === 'object' &&
|
|
33
|
+
'stylize' in options &&
|
|
34
|
+
typeof options.stylize === 'function';
|
|
35
|
+
if (stylizeExists) {
|
|
36
|
+
return options.stylize;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
19
39
|
|
|
20
40
|
const BSON_MAJOR_VERSION = 6;
|
|
21
41
|
const BSON_INT32_MAX = 0x7fffffff;
|
|
@@ -96,7 +116,7 @@ class BSONVersionError extends BSONError {
|
|
|
96
116
|
return 'BSONVersionError';
|
|
97
117
|
}
|
|
98
118
|
constructor() {
|
|
99
|
-
super(`Unsupported BSON version, bson types must be from bson ${BSON_MAJOR_VERSION}.
|
|
119
|
+
super(`Unsupported BSON version, bson types must be from bson ${BSON_MAJOR_VERSION}.x.x`);
|
|
100
120
|
}
|
|
101
121
|
}
|
|
102
122
|
class BSONRuntimeError extends BSONError {
|
|
@@ -303,6 +323,9 @@ class BSONValue {
|
|
|
303
323
|
get [Symbol.for('@@mdb.bson.version')]() {
|
|
304
324
|
return BSON_MAJOR_VERSION;
|
|
305
325
|
}
|
|
326
|
+
[Symbol.for('nodejs.util.inspect.custom')](depth, options, inspect) {
|
|
327
|
+
return this.inspect(depth, options, inspect);
|
|
328
|
+
}
|
|
306
329
|
}
|
|
307
330
|
|
|
308
331
|
class Binary extends BSONValue {
|
|
@@ -453,12 +476,12 @@ class Binary extends BSONValue {
|
|
|
453
476
|
}
|
|
454
477
|
return type === BSON_BINARY_SUBTYPE_UUID_NEW ? new UUID(data) : new Binary(data, type);
|
|
455
478
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
inspect() {
|
|
479
|
+
inspect(depth, options, inspect) {
|
|
480
|
+
inspect ??= defaultInspect;
|
|
460
481
|
const base64 = ByteUtils.toBase64(this.buffer.subarray(0, this.position));
|
|
461
|
-
|
|
482
|
+
const base64Arg = inspect(base64, options);
|
|
483
|
+
const subTypeArg = inspect(this.sub_type, options);
|
|
484
|
+
return `Binary.createFromBase64(${base64Arg}, ${subTypeArg})`;
|
|
462
485
|
}
|
|
463
486
|
}
|
|
464
487
|
Binary.BSON_BINARY_SUBTYPE_DEFAULT = 0;
|
|
@@ -576,11 +599,9 @@ class UUID extends Binary {
|
|
|
576
599
|
static isValidUUIDString(representation) {
|
|
577
600
|
return UUID_WITHOUT_DASHES.test(representation) || UUID_WITH_DASHES.test(representation);
|
|
578
601
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
inspect() {
|
|
583
|
-
return `new UUID("${this.toHexString()}")`;
|
|
602
|
+
inspect(depth, options, inspect) {
|
|
603
|
+
inspect ??= defaultInspect;
|
|
604
|
+
return `new UUID(${inspect(this.toHexString(), options)})`;
|
|
584
605
|
}
|
|
585
606
|
}
|
|
586
607
|
|
|
@@ -608,12 +629,15 @@ class Code extends BSONValue {
|
|
|
608
629
|
static fromExtendedJSON(doc) {
|
|
609
630
|
return new Code(doc.$code, doc.$scope);
|
|
610
631
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
632
|
+
inspect(depth, options, inspect) {
|
|
633
|
+
inspect ??= defaultInspect;
|
|
634
|
+
let parametersString = inspect(this.code, options);
|
|
635
|
+
const multiLineFn = parametersString.includes('\n');
|
|
636
|
+
if (this.scope != null) {
|
|
637
|
+
parametersString += `,${multiLineFn ? '\n' : ' '}${inspect(this.scope, options)}`;
|
|
638
|
+
}
|
|
639
|
+
const endingNewline = multiLineFn && this.scope === null;
|
|
640
|
+
return `new Code(${multiLineFn ? '\n' : ''}${parametersString}${endingNewline ? '\n' : ''})`;
|
|
617
641
|
}
|
|
618
642
|
}
|
|
619
643
|
|
|
@@ -678,12 +702,16 @@ class DBRef extends BSONValue {
|
|
|
678
702
|
delete copy.$db;
|
|
679
703
|
return new DBRef(doc.$ref, doc.$id, doc.$db, copy);
|
|
680
704
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
705
|
+
inspect(depth, options, inspect) {
|
|
706
|
+
inspect ??= defaultInspect;
|
|
707
|
+
const args = [
|
|
708
|
+
inspect(this.namespace, options),
|
|
709
|
+
inspect(this.oid, options),
|
|
710
|
+
...(this.db ? [inspect(this.db, options)] : []),
|
|
711
|
+
...(Object.keys(this.fields).length > 0 ? [inspect(this.fields, options)] : [])
|
|
712
|
+
];
|
|
713
|
+
args[1] = inspect === defaultInspect ? `new ObjectId(${args[1]})` : args[1];
|
|
714
|
+
return `new DBRef(${args.join(', ')})`;
|
|
687
715
|
}
|
|
688
716
|
}
|
|
689
717
|
|
|
@@ -1310,11 +1338,11 @@ class Long extends BSONValue {
|
|
|
1310
1338
|
}
|
|
1311
1339
|
return longResult;
|
|
1312
1340
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
return `new Long(
|
|
1341
|
+
inspect(depth, options, inspect) {
|
|
1342
|
+
inspect ??= defaultInspect;
|
|
1343
|
+
const longVal = inspect(this.toString(), options);
|
|
1344
|
+
const unsignedVal = this.unsigned ? `, ${inspect(this.unsigned, options)}` : '';
|
|
1345
|
+
return `new Long(${longVal}${unsignedVal})`;
|
|
1318
1346
|
}
|
|
1319
1347
|
}
|
|
1320
1348
|
Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
|
|
@@ -1422,6 +1450,12 @@ class Decimal128 extends BSONValue {
|
|
|
1422
1450
|
}
|
|
1423
1451
|
}
|
|
1424
1452
|
static fromString(representation) {
|
|
1453
|
+
return Decimal128._fromString(representation, { allowRounding: false });
|
|
1454
|
+
}
|
|
1455
|
+
static fromStringWithRounding(representation) {
|
|
1456
|
+
return Decimal128._fromString(representation, { allowRounding: true });
|
|
1457
|
+
}
|
|
1458
|
+
static _fromString(representation, options) {
|
|
1425
1459
|
let isNegative = false;
|
|
1426
1460
|
let sawSign = false;
|
|
1427
1461
|
let sawRadix = false;
|
|
@@ -1542,44 +1576,117 @@ class Decimal128 extends BSONValue {
|
|
|
1542
1576
|
}
|
|
1543
1577
|
exponent = exponent - 1;
|
|
1544
1578
|
}
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
if (
|
|
1579
|
+
if (options.allowRounding) {
|
|
1580
|
+
while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
|
|
1581
|
+
if (lastDigit === 0 && significantDigits < nDigitsStored) {
|
|
1548
1582
|
exponent = EXPONENT_MIN;
|
|
1583
|
+
significantDigits = 0;
|
|
1549
1584
|
break;
|
|
1550
1585
|
}
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
if (nDigitsStored < nDigits) {
|
|
1554
|
-
if (representation[nDigits - 1 + Number(sawSign) + Number(sawRadix)] !== '0' &&
|
|
1555
|
-
significantDigits !== 0) {
|
|
1556
|
-
invalidErr(representation, 'inexact rounding');
|
|
1586
|
+
if (nDigitsStored < nDigits) {
|
|
1587
|
+
nDigits = nDigits - 1;
|
|
1557
1588
|
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
if (
|
|
1562
|
-
|
|
1589
|
+
else {
|
|
1590
|
+
lastDigit = lastDigit - 1;
|
|
1591
|
+
}
|
|
1592
|
+
if (exponent < EXPONENT_MAX) {
|
|
1593
|
+
exponent = exponent + 1;
|
|
1594
|
+
}
|
|
1595
|
+
else {
|
|
1596
|
+
const digitsString = digits.join('');
|
|
1597
|
+
if (digitsString.match(/^0+$/)) {
|
|
1598
|
+
exponent = EXPONENT_MAX;
|
|
1599
|
+
break;
|
|
1600
|
+
}
|
|
1601
|
+
invalidErr(representation, 'overflow');
|
|
1563
1602
|
}
|
|
1564
|
-
lastDigit = lastDigit - 1;
|
|
1565
|
-
}
|
|
1566
|
-
if (exponent < EXPONENT_MAX) {
|
|
1567
|
-
exponent = exponent + 1;
|
|
1568
1603
|
}
|
|
1569
|
-
|
|
1570
|
-
|
|
1604
|
+
if (lastDigit + 1 < significantDigits) {
|
|
1605
|
+
let endOfString = nDigitsRead;
|
|
1606
|
+
if (sawRadix) {
|
|
1607
|
+
firstNonZero = firstNonZero + 1;
|
|
1608
|
+
endOfString = endOfString + 1;
|
|
1609
|
+
}
|
|
1610
|
+
if (sawSign) {
|
|
1611
|
+
firstNonZero = firstNonZero + 1;
|
|
1612
|
+
endOfString = endOfString + 1;
|
|
1613
|
+
}
|
|
1614
|
+
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
|
|
1615
|
+
let roundBit = 0;
|
|
1616
|
+
if (roundDigit >= 5) {
|
|
1617
|
+
roundBit = 1;
|
|
1618
|
+
if (roundDigit === 5) {
|
|
1619
|
+
roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
|
|
1620
|
+
for (let i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
|
|
1621
|
+
if (parseInt(representation[i], 10)) {
|
|
1622
|
+
roundBit = 1;
|
|
1623
|
+
break;
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
if (roundBit) {
|
|
1629
|
+
let dIdx = lastDigit;
|
|
1630
|
+
for (; dIdx >= 0; dIdx--) {
|
|
1631
|
+
if (++digits[dIdx] > 9) {
|
|
1632
|
+
digits[dIdx] = 0;
|
|
1633
|
+
if (dIdx === 0) {
|
|
1634
|
+
if (exponent < EXPONENT_MAX) {
|
|
1635
|
+
exponent = exponent + 1;
|
|
1636
|
+
digits[dIdx] = 1;
|
|
1637
|
+
}
|
|
1638
|
+
else {
|
|
1639
|
+
return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
else {
|
|
1644
|
+
break;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1571
1648
|
}
|
|
1572
1649
|
}
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1650
|
+
else {
|
|
1651
|
+
while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
|
|
1652
|
+
if (lastDigit === 0) {
|
|
1653
|
+
if (significantDigits === 0) {
|
|
1654
|
+
exponent = EXPONENT_MIN;
|
|
1655
|
+
break;
|
|
1656
|
+
}
|
|
1657
|
+
invalidErr(representation, 'exponent underflow');
|
|
1658
|
+
}
|
|
1659
|
+
if (nDigitsStored < nDigits) {
|
|
1660
|
+
if (representation[nDigits - 1 + Number(sawSign) + Number(sawRadix)] !== '0' &&
|
|
1661
|
+
significantDigits !== 0) {
|
|
1662
|
+
invalidErr(representation, 'inexact rounding');
|
|
1663
|
+
}
|
|
1664
|
+
nDigits = nDigits - 1;
|
|
1665
|
+
}
|
|
1666
|
+
else {
|
|
1667
|
+
if (digits[lastDigit] !== 0) {
|
|
1668
|
+
invalidErr(representation, 'inexact rounding');
|
|
1669
|
+
}
|
|
1670
|
+
lastDigit = lastDigit - 1;
|
|
1671
|
+
}
|
|
1672
|
+
if (exponent < EXPONENT_MAX) {
|
|
1673
|
+
exponent = exponent + 1;
|
|
1674
|
+
}
|
|
1675
|
+
else {
|
|
1676
|
+
invalidErr(representation, 'overflow');
|
|
1677
|
+
}
|
|
1579
1678
|
}
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1679
|
+
if (lastDigit + 1 < significantDigits) {
|
|
1680
|
+
if (sawRadix) {
|
|
1681
|
+
firstNonZero = firstNonZero + 1;
|
|
1682
|
+
}
|
|
1683
|
+
if (sawSign) {
|
|
1684
|
+
firstNonZero = firstNonZero + 1;
|
|
1685
|
+
}
|
|
1686
|
+
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
|
|
1687
|
+
if (roundDigit !== 0) {
|
|
1688
|
+
invalidErr(representation, 'inexact rounding');
|
|
1689
|
+
}
|
|
1583
1690
|
}
|
|
1584
1691
|
}
|
|
1585
1692
|
significandHigh = Long.fromNumber(0);
|
|
@@ -1791,11 +1898,10 @@ class Decimal128 extends BSONValue {
|
|
|
1791
1898
|
static fromExtendedJSON(doc) {
|
|
1792
1899
|
return Decimal128.fromString(doc.$numberDecimal);
|
|
1793
1900
|
}
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
return `new Decimal128("${this.toString()}")`;
|
|
1901
|
+
inspect(depth, options, inspect) {
|
|
1902
|
+
inspect ??= defaultInspect;
|
|
1903
|
+
const d128string = inspect(this.toString(), options);
|
|
1904
|
+
return `new Decimal128(${d128string})`;
|
|
1799
1905
|
}
|
|
1800
1906
|
}
|
|
1801
1907
|
|
|
@@ -1834,12 +1940,9 @@ class Double extends BSONValue {
|
|
|
1834
1940
|
const doubleValue = parseFloat(doc.$numberDouble);
|
|
1835
1941
|
return options && options.relaxed ? doubleValue : new Double(doubleValue);
|
|
1836
1942
|
}
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
inspect() {
|
|
1841
|
-
const eJSON = this.toExtendedJSON();
|
|
1842
|
-
return `new Double(${eJSON.$numberDouble})`;
|
|
1943
|
+
inspect(depth, options, inspect) {
|
|
1944
|
+
inspect ??= defaultInspect;
|
|
1945
|
+
return `new Double(${inspect(this.value, options)})`;
|
|
1843
1946
|
}
|
|
1844
1947
|
}
|
|
1845
1948
|
|
|
@@ -1871,11 +1974,9 @@ class Int32 extends BSONValue {
|
|
|
1871
1974
|
static fromExtendedJSON(doc, options) {
|
|
1872
1975
|
return options && options.relaxed ? parseInt(doc.$numberInt, 10) : new Int32(doc.$numberInt);
|
|
1873
1976
|
}
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
inspect() {
|
|
1878
|
-
return `new Int32(${this.valueOf()})`;
|
|
1977
|
+
inspect(depth, options, inspect) {
|
|
1978
|
+
inspect ??= defaultInspect;
|
|
1979
|
+
return `new Int32(${inspect(this.value, options)})`;
|
|
1879
1980
|
}
|
|
1880
1981
|
}
|
|
1881
1982
|
|
|
@@ -1889,9 +1990,6 @@ class MaxKey extends BSONValue {
|
|
|
1889
1990
|
static fromExtendedJSON() {
|
|
1890
1991
|
return new MaxKey();
|
|
1891
1992
|
}
|
|
1892
|
-
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
1893
|
-
return this.inspect();
|
|
1894
|
-
}
|
|
1895
1993
|
inspect() {
|
|
1896
1994
|
return 'new MaxKey()';
|
|
1897
1995
|
}
|
|
@@ -1907,9 +2005,6 @@ class MinKey extends BSONValue {
|
|
|
1907
2005
|
static fromExtendedJSON() {
|
|
1908
2006
|
return new MinKey();
|
|
1909
2007
|
}
|
|
1910
|
-
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
1911
|
-
return this.inspect();
|
|
1912
|
-
}
|
|
1913
2008
|
inspect() {
|
|
1914
2009
|
return 'new MinKey()';
|
|
1915
2010
|
}
|
|
@@ -2080,11 +2175,9 @@ class ObjectId extends BSONValue {
|
|
|
2080
2175
|
static fromExtendedJSON(doc) {
|
|
2081
2176
|
return new ObjectId(doc.$oid);
|
|
2082
2177
|
}
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
inspect() {
|
|
2087
|
-
return `new ObjectId("${this.toHexString()}")`;
|
|
2178
|
+
inspect(depth, options, inspect) {
|
|
2179
|
+
inspect ??= defaultInspect;
|
|
2180
|
+
return `new ObjectId(${inspect(this.toHexString(), options)})`;
|
|
2088
2181
|
}
|
|
2089
2182
|
}
|
|
2090
2183
|
ObjectId.index = Math.floor(Math.random() * 0xffffff);
|
|
@@ -2297,11 +2390,12 @@ class BSONRegExp extends BSONValue {
|
|
|
2297
2390
|
}
|
|
2298
2391
|
throw new BSONError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(doc)}`);
|
|
2299
2392
|
}
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2393
|
+
inspect(depth, options, inspect) {
|
|
2394
|
+
const stylize = getStylizeFunction(options) ?? (v => v);
|
|
2395
|
+
inspect ??= defaultInspect;
|
|
2396
|
+
const pattern = stylize(inspect(this.pattern), 'regexp');
|
|
2397
|
+
const flags = stylize(inspect(this.options), 'regexp');
|
|
2398
|
+
return `new BSONRegExp(${pattern}, ${flags})`;
|
|
2305
2399
|
}
|
|
2306
2400
|
}
|
|
2307
2401
|
|
|
@@ -2319,9 +2413,6 @@ class BSONSymbol extends BSONValue {
|
|
|
2319
2413
|
toString() {
|
|
2320
2414
|
return this.value;
|
|
2321
2415
|
}
|
|
2322
|
-
inspect() {
|
|
2323
|
-
return `new BSONSymbol(${JSON.stringify(this.value)})`;
|
|
2324
|
-
}
|
|
2325
2416
|
toJSON() {
|
|
2326
2417
|
return this.value;
|
|
2327
2418
|
}
|
|
@@ -2331,8 +2422,9 @@ class BSONSymbol extends BSONValue {
|
|
|
2331
2422
|
static fromExtendedJSON(doc) {
|
|
2332
2423
|
return new BSONSymbol(doc.$symbol);
|
|
2333
2424
|
}
|
|
2334
|
-
|
|
2335
|
-
|
|
2425
|
+
inspect(depth, options, inspect) {
|
|
2426
|
+
inspect ??= defaultInspect;
|
|
2427
|
+
return `new BSONSymbol(${inspect(this.value, options)})`;
|
|
2336
2428
|
}
|
|
2337
2429
|
}
|
|
2338
2430
|
|
|
@@ -2407,11 +2499,11 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
2407
2499
|
: doc.$timestamp.t;
|
|
2408
2500
|
return new Timestamp({ t, i });
|
|
2409
2501
|
}
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
return `new Timestamp({ t: ${
|
|
2502
|
+
inspect(depth, options, inspect) {
|
|
2503
|
+
inspect ??= defaultInspect;
|
|
2504
|
+
const t = inspect(this.high >>> 0, options);
|
|
2505
|
+
const i = inspect(this.low >>> 0, options);
|
|
2506
|
+
return `new Timestamp({ t: ${t}, i: ${i} })`;
|
|
2415
2507
|
}
|
|
2416
2508
|
}
|
|
2417
2509
|
Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
|
|
@@ -3090,13 +3182,16 @@ function serializeObjectId(buffer, key, value, index) {
|
|
|
3090
3182
|
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
|
3091
3183
|
index = index + numberOfWrittenBytes;
|
|
3092
3184
|
buffer[index++] = 0;
|
|
3093
|
-
|
|
3094
|
-
|
|
3185
|
+
const idValue = value.id;
|
|
3186
|
+
if (isUint8Array(idValue)) {
|
|
3187
|
+
for (let i = 0; i < 12; i++) {
|
|
3188
|
+
buffer[index++] = idValue[i];
|
|
3189
|
+
}
|
|
3095
3190
|
}
|
|
3096
3191
|
else {
|
|
3097
3192
|
throw new BSONError('object [' + JSON.stringify(value) + '] is not a valid ObjectId');
|
|
3098
3193
|
}
|
|
3099
|
-
return index
|
|
3194
|
+
return index;
|
|
3100
3195
|
}
|
|
3101
3196
|
function serializeBuffer(buffer, key, value, index) {
|
|
3102
3197
|
buffer[index++] = BSON_DATA_BINARY;
|