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
@@ -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
  }());
@@ -2444,9 +2437,17 @@ Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
2444
2437
  /**
2445
2438
  * A class representation of the BSON Binary type.
2446
2439
  * @public
2440
+ * @category BSONType
2447
2441
  */
2448
2442
  var Binary = /** @class */ (function () {
2449
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
+ *
2450
2451
  * @param buffer - a buffer object containing the binary data.
2451
2452
  * @param subType - the option binary type.
2452
2453
  */
@@ -2606,7 +2607,7 @@ var Binary = /** @class */ (function () {
2606
2607
  if (this.sub_type === Binary.SUBTYPE_UUID) {
2607
2608
  return new UUID(this.buffer.slice(0, this.position));
2608
2609
  }
2609
- 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."));
2610
2611
  };
2611
2612
  /** @internal */
2612
2613
  Binary.fromExtendedJSON = function (doc, options) {
@@ -2630,7 +2631,7 @@ var Binary = /** @class */ (function () {
2630
2631
  data = uuidHexStringToBuffer(doc.$uuid);
2631
2632
  }
2632
2633
  if (!data) {
2633
- throw new BSONTypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc));
2634
+ throw new BSONTypeError("Unexpected Binary Extended JSON format ".concat(JSON.stringify(doc)));
2634
2635
  }
2635
2636
  return new Binary(data, type);
2636
2637
  };
@@ -2640,7 +2641,7 @@ var Binary = /** @class */ (function () {
2640
2641
  };
2641
2642
  Binary.prototype.inspect = function () {
2642
2643
  var asBuffer = this.value(true);
2643
- 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, ")");
2644
2645
  };
2645
2646
  /**
2646
2647
  * Binary default subtype
@@ -2674,6 +2675,7 @@ Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' });
2674
2675
  /**
2675
2676
  * A class representation of the BSON Code type.
2676
2677
  * @public
2678
+ * @category BSONType
2677
2679
  */
2678
2680
  var Code = /** @class */ (function () {
2679
2681
  /**
@@ -2706,7 +2708,7 @@ var Code = /** @class */ (function () {
2706
2708
  };
2707
2709
  Code.prototype.inspect = function () {
2708
2710
  var codeJson = this.toJSON();
2709
- 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)) : '', ")");
2710
2712
  };
2711
2713
  return Code;
2712
2714
  }());
@@ -2722,6 +2724,7 @@ function isDBRefLike(value) {
2722
2724
  /**
2723
2725
  * A class representation of the BSON DBRef type.
2724
2726
  * @public
2727
+ * @category BSONType
2725
2728
  */
2726
2729
  var DBRef = /** @class */ (function () {
2727
2730
  /**
@@ -2796,7 +2799,7 @@ var DBRef = /** @class */ (function () {
2796
2799
  DBRef.prototype.inspect = function () {
2797
2800
  // NOTE: if OID is an ObjectId class it will just print the oid string.
2798
2801
  var oid = this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString();
2799
- 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, "\"") : '', ")");
2800
2803
  };
2801
2804
  return DBRef;
2802
2805
  }());
@@ -2826,6 +2829,7 @@ var UINT_CACHE = {};
2826
2829
  /**
2827
2830
  * A class representing a 64-bit integer
2828
2831
  * @public
2832
+ * @category BSONType
2829
2833
  * @remarks
2830
2834
  * The internal representation of a long is the two given signed, 32-bit values.
2831
2835
  * We use 32-bit pieces because these are the size of integers on which
@@ -3032,7 +3036,6 @@ var Long = /** @class */ (function () {
3032
3036
  /**
3033
3037
  * Tests if the specified object is a Long.
3034
3038
  */
3035
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
3036
3039
  Long.isLong = function (value) {
3037
3040
  return isObjectLike(value) && value['__isLong__'] === true;
3038
3041
  };
@@ -3189,6 +3192,7 @@ var Long = /** @class */ (function () {
3189
3192
  // into the result, and subtract it from the remainder. It is critical that
3190
3193
  // the approximate value is less than or equal to the real value so that the
3191
3194
  // remainder never becomes negative.
3195
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3192
3196
  rem = this;
3193
3197
  while (rem.gte(divisor)) {
3194
3198
  // Approximate the result of division. This may be a little greater or
@@ -3672,7 +3676,7 @@ var Long = /** @class */ (function () {
3672
3676
  return this.inspect();
3673
3677
  };
3674
3678
  Long.prototype.inspect = function () {
3675
- return "new Long(\"" + this.toString() + "\"" + (this.unsigned ? ', true' : '') + ")";
3679
+ return "new Long(\"".concat(this.toString(), "\"").concat(this.unsigned ? ', true' : '', ")");
3676
3680
  };
3677
3681
  Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
3678
3682
  /** Maximum unsigned value. */
@@ -3783,11 +3787,12 @@ function lessThan(left, right) {
3783
3787
  return false;
3784
3788
  }
3785
3789
  function invalidErr(string, message) {
3786
- 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));
3787
3791
  }
3788
3792
  /**
3789
3793
  * A class representation of the BSON Decimal128 type.
3790
3794
  * @public
3795
+ * @category BSONType
3791
3796
  */
3792
3797
  var Decimal128 = /** @class */ (function () {
3793
3798
  /**
@@ -4280,35 +4285,35 @@ var Decimal128 = /** @class */ (function () {
4280
4285
  // as + or - 0 and using the non-scientific exponent (this is for the "invalid
4281
4286
  // representation should be treated as 0/-0" spec cases in decimal128-1.json)
4282
4287
  if (significand_digits > 34) {
4283
- string.push("" + 0);
4288
+ string.push("".concat(0));
4284
4289
  if (exponent > 0)
4285
- string.push('E+' + exponent);
4290
+ string.push("E+".concat(exponent));
4286
4291
  else if (exponent < 0)
4287
- string.push('E' + exponent);
4292
+ string.push("E".concat(exponent));
4288
4293
  return string.join('');
4289
4294
  }
4290
- string.push("" + significand[index++]);
4295
+ string.push("".concat(significand[index++]));
4291
4296
  significand_digits = significand_digits - 1;
4292
4297
  if (significand_digits) {
4293
4298
  string.push('.');
4294
4299
  }
4295
4300
  for (var i = 0; i < significand_digits; i++) {
4296
- string.push("" + significand[index++]);
4301
+ string.push("".concat(significand[index++]));
4297
4302
  }
4298
4303
  // Exponent
4299
4304
  string.push('E');
4300
4305
  if (scientific_exponent > 0) {
4301
- string.push('+' + scientific_exponent);
4306
+ string.push("+".concat(scientific_exponent));
4302
4307
  }
4303
4308
  else {
4304
- string.push("" + scientific_exponent);
4309
+ string.push("".concat(scientific_exponent));
4305
4310
  }
4306
4311
  }
4307
4312
  else {
4308
4313
  // Regular format with no decimal place
4309
4314
  if (exponent >= 0) {
4310
4315
  for (var i = 0; i < significand_digits; i++) {
4311
- string.push("" + significand[index++]);
4316
+ string.push("".concat(significand[index++]));
4312
4317
  }
4313
4318
  }
4314
4319
  else {
@@ -4316,7 +4321,7 @@ var Decimal128 = /** @class */ (function () {
4316
4321
  // non-zero digits before radix
4317
4322
  if (radix_position > 0) {
4318
4323
  for (var i = 0; i < radix_position; i++) {
4319
- string.push("" + significand[index++]);
4324
+ string.push("".concat(significand[index++]));
4320
4325
  }
4321
4326
  }
4322
4327
  else {
@@ -4328,7 +4333,7 @@ var Decimal128 = /** @class */ (function () {
4328
4333
  string.push('0');
4329
4334
  }
4330
4335
  for (var i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
4331
- string.push("" + significand[index++]);
4336
+ string.push("".concat(significand[index++]));
4332
4337
  }
4333
4338
  }
4334
4339
  }
@@ -4350,7 +4355,7 @@ var Decimal128 = /** @class */ (function () {
4350
4355
  return this.inspect();
4351
4356
  };
4352
4357
  Decimal128.prototype.inspect = function () {
4353
- return "new Decimal128(\"" + this.toString() + "\")";
4358
+ return "new Decimal128(\"".concat(this.toString(), "\")");
4354
4359
  };
4355
4360
  return Decimal128;
4356
4361
  }());
@@ -4359,6 +4364,7 @@ Object.defineProperty(Decimal128.prototype, '_bsontype', { value: 'Decimal128' }
4359
4364
  /**
4360
4365
  * A class representation of the BSON Double type.
4361
4366
  * @public
4367
+ * @category BSONType
4362
4368
  */
4363
4369
  var Double = /** @class */ (function () {
4364
4370
  /**
@@ -4396,7 +4402,7 @@ var Double = /** @class */ (function () {
4396
4402
  // NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
4397
4403
  // explicitly provided `-0` then we need to ensure the sign makes it into the output
4398
4404
  if (Object.is(Math.sign(this.value), -0)) {
4399
- return { $numberDouble: "-" + this.value.toFixed(1) };
4405
+ return { $numberDouble: "-".concat(this.value.toFixed(1)) };
4400
4406
  }
4401
4407
  var $numberDouble;
4402
4408
  if (Number.isInteger(this.value)) {
@@ -4421,7 +4427,7 @@ var Double = /** @class */ (function () {
4421
4427
  };
4422
4428
  Double.prototype.inspect = function () {
4423
4429
  var eJSON = this.toExtendedJSON();
4424
- return "new Double(" + eJSON.$numberDouble + ")";
4430
+ return "new Double(".concat(eJSON.$numberDouble, ")");
4425
4431
  };
4426
4432
  return Double;
4427
4433
  }());
@@ -4430,6 +4436,7 @@ Object.defineProperty(Double.prototype, '_bsontype', { value: 'Double' });
4430
4436
  /**
4431
4437
  * A class representation of a BSON Int32 type.
4432
4438
  * @public
4439
+ * @category BSONType
4433
4440
  */
4434
4441
  var Int32 = /** @class */ (function () {
4435
4442
  /**
@@ -4474,7 +4481,7 @@ var Int32 = /** @class */ (function () {
4474
4481
  return this.inspect();
4475
4482
  };
4476
4483
  Int32.prototype.inspect = function () {
4477
- return "new Int32(" + this.valueOf() + ")";
4484
+ return "new Int32(".concat(this.valueOf(), ")");
4478
4485
  };
4479
4486
  return Int32;
4480
4487
  }());
@@ -4483,6 +4490,7 @@ Object.defineProperty(Int32.prototype, '_bsontype', { value: 'Int32' });
4483
4490
  /**
4484
4491
  * A class representation of the BSON MaxKey type.
4485
4492
  * @public
4493
+ * @category BSONType
4486
4494
  */
4487
4495
  var MaxKey = /** @class */ (function () {
4488
4496
  function MaxKey() {
@@ -4511,6 +4519,7 @@ Object.defineProperty(MaxKey.prototype, '_bsontype', { value: 'MaxKey' });
4511
4519
  /**
4512
4520
  * A class representation of the BSON MinKey type.
4513
4521
  * @public
4522
+ * @category BSONType
4514
4523
  */
4515
4524
  var MinKey = /** @class */ (function () {
4516
4525
  function MinKey() {
@@ -4544,6 +4553,7 @@ var kId = Symbol('id');
4544
4553
  /**
4545
4554
  * A class representation of the BSON ObjectId type.
4546
4555
  * @public
4556
+ * @category BSONType
4547
4557
  */
4548
4558
  var ObjectId = /** @class */ (function () {
4549
4559
  /**
@@ -4577,7 +4587,8 @@ var ObjectId = /** @class */ (function () {
4577
4587
  this[kId] = ObjectId.generate(typeof workingId === 'number' ? workingId : undefined);
4578
4588
  }
4579
4589
  else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
4580
- this[kId] = ensureBuffer(workingId);
4590
+ // If intstanceof matches we can escape calling ensure buffer in Node.js environments
4591
+ this[kId] = workingId instanceof buffer_1 ? workingId : ensureBuffer(workingId);
4581
4592
  }
4582
4593
  else if (typeof workingId === 'string') {
4583
4594
  if (workingId.length === 12) {
@@ -4804,7 +4815,7 @@ var ObjectId = /** @class */ (function () {
4804
4815
  return this.inspect();
4805
4816
  };
4806
4817
  ObjectId.prototype.inspect = function () {
4807
- return "new ObjectId(\"" + this.toHexString() + "\")";
4818
+ return "new ObjectId(\"".concat(this.toHexString(), "\")");
4808
4819
  };
4809
4820
  /** @internal */
4810
4821
  ObjectId.index = Math.floor(Math.random() * 0xffffff);
@@ -4831,6 +4842,7 @@ function alphabetize(str) {
4831
4842
  /**
4832
4843
  * A class representation of the BSON RegExp type.
4833
4844
  * @public
4845
+ * @category BSONType
4834
4846
  */
4835
4847
  var BSONRegExp = /** @class */ (function () {
4836
4848
  /**
@@ -4843,10 +4855,10 @@ var BSONRegExp = /** @class */ (function () {
4843
4855
  this.pattern = pattern;
4844
4856
  this.options = alphabetize(options !== null && options !== void 0 ? options : '');
4845
4857
  if (this.pattern.indexOf('\x00') !== -1) {
4846
- 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)));
4847
4859
  }
4848
4860
  if (this.options.indexOf('\x00') !== -1) {
4849
- 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)));
4850
4862
  }
4851
4863
  // Validate options
4852
4864
  for (var i = 0; i < this.options.length; i++) {
@@ -4856,7 +4868,7 @@ var BSONRegExp = /** @class */ (function () {
4856
4868
  this.options[i] === 'l' ||
4857
4869
  this.options[i] === 's' ||
4858
4870
  this.options[i] === 'u')) {
4859
- 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"));
4860
4872
  }
4861
4873
  }
4862
4874
  }
@@ -4887,7 +4899,7 @@ var BSONRegExp = /** @class */ (function () {
4887
4899
  if ('$regularExpression' in doc) {
4888
4900
  return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
4889
4901
  }
4890
- throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: " + JSON.stringify(doc));
4902
+ throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(doc)));
4891
4903
  };
4892
4904
  return BSONRegExp;
4893
4905
  }());
@@ -4896,6 +4908,7 @@ Object.defineProperty(BSONRegExp.prototype, '_bsontype', { value: 'BSONRegExp' }
4896
4908
  /**
4897
4909
  * A class representation of the BSON Symbol type.
4898
4910
  * @public
4911
+ * @category BSONType
4899
4912
  */
4900
4913
  var BSONSymbol = /** @class */ (function () {
4901
4914
  /**
@@ -4915,7 +4928,7 @@ var BSONSymbol = /** @class */ (function () {
4915
4928
  };
4916
4929
  /** @internal */
4917
4930
  BSONSymbol.prototype.inspect = function () {
4918
- return "new BSONSymbol(\"" + this.value + "\")";
4931
+ return "new BSONSymbol(\"".concat(this.value, "\")");
4919
4932
  };
4920
4933
  BSONSymbol.prototype.toJSON = function () {
4921
4934
  return this.value;
@@ -4938,13 +4951,16 @@ Object.defineProperty(BSONSymbol.prototype, '_bsontype', { value: 'Symbol' });
4938
4951
 
4939
4952
  /** @public */
4940
4953
  var LongWithoutOverridesClass = Long;
4941
- /** @public */
4954
+ /**
4955
+ * @public
4956
+ * @category BSONType
4957
+ * */
4942
4958
  var Timestamp = /** @class */ (function (_super) {
4943
4959
  __extends(Timestamp, _super);
4944
4960
  function Timestamp(low, high) {
4945
4961
  var _this = this;
4946
4962
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4947
- ///@ts-expect-error
4963
+ // @ts-expect-error
4948
4964
  if (!(_this instanceof Timestamp))
4949
4965
  return new Timestamp(low, high);
4950
4966
  if (Long.isLong(low)) {
@@ -5008,7 +5024,7 @@ var Timestamp = /** @class */ (function (_super) {
5008
5024
  return this.inspect();
5009
5025
  };
5010
5026
  Timestamp.prototype.inspect = function () {
5011
- return "new Timestamp({ t: " + this.getHighBits() + ", i: " + this.getLowBits() + " })";
5027
+ return "new Timestamp({ t: ".concat(this.getHighBits(), ", i: ").concat(this.getLowBits(), " })");
5012
5028
  };
5013
5029
  Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
5014
5030
  return Timestamp;
@@ -5021,7 +5037,8 @@ function isBSONType(value) {
5021
5037
  var BSON_INT32_MAX$1 = 0x7fffffff;
5022
5038
  var BSON_INT32_MIN$1 = -0x80000000;
5023
5039
  // INT64 boundaries
5024
- 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;
5025
5042
  var BSON_INT64_MIN$1 = -0x8000000000000000;
5026
5043
  // all the types where we don't need to do any special processing and can just pass the EJSON
5027
5044
  //straight to type.fromExtendedJSON
@@ -5117,7 +5134,7 @@ function deserializeValue(value, options) {
5117
5134
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5118
5135
  function serializeArray(array, options) {
5119
5136
  return array.map(function (v, index) {
5120
- options.seenObjects.push({ propertyName: "index " + index, obj: null });
5137
+ options.seenObjects.push({ propertyName: "index ".concat(index), obj: null });
5121
5138
  try {
5122
5139
  return serializeValue(v, options);
5123
5140
  }
@@ -5139,20 +5156,20 @@ function serializeValue(value, options) {
5139
5156
  var props = options.seenObjects.map(function (entry) { return entry.propertyName; });
5140
5157
  var leadingPart = props
5141
5158
  .slice(0, index)
5142
- .map(function (prop) { return prop + " -> "; })
5159
+ .map(function (prop) { return "".concat(prop, " -> "); })
5143
5160
  .join('');
5144
5161
  var alreadySeen = props[index];
5145
5162
  var circularPart = ' -> ' +
5146
5163
  props
5147
5164
  .slice(index + 1, props.length - 1)
5148
- .map(function (prop) { return prop + " -> "; })
5165
+ .map(function (prop) { return "".concat(prop, " -> "); })
5149
5166
  .join('');
5150
5167
  var current = props[props.length - 1];
5151
5168
  var leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
5152
5169
  var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
5153
5170
  throw new BSONTypeError('Converting circular structure to EJSON:\n' +
5154
- (" " + leadingPart + alreadySeen + circularPart + current + "\n") +
5155
- (" " + leadingSpace + "\\" + dashes + "/"));
5171
+ " ".concat(leadingPart).concat(alreadySeen).concat(circularPart).concat(current, "\n") +
5172
+ " ".concat(leadingSpace, "\\").concat(dashes, "/"));
5156
5173
  }
5157
5174
  options.seenObjects[options.seenObjects.length - 1].obj = value;
5158
5175
  }
@@ -5231,7 +5248,18 @@ function serializeDocument(doc, options) {
5231
5248
  for (var name in doc) {
5232
5249
  options.seenObjects.push({ propertyName: name, obj: null });
5233
5250
  try {
5234
- _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
+ }
5235
5263
  }
5236
5264
  finally {
5237
5265
  options.seenObjects.pop();
@@ -5301,7 +5329,7 @@ var EJSON;
5301
5329
  finalOptions.relaxed = !finalOptions.strict;
5302
5330
  return JSON.parse(text, function (key, value) {
5303
5331
  if (key.indexOf('\x00') !== -1) {
5304
- 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)));
5305
5333
  }
5306
5334
  return deserializeValue(value, finalOptions);
5307
5335
  });
@@ -5667,13 +5695,14 @@ value, serializeFunctions, isArray, ignoreUndefined) {
5667
5695
  }
5668
5696
  }
5669
5697
  else if (value['_bsontype'] === 'Binary') {
5698
+ var binary = value;
5670
5699
  // Check what kind of subtype we have
5671
- if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5700
+ if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5672
5701
  return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
5673
- (value.position + 1 + 4 + 1 + 4));
5702
+ (binary.position + 1 + 4 + 1 + 4));
5674
5703
  }
5675
5704
  else {
5676
- 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));
5677
5706
  }
5678
5707
  }
5679
5708
  else if (value['_bsontype'] === 'Symbol') {
@@ -5810,16 +5839,16 @@ function deserialize$1(buffer, options, isArray) {
5810
5839
  (buffer[index + 2] << 16) |
5811
5840
  (buffer[index + 3] << 24);
5812
5841
  if (size < 5) {
5813
- throw new BSONError("bson size must be >= 5, is " + size);
5842
+ throw new BSONError("bson size must be >= 5, is ".concat(size));
5814
5843
  }
5815
5844
  if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
5816
- 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));
5817
5846
  }
5818
5847
  if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
5819
- 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));
5820
5849
  }
5821
5850
  if (size + index > buffer.byteLength) {
5822
- 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, ")"));
5823
5852
  }
5824
5853
  // Illegal end value
5825
5854
  if (buffer[index + size - 1] !== 0) {
@@ -5896,6 +5925,7 @@ function deserializeObject(buffer, index, options, isArray) {
5896
5925
  var done = false;
5897
5926
  var isPossibleDBRef = isArray ? false : null;
5898
5927
  // While we have more left data left keep parsing
5928
+ var dataview = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
5899
5929
  while (!done) {
5900
5930
  // Read the type
5901
5931
  var elementType = buffer[index++];
@@ -5956,11 +5986,11 @@ function deserializeObject(buffer, index, options, isArray) {
5956
5986
  (buffer[index++] << 24);
5957
5987
  }
5958
5988
  else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
5959
- value = new Double(buffer.readDoubleLE(index));
5989
+ value = new Double(dataview.getFloat64(index, true));
5960
5990
  index = index + 8;
5961
5991
  }
5962
5992
  else if (elementType === BSON_DATA_NUMBER) {
5963
- value = buffer.readDoubleLE(index);
5993
+ value = dataview.getFloat64(index, true);
5964
5994
  index = index + 8;
5965
5995
  }
5966
5996
  else if (elementType === BSON_DATA_DATE) {
@@ -6358,7 +6388,7 @@ function deserializeObject(buffer, index, options, isArray) {
6358
6388
  value = new DBRef(namespace, oid);
6359
6389
  }
6360
6390
  else {
6361
- 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, "\""));
6362
6392
  }
6363
6393
  if (name === '__proto__') {
6364
6394
  Object.defineProperty(object, name, {
@@ -6396,10 +6426,12 @@ function deserializeObject(buffer, index, options, isArray) {
6396
6426
  * @internal
6397
6427
  */
6398
6428
  function isolateEval(functionString, functionCache, object) {
6429
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
6399
6430
  if (!functionCache)
6400
6431
  return new Function(functionString);
6401
6432
  // Check for cache hit, eval if missing and return cached function
6402
6433
  if (functionCache[functionString] == null) {
6434
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
6403
6435
  functionCache[functionString] = new Function(functionString);
6404
6436
  }
6405
6437
  // Set the object
@@ -6421,74 +6453,6 @@ function getValidatedString(buffer, start, end, shouldValidateUtf8) {
6421
6453
  return value;
6422
6454
  }
6423
6455
 
6424
- // Copyright (c) 2008, Fair Oaks Labs, Inc.
6425
- function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
6426
- var e;
6427
- var m;
6428
- var c;
6429
- var bBE = endian === 'big';
6430
- var eLen = nBytes * 8 - mLen - 1;
6431
- var eMax = (1 << eLen) - 1;
6432
- var eBias = eMax >> 1;
6433
- var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
6434
- var i = bBE ? nBytes - 1 : 0;
6435
- var d = bBE ? -1 : 1;
6436
- var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
6437
- value = Math.abs(value);
6438
- if (isNaN(value) || value === Infinity) {
6439
- m = isNaN(value) ? 1 : 0;
6440
- e = eMax;
6441
- }
6442
- else {
6443
- e = Math.floor(Math.log(value) / Math.LN2);
6444
- if (value * (c = Math.pow(2, -e)) < 1) {
6445
- e--;
6446
- c *= 2;
6447
- }
6448
- if (e + eBias >= 1) {
6449
- value += rt / c;
6450
- }
6451
- else {
6452
- value += rt * Math.pow(2, 1 - eBias);
6453
- }
6454
- if (value * c >= 2) {
6455
- e++;
6456
- c /= 2;
6457
- }
6458
- if (e + eBias >= eMax) {
6459
- m = 0;
6460
- e = eMax;
6461
- }
6462
- else if (e + eBias >= 1) {
6463
- m = (value * c - 1) * Math.pow(2, mLen);
6464
- e = e + eBias;
6465
- }
6466
- else {
6467
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
6468
- e = 0;
6469
- }
6470
- }
6471
- if (isNaN(value))
6472
- m = 0;
6473
- while (mLen >= 8) {
6474
- buffer[offset + i] = m & 0xff;
6475
- i += d;
6476
- m /= 256;
6477
- mLen -= 8;
6478
- }
6479
- e = (e << mLen) | m;
6480
- if (isNaN(value))
6481
- e += 8;
6482
- eLen += mLen;
6483
- while (eLen > 0) {
6484
- buffer[offset + i] = e & 0xff;
6485
- i += d;
6486
- e /= 256;
6487
- eLen -= 8;
6488
- }
6489
- buffer[offset + i - d] |= s * 128;
6490
- }
6491
-
6492
6456
  var regexp = /\x00/; // eslint-disable-line no-control-regex
6493
6457
  var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
6494
6458
  /*
@@ -6519,6 +6483,8 @@ function serializeString(buffer, key, value, index, isArray) {
6519
6483
  buffer[index++] = 0;
6520
6484
  return index;
6521
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);
6522
6488
  function serializeNumber(buffer, key, value, index, isArray) {
6523
6489
  // We have an integer value
6524
6490
  // TODO(NODE-2529): Add support for big int
@@ -6552,7 +6518,8 @@ function serializeNumber(buffer, key, value, index, isArray) {
6552
6518
  index = index + numberOfWrittenBytes;
6553
6519
  buffer[index++] = 0;
6554
6520
  // Write float
6555
- writeIEEE754(buffer, value, index, 'little', 52, 8);
6521
+ DV_FOR_FLOAT64.setFloat64(0, value, true);
6522
+ buffer.set(SPACE_FOR_FLOAT64, index);
6556
6523
  // Adjust index
6557
6524
  index = index + 8;
6558
6525
  }
@@ -6831,7 +6798,8 @@ function serializeDouble(buffer, key, value, index, isArray) {
6831
6798
  index = index + numberOfWrittenBytes;
6832
6799
  buffer[index++] = 0;
6833
6800
  // Write float
6834
- writeIEEE754(buffer, value.value, index, 'little', 52, 8);
6801
+ DV_FOR_FLOAT64.setFloat64(0, value.value, true);
6802
+ buffer.set(SPACE_FOR_FLOAT64, index);
6835
6803
  // Adjust index
6836
6804
  index = index + 8;
6837
6805
  return index;
@@ -7041,7 +7009,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7041
7009
  if (Array.isArray(object)) {
7042
7010
  // Get object keys
7043
7011
  for (var i = 0; i < object.length; i++) {
7044
- var key = '' + i;
7012
+ var key = "".concat(i);
7045
7013
  var value = object[i];
7046
7014
  // Is there an override value
7047
7015
  if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
@@ -7116,7 +7084,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7116
7084
  index = serializeMinMax(buffer, key, value, index, true);
7117
7085
  }
7118
7086
  else if (typeof value['_bsontype'] !== 'undefined') {
7119
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7087
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7120
7088
  }
7121
7089
  }
7122
7090
  }
@@ -7215,7 +7183,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7215
7183
  index = serializeMinMax(buffer, key, value, index);
7216
7184
  }
7217
7185
  else if (typeof value['_bsontype'] !== 'undefined') {
7218
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7186
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7219
7187
  }
7220
7188
  }
7221
7189
  }
@@ -7320,7 +7288,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7320
7288
  index = serializeMinMax(buffer, key, value, index);
7321
7289
  }
7322
7290
  else if (typeof value['_bsontype'] !== 'undefined') {
7323
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7291
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7324
7292
  }
7325
7293
  }
7326
7294
  }