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
@@ -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) {
@@ -2272,174 +2265,84 @@ var bufferToUuidHexString = function (buffer, includeDashes) {
2272
2265
  : buffer.toString('hex');
2273
2266
  };
2274
2267
 
2275
- var BYTE_LENGTH = 16;
2276
- var kId$1 = Symbol('id');
2268
+ /** @internal */
2269
+ var BSON_INT32_MAX$1 = 0x7fffffff;
2270
+ /** @internal */
2271
+ var BSON_INT32_MIN$1 = -0x80000000;
2272
+ /** @internal */
2273
+ var BSON_INT64_MAX$1 = Math.pow(2, 63) - 1;
2274
+ /** @internal */
2275
+ var BSON_INT64_MIN$1 = -Math.pow(2, 63);
2277
2276
  /**
2278
- * A class representation of the BSON UUID type.
2279
- * @public
2277
+ * Any integer up to 2^53 can be precisely represented by a double.
2278
+ * @internal
2280
2279
  */
2281
- var UUID = /** @class */ (function () {
2282
- /**
2283
- * Create an UUID type
2284
- *
2285
- * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
2286
- */
2287
- function UUID(input) {
2288
- if (typeof input === 'undefined') {
2289
- // The most common use case (blank id, new UUID() instance)
2290
- this.id = UUID.generate();
2291
- }
2292
- else if (input instanceof UUID) {
2293
- this[kId$1] = buffer_1.from(input.id);
2294
- this.__id = input.__id;
2295
- }
2296
- else if (ArrayBuffer.isView(input) && input.byteLength === BYTE_LENGTH) {
2297
- this.id = ensureBuffer(input);
2298
- }
2299
- else if (typeof input === 'string') {
2300
- this.id = uuidHexStringToBuffer(input);
2301
- }
2302
- else {
2303
- 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).');
2304
- }
2305
- }
2306
- Object.defineProperty(UUID.prototype, "id", {
2307
- /**
2308
- * The UUID bytes
2309
- * @readonly
2310
- */
2311
- get: function () {
2312
- return this[kId$1];
2313
- },
2314
- set: function (value) {
2315
- this[kId$1] = value;
2316
- if (UUID.cacheHexString) {
2317
- this.__id = bufferToUuidHexString(value);
2318
- }
2319
- },
2320
- enumerable: false,
2321
- configurable: true
2322
- });
2323
- /**
2324
- * Generate a 16 byte uuid v4 buffer used in UUIDs
2325
- */
2326
- /**
2327
- * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
2328
- * @param includeDashes - should the string exclude dash-separators.
2329
- * */
2330
- UUID.prototype.toHexString = function (includeDashes) {
2331
- if (includeDashes === void 0) { includeDashes = true; }
2332
- if (UUID.cacheHexString && this.__id) {
2333
- return this.__id;
2334
- }
2335
- var uuidHexString = bufferToUuidHexString(this.id, includeDashes);
2336
- if (UUID.cacheHexString) {
2337
- this.__id = uuidHexString;
2338
- }
2339
- return uuidHexString;
2340
- };
2341
- /**
2342
- * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
2343
- */
2344
- UUID.prototype.toString = function (encoding) {
2345
- return encoding ? this.id.toString(encoding) : this.toHexString();
2346
- };
2347
- /**
2348
- * Converts the id into its JSON string representation.
2349
- * A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
2350
- */
2351
- UUID.prototype.toJSON = function () {
2352
- return this.toHexString();
2353
- };
2354
- /**
2355
- * Compares the equality of this UUID with `otherID`.
2356
- *
2357
- * @param otherId - UUID instance to compare against.
2358
- */
2359
- UUID.prototype.equals = function (otherId) {
2360
- if (!otherId) {
2361
- return false;
2362
- }
2363
- if (otherId instanceof UUID) {
2364
- return otherId.id.equals(this.id);
2365
- }
2366
- try {
2367
- return new UUID(otherId).id.equals(this.id);
2368
- }
2369
- catch (_a) {
2370
- return false;
2371
- }
2372
- };
2373
- /**
2374
- * Creates a Binary instance from the current UUID.
2375
- */
2376
- UUID.prototype.toBinary = function () {
2377
- return new Binary(this.id, Binary.SUBTYPE_UUID);
2378
- };
2379
- /**
2380
- * Generates a populated buffer containing a v4 uuid
2381
- */
2382
- UUID.generate = function () {
2383
- var bytes = randomBytes(BYTE_LENGTH);
2384
- // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
2385
- // Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
2386
- bytes[6] = (bytes[6] & 0x0f) | 0x40;
2387
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
2388
- return buffer_1.from(bytes);
2389
- };
2390
- /**
2391
- * Checks if a value is a valid bson UUID
2392
- * @param input - UUID, string or Buffer to validate.
2393
- */
2394
- UUID.isValid = function (input) {
2395
- if (!input) {
2396
- return false;
2397
- }
2398
- if (input instanceof UUID) {
2399
- return true;
2400
- }
2401
- if (typeof input === 'string') {
2402
- return uuidValidateString(input);
2403
- }
2404
- if (isUint8Array(input)) {
2405
- // check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
2406
- if (input.length !== BYTE_LENGTH) {
2407
- return false;
2408
- }
2409
- try {
2410
- // get this byte as hex: xxxxxxxx-xxxx-XXxx-xxxx-xxxxxxxxxxxx
2411
- // check first part as uuid version: xxxxxxxx-xxxx-Xxxx-xxxx-xxxxxxxxxxxx
2412
- return parseInt(input[6].toString(16)[0], 10) === Binary.SUBTYPE_UUID;
2413
- }
2414
- catch (_a) {
2415
- return false;
2416
- }
2417
- }
2418
- return false;
2419
- };
2420
- /**
2421
- * Creates an UUID from a hex string representation of an UUID.
2422
- * @param hexString - 32 or 36 character hex string (dashes excluded/included).
2423
- */
2424
- UUID.createFromHexString = function (hexString) {
2425
- var buffer = uuidHexStringToBuffer(hexString);
2426
- return new UUID(buffer);
2427
- };
2428
- /**
2429
- * Converts to a string representation of this Id.
2430
- *
2431
- * @returns return the 36 character hex string representation.
2432
- * @internal
2433
- */
2434
- UUID.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
2435
- return this.inspect();
2436
- };
2437
- UUID.prototype.inspect = function () {
2438
- return "new UUID(\"" + this.toHexString() + "\")";
2439
- };
2440
- return UUID;
2441
- }());
2442
- Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
2280
+ var JS_INT_MAX = Math.pow(2, 53);
2281
+ /**
2282
+ * Any integer down to -2^53 can be precisely represented by a double.
2283
+ * @internal
2284
+ */
2285
+ var JS_INT_MIN = -Math.pow(2, 53);
2286
+ /** Number BSON Type @internal */
2287
+ var BSON_DATA_NUMBER = 1;
2288
+ /** String BSON Type @internal */
2289
+ var BSON_DATA_STRING = 2;
2290
+ /** Object BSON Type @internal */
2291
+ var BSON_DATA_OBJECT = 3;
2292
+ /** Array BSON Type @internal */
2293
+ var BSON_DATA_ARRAY = 4;
2294
+ /** Binary BSON Type @internal */
2295
+ var BSON_DATA_BINARY = 5;
2296
+ /** Binary BSON Type @internal */
2297
+ var BSON_DATA_UNDEFINED = 6;
2298
+ /** ObjectId BSON Type @internal */
2299
+ var BSON_DATA_OID = 7;
2300
+ /** Boolean BSON Type @internal */
2301
+ var BSON_DATA_BOOLEAN = 8;
2302
+ /** Date BSON Type @internal */
2303
+ var BSON_DATA_DATE = 9;
2304
+ /** null BSON Type @internal */
2305
+ var BSON_DATA_NULL = 10;
2306
+ /** RegExp BSON Type @internal */
2307
+ var BSON_DATA_REGEXP = 11;
2308
+ /** Code BSON Type @internal */
2309
+ var BSON_DATA_DBPOINTER = 12;
2310
+ /** Code BSON Type @internal */
2311
+ var BSON_DATA_CODE = 13;
2312
+ /** Symbol BSON Type @internal */
2313
+ var BSON_DATA_SYMBOL = 14;
2314
+ /** Code with Scope BSON Type @internal */
2315
+ var BSON_DATA_CODE_W_SCOPE = 15;
2316
+ /** 32 bit Integer BSON Type @internal */
2317
+ var BSON_DATA_INT = 16;
2318
+ /** Timestamp BSON Type @internal */
2319
+ var BSON_DATA_TIMESTAMP = 17;
2320
+ /** Long BSON Type @internal */
2321
+ var BSON_DATA_LONG = 18;
2322
+ /** Decimal128 BSON Type @internal */
2323
+ var BSON_DATA_DECIMAL128 = 19;
2324
+ /** MinKey BSON Type @internal */
2325
+ var BSON_DATA_MIN_KEY = 0xff;
2326
+ /** MaxKey BSON Type @internal */
2327
+ var BSON_DATA_MAX_KEY = 0x7f;
2328
+ /** Binary Default Type @internal */
2329
+ var BSON_BINARY_SUBTYPE_DEFAULT = 0;
2330
+ /** Binary Function Type @internal */
2331
+ var BSON_BINARY_SUBTYPE_FUNCTION = 1;
2332
+ /** Binary Byte Array Type @internal */
2333
+ var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
2334
+ /** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
2335
+ var BSON_BINARY_SUBTYPE_UUID = 3;
2336
+ /** Binary UUID Type @internal */
2337
+ var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
2338
+ /** Binary MD5 Type @internal */
2339
+ var BSON_BINARY_SUBTYPE_MD5 = 5;
2340
+ /** Encrypted BSON type @internal */
2341
+ var BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
2342
+ /** Column BSON type @internal */
2343
+ var BSON_BINARY_SUBTYPE_COLUMN = 7;
2344
+ /** Binary User Defined Type @internal */
2345
+ var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
2443
2346
 
2444
2347
  /**
2445
2348
  * A class representation of the BSON Binary type.
@@ -2448,6 +2351,13 @@ Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
2448
2351
  */
2449
2352
  var Binary = /** @class */ (function () {
2450
2353
  /**
2354
+ * Create a new Binary instance.
2355
+ *
2356
+ * This constructor can accept a string as its first argument. In this case,
2357
+ * this string will be encoded using ISO-8859-1, **not** using UTF-8.
2358
+ * This is almost certainly not what you want. Use `new Binary(Buffer.from(string))`
2359
+ * instead to convert the string to a Buffer using UTF-8 first.
2360
+ *
2451
2361
  * @param buffer - a buffer object containing the binary data.
2452
2362
  * @param subType - the option binary type.
2453
2363
  */
@@ -2607,7 +2517,7 @@ var Binary = /** @class */ (function () {
2607
2517
  if (this.sub_type === Binary.SUBTYPE_UUID) {
2608
2518
  return new UUID(this.buffer.slice(0, this.position));
2609
2519
  }
2610
- throw new BSONError("Binary sub_type \"" + this.sub_type + "\" is not supported for converting to UUID. Only \"" + Binary.SUBTYPE_UUID + "\" is currently supported.");
2520
+ 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."));
2611
2521
  };
2612
2522
  /** @internal */
2613
2523
  Binary.fromExtendedJSON = function (doc, options) {
@@ -2631,9 +2541,9 @@ var Binary = /** @class */ (function () {
2631
2541
  data = uuidHexStringToBuffer(doc.$uuid);
2632
2542
  }
2633
2543
  if (!data) {
2634
- throw new BSONTypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc));
2544
+ throw new BSONTypeError("Unexpected Binary Extended JSON format ".concat(JSON.stringify(doc)));
2635
2545
  }
2636
- return new Binary(data, type);
2546
+ return type === BSON_BINARY_SUBTYPE_UUID_NEW ? new UUID(data) : new Binary(data, type);
2637
2547
  };
2638
2548
  /** @internal */
2639
2549
  Binary.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
@@ -2641,7 +2551,7 @@ var Binary = /** @class */ (function () {
2641
2551
  };
2642
2552
  Binary.prototype.inspect = function () {
2643
2553
  var asBuffer = this.value(true);
2644
- return "new Binary(Buffer.from(\"" + asBuffer.toString('hex') + "\", \"hex\"), " + this.sub_type + ")";
2554
+ return "new Binary(Buffer.from(\"".concat(asBuffer.toString('hex'), "\", \"hex\"), ").concat(this.sub_type, ")");
2645
2555
  };
2646
2556
  /**
2647
2557
  * Binary default subtype
@@ -2671,6 +2581,168 @@ var Binary = /** @class */ (function () {
2671
2581
  return Binary;
2672
2582
  }());
2673
2583
  Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' });
2584
+ var UUID_BYTE_LENGTH = 16;
2585
+ /**
2586
+ * A class representation of the BSON UUID type.
2587
+ * @public
2588
+ */
2589
+ var UUID = /** @class */ (function (_super) {
2590
+ __extends(UUID, _super);
2591
+ /**
2592
+ * Create an UUID type
2593
+ *
2594
+ * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
2595
+ */
2596
+ function UUID(input) {
2597
+ var _this = this;
2598
+ var bytes;
2599
+ var hexStr;
2600
+ if (input == null) {
2601
+ bytes = UUID.generate();
2602
+ }
2603
+ else if (input instanceof UUID) {
2604
+ bytes = buffer_1.from(input.buffer);
2605
+ hexStr = input.__id;
2606
+ }
2607
+ else if (ArrayBuffer.isView(input) && input.byteLength === UUID_BYTE_LENGTH) {
2608
+ bytes = ensureBuffer(input);
2609
+ }
2610
+ else if (typeof input === 'string') {
2611
+ bytes = uuidHexStringToBuffer(input);
2612
+ }
2613
+ else {
2614
+ 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).');
2615
+ }
2616
+ _this = _super.call(this, bytes, BSON_BINARY_SUBTYPE_UUID_NEW) || this;
2617
+ _this.__id = hexStr;
2618
+ return _this;
2619
+ }
2620
+ Object.defineProperty(UUID.prototype, "id", {
2621
+ /**
2622
+ * The UUID bytes
2623
+ * @readonly
2624
+ */
2625
+ get: function () {
2626
+ return this.buffer;
2627
+ },
2628
+ set: function (value) {
2629
+ this.buffer = value;
2630
+ if (UUID.cacheHexString) {
2631
+ this.__id = bufferToUuidHexString(value);
2632
+ }
2633
+ },
2634
+ enumerable: false,
2635
+ configurable: true
2636
+ });
2637
+ /**
2638
+ * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
2639
+ * @param includeDashes - should the string exclude dash-separators.
2640
+ * */
2641
+ UUID.prototype.toHexString = function (includeDashes) {
2642
+ if (includeDashes === void 0) { includeDashes = true; }
2643
+ if (UUID.cacheHexString && this.__id) {
2644
+ return this.__id;
2645
+ }
2646
+ var uuidHexString = bufferToUuidHexString(this.id, includeDashes);
2647
+ if (UUID.cacheHexString) {
2648
+ this.__id = uuidHexString;
2649
+ }
2650
+ return uuidHexString;
2651
+ };
2652
+ /**
2653
+ * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
2654
+ */
2655
+ UUID.prototype.toString = function (encoding) {
2656
+ return encoding ? this.id.toString(encoding) : this.toHexString();
2657
+ };
2658
+ /**
2659
+ * Converts the id into its JSON string representation.
2660
+ * A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
2661
+ */
2662
+ UUID.prototype.toJSON = function () {
2663
+ return this.toHexString();
2664
+ };
2665
+ /**
2666
+ * Compares the equality of this UUID with `otherID`.
2667
+ *
2668
+ * @param otherId - UUID instance to compare against.
2669
+ */
2670
+ UUID.prototype.equals = function (otherId) {
2671
+ if (!otherId) {
2672
+ return false;
2673
+ }
2674
+ if (otherId instanceof UUID) {
2675
+ return otherId.id.equals(this.id);
2676
+ }
2677
+ try {
2678
+ return new UUID(otherId).id.equals(this.id);
2679
+ }
2680
+ catch (_a) {
2681
+ return false;
2682
+ }
2683
+ };
2684
+ /**
2685
+ * Creates a Binary instance from the current UUID.
2686
+ */
2687
+ UUID.prototype.toBinary = function () {
2688
+ return new Binary(this.id, Binary.SUBTYPE_UUID);
2689
+ };
2690
+ /**
2691
+ * Generates a populated buffer containing a v4 uuid
2692
+ */
2693
+ UUID.generate = function () {
2694
+ var bytes = randomBytes(UUID_BYTE_LENGTH);
2695
+ // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
2696
+ // Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
2697
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
2698
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
2699
+ return buffer_1.from(bytes);
2700
+ };
2701
+ /**
2702
+ * Checks if a value is a valid bson UUID
2703
+ * @param input - UUID, string or Buffer to validate.
2704
+ */
2705
+ UUID.isValid = function (input) {
2706
+ if (!input) {
2707
+ return false;
2708
+ }
2709
+ if (input instanceof UUID) {
2710
+ return true;
2711
+ }
2712
+ if (typeof input === 'string') {
2713
+ return uuidValidateString(input);
2714
+ }
2715
+ if (isUint8Array(input)) {
2716
+ // check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
2717
+ if (input.length !== UUID_BYTE_LENGTH) {
2718
+ return false;
2719
+ }
2720
+ return (input[6] & 0xf0) === 0x40 && (input[8] & 0x80) === 0x80;
2721
+ }
2722
+ return false;
2723
+ };
2724
+ /**
2725
+ * Creates an UUID from a hex string representation of an UUID.
2726
+ * @param hexString - 32 or 36 character hex string (dashes excluded/included).
2727
+ */
2728
+ UUID.createFromHexString = function (hexString) {
2729
+ var buffer = uuidHexStringToBuffer(hexString);
2730
+ return new UUID(buffer);
2731
+ };
2732
+ /**
2733
+ * Converts to a string representation of this Id.
2734
+ *
2735
+ * @returns return the 36 character hex string representation.
2736
+ * @internal
2737
+ */
2738
+ UUID.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
2739
+ return this.inspect();
2740
+ };
2741
+ UUID.prototype.inspect = function () {
2742
+ return "new UUID(\"".concat(this.toHexString(), "\")");
2743
+ };
2744
+ return UUID;
2745
+ }(Binary));
2674
2746
 
2675
2747
  /**
2676
2748
  * A class representation of the BSON Code type.
@@ -2708,7 +2780,7 @@ var Code = /** @class */ (function () {
2708
2780
  };
2709
2781
  Code.prototype.inspect = function () {
2710
2782
  var codeJson = this.toJSON();
2711
- return "new Code(\"" + codeJson.code + "\"" + (codeJson.scope ? ", " + JSON.stringify(codeJson.scope) : '') + ")";
2783
+ return "new Code(\"".concat(String(codeJson.code), "\"").concat(codeJson.scope ? ", ".concat(JSON.stringify(codeJson.scope)) : '', ")");
2712
2784
  };
2713
2785
  return Code;
2714
2786
  }());
@@ -2799,7 +2871,7 @@ var DBRef = /** @class */ (function () {
2799
2871
  DBRef.prototype.inspect = function () {
2800
2872
  // NOTE: if OID is an ObjectId class it will just print the oid string.
2801
2873
  var oid = this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString();
2802
- return "new DBRef(\"" + this.namespace + "\", new ObjectId(\"" + oid + "\")" + (this.db ? ", \"" + this.db + "\"" : '') + ")";
2874
+ return "new DBRef(\"".concat(this.namespace, "\", new ObjectId(\"").concat(String(oid), "\")").concat(this.db ? ", \"".concat(this.db, "\"") : '', ")");
2803
2875
  };
2804
2876
  return DBRef;
2805
2877
  }());
@@ -3036,7 +3108,6 @@ var Long = /** @class */ (function () {
3036
3108
  /**
3037
3109
  * Tests if the specified object is a Long.
3038
3110
  */
3039
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
3040
3111
  Long.isLong = function (value) {
3041
3112
  return isObjectLike(value) && value['__isLong__'] === true;
3042
3113
  };
@@ -3193,6 +3264,7 @@ var Long = /** @class */ (function () {
3193
3264
  // into the result, and subtract it from the remainder. It is critical that
3194
3265
  // the approximate value is less than or equal to the real value so that the
3195
3266
  // remainder never becomes negative.
3267
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3196
3268
  rem = this;
3197
3269
  while (rem.gte(divisor)) {
3198
3270
  // Approximate the result of division. This may be a little greater or
@@ -3676,7 +3748,7 @@ var Long = /** @class */ (function () {
3676
3748
  return this.inspect();
3677
3749
  };
3678
3750
  Long.prototype.inspect = function () {
3679
- return "new Long(\"" + this.toString() + "\"" + (this.unsigned ? ', true' : '') + ")";
3751
+ return "new Long(\"".concat(this.toString(), "\"").concat(this.unsigned ? ', true' : '', ")");
3680
3752
  };
3681
3753
  Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
3682
3754
  /** Maximum unsigned value. */
@@ -3787,7 +3859,7 @@ function lessThan(left, right) {
3787
3859
  return false;
3788
3860
  }
3789
3861
  function invalidErr(string, message) {
3790
- throw new BSONTypeError("\"" + string + "\" is not a valid Decimal128 string - " + message);
3862
+ throw new BSONTypeError("\"".concat(string, "\" is not a valid Decimal128 string - ").concat(message));
3791
3863
  }
3792
3864
  /**
3793
3865
  * A class representation of the BSON Decimal128 type.
@@ -4285,35 +4357,35 @@ var Decimal128 = /** @class */ (function () {
4285
4357
  // as + or - 0 and using the non-scientific exponent (this is for the "invalid
4286
4358
  // representation should be treated as 0/-0" spec cases in decimal128-1.json)
4287
4359
  if (significand_digits > 34) {
4288
- string.push("" + 0);
4360
+ string.push("".concat(0));
4289
4361
  if (exponent > 0)
4290
- string.push('E+' + exponent);
4362
+ string.push("E+".concat(exponent));
4291
4363
  else if (exponent < 0)
4292
- string.push('E' + exponent);
4364
+ string.push("E".concat(exponent));
4293
4365
  return string.join('');
4294
4366
  }
4295
- string.push("" + significand[index++]);
4367
+ string.push("".concat(significand[index++]));
4296
4368
  significand_digits = significand_digits - 1;
4297
4369
  if (significand_digits) {
4298
4370
  string.push('.');
4299
4371
  }
4300
4372
  for (var i = 0; i < significand_digits; i++) {
4301
- string.push("" + significand[index++]);
4373
+ string.push("".concat(significand[index++]));
4302
4374
  }
4303
4375
  // Exponent
4304
4376
  string.push('E');
4305
4377
  if (scientific_exponent > 0) {
4306
- string.push('+' + scientific_exponent);
4378
+ string.push("+".concat(scientific_exponent));
4307
4379
  }
4308
4380
  else {
4309
- string.push("" + scientific_exponent);
4381
+ string.push("".concat(scientific_exponent));
4310
4382
  }
4311
4383
  }
4312
4384
  else {
4313
4385
  // Regular format with no decimal place
4314
4386
  if (exponent >= 0) {
4315
4387
  for (var i = 0; i < significand_digits; i++) {
4316
- string.push("" + significand[index++]);
4388
+ string.push("".concat(significand[index++]));
4317
4389
  }
4318
4390
  }
4319
4391
  else {
@@ -4321,7 +4393,7 @@ var Decimal128 = /** @class */ (function () {
4321
4393
  // non-zero digits before radix
4322
4394
  if (radix_position > 0) {
4323
4395
  for (var i = 0; i < radix_position; i++) {
4324
- string.push("" + significand[index++]);
4396
+ string.push("".concat(significand[index++]));
4325
4397
  }
4326
4398
  }
4327
4399
  else {
@@ -4333,7 +4405,7 @@ var Decimal128 = /** @class */ (function () {
4333
4405
  string.push('0');
4334
4406
  }
4335
4407
  for (var i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
4336
- string.push("" + significand[index++]);
4408
+ string.push("".concat(significand[index++]));
4337
4409
  }
4338
4410
  }
4339
4411
  }
@@ -4355,7 +4427,7 @@ var Decimal128 = /** @class */ (function () {
4355
4427
  return this.inspect();
4356
4428
  };
4357
4429
  Decimal128.prototype.inspect = function () {
4358
- return "new Decimal128(\"" + this.toString() + "\")";
4430
+ return "new Decimal128(\"".concat(this.toString(), "\")");
4359
4431
  };
4360
4432
  return Decimal128;
4361
4433
  }());
@@ -4402,7 +4474,7 @@ var Double = /** @class */ (function () {
4402
4474
  // NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
4403
4475
  // explicitly provided `-0` then we need to ensure the sign makes it into the output
4404
4476
  if (Object.is(Math.sign(this.value), -0)) {
4405
- return { $numberDouble: "-" + this.value.toFixed(1) };
4477
+ return { $numberDouble: "-".concat(this.value.toFixed(1)) };
4406
4478
  }
4407
4479
  var $numberDouble;
4408
4480
  if (Number.isInteger(this.value)) {
@@ -4427,7 +4499,7 @@ var Double = /** @class */ (function () {
4427
4499
  };
4428
4500
  Double.prototype.inspect = function () {
4429
4501
  var eJSON = this.toExtendedJSON();
4430
- return "new Double(" + eJSON.$numberDouble + ")";
4502
+ return "new Double(".concat(eJSON.$numberDouble, ")");
4431
4503
  };
4432
4504
  return Double;
4433
4505
  }());
@@ -4481,7 +4553,7 @@ var Int32 = /** @class */ (function () {
4481
4553
  return this.inspect();
4482
4554
  };
4483
4555
  Int32.prototype.inspect = function () {
4484
- return "new Int32(" + this.valueOf() + ")";
4556
+ return "new Int32(".concat(this.valueOf(), ")");
4485
4557
  };
4486
4558
  return Int32;
4487
4559
  }());
@@ -4587,7 +4659,8 @@ var ObjectId = /** @class */ (function () {
4587
4659
  this[kId] = ObjectId.generate(typeof workingId === 'number' ? workingId : undefined);
4588
4660
  }
4589
4661
  else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
4590
- this[kId] = ensureBuffer(workingId);
4662
+ // If intstanceof matches we can escape calling ensure buffer in Node.js environments
4663
+ this[kId] = workingId instanceof buffer_1 ? workingId : ensureBuffer(workingId);
4591
4664
  }
4592
4665
  else if (typeof workingId === 'string') {
4593
4666
  if (workingId.length === 12) {
@@ -4814,7 +4887,7 @@ var ObjectId = /** @class */ (function () {
4814
4887
  return this.inspect();
4815
4888
  };
4816
4889
  ObjectId.prototype.inspect = function () {
4817
- return "new ObjectId(\"" + this.toHexString() + "\")";
4890
+ return "new ObjectId(\"".concat(this.toHexString(), "\")");
4818
4891
  };
4819
4892
  /** @internal */
4820
4893
  ObjectId.index = Math.floor(Math.random() * 0xffffff);
@@ -4854,10 +4927,10 @@ var BSONRegExp = /** @class */ (function () {
4854
4927
  this.pattern = pattern;
4855
4928
  this.options = alphabetize(options !== null && options !== void 0 ? options : '');
4856
4929
  if (this.pattern.indexOf('\x00') !== -1) {
4857
- throw new BSONError("BSON Regex patterns cannot contain null bytes, found: " + JSON.stringify(this.pattern));
4930
+ throw new BSONError("BSON Regex patterns cannot contain null bytes, found: ".concat(JSON.stringify(this.pattern)));
4858
4931
  }
4859
4932
  if (this.options.indexOf('\x00') !== -1) {
4860
- throw new BSONError("BSON Regex options cannot contain null bytes, found: " + JSON.stringify(this.options));
4933
+ throw new BSONError("BSON Regex options cannot contain null bytes, found: ".concat(JSON.stringify(this.options)));
4861
4934
  }
4862
4935
  // Validate options
4863
4936
  for (var i = 0; i < this.options.length; i++) {
@@ -4867,7 +4940,7 @@ var BSONRegExp = /** @class */ (function () {
4867
4940
  this.options[i] === 'l' ||
4868
4941
  this.options[i] === 's' ||
4869
4942
  this.options[i] === 'u')) {
4870
- throw new BSONError("The regular expression option [" + this.options[i] + "] is not supported");
4943
+ throw new BSONError("The regular expression option [".concat(this.options[i], "] is not supported"));
4871
4944
  }
4872
4945
  }
4873
4946
  }
@@ -4898,7 +4971,7 @@ var BSONRegExp = /** @class */ (function () {
4898
4971
  if ('$regularExpression' in doc) {
4899
4972
  return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
4900
4973
  }
4901
- throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: " + JSON.stringify(doc));
4974
+ throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(doc)));
4902
4975
  };
4903
4976
  return BSONRegExp;
4904
4977
  }());
@@ -4927,7 +5000,7 @@ var BSONSymbol = /** @class */ (function () {
4927
5000
  };
4928
5001
  /** @internal */
4929
5002
  BSONSymbol.prototype.inspect = function () {
4930
- return "new BSONSymbol(\"" + this.value + "\")";
5003
+ return "new BSONSymbol(\"".concat(this.value, "\")");
4931
5004
  };
4932
5005
  BSONSymbol.prototype.toJSON = function () {
4933
5006
  return this.value;
@@ -4959,7 +5032,7 @@ var Timestamp = /** @class */ (function (_super) {
4959
5032
  function Timestamp(low, high) {
4960
5033
  var _this = this;
4961
5034
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4962
- ///@ts-expect-error
5035
+ // @ts-expect-error
4963
5036
  if (!(_this instanceof Timestamp))
4964
5037
  return new Timestamp(low, high);
4965
5038
  if (Long.isLong(low)) {
@@ -5023,7 +5096,7 @@ var Timestamp = /** @class */ (function (_super) {
5023
5096
  return this.inspect();
5024
5097
  };
5025
5098
  Timestamp.prototype.inspect = function () {
5026
- return "new Timestamp({ t: " + this.getHighBits() + ", i: " + this.getLowBits() + " })";
5099
+ return "new Timestamp({ t: ".concat(this.getHighBits(), ", i: ").concat(this.getLowBits(), " })");
5027
5100
  };
5028
5101
  Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
5029
5102
  return Timestamp;
@@ -5033,11 +5106,12 @@ function isBSONType(value) {
5033
5106
  return (isObjectLike(value) && Reflect.has(value, '_bsontype') && typeof value._bsontype === 'string');
5034
5107
  }
5035
5108
  // INT32 boundaries
5036
- var BSON_INT32_MAX$1 = 0x7fffffff;
5037
- var BSON_INT32_MIN$1 = -0x80000000;
5109
+ var BSON_INT32_MAX = 0x7fffffff;
5110
+ var BSON_INT32_MIN = -0x80000000;
5038
5111
  // INT64 boundaries
5039
- var BSON_INT64_MAX$1 = 0x7fffffffffffffff;
5040
- var BSON_INT64_MIN$1 = -0x8000000000000000;
5112
+ // const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
5113
+ var BSON_INT64_MAX = 0x8000000000000000;
5114
+ var BSON_INT64_MIN = -0x8000000000000000;
5041
5115
  // all the types where we don't need to do any special processing and can just pass the EJSON
5042
5116
  //straight to type.fromExtendedJSON
5043
5117
  var keysToCodecs = {
@@ -5065,9 +5139,9 @@ function deserializeValue(value, options) {
5065
5139
  // if it's an integer, should interpret as smallest BSON integer
5066
5140
  // that can represent it exactly. (if out of range, interpret as double.)
5067
5141
  if (Math.floor(value) === value) {
5068
- if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1)
5142
+ if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX)
5069
5143
  return new Int32(value);
5070
- if (value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1)
5144
+ if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX)
5071
5145
  return Long.fromNumber(value);
5072
5146
  }
5073
5147
  // If the number is a non-integer or out of integer range, should interpret as BSON Double.
@@ -5132,7 +5206,7 @@ function deserializeValue(value, options) {
5132
5206
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5133
5207
  function serializeArray(array, options) {
5134
5208
  return array.map(function (v, index) {
5135
- options.seenObjects.push({ propertyName: "index " + index, obj: null });
5209
+ options.seenObjects.push({ propertyName: "index ".concat(index), obj: null });
5136
5210
  try {
5137
5211
  return serializeValue(v, options);
5138
5212
  }
@@ -5154,20 +5228,20 @@ function serializeValue(value, options) {
5154
5228
  var props = options.seenObjects.map(function (entry) { return entry.propertyName; });
5155
5229
  var leadingPart = props
5156
5230
  .slice(0, index)
5157
- .map(function (prop) { return prop + " -> "; })
5231
+ .map(function (prop) { return "".concat(prop, " -> "); })
5158
5232
  .join('');
5159
5233
  var alreadySeen = props[index];
5160
5234
  var circularPart = ' -> ' +
5161
5235
  props
5162
5236
  .slice(index + 1, props.length - 1)
5163
- .map(function (prop) { return prop + " -> "; })
5237
+ .map(function (prop) { return "".concat(prop, " -> "); })
5164
5238
  .join('');
5165
5239
  var current = props[props.length - 1];
5166
5240
  var leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
5167
5241
  var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
5168
5242
  throw new BSONTypeError('Converting circular structure to EJSON:\n' +
5169
- (" " + leadingPart + alreadySeen + circularPart + current + "\n") +
5170
- (" " + leadingSpace + "\\" + dashes + "/"));
5243
+ " ".concat(leadingPart).concat(alreadySeen).concat(circularPart).concat(current, "\n") +
5244
+ " ".concat(leadingSpace, "\\").concat(dashes, "/"));
5171
5245
  }
5172
5246
  options.seenObjects[options.seenObjects.length - 1].obj = value;
5173
5247
  }
@@ -5191,7 +5265,7 @@ function serializeValue(value, options) {
5191
5265
  if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) {
5192
5266
  // it's an integer
5193
5267
  if (Math.floor(value) === value) {
5194
- var int32Range = value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1, int64Range = value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1;
5268
+ var int32Range = value >= BSON_INT32_MIN && value <= BSON_INT32_MAX, int64Range = value >= BSON_INT64_MIN && value <= BSON_INT64_MAX;
5195
5269
  // interpret as being of the smallest BSON integer type that can represent the number exactly
5196
5270
  if (int32Range)
5197
5271
  return { $numberInt: value.toString() };
@@ -5246,7 +5320,18 @@ function serializeDocument(doc, options) {
5246
5320
  for (var name in doc) {
5247
5321
  options.seenObjects.push({ propertyName: name, obj: null });
5248
5322
  try {
5249
- _doc[name] = serializeValue(doc[name], options);
5323
+ var value = serializeValue(doc[name], options);
5324
+ if (name === '__proto__') {
5325
+ Object.defineProperty(_doc, name, {
5326
+ value: value,
5327
+ writable: true,
5328
+ enumerable: true,
5329
+ configurable: true
5330
+ });
5331
+ }
5332
+ else {
5333
+ _doc[name] = value;
5334
+ }
5250
5335
  }
5251
5336
  finally {
5252
5337
  options.seenObjects.pop();
@@ -5316,7 +5401,7 @@ var EJSON;
5316
5401
  finalOptions.relaxed = !finalOptions.strict;
5317
5402
  return JSON.parse(text, function (key, value) {
5318
5403
  if (key.indexOf('\x00') !== -1) {
5319
- throw new BSONError("BSON Document field names cannot contain null bytes, found: " + JSON.stringify(key));
5404
+ throw new BSONError("BSON Document field names cannot contain null bytes, found: ".concat(JSON.stringify(key)));
5320
5405
  }
5321
5406
  return deserializeValue(value, finalOptions);
5322
5407
  });
@@ -5505,85 +5590,6 @@ else {
5505
5590
  }());
5506
5591
  }
5507
5592
 
5508
- /** @internal */
5509
- var BSON_INT32_MAX = 0x7fffffff;
5510
- /** @internal */
5511
- var BSON_INT32_MIN = -0x80000000;
5512
- /** @internal */
5513
- var BSON_INT64_MAX = Math.pow(2, 63) - 1;
5514
- /** @internal */
5515
- var BSON_INT64_MIN = -Math.pow(2, 63);
5516
- /**
5517
- * Any integer up to 2^53 can be precisely represented by a double.
5518
- * @internal
5519
- */
5520
- var JS_INT_MAX = Math.pow(2, 53);
5521
- /**
5522
- * Any integer down to -2^53 can be precisely represented by a double.
5523
- * @internal
5524
- */
5525
- var JS_INT_MIN = -Math.pow(2, 53);
5526
- /** Number BSON Type @internal */
5527
- var BSON_DATA_NUMBER = 1;
5528
- /** String BSON Type @internal */
5529
- var BSON_DATA_STRING = 2;
5530
- /** Object BSON Type @internal */
5531
- var BSON_DATA_OBJECT = 3;
5532
- /** Array BSON Type @internal */
5533
- var BSON_DATA_ARRAY = 4;
5534
- /** Binary BSON Type @internal */
5535
- var BSON_DATA_BINARY = 5;
5536
- /** Binary BSON Type @internal */
5537
- var BSON_DATA_UNDEFINED = 6;
5538
- /** ObjectId BSON Type @internal */
5539
- var BSON_DATA_OID = 7;
5540
- /** Boolean BSON Type @internal */
5541
- var BSON_DATA_BOOLEAN = 8;
5542
- /** Date BSON Type @internal */
5543
- var BSON_DATA_DATE = 9;
5544
- /** null BSON Type @internal */
5545
- var BSON_DATA_NULL = 10;
5546
- /** RegExp BSON Type @internal */
5547
- var BSON_DATA_REGEXP = 11;
5548
- /** Code BSON Type @internal */
5549
- var BSON_DATA_DBPOINTER = 12;
5550
- /** Code BSON Type @internal */
5551
- var BSON_DATA_CODE = 13;
5552
- /** Symbol BSON Type @internal */
5553
- var BSON_DATA_SYMBOL = 14;
5554
- /** Code with Scope BSON Type @internal */
5555
- var BSON_DATA_CODE_W_SCOPE = 15;
5556
- /** 32 bit Integer BSON Type @internal */
5557
- var BSON_DATA_INT = 16;
5558
- /** Timestamp BSON Type @internal */
5559
- var BSON_DATA_TIMESTAMP = 17;
5560
- /** Long BSON Type @internal */
5561
- var BSON_DATA_LONG = 18;
5562
- /** Decimal128 BSON Type @internal */
5563
- var BSON_DATA_DECIMAL128 = 19;
5564
- /** MinKey BSON Type @internal */
5565
- var BSON_DATA_MIN_KEY = 0xff;
5566
- /** MaxKey BSON Type @internal */
5567
- var BSON_DATA_MAX_KEY = 0x7f;
5568
- /** Binary Default Type @internal */
5569
- var BSON_BINARY_SUBTYPE_DEFAULT = 0;
5570
- /** Binary Function Type @internal */
5571
- var BSON_BINARY_SUBTYPE_FUNCTION = 1;
5572
- /** Binary Byte Array Type @internal */
5573
- var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
5574
- /** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
5575
- var BSON_BINARY_SUBTYPE_UUID = 3;
5576
- /** Binary UUID Type @internal */
5577
- var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
5578
- /** Binary MD5 Type @internal */
5579
- var BSON_BINARY_SUBTYPE_MD5 = 5;
5580
- /** Encrypted BSON type @internal */
5581
- var BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
5582
- /** Column BSON type @internal */
5583
- var BSON_BINARY_SUBTYPE_COLUMN = 7;
5584
- /** Binary User Defined Type @internal */
5585
- var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
5586
-
5587
5593
  function calculateObjectSize$1(object, serializeFunctions, ignoreUndefined) {
5588
5594
  var totalLength = 4 + 1;
5589
5595
  if (Array.isArray(object)) {
@@ -5621,7 +5627,7 @@ value, serializeFunctions, isArray, ignoreUndefined) {
5621
5627
  if (Math.floor(value) === value &&
5622
5628
  value >= JS_INT_MIN &&
5623
5629
  value <= JS_INT_MAX) {
5624
- if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
5630
+ if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1) {
5625
5631
  // 32 bit
5626
5632
  return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (4 + 1);
5627
5633
  }
@@ -5682,13 +5688,14 @@ value, serializeFunctions, isArray, ignoreUndefined) {
5682
5688
  }
5683
5689
  }
5684
5690
  else if (value['_bsontype'] === 'Binary') {
5691
+ var binary = value;
5685
5692
  // Check what kind of subtype we have
5686
- if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5693
+ if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5687
5694
  return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
5688
- (value.position + 1 + 4 + 1 + 4));
5695
+ (binary.position + 1 + 4 + 1 + 4));
5689
5696
  }
5690
5697
  else {
5691
- return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1));
5698
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (binary.position + 1 + 4 + 1));
5692
5699
  }
5693
5700
  }
5694
5701
  else if (value['_bsontype'] === 'Symbol') {
@@ -5825,16 +5832,16 @@ function deserialize$1(buffer, options, isArray) {
5825
5832
  (buffer[index + 2] << 16) |
5826
5833
  (buffer[index + 3] << 24);
5827
5834
  if (size < 5) {
5828
- throw new BSONError("bson size must be >= 5, is " + size);
5835
+ throw new BSONError("bson size must be >= 5, is ".concat(size));
5829
5836
  }
5830
5837
  if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
5831
- throw new BSONError("buffer length " + buffer.length + " must be >= bson size " + size);
5838
+ throw new BSONError("buffer length ".concat(buffer.length, " must be >= bson size ").concat(size));
5832
5839
  }
5833
5840
  if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
5834
- throw new BSONError("buffer length " + buffer.length + " must === bson size " + size);
5841
+ throw new BSONError("buffer length ".concat(buffer.length, " must === bson size ").concat(size));
5835
5842
  }
5836
5843
  if (size + index > buffer.byteLength) {
5837
- throw new BSONError("(bson size " + size + " + options.index " + index + " must be <= buffer length " + buffer.byteLength + ")");
5844
+ throw new BSONError("(bson size ".concat(size, " + options.index ").concat(index, " must be <= buffer length ").concat(buffer.byteLength, ")"));
5838
5845
  }
5839
5846
  // Illegal end value
5840
5847
  if (buffer[index + size - 1] !== 0) {
@@ -5911,6 +5918,7 @@ function deserializeObject(buffer, index, options, isArray) {
5911
5918
  var done = false;
5912
5919
  var isPossibleDBRef = isArray ? false : null;
5913
5920
  // While we have more left data left keep parsing
5921
+ var dataview = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
5914
5922
  while (!done) {
5915
5923
  // Read the type
5916
5924
  var elementType = buffer[index++];
@@ -5971,11 +5979,11 @@ function deserializeObject(buffer, index, options, isArray) {
5971
5979
  (buffer[index++] << 24);
5972
5980
  }
5973
5981
  else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
5974
- value = new Double(buffer.readDoubleLE(index));
5982
+ value = new Double(dataview.getFloat64(index, true));
5975
5983
  index = index + 8;
5976
5984
  }
5977
5985
  else if (elementType === BSON_DATA_NUMBER) {
5978
- value = buffer.readDoubleLE(index);
5986
+ value = dataview.getFloat64(index, true);
5979
5987
  index = index + 8;
5980
5988
  }
5981
5989
  else if (elementType === BSON_DATA_DATE) {
@@ -6121,6 +6129,9 @@ function deserializeObject(buffer, index, options, isArray) {
6121
6129
  }
6122
6130
  else {
6123
6131
  value = new Binary(buffer.slice(index, index + binarySize), subType);
6132
+ if (subType === BSON_BINARY_SUBTYPE_UUID_NEW) {
6133
+ value = value.toUUID();
6134
+ }
6124
6135
  }
6125
6136
  }
6126
6137
  else {
@@ -6146,8 +6157,11 @@ function deserializeObject(buffer, index, options, isArray) {
6146
6157
  if (promoteBuffers && promoteValues) {
6147
6158
  value = _buffer;
6148
6159
  }
6160
+ else if (subType === BSON_BINARY_SUBTYPE_UUID_NEW) {
6161
+ value = new Binary(buffer.slice(index, index + binarySize), subType).toUUID();
6162
+ }
6149
6163
  else {
6150
- value = new Binary(_buffer, subType);
6164
+ value = new Binary(buffer.slice(index, index + binarySize), subType);
6151
6165
  }
6152
6166
  }
6153
6167
  // Update the index
@@ -6373,7 +6387,7 @@ function deserializeObject(buffer, index, options, isArray) {
6373
6387
  value = new DBRef(namespace, oid);
6374
6388
  }
6375
6389
  else {
6376
- throw new BSONError('Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"');
6390
+ throw new BSONError("Detected unknown BSON type ".concat(elementType.toString(16), " for fieldname \"").concat(name, "\""));
6377
6391
  }
6378
6392
  if (name === '__proto__') {
6379
6393
  Object.defineProperty(object, name, {
@@ -6411,10 +6425,12 @@ function deserializeObject(buffer, index, options, isArray) {
6411
6425
  * @internal
6412
6426
  */
6413
6427
  function isolateEval(functionString, functionCache, object) {
6428
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
6414
6429
  if (!functionCache)
6415
6430
  return new Function(functionString);
6416
6431
  // Check for cache hit, eval if missing and return cached function
6417
6432
  if (functionCache[functionString] == null) {
6433
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
6418
6434
  functionCache[functionString] = new Function(functionString);
6419
6435
  }
6420
6436
  // Set the object
@@ -6436,74 +6452,6 @@ function getValidatedString(buffer, start, end, shouldValidateUtf8) {
6436
6452
  return value;
6437
6453
  }
6438
6454
 
6439
- // Copyright (c) 2008, Fair Oaks Labs, Inc.
6440
- function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
6441
- var e;
6442
- var m;
6443
- var c;
6444
- var bBE = endian === 'big';
6445
- var eLen = nBytes * 8 - mLen - 1;
6446
- var eMax = (1 << eLen) - 1;
6447
- var eBias = eMax >> 1;
6448
- var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
6449
- var i = bBE ? nBytes - 1 : 0;
6450
- var d = bBE ? -1 : 1;
6451
- var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
6452
- value = Math.abs(value);
6453
- if (isNaN(value) || value === Infinity) {
6454
- m = isNaN(value) ? 1 : 0;
6455
- e = eMax;
6456
- }
6457
- else {
6458
- e = Math.floor(Math.log(value) / Math.LN2);
6459
- if (value * (c = Math.pow(2, -e)) < 1) {
6460
- e--;
6461
- c *= 2;
6462
- }
6463
- if (e + eBias >= 1) {
6464
- value += rt / c;
6465
- }
6466
- else {
6467
- value += rt * Math.pow(2, 1 - eBias);
6468
- }
6469
- if (value * c >= 2) {
6470
- e++;
6471
- c /= 2;
6472
- }
6473
- if (e + eBias >= eMax) {
6474
- m = 0;
6475
- e = eMax;
6476
- }
6477
- else if (e + eBias >= 1) {
6478
- m = (value * c - 1) * Math.pow(2, mLen);
6479
- e = e + eBias;
6480
- }
6481
- else {
6482
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
6483
- e = 0;
6484
- }
6485
- }
6486
- if (isNaN(value))
6487
- m = 0;
6488
- while (mLen >= 8) {
6489
- buffer[offset + i] = m & 0xff;
6490
- i += d;
6491
- m /= 256;
6492
- mLen -= 8;
6493
- }
6494
- e = (e << mLen) | m;
6495
- if (isNaN(value))
6496
- e += 8;
6497
- eLen += mLen;
6498
- while (eLen > 0) {
6499
- buffer[offset + i] = e & 0xff;
6500
- i += d;
6501
- e /= 256;
6502
- eLen -= 8;
6503
- }
6504
- buffer[offset + i - d] |= s * 128;
6505
- }
6506
-
6507
6455
  var regexp = /\x00/; // eslint-disable-line no-control-regex
6508
6456
  var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
6509
6457
  /*
@@ -6534,12 +6482,14 @@ function serializeString(buffer, key, value, index, isArray) {
6534
6482
  buffer[index++] = 0;
6535
6483
  return index;
6536
6484
  }
6485
+ var SPACE_FOR_FLOAT64 = new Uint8Array(8);
6486
+ var DV_FOR_FLOAT64 = new DataView(SPACE_FOR_FLOAT64.buffer, SPACE_FOR_FLOAT64.byteOffset, SPACE_FOR_FLOAT64.byteLength);
6537
6487
  function serializeNumber(buffer, key, value, index, isArray) {
6538
6488
  // We have an integer value
6539
6489
  // TODO(NODE-2529): Add support for big int
6540
6490
  if (Number.isInteger(value) &&
6541
- value >= BSON_INT32_MIN &&
6542
- value <= BSON_INT32_MAX) {
6491
+ value >= BSON_INT32_MIN$1 &&
6492
+ value <= BSON_INT32_MAX$1) {
6543
6493
  // If the value fits in 32 bits encode as int32
6544
6494
  // Set int type 32 bits or less
6545
6495
  buffer[index++] = BSON_DATA_INT;
@@ -6567,7 +6517,8 @@ function serializeNumber(buffer, key, value, index, isArray) {
6567
6517
  index = index + numberOfWrittenBytes;
6568
6518
  buffer[index++] = 0;
6569
6519
  // Write float
6570
- writeIEEE754(buffer, value, index, 'little', 52, 8);
6520
+ DV_FOR_FLOAT64.setFloat64(0, value, true);
6521
+ buffer.set(SPACE_FOR_FLOAT64, index);
6571
6522
  // Adjust index
6572
6523
  index = index + 8;
6573
6524
  }
@@ -6846,7 +6797,8 @@ function serializeDouble(buffer, key, value, index, isArray) {
6846
6797
  index = index + numberOfWrittenBytes;
6847
6798
  buffer[index++] = 0;
6848
6799
  // Write float
6849
- writeIEEE754(buffer, value.value, index, 'little', 52, 8);
6800
+ DV_FOR_FLOAT64.setFloat64(0, value.value, true);
6801
+ buffer.set(SPACE_FOR_FLOAT64, index);
6850
6802
  // Adjust index
6851
6803
  index = index + 8;
6852
6804
  return index;
@@ -7056,7 +7008,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7056
7008
  if (Array.isArray(object)) {
7057
7009
  // Get object keys
7058
7010
  for (var i = 0; i < object.length; i++) {
7059
- var key = '' + i;
7011
+ var key = "".concat(i);
7060
7012
  var value = object[i];
7061
7013
  // Is there an override value
7062
7014
  if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
@@ -7131,7 +7083,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7131
7083
  index = serializeMinMax(buffer, key, value, index, true);
7132
7084
  }
7133
7085
  else if (typeof value['_bsontype'] !== 'undefined') {
7134
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7086
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7135
7087
  }
7136
7088
  }
7137
7089
  }
@@ -7230,7 +7182,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7230
7182
  index = serializeMinMax(buffer, key, value, index);
7231
7183
  }
7232
7184
  else if (typeof value['_bsontype'] !== 'undefined') {
7233
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7185
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7234
7186
  }
7235
7187
  }
7236
7188
  }
@@ -7335,7 +7287,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7335
7287
  index = serializeMinMax(buffer, key, value, index);
7336
7288
  }
7337
7289
  else if (typeof value['_bsontype'] !== 'undefined') {
7338
- throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
7290
+ throw new BSONTypeError("Unrecognized or invalid _bsontype: ".concat(String(value['_bsontype'])));
7339
7291
  }
7340
7292
  }
7341
7293
  }
@@ -7514,5 +7466,5 @@ var BSON = {
7514
7466
  };
7515
7467
 
7516
7468
  export default BSON;
7517
- export { BSONError, BSONRegExp, BSONSymbol, BSONTypeError, BSON_BINARY_SUBTYPE_BYTE_ARRAY, BSON_BINARY_SUBTYPE_COLUMN, BSON_BINARY_SUBTYPE_DEFAULT, BSON_BINARY_SUBTYPE_ENCRYPTED, BSON_BINARY_SUBTYPE_FUNCTION, BSON_BINARY_SUBTYPE_MD5, BSON_BINARY_SUBTYPE_USER_DEFINED, BSON_BINARY_SUBTYPE_UUID, BSON_BINARY_SUBTYPE_UUID_NEW, BSON_DATA_ARRAY, BSON_DATA_BINARY, BSON_DATA_BOOLEAN, BSON_DATA_CODE, BSON_DATA_CODE_W_SCOPE, BSON_DATA_DATE, BSON_DATA_DBPOINTER, BSON_DATA_DECIMAL128, BSON_DATA_INT, BSON_DATA_LONG, BSON_DATA_MAX_KEY, BSON_DATA_MIN_KEY, BSON_DATA_NULL, BSON_DATA_NUMBER, BSON_DATA_OBJECT, BSON_DATA_OID, BSON_DATA_REGEXP, BSON_DATA_STRING, BSON_DATA_SYMBOL, BSON_DATA_TIMESTAMP, BSON_DATA_UNDEFINED, BSON_INT32_MAX, BSON_INT32_MIN, BSON_INT64_MAX, BSON_INT64_MIN, Binary, Code, DBRef, Decimal128, Double, EJSON, Int32, Long, LongWithoutOverridesClass, bsonMap as Map, MaxKey, MinKey, ObjectId as ObjectID, ObjectId, Timestamp, UUID, calculateObjectSize, deserialize, deserializeStream, serialize, serializeWithBufferAndIndex, setInternalBufferSize };
7469
+ export { BSONError, BSONRegExp, BSONSymbol, BSONTypeError, BSON_BINARY_SUBTYPE_BYTE_ARRAY, BSON_BINARY_SUBTYPE_COLUMN, BSON_BINARY_SUBTYPE_DEFAULT, BSON_BINARY_SUBTYPE_ENCRYPTED, BSON_BINARY_SUBTYPE_FUNCTION, BSON_BINARY_SUBTYPE_MD5, BSON_BINARY_SUBTYPE_USER_DEFINED, BSON_BINARY_SUBTYPE_UUID, BSON_BINARY_SUBTYPE_UUID_NEW, BSON_DATA_ARRAY, BSON_DATA_BINARY, BSON_DATA_BOOLEAN, BSON_DATA_CODE, BSON_DATA_CODE_W_SCOPE, BSON_DATA_DATE, BSON_DATA_DBPOINTER, BSON_DATA_DECIMAL128, BSON_DATA_INT, BSON_DATA_LONG, BSON_DATA_MAX_KEY, BSON_DATA_MIN_KEY, BSON_DATA_NULL, BSON_DATA_NUMBER, BSON_DATA_OBJECT, BSON_DATA_OID, BSON_DATA_REGEXP, BSON_DATA_STRING, BSON_DATA_SYMBOL, BSON_DATA_TIMESTAMP, BSON_DATA_UNDEFINED, BSON_INT32_MAX$1 as BSON_INT32_MAX, BSON_INT32_MIN$1 as BSON_INT32_MIN, BSON_INT64_MAX$1 as BSON_INT64_MAX, BSON_INT64_MIN$1 as BSON_INT64_MIN, Binary, Code, DBRef, Decimal128, Double, EJSON, Int32, Long, LongWithoutOverridesClass, bsonMap as Map, MaxKey, MinKey, ObjectId as ObjectID, ObjectId, Timestamp, UUID, calculateObjectSize, deserialize, deserializeStream, serialize, serializeWithBufferAndIndex, setInternalBufferSize };
7518
7470
  //# sourceMappingURL=bson.browser.esm.js.map