bson 5.3.0 → 6.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 +51 -43
- package/bson.d.ts +10 -23
- package/lib/bson.bundle.js +73 -130
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +73 -130
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +73 -130
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.rn.cjs +4051 -0
- package/lib/bson.rn.cjs.map +1 -0
- package/package.json +26 -24
- package/src/binary.ts +19 -53
- package/src/bson.ts +2 -2
- package/src/code.ts +1 -1
- package/src/constants.ts +1 -1
- package/src/decimal128.ts +35 -67
- package/src/objectid.ts +20 -37
- package/src/parser/deserializer.ts +8 -8
- package/src/symbol.ts +1 -1
- package/src/timestamp.ts +7 -5
- package/src/utils/byte_utils.ts +2 -2
- package/src/utils/node_byte_utils.ts +3 -3
- package/src/utils/web_byte_utils.ts +2 -2
- package/vendor/base64/LICENSE-MIT.txt +20 -0
- package/vendor/base64/README.md +112 -0
- package/vendor/base64/base64.js +157 -0
- package/vendor/base64/package.json +43 -0
- package/vendor/text-encoding/LICENSE.md +237 -0
- package/vendor/text-encoding/README.md +111 -0
- package/vendor/text-encoding/index.js +9 -0
- package/vendor/text-encoding/lib/encoding-indexes.js +47 -0
- package/vendor/text-encoding/lib/encoding.js +3301 -0
- package/vendor/text-encoding/package.json +37 -0
- package/lib/binary.d.ts +0 -182
- package/lib/binary.d.ts.map +0 -1
- package/lib/bson.d.ts +0 -97
- package/lib/bson.d.ts.map +0 -1
- package/lib/bson_value.d.ts +0 -10
- package/lib/bson_value.d.ts.map +0 -1
- package/lib/code.d.ts +0 -32
- package/lib/code.d.ts.map +0 -1
- package/lib/constants.d.ts +0 -107
- package/lib/constants.d.ts.map +0 -1
- package/lib/db_ref.d.ts +0 -40
- package/lib/db_ref.d.ts.map +0 -1
- package/lib/decimal128.d.ts +0 -34
- package/lib/decimal128.d.ts.map +0 -1
- package/lib/double.d.ts +0 -35
- package/lib/double.d.ts.map +0 -1
- package/lib/error.d.ts +0 -50
- package/lib/error.d.ts.map +0 -1
- package/lib/extended_json.d.ts +0 -82
- package/lib/extended_json.d.ts.map +0 -1
- package/lib/index.d.ts +0 -4
- package/lib/index.d.ts.map +0 -1
- package/lib/int_32.d.ts +0 -35
- package/lib/int_32.d.ts.map +0 -1
- package/lib/long.d.ts +0 -323
- package/lib/long.d.ts.map +0 -1
- package/lib/max_key.d.ts +0 -19
- package/lib/max_key.d.ts.map +0 -1
- package/lib/min_key.d.ts +0 -19
- package/lib/min_key.d.ts.map +0 -1
- package/lib/objectid.d.ts +0 -96
- package/lib/objectid.d.ts.map +0 -1
- package/lib/regexp.d.ts +0 -36
- package/lib/regexp.d.ts.map +0 -1
- package/lib/symbol.d.ts +0 -28
- package/lib/symbol.d.ts.map +0 -1
- package/lib/timestamp.d.ts +0 -66
- package/lib/timestamp.d.ts.map +0 -1
- package/lib/validate_utf8.d.ts +0 -10
- package/lib/validate_utf8.d.ts.map +0 -1
package/lib/bson.cjs
CHANGED
|
@@ -16,7 +16,7 @@ function isDate(d) {
|
|
|
16
16
|
return Object.prototype.toString.call(d) === '[object Date]';
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const BSON_MAJOR_VERSION =
|
|
19
|
+
const BSON_MAJOR_VERSION = 6;
|
|
20
20
|
const BSON_INT32_MAX = 0x7fffffff;
|
|
21
21
|
const BSON_INT32_MIN = -0x80000000;
|
|
22
22
|
const BSON_INT64_MAX = Math.pow(2, 63) - 1;
|
|
@@ -165,8 +165,8 @@ const nodeJsByteUtils = {
|
|
|
165
165
|
fromUTF8(text) {
|
|
166
166
|
return Buffer.from(text, 'utf8');
|
|
167
167
|
},
|
|
168
|
-
toUTF8(buffer) {
|
|
169
|
-
return nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8');
|
|
168
|
+
toUTF8(buffer, start, end) {
|
|
169
|
+
return nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8', start, end);
|
|
170
170
|
},
|
|
171
171
|
utf8ByteLength(input) {
|
|
172
172
|
return Buffer.byteLength(input, 'utf8');
|
|
@@ -276,8 +276,8 @@ const webByteUtils = {
|
|
|
276
276
|
fromUTF8(text) {
|
|
277
277
|
return new TextEncoder().encode(text);
|
|
278
278
|
},
|
|
279
|
-
toUTF8(uint8array) {
|
|
280
|
-
return new TextDecoder('utf8', { fatal: false }).decode(uint8array);
|
|
279
|
+
toUTF8(uint8array, start, end) {
|
|
280
|
+
return new TextDecoder('utf8', { fatal: false }).decode(uint8array.slice(start, end));
|
|
281
281
|
},
|
|
282
282
|
utf8ByteLength(input) {
|
|
283
283
|
return webByteUtils.fromUTF8(input).byteLength;
|
|
@@ -311,11 +311,11 @@ class Binary extends BSONValue {
|
|
|
311
311
|
constructor(buffer, subType) {
|
|
312
312
|
super();
|
|
313
313
|
if (!(buffer == null) &&
|
|
314
|
-
|
|
314
|
+
typeof buffer === 'string' &&
|
|
315
315
|
!ArrayBuffer.isView(buffer) &&
|
|
316
|
-
!(buffer
|
|
316
|
+
!isAnyArrayBuffer(buffer) &&
|
|
317
317
|
!Array.isArray(buffer)) {
|
|
318
|
-
throw new BSONError('Binary can only be constructed from
|
|
318
|
+
throw new BSONError('Binary can only be constructed from Uint8Array or number[]');
|
|
319
319
|
}
|
|
320
320
|
this.sub_type = subType ?? Binary.BSON_BINARY_SUBTYPE_DEFAULT;
|
|
321
321
|
if (buffer == null) {
|
|
@@ -323,15 +323,9 @@ class Binary extends BSONValue {
|
|
|
323
323
|
this.position = 0;
|
|
324
324
|
}
|
|
325
325
|
else {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
else if (Array.isArray(buffer)) {
|
|
330
|
-
this.buffer = ByteUtils.fromNumberArray(buffer);
|
|
331
|
-
}
|
|
332
|
-
else {
|
|
333
|
-
this.buffer = ByteUtils.toLocalBufferType(buffer);
|
|
334
|
-
}
|
|
326
|
+
this.buffer = Array.isArray(buffer)
|
|
327
|
+
? ByteUtils.fromNumberArray(buffer)
|
|
328
|
+
: ByteUtils.toLocalBufferType(buffer);
|
|
335
329
|
this.position = this.buffer.byteLength;
|
|
336
330
|
}
|
|
337
331
|
}
|
|
@@ -377,25 +371,17 @@ class Binary extends BSONValue {
|
|
|
377
371
|
offset + sequence.byteLength > this.position ? offset + sequence.length : this.position;
|
|
378
372
|
}
|
|
379
373
|
else if (typeof sequence === 'string') {
|
|
380
|
-
|
|
381
|
-
this.buffer.set(bytes, offset);
|
|
382
|
-
this.position =
|
|
383
|
-
offset + sequence.length > this.position ? offset + sequence.length : this.position;
|
|
374
|
+
throw new BSONError('input cannot be string');
|
|
384
375
|
}
|
|
385
376
|
}
|
|
386
377
|
read(position, length) {
|
|
387
378
|
length = length && length > 0 ? length : this.position;
|
|
388
379
|
return this.buffer.slice(position, position + length);
|
|
389
380
|
}
|
|
390
|
-
value(
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
395
|
-
if (asRaw) {
|
|
396
|
-
return this.buffer.slice(0, this.position);
|
|
397
|
-
}
|
|
398
|
-
return ByteUtils.toISO88591(this.buffer.subarray(0, this.position));
|
|
381
|
+
value() {
|
|
382
|
+
return this.buffer.length === this.position
|
|
383
|
+
? this.buffer
|
|
384
|
+
: this.buffer.subarray(0, this.position);
|
|
399
385
|
}
|
|
400
386
|
length() {
|
|
401
387
|
return this.position;
|
|
@@ -409,8 +395,8 @@ class Binary extends BSONValue {
|
|
|
409
395
|
if (encoding === 'base64')
|
|
410
396
|
return ByteUtils.toBase64(this.buffer);
|
|
411
397
|
if (encoding === 'utf8' || encoding === 'utf-8')
|
|
412
|
-
return ByteUtils.toUTF8(this.buffer);
|
|
413
|
-
return ByteUtils.toUTF8(this.buffer);
|
|
398
|
+
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
|
|
399
|
+
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
|
|
414
400
|
}
|
|
415
401
|
toExtendedJSON(options) {
|
|
416
402
|
options = options || {};
|
|
@@ -596,7 +582,6 @@ class UUID extends Binary {
|
|
|
596
582
|
return `new UUID("${this.toHexString()}")`;
|
|
597
583
|
}
|
|
598
584
|
}
|
|
599
|
-
UUID.cacheHexString = false;
|
|
600
585
|
|
|
601
586
|
class Code extends BSONValue {
|
|
602
587
|
get _bsontype() {
|
|
@@ -627,7 +612,7 @@ class Code extends BSONValue {
|
|
|
627
612
|
}
|
|
628
613
|
inspect() {
|
|
629
614
|
const codeJson = this.toJSON();
|
|
630
|
-
return `new Code(
|
|
615
|
+
return `new Code(${JSON.stringify(String(codeJson.code))}${codeJson.scope != null ? `, ${JSON.stringify(codeJson.scope)}` : ''})`;
|
|
631
616
|
}
|
|
632
617
|
}
|
|
633
618
|
|
|
@@ -1437,6 +1422,7 @@ class Decimal128 extends BSONValue {
|
|
|
1437
1422
|
}
|
|
1438
1423
|
static fromString(representation) {
|
|
1439
1424
|
let isNegative = false;
|
|
1425
|
+
let sawSign = false;
|
|
1440
1426
|
let sawRadix = false;
|
|
1441
1427
|
let foundNonZero = false;
|
|
1442
1428
|
let significantDigits = 0;
|
|
@@ -1447,10 +1433,8 @@ class Decimal128 extends BSONValue {
|
|
|
1447
1433
|
const digits = [0];
|
|
1448
1434
|
let nDigitsStored = 0;
|
|
1449
1435
|
let digitsInsert = 0;
|
|
1450
|
-
let firstDigit = 0;
|
|
1451
1436
|
let lastDigit = 0;
|
|
1452
1437
|
let exponent = 0;
|
|
1453
|
-
let i = 0;
|
|
1454
1438
|
let significandHigh = new Long(0, 0);
|
|
1455
1439
|
let significandLow = new Long(0, 0);
|
|
1456
1440
|
let biasedExponent = 0;
|
|
@@ -1478,6 +1462,7 @@ class Decimal128 extends BSONValue {
|
|
|
1478
1462
|
}
|
|
1479
1463
|
}
|
|
1480
1464
|
if (representation[index] === '+' || representation[index] === '-') {
|
|
1465
|
+
sawSign = true;
|
|
1481
1466
|
isNegative = representation[index++] === '-';
|
|
1482
1467
|
}
|
|
1483
1468
|
if (!isDigit(representation[index]) && representation[index] !== '.') {
|
|
@@ -1496,7 +1481,7 @@ class Decimal128 extends BSONValue {
|
|
|
1496
1481
|
index = index + 1;
|
|
1497
1482
|
continue;
|
|
1498
1483
|
}
|
|
1499
|
-
if (nDigitsStored <
|
|
1484
|
+
if (nDigitsStored < MAX_DIGITS) {
|
|
1500
1485
|
if (representation[index] !== '0' || foundNonZero) {
|
|
1501
1486
|
if (!foundNonZero) {
|
|
1502
1487
|
firstNonZero = nDigitsRead;
|
|
@@ -1524,10 +1509,7 @@ class Decimal128 extends BSONValue {
|
|
|
1524
1509
|
}
|
|
1525
1510
|
if (representation[index])
|
|
1526
1511
|
return new Decimal128(NAN_BUFFER);
|
|
1527
|
-
firstDigit = 0;
|
|
1528
1512
|
if (!nDigitsStored) {
|
|
1529
|
-
firstDigit = 0;
|
|
1530
|
-
lastDigit = 0;
|
|
1531
1513
|
digits[0] = 0;
|
|
1532
1514
|
nDigits = 1;
|
|
1533
1515
|
nDigitsStored = 1;
|
|
@@ -1537,12 +1519,12 @@ class Decimal128 extends BSONValue {
|
|
|
1537
1519
|
lastDigit = nDigitsStored - 1;
|
|
1538
1520
|
significantDigits = nDigits;
|
|
1539
1521
|
if (significantDigits !== 1) {
|
|
1540
|
-
while (
|
|
1522
|
+
while (representation[firstNonZero + significantDigits - 1 + Number(sawSign) + Number(sawRadix)] === '0') {
|
|
1541
1523
|
significantDigits = significantDigits - 1;
|
|
1542
1524
|
}
|
|
1543
1525
|
}
|
|
1544
1526
|
}
|
|
1545
|
-
if (exponent <= radixPosition && radixPosition
|
|
1527
|
+
if (exponent <= radixPosition && radixPosition > exponent + (1 << 14)) {
|
|
1546
1528
|
exponent = EXPONENT_MIN;
|
|
1547
1529
|
}
|
|
1548
1530
|
else {
|
|
@@ -1550,9 +1532,8 @@ class Decimal128 extends BSONValue {
|
|
|
1550
1532
|
}
|
|
1551
1533
|
while (exponent > EXPONENT_MAX) {
|
|
1552
1534
|
lastDigit = lastDigit + 1;
|
|
1553
|
-
if (lastDigit
|
|
1554
|
-
|
|
1555
|
-
if (digitsString.match(/^0+$/)) {
|
|
1535
|
+
if (lastDigit >= MAX_DIGITS) {
|
|
1536
|
+
if (significantDigits === 0) {
|
|
1556
1537
|
exponent = EXPONENT_MAX;
|
|
1557
1538
|
break;
|
|
1558
1539
|
}
|
|
@@ -1561,69 +1542,43 @@ class Decimal128 extends BSONValue {
|
|
|
1561
1542
|
exponent = exponent - 1;
|
|
1562
1543
|
}
|
|
1563
1544
|
while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
|
|
1564
|
-
if (lastDigit === 0
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1545
|
+
if (lastDigit === 0) {
|
|
1546
|
+
if (significantDigits === 0) {
|
|
1547
|
+
exponent = EXPONENT_MIN;
|
|
1548
|
+
break;
|
|
1549
|
+
}
|
|
1550
|
+
invalidErr(representation, 'exponent underflow');
|
|
1568
1551
|
}
|
|
1569
1552
|
if (nDigitsStored < nDigits) {
|
|
1553
|
+
if (representation[nDigits - 1 + Number(sawSign) + Number(sawRadix)] !== '0' &&
|
|
1554
|
+
significantDigits !== 0) {
|
|
1555
|
+
invalidErr(representation, 'inexact rounding');
|
|
1556
|
+
}
|
|
1570
1557
|
nDigits = nDigits - 1;
|
|
1571
1558
|
}
|
|
1572
1559
|
else {
|
|
1560
|
+
if (digits[lastDigit] !== 0) {
|
|
1561
|
+
invalidErr(representation, 'inexact rounding');
|
|
1562
|
+
}
|
|
1573
1563
|
lastDigit = lastDigit - 1;
|
|
1574
1564
|
}
|
|
1575
1565
|
if (exponent < EXPONENT_MAX) {
|
|
1576
1566
|
exponent = exponent + 1;
|
|
1577
1567
|
}
|
|
1578
1568
|
else {
|
|
1579
|
-
const digitsString = digits.join('');
|
|
1580
|
-
if (digitsString.match(/^0+$/)) {
|
|
1581
|
-
exponent = EXPONENT_MAX;
|
|
1582
|
-
break;
|
|
1583
|
-
}
|
|
1584
1569
|
invalidErr(representation, 'overflow');
|
|
1585
1570
|
}
|
|
1586
1571
|
}
|
|
1587
|
-
if (lastDigit
|
|
1588
|
-
let endOfString = nDigitsRead;
|
|
1572
|
+
if (lastDigit + 1 < significantDigits) {
|
|
1589
1573
|
if (sawRadix) {
|
|
1590
1574
|
firstNonZero = firstNonZero + 1;
|
|
1591
|
-
endOfString = endOfString + 1;
|
|
1592
1575
|
}
|
|
1593
|
-
if (
|
|
1576
|
+
if (sawSign) {
|
|
1594
1577
|
firstNonZero = firstNonZero + 1;
|
|
1595
|
-
endOfString = endOfString + 1;
|
|
1596
1578
|
}
|
|
1597
1579
|
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
roundBit = 1;
|
|
1601
|
-
if (roundDigit === 5) {
|
|
1602
|
-
roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
|
|
1603
|
-
for (i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
|
|
1604
|
-
if (parseInt(representation[i], 10)) {
|
|
1605
|
-
roundBit = 1;
|
|
1606
|
-
break;
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
if (roundBit) {
|
|
1612
|
-
let dIdx = lastDigit;
|
|
1613
|
-
for (; dIdx >= 0; dIdx--) {
|
|
1614
|
-
if (++digits[dIdx] > 9) {
|
|
1615
|
-
digits[dIdx] = 0;
|
|
1616
|
-
if (dIdx === 0) {
|
|
1617
|
-
if (exponent < EXPONENT_MAX) {
|
|
1618
|
-
exponent = exponent + 1;
|
|
1619
|
-
digits[dIdx] = 1;
|
|
1620
|
-
}
|
|
1621
|
-
else {
|
|
1622
|
-
return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1580
|
+
if (roundDigit !== 0) {
|
|
1581
|
+
invalidErr(representation, 'inexact rounding');
|
|
1627
1582
|
}
|
|
1628
1583
|
}
|
|
1629
1584
|
significandHigh = Long.fromNumber(0);
|
|
@@ -1632,8 +1587,8 @@ class Decimal128 extends BSONValue {
|
|
|
1632
1587
|
significandHigh = Long.fromNumber(0);
|
|
1633
1588
|
significandLow = Long.fromNumber(0);
|
|
1634
1589
|
}
|
|
1635
|
-
else if (lastDigit
|
|
1636
|
-
let dIdx =
|
|
1590
|
+
else if (lastDigit < 17) {
|
|
1591
|
+
let dIdx = 0;
|
|
1637
1592
|
significandLow = Long.fromNumber(digits[dIdx++]);
|
|
1638
1593
|
significandHigh = new Long(0, 0);
|
|
1639
1594
|
for (; dIdx <= lastDigit; dIdx++) {
|
|
@@ -1642,7 +1597,7 @@ class Decimal128 extends BSONValue {
|
|
|
1642
1597
|
}
|
|
1643
1598
|
}
|
|
1644
1599
|
else {
|
|
1645
|
-
let dIdx =
|
|
1600
|
+
let dIdx = 0;
|
|
1646
1601
|
significandHigh = Long.fromNumber(digits[dIdx++]);
|
|
1647
1602
|
for (; dIdx <= lastDigit - 17; dIdx++) {
|
|
1648
1603
|
significandHigh = significandHigh.multiply(Long.fromNumber(10));
|
|
@@ -1990,20 +1945,11 @@ class ObjectId extends BSONValue {
|
|
|
1990
1945
|
this[kId] = ByteUtils.toLocalBufferType(workingId);
|
|
1991
1946
|
}
|
|
1992
1947
|
else if (typeof workingId === 'string') {
|
|
1993
|
-
if (workingId.length ===
|
|
1994
|
-
const bytes = ByteUtils.fromUTF8(workingId);
|
|
1995
|
-
if (bytes.byteLength === 12) {
|
|
1996
|
-
this[kId] = bytes;
|
|
1997
|
-
}
|
|
1998
|
-
else {
|
|
1999
|
-
throw new BSONError('Argument passed in must be a string of 12 bytes');
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
else if (workingId.length === 24 && checkForHexRegExp.test(workingId)) {
|
|
1948
|
+
if (workingId.length === 24 && checkForHexRegExp.test(workingId)) {
|
|
2003
1949
|
this[kId] = ByteUtils.fromHex(workingId);
|
|
2004
1950
|
}
|
|
2005
1951
|
else {
|
|
2006
|
-
throw new BSONError('
|
|
1952
|
+
throw new BSONError('input must be a 24 character hex string, 12 byte Uint8Array, or an integer');
|
|
2007
1953
|
}
|
|
2008
1954
|
}
|
|
2009
1955
|
else {
|
|
@@ -2065,30 +2011,25 @@ class ObjectId extends BSONValue {
|
|
|
2065
2011
|
toJSON() {
|
|
2066
2012
|
return this.toHexString();
|
|
2067
2013
|
}
|
|
2014
|
+
static is(variable) {
|
|
2015
|
+
return (variable != null &&
|
|
2016
|
+
typeof variable === 'object' &&
|
|
2017
|
+
'_bsontype' in variable &&
|
|
2018
|
+
variable._bsontype === 'ObjectId');
|
|
2019
|
+
}
|
|
2068
2020
|
equals(otherId) {
|
|
2069
2021
|
if (otherId === undefined || otherId === null) {
|
|
2070
2022
|
return false;
|
|
2071
2023
|
}
|
|
2072
|
-
if (otherId
|
|
2024
|
+
if (ObjectId.is(otherId)) {
|
|
2073
2025
|
return this[kId][11] === otherId[kId][11] && ByteUtils.equals(this[kId], otherId[kId]);
|
|
2074
2026
|
}
|
|
2075
|
-
if (typeof otherId === 'string'
|
|
2076
|
-
ObjectId.isValid(otherId) &&
|
|
2077
|
-
otherId.length === 12 &&
|
|
2078
|
-
isUint8Array(this.id)) {
|
|
2079
|
-
return ByteUtils.equals(this.id, ByteUtils.fromISO88591(otherId));
|
|
2080
|
-
}
|
|
2081
|
-
if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 24) {
|
|
2027
|
+
if (typeof otherId === 'string') {
|
|
2082
2028
|
return otherId.toLowerCase() === this.toHexString();
|
|
2083
2029
|
}
|
|
2084
|
-
if (typeof otherId === '
|
|
2085
|
-
return ByteUtils.equals(ByteUtils.fromUTF8(otherId), this.id);
|
|
2086
|
-
}
|
|
2087
|
-
if (typeof otherId === 'object' &&
|
|
2088
|
-
'toHexString' in otherId &&
|
|
2089
|
-
typeof otherId.toHexString === 'function') {
|
|
2030
|
+
if (typeof otherId === 'object' && typeof otherId.toHexString === 'function') {
|
|
2090
2031
|
const otherIdString = otherId.toHexString();
|
|
2091
|
-
const thisIdString = this.toHexString()
|
|
2032
|
+
const thisIdString = this.toHexString();
|
|
2092
2033
|
return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;
|
|
2093
2034
|
}
|
|
2094
2035
|
return false;
|
|
@@ -2378,7 +2319,7 @@ class BSONSymbol extends BSONValue {
|
|
|
2378
2319
|
return this.value;
|
|
2379
2320
|
}
|
|
2380
2321
|
inspect() {
|
|
2381
|
-
return `new BSONSymbol(
|
|
2322
|
+
return `new BSONSymbol(${JSON.stringify(this.value)})`;
|
|
2382
2323
|
}
|
|
2383
2324
|
toJSON() {
|
|
2384
2325
|
return this.value;
|
|
@@ -2416,19 +2357,21 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
2416
2357
|
if (typeof low.i !== 'number' && (typeof low.i !== 'object' || low.i._bsontype !== 'Int32')) {
|
|
2417
2358
|
throw new BSONError('Timestamp constructed from { t, i } must provide i as a number');
|
|
2418
2359
|
}
|
|
2419
|
-
|
|
2360
|
+
const t = Number(low.t);
|
|
2361
|
+
const i = Number(low.i);
|
|
2362
|
+
if (t < 0 || Number.isNaN(t)) {
|
|
2420
2363
|
throw new BSONError('Timestamp constructed from { t, i } must provide a positive t');
|
|
2421
2364
|
}
|
|
2422
|
-
if (
|
|
2365
|
+
if (i < 0 || Number.isNaN(i)) {
|
|
2423
2366
|
throw new BSONError('Timestamp constructed from { t, i } must provide a positive i');
|
|
2424
2367
|
}
|
|
2425
|
-
if (
|
|
2368
|
+
if (t > 4294967295) {
|
|
2426
2369
|
throw new BSONError('Timestamp constructed from { t, i } must provide t equal or less than uint32 max');
|
|
2427
2370
|
}
|
|
2428
|
-
if (
|
|
2371
|
+
if (i > 4294967295) {
|
|
2429
2372
|
throw new BSONError('Timestamp constructed from { t, i } must provide i equal or less than uint32 max');
|
|
2430
2373
|
}
|
|
2431
|
-
super(
|
|
2374
|
+
super(i, t, true);
|
|
2432
2375
|
}
|
|
2433
2376
|
else {
|
|
2434
2377
|
throw new BSONError('A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }');
|
|
@@ -2600,7 +2543,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2600
2543
|
}
|
|
2601
2544
|
if (i >= buffer.byteLength)
|
|
2602
2545
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2603
|
-
const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer
|
|
2546
|
+
const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer, index, i);
|
|
2604
2547
|
let shouldValidateKey = true;
|
|
2605
2548
|
if (globalUTFValidation || utf8KeysSet.has(name)) {
|
|
2606
2549
|
shouldValidateKey = validationSetting;
|
|
@@ -2815,7 +2758,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2815
2758
|
}
|
|
2816
2759
|
if (i >= buffer.length)
|
|
2817
2760
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2818
|
-
const source = ByteUtils.toUTF8(buffer
|
|
2761
|
+
const source = ByteUtils.toUTF8(buffer, index, i);
|
|
2819
2762
|
index = i + 1;
|
|
2820
2763
|
i = index;
|
|
2821
2764
|
while (buffer[i] !== 0x00 && i < buffer.length) {
|
|
@@ -2823,7 +2766,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2823
2766
|
}
|
|
2824
2767
|
if (i >= buffer.length)
|
|
2825
2768
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2826
|
-
const regExpOptions = ByteUtils.toUTF8(buffer
|
|
2769
|
+
const regExpOptions = ByteUtils.toUTF8(buffer, index, i);
|
|
2827
2770
|
index = i + 1;
|
|
2828
2771
|
const optionsArray = new Array(regExpOptions.length);
|
|
2829
2772
|
for (i = 0; i < regExpOptions.length; i++) {
|
|
@@ -2848,7 +2791,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2848
2791
|
}
|
|
2849
2792
|
if (i >= buffer.length)
|
|
2850
2793
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2851
|
-
const source = ByteUtils.toUTF8(buffer
|
|
2794
|
+
const source = ByteUtils.toUTF8(buffer, index, i);
|
|
2852
2795
|
index = i + 1;
|
|
2853
2796
|
i = index;
|
|
2854
2797
|
while (buffer[i] !== 0x00 && i < buffer.length) {
|
|
@@ -2856,7 +2799,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2856
2799
|
}
|
|
2857
2800
|
if (i >= buffer.length)
|
|
2858
2801
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2859
|
-
const regExpOptions = ByteUtils.toUTF8(buffer
|
|
2802
|
+
const regExpOptions = ByteUtils.toUTF8(buffer, index, i);
|
|
2860
2803
|
index = i + 1;
|
|
2861
2804
|
value = new BSONRegExp(source, regExpOptions);
|
|
2862
2805
|
}
|
|
@@ -2953,7 +2896,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2953
2896
|
throw new BSONError('Invalid UTF-8 string in BSON document');
|
|
2954
2897
|
}
|
|
2955
2898
|
}
|
|
2956
|
-
const namespace = ByteUtils.toUTF8(buffer
|
|
2899
|
+
const namespace = ByteUtils.toUTF8(buffer, index, index + stringSize - 1);
|
|
2957
2900
|
index = index + stringSize;
|
|
2958
2901
|
const oidBuffer = ByteUtils.allocate(12);
|
|
2959
2902
|
oidBuffer.set(buffer.subarray(index, index + 12), 0);
|
|
@@ -2993,7 +2936,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2993
2936
|
return object;
|
|
2994
2937
|
}
|
|
2995
2938
|
function getValidatedString(buffer, start, end, shouldValidateUtf8) {
|
|
2996
|
-
const value = ByteUtils.toUTF8(buffer
|
|
2939
|
+
const value = ByteUtils.toUTF8(buffer, start, end);
|
|
2997
2940
|
if (shouldValidateUtf8) {
|
|
2998
2941
|
for (let i = 0; i < value.length; i++) {
|
|
2999
2942
|
if (value.charCodeAt(i) === 0xfffd) {
|