bson 5.3.0 → 5.4.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/lib/bson.bundle.js +20 -18
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +20 -18
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +20 -18
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.rn.cjs +4110 -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/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/lib/bson.mjs
CHANGED
|
@@ -163,8 +163,8 @@ const nodeJsByteUtils = {
|
|
|
163
163
|
fromUTF8(text) {
|
|
164
164
|
return Buffer.from(text, 'utf8');
|
|
165
165
|
},
|
|
166
|
-
toUTF8(buffer) {
|
|
167
|
-
return nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8');
|
|
166
|
+
toUTF8(buffer, start, end) {
|
|
167
|
+
return nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8', start, end);
|
|
168
168
|
},
|
|
169
169
|
utf8ByteLength(input) {
|
|
170
170
|
return Buffer.byteLength(input, 'utf8');
|
|
@@ -274,8 +274,8 @@ const webByteUtils = {
|
|
|
274
274
|
fromUTF8(text) {
|
|
275
275
|
return new TextEncoder().encode(text);
|
|
276
276
|
},
|
|
277
|
-
toUTF8(uint8array) {
|
|
278
|
-
return new TextDecoder('utf8', { fatal: false }).decode(uint8array);
|
|
277
|
+
toUTF8(uint8array, start, end) {
|
|
278
|
+
return new TextDecoder('utf8', { fatal: false }).decode(uint8array.slice(start, end));
|
|
279
279
|
},
|
|
280
280
|
utf8ByteLength(input) {
|
|
281
281
|
return webByteUtils.fromUTF8(input).byteLength;
|
|
@@ -407,8 +407,8 @@ class Binary extends BSONValue {
|
|
|
407
407
|
if (encoding === 'base64')
|
|
408
408
|
return ByteUtils.toBase64(this.buffer);
|
|
409
409
|
if (encoding === 'utf8' || encoding === 'utf-8')
|
|
410
|
-
return ByteUtils.toUTF8(this.buffer);
|
|
411
|
-
return ByteUtils.toUTF8(this.buffer);
|
|
410
|
+
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
|
|
411
|
+
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
|
|
412
412
|
}
|
|
413
413
|
toExtendedJSON(options) {
|
|
414
414
|
options = options || {};
|
|
@@ -2414,19 +2414,21 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
2414
2414
|
if (typeof low.i !== 'number' && (typeof low.i !== 'object' || low.i._bsontype !== 'Int32')) {
|
|
2415
2415
|
throw new BSONError('Timestamp constructed from { t, i } must provide i as a number');
|
|
2416
2416
|
}
|
|
2417
|
-
|
|
2417
|
+
const t = Number(low.t);
|
|
2418
|
+
const i = Number(low.i);
|
|
2419
|
+
if (t < 0 || Number.isNaN(t)) {
|
|
2418
2420
|
throw new BSONError('Timestamp constructed from { t, i } must provide a positive t');
|
|
2419
2421
|
}
|
|
2420
|
-
if (
|
|
2422
|
+
if (i < 0 || Number.isNaN(i)) {
|
|
2421
2423
|
throw new BSONError('Timestamp constructed from { t, i } must provide a positive i');
|
|
2422
2424
|
}
|
|
2423
|
-
if (
|
|
2425
|
+
if (t > 4294967295) {
|
|
2424
2426
|
throw new BSONError('Timestamp constructed from { t, i } must provide t equal or less than uint32 max');
|
|
2425
2427
|
}
|
|
2426
|
-
if (
|
|
2428
|
+
if (i > 4294967295) {
|
|
2427
2429
|
throw new BSONError('Timestamp constructed from { t, i } must provide i equal or less than uint32 max');
|
|
2428
2430
|
}
|
|
2429
|
-
super(
|
|
2431
|
+
super(i, t, true);
|
|
2430
2432
|
}
|
|
2431
2433
|
else {
|
|
2432
2434
|
throw new BSONError('A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }');
|
|
@@ -2598,7 +2600,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2598
2600
|
}
|
|
2599
2601
|
if (i >= buffer.byteLength)
|
|
2600
2602
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2601
|
-
const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer
|
|
2603
|
+
const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer, index, i);
|
|
2602
2604
|
let shouldValidateKey = true;
|
|
2603
2605
|
if (globalUTFValidation || utf8KeysSet.has(name)) {
|
|
2604
2606
|
shouldValidateKey = validationSetting;
|
|
@@ -2813,7 +2815,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2813
2815
|
}
|
|
2814
2816
|
if (i >= buffer.length)
|
|
2815
2817
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2816
|
-
const source = ByteUtils.toUTF8(buffer
|
|
2818
|
+
const source = ByteUtils.toUTF8(buffer, index, i);
|
|
2817
2819
|
index = i + 1;
|
|
2818
2820
|
i = index;
|
|
2819
2821
|
while (buffer[i] !== 0x00 && i < buffer.length) {
|
|
@@ -2821,7 +2823,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2821
2823
|
}
|
|
2822
2824
|
if (i >= buffer.length)
|
|
2823
2825
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2824
|
-
const regExpOptions = ByteUtils.toUTF8(buffer
|
|
2826
|
+
const regExpOptions = ByteUtils.toUTF8(buffer, index, i);
|
|
2825
2827
|
index = i + 1;
|
|
2826
2828
|
const optionsArray = new Array(regExpOptions.length);
|
|
2827
2829
|
for (i = 0; i < regExpOptions.length; i++) {
|
|
@@ -2846,7 +2848,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2846
2848
|
}
|
|
2847
2849
|
if (i >= buffer.length)
|
|
2848
2850
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2849
|
-
const source = ByteUtils.toUTF8(buffer
|
|
2851
|
+
const source = ByteUtils.toUTF8(buffer, index, i);
|
|
2850
2852
|
index = i + 1;
|
|
2851
2853
|
i = index;
|
|
2852
2854
|
while (buffer[i] !== 0x00 && i < buffer.length) {
|
|
@@ -2854,7 +2856,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2854
2856
|
}
|
|
2855
2857
|
if (i >= buffer.length)
|
|
2856
2858
|
throw new BSONError('Bad BSON Document: illegal CString');
|
|
2857
|
-
const regExpOptions = ByteUtils.toUTF8(buffer
|
|
2859
|
+
const regExpOptions = ByteUtils.toUTF8(buffer, index, i);
|
|
2858
2860
|
index = i + 1;
|
|
2859
2861
|
value = new BSONRegExp(source, regExpOptions);
|
|
2860
2862
|
}
|
|
@@ -2951,7 +2953,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2951
2953
|
throw new BSONError('Invalid UTF-8 string in BSON document');
|
|
2952
2954
|
}
|
|
2953
2955
|
}
|
|
2954
|
-
const namespace = ByteUtils.toUTF8(buffer
|
|
2956
|
+
const namespace = ByteUtils.toUTF8(buffer, index, index + stringSize - 1);
|
|
2955
2957
|
index = index + stringSize;
|
|
2956
2958
|
const oidBuffer = ByteUtils.allocate(12);
|
|
2957
2959
|
oidBuffer.set(buffer.subarray(index, index + 12), 0);
|
|
@@ -2991,7 +2993,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
|
|
|
2991
2993
|
return object;
|
|
2992
2994
|
}
|
|
2993
2995
|
function getValidatedString(buffer, start, end, shouldValidateUtf8) {
|
|
2994
|
-
const value = ByteUtils.toUTF8(buffer
|
|
2996
|
+
const value = ByteUtils.toUTF8(buffer, start, end);
|
|
2995
2997
|
if (shouldValidateUtf8) {
|
|
2996
2998
|
for (let i = 0; i < value.length; i++) {
|
|
2997
2999
|
if (value.charCodeAt(i) === 0xfffd) {
|