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.browser.umd.js
CHANGED
|
@@ -2134,11 +2134,11 @@
|
|
|
2134
2134
|
}
|
|
2135
2135
|
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
|
|
2136
2136
|
function getGlobal() {
|
|
2137
|
-
// eslint-disable-next-line no-undef
|
|
2138
2137
|
return (checkForMath(typeof globalThis === 'object' && globalThis) ||
|
|
2139
2138
|
checkForMath(typeof window === 'object' && window) ||
|
|
2140
2139
|
checkForMath(typeof self === 'object' && self) ||
|
|
2141
2140
|
checkForMath(typeof global === 'object' && global) ||
|
|
2141
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
2142
2142
|
Function('return this')());
|
|
2143
2143
|
}
|
|
2144
2144
|
|
|
@@ -2164,27 +2164,20 @@
|
|
|
2164
2164
|
return result;
|
|
2165
2165
|
};
|
|
2166
2166
|
var detectRandomBytes = function () {
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2167
|
+
{
|
|
2168
|
+
if (typeof window !== 'undefined') {
|
|
2169
|
+
// browser crypto implementation(s)
|
|
2170
|
+
var target_1 = window.crypto || window.msCrypto; // allow for IE11
|
|
2171
|
+
if (target_1 && target_1.getRandomValues) {
|
|
2172
|
+
return function (size) { return target_1.getRandomValues(buffer_1.alloc(size)); };
|
|
2173
|
+
}
|
|
2172
2174
|
}
|
|
2175
|
+
if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
|
|
2176
|
+
// allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
|
|
2177
|
+
return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
|
|
2178
|
+
}
|
|
2179
|
+
return insecureRandomBytes;
|
|
2173
2180
|
}
|
|
2174
|
-
if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
|
|
2175
|
-
// allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
|
|
2176
|
-
return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
|
|
2177
|
-
}
|
|
2178
|
-
var requiredRandomBytes;
|
|
2179
|
-
try {
|
|
2180
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2181
|
-
requiredRandomBytes = require('crypto').randomBytes;
|
|
2182
|
-
}
|
|
2183
|
-
catch (e) {
|
|
2184
|
-
// keep the fallback
|
|
2185
|
-
}
|
|
2186
|
-
// NOTE: in transpiled cases the above require might return null/undefined
|
|
2187
|
-
return requiredRandomBytes || insecureRandomBytes;
|
|
2188
2181
|
};
|
|
2189
2182
|
var randomBytes = detectRandomBytes();
|
|
2190
2183
|
function isAnyArrayBuffer(value) {
|
|
@@ -2441,7 +2434,7 @@
|
|
|
2441
2434
|
return this.inspect();
|
|
2442
2435
|
};
|
|
2443
2436
|
UUID.prototype.inspect = function () {
|
|
2444
|
-
return "new UUID(\""
|
|
2437
|
+
return "new UUID(\"".concat(this.toHexString(), "\")");
|
|
2445
2438
|
};
|
|
2446
2439
|
return UUID;
|
|
2447
2440
|
}());
|
|
@@ -2454,6 +2447,13 @@
|
|
|
2454
2447
|
*/
|
|
2455
2448
|
var Binary = /** @class */ (function () {
|
|
2456
2449
|
/**
|
|
2450
|
+
* Create a new Binary instance.
|
|
2451
|
+
*
|
|
2452
|
+
* This constructor can accept a string as its first argument. In this case,
|
|
2453
|
+
* this string will be encoded using ISO-8859-1, **not** using UTF-8.
|
|
2454
|
+
* This is almost certainly not what you want. Use `new Binary(Buffer.from(string))`
|
|
2455
|
+
* instead to convert the string to a Buffer using UTF-8 first.
|
|
2456
|
+
*
|
|
2457
2457
|
* @param buffer - a buffer object containing the binary data.
|
|
2458
2458
|
* @param subType - the option binary type.
|
|
2459
2459
|
*/
|
|
@@ -2613,7 +2613,7 @@
|
|
|
2613
2613
|
if (this.sub_type === Binary.SUBTYPE_UUID) {
|
|
2614
2614
|
return new UUID(this.buffer.slice(0, this.position));
|
|
2615
2615
|
}
|
|
2616
|
-
throw new BSONError("Binary sub_type \""
|
|
2616
|
+
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."));
|
|
2617
2617
|
};
|
|
2618
2618
|
/** @internal */
|
|
2619
2619
|
Binary.fromExtendedJSON = function (doc, options) {
|
|
@@ -2637,7 +2637,7 @@
|
|
|
2637
2637
|
data = uuidHexStringToBuffer(doc.$uuid);
|
|
2638
2638
|
}
|
|
2639
2639
|
if (!data) {
|
|
2640
|
-
throw new BSONTypeError("Unexpected Binary Extended JSON format "
|
|
2640
|
+
throw new BSONTypeError("Unexpected Binary Extended JSON format ".concat(JSON.stringify(doc)));
|
|
2641
2641
|
}
|
|
2642
2642
|
return new Binary(data, type);
|
|
2643
2643
|
};
|
|
@@ -2647,7 +2647,7 @@
|
|
|
2647
2647
|
};
|
|
2648
2648
|
Binary.prototype.inspect = function () {
|
|
2649
2649
|
var asBuffer = this.value(true);
|
|
2650
|
-
return "new Binary(Buffer.from(\""
|
|
2650
|
+
return "new Binary(Buffer.from(\"".concat(asBuffer.toString('hex'), "\", \"hex\"), ").concat(this.sub_type, ")");
|
|
2651
2651
|
};
|
|
2652
2652
|
/**
|
|
2653
2653
|
* Binary default subtype
|
|
@@ -2714,7 +2714,7 @@
|
|
|
2714
2714
|
};
|
|
2715
2715
|
Code.prototype.inspect = function () {
|
|
2716
2716
|
var codeJson = this.toJSON();
|
|
2717
|
-
return "new Code(\""
|
|
2717
|
+
return "new Code(\"".concat(String(codeJson.code), "\"").concat(codeJson.scope ? ", ".concat(JSON.stringify(codeJson.scope)) : '', ")");
|
|
2718
2718
|
};
|
|
2719
2719
|
return Code;
|
|
2720
2720
|
}());
|
|
@@ -2805,7 +2805,7 @@
|
|
|
2805
2805
|
DBRef.prototype.inspect = function () {
|
|
2806
2806
|
// NOTE: if OID is an ObjectId class it will just print the oid string.
|
|
2807
2807
|
var oid = this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString();
|
|
2808
|
-
return "new DBRef(\""
|
|
2808
|
+
return "new DBRef(\"".concat(this.namespace, "\", new ObjectId(\"").concat(String(oid), "\")").concat(this.db ? ", \"".concat(this.db, "\"") : '', ")");
|
|
2809
2809
|
};
|
|
2810
2810
|
return DBRef;
|
|
2811
2811
|
}());
|
|
@@ -3042,7 +3042,6 @@
|
|
|
3042
3042
|
/**
|
|
3043
3043
|
* Tests if the specified object is a Long.
|
|
3044
3044
|
*/
|
|
3045
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
3046
3045
|
Long.isLong = function (value) {
|
|
3047
3046
|
return isObjectLike(value) && value['__isLong__'] === true;
|
|
3048
3047
|
};
|
|
@@ -3199,6 +3198,7 @@
|
|
|
3199
3198
|
// into the result, and subtract it from the remainder. It is critical that
|
|
3200
3199
|
// the approximate value is less than or equal to the real value so that the
|
|
3201
3200
|
// remainder never becomes negative.
|
|
3201
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3202
3202
|
rem = this;
|
|
3203
3203
|
while (rem.gte(divisor)) {
|
|
3204
3204
|
// Approximate the result of division. This may be a little greater or
|
|
@@ -3682,7 +3682,7 @@
|
|
|
3682
3682
|
return this.inspect();
|
|
3683
3683
|
};
|
|
3684
3684
|
Long.prototype.inspect = function () {
|
|
3685
|
-
return "new Long(\""
|
|
3685
|
+
return "new Long(\"".concat(this.toString(), "\"").concat(this.unsigned ? ', true' : '', ")");
|
|
3686
3686
|
};
|
|
3687
3687
|
Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
|
|
3688
3688
|
/** Maximum unsigned value. */
|
|
@@ -3793,7 +3793,7 @@
|
|
|
3793
3793
|
return false;
|
|
3794
3794
|
}
|
|
3795
3795
|
function invalidErr(string, message) {
|
|
3796
|
-
throw new BSONTypeError("\""
|
|
3796
|
+
throw new BSONTypeError("\"".concat(string, "\" is not a valid Decimal128 string - ").concat(message));
|
|
3797
3797
|
}
|
|
3798
3798
|
/**
|
|
3799
3799
|
* A class representation of the BSON Decimal128 type.
|
|
@@ -4291,35 +4291,35 @@
|
|
|
4291
4291
|
// as + or - 0 and using the non-scientific exponent (this is for the "invalid
|
|
4292
4292
|
// representation should be treated as 0/-0" spec cases in decimal128-1.json)
|
|
4293
4293
|
if (significand_digits > 34) {
|
|
4294
|
-
string.push(""
|
|
4294
|
+
string.push("".concat(0));
|
|
4295
4295
|
if (exponent > 0)
|
|
4296
|
-
string.push(
|
|
4296
|
+
string.push("E+".concat(exponent));
|
|
4297
4297
|
else if (exponent < 0)
|
|
4298
|
-
string.push(
|
|
4298
|
+
string.push("E".concat(exponent));
|
|
4299
4299
|
return string.join('');
|
|
4300
4300
|
}
|
|
4301
|
-
string.push(""
|
|
4301
|
+
string.push("".concat(significand[index++]));
|
|
4302
4302
|
significand_digits = significand_digits - 1;
|
|
4303
4303
|
if (significand_digits) {
|
|
4304
4304
|
string.push('.');
|
|
4305
4305
|
}
|
|
4306
4306
|
for (var i = 0; i < significand_digits; i++) {
|
|
4307
|
-
string.push(""
|
|
4307
|
+
string.push("".concat(significand[index++]));
|
|
4308
4308
|
}
|
|
4309
4309
|
// Exponent
|
|
4310
4310
|
string.push('E');
|
|
4311
4311
|
if (scientific_exponent > 0) {
|
|
4312
|
-
string.push(
|
|
4312
|
+
string.push("+".concat(scientific_exponent));
|
|
4313
4313
|
}
|
|
4314
4314
|
else {
|
|
4315
|
-
string.push(""
|
|
4315
|
+
string.push("".concat(scientific_exponent));
|
|
4316
4316
|
}
|
|
4317
4317
|
}
|
|
4318
4318
|
else {
|
|
4319
4319
|
// Regular format with no decimal place
|
|
4320
4320
|
if (exponent >= 0) {
|
|
4321
4321
|
for (var i = 0; i < significand_digits; i++) {
|
|
4322
|
-
string.push(""
|
|
4322
|
+
string.push("".concat(significand[index++]));
|
|
4323
4323
|
}
|
|
4324
4324
|
}
|
|
4325
4325
|
else {
|
|
@@ -4327,7 +4327,7 @@
|
|
|
4327
4327
|
// non-zero digits before radix
|
|
4328
4328
|
if (radix_position > 0) {
|
|
4329
4329
|
for (var i = 0; i < radix_position; i++) {
|
|
4330
|
-
string.push(""
|
|
4330
|
+
string.push("".concat(significand[index++]));
|
|
4331
4331
|
}
|
|
4332
4332
|
}
|
|
4333
4333
|
else {
|
|
@@ -4339,7 +4339,7 @@
|
|
|
4339
4339
|
string.push('0');
|
|
4340
4340
|
}
|
|
4341
4341
|
for (var i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
|
|
4342
|
-
string.push(""
|
|
4342
|
+
string.push("".concat(significand[index++]));
|
|
4343
4343
|
}
|
|
4344
4344
|
}
|
|
4345
4345
|
}
|
|
@@ -4361,7 +4361,7 @@
|
|
|
4361
4361
|
return this.inspect();
|
|
4362
4362
|
};
|
|
4363
4363
|
Decimal128.prototype.inspect = function () {
|
|
4364
|
-
return "new Decimal128(\""
|
|
4364
|
+
return "new Decimal128(\"".concat(this.toString(), "\")");
|
|
4365
4365
|
};
|
|
4366
4366
|
return Decimal128;
|
|
4367
4367
|
}());
|
|
@@ -4408,7 +4408,7 @@
|
|
|
4408
4408
|
// NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
|
|
4409
4409
|
// explicitly provided `-0` then we need to ensure the sign makes it into the output
|
|
4410
4410
|
if (Object.is(Math.sign(this.value), -0)) {
|
|
4411
|
-
return { $numberDouble: "-"
|
|
4411
|
+
return { $numberDouble: "-".concat(this.value.toFixed(1)) };
|
|
4412
4412
|
}
|
|
4413
4413
|
var $numberDouble;
|
|
4414
4414
|
if (Number.isInteger(this.value)) {
|
|
@@ -4433,7 +4433,7 @@
|
|
|
4433
4433
|
};
|
|
4434
4434
|
Double.prototype.inspect = function () {
|
|
4435
4435
|
var eJSON = this.toExtendedJSON();
|
|
4436
|
-
return "new Double("
|
|
4436
|
+
return "new Double(".concat(eJSON.$numberDouble, ")");
|
|
4437
4437
|
};
|
|
4438
4438
|
return Double;
|
|
4439
4439
|
}());
|
|
@@ -4487,7 +4487,7 @@
|
|
|
4487
4487
|
return this.inspect();
|
|
4488
4488
|
};
|
|
4489
4489
|
Int32.prototype.inspect = function () {
|
|
4490
|
-
return "new Int32("
|
|
4490
|
+
return "new Int32(".concat(this.valueOf(), ")");
|
|
4491
4491
|
};
|
|
4492
4492
|
return Int32;
|
|
4493
4493
|
}());
|
|
@@ -4821,7 +4821,7 @@
|
|
|
4821
4821
|
return this.inspect();
|
|
4822
4822
|
};
|
|
4823
4823
|
ObjectId.prototype.inspect = function () {
|
|
4824
|
-
return "new ObjectId(\""
|
|
4824
|
+
return "new ObjectId(\"".concat(this.toHexString(), "\")");
|
|
4825
4825
|
};
|
|
4826
4826
|
/** @internal */
|
|
4827
4827
|
ObjectId.index = Math.floor(Math.random() * 0xffffff);
|
|
@@ -4861,10 +4861,10 @@
|
|
|
4861
4861
|
this.pattern = pattern;
|
|
4862
4862
|
this.options = alphabetize(options !== null && options !== void 0 ? options : '');
|
|
4863
4863
|
if (this.pattern.indexOf('\x00') !== -1) {
|
|
4864
|
-
throw new BSONError("BSON Regex patterns cannot contain null bytes, found: "
|
|
4864
|
+
throw new BSONError("BSON Regex patterns cannot contain null bytes, found: ".concat(JSON.stringify(this.pattern)));
|
|
4865
4865
|
}
|
|
4866
4866
|
if (this.options.indexOf('\x00') !== -1) {
|
|
4867
|
-
throw new BSONError("BSON Regex options cannot contain null bytes, found: "
|
|
4867
|
+
throw new BSONError("BSON Regex options cannot contain null bytes, found: ".concat(JSON.stringify(this.options)));
|
|
4868
4868
|
}
|
|
4869
4869
|
// Validate options
|
|
4870
4870
|
for (var i = 0; i < this.options.length; i++) {
|
|
@@ -4874,7 +4874,7 @@
|
|
|
4874
4874
|
this.options[i] === 'l' ||
|
|
4875
4875
|
this.options[i] === 's' ||
|
|
4876
4876
|
this.options[i] === 'u')) {
|
|
4877
|
-
throw new BSONError("The regular expression option ["
|
|
4877
|
+
throw new BSONError("The regular expression option [".concat(this.options[i], "] is not supported"));
|
|
4878
4878
|
}
|
|
4879
4879
|
}
|
|
4880
4880
|
}
|
|
@@ -4905,7 +4905,7 @@
|
|
|
4905
4905
|
if ('$regularExpression' in doc) {
|
|
4906
4906
|
return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
|
|
4907
4907
|
}
|
|
4908
|
-
throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: "
|
|
4908
|
+
throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(doc)));
|
|
4909
4909
|
};
|
|
4910
4910
|
return BSONRegExp;
|
|
4911
4911
|
}());
|
|
@@ -4934,7 +4934,7 @@
|
|
|
4934
4934
|
};
|
|
4935
4935
|
/** @internal */
|
|
4936
4936
|
BSONSymbol.prototype.inspect = function () {
|
|
4937
|
-
return "new BSONSymbol(\""
|
|
4937
|
+
return "new BSONSymbol(\"".concat(this.value, "\")");
|
|
4938
4938
|
};
|
|
4939
4939
|
BSONSymbol.prototype.toJSON = function () {
|
|
4940
4940
|
return this.value;
|
|
@@ -4966,7 +4966,7 @@
|
|
|
4966
4966
|
function Timestamp(low, high) {
|
|
4967
4967
|
var _this = this;
|
|
4968
4968
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4969
|
-
|
|
4969
|
+
// @ts-expect-error
|
|
4970
4970
|
if (!(_this instanceof Timestamp))
|
|
4971
4971
|
return new Timestamp(low, high);
|
|
4972
4972
|
if (Long.isLong(low)) {
|
|
@@ -5030,7 +5030,7 @@
|
|
|
5030
5030
|
return this.inspect();
|
|
5031
5031
|
};
|
|
5032
5032
|
Timestamp.prototype.inspect = function () {
|
|
5033
|
-
return "new Timestamp({ t: "
|
|
5033
|
+
return "new Timestamp({ t: ".concat(this.getHighBits(), ", i: ").concat(this.getLowBits(), " })");
|
|
5034
5034
|
};
|
|
5035
5035
|
Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
|
|
5036
5036
|
return Timestamp;
|
|
@@ -5043,7 +5043,8 @@
|
|
|
5043
5043
|
var BSON_INT32_MAX$1 = 0x7fffffff;
|
|
5044
5044
|
var BSON_INT32_MIN$1 = -0x80000000;
|
|
5045
5045
|
// INT64 boundaries
|
|
5046
|
-
|
|
5046
|
+
// const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
|
|
5047
|
+
var BSON_INT64_MAX$1 = 0x8000000000000000;
|
|
5047
5048
|
var BSON_INT64_MIN$1 = -0x8000000000000000;
|
|
5048
5049
|
// all the types where we don't need to do any special processing and can just pass the EJSON
|
|
5049
5050
|
//straight to type.fromExtendedJSON
|
|
@@ -5139,7 +5140,7 @@
|
|
|
5139
5140
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5140
5141
|
function serializeArray(array, options) {
|
|
5141
5142
|
return array.map(function (v, index) {
|
|
5142
|
-
options.seenObjects.push({ propertyName: "index "
|
|
5143
|
+
options.seenObjects.push({ propertyName: "index ".concat(index), obj: null });
|
|
5143
5144
|
try {
|
|
5144
5145
|
return serializeValue(v, options);
|
|
5145
5146
|
}
|
|
@@ -5161,20 +5162,20 @@
|
|
|
5161
5162
|
var props = options.seenObjects.map(function (entry) { return entry.propertyName; });
|
|
5162
5163
|
var leadingPart = props
|
|
5163
5164
|
.slice(0, index)
|
|
5164
|
-
.map(function (prop) { return prop
|
|
5165
|
+
.map(function (prop) { return "".concat(prop, " -> "); })
|
|
5165
5166
|
.join('');
|
|
5166
5167
|
var alreadySeen = props[index];
|
|
5167
5168
|
var circularPart = ' -> ' +
|
|
5168
5169
|
props
|
|
5169
5170
|
.slice(index + 1, props.length - 1)
|
|
5170
|
-
.map(function (prop) { return prop
|
|
5171
|
+
.map(function (prop) { return "".concat(prop, " -> "); })
|
|
5171
5172
|
.join('');
|
|
5172
5173
|
var current = props[props.length - 1];
|
|
5173
5174
|
var leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
|
|
5174
5175
|
var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
|
|
5175
5176
|
throw new BSONTypeError('Converting circular structure to EJSON:\n' +
|
|
5176
|
-
|
|
5177
|
-
|
|
5177
|
+
" ".concat(leadingPart).concat(alreadySeen).concat(circularPart).concat(current, "\n") +
|
|
5178
|
+
" ".concat(leadingSpace, "\\").concat(dashes, "/"));
|
|
5178
5179
|
}
|
|
5179
5180
|
options.seenObjects[options.seenObjects.length - 1].obj = value;
|
|
5180
5181
|
}
|
|
@@ -5253,7 +5254,18 @@
|
|
|
5253
5254
|
for (var name in doc) {
|
|
5254
5255
|
options.seenObjects.push({ propertyName: name, obj: null });
|
|
5255
5256
|
try {
|
|
5256
|
-
|
|
5257
|
+
var value = serializeValue(doc[name], options);
|
|
5258
|
+
if (name === '__proto__') {
|
|
5259
|
+
Object.defineProperty(_doc, name, {
|
|
5260
|
+
value: value,
|
|
5261
|
+
writable: true,
|
|
5262
|
+
enumerable: true,
|
|
5263
|
+
configurable: true
|
|
5264
|
+
});
|
|
5265
|
+
}
|
|
5266
|
+
else {
|
|
5267
|
+
_doc[name] = value;
|
|
5268
|
+
}
|
|
5257
5269
|
}
|
|
5258
5270
|
finally {
|
|
5259
5271
|
options.seenObjects.pop();
|
|
@@ -5323,7 +5335,7 @@
|
|
|
5323
5335
|
finalOptions.relaxed = !finalOptions.strict;
|
|
5324
5336
|
return JSON.parse(text, function (key, value) {
|
|
5325
5337
|
if (key.indexOf('\x00') !== -1) {
|
|
5326
|
-
throw new BSONError("BSON Document field names cannot contain null bytes, found: "
|
|
5338
|
+
throw new BSONError("BSON Document field names cannot contain null bytes, found: ".concat(JSON.stringify(key)));
|
|
5327
5339
|
}
|
|
5328
5340
|
return deserializeValue(value, finalOptions);
|
|
5329
5341
|
});
|
|
@@ -5689,13 +5701,14 @@
|
|
|
5689
5701
|
}
|
|
5690
5702
|
}
|
|
5691
5703
|
else if (value['_bsontype'] === 'Binary') {
|
|
5704
|
+
var binary = value;
|
|
5692
5705
|
// Check what kind of subtype we have
|
|
5693
|
-
if (
|
|
5706
|
+
if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
|
|
5694
5707
|
return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
|
|
5695
|
-
(
|
|
5708
|
+
(binary.position + 1 + 4 + 1 + 4));
|
|
5696
5709
|
}
|
|
5697
5710
|
else {
|
|
5698
|
-
return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (
|
|
5711
|
+
return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (binary.position + 1 + 4 + 1));
|
|
5699
5712
|
}
|
|
5700
5713
|
}
|
|
5701
5714
|
else if (value['_bsontype'] === 'Symbol') {
|
|
@@ -5832,16 +5845,16 @@
|
|
|
5832
5845
|
(buffer[index + 2] << 16) |
|
|
5833
5846
|
(buffer[index + 3] << 24);
|
|
5834
5847
|
if (size < 5) {
|
|
5835
|
-
throw new BSONError("bson size must be >= 5, is "
|
|
5848
|
+
throw new BSONError("bson size must be >= 5, is ".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 be >= bson size ").concat(size));
|
|
5839
5852
|
}
|
|
5840
5853
|
if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
|
|
5841
|
-
throw new BSONError("buffer length "
|
|
5854
|
+
throw new BSONError("buffer length ".concat(buffer.length, " must === bson size ").concat(size));
|
|
5842
5855
|
}
|
|
5843
5856
|
if (size + index > buffer.byteLength) {
|
|
5844
|
-
throw new BSONError("(bson size "
|
|
5857
|
+
throw new BSONError("(bson size ".concat(size, " + options.index ").concat(index, " must be <= buffer length ").concat(buffer.byteLength, ")"));
|
|
5845
5858
|
}
|
|
5846
5859
|
// Illegal end value
|
|
5847
5860
|
if (buffer[index + size - 1] !== 0) {
|
|
@@ -5918,6 +5931,7 @@
|
|
|
5918
5931
|
var done = false;
|
|
5919
5932
|
var isPossibleDBRef = isArray ? false : null;
|
|
5920
5933
|
// While we have more left data left keep parsing
|
|
5934
|
+
var dataview = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
5921
5935
|
while (!done) {
|
|
5922
5936
|
// Read the type
|
|
5923
5937
|
var elementType = buffer[index++];
|
|
@@ -5978,11 +5992,11 @@
|
|
|
5978
5992
|
(buffer[index++] << 24);
|
|
5979
5993
|
}
|
|
5980
5994
|
else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
|
|
5981
|
-
value = new Double(
|
|
5995
|
+
value = new Double(dataview.getFloat64(index, true));
|
|
5982
5996
|
index = index + 8;
|
|
5983
5997
|
}
|
|
5984
5998
|
else if (elementType === BSON_DATA_NUMBER) {
|
|
5985
|
-
value =
|
|
5999
|
+
value = dataview.getFloat64(index, true);
|
|
5986
6000
|
index = index + 8;
|
|
5987
6001
|
}
|
|
5988
6002
|
else if (elementType === BSON_DATA_DATE) {
|
|
@@ -6380,7 +6394,7 @@
|
|
|
6380
6394
|
value = new DBRef(namespace, oid);
|
|
6381
6395
|
}
|
|
6382
6396
|
else {
|
|
6383
|
-
throw new BSONError(
|
|
6397
|
+
throw new BSONError("Detected unknown BSON type ".concat(elementType.toString(16), " for fieldname \"").concat(name, "\""));
|
|
6384
6398
|
}
|
|
6385
6399
|
if (name === '__proto__') {
|
|
6386
6400
|
Object.defineProperty(object, name, {
|
|
@@ -6418,10 +6432,12 @@
|
|
|
6418
6432
|
* @internal
|
|
6419
6433
|
*/
|
|
6420
6434
|
function isolateEval(functionString, functionCache, object) {
|
|
6435
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
6421
6436
|
if (!functionCache)
|
|
6422
6437
|
return new Function(functionString);
|
|
6423
6438
|
// Check for cache hit, eval if missing and return cached function
|
|
6424
6439
|
if (functionCache[functionString] == null) {
|
|
6440
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
6425
6441
|
functionCache[functionString] = new Function(functionString);
|
|
6426
6442
|
}
|
|
6427
6443
|
// Set the object
|
|
@@ -6443,74 +6459,6 @@
|
|
|
6443
6459
|
return value;
|
|
6444
6460
|
}
|
|
6445
6461
|
|
|
6446
|
-
// Copyright (c) 2008, Fair Oaks Labs, Inc.
|
|
6447
|
-
function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
|
|
6448
|
-
var e;
|
|
6449
|
-
var m;
|
|
6450
|
-
var c;
|
|
6451
|
-
var bBE = endian === 'big';
|
|
6452
|
-
var eLen = nBytes * 8 - mLen - 1;
|
|
6453
|
-
var eMax = (1 << eLen) - 1;
|
|
6454
|
-
var eBias = eMax >> 1;
|
|
6455
|
-
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
6456
|
-
var i = bBE ? nBytes - 1 : 0;
|
|
6457
|
-
var d = bBE ? -1 : 1;
|
|
6458
|
-
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
|
6459
|
-
value = Math.abs(value);
|
|
6460
|
-
if (isNaN(value) || value === Infinity) {
|
|
6461
|
-
m = isNaN(value) ? 1 : 0;
|
|
6462
|
-
e = eMax;
|
|
6463
|
-
}
|
|
6464
|
-
else {
|
|
6465
|
-
e = Math.floor(Math.log(value) / Math.LN2);
|
|
6466
|
-
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
6467
|
-
e--;
|
|
6468
|
-
c *= 2;
|
|
6469
|
-
}
|
|
6470
|
-
if (e + eBias >= 1) {
|
|
6471
|
-
value += rt / c;
|
|
6472
|
-
}
|
|
6473
|
-
else {
|
|
6474
|
-
value += rt * Math.pow(2, 1 - eBias);
|
|
6475
|
-
}
|
|
6476
|
-
if (value * c >= 2) {
|
|
6477
|
-
e++;
|
|
6478
|
-
c /= 2;
|
|
6479
|
-
}
|
|
6480
|
-
if (e + eBias >= eMax) {
|
|
6481
|
-
m = 0;
|
|
6482
|
-
e = eMax;
|
|
6483
|
-
}
|
|
6484
|
-
else if (e + eBias >= 1) {
|
|
6485
|
-
m = (value * c - 1) * Math.pow(2, mLen);
|
|
6486
|
-
e = e + eBias;
|
|
6487
|
-
}
|
|
6488
|
-
else {
|
|
6489
|
-
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
6490
|
-
e = 0;
|
|
6491
|
-
}
|
|
6492
|
-
}
|
|
6493
|
-
if (isNaN(value))
|
|
6494
|
-
m = 0;
|
|
6495
|
-
while (mLen >= 8) {
|
|
6496
|
-
buffer[offset + i] = m & 0xff;
|
|
6497
|
-
i += d;
|
|
6498
|
-
m /= 256;
|
|
6499
|
-
mLen -= 8;
|
|
6500
|
-
}
|
|
6501
|
-
e = (e << mLen) | m;
|
|
6502
|
-
if (isNaN(value))
|
|
6503
|
-
e += 8;
|
|
6504
|
-
eLen += mLen;
|
|
6505
|
-
while (eLen > 0) {
|
|
6506
|
-
buffer[offset + i] = e & 0xff;
|
|
6507
|
-
i += d;
|
|
6508
|
-
e /= 256;
|
|
6509
|
-
eLen -= 8;
|
|
6510
|
-
}
|
|
6511
|
-
buffer[offset + i - d] |= s * 128;
|
|
6512
|
-
}
|
|
6513
|
-
|
|
6514
6462
|
var regexp = /\x00/; // eslint-disable-line no-control-regex
|
|
6515
6463
|
var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
|
|
6516
6464
|
/*
|
|
@@ -6541,6 +6489,8 @@
|
|
|
6541
6489
|
buffer[index++] = 0;
|
|
6542
6490
|
return index;
|
|
6543
6491
|
}
|
|
6492
|
+
var SPACE_FOR_FLOAT64 = new Uint8Array(8);
|
|
6493
|
+
var DV_FOR_FLOAT64 = new DataView(SPACE_FOR_FLOAT64.buffer, SPACE_FOR_FLOAT64.byteOffset, SPACE_FOR_FLOAT64.byteLength);
|
|
6544
6494
|
function serializeNumber(buffer, key, value, index, isArray) {
|
|
6545
6495
|
// We have an integer value
|
|
6546
6496
|
// TODO(NODE-2529): Add support for big int
|
|
@@ -6574,7 +6524,8 @@
|
|
|
6574
6524
|
index = index + numberOfWrittenBytes;
|
|
6575
6525
|
buffer[index++] = 0;
|
|
6576
6526
|
// Write float
|
|
6577
|
-
|
|
6527
|
+
DV_FOR_FLOAT64.setFloat64(0, value, true);
|
|
6528
|
+
buffer.set(SPACE_FOR_FLOAT64, index);
|
|
6578
6529
|
// Adjust index
|
|
6579
6530
|
index = index + 8;
|
|
6580
6531
|
}
|
|
@@ -6853,7 +6804,8 @@
|
|
|
6853
6804
|
index = index + numberOfWrittenBytes;
|
|
6854
6805
|
buffer[index++] = 0;
|
|
6855
6806
|
// Write float
|
|
6856
|
-
|
|
6807
|
+
DV_FOR_FLOAT64.setFloat64(0, value.value, true);
|
|
6808
|
+
buffer.set(SPACE_FOR_FLOAT64, index);
|
|
6857
6809
|
// Adjust index
|
|
6858
6810
|
index = index + 8;
|
|
6859
6811
|
return index;
|
|
@@ -7063,7 +7015,7 @@
|
|
|
7063
7015
|
if (Array.isArray(object)) {
|
|
7064
7016
|
// Get object keys
|
|
7065
7017
|
for (var i = 0; i < object.length; i++) {
|
|
7066
|
-
var key =
|
|
7018
|
+
var key = "".concat(i);
|
|
7067
7019
|
var value = object[i];
|
|
7068
7020
|
// Is there an override value
|
|
7069
7021
|
if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
|
|
@@ -7138,7 +7090,7 @@
|
|
|
7138
7090
|
index = serializeMinMax(buffer, key, value, index, true);
|
|
7139
7091
|
}
|
|
7140
7092
|
else if (typeof value['_bsontype'] !== 'undefined') {
|
|
7141
|
-
throw new BSONTypeError(
|
|
7093
|
+
throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
|
|
7142
7094
|
}
|
|
7143
7095
|
}
|
|
7144
7096
|
}
|
|
@@ -7237,7 +7189,7 @@
|
|
|
7237
7189
|
index = serializeMinMax(buffer, key, value, index);
|
|
7238
7190
|
}
|
|
7239
7191
|
else if (typeof value['_bsontype'] !== 'undefined') {
|
|
7240
|
-
throw new BSONTypeError(
|
|
7192
|
+
throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
|
|
7241
7193
|
}
|
|
7242
7194
|
}
|
|
7243
7195
|
}
|
|
@@ -7342,7 +7294,7 @@
|
|
|
7342
7294
|
index = serializeMinMax(buffer, key, value, index);
|
|
7343
7295
|
}
|
|
7344
7296
|
else if (typeof value['_bsontype'] !== 'undefined') {
|
|
7345
|
-
throw new BSONTypeError(
|
|
7297
|
+
throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
|
|
7346
7298
|
}
|
|
7347
7299
|
}
|
|
7348
7300
|
}
|