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.
Files changed (73) hide show
  1. package/bower.json +1 -1
  2. package/bson.d.ts +8 -1
  3. package/dist/bson.browser.esm.js +95 -143
  4. package/dist/bson.browser.esm.js.map +1 -1
  5. package/dist/bson.browser.umd.js +95 -143
  6. package/dist/bson.browser.umd.js.map +1 -1
  7. package/dist/bson.bundle.js +95 -143
  8. package/dist/bson.bundle.js.map +1 -1
  9. package/dist/bson.esm.js +92 -143
  10. package/dist/bson.esm.js.map +1 -1
  11. package/lib/binary.js +13 -6
  12. package/lib/binary.js.map +1 -1
  13. package/lib/bson.js +19 -6
  14. package/lib/bson.js.map +1 -1
  15. package/lib/code.js +1 -1
  16. package/lib/code.js.map +1 -1
  17. package/lib/db_ref.js +2 -2
  18. package/lib/db_ref.js.map +1 -1
  19. package/lib/decimal128.js +13 -13
  20. package/lib/decimal128.js.map +1 -1
  21. package/lib/double.js +2 -2
  22. package/lib/double.js.map +1 -1
  23. package/lib/ensure_buffer.js +1 -1
  24. package/lib/ensure_buffer.js.map +1 -1
  25. package/lib/extended_json.js +24 -12
  26. package/lib/extended_json.js.map +1 -1
  27. package/lib/int_32.js +1 -1
  28. package/lib/int_32.js.map +1 -1
  29. package/lib/long.js +3 -3
  30. package/lib/long.js.map +1 -1
  31. package/lib/map.js +1 -1
  32. package/lib/map.js.map +1 -1
  33. package/lib/objectid.js +8 -8
  34. package/lib/objectid.js.map +1 -1
  35. package/lib/parser/calculate_size.js +10 -9
  36. package/lib/parser/calculate_size.js.map +1 -1
  37. package/lib/parser/deserializer.js +13 -10
  38. package/lib/parser/deserializer.js.map +1 -1
  39. package/lib/parser/serializer.js +25 -22
  40. package/lib/parser/serializer.js.map +1 -1
  41. package/lib/parser/utils.js +23 -19
  42. package/lib/parser/utils.js.map +1 -1
  43. package/lib/regexp.js +4 -4
  44. package/lib/regexp.js.map +1 -1
  45. package/lib/symbol.js +1 -1
  46. package/lib/symbol.js.map +1 -1
  47. package/lib/timestamp.js +3 -3
  48. package/lib/timestamp.js.map +1 -1
  49. package/lib/utils/global.js +1 -1
  50. package/lib/utils/global.js.map +1 -1
  51. package/lib/uuid.js +9 -9
  52. package/lib/uuid.js.map +1 -1
  53. package/lib/uuid_utils.js +1 -1
  54. package/lib/uuid_utils.js.map +1 -1
  55. package/package.json +16 -24
  56. package/src/binary.ts +7 -0
  57. package/src/code.ts +1 -1
  58. package/src/db_ref.ts +1 -1
  59. package/src/decimal128.ts +3 -3
  60. package/src/extended_json.ts +13 -2
  61. package/src/long.ts +32 -7
  62. package/src/objectid.ts +1 -1
  63. package/src/parser/calculate_size.ts +4 -3
  64. package/src/parser/deserializer.ts +6 -3
  65. package/src/parser/serializer.ts +14 -7
  66. package/src/parser/utils.ts +24 -20
  67. package/src/timestamp.ts +1 -1
  68. package/src/utils/global.ts +1 -1
  69. package/src/uuid.ts +1 -1
  70. package/bson-ts34.d.ts +0 -1133
  71. package/lib/float_parser.js +0 -137
  72. package/lib/float_parser.js.map +0 -1
  73. package/src/float_parser.ts +0 -152
package/bower.json CHANGED
@@ -22,5 +22,5 @@
22
22
  "test",
23
23
  "tools"
24
24
  ],
25
- "version": "4.6.4"
25
+ "version": "4.6.5"
26
26
  }
package/bson.d.ts CHANGED
@@ -32,6 +32,13 @@ export declare class Binary {
32
32
  sub_type: number;
33
33
  position: number;
34
34
  /**
35
+ * Create a new Binary instance.
36
+ *
37
+ * This constructor can accept a string as its first argument. In this case,
38
+ * this string will be encoded using ISO-8859-1, **not** using UTF-8.
39
+ * This is almost certainly not what you want. Use `new Binary(Buffer.from(string))`
40
+ * instead to convert the string to a Buffer using UTF-8 first.
41
+ *
35
42
  * @param buffer - a buffer object containing the binary data.
36
43
  * @param subType - the option binary type.
37
44
  */
@@ -721,7 +728,7 @@ export declare class Long {
721
728
  /**
722
729
  * Tests if the specified object is a Long.
723
730
  */
724
- static isLong(value: any): value is Long;
731
+ static isLong(value: unknown): value is Long;
725
732
  /**
726
733
  * Converts the specified value to a Long.
727
734
  * @param unsigned - Whether unsigned or not, defaults to signed
@@ -2128,11 +2128,11 @@ function checkForMath(potentialGlobal) {
2128
2128
  }
2129
2129
  // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
2130
2130
  function getGlobal() {
2131
- // eslint-disable-next-line no-undef
2132
2131
  return (checkForMath(typeof globalThis === 'object' && globalThis) ||
2133
2132
  checkForMath(typeof window === 'object' && window) ||
2134
2133
  checkForMath(typeof self === 'object' && self) ||
2135
2134
  checkForMath(typeof global === 'object' && global) ||
2135
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
2136
2136
  Function('return this')());
2137
2137
  }
2138
2138
 
@@ -2158,27 +2158,20 @@ var insecureRandomBytes = function insecureRandomBytes(size) {
2158
2158
  return result;
2159
2159
  };
2160
2160
  var detectRandomBytes = function () {
2161
- if (typeof window !== 'undefined') {
2162
- // browser crypto implementation(s)
2163
- var target_1 = window.crypto || window.msCrypto; // allow for IE11
2164
- if (target_1 && target_1.getRandomValues) {
2165
- return function (size) { return target_1.getRandomValues(buffer_1.alloc(size)); };
2161
+ {
2162
+ if (typeof window !== 'undefined') {
2163
+ // browser crypto implementation(s)
2164
+ var target_1 = window.crypto || window.msCrypto; // allow for IE11
2165
+ if (target_1 && target_1.getRandomValues) {
2166
+ return function (size) { return target_1.getRandomValues(buffer_1.alloc(size)); };
2167
+ }
2166
2168
  }
2169
+ if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
2170
+ // allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
2171
+ return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
2172
+ }
2173
+ return insecureRandomBytes;
2167
2174
  }
2168
- if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
2169
- // allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
2170
- return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
2171
- }
2172
- var requiredRandomBytes;
2173
- try {
2174
- // eslint-disable-next-line @typescript-eslint/no-var-requires
2175
- requiredRandomBytes = require('crypto').randomBytes;
2176
- }
2177
- catch (e) {
2178
- // keep the fallback
2179
- }
2180
- // NOTE: in transpiled cases the above require might return null/undefined
2181
- return requiredRandomBytes || insecureRandomBytes;
2182
2175
  };
2183
2176
  var randomBytes = detectRandomBytes();
2184
2177
  function isAnyArrayBuffer(value) {
@@ -2435,7 +2428,7 @@ var UUID = /** @class */ (function () {
2435
2428
  return this.inspect();
2436
2429
  };
2437
2430
  UUID.prototype.inspect = function () {
2438
- return "new UUID(\"" + this.toHexString() + "\")";
2431
+ return "new UUID(\"".concat(this.toHexString(), "\")");
2439
2432
  };
2440
2433
  return UUID;
2441
2434
  }());
@@ -2448,6 +2441,13 @@ Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
2448
2441
  */
2449
2442
  var Binary = /** @class */ (function () {
2450
2443
  /**
2444
+ * Create a new Binary instance.
2445
+ *
2446
+ * This constructor can accept a string as its first argument. In this case,
2447
+ * this string will be encoded using ISO-8859-1, **not** using UTF-8.
2448
+ * This is almost certainly not what you want. Use `new Binary(Buffer.from(string))`
2449
+ * instead to convert the string to a Buffer using UTF-8 first.
2450
+ *
2451
2451
  * @param buffer - a buffer object containing the binary data.
2452
2452
  * @param subType - the option binary type.
2453
2453
  */
@@ -2607,7 +2607,7 @@ var Binary = /** @class */ (function () {
2607
2607
  if (this.sub_type === Binary.SUBTYPE_UUID) {
2608
2608
  return new UUID(this.buffer.slice(0, this.position));
2609
2609
  }
2610
- throw new BSONError("Binary sub_type \"" + this.sub_type + "\" is not supported for converting to UUID. Only \"" + Binary.SUBTYPE_UUID + "\" is currently supported.");
2610
+ 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."));
2611
2611
  };
2612
2612
  /** @internal */
2613
2613
  Binary.fromExtendedJSON = function (doc, options) {
@@ -2631,7 +2631,7 @@ var Binary = /** @class */ (function () {
2631
2631
  data = uuidHexStringToBuffer(doc.$uuid);
2632
2632
  }
2633
2633
  if (!data) {
2634
- throw new BSONTypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc));
2634
+ throw new BSONTypeError("Unexpected Binary Extended JSON format ".concat(JSON.stringify(doc)));
2635
2635
  }
2636
2636
  return new Binary(data, type);
2637
2637
  };
@@ -2641,7 +2641,7 @@ var Binary = /** @class */ (function () {
2641
2641
  };
2642
2642
  Binary.prototype.inspect = function () {
2643
2643
  var asBuffer = this.value(true);
2644
- return "new Binary(Buffer.from(\"" + asBuffer.toString('hex') + "\", \"hex\"), " + this.sub_type + ")";
2644
+ return "new Binary(Buffer.from(\"".concat(asBuffer.toString('hex'), "\", \"hex\"), ").concat(this.sub_type, ")");
2645
2645
  };
2646
2646
  /**
2647
2647
  * Binary default subtype
@@ -2708,7 +2708,7 @@ var Code = /** @class */ (function () {
2708
2708
  };
2709
2709
  Code.prototype.inspect = function () {
2710
2710
  var codeJson = this.toJSON();
2711
- return "new Code(\"" + codeJson.code + "\"" + (codeJson.scope ? ", " + JSON.stringify(codeJson.scope) : '') + ")";
2711
+ return "new Code(\"".concat(String(codeJson.code), "\"").concat(codeJson.scope ? ", ".concat(JSON.stringify(codeJson.scope)) : '', ")");
2712
2712
  };
2713
2713
  return Code;
2714
2714
  }());
@@ -2799,7 +2799,7 @@ var DBRef = /** @class */ (function () {
2799
2799
  DBRef.prototype.inspect = function () {
2800
2800
  // NOTE: if OID is an ObjectId class it will just print the oid string.
2801
2801
  var oid = this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString();
2802
- return "new DBRef(\"" + this.namespace + "\", new ObjectId(\"" + oid + "\")" + (this.db ? ", \"" + this.db + "\"" : '') + ")";
2802
+ return "new DBRef(\"".concat(this.namespace, "\", new ObjectId(\"").concat(String(oid), "\")").concat(this.db ? ", \"".concat(this.db, "\"") : '', ")");
2803
2803
  };
2804
2804
  return DBRef;
2805
2805
  }());
@@ -3036,7 +3036,6 @@ var Long = /** @class */ (function () {
3036
3036
  /**
3037
3037
  * Tests if the specified object is a Long.
3038
3038
  */
3039
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
3040
3039
  Long.isLong = function (value) {
3041
3040
  return isObjectLike(value) && value['__isLong__'] === true;
3042
3041
  };
@@ -3193,6 +3192,7 @@ var Long = /** @class */ (function () {
3193
3192
  // into the result, and subtract it from the remainder. It is critical that
3194
3193
  // the approximate value is less than or equal to the real value so that the
3195
3194
  // remainder never becomes negative.
3195
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3196
3196
  rem = this;
3197
3197
  while (rem.gte(divisor)) {
3198
3198
  // Approximate the result of division. This may be a little greater or
@@ -3676,7 +3676,7 @@ var Long = /** @class */ (function () {
3676
3676
  return this.inspect();
3677
3677
  };
3678
3678
  Long.prototype.inspect = function () {
3679
- return "new Long(\"" + this.toString() + "\"" + (this.unsigned ? ', true' : '') + ")";
3679
+ return "new Long(\"".concat(this.toString(), "\"").concat(this.unsigned ? ', true' : '', ")");
3680
3680
  };
3681
3681
  Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
3682
3682
  /** Maximum unsigned value. */
@@ -3787,7 +3787,7 @@ function lessThan(left, right) {
3787
3787
  return false;
3788
3788
  }
3789
3789
  function invalidErr(string, message) {
3790
- throw new BSONTypeError("\"" + string + "\" is not a valid Decimal128 string - " + message);
3790
+ throw new BSONTypeError("\"".concat(string, "\" is not a valid Decimal128 string - ").concat(message));
3791
3791
  }
3792
3792
  /**
3793
3793
  * A class representation of the BSON Decimal128 type.
@@ -4285,35 +4285,35 @@ var Decimal128 = /** @class */ (function () {
4285
4285
  // as + or - 0 and using the non-scientific exponent (this is for the "invalid
4286
4286
  // representation should be treated as 0/-0" spec cases in decimal128-1.json)
4287
4287
  if (significand_digits > 34) {
4288
- string.push("" + 0);
4288
+ string.push("".concat(0));
4289
4289
  if (exponent > 0)
4290
- string.push('E+' + exponent);
4290
+ string.push("E+".concat(exponent));
4291
4291
  else if (exponent < 0)
4292
- string.push('E' + exponent);
4292
+ string.push("E".concat(exponent));
4293
4293
  return string.join('');
4294
4294
  }
4295
- string.push("" + significand[index++]);
4295
+ string.push("".concat(significand[index++]));
4296
4296
  significand_digits = significand_digits - 1;
4297
4297
  if (significand_digits) {
4298
4298
  string.push('.');
4299
4299
  }
4300
4300
  for (var i = 0; i < significand_digits; i++) {
4301
- string.push("" + significand[index++]);
4301
+ string.push("".concat(significand[index++]));
4302
4302
  }
4303
4303
  // Exponent
4304
4304
  string.push('E');
4305
4305
  if (scientific_exponent > 0) {
4306
- string.push('+' + scientific_exponent);
4306
+ string.push("+".concat(scientific_exponent));
4307
4307
  }
4308
4308
  else {
4309
- string.push("" + scientific_exponent);
4309
+ string.push("".concat(scientific_exponent));
4310
4310
  }
4311
4311
  }
4312
4312
  else {
4313
4313
  // Regular format with no decimal place
4314
4314
  if (exponent >= 0) {
4315
4315
  for (var i = 0; i < significand_digits; i++) {
4316
- string.push("" + significand[index++]);
4316
+ string.push("".concat(significand[index++]));
4317
4317
  }
4318
4318
  }
4319
4319
  else {
@@ -4321,7 +4321,7 @@ var Decimal128 = /** @class */ (function () {
4321
4321
  // non-zero digits before radix
4322
4322
  if (radix_position > 0) {
4323
4323
  for (var i = 0; i < radix_position; i++) {
4324
- string.push("" + significand[index++]);
4324
+ string.push("".concat(significand[index++]));
4325
4325
  }
4326
4326
  }
4327
4327
  else {
@@ -4333,7 +4333,7 @@ var Decimal128 = /** @class */ (function () {
4333
4333
  string.push('0');
4334
4334
  }
4335
4335
  for (var i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
4336
- string.push("" + significand[index++]);
4336
+ string.push("".concat(significand[index++]));
4337
4337
  }
4338
4338
  }
4339
4339
  }
@@ -4355,7 +4355,7 @@ var Decimal128 = /** @class */ (function () {
4355
4355
  return this.inspect();
4356
4356
  };
4357
4357
  Decimal128.prototype.inspect = function () {
4358
- return "new Decimal128(\"" + this.toString() + "\")";
4358
+ return "new Decimal128(\"".concat(this.toString(), "\")");
4359
4359
  };
4360
4360
  return Decimal128;
4361
4361
  }());
@@ -4402,7 +4402,7 @@ var Double = /** @class */ (function () {
4402
4402
  // NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
4403
4403
  // explicitly provided `-0` then we need to ensure the sign makes it into the output
4404
4404
  if (Object.is(Math.sign(this.value), -0)) {
4405
- return { $numberDouble: "-" + this.value.toFixed(1) };
4405
+ return { $numberDouble: "-".concat(this.value.toFixed(1)) };
4406
4406
  }
4407
4407
  var $numberDouble;
4408
4408
  if (Number.isInteger(this.value)) {
@@ -4427,7 +4427,7 @@ var Double = /** @class */ (function () {
4427
4427
  };
4428
4428
  Double.prototype.inspect = function () {
4429
4429
  var eJSON = this.toExtendedJSON();
4430
- return "new Double(" + eJSON.$numberDouble + ")";
4430
+ return "new Double(".concat(eJSON.$numberDouble, ")");
4431
4431
  };
4432
4432
  return Double;
4433
4433
  }());
@@ -4481,7 +4481,7 @@ var Int32 = /** @class */ (function () {
4481
4481
  return this.inspect();
4482
4482
  };
4483
4483
  Int32.prototype.inspect = function () {
4484
- return "new Int32(" + this.valueOf() + ")";
4484
+ return "new Int32(".concat(this.valueOf(), ")");
4485
4485
  };
4486
4486
  return Int32;
4487
4487
  }());
@@ -4815,7 +4815,7 @@ var ObjectId = /** @class */ (function () {
4815
4815
  return this.inspect();
4816
4816
  };
4817
4817
  ObjectId.prototype.inspect = function () {
4818
- return "new ObjectId(\"" + this.toHexString() + "\")";
4818
+ return "new ObjectId(\"".concat(this.toHexString(), "\")");
4819
4819
  };
4820
4820
  /** @internal */
4821
4821
  ObjectId.index = Math.floor(Math.random() * 0xffffff);
@@ -4855,10 +4855,10 @@ var BSONRegExp = /** @class */ (function () {
4855
4855
  this.pattern = pattern;
4856
4856
  this.options = alphabetize(options !== null && options !== void 0 ? options : '');
4857
4857
  if (this.pattern.indexOf('\x00') !== -1) {
4858
- throw new BSONError("BSON Regex patterns cannot contain null bytes, found: " + JSON.stringify(this.pattern));
4858
+ throw new BSONError("BSON Regex patterns cannot contain null bytes, found: ".concat(JSON.stringify(this.pattern)));
4859
4859
  }
4860
4860
  if (this.options.indexOf('\x00') !== -1) {
4861
- throw new BSONError("BSON Regex options cannot contain null bytes, found: " + JSON.stringify(this.options));
4861
+ throw new BSONError("BSON Regex options cannot contain null bytes, found: ".concat(JSON.stringify(this.options)));
4862
4862
  }
4863
4863
  // Validate options
4864
4864
  for (var i = 0; i < this.options.length; i++) {
@@ -4868,7 +4868,7 @@ var BSONRegExp = /** @class */ (function () {
4868
4868
  this.options[i] === 'l' ||
4869
4869
  this.options[i] === 's' ||
4870
4870
  this.options[i] === 'u')) {
4871
- throw new BSONError("The regular expression option [" + this.options[i] + "] is not supported");
4871
+ throw new BSONError("The regular expression option [".concat(this.options[i], "] is not supported"));
4872
4872
  }
4873
4873
  }
4874
4874
  }
@@ -4899,7 +4899,7 @@ var BSONRegExp = /** @class */ (function () {
4899
4899
  if ('$regularExpression' in doc) {
4900
4900
  return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
4901
4901
  }
4902
- throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: " + JSON.stringify(doc));
4902
+ throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(doc)));
4903
4903
  };
4904
4904
  return BSONRegExp;
4905
4905
  }());
@@ -4928,7 +4928,7 @@ var BSONSymbol = /** @class */ (function () {
4928
4928
  };
4929
4929
  /** @internal */
4930
4930
  BSONSymbol.prototype.inspect = function () {
4931
- return "new BSONSymbol(\"" + this.value + "\")";
4931
+ return "new BSONSymbol(\"".concat(this.value, "\")");
4932
4932
  };
4933
4933
  BSONSymbol.prototype.toJSON = function () {
4934
4934
  return this.value;
@@ -4960,7 +4960,7 @@ var Timestamp = /** @class */ (function (_super) {
4960
4960
  function Timestamp(low, high) {
4961
4961
  var _this = this;
4962
4962
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4963
- ///@ts-expect-error
4963
+ // @ts-expect-error
4964
4964
  if (!(_this instanceof Timestamp))
4965
4965
  return new Timestamp(low, high);
4966
4966
  if (Long.isLong(low)) {
@@ -5024,7 +5024,7 @@ var Timestamp = /** @class */ (function (_super) {
5024
5024
  return this.inspect();
5025
5025
  };
5026
5026
  Timestamp.prototype.inspect = function () {
5027
- return "new Timestamp({ t: " + this.getHighBits() + ", i: " + this.getLowBits() + " })";
5027
+ return "new Timestamp({ t: ".concat(this.getHighBits(), ", i: ").concat(this.getLowBits(), " })");
5028
5028
  };
5029
5029
  Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
5030
5030
  return Timestamp;
@@ -5037,7 +5037,8 @@ function isBSONType(value) {
5037
5037
  var BSON_INT32_MAX$1 = 0x7fffffff;
5038
5038
  var BSON_INT32_MIN$1 = -0x80000000;
5039
5039
  // INT64 boundaries
5040
- var BSON_INT64_MAX$1 = 0x7fffffffffffffff;
5040
+ // const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
5041
+ var BSON_INT64_MAX$1 = 0x8000000000000000;
5041
5042
  var BSON_INT64_MIN$1 = -0x8000000000000000;
5042
5043
  // all the types where we don't need to do any special processing and can just pass the EJSON
5043
5044
  //straight to type.fromExtendedJSON
@@ -5133,7 +5134,7 @@ function deserializeValue(value, options) {
5133
5134
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5134
5135
  function serializeArray(array, options) {
5135
5136
  return array.map(function (v, index) {
5136
- options.seenObjects.push({ propertyName: "index " + index, obj: null });
5137
+ options.seenObjects.push({ propertyName: "index ".concat(index), obj: null });
5137
5138
  try {
5138
5139
  return serializeValue(v, options);
5139
5140
  }
@@ -5155,20 +5156,20 @@ function serializeValue(value, options) {
5155
5156
  var props = options.seenObjects.map(function (entry) { return entry.propertyName; });
5156
5157
  var leadingPart = props
5157
5158
  .slice(0, index)
5158
- .map(function (prop) { return prop + " -> "; })
5159
+ .map(function (prop) { return "".concat(prop, " -> "); })
5159
5160
  .join('');
5160
5161
  var alreadySeen = props[index];
5161
5162
  var circularPart = ' -> ' +
5162
5163
  props
5163
5164
  .slice(index + 1, props.length - 1)
5164
- .map(function (prop) { return prop + " -> "; })
5165
+ .map(function (prop) { return "".concat(prop, " -> "); })
5165
5166
  .join('');
5166
5167
  var current = props[props.length - 1];
5167
5168
  var leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
5168
5169
  var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
5169
5170
  throw new BSONTypeError('Converting circular structure to EJSON:\n' +
5170
- (" " + leadingPart + alreadySeen + circularPart + current + "\n") +
5171
- (" " + leadingSpace + "\\" + dashes + "/"));
5171
+ " ".concat(leadingPart).concat(alreadySeen).concat(circularPart).concat(current, "\n") +
5172
+ " ".concat(leadingSpace, "\\").concat(dashes, "/"));
5172
5173
  }
5173
5174
  options.seenObjects[options.seenObjects.length - 1].obj = value;
5174
5175
  }
@@ -5247,7 +5248,18 @@ function serializeDocument(doc, options) {
5247
5248
  for (var name in doc) {
5248
5249
  options.seenObjects.push({ propertyName: name, obj: null });
5249
5250
  try {
5250
- _doc[name] = serializeValue(doc[name], options);
5251
+ var value = serializeValue(doc[name], options);
5252
+ if (name === '__proto__') {
5253
+ Object.defineProperty(_doc, name, {
5254
+ value: value,
5255
+ writable: true,
5256
+ enumerable: true,
5257
+ configurable: true
5258
+ });
5259
+ }
5260
+ else {
5261
+ _doc[name] = value;
5262
+ }
5251
5263
  }
5252
5264
  finally {
5253
5265
  options.seenObjects.pop();
@@ -5317,7 +5329,7 @@ var EJSON;
5317
5329
  finalOptions.relaxed = !finalOptions.strict;
5318
5330
  return JSON.parse(text, function (key, value) {
5319
5331
  if (key.indexOf('\x00') !== -1) {
5320
- throw new BSONError("BSON Document field names cannot contain null bytes, found: " + JSON.stringify(key));
5332
+ throw new BSONError("BSON Document field names cannot contain null bytes, found: ".concat(JSON.stringify(key)));
5321
5333
  }
5322
5334
  return deserializeValue(value, finalOptions);
5323
5335
  });
@@ -5683,13 +5695,14 @@ value, serializeFunctions, isArray, ignoreUndefined) {
5683
5695
  }
5684
5696
  }
5685
5697
  else if (value['_bsontype'] === 'Binary') {
5698
+ var binary = value;
5686
5699
  // Check what kind of subtype we have
5687
- if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5700
+ if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5688
5701
  return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
5689
- (value.position + 1 + 4 + 1 + 4));
5702
+ (binary.position + 1 + 4 + 1 + 4));
5690
5703
  }
5691
5704
  else {
5692
- return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1));
5705
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (binary.position + 1 + 4 + 1));
5693
5706
  }
5694
5707
  }
5695
5708
  else if (value['_bsontype'] === 'Symbol') {
@@ -5826,16 +5839,16 @@ function deserialize$1(buffer, options, isArray) {
5826
5839
  (buffer[index + 2] << 16) |
5827
5840
  (buffer[index + 3] << 24);
5828
5841
  if (size < 5) {
5829
- throw new BSONError("bson size must be >= 5, is " + size);
5842
+ throw new BSONError("bson size must be >= 5, is ".concat(size));
5830
5843
  }
5831
5844
  if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
5832
- throw new BSONError("buffer length " + buffer.length + " must be >= bson size " + size);
5845
+ throw new BSONError("buffer length ".concat(buffer.length, " must be >= bson size ").concat(size));
5833
5846
  }
5834
5847
  if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
5835
- throw new BSONError("buffer length " + buffer.length + " must === bson size " + size);
5848
+ throw new BSONError("buffer length ".concat(buffer.length, " must === bson size ").concat(size));
5836
5849
  }
5837
5850
  if (size + index > buffer.byteLength) {
5838
- throw new BSONError("(bson size " + size + " + options.index " + index + " must be <= buffer length " + buffer.byteLength + ")");
5851
+ throw new BSONError("(bson size ".concat(size, " + options.index ").concat(index, " must be <= buffer length ").concat(buffer.byteLength, ")"));
5839
5852
  }
5840
5853
  // Illegal end value
5841
5854
  if (buffer[index + size - 1] !== 0) {
@@ -5912,6 +5925,7 @@ function deserializeObject(buffer, index, options, isArray) {
5912
5925
  var done = false;
5913
5926
  var isPossibleDBRef = isArray ? false : null;
5914
5927
  // While we have more left data left keep parsing
5928
+ var dataview = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
5915
5929
  while (!done) {
5916
5930
  // Read the type
5917
5931
  var elementType = buffer[index++];
@@ -5972,11 +5986,11 @@ function deserializeObject(buffer, index, options, isArray) {
5972
5986
  (buffer[index++] << 24);
5973
5987
  }
5974
5988
  else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
5975
- value = new Double(buffer.readDoubleLE(index));
5989
+ value = new Double(dataview.getFloat64(index, true));
5976
5990
  index = index + 8;
5977
5991
  }
5978
5992
  else if (elementType === BSON_DATA_NUMBER) {
5979
- value = buffer.readDoubleLE(index);
5993
+ value = dataview.getFloat64(index, true);
5980
5994
  index = index + 8;
5981
5995
  }
5982
5996
  else if (elementType === BSON_DATA_DATE) {
@@ -6374,7 +6388,7 @@ function deserializeObject(buffer, index, options, isArray) {
6374
6388
  value = new DBRef(namespace, oid);
6375
6389
  }
6376
6390
  else {
6377
- throw new BSONError('Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"');
6391
+ throw new BSONError("Detected unknown BSON type ".concat(elementType.toString(16), " for fieldname \"").concat(name, "\""));
6378
6392
  }
6379
6393
  if (name === '__proto__') {
6380
6394
  Object.defineProperty(object, name, {
@@ -6412,10 +6426,12 @@ function deserializeObject(buffer, index, options, isArray) {
6412
6426
  * @internal
6413
6427
  */
6414
6428
  function isolateEval(functionString, functionCache, object) {
6429
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
6415
6430
  if (!functionCache)
6416
6431
  return new Function(functionString);
6417
6432
  // Check for cache hit, eval if missing and return cached function
6418
6433
  if (functionCache[functionString] == null) {
6434
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
6419
6435
  functionCache[functionString] = new Function(functionString);
6420
6436
  }
6421
6437
  // Set the object
@@ -6437,74 +6453,6 @@ function getValidatedString(buffer, start, end, shouldValidateUtf8) {
6437
6453
  return value;
6438
6454
  }
6439
6455
 
6440
- // Copyright (c) 2008, Fair Oaks Labs, Inc.
6441
- function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
6442
- var e;
6443
- var m;
6444
- var c;
6445
- var bBE = endian === 'big';
6446
- var eLen = nBytes * 8 - mLen - 1;
6447
- var eMax = (1 << eLen) - 1;
6448
- var eBias = eMax >> 1;
6449
- var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
6450
- var i = bBE ? nBytes - 1 : 0;
6451
- var d = bBE ? -1 : 1;
6452
- var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
6453
- value = Math.abs(value);
6454
- if (isNaN(value) || value === Infinity) {
6455
- m = isNaN(value) ? 1 : 0;
6456
- e = eMax;
6457
- }
6458
- else {
6459
- e = Math.floor(Math.log(value) / Math.LN2);
6460
- if (value * (c = Math.pow(2, -e)) < 1) {
6461
- e--;
6462
- c *= 2;
6463
- }
6464
- if (e + eBias >= 1) {
6465
- value += rt / c;
6466
- }
6467
- else {
6468
- value += rt * Math.pow(2, 1 - eBias);
6469
- }
6470
- if (value * c >= 2) {
6471
- e++;
6472
- c /= 2;
6473
- }
6474
- if (e + eBias >= eMax) {
6475
- m = 0;
6476
- e = eMax;
6477
- }
6478
- else if (e + eBias >= 1) {
6479
- m = (value * c - 1) * Math.pow(2, mLen);
6480
- e = e + eBias;
6481
- }
6482
- else {
6483
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
6484
- e = 0;
6485
- }
6486
- }
6487
- if (isNaN(value))
6488
- m = 0;
6489
- while (mLen >= 8) {
6490
- buffer[offset + i] = m & 0xff;
6491
- i += d;
6492
- m /= 256;
6493
- mLen -= 8;
6494
- }
6495
- e = (e << mLen) | m;
6496
- if (isNaN(value))
6497
- e += 8;
6498
- eLen += mLen;
6499
- while (eLen > 0) {
6500
- buffer[offset + i] = e & 0xff;
6501
- i += d;
6502
- e /= 256;
6503
- eLen -= 8;
6504
- }
6505
- buffer[offset + i - d] |= s * 128;
6506
- }
6507
-
6508
6456
  var regexp = /\x00/; // eslint-disable-line no-control-regex
6509
6457
  var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
6510
6458
  /*
@@ -6535,6 +6483,8 @@ function serializeString(buffer, key, value, index, isArray) {
6535
6483
  buffer[index++] = 0;
6536
6484
  return index;
6537
6485
  }
6486
+ var SPACE_FOR_FLOAT64 = new Uint8Array(8);
6487
+ var DV_FOR_FLOAT64 = new DataView(SPACE_FOR_FLOAT64.buffer, SPACE_FOR_FLOAT64.byteOffset, SPACE_FOR_FLOAT64.byteLength);
6538
6488
  function serializeNumber(buffer, key, value, index, isArray) {
6539
6489
  // We have an integer value
6540
6490
  // TODO(NODE-2529): Add support for big int
@@ -6568,7 +6518,8 @@ function serializeNumber(buffer, key, value, index, isArray) {
6568
6518
  index = index + numberOfWrittenBytes;
6569
6519
  buffer[index++] = 0;
6570
6520
  // Write float
6571
- writeIEEE754(buffer, value, index, 'little', 52, 8);
6521
+ DV_FOR_FLOAT64.setFloat64(0, value, true);
6522
+ buffer.set(SPACE_FOR_FLOAT64, index);
6572
6523
  // Adjust index
6573
6524
  index = index + 8;
6574
6525
  }
@@ -6847,7 +6798,8 @@ function serializeDouble(buffer, key, value, index, isArray) {
6847
6798
  index = index + numberOfWrittenBytes;
6848
6799
  buffer[index++] = 0;
6849
6800
  // Write float
6850
- writeIEEE754(buffer, value.value, index, 'little', 52, 8);
6801
+ DV_FOR_FLOAT64.setFloat64(0, value.value, true);
6802
+ buffer.set(SPACE_FOR_FLOAT64, index);
6851
6803
  // Adjust index
6852
6804
  index = index + 8;
6853
6805
  return index;
@@ -7057,7 +7009,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7057
7009
  if (Array.isArray(object)) {
7058
7010
  // Get object keys
7059
7011
  for (var i = 0; i < object.length; i++) {
7060
- var key = '' + i;
7012
+ var key = "".concat(i);
7061
7013
  var value = object[i];
7062
7014
  // Is there an override value
7063
7015
  if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
@@ -7132,7 +7084,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7132
7084
  index = serializeMinMax(buffer, key, value, index, true);
7133
7085
  }
7134
7086
  else if (typeof value['_bsontype'] !== 'undefined') {
7135
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7087
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7136
7088
  }
7137
7089
  }
7138
7090
  }
@@ -7231,7 +7183,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7231
7183
  index = serializeMinMax(buffer, key, value, index);
7232
7184
  }
7233
7185
  else if (typeof value['_bsontype'] !== 'undefined') {
7234
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7186
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7235
7187
  }
7236
7188
  }
7237
7189
  }
@@ -7336,7 +7288,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7336
7288
  index = serializeMinMax(buffer, key, value, index);
7337
7289
  }
7338
7290
  else if (typeof value['_bsontype'] !== 'undefined') {
7339
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7291
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7340
7292
  }
7341
7293
  }
7342
7294
  }