bson 4.6.5 → 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.
package/bower.json CHANGED
@@ -22,5 +22,5 @@
22
22
  "test",
23
23
  "tools"
24
24
  ],
25
- "version": "4.6.5"
25
+ "version": "4.7.0"
26
26
  }
package/bson.d.ts CHANGED
@@ -597,8 +597,6 @@ export declare interface Int32Extended {
597
597
 
598
598
  declare const kId: unique symbol;
599
599
 
600
- declare const kId_2: unique symbol;
601
-
602
600
  /**
603
601
  * A class representing a 64-bit integer
604
602
  * @public
@@ -1166,10 +1164,8 @@ export declare type TimestampOverrides = '_bsontype' | 'toExtendedJSON' | 'fromE
1166
1164
  * A class representation of the BSON UUID type.
1167
1165
  * @public
1168
1166
  */
1169
- export declare class UUID {
1170
- _bsontype: 'UUID';
1167
+ export declare class UUID extends Binary {
1171
1168
  static cacheHexString: boolean;
1172
- /* Excluded from this release type: [kId] */
1173
1169
  /* Excluded from this release type: __id */
1174
1170
  /**
1175
1171
  * Create an UUID type
@@ -1183,9 +1179,6 @@ export declare class UUID {
1183
1179
  */
1184
1180
  get id(): Buffer;
1185
1181
  set id(value: Buffer);
1186
- /**
1187
- * Generate a 16 byte uuid v4 buffer used in UUIDs
1188
- */
1189
1182
  /**
1190
1183
  * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
1191
1184
  * @param includeDashes - should the string exclude dash-separators.
@@ -2265,174 +2265,84 @@ var bufferToUuidHexString = function (buffer, includeDashes) {
2265
2265
  : buffer.toString('hex');
2266
2266
  };
2267
2267
 
2268
- var BYTE_LENGTH = 16;
2269
- 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);
2270
2276
  /**
2271
- * A class representation of the BSON UUID type.
2272
- * @public
2277
+ * Any integer up to 2^53 can be precisely represented by a double.
2278
+ * @internal
2273
2279
  */
2274
- var UUID = /** @class */ (function () {
2275
- /**
2276
- * Create an UUID type
2277
- *
2278
- * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
2279
- */
2280
- function UUID(input) {
2281
- if (typeof input === 'undefined') {
2282
- // The most common use case (blank id, new UUID() instance)
2283
- this.id = UUID.generate();
2284
- }
2285
- else if (input instanceof UUID) {
2286
- this[kId$1] = buffer_1.from(input.id);
2287
- this.__id = input.__id;
2288
- }
2289
- else if (ArrayBuffer.isView(input) && input.byteLength === BYTE_LENGTH) {
2290
- this.id = ensureBuffer(input);
2291
- }
2292
- else if (typeof input === 'string') {
2293
- this.id = uuidHexStringToBuffer(input);
2294
- }
2295
- else {
2296
- 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).');
2297
- }
2298
- }
2299
- Object.defineProperty(UUID.prototype, "id", {
2300
- /**
2301
- * The UUID bytes
2302
- * @readonly
2303
- */
2304
- get: function () {
2305
- return this[kId$1];
2306
- },
2307
- set: function (value) {
2308
- this[kId$1] = value;
2309
- if (UUID.cacheHexString) {
2310
- this.__id = bufferToUuidHexString(value);
2311
- }
2312
- },
2313
- enumerable: false,
2314
- configurable: true
2315
- });
2316
- /**
2317
- * Generate a 16 byte uuid v4 buffer used in UUIDs
2318
- */
2319
- /**
2320
- * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
2321
- * @param includeDashes - should the string exclude dash-separators.
2322
- * */
2323
- UUID.prototype.toHexString = function (includeDashes) {
2324
- if (includeDashes === void 0) { includeDashes = true; }
2325
- if (UUID.cacheHexString && this.__id) {
2326
- return this.__id;
2327
- }
2328
- var uuidHexString = bufferToUuidHexString(this.id, includeDashes);
2329
- if (UUID.cacheHexString) {
2330
- this.__id = uuidHexString;
2331
- }
2332
- return uuidHexString;
2333
- };
2334
- /**
2335
- * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
2336
- */
2337
- UUID.prototype.toString = function (encoding) {
2338
- return encoding ? this.id.toString(encoding) : this.toHexString();
2339
- };
2340
- /**
2341
- * Converts the id into its JSON string representation.
2342
- * A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
2343
- */
2344
- UUID.prototype.toJSON = function () {
2345
- return this.toHexString();
2346
- };
2347
- /**
2348
- * Compares the equality of this UUID with `otherID`.
2349
- *
2350
- * @param otherId - UUID instance to compare against.
2351
- */
2352
- UUID.prototype.equals = function (otherId) {
2353
- if (!otherId) {
2354
- return false;
2355
- }
2356
- if (otherId instanceof UUID) {
2357
- return otherId.id.equals(this.id);
2358
- }
2359
- try {
2360
- return new UUID(otherId).id.equals(this.id);
2361
- }
2362
- catch (_a) {
2363
- return false;
2364
- }
2365
- };
2366
- /**
2367
- * Creates a Binary instance from the current UUID.
2368
- */
2369
- UUID.prototype.toBinary = function () {
2370
- return new Binary(this.id, Binary.SUBTYPE_UUID);
2371
- };
2372
- /**
2373
- * Generates a populated buffer containing a v4 uuid
2374
- */
2375
- UUID.generate = function () {
2376
- var bytes = randomBytes(BYTE_LENGTH);
2377
- // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
2378
- // Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
2379
- bytes[6] = (bytes[6] & 0x0f) | 0x40;
2380
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
2381
- return buffer_1.from(bytes);
2382
- };
2383
- /**
2384
- * Checks if a value is a valid bson UUID
2385
- * @param input - UUID, string or Buffer to validate.
2386
- */
2387
- UUID.isValid = function (input) {
2388
- if (!input) {
2389
- return false;
2390
- }
2391
- if (input instanceof UUID) {
2392
- return true;
2393
- }
2394
- if (typeof input === 'string') {
2395
- return uuidValidateString(input);
2396
- }
2397
- if (isUint8Array(input)) {
2398
- // check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
2399
- if (input.length !== BYTE_LENGTH) {
2400
- return false;
2401
- }
2402
- try {
2403
- // get this byte as hex: xxxxxxxx-xxxx-XXxx-xxxx-xxxxxxxxxxxx
2404
- // check first part as uuid version: xxxxxxxx-xxxx-Xxxx-xxxx-xxxxxxxxxxxx
2405
- return parseInt(input[6].toString(16)[0], 10) === Binary.SUBTYPE_UUID;
2406
- }
2407
- catch (_a) {
2408
- return false;
2409
- }
2410
- }
2411
- return false;
2412
- };
2413
- /**
2414
- * Creates an UUID from a hex string representation of an UUID.
2415
- * @param hexString - 32 or 36 character hex string (dashes excluded/included).
2416
- */
2417
- UUID.createFromHexString = function (hexString) {
2418
- var buffer = uuidHexStringToBuffer(hexString);
2419
- return new UUID(buffer);
2420
- };
2421
- /**
2422
- * Converts to a string representation of this Id.
2423
- *
2424
- * @returns return the 36 character hex string representation.
2425
- * @internal
2426
- */
2427
- UUID.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
2428
- return this.inspect();
2429
- };
2430
- UUID.prototype.inspect = function () {
2431
- return "new UUID(\"".concat(this.toHexString(), "\")");
2432
- };
2433
- return UUID;
2434
- }());
2435
- 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;
2436
2346
 
2437
2347
  /**
2438
2348
  * A class representation of the BSON Binary type.
@@ -2633,7 +2543,7 @@ var Binary = /** @class */ (function () {
2633
2543
  if (!data) {
2634
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 () {
@@ -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.
@@ -5034,12 +5106,12 @@ function isBSONType(value) {
5034
5106
  return (isObjectLike(value) && Reflect.has(value, '_bsontype') && typeof value._bsontype === 'string');
5035
5107
  }
5036
5108
  // INT32 boundaries
5037
- var BSON_INT32_MAX$1 = 0x7fffffff;
5038
- var BSON_INT32_MIN$1 = -0x80000000;
5109
+ var BSON_INT32_MAX = 0x7fffffff;
5110
+ var BSON_INT32_MIN = -0x80000000;
5039
5111
  // INT64 boundaries
5040
5112
  // const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
5041
- var BSON_INT64_MAX$1 = 0x8000000000000000;
5042
- var BSON_INT64_MIN$1 = -0x8000000000000000;
5113
+ var BSON_INT64_MAX = 0x8000000000000000;
5114
+ var BSON_INT64_MIN = -0x8000000000000000;
5043
5115
  // all the types where we don't need to do any special processing and can just pass the EJSON
5044
5116
  //straight to type.fromExtendedJSON
5045
5117
  var keysToCodecs = {
@@ -5067,9 +5139,9 @@ function deserializeValue(value, options) {
5067
5139
  // if it's an integer, should interpret as smallest BSON integer
5068
5140
  // that can represent it exactly. (if out of range, interpret as double.)
5069
5141
  if (Math.floor(value) === value) {
5070
- if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1)
5142
+ if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX)
5071
5143
  return new Int32(value);
5072
- if (value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1)
5144
+ if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX)
5073
5145
  return Long.fromNumber(value);
5074
5146
  }
5075
5147
  // If the number is a non-integer or out of integer range, should interpret as BSON Double.
@@ -5193,7 +5265,7 @@ function serializeValue(value, options) {
5193
5265
  if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) {
5194
5266
  // it's an integer
5195
5267
  if (Math.floor(value) === value) {
5196
- 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;
5197
5269
  // interpret as being of the smallest BSON integer type that can represent the number exactly
5198
5270
  if (int32Range)
5199
5271
  return { $numberInt: value.toString() };
@@ -5518,85 +5590,6 @@ else {
5518
5590
  }());
5519
5591
  }
5520
5592
 
5521
- /** @internal */
5522
- var BSON_INT32_MAX = 0x7fffffff;
5523
- /** @internal */
5524
- var BSON_INT32_MIN = -0x80000000;
5525
- /** @internal */
5526
- var BSON_INT64_MAX = Math.pow(2, 63) - 1;
5527
- /** @internal */
5528
- var BSON_INT64_MIN = -Math.pow(2, 63);
5529
- /**
5530
- * Any integer up to 2^53 can be precisely represented by a double.
5531
- * @internal
5532
- */
5533
- var JS_INT_MAX = Math.pow(2, 53);
5534
- /**
5535
- * Any integer down to -2^53 can be precisely represented by a double.
5536
- * @internal
5537
- */
5538
- var JS_INT_MIN = -Math.pow(2, 53);
5539
- /** Number BSON Type @internal */
5540
- var BSON_DATA_NUMBER = 1;
5541
- /** String BSON Type @internal */
5542
- var BSON_DATA_STRING = 2;
5543
- /** Object BSON Type @internal */
5544
- var BSON_DATA_OBJECT = 3;
5545
- /** Array BSON Type @internal */
5546
- var BSON_DATA_ARRAY = 4;
5547
- /** Binary BSON Type @internal */
5548
- var BSON_DATA_BINARY = 5;
5549
- /** Binary BSON Type @internal */
5550
- var BSON_DATA_UNDEFINED = 6;
5551
- /** ObjectId BSON Type @internal */
5552
- var BSON_DATA_OID = 7;
5553
- /** Boolean BSON Type @internal */
5554
- var BSON_DATA_BOOLEAN = 8;
5555
- /** Date BSON Type @internal */
5556
- var BSON_DATA_DATE = 9;
5557
- /** null BSON Type @internal */
5558
- var BSON_DATA_NULL = 10;
5559
- /** RegExp BSON Type @internal */
5560
- var BSON_DATA_REGEXP = 11;
5561
- /** Code BSON Type @internal */
5562
- var BSON_DATA_DBPOINTER = 12;
5563
- /** Code BSON Type @internal */
5564
- var BSON_DATA_CODE = 13;
5565
- /** Symbol BSON Type @internal */
5566
- var BSON_DATA_SYMBOL = 14;
5567
- /** Code with Scope BSON Type @internal */
5568
- var BSON_DATA_CODE_W_SCOPE = 15;
5569
- /** 32 bit Integer BSON Type @internal */
5570
- var BSON_DATA_INT = 16;
5571
- /** Timestamp BSON Type @internal */
5572
- var BSON_DATA_TIMESTAMP = 17;
5573
- /** Long BSON Type @internal */
5574
- var BSON_DATA_LONG = 18;
5575
- /** Decimal128 BSON Type @internal */
5576
- var BSON_DATA_DECIMAL128 = 19;
5577
- /** MinKey BSON Type @internal */
5578
- var BSON_DATA_MIN_KEY = 0xff;
5579
- /** MaxKey BSON Type @internal */
5580
- var BSON_DATA_MAX_KEY = 0x7f;
5581
- /** Binary Default Type @internal */
5582
- var BSON_BINARY_SUBTYPE_DEFAULT = 0;
5583
- /** Binary Function Type @internal */
5584
- var BSON_BINARY_SUBTYPE_FUNCTION = 1;
5585
- /** Binary Byte Array Type @internal */
5586
- var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
5587
- /** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
5588
- var BSON_BINARY_SUBTYPE_UUID = 3;
5589
- /** Binary UUID Type @internal */
5590
- var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
5591
- /** Binary MD5 Type @internal */
5592
- var BSON_BINARY_SUBTYPE_MD5 = 5;
5593
- /** Encrypted BSON type @internal */
5594
- var BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
5595
- /** Column BSON type @internal */
5596
- var BSON_BINARY_SUBTYPE_COLUMN = 7;
5597
- /** Binary User Defined Type @internal */
5598
- var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
5599
-
5600
5593
  function calculateObjectSize$1(object, serializeFunctions, ignoreUndefined) {
5601
5594
  var totalLength = 4 + 1;
5602
5595
  if (Array.isArray(object)) {
@@ -5634,7 +5627,7 @@ value, serializeFunctions, isArray, ignoreUndefined) {
5634
5627
  if (Math.floor(value) === value &&
5635
5628
  value >= JS_INT_MIN &&
5636
5629
  value <= JS_INT_MAX) {
5637
- if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
5630
+ if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1) {
5638
5631
  // 32 bit
5639
5632
  return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (4 + 1);
5640
5633
  }
@@ -6136,6 +6129,9 @@ function deserializeObject(buffer, index, options, isArray) {
6136
6129
  }
6137
6130
  else {
6138
6131
  value = new Binary(buffer.slice(index, index + binarySize), subType);
6132
+ if (subType === BSON_BINARY_SUBTYPE_UUID_NEW) {
6133
+ value = value.toUUID();
6134
+ }
6139
6135
  }
6140
6136
  }
6141
6137
  else {
@@ -6161,8 +6157,11 @@ function deserializeObject(buffer, index, options, isArray) {
6161
6157
  if (promoteBuffers && promoteValues) {
6162
6158
  value = _buffer;
6163
6159
  }
6160
+ else if (subType === BSON_BINARY_SUBTYPE_UUID_NEW) {
6161
+ value = new Binary(buffer.slice(index, index + binarySize), subType).toUUID();
6162
+ }
6164
6163
  else {
6165
- value = new Binary(_buffer, subType);
6164
+ value = new Binary(buffer.slice(index, index + binarySize), subType);
6166
6165
  }
6167
6166
  }
6168
6167
  // Update the index
@@ -6489,8 +6488,8 @@ function serializeNumber(buffer, key, value, index, isArray) {
6489
6488
  // We have an integer value
6490
6489
  // TODO(NODE-2529): Add support for big int
6491
6490
  if (Number.isInteger(value) &&
6492
- value >= BSON_INT32_MIN &&
6493
- value <= BSON_INT32_MAX) {
6491
+ value >= BSON_INT32_MIN$1 &&
6492
+ value <= BSON_INT32_MAX$1) {
6494
6493
  // If the value fits in 32 bits encode as int32
6495
6494
  // Set int type 32 bits or less
6496
6495
  buffer[index++] = BSON_DATA_INT;
@@ -7467,5 +7466,5 @@ var BSON = {
7467
7466
  };
7468
7467
 
7469
7468
  export default BSON;
7470
- 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 };
7471
7470
  //# sourceMappingURL=bson.browser.esm.js.map