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.
package/dist/bson.esm.js CHANGED
@@ -231,174 +231,84 @@ var bufferToUuidHexString = function (buffer, includeDashes) {
231
231
  : buffer.toString('hex');
232
232
  };
233
233
 
234
- var BYTE_LENGTH = 16;
235
- var kId$1 = Symbol('id');
234
+ /** @internal */
235
+ var BSON_INT32_MAX$1 = 0x7fffffff;
236
+ /** @internal */
237
+ var BSON_INT32_MIN$1 = -0x80000000;
238
+ /** @internal */
239
+ var BSON_INT64_MAX$1 = Math.pow(2, 63) - 1;
240
+ /** @internal */
241
+ var BSON_INT64_MIN$1 = -Math.pow(2, 63);
236
242
  /**
237
- * A class representation of the BSON UUID type.
238
- * @public
243
+ * Any integer up to 2^53 can be precisely represented by a double.
244
+ * @internal
239
245
  */
240
- var UUID = /** @class */ (function () {
241
- /**
242
- * Create an UUID type
243
- *
244
- * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
245
- */
246
- function UUID(input) {
247
- if (typeof input === 'undefined') {
248
- // The most common use case (blank id, new UUID() instance)
249
- this.id = UUID.generate();
250
- }
251
- else if (input instanceof UUID) {
252
- this[kId$1] = Buffer.from(input.id);
253
- this.__id = input.__id;
254
- }
255
- else if (ArrayBuffer.isView(input) && input.byteLength === BYTE_LENGTH) {
256
- this.id = ensureBuffer(input);
257
- }
258
- else if (typeof input === 'string') {
259
- this.id = uuidHexStringToBuffer(input);
260
- }
261
- else {
262
- 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).');
263
- }
264
- }
265
- Object.defineProperty(UUID.prototype, "id", {
266
- /**
267
- * The UUID bytes
268
- * @readonly
269
- */
270
- get: function () {
271
- return this[kId$1];
272
- },
273
- set: function (value) {
274
- this[kId$1] = value;
275
- if (UUID.cacheHexString) {
276
- this.__id = bufferToUuidHexString(value);
277
- }
278
- },
279
- enumerable: false,
280
- configurable: true
281
- });
282
- /**
283
- * Generate a 16 byte uuid v4 buffer used in UUIDs
284
- */
285
- /**
286
- * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
287
- * @param includeDashes - should the string exclude dash-separators.
288
- * */
289
- UUID.prototype.toHexString = function (includeDashes) {
290
- if (includeDashes === void 0) { includeDashes = true; }
291
- if (UUID.cacheHexString && this.__id) {
292
- return this.__id;
293
- }
294
- var uuidHexString = bufferToUuidHexString(this.id, includeDashes);
295
- if (UUID.cacheHexString) {
296
- this.__id = uuidHexString;
297
- }
298
- return uuidHexString;
299
- };
300
- /**
301
- * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
302
- */
303
- UUID.prototype.toString = function (encoding) {
304
- return encoding ? this.id.toString(encoding) : this.toHexString();
305
- };
306
- /**
307
- * Converts the id into its JSON string representation.
308
- * A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
309
- */
310
- UUID.prototype.toJSON = function () {
311
- return this.toHexString();
312
- };
313
- /**
314
- * Compares the equality of this UUID with `otherID`.
315
- *
316
- * @param otherId - UUID instance to compare against.
317
- */
318
- UUID.prototype.equals = function (otherId) {
319
- if (!otherId) {
320
- return false;
321
- }
322
- if (otherId instanceof UUID) {
323
- return otherId.id.equals(this.id);
324
- }
325
- try {
326
- return new UUID(otherId).id.equals(this.id);
327
- }
328
- catch (_a) {
329
- return false;
330
- }
331
- };
332
- /**
333
- * Creates a Binary instance from the current UUID.
334
- */
335
- UUID.prototype.toBinary = function () {
336
- return new Binary(this.id, Binary.SUBTYPE_UUID);
337
- };
338
- /**
339
- * Generates a populated buffer containing a v4 uuid
340
- */
341
- UUID.generate = function () {
342
- var bytes = randomBytes(BYTE_LENGTH);
343
- // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
344
- // Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
345
- bytes[6] = (bytes[6] & 0x0f) | 0x40;
346
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
347
- return Buffer.from(bytes);
348
- };
349
- /**
350
- * Checks if a value is a valid bson UUID
351
- * @param input - UUID, string or Buffer to validate.
352
- */
353
- UUID.isValid = function (input) {
354
- if (!input) {
355
- return false;
356
- }
357
- if (input instanceof UUID) {
358
- return true;
359
- }
360
- if (typeof input === 'string') {
361
- return uuidValidateString(input);
362
- }
363
- if (isUint8Array(input)) {
364
- // check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
365
- if (input.length !== BYTE_LENGTH) {
366
- return false;
367
- }
368
- try {
369
- // get this byte as hex: xxxxxxxx-xxxx-XXxx-xxxx-xxxxxxxxxxxx
370
- // check first part as uuid version: xxxxxxxx-xxxx-Xxxx-xxxx-xxxxxxxxxxxx
371
- return parseInt(input[6].toString(16)[0], 10) === Binary.SUBTYPE_UUID;
372
- }
373
- catch (_a) {
374
- return false;
375
- }
376
- }
377
- return false;
378
- };
379
- /**
380
- * Creates an UUID from a hex string representation of an UUID.
381
- * @param hexString - 32 or 36 character hex string (dashes excluded/included).
382
- */
383
- UUID.createFromHexString = function (hexString) {
384
- var buffer = uuidHexStringToBuffer(hexString);
385
- return new UUID(buffer);
386
- };
387
- /**
388
- * Converts to a string representation of this Id.
389
- *
390
- * @returns return the 36 character hex string representation.
391
- * @internal
392
- */
393
- UUID.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
394
- return this.inspect();
395
- };
396
- UUID.prototype.inspect = function () {
397
- return "new UUID(\"".concat(this.toHexString(), "\")");
398
- };
399
- return UUID;
400
- }());
401
- Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
246
+ var JS_INT_MAX = Math.pow(2, 53);
247
+ /**
248
+ * Any integer down to -2^53 can be precisely represented by a double.
249
+ * @internal
250
+ */
251
+ var JS_INT_MIN = -Math.pow(2, 53);
252
+ /** Number BSON Type @internal */
253
+ var BSON_DATA_NUMBER = 1;
254
+ /** String BSON Type @internal */
255
+ var BSON_DATA_STRING = 2;
256
+ /** Object BSON Type @internal */
257
+ var BSON_DATA_OBJECT = 3;
258
+ /** Array BSON Type @internal */
259
+ var BSON_DATA_ARRAY = 4;
260
+ /** Binary BSON Type @internal */
261
+ var BSON_DATA_BINARY = 5;
262
+ /** Binary BSON Type @internal */
263
+ var BSON_DATA_UNDEFINED = 6;
264
+ /** ObjectId BSON Type @internal */
265
+ var BSON_DATA_OID = 7;
266
+ /** Boolean BSON Type @internal */
267
+ var BSON_DATA_BOOLEAN = 8;
268
+ /** Date BSON Type @internal */
269
+ var BSON_DATA_DATE = 9;
270
+ /** null BSON Type @internal */
271
+ var BSON_DATA_NULL = 10;
272
+ /** RegExp BSON Type @internal */
273
+ var BSON_DATA_REGEXP = 11;
274
+ /** Code BSON Type @internal */
275
+ var BSON_DATA_DBPOINTER = 12;
276
+ /** Code BSON Type @internal */
277
+ var BSON_DATA_CODE = 13;
278
+ /** Symbol BSON Type @internal */
279
+ var BSON_DATA_SYMBOL = 14;
280
+ /** Code with Scope BSON Type @internal */
281
+ var BSON_DATA_CODE_W_SCOPE = 15;
282
+ /** 32 bit Integer BSON Type @internal */
283
+ var BSON_DATA_INT = 16;
284
+ /** Timestamp BSON Type @internal */
285
+ var BSON_DATA_TIMESTAMP = 17;
286
+ /** Long BSON Type @internal */
287
+ var BSON_DATA_LONG = 18;
288
+ /** Decimal128 BSON Type @internal */
289
+ var BSON_DATA_DECIMAL128 = 19;
290
+ /** MinKey BSON Type @internal */
291
+ var BSON_DATA_MIN_KEY = 0xff;
292
+ /** MaxKey BSON Type @internal */
293
+ var BSON_DATA_MAX_KEY = 0x7f;
294
+ /** Binary Default Type @internal */
295
+ var BSON_BINARY_SUBTYPE_DEFAULT = 0;
296
+ /** Binary Function Type @internal */
297
+ var BSON_BINARY_SUBTYPE_FUNCTION = 1;
298
+ /** Binary Byte Array Type @internal */
299
+ var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
300
+ /** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
301
+ var BSON_BINARY_SUBTYPE_UUID = 3;
302
+ /** Binary UUID Type @internal */
303
+ var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
304
+ /** Binary MD5 Type @internal */
305
+ var BSON_BINARY_SUBTYPE_MD5 = 5;
306
+ /** Encrypted BSON type @internal */
307
+ var BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
308
+ /** Column BSON type @internal */
309
+ var BSON_BINARY_SUBTYPE_COLUMN = 7;
310
+ /** Binary User Defined Type @internal */
311
+ var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
402
312
 
403
313
  /**
404
314
  * A class representation of the BSON Binary type.
@@ -599,7 +509,7 @@ var Binary = /** @class */ (function () {
599
509
  if (!data) {
600
510
  throw new BSONTypeError("Unexpected Binary Extended JSON format ".concat(JSON.stringify(doc)));
601
511
  }
602
- return new Binary(data, type);
512
+ return type === BSON_BINARY_SUBTYPE_UUID_NEW ? new UUID(data) : new Binary(data, type);
603
513
  };
604
514
  /** @internal */
605
515
  Binary.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
@@ -637,6 +547,168 @@ var Binary = /** @class */ (function () {
637
547
  return Binary;
638
548
  }());
639
549
  Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' });
550
+ var UUID_BYTE_LENGTH = 16;
551
+ /**
552
+ * A class representation of the BSON UUID type.
553
+ * @public
554
+ */
555
+ var UUID = /** @class */ (function (_super) {
556
+ __extends(UUID, _super);
557
+ /**
558
+ * Create an UUID type
559
+ *
560
+ * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
561
+ */
562
+ function UUID(input) {
563
+ var _this = this;
564
+ var bytes;
565
+ var hexStr;
566
+ if (input == null) {
567
+ bytes = UUID.generate();
568
+ }
569
+ else if (input instanceof UUID) {
570
+ bytes = Buffer.from(input.buffer);
571
+ hexStr = input.__id;
572
+ }
573
+ else if (ArrayBuffer.isView(input) && input.byteLength === UUID_BYTE_LENGTH) {
574
+ bytes = ensureBuffer(input);
575
+ }
576
+ else if (typeof input === 'string') {
577
+ bytes = uuidHexStringToBuffer(input);
578
+ }
579
+ else {
580
+ 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).');
581
+ }
582
+ _this = _super.call(this, bytes, BSON_BINARY_SUBTYPE_UUID_NEW) || this;
583
+ _this.__id = hexStr;
584
+ return _this;
585
+ }
586
+ Object.defineProperty(UUID.prototype, "id", {
587
+ /**
588
+ * The UUID bytes
589
+ * @readonly
590
+ */
591
+ get: function () {
592
+ return this.buffer;
593
+ },
594
+ set: function (value) {
595
+ this.buffer = value;
596
+ if (UUID.cacheHexString) {
597
+ this.__id = bufferToUuidHexString(value);
598
+ }
599
+ },
600
+ enumerable: false,
601
+ configurable: true
602
+ });
603
+ /**
604
+ * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
605
+ * @param includeDashes - should the string exclude dash-separators.
606
+ * */
607
+ UUID.prototype.toHexString = function (includeDashes) {
608
+ if (includeDashes === void 0) { includeDashes = true; }
609
+ if (UUID.cacheHexString && this.__id) {
610
+ return this.__id;
611
+ }
612
+ var uuidHexString = bufferToUuidHexString(this.id, includeDashes);
613
+ if (UUID.cacheHexString) {
614
+ this.__id = uuidHexString;
615
+ }
616
+ return uuidHexString;
617
+ };
618
+ /**
619
+ * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
620
+ */
621
+ UUID.prototype.toString = function (encoding) {
622
+ return encoding ? this.id.toString(encoding) : this.toHexString();
623
+ };
624
+ /**
625
+ * Converts the id into its JSON string representation.
626
+ * A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
627
+ */
628
+ UUID.prototype.toJSON = function () {
629
+ return this.toHexString();
630
+ };
631
+ /**
632
+ * Compares the equality of this UUID with `otherID`.
633
+ *
634
+ * @param otherId - UUID instance to compare against.
635
+ */
636
+ UUID.prototype.equals = function (otherId) {
637
+ if (!otherId) {
638
+ return false;
639
+ }
640
+ if (otherId instanceof UUID) {
641
+ return otherId.id.equals(this.id);
642
+ }
643
+ try {
644
+ return new UUID(otherId).id.equals(this.id);
645
+ }
646
+ catch (_a) {
647
+ return false;
648
+ }
649
+ };
650
+ /**
651
+ * Creates a Binary instance from the current UUID.
652
+ */
653
+ UUID.prototype.toBinary = function () {
654
+ return new Binary(this.id, Binary.SUBTYPE_UUID);
655
+ };
656
+ /**
657
+ * Generates a populated buffer containing a v4 uuid
658
+ */
659
+ UUID.generate = function () {
660
+ var bytes = randomBytes(UUID_BYTE_LENGTH);
661
+ // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
662
+ // Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
663
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
664
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
665
+ return Buffer.from(bytes);
666
+ };
667
+ /**
668
+ * Checks if a value is a valid bson UUID
669
+ * @param input - UUID, string or Buffer to validate.
670
+ */
671
+ UUID.isValid = function (input) {
672
+ if (!input) {
673
+ return false;
674
+ }
675
+ if (input instanceof UUID) {
676
+ return true;
677
+ }
678
+ if (typeof input === 'string') {
679
+ return uuidValidateString(input);
680
+ }
681
+ if (isUint8Array(input)) {
682
+ // check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
683
+ if (input.length !== UUID_BYTE_LENGTH) {
684
+ return false;
685
+ }
686
+ return (input[6] & 0xf0) === 0x40 && (input[8] & 0x80) === 0x80;
687
+ }
688
+ return false;
689
+ };
690
+ /**
691
+ * Creates an UUID from a hex string representation of an UUID.
692
+ * @param hexString - 32 or 36 character hex string (dashes excluded/included).
693
+ */
694
+ UUID.createFromHexString = function (hexString) {
695
+ var buffer = uuidHexStringToBuffer(hexString);
696
+ return new UUID(buffer);
697
+ };
698
+ /**
699
+ * Converts to a string representation of this Id.
700
+ *
701
+ * @returns return the 36 character hex string representation.
702
+ * @internal
703
+ */
704
+ UUID.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
705
+ return this.inspect();
706
+ };
707
+ UUID.prototype.inspect = function () {
708
+ return "new UUID(\"".concat(this.toHexString(), "\")");
709
+ };
710
+ return UUID;
711
+ }(Binary));
640
712
 
641
713
  /**
642
714
  * A class representation of the BSON Code type.
@@ -2365,22 +2437,17 @@ var Double = /** @class */ (function () {
2365
2437
  if (options && (options.legacy || (options.relaxed && isFinite(this.value)))) {
2366
2438
  return this.value;
2367
2439
  }
2368
- // NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
2369
- // explicitly provided `-0` then we need to ensure the sign makes it into the output
2370
2440
  if (Object.is(Math.sign(this.value), -0)) {
2371
- return { $numberDouble: "-".concat(this.value.toFixed(1)) };
2441
+ // NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
2442
+ // explicitly provided `-0` then we need to ensure the sign makes it into the output
2443
+ return { $numberDouble: '-0.0' };
2372
2444
  }
2373
- var $numberDouble;
2374
2445
  if (Number.isInteger(this.value)) {
2375
- $numberDouble = this.value.toFixed(1);
2376
- if ($numberDouble.length >= 13) {
2377
- $numberDouble = this.value.toExponential(13).toUpperCase();
2378
- }
2446
+ return { $numberDouble: "".concat(this.value, ".0") };
2379
2447
  }
2380
2448
  else {
2381
- $numberDouble = this.value.toString();
2449
+ return { $numberDouble: "".concat(this.value) };
2382
2450
  }
2383
- return { $numberDouble: $numberDouble };
2384
2451
  };
2385
2452
  /** @internal */
2386
2453
  Double.fromExtendedJSON = function (doc, options) {
@@ -3000,12 +3067,12 @@ function isBSONType(value) {
3000
3067
  return (isObjectLike(value) && Reflect.has(value, '_bsontype') && typeof value._bsontype === 'string');
3001
3068
  }
3002
3069
  // INT32 boundaries
3003
- var BSON_INT32_MAX$1 = 0x7fffffff;
3004
- var BSON_INT32_MIN$1 = -0x80000000;
3070
+ var BSON_INT32_MAX = 0x7fffffff;
3071
+ var BSON_INT32_MIN = -0x80000000;
3005
3072
  // INT64 boundaries
3006
3073
  // const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
3007
- var BSON_INT64_MAX$1 = 0x8000000000000000;
3008
- var BSON_INT64_MIN$1 = -0x8000000000000000;
3074
+ var BSON_INT64_MAX = 0x8000000000000000;
3075
+ var BSON_INT64_MIN = -0x8000000000000000;
3009
3076
  // all the types where we don't need to do any special processing and can just pass the EJSON
3010
3077
  //straight to type.fromExtendedJSON
3011
3078
  var keysToCodecs = {
@@ -3033,9 +3100,9 @@ function deserializeValue(value, options) {
3033
3100
  // if it's an integer, should interpret as smallest BSON integer
3034
3101
  // that can represent it exactly. (if out of range, interpret as double.)
3035
3102
  if (Math.floor(value) === value) {
3036
- if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1)
3103
+ if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX)
3037
3104
  return new Int32(value);
3038
- if (value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1)
3105
+ if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX)
3039
3106
  return Long.fromNumber(value);
3040
3107
  }
3041
3108
  // If the number is a non-integer or out of integer range, should interpret as BSON Double.
@@ -3159,7 +3226,7 @@ function serializeValue(value, options) {
3159
3226
  if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) {
3160
3227
  // it's an integer
3161
3228
  if (Math.floor(value) === value) {
3162
- var int32Range = value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1, int64Range = value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1;
3229
+ var int32Range = value >= BSON_INT32_MIN && value <= BSON_INT32_MAX, int64Range = value >= BSON_INT64_MIN && value <= BSON_INT64_MAX;
3163
3230
  // interpret as being of the smallest BSON integer type that can represent the number exactly
3164
3231
  if (int32Range)
3165
3232
  return { $numberInt: value.toString() };
@@ -3484,85 +3551,6 @@ else {
3484
3551
  }());
3485
3552
  }
3486
3553
 
3487
- /** @internal */
3488
- var BSON_INT32_MAX = 0x7fffffff;
3489
- /** @internal */
3490
- var BSON_INT32_MIN = -0x80000000;
3491
- /** @internal */
3492
- var BSON_INT64_MAX = Math.pow(2, 63) - 1;
3493
- /** @internal */
3494
- var BSON_INT64_MIN = -Math.pow(2, 63);
3495
- /**
3496
- * Any integer up to 2^53 can be precisely represented by a double.
3497
- * @internal
3498
- */
3499
- var JS_INT_MAX = Math.pow(2, 53);
3500
- /**
3501
- * Any integer down to -2^53 can be precisely represented by a double.
3502
- * @internal
3503
- */
3504
- var JS_INT_MIN = -Math.pow(2, 53);
3505
- /** Number BSON Type @internal */
3506
- var BSON_DATA_NUMBER = 1;
3507
- /** String BSON Type @internal */
3508
- var BSON_DATA_STRING = 2;
3509
- /** Object BSON Type @internal */
3510
- var BSON_DATA_OBJECT = 3;
3511
- /** Array BSON Type @internal */
3512
- var BSON_DATA_ARRAY = 4;
3513
- /** Binary BSON Type @internal */
3514
- var BSON_DATA_BINARY = 5;
3515
- /** Binary BSON Type @internal */
3516
- var BSON_DATA_UNDEFINED = 6;
3517
- /** ObjectId BSON Type @internal */
3518
- var BSON_DATA_OID = 7;
3519
- /** Boolean BSON Type @internal */
3520
- var BSON_DATA_BOOLEAN = 8;
3521
- /** Date BSON Type @internal */
3522
- var BSON_DATA_DATE = 9;
3523
- /** null BSON Type @internal */
3524
- var BSON_DATA_NULL = 10;
3525
- /** RegExp BSON Type @internal */
3526
- var BSON_DATA_REGEXP = 11;
3527
- /** Code BSON Type @internal */
3528
- var BSON_DATA_DBPOINTER = 12;
3529
- /** Code BSON Type @internal */
3530
- var BSON_DATA_CODE = 13;
3531
- /** Symbol BSON Type @internal */
3532
- var BSON_DATA_SYMBOL = 14;
3533
- /** Code with Scope BSON Type @internal */
3534
- var BSON_DATA_CODE_W_SCOPE = 15;
3535
- /** 32 bit Integer BSON Type @internal */
3536
- var BSON_DATA_INT = 16;
3537
- /** Timestamp BSON Type @internal */
3538
- var BSON_DATA_TIMESTAMP = 17;
3539
- /** Long BSON Type @internal */
3540
- var BSON_DATA_LONG = 18;
3541
- /** Decimal128 BSON Type @internal */
3542
- var BSON_DATA_DECIMAL128 = 19;
3543
- /** MinKey BSON Type @internal */
3544
- var BSON_DATA_MIN_KEY = 0xff;
3545
- /** MaxKey BSON Type @internal */
3546
- var BSON_DATA_MAX_KEY = 0x7f;
3547
- /** Binary Default Type @internal */
3548
- var BSON_BINARY_SUBTYPE_DEFAULT = 0;
3549
- /** Binary Function Type @internal */
3550
- var BSON_BINARY_SUBTYPE_FUNCTION = 1;
3551
- /** Binary Byte Array Type @internal */
3552
- var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
3553
- /** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
3554
- var BSON_BINARY_SUBTYPE_UUID = 3;
3555
- /** Binary UUID Type @internal */
3556
- var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
3557
- /** Binary MD5 Type @internal */
3558
- var BSON_BINARY_SUBTYPE_MD5 = 5;
3559
- /** Encrypted BSON type @internal */
3560
- var BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
3561
- /** Column BSON type @internal */
3562
- var BSON_BINARY_SUBTYPE_COLUMN = 7;
3563
- /** Binary User Defined Type @internal */
3564
- var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
3565
-
3566
3554
  function calculateObjectSize$1(object, serializeFunctions, ignoreUndefined) {
3567
3555
  var totalLength = 4 + 1;
3568
3556
  if (Array.isArray(object)) {
@@ -3600,7 +3588,7 @@ value, serializeFunctions, isArray, ignoreUndefined) {
3600
3588
  if (Math.floor(value) === value &&
3601
3589
  value >= JS_INT_MIN &&
3602
3590
  value <= JS_INT_MAX) {
3603
- if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
3591
+ if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1) {
3604
3592
  // 32 bit
3605
3593
  return (name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (4 + 1);
3606
3594
  }
@@ -4102,6 +4090,9 @@ function deserializeObject(buffer, index, options, isArray) {
4102
4090
  }
4103
4091
  else {
4104
4092
  value = new Binary(buffer.slice(index, index + binarySize), subType);
4093
+ if (subType === BSON_BINARY_SUBTYPE_UUID_NEW) {
4094
+ value = value.toUUID();
4095
+ }
4105
4096
  }
4106
4097
  }
4107
4098
  else {
@@ -4127,8 +4118,11 @@ function deserializeObject(buffer, index, options, isArray) {
4127
4118
  if (promoteBuffers && promoteValues) {
4128
4119
  value = _buffer;
4129
4120
  }
4121
+ else if (subType === BSON_BINARY_SUBTYPE_UUID_NEW) {
4122
+ value = new Binary(buffer.slice(index, index + binarySize), subType).toUUID();
4123
+ }
4130
4124
  else {
4131
- value = new Binary(_buffer, subType);
4125
+ value = new Binary(buffer.slice(index, index + binarySize), subType);
4132
4126
  }
4133
4127
  }
4134
4128
  // Update the index
@@ -4455,8 +4449,8 @@ function serializeNumber(buffer, key, value, index, isArray) {
4455
4449
  // We have an integer value
4456
4450
  // TODO(NODE-2529): Add support for big int
4457
4451
  if (Number.isInteger(value) &&
4458
- value >= BSON_INT32_MIN &&
4459
- value <= BSON_INT32_MAX) {
4452
+ value >= BSON_INT32_MIN$1 &&
4453
+ value <= BSON_INT32_MAX$1) {
4460
4454
  // If the value fits in 32 bits encode as int32
4461
4455
  // Set int type 32 bits or less
4462
4456
  buffer[index++] = BSON_DATA_INT;
@@ -5433,5 +5427,5 @@ var BSON = {
5433
5427
  };
5434
5428
 
5435
5429
  export default BSON;
5436
- 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 };
5430
+ 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 };
5437
5431
  //# sourceMappingURL=bson.esm.js.map