bson 4.6.2 → 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 (82) hide show
  1. package/bower.json +1 -1
  2. package/bson.d.ts +1235 -1118
  3. package/dist/bson.browser.esm.js +113 -145
  4. package/dist/bson.browser.esm.js.map +1 -1
  5. package/dist/bson.browser.umd.js +113 -145
  6. package/dist/bson.browser.umd.js.map +1 -1
  7. package/dist/bson.bundle.js +113 -145
  8. package/dist/bson.bundle.js.map +1 -1
  9. package/dist/bson.esm.js +110 -145
  10. package/dist/bson.esm.js.map +1 -1
  11. package/lib/binary.js +14 -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 +2 -1
  16. package/lib/code.js.map +1 -1
  17. package/lib/db_ref.js +3 -2
  18. package/lib/db_ref.js.map +1 -1
  19. package/lib/decimal128.js +14 -13
  20. package/lib/decimal128.js.map +1 -1
  21. package/lib/double.js +3 -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 +2 -1
  28. package/lib/int_32.js.map +1 -1
  29. package/lib/long.js +4 -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/max_key.js +1 -0
  34. package/lib/max_key.js.map +1 -1
  35. package/lib/min_key.js +1 -0
  36. package/lib/min_key.js.map +1 -1
  37. package/lib/objectid.js +10 -8
  38. package/lib/objectid.js.map +1 -1
  39. package/lib/parser/calculate_size.js +10 -9
  40. package/lib/parser/calculate_size.js.map +1 -1
  41. package/lib/parser/deserializer.js +13 -10
  42. package/lib/parser/deserializer.js.map +1 -1
  43. package/lib/parser/serializer.js +25 -22
  44. package/lib/parser/serializer.js.map +1 -1
  45. package/lib/parser/utils.js +23 -19
  46. package/lib/parser/utils.js.map +1 -1
  47. package/lib/regexp.js +5 -4
  48. package/lib/regexp.js.map +1 -1
  49. package/lib/symbol.js +2 -1
  50. package/lib/symbol.js.map +1 -1
  51. package/lib/timestamp.js +7 -4
  52. package/lib/timestamp.js.map +1 -1
  53. package/lib/utils/global.js +1 -1
  54. package/lib/utils/global.js.map +1 -1
  55. package/lib/uuid.js +9 -9
  56. package/lib/uuid.js.map +1 -1
  57. package/lib/uuid_utils.js +1 -1
  58. package/lib/uuid_utils.js.map +1 -1
  59. package/package.json +16 -16
  60. package/src/binary.ts +8 -0
  61. package/src/code.ts +2 -1
  62. package/src/db_ref.ts +2 -1
  63. package/src/decimal128.ts +4 -3
  64. package/src/double.ts +1 -0
  65. package/src/extended_json.ts +13 -2
  66. package/src/int_32.ts +1 -0
  67. package/src/long.ts +33 -7
  68. package/src/max_key.ts +1 -0
  69. package/src/min_key.ts +1 -0
  70. package/src/objectid.ts +4 -2
  71. package/src/parser/calculate_size.ts +4 -3
  72. package/src/parser/deserializer.ts +6 -3
  73. package/src/parser/serializer.ts +14 -7
  74. package/src/parser/utils.ts +24 -20
  75. package/src/regexp.ts +1 -0
  76. package/src/symbol.ts +1 -0
  77. package/src/timestamp.ts +5 -2
  78. package/src/utils/global.ts +1 -1
  79. package/src/uuid.ts +1 -1
  80. package/lib/float_parser.js +0 -137
  81. package/lib/float_parser.js.map +0 -1
  82. package/src/float_parser.ts +0 -152
@@ -2131,11 +2131,11 @@ var BSON = (function (exports) {
2131
2131
  }
2132
2132
  // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
2133
2133
  function getGlobal() {
2134
- // eslint-disable-next-line no-undef
2135
2134
  return (checkForMath(typeof globalThis === 'object' && globalThis) ||
2136
2135
  checkForMath(typeof window === 'object' && window) ||
2137
2136
  checkForMath(typeof self === 'object' && self) ||
2138
2137
  checkForMath(typeof global === 'object' && global) ||
2138
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
2139
2139
  Function('return this')());
2140
2140
  }
2141
2141
 
@@ -2161,27 +2161,20 @@ var BSON = (function (exports) {
2161
2161
  return result;
2162
2162
  };
2163
2163
  var detectRandomBytes = function () {
2164
- if (typeof window !== 'undefined') {
2165
- // browser crypto implementation(s)
2166
- var target_1 = window.crypto || window.msCrypto; // allow for IE11
2167
- if (target_1 && target_1.getRandomValues) {
2168
- return function (size) { return target_1.getRandomValues(buffer_1.alloc(size)); };
2164
+ {
2165
+ if (typeof window !== 'undefined') {
2166
+ // browser crypto implementation(s)
2167
+ var target_1 = window.crypto || window.msCrypto; // allow for IE11
2168
+ if (target_1 && target_1.getRandomValues) {
2169
+ return function (size) { return target_1.getRandomValues(buffer_1.alloc(size)); };
2170
+ }
2169
2171
  }
2172
+ if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
2173
+ // allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
2174
+ return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
2175
+ }
2176
+ return insecureRandomBytes;
2170
2177
  }
2171
- if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
2172
- // allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
2173
- return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
2174
- }
2175
- var requiredRandomBytes;
2176
- try {
2177
- // eslint-disable-next-line @typescript-eslint/no-var-requires
2178
- requiredRandomBytes = require('crypto').randomBytes;
2179
- }
2180
- catch (e) {
2181
- // keep the fallback
2182
- }
2183
- // NOTE: in transpiled cases the above require might return null/undefined
2184
- return requiredRandomBytes || insecureRandomBytes;
2185
2178
  };
2186
2179
  var randomBytes = detectRandomBytes();
2187
2180
  function isAnyArrayBuffer(value) {
@@ -2438,7 +2431,7 @@ var BSON = (function (exports) {
2438
2431
  return this.inspect();
2439
2432
  };
2440
2433
  UUID.prototype.inspect = function () {
2441
- return "new UUID(\"" + this.toHexString() + "\")";
2434
+ return "new UUID(\"".concat(this.toHexString(), "\")");
2442
2435
  };
2443
2436
  return UUID;
2444
2437
  }());
@@ -2447,9 +2440,17 @@ var BSON = (function (exports) {
2447
2440
  /**
2448
2441
  * A class representation of the BSON Binary type.
2449
2442
  * @public
2443
+ * @category BSONType
2450
2444
  */
2451
2445
  var Binary = /** @class */ (function () {
2452
2446
  /**
2447
+ * Create a new Binary instance.
2448
+ *
2449
+ * This constructor can accept a string as its first argument. In this case,
2450
+ * this string will be encoded using ISO-8859-1, **not** using UTF-8.
2451
+ * This is almost certainly not what you want. Use `new Binary(Buffer.from(string))`
2452
+ * instead to convert the string to a Buffer using UTF-8 first.
2453
+ *
2453
2454
  * @param buffer - a buffer object containing the binary data.
2454
2455
  * @param subType - the option binary type.
2455
2456
  */
@@ -2609,7 +2610,7 @@ var BSON = (function (exports) {
2609
2610
  if (this.sub_type === Binary.SUBTYPE_UUID) {
2610
2611
  return new UUID(this.buffer.slice(0, this.position));
2611
2612
  }
2612
- throw new BSONError("Binary sub_type \"" + this.sub_type + "\" is not supported for converting to UUID. Only \"" + Binary.SUBTYPE_UUID + "\" is currently supported.");
2613
+ throw new BSONError("Binary sub_type \"".concat(this.sub_type, "\" is not supported for converting to UUID. Only \"").concat(Binary.SUBTYPE_UUID, "\" is currently supported."));
2613
2614
  };
2614
2615
  /** @internal */
2615
2616
  Binary.fromExtendedJSON = function (doc, options) {
@@ -2633,7 +2634,7 @@ var BSON = (function (exports) {
2633
2634
  data = uuidHexStringToBuffer(doc.$uuid);
2634
2635
  }
2635
2636
  if (!data) {
2636
- throw new BSONTypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc));
2637
+ throw new BSONTypeError("Unexpected Binary Extended JSON format ".concat(JSON.stringify(doc)));
2637
2638
  }
2638
2639
  return new Binary(data, type);
2639
2640
  };
@@ -2643,7 +2644,7 @@ var BSON = (function (exports) {
2643
2644
  };
2644
2645
  Binary.prototype.inspect = function () {
2645
2646
  var asBuffer = this.value(true);
2646
- return "new Binary(Buffer.from(\"" + asBuffer.toString('hex') + "\", \"hex\"), " + this.sub_type + ")";
2647
+ return "new Binary(Buffer.from(\"".concat(asBuffer.toString('hex'), "\", \"hex\"), ").concat(this.sub_type, ")");
2647
2648
  };
2648
2649
  /**
2649
2650
  * Binary default subtype
@@ -2677,6 +2678,7 @@ var BSON = (function (exports) {
2677
2678
  /**
2678
2679
  * A class representation of the BSON Code type.
2679
2680
  * @public
2681
+ * @category BSONType
2680
2682
  */
2681
2683
  var Code = /** @class */ (function () {
2682
2684
  /**
@@ -2709,7 +2711,7 @@ var BSON = (function (exports) {
2709
2711
  };
2710
2712
  Code.prototype.inspect = function () {
2711
2713
  var codeJson = this.toJSON();
2712
- return "new Code(\"" + codeJson.code + "\"" + (codeJson.scope ? ", " + JSON.stringify(codeJson.scope) : '') + ")";
2714
+ return "new Code(\"".concat(String(codeJson.code), "\"").concat(codeJson.scope ? ", ".concat(JSON.stringify(codeJson.scope)) : '', ")");
2713
2715
  };
2714
2716
  return Code;
2715
2717
  }());
@@ -2725,6 +2727,7 @@ var BSON = (function (exports) {
2725
2727
  /**
2726
2728
  * A class representation of the BSON DBRef type.
2727
2729
  * @public
2730
+ * @category BSONType
2728
2731
  */
2729
2732
  var DBRef = /** @class */ (function () {
2730
2733
  /**
@@ -2799,7 +2802,7 @@ var BSON = (function (exports) {
2799
2802
  DBRef.prototype.inspect = function () {
2800
2803
  // NOTE: if OID is an ObjectId class it will just print the oid string.
2801
2804
  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 + "\"" : '') + ")";
2805
+ return "new DBRef(\"".concat(this.namespace, "\", new ObjectId(\"").concat(String(oid), "\")").concat(this.db ? ", \"".concat(this.db, "\"") : '', ")");
2803
2806
  };
2804
2807
  return DBRef;
2805
2808
  }());
@@ -2829,6 +2832,7 @@ var BSON = (function (exports) {
2829
2832
  /**
2830
2833
  * A class representing a 64-bit integer
2831
2834
  * @public
2835
+ * @category BSONType
2832
2836
  * @remarks
2833
2837
  * The internal representation of a long is the two given signed, 32-bit values.
2834
2838
  * We use 32-bit pieces because these are the size of integers on which
@@ -3035,7 +3039,6 @@ var BSON = (function (exports) {
3035
3039
  /**
3036
3040
  * Tests if the specified object is a Long.
3037
3041
  */
3038
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
3039
3042
  Long.isLong = function (value) {
3040
3043
  return isObjectLike(value) && value['__isLong__'] === true;
3041
3044
  };
@@ -3192,6 +3195,7 @@ var BSON = (function (exports) {
3192
3195
  // into the result, and subtract it from the remainder. It is critical that
3193
3196
  // the approximate value is less than or equal to the real value so that the
3194
3197
  // remainder never becomes negative.
3198
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3195
3199
  rem = this;
3196
3200
  while (rem.gte(divisor)) {
3197
3201
  // Approximate the result of division. This may be a little greater or
@@ -3675,7 +3679,7 @@ var BSON = (function (exports) {
3675
3679
  return this.inspect();
3676
3680
  };
3677
3681
  Long.prototype.inspect = function () {
3678
- return "new Long(\"" + this.toString() + "\"" + (this.unsigned ? ', true' : '') + ")";
3682
+ return "new Long(\"".concat(this.toString(), "\"").concat(this.unsigned ? ', true' : '', ")");
3679
3683
  };
3680
3684
  Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
3681
3685
  /** Maximum unsigned value. */
@@ -3786,11 +3790,12 @@ var BSON = (function (exports) {
3786
3790
  return false;
3787
3791
  }
3788
3792
  function invalidErr(string, message) {
3789
- throw new BSONTypeError("\"" + string + "\" is not a valid Decimal128 string - " + message);
3793
+ throw new BSONTypeError("\"".concat(string, "\" is not a valid Decimal128 string - ").concat(message));
3790
3794
  }
3791
3795
  /**
3792
3796
  * A class representation of the BSON Decimal128 type.
3793
3797
  * @public
3798
+ * @category BSONType
3794
3799
  */
3795
3800
  var Decimal128 = /** @class */ (function () {
3796
3801
  /**
@@ -4283,35 +4288,35 @@ var BSON = (function (exports) {
4283
4288
  // as + or - 0 and using the non-scientific exponent (this is for the "invalid
4284
4289
  // representation should be treated as 0/-0" spec cases in decimal128-1.json)
4285
4290
  if (significand_digits > 34) {
4286
- string.push("" + 0);
4291
+ string.push("".concat(0));
4287
4292
  if (exponent > 0)
4288
- string.push('E+' + exponent);
4293
+ string.push("E+".concat(exponent));
4289
4294
  else if (exponent < 0)
4290
- string.push('E' + exponent);
4295
+ string.push("E".concat(exponent));
4291
4296
  return string.join('');
4292
4297
  }
4293
- string.push("" + significand[index++]);
4298
+ string.push("".concat(significand[index++]));
4294
4299
  significand_digits = significand_digits - 1;
4295
4300
  if (significand_digits) {
4296
4301
  string.push('.');
4297
4302
  }
4298
4303
  for (var i = 0; i < significand_digits; i++) {
4299
- string.push("" + significand[index++]);
4304
+ string.push("".concat(significand[index++]));
4300
4305
  }
4301
4306
  // Exponent
4302
4307
  string.push('E');
4303
4308
  if (scientific_exponent > 0) {
4304
- string.push('+' + scientific_exponent);
4309
+ string.push("+".concat(scientific_exponent));
4305
4310
  }
4306
4311
  else {
4307
- string.push("" + scientific_exponent);
4312
+ string.push("".concat(scientific_exponent));
4308
4313
  }
4309
4314
  }
4310
4315
  else {
4311
4316
  // Regular format with no decimal place
4312
4317
  if (exponent >= 0) {
4313
4318
  for (var i = 0; i < significand_digits; i++) {
4314
- string.push("" + significand[index++]);
4319
+ string.push("".concat(significand[index++]));
4315
4320
  }
4316
4321
  }
4317
4322
  else {
@@ -4319,7 +4324,7 @@ var BSON = (function (exports) {
4319
4324
  // non-zero digits before radix
4320
4325
  if (radix_position > 0) {
4321
4326
  for (var i = 0; i < radix_position; i++) {
4322
- string.push("" + significand[index++]);
4327
+ string.push("".concat(significand[index++]));
4323
4328
  }
4324
4329
  }
4325
4330
  else {
@@ -4331,7 +4336,7 @@ var BSON = (function (exports) {
4331
4336
  string.push('0');
4332
4337
  }
4333
4338
  for (var i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
4334
- string.push("" + significand[index++]);
4339
+ string.push("".concat(significand[index++]));
4335
4340
  }
4336
4341
  }
4337
4342
  }
@@ -4353,7 +4358,7 @@ var BSON = (function (exports) {
4353
4358
  return this.inspect();
4354
4359
  };
4355
4360
  Decimal128.prototype.inspect = function () {
4356
- return "new Decimal128(\"" + this.toString() + "\")";
4361
+ return "new Decimal128(\"".concat(this.toString(), "\")");
4357
4362
  };
4358
4363
  return Decimal128;
4359
4364
  }());
@@ -4362,6 +4367,7 @@ var BSON = (function (exports) {
4362
4367
  /**
4363
4368
  * A class representation of the BSON Double type.
4364
4369
  * @public
4370
+ * @category BSONType
4365
4371
  */
4366
4372
  var Double = /** @class */ (function () {
4367
4373
  /**
@@ -4399,7 +4405,7 @@ var BSON = (function (exports) {
4399
4405
  // NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
4400
4406
  // explicitly provided `-0` then we need to ensure the sign makes it into the output
4401
4407
  if (Object.is(Math.sign(this.value), -0)) {
4402
- return { $numberDouble: "-" + this.value.toFixed(1) };
4408
+ return { $numberDouble: "-".concat(this.value.toFixed(1)) };
4403
4409
  }
4404
4410
  var $numberDouble;
4405
4411
  if (Number.isInteger(this.value)) {
@@ -4424,7 +4430,7 @@ var BSON = (function (exports) {
4424
4430
  };
4425
4431
  Double.prototype.inspect = function () {
4426
4432
  var eJSON = this.toExtendedJSON();
4427
- return "new Double(" + eJSON.$numberDouble + ")";
4433
+ return "new Double(".concat(eJSON.$numberDouble, ")");
4428
4434
  };
4429
4435
  return Double;
4430
4436
  }());
@@ -4433,6 +4439,7 @@ var BSON = (function (exports) {
4433
4439
  /**
4434
4440
  * A class representation of a BSON Int32 type.
4435
4441
  * @public
4442
+ * @category BSONType
4436
4443
  */
4437
4444
  var Int32 = /** @class */ (function () {
4438
4445
  /**
@@ -4477,7 +4484,7 @@ var BSON = (function (exports) {
4477
4484
  return this.inspect();
4478
4485
  };
4479
4486
  Int32.prototype.inspect = function () {
4480
- return "new Int32(" + this.valueOf() + ")";
4487
+ return "new Int32(".concat(this.valueOf(), ")");
4481
4488
  };
4482
4489
  return Int32;
4483
4490
  }());
@@ -4486,6 +4493,7 @@ var BSON = (function (exports) {
4486
4493
  /**
4487
4494
  * A class representation of the BSON MaxKey type.
4488
4495
  * @public
4496
+ * @category BSONType
4489
4497
  */
4490
4498
  var MaxKey = /** @class */ (function () {
4491
4499
  function MaxKey() {
@@ -4514,6 +4522,7 @@ var BSON = (function (exports) {
4514
4522
  /**
4515
4523
  * A class representation of the BSON MinKey type.
4516
4524
  * @public
4525
+ * @category BSONType
4517
4526
  */
4518
4527
  var MinKey = /** @class */ (function () {
4519
4528
  function MinKey() {
@@ -4547,6 +4556,7 @@ var BSON = (function (exports) {
4547
4556
  /**
4548
4557
  * A class representation of the BSON ObjectId type.
4549
4558
  * @public
4559
+ * @category BSONType
4550
4560
  */
4551
4561
  var ObjectId = /** @class */ (function () {
4552
4562
  /**
@@ -4580,7 +4590,8 @@ var BSON = (function (exports) {
4580
4590
  this[kId] = ObjectId.generate(typeof workingId === 'number' ? workingId : undefined);
4581
4591
  }
4582
4592
  else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
4583
- this[kId] = ensureBuffer(workingId);
4593
+ // If intstanceof matches we can escape calling ensure buffer in Node.js environments
4594
+ this[kId] = workingId instanceof buffer_1 ? workingId : ensureBuffer(workingId);
4584
4595
  }
4585
4596
  else if (typeof workingId === 'string') {
4586
4597
  if (workingId.length === 12) {
@@ -4807,7 +4818,7 @@ var BSON = (function (exports) {
4807
4818
  return this.inspect();
4808
4819
  };
4809
4820
  ObjectId.prototype.inspect = function () {
4810
- return "new ObjectId(\"" + this.toHexString() + "\")";
4821
+ return "new ObjectId(\"".concat(this.toHexString(), "\")");
4811
4822
  };
4812
4823
  /** @internal */
4813
4824
  ObjectId.index = Math.floor(Math.random() * 0xffffff);
@@ -4834,6 +4845,7 @@ var BSON = (function (exports) {
4834
4845
  /**
4835
4846
  * A class representation of the BSON RegExp type.
4836
4847
  * @public
4848
+ * @category BSONType
4837
4849
  */
4838
4850
  var BSONRegExp = /** @class */ (function () {
4839
4851
  /**
@@ -4846,10 +4858,10 @@ var BSON = (function (exports) {
4846
4858
  this.pattern = pattern;
4847
4859
  this.options = alphabetize(options !== null && options !== void 0 ? options : '');
4848
4860
  if (this.pattern.indexOf('\x00') !== -1) {
4849
- throw new BSONError("BSON Regex patterns cannot contain null bytes, found: " + JSON.stringify(this.pattern));
4861
+ throw new BSONError("BSON Regex patterns cannot contain null bytes, found: ".concat(JSON.stringify(this.pattern)));
4850
4862
  }
4851
4863
  if (this.options.indexOf('\x00') !== -1) {
4852
- throw new BSONError("BSON Regex options cannot contain null bytes, found: " + JSON.stringify(this.options));
4864
+ throw new BSONError("BSON Regex options cannot contain null bytes, found: ".concat(JSON.stringify(this.options)));
4853
4865
  }
4854
4866
  // Validate options
4855
4867
  for (var i = 0; i < this.options.length; i++) {
@@ -4859,7 +4871,7 @@ var BSON = (function (exports) {
4859
4871
  this.options[i] === 'l' ||
4860
4872
  this.options[i] === 's' ||
4861
4873
  this.options[i] === 'u')) {
4862
- throw new BSONError("The regular expression option [" + this.options[i] + "] is not supported");
4874
+ throw new BSONError("The regular expression option [".concat(this.options[i], "] is not supported"));
4863
4875
  }
4864
4876
  }
4865
4877
  }
@@ -4890,7 +4902,7 @@ var BSON = (function (exports) {
4890
4902
  if ('$regularExpression' in doc) {
4891
4903
  return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
4892
4904
  }
4893
- throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: " + JSON.stringify(doc));
4905
+ throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(doc)));
4894
4906
  };
4895
4907
  return BSONRegExp;
4896
4908
  }());
@@ -4899,6 +4911,7 @@ var BSON = (function (exports) {
4899
4911
  /**
4900
4912
  * A class representation of the BSON Symbol type.
4901
4913
  * @public
4914
+ * @category BSONType
4902
4915
  */
4903
4916
  var BSONSymbol = /** @class */ (function () {
4904
4917
  /**
@@ -4918,7 +4931,7 @@ var BSON = (function (exports) {
4918
4931
  };
4919
4932
  /** @internal */
4920
4933
  BSONSymbol.prototype.inspect = function () {
4921
- return "new BSONSymbol(\"" + this.value + "\")";
4934
+ return "new BSONSymbol(\"".concat(this.value, "\")");
4922
4935
  };
4923
4936
  BSONSymbol.prototype.toJSON = function () {
4924
4937
  return this.value;
@@ -4941,13 +4954,16 @@ var BSON = (function (exports) {
4941
4954
 
4942
4955
  /** @public */
4943
4956
  var LongWithoutOverridesClass = Long;
4944
- /** @public */
4957
+ /**
4958
+ * @public
4959
+ * @category BSONType
4960
+ * */
4945
4961
  var Timestamp = /** @class */ (function (_super) {
4946
4962
  __extends(Timestamp, _super);
4947
4963
  function Timestamp(low, high) {
4948
4964
  var _this = this;
4949
4965
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4950
- ///@ts-expect-error
4966
+ // @ts-expect-error
4951
4967
  if (!(_this instanceof Timestamp))
4952
4968
  return new Timestamp(low, high);
4953
4969
  if (Long.isLong(low)) {
@@ -5011,7 +5027,7 @@ var BSON = (function (exports) {
5011
5027
  return this.inspect();
5012
5028
  };
5013
5029
  Timestamp.prototype.inspect = function () {
5014
- return "new Timestamp({ t: " + this.getHighBits() + ", i: " + this.getLowBits() + " })";
5030
+ return "new Timestamp({ t: ".concat(this.getHighBits(), ", i: ").concat(this.getLowBits(), " })");
5015
5031
  };
5016
5032
  Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
5017
5033
  return Timestamp;
@@ -5024,7 +5040,8 @@ var BSON = (function (exports) {
5024
5040
  var BSON_INT32_MAX$1 = 0x7fffffff;
5025
5041
  var BSON_INT32_MIN$1 = -0x80000000;
5026
5042
  // INT64 boundaries
5027
- var BSON_INT64_MAX$1 = 0x7fffffffffffffff;
5043
+ // const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
5044
+ var BSON_INT64_MAX$1 = 0x8000000000000000;
5028
5045
  var BSON_INT64_MIN$1 = -0x8000000000000000;
5029
5046
  // all the types where we don't need to do any special processing and can just pass the EJSON
5030
5047
  //straight to type.fromExtendedJSON
@@ -5120,7 +5137,7 @@ var BSON = (function (exports) {
5120
5137
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5121
5138
  function serializeArray(array, options) {
5122
5139
  return array.map(function (v, index) {
5123
- options.seenObjects.push({ propertyName: "index " + index, obj: null });
5140
+ options.seenObjects.push({ propertyName: "index ".concat(index), obj: null });
5124
5141
  try {
5125
5142
  return serializeValue(v, options);
5126
5143
  }
@@ -5142,20 +5159,20 @@ var BSON = (function (exports) {
5142
5159
  var props = options.seenObjects.map(function (entry) { return entry.propertyName; });
5143
5160
  var leadingPart = props
5144
5161
  .slice(0, index)
5145
- .map(function (prop) { return prop + " -> "; })
5162
+ .map(function (prop) { return "".concat(prop, " -> "); })
5146
5163
  .join('');
5147
5164
  var alreadySeen = props[index];
5148
5165
  var circularPart = ' -> ' +
5149
5166
  props
5150
5167
  .slice(index + 1, props.length - 1)
5151
- .map(function (prop) { return prop + " -> "; })
5168
+ .map(function (prop) { return "".concat(prop, " -> "); })
5152
5169
  .join('');
5153
5170
  var current = props[props.length - 1];
5154
5171
  var leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
5155
5172
  var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
5156
5173
  throw new BSONTypeError('Converting circular structure to EJSON:\n' +
5157
- (" " + leadingPart + alreadySeen + circularPart + current + "\n") +
5158
- (" " + leadingSpace + "\\" + dashes + "/"));
5174
+ " ".concat(leadingPart).concat(alreadySeen).concat(circularPart).concat(current, "\n") +
5175
+ " ".concat(leadingSpace, "\\").concat(dashes, "/"));
5159
5176
  }
5160
5177
  options.seenObjects[options.seenObjects.length - 1].obj = value;
5161
5178
  }
@@ -5234,7 +5251,18 @@ var BSON = (function (exports) {
5234
5251
  for (var name in doc) {
5235
5252
  options.seenObjects.push({ propertyName: name, obj: null });
5236
5253
  try {
5237
- _doc[name] = serializeValue(doc[name], options);
5254
+ var value = serializeValue(doc[name], options);
5255
+ if (name === '__proto__') {
5256
+ Object.defineProperty(_doc, name, {
5257
+ value: value,
5258
+ writable: true,
5259
+ enumerable: true,
5260
+ configurable: true
5261
+ });
5262
+ }
5263
+ else {
5264
+ _doc[name] = value;
5265
+ }
5238
5266
  }
5239
5267
  finally {
5240
5268
  options.seenObjects.pop();
@@ -5304,7 +5332,7 @@ var BSON = (function (exports) {
5304
5332
  finalOptions.relaxed = !finalOptions.strict;
5305
5333
  return JSON.parse(text, function (key, value) {
5306
5334
  if (key.indexOf('\x00') !== -1) {
5307
- throw new BSONError("BSON Document field names cannot contain null bytes, found: " + JSON.stringify(key));
5335
+ throw new BSONError("BSON Document field names cannot contain null bytes, found: ".concat(JSON.stringify(key)));
5308
5336
  }
5309
5337
  return deserializeValue(value, finalOptions);
5310
5338
  });
@@ -5670,13 +5698,14 @@ var BSON = (function (exports) {
5670
5698
  }
5671
5699
  }
5672
5700
  else if (value['_bsontype'] === 'Binary') {
5701
+ var binary = value;
5673
5702
  // Check what kind of subtype we have
5674
- if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5703
+ if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5675
5704
  return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
5676
- (value.position + 1 + 4 + 1 + 4));
5705
+ (binary.position + 1 + 4 + 1 + 4));
5677
5706
  }
5678
5707
  else {
5679
- return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1));
5708
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (binary.position + 1 + 4 + 1));
5680
5709
  }
5681
5710
  }
5682
5711
  else if (value['_bsontype'] === 'Symbol') {
@@ -5813,16 +5842,16 @@ var BSON = (function (exports) {
5813
5842
  (buffer[index + 2] << 16) |
5814
5843
  (buffer[index + 3] << 24);
5815
5844
  if (size < 5) {
5816
- throw new BSONError("bson size must be >= 5, is " + size);
5845
+ throw new BSONError("bson size must be >= 5, is ".concat(size));
5817
5846
  }
5818
5847
  if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
5819
- throw new BSONError("buffer length " + buffer.length + " must be >= bson size " + size);
5848
+ throw new BSONError("buffer length ".concat(buffer.length, " must be >= bson size ").concat(size));
5820
5849
  }
5821
5850
  if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
5822
- throw new BSONError("buffer length " + buffer.length + " must === bson size " + size);
5851
+ throw new BSONError("buffer length ".concat(buffer.length, " must === bson size ").concat(size));
5823
5852
  }
5824
5853
  if (size + index > buffer.byteLength) {
5825
- throw new BSONError("(bson size " + size + " + options.index " + index + " must be <= buffer length " + buffer.byteLength + ")");
5854
+ throw new BSONError("(bson size ".concat(size, " + options.index ").concat(index, " must be <= buffer length ").concat(buffer.byteLength, ")"));
5826
5855
  }
5827
5856
  // Illegal end value
5828
5857
  if (buffer[index + size - 1] !== 0) {
@@ -5899,6 +5928,7 @@ var BSON = (function (exports) {
5899
5928
  var done = false;
5900
5929
  var isPossibleDBRef = isArray ? false : null;
5901
5930
  // While we have more left data left keep parsing
5931
+ var dataview = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
5902
5932
  while (!done) {
5903
5933
  // Read the type
5904
5934
  var elementType = buffer[index++];
@@ -5959,11 +5989,11 @@ var BSON = (function (exports) {
5959
5989
  (buffer[index++] << 24);
5960
5990
  }
5961
5991
  else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
5962
- value = new Double(buffer.readDoubleLE(index));
5992
+ value = new Double(dataview.getFloat64(index, true));
5963
5993
  index = index + 8;
5964
5994
  }
5965
5995
  else if (elementType === BSON_DATA_NUMBER) {
5966
- value = buffer.readDoubleLE(index);
5996
+ value = dataview.getFloat64(index, true);
5967
5997
  index = index + 8;
5968
5998
  }
5969
5999
  else if (elementType === BSON_DATA_DATE) {
@@ -6361,7 +6391,7 @@ var BSON = (function (exports) {
6361
6391
  value = new DBRef(namespace, oid);
6362
6392
  }
6363
6393
  else {
6364
- throw new BSONError('Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"');
6394
+ throw new BSONError("Detected unknown BSON type ".concat(elementType.toString(16), " for fieldname \"").concat(name, "\""));
6365
6395
  }
6366
6396
  if (name === '__proto__') {
6367
6397
  Object.defineProperty(object, name, {
@@ -6399,10 +6429,12 @@ var BSON = (function (exports) {
6399
6429
  * @internal
6400
6430
  */
6401
6431
  function isolateEval(functionString, functionCache, object) {
6432
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
6402
6433
  if (!functionCache)
6403
6434
  return new Function(functionString);
6404
6435
  // Check for cache hit, eval if missing and return cached function
6405
6436
  if (functionCache[functionString] == null) {
6437
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
6406
6438
  functionCache[functionString] = new Function(functionString);
6407
6439
  }
6408
6440
  // Set the object
@@ -6424,74 +6456,6 @@ var BSON = (function (exports) {
6424
6456
  return value;
6425
6457
  }
6426
6458
 
6427
- // Copyright (c) 2008, Fair Oaks Labs, Inc.
6428
- function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
6429
- var e;
6430
- var m;
6431
- var c;
6432
- var bBE = endian === 'big';
6433
- var eLen = nBytes * 8 - mLen - 1;
6434
- var eMax = (1 << eLen) - 1;
6435
- var eBias = eMax >> 1;
6436
- var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
6437
- var i = bBE ? nBytes - 1 : 0;
6438
- var d = bBE ? -1 : 1;
6439
- var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
6440
- value = Math.abs(value);
6441
- if (isNaN(value) || value === Infinity) {
6442
- m = isNaN(value) ? 1 : 0;
6443
- e = eMax;
6444
- }
6445
- else {
6446
- e = Math.floor(Math.log(value) / Math.LN2);
6447
- if (value * (c = Math.pow(2, -e)) < 1) {
6448
- e--;
6449
- c *= 2;
6450
- }
6451
- if (e + eBias >= 1) {
6452
- value += rt / c;
6453
- }
6454
- else {
6455
- value += rt * Math.pow(2, 1 - eBias);
6456
- }
6457
- if (value * c >= 2) {
6458
- e++;
6459
- c /= 2;
6460
- }
6461
- if (e + eBias >= eMax) {
6462
- m = 0;
6463
- e = eMax;
6464
- }
6465
- else if (e + eBias >= 1) {
6466
- m = (value * c - 1) * Math.pow(2, mLen);
6467
- e = e + eBias;
6468
- }
6469
- else {
6470
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
6471
- e = 0;
6472
- }
6473
- }
6474
- if (isNaN(value))
6475
- m = 0;
6476
- while (mLen >= 8) {
6477
- buffer[offset + i] = m & 0xff;
6478
- i += d;
6479
- m /= 256;
6480
- mLen -= 8;
6481
- }
6482
- e = (e << mLen) | m;
6483
- if (isNaN(value))
6484
- e += 8;
6485
- eLen += mLen;
6486
- while (eLen > 0) {
6487
- buffer[offset + i] = e & 0xff;
6488
- i += d;
6489
- e /= 256;
6490
- eLen -= 8;
6491
- }
6492
- buffer[offset + i - d] |= s * 128;
6493
- }
6494
-
6495
6459
  var regexp = /\x00/; // eslint-disable-line no-control-regex
6496
6460
  var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
6497
6461
  /*
@@ -6522,6 +6486,8 @@ var BSON = (function (exports) {
6522
6486
  buffer[index++] = 0;
6523
6487
  return index;
6524
6488
  }
6489
+ var SPACE_FOR_FLOAT64 = new Uint8Array(8);
6490
+ var DV_FOR_FLOAT64 = new DataView(SPACE_FOR_FLOAT64.buffer, SPACE_FOR_FLOAT64.byteOffset, SPACE_FOR_FLOAT64.byteLength);
6525
6491
  function serializeNumber(buffer, key, value, index, isArray) {
6526
6492
  // We have an integer value
6527
6493
  // TODO(NODE-2529): Add support for big int
@@ -6555,7 +6521,8 @@ var BSON = (function (exports) {
6555
6521
  index = index + numberOfWrittenBytes;
6556
6522
  buffer[index++] = 0;
6557
6523
  // Write float
6558
- writeIEEE754(buffer, value, index, 'little', 52, 8);
6524
+ DV_FOR_FLOAT64.setFloat64(0, value, true);
6525
+ buffer.set(SPACE_FOR_FLOAT64, index);
6559
6526
  // Adjust index
6560
6527
  index = index + 8;
6561
6528
  }
@@ -6834,7 +6801,8 @@ var BSON = (function (exports) {
6834
6801
  index = index + numberOfWrittenBytes;
6835
6802
  buffer[index++] = 0;
6836
6803
  // Write float
6837
- writeIEEE754(buffer, value.value, index, 'little', 52, 8);
6804
+ DV_FOR_FLOAT64.setFloat64(0, value.value, true);
6805
+ buffer.set(SPACE_FOR_FLOAT64, index);
6838
6806
  // Adjust index
6839
6807
  index = index + 8;
6840
6808
  return index;
@@ -7044,7 +7012,7 @@ var BSON = (function (exports) {
7044
7012
  if (Array.isArray(object)) {
7045
7013
  // Get object keys
7046
7014
  for (var i = 0; i < object.length; i++) {
7047
- var key = '' + i;
7015
+ var key = "".concat(i);
7048
7016
  var value = object[i];
7049
7017
  // Is there an override value
7050
7018
  if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
@@ -7119,7 +7087,7 @@ var BSON = (function (exports) {
7119
7087
  index = serializeMinMax(buffer, key, value, index, true);
7120
7088
  }
7121
7089
  else if (typeof value['_bsontype'] !== 'undefined') {
7122
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7090
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7123
7091
  }
7124
7092
  }
7125
7093
  }
@@ -7218,7 +7186,7 @@ var BSON = (function (exports) {
7218
7186
  index = serializeMinMax(buffer, key, value, index);
7219
7187
  }
7220
7188
  else if (typeof value['_bsontype'] !== 'undefined') {
7221
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7189
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7222
7190
  }
7223
7191
  }
7224
7192
  }
@@ -7323,7 +7291,7 @@ var BSON = (function (exports) {
7323
7291
  index = serializeMinMax(buffer, key, value, index);
7324
7292
  }
7325
7293
  else if (typeof value['_bsontype'] !== 'undefined') {
7326
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7294
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7327
7295
  }
7328
7296
  }
7329
7297
  }