bson 5.3.0 → 5.5.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 +4 -11
- package/bson.d.ts +20 -0
- package/lib/bson.bundle.js +137 -86
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +137 -86
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +137 -86
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.rn.cjs +4159 -0
- package/lib/bson.rn.cjs.map +1 -0
- package/package.json +8 -7
- package/src/binary.ts +3 -2
- package/src/bson.ts +2 -2
- package/src/decimal128.ts +165 -84
- package/src/parser/deserializer.ts +8 -8
- package/src/timestamp.ts +7 -5
- package/src/utils/byte_utils.ts +1 -1
- 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/README.md
CHANGED
|
@@ -188,23 +188,16 @@ try {
|
|
|
188
188
|
|
|
189
189
|
## React Native
|
|
190
190
|
|
|
191
|
-
BSON
|
|
191
|
+
BSON vendors the required polyfills for `TextEncoder`, `TextDecoder`, `atob`, `btoa` imported from React Native and therefore doesn't expect users to polyfill these. One additional polyfill, `crypto.getRandomValues` is recommended and can be installed with the following command:
|
|
192
|
+
|
|
192
193
|
```sh
|
|
193
|
-
npm install --save react-native-get-random-values
|
|
194
|
+
npm install --save react-native-get-random-values
|
|
194
195
|
```
|
|
195
196
|
|
|
196
197
|
The following snippet should be placed at the top of the entrypoint (by default this is the root `index.js` file) for React Native projects using the BSON library. These lines must be placed for any code that imports `BSON`.
|
|
197
198
|
|
|
198
199
|
```typescript
|
|
199
200
|
// Required Polyfills For ReactNative
|
|
200
|
-
import {encode, decode} from 'base-64';
|
|
201
|
-
if (global.btoa == null) {
|
|
202
|
-
global.btoa = encode;
|
|
203
|
-
}
|
|
204
|
-
if (global.atob == null) {
|
|
205
|
-
global.atob = decode;
|
|
206
|
-
}
|
|
207
|
-
import 'text-encoding-polyfill';
|
|
208
201
|
import 'react-native-get-random-values';
|
|
209
202
|
```
|
|
210
203
|
|
|
@@ -214,7 +207,7 @@ Finally, import the `BSON` library like so:
|
|
|
214
207
|
import { BSON, EJSON } from 'bson';
|
|
215
208
|
```
|
|
216
209
|
|
|
217
|
-
This will cause React Native to import the `node_modules/bson/lib/bson.cjs` bundle (see the `"react-native"` setting we have in the `"exports"` section of our [package.json](./package.json).)
|
|
210
|
+
This will cause React Native to import the `node_modules/bson/lib/bson.rn.cjs` bundle (see the `"react-native"` setting we have in the `"exports"` section of our [package.json](./package.json).)
|
|
218
211
|
|
|
219
212
|
### Technical Note about React Native module import
|
|
220
213
|
|
package/bson.d.ts
CHANGED
|
@@ -392,6 +392,26 @@ export declare class Decimal128 extends BSONValue {
|
|
|
392
392
|
* @param representation - a numeric string representation.
|
|
393
393
|
*/
|
|
394
394
|
static fromString(representation: string): Decimal128;
|
|
395
|
+
/**
|
|
396
|
+
* Create a Decimal128 instance from a string representation, allowing for rounding to 34
|
|
397
|
+
* significant digits
|
|
398
|
+
*
|
|
399
|
+
* @example Example of a number that will be rounded
|
|
400
|
+
* ```ts
|
|
401
|
+
* > let d = Decimal128.fromString('37.499999999999999196428571428571375')
|
|
402
|
+
* Uncaught:
|
|
403
|
+
* BSONError: "37.499999999999999196428571428571375" is not a valid Decimal128 string - inexact rounding
|
|
404
|
+
* at invalidErr (/home/wajames/js-bson/lib/bson.cjs:1402:11)
|
|
405
|
+
* at Decimal128.fromStringInternal (/home/wajames/js-bson/lib/bson.cjs:1633:25)
|
|
406
|
+
* at Decimal128.fromString (/home/wajames/js-bson/lib/bson.cjs:1424:27)
|
|
407
|
+
*
|
|
408
|
+
* > d = Decimal128.fromStringWithRounding('37.499999999999999196428571428571375')
|
|
409
|
+
* new Decimal128("37.49999999999999919642857142857138")
|
|
410
|
+
* ```
|
|
411
|
+
* @param representation - a numeric string representation.
|
|
412
|
+
*/
|
|
413
|
+
static fromStringWithRounding(representation: string): Decimal128;
|
|
414
|
+
private static _fromString;
|
|
395
415
|
/** Create a string representation of the raw Decimal128 value */
|
|
396
416
|
toString(): string;
|
|
397
417
|
toJSON(): Decimal128Extended;
|
package/lib/bson.bundle.js
CHANGED
|
@@ -166,8 +166,8 @@ const nodeJsByteUtils = {
|
|
|
166
166
|
fromUTF8(text) {
|
|
167
167
|
return Buffer.from(text, 'utf8');
|
|
168
168
|
},
|
|
169
|
-
toUTF8(buffer) {
|
|
170
|
-
return nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8');
|
|
169
|
+
toUTF8(buffer, start, end) {
|
|
170
|
+
return nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8', start, end);
|
|
171
171
|
},
|
|
172
172
|
utf8ByteLength(input) {
|
|
173
173
|
return Buffer.byteLength(input, 'utf8');
|
|
@@ -277,8 +277,8 @@ const webByteUtils = {
|
|
|
277
277
|
fromUTF8(text) {
|
|
278
278
|
return new TextEncoder().encode(text);
|
|
279
279
|
},
|
|
280
|
-
toUTF8(uint8array) {
|
|
281
|
-
return new TextDecoder('utf8', { fatal: false }).decode(uint8array);
|
|
280
|
+
toUTF8(uint8array, start, end) {
|
|
281
|
+
return new TextDecoder('utf8', { fatal: false }).decode(uint8array.slice(start, end));
|
|
282
282
|
},
|
|
283
283
|
utf8ByteLength(input) {
|
|
284
284
|
return webByteUtils.fromUTF8(input).byteLength;
|
|
@@ -410,8 +410,8 @@ class Binary extends BSONValue {
|
|
|
410
410
|
if (encoding === 'base64')
|
|
411
411
|
return ByteUtils.toBase64(this.buffer);
|
|
412
412
|
if (encoding === 'utf8' || encoding === 'utf-8')
|
|
413
|
-
return ByteUtils.toUTF8(this.buffer);
|
|
414
|
-
return ByteUtils.toUTF8(this.buffer);
|
|
413
|
+
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
|
|
414
|
+
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
|
|
415
415
|
}
|
|
416
416
|
toExtendedJSON(options) {
|
|
417
417
|
options = options || {};
|
|
@@ -1437,7 +1437,14 @@ class Decimal128 extends BSONValue {
|
|
|
1437
1437
|
}
|
|
1438
1438
|
}
|
|
1439
1439
|
static fromString(representation) {
|
|
1440
|
+
return Decimal128._fromString(representation, { allowRounding: false });
|
|
1441
|
+
}
|
|
1442
|
+
static fromStringWithRounding(representation) {
|
|
1443
|
+
return Decimal128._fromString(representation, { allowRounding: true });
|
|
1444
|
+
}
|
|
1445
|
+
static _fromString(representation, options) {
|
|
1440
1446
|
let isNegative = false;
|
|
1447
|
+
let sawSign = false;
|
|
1441
1448
|
let sawRadix = false;
|
|
1442
1449
|
let foundNonZero = false;
|
|
1443
1450
|
let significantDigits = 0;
|
|
@@ -1448,10 +1455,8 @@ class Decimal128 extends BSONValue {
|
|
|
1448
1455
|
const digits = [0];
|
|
1449
1456
|
let nDigitsStored = 0;
|
|
1450
1457
|
let digitsInsert = 0;
|
|
1451
|
-
let firstDigit = 0;
|
|
1452
1458
|
let lastDigit = 0;
|
|
1453
1459
|
let exponent = 0;
|
|
1454
|
-
let i = 0;
|
|
1455
1460
|
let significandHigh = new Long(0, 0);
|
|
1456
1461
|
let significandLow = new Long(0, 0);
|
|
1457
1462
|
let biasedExponent = 0;
|
|
@@ -1479,6 +1484,7 @@ class Decimal128 extends BSONValue {
|
|
|
1479
1484
|
}
|
|
1480
1485
|
}
|
|
1481
1486
|
if (representation[index] === '+' || representation[index] === '-') {
|
|
1487
|
+
sawSign = true;
|
|
1482
1488
|
isNegative = representation[index++] === '-';
|
|
1483
1489
|
}
|
|
1484
1490
|
if (!isDigit(representation[index]) && representation[index] !== '.') {
|
|
@@ -1497,7 +1503,7 @@ class Decimal128 extends BSONValue {
|
|
|
1497
1503
|
index = index + 1;
|
|
1498
1504
|
continue;
|
|
1499
1505
|
}
|
|
1500
|
-
if (nDigitsStored <
|
|
1506
|
+
if (nDigitsStored < MAX_DIGITS) {
|
|
1501
1507
|
if (representation[index] !== '0' || foundNonZero) {
|
|
1502
1508
|
if (!foundNonZero) {
|
|
1503
1509
|
firstNonZero = nDigitsRead;
|
|
@@ -1525,10 +1531,7 @@ class Decimal128 extends BSONValue {
|
|
|
1525
1531
|
}
|
|
1526
1532
|
if (representation[index])
|
|
1527
1533
|
return new Decimal128(NAN_BUFFER);
|
|
1528
|
-
firstDigit = 0;
|
|
1529
1534
|
if (!nDigitsStored) {
|
|
1530
|
-
firstDigit = 0;
|
|
1531
|
-
lastDigit = 0;
|
|
1532
1535
|
digits[0] = 0;
|
|
1533
1536
|
nDigits = 1;
|
|
1534
1537
|
nDigitsStored = 1;
|
|
@@ -1538,12 +1541,12 @@ class Decimal128 extends BSONValue {
|
|
|
1538
1541
|
lastDigit = nDigitsStored - 1;
|
|
1539
1542
|
significantDigits = nDigits;
|
|
1540
1543
|
if (significantDigits !== 1) {
|
|
1541
|
-
while (
|
|
1544
|
+
while (representation[firstNonZero + significantDigits - 1 + Number(sawSign) + Number(sawRadix)] === '0') {
|
|
1542
1545
|
significantDigits = significantDigits - 1;
|
|
1543
1546
|
}
|
|
1544
1547
|
}
|
|
1545
1548
|
}
|
|
1546
|
-
if (exponent <= radixPosition && radixPosition
|
|
1549
|
+
if (exponent <= radixPosition && radixPosition > exponent + (1 << 14)) {
|
|
1547
1550
|
exponent = EXPONENT_MIN;
|
|
1548
1551
|
}
|
|
1549
1552
|
else {
|
|
@@ -1551,9 +1554,8 @@ class Decimal128 extends BSONValue {
|
|
|
1551
1554
|
}
|
|
1552
1555
|
while (exponent > EXPONENT_MAX) {
|
|
1553
1556
|
lastDigit = lastDigit + 1;
|
|
1554
|
-
if (lastDigit
|
|
1555
|
-
|
|
1556
|
-
if (digitsString.match(/^0+$/)) {
|
|
1557
|
+
if (lastDigit >= MAX_DIGITS) {
|
|
1558
|
+
if (significantDigits === 0) {
|
|
1557
1559
|
exponent = EXPONENT_MAX;
|
|
1558
1560
|
break;
|
|
1559
1561
|
}
|
|
@@ -1561,69 +1563,116 @@ class Decimal128 extends BSONValue {
|
|
|
1561
1563
|
}
|
|
1562
1564
|
exponent = exponent - 1;
|
|
1563
1565
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
}
|
|
1570
|
-
if (nDigitsStored < nDigits) {
|
|
1571
|
-
nDigits = nDigits - 1;
|
|
1572
|
-
}
|
|
1573
|
-
else {
|
|
1574
|
-
lastDigit = lastDigit - 1;
|
|
1575
|
-
}
|
|
1576
|
-
if (exponent < EXPONENT_MAX) {
|
|
1577
|
-
exponent = exponent + 1;
|
|
1578
|
-
}
|
|
1579
|
-
else {
|
|
1580
|
-
const digitsString = digits.join('');
|
|
1581
|
-
if (digitsString.match(/^0+$/)) {
|
|
1582
|
-
exponent = EXPONENT_MAX;
|
|
1566
|
+
if (options.allowRounding) {
|
|
1567
|
+
while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
|
|
1568
|
+
if (lastDigit === 0 && significantDigits < nDigitsStored) {
|
|
1569
|
+
exponent = EXPONENT_MIN;
|
|
1570
|
+
significantDigits = 0;
|
|
1583
1571
|
break;
|
|
1584
1572
|
}
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
let roundBit = 0;
|
|
1600
|
-
if (roundDigit >= 5) {
|
|
1601
|
-
roundBit = 1;
|
|
1602
|
-
if (roundDigit === 5) {
|
|
1603
|
-
roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
|
|
1604
|
-
for (i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
|
|
1605
|
-
if (parseInt(representation[i], 10)) {
|
|
1606
|
-
roundBit = 1;
|
|
1607
|
-
break;
|
|
1608
|
-
}
|
|
1573
|
+
if (nDigitsStored < nDigits) {
|
|
1574
|
+
nDigits = nDigits - 1;
|
|
1575
|
+
}
|
|
1576
|
+
else {
|
|
1577
|
+
lastDigit = lastDigit - 1;
|
|
1578
|
+
}
|
|
1579
|
+
if (exponent < EXPONENT_MAX) {
|
|
1580
|
+
exponent = exponent + 1;
|
|
1581
|
+
}
|
|
1582
|
+
else {
|
|
1583
|
+
const digitsString = digits.join('');
|
|
1584
|
+
if (digitsString.match(/^0+$/)) {
|
|
1585
|
+
exponent = EXPONENT_MAX;
|
|
1586
|
+
break;
|
|
1609
1587
|
}
|
|
1588
|
+
invalidErr(representation, 'overflow');
|
|
1610
1589
|
}
|
|
1611
1590
|
}
|
|
1612
|
-
if (
|
|
1613
|
-
let
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1591
|
+
if (lastDigit + 1 < significantDigits) {
|
|
1592
|
+
let endOfString = nDigitsRead;
|
|
1593
|
+
if (sawRadix) {
|
|
1594
|
+
firstNonZero = firstNonZero + 1;
|
|
1595
|
+
endOfString = endOfString + 1;
|
|
1596
|
+
}
|
|
1597
|
+
if (sawSign) {
|
|
1598
|
+
firstNonZero = firstNonZero + 1;
|
|
1599
|
+
endOfString = endOfString + 1;
|
|
1600
|
+
}
|
|
1601
|
+
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
|
|
1602
|
+
let roundBit = 0;
|
|
1603
|
+
if (roundDigit >= 5) {
|
|
1604
|
+
roundBit = 1;
|
|
1605
|
+
if (roundDigit === 5) {
|
|
1606
|
+
roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
|
|
1607
|
+
for (let i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
|
|
1608
|
+
if (parseInt(representation[i], 10)) {
|
|
1609
|
+
roundBit = 1;
|
|
1610
|
+
break;
|
|
1621
1611
|
}
|
|
1622
|
-
|
|
1623
|
-
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
if (roundBit) {
|
|
1616
|
+
let dIdx = lastDigit;
|
|
1617
|
+
for (; dIdx >= 0; dIdx--) {
|
|
1618
|
+
if (++digits[dIdx] > 9) {
|
|
1619
|
+
digits[dIdx] = 0;
|
|
1620
|
+
if (dIdx === 0) {
|
|
1621
|
+
if (exponent < EXPONENT_MAX) {
|
|
1622
|
+
exponent = exponent + 1;
|
|
1623
|
+
digits[dIdx] = 1;
|
|
1624
|
+
}
|
|
1625
|
+
else {
|
|
1626
|
+
return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
|
|
1627
|
+
}
|
|
1624
1628
|
}
|
|
1625
1629
|
}
|
|
1630
|
+
else {
|
|
1631
|
+
break;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
else {
|
|
1638
|
+
while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
|
|
1639
|
+
if (lastDigit === 0) {
|
|
1640
|
+
if (significantDigits === 0) {
|
|
1641
|
+
exponent = EXPONENT_MIN;
|
|
1642
|
+
break;
|
|
1626
1643
|
}
|
|
1644
|
+
invalidErr(representation, 'exponent underflow');
|
|
1645
|
+
}
|
|
1646
|
+
if (nDigitsStored < nDigits) {
|
|
1647
|
+
if (representation[nDigits - 1 + Number(sawSign) + Number(sawRadix)] !== '0' &&
|
|
1648
|
+
significantDigits !== 0) {
|
|
1649
|
+
invalidErr(representation, 'inexact rounding');
|
|
1650
|
+
}
|
|
1651
|
+
nDigits = nDigits - 1;
|
|
1652
|
+
}
|
|
1653
|
+
else {
|
|
1654
|
+
if (digits[lastDigit] !== 0) {
|
|
1655
|
+
invalidErr(representation, 'inexact rounding');
|
|
1656
|
+
}
|
|
1657
|
+
lastDigit = lastDigit - 1;
|
|
1658
|
+
}
|
|
1659
|
+
if (exponent < EXPONENT_MAX) {
|
|
1660
|
+
exponent = exponent + 1;
|
|
1661
|
+
}
|
|
1662
|
+
else {
|
|
1663
|
+
invalidErr(representation, 'overflow');
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
if (lastDigit + 1 < significantDigits) {
|
|
1667
|
+
if (sawRadix) {
|
|
1668
|
+
firstNonZero = firstNonZero + 1;
|
|
1669
|
+
}
|
|
1670
|
+
if (sawSign) {
|
|
1671
|
+
firstNonZero = firstNonZero + 1;
|
|
1672
|
+
}
|
|
1673
|
+
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
|
|
1674
|
+
if (roundDigit !== 0) {
|
|
1675
|
+
invalidErr(representation, 'inexact rounding');
|
|
1627
1676
|
}
|
|
1628
1677
|
}
|
|
1629
1678
|
}
|
|
@@ -1633,8 +1682,8 @@ class Decimal128 extends BSONValue {
|
|
|
1633
1682
|
significandHigh = Long.fromNumber(0);
|
|
1634
1683
|
significandLow = Long.fromNumber(0);
|
|
1635
1684
|
}
|
|
1636
|
-
else if (lastDigit
|
|
1637
|
-
let dIdx =
|
|
1685
|
+
else if (lastDigit < 17) {
|
|
1686
|
+
let dIdx = 0;
|
|
1638
1687
|
significandLow = Long.fromNumber(digits[dIdx++]);
|
|
1639
1688
|
significandHigh = new Long(0, 0);
|
|
1640
1689
|
for (; dIdx <= lastDigit; dIdx++) {
|
|
@@ -1643,7 +1692,7 @@ class Decimal128 extends BSONValue {
|
|
|
1643
1692
|
}
|
|
1644
1693
|
}
|
|
1645
1694
|
else {
|
|
1646
|
-
let dIdx =
|
|
1695
|
+
let dIdx = 0;
|
|
1647
1696
|
significandHigh = Long.fromNumber(digits[dIdx++]);
|
|
1648
1697
|
for (; dIdx <= lastDigit - 17; dIdx++) {
|
|
1649
1698
|
significandHigh = significandHigh.multiply(Long.fromNumber(10));
|
|
@@ -2417,19 +2466,21 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
2417
2466
|
if (typeof low.i !== 'number' && (typeof low.i !== 'object' || low.i._bsontype !== 'Int32')) {
|
|
2418
2467
|
throw new BSONError('Timestamp constructed from { t, i } must provide i as a number');
|
|
2419
2468
|
}
|
|
2420
|
-
|
|
2469
|
+
const t = Number(low.t);
|
|
2470
|
+
const i = Number(low.i);
|
|
2471
|
+
if (t < 0 || Number.isNaN(t)) {
|
|
2421
2472
|
throw new BSONError('Timestamp constructed from { t, i } must provide a positive t');
|
|
2422
2473
|
}
|
|
2423
|
-
if (
|
|
2474
|
+
if (i < 0 || Number.isNaN(i)) {
|
|
2424
2475
|
throw new BSONError('Timestamp constructed from { t, i } must provide a positive i');
|
|
2425
2476
|
}
|
|
2426
|
-
if (
|
|
2477
|
+
if (t > 4294967295) {
|
|
2427
2478
|
throw new BSONError('Timestamp constructed from { t, i } must provide t equal or less than uint32 max');
|
|
2428
2479
|
}
|
|
2429
|
-
if (
|
|
2480
|
+
if (i > 4294967295) {
|
|
2430
2481
|
throw new BSONError('Timestamp constructed from { t, i } must provide i equal or less than uint32 max');
|
|
2431
2482
|
}
|
|
2432
|
-
super(
|
|
2483
|
+
super(i, t, true);
|
|
2433
2484
|
}
|
|
2434
2485
|
else {
|
|
2435
2486
|
throw new BSONError('A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }');
|
|
@@ -2601,7 +2652,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2601
2652
|
}
|
|
2602
2653
|
if (i >= buffer.byteLength)
|
|
2603
2654
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2604
|
-
const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer
|
|
2655
|
+
const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer, index, i);
|
|
2605
2656
|
let shouldValidateKey = true;
|
|
2606
2657
|
if (globalUTFValidation || utf8KeysSet.has(name)) {
|
|
2607
2658
|
shouldValidateKey = validationSetting;
|
|
@@ -2816,7 +2867,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2816
2867
|
}
|
|
2817
2868
|
if (i >= buffer.length)
|
|
2818
2869
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2819
|
-
const source = ByteUtils.toUTF8(buffer
|
|
2870
|
+
const source = ByteUtils.toUTF8(buffer, index, i);
|
|
2820
2871
|
index = i + 1;
|
|
2821
2872
|
i = index;
|
|
2822
2873
|
while (buffer[i] !== 0x00 && i < buffer.length) {
|
|
@@ -2824,7 +2875,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2824
2875
|
}
|
|
2825
2876
|
if (i >= buffer.length)
|
|
2826
2877
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2827
|
-
const regExpOptions = ByteUtils.toUTF8(buffer
|
|
2878
|
+
const regExpOptions = ByteUtils.toUTF8(buffer, index, i);
|
|
2828
2879
|
index = i + 1;
|
|
2829
2880
|
const optionsArray = new Array(regExpOptions.length);
|
|
2830
2881
|
for (i = 0; i < regExpOptions.length; i++) {
|
|
@@ -2849,7 +2900,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2849
2900
|
}
|
|
2850
2901
|
if (i >= buffer.length)
|
|
2851
2902
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2852
|
-
const source = ByteUtils.toUTF8(buffer
|
|
2903
|
+
const source = ByteUtils.toUTF8(buffer, index, i);
|
|
2853
2904
|
index = i + 1;
|
|
2854
2905
|
i = index;
|
|
2855
2906
|
while (buffer[i] !== 0x00 && i < buffer.length) {
|
|
@@ -2857,7 +2908,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2857
2908
|
}
|
|
2858
2909
|
if (i >= buffer.length)
|
|
2859
2910
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2860
|
-
const regExpOptions = ByteUtils.toUTF8(buffer
|
|
2911
|
+
const regExpOptions = ByteUtils.toUTF8(buffer, index, i);
|
|
2861
2912
|
index = i + 1;
|
|
2862
2913
|
value = new BSONRegExp(source, regExpOptions);
|
|
2863
2914
|
}
|
|
@@ -2954,7 +3005,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2954
3005
|
throw new BSONError('Invalid UTF-8 string in BSON document');
|
|
2955
3006
|
}
|
|
2956
3007
|
}
|
|
2957
|
-
const namespace = ByteUtils.toUTF8(buffer
|
|
3008
|
+
const namespace = ByteUtils.toUTF8(buffer, index, index + stringSize - 1);
|
|
2958
3009
|
index = index + stringSize;
|
|
2959
3010
|
const oidBuffer = ByteUtils.allocate(12);
|
|
2960
3011
|
oidBuffer.set(buffer.subarray(index, index + 12), 0);
|
|
@@ -2994,7 +3045,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2994
3045
|
return object;
|
|
2995
3046
|
}
|
|
2996
3047
|
function getValidatedString(buffer, start, end, shouldValidateUtf8) {
|
|
2997
|
-
const value = ByteUtils.toUTF8(buffer
|
|
3048
|
+
const value = ByteUtils.toUTF8(buffer, start, end);
|
|
2998
3049
|
if (shouldValidateUtf8) {
|
|
2999
3050
|
for (let i = 0; i < value.length; i++) {
|
|
3000
3051
|
if (value.charCodeAt(i) === 0xfffd) {
|