bson 4.6.4 → 4.6.5
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/bower.json +1 -1
- package/bson.d.ts +8 -1
- package/dist/bson.browser.esm.js +95 -143
- package/dist/bson.browser.esm.js.map +1 -1
- package/dist/bson.browser.umd.js +95 -143
- package/dist/bson.browser.umd.js.map +1 -1
- package/dist/bson.bundle.js +95 -143
- package/dist/bson.bundle.js.map +1 -1
- package/dist/bson.esm.js +92 -143
- package/dist/bson.esm.js.map +1 -1
- package/lib/binary.js +13 -6
- package/lib/binary.js.map +1 -1
- package/lib/bson.js +19 -6
- package/lib/bson.js.map +1 -1
- package/lib/code.js +1 -1
- package/lib/code.js.map +1 -1
- package/lib/db_ref.js +2 -2
- package/lib/db_ref.js.map +1 -1
- package/lib/decimal128.js +13 -13
- package/lib/decimal128.js.map +1 -1
- package/lib/double.js +2 -2
- package/lib/double.js.map +1 -1
- package/lib/ensure_buffer.js +1 -1
- package/lib/ensure_buffer.js.map +1 -1
- package/lib/extended_json.js +24 -12
- package/lib/extended_json.js.map +1 -1
- package/lib/int_32.js +1 -1
- package/lib/int_32.js.map +1 -1
- package/lib/long.js +3 -3
- package/lib/long.js.map +1 -1
- package/lib/map.js +1 -1
- package/lib/map.js.map +1 -1
- package/lib/objectid.js +8 -8
- package/lib/objectid.js.map +1 -1
- package/lib/parser/calculate_size.js +10 -9
- package/lib/parser/calculate_size.js.map +1 -1
- package/lib/parser/deserializer.js +13 -10
- package/lib/parser/deserializer.js.map +1 -1
- package/lib/parser/serializer.js +25 -22
- package/lib/parser/serializer.js.map +1 -1
- package/lib/parser/utils.js +23 -19
- package/lib/parser/utils.js.map +1 -1
- package/lib/regexp.js +4 -4
- package/lib/regexp.js.map +1 -1
- package/lib/symbol.js +1 -1
- package/lib/symbol.js.map +1 -1
- package/lib/timestamp.js +3 -3
- package/lib/timestamp.js.map +1 -1
- package/lib/utils/global.js +1 -1
- package/lib/utils/global.js.map +1 -1
- package/lib/uuid.js +9 -9
- package/lib/uuid.js.map +1 -1
- package/lib/uuid_utils.js +1 -1
- package/lib/uuid_utils.js.map +1 -1
- package/package.json +16 -24
- package/src/binary.ts +7 -0
- package/src/code.ts +1 -1
- package/src/db_ref.ts +1 -1
- package/src/decimal128.ts +3 -3
- package/src/extended_json.ts +13 -2
- package/src/long.ts +32 -7
- package/src/objectid.ts +1 -1
- package/src/parser/calculate_size.ts +4 -3
- package/src/parser/deserializer.ts +6 -3
- package/src/parser/serializer.ts +14 -7
- package/src/parser/utils.ts +24 -20
- package/src/timestamp.ts +1 -1
- package/src/utils/global.ts +1 -1
- package/src/uuid.ts +1 -1
- package/bson-ts34.d.ts +0 -1133
- package/lib/float_parser.js +0 -137
- package/lib/float_parser.js.map +0 -1
- package/src/float_parser.ts +0 -152
package/dist/bson.bundle.js
CHANGED
|
@@ -2131,11 +2131,11 @@ var BSON = (function (exports) {
|
|
|
2131
2131
|
}
|
|
2132
2132
|
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
|
|
2133
2133
|
function getGlobal() {
|
|
2134
|
-
// eslint-disable-next-line no-undef
|
|
2135
2134
|
return (checkForMath(typeof globalThis === 'object' && globalThis) ||
|
|
2136
2135
|
checkForMath(typeof window === 'object' && window) ||
|
|
2137
2136
|
checkForMath(typeof self === 'object' && self) ||
|
|
2138
2137
|
checkForMath(typeof global === 'object' && global) ||
|
|
2138
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
2139
2139
|
Function('return this')());
|
|
2140
2140
|
}
|
|
2141
2141
|
|
|
@@ -2161,27 +2161,20 @@ var BSON = (function (exports) {
|
|
|
2161
2161
|
return result;
|
|
2162
2162
|
};
|
|
2163
2163
|
var detectRandomBytes = function () {
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2164
|
+
{
|
|
2165
|
+
if (typeof window !== 'undefined') {
|
|
2166
|
+
// browser crypto implementation(s)
|
|
2167
|
+
var target_1 = window.crypto || window.msCrypto; // allow for IE11
|
|
2168
|
+
if (target_1 && target_1.getRandomValues) {
|
|
2169
|
+
return function (size) { return target_1.getRandomValues(buffer_1.alloc(size)); };
|
|
2170
|
+
}
|
|
2169
2171
|
}
|
|
2172
|
+
if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
|
|
2173
|
+
// allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
|
|
2174
|
+
return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
|
|
2175
|
+
}
|
|
2176
|
+
return insecureRandomBytes;
|
|
2170
2177
|
}
|
|
2171
|
-
if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
|
|
2172
|
-
// allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
|
|
2173
|
-
return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
|
|
2174
|
-
}
|
|
2175
|
-
var requiredRandomBytes;
|
|
2176
|
-
try {
|
|
2177
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2178
|
-
requiredRandomBytes = require('crypto').randomBytes;
|
|
2179
|
-
}
|
|
2180
|
-
catch (e) {
|
|
2181
|
-
// keep the fallback
|
|
2182
|
-
}
|
|
2183
|
-
// NOTE: in transpiled cases the above require might return null/undefined
|
|
2184
|
-
return requiredRandomBytes || insecureRandomBytes;
|
|
2185
2178
|
};
|
|
2186
2179
|
var randomBytes = detectRandomBytes();
|
|
2187
2180
|
function isAnyArrayBuffer(value) {
|
|
@@ -2438,7 +2431,7 @@ var BSON = (function (exports) {
|
|
|
2438
2431
|
return this.inspect();
|
|
2439
2432
|
};
|
|
2440
2433
|
UUID.prototype.inspect = function () {
|
|
2441
|
-
return "new UUID(\""
|
|
2434
|
+
return "new UUID(\"".concat(this.toHexString(), "\")");
|
|
2442
2435
|
};
|
|
2443
2436
|
return UUID;
|
|
2444
2437
|
}());
|
|
@@ -2451,6 +2444,13 @@ var BSON = (function (exports) {
|
|
|
2451
2444
|
*/
|
|
2452
2445
|
var Binary = /** @class */ (function () {
|
|
2453
2446
|
/**
|
|
2447
|
+
* Create a new Binary instance.
|
|
2448
|
+
*
|
|
2449
|
+
* This constructor can accept a string as its first argument. In this case,
|
|
2450
|
+
* this string will be encoded using ISO-8859-1, **not** using UTF-8.
|
|
2451
|
+
* This is almost certainly not what you want. Use `new Binary(Buffer.from(string))`
|
|
2452
|
+
* instead to convert the string to a Buffer using UTF-8 first.
|
|
2453
|
+
*
|
|
2454
2454
|
* @param buffer - a buffer object containing the binary data.
|
|
2455
2455
|
* @param subType - the option binary type.
|
|
2456
2456
|
*/
|
|
@@ -2610,7 +2610,7 @@ var BSON = (function (exports) {
|
|
|
2610
2610
|
if (this.sub_type === Binary.SUBTYPE_UUID) {
|
|
2611
2611
|
return new UUID(this.buffer.slice(0, this.position));
|
|
2612
2612
|
}
|
|
2613
|
-
throw new BSONError("Binary sub_type \""
|
|
2613
|
+
throw new BSONError("Binary sub_type \"".concat(this.sub_type, "\" is not supported for converting to UUID. Only \"").concat(Binary.SUBTYPE_UUID, "\" is currently supported."));
|
|
2614
2614
|
};
|
|
2615
2615
|
/** @internal */
|
|
2616
2616
|
Binary.fromExtendedJSON = function (doc, options) {
|
|
@@ -2634,7 +2634,7 @@ var BSON = (function (exports) {
|
|
|
2634
2634
|
data = uuidHexStringToBuffer(doc.$uuid);
|
|
2635
2635
|
}
|
|
2636
2636
|
if (!data) {
|
|
2637
|
-
throw new BSONTypeError("Unexpected Binary Extended JSON format "
|
|
2637
|
+
throw new BSONTypeError("Unexpected Binary Extended JSON format ".concat(JSON.stringify(doc)));
|
|
2638
2638
|
}
|
|
2639
2639
|
return new Binary(data, type);
|
|
2640
2640
|
};
|
|
@@ -2644,7 +2644,7 @@ var BSON = (function (exports) {
|
|
|
2644
2644
|
};
|
|
2645
2645
|
Binary.prototype.inspect = function () {
|
|
2646
2646
|
var asBuffer = this.value(true);
|
|
2647
|
-
return "new Binary(Buffer.from(\""
|
|
2647
|
+
return "new Binary(Buffer.from(\"".concat(asBuffer.toString('hex'), "\", \"hex\"), ").concat(this.sub_type, ")");
|
|
2648
2648
|
};
|
|
2649
2649
|
/**
|
|
2650
2650
|
* Binary default subtype
|
|
@@ -2711,7 +2711,7 @@ var BSON = (function (exports) {
|
|
|
2711
2711
|
};
|
|
2712
2712
|
Code.prototype.inspect = function () {
|
|
2713
2713
|
var codeJson = this.toJSON();
|
|
2714
|
-
return "new Code(\""
|
|
2714
|
+
return "new Code(\"".concat(String(codeJson.code), "\"").concat(codeJson.scope ? ", ".concat(JSON.stringify(codeJson.scope)) : '', ")");
|
|
2715
2715
|
};
|
|
2716
2716
|
return Code;
|
|
2717
2717
|
}());
|
|
@@ -2802,7 +2802,7 @@ var BSON = (function (exports) {
|
|
|
2802
2802
|
DBRef.prototype.inspect = function () {
|
|
2803
2803
|
// NOTE: if OID is an ObjectId class it will just print the oid string.
|
|
2804
2804
|
var oid = this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString();
|
|
2805
|
-
return "new DBRef(\""
|
|
2805
|
+
return "new DBRef(\"".concat(this.namespace, "\", new ObjectId(\"").concat(String(oid), "\")").concat(this.db ? ", \"".concat(this.db, "\"") : '', ")");
|
|
2806
2806
|
};
|
|
2807
2807
|
return DBRef;
|
|
2808
2808
|
}());
|
|
@@ -3039,7 +3039,6 @@ var BSON = (function (exports) {
|
|
|
3039
3039
|
/**
|
|
3040
3040
|
* Tests if the specified object is a Long.
|
|
3041
3041
|
*/
|
|
3042
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
3043
3042
|
Long.isLong = function (value) {
|
|
3044
3043
|
return isObjectLike(value) && value['__isLong__'] === true;
|
|
3045
3044
|
};
|
|
@@ -3196,6 +3195,7 @@ var BSON = (function (exports) {
|
|
|
3196
3195
|
// into the result, and subtract it from the remainder. It is critical that
|
|
3197
3196
|
// the approximate value is less than or equal to the real value so that the
|
|
3198
3197
|
// remainder never becomes negative.
|
|
3198
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3199
3199
|
rem = this;
|
|
3200
3200
|
while (rem.gte(divisor)) {
|
|
3201
3201
|
// Approximate the result of division. This may be a little greater or
|
|
@@ -3679,7 +3679,7 @@ var BSON = (function (exports) {
|
|
|
3679
3679
|
return this.inspect();
|
|
3680
3680
|
};
|
|
3681
3681
|
Long.prototype.inspect = function () {
|
|
3682
|
-
return "new Long(\""
|
|
3682
|
+
return "new Long(\"".concat(this.toString(), "\"").concat(this.unsigned ? ', true' : '', ")");
|
|
3683
3683
|
};
|
|
3684
3684
|
Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
|
|
3685
3685
|
/** Maximum unsigned value. */
|
|
@@ -3790,7 +3790,7 @@ var BSON = (function (exports) {
|
|
|
3790
3790
|
return false;
|
|
3791
3791
|
}
|
|
3792
3792
|
function invalidErr(string, message) {
|
|
3793
|
-
throw new BSONTypeError("\""
|
|
3793
|
+
throw new BSONTypeError("\"".concat(string, "\" is not a valid Decimal128 string - ").concat(message));
|
|
3794
3794
|
}
|
|
3795
3795
|
/**
|
|
3796
3796
|
* A class representation of the BSON Decimal128 type.
|
|
@@ -4288,35 +4288,35 @@ var BSON = (function (exports) {
|
|
|
4288
4288
|
// as + or - 0 and using the non-scientific exponent (this is for the "invalid
|
|
4289
4289
|
// representation should be treated as 0/-0" spec cases in decimal128-1.json)
|
|
4290
4290
|
if (significand_digits > 34) {
|
|
4291
|
-
string.push(""
|
|
4291
|
+
string.push("".concat(0));
|
|
4292
4292
|
if (exponent > 0)
|
|
4293
|
-
string.push(
|
|
4293
|
+
string.push("E+".concat(exponent));
|
|
4294
4294
|
else if (exponent < 0)
|
|
4295
|
-
string.push(
|
|
4295
|
+
string.push("E".concat(exponent));
|
|
4296
4296
|
return string.join('');
|
|
4297
4297
|
}
|
|
4298
|
-
string.push(""
|
|
4298
|
+
string.push("".concat(significand[index++]));
|
|
4299
4299
|
significand_digits = significand_digits - 1;
|
|
4300
4300
|
if (significand_digits) {
|
|
4301
4301
|
string.push('.');
|
|
4302
4302
|
}
|
|
4303
4303
|
for (var i = 0; i < significand_digits; i++) {
|
|
4304
|
-
string.push(""
|
|
4304
|
+
string.push("".concat(significand[index++]));
|
|
4305
4305
|
}
|
|
4306
4306
|
// Exponent
|
|
4307
4307
|
string.push('E');
|
|
4308
4308
|
if (scientific_exponent > 0) {
|
|
4309
|
-
string.push(
|
|
4309
|
+
string.push("+".concat(scientific_exponent));
|
|
4310
4310
|
}
|
|
4311
4311
|
else {
|
|
4312
|
-
string.push(""
|
|
4312
|
+
string.push("".concat(scientific_exponent));
|
|
4313
4313
|
}
|
|
4314
4314
|
}
|
|
4315
4315
|
else {
|
|
4316
4316
|
// Regular format with no decimal place
|
|
4317
4317
|
if (exponent >= 0) {
|
|
4318
4318
|
for (var i = 0; i < significand_digits; i++) {
|
|
4319
|
-
string.push(""
|
|
4319
|
+
string.push("".concat(significand[index++]));
|
|
4320
4320
|
}
|
|
4321
4321
|
}
|
|
4322
4322
|
else {
|
|
@@ -4324,7 +4324,7 @@ var BSON = (function (exports) {
|
|
|
4324
4324
|
// non-zero digits before radix
|
|
4325
4325
|
if (radix_position > 0) {
|
|
4326
4326
|
for (var i = 0; i < radix_position; i++) {
|
|
4327
|
-
string.push(""
|
|
4327
|
+
string.push("".concat(significand[index++]));
|
|
4328
4328
|
}
|
|
4329
4329
|
}
|
|
4330
4330
|
else {
|
|
@@ -4336,7 +4336,7 @@ var BSON = (function (exports) {
|
|
|
4336
4336
|
string.push('0');
|
|
4337
4337
|
}
|
|
4338
4338
|
for (var i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
|
|
4339
|
-
string.push(""
|
|
4339
|
+
string.push("".concat(significand[index++]));
|
|
4340
4340
|
}
|
|
4341
4341
|
}
|
|
4342
4342
|
}
|
|
@@ -4358,7 +4358,7 @@ var BSON = (function (exports) {
|
|
|
4358
4358
|
return this.inspect();
|
|
4359
4359
|
};
|
|
4360
4360
|
Decimal128.prototype.inspect = function () {
|
|
4361
|
-
return "new Decimal128(\""
|
|
4361
|
+
return "new Decimal128(\"".concat(this.toString(), "\")");
|
|
4362
4362
|
};
|
|
4363
4363
|
return Decimal128;
|
|
4364
4364
|
}());
|
|
@@ -4405,7 +4405,7 @@ var BSON = (function (exports) {
|
|
|
4405
4405
|
// NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
|
|
4406
4406
|
// explicitly provided `-0` then we need to ensure the sign makes it into the output
|
|
4407
4407
|
if (Object.is(Math.sign(this.value), -0)) {
|
|
4408
|
-
return { $numberDouble: "-"
|
|
4408
|
+
return { $numberDouble: "-".concat(this.value.toFixed(1)) };
|
|
4409
4409
|
}
|
|
4410
4410
|
var $numberDouble;
|
|
4411
4411
|
if (Number.isInteger(this.value)) {
|
|
@@ -4430,7 +4430,7 @@ var BSON = (function (exports) {
|
|
|
4430
4430
|
};
|
|
4431
4431
|
Double.prototype.inspect = function () {
|
|
4432
4432
|
var eJSON = this.toExtendedJSON();
|
|
4433
|
-
return "new Double("
|
|
4433
|
+
return "new Double(".concat(eJSON.$numberDouble, ")");
|
|
4434
4434
|
};
|
|
4435
4435
|
return Double;
|
|
4436
4436
|
}());
|
|
@@ -4484,7 +4484,7 @@ var BSON = (function (exports) {
|
|
|
4484
4484
|
return this.inspect();
|
|
4485
4485
|
};
|
|
4486
4486
|
Int32.prototype.inspect = function () {
|
|
4487
|
-
return "new Int32("
|
|
4487
|
+
return "new Int32(".concat(this.valueOf(), ")");
|
|
4488
4488
|
};
|
|
4489
4489
|
return Int32;
|
|
4490
4490
|
}());
|
|
@@ -4818,7 +4818,7 @@ var BSON = (function (exports) {
|
|
|
4818
4818
|
return this.inspect();
|
|
4819
4819
|
};
|
|
4820
4820
|
ObjectId.prototype.inspect = function () {
|
|
4821
|
-
return "new ObjectId(\""
|
|
4821
|
+
return "new ObjectId(\"".concat(this.toHexString(), "\")");
|
|
4822
4822
|
};
|
|
4823
4823
|
/** @internal */
|
|
4824
4824
|
ObjectId.index = Math.floor(Math.random() * 0xffffff);
|
|
@@ -4858,10 +4858,10 @@ var BSON = (function (exports) {
|
|
|
4858
4858
|
this.pattern = pattern;
|
|
4859
4859
|
this.options = alphabetize(options !== null && options !== void 0 ? options : '');
|
|
4860
4860
|
if (this.pattern.indexOf('\x00') !== -1) {
|
|
4861
|
-
throw new BSONError("BSON Regex patterns cannot contain null bytes, found: "
|
|
4861
|
+
throw new BSONError("BSON Regex patterns cannot contain null bytes, found: ".concat(JSON.stringify(this.pattern)));
|
|
4862
4862
|
}
|
|
4863
4863
|
if (this.options.indexOf('\x00') !== -1) {
|
|
4864
|
-
throw new BSONError("BSON Regex options cannot contain null bytes, found: "
|
|
4864
|
+
throw new BSONError("BSON Regex options cannot contain null bytes, found: ".concat(JSON.stringify(this.options)));
|
|
4865
4865
|
}
|
|
4866
4866
|
// Validate options
|
|
4867
4867
|
for (var i = 0; i < this.options.length; i++) {
|
|
@@ -4871,7 +4871,7 @@ var BSON = (function (exports) {
|
|
|
4871
4871
|
this.options[i] === 'l' ||
|
|
4872
4872
|
this.options[i] === 's' ||
|
|
4873
4873
|
this.options[i] === 'u')) {
|
|
4874
|
-
throw new BSONError("The regular expression option ["
|
|
4874
|
+
throw new BSONError("The regular expression option [".concat(this.options[i], "] is not supported"));
|
|
4875
4875
|
}
|
|
4876
4876
|
}
|
|
4877
4877
|
}
|
|
@@ -4902,7 +4902,7 @@ var BSON = (function (exports) {
|
|
|
4902
4902
|
if ('$regularExpression' in doc) {
|
|
4903
4903
|
return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
|
|
4904
4904
|
}
|
|
4905
|
-
throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: "
|
|
4905
|
+
throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(doc)));
|
|
4906
4906
|
};
|
|
4907
4907
|
return BSONRegExp;
|
|
4908
4908
|
}());
|
|
@@ -4931,7 +4931,7 @@ var BSON = (function (exports) {
|
|
|
4931
4931
|
};
|
|
4932
4932
|
/** @internal */
|
|
4933
4933
|
BSONSymbol.prototype.inspect = function () {
|
|
4934
|
-
return "new BSONSymbol(\""
|
|
4934
|
+
return "new BSONSymbol(\"".concat(this.value, "\")");
|
|
4935
4935
|
};
|
|
4936
4936
|
BSONSymbol.prototype.toJSON = function () {
|
|
4937
4937
|
return this.value;
|
|
@@ -4963,7 +4963,7 @@ var BSON = (function (exports) {
|
|
|
4963
4963
|
function Timestamp(low, high) {
|
|
4964
4964
|
var _this = this;
|
|
4965
4965
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4966
|
-
|
|
4966
|
+
// @ts-expect-error
|
|
4967
4967
|
if (!(_this instanceof Timestamp))
|
|
4968
4968
|
return new Timestamp(low, high);
|
|
4969
4969
|
if (Long.isLong(low)) {
|
|
@@ -5027,7 +5027,7 @@ var BSON = (function (exports) {
|
|
|
5027
5027
|
return this.inspect();
|
|
5028
5028
|
};
|
|
5029
5029
|
Timestamp.prototype.inspect = function () {
|
|
5030
|
-
return "new Timestamp({ t: "
|
|
5030
|
+
return "new Timestamp({ t: ".concat(this.getHighBits(), ", i: ").concat(this.getLowBits(), " })");
|
|
5031
5031
|
};
|
|
5032
5032
|
Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
|
|
5033
5033
|
return Timestamp;
|
|
@@ -5040,7 +5040,8 @@ var BSON = (function (exports) {
|
|
|
5040
5040
|
var BSON_INT32_MAX$1 = 0x7fffffff;
|
|
5041
5041
|
var BSON_INT32_MIN$1 = -0x80000000;
|
|
5042
5042
|
// INT64 boundaries
|
|
5043
|
-
|
|
5043
|
+
// const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
|
|
5044
|
+
var BSON_INT64_MAX$1 = 0x8000000000000000;
|
|
5044
5045
|
var BSON_INT64_MIN$1 = -0x8000000000000000;
|
|
5045
5046
|
// all the types where we don't need to do any special processing and can just pass the EJSON
|
|
5046
5047
|
//straight to type.fromExtendedJSON
|
|
@@ -5136,7 +5137,7 @@ var BSON = (function (exports) {
|
|
|
5136
5137
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5137
5138
|
function serializeArray(array, options) {
|
|
5138
5139
|
return array.map(function (v, index) {
|
|
5139
|
-
options.seenObjects.push({ propertyName: "index "
|
|
5140
|
+
options.seenObjects.push({ propertyName: "index ".concat(index), obj: null });
|
|
5140
5141
|
try {
|
|
5141
5142
|
return serializeValue(v, options);
|
|
5142
5143
|
}
|
|
@@ -5158,20 +5159,20 @@ var BSON = (function (exports) {
|
|
|
5158
5159
|
var props = options.seenObjects.map(function (entry) { return entry.propertyName; });
|
|
5159
5160
|
var leadingPart = props
|
|
5160
5161
|
.slice(0, index)
|
|
5161
|
-
.map(function (prop) { return prop
|
|
5162
|
+
.map(function (prop) { return "".concat(prop, " -> "); })
|
|
5162
5163
|
.join('');
|
|
5163
5164
|
var alreadySeen = props[index];
|
|
5164
5165
|
var circularPart = ' -> ' +
|
|
5165
5166
|
props
|
|
5166
5167
|
.slice(index + 1, props.length - 1)
|
|
5167
|
-
.map(function (prop) { return prop
|
|
5168
|
+
.map(function (prop) { return "".concat(prop, " -> "); })
|
|
5168
5169
|
.join('');
|
|
5169
5170
|
var current = props[props.length - 1];
|
|
5170
5171
|
var leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
|
|
5171
5172
|
var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
|
|
5172
5173
|
throw new BSONTypeError('Converting circular structure to EJSON:\n' +
|
|
5173
|
-
|
|
5174
|
-
|
|
5174
|
+
" ".concat(leadingPart).concat(alreadySeen).concat(circularPart).concat(current, "\n") +
|
|
5175
|
+
" ".concat(leadingSpace, "\\").concat(dashes, "/"));
|
|
5175
5176
|
}
|
|
5176
5177
|
options.seenObjects[options.seenObjects.length - 1].obj = value;
|
|
5177
5178
|
}
|
|
@@ -5250,7 +5251,18 @@ var BSON = (function (exports) {
|
|
|
5250
5251
|
for (var name in doc) {
|
|
5251
5252
|
options.seenObjects.push({ propertyName: name, obj: null });
|
|
5252
5253
|
try {
|
|
5253
|
-
|
|
5254
|
+
var value = serializeValue(doc[name], options);
|
|
5255
|
+
if (name === '__proto__') {
|
|
5256
|
+
Object.defineProperty(_doc, name, {
|
|
5257
|
+
value: value,
|
|
5258
|
+
writable: true,
|
|
5259
|
+
enumerable: true,
|
|
5260
|
+
configurable: true
|
|
5261
|
+
});
|
|
5262
|
+
}
|
|
5263
|
+
else {
|
|
5264
|
+
_doc[name] = value;
|
|
5265
|
+
}
|
|
5254
5266
|
}
|
|
5255
5267
|
finally {
|
|
5256
5268
|
options.seenObjects.pop();
|
|
@@ -5320,7 +5332,7 @@ var BSON = (function (exports) {
|
|
|
5320
5332
|
finalOptions.relaxed = !finalOptions.strict;
|
|
5321
5333
|
return JSON.parse(text, function (key, value) {
|
|
5322
5334
|
if (key.indexOf('\x00') !== -1) {
|
|
5323
|
-
throw new BSONError("BSON Document field names cannot contain null bytes, found: "
|
|
5335
|
+
throw new BSONError("BSON Document field names cannot contain null bytes, found: ".concat(JSON.stringify(key)));
|
|
5324
5336
|
}
|
|
5325
5337
|
return deserializeValue(value, finalOptions);
|
|
5326
5338
|
});
|
|
@@ -5686,13 +5698,14 @@ var BSON = (function (exports) {
|
|
|
5686
5698
|
}
|
|
5687
5699
|
}
|
|
5688
5700
|
else if (value['_bsontype'] === 'Binary') {
|
|
5701
|
+
var binary = value;
|
|
5689
5702
|
// Check what kind of subtype we have
|
|
5690
|
-
if (
|
|
5703
|
+
if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
|
|
5691
5704
|
return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
|
|
5692
|
-
(
|
|
5705
|
+
(binary.position + 1 + 4 + 1 + 4));
|
|
5693
5706
|
}
|
|
5694
5707
|
else {
|
|
5695
|
-
return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (
|
|
5708
|
+
return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (binary.position + 1 + 4 + 1));
|
|
5696
5709
|
}
|
|
5697
5710
|
}
|
|
5698
5711
|
else if (value['_bsontype'] === 'Symbol') {
|
|
@@ -5829,16 +5842,16 @@ var BSON = (function (exports) {
|
|
|
5829
5842
|
(buffer[index + 2] << 16) |
|
|
5830
5843
|
(buffer[index + 3] << 24);
|
|
5831
5844
|
if (size < 5) {
|
|
5832
|
-
throw new BSONError("bson size must be >= 5, is "
|
|
5845
|
+
throw new BSONError("bson size must be >= 5, is ".concat(size));
|
|
5833
5846
|
}
|
|
5834
5847
|
if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
|
|
5835
|
-
throw new BSONError("buffer length "
|
|
5848
|
+
throw new BSONError("buffer length ".concat(buffer.length, " must be >= bson size ").concat(size));
|
|
5836
5849
|
}
|
|
5837
5850
|
if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
|
|
5838
|
-
throw new BSONError("buffer length "
|
|
5851
|
+
throw new BSONError("buffer length ".concat(buffer.length, " must === bson size ").concat(size));
|
|
5839
5852
|
}
|
|
5840
5853
|
if (size + index > buffer.byteLength) {
|
|
5841
|
-
throw new BSONError("(bson size "
|
|
5854
|
+
throw new BSONError("(bson size ".concat(size, " + options.index ").concat(index, " must be <= buffer length ").concat(buffer.byteLength, ")"));
|
|
5842
5855
|
}
|
|
5843
5856
|
// Illegal end value
|
|
5844
5857
|
if (buffer[index + size - 1] !== 0) {
|
|
@@ -5915,6 +5928,7 @@ var BSON = (function (exports) {
|
|
|
5915
5928
|
var done = false;
|
|
5916
5929
|
var isPossibleDBRef = isArray ? false : null;
|
|
5917
5930
|
// While we have more left data left keep parsing
|
|
5931
|
+
var dataview = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
5918
5932
|
while (!done) {
|
|
5919
5933
|
// Read the type
|
|
5920
5934
|
var elementType = buffer[index++];
|
|
@@ -5975,11 +5989,11 @@ var BSON = (function (exports) {
|
|
|
5975
5989
|
(buffer[index++] << 24);
|
|
5976
5990
|
}
|
|
5977
5991
|
else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
|
|
5978
|
-
value = new Double(
|
|
5992
|
+
value = new Double(dataview.getFloat64(index, true));
|
|
5979
5993
|
index = index + 8;
|
|
5980
5994
|
}
|
|
5981
5995
|
else if (elementType === BSON_DATA_NUMBER) {
|
|
5982
|
-
value =
|
|
5996
|
+
value = dataview.getFloat64(index, true);
|
|
5983
5997
|
index = index + 8;
|
|
5984
5998
|
}
|
|
5985
5999
|
else if (elementType === BSON_DATA_DATE) {
|
|
@@ -6377,7 +6391,7 @@ var BSON = (function (exports) {
|
|
|
6377
6391
|
value = new DBRef(namespace, oid);
|
|
6378
6392
|
}
|
|
6379
6393
|
else {
|
|
6380
|
-
throw new BSONError(
|
|
6394
|
+
throw new BSONError("Detected unknown BSON type ".concat(elementType.toString(16), " for fieldname \"").concat(name, "\""));
|
|
6381
6395
|
}
|
|
6382
6396
|
if (name === '__proto__') {
|
|
6383
6397
|
Object.defineProperty(object, name, {
|
|
@@ -6415,10 +6429,12 @@ var BSON = (function (exports) {
|
|
|
6415
6429
|
* @internal
|
|
6416
6430
|
*/
|
|
6417
6431
|
function isolateEval(functionString, functionCache, object) {
|
|
6432
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
6418
6433
|
if (!functionCache)
|
|
6419
6434
|
return new Function(functionString);
|
|
6420
6435
|
// Check for cache hit, eval if missing and return cached function
|
|
6421
6436
|
if (functionCache[functionString] == null) {
|
|
6437
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
6422
6438
|
functionCache[functionString] = new Function(functionString);
|
|
6423
6439
|
}
|
|
6424
6440
|
// Set the object
|
|
@@ -6440,74 +6456,6 @@ var BSON = (function (exports) {
|
|
|
6440
6456
|
return value;
|
|
6441
6457
|
}
|
|
6442
6458
|
|
|
6443
|
-
// Copyright (c) 2008, Fair Oaks Labs, Inc.
|
|
6444
|
-
function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
|
|
6445
|
-
var e;
|
|
6446
|
-
var m;
|
|
6447
|
-
var c;
|
|
6448
|
-
var bBE = endian === 'big';
|
|
6449
|
-
var eLen = nBytes * 8 - mLen - 1;
|
|
6450
|
-
var eMax = (1 << eLen) - 1;
|
|
6451
|
-
var eBias = eMax >> 1;
|
|
6452
|
-
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
6453
|
-
var i = bBE ? nBytes - 1 : 0;
|
|
6454
|
-
var d = bBE ? -1 : 1;
|
|
6455
|
-
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
|
6456
|
-
value = Math.abs(value);
|
|
6457
|
-
if (isNaN(value) || value === Infinity) {
|
|
6458
|
-
m = isNaN(value) ? 1 : 0;
|
|
6459
|
-
e = eMax;
|
|
6460
|
-
}
|
|
6461
|
-
else {
|
|
6462
|
-
e = Math.floor(Math.log(value) / Math.LN2);
|
|
6463
|
-
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
6464
|
-
e--;
|
|
6465
|
-
c *= 2;
|
|
6466
|
-
}
|
|
6467
|
-
if (e + eBias >= 1) {
|
|
6468
|
-
value += rt / c;
|
|
6469
|
-
}
|
|
6470
|
-
else {
|
|
6471
|
-
value += rt * Math.pow(2, 1 - eBias);
|
|
6472
|
-
}
|
|
6473
|
-
if (value * c >= 2) {
|
|
6474
|
-
e++;
|
|
6475
|
-
c /= 2;
|
|
6476
|
-
}
|
|
6477
|
-
if (e + eBias >= eMax) {
|
|
6478
|
-
m = 0;
|
|
6479
|
-
e = eMax;
|
|
6480
|
-
}
|
|
6481
|
-
else if (e + eBias >= 1) {
|
|
6482
|
-
m = (value * c - 1) * Math.pow(2, mLen);
|
|
6483
|
-
e = e + eBias;
|
|
6484
|
-
}
|
|
6485
|
-
else {
|
|
6486
|
-
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
6487
|
-
e = 0;
|
|
6488
|
-
}
|
|
6489
|
-
}
|
|
6490
|
-
if (isNaN(value))
|
|
6491
|
-
m = 0;
|
|
6492
|
-
while (mLen >= 8) {
|
|
6493
|
-
buffer[offset + i] = m & 0xff;
|
|
6494
|
-
i += d;
|
|
6495
|
-
m /= 256;
|
|
6496
|
-
mLen -= 8;
|
|
6497
|
-
}
|
|
6498
|
-
e = (e << mLen) | m;
|
|
6499
|
-
if (isNaN(value))
|
|
6500
|
-
e += 8;
|
|
6501
|
-
eLen += mLen;
|
|
6502
|
-
while (eLen > 0) {
|
|
6503
|
-
buffer[offset + i] = e & 0xff;
|
|
6504
|
-
i += d;
|
|
6505
|
-
e /= 256;
|
|
6506
|
-
eLen -= 8;
|
|
6507
|
-
}
|
|
6508
|
-
buffer[offset + i - d] |= s * 128;
|
|
6509
|
-
}
|
|
6510
|
-
|
|
6511
6459
|
var regexp = /\x00/; // eslint-disable-line no-control-regex
|
|
6512
6460
|
var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
|
|
6513
6461
|
/*
|
|
@@ -6538,6 +6486,8 @@ var BSON = (function (exports) {
|
|
|
6538
6486
|
buffer[index++] = 0;
|
|
6539
6487
|
return index;
|
|
6540
6488
|
}
|
|
6489
|
+
var SPACE_FOR_FLOAT64 = new Uint8Array(8);
|
|
6490
|
+
var DV_FOR_FLOAT64 = new DataView(SPACE_FOR_FLOAT64.buffer, SPACE_FOR_FLOAT64.byteOffset, SPACE_FOR_FLOAT64.byteLength);
|
|
6541
6491
|
function serializeNumber(buffer, key, value, index, isArray) {
|
|
6542
6492
|
// We have an integer value
|
|
6543
6493
|
// TODO(NODE-2529): Add support for big int
|
|
@@ -6571,7 +6521,8 @@ var BSON = (function (exports) {
|
|
|
6571
6521
|
index = index + numberOfWrittenBytes;
|
|
6572
6522
|
buffer[index++] = 0;
|
|
6573
6523
|
// Write float
|
|
6574
|
-
|
|
6524
|
+
DV_FOR_FLOAT64.setFloat64(0, value, true);
|
|
6525
|
+
buffer.set(SPACE_FOR_FLOAT64, index);
|
|
6575
6526
|
// Adjust index
|
|
6576
6527
|
index = index + 8;
|
|
6577
6528
|
}
|
|
@@ -6850,7 +6801,8 @@ var BSON = (function (exports) {
|
|
|
6850
6801
|
index = index + numberOfWrittenBytes;
|
|
6851
6802
|
buffer[index++] = 0;
|
|
6852
6803
|
// Write float
|
|
6853
|
-
|
|
6804
|
+
DV_FOR_FLOAT64.setFloat64(0, value.value, true);
|
|
6805
|
+
buffer.set(SPACE_FOR_FLOAT64, index);
|
|
6854
6806
|
// Adjust index
|
|
6855
6807
|
index = index + 8;
|
|
6856
6808
|
return index;
|
|
@@ -7060,7 +7012,7 @@ var BSON = (function (exports) {
|
|
|
7060
7012
|
if (Array.isArray(object)) {
|
|
7061
7013
|
// Get object keys
|
|
7062
7014
|
for (var i = 0; i < object.length; i++) {
|
|
7063
|
-
var key =
|
|
7015
|
+
var key = "".concat(i);
|
|
7064
7016
|
var value = object[i];
|
|
7065
7017
|
// Is there an override value
|
|
7066
7018
|
if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
|
|
@@ -7135,7 +7087,7 @@ var BSON = (function (exports) {
|
|
|
7135
7087
|
index = serializeMinMax(buffer, key, value, index, true);
|
|
7136
7088
|
}
|
|
7137
7089
|
else if (typeof value['_bsontype'] !== 'undefined') {
|
|
7138
|
-
throw new BSONTypeError(
|
|
7090
|
+
throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
|
|
7139
7091
|
}
|
|
7140
7092
|
}
|
|
7141
7093
|
}
|
|
@@ -7234,7 +7186,7 @@ var BSON = (function (exports) {
|
|
|
7234
7186
|
index = serializeMinMax(buffer, key, value, index);
|
|
7235
7187
|
}
|
|
7236
7188
|
else if (typeof value['_bsontype'] !== 'undefined') {
|
|
7237
|
-
throw new BSONTypeError(
|
|
7189
|
+
throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
|
|
7238
7190
|
}
|
|
7239
7191
|
}
|
|
7240
7192
|
}
|
|
@@ -7339,7 +7291,7 @@ var BSON = (function (exports) {
|
|
|
7339
7291
|
index = serializeMinMax(buffer, key, value, index);
|
|
7340
7292
|
}
|
|
7341
7293
|
else if (typeof value['_bsontype'] !== 'undefined') {
|
|
7342
|
-
throw new BSONTypeError(
|
|
7294
|
+
throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
|
|
7343
7295
|
}
|
|
7344
7296
|
}
|
|
7345
7297
|
}
|