bson 4.6.3 → 4.7.0

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 (74) hide show
  1. package/bower.json +1 -1
  2. package/bson.d.ts +9 -9
  3. package/dist/bson.browser.esm.js +352 -400
  4. package/dist/bson.browser.esm.js.map +1 -1
  5. package/dist/bson.browser.umd.js +355 -403
  6. package/dist/bson.browser.umd.js.map +1 -1
  7. package/dist/bson.bundle.js +355 -403
  8. package/dist/bson.bundle.js.map +1 -1
  9. package/dist/bson.esm.js +349 -400
  10. package/dist/bson.esm.js.map +1 -1
  11. package/lib/binary.js +196 -10
  12. package/lib/binary.js.map +1 -1
  13. package/lib/bson.js +8 -9
  14. package/lib/bson.js.map +1 -1
  15. package/lib/code.js +1 -1
  16. package/lib/code.js.map +1 -1
  17. package/lib/db_ref.js +2 -2
  18. package/lib/db_ref.js.map +1 -1
  19. package/lib/decimal128.js +13 -13
  20. package/lib/decimal128.js.map +1 -1
  21. package/lib/double.js +2 -2
  22. package/lib/double.js.map +1 -1
  23. package/lib/ensure_buffer.js +1 -1
  24. package/lib/ensure_buffer.js.map +1 -1
  25. package/lib/extended_json.js +24 -12
  26. package/lib/extended_json.js.map +1 -1
  27. package/lib/int_32.js +1 -1
  28. package/lib/int_32.js.map +1 -1
  29. package/lib/long.js +3 -3
  30. package/lib/long.js.map +1 -1
  31. package/lib/map.js +1 -1
  32. package/lib/map.js.map +1 -1
  33. package/lib/objectid.js +9 -8
  34. package/lib/objectid.js.map +1 -1
  35. package/lib/parser/calculate_size.js +10 -9
  36. package/lib/parser/calculate_size.js.map +1 -1
  37. package/lib/parser/deserializer.js +20 -11
  38. package/lib/parser/deserializer.js.map +1 -1
  39. package/lib/parser/serializer.js +25 -22
  40. package/lib/parser/serializer.js.map +1 -1
  41. package/lib/parser/utils.js +23 -19
  42. package/lib/parser/utils.js.map +1 -1
  43. package/lib/regexp.js +4 -4
  44. package/lib/regexp.js.map +1 -1
  45. package/lib/symbol.js +1 -1
  46. package/lib/symbol.js.map +1 -1
  47. package/lib/timestamp.js +3 -3
  48. package/lib/timestamp.js.map +1 -1
  49. package/lib/utils/global.js +1 -1
  50. package/lib/utils/global.js.map +1 -1
  51. package/lib/uuid_utils.js +1 -1
  52. package/lib/uuid_utils.js.map +1 -1
  53. package/package.json +17 -24
  54. package/src/binary.ts +197 -3
  55. package/src/bson.ts +18 -23
  56. package/src/code.ts +1 -1
  57. package/src/db_ref.ts +1 -1
  58. package/src/decimal128.ts +3 -3
  59. package/src/extended_json.ts +13 -2
  60. package/src/long.ts +32 -7
  61. package/src/objectid.ts +3 -2
  62. package/src/parser/calculate_size.ts +4 -3
  63. package/src/parser/deserializer.ts +12 -4
  64. package/src/parser/serializer.ts +14 -7
  65. package/src/parser/utils.ts +24 -20
  66. package/src/timestamp.ts +1 -1
  67. package/src/utils/global.ts +1 -1
  68. package/bson-ts34.d.ts +0 -1133
  69. package/lib/float_parser.js +0 -137
  70. package/lib/float_parser.js.map +0 -1
  71. package/lib/uuid.js +0 -179
  72. package/lib/uuid.js.map +0 -1
  73. package/src/float_parser.ts +0 -152
  74. package/src/uuid.ts +0 -209
@@ -2131,11 +2131,11 @@ var BSON = (function (exports) {
2131
2131
  }
2132
2132
  // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
2133
2133
  function getGlobal() {
2134
- // eslint-disable-next-line no-undef
2135
2134
  return (checkForMath(typeof globalThis === 'object' && globalThis) ||
2136
2135
  checkForMath(typeof window === 'object' && window) ||
2137
2136
  checkForMath(typeof self === 'object' && self) ||
2138
2137
  checkForMath(typeof global === 'object' && global) ||
2138
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
2139
2139
  Function('return this')());
2140
2140
  }
2141
2141
 
@@ -2161,27 +2161,20 @@ var BSON = (function (exports) {
2161
2161
  return result;
2162
2162
  };
2163
2163
  var detectRandomBytes = function () {
2164
- if (typeof window !== 'undefined') {
2165
- // browser crypto implementation(s)
2166
- var target_1 = window.crypto || window.msCrypto; // allow for IE11
2167
- if (target_1 && target_1.getRandomValues) {
2168
- return function (size) { return target_1.getRandomValues(buffer_1.alloc(size)); };
2164
+ {
2165
+ if (typeof window !== 'undefined') {
2166
+ // browser crypto implementation(s)
2167
+ var target_1 = window.crypto || window.msCrypto; // allow for IE11
2168
+ if (target_1 && target_1.getRandomValues) {
2169
+ return function (size) { return target_1.getRandomValues(buffer_1.alloc(size)); };
2170
+ }
2169
2171
  }
2172
+ if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
2173
+ // allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
2174
+ return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
2175
+ }
2176
+ return insecureRandomBytes;
2170
2177
  }
2171
- if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
2172
- // allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
2173
- return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
2174
- }
2175
- var requiredRandomBytes;
2176
- try {
2177
- // eslint-disable-next-line @typescript-eslint/no-var-requires
2178
- requiredRandomBytes = require('crypto').randomBytes;
2179
- }
2180
- catch (e) {
2181
- // keep the fallback
2182
- }
2183
- // NOTE: in transpiled cases the above require might return null/undefined
2184
- return requiredRandomBytes || insecureRandomBytes;
2185
2178
  };
2186
2179
  var randomBytes = detectRandomBytes();
2187
2180
  function isAnyArrayBuffer(value) {
@@ -2275,174 +2268,84 @@ var BSON = (function (exports) {
2275
2268
  : buffer.toString('hex');
2276
2269
  };
2277
2270
 
2278
- var BYTE_LENGTH = 16;
2279
- var kId$1 = Symbol('id');
2271
+ /** @internal */
2272
+ var BSON_INT32_MAX$1 = 0x7fffffff;
2273
+ /** @internal */
2274
+ var BSON_INT32_MIN$1 = -0x80000000;
2275
+ /** @internal */
2276
+ var BSON_INT64_MAX$1 = Math.pow(2, 63) - 1;
2277
+ /** @internal */
2278
+ var BSON_INT64_MIN$1 = -Math.pow(2, 63);
2280
2279
  /**
2281
- * A class representation of the BSON UUID type.
2282
- * @public
2280
+ * Any integer up to 2^53 can be precisely represented by a double.
2281
+ * @internal
2283
2282
  */
2284
- var UUID = /** @class */ (function () {
2285
- /**
2286
- * Create an UUID type
2287
- *
2288
- * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
2289
- */
2290
- function UUID(input) {
2291
- if (typeof input === 'undefined') {
2292
- // The most common use case (blank id, new UUID() instance)
2293
- this.id = UUID.generate();
2294
- }
2295
- else if (input instanceof UUID) {
2296
- this[kId$1] = buffer_1.from(input.id);
2297
- this.__id = input.__id;
2298
- }
2299
- else if (ArrayBuffer.isView(input) && input.byteLength === BYTE_LENGTH) {
2300
- this.id = ensureBuffer(input);
2301
- }
2302
- else if (typeof input === 'string') {
2303
- this.id = uuidHexStringToBuffer(input);
2304
- }
2305
- else {
2306
- throw new BSONTypeError('Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).');
2307
- }
2308
- }
2309
- Object.defineProperty(UUID.prototype, "id", {
2310
- /**
2311
- * The UUID bytes
2312
- * @readonly
2313
- */
2314
- get: function () {
2315
- return this[kId$1];
2316
- },
2317
- set: function (value) {
2318
- this[kId$1] = value;
2319
- if (UUID.cacheHexString) {
2320
- this.__id = bufferToUuidHexString(value);
2321
- }
2322
- },
2323
- enumerable: false,
2324
- configurable: true
2325
- });
2326
- /**
2327
- * Generate a 16 byte uuid v4 buffer used in UUIDs
2328
- */
2329
- /**
2330
- * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
2331
- * @param includeDashes - should the string exclude dash-separators.
2332
- * */
2333
- UUID.prototype.toHexString = function (includeDashes) {
2334
- if (includeDashes === void 0) { includeDashes = true; }
2335
- if (UUID.cacheHexString && this.__id) {
2336
- return this.__id;
2337
- }
2338
- var uuidHexString = bufferToUuidHexString(this.id, includeDashes);
2339
- if (UUID.cacheHexString) {
2340
- this.__id = uuidHexString;
2341
- }
2342
- return uuidHexString;
2343
- };
2344
- /**
2345
- * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
2346
- */
2347
- UUID.prototype.toString = function (encoding) {
2348
- return encoding ? this.id.toString(encoding) : this.toHexString();
2349
- };
2350
- /**
2351
- * Converts the id into its JSON string representation.
2352
- * A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
2353
- */
2354
- UUID.prototype.toJSON = function () {
2355
- return this.toHexString();
2356
- };
2357
- /**
2358
- * Compares the equality of this UUID with `otherID`.
2359
- *
2360
- * @param otherId - UUID instance to compare against.
2361
- */
2362
- UUID.prototype.equals = function (otherId) {
2363
- if (!otherId) {
2364
- return false;
2365
- }
2366
- if (otherId instanceof UUID) {
2367
- return otherId.id.equals(this.id);
2368
- }
2369
- try {
2370
- return new UUID(otherId).id.equals(this.id);
2371
- }
2372
- catch (_a) {
2373
- return false;
2374
- }
2375
- };
2376
- /**
2377
- * Creates a Binary instance from the current UUID.
2378
- */
2379
- UUID.prototype.toBinary = function () {
2380
- return new Binary(this.id, Binary.SUBTYPE_UUID);
2381
- };
2382
- /**
2383
- * Generates a populated buffer containing a v4 uuid
2384
- */
2385
- UUID.generate = function () {
2386
- var bytes = randomBytes(BYTE_LENGTH);
2387
- // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
2388
- // Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
2389
- bytes[6] = (bytes[6] & 0x0f) | 0x40;
2390
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
2391
- return buffer_1.from(bytes);
2392
- };
2393
- /**
2394
- * Checks if a value is a valid bson UUID
2395
- * @param input - UUID, string or Buffer to validate.
2396
- */
2397
- UUID.isValid = function (input) {
2398
- if (!input) {
2399
- return false;
2400
- }
2401
- if (input instanceof UUID) {
2402
- return true;
2403
- }
2404
- if (typeof input === 'string') {
2405
- return uuidValidateString(input);
2406
- }
2407
- if (isUint8Array(input)) {
2408
- // check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
2409
- if (input.length !== BYTE_LENGTH) {
2410
- return false;
2411
- }
2412
- try {
2413
- // get this byte as hex: xxxxxxxx-xxxx-XXxx-xxxx-xxxxxxxxxxxx
2414
- // check first part as uuid version: xxxxxxxx-xxxx-Xxxx-xxxx-xxxxxxxxxxxx
2415
- return parseInt(input[6].toString(16)[0], 10) === Binary.SUBTYPE_UUID;
2416
- }
2417
- catch (_a) {
2418
- return false;
2419
- }
2420
- }
2421
- return false;
2422
- };
2423
- /**
2424
- * Creates an UUID from a hex string representation of an UUID.
2425
- * @param hexString - 32 or 36 character hex string (dashes excluded/included).
2426
- */
2427
- UUID.createFromHexString = function (hexString) {
2428
- var buffer = uuidHexStringToBuffer(hexString);
2429
- return new UUID(buffer);
2430
- };
2431
- /**
2432
- * Converts to a string representation of this Id.
2433
- *
2434
- * @returns return the 36 character hex string representation.
2435
- * @internal
2436
- */
2437
- UUID.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
2438
- return this.inspect();
2439
- };
2440
- UUID.prototype.inspect = function () {
2441
- return "new UUID(\"" + this.toHexString() + "\")";
2442
- };
2443
- return UUID;
2444
- }());
2445
- Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
2283
+ var JS_INT_MAX = Math.pow(2, 53);
2284
+ /**
2285
+ * Any integer down to -2^53 can be precisely represented by a double.
2286
+ * @internal
2287
+ */
2288
+ var JS_INT_MIN = -Math.pow(2, 53);
2289
+ /** Number BSON Type @internal */
2290
+ var BSON_DATA_NUMBER = 1;
2291
+ /** String BSON Type @internal */
2292
+ var BSON_DATA_STRING = 2;
2293
+ /** Object BSON Type @internal */
2294
+ var BSON_DATA_OBJECT = 3;
2295
+ /** Array BSON Type @internal */
2296
+ var BSON_DATA_ARRAY = 4;
2297
+ /** Binary BSON Type @internal */
2298
+ var BSON_DATA_BINARY = 5;
2299
+ /** Binary BSON Type @internal */
2300
+ var BSON_DATA_UNDEFINED = 6;
2301
+ /** ObjectId BSON Type @internal */
2302
+ var BSON_DATA_OID = 7;
2303
+ /** Boolean BSON Type @internal */
2304
+ var BSON_DATA_BOOLEAN = 8;
2305
+ /** Date BSON Type @internal */
2306
+ var BSON_DATA_DATE = 9;
2307
+ /** null BSON Type @internal */
2308
+ var BSON_DATA_NULL = 10;
2309
+ /** RegExp BSON Type @internal */
2310
+ var BSON_DATA_REGEXP = 11;
2311
+ /** Code BSON Type @internal */
2312
+ var BSON_DATA_DBPOINTER = 12;
2313
+ /** Code BSON Type @internal */
2314
+ var BSON_DATA_CODE = 13;
2315
+ /** Symbol BSON Type @internal */
2316
+ var BSON_DATA_SYMBOL = 14;
2317
+ /** Code with Scope BSON Type @internal */
2318
+ var BSON_DATA_CODE_W_SCOPE = 15;
2319
+ /** 32 bit Integer BSON Type @internal */
2320
+ var BSON_DATA_INT = 16;
2321
+ /** Timestamp BSON Type @internal */
2322
+ var BSON_DATA_TIMESTAMP = 17;
2323
+ /** Long BSON Type @internal */
2324
+ var BSON_DATA_LONG = 18;
2325
+ /** Decimal128 BSON Type @internal */
2326
+ var BSON_DATA_DECIMAL128 = 19;
2327
+ /** MinKey BSON Type @internal */
2328
+ var BSON_DATA_MIN_KEY = 0xff;
2329
+ /** MaxKey BSON Type @internal */
2330
+ var BSON_DATA_MAX_KEY = 0x7f;
2331
+ /** Binary Default Type @internal */
2332
+ var BSON_BINARY_SUBTYPE_DEFAULT = 0;
2333
+ /** Binary Function Type @internal */
2334
+ var BSON_BINARY_SUBTYPE_FUNCTION = 1;
2335
+ /** Binary Byte Array Type @internal */
2336
+ var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
2337
+ /** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
2338
+ var BSON_BINARY_SUBTYPE_UUID = 3;
2339
+ /** Binary UUID Type @internal */
2340
+ var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
2341
+ /** Binary MD5 Type @internal */
2342
+ var BSON_BINARY_SUBTYPE_MD5 = 5;
2343
+ /** Encrypted BSON type @internal */
2344
+ var BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
2345
+ /** Column BSON type @internal */
2346
+ var BSON_BINARY_SUBTYPE_COLUMN = 7;
2347
+ /** Binary User Defined Type @internal */
2348
+ var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
2446
2349
 
2447
2350
  /**
2448
2351
  * A class representation of the BSON Binary type.
@@ -2451,6 +2354,13 @@ var BSON = (function (exports) {
2451
2354
  */
2452
2355
  var Binary = /** @class */ (function () {
2453
2356
  /**
2357
+ * Create a new Binary instance.
2358
+ *
2359
+ * This constructor can accept a string as its first argument. In this case,
2360
+ * this string will be encoded using ISO-8859-1, **not** using UTF-8.
2361
+ * This is almost certainly not what you want. Use `new Binary(Buffer.from(string))`
2362
+ * instead to convert the string to a Buffer using UTF-8 first.
2363
+ *
2454
2364
  * @param buffer - a buffer object containing the binary data.
2455
2365
  * @param subType - the option binary type.
2456
2366
  */
@@ -2610,7 +2520,7 @@ var BSON = (function (exports) {
2610
2520
  if (this.sub_type === Binary.SUBTYPE_UUID) {
2611
2521
  return new UUID(this.buffer.slice(0, this.position));
2612
2522
  }
2613
- throw new BSONError("Binary sub_type \"" + this.sub_type + "\" is not supported for converting to UUID. Only \"" + Binary.SUBTYPE_UUID + "\" is currently supported.");
2523
+ 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."));
2614
2524
  };
2615
2525
  /** @internal */
2616
2526
  Binary.fromExtendedJSON = function (doc, options) {
@@ -2634,9 +2544,9 @@ var BSON = (function (exports) {
2634
2544
  data = uuidHexStringToBuffer(doc.$uuid);
2635
2545
  }
2636
2546
  if (!data) {
2637
- throw new BSONTypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc));
2547
+ throw new BSONTypeError("Unexpected Binary Extended JSON format ".concat(JSON.stringify(doc)));
2638
2548
  }
2639
- return new Binary(data, type);
2549
+ return type === BSON_BINARY_SUBTYPE_UUID_NEW ? new UUID(data) : new Binary(data, type);
2640
2550
  };
2641
2551
  /** @internal */
2642
2552
  Binary.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
@@ -2644,7 +2554,7 @@ var BSON = (function (exports) {
2644
2554
  };
2645
2555
  Binary.prototype.inspect = function () {
2646
2556
  var asBuffer = this.value(true);
2647
- return "new Binary(Buffer.from(\"" + asBuffer.toString('hex') + "\", \"hex\"), " + this.sub_type + ")";
2557
+ return "new Binary(Buffer.from(\"".concat(asBuffer.toString('hex'), "\", \"hex\"), ").concat(this.sub_type, ")");
2648
2558
  };
2649
2559
  /**
2650
2560
  * Binary default subtype
@@ -2674,6 +2584,168 @@ var BSON = (function (exports) {
2674
2584
  return Binary;
2675
2585
  }());
2676
2586
  Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' });
2587
+ var UUID_BYTE_LENGTH = 16;
2588
+ /**
2589
+ * A class representation of the BSON UUID type.
2590
+ * @public
2591
+ */
2592
+ var UUID = /** @class */ (function (_super) {
2593
+ __extends(UUID, _super);
2594
+ /**
2595
+ * Create an UUID type
2596
+ *
2597
+ * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
2598
+ */
2599
+ function UUID(input) {
2600
+ var _this = this;
2601
+ var bytes;
2602
+ var hexStr;
2603
+ if (input == null) {
2604
+ bytes = UUID.generate();
2605
+ }
2606
+ else if (input instanceof UUID) {
2607
+ bytes = buffer_1.from(input.buffer);
2608
+ hexStr = input.__id;
2609
+ }
2610
+ else if (ArrayBuffer.isView(input) && input.byteLength === UUID_BYTE_LENGTH) {
2611
+ bytes = ensureBuffer(input);
2612
+ }
2613
+ else if (typeof input === 'string') {
2614
+ bytes = uuidHexStringToBuffer(input);
2615
+ }
2616
+ else {
2617
+ throw new BSONTypeError('Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).');
2618
+ }
2619
+ _this = _super.call(this, bytes, BSON_BINARY_SUBTYPE_UUID_NEW) || this;
2620
+ _this.__id = hexStr;
2621
+ return _this;
2622
+ }
2623
+ Object.defineProperty(UUID.prototype, "id", {
2624
+ /**
2625
+ * The UUID bytes
2626
+ * @readonly
2627
+ */
2628
+ get: function () {
2629
+ return this.buffer;
2630
+ },
2631
+ set: function (value) {
2632
+ this.buffer = value;
2633
+ if (UUID.cacheHexString) {
2634
+ this.__id = bufferToUuidHexString(value);
2635
+ }
2636
+ },
2637
+ enumerable: false,
2638
+ configurable: true
2639
+ });
2640
+ /**
2641
+ * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
2642
+ * @param includeDashes - should the string exclude dash-separators.
2643
+ * */
2644
+ UUID.prototype.toHexString = function (includeDashes) {
2645
+ if (includeDashes === void 0) { includeDashes = true; }
2646
+ if (UUID.cacheHexString && this.__id) {
2647
+ return this.__id;
2648
+ }
2649
+ var uuidHexString = bufferToUuidHexString(this.id, includeDashes);
2650
+ if (UUID.cacheHexString) {
2651
+ this.__id = uuidHexString;
2652
+ }
2653
+ return uuidHexString;
2654
+ };
2655
+ /**
2656
+ * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
2657
+ */
2658
+ UUID.prototype.toString = function (encoding) {
2659
+ return encoding ? this.id.toString(encoding) : this.toHexString();
2660
+ };
2661
+ /**
2662
+ * Converts the id into its JSON string representation.
2663
+ * A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
2664
+ */
2665
+ UUID.prototype.toJSON = function () {
2666
+ return this.toHexString();
2667
+ };
2668
+ /**
2669
+ * Compares the equality of this UUID with `otherID`.
2670
+ *
2671
+ * @param otherId - UUID instance to compare against.
2672
+ */
2673
+ UUID.prototype.equals = function (otherId) {
2674
+ if (!otherId) {
2675
+ return false;
2676
+ }
2677
+ if (otherId instanceof UUID) {
2678
+ return otherId.id.equals(this.id);
2679
+ }
2680
+ try {
2681
+ return new UUID(otherId).id.equals(this.id);
2682
+ }
2683
+ catch (_a) {
2684
+ return false;
2685
+ }
2686
+ };
2687
+ /**
2688
+ * Creates a Binary instance from the current UUID.
2689
+ */
2690
+ UUID.prototype.toBinary = function () {
2691
+ return new Binary(this.id, Binary.SUBTYPE_UUID);
2692
+ };
2693
+ /**
2694
+ * Generates a populated buffer containing a v4 uuid
2695
+ */
2696
+ UUID.generate = function () {
2697
+ var bytes = randomBytes(UUID_BYTE_LENGTH);
2698
+ // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
2699
+ // Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
2700
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
2701
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
2702
+ return buffer_1.from(bytes);
2703
+ };
2704
+ /**
2705
+ * Checks if a value is a valid bson UUID
2706
+ * @param input - UUID, string or Buffer to validate.
2707
+ */
2708
+ UUID.isValid = function (input) {
2709
+ if (!input) {
2710
+ return false;
2711
+ }
2712
+ if (input instanceof UUID) {
2713
+ return true;
2714
+ }
2715
+ if (typeof input === 'string') {
2716
+ return uuidValidateString(input);
2717
+ }
2718
+ if (isUint8Array(input)) {
2719
+ // check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
2720
+ if (input.length !== UUID_BYTE_LENGTH) {
2721
+ return false;
2722
+ }
2723
+ return (input[6] & 0xf0) === 0x40 && (input[8] & 0x80) === 0x80;
2724
+ }
2725
+ return false;
2726
+ };
2727
+ /**
2728
+ * Creates an UUID from a hex string representation of an UUID.
2729
+ * @param hexString - 32 or 36 character hex string (dashes excluded/included).
2730
+ */
2731
+ UUID.createFromHexString = function (hexString) {
2732
+ var buffer = uuidHexStringToBuffer(hexString);
2733
+ return new UUID(buffer);
2734
+ };
2735
+ /**
2736
+ * Converts to a string representation of this Id.
2737
+ *
2738
+ * @returns return the 36 character hex string representation.
2739
+ * @internal
2740
+ */
2741
+ UUID.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
2742
+ return this.inspect();
2743
+ };
2744
+ UUID.prototype.inspect = function () {
2745
+ return "new UUID(\"".concat(this.toHexString(), "\")");
2746
+ };
2747
+ return UUID;
2748
+ }(Binary));
2677
2749
 
2678
2750
  /**
2679
2751
  * A class representation of the BSON Code type.
@@ -2711,7 +2783,7 @@ var BSON = (function (exports) {
2711
2783
  };
2712
2784
  Code.prototype.inspect = function () {
2713
2785
  var codeJson = this.toJSON();
2714
- return "new Code(\"" + codeJson.code + "\"" + (codeJson.scope ? ", " + JSON.stringify(codeJson.scope) : '') + ")";
2786
+ return "new Code(\"".concat(String(codeJson.code), "\"").concat(codeJson.scope ? ", ".concat(JSON.stringify(codeJson.scope)) : '', ")");
2715
2787
  };
2716
2788
  return Code;
2717
2789
  }());
@@ -2802,7 +2874,7 @@ var BSON = (function (exports) {
2802
2874
  DBRef.prototype.inspect = function () {
2803
2875
  // NOTE: if OID is an ObjectId class it will just print the oid string.
2804
2876
  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 + "\"" : '') + ")";
2877
+ return "new DBRef(\"".concat(this.namespace, "\", new ObjectId(\"").concat(String(oid), "\")").concat(this.db ? ", \"".concat(this.db, "\"") : '', ")");
2806
2878
  };
2807
2879
  return DBRef;
2808
2880
  }());
@@ -3039,7 +3111,6 @@ var BSON = (function (exports) {
3039
3111
  /**
3040
3112
  * Tests if the specified object is a Long.
3041
3113
  */
3042
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
3043
3114
  Long.isLong = function (value) {
3044
3115
  return isObjectLike(value) && value['__isLong__'] === true;
3045
3116
  };
@@ -3196,6 +3267,7 @@ var BSON = (function (exports) {
3196
3267
  // into the result, and subtract it from the remainder. It is critical that
3197
3268
  // the approximate value is less than or equal to the real value so that the
3198
3269
  // remainder never becomes negative.
3270
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3199
3271
  rem = this;
3200
3272
  while (rem.gte(divisor)) {
3201
3273
  // Approximate the result of division. This may be a little greater or
@@ -3679,7 +3751,7 @@ var BSON = (function (exports) {
3679
3751
  return this.inspect();
3680
3752
  };
3681
3753
  Long.prototype.inspect = function () {
3682
- return "new Long(\"" + this.toString() + "\"" + (this.unsigned ? ', true' : '') + ")";
3754
+ return "new Long(\"".concat(this.toString(), "\"").concat(this.unsigned ? ', true' : '', ")");
3683
3755
  };
3684
3756
  Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
3685
3757
  /** Maximum unsigned value. */
@@ -3790,7 +3862,7 @@ var BSON = (function (exports) {
3790
3862
  return false;
3791
3863
  }
3792
3864
  function invalidErr(string, message) {
3793
- throw new BSONTypeError("\"" + string + "\" is not a valid Decimal128 string - " + message);
3865
+ throw new BSONTypeError("\"".concat(string, "\" is not a valid Decimal128 string - ").concat(message));
3794
3866
  }
3795
3867
  /**
3796
3868
  * A class representation of the BSON Decimal128 type.
@@ -4288,35 +4360,35 @@ var BSON = (function (exports) {
4288
4360
  // as + or - 0 and using the non-scientific exponent (this is for the "invalid
4289
4361
  // representation should be treated as 0/-0" spec cases in decimal128-1.json)
4290
4362
  if (significand_digits > 34) {
4291
- string.push("" + 0);
4363
+ string.push("".concat(0));
4292
4364
  if (exponent > 0)
4293
- string.push('E+' + exponent);
4365
+ string.push("E+".concat(exponent));
4294
4366
  else if (exponent < 0)
4295
- string.push('E' + exponent);
4367
+ string.push("E".concat(exponent));
4296
4368
  return string.join('');
4297
4369
  }
4298
- string.push("" + significand[index++]);
4370
+ string.push("".concat(significand[index++]));
4299
4371
  significand_digits = significand_digits - 1;
4300
4372
  if (significand_digits) {
4301
4373
  string.push('.');
4302
4374
  }
4303
4375
  for (var i = 0; i < significand_digits; i++) {
4304
- string.push("" + significand[index++]);
4376
+ string.push("".concat(significand[index++]));
4305
4377
  }
4306
4378
  // Exponent
4307
4379
  string.push('E');
4308
4380
  if (scientific_exponent > 0) {
4309
- string.push('+' + scientific_exponent);
4381
+ string.push("+".concat(scientific_exponent));
4310
4382
  }
4311
4383
  else {
4312
- string.push("" + scientific_exponent);
4384
+ string.push("".concat(scientific_exponent));
4313
4385
  }
4314
4386
  }
4315
4387
  else {
4316
4388
  // Regular format with no decimal place
4317
4389
  if (exponent >= 0) {
4318
4390
  for (var i = 0; i < significand_digits; i++) {
4319
- string.push("" + significand[index++]);
4391
+ string.push("".concat(significand[index++]));
4320
4392
  }
4321
4393
  }
4322
4394
  else {
@@ -4324,7 +4396,7 @@ var BSON = (function (exports) {
4324
4396
  // non-zero digits before radix
4325
4397
  if (radix_position > 0) {
4326
4398
  for (var i = 0; i < radix_position; i++) {
4327
- string.push("" + significand[index++]);
4399
+ string.push("".concat(significand[index++]));
4328
4400
  }
4329
4401
  }
4330
4402
  else {
@@ -4336,7 +4408,7 @@ var BSON = (function (exports) {
4336
4408
  string.push('0');
4337
4409
  }
4338
4410
  for (var i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
4339
- string.push("" + significand[index++]);
4411
+ string.push("".concat(significand[index++]));
4340
4412
  }
4341
4413
  }
4342
4414
  }
@@ -4358,7 +4430,7 @@ var BSON = (function (exports) {
4358
4430
  return this.inspect();
4359
4431
  };
4360
4432
  Decimal128.prototype.inspect = function () {
4361
- return "new Decimal128(\"" + this.toString() + "\")";
4433
+ return "new Decimal128(\"".concat(this.toString(), "\")");
4362
4434
  };
4363
4435
  return Decimal128;
4364
4436
  }());
@@ -4405,7 +4477,7 @@ var BSON = (function (exports) {
4405
4477
  // NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
4406
4478
  // explicitly provided `-0` then we need to ensure the sign makes it into the output
4407
4479
  if (Object.is(Math.sign(this.value), -0)) {
4408
- return { $numberDouble: "-" + this.value.toFixed(1) };
4480
+ return { $numberDouble: "-".concat(this.value.toFixed(1)) };
4409
4481
  }
4410
4482
  var $numberDouble;
4411
4483
  if (Number.isInteger(this.value)) {
@@ -4430,7 +4502,7 @@ var BSON = (function (exports) {
4430
4502
  };
4431
4503
  Double.prototype.inspect = function () {
4432
4504
  var eJSON = this.toExtendedJSON();
4433
- return "new Double(" + eJSON.$numberDouble + ")";
4505
+ return "new Double(".concat(eJSON.$numberDouble, ")");
4434
4506
  };
4435
4507
  return Double;
4436
4508
  }());
@@ -4484,7 +4556,7 @@ var BSON = (function (exports) {
4484
4556
  return this.inspect();
4485
4557
  };
4486
4558
  Int32.prototype.inspect = function () {
4487
- return "new Int32(" + this.valueOf() + ")";
4559
+ return "new Int32(".concat(this.valueOf(), ")");
4488
4560
  };
4489
4561
  return Int32;
4490
4562
  }());
@@ -4590,7 +4662,8 @@ var BSON = (function (exports) {
4590
4662
  this[kId] = ObjectId.generate(typeof workingId === 'number' ? workingId : undefined);
4591
4663
  }
4592
4664
  else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
4593
- this[kId] = ensureBuffer(workingId);
4665
+ // If intstanceof matches we can escape calling ensure buffer in Node.js environments
4666
+ this[kId] = workingId instanceof buffer_1 ? workingId : ensureBuffer(workingId);
4594
4667
  }
4595
4668
  else if (typeof workingId === 'string') {
4596
4669
  if (workingId.length === 12) {
@@ -4817,7 +4890,7 @@ var BSON = (function (exports) {
4817
4890
  return this.inspect();
4818
4891
  };
4819
4892
  ObjectId.prototype.inspect = function () {
4820
- return "new ObjectId(\"" + this.toHexString() + "\")";
4893
+ return "new ObjectId(\"".concat(this.toHexString(), "\")");
4821
4894
  };
4822
4895
  /** @internal */
4823
4896
  ObjectId.index = Math.floor(Math.random() * 0xffffff);
@@ -4857,10 +4930,10 @@ var BSON = (function (exports) {
4857
4930
  this.pattern = pattern;
4858
4931
  this.options = alphabetize(options !== null && options !== void 0 ? options : '');
4859
4932
  if (this.pattern.indexOf('\x00') !== -1) {
4860
- throw new BSONError("BSON Regex patterns cannot contain null bytes, found: " + JSON.stringify(this.pattern));
4933
+ throw new BSONError("BSON Regex patterns cannot contain null bytes, found: ".concat(JSON.stringify(this.pattern)));
4861
4934
  }
4862
4935
  if (this.options.indexOf('\x00') !== -1) {
4863
- throw new BSONError("BSON Regex options cannot contain null bytes, found: " + JSON.stringify(this.options));
4936
+ throw new BSONError("BSON Regex options cannot contain null bytes, found: ".concat(JSON.stringify(this.options)));
4864
4937
  }
4865
4938
  // Validate options
4866
4939
  for (var i = 0; i < this.options.length; i++) {
@@ -4870,7 +4943,7 @@ var BSON = (function (exports) {
4870
4943
  this.options[i] === 'l' ||
4871
4944
  this.options[i] === 's' ||
4872
4945
  this.options[i] === 'u')) {
4873
- throw new BSONError("The regular expression option [" + this.options[i] + "] is not supported");
4946
+ throw new BSONError("The regular expression option [".concat(this.options[i], "] is not supported"));
4874
4947
  }
4875
4948
  }
4876
4949
  }
@@ -4901,7 +4974,7 @@ var BSON = (function (exports) {
4901
4974
  if ('$regularExpression' in doc) {
4902
4975
  return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
4903
4976
  }
4904
- throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: " + JSON.stringify(doc));
4977
+ throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(doc)));
4905
4978
  };
4906
4979
  return BSONRegExp;
4907
4980
  }());
@@ -4930,7 +5003,7 @@ var BSON = (function (exports) {
4930
5003
  };
4931
5004
  /** @internal */
4932
5005
  BSONSymbol.prototype.inspect = function () {
4933
- return "new BSONSymbol(\"" + this.value + "\")";
5006
+ return "new BSONSymbol(\"".concat(this.value, "\")");
4934
5007
  };
4935
5008
  BSONSymbol.prototype.toJSON = function () {
4936
5009
  return this.value;
@@ -4962,7 +5035,7 @@ var BSON = (function (exports) {
4962
5035
  function Timestamp(low, high) {
4963
5036
  var _this = this;
4964
5037
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4965
- ///@ts-expect-error
5038
+ // @ts-expect-error
4966
5039
  if (!(_this instanceof Timestamp))
4967
5040
  return new Timestamp(low, high);
4968
5041
  if (Long.isLong(low)) {
@@ -5026,7 +5099,7 @@ var BSON = (function (exports) {
5026
5099
  return this.inspect();
5027
5100
  };
5028
5101
  Timestamp.prototype.inspect = function () {
5029
- return "new Timestamp({ t: " + this.getHighBits() + ", i: " + this.getLowBits() + " })";
5102
+ return "new Timestamp({ t: ".concat(this.getHighBits(), ", i: ").concat(this.getLowBits(), " })");
5030
5103
  };
5031
5104
  Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
5032
5105
  return Timestamp;
@@ -5036,11 +5109,12 @@ var BSON = (function (exports) {
5036
5109
  return (isObjectLike(value) && Reflect.has(value, '_bsontype') && typeof value._bsontype === 'string');
5037
5110
  }
5038
5111
  // INT32 boundaries
5039
- var BSON_INT32_MAX$1 = 0x7fffffff;
5040
- var BSON_INT32_MIN$1 = -0x80000000;
5112
+ var BSON_INT32_MAX = 0x7fffffff;
5113
+ var BSON_INT32_MIN = -0x80000000;
5041
5114
  // INT64 boundaries
5042
- var BSON_INT64_MAX$1 = 0x7fffffffffffffff;
5043
- var BSON_INT64_MIN$1 = -0x8000000000000000;
5115
+ // const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
5116
+ var BSON_INT64_MAX = 0x8000000000000000;
5117
+ var BSON_INT64_MIN = -0x8000000000000000;
5044
5118
  // all the types where we don't need to do any special processing and can just pass the EJSON
5045
5119
  //straight to type.fromExtendedJSON
5046
5120
  var keysToCodecs = {
@@ -5068,9 +5142,9 @@ var BSON = (function (exports) {
5068
5142
  // if it's an integer, should interpret as smallest BSON integer
5069
5143
  // that can represent it exactly. (if out of range, interpret as double.)
5070
5144
  if (Math.floor(value) === value) {
5071
- if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1)
5145
+ if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX)
5072
5146
  return new Int32(value);
5073
- if (value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1)
5147
+ if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX)
5074
5148
  return Long.fromNumber(value);
5075
5149
  }
5076
5150
  // If the number is a non-integer or out of integer range, should interpret as BSON Double.
@@ -5135,7 +5209,7 @@ var BSON = (function (exports) {
5135
5209
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5136
5210
  function serializeArray(array, options) {
5137
5211
  return array.map(function (v, index) {
5138
- options.seenObjects.push({ propertyName: "index " + index, obj: null });
5212
+ options.seenObjects.push({ propertyName: "index ".concat(index), obj: null });
5139
5213
  try {
5140
5214
  return serializeValue(v, options);
5141
5215
  }
@@ -5157,20 +5231,20 @@ var BSON = (function (exports) {
5157
5231
  var props = options.seenObjects.map(function (entry) { return entry.propertyName; });
5158
5232
  var leadingPart = props
5159
5233
  .slice(0, index)
5160
- .map(function (prop) { return prop + " -> "; })
5234
+ .map(function (prop) { return "".concat(prop, " -> "); })
5161
5235
  .join('');
5162
5236
  var alreadySeen = props[index];
5163
5237
  var circularPart = ' -> ' +
5164
5238
  props
5165
5239
  .slice(index + 1, props.length - 1)
5166
- .map(function (prop) { return prop + " -> "; })
5240
+ .map(function (prop) { return "".concat(prop, " -> "); })
5167
5241
  .join('');
5168
5242
  var current = props[props.length - 1];
5169
5243
  var leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
5170
5244
  var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
5171
5245
  throw new BSONTypeError('Converting circular structure to EJSON:\n' +
5172
- (" " + leadingPart + alreadySeen + circularPart + current + "\n") +
5173
- (" " + leadingSpace + "\\" + dashes + "/"));
5246
+ " ".concat(leadingPart).concat(alreadySeen).concat(circularPart).concat(current, "\n") +
5247
+ " ".concat(leadingSpace, "\\").concat(dashes, "/"));
5174
5248
  }
5175
5249
  options.seenObjects[options.seenObjects.length - 1].obj = value;
5176
5250
  }
@@ -5194,7 +5268,7 @@ var BSON = (function (exports) {
5194
5268
  if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) {
5195
5269
  // it's an integer
5196
5270
  if (Math.floor(value) === value) {
5197
- var int32Range = value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1, int64Range = value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1;
5271
+ var int32Range = value >= BSON_INT32_MIN && value <= BSON_INT32_MAX, int64Range = value >= BSON_INT64_MIN && value <= BSON_INT64_MAX;
5198
5272
  // interpret as being of the smallest BSON integer type that can represent the number exactly
5199
5273
  if (int32Range)
5200
5274
  return { $numberInt: value.toString() };
@@ -5249,7 +5323,18 @@ var BSON = (function (exports) {
5249
5323
  for (var name in doc) {
5250
5324
  options.seenObjects.push({ propertyName: name, obj: null });
5251
5325
  try {
5252
- _doc[name] = serializeValue(doc[name], options);
5326
+ var value = serializeValue(doc[name], options);
5327
+ if (name === '__proto__') {
5328
+ Object.defineProperty(_doc, name, {
5329
+ value: value,
5330
+ writable: true,
5331
+ enumerable: true,
5332
+ configurable: true
5333
+ });
5334
+ }
5335
+ else {
5336
+ _doc[name] = value;
5337
+ }
5253
5338
  }
5254
5339
  finally {
5255
5340
  options.seenObjects.pop();
@@ -5319,7 +5404,7 @@ var BSON = (function (exports) {
5319
5404
  finalOptions.relaxed = !finalOptions.strict;
5320
5405
  return JSON.parse(text, function (key, value) {
5321
5406
  if (key.indexOf('\x00') !== -1) {
5322
- throw new BSONError("BSON Document field names cannot contain null bytes, found: " + JSON.stringify(key));
5407
+ throw new BSONError("BSON Document field names cannot contain null bytes, found: ".concat(JSON.stringify(key)));
5323
5408
  }
5324
5409
  return deserializeValue(value, finalOptions);
5325
5410
  });
@@ -5508,85 +5593,6 @@ var BSON = (function (exports) {
5508
5593
  }());
5509
5594
  }
5510
5595
 
5511
- /** @internal */
5512
- var BSON_INT32_MAX = 0x7fffffff;
5513
- /** @internal */
5514
- var BSON_INT32_MIN = -0x80000000;
5515
- /** @internal */
5516
- var BSON_INT64_MAX = Math.pow(2, 63) - 1;
5517
- /** @internal */
5518
- var BSON_INT64_MIN = -Math.pow(2, 63);
5519
- /**
5520
- * Any integer up to 2^53 can be precisely represented by a double.
5521
- * @internal
5522
- */
5523
- var JS_INT_MAX = Math.pow(2, 53);
5524
- /**
5525
- * Any integer down to -2^53 can be precisely represented by a double.
5526
- * @internal
5527
- */
5528
- var JS_INT_MIN = -Math.pow(2, 53);
5529
- /** Number BSON Type @internal */
5530
- var BSON_DATA_NUMBER = 1;
5531
- /** String BSON Type @internal */
5532
- var BSON_DATA_STRING = 2;
5533
- /** Object BSON Type @internal */
5534
- var BSON_DATA_OBJECT = 3;
5535
- /** Array BSON Type @internal */
5536
- var BSON_DATA_ARRAY = 4;
5537
- /** Binary BSON Type @internal */
5538
- var BSON_DATA_BINARY = 5;
5539
- /** Binary BSON Type @internal */
5540
- var BSON_DATA_UNDEFINED = 6;
5541
- /** ObjectId BSON Type @internal */
5542
- var BSON_DATA_OID = 7;
5543
- /** Boolean BSON Type @internal */
5544
- var BSON_DATA_BOOLEAN = 8;
5545
- /** Date BSON Type @internal */
5546
- var BSON_DATA_DATE = 9;
5547
- /** null BSON Type @internal */
5548
- var BSON_DATA_NULL = 10;
5549
- /** RegExp BSON Type @internal */
5550
- var BSON_DATA_REGEXP = 11;
5551
- /** Code BSON Type @internal */
5552
- var BSON_DATA_DBPOINTER = 12;
5553
- /** Code BSON Type @internal */
5554
- var BSON_DATA_CODE = 13;
5555
- /** Symbol BSON Type @internal */
5556
- var BSON_DATA_SYMBOL = 14;
5557
- /** Code with Scope BSON Type @internal */
5558
- var BSON_DATA_CODE_W_SCOPE = 15;
5559
- /** 32 bit Integer BSON Type @internal */
5560
- var BSON_DATA_INT = 16;
5561
- /** Timestamp BSON Type @internal */
5562
- var BSON_DATA_TIMESTAMP = 17;
5563
- /** Long BSON Type @internal */
5564
- var BSON_DATA_LONG = 18;
5565
- /** Decimal128 BSON Type @internal */
5566
- var BSON_DATA_DECIMAL128 = 19;
5567
- /** MinKey BSON Type @internal */
5568
- var BSON_DATA_MIN_KEY = 0xff;
5569
- /** MaxKey BSON Type @internal */
5570
- var BSON_DATA_MAX_KEY = 0x7f;
5571
- /** Binary Default Type @internal */
5572
- var BSON_BINARY_SUBTYPE_DEFAULT = 0;
5573
- /** Binary Function Type @internal */
5574
- var BSON_BINARY_SUBTYPE_FUNCTION = 1;
5575
- /** Binary Byte Array Type @internal */
5576
- var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
5577
- /** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
5578
- var BSON_BINARY_SUBTYPE_UUID = 3;
5579
- /** Binary UUID Type @internal */
5580
- var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
5581
- /** Binary MD5 Type @internal */
5582
- var BSON_BINARY_SUBTYPE_MD5 = 5;
5583
- /** Encrypted BSON type @internal */
5584
- var BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
5585
- /** Column BSON type @internal */
5586
- var BSON_BINARY_SUBTYPE_COLUMN = 7;
5587
- /** Binary User Defined Type @internal */
5588
- var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
5589
-
5590
5596
  function calculateObjectSize$1(object, serializeFunctions, ignoreUndefined) {
5591
5597
  var totalLength = 4 + 1;
5592
5598
  if (Array.isArray(object)) {
@@ -5624,7 +5630,7 @@ var BSON = (function (exports) {
5624
5630
  if (Math.floor(value) === value &&
5625
5631
  value >= JS_INT_MIN &&
5626
5632
  value <= JS_INT_MAX) {
5627
- if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
5633
+ if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1) {
5628
5634
  // 32 bit
5629
5635
  return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (4 + 1);
5630
5636
  }
@@ -5685,13 +5691,14 @@ var BSON = (function (exports) {
5685
5691
  }
5686
5692
  }
5687
5693
  else if (value['_bsontype'] === 'Binary') {
5694
+ var binary = value;
5688
5695
  // Check what kind of subtype we have
5689
- if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5696
+ if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5690
5697
  return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
5691
- (value.position + 1 + 4 + 1 + 4));
5698
+ (binary.position + 1 + 4 + 1 + 4));
5692
5699
  }
5693
5700
  else {
5694
- return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1));
5701
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (binary.position + 1 + 4 + 1));
5695
5702
  }
5696
5703
  }
5697
5704
  else if (value['_bsontype'] === 'Symbol') {
@@ -5828,16 +5835,16 @@ var BSON = (function (exports) {
5828
5835
  (buffer[index + 2] << 16) |
5829
5836
  (buffer[index + 3] << 24);
5830
5837
  if (size < 5) {
5831
- throw new BSONError("bson size must be >= 5, is " + size);
5838
+ throw new BSONError("bson size must be >= 5, is ".concat(size));
5832
5839
  }
5833
5840
  if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
5834
- throw new BSONError("buffer length " + buffer.length + " must be >= bson size " + size);
5841
+ throw new BSONError("buffer length ".concat(buffer.length, " must be >= bson size ").concat(size));
5835
5842
  }
5836
5843
  if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
5837
- throw new BSONError("buffer length " + buffer.length + " must === bson size " + size);
5844
+ throw new BSONError("buffer length ".concat(buffer.length, " must === bson size ").concat(size));
5838
5845
  }
5839
5846
  if (size + index > buffer.byteLength) {
5840
- throw new BSONError("(bson size " + size + " + options.index " + index + " must be <= buffer length " + buffer.byteLength + ")");
5847
+ throw new BSONError("(bson size ".concat(size, " + options.index ").concat(index, " must be <= buffer length ").concat(buffer.byteLength, ")"));
5841
5848
  }
5842
5849
  // Illegal end value
5843
5850
  if (buffer[index + size - 1] !== 0) {
@@ -5914,6 +5921,7 @@ var BSON = (function (exports) {
5914
5921
  var done = false;
5915
5922
  var isPossibleDBRef = isArray ? false : null;
5916
5923
  // While we have more left data left keep parsing
5924
+ var dataview = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
5917
5925
  while (!done) {
5918
5926
  // Read the type
5919
5927
  var elementType = buffer[index++];
@@ -5974,11 +5982,11 @@ var BSON = (function (exports) {
5974
5982
  (buffer[index++] << 24);
5975
5983
  }
5976
5984
  else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
5977
- value = new Double(buffer.readDoubleLE(index));
5985
+ value = new Double(dataview.getFloat64(index, true));
5978
5986
  index = index + 8;
5979
5987
  }
5980
5988
  else if (elementType === BSON_DATA_NUMBER) {
5981
- value = buffer.readDoubleLE(index);
5989
+ value = dataview.getFloat64(index, true);
5982
5990
  index = index + 8;
5983
5991
  }
5984
5992
  else if (elementType === BSON_DATA_DATE) {
@@ -6124,6 +6132,9 @@ var BSON = (function (exports) {
6124
6132
  }
6125
6133
  else {
6126
6134
  value = new Binary(buffer.slice(index, index + binarySize), subType);
6135
+ if (subType === BSON_BINARY_SUBTYPE_UUID_NEW) {
6136
+ value = value.toUUID();
6137
+ }
6127
6138
  }
6128
6139
  }
6129
6140
  else {
@@ -6149,8 +6160,11 @@ var BSON = (function (exports) {
6149
6160
  if (promoteBuffers && promoteValues) {
6150
6161
  value = _buffer;
6151
6162
  }
6163
+ else if (subType === BSON_BINARY_SUBTYPE_UUID_NEW) {
6164
+ value = new Binary(buffer.slice(index, index + binarySize), subType).toUUID();
6165
+ }
6152
6166
  else {
6153
- value = new Binary(_buffer, subType);
6167
+ value = new Binary(buffer.slice(index, index + binarySize), subType);
6154
6168
  }
6155
6169
  }
6156
6170
  // Update the index
@@ -6376,7 +6390,7 @@ var BSON = (function (exports) {
6376
6390
  value = new DBRef(namespace, oid);
6377
6391
  }
6378
6392
  else {
6379
- throw new BSONError('Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"');
6393
+ throw new BSONError("Detected unknown BSON type ".concat(elementType.toString(16), " for fieldname \"").concat(name, "\""));
6380
6394
  }
6381
6395
  if (name === '__proto__') {
6382
6396
  Object.defineProperty(object, name, {
@@ -6414,10 +6428,12 @@ var BSON = (function (exports) {
6414
6428
  * @internal
6415
6429
  */
6416
6430
  function isolateEval(functionString, functionCache, object) {
6431
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
6417
6432
  if (!functionCache)
6418
6433
  return new Function(functionString);
6419
6434
  // Check for cache hit, eval if missing and return cached function
6420
6435
  if (functionCache[functionString] == null) {
6436
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
6421
6437
  functionCache[functionString] = new Function(functionString);
6422
6438
  }
6423
6439
  // Set the object
@@ -6439,74 +6455,6 @@ var BSON = (function (exports) {
6439
6455
  return value;
6440
6456
  }
6441
6457
 
6442
- // Copyright (c) 2008, Fair Oaks Labs, Inc.
6443
- function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
6444
- var e;
6445
- var m;
6446
- var c;
6447
- var bBE = endian === 'big';
6448
- var eLen = nBytes * 8 - mLen - 1;
6449
- var eMax = (1 << eLen) - 1;
6450
- var eBias = eMax >> 1;
6451
- var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
6452
- var i = bBE ? nBytes - 1 : 0;
6453
- var d = bBE ? -1 : 1;
6454
- var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
6455
- value = Math.abs(value);
6456
- if (isNaN(value) || value === Infinity) {
6457
- m = isNaN(value) ? 1 : 0;
6458
- e = eMax;
6459
- }
6460
- else {
6461
- e = Math.floor(Math.log(value) / Math.LN2);
6462
- if (value * (c = Math.pow(2, -e)) < 1) {
6463
- e--;
6464
- c *= 2;
6465
- }
6466
- if (e + eBias >= 1) {
6467
- value += rt / c;
6468
- }
6469
- else {
6470
- value += rt * Math.pow(2, 1 - eBias);
6471
- }
6472
- if (value * c >= 2) {
6473
- e++;
6474
- c /= 2;
6475
- }
6476
- if (e + eBias >= eMax) {
6477
- m = 0;
6478
- e = eMax;
6479
- }
6480
- else if (e + eBias >= 1) {
6481
- m = (value * c - 1) * Math.pow(2, mLen);
6482
- e = e + eBias;
6483
- }
6484
- else {
6485
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
6486
- e = 0;
6487
- }
6488
- }
6489
- if (isNaN(value))
6490
- m = 0;
6491
- while (mLen >= 8) {
6492
- buffer[offset + i] = m & 0xff;
6493
- i += d;
6494
- m /= 256;
6495
- mLen -= 8;
6496
- }
6497
- e = (e << mLen) | m;
6498
- if (isNaN(value))
6499
- e += 8;
6500
- eLen += mLen;
6501
- while (eLen > 0) {
6502
- buffer[offset + i] = e & 0xff;
6503
- i += d;
6504
- e /= 256;
6505
- eLen -= 8;
6506
- }
6507
- buffer[offset + i - d] |= s * 128;
6508
- }
6509
-
6510
6458
  var regexp = /\x00/; // eslint-disable-line no-control-regex
6511
6459
  var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
6512
6460
  /*
@@ -6537,12 +6485,14 @@ var BSON = (function (exports) {
6537
6485
  buffer[index++] = 0;
6538
6486
  return index;
6539
6487
  }
6488
+ var SPACE_FOR_FLOAT64 = new Uint8Array(8);
6489
+ var DV_FOR_FLOAT64 = new DataView(SPACE_FOR_FLOAT64.buffer, SPACE_FOR_FLOAT64.byteOffset, SPACE_FOR_FLOAT64.byteLength);
6540
6490
  function serializeNumber(buffer, key, value, index, isArray) {
6541
6491
  // We have an integer value
6542
6492
  // TODO(NODE-2529): Add support for big int
6543
6493
  if (Number.isInteger(value) &&
6544
- value >= BSON_INT32_MIN &&
6545
- value <= BSON_INT32_MAX) {
6494
+ value >= BSON_INT32_MIN$1 &&
6495
+ value <= BSON_INT32_MAX$1) {
6546
6496
  // If the value fits in 32 bits encode as int32
6547
6497
  // Set int type 32 bits or less
6548
6498
  buffer[index++] = BSON_DATA_INT;
@@ -6570,7 +6520,8 @@ var BSON = (function (exports) {
6570
6520
  index = index + numberOfWrittenBytes;
6571
6521
  buffer[index++] = 0;
6572
6522
  // Write float
6573
- writeIEEE754(buffer, value, index, 'little', 52, 8);
6523
+ DV_FOR_FLOAT64.setFloat64(0, value, true);
6524
+ buffer.set(SPACE_FOR_FLOAT64, index);
6574
6525
  // Adjust index
6575
6526
  index = index + 8;
6576
6527
  }
@@ -6849,7 +6800,8 @@ var BSON = (function (exports) {
6849
6800
  index = index + numberOfWrittenBytes;
6850
6801
  buffer[index++] = 0;
6851
6802
  // Write float
6852
- writeIEEE754(buffer, value.value, index, 'little', 52, 8);
6803
+ DV_FOR_FLOAT64.setFloat64(0, value.value, true);
6804
+ buffer.set(SPACE_FOR_FLOAT64, index);
6853
6805
  // Adjust index
6854
6806
  index = index + 8;
6855
6807
  return index;
@@ -7059,7 +7011,7 @@ var BSON = (function (exports) {
7059
7011
  if (Array.isArray(object)) {
7060
7012
  // Get object keys
7061
7013
  for (var i = 0; i < object.length; i++) {
7062
- var key = '' + i;
7014
+ var key = "".concat(i);
7063
7015
  var value = object[i];
7064
7016
  // Is there an override value
7065
7017
  if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
@@ -7134,7 +7086,7 @@ var BSON = (function (exports) {
7134
7086
  index = serializeMinMax(buffer, key, value, index, true);
7135
7087
  }
7136
7088
  else if (typeof value['_bsontype'] !== 'undefined') {
7137
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7089
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7138
7090
  }
7139
7091
  }
7140
7092
  }
@@ -7233,7 +7185,7 @@ var BSON = (function (exports) {
7233
7185
  index = serializeMinMax(buffer, key, value, index);
7234
7186
  }
7235
7187
  else if (typeof value['_bsontype'] !== 'undefined') {
7236
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7188
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7237
7189
  }
7238
7190
  }
7239
7191
  }
@@ -7338,7 +7290,7 @@ var BSON = (function (exports) {
7338
7290
  index = serializeMinMax(buffer, key, value, index);
7339
7291
  }
7340
7292
  else if (typeof value['_bsontype'] !== 'undefined') {
7341
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7293
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7342
7294
  }
7343
7295
  }
7344
7296
  }
@@ -7550,10 +7502,10 @@ var BSON = (function (exports) {
7550
7502
  exports.BSON_DATA_SYMBOL = BSON_DATA_SYMBOL;
7551
7503
  exports.BSON_DATA_TIMESTAMP = BSON_DATA_TIMESTAMP;
7552
7504
  exports.BSON_DATA_UNDEFINED = BSON_DATA_UNDEFINED;
7553
- exports.BSON_INT32_MAX = BSON_INT32_MAX;
7554
- exports.BSON_INT32_MIN = BSON_INT32_MIN;
7555
- exports.BSON_INT64_MAX = BSON_INT64_MAX;
7556
- exports.BSON_INT64_MIN = BSON_INT64_MIN;
7505
+ exports.BSON_INT32_MAX = BSON_INT32_MAX$1;
7506
+ exports.BSON_INT32_MIN = BSON_INT32_MIN$1;
7507
+ exports.BSON_INT64_MAX = BSON_INT64_MAX$1;
7508
+ exports.BSON_INT64_MIN = BSON_INT64_MIN$1;
7557
7509
  exports.Binary = Binary;
7558
7510
  exports.Code = Code;
7559
7511
  exports.DBRef = DBRef;