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.esm.js
CHANGED
|
@@ -97,11 +97,11 @@ function checkForMath(potentialGlobal) {
|
|
|
97
97
|
}
|
|
98
98
|
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
|
|
99
99
|
function getGlobal() {
|
|
100
|
-
// eslint-disable-next-line no-undef
|
|
101
100
|
return (checkForMath(typeof globalThis === 'object' && globalThis) ||
|
|
102
101
|
checkForMath(typeof window === 'object' && window) ||
|
|
103
102
|
checkForMath(typeof self === 'object' && self) ||
|
|
104
103
|
checkForMath(typeof global === 'object' && global) ||
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
105
105
|
Function('return this')());
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -127,27 +127,17 @@ var insecureRandomBytes = function insecureRandomBytes(size) {
|
|
|
127
127
|
return result;
|
|
128
128
|
};
|
|
129
129
|
var detectRandomBytes = function () {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return function (size) { return target_1.getRandomValues(Buffer.alloc(size)); };
|
|
130
|
+
{
|
|
131
|
+
var requiredRandomBytes = void 0;
|
|
132
|
+
try {
|
|
133
|
+
requiredRandomBytes = require('crypto').randomBytes;
|
|
135
134
|
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
// keep the fallback
|
|
137
|
+
}
|
|
138
|
+
// NOTE: in transpiled cases the above require might return null/undefined
|
|
139
|
+
return requiredRandomBytes || insecureRandomBytes;
|
|
136
140
|
}
|
|
137
|
-
if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
|
|
138
|
-
// allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
|
|
139
|
-
return function (size) { return global.crypto.getRandomValues(Buffer.alloc(size)); };
|
|
140
|
-
}
|
|
141
|
-
var requiredRandomBytes;
|
|
142
|
-
try {
|
|
143
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
144
|
-
requiredRandomBytes = require('crypto').randomBytes;
|
|
145
|
-
}
|
|
146
|
-
catch (e) {
|
|
147
|
-
// keep the fallback
|
|
148
|
-
}
|
|
149
|
-
// NOTE: in transpiled cases the above require might return null/undefined
|
|
150
|
-
return requiredRandomBytes || insecureRandomBytes;
|
|
151
141
|
};
|
|
152
142
|
var randomBytes = detectRandomBytes();
|
|
153
143
|
function isAnyArrayBuffer(value) {
|
|
@@ -404,7 +394,7 @@ var UUID = /** @class */ (function () {
|
|
|
404
394
|
return this.inspect();
|
|
405
395
|
};
|
|
406
396
|
UUID.prototype.inspect = function () {
|
|
407
|
-
return "new UUID(\""
|
|
397
|
+
return "new UUID(\"".concat(this.toHexString(), "\")");
|
|
408
398
|
};
|
|
409
399
|
return UUID;
|
|
410
400
|
}());
|
|
@@ -417,6 +407,13 @@ Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
|
|
|
417
407
|
*/
|
|
418
408
|
var Binary = /** @class */ (function () {
|
|
419
409
|
/**
|
|
410
|
+
* Create a new Binary instance.
|
|
411
|
+
*
|
|
412
|
+
* This constructor can accept a string as its first argument. In this case,
|
|
413
|
+
* this string will be encoded using ISO-8859-1, **not** using UTF-8.
|
|
414
|
+
* This is almost certainly not what you want. Use `new Binary(Buffer.from(string))`
|
|
415
|
+
* instead to convert the string to a Buffer using UTF-8 first.
|
|
416
|
+
*
|
|
420
417
|
* @param buffer - a buffer object containing the binary data.
|
|
421
418
|
* @param subType - the option binary type.
|
|
422
419
|
*/
|
|
@@ -576,7 +573,7 @@ var Binary = /** @class */ (function () {
|
|
|
576
573
|
if (this.sub_type === Binary.SUBTYPE_UUID) {
|
|
577
574
|
return new UUID(this.buffer.slice(0, this.position));
|
|
578
575
|
}
|
|
579
|
-
throw new BSONError("Binary sub_type \""
|
|
576
|
+
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."));
|
|
580
577
|
};
|
|
581
578
|
/** @internal */
|
|
582
579
|
Binary.fromExtendedJSON = function (doc, options) {
|
|
@@ -600,7 +597,7 @@ var Binary = /** @class */ (function () {
|
|
|
600
597
|
data = uuidHexStringToBuffer(doc.$uuid);
|
|
601
598
|
}
|
|
602
599
|
if (!data) {
|
|
603
|
-
throw new BSONTypeError("Unexpected Binary Extended JSON format "
|
|
600
|
+
throw new BSONTypeError("Unexpected Binary Extended JSON format ".concat(JSON.stringify(doc)));
|
|
604
601
|
}
|
|
605
602
|
return new Binary(data, type);
|
|
606
603
|
};
|
|
@@ -610,7 +607,7 @@ var Binary = /** @class */ (function () {
|
|
|
610
607
|
};
|
|
611
608
|
Binary.prototype.inspect = function () {
|
|
612
609
|
var asBuffer = this.value(true);
|
|
613
|
-
return "new Binary(Buffer.from(\""
|
|
610
|
+
return "new Binary(Buffer.from(\"".concat(asBuffer.toString('hex'), "\", \"hex\"), ").concat(this.sub_type, ")");
|
|
614
611
|
};
|
|
615
612
|
/**
|
|
616
613
|
* Binary default subtype
|
|
@@ -677,7 +674,7 @@ var Code = /** @class */ (function () {
|
|
|
677
674
|
};
|
|
678
675
|
Code.prototype.inspect = function () {
|
|
679
676
|
var codeJson = this.toJSON();
|
|
680
|
-
return "new Code(\""
|
|
677
|
+
return "new Code(\"".concat(String(codeJson.code), "\"").concat(codeJson.scope ? ", ".concat(JSON.stringify(codeJson.scope)) : '', ")");
|
|
681
678
|
};
|
|
682
679
|
return Code;
|
|
683
680
|
}());
|
|
@@ -768,7 +765,7 @@ var DBRef = /** @class */ (function () {
|
|
|
768
765
|
DBRef.prototype.inspect = function () {
|
|
769
766
|
// NOTE: if OID is an ObjectId class it will just print the oid string.
|
|
770
767
|
var oid = this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString();
|
|
771
|
-
return "new DBRef(\""
|
|
768
|
+
return "new DBRef(\"".concat(this.namespace, "\", new ObjectId(\"").concat(String(oid), "\")").concat(this.db ? ", \"".concat(this.db, "\"") : '', ")");
|
|
772
769
|
};
|
|
773
770
|
return DBRef;
|
|
774
771
|
}());
|
|
@@ -1005,7 +1002,6 @@ var Long = /** @class */ (function () {
|
|
|
1005
1002
|
/**
|
|
1006
1003
|
* Tests if the specified object is a Long.
|
|
1007
1004
|
*/
|
|
1008
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
1009
1005
|
Long.isLong = function (value) {
|
|
1010
1006
|
return isObjectLike(value) && value['__isLong__'] === true;
|
|
1011
1007
|
};
|
|
@@ -1162,6 +1158,7 @@ var Long = /** @class */ (function () {
|
|
|
1162
1158
|
// into the result, and subtract it from the remainder. It is critical that
|
|
1163
1159
|
// the approximate value is less than or equal to the real value so that the
|
|
1164
1160
|
// remainder never becomes negative.
|
|
1161
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
1165
1162
|
rem = this;
|
|
1166
1163
|
while (rem.gte(divisor)) {
|
|
1167
1164
|
// Approximate the result of division. This may be a little greater or
|
|
@@ -1645,7 +1642,7 @@ var Long = /** @class */ (function () {
|
|
|
1645
1642
|
return this.inspect();
|
|
1646
1643
|
};
|
|
1647
1644
|
Long.prototype.inspect = function () {
|
|
1648
|
-
return "new Long(\""
|
|
1645
|
+
return "new Long(\"".concat(this.toString(), "\"").concat(this.unsigned ? ', true' : '', ")");
|
|
1649
1646
|
};
|
|
1650
1647
|
Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
|
|
1651
1648
|
/** Maximum unsigned value. */
|
|
@@ -1756,7 +1753,7 @@ function lessThan(left, right) {
|
|
|
1756
1753
|
return false;
|
|
1757
1754
|
}
|
|
1758
1755
|
function invalidErr(string, message) {
|
|
1759
|
-
throw new BSONTypeError("\""
|
|
1756
|
+
throw new BSONTypeError("\"".concat(string, "\" is not a valid Decimal128 string - ").concat(message));
|
|
1760
1757
|
}
|
|
1761
1758
|
/**
|
|
1762
1759
|
* A class representation of the BSON Decimal128 type.
|
|
@@ -2254,35 +2251,35 @@ var Decimal128 = /** @class */ (function () {
|
|
|
2254
2251
|
// as + or - 0 and using the non-scientific exponent (this is for the "invalid
|
|
2255
2252
|
// representation should be treated as 0/-0" spec cases in decimal128-1.json)
|
|
2256
2253
|
if (significand_digits > 34) {
|
|
2257
|
-
string.push(""
|
|
2254
|
+
string.push("".concat(0));
|
|
2258
2255
|
if (exponent > 0)
|
|
2259
|
-
string.push(
|
|
2256
|
+
string.push("E+".concat(exponent));
|
|
2260
2257
|
else if (exponent < 0)
|
|
2261
|
-
string.push(
|
|
2258
|
+
string.push("E".concat(exponent));
|
|
2262
2259
|
return string.join('');
|
|
2263
2260
|
}
|
|
2264
|
-
string.push(""
|
|
2261
|
+
string.push("".concat(significand[index++]));
|
|
2265
2262
|
significand_digits = significand_digits - 1;
|
|
2266
2263
|
if (significand_digits) {
|
|
2267
2264
|
string.push('.');
|
|
2268
2265
|
}
|
|
2269
2266
|
for (var i = 0; i < significand_digits; i++) {
|
|
2270
|
-
string.push(""
|
|
2267
|
+
string.push("".concat(significand[index++]));
|
|
2271
2268
|
}
|
|
2272
2269
|
// Exponent
|
|
2273
2270
|
string.push('E');
|
|
2274
2271
|
if (scientific_exponent > 0) {
|
|
2275
|
-
string.push(
|
|
2272
|
+
string.push("+".concat(scientific_exponent));
|
|
2276
2273
|
}
|
|
2277
2274
|
else {
|
|
2278
|
-
string.push(""
|
|
2275
|
+
string.push("".concat(scientific_exponent));
|
|
2279
2276
|
}
|
|
2280
2277
|
}
|
|
2281
2278
|
else {
|
|
2282
2279
|
// Regular format with no decimal place
|
|
2283
2280
|
if (exponent >= 0) {
|
|
2284
2281
|
for (var i = 0; i < significand_digits; i++) {
|
|
2285
|
-
string.push(""
|
|
2282
|
+
string.push("".concat(significand[index++]));
|
|
2286
2283
|
}
|
|
2287
2284
|
}
|
|
2288
2285
|
else {
|
|
@@ -2290,7 +2287,7 @@ var Decimal128 = /** @class */ (function () {
|
|
|
2290
2287
|
// non-zero digits before radix
|
|
2291
2288
|
if (radix_position > 0) {
|
|
2292
2289
|
for (var i = 0; i < radix_position; i++) {
|
|
2293
|
-
string.push(""
|
|
2290
|
+
string.push("".concat(significand[index++]));
|
|
2294
2291
|
}
|
|
2295
2292
|
}
|
|
2296
2293
|
else {
|
|
@@ -2302,7 +2299,7 @@ var Decimal128 = /** @class */ (function () {
|
|
|
2302
2299
|
string.push('0');
|
|
2303
2300
|
}
|
|
2304
2301
|
for (var i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
|
|
2305
|
-
string.push(""
|
|
2302
|
+
string.push("".concat(significand[index++]));
|
|
2306
2303
|
}
|
|
2307
2304
|
}
|
|
2308
2305
|
}
|
|
@@ -2324,7 +2321,7 @@ var Decimal128 = /** @class */ (function () {
|
|
|
2324
2321
|
return this.inspect();
|
|
2325
2322
|
};
|
|
2326
2323
|
Decimal128.prototype.inspect = function () {
|
|
2327
|
-
return "new Decimal128(\""
|
|
2324
|
+
return "new Decimal128(\"".concat(this.toString(), "\")");
|
|
2328
2325
|
};
|
|
2329
2326
|
return Decimal128;
|
|
2330
2327
|
}());
|
|
@@ -2371,7 +2368,7 @@ var Double = /** @class */ (function () {
|
|
|
2371
2368
|
// NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
|
|
2372
2369
|
// explicitly provided `-0` then we need to ensure the sign makes it into the output
|
|
2373
2370
|
if (Object.is(Math.sign(this.value), -0)) {
|
|
2374
|
-
return { $numberDouble: "-"
|
|
2371
|
+
return { $numberDouble: "-".concat(this.value.toFixed(1)) };
|
|
2375
2372
|
}
|
|
2376
2373
|
var $numberDouble;
|
|
2377
2374
|
if (Number.isInteger(this.value)) {
|
|
@@ -2396,7 +2393,7 @@ var Double = /** @class */ (function () {
|
|
|
2396
2393
|
};
|
|
2397
2394
|
Double.prototype.inspect = function () {
|
|
2398
2395
|
var eJSON = this.toExtendedJSON();
|
|
2399
|
-
return "new Double("
|
|
2396
|
+
return "new Double(".concat(eJSON.$numberDouble, ")");
|
|
2400
2397
|
};
|
|
2401
2398
|
return Double;
|
|
2402
2399
|
}());
|
|
@@ -2450,7 +2447,7 @@ var Int32 = /** @class */ (function () {
|
|
|
2450
2447
|
return this.inspect();
|
|
2451
2448
|
};
|
|
2452
2449
|
Int32.prototype.inspect = function () {
|
|
2453
|
-
return "new Int32("
|
|
2450
|
+
return "new Int32(".concat(this.valueOf(), ")");
|
|
2454
2451
|
};
|
|
2455
2452
|
return Int32;
|
|
2456
2453
|
}());
|
|
@@ -2784,7 +2781,7 @@ var ObjectId = /** @class */ (function () {
|
|
|
2784
2781
|
return this.inspect();
|
|
2785
2782
|
};
|
|
2786
2783
|
ObjectId.prototype.inspect = function () {
|
|
2787
|
-
return "new ObjectId(\""
|
|
2784
|
+
return "new ObjectId(\"".concat(this.toHexString(), "\")");
|
|
2788
2785
|
};
|
|
2789
2786
|
/** @internal */
|
|
2790
2787
|
ObjectId.index = Math.floor(Math.random() * 0xffffff);
|
|
@@ -2824,10 +2821,10 @@ var BSONRegExp = /** @class */ (function () {
|
|
|
2824
2821
|
this.pattern = pattern;
|
|
2825
2822
|
this.options = alphabetize(options !== null && options !== void 0 ? options : '');
|
|
2826
2823
|
if (this.pattern.indexOf('\x00') !== -1) {
|
|
2827
|
-
throw new BSONError("BSON Regex patterns cannot contain null bytes, found: "
|
|
2824
|
+
throw new BSONError("BSON Regex patterns cannot contain null bytes, found: ".concat(JSON.stringify(this.pattern)));
|
|
2828
2825
|
}
|
|
2829
2826
|
if (this.options.indexOf('\x00') !== -1) {
|
|
2830
|
-
throw new BSONError("BSON Regex options cannot contain null bytes, found: "
|
|
2827
|
+
throw new BSONError("BSON Regex options cannot contain null bytes, found: ".concat(JSON.stringify(this.options)));
|
|
2831
2828
|
}
|
|
2832
2829
|
// Validate options
|
|
2833
2830
|
for (var i = 0; i < this.options.length; i++) {
|
|
@@ -2837,7 +2834,7 @@ var BSONRegExp = /** @class */ (function () {
|
|
|
2837
2834
|
this.options[i] === 'l' ||
|
|
2838
2835
|
this.options[i] === 's' ||
|
|
2839
2836
|
this.options[i] === 'u')) {
|
|
2840
|
-
throw new BSONError("The regular expression option ["
|
|
2837
|
+
throw new BSONError("The regular expression option [".concat(this.options[i], "] is not supported"));
|
|
2841
2838
|
}
|
|
2842
2839
|
}
|
|
2843
2840
|
}
|
|
@@ -2868,7 +2865,7 @@ var BSONRegExp = /** @class */ (function () {
|
|
|
2868
2865
|
if ('$regularExpression' in doc) {
|
|
2869
2866
|
return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
|
|
2870
2867
|
}
|
|
2871
|
-
throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: "
|
|
2868
|
+
throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(doc)));
|
|
2872
2869
|
};
|
|
2873
2870
|
return BSONRegExp;
|
|
2874
2871
|
}());
|
|
@@ -2897,7 +2894,7 @@ var BSONSymbol = /** @class */ (function () {
|
|
|
2897
2894
|
};
|
|
2898
2895
|
/** @internal */
|
|
2899
2896
|
BSONSymbol.prototype.inspect = function () {
|
|
2900
|
-
return "new BSONSymbol(\""
|
|
2897
|
+
return "new BSONSymbol(\"".concat(this.value, "\")");
|
|
2901
2898
|
};
|
|
2902
2899
|
BSONSymbol.prototype.toJSON = function () {
|
|
2903
2900
|
return this.value;
|
|
@@ -2929,7 +2926,7 @@ var Timestamp = /** @class */ (function (_super) {
|
|
|
2929
2926
|
function Timestamp(low, high) {
|
|
2930
2927
|
var _this = this;
|
|
2931
2928
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2932
|
-
|
|
2929
|
+
// @ts-expect-error
|
|
2933
2930
|
if (!(_this instanceof Timestamp))
|
|
2934
2931
|
return new Timestamp(low, high);
|
|
2935
2932
|
if (Long.isLong(low)) {
|
|
@@ -2993,7 +2990,7 @@ var Timestamp = /** @class */ (function (_super) {
|
|
|
2993
2990
|
return this.inspect();
|
|
2994
2991
|
};
|
|
2995
2992
|
Timestamp.prototype.inspect = function () {
|
|
2996
|
-
return "new Timestamp({ t: "
|
|
2993
|
+
return "new Timestamp({ t: ".concat(this.getHighBits(), ", i: ").concat(this.getLowBits(), " })");
|
|
2997
2994
|
};
|
|
2998
2995
|
Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
|
|
2999
2996
|
return Timestamp;
|
|
@@ -3006,7 +3003,8 @@ function isBSONType(value) {
|
|
|
3006
3003
|
var BSON_INT32_MAX$1 = 0x7fffffff;
|
|
3007
3004
|
var BSON_INT32_MIN$1 = -0x80000000;
|
|
3008
3005
|
// INT64 boundaries
|
|
3009
|
-
|
|
3006
|
+
// const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
|
|
3007
|
+
var BSON_INT64_MAX$1 = 0x8000000000000000;
|
|
3010
3008
|
var BSON_INT64_MIN$1 = -0x8000000000000000;
|
|
3011
3009
|
// all the types where we don't need to do any special processing and can just pass the EJSON
|
|
3012
3010
|
//straight to type.fromExtendedJSON
|
|
@@ -3102,7 +3100,7 @@ function deserializeValue(value, options) {
|
|
|
3102
3100
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3103
3101
|
function serializeArray(array, options) {
|
|
3104
3102
|
return array.map(function (v, index) {
|
|
3105
|
-
options.seenObjects.push({ propertyName: "index "
|
|
3103
|
+
options.seenObjects.push({ propertyName: "index ".concat(index), obj: null });
|
|
3106
3104
|
try {
|
|
3107
3105
|
return serializeValue(v, options);
|
|
3108
3106
|
}
|
|
@@ -3124,20 +3122,20 @@ function serializeValue(value, options) {
|
|
|
3124
3122
|
var props = options.seenObjects.map(function (entry) { return entry.propertyName; });
|
|
3125
3123
|
var leadingPart = props
|
|
3126
3124
|
.slice(0, index)
|
|
3127
|
-
.map(function (prop) { return prop
|
|
3125
|
+
.map(function (prop) { return "".concat(prop, " -> "); })
|
|
3128
3126
|
.join('');
|
|
3129
3127
|
var alreadySeen = props[index];
|
|
3130
3128
|
var circularPart = ' -> ' +
|
|
3131
3129
|
props
|
|
3132
3130
|
.slice(index + 1, props.length - 1)
|
|
3133
|
-
.map(function (prop) { return prop
|
|
3131
|
+
.map(function (prop) { return "".concat(prop, " -> "); })
|
|
3134
3132
|
.join('');
|
|
3135
3133
|
var current = props[props.length - 1];
|
|
3136
3134
|
var leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
|
|
3137
3135
|
var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
|
|
3138
3136
|
throw new BSONTypeError('Converting circular structure to EJSON:\n' +
|
|
3139
|
-
|
|
3140
|
-
|
|
3137
|
+
" ".concat(leadingPart).concat(alreadySeen).concat(circularPart).concat(current, "\n") +
|
|
3138
|
+
" ".concat(leadingSpace, "\\").concat(dashes, "/"));
|
|
3141
3139
|
}
|
|
3142
3140
|
options.seenObjects[options.seenObjects.length - 1].obj = value;
|
|
3143
3141
|
}
|
|
@@ -3216,7 +3214,18 @@ function serializeDocument(doc, options) {
|
|
|
3216
3214
|
for (var name in doc) {
|
|
3217
3215
|
options.seenObjects.push({ propertyName: name, obj: null });
|
|
3218
3216
|
try {
|
|
3219
|
-
|
|
3217
|
+
var value = serializeValue(doc[name], options);
|
|
3218
|
+
if (name === '__proto__') {
|
|
3219
|
+
Object.defineProperty(_doc, name, {
|
|
3220
|
+
value: value,
|
|
3221
|
+
writable: true,
|
|
3222
|
+
enumerable: true,
|
|
3223
|
+
configurable: true
|
|
3224
|
+
});
|
|
3225
|
+
}
|
|
3226
|
+
else {
|
|
3227
|
+
_doc[name] = value;
|
|
3228
|
+
}
|
|
3220
3229
|
}
|
|
3221
3230
|
finally {
|
|
3222
3231
|
options.seenObjects.pop();
|
|
@@ -3286,7 +3295,7 @@ var EJSON;
|
|
|
3286
3295
|
finalOptions.relaxed = !finalOptions.strict;
|
|
3287
3296
|
return JSON.parse(text, function (key, value) {
|
|
3288
3297
|
if (key.indexOf('\x00') !== -1) {
|
|
3289
|
-
throw new BSONError("BSON Document field names cannot contain null bytes, found: "
|
|
3298
|
+
throw new BSONError("BSON Document field names cannot contain null bytes, found: ".concat(JSON.stringify(key)));
|
|
3290
3299
|
}
|
|
3291
3300
|
return deserializeValue(value, finalOptions);
|
|
3292
3301
|
});
|
|
@@ -3652,13 +3661,14 @@ value, serializeFunctions, isArray, ignoreUndefined) {
|
|
|
3652
3661
|
}
|
|
3653
3662
|
}
|
|
3654
3663
|
else if (value['_bsontype'] === 'Binary') {
|
|
3664
|
+
var binary = value;
|
|
3655
3665
|
// Check what kind of subtype we have
|
|
3656
|
-
if (
|
|
3666
|
+
if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
|
|
3657
3667
|
return ((name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) +
|
|
3658
|
-
(
|
|
3668
|
+
(binary.position + 1 + 4 + 1 + 4));
|
|
3659
3669
|
}
|
|
3660
3670
|
else {
|
|
3661
|
-
return ((name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (
|
|
3671
|
+
return ((name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (binary.position + 1 + 4 + 1));
|
|
3662
3672
|
}
|
|
3663
3673
|
}
|
|
3664
3674
|
else if (value['_bsontype'] === 'Symbol') {
|
|
@@ -3795,16 +3805,16 @@ function deserialize$1(buffer, options, isArray) {
|
|
|
3795
3805
|
(buffer[index + 2] << 16) |
|
|
3796
3806
|
(buffer[index + 3] << 24);
|
|
3797
3807
|
if (size < 5) {
|
|
3798
|
-
throw new BSONError("bson size must be >= 5, is "
|
|
3808
|
+
throw new BSONError("bson size must be >= 5, is ".concat(size));
|
|
3799
3809
|
}
|
|
3800
3810
|
if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
|
|
3801
|
-
throw new BSONError("buffer length "
|
|
3811
|
+
throw new BSONError("buffer length ".concat(buffer.length, " must be >= bson size ").concat(size));
|
|
3802
3812
|
}
|
|
3803
3813
|
if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
|
|
3804
|
-
throw new BSONError("buffer length "
|
|
3814
|
+
throw new BSONError("buffer length ".concat(buffer.length, " must === bson size ").concat(size));
|
|
3805
3815
|
}
|
|
3806
3816
|
if (size + index > buffer.byteLength) {
|
|
3807
|
-
throw new BSONError("(bson size "
|
|
3817
|
+
throw new BSONError("(bson size ".concat(size, " + options.index ").concat(index, " must be <= buffer length ").concat(buffer.byteLength, ")"));
|
|
3808
3818
|
}
|
|
3809
3819
|
// Illegal end value
|
|
3810
3820
|
if (buffer[index + size - 1] !== 0) {
|
|
@@ -3881,6 +3891,7 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
3881
3891
|
var done = false;
|
|
3882
3892
|
var isPossibleDBRef = isArray ? false : null;
|
|
3883
3893
|
// While we have more left data left keep parsing
|
|
3894
|
+
var dataview = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
3884
3895
|
while (!done) {
|
|
3885
3896
|
// Read the type
|
|
3886
3897
|
var elementType = buffer[index++];
|
|
@@ -3941,11 +3952,11 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
3941
3952
|
(buffer[index++] << 24);
|
|
3942
3953
|
}
|
|
3943
3954
|
else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
|
|
3944
|
-
value = new Double(
|
|
3955
|
+
value = new Double(dataview.getFloat64(index, true));
|
|
3945
3956
|
index = index + 8;
|
|
3946
3957
|
}
|
|
3947
3958
|
else if (elementType === BSON_DATA_NUMBER) {
|
|
3948
|
-
value =
|
|
3959
|
+
value = dataview.getFloat64(index, true);
|
|
3949
3960
|
index = index + 8;
|
|
3950
3961
|
}
|
|
3951
3962
|
else if (elementType === BSON_DATA_DATE) {
|
|
@@ -4343,7 +4354,7 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
4343
4354
|
value = new DBRef(namespace, oid);
|
|
4344
4355
|
}
|
|
4345
4356
|
else {
|
|
4346
|
-
throw new BSONError(
|
|
4357
|
+
throw new BSONError("Detected unknown BSON type ".concat(elementType.toString(16), " for fieldname \"").concat(name, "\""));
|
|
4347
4358
|
}
|
|
4348
4359
|
if (name === '__proto__') {
|
|
4349
4360
|
Object.defineProperty(object, name, {
|
|
@@ -4381,10 +4392,12 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
4381
4392
|
* @internal
|
|
4382
4393
|
*/
|
|
4383
4394
|
function isolateEval(functionString, functionCache, object) {
|
|
4395
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
4384
4396
|
if (!functionCache)
|
|
4385
4397
|
return new Function(functionString);
|
|
4386
4398
|
// Check for cache hit, eval if missing and return cached function
|
|
4387
4399
|
if (functionCache[functionString] == null) {
|
|
4400
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
4388
4401
|
functionCache[functionString] = new Function(functionString);
|
|
4389
4402
|
}
|
|
4390
4403
|
// Set the object
|
|
@@ -4406,74 +4419,6 @@ function getValidatedString(buffer, start, end, shouldValidateUtf8) {
|
|
|
4406
4419
|
return value;
|
|
4407
4420
|
}
|
|
4408
4421
|
|
|
4409
|
-
// Copyright (c) 2008, Fair Oaks Labs, Inc.
|
|
4410
|
-
function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
|
|
4411
|
-
var e;
|
|
4412
|
-
var m;
|
|
4413
|
-
var c;
|
|
4414
|
-
var bBE = endian === 'big';
|
|
4415
|
-
var eLen = nBytes * 8 - mLen - 1;
|
|
4416
|
-
var eMax = (1 << eLen) - 1;
|
|
4417
|
-
var eBias = eMax >> 1;
|
|
4418
|
-
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
4419
|
-
var i = bBE ? nBytes - 1 : 0;
|
|
4420
|
-
var d = bBE ? -1 : 1;
|
|
4421
|
-
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
|
4422
|
-
value = Math.abs(value);
|
|
4423
|
-
if (isNaN(value) || value === Infinity) {
|
|
4424
|
-
m = isNaN(value) ? 1 : 0;
|
|
4425
|
-
e = eMax;
|
|
4426
|
-
}
|
|
4427
|
-
else {
|
|
4428
|
-
e = Math.floor(Math.log(value) / Math.LN2);
|
|
4429
|
-
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
4430
|
-
e--;
|
|
4431
|
-
c *= 2;
|
|
4432
|
-
}
|
|
4433
|
-
if (e + eBias >= 1) {
|
|
4434
|
-
value += rt / c;
|
|
4435
|
-
}
|
|
4436
|
-
else {
|
|
4437
|
-
value += rt * Math.pow(2, 1 - eBias);
|
|
4438
|
-
}
|
|
4439
|
-
if (value * c >= 2) {
|
|
4440
|
-
e++;
|
|
4441
|
-
c /= 2;
|
|
4442
|
-
}
|
|
4443
|
-
if (e + eBias >= eMax) {
|
|
4444
|
-
m = 0;
|
|
4445
|
-
e = eMax;
|
|
4446
|
-
}
|
|
4447
|
-
else if (e + eBias >= 1) {
|
|
4448
|
-
m = (value * c - 1) * Math.pow(2, mLen);
|
|
4449
|
-
e = e + eBias;
|
|
4450
|
-
}
|
|
4451
|
-
else {
|
|
4452
|
-
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
4453
|
-
e = 0;
|
|
4454
|
-
}
|
|
4455
|
-
}
|
|
4456
|
-
if (isNaN(value))
|
|
4457
|
-
m = 0;
|
|
4458
|
-
while (mLen >= 8) {
|
|
4459
|
-
buffer[offset + i] = m & 0xff;
|
|
4460
|
-
i += d;
|
|
4461
|
-
m /= 256;
|
|
4462
|
-
mLen -= 8;
|
|
4463
|
-
}
|
|
4464
|
-
e = (e << mLen) | m;
|
|
4465
|
-
if (isNaN(value))
|
|
4466
|
-
e += 8;
|
|
4467
|
-
eLen += mLen;
|
|
4468
|
-
while (eLen > 0) {
|
|
4469
|
-
buffer[offset + i] = e & 0xff;
|
|
4470
|
-
i += d;
|
|
4471
|
-
e /= 256;
|
|
4472
|
-
eLen -= 8;
|
|
4473
|
-
}
|
|
4474
|
-
buffer[offset + i - d] |= s * 128;
|
|
4475
|
-
}
|
|
4476
|
-
|
|
4477
4422
|
var regexp = /\x00/; // eslint-disable-line no-control-regex
|
|
4478
4423
|
var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
|
|
4479
4424
|
/*
|
|
@@ -4504,6 +4449,8 @@ function serializeString(buffer, key, value, index, isArray) {
|
|
|
4504
4449
|
buffer[index++] = 0;
|
|
4505
4450
|
return index;
|
|
4506
4451
|
}
|
|
4452
|
+
var SPACE_FOR_FLOAT64 = new Uint8Array(8);
|
|
4453
|
+
var DV_FOR_FLOAT64 = new DataView(SPACE_FOR_FLOAT64.buffer, SPACE_FOR_FLOAT64.byteOffset, SPACE_FOR_FLOAT64.byteLength);
|
|
4507
4454
|
function serializeNumber(buffer, key, value, index, isArray) {
|
|
4508
4455
|
// We have an integer value
|
|
4509
4456
|
// TODO(NODE-2529): Add support for big int
|
|
@@ -4537,7 +4484,8 @@ function serializeNumber(buffer, key, value, index, isArray) {
|
|
|
4537
4484
|
index = index + numberOfWrittenBytes;
|
|
4538
4485
|
buffer[index++] = 0;
|
|
4539
4486
|
// Write float
|
|
4540
|
-
|
|
4487
|
+
DV_FOR_FLOAT64.setFloat64(0, value, true);
|
|
4488
|
+
buffer.set(SPACE_FOR_FLOAT64, index);
|
|
4541
4489
|
// Adjust index
|
|
4542
4490
|
index = index + 8;
|
|
4543
4491
|
}
|
|
@@ -4816,7 +4764,8 @@ function serializeDouble(buffer, key, value, index, isArray) {
|
|
|
4816
4764
|
index = index + numberOfWrittenBytes;
|
|
4817
4765
|
buffer[index++] = 0;
|
|
4818
4766
|
// Write float
|
|
4819
|
-
|
|
4767
|
+
DV_FOR_FLOAT64.setFloat64(0, value.value, true);
|
|
4768
|
+
buffer.set(SPACE_FOR_FLOAT64, index);
|
|
4820
4769
|
// Adjust index
|
|
4821
4770
|
index = index + 8;
|
|
4822
4771
|
return index;
|
|
@@ -5026,7 +4975,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
5026
4975
|
if (Array.isArray(object)) {
|
|
5027
4976
|
// Get object keys
|
|
5028
4977
|
for (var i = 0; i < object.length; i++) {
|
|
5029
|
-
var key =
|
|
4978
|
+
var key = "".concat(i);
|
|
5030
4979
|
var value = object[i];
|
|
5031
4980
|
// Is there an override value
|
|
5032
4981
|
if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
|
|
@@ -5101,7 +5050,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
5101
5050
|
index = serializeMinMax(buffer, key, value, index, true);
|
|
5102
5051
|
}
|
|
5103
5052
|
else if (typeof value['_bsontype'] !== 'undefined') {
|
|
5104
|
-
throw new BSONTypeError(
|
|
5053
|
+
throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
|
|
5105
5054
|
}
|
|
5106
5055
|
}
|
|
5107
5056
|
}
|
|
@@ -5200,7 +5149,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
5200
5149
|
index = serializeMinMax(buffer, key, value, index);
|
|
5201
5150
|
}
|
|
5202
5151
|
else if (typeof value['_bsontype'] !== 'undefined') {
|
|
5203
|
-
throw new BSONTypeError(
|
|
5152
|
+
throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
|
|
5204
5153
|
}
|
|
5205
5154
|
}
|
|
5206
5155
|
}
|
|
@@ -5305,7 +5254,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
5305
5254
|
index = serializeMinMax(buffer, key, value, index);
|
|
5306
5255
|
}
|
|
5307
5256
|
else if (typeof value['_bsontype'] !== 'undefined') {
|
|
5308
|
-
throw new BSONTypeError(
|
|
5257
|
+
throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
|
|
5309
5258
|
}
|
|
5310
5259
|
}
|
|
5311
5260
|
}
|