bson 4.6.5 → 4.7.1

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.
@@ -2268,174 +2268,84 @@ var BSON = (function (exports) {
2268
2268
  : buffer.toString('hex');
2269
2269
  };
2270
2270
 
2271
- var BYTE_LENGTH = 16;
2272
- 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);
2273
2279
  /**
2274
- * A class representation of the BSON UUID type.
2275
- * @public
2280
+ * Any integer up to 2^53 can be precisely represented by a double.
2281
+ * @internal
2276
2282
  */
2277
- var UUID = /** @class */ (function () {
2278
- /**
2279
- * Create an UUID type
2280
- *
2281
- * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
2282
- */
2283
- function UUID(input) {
2284
- if (typeof input === 'undefined') {
2285
- // The most common use case (blank id, new UUID() instance)
2286
- this.id = UUID.generate();
2287
- }
2288
- else if (input instanceof UUID) {
2289
- this[kId$1] = buffer_1.from(input.id);
2290
- this.__id = input.__id;
2291
- }
2292
- else if (ArrayBuffer.isView(input) && input.byteLength === BYTE_LENGTH) {
2293
- this.id = ensureBuffer(input);
2294
- }
2295
- else if (typeof input === 'string') {
2296
- this.id = uuidHexStringToBuffer(input);
2297
- }
2298
- else {
2299
- 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).');
2300
- }
2301
- }
2302
- Object.defineProperty(UUID.prototype, "id", {
2303
- /**
2304
- * The UUID bytes
2305
- * @readonly
2306
- */
2307
- get: function () {
2308
- return this[kId$1];
2309
- },
2310
- set: function (value) {
2311
- this[kId$1] = value;
2312
- if (UUID.cacheHexString) {
2313
- this.__id = bufferToUuidHexString(value);
2314
- }
2315
- },
2316
- enumerable: false,
2317
- configurable: true
2318
- });
2319
- /**
2320
- * Generate a 16 byte uuid v4 buffer used in UUIDs
2321
- */
2322
- /**
2323
- * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
2324
- * @param includeDashes - should the string exclude dash-separators.
2325
- * */
2326
- UUID.prototype.toHexString = function (includeDashes) {
2327
- if (includeDashes === void 0) { includeDashes = true; }
2328
- if (UUID.cacheHexString && this.__id) {
2329
- return this.__id;
2330
- }
2331
- var uuidHexString = bufferToUuidHexString(this.id, includeDashes);
2332
- if (UUID.cacheHexString) {
2333
- this.__id = uuidHexString;
2334
- }
2335
- return uuidHexString;
2336
- };
2337
- /**
2338
- * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
2339
- */
2340
- UUID.prototype.toString = function (encoding) {
2341
- return encoding ? this.id.toString(encoding) : this.toHexString();
2342
- };
2343
- /**
2344
- * Converts the id into its JSON string representation.
2345
- * A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
2346
- */
2347
- UUID.prototype.toJSON = function () {
2348
- return this.toHexString();
2349
- };
2350
- /**
2351
- * Compares the equality of this UUID with `otherID`.
2352
- *
2353
- * @param otherId - UUID instance to compare against.
2354
- */
2355
- UUID.prototype.equals = function (otherId) {
2356
- if (!otherId) {
2357
- return false;
2358
- }
2359
- if (otherId instanceof UUID) {
2360
- return otherId.id.equals(this.id);
2361
- }
2362
- try {
2363
- return new UUID(otherId).id.equals(this.id);
2364
- }
2365
- catch (_a) {
2366
- return false;
2367
- }
2368
- };
2369
- /**
2370
- * Creates a Binary instance from the current UUID.
2371
- */
2372
- UUID.prototype.toBinary = function () {
2373
- return new Binary(this.id, Binary.SUBTYPE_UUID);
2374
- };
2375
- /**
2376
- * Generates a populated buffer containing a v4 uuid
2377
- */
2378
- UUID.generate = function () {
2379
- var bytes = randomBytes(BYTE_LENGTH);
2380
- // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
2381
- // Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
2382
- bytes[6] = (bytes[6] & 0x0f) | 0x40;
2383
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
2384
- return buffer_1.from(bytes);
2385
- };
2386
- /**
2387
- * Checks if a value is a valid bson UUID
2388
- * @param input - UUID, string or Buffer to validate.
2389
- */
2390
- UUID.isValid = function (input) {
2391
- if (!input) {
2392
- return false;
2393
- }
2394
- if (input instanceof UUID) {
2395
- return true;
2396
- }
2397
- if (typeof input === 'string') {
2398
- return uuidValidateString(input);
2399
- }
2400
- if (isUint8Array(input)) {
2401
- // check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
2402
- if (input.length !== BYTE_LENGTH) {
2403
- return false;
2404
- }
2405
- try {
2406
- // get this byte as hex: xxxxxxxx-xxxx-XXxx-xxxx-xxxxxxxxxxxx
2407
- // check first part as uuid version: xxxxxxxx-xxxx-Xxxx-xxxx-xxxxxxxxxxxx
2408
- return parseInt(input[6].toString(16)[0], 10) === Binary.SUBTYPE_UUID;
2409
- }
2410
- catch (_a) {
2411
- return false;
2412
- }
2413
- }
2414
- return false;
2415
- };
2416
- /**
2417
- * Creates an UUID from a hex string representation of an UUID.
2418
- * @param hexString - 32 or 36 character hex string (dashes excluded/included).
2419
- */
2420
- UUID.createFromHexString = function (hexString) {
2421
- var buffer = uuidHexStringToBuffer(hexString);
2422
- return new UUID(buffer);
2423
- };
2424
- /**
2425
- * Converts to a string representation of this Id.
2426
- *
2427
- * @returns return the 36 character hex string representation.
2428
- * @internal
2429
- */
2430
- UUID.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
2431
- return this.inspect();
2432
- };
2433
- UUID.prototype.inspect = function () {
2434
- return "new UUID(\"".concat(this.toHexString(), "\")");
2435
- };
2436
- return UUID;
2437
- }());
2438
- 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;
2439
2349
 
2440
2350
  /**
2441
2351
  * A class representation of the BSON Binary type.
@@ -2636,7 +2546,7 @@ var BSON = (function (exports) {
2636
2546
  if (!data) {
2637
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 () {
@@ -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.
@@ -4402,22 +4474,17 @@ var BSON = (function (exports) {
4402
4474
  if (options && (options.legacy || (options.relaxed && isFinite(this.value)))) {
4403
4475
  return this.value;
4404
4476
  }
4405
- // NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
4406
- // explicitly provided `-0` then we need to ensure the sign makes it into the output
4407
4477
  if (Object.is(Math.sign(this.value), -0)) {
4408
- return { $numberDouble: "-".concat(this.value.toFixed(1)) };
4478
+ // NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
4479
+ // explicitly provided `-0` then we need to ensure the sign makes it into the output
4480
+ return { $numberDouble: '-0.0' };
4409
4481
  }
4410
- var $numberDouble;
4411
4482
  if (Number.isInteger(this.value)) {
4412
- $numberDouble = this.value.toFixed(1);
4413
- if ($numberDouble.length >= 13) {
4414
- $numberDouble = this.value.toExponential(13).toUpperCase();
4415
- }
4483
+ return { $numberDouble: "".concat(this.value, ".0") };
4416
4484
  }
4417
4485
  else {
4418
- $numberDouble = this.value.toString();
4486
+ return { $numberDouble: "".concat(this.value) };
4419
4487
  }
4420
- return { $numberDouble: $numberDouble };
4421
4488
  };
4422
4489
  /** @internal */
4423
4490
  Double.fromExtendedJSON = function (doc, options) {
@@ -5037,12 +5104,12 @@ var BSON = (function (exports) {
5037
5104
  return (isObjectLike(value) && Reflect.has(value, '_bsontype') && typeof value._bsontype === 'string');
5038
5105
  }
5039
5106
  // INT32 boundaries
5040
- var BSON_INT32_MAX$1 = 0x7fffffff;
5041
- var BSON_INT32_MIN$1 = -0x80000000;
5107
+ var BSON_INT32_MAX = 0x7fffffff;
5108
+ var BSON_INT32_MIN = -0x80000000;
5042
5109
  // INT64 boundaries
5043
5110
  // const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
5044
- var BSON_INT64_MAX$1 = 0x8000000000000000;
5045
- var BSON_INT64_MIN$1 = -0x8000000000000000;
5111
+ var BSON_INT64_MAX = 0x8000000000000000;
5112
+ var BSON_INT64_MIN = -0x8000000000000000;
5046
5113
  // all the types where we don't need to do any special processing and can just pass the EJSON
5047
5114
  //straight to type.fromExtendedJSON
5048
5115
  var keysToCodecs = {
@@ -5070,9 +5137,9 @@ var BSON = (function (exports) {
5070
5137
  // if it's an integer, should interpret as smallest BSON integer
5071
5138
  // that can represent it exactly. (if out of range, interpret as double.)
5072
5139
  if (Math.floor(value) === value) {
5073
- if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1)
5140
+ if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX)
5074
5141
  return new Int32(value);
5075
- if (value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1)
5142
+ if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX)
5076
5143
  return Long.fromNumber(value);
5077
5144
  }
5078
5145
  // If the number is a non-integer or out of integer range, should interpret as BSON Double.
@@ -5196,7 +5263,7 @@ var BSON = (function (exports) {
5196
5263
  if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) {
5197
5264
  // it's an integer
5198
5265
  if (Math.floor(value) === value) {
5199
- var int32Range = value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1, int64Range = value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1;
5266
+ var int32Range = value >= BSON_INT32_MIN && value <= BSON_INT32_MAX, int64Range = value >= BSON_INT64_MIN && value <= BSON_INT64_MAX;
5200
5267
  // interpret as being of the smallest BSON integer type that can represent the number exactly
5201
5268
  if (int32Range)
5202
5269
  return { $numberInt: value.toString() };
@@ -5521,85 +5588,6 @@ var BSON = (function (exports) {
5521
5588
  }());
5522
5589
  }
5523
5590
 
5524
- /** @internal */
5525
- var BSON_INT32_MAX = 0x7fffffff;
5526
- /** @internal */
5527
- var BSON_INT32_MIN = -0x80000000;
5528
- /** @internal */
5529
- var BSON_INT64_MAX = Math.pow(2, 63) - 1;
5530
- /** @internal */
5531
- var BSON_INT64_MIN = -Math.pow(2, 63);
5532
- /**
5533
- * Any integer up to 2^53 can be precisely represented by a double.
5534
- * @internal
5535
- */
5536
- var JS_INT_MAX = Math.pow(2, 53);
5537
- /**
5538
- * Any integer down to -2^53 can be precisely represented by a double.
5539
- * @internal
5540
- */
5541
- var JS_INT_MIN = -Math.pow(2, 53);
5542
- /** Number BSON Type @internal */
5543
- var BSON_DATA_NUMBER = 1;
5544
- /** String BSON Type @internal */
5545
- var BSON_DATA_STRING = 2;
5546
- /** Object BSON Type @internal */
5547
- var BSON_DATA_OBJECT = 3;
5548
- /** Array BSON Type @internal */
5549
- var BSON_DATA_ARRAY = 4;
5550
- /** Binary BSON Type @internal */
5551
- var BSON_DATA_BINARY = 5;
5552
- /** Binary BSON Type @internal */
5553
- var BSON_DATA_UNDEFINED = 6;
5554
- /** ObjectId BSON Type @internal */
5555
- var BSON_DATA_OID = 7;
5556
- /** Boolean BSON Type @internal */
5557
- var BSON_DATA_BOOLEAN = 8;
5558
- /** Date BSON Type @internal */
5559
- var BSON_DATA_DATE = 9;
5560
- /** null BSON Type @internal */
5561
- var BSON_DATA_NULL = 10;
5562
- /** RegExp BSON Type @internal */
5563
- var BSON_DATA_REGEXP = 11;
5564
- /** Code BSON Type @internal */
5565
- var BSON_DATA_DBPOINTER = 12;
5566
- /** Code BSON Type @internal */
5567
- var BSON_DATA_CODE = 13;
5568
- /** Symbol BSON Type @internal */
5569
- var BSON_DATA_SYMBOL = 14;
5570
- /** Code with Scope BSON Type @internal */
5571
- var BSON_DATA_CODE_W_SCOPE = 15;
5572
- /** 32 bit Integer BSON Type @internal */
5573
- var BSON_DATA_INT = 16;
5574
- /** Timestamp BSON Type @internal */
5575
- var BSON_DATA_TIMESTAMP = 17;
5576
- /** Long BSON Type @internal */
5577
- var BSON_DATA_LONG = 18;
5578
- /** Decimal128 BSON Type @internal */
5579
- var BSON_DATA_DECIMAL128 = 19;
5580
- /** MinKey BSON Type @internal */
5581
- var BSON_DATA_MIN_KEY = 0xff;
5582
- /** MaxKey BSON Type @internal */
5583
- var BSON_DATA_MAX_KEY = 0x7f;
5584
- /** Binary Default Type @internal */
5585
- var BSON_BINARY_SUBTYPE_DEFAULT = 0;
5586
- /** Binary Function Type @internal */
5587
- var BSON_BINARY_SUBTYPE_FUNCTION = 1;
5588
- /** Binary Byte Array Type @internal */
5589
- var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
5590
- /** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
5591
- var BSON_BINARY_SUBTYPE_UUID = 3;
5592
- /** Binary UUID Type @internal */
5593
- var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
5594
- /** Binary MD5 Type @internal */
5595
- var BSON_BINARY_SUBTYPE_MD5 = 5;
5596
- /** Encrypted BSON type @internal */
5597
- var BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
5598
- /** Column BSON type @internal */
5599
- var BSON_BINARY_SUBTYPE_COLUMN = 7;
5600
- /** Binary User Defined Type @internal */
5601
- var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
5602
-
5603
5591
  function calculateObjectSize$1(object, serializeFunctions, ignoreUndefined) {
5604
5592
  var totalLength = 4 + 1;
5605
5593
  if (Array.isArray(object)) {
@@ -5637,7 +5625,7 @@ var BSON = (function (exports) {
5637
5625
  if (Math.floor(value) === value &&
5638
5626
  value >= JS_INT_MIN &&
5639
5627
  value <= JS_INT_MAX) {
5640
- if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
5628
+ if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1) {
5641
5629
  // 32 bit
5642
5630
  return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (4 + 1);
5643
5631
  }
@@ -6139,6 +6127,9 @@ var BSON = (function (exports) {
6139
6127
  }
6140
6128
  else {
6141
6129
  value = new Binary(buffer.slice(index, index + binarySize), subType);
6130
+ if (subType === BSON_BINARY_SUBTYPE_UUID_NEW) {
6131
+ value = value.toUUID();
6132
+ }
6142
6133
  }
6143
6134
  }
6144
6135
  else {
@@ -6164,8 +6155,11 @@ var BSON = (function (exports) {
6164
6155
  if (promoteBuffers && promoteValues) {
6165
6156
  value = _buffer;
6166
6157
  }
6158
+ else if (subType === BSON_BINARY_SUBTYPE_UUID_NEW) {
6159
+ value = new Binary(buffer.slice(index, index + binarySize), subType).toUUID();
6160
+ }
6167
6161
  else {
6168
- value = new Binary(_buffer, subType);
6162
+ value = new Binary(buffer.slice(index, index + binarySize), subType);
6169
6163
  }
6170
6164
  }
6171
6165
  // Update the index
@@ -6492,8 +6486,8 @@ var BSON = (function (exports) {
6492
6486
  // We have an integer value
6493
6487
  // TODO(NODE-2529): Add support for big int
6494
6488
  if (Number.isInteger(value) &&
6495
- value >= BSON_INT32_MIN &&
6496
- value <= BSON_INT32_MAX) {
6489
+ value >= BSON_INT32_MIN$1 &&
6490
+ value <= BSON_INT32_MAX$1) {
6497
6491
  // If the value fits in 32 bits encode as int32
6498
6492
  // Set int type 32 bits or less
6499
6493
  buffer[index++] = BSON_DATA_INT;
@@ -7503,10 +7497,10 @@ var BSON = (function (exports) {
7503
7497
  exports.BSON_DATA_SYMBOL = BSON_DATA_SYMBOL;
7504
7498
  exports.BSON_DATA_TIMESTAMP = BSON_DATA_TIMESTAMP;
7505
7499
  exports.BSON_DATA_UNDEFINED = BSON_DATA_UNDEFINED;
7506
- exports.BSON_INT32_MAX = BSON_INT32_MAX;
7507
- exports.BSON_INT32_MIN = BSON_INT32_MIN;
7508
- exports.BSON_INT64_MAX = BSON_INT64_MAX;
7509
- exports.BSON_INT64_MIN = BSON_INT64_MIN;
7500
+ exports.BSON_INT32_MAX = BSON_INT32_MAX$1;
7501
+ exports.BSON_INT32_MIN = BSON_INT32_MIN$1;
7502
+ exports.BSON_INT64_MAX = BSON_INT64_MAX$1;
7503
+ exports.BSON_INT64_MIN = BSON_INT64_MIN$1;
7510
7504
  exports.Binary = Binary;
7511
7505
  exports.Code = Code;
7512
7506
  exports.DBRef = DBRef;