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
@@ -2134,11 +2134,11 @@
2134
2134
  }
2135
2135
  // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
2136
2136
  function getGlobal() {
2137
- // eslint-disable-next-line no-undef
2138
2137
  return (checkForMath(typeof globalThis === 'object' && globalThis) ||
2139
2138
  checkForMath(typeof window === 'object' && window) ||
2140
2139
  checkForMath(typeof self === 'object' && self) ||
2141
2140
  checkForMath(typeof global === 'object' && global) ||
2141
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
2142
2142
  Function('return this')());
2143
2143
  }
2144
2144
 
@@ -2164,27 +2164,20 @@
2164
2164
  return result;
2165
2165
  };
2166
2166
  var detectRandomBytes = function () {
2167
- if (typeof window !== 'undefined') {
2168
- // browser crypto implementation(s)
2169
- var target_1 = window.crypto || window.msCrypto; // allow for IE11
2170
- if (target_1 && target_1.getRandomValues) {
2171
- return function (size) { return target_1.getRandomValues(buffer_1.alloc(size)); };
2167
+ {
2168
+ if (typeof window !== 'undefined') {
2169
+ // browser crypto implementation(s)
2170
+ var target_1 = window.crypto || window.msCrypto; // allow for IE11
2171
+ if (target_1 && target_1.getRandomValues) {
2172
+ return function (size) { return target_1.getRandomValues(buffer_1.alloc(size)); };
2173
+ }
2172
2174
  }
2175
+ if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
2176
+ // allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
2177
+ return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
2178
+ }
2179
+ return insecureRandomBytes;
2173
2180
  }
2174
- if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
2175
- // allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
2176
- return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
2177
- }
2178
- var requiredRandomBytes;
2179
- try {
2180
- // eslint-disable-next-line @typescript-eslint/no-var-requires
2181
- requiredRandomBytes = require('crypto').randomBytes;
2182
- }
2183
- catch (e) {
2184
- // keep the fallback
2185
- }
2186
- // NOTE: in transpiled cases the above require might return null/undefined
2187
- return requiredRandomBytes || insecureRandomBytes;
2188
2181
  };
2189
2182
  var randomBytes = detectRandomBytes();
2190
2183
  function isAnyArrayBuffer(value) {
@@ -2441,7 +2434,7 @@
2441
2434
  return this.inspect();
2442
2435
  };
2443
2436
  UUID.prototype.inspect = function () {
2444
- return "new UUID(\"" + this.toHexString() + "\")";
2437
+ return "new UUID(\"".concat(this.toHexString(), "\")");
2445
2438
  };
2446
2439
  return UUID;
2447
2440
  }());
@@ -2450,9 +2443,17 @@
2450
2443
  /**
2451
2444
  * A class representation of the BSON Binary type.
2452
2445
  * @public
2446
+ * @category BSONType
2453
2447
  */
2454
2448
  var Binary = /** @class */ (function () {
2455
2449
  /**
2450
+ * Create a new Binary instance.
2451
+ *
2452
+ * This constructor can accept a string as its first argument. In this case,
2453
+ * this string will be encoded using ISO-8859-1, **not** using UTF-8.
2454
+ * This is almost certainly not what you want. Use `new Binary(Buffer.from(string))`
2455
+ * instead to convert the string to a Buffer using UTF-8 first.
2456
+ *
2456
2457
  * @param buffer - a buffer object containing the binary data.
2457
2458
  * @param subType - the option binary type.
2458
2459
  */
@@ -2612,7 +2613,7 @@
2612
2613
  if (this.sub_type === Binary.SUBTYPE_UUID) {
2613
2614
  return new UUID(this.buffer.slice(0, this.position));
2614
2615
  }
2615
- throw new BSONError("Binary sub_type \"" + this.sub_type + "\" is not supported for converting to UUID. Only \"" + Binary.SUBTYPE_UUID + "\" is currently supported.");
2616
+ throw new BSONError("Binary sub_type \"".concat(this.sub_type, "\" is not supported for converting to UUID. Only \"").concat(Binary.SUBTYPE_UUID, "\" is currently supported."));
2616
2617
  };
2617
2618
  /** @internal */
2618
2619
  Binary.fromExtendedJSON = function (doc, options) {
@@ -2636,7 +2637,7 @@
2636
2637
  data = uuidHexStringToBuffer(doc.$uuid);
2637
2638
  }
2638
2639
  if (!data) {
2639
- throw new BSONTypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc));
2640
+ throw new BSONTypeError("Unexpected Binary Extended JSON format ".concat(JSON.stringify(doc)));
2640
2641
  }
2641
2642
  return new Binary(data, type);
2642
2643
  };
@@ -2646,7 +2647,7 @@
2646
2647
  };
2647
2648
  Binary.prototype.inspect = function () {
2648
2649
  var asBuffer = this.value(true);
2649
- return "new Binary(Buffer.from(\"" + asBuffer.toString('hex') + "\", \"hex\"), " + this.sub_type + ")";
2650
+ return "new Binary(Buffer.from(\"".concat(asBuffer.toString('hex'), "\", \"hex\"), ").concat(this.sub_type, ")");
2650
2651
  };
2651
2652
  /**
2652
2653
  * Binary default subtype
@@ -2680,6 +2681,7 @@
2680
2681
  /**
2681
2682
  * A class representation of the BSON Code type.
2682
2683
  * @public
2684
+ * @category BSONType
2683
2685
  */
2684
2686
  var Code = /** @class */ (function () {
2685
2687
  /**
@@ -2712,7 +2714,7 @@
2712
2714
  };
2713
2715
  Code.prototype.inspect = function () {
2714
2716
  var codeJson = this.toJSON();
2715
- return "new Code(\"" + codeJson.code + "\"" + (codeJson.scope ? ", " + JSON.stringify(codeJson.scope) : '') + ")";
2717
+ return "new Code(\"".concat(String(codeJson.code), "\"").concat(codeJson.scope ? ", ".concat(JSON.stringify(codeJson.scope)) : '', ")");
2716
2718
  };
2717
2719
  return Code;
2718
2720
  }());
@@ -2728,6 +2730,7 @@
2728
2730
  /**
2729
2731
  * A class representation of the BSON DBRef type.
2730
2732
  * @public
2733
+ * @category BSONType
2731
2734
  */
2732
2735
  var DBRef = /** @class */ (function () {
2733
2736
  /**
@@ -2802,7 +2805,7 @@
2802
2805
  DBRef.prototype.inspect = function () {
2803
2806
  // NOTE: if OID is an ObjectId class it will just print the oid string.
2804
2807
  var oid = this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString();
2805
- return "new DBRef(\"" + this.namespace + "\", new ObjectId(\"" + oid + "\")" + (this.db ? ", \"" + this.db + "\"" : '') + ")";
2808
+ return "new DBRef(\"".concat(this.namespace, "\", new ObjectId(\"").concat(String(oid), "\")").concat(this.db ? ", \"".concat(this.db, "\"") : '', ")");
2806
2809
  };
2807
2810
  return DBRef;
2808
2811
  }());
@@ -2832,6 +2835,7 @@
2832
2835
  /**
2833
2836
  * A class representing a 64-bit integer
2834
2837
  * @public
2838
+ * @category BSONType
2835
2839
  * @remarks
2836
2840
  * The internal representation of a long is the two given signed, 32-bit values.
2837
2841
  * We use 32-bit pieces because these are the size of integers on which
@@ -3038,7 +3042,6 @@
3038
3042
  /**
3039
3043
  * Tests if the specified object is a Long.
3040
3044
  */
3041
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
3042
3045
  Long.isLong = function (value) {
3043
3046
  return isObjectLike(value) && value['__isLong__'] === true;
3044
3047
  };
@@ -3195,6 +3198,7 @@
3195
3198
  // into the result, and subtract it from the remainder. It is critical that
3196
3199
  // the approximate value is less than or equal to the real value so that the
3197
3200
  // remainder never becomes negative.
3201
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3198
3202
  rem = this;
3199
3203
  while (rem.gte(divisor)) {
3200
3204
  // Approximate the result of division. This may be a little greater or
@@ -3678,7 +3682,7 @@
3678
3682
  return this.inspect();
3679
3683
  };
3680
3684
  Long.prototype.inspect = function () {
3681
- return "new Long(\"" + this.toString() + "\"" + (this.unsigned ? ', true' : '') + ")";
3685
+ return "new Long(\"".concat(this.toString(), "\"").concat(this.unsigned ? ', true' : '', ")");
3682
3686
  };
3683
3687
  Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
3684
3688
  /** Maximum unsigned value. */
@@ -3789,11 +3793,12 @@
3789
3793
  return false;
3790
3794
  }
3791
3795
  function invalidErr(string, message) {
3792
- throw new BSONTypeError("\"" + string + "\" is not a valid Decimal128 string - " + message);
3796
+ throw new BSONTypeError("\"".concat(string, "\" is not a valid Decimal128 string - ").concat(message));
3793
3797
  }
3794
3798
  /**
3795
3799
  * A class representation of the BSON Decimal128 type.
3796
3800
  * @public
3801
+ * @category BSONType
3797
3802
  */
3798
3803
  var Decimal128 = /** @class */ (function () {
3799
3804
  /**
@@ -4286,35 +4291,35 @@
4286
4291
  // as + or - 0 and using the non-scientific exponent (this is for the "invalid
4287
4292
  // representation should be treated as 0/-0" spec cases in decimal128-1.json)
4288
4293
  if (significand_digits > 34) {
4289
- string.push("" + 0);
4294
+ string.push("".concat(0));
4290
4295
  if (exponent > 0)
4291
- string.push('E+' + exponent);
4296
+ string.push("E+".concat(exponent));
4292
4297
  else if (exponent < 0)
4293
- string.push('E' + exponent);
4298
+ string.push("E".concat(exponent));
4294
4299
  return string.join('');
4295
4300
  }
4296
- string.push("" + significand[index++]);
4301
+ string.push("".concat(significand[index++]));
4297
4302
  significand_digits = significand_digits - 1;
4298
4303
  if (significand_digits) {
4299
4304
  string.push('.');
4300
4305
  }
4301
4306
  for (var i = 0; i < significand_digits; i++) {
4302
- string.push("" + significand[index++]);
4307
+ string.push("".concat(significand[index++]));
4303
4308
  }
4304
4309
  // Exponent
4305
4310
  string.push('E');
4306
4311
  if (scientific_exponent > 0) {
4307
- string.push('+' + scientific_exponent);
4312
+ string.push("+".concat(scientific_exponent));
4308
4313
  }
4309
4314
  else {
4310
- string.push("" + scientific_exponent);
4315
+ string.push("".concat(scientific_exponent));
4311
4316
  }
4312
4317
  }
4313
4318
  else {
4314
4319
  // Regular format with no decimal place
4315
4320
  if (exponent >= 0) {
4316
4321
  for (var i = 0; i < significand_digits; i++) {
4317
- string.push("" + significand[index++]);
4322
+ string.push("".concat(significand[index++]));
4318
4323
  }
4319
4324
  }
4320
4325
  else {
@@ -4322,7 +4327,7 @@
4322
4327
  // non-zero digits before radix
4323
4328
  if (radix_position > 0) {
4324
4329
  for (var i = 0; i < radix_position; i++) {
4325
- string.push("" + significand[index++]);
4330
+ string.push("".concat(significand[index++]));
4326
4331
  }
4327
4332
  }
4328
4333
  else {
@@ -4334,7 +4339,7 @@
4334
4339
  string.push('0');
4335
4340
  }
4336
4341
  for (var i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
4337
- string.push("" + significand[index++]);
4342
+ string.push("".concat(significand[index++]));
4338
4343
  }
4339
4344
  }
4340
4345
  }
@@ -4356,7 +4361,7 @@
4356
4361
  return this.inspect();
4357
4362
  };
4358
4363
  Decimal128.prototype.inspect = function () {
4359
- return "new Decimal128(\"" + this.toString() + "\")";
4364
+ return "new Decimal128(\"".concat(this.toString(), "\")");
4360
4365
  };
4361
4366
  return Decimal128;
4362
4367
  }());
@@ -4365,6 +4370,7 @@
4365
4370
  /**
4366
4371
  * A class representation of the BSON Double type.
4367
4372
  * @public
4373
+ * @category BSONType
4368
4374
  */
4369
4375
  var Double = /** @class */ (function () {
4370
4376
  /**
@@ -4402,7 +4408,7 @@
4402
4408
  // NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
4403
4409
  // explicitly provided `-0` then we need to ensure the sign makes it into the output
4404
4410
  if (Object.is(Math.sign(this.value), -0)) {
4405
- return { $numberDouble: "-" + this.value.toFixed(1) };
4411
+ return { $numberDouble: "-".concat(this.value.toFixed(1)) };
4406
4412
  }
4407
4413
  var $numberDouble;
4408
4414
  if (Number.isInteger(this.value)) {
@@ -4427,7 +4433,7 @@
4427
4433
  };
4428
4434
  Double.prototype.inspect = function () {
4429
4435
  var eJSON = this.toExtendedJSON();
4430
- return "new Double(" + eJSON.$numberDouble + ")";
4436
+ return "new Double(".concat(eJSON.$numberDouble, ")");
4431
4437
  };
4432
4438
  return Double;
4433
4439
  }());
@@ -4436,6 +4442,7 @@
4436
4442
  /**
4437
4443
  * A class representation of a BSON Int32 type.
4438
4444
  * @public
4445
+ * @category BSONType
4439
4446
  */
4440
4447
  var Int32 = /** @class */ (function () {
4441
4448
  /**
@@ -4480,7 +4487,7 @@
4480
4487
  return this.inspect();
4481
4488
  };
4482
4489
  Int32.prototype.inspect = function () {
4483
- return "new Int32(" + this.valueOf() + ")";
4490
+ return "new Int32(".concat(this.valueOf(), ")");
4484
4491
  };
4485
4492
  return Int32;
4486
4493
  }());
@@ -4489,6 +4496,7 @@
4489
4496
  /**
4490
4497
  * A class representation of the BSON MaxKey type.
4491
4498
  * @public
4499
+ * @category BSONType
4492
4500
  */
4493
4501
  var MaxKey = /** @class */ (function () {
4494
4502
  function MaxKey() {
@@ -4517,6 +4525,7 @@
4517
4525
  /**
4518
4526
  * A class representation of the BSON MinKey type.
4519
4527
  * @public
4528
+ * @category BSONType
4520
4529
  */
4521
4530
  var MinKey = /** @class */ (function () {
4522
4531
  function MinKey() {
@@ -4550,6 +4559,7 @@
4550
4559
  /**
4551
4560
  * A class representation of the BSON ObjectId type.
4552
4561
  * @public
4562
+ * @category BSONType
4553
4563
  */
4554
4564
  var ObjectId = /** @class */ (function () {
4555
4565
  /**
@@ -4583,7 +4593,8 @@
4583
4593
  this[kId] = ObjectId.generate(typeof workingId === 'number' ? workingId : undefined);
4584
4594
  }
4585
4595
  else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
4586
- this[kId] = ensureBuffer(workingId);
4596
+ // If intstanceof matches we can escape calling ensure buffer in Node.js environments
4597
+ this[kId] = workingId instanceof buffer_1 ? workingId : ensureBuffer(workingId);
4587
4598
  }
4588
4599
  else if (typeof workingId === 'string') {
4589
4600
  if (workingId.length === 12) {
@@ -4810,7 +4821,7 @@
4810
4821
  return this.inspect();
4811
4822
  };
4812
4823
  ObjectId.prototype.inspect = function () {
4813
- return "new ObjectId(\"" + this.toHexString() + "\")";
4824
+ return "new ObjectId(\"".concat(this.toHexString(), "\")");
4814
4825
  };
4815
4826
  /** @internal */
4816
4827
  ObjectId.index = Math.floor(Math.random() * 0xffffff);
@@ -4837,6 +4848,7 @@
4837
4848
  /**
4838
4849
  * A class representation of the BSON RegExp type.
4839
4850
  * @public
4851
+ * @category BSONType
4840
4852
  */
4841
4853
  var BSONRegExp = /** @class */ (function () {
4842
4854
  /**
@@ -4849,10 +4861,10 @@
4849
4861
  this.pattern = pattern;
4850
4862
  this.options = alphabetize(options !== null && options !== void 0 ? options : '');
4851
4863
  if (this.pattern.indexOf('\x00') !== -1) {
4852
- throw new BSONError("BSON Regex patterns cannot contain null bytes, found: " + JSON.stringify(this.pattern));
4864
+ throw new BSONError("BSON Regex patterns cannot contain null bytes, found: ".concat(JSON.stringify(this.pattern)));
4853
4865
  }
4854
4866
  if (this.options.indexOf('\x00') !== -1) {
4855
- throw new BSONError("BSON Regex options cannot contain null bytes, found: " + JSON.stringify(this.options));
4867
+ throw new BSONError("BSON Regex options cannot contain null bytes, found: ".concat(JSON.stringify(this.options)));
4856
4868
  }
4857
4869
  // Validate options
4858
4870
  for (var i = 0; i < this.options.length; i++) {
@@ -4862,7 +4874,7 @@
4862
4874
  this.options[i] === 'l' ||
4863
4875
  this.options[i] === 's' ||
4864
4876
  this.options[i] === 'u')) {
4865
- throw new BSONError("The regular expression option [" + this.options[i] + "] is not supported");
4877
+ throw new BSONError("The regular expression option [".concat(this.options[i], "] is not supported"));
4866
4878
  }
4867
4879
  }
4868
4880
  }
@@ -4893,7 +4905,7 @@
4893
4905
  if ('$regularExpression' in doc) {
4894
4906
  return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
4895
4907
  }
4896
- throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: " + JSON.stringify(doc));
4908
+ throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(doc)));
4897
4909
  };
4898
4910
  return BSONRegExp;
4899
4911
  }());
@@ -4902,6 +4914,7 @@
4902
4914
  /**
4903
4915
  * A class representation of the BSON Symbol type.
4904
4916
  * @public
4917
+ * @category BSONType
4905
4918
  */
4906
4919
  var BSONSymbol = /** @class */ (function () {
4907
4920
  /**
@@ -4921,7 +4934,7 @@
4921
4934
  };
4922
4935
  /** @internal */
4923
4936
  BSONSymbol.prototype.inspect = function () {
4924
- return "new BSONSymbol(\"" + this.value + "\")";
4937
+ return "new BSONSymbol(\"".concat(this.value, "\")");
4925
4938
  };
4926
4939
  BSONSymbol.prototype.toJSON = function () {
4927
4940
  return this.value;
@@ -4944,13 +4957,16 @@
4944
4957
 
4945
4958
  /** @public */
4946
4959
  var LongWithoutOverridesClass = Long;
4947
- /** @public */
4960
+ /**
4961
+ * @public
4962
+ * @category BSONType
4963
+ * */
4948
4964
  var Timestamp = /** @class */ (function (_super) {
4949
4965
  __extends(Timestamp, _super);
4950
4966
  function Timestamp(low, high) {
4951
4967
  var _this = this;
4952
4968
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4953
- ///@ts-expect-error
4969
+ // @ts-expect-error
4954
4970
  if (!(_this instanceof Timestamp))
4955
4971
  return new Timestamp(low, high);
4956
4972
  if (Long.isLong(low)) {
@@ -5014,7 +5030,7 @@
5014
5030
  return this.inspect();
5015
5031
  };
5016
5032
  Timestamp.prototype.inspect = function () {
5017
- return "new Timestamp({ t: " + this.getHighBits() + ", i: " + this.getLowBits() + " })";
5033
+ return "new Timestamp({ t: ".concat(this.getHighBits(), ", i: ").concat(this.getLowBits(), " })");
5018
5034
  };
5019
5035
  Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
5020
5036
  return Timestamp;
@@ -5027,7 +5043,8 @@
5027
5043
  var BSON_INT32_MAX$1 = 0x7fffffff;
5028
5044
  var BSON_INT32_MIN$1 = -0x80000000;
5029
5045
  // INT64 boundaries
5030
- var BSON_INT64_MAX$1 = 0x7fffffffffffffff;
5046
+ // const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
5047
+ var BSON_INT64_MAX$1 = 0x8000000000000000;
5031
5048
  var BSON_INT64_MIN$1 = -0x8000000000000000;
5032
5049
  // all the types where we don't need to do any special processing and can just pass the EJSON
5033
5050
  //straight to type.fromExtendedJSON
@@ -5123,7 +5140,7 @@
5123
5140
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5124
5141
  function serializeArray(array, options) {
5125
5142
  return array.map(function (v, index) {
5126
- options.seenObjects.push({ propertyName: "index " + index, obj: null });
5143
+ options.seenObjects.push({ propertyName: "index ".concat(index), obj: null });
5127
5144
  try {
5128
5145
  return serializeValue(v, options);
5129
5146
  }
@@ -5145,20 +5162,20 @@
5145
5162
  var props = options.seenObjects.map(function (entry) { return entry.propertyName; });
5146
5163
  var leadingPart = props
5147
5164
  .slice(0, index)
5148
- .map(function (prop) { return prop + " -> "; })
5165
+ .map(function (prop) { return "".concat(prop, " -> "); })
5149
5166
  .join('');
5150
5167
  var alreadySeen = props[index];
5151
5168
  var circularPart = ' -> ' +
5152
5169
  props
5153
5170
  .slice(index + 1, props.length - 1)
5154
- .map(function (prop) { return prop + " -> "; })
5171
+ .map(function (prop) { return "".concat(prop, " -> "); })
5155
5172
  .join('');
5156
5173
  var current = props[props.length - 1];
5157
5174
  var leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
5158
5175
  var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
5159
5176
  throw new BSONTypeError('Converting circular structure to EJSON:\n' +
5160
- (" " + leadingPart + alreadySeen + circularPart + current + "\n") +
5161
- (" " + leadingSpace + "\\" + dashes + "/"));
5177
+ " ".concat(leadingPart).concat(alreadySeen).concat(circularPart).concat(current, "\n") +
5178
+ " ".concat(leadingSpace, "\\").concat(dashes, "/"));
5162
5179
  }
5163
5180
  options.seenObjects[options.seenObjects.length - 1].obj = value;
5164
5181
  }
@@ -5237,7 +5254,18 @@
5237
5254
  for (var name in doc) {
5238
5255
  options.seenObjects.push({ propertyName: name, obj: null });
5239
5256
  try {
5240
- _doc[name] = serializeValue(doc[name], options);
5257
+ var value = serializeValue(doc[name], options);
5258
+ if (name === '__proto__') {
5259
+ Object.defineProperty(_doc, name, {
5260
+ value: value,
5261
+ writable: true,
5262
+ enumerable: true,
5263
+ configurable: true
5264
+ });
5265
+ }
5266
+ else {
5267
+ _doc[name] = value;
5268
+ }
5241
5269
  }
5242
5270
  finally {
5243
5271
  options.seenObjects.pop();
@@ -5307,7 +5335,7 @@
5307
5335
  finalOptions.relaxed = !finalOptions.strict;
5308
5336
  return JSON.parse(text, function (key, value) {
5309
5337
  if (key.indexOf('\x00') !== -1) {
5310
- throw new BSONError("BSON Document field names cannot contain null bytes, found: " + JSON.stringify(key));
5338
+ throw new BSONError("BSON Document field names cannot contain null bytes, found: ".concat(JSON.stringify(key)));
5311
5339
  }
5312
5340
  return deserializeValue(value, finalOptions);
5313
5341
  });
@@ -5673,13 +5701,14 @@
5673
5701
  }
5674
5702
  }
5675
5703
  else if (value['_bsontype'] === 'Binary') {
5704
+ var binary = value;
5676
5705
  // Check what kind of subtype we have
5677
- if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5706
+ if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5678
5707
  return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
5679
- (value.position + 1 + 4 + 1 + 4));
5708
+ (binary.position + 1 + 4 + 1 + 4));
5680
5709
  }
5681
5710
  else {
5682
- return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1));
5711
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (binary.position + 1 + 4 + 1));
5683
5712
  }
5684
5713
  }
5685
5714
  else if (value['_bsontype'] === 'Symbol') {
@@ -5816,16 +5845,16 @@
5816
5845
  (buffer[index + 2] << 16) |
5817
5846
  (buffer[index + 3] << 24);
5818
5847
  if (size < 5) {
5819
- throw new BSONError("bson size must be >= 5, is " + size);
5848
+ throw new BSONError("bson size must be >= 5, is ".concat(size));
5820
5849
  }
5821
5850
  if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
5822
- throw new BSONError("buffer length " + buffer.length + " must be >= bson size " + size);
5851
+ throw new BSONError("buffer length ".concat(buffer.length, " must be >= bson size ").concat(size));
5823
5852
  }
5824
5853
  if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
5825
- throw new BSONError("buffer length " + buffer.length + " must === bson size " + size);
5854
+ throw new BSONError("buffer length ".concat(buffer.length, " must === bson size ").concat(size));
5826
5855
  }
5827
5856
  if (size + index > buffer.byteLength) {
5828
- throw new BSONError("(bson size " + size + " + options.index " + index + " must be <= buffer length " + buffer.byteLength + ")");
5857
+ throw new BSONError("(bson size ".concat(size, " + options.index ").concat(index, " must be <= buffer length ").concat(buffer.byteLength, ")"));
5829
5858
  }
5830
5859
  // Illegal end value
5831
5860
  if (buffer[index + size - 1] !== 0) {
@@ -5902,6 +5931,7 @@
5902
5931
  var done = false;
5903
5932
  var isPossibleDBRef = isArray ? false : null;
5904
5933
  // While we have more left data left keep parsing
5934
+ var dataview = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
5905
5935
  while (!done) {
5906
5936
  // Read the type
5907
5937
  var elementType = buffer[index++];
@@ -5962,11 +5992,11 @@
5962
5992
  (buffer[index++] << 24);
5963
5993
  }
5964
5994
  else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
5965
- value = new Double(buffer.readDoubleLE(index));
5995
+ value = new Double(dataview.getFloat64(index, true));
5966
5996
  index = index + 8;
5967
5997
  }
5968
5998
  else if (elementType === BSON_DATA_NUMBER) {
5969
- value = buffer.readDoubleLE(index);
5999
+ value = dataview.getFloat64(index, true);
5970
6000
  index = index + 8;
5971
6001
  }
5972
6002
  else if (elementType === BSON_DATA_DATE) {
@@ -6364,7 +6394,7 @@
6364
6394
  value = new DBRef(namespace, oid);
6365
6395
  }
6366
6396
  else {
6367
- throw new BSONError('Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"');
6397
+ throw new BSONError("Detected unknown BSON type ".concat(elementType.toString(16), " for fieldname \"").concat(name, "\""));
6368
6398
  }
6369
6399
  if (name === '__proto__') {
6370
6400
  Object.defineProperty(object, name, {
@@ -6402,10 +6432,12 @@
6402
6432
  * @internal
6403
6433
  */
6404
6434
  function isolateEval(functionString, functionCache, object) {
6435
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
6405
6436
  if (!functionCache)
6406
6437
  return new Function(functionString);
6407
6438
  // Check for cache hit, eval if missing and return cached function
6408
6439
  if (functionCache[functionString] == null) {
6440
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
6409
6441
  functionCache[functionString] = new Function(functionString);
6410
6442
  }
6411
6443
  // Set the object
@@ -6427,74 +6459,6 @@
6427
6459
  return value;
6428
6460
  }
6429
6461
 
6430
- // Copyright (c) 2008, Fair Oaks Labs, Inc.
6431
- function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
6432
- var e;
6433
- var m;
6434
- var c;
6435
- var bBE = endian === 'big';
6436
- var eLen = nBytes * 8 - mLen - 1;
6437
- var eMax = (1 << eLen) - 1;
6438
- var eBias = eMax >> 1;
6439
- var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
6440
- var i = bBE ? nBytes - 1 : 0;
6441
- var d = bBE ? -1 : 1;
6442
- var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
6443
- value = Math.abs(value);
6444
- if (isNaN(value) || value === Infinity) {
6445
- m = isNaN(value) ? 1 : 0;
6446
- e = eMax;
6447
- }
6448
- else {
6449
- e = Math.floor(Math.log(value) / Math.LN2);
6450
- if (value * (c = Math.pow(2, -e)) < 1) {
6451
- e--;
6452
- c *= 2;
6453
- }
6454
- if (e + eBias >= 1) {
6455
- value += rt / c;
6456
- }
6457
- else {
6458
- value += rt * Math.pow(2, 1 - eBias);
6459
- }
6460
- if (value * c >= 2) {
6461
- e++;
6462
- c /= 2;
6463
- }
6464
- if (e + eBias >= eMax) {
6465
- m = 0;
6466
- e = eMax;
6467
- }
6468
- else if (e + eBias >= 1) {
6469
- m = (value * c - 1) * Math.pow(2, mLen);
6470
- e = e + eBias;
6471
- }
6472
- else {
6473
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
6474
- e = 0;
6475
- }
6476
- }
6477
- if (isNaN(value))
6478
- m = 0;
6479
- while (mLen >= 8) {
6480
- buffer[offset + i] = m & 0xff;
6481
- i += d;
6482
- m /= 256;
6483
- mLen -= 8;
6484
- }
6485
- e = (e << mLen) | m;
6486
- if (isNaN(value))
6487
- e += 8;
6488
- eLen += mLen;
6489
- while (eLen > 0) {
6490
- buffer[offset + i] = e & 0xff;
6491
- i += d;
6492
- e /= 256;
6493
- eLen -= 8;
6494
- }
6495
- buffer[offset + i - d] |= s * 128;
6496
- }
6497
-
6498
6462
  var regexp = /\x00/; // eslint-disable-line no-control-regex
6499
6463
  var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
6500
6464
  /*
@@ -6525,6 +6489,8 @@
6525
6489
  buffer[index++] = 0;
6526
6490
  return index;
6527
6491
  }
6492
+ var SPACE_FOR_FLOAT64 = new Uint8Array(8);
6493
+ var DV_FOR_FLOAT64 = new DataView(SPACE_FOR_FLOAT64.buffer, SPACE_FOR_FLOAT64.byteOffset, SPACE_FOR_FLOAT64.byteLength);
6528
6494
  function serializeNumber(buffer, key, value, index, isArray) {
6529
6495
  // We have an integer value
6530
6496
  // TODO(NODE-2529): Add support for big int
@@ -6558,7 +6524,8 @@
6558
6524
  index = index + numberOfWrittenBytes;
6559
6525
  buffer[index++] = 0;
6560
6526
  // Write float
6561
- writeIEEE754(buffer, value, index, 'little', 52, 8);
6527
+ DV_FOR_FLOAT64.setFloat64(0, value, true);
6528
+ buffer.set(SPACE_FOR_FLOAT64, index);
6562
6529
  // Adjust index
6563
6530
  index = index + 8;
6564
6531
  }
@@ -6837,7 +6804,8 @@
6837
6804
  index = index + numberOfWrittenBytes;
6838
6805
  buffer[index++] = 0;
6839
6806
  // Write float
6840
- writeIEEE754(buffer, value.value, index, 'little', 52, 8);
6807
+ DV_FOR_FLOAT64.setFloat64(0, value.value, true);
6808
+ buffer.set(SPACE_FOR_FLOAT64, index);
6841
6809
  // Adjust index
6842
6810
  index = index + 8;
6843
6811
  return index;
@@ -7047,7 +7015,7 @@
7047
7015
  if (Array.isArray(object)) {
7048
7016
  // Get object keys
7049
7017
  for (var i = 0; i < object.length; i++) {
7050
- var key = '' + i;
7018
+ var key = "".concat(i);
7051
7019
  var value = object[i];
7052
7020
  // Is there an override value
7053
7021
  if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
@@ -7122,7 +7090,7 @@
7122
7090
  index = serializeMinMax(buffer, key, value, index, true);
7123
7091
  }
7124
7092
  else if (typeof value['_bsontype'] !== 'undefined') {
7125
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7093
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7126
7094
  }
7127
7095
  }
7128
7096
  }
@@ -7221,7 +7189,7 @@
7221
7189
  index = serializeMinMax(buffer, key, value, index);
7222
7190
  }
7223
7191
  else if (typeof value['_bsontype'] !== 'undefined') {
7224
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7192
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7225
7193
  }
7226
7194
  }
7227
7195
  }
@@ -7326,7 +7294,7 @@
7326
7294
  index = serializeMinMax(buffer, key, value, index);
7327
7295
  }
7328
7296
  else if (typeof value['_bsontype'] !== 'undefined') {
7329
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7297
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7330
7298
  }
7331
7299
  }
7332
7300
  }