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
package/dist/bson.esm.js CHANGED
@@ -97,11 +97,11 @@ function checkForMath(potentialGlobal) {
97
97
  }
98
98
  // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
99
99
  function getGlobal() {
100
- // eslint-disable-next-line no-undef
101
100
  return (checkForMath(typeof globalThis === 'object' && globalThis) ||
102
101
  checkForMath(typeof window === 'object' && window) ||
103
102
  checkForMath(typeof self === 'object' && self) ||
104
103
  checkForMath(typeof global === 'object' && global) ||
104
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
105
105
  Function('return this')());
106
106
  }
107
107
 
@@ -127,27 +127,17 @@ var insecureRandomBytes = function insecureRandomBytes(size) {
127
127
  return result;
128
128
  };
129
129
  var detectRandomBytes = function () {
130
- if (typeof window !== 'undefined') {
131
- // browser crypto implementation(s)
132
- var target_1 = window.crypto || window.msCrypto; // allow for IE11
133
- if (target_1 && target_1.getRandomValues) {
134
- return function (size) { return target_1.getRandomValues(Buffer.alloc(size)); };
130
+ {
131
+ var requiredRandomBytes = void 0;
132
+ try {
133
+ requiredRandomBytes = require('crypto').randomBytes;
135
134
  }
135
+ catch (e) {
136
+ // keep the fallback
137
+ }
138
+ // NOTE: in transpiled cases the above require might return null/undefined
139
+ return requiredRandomBytes || insecureRandomBytes;
136
140
  }
137
- if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
138
- // allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
139
- return function (size) { return global.crypto.getRandomValues(Buffer.alloc(size)); };
140
- }
141
- var requiredRandomBytes;
142
- try {
143
- // eslint-disable-next-line @typescript-eslint/no-var-requires
144
- requiredRandomBytes = require('crypto').randomBytes;
145
- }
146
- catch (e) {
147
- // keep the fallback
148
- }
149
- // NOTE: in transpiled cases the above require might return null/undefined
150
- return requiredRandomBytes || insecureRandomBytes;
151
141
  };
152
142
  var randomBytes = detectRandomBytes();
153
143
  function isAnyArrayBuffer(value) {
@@ -404,7 +394,7 @@ var UUID = /** @class */ (function () {
404
394
  return this.inspect();
405
395
  };
406
396
  UUID.prototype.inspect = function () {
407
- return "new UUID(\"" + this.toHexString() + "\")";
397
+ return "new UUID(\"".concat(this.toHexString(), "\")");
408
398
  };
409
399
  return UUID;
410
400
  }());
@@ -413,9 +403,17 @@ Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
413
403
  /**
414
404
  * A class representation of the BSON Binary type.
415
405
  * @public
406
+ * @category BSONType
416
407
  */
417
408
  var Binary = /** @class */ (function () {
418
409
  /**
410
+ * Create a new Binary instance.
411
+ *
412
+ * This constructor can accept a string as its first argument. In this case,
413
+ * this string will be encoded using ISO-8859-1, **not** using UTF-8.
414
+ * This is almost certainly not what you want. Use `new Binary(Buffer.from(string))`
415
+ * instead to convert the string to a Buffer using UTF-8 first.
416
+ *
419
417
  * @param buffer - a buffer object containing the binary data.
420
418
  * @param subType - the option binary type.
421
419
  */
@@ -575,7 +573,7 @@ var Binary = /** @class */ (function () {
575
573
  if (this.sub_type === Binary.SUBTYPE_UUID) {
576
574
  return new UUID(this.buffer.slice(0, this.position));
577
575
  }
578
- throw new BSONError("Binary sub_type \"" + this.sub_type + "\" is not supported for converting to UUID. Only \"" + Binary.SUBTYPE_UUID + "\" is currently supported.");
576
+ throw new BSONError("Binary sub_type \"".concat(this.sub_type, "\" is not supported for converting to UUID. Only \"").concat(Binary.SUBTYPE_UUID, "\" is currently supported."));
579
577
  };
580
578
  /** @internal */
581
579
  Binary.fromExtendedJSON = function (doc, options) {
@@ -599,7 +597,7 @@ var Binary = /** @class */ (function () {
599
597
  data = uuidHexStringToBuffer(doc.$uuid);
600
598
  }
601
599
  if (!data) {
602
- throw new BSONTypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc));
600
+ throw new BSONTypeError("Unexpected Binary Extended JSON format ".concat(JSON.stringify(doc)));
603
601
  }
604
602
  return new Binary(data, type);
605
603
  };
@@ -609,7 +607,7 @@ var Binary = /** @class */ (function () {
609
607
  };
610
608
  Binary.prototype.inspect = function () {
611
609
  var asBuffer = this.value(true);
612
- return "new Binary(Buffer.from(\"" + asBuffer.toString('hex') + "\", \"hex\"), " + this.sub_type + ")";
610
+ return "new Binary(Buffer.from(\"".concat(asBuffer.toString('hex'), "\", \"hex\"), ").concat(this.sub_type, ")");
613
611
  };
614
612
  /**
615
613
  * Binary default subtype
@@ -643,6 +641,7 @@ Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' });
643
641
  /**
644
642
  * A class representation of the BSON Code type.
645
643
  * @public
644
+ * @category BSONType
646
645
  */
647
646
  var Code = /** @class */ (function () {
648
647
  /**
@@ -675,7 +674,7 @@ var Code = /** @class */ (function () {
675
674
  };
676
675
  Code.prototype.inspect = function () {
677
676
  var codeJson = this.toJSON();
678
- return "new Code(\"" + codeJson.code + "\"" + (codeJson.scope ? ", " + JSON.stringify(codeJson.scope) : '') + ")";
677
+ return "new Code(\"".concat(String(codeJson.code), "\"").concat(codeJson.scope ? ", ".concat(JSON.stringify(codeJson.scope)) : '', ")");
679
678
  };
680
679
  return Code;
681
680
  }());
@@ -691,6 +690,7 @@ function isDBRefLike(value) {
691
690
  /**
692
691
  * A class representation of the BSON DBRef type.
693
692
  * @public
693
+ * @category BSONType
694
694
  */
695
695
  var DBRef = /** @class */ (function () {
696
696
  /**
@@ -765,7 +765,7 @@ var DBRef = /** @class */ (function () {
765
765
  DBRef.prototype.inspect = function () {
766
766
  // NOTE: if OID is an ObjectId class it will just print the oid string.
767
767
  var oid = this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString();
768
- return "new DBRef(\"" + this.namespace + "\", new ObjectId(\"" + oid + "\")" + (this.db ? ", \"" + this.db + "\"" : '') + ")";
768
+ return "new DBRef(\"".concat(this.namespace, "\", new ObjectId(\"").concat(String(oid), "\")").concat(this.db ? ", \"".concat(this.db, "\"") : '', ")");
769
769
  };
770
770
  return DBRef;
771
771
  }());
@@ -795,6 +795,7 @@ var UINT_CACHE = {};
795
795
  /**
796
796
  * A class representing a 64-bit integer
797
797
  * @public
798
+ * @category BSONType
798
799
  * @remarks
799
800
  * The internal representation of a long is the two given signed, 32-bit values.
800
801
  * We use 32-bit pieces because these are the size of integers on which
@@ -1001,7 +1002,6 @@ var Long = /** @class */ (function () {
1001
1002
  /**
1002
1003
  * Tests if the specified object is a Long.
1003
1004
  */
1004
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1005
1005
  Long.isLong = function (value) {
1006
1006
  return isObjectLike(value) && value['__isLong__'] === true;
1007
1007
  };
@@ -1158,6 +1158,7 @@ var Long = /** @class */ (function () {
1158
1158
  // into the result, and subtract it from the remainder. It is critical that
1159
1159
  // the approximate value is less than or equal to the real value so that the
1160
1160
  // remainder never becomes negative.
1161
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
1161
1162
  rem = this;
1162
1163
  while (rem.gte(divisor)) {
1163
1164
  // Approximate the result of division. This may be a little greater or
@@ -1641,7 +1642,7 @@ var Long = /** @class */ (function () {
1641
1642
  return this.inspect();
1642
1643
  };
1643
1644
  Long.prototype.inspect = function () {
1644
- return "new Long(\"" + this.toString() + "\"" + (this.unsigned ? ', true' : '') + ")";
1645
+ return "new Long(\"".concat(this.toString(), "\"").concat(this.unsigned ? ', true' : '', ")");
1645
1646
  };
1646
1647
  Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
1647
1648
  /** Maximum unsigned value. */
@@ -1752,11 +1753,12 @@ function lessThan(left, right) {
1752
1753
  return false;
1753
1754
  }
1754
1755
  function invalidErr(string, message) {
1755
- throw new BSONTypeError("\"" + string + "\" is not a valid Decimal128 string - " + message);
1756
+ throw new BSONTypeError("\"".concat(string, "\" is not a valid Decimal128 string - ").concat(message));
1756
1757
  }
1757
1758
  /**
1758
1759
  * A class representation of the BSON Decimal128 type.
1759
1760
  * @public
1761
+ * @category BSONType
1760
1762
  */
1761
1763
  var Decimal128 = /** @class */ (function () {
1762
1764
  /**
@@ -2249,35 +2251,35 @@ var Decimal128 = /** @class */ (function () {
2249
2251
  // as + or - 0 and using the non-scientific exponent (this is for the "invalid
2250
2252
  // representation should be treated as 0/-0" spec cases in decimal128-1.json)
2251
2253
  if (significand_digits > 34) {
2252
- string.push("" + 0);
2254
+ string.push("".concat(0));
2253
2255
  if (exponent > 0)
2254
- string.push('E+' + exponent);
2256
+ string.push("E+".concat(exponent));
2255
2257
  else if (exponent < 0)
2256
- string.push('E' + exponent);
2258
+ string.push("E".concat(exponent));
2257
2259
  return string.join('');
2258
2260
  }
2259
- string.push("" + significand[index++]);
2261
+ string.push("".concat(significand[index++]));
2260
2262
  significand_digits = significand_digits - 1;
2261
2263
  if (significand_digits) {
2262
2264
  string.push('.');
2263
2265
  }
2264
2266
  for (var i = 0; i < significand_digits; i++) {
2265
- string.push("" + significand[index++]);
2267
+ string.push("".concat(significand[index++]));
2266
2268
  }
2267
2269
  // Exponent
2268
2270
  string.push('E');
2269
2271
  if (scientific_exponent > 0) {
2270
- string.push('+' + scientific_exponent);
2272
+ string.push("+".concat(scientific_exponent));
2271
2273
  }
2272
2274
  else {
2273
- string.push("" + scientific_exponent);
2275
+ string.push("".concat(scientific_exponent));
2274
2276
  }
2275
2277
  }
2276
2278
  else {
2277
2279
  // Regular format with no decimal place
2278
2280
  if (exponent >= 0) {
2279
2281
  for (var i = 0; i < significand_digits; i++) {
2280
- string.push("" + significand[index++]);
2282
+ string.push("".concat(significand[index++]));
2281
2283
  }
2282
2284
  }
2283
2285
  else {
@@ -2285,7 +2287,7 @@ var Decimal128 = /** @class */ (function () {
2285
2287
  // non-zero digits before radix
2286
2288
  if (radix_position > 0) {
2287
2289
  for (var i = 0; i < radix_position; i++) {
2288
- string.push("" + significand[index++]);
2290
+ string.push("".concat(significand[index++]));
2289
2291
  }
2290
2292
  }
2291
2293
  else {
@@ -2297,7 +2299,7 @@ var Decimal128 = /** @class */ (function () {
2297
2299
  string.push('0');
2298
2300
  }
2299
2301
  for (var i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
2300
- string.push("" + significand[index++]);
2302
+ string.push("".concat(significand[index++]));
2301
2303
  }
2302
2304
  }
2303
2305
  }
@@ -2319,7 +2321,7 @@ var Decimal128 = /** @class */ (function () {
2319
2321
  return this.inspect();
2320
2322
  };
2321
2323
  Decimal128.prototype.inspect = function () {
2322
- return "new Decimal128(\"" + this.toString() + "\")";
2324
+ return "new Decimal128(\"".concat(this.toString(), "\")");
2323
2325
  };
2324
2326
  return Decimal128;
2325
2327
  }());
@@ -2328,6 +2330,7 @@ Object.defineProperty(Decimal128.prototype, '_bsontype', { value: 'Decimal128' }
2328
2330
  /**
2329
2331
  * A class representation of the BSON Double type.
2330
2332
  * @public
2333
+ * @category BSONType
2331
2334
  */
2332
2335
  var Double = /** @class */ (function () {
2333
2336
  /**
@@ -2365,7 +2368,7 @@ var Double = /** @class */ (function () {
2365
2368
  // NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
2366
2369
  // explicitly provided `-0` then we need to ensure the sign makes it into the output
2367
2370
  if (Object.is(Math.sign(this.value), -0)) {
2368
- return { $numberDouble: "-" + this.value.toFixed(1) };
2371
+ return { $numberDouble: "-".concat(this.value.toFixed(1)) };
2369
2372
  }
2370
2373
  var $numberDouble;
2371
2374
  if (Number.isInteger(this.value)) {
@@ -2390,7 +2393,7 @@ var Double = /** @class */ (function () {
2390
2393
  };
2391
2394
  Double.prototype.inspect = function () {
2392
2395
  var eJSON = this.toExtendedJSON();
2393
- return "new Double(" + eJSON.$numberDouble + ")";
2396
+ return "new Double(".concat(eJSON.$numberDouble, ")");
2394
2397
  };
2395
2398
  return Double;
2396
2399
  }());
@@ -2399,6 +2402,7 @@ Object.defineProperty(Double.prototype, '_bsontype', { value: 'Double' });
2399
2402
  /**
2400
2403
  * A class representation of a BSON Int32 type.
2401
2404
  * @public
2405
+ * @category BSONType
2402
2406
  */
2403
2407
  var Int32 = /** @class */ (function () {
2404
2408
  /**
@@ -2443,7 +2447,7 @@ var Int32 = /** @class */ (function () {
2443
2447
  return this.inspect();
2444
2448
  };
2445
2449
  Int32.prototype.inspect = function () {
2446
- return "new Int32(" + this.valueOf() + ")";
2450
+ return "new Int32(".concat(this.valueOf(), ")");
2447
2451
  };
2448
2452
  return Int32;
2449
2453
  }());
@@ -2452,6 +2456,7 @@ Object.defineProperty(Int32.prototype, '_bsontype', { value: 'Int32' });
2452
2456
  /**
2453
2457
  * A class representation of the BSON MaxKey type.
2454
2458
  * @public
2459
+ * @category BSONType
2455
2460
  */
2456
2461
  var MaxKey = /** @class */ (function () {
2457
2462
  function MaxKey() {
@@ -2480,6 +2485,7 @@ Object.defineProperty(MaxKey.prototype, '_bsontype', { value: 'MaxKey' });
2480
2485
  /**
2481
2486
  * A class representation of the BSON MinKey type.
2482
2487
  * @public
2488
+ * @category BSONType
2483
2489
  */
2484
2490
  var MinKey = /** @class */ (function () {
2485
2491
  function MinKey() {
@@ -2513,6 +2519,7 @@ var kId = Symbol('id');
2513
2519
  /**
2514
2520
  * A class representation of the BSON ObjectId type.
2515
2521
  * @public
2522
+ * @category BSONType
2516
2523
  */
2517
2524
  var ObjectId = /** @class */ (function () {
2518
2525
  /**
@@ -2546,7 +2553,8 @@ var ObjectId = /** @class */ (function () {
2546
2553
  this[kId] = ObjectId.generate(typeof workingId === 'number' ? workingId : undefined);
2547
2554
  }
2548
2555
  else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
2549
- this[kId] = ensureBuffer(workingId);
2556
+ // If intstanceof matches we can escape calling ensure buffer in Node.js environments
2557
+ this[kId] = workingId instanceof Buffer ? workingId : ensureBuffer(workingId);
2550
2558
  }
2551
2559
  else if (typeof workingId === 'string') {
2552
2560
  if (workingId.length === 12) {
@@ -2773,7 +2781,7 @@ var ObjectId = /** @class */ (function () {
2773
2781
  return this.inspect();
2774
2782
  };
2775
2783
  ObjectId.prototype.inspect = function () {
2776
- return "new ObjectId(\"" + this.toHexString() + "\")";
2784
+ return "new ObjectId(\"".concat(this.toHexString(), "\")");
2777
2785
  };
2778
2786
  /** @internal */
2779
2787
  ObjectId.index = Math.floor(Math.random() * 0xffffff);
@@ -2800,6 +2808,7 @@ function alphabetize(str) {
2800
2808
  /**
2801
2809
  * A class representation of the BSON RegExp type.
2802
2810
  * @public
2811
+ * @category BSONType
2803
2812
  */
2804
2813
  var BSONRegExp = /** @class */ (function () {
2805
2814
  /**
@@ -2812,10 +2821,10 @@ var BSONRegExp = /** @class */ (function () {
2812
2821
  this.pattern = pattern;
2813
2822
  this.options = alphabetize(options !== null && options !== void 0 ? options : '');
2814
2823
  if (this.pattern.indexOf('\x00') !== -1) {
2815
- throw new BSONError("BSON Regex patterns cannot contain null bytes, found: " + JSON.stringify(this.pattern));
2824
+ throw new BSONError("BSON Regex patterns cannot contain null bytes, found: ".concat(JSON.stringify(this.pattern)));
2816
2825
  }
2817
2826
  if (this.options.indexOf('\x00') !== -1) {
2818
- throw new BSONError("BSON Regex options cannot contain null bytes, found: " + JSON.stringify(this.options));
2827
+ throw new BSONError("BSON Regex options cannot contain null bytes, found: ".concat(JSON.stringify(this.options)));
2819
2828
  }
2820
2829
  // Validate options
2821
2830
  for (var i = 0; i < this.options.length; i++) {
@@ -2825,7 +2834,7 @@ var BSONRegExp = /** @class */ (function () {
2825
2834
  this.options[i] === 'l' ||
2826
2835
  this.options[i] === 's' ||
2827
2836
  this.options[i] === 'u')) {
2828
- throw new BSONError("The regular expression option [" + this.options[i] + "] is not supported");
2837
+ throw new BSONError("The regular expression option [".concat(this.options[i], "] is not supported"));
2829
2838
  }
2830
2839
  }
2831
2840
  }
@@ -2856,7 +2865,7 @@ var BSONRegExp = /** @class */ (function () {
2856
2865
  if ('$regularExpression' in doc) {
2857
2866
  return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
2858
2867
  }
2859
- throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: " + JSON.stringify(doc));
2868
+ throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(doc)));
2860
2869
  };
2861
2870
  return BSONRegExp;
2862
2871
  }());
@@ -2865,6 +2874,7 @@ Object.defineProperty(BSONRegExp.prototype, '_bsontype', { value: 'BSONRegExp' }
2865
2874
  /**
2866
2875
  * A class representation of the BSON Symbol type.
2867
2876
  * @public
2877
+ * @category BSONType
2868
2878
  */
2869
2879
  var BSONSymbol = /** @class */ (function () {
2870
2880
  /**
@@ -2884,7 +2894,7 @@ var BSONSymbol = /** @class */ (function () {
2884
2894
  };
2885
2895
  /** @internal */
2886
2896
  BSONSymbol.prototype.inspect = function () {
2887
- return "new BSONSymbol(\"" + this.value + "\")";
2897
+ return "new BSONSymbol(\"".concat(this.value, "\")");
2888
2898
  };
2889
2899
  BSONSymbol.prototype.toJSON = function () {
2890
2900
  return this.value;
@@ -2907,13 +2917,16 @@ Object.defineProperty(BSONSymbol.prototype, '_bsontype', { value: 'Symbol' });
2907
2917
 
2908
2918
  /** @public */
2909
2919
  var LongWithoutOverridesClass = Long;
2910
- /** @public */
2920
+ /**
2921
+ * @public
2922
+ * @category BSONType
2923
+ * */
2911
2924
  var Timestamp = /** @class */ (function (_super) {
2912
2925
  __extends(Timestamp, _super);
2913
2926
  function Timestamp(low, high) {
2914
2927
  var _this = this;
2915
2928
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2916
- ///@ts-expect-error
2929
+ // @ts-expect-error
2917
2930
  if (!(_this instanceof Timestamp))
2918
2931
  return new Timestamp(low, high);
2919
2932
  if (Long.isLong(low)) {
@@ -2977,7 +2990,7 @@ var Timestamp = /** @class */ (function (_super) {
2977
2990
  return this.inspect();
2978
2991
  };
2979
2992
  Timestamp.prototype.inspect = function () {
2980
- return "new Timestamp({ t: " + this.getHighBits() + ", i: " + this.getLowBits() + " })";
2993
+ return "new Timestamp({ t: ".concat(this.getHighBits(), ", i: ").concat(this.getLowBits(), " })");
2981
2994
  };
2982
2995
  Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
2983
2996
  return Timestamp;
@@ -2990,7 +3003,8 @@ function isBSONType(value) {
2990
3003
  var BSON_INT32_MAX$1 = 0x7fffffff;
2991
3004
  var BSON_INT32_MIN$1 = -0x80000000;
2992
3005
  // INT64 boundaries
2993
- var BSON_INT64_MAX$1 = 0x7fffffffffffffff;
3006
+ // const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
3007
+ var BSON_INT64_MAX$1 = 0x8000000000000000;
2994
3008
  var BSON_INT64_MIN$1 = -0x8000000000000000;
2995
3009
  // all the types where we don't need to do any special processing and can just pass the EJSON
2996
3010
  //straight to type.fromExtendedJSON
@@ -3086,7 +3100,7 @@ function deserializeValue(value, options) {
3086
3100
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3087
3101
  function serializeArray(array, options) {
3088
3102
  return array.map(function (v, index) {
3089
- options.seenObjects.push({ propertyName: "index " + index, obj: null });
3103
+ options.seenObjects.push({ propertyName: "index ".concat(index), obj: null });
3090
3104
  try {
3091
3105
  return serializeValue(v, options);
3092
3106
  }
@@ -3108,20 +3122,20 @@ function serializeValue(value, options) {
3108
3122
  var props = options.seenObjects.map(function (entry) { return entry.propertyName; });
3109
3123
  var leadingPart = props
3110
3124
  .slice(0, index)
3111
- .map(function (prop) { return prop + " -> "; })
3125
+ .map(function (prop) { return "".concat(prop, " -> "); })
3112
3126
  .join('');
3113
3127
  var alreadySeen = props[index];
3114
3128
  var circularPart = ' -> ' +
3115
3129
  props
3116
3130
  .slice(index + 1, props.length - 1)
3117
- .map(function (prop) { return prop + " -> "; })
3131
+ .map(function (prop) { return "".concat(prop, " -> "); })
3118
3132
  .join('');
3119
3133
  var current = props[props.length - 1];
3120
3134
  var leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
3121
3135
  var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
3122
3136
  throw new BSONTypeError('Converting circular structure to EJSON:\n' +
3123
- (" " + leadingPart + alreadySeen + circularPart + current + "\n") +
3124
- (" " + leadingSpace + "\\" + dashes + "/"));
3137
+ " ".concat(leadingPart).concat(alreadySeen).concat(circularPart).concat(current, "\n") +
3138
+ " ".concat(leadingSpace, "\\").concat(dashes, "/"));
3125
3139
  }
3126
3140
  options.seenObjects[options.seenObjects.length - 1].obj = value;
3127
3141
  }
@@ -3200,7 +3214,18 @@ function serializeDocument(doc, options) {
3200
3214
  for (var name in doc) {
3201
3215
  options.seenObjects.push({ propertyName: name, obj: null });
3202
3216
  try {
3203
- _doc[name] = serializeValue(doc[name], options);
3217
+ var value = serializeValue(doc[name], options);
3218
+ if (name === '__proto__') {
3219
+ Object.defineProperty(_doc, name, {
3220
+ value: value,
3221
+ writable: true,
3222
+ enumerable: true,
3223
+ configurable: true
3224
+ });
3225
+ }
3226
+ else {
3227
+ _doc[name] = value;
3228
+ }
3204
3229
  }
3205
3230
  finally {
3206
3231
  options.seenObjects.pop();
@@ -3270,7 +3295,7 @@ var EJSON;
3270
3295
  finalOptions.relaxed = !finalOptions.strict;
3271
3296
  return JSON.parse(text, function (key, value) {
3272
3297
  if (key.indexOf('\x00') !== -1) {
3273
- throw new BSONError("BSON Document field names cannot contain null bytes, found: " + JSON.stringify(key));
3298
+ throw new BSONError("BSON Document field names cannot contain null bytes, found: ".concat(JSON.stringify(key)));
3274
3299
  }
3275
3300
  return deserializeValue(value, finalOptions);
3276
3301
  });
@@ -3636,13 +3661,14 @@ value, serializeFunctions, isArray, ignoreUndefined) {
3636
3661
  }
3637
3662
  }
3638
3663
  else if (value['_bsontype'] === 'Binary') {
3664
+ var binary = value;
3639
3665
  // Check what kind of subtype we have
3640
- if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
3666
+ if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
3641
3667
  return ((name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) +
3642
- (value.position + 1 + 4 + 1 + 4));
3668
+ (binary.position + 1 + 4 + 1 + 4));
3643
3669
  }
3644
3670
  else {
3645
- return ((name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1));
3671
+ return ((name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (binary.position + 1 + 4 + 1));
3646
3672
  }
3647
3673
  }
3648
3674
  else if (value['_bsontype'] === 'Symbol') {
@@ -3779,16 +3805,16 @@ function deserialize$1(buffer, options, isArray) {
3779
3805
  (buffer[index + 2] << 16) |
3780
3806
  (buffer[index + 3] << 24);
3781
3807
  if (size < 5) {
3782
- throw new BSONError("bson size must be >= 5, is " + size);
3808
+ throw new BSONError("bson size must be >= 5, is ".concat(size));
3783
3809
  }
3784
3810
  if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
3785
- throw new BSONError("buffer length " + buffer.length + " must be >= bson size " + size);
3811
+ throw new BSONError("buffer length ".concat(buffer.length, " must be >= bson size ").concat(size));
3786
3812
  }
3787
3813
  if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
3788
- throw new BSONError("buffer length " + buffer.length + " must === bson size " + size);
3814
+ throw new BSONError("buffer length ".concat(buffer.length, " must === bson size ").concat(size));
3789
3815
  }
3790
3816
  if (size + index > buffer.byteLength) {
3791
- throw new BSONError("(bson size " + size + " + options.index " + index + " must be <= buffer length " + buffer.byteLength + ")");
3817
+ throw new BSONError("(bson size ".concat(size, " + options.index ").concat(index, " must be <= buffer length ").concat(buffer.byteLength, ")"));
3792
3818
  }
3793
3819
  // Illegal end value
3794
3820
  if (buffer[index + size - 1] !== 0) {
@@ -3865,6 +3891,7 @@ function deserializeObject(buffer, index, options, isArray) {
3865
3891
  var done = false;
3866
3892
  var isPossibleDBRef = isArray ? false : null;
3867
3893
  // While we have more left data left keep parsing
3894
+ var dataview = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3868
3895
  while (!done) {
3869
3896
  // Read the type
3870
3897
  var elementType = buffer[index++];
@@ -3925,11 +3952,11 @@ function deserializeObject(buffer, index, options, isArray) {
3925
3952
  (buffer[index++] << 24);
3926
3953
  }
3927
3954
  else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
3928
- value = new Double(buffer.readDoubleLE(index));
3955
+ value = new Double(dataview.getFloat64(index, true));
3929
3956
  index = index + 8;
3930
3957
  }
3931
3958
  else if (elementType === BSON_DATA_NUMBER) {
3932
- value = buffer.readDoubleLE(index);
3959
+ value = dataview.getFloat64(index, true);
3933
3960
  index = index + 8;
3934
3961
  }
3935
3962
  else if (elementType === BSON_DATA_DATE) {
@@ -4327,7 +4354,7 @@ function deserializeObject(buffer, index, options, isArray) {
4327
4354
  value = new DBRef(namespace, oid);
4328
4355
  }
4329
4356
  else {
4330
- throw new BSONError('Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"');
4357
+ throw new BSONError("Detected unknown BSON type ".concat(elementType.toString(16), " for fieldname \"").concat(name, "\""));
4331
4358
  }
4332
4359
  if (name === '__proto__') {
4333
4360
  Object.defineProperty(object, name, {
@@ -4365,10 +4392,12 @@ function deserializeObject(buffer, index, options, isArray) {
4365
4392
  * @internal
4366
4393
  */
4367
4394
  function isolateEval(functionString, functionCache, object) {
4395
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
4368
4396
  if (!functionCache)
4369
4397
  return new Function(functionString);
4370
4398
  // Check for cache hit, eval if missing and return cached function
4371
4399
  if (functionCache[functionString] == null) {
4400
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
4372
4401
  functionCache[functionString] = new Function(functionString);
4373
4402
  }
4374
4403
  // Set the object
@@ -4390,74 +4419,6 @@ function getValidatedString(buffer, start, end, shouldValidateUtf8) {
4390
4419
  return value;
4391
4420
  }
4392
4421
 
4393
- // Copyright (c) 2008, Fair Oaks Labs, Inc.
4394
- function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
4395
- var e;
4396
- var m;
4397
- var c;
4398
- var bBE = endian === 'big';
4399
- var eLen = nBytes * 8 - mLen - 1;
4400
- var eMax = (1 << eLen) - 1;
4401
- var eBias = eMax >> 1;
4402
- var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
4403
- var i = bBE ? nBytes - 1 : 0;
4404
- var d = bBE ? -1 : 1;
4405
- var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
4406
- value = Math.abs(value);
4407
- if (isNaN(value) || value === Infinity) {
4408
- m = isNaN(value) ? 1 : 0;
4409
- e = eMax;
4410
- }
4411
- else {
4412
- e = Math.floor(Math.log(value) / Math.LN2);
4413
- if (value * (c = Math.pow(2, -e)) < 1) {
4414
- e--;
4415
- c *= 2;
4416
- }
4417
- if (e + eBias >= 1) {
4418
- value += rt / c;
4419
- }
4420
- else {
4421
- value += rt * Math.pow(2, 1 - eBias);
4422
- }
4423
- if (value * c >= 2) {
4424
- e++;
4425
- c /= 2;
4426
- }
4427
- if (e + eBias >= eMax) {
4428
- m = 0;
4429
- e = eMax;
4430
- }
4431
- else if (e + eBias >= 1) {
4432
- m = (value * c - 1) * Math.pow(2, mLen);
4433
- e = e + eBias;
4434
- }
4435
- else {
4436
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
4437
- e = 0;
4438
- }
4439
- }
4440
- if (isNaN(value))
4441
- m = 0;
4442
- while (mLen >= 8) {
4443
- buffer[offset + i] = m & 0xff;
4444
- i += d;
4445
- m /= 256;
4446
- mLen -= 8;
4447
- }
4448
- e = (e << mLen) | m;
4449
- if (isNaN(value))
4450
- e += 8;
4451
- eLen += mLen;
4452
- while (eLen > 0) {
4453
- buffer[offset + i] = e & 0xff;
4454
- i += d;
4455
- e /= 256;
4456
- eLen -= 8;
4457
- }
4458
- buffer[offset + i - d] |= s * 128;
4459
- }
4460
-
4461
4422
  var regexp = /\x00/; // eslint-disable-line no-control-regex
4462
4423
  var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
4463
4424
  /*
@@ -4488,6 +4449,8 @@ function serializeString(buffer, key, value, index, isArray) {
4488
4449
  buffer[index++] = 0;
4489
4450
  return index;
4490
4451
  }
4452
+ var SPACE_FOR_FLOAT64 = new Uint8Array(8);
4453
+ var DV_FOR_FLOAT64 = new DataView(SPACE_FOR_FLOAT64.buffer, SPACE_FOR_FLOAT64.byteOffset, SPACE_FOR_FLOAT64.byteLength);
4491
4454
  function serializeNumber(buffer, key, value, index, isArray) {
4492
4455
  // We have an integer value
4493
4456
  // TODO(NODE-2529): Add support for big int
@@ -4521,7 +4484,8 @@ function serializeNumber(buffer, key, value, index, isArray) {
4521
4484
  index = index + numberOfWrittenBytes;
4522
4485
  buffer[index++] = 0;
4523
4486
  // Write float
4524
- writeIEEE754(buffer, value, index, 'little', 52, 8);
4487
+ DV_FOR_FLOAT64.setFloat64(0, value, true);
4488
+ buffer.set(SPACE_FOR_FLOAT64, index);
4525
4489
  // Adjust index
4526
4490
  index = index + 8;
4527
4491
  }
@@ -4800,7 +4764,8 @@ function serializeDouble(buffer, key, value, index, isArray) {
4800
4764
  index = index + numberOfWrittenBytes;
4801
4765
  buffer[index++] = 0;
4802
4766
  // Write float
4803
- writeIEEE754(buffer, value.value, index, 'little', 52, 8);
4767
+ DV_FOR_FLOAT64.setFloat64(0, value.value, true);
4768
+ buffer.set(SPACE_FOR_FLOAT64, index);
4804
4769
  // Adjust index
4805
4770
  index = index + 8;
4806
4771
  return index;
@@ -5010,7 +4975,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
5010
4975
  if (Array.isArray(object)) {
5011
4976
  // Get object keys
5012
4977
  for (var i = 0; i < object.length; i++) {
5013
- var key = '' + i;
4978
+ var key = "".concat(i);
5014
4979
  var value = object[i];
5015
4980
  // Is there an override value
5016
4981
  if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
@@ -5085,7 +5050,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
5085
5050
  index = serializeMinMax(buffer, key, value, index, true);
5086
5051
  }
5087
5052
  else if (typeof value['_bsontype'] !== 'undefined') {
5088
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
5053
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
5089
5054
  }
5090
5055
  }
5091
5056
  }
@@ -5184,7 +5149,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
5184
5149
  index = serializeMinMax(buffer, key, value, index);
5185
5150
  }
5186
5151
  else if (typeof value['_bsontype'] !== 'undefined') {
5187
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
5152
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
5188
5153
  }
5189
5154
  }
5190
5155
  }
@@ -5289,7 +5254,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
5289
5254
  index = serializeMinMax(buffer, key, value, index);
5290
5255
  }
5291
5256
  else if (typeof value['_bsontype'] !== 'undefined') {
5292
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
5257
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
5293
5258
  }
5294
5259
  }
5295
5260
  }