bson 4.2.3 → 4.5.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 (66) hide show
  1. package/bower.json +1 -1
  2. package/bson.d.ts +84 -9
  3. package/dist/bson.browser.esm.js +991 -2292
  4. package/dist/bson.browser.esm.js.map +1 -1
  5. package/dist/bson.browser.umd.js +1095 -2397
  6. package/dist/bson.browser.umd.js.map +1 -1
  7. package/dist/bson.bundle.js +1097 -2397
  8. package/dist/bson.bundle.js.map +1 -1
  9. package/dist/bson.esm.js +945 -2254
  10. package/dist/bson.esm.js.map +1 -1
  11. package/lib/binary.js +9 -1
  12. package/lib/binary.js.map +1 -1
  13. package/lib/bson.js +6 -2
  14. package/lib/bson.js.map +1 -1
  15. package/lib/db_ref.js +4 -1
  16. package/lib/db_ref.js.map +1 -1
  17. package/lib/decimal128.js +14 -51
  18. package/lib/decimal128.js.map +1 -1
  19. package/lib/ensure_buffer.js +2 -5
  20. package/lib/ensure_buffer.js.map +1 -1
  21. package/lib/extended_json.js +48 -9
  22. package/lib/extended_json.js.map +1 -1
  23. package/lib/long.js +18 -5
  24. package/lib/long.js.map +1 -1
  25. package/lib/map.js +3 -15
  26. package/lib/map.js.map +1 -1
  27. package/lib/objectid.js +9 -17
  28. package/lib/objectid.js.map +1 -1
  29. package/lib/parser/calculate_size.js +5 -6
  30. package/lib/parser/calculate_size.js.map +1 -1
  31. package/lib/parser/deserializer.js +61 -47
  32. package/lib/parser/deserializer.js.map +1 -1
  33. package/lib/parser/serializer.js +14 -13
  34. package/lib/parser/serializer.js.map +1 -1
  35. package/lib/parser/utils.js +44 -27
  36. package/lib/parser/utils.js.map +1 -1
  37. package/lib/regexp.js +1 -3
  38. package/lib/regexp.js.map +1 -1
  39. package/lib/timestamp.js +8 -2
  40. package/lib/timestamp.js.map +1 -1
  41. package/lib/utils/global.js +18 -0
  42. package/lib/utils/global.js.map +1 -0
  43. package/lib/uuid.js +173 -42
  44. package/lib/uuid.js.map +1 -1
  45. package/lib/uuid_utils.js +34 -0
  46. package/lib/uuid_utils.js.map +1 -0
  47. package/package.json +12 -9
  48. package/src/binary.ts +14 -2
  49. package/src/bson.ts +4 -1
  50. package/src/db_ref.ts +6 -1
  51. package/src/decimal128.ts +14 -52
  52. package/src/ensure_buffer.ts +7 -7
  53. package/src/extended_json.ts +64 -16
  54. package/src/long.ts +19 -7
  55. package/src/map.ts +5 -25
  56. package/src/objectid.ts +12 -19
  57. package/src/parser/calculate_size.ts +8 -11
  58. package/src/parser/deserializer.ts +68 -51
  59. package/src/parser/serializer.ts +13 -12
  60. package/src/parser/utils.ts +56 -18
  61. package/src/regexp.ts +2 -4
  62. package/src/timestamp.ts +15 -7
  63. package/src/utils/global.ts +22 -0
  64. package/src/uuid.ts +192 -40
  65. package/src/uuid_utils.ts +32 -0
  66. package/HISTORY.md +0 -481
@@ -1,9 +1,3 @@
1
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2
-
3
- function unwrapExports (x) {
4
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
- }
6
-
7
1
  function createCommonjsModule(fn, module) {
8
2
  return module = { exports: {} }, fn(module, module.exports), module.exports;
9
3
  }
@@ -132,6 +126,7 @@ var base64Js = {
132
126
  fromByteArray: fromByteArray_1
133
127
  };
134
128
 
129
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
135
130
  var read = function read(buffer, offset, isLE, mLen, nBytes) {
136
131
  var e, m;
137
132
  var eLen = nBytes * 8 - mLen - 1;
@@ -226,9 +221,11 @@ var ieee754 = {
226
221
  write: write
227
222
  };
228
223
 
229
- var buffer = createCommonjsModule(function (module, exports) {
224
+ var buffer$1 = createCommonjsModule(function (module, exports) {
230
225
 
231
- var customInspectSymbol = typeof Symbol === 'function' && typeof Symbol["for"] === 'function' ? Symbol["for"]('nodejs.util.inspect.custom') : null;
226
+ var customInspectSymbol = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' ? // eslint-disable-line dot-notation
227
+ Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
228
+ : null;
232
229
  exports.Buffer = Buffer;
233
230
  exports.SlowBuffer = SlowBuffer;
234
231
  exports.INSPECT_MAX_BYTES = 50;
@@ -329,7 +326,7 @@ var buffer = createCommonjsModule(function (module, exports) {
329
326
  }
330
327
 
331
328
  if (ArrayBuffer.isView(value)) {
332
- return fromArrayLike(value);
329
+ return fromArrayView(value);
333
330
  }
334
331
 
335
332
  if (value == null) {
@@ -400,7 +397,7 @@ var buffer = createCommonjsModule(function (module, exports) {
400
397
  if (fill !== undefined) {
401
398
  // Only pay attention to encoding if it's a string. This
402
399
  // prevents accidentally sending in a number that would
403
- // be interpretted as a start offset.
400
+ // be interpreted as a start offset.
404
401
  return typeof encoding === 'string' ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
405
402
  }
406
403
 
@@ -471,6 +468,15 @@ var buffer = createCommonjsModule(function (module, exports) {
471
468
  return buf;
472
469
  }
473
470
 
471
+ function fromArrayView(arrayView) {
472
+ if (isInstance(arrayView, Uint8Array)) {
473
+ var copy = new Uint8Array(arrayView);
474
+ return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
475
+ }
476
+
477
+ return fromArrayLike(arrayView);
478
+ }
479
+
474
480
  function fromArrayBuffer(array, byteOffset, length) {
475
481
  if (byteOffset < 0 || array.byteLength < byteOffset) {
476
482
  throw new RangeError('"offset" is outside of buffer bounds');
@@ -615,14 +621,17 @@ var buffer = createCommonjsModule(function (module, exports) {
615
621
  var buf = list[i];
616
622
 
617
623
  if (isInstance(buf, Uint8Array)) {
618
- buf = Buffer.from(buf);
619
- }
620
-
621
- if (!Buffer.isBuffer(buf)) {
624
+ if (pos + buf.length > buffer.length) {
625
+ Buffer.from(buf).copy(buffer, pos);
626
+ } else {
627
+ Uint8Array.prototype.set.call(buffer, buf, pos);
628
+ }
629
+ } else if (!Buffer.isBuffer(buf)) {
622
630
  throw new TypeError('"list" argument must be an Array of Buffers');
631
+ } else {
632
+ buf.copy(buffer, pos);
623
633
  }
624
634
 
625
- buf.copy(buffer, pos);
626
635
  pos += buf.length;
627
636
  }
628
637
 
@@ -708,7 +717,7 @@ var buffer = createCommonjsModule(function (module, exports) {
708
717
 
709
718
  if (end <= 0) {
710
719
  return '';
711
- } // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
720
+ } // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
712
721
 
713
722
 
714
723
  end >>>= 0;
@@ -1084,10 +1093,6 @@ var buffer = createCommonjsModule(function (module, exports) {
1084
1093
  return blitBuffer(asciiToBytes(string), buf, offset, length);
1085
1094
  }
1086
1095
 
1087
- function latin1Write(buf, string, offset, length) {
1088
- return asciiWrite(buf, string, offset, length);
1089
- }
1090
-
1091
1096
  function base64Write(buf, string, offset, length) {
1092
1097
  return blitBuffer(base64ToBytes(string), buf, offset, length);
1093
1098
  }
@@ -1140,11 +1145,9 @@ var buffer = createCommonjsModule(function (module, exports) {
1140
1145
  return utf8Write(this, string, offset, length);
1141
1146
 
1142
1147
  case 'ascii':
1143
- return asciiWrite(this, string, offset, length);
1144
-
1145
1148
  case 'latin1':
1146
1149
  case 'binary':
1147
- return latin1Write(this, string, offset, length);
1150
+ return asciiWrite(this, string, offset, length);
1148
1151
 
1149
1152
  case 'base64':
1150
1153
  // Warning: maxLength not taken into account in base64Write
@@ -1322,9 +1325,9 @@ var buffer = createCommonjsModule(function (module, exports) {
1322
1325
 
1323
1326
  function utf16leSlice(buf, start, end) {
1324
1327
  var bytes = buf.slice(start, end);
1325
- var res = '';
1328
+ var res = ''; // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
1326
1329
 
1327
- for (var i = 0; i < bytes.length; i += 2) {
1330
+ for (var i = 0; i < bytes.length - 1; i += 2) {
1328
1331
  res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
1329
1332
  }
1330
1333
 
@@ -1366,7 +1369,7 @@ var buffer = createCommonjsModule(function (module, exports) {
1366
1369
  if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length');
1367
1370
  }
1368
1371
 
1369
- Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
1372
+ Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
1370
1373
  offset = offset >>> 0;
1371
1374
  byteLength = byteLength >>> 0;
1372
1375
  if (!noAssert) checkOffset(offset, byteLength, this.length);
@@ -1381,7 +1384,7 @@ var buffer = createCommonjsModule(function (module, exports) {
1381
1384
  return val;
1382
1385
  };
1383
1386
 
1384
- Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
1387
+ Buffer.prototype.readUintBE = Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
1385
1388
  offset = offset >>> 0;
1386
1389
  byteLength = byteLength >>> 0;
1387
1390
 
@@ -1399,31 +1402,31 @@ var buffer = createCommonjsModule(function (module, exports) {
1399
1402
  return val;
1400
1403
  };
1401
1404
 
1402
- Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
1405
+ Buffer.prototype.readUint8 = Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
1403
1406
  offset = offset >>> 0;
1404
1407
  if (!noAssert) checkOffset(offset, 1, this.length);
1405
1408
  return this[offset];
1406
1409
  };
1407
1410
 
1408
- Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
1411
+ Buffer.prototype.readUint16LE = Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
1409
1412
  offset = offset >>> 0;
1410
1413
  if (!noAssert) checkOffset(offset, 2, this.length);
1411
1414
  return this[offset] | this[offset + 1] << 8;
1412
1415
  };
1413
1416
 
1414
- Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
1417
+ Buffer.prototype.readUint16BE = Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
1415
1418
  offset = offset >>> 0;
1416
1419
  if (!noAssert) checkOffset(offset, 2, this.length);
1417
1420
  return this[offset] << 8 | this[offset + 1];
1418
1421
  };
1419
1422
 
1420
- Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
1423
+ Buffer.prototype.readUint32LE = Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
1421
1424
  offset = offset >>> 0;
1422
1425
  if (!noAssert) checkOffset(offset, 4, this.length);
1423
1426
  return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 0x1000000;
1424
1427
  };
1425
1428
 
1426
- Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
1429
+ Buffer.prototype.readUint32BE = Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
1427
1430
  offset = offset >>> 0;
1428
1431
  if (!noAssert) checkOffset(offset, 4, this.length);
1429
1432
  return this[offset] * 0x1000000 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
@@ -1526,7 +1529,7 @@ var buffer = createCommonjsModule(function (module, exports) {
1526
1529
  if (offset + ext > buf.length) throw new RangeError('Index out of range');
1527
1530
  }
1528
1531
 
1529
- Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
1532
+ Buffer.prototype.writeUintLE = Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
1530
1533
  value = +value;
1531
1534
  offset = offset >>> 0;
1532
1535
  byteLength = byteLength >>> 0;
@@ -1547,7 +1550,7 @@ var buffer = createCommonjsModule(function (module, exports) {
1547
1550
  return offset + byteLength;
1548
1551
  };
1549
1552
 
1550
- Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
1553
+ Buffer.prototype.writeUintBE = Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
1551
1554
  value = +value;
1552
1555
  offset = offset >>> 0;
1553
1556
  byteLength = byteLength >>> 0;
@@ -1568,7 +1571,7 @@ var buffer = createCommonjsModule(function (module, exports) {
1568
1571
  return offset + byteLength;
1569
1572
  };
1570
1573
 
1571
- Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
1574
+ Buffer.prototype.writeUint8 = Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
1572
1575
  value = +value;
1573
1576
  offset = offset >>> 0;
1574
1577
  if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
@@ -1576,7 +1579,7 @@ var buffer = createCommonjsModule(function (module, exports) {
1576
1579
  return offset + 1;
1577
1580
  };
1578
1581
 
1579
- Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
1582
+ Buffer.prototype.writeUint16LE = Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
1580
1583
  value = +value;
1581
1584
  offset = offset >>> 0;
1582
1585
  if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
@@ -1585,7 +1588,7 @@ var buffer = createCommonjsModule(function (module, exports) {
1585
1588
  return offset + 2;
1586
1589
  };
1587
1590
 
1588
- Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
1591
+ Buffer.prototype.writeUint16BE = Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
1589
1592
  value = +value;
1590
1593
  offset = offset >>> 0;
1591
1594
  if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
@@ -1594,7 +1597,7 @@ var buffer = createCommonjsModule(function (module, exports) {
1594
1597
  return offset + 2;
1595
1598
  };
1596
1599
 
1597
- Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
1600
+ Buffer.prototype.writeUint32LE = Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
1598
1601
  value = +value;
1599
1602
  offset = offset >>> 0;
1600
1603
  if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
@@ -1605,7 +1608,7 @@ var buffer = createCommonjsModule(function (module, exports) {
1605
1608
  return offset + 4;
1606
1609
  };
1607
1610
 
1608
- Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
1611
+ Buffer.prototype.writeUint32BE = Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
1609
1612
  value = +value;
1610
1613
  offset = offset >>> 0;
1611
1614
  if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
@@ -1791,11 +1794,6 @@ var buffer = createCommonjsModule(function (module, exports) {
1791
1794
  if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
1792
1795
  // Use built-in when available, missing from IE11
1793
1796
  this.copyWithin(targetStart, start, end);
1794
- } else if (this === target && start < targetStart && targetStart < end) {
1795
- // descending copy from end
1796
- for (var i = len - 1; i >= 0; --i) {
1797
- target[i + targetStart] = this[i + start];
1798
- }
1799
1797
  } else {
1800
1798
  Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
1801
1799
  }
@@ -2028,1020 +2026,25 @@ var buffer = createCommonjsModule(function (module, exports) {
2028
2026
  return table;
2029
2027
  }();
2030
2028
  });
2031
- var buffer_1 = buffer.Buffer;
2032
- var buffer_2 = buffer.SlowBuffer;
2033
- var buffer_3 = buffer.INSPECT_MAX_BYTES;
2034
- var buffer_4 = buffer.kMaxLength;
2035
-
2036
- /*! *****************************************************************************
2037
- Copyright (c) Microsoft Corporation.
2038
-
2039
- Permission to use, copy, modify, and/or distribute this software for any
2040
- purpose with or without fee is hereby granted.
2041
-
2042
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2043
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2044
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2045
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2046
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2047
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2048
- PERFORMANCE OF THIS SOFTWARE.
2049
- ***************************************************************************** */
2050
-
2051
- /* global Reflect, Promise */
2052
- var _extendStatics = function extendStatics(d, b) {
2053
- _extendStatics = Object.setPrototypeOf || {
2054
- __proto__: []
2055
- } instanceof Array && function (d, b) {
2056
- d.__proto__ = b;
2057
- } || function (d, b) {
2058
- for (var p in b) {
2059
- if (b.hasOwnProperty(p)) d[p] = b[p];
2060
- }
2061
- };
2029
+ var buffer_1 = buffer$1.Buffer;
2030
+ buffer$1.SlowBuffer;
2031
+ buffer$1.INSPECT_MAX_BYTES;
2032
+ buffer$1.kMaxLength;
2062
2033
 
2063
- return _extendStatics(d, b);
2064
- };
2065
-
2066
- function __extends(d, b) {
2067
- _extendStatics(d, b);
2068
-
2069
- function __() {
2070
- this.constructor = d;
2071
- }
2072
-
2073
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
2074
- }
2075
-
2076
- var _assign = function __assign() {
2077
- _assign = Object.assign || function __assign(t) {
2078
- for (var s, i = 1, n = arguments.length; i < n; i++) {
2079
- s = arguments[i];
2080
-
2081
- for (var p in s) {
2082
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
2083
- }
2084
- }
2085
-
2086
- return t;
2087
- };
2088
-
2089
- return _assign.apply(this, arguments);
2090
- };
2091
- function __rest(s, e) {
2092
- var t = {};
2093
-
2094
- for (var p in s) {
2095
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
2096
- }
2097
-
2098
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
2099
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
2100
- }
2101
- return t;
2102
- }
2103
- function __decorate(decorators, target, key, desc) {
2104
- var c = arguments.length,
2105
- r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
2106
- d;
2107
- if ((typeof Reflect === "undefined" ? "undefined" : babelHelpers["typeof"](Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
2108
- if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2109
- }
2110
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2111
- }
2112
- function __param(paramIndex, decorator) {
2113
- return function (target, key) {
2114
- decorator(target, key, paramIndex);
2115
- };
2116
- }
2117
- function __metadata(metadataKey, metadataValue) {
2118
- if ((typeof Reflect === "undefined" ? "undefined" : babelHelpers["typeof"](Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
2119
- }
2120
- function __awaiter(thisArg, _arguments, P, generator) {
2121
- function adopt(value) {
2122
- return value instanceof P ? value : new P(function (resolve) {
2123
- resolve(value);
2124
- });
2125
- }
2126
-
2127
- return new (P || (P = Promise))(function (resolve, reject) {
2128
- function fulfilled(value) {
2129
- try {
2130
- step(generator.next(value));
2131
- } catch (e) {
2132
- reject(e);
2133
- }
2134
- }
2135
-
2136
- function rejected(value) {
2137
- try {
2138
- step(generator["throw"](value));
2139
- } catch (e) {
2140
- reject(e);
2141
- }
2142
- }
2143
-
2144
- function step(result) {
2145
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
2146
- }
2147
-
2148
- step((generator = generator.apply(thisArg, _arguments || [])).next());
2149
- });
2150
- }
2151
- function __generator(thisArg, body) {
2152
- var _ = {
2153
- label: 0,
2154
- sent: function sent() {
2155
- if (t[0] & 1) throw t[1];
2156
- return t[1];
2157
- },
2158
- trys: [],
2159
- ops: []
2160
- },
2161
- f,
2162
- y,
2163
- t,
2164
- g;
2165
- return g = {
2166
- next: verb(0),
2167
- "throw": verb(1),
2168
- "return": verb(2)
2169
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
2170
- return this;
2171
- }), g;
2172
-
2173
- function verb(n) {
2174
- return function (v) {
2175
- return step([n, v]);
2176
- };
2177
- }
2178
-
2179
- function step(op) {
2180
- if (f) throw new TypeError("Generator is already executing.");
2181
-
2182
- while (_) {
2183
- try {
2184
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
2185
- if (y = 0, t) op = [op[0] & 2, t.value];
2186
-
2187
- switch (op[0]) {
2188
- case 0:
2189
- case 1:
2190
- t = op;
2191
- break;
2192
-
2193
- case 4:
2194
- _.label++;
2195
- return {
2196
- value: op[1],
2197
- done: false
2198
- };
2199
-
2200
- case 5:
2201
- _.label++;
2202
- y = op[1];
2203
- op = [0];
2204
- continue;
2205
-
2206
- case 7:
2207
- op = _.ops.pop();
2208
-
2209
- _.trys.pop();
2210
-
2211
- continue;
2212
-
2213
- default:
2214
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
2215
- _ = 0;
2216
- continue;
2217
- }
2218
-
2219
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
2220
- _.label = op[1];
2221
- break;
2222
- }
2223
-
2224
- if (op[0] === 6 && _.label < t[1]) {
2225
- _.label = t[1];
2226
- t = op;
2227
- break;
2228
- }
2229
-
2230
- if (t && _.label < t[2]) {
2231
- _.label = t[2];
2232
-
2233
- _.ops.push(op);
2234
-
2235
- break;
2236
- }
2237
-
2238
- if (t[2]) _.ops.pop();
2239
-
2240
- _.trys.pop();
2241
-
2242
- continue;
2243
- }
2244
-
2245
- op = body.call(thisArg, _);
2246
- } catch (e) {
2247
- op = [6, e];
2248
- y = 0;
2249
- } finally {
2250
- f = t = 0;
2251
- }
2252
- }
2253
-
2254
- if (op[0] & 5) throw op[1];
2255
- return {
2256
- value: op[0] ? op[1] : void 0,
2257
- done: true
2258
- };
2259
- }
2260
- }
2261
- function __createBinding(o, m, k, k2) {
2262
- if (k2 === undefined) k2 = k;
2263
- o[k2] = m[k];
2264
- }
2265
- function __exportStar(m, exports) {
2266
- for (var p in m) {
2267
- if (p !== "default" && !exports.hasOwnProperty(p)) exports[p] = m[p];
2268
- }
2269
- }
2270
- function __values(o) {
2271
- var s = typeof Symbol === "function" && Symbol.iterator,
2272
- m = s && o[s],
2273
- i = 0;
2274
- if (m) return m.call(o);
2275
- if (o && typeof o.length === "number") return {
2276
- next: function next() {
2277
- if (o && i >= o.length) o = void 0;
2278
- return {
2279
- value: o && o[i++],
2280
- done: !o
2281
- };
2282
- }
2283
- };
2284
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
2285
- }
2286
- function __read(o, n) {
2287
- var m = typeof Symbol === "function" && o[Symbol.iterator];
2288
- if (!m) return o;
2289
- var i = m.call(o),
2290
- r,
2291
- ar = [],
2292
- e;
2293
-
2294
- try {
2295
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
2296
- ar.push(r.value);
2297
- }
2298
- } catch (error) {
2299
- e = {
2300
- error: error
2301
- };
2302
- } finally {
2303
- try {
2304
- if (r && !r.done && (m = i["return"])) m.call(i);
2305
- } finally {
2306
- if (e) throw e.error;
2307
- }
2308
- }
2309
-
2310
- return ar;
2311
- }
2312
- function __spread() {
2313
- for (var ar = [], i = 0; i < arguments.length; i++) {
2314
- ar = ar.concat(__read(arguments[i]));
2315
- }
2316
-
2317
- return ar;
2318
- }
2319
- function __spreadArrays() {
2320
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) {
2321
- s += arguments[i].length;
2322
- }
2323
-
2324
- for (var r = Array(s), k = 0, i = 0; i < il; i++) {
2325
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) {
2326
- r[k] = a[j];
2327
- }
2328
- }
2329
-
2330
- return r;
2331
- }
2332
- function __await(v) {
2333
- return this instanceof __await ? (this.v = v, this) : new __await(v);
2334
- }
2335
- function __asyncGenerator(thisArg, _arguments, generator) {
2336
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
2337
- var g = generator.apply(thisArg, _arguments || []),
2338
- i,
2339
- q = [];
2340
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
2341
- return this;
2342
- }, i;
2343
-
2344
- function verb(n) {
2345
- if (g[n]) i[n] = function (v) {
2346
- return new Promise(function (a, b) {
2347
- q.push([n, v, a, b]) > 1 || resume(n, v);
2348
- });
2349
- };
2350
- }
2351
-
2352
- function resume(n, v) {
2353
- try {
2354
- step(g[n](v));
2355
- } catch (e) {
2356
- settle(q[0][3], e);
2357
- }
2358
- }
2359
-
2360
- function step(r) {
2361
- r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
2362
- }
2363
-
2364
- function fulfill(value) {
2365
- resume("next", value);
2366
- }
2367
-
2368
- function reject(value) {
2369
- resume("throw", value);
2370
- }
2371
-
2372
- function settle(f, v) {
2373
- if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
2374
- }
2375
- }
2376
- function __asyncDelegator(o) {
2377
- var i, p;
2378
- return i = {}, verb("next"), verb("throw", function (e) {
2379
- throw e;
2380
- }), verb("return"), i[Symbol.iterator] = function () {
2381
- return this;
2382
- }, i;
2383
-
2384
- function verb(n, f) {
2385
- i[n] = o[n] ? function (v) {
2386
- return (p = !p) ? {
2387
- value: __await(o[n](v)),
2388
- done: n === "return"
2389
- } : f ? f(v) : v;
2390
- } : f;
2391
- }
2392
- }
2393
- function __asyncValues(o) {
2394
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
2395
- var m = o[Symbol.asyncIterator],
2396
- i;
2397
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
2398
- return this;
2399
- }, i);
2400
-
2401
- function verb(n) {
2402
- i[n] = o[n] && function (v) {
2403
- return new Promise(function (resolve, reject) {
2404
- v = o[n](v), settle(resolve, reject, v.done, v.value);
2405
- });
2406
- };
2407
- }
2408
-
2409
- function settle(resolve, reject, d, v) {
2410
- Promise.resolve(v).then(function (v) {
2411
- resolve({
2412
- value: v,
2413
- done: d
2414
- });
2415
- }, reject);
2416
- }
2417
- }
2418
- function __makeTemplateObject(cooked, raw) {
2419
- if (Object.defineProperty) {
2420
- Object.defineProperty(cooked, "raw", {
2421
- value: raw
2422
- });
2423
- } else {
2424
- cooked.raw = raw;
2425
- }
2426
-
2427
- return cooked;
2428
- }
2429
- function __importStar(mod) {
2430
- if (mod && mod.__esModule) return mod;
2431
- var result = {};
2432
- if (mod != null) for (var k in mod) {
2433
- if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
2434
- }
2435
- result["default"] = mod;
2436
- return result;
2437
- }
2438
- function __importDefault(mod) {
2439
- return mod && mod.__esModule ? mod : {
2440
- "default": mod
2441
- };
2442
- }
2443
- function __classPrivateFieldGet(receiver, privateMap) {
2444
- if (!privateMap.has(receiver)) {
2445
- throw new TypeError("attempted to get private field on non-instance");
2446
- }
2447
-
2448
- return privateMap.get(receiver);
2449
- }
2450
- function __classPrivateFieldSet(receiver, privateMap, value) {
2451
- if (!privateMap.has(receiver)) {
2452
- throw new TypeError("attempted to set private field on non-instance");
2453
- }
2454
-
2455
- privateMap.set(receiver, value);
2456
- return value;
2457
- }
2458
-
2459
- var tslib_es6 = /*#__PURE__*/Object.freeze({
2460
- __proto__: null,
2461
- __extends: __extends,
2462
- get __assign () { return _assign; },
2463
- __rest: __rest,
2464
- __decorate: __decorate,
2465
- __param: __param,
2466
- __metadata: __metadata,
2467
- __awaiter: __awaiter,
2468
- __generator: __generator,
2469
- __createBinding: __createBinding,
2470
- __exportStar: __exportStar,
2471
- __values: __values,
2472
- __read: __read,
2473
- __spread: __spread,
2474
- __spreadArrays: __spreadArrays,
2475
- __await: __await,
2476
- __asyncGenerator: __asyncGenerator,
2477
- __asyncDelegator: __asyncDelegator,
2478
- __asyncValues: __asyncValues,
2479
- __makeTemplateObject: __makeTemplateObject,
2480
- __importStar: __importStar,
2481
- __importDefault: __importDefault,
2482
- __classPrivateFieldGet: __classPrivateFieldGet,
2483
- __classPrivateFieldSet: __classPrivateFieldSet
2484
- });
2485
-
2486
- var require$$0 = {};
2487
-
2488
- var inherits;
2489
-
2490
- if (typeof Object.create === 'function') {
2491
- inherits = function inherits(ctor, superCtor) {
2492
- // implementation from standard node.js 'util' module
2493
- ctor.super_ = superCtor;
2494
- ctor.prototype = Object.create(superCtor.prototype, {
2495
- constructor: {
2496
- value: ctor,
2497
- enumerable: false,
2498
- writable: true,
2499
- configurable: true
2500
- }
2501
- });
2502
- };
2503
- } else {
2504
- inherits = function inherits(ctor, superCtor) {
2505
- ctor.super_ = superCtor;
2506
-
2507
- var TempCtor = function TempCtor() {};
2508
-
2509
- TempCtor.prototype = superCtor.prototype;
2510
- ctor.prototype = new TempCtor();
2511
- ctor.prototype.constructor = ctor;
2512
- };
2513
- }
2514
-
2515
- var inherits$1 = inherits;
2516
-
2517
- // Copyright Joyent, Inc. and other Node contributors.
2518
- var formatRegExp = /%[sdj%]/g;
2519
- function format(f) {
2520
- if (!isString(f)) {
2521
- var objects = [];
2522
-
2523
- for (var i = 0; i < arguments.length; i++) {
2524
- objects.push(inspect(arguments[i]));
2525
- }
2526
-
2527
- return objects.join(' ');
2528
- }
2529
-
2530
- var i = 1;
2531
- var args = arguments;
2532
- var len = args.length;
2533
- var str = String(f).replace(formatRegExp, function (x) {
2534
- if (x === '%%') return '%';
2535
- if (i >= len) return x;
2536
-
2537
- switch (x) {
2538
- case '%s':
2539
- return String(args[i++]);
2540
-
2541
- case '%d':
2542
- return Number(args[i++]);
2543
-
2544
- case '%j':
2545
- try {
2546
- return JSON.stringify(args[i++]);
2547
- } catch (_) {
2548
- return '[Circular]';
2549
- }
2550
-
2551
- default:
2552
- return x;
2553
- }
2554
- });
2555
-
2556
- for (var x = args[i]; i < len; x = args[++i]) {
2557
- if (isNull(x) || !isObject(x)) {
2558
- str += ' ' + x;
2559
- } else {
2560
- str += ' ' + inspect(x);
2561
- }
2562
- }
2563
-
2564
- return str;
2565
- }
2566
- // Returns a modified function which warns once by default.
2567
- // If --no-deprecation is set, then it is a no-op.
2568
-
2569
- function deprecate(fn, msg) {
2570
- // Allow for deprecating things in the process of starting up.
2571
- if (isUndefined(global.process)) {
2572
- return function () {
2573
- return deprecate(fn, msg).apply(this, arguments);
2574
- };
2575
- }
2576
-
2577
- var warned = false;
2578
-
2579
- function deprecated() {
2580
- if (!warned) {
2581
- {
2582
- console.error(msg);
2583
- }
2584
-
2585
- warned = true;
2586
- }
2587
-
2588
- return fn.apply(this, arguments);
2589
- }
2590
-
2591
- return deprecated;
2592
- }
2593
- var debugs = {};
2594
- var debugEnviron;
2595
- function debuglog(set) {
2596
- if (isUndefined(debugEnviron)) debugEnviron = '';
2597
- set = set.toUpperCase();
2598
-
2599
- if (!debugs[set]) {
2600
- if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
2601
- var pid = 0;
2602
-
2603
- debugs[set] = function () {
2604
- var msg = format.apply(null, arguments);
2605
- console.error('%s %d: %s', set, pid, msg);
2606
- };
2607
- } else {
2608
- debugs[set] = function () {};
2609
- }
2610
- }
2611
-
2612
- return debugs[set];
2613
- }
2614
- /**
2615
- * Echos the value of a value. Trys to print the value out
2616
- * in the best way possible given the different types.
2617
- *
2618
- * @param {Object} obj The object to print out.
2619
- * @param {Object} opts Optional options object that alters the output.
2620
- */
2621
-
2622
- /* legacy: obj, showHidden, depth, colors*/
2623
-
2624
- function inspect(obj, opts) {
2625
- // default options
2626
- var ctx = {
2627
- seen: [],
2628
- stylize: stylizeNoColor
2629
- }; // legacy...
2630
-
2631
- if (arguments.length >= 3) ctx.depth = arguments[2];
2632
- if (arguments.length >= 4) ctx.colors = arguments[3];
2633
-
2634
- if (isBoolean(opts)) {
2635
- // legacy...
2636
- ctx.showHidden = opts;
2637
- } else if (opts) {
2638
- // got an "options" object
2639
- _extend(ctx, opts);
2640
- } // set default options
2641
-
2642
-
2643
- if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
2644
- if (isUndefined(ctx.depth)) ctx.depth = 2;
2645
- if (isUndefined(ctx.colors)) ctx.colors = false;
2646
- if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
2647
- if (ctx.colors) ctx.stylize = stylizeWithColor;
2648
- return formatValue(ctx, obj, ctx.depth);
2649
- } // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
2650
-
2651
- inspect.colors = {
2652
- 'bold': [1, 22],
2653
- 'italic': [3, 23],
2654
- 'underline': [4, 24],
2655
- 'inverse': [7, 27],
2656
- 'white': [37, 39],
2657
- 'grey': [90, 39],
2658
- 'black': [30, 39],
2659
- 'blue': [34, 39],
2660
- 'cyan': [36, 39],
2661
- 'green': [32, 39],
2662
- 'magenta': [35, 39],
2663
- 'red': [31, 39],
2664
- 'yellow': [33, 39]
2665
- }; // Don't use 'blue' not visible on cmd.exe
2666
-
2667
- inspect.styles = {
2668
- 'special': 'cyan',
2669
- 'number': 'yellow',
2670
- 'boolean': 'yellow',
2671
- 'undefined': 'grey',
2672
- 'null': 'bold',
2673
- 'string': 'green',
2674
- 'date': 'magenta',
2675
- // "name": intentionally not styling
2676
- 'regexp': 'red'
2677
- };
2678
-
2679
- function stylizeWithColor(str, styleType) {
2680
- var style = inspect.styles[styleType];
2681
-
2682
- if (style) {
2683
- return "\x1B[" + inspect.colors[style][0] + 'm' + str + "\x1B[" + inspect.colors[style][1] + 'm';
2684
- } else {
2685
- return str;
2686
- }
2687
- }
2688
-
2689
- function stylizeNoColor(str, styleType) {
2690
- return str;
2691
- }
2692
-
2693
- function arrayToHash(array) {
2694
- var hash = {};
2695
- array.forEach(function (val, idx) {
2696
- hash[val] = true;
2697
- });
2698
- return hash;
2699
- }
2700
-
2701
- function formatValue(ctx, value, recurseTimes) {
2702
- // Provide a hook for user-specified inspect functions.
2703
- // Check that value is an object with an inspect function on it
2704
- if (ctx.customInspect && value && isFunction(value.inspect) && // Filter out the util module, it's inspect function is special
2705
- value.inspect !== inspect && // Also filter out any prototype objects using the circular check.
2706
- !(value.constructor && value.constructor.prototype === value)) {
2707
- var ret = value.inspect(recurseTimes, ctx);
2708
-
2709
- if (!isString(ret)) {
2710
- ret = formatValue(ctx, ret, recurseTimes);
2711
- }
2712
-
2713
- return ret;
2714
- } // Primitive types cannot have properties
2715
-
2716
-
2717
- var primitive = formatPrimitive(ctx, value);
2718
-
2719
- if (primitive) {
2720
- return primitive;
2721
- } // Look up the keys of the object.
2722
-
2723
-
2724
- var keys = Object.keys(value);
2725
- var visibleKeys = arrayToHash(keys);
2726
-
2727
- if (ctx.showHidden) {
2728
- keys = Object.getOwnPropertyNames(value);
2729
- } // IE doesn't make error fields non-enumerable
2730
- // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
2731
-
2732
-
2733
- if (isError(value) && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
2734
- return formatError(value);
2735
- } // Some type of object without properties can be shortcutted.
2736
-
2737
-
2738
- if (keys.length === 0) {
2739
- if (isFunction(value)) {
2740
- var name = value.name ? ': ' + value.name : '';
2741
- return ctx.stylize('[Function' + name + ']', 'special');
2742
- }
2743
-
2744
- if (isRegExp(value)) {
2745
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
2746
- }
2747
-
2748
- if (isDate(value)) {
2749
- return ctx.stylize(Date.prototype.toString.call(value), 'date');
2750
- }
2751
-
2752
- if (isError(value)) {
2753
- return formatError(value);
2754
- }
2755
- }
2756
-
2757
- var base = '',
2758
- array = false,
2759
- braces = ['{', '}']; // Make Array say that they are Array
2760
-
2761
- if (isArray(value)) {
2762
- array = true;
2763
- braces = ['[', ']'];
2764
- } // Make functions say that they are functions
2765
-
2766
-
2767
- if (isFunction(value)) {
2768
- var n = value.name ? ': ' + value.name : '';
2769
- base = ' [Function' + n + ']';
2770
- } // Make RegExps say that they are RegExps
2771
-
2772
-
2773
- if (isRegExp(value)) {
2774
- base = ' ' + RegExp.prototype.toString.call(value);
2775
- } // Make dates with properties first say the date
2776
-
2777
-
2778
- if (isDate(value)) {
2779
- base = ' ' + Date.prototype.toUTCString.call(value);
2780
- } // Make error with message first say the error
2781
-
2782
-
2783
- if (isError(value)) {
2784
- base = ' ' + formatError(value);
2785
- }
2786
-
2787
- if (keys.length === 0 && (!array || value.length == 0)) {
2788
- return braces[0] + base + braces[1];
2789
- }
2790
-
2791
- if (recurseTimes < 0) {
2792
- if (isRegExp(value)) {
2793
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
2794
- } else {
2795
- return ctx.stylize('[Object]', 'special');
2796
- }
2797
- }
2798
-
2799
- ctx.seen.push(value);
2800
- var output;
2801
-
2802
- if (array) {
2803
- output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
2804
- } else {
2805
- output = keys.map(function (key) {
2806
- return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
2807
- });
2808
- }
2809
-
2810
- ctx.seen.pop();
2811
- return reduceToSingleString(output, base, braces);
2812
- }
2813
-
2814
- function formatPrimitive(ctx, value) {
2815
- if (isUndefined(value)) return ctx.stylize('undefined', 'undefined');
2816
-
2817
- if (isString(value)) {
2818
- var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\'';
2819
- return ctx.stylize(simple, 'string');
2820
- }
2821
-
2822
- if (isNumber(value)) return ctx.stylize('' + value, 'number');
2823
- if (isBoolean(value)) return ctx.stylize('' + value, 'boolean'); // For some reason typeof null is "object", so special case here.
2824
-
2825
- if (isNull(value)) return ctx.stylize('null', 'null');
2826
- }
2827
-
2828
- function formatError(value) {
2829
- return '[' + Error.prototype.toString.call(value) + ']';
2830
- }
2831
-
2832
- function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
2833
- var output = [];
2834
-
2835
- for (var i = 0, l = value.length; i < l; ++i) {
2836
- if (hasOwnProperty(value, String(i))) {
2837
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true));
2838
- } else {
2839
- output.push('');
2840
- }
2841
- }
2842
-
2843
- keys.forEach(function (key) {
2844
- if (!key.match(/^\d+$/)) {
2845
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true));
2846
- }
2847
- });
2848
- return output;
2849
- }
2850
-
2851
- function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
2852
- var name, str, desc;
2853
- desc = Object.getOwnPropertyDescriptor(value, key) || {
2854
- value: value[key]
2855
- };
2856
-
2857
- if (desc.get) {
2858
- if (desc.set) {
2859
- str = ctx.stylize('[Getter/Setter]', 'special');
2860
- } else {
2861
- str = ctx.stylize('[Getter]', 'special');
2862
- }
2863
- } else {
2864
- if (desc.set) {
2865
- str = ctx.stylize('[Setter]', 'special');
2866
- }
2867
- }
2868
-
2869
- if (!hasOwnProperty(visibleKeys, key)) {
2870
- name = '[' + key + ']';
2871
- }
2872
-
2873
- if (!str) {
2874
- if (ctx.seen.indexOf(desc.value) < 0) {
2875
- if (isNull(recurseTimes)) {
2876
- str = formatValue(ctx, desc.value, null);
2877
- } else {
2878
- str = formatValue(ctx, desc.value, recurseTimes - 1);
2879
- }
2880
-
2881
- if (str.indexOf('\n') > -1) {
2882
- if (array) {
2883
- str = str.split('\n').map(function (line) {
2884
- return ' ' + line;
2885
- }).join('\n').substr(2);
2886
- } else {
2887
- str = '\n' + str.split('\n').map(function (line) {
2888
- return ' ' + line;
2889
- }).join('\n');
2890
- }
2891
- }
2892
- } else {
2893
- str = ctx.stylize('[Circular]', 'special');
2894
- }
2895
- }
2896
-
2897
- if (isUndefined(name)) {
2898
- if (array && key.match(/^\d+$/)) {
2899
- return str;
2900
- }
2901
-
2902
- name = JSON.stringify('' + key);
2903
-
2904
- if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
2905
- name = name.substr(1, name.length - 2);
2906
- name = ctx.stylize(name, 'name');
2907
- } else {
2908
- name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
2909
- name = ctx.stylize(name, 'string');
2910
- }
2911
- }
2912
-
2913
- return name + ': ' + str;
2914
- }
2915
-
2916
- function reduceToSingleString(output, base, braces) {
2917
- var length = output.reduce(function (prev, cur) {
2918
- if (cur.indexOf('\n') >= 0) ;
2919
- return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
2920
- }, 0);
2921
-
2922
- if (length > 60) {
2923
- return braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1];
2924
- }
2925
-
2926
- return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
2927
- } // NOTE: These type checking functions intentionally don't use `instanceof`
2928
- // because it is fragile and can be easily faked with `Object.create()`.
2929
-
2930
-
2931
- function isArray(ar) {
2932
- return Array.isArray(ar);
2933
- }
2934
- function isBoolean(arg) {
2935
- return typeof arg === 'boolean';
2936
- }
2937
- function isNull(arg) {
2938
- return arg === null;
2939
- }
2940
- function isNullOrUndefined(arg) {
2941
- return arg == null;
2942
- }
2943
- function isNumber(arg) {
2944
- return typeof arg === 'number';
2945
- }
2946
- function isString(arg) {
2947
- return typeof arg === 'string';
2948
- }
2949
- function isSymbol(arg) {
2950
- return babelHelpers["typeof"](arg) === 'symbol';
2951
- }
2952
- function isUndefined(arg) {
2953
- return arg === void 0;
2954
- }
2955
- function isRegExp(re) {
2956
- return isObject(re) && objectToString(re) === '[object RegExp]';
2957
- }
2958
- function isObject(arg) {
2959
- return babelHelpers["typeof"](arg) === 'object' && arg !== null;
2960
- }
2961
- function isDate(d) {
2962
- return isObject(d) && objectToString(d) === '[object Date]';
2963
- }
2964
- function isError(e) {
2965
- return isObject(e) && (objectToString(e) === '[object Error]' || e instanceof Error);
2966
- }
2967
- function isFunction(arg) {
2968
- return typeof arg === 'function';
2969
- }
2970
- function isPrimitive(arg) {
2971
- return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || babelHelpers["typeof"](arg) === 'symbol' || // ES6 symbol
2972
- typeof arg === 'undefined';
2973
- }
2974
- function isBuffer(maybeBuf) {
2975
- return Buffer.isBuffer(maybeBuf);
2976
- }
2977
-
2978
- function objectToString(o) {
2979
- return Object.prototype.toString.call(o);
2980
- }
2981
-
2982
- function pad(n) {
2983
- return n < 10 ? '0' + n.toString(10) : n.toString(10);
2984
- }
2985
-
2986
- var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; // 26 Feb 16:19:34
2987
-
2988
- function timestamp() {
2989
- var d = new Date();
2990
- var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':');
2991
- return [d.getDate(), months[d.getMonth()], time].join(' ');
2992
- } // log is just a thin wrapper to console.log that prepends a timestamp
2993
-
2994
-
2995
- function log() {
2996
- console.log('%s - %s', timestamp(), format.apply(null, arguments));
2997
- }
2998
- function _extend(origin, add) {
2999
- // Don't do anything if add isn't an object
3000
- if (!add || !isObject(add)) return origin;
3001
- var keys = Object.keys(add);
3002
- var i = keys.length;
3003
-
3004
- while (i--) {
3005
- origin[keys[i]] = add[keys[i]];
3006
- }
3007
-
3008
- return origin;
2034
+ function checkForMath(potentialGlobal) {
2035
+ // eslint-disable-next-line eqeqeq
2036
+ return potentialGlobal && potentialGlobal.Math == Math && potentialGlobal;
3009
2037
  }
3010
-
3011
- function hasOwnProperty(obj, prop) {
3012
- return Object.prototype.hasOwnProperty.call(obj, prop);
2038
+ // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
2039
+ function getGlobal() {
2040
+ // eslint-disable-next-line no-undef
2041
+ return (checkForMath(typeof globalThis === 'object' && globalThis) ||
2042
+ checkForMath(typeof window === 'object' && window) ||
2043
+ checkForMath(typeof self === 'object' && self) ||
2044
+ checkForMath(typeof global === 'object' && global) ||
2045
+ Function('return this')());
3013
2046
  }
3014
2047
 
3015
- var require$$1 = {
3016
- inherits: inherits$1,
3017
- _extend: _extend,
3018
- log: log,
3019
- isBuffer: isBuffer,
3020
- isPrimitive: isPrimitive,
3021
- isFunction: isFunction,
3022
- isError: isError,
3023
- isDate: isDate,
3024
- isObject: isObject,
3025
- isRegExp: isRegExp,
3026
- isUndefined: isUndefined,
3027
- isSymbol: isSymbol,
3028
- isString: isString,
3029
- isNumber: isNumber,
3030
- isNullOrUndefined: isNullOrUndefined,
3031
- isNull: isNull,
3032
- isBoolean: isBoolean,
3033
- isArray: isArray,
3034
- inspect: inspect,
3035
- deprecate: deprecate,
3036
- format: format,
3037
- debuglog: debuglog
3038
- };
3039
-
3040
- var utils = createCommonjsModule(function (module, exports) {
3041
- Object.defineProperty(exports, "__esModule", { value: true });
3042
- exports.deprecate = exports.isObjectLike = exports.isDate = exports.isBuffer = exports.haveBuffer = exports.isBigUInt64Array = exports.isBigInt64Array = exports.isUint8Array = exports.randomBytes = exports.normalizedFunctionString = void 0;
3043
-
3044
-
3045
2048
  /**
3046
2049
  * Normalizes our expected stringified form of a function across versions of node
3047
2050
  * @param fn - The function to stringify
@@ -3049,58 +2052,66 @@ exports.deprecate = exports.isObjectLike = exports.isDate = exports.isBuffer = e
3049
2052
  function normalizedFunctionString(fn) {
3050
2053
  return fn.toString().replace('function(', 'function (');
3051
2054
  }
3052
- exports.normalizedFunctionString = normalizedFunctionString;
3053
- function insecureRandomBytes(size) {
3054
- var result = buffer.Buffer.alloc(size);
2055
+ function isReactNative() {
2056
+ var g = getGlobal();
2057
+ return typeof g.navigator === 'object' && g.navigator.product === 'ReactNative';
2058
+ }
2059
+ var insecureRandomBytes = function insecureRandomBytes(size) {
2060
+ var insecureWarning = isReactNative()
2061
+ ? 'BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.'
2062
+ : 'BSON: No cryptographic implementation for random bytes present, falling back to a less secure implementation.';
2063
+ console.warn(insecureWarning);
2064
+ var result = buffer_1.alloc(size);
3055
2065
  for (var i = 0; i < size; ++i)
3056
2066
  result[i] = Math.floor(Math.random() * 256);
3057
2067
  return result;
3058
- }
3059
- exports.randomBytes = insecureRandomBytes;
3060
- if (typeof window !== 'undefined' && window.crypto && window.crypto.getRandomValues) {
3061
- exports.randomBytes = function (size) { return window.crypto.getRandomValues(buffer.Buffer.alloc(size)); };
3062
- }
3063
- else {
2068
+ };
2069
+ var detectRandomBytes = function () {
2070
+ if (typeof window !== 'undefined') {
2071
+ // browser crypto implementation(s)
2072
+ var target_1 = window.crypto || window.msCrypto; // allow for IE11
2073
+ if (target_1 && target_1.getRandomValues) {
2074
+ return function (size) { return target_1.getRandomValues(buffer_1.alloc(size)); };
2075
+ }
2076
+ }
2077
+ if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
2078
+ // allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
2079
+ return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
2080
+ }
2081
+ var requiredRandomBytes;
3064
2082
  try {
3065
2083
  // eslint-disable-next-line @typescript-eslint/no-var-requires
3066
- exports.randomBytes = require$$0.randomBytes;
2084
+ requiredRandomBytes = require('crypto').randomBytes;
3067
2085
  }
3068
2086
  catch (e) {
3069
2087
  // keep the fallback
3070
2088
  }
3071
2089
  // NOTE: in transpiled cases the above require might return null/undefined
3072
- if (exports.randomBytes == null) {
3073
- exports.randomBytes = insecureRandomBytes;
3074
- }
2090
+ return requiredRandomBytes || insecureRandomBytes;
2091
+ };
2092
+ var randomBytes = detectRandomBytes();
2093
+ function isAnyArrayBuffer(value) {
2094
+ return ['[object ArrayBuffer]', '[object SharedArrayBuffer]'].includes(Object.prototype.toString.call(value));
3075
2095
  }
3076
2096
  function isUint8Array(value) {
3077
2097
  return Object.prototype.toString.call(value) === '[object Uint8Array]';
3078
2098
  }
3079
- exports.isUint8Array = isUint8Array;
3080
2099
  function isBigInt64Array(value) {
3081
2100
  return Object.prototype.toString.call(value) === '[object BigInt64Array]';
3082
2101
  }
3083
- exports.isBigInt64Array = isBigInt64Array;
3084
2102
  function isBigUInt64Array(value) {
3085
2103
  return Object.prototype.toString.call(value) === '[object BigUint64Array]';
3086
2104
  }
3087
- exports.isBigUInt64Array = isBigUInt64Array;
3088
- /** Call to check if your environment has `Buffer` */
3089
- function haveBuffer() {
3090
- return typeof commonjsGlobal !== 'undefined' && typeof commonjsGlobal.Buffer !== 'undefined';
2105
+ function isRegExp(d) {
2106
+ return Object.prototype.toString.call(d) === '[object RegExp]';
3091
2107
  }
3092
- exports.haveBuffer = haveBuffer;
3093
- /** Callable in any environment to check if value is a Buffer */
3094
- function isBuffer(value) {
3095
- var _a;
3096
- return typeof value === 'object' && ((_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'Buffer';
2108
+ function isMap(d) {
2109
+ return Object.prototype.toString.call(d) === '[object Map]';
3097
2110
  }
3098
- exports.isBuffer = isBuffer;
3099
2111
  // To ensure that 0.4 of node works correctly
3100
2112
  function isDate(d) {
3101
2113
  return isObjectLike(d) && Object.prototype.toString.call(d) === '[object Date]';
3102
2114
  }
3103
- exports.isDate = isDate;
3104
2115
  /**
3105
2116
  * @internal
3106
2117
  * this is to solve the `'someKey' in x` problem where x is unknown.
@@ -3109,11 +2120,12 @@ exports.isDate = isDate;
3109
2120
  function isObjectLike(candidate) {
3110
2121
  return typeof candidate === 'object' && candidate !== null;
3111
2122
  }
3112
- exports.isObjectLike = isObjectLike;
3113
2123
  function deprecate(fn, message) {
3114
- if (typeof window === 'undefined' && typeof self === 'undefined') {
2124
+ if (typeof require === 'function' &&
2125
+ typeof window === 'undefined' &&
2126
+ typeof self === 'undefined') {
3115
2127
  // eslint-disable-next-line @typescript-eslint/no-var-requires
3116
- return require$$1.deprecate(fn, message);
2128
+ return require('util').deprecate(fn, message);
3117
2129
  }
3118
2130
  var warned = false;
3119
2131
  function deprecated() {
@@ -3125,30 +2137,10 @@ function deprecate(fn, message) {
3125
2137
  console.warn(message);
3126
2138
  warned = true;
3127
2139
  }
3128
- return fn.apply.apply(fn, tslib_es6.__spreadArrays([this], args));
2140
+ return fn.apply(this, args);
3129
2141
  }
3130
2142
  return deprecated;
3131
2143
  }
3132
- exports.deprecate = deprecate;
3133
-
3134
- });
3135
-
3136
- unwrapExports(utils);
3137
- var utils_1 = utils.deprecate;
3138
- var utils_2 = utils.isObjectLike;
3139
- var utils_3 = utils.isDate;
3140
- var utils_4 = utils.isBuffer;
3141
- var utils_5 = utils.haveBuffer;
3142
- var utils_6 = utils.isBigUInt64Array;
3143
- var utils_7 = utils.isBigInt64Array;
3144
- var utils_8 = utils.isUint8Array;
3145
- var utils_9 = utils.randomBytes;
3146
- var utils_10 = utils.normalizedFunctionString;
3147
-
3148
- var ensure_buffer = createCommonjsModule(function (module, exports) {
3149
- Object.defineProperty(exports, "__esModule", { value: true });
3150
- exports.ensureBuffer = void 0;
3151
-
3152
2144
 
3153
2145
  /**
3154
2146
  * Makes sure that, if a Uint8Array is passed in, it is wrapped in a Buffer.
@@ -3159,82 +2151,211 @@ exports.ensureBuffer = void 0;
3159
2151
  * @throws TypeError If anything other than a Buffer or Uint8Array is passed in
3160
2152
  */
3161
2153
  function ensureBuffer(potentialBuffer) {
3162
- if (utils.isBuffer(potentialBuffer)) {
3163
- return potentialBuffer;
3164
- }
3165
2154
  if (ArrayBuffer.isView(potentialBuffer)) {
3166
- return buffer.Buffer.from(potentialBuffer.buffer);
2155
+ return buffer_1.from(potentialBuffer.buffer, potentialBuffer.byteOffset, potentialBuffer.byteLength);
3167
2156
  }
3168
- if (potentialBuffer instanceof ArrayBuffer) {
3169
- return buffer.Buffer.from(potentialBuffer);
2157
+ if (isAnyArrayBuffer(potentialBuffer)) {
2158
+ return buffer_1.from(potentialBuffer);
3170
2159
  }
3171
2160
  throw new TypeError('Must use either Buffer or TypedArray');
3172
2161
  }
3173
- exports.ensureBuffer = ensureBuffer;
3174
-
3175
- });
3176
2162
 
3177
- unwrapExports(ensure_buffer);
3178
- var ensure_buffer_1 = ensure_buffer.ensureBuffer;
2163
+ // Validation regex for v4 uuid (validates with or without dashes)
2164
+ var VALIDATION_REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15})$/i;
2165
+ var uuidValidateString = function (str) {
2166
+ return typeof str === 'string' && VALIDATION_REGEX.test(str);
2167
+ };
2168
+ var uuidHexStringToBuffer = function (hexString) {
2169
+ if (!uuidValidateString(hexString)) {
2170
+ throw new TypeError('UUID string representations must be a 32 or 36 character hex string (dashes excluded/included). Format: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" or "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".');
2171
+ }
2172
+ var sanitizedHexString = hexString.replace(/-/g, '');
2173
+ return buffer_1.from(sanitizedHexString, 'hex');
2174
+ };
2175
+ var bufferToUuidHexString = function (buffer, includeDashes) {
2176
+ if (includeDashes === void 0) { includeDashes = true; }
2177
+ return includeDashes
2178
+ ? buffer.toString('hex', 0, 4) +
2179
+ '-' +
2180
+ buffer.toString('hex', 4, 6) +
2181
+ '-' +
2182
+ buffer.toString('hex', 6, 8) +
2183
+ '-' +
2184
+ buffer.toString('hex', 8, 10) +
2185
+ '-' +
2186
+ buffer.toString('hex', 10, 16)
2187
+ : buffer.toString('hex');
2188
+ };
3179
2189
 
3180
- var uuid = createCommonjsModule(function (module, exports) {
3181
- Object.defineProperty(exports, "__esModule", { value: true });
3182
- exports.parseUUID = void 0;
3183
- /**
3184
- * UUID regular expression pattern copied from `uuid` npm module.
3185
- * @see https://github.com/uuidjs/uuid/blob/master/src/regex.js
3186
- */
3187
- var UUID_RX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
2190
+ var BYTE_LENGTH = 16;
2191
+ var kId$1 = Symbol('id');
3188
2192
  /**
3189
- * Parser function copied from `uuid` npm module.
3190
- * @see https://github.com/uuidjs/uuid/blob/master/src/parse.js
3191
- * @internal
2193
+ * A class representation of the BSON UUID type.
2194
+ * @public
3192
2195
  */
3193
- function parseUUID(uuid) {
3194
- if (typeof uuid !== 'string') {
3195
- throw new TypeError('Invalid type for UUID, expected string but got ' + typeof uuid);
3196
- }
3197
- if (!UUID_RX.test(uuid)) {
3198
- throw new TypeError('Invalid format for UUID: ' + uuid);
3199
- }
3200
- var v;
3201
- var arr = new Uint8Array(16);
3202
- // Parse ########-....-....-....-............
3203
- arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
3204
- arr[1] = (v >>> 16) & 0xff;
3205
- arr[2] = (v >>> 8) & 0xff;
3206
- arr[3] = v & 0xff;
3207
- // Parse ........-####-....-....-............
3208
- arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
3209
- arr[5] = v & 0xff;
3210
- // Parse ........-....-####-....-............
3211
- arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
3212
- arr[7] = v & 0xff;
3213
- // Parse ........-....-....-####-............
3214
- arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
3215
- arr[9] = v & 0xff;
3216
- // Parse ........-....-....-....-############
3217
- // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
3218
- arr[10] = ((v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000) & 0xff;
3219
- arr[11] = (v / 0x100000000) & 0xff;
3220
- arr[12] = (v >>> 24) & 0xff;
3221
- arr[13] = (v >>> 16) & 0xff;
3222
- arr[14] = (v >>> 8) & 0xff;
3223
- arr[15] = v & 0xff;
3224
- return arr;
3225
- }
3226
- exports.parseUUID = parseUUID;
3227
-
3228
- });
3229
-
3230
- unwrapExports(uuid);
3231
- var uuid_1 = uuid.parseUUID;
3232
-
3233
- var binary = createCommonjsModule(function (module, exports) {
3234
- Object.defineProperty(exports, "__esModule", { value: true });
3235
- exports.Binary = void 0;
3236
-
3237
-
2196
+ var UUID = /** @class */ (function () {
2197
+ /**
2198
+ * Create an UUID type
2199
+ *
2200
+ * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
2201
+ */
2202
+ function UUID(input) {
2203
+ if (typeof input === 'undefined') {
2204
+ // The most common use case (blank id, new UUID() instance)
2205
+ this.id = UUID.generate();
2206
+ }
2207
+ else if (input instanceof UUID) {
2208
+ this[kId$1] = buffer_1.from(input.id);
2209
+ this.__id = input.__id;
2210
+ }
2211
+ else if (ArrayBuffer.isView(input) && input.byteLength === BYTE_LENGTH) {
2212
+ this.id = ensureBuffer(input);
2213
+ }
2214
+ else if (typeof input === 'string') {
2215
+ this.id = uuidHexStringToBuffer(input);
2216
+ }
2217
+ else {
2218
+ throw new TypeError('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).');
2219
+ }
2220
+ }
2221
+ Object.defineProperty(UUID.prototype, "id", {
2222
+ /**
2223
+ * The UUID bytes
2224
+ * @readonly
2225
+ */
2226
+ get: function () {
2227
+ return this[kId$1];
2228
+ },
2229
+ set: function (value) {
2230
+ this[kId$1] = value;
2231
+ if (UUID.cacheHexString) {
2232
+ this.__id = bufferToUuidHexString(value);
2233
+ }
2234
+ },
2235
+ enumerable: false,
2236
+ configurable: true
2237
+ });
2238
+ /**
2239
+ * Generate a 16 byte uuid v4 buffer used in UUIDs
2240
+ */
2241
+ /**
2242
+ * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
2243
+ * @param includeDashes - should the string exclude dash-separators.
2244
+ * */
2245
+ UUID.prototype.toHexString = function (includeDashes) {
2246
+ if (includeDashes === void 0) { includeDashes = true; }
2247
+ if (UUID.cacheHexString && this.__id) {
2248
+ return this.__id;
2249
+ }
2250
+ var uuidHexString = bufferToUuidHexString(this.id, includeDashes);
2251
+ if (UUID.cacheHexString) {
2252
+ this.__id = uuidHexString;
2253
+ }
2254
+ return uuidHexString;
2255
+ };
2256
+ /**
2257
+ * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
2258
+ * @internal
2259
+ */
2260
+ UUID.prototype.toString = function (encoding) {
2261
+ return encoding ? this.id.toString(encoding) : this.toHexString();
2262
+ };
2263
+ /**
2264
+ * Converts the id into its JSON string representation. A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
2265
+ * @internal
2266
+ */
2267
+ UUID.prototype.toJSON = function () {
2268
+ return this.toHexString();
2269
+ };
2270
+ /**
2271
+ * Compares the equality of this UUID with `otherID`.
2272
+ *
2273
+ * @param otherId - UUID instance to compare against.
2274
+ */
2275
+ UUID.prototype.equals = function (otherId) {
2276
+ if (!otherId) {
2277
+ return false;
2278
+ }
2279
+ if (otherId instanceof UUID) {
2280
+ return otherId.id.equals(this.id);
2281
+ }
2282
+ try {
2283
+ return new UUID(otherId).id.equals(this.id);
2284
+ }
2285
+ catch (_a) {
2286
+ return false;
2287
+ }
2288
+ };
2289
+ /**
2290
+ * Creates a Binary instance from the current UUID.
2291
+ */
2292
+ UUID.prototype.toBinary = function () {
2293
+ return new Binary(this.id, Binary.SUBTYPE_UUID);
2294
+ };
2295
+ /**
2296
+ * Generates a populated buffer containing a v4 uuid
2297
+ */
2298
+ UUID.generate = function () {
2299
+ var bytes = randomBytes(BYTE_LENGTH);
2300
+ // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
2301
+ // Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
2302
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
2303
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
2304
+ return buffer_1.from(bytes);
2305
+ };
2306
+ /**
2307
+ * Checks if a value is a valid bson UUID
2308
+ * @param input - UUID, string or Buffer to validate.
2309
+ */
2310
+ UUID.isValid = function (input) {
2311
+ if (!input) {
2312
+ return false;
2313
+ }
2314
+ if (input instanceof UUID) {
2315
+ return true;
2316
+ }
2317
+ if (typeof input === 'string') {
2318
+ return uuidValidateString(input);
2319
+ }
2320
+ if (isUint8Array(input)) {
2321
+ // check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
2322
+ if (input.length !== BYTE_LENGTH) {
2323
+ return false;
2324
+ }
2325
+ try {
2326
+ // get this byte as hex: xxxxxxxx-xxxx-XXxx-xxxx-xxxxxxxxxxxx
2327
+ // check first part as uuid version: xxxxxxxx-xxxx-Xxxx-xxxx-xxxxxxxxxxxx
2328
+ return parseInt(input[6].toString(16)[0], 10) === Binary.SUBTYPE_UUID;
2329
+ }
2330
+ catch (_a) {
2331
+ return false;
2332
+ }
2333
+ }
2334
+ return false;
2335
+ };
2336
+ /**
2337
+ * Creates an UUID from a hex string representation of an UUID.
2338
+ * @param hexString - 32 or 36 character hex string (dashes excluded/included).
2339
+ */
2340
+ UUID.createFromHexString = function (hexString) {
2341
+ var buffer = uuidHexStringToBuffer(hexString);
2342
+ return new UUID(buffer);
2343
+ };
2344
+ /**
2345
+ * Converts to a string representation of this Id.
2346
+ *
2347
+ * @returns return the 36 character hex string representation.
2348
+ * @internal
2349
+ */
2350
+ UUID.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
2351
+ return this.inspect();
2352
+ };
2353
+ UUID.prototype.inspect = function () {
2354
+ return "new UUID(\"" + this.toHexString() + "\")";
2355
+ };
2356
+ return UUID;
2357
+ }());
2358
+ Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
3238
2359
 
3239
2360
  /**
3240
2361
  * A class representation of the BSON Binary type.
@@ -3245,34 +2366,34 @@ var Binary = /** @class */ (function () {
3245
2366
  * @param buffer - a buffer object containing the binary data.
3246
2367
  * @param subType - the option binary type.
3247
2368
  */
3248
- function Binary(buffer$1, subType) {
2369
+ function Binary(buffer, subType) {
3249
2370
  if (!(this instanceof Binary))
3250
- return new Binary(buffer$1, subType);
3251
- if (!(buffer$1 == null) &&
3252
- !(typeof buffer$1 === 'string') &&
3253
- !ArrayBuffer.isView(buffer$1) &&
3254
- !(buffer$1 instanceof ArrayBuffer) &&
3255
- !Array.isArray(buffer$1)) {
2371
+ return new Binary(buffer, subType);
2372
+ if (!(buffer == null) &&
2373
+ !(typeof buffer === 'string') &&
2374
+ !ArrayBuffer.isView(buffer) &&
2375
+ !(buffer instanceof ArrayBuffer) &&
2376
+ !Array.isArray(buffer)) {
3256
2377
  throw new TypeError('Binary can only be constructed from string, Buffer, TypedArray, or Array<number>');
3257
2378
  }
3258
2379
  this.sub_type = subType !== null && subType !== void 0 ? subType : Binary.BSON_BINARY_SUBTYPE_DEFAULT;
3259
- if (buffer$1 == null) {
2380
+ if (buffer == null) {
3260
2381
  // create an empty binary buffer
3261
- this.buffer = buffer.Buffer.alloc(Binary.BUFFER_SIZE);
2382
+ this.buffer = buffer_1.alloc(Binary.BUFFER_SIZE);
3262
2383
  this.position = 0;
3263
2384
  }
3264
2385
  else {
3265
- if (typeof buffer$1 === 'string') {
2386
+ if (typeof buffer === 'string') {
3266
2387
  // string
3267
- this.buffer = buffer.Buffer.from(buffer$1, 'binary');
2388
+ this.buffer = buffer_1.from(buffer, 'binary');
3268
2389
  }
3269
- else if (Array.isArray(buffer$1)) {
2390
+ else if (Array.isArray(buffer)) {
3270
2391
  // number[]
3271
- this.buffer = buffer.Buffer.from(buffer$1);
2392
+ this.buffer = buffer_1.from(buffer);
3272
2393
  }
3273
2394
  else {
3274
2395
  // Buffer | TypedArray | ArrayBuffer
3275
- this.buffer = ensure_buffer.ensureBuffer(buffer$1);
2396
+ this.buffer = ensureBuffer(buffer);
3276
2397
  }
3277
2398
  this.position = this.buffer.byteLength;
3278
2399
  }
@@ -3307,10 +2428,10 @@ var Binary = /** @class */ (function () {
3307
2428
  this.buffer[this.position++] = decodedByte;
3308
2429
  }
3309
2430
  else {
3310
- var buffer$1 = buffer.Buffer.alloc(Binary.BUFFER_SIZE + this.buffer.length);
2431
+ var buffer = buffer_1.alloc(Binary.BUFFER_SIZE + this.buffer.length);
3311
2432
  // Combine the two buffers together
3312
- this.buffer.copy(buffer$1, 0, 0, this.buffer.length);
3313
- this.buffer = buffer$1;
2433
+ this.buffer.copy(buffer, 0, 0, this.buffer.length);
2434
+ this.buffer = buffer;
3314
2435
  this.buffer[this.position++] = decodedByte;
3315
2436
  }
3316
2437
  };
@@ -3324,13 +2445,13 @@ var Binary = /** @class */ (function () {
3324
2445
  offset = typeof offset === 'number' ? offset : this.position;
3325
2446
  // If the buffer is to small let's extend the buffer
3326
2447
  if (this.buffer.length < offset + sequence.length) {
3327
- var buffer$1 = buffer.Buffer.alloc(this.buffer.length + sequence.length);
3328
- this.buffer.copy(buffer$1, 0, 0, this.buffer.length);
2448
+ var buffer = buffer_1.alloc(this.buffer.length + sequence.length);
2449
+ this.buffer.copy(buffer, 0, 0, this.buffer.length);
3329
2450
  // Assign the new buffer
3330
- this.buffer = buffer$1;
2451
+ this.buffer = buffer;
3331
2452
  }
3332
2453
  if (ArrayBuffer.isView(sequence)) {
3333
- this.buffer.set(ensure_buffer.ensureBuffer(sequence), offset);
2454
+ this.buffer.set(ensureBuffer(sequence), offset);
3334
2455
  this.position =
3335
2456
  offset + sequence.byteLength > this.position ? offset + sequence.length : this.position;
3336
2457
  }
@@ -3400,6 +2521,13 @@ var Binary = /** @class */ (function () {
3400
2521
  };
3401
2522
  };
3402
2523
  /** @internal */
2524
+ Binary.prototype.toUUID = function () {
2525
+ if (this.sub_type === Binary.SUBTYPE_UUID) {
2526
+ return new UUID(this.buffer.slice(0, this.position));
2527
+ }
2528
+ throw new Error("Binary sub_type \"" + this.sub_type + "\" is not supported for converting to UUID. Only \"" + Binary.SUBTYPE_UUID + "\" is currently supported.");
2529
+ };
2530
+ /** @internal */
3403
2531
  Binary.fromExtendedJSON = function (doc, options) {
3404
2532
  options = options || {};
3405
2533
  var data;
@@ -3407,18 +2535,18 @@ var Binary = /** @class */ (function () {
3407
2535
  if ('$binary' in doc) {
3408
2536
  if (options.legacy && typeof doc.$binary === 'string' && '$type' in doc) {
3409
2537
  type = doc.$type ? parseInt(doc.$type, 16) : 0;
3410
- data = buffer.Buffer.from(doc.$binary, 'base64');
2538
+ data = buffer_1.from(doc.$binary, 'base64');
3411
2539
  }
3412
2540
  else {
3413
2541
  if (typeof doc.$binary !== 'string') {
3414
2542
  type = doc.$binary.subType ? parseInt(doc.$binary.subType, 16) : 0;
3415
- data = buffer.Buffer.from(doc.$binary.base64, 'base64');
2543
+ data = buffer_1.from(doc.$binary.base64, 'base64');
3416
2544
  }
3417
2545
  }
3418
2546
  }
3419
2547
  else if ('$uuid' in doc) {
3420
2548
  type = 4;
3421
- data = buffer.Buffer.from(uuid.parseUUID(doc.$uuid));
2549
+ data = uuidHexStringToBuffer(doc.$uuid);
3422
2550
  }
3423
2551
  if (!data) {
3424
2552
  throw new TypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc));
@@ -3456,17 +2584,8 @@ var Binary = /** @class */ (function () {
3456
2584
  Binary.SUBTYPE_USER_DEFINED = 128;
3457
2585
  return Binary;
3458
2586
  }());
3459
- exports.Binary = Binary;
3460
2587
  Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' });
3461
2588
 
3462
- });
3463
-
3464
- unwrapExports(binary);
3465
- var binary_1 = binary.Binary;
3466
-
3467
- var code$1 = createCommonjsModule(function (module, exports) {
3468
- Object.defineProperty(exports, "__esModule", { value: true });
3469
- exports.Code = void 0;
3470
2589
  /**
3471
2590
  * A class representation of the BSON Code type.
3472
2591
  * @public
@@ -3507,23 +2626,15 @@ var Code = /** @class */ (function () {
3507
2626
  };
3508
2627
  return Code;
3509
2628
  }());
3510
- exports.Code = Code;
3511
2629
  Object.defineProperty(Code.prototype, '_bsontype', { value: 'Code' });
3512
2630
 
3513
- });
3514
-
3515
- unwrapExports(code$1);
3516
- var code_1 = code$1.Code;
3517
-
3518
- var db_ref = createCommonjsModule(function (module, exports) {
3519
- Object.defineProperty(exports, "__esModule", { value: true });
3520
- exports.DBRef = exports.isDBRefLike = void 0;
3521
-
3522
2631
  /** @internal */
3523
2632
  function isDBRefLike(value) {
3524
- return utils.isObjectLike(value) && value['$id'] != null && value['$ref'] != null;
2633
+ return (isObjectLike(value) &&
2634
+ value.$id != null &&
2635
+ typeof value.$ref === 'string' &&
2636
+ (value.$db == null || typeof value.$db === 'string'));
3525
2637
  }
3526
- exports.isDBRefLike = isDBRefLike;
3527
2638
  /**
3528
2639
  * A class representation of the BSON DBRef type.
3529
2640
  * @public
@@ -3606,19 +2717,8 @@ var DBRef = /** @class */ (function () {
3606
2717
  };
3607
2718
  return DBRef;
3608
2719
  }());
3609
- exports.DBRef = DBRef;
3610
2720
  Object.defineProperty(DBRef.prototype, '_bsontype', { value: 'DBRef' });
3611
2721
 
3612
- });
3613
-
3614
- unwrapExports(db_ref);
3615
- var db_ref_1 = db_ref.DBRef;
3616
- var db_ref_2 = db_ref.isDBRefLike;
3617
-
3618
- var long_1 = createCommonjsModule(function (module, exports) {
3619
- Object.defineProperty(exports, "__esModule", { value: true });
3620
- exports.Long = void 0;
3621
-
3622
2722
  /**
3623
2723
  * wasm optimizations, to do native i64 multiplication and divide
3624
2724
  */
@@ -3662,18 +2762,31 @@ var Long = /** @class */ (function () {
3662
2762
  /**
3663
2763
  * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
3664
2764
  * See the from* functions below for more convenient ways of constructing Longs.
2765
+ *
2766
+ * Acceptable signatures are:
2767
+ * - Long(low, high, unsigned?)
2768
+ * - Long(bigint, unsigned?)
2769
+ * - Long(string, unsigned?)
2770
+ *
3665
2771
  * @param low - The low (signed) 32 bits of the long
3666
2772
  * @param high - The high (signed) 32 bits of the long
3667
2773
  * @param unsigned - Whether unsigned or not, defaults to signed
3668
2774
  */
3669
2775
  function Long(low, high, unsigned) {
3670
2776
  if (low === void 0) { low = 0; }
3671
- if (high === void 0) { high = 0; }
3672
2777
  if (!(this instanceof Long))
3673
2778
  return new Long(low, high, unsigned);
3674
- this.low = low | 0;
3675
- this.high = high | 0;
3676
- this.unsigned = !!unsigned;
2779
+ if (typeof low === 'bigint') {
2780
+ Object.assign(this, Long.fromBigInt(low, !!high));
2781
+ }
2782
+ else if (typeof low === 'string') {
2783
+ Object.assign(this, Long.fromString(low, !!high));
2784
+ }
2785
+ else {
2786
+ this.low = low | 0;
2787
+ this.high = high | 0;
2788
+ this.unsigned = !!unsigned;
2789
+ }
3677
2790
  Object.defineProperty(this, '__isLong__', {
3678
2791
  value: true,
3679
2792
  configurable: false,
@@ -3838,7 +2951,7 @@ var Long = /** @class */ (function () {
3838
2951
  */
3839
2952
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
3840
2953
  Long.isLong = function (value) {
3841
- return utils.isObjectLike(value) && value['__isLong__'] === true;
2954
+ return isObjectLike(value) && value['__isLong__'] === true;
3842
2955
  };
3843
2956
  /**
3844
2957
  * Converts the specified value to a Long.
@@ -4476,7 +3589,7 @@ var Long = /** @class */ (function () {
4476
3589
  return this.inspect();
4477
3590
  };
4478
3591
  Long.prototype.inspect = function () {
4479
- return "new Long(\"" + this.toString() + "\")";
3592
+ return "new Long(\"" + this.toString() + "\"" + (this.unsigned ? ', true' : '') + ")";
4480
3593
  };
4481
3594
  Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
4482
3595
  /** Maximum unsigned value. */
@@ -4497,20 +3610,9 @@ var Long = /** @class */ (function () {
4497
3610
  Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false);
4498
3611
  return Long;
4499
3612
  }());
4500
- exports.Long = Long;
4501
3613
  Object.defineProperty(Long.prototype, '__isLong__', { value: true });
4502
3614
  Object.defineProperty(Long.prototype, '_bsontype', { value: 'Long' });
4503
3615
 
4504
- });
4505
-
4506
- unwrapExports(long_1);
4507
- var long_2 = long_1.Long;
4508
-
4509
- var decimal128 = createCommonjsModule(function (module, exports) {
4510
- Object.defineProperty(exports, "__esModule", { value: true });
4511
- exports.Decimal128 = void 0;
4512
-
4513
-
4514
3616
  var PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
4515
3617
  var PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i;
4516
3618
  var PARSE_NAN_REGEXP = /^(\+|-)?NaN$/i;
@@ -4520,59 +3622,14 @@ var EXPONENT_BIAS = 6176;
4520
3622
  var MAX_DIGITS = 34;
4521
3623
  // Nan value bits as 32 bit values (due to lack of longs)
4522
3624
  var NAN_BUFFER = [
4523
- 0x7c,
4524
- 0x00,
4525
- 0x00,
4526
- 0x00,
4527
- 0x00,
4528
- 0x00,
4529
- 0x00,
4530
- 0x00,
4531
- 0x00,
4532
- 0x00,
4533
- 0x00,
4534
- 0x00,
4535
- 0x00,
4536
- 0x00,
4537
- 0x00,
4538
- 0x00
3625
+ 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4539
3626
  ].reverse();
4540
3627
  // Infinity value bits 32 bit values (due to lack of longs)
4541
3628
  var INF_NEGATIVE_BUFFER = [
4542
- 0xf8,
4543
- 0x00,
4544
- 0x00,
4545
- 0x00,
4546
- 0x00,
4547
- 0x00,
4548
- 0x00,
4549
- 0x00,
4550
- 0x00,
4551
- 0x00,
4552
- 0x00,
4553
- 0x00,
4554
- 0x00,
4555
- 0x00,
4556
- 0x00,
4557
- 0x00
3629
+ 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4558
3630
  ].reverse();
4559
3631
  var INF_POSITIVE_BUFFER = [
4560
- 0x78,
4561
- 0x00,
4562
- 0x00,
4563
- 0x00,
4564
- 0x00,
4565
- 0x00,
4566
- 0x00,
4567
- 0x00,
4568
- 0x00,
4569
- 0x00,
4570
- 0x00,
4571
- 0x00,
4572
- 0x00,
4573
- 0x00,
4574
- 0x00,
4575
- 0x00
3632
+ 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4576
3633
  ].reverse();
4577
3634
  var EXPONENT_REGEX = /^([-+])?(\d+)?$/;
4578
3635
  // Extract least significant 5 bits
@@ -4589,8 +3646,8 @@ function isDigit(value) {
4589
3646
  }
4590
3647
  // Divide two uint128 values
4591
3648
  function divideu128(value) {
4592
- var DIVISOR = long_1.Long.fromNumber(1000 * 1000 * 1000);
4593
- var _rem = long_1.Long.fromNumber(0);
3649
+ var DIVISOR = Long.fromNumber(1000 * 1000 * 1000);
3650
+ var _rem = Long.fromNumber(0);
4594
3651
  if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) {
4595
3652
  return { quotient: value, rem: _rem };
4596
3653
  }
@@ -4598,7 +3655,7 @@ function divideu128(value) {
4598
3655
  // Adjust remainder to match value of next dividend
4599
3656
  _rem = _rem.shiftLeft(32);
4600
3657
  // Add the divided to _rem
4601
- _rem = _rem.add(new long_1.Long(value.parts[i], 0));
3658
+ _rem = _rem.add(new Long(value.parts[i], 0));
4602
3659
  value.parts[i] = _rem.div(DIVISOR).low;
4603
3660
  _rem = _rem.modulo(DIVISOR);
4604
3661
  }
@@ -4607,22 +3664,22 @@ function divideu128(value) {
4607
3664
  // Multiply two Long values and return the 128 bit value
4608
3665
  function multiply64x2(left, right) {
4609
3666
  if (!left && !right) {
4610
- return { high: long_1.Long.fromNumber(0), low: long_1.Long.fromNumber(0) };
3667
+ return { high: Long.fromNumber(0), low: Long.fromNumber(0) };
4611
3668
  }
4612
3669
  var leftHigh = left.shiftRightUnsigned(32);
4613
- var leftLow = new long_1.Long(left.getLowBits(), 0);
3670
+ var leftLow = new Long(left.getLowBits(), 0);
4614
3671
  var rightHigh = right.shiftRightUnsigned(32);
4615
- var rightLow = new long_1.Long(right.getLowBits(), 0);
3672
+ var rightLow = new Long(right.getLowBits(), 0);
4616
3673
  var productHigh = leftHigh.multiply(rightHigh);
4617
3674
  var productMid = leftHigh.multiply(rightLow);
4618
3675
  var productMid2 = leftLow.multiply(rightHigh);
4619
3676
  var productLow = leftLow.multiply(rightLow);
4620
3677
  productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
4621
- productMid = new long_1.Long(productMid.getLowBits(), 0)
3678
+ productMid = new Long(productMid.getLowBits(), 0)
4622
3679
  .add(productMid2)
4623
3680
  .add(productLow.shiftRightUnsigned(32));
4624
3681
  productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
4625
- productLow = productMid.shiftLeft(32).add(new long_1.Long(productLow.getLowBits(), 0));
3682
+ productLow = productMid.shiftLeft(32).add(new Long(productLow.getLowBits(), 0));
4626
3683
  // Return the 128 bit result
4627
3684
  return { high: productHigh, low: productLow };
4628
3685
  }
@@ -4650,11 +3707,19 @@ function invalidErr(string, message) {
4650
3707
  * @public
4651
3708
  */
4652
3709
  var Decimal128 = /** @class */ (function () {
4653
- /** @param bytes - a buffer containing the raw Decimal128 bytes in little endian order */
3710
+ /**
3711
+ * @param bytes - a buffer containing the raw Decimal128 bytes in little endian order,
3712
+ * or a string representation as returned by .toString()
3713
+ */
4654
3714
  function Decimal128(bytes) {
4655
3715
  if (!(this instanceof Decimal128))
4656
3716
  return new Decimal128(bytes);
4657
- this.bytes = bytes;
3717
+ if (typeof bytes === 'string') {
3718
+ this.bytes = Decimal128.fromString(bytes).bytes;
3719
+ }
3720
+ else {
3721
+ this.bytes = bytes;
3722
+ }
4658
3723
  }
4659
3724
  /**
4660
3725
  * Create a Decimal128 instance from a string representation
@@ -4691,9 +3756,9 @@ var Decimal128 = /** @class */ (function () {
4691
3756
  // loop index over array
4692
3757
  var i = 0;
4693
3758
  // The high 17 digits of the significand
4694
- var significandHigh = new long_1.Long(0, 0);
3759
+ var significandHigh = new Long(0, 0);
4695
3760
  // The low 17 digits of the significand
4696
- var significandLow = new long_1.Long(0, 0);
3761
+ var significandLow = new Long(0, 0);
4697
3762
  // The biased exponent
4698
3763
  var biasedExponent = 0;
4699
3764
  // Read index
@@ -4738,10 +3803,10 @@ var Decimal128 = /** @class */ (function () {
4738
3803
  // Check if user passed Infinity or NaN
4739
3804
  if (!isDigit(representation[index]) && representation[index] !== '.') {
4740
3805
  if (representation[index] === 'i' || representation[index] === 'I') {
4741
- return new Decimal128(buffer.Buffer.from(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
3806
+ return new Decimal128(buffer_1.from(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
4742
3807
  }
4743
3808
  else if (representation[index] === 'N') {
4744
- return new Decimal128(buffer.Buffer.from(NAN_BUFFER));
3809
+ return new Decimal128(buffer_1.from(NAN_BUFFER));
4745
3810
  }
4746
3811
  }
4747
3812
  // Read all the digits
@@ -4779,7 +3844,7 @@ var Decimal128 = /** @class */ (function () {
4779
3844
  var match = representation.substr(++index).match(EXPONENT_REGEX);
4780
3845
  // No digits read
4781
3846
  if (!match || !match[2])
4782
- return new Decimal128(buffer.Buffer.from(NAN_BUFFER));
3847
+ return new Decimal128(buffer_1.from(NAN_BUFFER));
4783
3848
  // Get exponent
4784
3849
  exponent = parseInt(match[0], 10);
4785
3850
  // Adjust the index
@@ -4787,7 +3852,7 @@ var Decimal128 = /** @class */ (function () {
4787
3852
  }
4788
3853
  // Return not a number
4789
3854
  if (representation[index])
4790
- return new Decimal128(buffer.Buffer.from(NAN_BUFFER));
3855
+ return new Decimal128(buffer_1.from(NAN_BUFFER));
4791
3856
  // Done reading input
4792
3857
  // Find first non-zero digit in digits
4793
3858
  firstDigit = 0;
@@ -4903,7 +3968,7 @@ var Decimal128 = /** @class */ (function () {
4903
3968
  digits[dIdx] = 1;
4904
3969
  }
4905
3970
  else {
4906
- return new Decimal128(buffer.Buffer.from(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
3971
+ return new Decimal128(buffer_1.from(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
4907
3972
  }
4908
3973
  }
4909
3974
  }
@@ -4912,87 +3977,87 @@ var Decimal128 = /** @class */ (function () {
4912
3977
  }
4913
3978
  // Encode significand
4914
3979
  // The high 17 digits of the significand
4915
- significandHigh = long_1.Long.fromNumber(0);
3980
+ significandHigh = Long.fromNumber(0);
4916
3981
  // The low 17 digits of the significand
4917
- significandLow = long_1.Long.fromNumber(0);
3982
+ significandLow = Long.fromNumber(0);
4918
3983
  // read a zero
4919
3984
  if (significantDigits === 0) {
4920
- significandHigh = long_1.Long.fromNumber(0);
4921
- significandLow = long_1.Long.fromNumber(0);
3985
+ significandHigh = Long.fromNumber(0);
3986
+ significandLow = Long.fromNumber(0);
4922
3987
  }
4923
3988
  else if (lastDigit - firstDigit < 17) {
4924
3989
  var dIdx = firstDigit;
4925
- significandLow = long_1.Long.fromNumber(digits[dIdx++]);
4926
- significandHigh = new long_1.Long(0, 0);
3990
+ significandLow = Long.fromNumber(digits[dIdx++]);
3991
+ significandHigh = new Long(0, 0);
4927
3992
  for (; dIdx <= lastDigit; dIdx++) {
4928
- significandLow = significandLow.multiply(long_1.Long.fromNumber(10));
4929
- significandLow = significandLow.add(long_1.Long.fromNumber(digits[dIdx]));
3993
+ significandLow = significandLow.multiply(Long.fromNumber(10));
3994
+ significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
4930
3995
  }
4931
3996
  }
4932
3997
  else {
4933
3998
  var dIdx = firstDigit;
4934
- significandHigh = long_1.Long.fromNumber(digits[dIdx++]);
3999
+ significandHigh = Long.fromNumber(digits[dIdx++]);
4935
4000
  for (; dIdx <= lastDigit - 17; dIdx++) {
4936
- significandHigh = significandHigh.multiply(long_1.Long.fromNumber(10));
4937
- significandHigh = significandHigh.add(long_1.Long.fromNumber(digits[dIdx]));
4001
+ significandHigh = significandHigh.multiply(Long.fromNumber(10));
4002
+ significandHigh = significandHigh.add(Long.fromNumber(digits[dIdx]));
4938
4003
  }
4939
- significandLow = long_1.Long.fromNumber(digits[dIdx++]);
4004
+ significandLow = Long.fromNumber(digits[dIdx++]);
4940
4005
  for (; dIdx <= lastDigit; dIdx++) {
4941
- significandLow = significandLow.multiply(long_1.Long.fromNumber(10));
4942
- significandLow = significandLow.add(long_1.Long.fromNumber(digits[dIdx]));
4006
+ significandLow = significandLow.multiply(Long.fromNumber(10));
4007
+ significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
4943
4008
  }
4944
4009
  }
4945
- var significand = multiply64x2(significandHigh, long_1.Long.fromString('100000000000000000'));
4010
+ var significand = multiply64x2(significandHigh, Long.fromString('100000000000000000'));
4946
4011
  significand.low = significand.low.add(significandLow);
4947
4012
  if (lessThan(significand.low, significandLow)) {
4948
- significand.high = significand.high.add(long_1.Long.fromNumber(1));
4013
+ significand.high = significand.high.add(Long.fromNumber(1));
4949
4014
  }
4950
4015
  // Biased exponent
4951
4016
  biasedExponent = exponent + EXPONENT_BIAS;
4952
- var dec = { low: long_1.Long.fromNumber(0), high: long_1.Long.fromNumber(0) };
4017
+ var dec = { low: Long.fromNumber(0), high: Long.fromNumber(0) };
4953
4018
  // Encode combination, exponent, and significand.
4954
- if (significand.high.shiftRightUnsigned(49).and(long_1.Long.fromNumber(1)).equals(long_1.Long.fromNumber(1))) {
4019
+ if (significand.high.shiftRightUnsigned(49).and(Long.fromNumber(1)).equals(Long.fromNumber(1))) {
4955
4020
  // Encode '11' into bits 1 to 3
4956
- dec.high = dec.high.or(long_1.Long.fromNumber(0x3).shiftLeft(61));
4957
- dec.high = dec.high.or(long_1.Long.fromNumber(biasedExponent).and(long_1.Long.fromNumber(0x3fff).shiftLeft(47)));
4958
- dec.high = dec.high.or(significand.high.and(long_1.Long.fromNumber(0x7fffffffffff)));
4021
+ dec.high = dec.high.or(Long.fromNumber(0x3).shiftLeft(61));
4022
+ dec.high = dec.high.or(Long.fromNumber(biasedExponent).and(Long.fromNumber(0x3fff).shiftLeft(47)));
4023
+ dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x7fffffffffff)));
4959
4024
  }
4960
4025
  else {
4961
- dec.high = dec.high.or(long_1.Long.fromNumber(biasedExponent & 0x3fff).shiftLeft(49));
4962
- dec.high = dec.high.or(significand.high.and(long_1.Long.fromNumber(0x1ffffffffffff)));
4026
+ dec.high = dec.high.or(Long.fromNumber(biasedExponent & 0x3fff).shiftLeft(49));
4027
+ dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x1ffffffffffff)));
4963
4028
  }
4964
4029
  dec.low = significand.low;
4965
4030
  // Encode sign
4966
4031
  if (isNegative) {
4967
- dec.high = dec.high.or(long_1.Long.fromString('9223372036854775808'));
4032
+ dec.high = dec.high.or(Long.fromString('9223372036854775808'));
4968
4033
  }
4969
4034
  // Encode into a buffer
4970
- var buffer$1 = buffer.Buffer.alloc(16);
4035
+ var buffer = buffer_1.alloc(16);
4971
4036
  index = 0;
4972
4037
  // Encode the low 64 bits of the decimal
4973
4038
  // Encode low bits
4974
- buffer$1[index++] = dec.low.low & 0xff;
4975
- buffer$1[index++] = (dec.low.low >> 8) & 0xff;
4976
- buffer$1[index++] = (dec.low.low >> 16) & 0xff;
4977
- buffer$1[index++] = (dec.low.low >> 24) & 0xff;
4039
+ buffer[index++] = dec.low.low & 0xff;
4040
+ buffer[index++] = (dec.low.low >> 8) & 0xff;
4041
+ buffer[index++] = (dec.low.low >> 16) & 0xff;
4042
+ buffer[index++] = (dec.low.low >> 24) & 0xff;
4978
4043
  // Encode high bits
4979
- buffer$1[index++] = dec.low.high & 0xff;
4980
- buffer$1[index++] = (dec.low.high >> 8) & 0xff;
4981
- buffer$1[index++] = (dec.low.high >> 16) & 0xff;
4982
- buffer$1[index++] = (dec.low.high >> 24) & 0xff;
4044
+ buffer[index++] = dec.low.high & 0xff;
4045
+ buffer[index++] = (dec.low.high >> 8) & 0xff;
4046
+ buffer[index++] = (dec.low.high >> 16) & 0xff;
4047
+ buffer[index++] = (dec.low.high >> 24) & 0xff;
4983
4048
  // Encode the high 64 bits of the decimal
4984
4049
  // Encode low bits
4985
- buffer$1[index++] = dec.high.low & 0xff;
4986
- buffer$1[index++] = (dec.high.low >> 8) & 0xff;
4987
- buffer$1[index++] = (dec.high.low >> 16) & 0xff;
4988
- buffer$1[index++] = (dec.high.low >> 24) & 0xff;
4050
+ buffer[index++] = dec.high.low & 0xff;
4051
+ buffer[index++] = (dec.high.low >> 8) & 0xff;
4052
+ buffer[index++] = (dec.high.low >> 16) & 0xff;
4053
+ buffer[index++] = (dec.high.low >> 24) & 0xff;
4989
4054
  // Encode high bits
4990
- buffer$1[index++] = dec.high.high & 0xff;
4991
- buffer$1[index++] = (dec.high.high >> 8) & 0xff;
4992
- buffer$1[index++] = (dec.high.high >> 16) & 0xff;
4993
- buffer$1[index++] = (dec.high.high >> 24) & 0xff;
4055
+ buffer[index++] = dec.high.high & 0xff;
4056
+ buffer[index++] = (dec.high.high >> 8) & 0xff;
4057
+ buffer[index++] = (dec.high.high >> 16) & 0xff;
4058
+ buffer[index++] = (dec.high.high >> 24) & 0xff;
4994
4059
  // Return the new Decimal128
4995
- return new Decimal128(buffer$1);
4060
+ return new Decimal128(buffer);
4996
4061
  };
4997
4062
  /** Create a string representation of the raw Decimal128 value */
4998
4063
  Decimal128.prototype.toString = function () {
@@ -5036,10 +4101,10 @@ var Decimal128 = /** @class */ (function () {
5036
4101
  index = 0;
5037
4102
  // Create the state of the decimal
5038
4103
  var dec = {
5039
- low: new long_1.Long(low, midl),
5040
- high: new long_1.Long(midh, high)
4104
+ low: new Long(low, midl),
4105
+ high: new Long(midh, high)
5041
4106
  };
5042
- if (dec.high.lessThan(long_1.Long.ZERO)) {
4107
+ if (dec.high.lessThan(Long.ZERO)) {
5043
4108
  string.push('-');
5044
4109
  }
5045
4110
  // Decode combination field and exponent
@@ -5196,21 +4261,12 @@ var Decimal128 = /** @class */ (function () {
5196
4261
  return this.inspect();
5197
4262
  };
5198
4263
  Decimal128.prototype.inspect = function () {
5199
- return "Decimal128.fromString(\"" + this.toString() + "\")";
4264
+ return "new Decimal128(\"" + this.toString() + "\")";
5200
4265
  };
5201
4266
  return Decimal128;
5202
4267
  }());
5203
- exports.Decimal128 = Decimal128;
5204
4268
  Object.defineProperty(Decimal128.prototype, '_bsontype', { value: 'Decimal128' });
5205
4269
 
5206
- });
5207
-
5208
- unwrapExports(decimal128);
5209
- var decimal128_1 = decimal128.Decimal128;
5210
-
5211
- var double_1 = createCommonjsModule(function (module, exports) {
5212
- Object.defineProperty(exports, "__esModule", { value: true });
5213
- exports.Double = void 0;
5214
4270
  /**
5215
4271
  * A class representation of the BSON Double type.
5216
4272
  * @public
@@ -5278,17 +4334,8 @@ var Double = /** @class */ (function () {
5278
4334
  };
5279
4335
  return Double;
5280
4336
  }());
5281
- exports.Double = Double;
5282
4337
  Object.defineProperty(Double.prototype, '_bsontype', { value: 'Double' });
5283
4338
 
5284
- });
5285
-
5286
- unwrapExports(double_1);
5287
- var double_2 = double_1.Double;
5288
-
5289
- var int_32 = createCommonjsModule(function (module, exports) {
5290
- Object.defineProperty(exports, "__esModule", { value: true });
5291
- exports.Int32 = void 0;
5292
4339
  /**
5293
4340
  * A class representation of a BSON Int32 type.
5294
4341
  * @public
@@ -5338,17 +4385,8 @@ var Int32 = /** @class */ (function () {
5338
4385
  };
5339
4386
  return Int32;
5340
4387
  }());
5341
- exports.Int32 = Int32;
5342
4388
  Object.defineProperty(Int32.prototype, '_bsontype', { value: 'Int32' });
5343
4389
 
5344
- });
5345
-
5346
- unwrapExports(int_32);
5347
- var int_32_1 = int_32.Int32;
5348
-
5349
- var max_key = createCommonjsModule(function (module, exports) {
5350
- Object.defineProperty(exports, "__esModule", { value: true });
5351
- exports.MaxKey = void 0;
5352
4390
  /**
5353
4391
  * A class representation of the BSON MaxKey type.
5354
4392
  * @public
@@ -5375,17 +4413,8 @@ var MaxKey = /** @class */ (function () {
5375
4413
  };
5376
4414
  return MaxKey;
5377
4415
  }());
5378
- exports.MaxKey = MaxKey;
5379
4416
  Object.defineProperty(MaxKey.prototype, '_bsontype', { value: 'MaxKey' });
5380
4417
 
5381
- });
5382
-
5383
- unwrapExports(max_key);
5384
- var max_key_1 = max_key.MaxKey;
5385
-
5386
- var min_key = createCommonjsModule(function (module, exports) {
5387
- Object.defineProperty(exports, "__esModule", { value: true });
5388
- exports.MinKey = void 0;
5389
4418
  /**
5390
4419
  * A class representation of the BSON MinKey type.
5391
4420
  * @public
@@ -5412,36 +4441,12 @@ var MinKey = /** @class */ (function () {
5412
4441
  };
5413
4442
  return MinKey;
5414
4443
  }());
5415
- exports.MinKey = MinKey;
5416
4444
  Object.defineProperty(MinKey.prototype, '_bsontype', { value: 'MinKey' });
5417
4445
 
5418
- });
5419
-
5420
- unwrapExports(min_key);
5421
- var min_key_1 = min_key.MinKey;
5422
-
5423
- var objectid = createCommonjsModule(function (module, exports) {
5424
- Object.defineProperty(exports, "__esModule", { value: true });
5425
- exports.ObjectId = void 0;
5426
-
5427
-
5428
-
5429
- // constants
5430
- var PROCESS_UNIQUE = utils.randomBytes(5);
5431
4446
  // Regular expression that checks for hex value
5432
4447
  var checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');
5433
- // Precomputed hex table enables speedy hex string conversion
5434
- var hexTable = [];
5435
- for (var i_1 = 0; i_1 < 256; i_1++) {
5436
- hexTable[i_1] = (i_1 <= 15 ? '0' : '') + i_1.toString(16);
5437
- }
5438
- // Lookup tables
5439
- var decodeLookup = [];
5440
- var i = 0;
5441
- while (i < 10)
5442
- decodeLookup[0x30 + i] = i++;
5443
- while (i < 16)
5444
- decodeLookup[0x41 - 10 + i] = decodeLookup[0x61 - 10 + i] = i++;
4448
+ // Unique sequence for the current process (initialized on first use)
4449
+ var PROCESS_UNIQUE = null;
5445
4450
  var kId = Symbol('id');
5446
4451
  /**
5447
4452
  * A class representation of the BSON ObjectId type.
@@ -5463,10 +4468,10 @@ var ObjectId = /** @class */ (function () {
5463
4468
  }
5464
4469
  if (typeof id === 'object' && id && 'id' in id) {
5465
4470
  if ('toHexString' in id && typeof id.toHexString === 'function') {
5466
- this[kId] = buffer.Buffer.from(id.toHexString(), 'hex');
4471
+ this[kId] = buffer_1.from(id.toHexString(), 'hex');
5467
4472
  }
5468
4473
  else {
5469
- this[kId] = typeof id.id === 'string' ? buffer.Buffer.from(id.id) : id.id;
4474
+ this[kId] = typeof id.id === 'string' ? buffer_1.from(id.id) : id.id;
5470
4475
  }
5471
4476
  }
5472
4477
  // The most common use case (blank id, new objectId instance)
@@ -5479,17 +4484,17 @@ var ObjectId = /** @class */ (function () {
5479
4484
  }
5480
4485
  }
5481
4486
  if (ArrayBuffer.isView(id) && id.byteLength === 12) {
5482
- this[kId] = ensure_buffer.ensureBuffer(id);
4487
+ this[kId] = ensureBuffer(id);
5483
4488
  }
5484
4489
  if (typeof id === 'string') {
5485
4490
  if (id.length === 12) {
5486
- var bytes = buffer.Buffer.from(id);
4491
+ var bytes = buffer_1.from(id);
5487
4492
  if (bytes.byteLength === 12) {
5488
4493
  this[kId] = bytes;
5489
4494
  }
5490
4495
  }
5491
4496
  else if (id.length === 24 && checkForHexRegExp.test(id)) {
5492
- this[kId] = buffer.Buffer.from(id, 'hex');
4497
+ this[kId] = buffer_1.from(id, 'hex');
5493
4498
  }
5494
4499
  else {
5495
4500
  throw new TypeError('Argument passed in must be a Buffer or string of 12 bytes or a string of 24 hex characters');
@@ -5561,20 +4566,24 @@ var ObjectId = /** @class */ (function () {
5561
4566
  time = ~~(Date.now() / 1000);
5562
4567
  }
5563
4568
  var inc = ObjectId.getInc();
5564
- var buffer$1 = buffer.Buffer.alloc(12);
4569
+ var buffer = buffer_1.alloc(12);
5565
4570
  // 4-byte timestamp
5566
- buffer$1.writeUInt32BE(time, 0);
4571
+ buffer.writeUInt32BE(time, 0);
4572
+ // set PROCESS_UNIQUE if yet not initialized
4573
+ if (PROCESS_UNIQUE === null) {
4574
+ PROCESS_UNIQUE = randomBytes(5);
4575
+ }
5567
4576
  // 5-byte process unique
5568
- buffer$1[4] = PROCESS_UNIQUE[0];
5569
- buffer$1[5] = PROCESS_UNIQUE[1];
5570
- buffer$1[6] = PROCESS_UNIQUE[2];
5571
- buffer$1[7] = PROCESS_UNIQUE[3];
5572
- buffer$1[8] = PROCESS_UNIQUE[4];
4577
+ buffer[4] = PROCESS_UNIQUE[0];
4578
+ buffer[5] = PROCESS_UNIQUE[1];
4579
+ buffer[6] = PROCESS_UNIQUE[2];
4580
+ buffer[7] = PROCESS_UNIQUE[3];
4581
+ buffer[8] = PROCESS_UNIQUE[4];
5573
4582
  // 3-byte counter
5574
- buffer$1[11] = inc & 0xff;
5575
- buffer$1[10] = (inc >> 8) & 0xff;
5576
- buffer$1[9] = (inc >> 16) & 0xff;
5577
- return buffer$1;
4583
+ buffer[11] = inc & 0xff;
4584
+ buffer[10] = (inc >> 8) & 0xff;
4585
+ buffer[9] = (inc >> 16) & 0xff;
4586
+ return buffer;
5578
4587
  };
5579
4588
  /**
5580
4589
  * Converts the id into a 24 character hex string for printing
@@ -5610,14 +4619,14 @@ var ObjectId = /** @class */ (function () {
5610
4619
  if (typeof otherId === 'string' &&
5611
4620
  ObjectId.isValid(otherId) &&
5612
4621
  otherId.length === 12 &&
5613
- this.id instanceof buffer.Buffer) {
5614
- return otherId === this.id.toString('binary');
4622
+ isUint8Array(this.id)) {
4623
+ return otherId === buffer_1.prototype.toString.call(this.id, 'latin1');
5615
4624
  }
5616
4625
  if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 24) {
5617
4626
  return otherId.toLowerCase() === this.toHexString();
5618
4627
  }
5619
4628
  if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 12) {
5620
- return buffer.Buffer.from(otherId).equals(this.id);
4629
+ return buffer_1.from(otherId).equals(this.id);
5621
4630
  }
5622
4631
  if (typeof otherId === 'object' &&
5623
4632
  'toHexString' in otherId &&
@@ -5643,11 +4652,11 @@ var ObjectId = /** @class */ (function () {
5643
4652
  * @param time - an integer number representing a number of seconds.
5644
4653
  */
5645
4654
  ObjectId.createFromTime = function (time) {
5646
- var buffer$1 = buffer.Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
4655
+ var buffer = buffer_1.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
5647
4656
  // Encode time into first 4 bytes
5648
- buffer$1.writeUInt32BE(time, 0);
4657
+ buffer.writeUInt32BE(time, 0);
5649
4658
  // Return the new objectId
5650
- return new ObjectId(buffer$1);
4659
+ return new ObjectId(buffer);
5651
4660
  };
5652
4661
  /**
5653
4662
  * Creates an ObjectId from a hex string representation of an ObjectId.
@@ -5659,7 +4668,7 @@ var ObjectId = /** @class */ (function () {
5659
4668
  if (typeof hexString === 'undefined' || (hexString != null && hexString.length !== 24)) {
5660
4669
  throw new TypeError('Argument passed in must be a single String of 12 bytes or a string of 24 hex characters');
5661
4670
  }
5662
- return new ObjectId(buffer.Buffer.from(hexString, 'hex'));
4671
+ return new ObjectId(buffer_1.from(hexString, 'hex'));
5663
4672
  };
5664
4673
  /**
5665
4674
  * Checks if a value is a valid bson ObjectId
@@ -5678,7 +4687,7 @@ var ObjectId = /** @class */ (function () {
5678
4687
  if (id instanceof ObjectId) {
5679
4688
  return true;
5680
4689
  }
5681
- if (id instanceof buffer.Buffer && id.length === 12) {
4690
+ if (isUint8Array(id) && id.length === 12) {
5682
4691
  return true;
5683
4692
  }
5684
4693
  // Duck-Typing detection of ObjectId like objects
@@ -5716,30 +4725,21 @@ var ObjectId = /** @class */ (function () {
5716
4725
  ObjectId.index = ~~(Math.random() * 0xffffff);
5717
4726
  return ObjectId;
5718
4727
  }());
5719
- exports.ObjectId = ObjectId;
5720
4728
  // Deprecated methods
5721
4729
  Object.defineProperty(ObjectId.prototype, 'generate', {
5722
- value: utils.deprecate(function (time) { return ObjectId.generate(time); }, 'Please use the static `ObjectId.generate(time)` instead')
4730
+ value: deprecate(function (time) { return ObjectId.generate(time); }, 'Please use the static `ObjectId.generate(time)` instead')
5723
4731
  });
5724
4732
  Object.defineProperty(ObjectId.prototype, 'getInc', {
5725
- value: utils.deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead')
4733
+ value: deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead')
5726
4734
  });
5727
4735
  Object.defineProperty(ObjectId.prototype, 'get_inc', {
5728
- value: utils.deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead')
4736
+ value: deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead')
5729
4737
  });
5730
4738
  Object.defineProperty(ObjectId, 'get_inc', {
5731
- value: utils.deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead')
4739
+ value: deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead')
5732
4740
  });
5733
4741
  Object.defineProperty(ObjectId.prototype, '_bsontype', { value: 'ObjectID' });
5734
4742
 
5735
- });
5736
-
5737
- unwrapExports(objectid);
5738
- var objectid_1 = objectid.ObjectId;
5739
-
5740
- var regexp = createCommonjsModule(function (module, exports) {
5741
- Object.defineProperty(exports, "__esModule", { value: true });
5742
- exports.BSONRegExp = void 0;
5743
4743
  function alphabetize(str) {
5744
4744
  return str.split('').sort().join('');
5745
4745
  }
@@ -5756,9 +4756,7 @@ var BSONRegExp = /** @class */ (function () {
5756
4756
  if (!(this instanceof BSONRegExp))
5757
4757
  return new BSONRegExp(pattern, options);
5758
4758
  this.pattern = pattern;
5759
- this.options = options !== null && options !== void 0 ? options : '';
5760
- // Execute
5761
- alphabetize(this.options);
4759
+ this.options = alphabetize(options !== null && options !== void 0 ? options : '');
5762
4760
  // Validate options
5763
4761
  for (var i = 0; i < this.options.length; i++) {
5764
4762
  if (!(this.options[i] === 'i' ||
@@ -5802,17 +4800,8 @@ var BSONRegExp = /** @class */ (function () {
5802
4800
  };
5803
4801
  return BSONRegExp;
5804
4802
  }());
5805
- exports.BSONRegExp = BSONRegExp;
5806
4803
  Object.defineProperty(BSONRegExp.prototype, '_bsontype', { value: 'BSONRegExp' });
5807
4804
 
5808
- });
5809
-
5810
- unwrapExports(regexp);
5811
- var regexp_1 = regexp.BSONRegExp;
5812
-
5813
- var symbol = createCommonjsModule(function (module, exports) {
5814
- Object.defineProperty(exports, "__esModule", { value: true });
5815
- exports.BSONSymbol = void 0;
5816
4805
  /**
5817
4806
  * A class representation of the BSON Symbol type.
5818
4807
  * @public
@@ -5856,33 +4845,65 @@ var BSONSymbol = /** @class */ (function () {
5856
4845
  };
5857
4846
  return BSONSymbol;
5858
4847
  }());
5859
- exports.BSONSymbol = BSONSymbol;
5860
4848
  Object.defineProperty(BSONSymbol.prototype, '_bsontype', { value: 'Symbol' });
5861
4849
 
5862
- });
4850
+ /*! *****************************************************************************
4851
+ Copyright (c) Microsoft Corporation.
4852
+
4853
+ Permission to use, copy, modify, and/or distribute this software for any
4854
+ purpose with or without fee is hereby granted.
4855
+
4856
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
4857
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
4858
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
4859
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
4860
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
4861
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4862
+ PERFORMANCE OF THIS SOFTWARE.
4863
+ ***************************************************************************** */
4864
+
4865
+ /* global Reflect, Promise */
4866
+ var _extendStatics = function extendStatics(d, b) {
4867
+ _extendStatics = Object.setPrototypeOf || {
4868
+ __proto__: []
4869
+ } instanceof Array && function (d, b) {
4870
+ d.__proto__ = b;
4871
+ } || function (d, b) {
4872
+ for (var p in b) {
4873
+ if (b.hasOwnProperty(p)) d[p] = b[p];
4874
+ }
4875
+ };
4876
+
4877
+ return _extendStatics(d, b);
4878
+ };
5863
4879
 
5864
- unwrapExports(symbol);
5865
- var symbol_1 = symbol.BSONSymbol;
4880
+ function __extends(d, b) {
4881
+ _extendStatics(d, b);
5866
4882
 
5867
- var timestamp$1 = createCommonjsModule(function (module, exports) {
5868
- Object.defineProperty(exports, "__esModule", { value: true });
5869
- exports.Timestamp = exports.LongWithoutOverridesClass = void 0;
4883
+ function __() {
4884
+ this.constructor = d;
4885
+ }
5870
4886
 
4887
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
4888
+ }
5871
4889
 
5872
4890
  /** @public */
5873
- exports.LongWithoutOverridesClass = long_1.Long;
4891
+ var LongWithoutOverridesClass = Long;
5874
4892
  /** @public */
5875
4893
  var Timestamp = /** @class */ (function (_super) {
5876
- tslib_es6.__extends(Timestamp, _super);
4894
+ __extends(Timestamp, _super);
5877
4895
  function Timestamp(low, high) {
5878
4896
  var _this = this;
5879
4897
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5880
4898
  ///@ts-expect-error
5881
4899
  if (!(_this instanceof Timestamp))
5882
4900
  return new Timestamp(low, high);
5883
- if (long_1.Long.isLong(low)) {
4901
+ if (Long.isLong(low)) {
5884
4902
  _this = _super.call(this, low.low, low.high, true) || this;
5885
4903
  }
4904
+ else if (isObjectLike(low) && typeof low.t !== 'undefined' && typeof low.i !== 'undefined') {
4905
+ _this = _super.call(this, low.i, low.t, true) || this;
4906
+ }
5886
4907
  else {
5887
4908
  _this = _super.call(this, low, high, true) || this;
5888
4909
  }
@@ -5901,11 +4922,11 @@ var Timestamp = /** @class */ (function (_super) {
5901
4922
  };
5902
4923
  /** Returns a Timestamp represented by the given (32-bit) integer value. */
5903
4924
  Timestamp.fromInt = function (value) {
5904
- return new Timestamp(long_1.Long.fromInt(value, true));
4925
+ return new Timestamp(Long.fromInt(value, true));
5905
4926
  };
5906
4927
  /** Returns a Timestamp representing the given number value, provided that it is a finite number. Otherwise, zero is returned. */
5907
4928
  Timestamp.fromNumber = function (value) {
5908
- return new Timestamp(long_1.Long.fromNumber(value, true));
4929
+ return new Timestamp(Long.fromNumber(value, true));
5909
4930
  };
5910
4931
  /**
5911
4932
  * Returns a Timestamp for the given high and low bits. Each is assumed to use 32 bits.
@@ -5923,7 +4944,7 @@ var Timestamp = /** @class */ (function (_super) {
5923
4944
  * @param optRadix - the radix in which the text is written.
5924
4945
  */
5925
4946
  Timestamp.fromString = function (str, optRadix) {
5926
- return new Timestamp(long_1.Long.fromString(str, true, optRadix));
4947
+ return new Timestamp(Long.fromString(str, true, optRadix));
5927
4948
  };
5928
4949
  /** @internal */
5929
4950
  Timestamp.prototype.toExtendedJSON = function () {
@@ -5931,69 +4952,44 @@ var Timestamp = /** @class */ (function (_super) {
5931
4952
  };
5932
4953
  /** @internal */
5933
4954
  Timestamp.fromExtendedJSON = function (doc) {
5934
- return new Timestamp(doc.$timestamp.i, doc.$timestamp.t);
4955
+ return new Timestamp(doc.$timestamp);
5935
4956
  };
5936
4957
  /** @internal */
5937
4958
  Timestamp.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
5938
4959
  return this.inspect();
5939
4960
  };
5940
4961
  Timestamp.prototype.inspect = function () {
5941
- return "new Timestamp(" + this.getLowBits().toString() + ", " + this.getHighBits().toString() + ")";
4962
+ return "new Timestamp({ t: " + this.getHighBits() + ", i: " + this.getLowBits() + " })";
5942
4963
  };
5943
- Timestamp.MAX_VALUE = long_1.Long.MAX_UNSIGNED_VALUE;
4964
+ Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
5944
4965
  return Timestamp;
5945
- }(exports.LongWithoutOverridesClass));
5946
- exports.Timestamp = Timestamp;
5947
-
5948
- });
5949
-
5950
- unwrapExports(timestamp$1);
5951
- var timestamp_1 = timestamp$1.Timestamp;
5952
- var timestamp_2 = timestamp$1.LongWithoutOverridesClass;
5953
-
5954
- var extended_json = createCommonjsModule(function (module, exports) {
5955
- Object.defineProperty(exports, "__esModule", { value: true });
5956
- exports.EJSON = exports.isBSONType = void 0;
5957
-
5958
-
5959
-
5960
-
5961
-
5962
-
5963
-
5964
-
5965
-
5966
-
5967
-
5968
-
5969
-
4966
+ }(LongWithoutOverridesClass));
5970
4967
 
5971
4968
  function isBSONType(value) {
5972
- return (utils.isObjectLike(value) && Reflect.has(value, '_bsontype') && typeof value._bsontype === 'string');
4969
+ return (isObjectLike(value) && Reflect.has(value, '_bsontype') && typeof value._bsontype === 'string');
5973
4970
  }
5974
- exports.isBSONType = isBSONType;
5975
4971
  // INT32 boundaries
5976
- var BSON_INT32_MAX = 0x7fffffff;
5977
- var BSON_INT32_MIN = -0x80000000;
4972
+ var BSON_INT32_MAX$1 = 0x7fffffff;
4973
+ var BSON_INT32_MIN$1 = -0x80000000;
5978
4974
  // INT64 boundaries
5979
- var BSON_INT64_MAX = 0x7fffffffffffffff;
5980
- var BSON_INT64_MIN = -0x8000000000000000;
4975
+ var BSON_INT64_MAX$1 = 0x7fffffffffffffff;
4976
+ var BSON_INT64_MIN$1 = -0x8000000000000000;
5981
4977
  // all the types where we don't need to do any special processing and can just pass the EJSON
5982
4978
  //straight to type.fromExtendedJSON
5983
4979
  var keysToCodecs = {
5984
- $oid: objectid.ObjectId,
5985
- $binary: binary.Binary,
5986
- $uuid: binary.Binary,
5987
- $symbol: symbol.BSONSymbol,
5988
- $numberInt: int_32.Int32,
5989
- $numberDecimal: decimal128.Decimal128,
5990
- $numberDouble: double_1.Double,
5991
- $numberLong: long_1.Long,
5992
- $minKey: min_key.MinKey,
5993
- $maxKey: max_key.MaxKey,
5994
- $regex: regexp.BSONRegExp,
5995
- $regularExpression: regexp.BSONRegExp,
5996
- $timestamp: timestamp$1.Timestamp
4980
+ $oid: ObjectId,
4981
+ $binary: Binary,
4982
+ $uuid: Binary,
4983
+ $symbol: BSONSymbol,
4984
+ $numberInt: Int32,
4985
+ $numberDecimal: Decimal128,
4986
+ $numberDouble: Double,
4987
+ $numberLong: Long,
4988
+ $minKey: MinKey,
4989
+ $maxKey: MaxKey,
4990
+ $regex: BSONRegExp,
4991
+ $regularExpression: BSONRegExp,
4992
+ $timestamp: Timestamp
5997
4993
  };
5998
4994
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5999
4995
  function deserializeValue(value, options) {
@@ -6005,13 +5001,13 @@ function deserializeValue(value, options) {
6005
5001
  // if it's an integer, should interpret as smallest BSON integer
6006
5002
  // that can represent it exactly. (if out of range, interpret as double.)
6007
5003
  if (Math.floor(value) === value) {
6008
- if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX)
6009
- return new int_32.Int32(value);
6010
- if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX)
6011
- return long_1.Long.fromNumber(value);
5004
+ if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1)
5005
+ return new Int32(value);
5006
+ if (value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1)
5007
+ return Long.fromNumber(value);
6012
5008
  }
6013
5009
  // If the number is a non-integer or out of integer range, should interpret as BSON Double.
6014
- return new double_1.Double(value);
5010
+ return new Double(value);
6015
5011
  }
6016
5012
  // from here on out we're looking for bson types, so bail if its not an object
6017
5013
  if (value == null || typeof value !== 'object')
@@ -6037,7 +5033,7 @@ function deserializeValue(value, options) {
6037
5033
  else {
6038
5034
  if (typeof d === 'string')
6039
5035
  date.setTime(Date.parse(d));
6040
- else if (long_1.Long.isLong(d))
5036
+ else if (Long.isLong(d))
6041
5037
  date.setTime(d.toNumber());
6042
5038
  else if (typeof d === 'number' && options.relaxed)
6043
5039
  date.setTime(d);
@@ -6049,13 +5045,13 @@ function deserializeValue(value, options) {
6049
5045
  if (value.$scope) {
6050
5046
  copy.$scope = deserializeValue(value.$scope);
6051
5047
  }
6052
- return code$1.Code.fromExtendedJSON(value);
5048
+ return Code.fromExtendedJSON(value);
6053
5049
  }
6054
- if (value.$ref != null || value.$dbPointer != null) {
5050
+ if (isDBRefLike(value) || value.$dbPointer) {
6055
5051
  var v = value.$ref ? value : value.$dbPointer;
6056
5052
  // we run into this in a "degenerate EJSON" case (with $id and $ref order flipped)
6057
5053
  // because of the order JSON.parse goes through the document
6058
- if (v instanceof db_ref.DBRef)
5054
+ if (v instanceof DBRef)
6059
5055
  return v;
6060
5056
  var dollarKeys = Object.keys(v).filter(function (k) { return k.startsWith('$'); });
6061
5057
  var valid_1 = true;
@@ -6065,13 +5061,21 @@ function deserializeValue(value, options) {
6065
5061
  });
6066
5062
  // only make DBRef if $ keys are all valid
6067
5063
  if (valid_1)
6068
- return db_ref.DBRef.fromExtendedJSON(v);
5064
+ return DBRef.fromExtendedJSON(v);
6069
5065
  }
6070
5066
  return value;
6071
5067
  }
6072
5068
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6073
5069
  function serializeArray(array, options) {
6074
- return array.map(function (v) { return serializeValue(v, options); });
5070
+ return array.map(function (v, index) {
5071
+ options.seenObjects.push({ propertyName: "index " + index, obj: null });
5072
+ try {
5073
+ return serializeValue(v, options);
5074
+ }
5075
+ finally {
5076
+ options.seenObjects.pop();
5077
+ }
5078
+ });
6075
5079
  }
6076
5080
  function getISOString(date) {
6077
5081
  var isoStr = date.toISOString();
@@ -6080,11 +5084,34 @@ function getISOString(date) {
6080
5084
  }
6081
5085
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6082
5086
  function serializeValue(value, options) {
5087
+ if ((typeof value === 'object' || typeof value === 'function') && value !== null) {
5088
+ var index = options.seenObjects.findIndex(function (entry) { return entry.obj === value; });
5089
+ if (index !== -1) {
5090
+ var props = options.seenObjects.map(function (entry) { return entry.propertyName; });
5091
+ var leadingPart = props
5092
+ .slice(0, index)
5093
+ .map(function (prop) { return prop + " -> "; })
5094
+ .join('');
5095
+ var alreadySeen = props[index];
5096
+ var circularPart = ' -> ' +
5097
+ props
5098
+ .slice(index + 1, props.length - 1)
5099
+ .map(function (prop) { return prop + " -> "; })
5100
+ .join('');
5101
+ var current = props[props.length - 1];
5102
+ var leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
5103
+ var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
5104
+ throw new TypeError('Converting circular structure to EJSON:\n' +
5105
+ (" " + leadingPart + alreadySeen + circularPart + current + "\n") +
5106
+ (" " + leadingSpace + "\\" + dashes + "/"));
5107
+ }
5108
+ options.seenObjects[options.seenObjects.length - 1].obj = value;
5109
+ }
6083
5110
  if (Array.isArray(value))
6084
5111
  return serializeArray(value, options);
6085
5112
  if (value === undefined)
6086
5113
  return null;
6087
- if (value instanceof Date) {
5114
+ if (value instanceof Date || isDate(value)) {
6088
5115
  var dateNum = value.getTime(),
6089
5116
  // is it in year range 1970-9999?
6090
5117
  inRange = dateNum > -1 && dateNum < 253402318800000;
@@ -6097,10 +5124,10 @@ function serializeValue(value, options) {
6097
5124
  ? { $date: getISOString(value) }
6098
5125
  : { $date: { $numberLong: value.getTime().toString() } };
6099
5126
  }
6100
- if (typeof value === 'number' && !options.relaxed) {
5127
+ if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) {
6101
5128
  // it's an integer
6102
5129
  if (Math.floor(value) === value) {
6103
- var int32Range = value >= BSON_INT32_MIN && value <= BSON_INT32_MAX, int64Range = value >= BSON_INT64_MIN && value <= BSON_INT64_MAX;
5130
+ var int32Range = value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1, int64Range = value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1;
6104
5131
  // interpret as being of the smallest BSON integer type that can represent the number exactly
6105
5132
  if (int32Range)
6106
5133
  return { $numberInt: value.toString() };
@@ -6109,7 +5136,7 @@ function serializeValue(value, options) {
6109
5136
  }
6110
5137
  return { $numberDouble: value.toString() };
6111
5138
  }
6112
- if (value instanceof RegExp) {
5139
+ if (value instanceof RegExp || isRegExp(value)) {
6113
5140
  var flags = value.flags;
6114
5141
  if (flags === undefined) {
6115
5142
  var match = value.toString().match(/[gimuy]*$/);
@@ -6117,7 +5144,7 @@ function serializeValue(value, options) {
6117
5144
  flags = match[0];
6118
5145
  }
6119
5146
  }
6120
- var rx = new regexp.BSONRegExp(value.source, flags);
5147
+ var rx = new BSONRegExp(value.source, flags);
6121
5148
  return rx.toExtendedJSON(options);
6122
5149
  }
6123
5150
  if (value != null && typeof value === 'object')
@@ -6125,24 +5152,24 @@ function serializeValue(value, options) {
6125
5152
  return value;
6126
5153
  }
6127
5154
  var BSON_TYPE_MAPPINGS = {
6128
- Binary: function (o) { return new binary.Binary(o.value(), o.sub_type); },
6129
- Code: function (o) { return new code$1.Code(o.code, o.scope); },
6130
- DBRef: function (o) { return new db_ref.DBRef(o.collection || o.namespace, o.oid, o.db, o.fields); },
6131
- Decimal128: function (o) { return new decimal128.Decimal128(o.bytes); },
6132
- Double: function (o) { return new double_1.Double(o.value); },
6133
- Int32: function (o) { return new int_32.Int32(o.value); },
5155
+ Binary: function (o) { return new Binary(o.value(), o.sub_type); },
5156
+ Code: function (o) { return new Code(o.code, o.scope); },
5157
+ DBRef: function (o) { return new DBRef(o.collection || o.namespace, o.oid, o.db, o.fields); },
5158
+ Decimal128: function (o) { return new Decimal128(o.bytes); },
5159
+ Double: function (o) { return new Double(o.value); },
5160
+ Int32: function (o) { return new Int32(o.value); },
6134
5161
  Long: function (o) {
6135
- return long_1.Long.fromBits(
5162
+ return Long.fromBits(
6136
5163
  // underscore variants for 1.x backwards compatibility
6137
5164
  o.low != null ? o.low : o.low_, o.low != null ? o.high : o.high_, o.low != null ? o.unsigned : o.unsigned_);
6138
5165
  },
6139
- MaxKey: function () { return new max_key.MaxKey(); },
6140
- MinKey: function () { return new min_key.MinKey(); },
6141
- ObjectID: function (o) { return new objectid.ObjectId(o); },
6142
- ObjectId: function (o) { return new objectid.ObjectId(o); },
6143
- BSONRegExp: function (o) { return new regexp.BSONRegExp(o.pattern, o.options); },
6144
- Symbol: function (o) { return new symbol.BSONSymbol(o.value); },
6145
- Timestamp: function (o) { return timestamp$1.Timestamp.fromBits(o.low, o.high); }
5166
+ MaxKey: function () { return new MaxKey(); },
5167
+ MinKey: function () { return new MinKey(); },
5168
+ ObjectID: function (o) { return new ObjectId(o); },
5169
+ ObjectId: function (o) { return new ObjectId(o); },
5170
+ BSONRegExp: function (o) { return new BSONRegExp(o.pattern, o.options); },
5171
+ Symbol: function (o) { return new BSONSymbol(o.value); },
5172
+ Timestamp: function (o) { return Timestamp.fromBits(o.low, o.high); }
6146
5173
  };
6147
5174
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6148
5175
  function serializeDocument(doc, options) {
@@ -6153,7 +5180,13 @@ function serializeDocument(doc, options) {
6153
5180
  // It's a regular object. Recursively serialize its property values.
6154
5181
  var _doc = {};
6155
5182
  for (var name in doc) {
6156
- _doc[name] = serializeValue(doc[name], options);
5183
+ options.seenObjects.push({ propertyName: name, obj: null });
5184
+ try {
5185
+ _doc[name] = serializeValue(doc[name], options);
5186
+ }
5187
+ finally {
5188
+ options.seenObjects.pop();
5189
+ }
6157
5190
  }
6158
5191
  return _doc;
6159
5192
  }
@@ -6174,10 +5207,10 @@ function serializeDocument(doc, options) {
6174
5207
  }
6175
5208
  // Two BSON types may have nested objects that may need to be serialized too
6176
5209
  if (bsontype === 'Code' && outDoc.scope) {
6177
- outDoc = new code$1.Code(outDoc.code, serializeValue(outDoc.scope, options));
5210
+ outDoc = new Code(outDoc.code, serializeValue(outDoc.scope, options));
6178
5211
  }
6179
5212
  else if (bsontype === 'DBRef' && outDoc.oid) {
6180
- outDoc = new db_ref.DBRef(outDoc.collection, serializeValue(outDoc.oid, options), outDoc.db, outDoc.fields);
5213
+ outDoc = new DBRef(serializeValue(outDoc.collection, options), serializeValue(outDoc.oid, options), serializeValue(outDoc.db, options), serializeValue(outDoc.fields, options));
6181
5214
  }
6182
5215
  return outDoc.toExtendedJSON(options);
6183
5216
  }
@@ -6255,8 +5288,10 @@ var EJSON;
6255
5288
  replacer = undefined;
6256
5289
  space = 0;
6257
5290
  }
6258
- options = Object.assign({}, { relaxed: true, legacy: false }, options);
6259
- var doc = serializeValue(value, options);
5291
+ var serializeOptions = Object.assign({ relaxed: true, legacy: false }, options, {
5292
+ seenObjects: [{ propertyName: '(root)', obj: null }]
5293
+ });
5294
+ var doc = serializeValue(value, serializeOptions);
6260
5295
  return JSON.stringify(doc, replacer, space);
6261
5296
  }
6262
5297
  EJSON.stringify = stringify;
@@ -6282,42 +5317,18 @@ var EJSON;
6282
5317
  return parse(JSON.stringify(ejson), options);
6283
5318
  }
6284
5319
  EJSON.deserialize = deserialize;
6285
- })(EJSON = exports.EJSON || (exports.EJSON = {}));
6286
-
6287
- });
6288
-
6289
- unwrapExports(extended_json);
6290
- var extended_json_1 = extended_json.EJSON;
6291
- var extended_json_2 = extended_json.isBSONType;
5320
+ })(EJSON || (EJSON = {}));
6292
5321
 
6293
- var map = createCommonjsModule(function (module, exports) {
6294
5322
  /* eslint-disable @typescript-eslint/no-explicit-any */
6295
- // We have an ES6 Map available, return the native instance
6296
- Object.defineProperty(exports, "__esModule", { value: true });
6297
- exports.Map = void 0;
6298
5323
  /** @public */
6299
5324
  var bsonMap;
6300
- exports.Map = bsonMap;
6301
- var check = function (potentialGlobal) {
6302
- // eslint-disable-next-line eqeqeq
6303
- return potentialGlobal && potentialGlobal.Math == Math && potentialGlobal;
6304
- };
6305
- // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
6306
- function getGlobal() {
6307
- // eslint-disable-next-line no-undef
6308
- return (check(typeof globalThis === 'object' && globalThis) ||
6309
- check(typeof window === 'object' && window) ||
6310
- check(typeof self === 'object' && self) ||
6311
- check(typeof commonjsGlobal === 'object' && commonjsGlobal) ||
6312
- Function('return this')());
6313
- }
6314
5325
  var bsonGlobal = getGlobal();
6315
- if (Object.prototype.hasOwnProperty.call(bsonGlobal, 'Map')) {
6316
- exports.Map = bsonMap = bsonGlobal.Map;
5326
+ if (bsonGlobal.Map) {
5327
+ bsonMap = bsonGlobal.Map;
6317
5328
  }
6318
5329
  else {
6319
5330
  // We will return a polyfill
6320
- exports.Map = bsonMap = /** @class */ (function () {
5331
+ bsonMap = /** @class */ (function () {
6321
5332
  function Map(array) {
6322
5333
  if (array === void 0) { array = []; }
6323
5334
  this._keys = [];
@@ -6425,135 +5436,82 @@ else {
6425
5436
  }());
6426
5437
  }
6427
5438
 
6428
- });
6429
-
6430
- unwrapExports(map);
6431
- var map_1 = map.Map;
6432
-
6433
- var constants = createCommonjsModule(function (module, exports) {
6434
- Object.defineProperty(exports, "__esModule", { value: true });
6435
- exports.BSON_BINARY_SUBTYPE_USER_DEFINED = exports.BSON_BINARY_SUBTYPE_MD5 = exports.BSON_BINARY_SUBTYPE_UUID_NEW = exports.BSON_BINARY_SUBTYPE_UUID = exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = exports.BSON_BINARY_SUBTYPE_FUNCTION = exports.BSON_BINARY_SUBTYPE_DEFAULT = exports.BSON_DATA_MAX_KEY = exports.BSON_DATA_MIN_KEY = exports.BSON_DATA_DECIMAL128 = exports.BSON_DATA_LONG = exports.BSON_DATA_TIMESTAMP = exports.BSON_DATA_INT = exports.BSON_DATA_CODE_W_SCOPE = exports.BSON_DATA_SYMBOL = exports.BSON_DATA_CODE = exports.BSON_DATA_DBPOINTER = exports.BSON_DATA_REGEXP = exports.BSON_DATA_NULL = exports.BSON_DATA_DATE = exports.BSON_DATA_BOOLEAN = exports.BSON_DATA_OID = exports.BSON_DATA_UNDEFINED = exports.BSON_DATA_BINARY = exports.BSON_DATA_ARRAY = exports.BSON_DATA_OBJECT = exports.BSON_DATA_STRING = exports.BSON_DATA_NUMBER = exports.JS_INT_MIN = exports.JS_INT_MAX = exports.BSON_INT64_MIN = exports.BSON_INT64_MAX = exports.BSON_INT32_MIN = exports.BSON_INT32_MAX = void 0;
6436
5439
  /** @internal */
6437
- exports.BSON_INT32_MAX = 0x7fffffff;
5440
+ var BSON_INT32_MAX = 0x7fffffff;
6438
5441
  /** @internal */
6439
- exports.BSON_INT32_MIN = -0x80000000;
5442
+ var BSON_INT32_MIN = -0x80000000;
6440
5443
  /** @internal */
6441
- exports.BSON_INT64_MAX = Math.pow(2, 63) - 1;
5444
+ var BSON_INT64_MAX = Math.pow(2, 63) - 1;
6442
5445
  /** @internal */
6443
- exports.BSON_INT64_MIN = -Math.pow(2, 63);
5446
+ var BSON_INT64_MIN = -Math.pow(2, 63);
6444
5447
  /**
6445
5448
  * Any integer up to 2^53 can be precisely represented by a double.
6446
5449
  * @internal
6447
5450
  */
6448
- exports.JS_INT_MAX = Math.pow(2, 53);
5451
+ var JS_INT_MAX = Math.pow(2, 53);
6449
5452
  /**
6450
5453
  * Any integer down to -2^53 can be precisely represented by a double.
6451
5454
  * @internal
6452
5455
  */
6453
- exports.JS_INT_MIN = -Math.pow(2, 53);
5456
+ var JS_INT_MIN = -Math.pow(2, 53);
6454
5457
  /** Number BSON Type @internal */
6455
- exports.BSON_DATA_NUMBER = 1;
5458
+ var BSON_DATA_NUMBER = 1;
6456
5459
  /** String BSON Type @internal */
6457
- exports.BSON_DATA_STRING = 2;
5460
+ var BSON_DATA_STRING = 2;
6458
5461
  /** Object BSON Type @internal */
6459
- exports.BSON_DATA_OBJECT = 3;
5462
+ var BSON_DATA_OBJECT = 3;
6460
5463
  /** Array BSON Type @internal */
6461
- exports.BSON_DATA_ARRAY = 4;
5464
+ var BSON_DATA_ARRAY = 4;
6462
5465
  /** Binary BSON Type @internal */
6463
- exports.BSON_DATA_BINARY = 5;
5466
+ var BSON_DATA_BINARY = 5;
6464
5467
  /** Binary BSON Type @internal */
6465
- exports.BSON_DATA_UNDEFINED = 6;
5468
+ var BSON_DATA_UNDEFINED = 6;
6466
5469
  /** ObjectId BSON Type @internal */
6467
- exports.BSON_DATA_OID = 7;
5470
+ var BSON_DATA_OID = 7;
6468
5471
  /** Boolean BSON Type @internal */
6469
- exports.BSON_DATA_BOOLEAN = 8;
5472
+ var BSON_DATA_BOOLEAN = 8;
6470
5473
  /** Date BSON Type @internal */
6471
- exports.BSON_DATA_DATE = 9;
5474
+ var BSON_DATA_DATE = 9;
6472
5475
  /** null BSON Type @internal */
6473
- exports.BSON_DATA_NULL = 10;
5476
+ var BSON_DATA_NULL = 10;
6474
5477
  /** RegExp BSON Type @internal */
6475
- exports.BSON_DATA_REGEXP = 11;
5478
+ var BSON_DATA_REGEXP = 11;
6476
5479
  /** Code BSON Type @internal */
6477
- exports.BSON_DATA_DBPOINTER = 12;
5480
+ var BSON_DATA_DBPOINTER = 12;
6478
5481
  /** Code BSON Type @internal */
6479
- exports.BSON_DATA_CODE = 13;
5482
+ var BSON_DATA_CODE = 13;
6480
5483
  /** Symbol BSON Type @internal */
6481
- exports.BSON_DATA_SYMBOL = 14;
5484
+ var BSON_DATA_SYMBOL = 14;
6482
5485
  /** Code with Scope BSON Type @internal */
6483
- exports.BSON_DATA_CODE_W_SCOPE = 15;
5486
+ var BSON_DATA_CODE_W_SCOPE = 15;
6484
5487
  /** 32 bit Integer BSON Type @internal */
6485
- exports.BSON_DATA_INT = 16;
5488
+ var BSON_DATA_INT = 16;
6486
5489
  /** Timestamp BSON Type @internal */
6487
- exports.BSON_DATA_TIMESTAMP = 17;
5490
+ var BSON_DATA_TIMESTAMP = 17;
6488
5491
  /** Long BSON Type @internal */
6489
- exports.BSON_DATA_LONG = 18;
5492
+ var BSON_DATA_LONG = 18;
6490
5493
  /** Decimal128 BSON Type @internal */
6491
- exports.BSON_DATA_DECIMAL128 = 19;
5494
+ var BSON_DATA_DECIMAL128 = 19;
6492
5495
  /** MinKey BSON Type @internal */
6493
- exports.BSON_DATA_MIN_KEY = 0xff;
5496
+ var BSON_DATA_MIN_KEY = 0xff;
6494
5497
  /** MaxKey BSON Type @internal */
6495
- exports.BSON_DATA_MAX_KEY = 0x7f;
5498
+ var BSON_DATA_MAX_KEY = 0x7f;
6496
5499
  /** Binary Default Type @internal */
6497
- exports.BSON_BINARY_SUBTYPE_DEFAULT = 0;
5500
+ var BSON_BINARY_SUBTYPE_DEFAULT = 0;
6498
5501
  /** Binary Function Type @internal */
6499
- exports.BSON_BINARY_SUBTYPE_FUNCTION = 1;
5502
+ var BSON_BINARY_SUBTYPE_FUNCTION = 1;
6500
5503
  /** Binary Byte Array Type @internal */
6501
- exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
5504
+ var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
6502
5505
  /** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
6503
- exports.BSON_BINARY_SUBTYPE_UUID = 3;
5506
+ var BSON_BINARY_SUBTYPE_UUID = 3;
6504
5507
  /** Binary UUID Type @internal */
6505
- exports.BSON_BINARY_SUBTYPE_UUID_NEW = 4;
5508
+ var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
6506
5509
  /** Binary MD5 Type @internal */
6507
- exports.BSON_BINARY_SUBTYPE_MD5 = 5;
5510
+ var BSON_BINARY_SUBTYPE_MD5 = 5;
6508
5511
  /** Binary User Defined Type @internal */
6509
- exports.BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
6510
-
6511
- });
5512
+ var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
6512
5513
 
6513
- unwrapExports(constants);
6514
- var constants_1 = constants.BSON_BINARY_SUBTYPE_USER_DEFINED;
6515
- var constants_2 = constants.BSON_BINARY_SUBTYPE_MD5;
6516
- var constants_3 = constants.BSON_BINARY_SUBTYPE_UUID_NEW;
6517
- var constants_4 = constants.BSON_BINARY_SUBTYPE_UUID;
6518
- var constants_5 = constants.BSON_BINARY_SUBTYPE_BYTE_ARRAY;
6519
- var constants_6 = constants.BSON_BINARY_SUBTYPE_FUNCTION;
6520
- var constants_7 = constants.BSON_BINARY_SUBTYPE_DEFAULT;
6521
- var constants_8 = constants.BSON_DATA_MAX_KEY;
6522
- var constants_9 = constants.BSON_DATA_MIN_KEY;
6523
- var constants_10 = constants.BSON_DATA_DECIMAL128;
6524
- var constants_11 = constants.BSON_DATA_LONG;
6525
- var constants_12 = constants.BSON_DATA_TIMESTAMP;
6526
- var constants_13 = constants.BSON_DATA_INT;
6527
- var constants_14 = constants.BSON_DATA_CODE_W_SCOPE;
6528
- var constants_15 = constants.BSON_DATA_SYMBOL;
6529
- var constants_16 = constants.BSON_DATA_CODE;
6530
- var constants_17 = constants.BSON_DATA_DBPOINTER;
6531
- var constants_18 = constants.BSON_DATA_REGEXP;
6532
- var constants_19 = constants.BSON_DATA_NULL;
6533
- var constants_20 = constants.BSON_DATA_DATE;
6534
- var constants_21 = constants.BSON_DATA_BOOLEAN;
6535
- var constants_22 = constants.BSON_DATA_OID;
6536
- var constants_23 = constants.BSON_DATA_UNDEFINED;
6537
- var constants_24 = constants.BSON_DATA_BINARY;
6538
- var constants_25 = constants.BSON_DATA_ARRAY;
6539
- var constants_26 = constants.BSON_DATA_OBJECT;
6540
- var constants_27 = constants.BSON_DATA_STRING;
6541
- var constants_28 = constants.BSON_DATA_NUMBER;
6542
- var constants_29 = constants.JS_INT_MIN;
6543
- var constants_30 = constants.JS_INT_MAX;
6544
- var constants_31 = constants.BSON_INT64_MIN;
6545
- var constants_32 = constants.BSON_INT64_MAX;
6546
- var constants_33 = constants.BSON_INT32_MIN;
6547
- var constants_34 = constants.BSON_INT32_MAX;
6548
-
6549
- var calculate_size = createCommonjsModule(function (module, exports) {
6550
- Object.defineProperty(exports, "__esModule", { value: true });
6551
- exports.calculateObjectSize = void 0;
6552
-
6553
-
6554
-
6555
-
6556
- function calculateObjectSize(object, serializeFunctions, ignoreUndefined) {
5514
+ function calculateObjectSize$1(object, serializeFunctions, ignoreUndefined) {
6557
5515
  var totalLength = 4 + 1;
6558
5516
  if (Array.isArray(object)) {
6559
5517
  for (var i = 0; i < object.length; i++) {
@@ -6572,7 +5530,6 @@ function calculateObjectSize(object, serializeFunctions, ignoreUndefined) {
6572
5530
  }
6573
5531
  return totalLength;
6574
5532
  }
6575
- exports.calculateObjectSize = calculateObjectSize;
6576
5533
  /** @internal */
6577
5534
  function calculateElement(name,
6578
5535
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -6586,82 +5543,84 @@ value, serializeFunctions, isArray, ignoreUndefined) {
6586
5543
  }
6587
5544
  switch (typeof value) {
6588
5545
  case 'string':
6589
- return 1 + buffer.Buffer.byteLength(name, 'utf8') + 1 + 4 + buffer.Buffer.byteLength(value, 'utf8') + 1;
5546
+ return 1 + buffer_1.byteLength(name, 'utf8') + 1 + 4 + buffer_1.byteLength(value, 'utf8') + 1;
6590
5547
  case 'number':
6591
5548
  if (Math.floor(value) === value &&
6592
- value >= constants.JS_INT_MIN &&
6593
- value <= constants.JS_INT_MAX) {
6594
- if (value >= constants.BSON_INT32_MIN && value <= constants.BSON_INT32_MAX) {
5549
+ value >= JS_INT_MIN &&
5550
+ value <= JS_INT_MAX) {
5551
+ if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
6595
5552
  // 32 bit
6596
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (4 + 1);
5553
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (4 + 1);
6597
5554
  }
6598
5555
  else {
6599
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
5556
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
6600
5557
  }
6601
5558
  }
6602
5559
  else {
6603
5560
  // 64 bit
6604
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
5561
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
6605
5562
  }
6606
5563
  case 'undefined':
6607
5564
  if (isArray || !ignoreUndefined)
6608
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + 1;
5565
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1;
6609
5566
  return 0;
6610
5567
  case 'boolean':
6611
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (1 + 1);
5568
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (1 + 1);
6612
5569
  case 'object':
6613
5570
  if (value == null || value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
6614
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + 1;
5571
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1;
6615
5572
  }
6616
5573
  else if (value['_bsontype'] === 'ObjectId' || value['_bsontype'] === 'ObjectID') {
6617
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (12 + 1);
5574
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (12 + 1);
6618
5575
  }
6619
- else if (value instanceof Date || utils.isDate(value)) {
6620
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
5576
+ else if (value instanceof Date || isDate(value)) {
5577
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
6621
5578
  }
6622
- else if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
6623
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (1 + 4 + 1) + value.byteLength);
5579
+ else if (ArrayBuffer.isView(value) ||
5580
+ value instanceof ArrayBuffer ||
5581
+ isAnyArrayBuffer(value)) {
5582
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (1 + 4 + 1) + value.byteLength);
6624
5583
  }
6625
5584
  else if (value['_bsontype'] === 'Long' ||
6626
5585
  value['_bsontype'] === 'Double' ||
6627
5586
  value['_bsontype'] === 'Timestamp') {
6628
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
5587
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
6629
5588
  }
6630
5589
  else if (value['_bsontype'] === 'Decimal128') {
6631
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (16 + 1);
5590
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (16 + 1);
6632
5591
  }
6633
5592
  else if (value['_bsontype'] === 'Code') {
6634
5593
  // Calculate size depending on the availability of a scope
6635
5594
  if (value.scope != null && Object.keys(value.scope).length > 0) {
6636
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5595
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6637
5596
  1 +
6638
5597
  4 +
6639
5598
  4 +
6640
- buffer.Buffer.byteLength(value.code.toString(), 'utf8') +
5599
+ buffer_1.byteLength(value.code.toString(), 'utf8') +
6641
5600
  1 +
6642
- calculateObjectSize(value.scope, serializeFunctions, ignoreUndefined));
5601
+ calculateObjectSize$1(value.scope, serializeFunctions, ignoreUndefined));
6643
5602
  }
6644
5603
  else {
6645
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5604
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6646
5605
  1 +
6647
5606
  4 +
6648
- buffer.Buffer.byteLength(value.code.toString(), 'utf8') +
5607
+ buffer_1.byteLength(value.code.toString(), 'utf8') +
6649
5608
  1);
6650
5609
  }
6651
5610
  }
6652
5611
  else if (value['_bsontype'] === 'Binary') {
6653
5612
  // Check what kind of subtype we have
6654
- if (value.sub_type === binary.Binary.SUBTYPE_BYTE_ARRAY) {
6655
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5613
+ if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5614
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6656
5615
  (value.position + 1 + 4 + 1 + 4));
6657
5616
  }
6658
5617
  else {
6659
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1));
5618
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1));
6660
5619
  }
6661
5620
  }
6662
5621
  else if (value['_bsontype'] === 'Symbol') {
6663
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
6664
- buffer.Buffer.byteLength(value.value, 'utf8') +
5622
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
5623
+ buffer_1.byteLength(value.value, 'utf8') +
6665
5624
  4 +
6666
5625
  1 +
6667
5626
  1);
@@ -6676,15 +5635,14 @@ value, serializeFunctions, isArray, ignoreUndefined) {
6676
5635
  if (value.db != null) {
6677
5636
  ordered_values['$db'] = value.db;
6678
5637
  }
6679
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5638
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6680
5639
  1 +
6681
- calculateObjectSize(ordered_values, serializeFunctions, ignoreUndefined));
5640
+ calculateObjectSize$1(ordered_values, serializeFunctions, ignoreUndefined));
6682
5641
  }
6683
- else if (value instanceof RegExp ||
6684
- Object.prototype.toString.call(value) === '[object RegExp]') {
6685
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5642
+ else if (value instanceof RegExp || isRegExp(value)) {
5643
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6686
5644
  1 +
6687
- buffer.Buffer.byteLength(value.source, 'utf8') +
5645
+ buffer_1.byteLength(value.source, 'utf8') +
6688
5646
  1 +
6689
5647
  (value.global ? 1 : 0) +
6690
5648
  (value.ignoreCase ? 1 : 0) +
@@ -6692,26 +5650,24 @@ value, serializeFunctions, isArray, ignoreUndefined) {
6692
5650
  1);
6693
5651
  }
6694
5652
  else if (value['_bsontype'] === 'BSONRegExp') {
6695
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5653
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6696
5654
  1 +
6697
- buffer.Buffer.byteLength(value.pattern, 'utf8') +
5655
+ buffer_1.byteLength(value.pattern, 'utf8') +
6698
5656
  1 +
6699
- buffer.Buffer.byteLength(value.options, 'utf8') +
5657
+ buffer_1.byteLength(value.options, 'utf8') +
6700
5658
  1);
6701
5659
  }
6702
5660
  else {
6703
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
6704
- calculateObjectSize(value, serializeFunctions, ignoreUndefined) +
5661
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
5662
+ calculateObjectSize$1(value, serializeFunctions, ignoreUndefined) +
6705
5663
  1);
6706
5664
  }
6707
5665
  case 'function':
6708
5666
  // WTF for 0.4.X where typeof /someregexp/ === 'function'
6709
- if (value instanceof RegExp ||
6710
- Object.prototype.toString.call(value) === '[object RegExp]' ||
6711
- String.call(value) === '[object RegExp]') {
6712
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5667
+ if (value instanceof RegExp || isRegExp(value) || String.call(value) === '[object RegExp]') {
5668
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6713
5669
  1 +
6714
- buffer.Buffer.byteLength(value.source, 'utf8') +
5670
+ buffer_1.byteLength(value.source, 'utf8') +
6715
5671
  1 +
6716
5672
  (value.global ? 1 : 0) +
6717
5673
  (value.ignoreCase ? 1 : 0) +
@@ -6720,19 +5676,19 @@ value, serializeFunctions, isArray, ignoreUndefined) {
6720
5676
  }
6721
5677
  else {
6722
5678
  if (serializeFunctions && value.scope != null && Object.keys(value.scope).length > 0) {
6723
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5679
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6724
5680
  1 +
6725
5681
  4 +
6726
5682
  4 +
6727
- buffer.Buffer.byteLength(utils.normalizedFunctionString(value), 'utf8') +
5683
+ buffer_1.byteLength(normalizedFunctionString(value), 'utf8') +
6728
5684
  1 +
6729
- calculateObjectSize(value.scope, serializeFunctions, ignoreUndefined));
5685
+ calculateObjectSize$1(value.scope, serializeFunctions, ignoreUndefined));
6730
5686
  }
6731
5687
  else if (serializeFunctions) {
6732
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5688
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6733
5689
  1 +
6734
5690
  4 +
6735
- buffer.Buffer.byteLength(utils.normalizedFunctionString(value), 'utf8') +
5691
+ buffer_1.byteLength(normalizedFunctionString(value), 'utf8') +
6736
5692
  1);
6737
5693
  }
6738
5694
  }
@@ -6740,14 +5696,6 @@ value, serializeFunctions, isArray, ignoreUndefined) {
6740
5696
  return 0;
6741
5697
  }
6742
5698
 
6743
- });
6744
-
6745
- unwrapExports(calculate_size);
6746
- var calculate_size_1 = calculate_size.calculateObjectSize;
6747
-
6748
- var validate_utf8 = createCommonjsModule(function (module, exports) {
6749
- Object.defineProperty(exports, "__esModule", { value: true });
6750
- exports.validateUtf8 = void 0;
6751
5699
  var FIRST_BIT = 0x80;
6752
5700
  var FIRST_TWO_BITS = 0xc0;
6753
5701
  var FIRST_THREE_BITS = 0xe0;
@@ -6790,37 +5738,12 @@ function validateUtf8(bytes, start, end) {
6790
5738
  }
6791
5739
  return !continuation;
6792
5740
  }
6793
- exports.validateUtf8 = validateUtf8;
6794
-
6795
- });
6796
-
6797
- unwrapExports(validate_utf8);
6798
- var validate_utf8_1 = validate_utf8.validateUtf8;
6799
-
6800
- var deserializer = createCommonjsModule(function (module, exports) {
6801
- Object.defineProperty(exports, "__esModule", { value: true });
6802
- exports.deserialize = void 0;
6803
-
6804
-
6805
-
6806
-
6807
-
6808
-
6809
-
6810
-
6811
-
6812
-
6813
-
6814
-
6815
-
6816
-
6817
-
6818
5741
 
6819
5742
  // Internal long versions
6820
- var JS_INT_MAX_LONG = long_1.Long.fromNumber(constants.JS_INT_MAX);
6821
- var JS_INT_MIN_LONG = long_1.Long.fromNumber(constants.JS_INT_MIN);
5743
+ var JS_INT_MAX_LONG = Long.fromNumber(JS_INT_MAX);
5744
+ var JS_INT_MIN_LONG = Long.fromNumber(JS_INT_MIN);
6822
5745
  var functionCache = {};
6823
- function deserialize(buffer, options, isArray) {
5746
+ function deserialize$1(buffer, options, isArray) {
6824
5747
  options = options == null ? {} : options;
6825
5748
  var index = options && options.index ? options.index : 0;
6826
5749
  // Read the document size
@@ -6847,8 +5770,8 @@ function deserialize(buffer, options, isArray) {
6847
5770
  // Start deserializtion
6848
5771
  return deserializeObject(buffer, index, options, isArray);
6849
5772
  }
6850
- exports.deserialize = deserialize;
6851
- function deserializeObject(buffer$1, index, options, isArray) {
5773
+ var allowedDBRefKeys = /^\$ref$|^\$id$|^\$db$/;
5774
+ function deserializeObject(buffer, index, options, isArray) {
6852
5775
  if (isArray === void 0) { isArray = false; }
6853
5776
  var evalFunctions = options['evalFunctions'] == null ? false : options['evalFunctions'];
6854
5777
  var cacheFunctions = options['cacheFunctions'] == null ? false : options['cacheFunctions'];
@@ -6864,115 +5787,124 @@ function deserializeObject(buffer$1, index, options, isArray) {
6864
5787
  // Set the start index
6865
5788
  var startIndex = index;
6866
5789
  // Validate that we have at least 4 bytes of buffer
6867
- if (buffer$1.length < 5)
5790
+ if (buffer.length < 5)
6868
5791
  throw new Error('corrupt bson message < 5 bytes long');
6869
5792
  // Read the document size
6870
- var size = buffer$1[index++] | (buffer$1[index++] << 8) | (buffer$1[index++] << 16) | (buffer$1[index++] << 24);
5793
+ var size = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
6871
5794
  // Ensure buffer is valid size
6872
- if (size < 5 || size > buffer$1.length)
5795
+ if (size < 5 || size > buffer.length)
6873
5796
  throw new Error('corrupt bson message');
6874
5797
  // Create holding object
6875
5798
  var object = isArray ? [] : {};
6876
5799
  // Used for arrays to skip having to perform utf8 decoding
6877
5800
  var arrayIndex = 0;
6878
5801
  var done = false;
5802
+ var isPossibleDBRef = isArray ? false : null;
6879
5803
  // While we have more left data left keep parsing
6880
5804
  while (!done) {
6881
5805
  // Read the type
6882
- var elementType = buffer$1[index++];
5806
+ var elementType = buffer[index++];
6883
5807
  // If we get a zero it's the last byte, exit
6884
5808
  if (elementType === 0)
6885
5809
  break;
6886
5810
  // Get the start search index
6887
5811
  var i = index;
6888
5812
  // Locate the end of the c string
6889
- while (buffer$1[i] !== 0x00 && i < buffer$1.length) {
5813
+ while (buffer[i] !== 0x00 && i < buffer.length) {
6890
5814
  i++;
6891
5815
  }
6892
5816
  // If are at the end of the buffer there is a problem with the document
6893
- if (i >= buffer$1.byteLength)
5817
+ if (i >= buffer.byteLength)
6894
5818
  throw new Error('Bad BSON Document: illegal CString');
6895
- var name = isArray ? arrayIndex++ : buffer$1.toString('utf8', index, i);
5819
+ var name = isArray ? arrayIndex++ : buffer.toString('utf8', index, i);
5820
+ if (isPossibleDBRef !== false && name[0] === '$') {
5821
+ isPossibleDBRef = allowedDBRefKeys.test(name);
5822
+ }
5823
+ var value = void 0;
6896
5824
  index = i + 1;
6897
- if (elementType === constants.BSON_DATA_STRING) {
6898
- var stringSize = buffer$1[index++] |
6899
- (buffer$1[index++] << 8) |
6900
- (buffer$1[index++] << 16) |
6901
- (buffer$1[index++] << 24);
5825
+ if (elementType === BSON_DATA_STRING) {
5826
+ var stringSize = buffer[index++] |
5827
+ (buffer[index++] << 8) |
5828
+ (buffer[index++] << 16) |
5829
+ (buffer[index++] << 24);
6902
5830
  if (stringSize <= 0 ||
6903
- stringSize > buffer$1.length - index ||
6904
- buffer$1[index + stringSize - 1] !== 0)
5831
+ stringSize > buffer.length - index ||
5832
+ buffer[index + stringSize - 1] !== 0)
6905
5833
  throw new Error('bad string length in bson');
6906
- if (!validate_utf8.validateUtf8(buffer$1, index, index + stringSize - 1)) {
6907
- throw new Error('Invalid UTF-8 string in BSON document');
5834
+ value = buffer.toString('utf8', index, index + stringSize - 1);
5835
+ for (var i_1 = 0; i_1 < value.length; i_1++) {
5836
+ if (value.charCodeAt(i_1) === 0xfffd) {
5837
+ if (!validateUtf8(buffer, index, index + stringSize - 1)) {
5838
+ throw new Error('Invalid UTF-8 string in BSON document');
5839
+ }
5840
+ break;
5841
+ }
6908
5842
  }
6909
- var s = buffer$1.toString('utf8', index, index + stringSize - 1);
6910
- object[name] = s;
6911
5843
  index = index + stringSize;
6912
5844
  }
6913
- else if (elementType === constants.BSON_DATA_OID) {
6914
- var oid = buffer.Buffer.alloc(12);
6915
- buffer$1.copy(oid, 0, index, index + 12);
6916
- object[name] = new objectid.ObjectId(oid);
5845
+ else if (elementType === BSON_DATA_OID) {
5846
+ var oid = buffer_1.alloc(12);
5847
+ buffer.copy(oid, 0, index, index + 12);
5848
+ value = new ObjectId(oid);
6917
5849
  index = index + 12;
6918
5850
  }
6919
- else if (elementType === constants.BSON_DATA_INT && promoteValues === false) {
6920
- object[name] = new int_32.Int32(buffer$1[index++] | (buffer$1[index++] << 8) | (buffer$1[index++] << 16) | (buffer$1[index++] << 24));
5851
+ else if (elementType === BSON_DATA_INT && promoteValues === false) {
5852
+ value = new Int32(buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24));
6921
5853
  }
6922
- else if (elementType === constants.BSON_DATA_INT) {
6923
- object[name] =
6924
- buffer$1[index++] |
6925
- (buffer$1[index++] << 8) |
6926
- (buffer$1[index++] << 16) |
6927
- (buffer$1[index++] << 24);
5854
+ else if (elementType === BSON_DATA_INT) {
5855
+ value =
5856
+ buffer[index++] |
5857
+ (buffer[index++] << 8) |
5858
+ (buffer[index++] << 16) |
5859
+ (buffer[index++] << 24);
6928
5860
  }
6929
- else if (elementType === constants.BSON_DATA_NUMBER && promoteValues === false) {
6930
- object[name] = new double_1.Double(buffer$1.readDoubleLE(index));
5861
+ else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
5862
+ value = new Double(buffer.readDoubleLE(index));
6931
5863
  index = index + 8;
6932
5864
  }
6933
- else if (elementType === constants.BSON_DATA_NUMBER) {
6934
- object[name] = buffer$1.readDoubleLE(index);
5865
+ else if (elementType === BSON_DATA_NUMBER) {
5866
+ value = buffer.readDoubleLE(index);
6935
5867
  index = index + 8;
6936
5868
  }
6937
- else if (elementType === constants.BSON_DATA_DATE) {
6938
- var lowBits = buffer$1[index++] |
6939
- (buffer$1[index++] << 8) |
6940
- (buffer$1[index++] << 16) |
6941
- (buffer$1[index++] << 24);
6942
- var highBits = buffer$1[index++] |
6943
- (buffer$1[index++] << 8) |
6944
- (buffer$1[index++] << 16) |
6945
- (buffer$1[index++] << 24);
6946
- object[name] = new Date(new long_1.Long(lowBits, highBits).toNumber());
6947
- }
6948
- else if (elementType === constants.BSON_DATA_BOOLEAN) {
6949
- if (buffer$1[index] !== 0 && buffer$1[index] !== 1)
5869
+ else if (elementType === BSON_DATA_DATE) {
5870
+ var lowBits = buffer[index++] |
5871
+ (buffer[index++] << 8) |
5872
+ (buffer[index++] << 16) |
5873
+ (buffer[index++] << 24);
5874
+ var highBits = buffer[index++] |
5875
+ (buffer[index++] << 8) |
5876
+ (buffer[index++] << 16) |
5877
+ (buffer[index++] << 24);
5878
+ value = new Date(new Long(lowBits, highBits).toNumber());
5879
+ }
5880
+ else if (elementType === BSON_DATA_BOOLEAN) {
5881
+ if (buffer[index] !== 0 && buffer[index] !== 1)
6950
5882
  throw new Error('illegal boolean type value');
6951
- object[name] = buffer$1[index++] === 1;
5883
+ value = buffer[index++] === 1;
6952
5884
  }
6953
- else if (elementType === constants.BSON_DATA_OBJECT) {
5885
+ else if (elementType === BSON_DATA_OBJECT) {
6954
5886
  var _index = index;
6955
- var objectSize = buffer$1[index] |
6956
- (buffer$1[index + 1] << 8) |
6957
- (buffer$1[index + 2] << 16) |
6958
- (buffer$1[index + 3] << 24);
6959
- if (objectSize <= 0 || objectSize > buffer$1.length - index)
5887
+ var objectSize = buffer[index] |
5888
+ (buffer[index + 1] << 8) |
5889
+ (buffer[index + 2] << 16) |
5890
+ (buffer[index + 3] << 24);
5891
+ if (objectSize <= 0 || objectSize > buffer.length - index)
6960
5892
  throw new Error('bad embedded document length in bson');
6961
5893
  // We have a raw value
6962
5894
  if (raw) {
6963
- object[name] = buffer$1.slice(index, index + objectSize);
5895
+ value = buffer.slice(index, index + objectSize);
6964
5896
  }
6965
5897
  else {
6966
- object[name] = deserializeObject(buffer$1, _index, options, false);
5898
+ value = deserializeObject(buffer, _index, options, false);
6967
5899
  }
6968
5900
  index = index + objectSize;
6969
5901
  }
6970
- else if (elementType === constants.BSON_DATA_ARRAY) {
5902
+ else if (elementType === BSON_DATA_ARRAY) {
6971
5903
  var _index = index;
6972
- var objectSize = buffer$1[index] |
6973
- (buffer$1[index + 1] << 8) |
6974
- (buffer$1[index + 2] << 16) |
6975
- (buffer$1[index + 3] << 24);
5904
+ var objectSize = buffer[index] |
5905
+ (buffer[index + 1] << 8) |
5906
+ (buffer[index + 2] << 16) |
5907
+ (buffer[index + 3] << 24);
6976
5908
  var arrayOptions = options;
6977
5909
  // Stop index
6978
5910
  var stopIndex = index + objectSize;
@@ -6984,80 +5916,80 @@ function deserializeObject(buffer$1, index, options, isArray) {
6984
5916
  }
6985
5917
  arrayOptions['raw'] = true;
6986
5918
  }
6987
- object[name] = deserializeObject(buffer$1, _index, arrayOptions, true);
5919
+ value = deserializeObject(buffer, _index, arrayOptions, true);
6988
5920
  index = index + objectSize;
6989
- if (buffer$1[index - 1] !== 0)
5921
+ if (buffer[index - 1] !== 0)
6990
5922
  throw new Error('invalid array terminator byte');
6991
5923
  if (index !== stopIndex)
6992
5924
  throw new Error('corrupted array bson');
6993
5925
  }
6994
- else if (elementType === constants.BSON_DATA_UNDEFINED) {
6995
- object[name] = undefined;
5926
+ else if (elementType === BSON_DATA_UNDEFINED) {
5927
+ value = undefined;
6996
5928
  }
6997
- else if (elementType === constants.BSON_DATA_NULL) {
6998
- object[name] = null;
5929
+ else if (elementType === BSON_DATA_NULL) {
5930
+ value = null;
6999
5931
  }
7000
- else if (elementType === constants.BSON_DATA_LONG) {
5932
+ else if (elementType === BSON_DATA_LONG) {
7001
5933
  // Unpack the low and high bits
7002
- var lowBits = buffer$1[index++] |
7003
- (buffer$1[index++] << 8) |
7004
- (buffer$1[index++] << 16) |
7005
- (buffer$1[index++] << 24);
7006
- var highBits = buffer$1[index++] |
7007
- (buffer$1[index++] << 8) |
7008
- (buffer$1[index++] << 16) |
7009
- (buffer$1[index++] << 24);
7010
- var long = new long_1.Long(lowBits, highBits);
5934
+ var lowBits = buffer[index++] |
5935
+ (buffer[index++] << 8) |
5936
+ (buffer[index++] << 16) |
5937
+ (buffer[index++] << 24);
5938
+ var highBits = buffer[index++] |
5939
+ (buffer[index++] << 8) |
5940
+ (buffer[index++] << 16) |
5941
+ (buffer[index++] << 24);
5942
+ var long = new Long(lowBits, highBits);
7011
5943
  // Promote the long if possible
7012
5944
  if (promoteLongs && promoteValues === true) {
7013
- object[name] =
5945
+ value =
7014
5946
  long.lessThanOrEqual(JS_INT_MAX_LONG) && long.greaterThanOrEqual(JS_INT_MIN_LONG)
7015
5947
  ? long.toNumber()
7016
5948
  : long;
7017
5949
  }
7018
5950
  else {
7019
- object[name] = long;
5951
+ value = long;
7020
5952
  }
7021
5953
  }
7022
- else if (elementType === constants.BSON_DATA_DECIMAL128) {
5954
+ else if (elementType === BSON_DATA_DECIMAL128) {
7023
5955
  // Buffer to contain the decimal bytes
7024
- var bytes = buffer.Buffer.alloc(16);
5956
+ var bytes = buffer_1.alloc(16);
7025
5957
  // Copy the next 16 bytes into the bytes buffer
7026
- buffer$1.copy(bytes, 0, index, index + 16);
5958
+ buffer.copy(bytes, 0, index, index + 16);
7027
5959
  // Update index
7028
5960
  index = index + 16;
7029
5961
  // Assign the new Decimal128 value
7030
- var decimal128$1 = new decimal128.Decimal128(bytes);
5962
+ var decimal128 = new Decimal128(bytes);
7031
5963
  // If we have an alternative mapper use that
7032
- if ('toObject' in decimal128$1 && typeof decimal128$1.toObject === 'function') {
7033
- object[name] = decimal128$1.toObject();
5964
+ if ('toObject' in decimal128 && typeof decimal128.toObject === 'function') {
5965
+ value = decimal128.toObject();
7034
5966
  }
7035
5967
  else {
7036
- object[name] = decimal128$1;
5968
+ value = decimal128;
7037
5969
  }
7038
5970
  }
7039
- else if (elementType === constants.BSON_DATA_BINARY) {
7040
- var binarySize = buffer$1[index++] |
7041
- (buffer$1[index++] << 8) |
7042
- (buffer$1[index++] << 16) |
7043
- (buffer$1[index++] << 24);
5971
+ else if (elementType === BSON_DATA_BINARY) {
5972
+ var binarySize = buffer[index++] |
5973
+ (buffer[index++] << 8) |
5974
+ (buffer[index++] << 16) |
5975
+ (buffer[index++] << 24);
7044
5976
  var totalBinarySize = binarySize;
7045
- var subType = buffer$1[index++];
5977
+ var subType = buffer[index++];
7046
5978
  // Did we have a negative binary size, throw
7047
5979
  if (binarySize < 0)
7048
5980
  throw new Error('Negative binary type element size found');
7049
5981
  // Is the length longer than the document
7050
- if (binarySize > buffer$1.byteLength)
5982
+ if (binarySize > buffer.byteLength)
7051
5983
  throw new Error('Binary type size larger than document size');
7052
5984
  // Decode as raw Buffer object if options specifies it
7053
- if (buffer$1['slice'] != null) {
5985
+ if (buffer['slice'] != null) {
7054
5986
  // If we have subtype 2 skip the 4 bytes for the size
7055
- if (subType === binary.Binary.SUBTYPE_BYTE_ARRAY) {
5987
+ if (subType === Binary.SUBTYPE_BYTE_ARRAY) {
7056
5988
  binarySize =
7057
- buffer$1[index++] |
7058
- (buffer$1[index++] << 8) |
7059
- (buffer$1[index++] << 16) |
7060
- (buffer$1[index++] << 24);
5989
+ buffer[index++] |
5990
+ (buffer[index++] << 8) |
5991
+ (buffer[index++] << 16) |
5992
+ (buffer[index++] << 24);
7061
5993
  if (binarySize < 0)
7062
5994
  throw new Error('Negative binary type element size found for subtype 0x02');
7063
5995
  if (binarySize > totalBinarySize - 4)
@@ -7066,21 +5998,21 @@ function deserializeObject(buffer$1, index, options, isArray) {
7066
5998
  throw new Error('Binary type with subtype 0x02 contains too short binary size');
7067
5999
  }
7068
6000
  if (promoteBuffers && promoteValues) {
7069
- object[name] = buffer$1.slice(index, index + binarySize);
6001
+ value = buffer.slice(index, index + binarySize);
7070
6002
  }
7071
6003
  else {
7072
- object[name] = new binary.Binary(buffer$1.slice(index, index + binarySize), subType);
6004
+ value = new Binary(buffer.slice(index, index + binarySize), subType);
7073
6005
  }
7074
6006
  }
7075
6007
  else {
7076
- var _buffer = buffer.Buffer.alloc(binarySize);
6008
+ var _buffer = buffer_1.alloc(binarySize);
7077
6009
  // If we have subtype 2 skip the 4 bytes for the size
7078
- if (subType === binary.Binary.SUBTYPE_BYTE_ARRAY) {
6010
+ if (subType === Binary.SUBTYPE_BYTE_ARRAY) {
7079
6011
  binarySize =
7080
- buffer$1[index++] |
7081
- (buffer$1[index++] << 8) |
7082
- (buffer$1[index++] << 16) |
7083
- (buffer$1[index++] << 24);
6012
+ buffer[index++] |
6013
+ (buffer[index++] << 8) |
6014
+ (buffer[index++] << 16) |
6015
+ (buffer[index++] << 24);
7084
6016
  if (binarySize < 0)
7085
6017
  throw new Error('Negative binary type element size found for subtype 0x02');
7086
6018
  if (binarySize > totalBinarySize - 4)
@@ -7090,43 +6022,43 @@ function deserializeObject(buffer$1, index, options, isArray) {
7090
6022
  }
7091
6023
  // Copy the data
7092
6024
  for (i = 0; i < binarySize; i++) {
7093
- _buffer[i] = buffer$1[index + i];
6025
+ _buffer[i] = buffer[index + i];
7094
6026
  }
7095
6027
  if (promoteBuffers && promoteValues) {
7096
- object[name] = _buffer;
6028
+ value = _buffer;
7097
6029
  }
7098
6030
  else {
7099
- object[name] = new binary.Binary(_buffer, subType);
6031
+ value = new Binary(_buffer, subType);
7100
6032
  }
7101
6033
  }
7102
6034
  // Update the index
7103
6035
  index = index + binarySize;
7104
6036
  }
7105
- else if (elementType === constants.BSON_DATA_REGEXP && bsonRegExp === false) {
6037
+ else if (elementType === BSON_DATA_REGEXP && bsonRegExp === false) {
7106
6038
  // Get the start search index
7107
6039
  i = index;
7108
6040
  // Locate the end of the c string
7109
- while (buffer$1[i] !== 0x00 && i < buffer$1.length) {
6041
+ while (buffer[i] !== 0x00 && i < buffer.length) {
7110
6042
  i++;
7111
6043
  }
7112
6044
  // If are at the end of the buffer there is a problem with the document
7113
- if (i >= buffer$1.length)
6045
+ if (i >= buffer.length)
7114
6046
  throw new Error('Bad BSON Document: illegal CString');
7115
6047
  // Return the C string
7116
- var source = buffer$1.toString('utf8', index, i);
6048
+ var source = buffer.toString('utf8', index, i);
7117
6049
  // Create the regexp
7118
6050
  index = i + 1;
7119
6051
  // Get the start search index
7120
6052
  i = index;
7121
6053
  // Locate the end of the c string
7122
- while (buffer$1[i] !== 0x00 && i < buffer$1.length) {
6054
+ while (buffer[i] !== 0x00 && i < buffer.length) {
7123
6055
  i++;
7124
6056
  }
7125
6057
  // If are at the end of the buffer there is a problem with the document
7126
- if (i >= buffer$1.length)
6058
+ if (i >= buffer.length)
7127
6059
  throw new Error('Bad BSON Document: illegal CString');
7128
6060
  // Return the C string
7129
- var regExpOptions = buffer$1.toString('utf8', index, i);
6061
+ var regExpOptions = buffer.toString('utf8', index, i);
7130
6062
  index = i + 1;
7131
6063
  // For each option add the corresponding one for javascript
7132
6064
  var optionsArray = new Array(regExpOptions.length);
@@ -7144,125 +6076,125 @@ function deserializeObject(buffer$1, index, options, isArray) {
7144
6076
  break;
7145
6077
  }
7146
6078
  }
7147
- object[name] = new RegExp(source, optionsArray.join(''));
6079
+ value = new RegExp(source, optionsArray.join(''));
7148
6080
  }
7149
- else if (elementType === constants.BSON_DATA_REGEXP && bsonRegExp === true) {
6081
+ else if (elementType === BSON_DATA_REGEXP && bsonRegExp === true) {
7150
6082
  // Get the start search index
7151
6083
  i = index;
7152
6084
  // Locate the end of the c string
7153
- while (buffer$1[i] !== 0x00 && i < buffer$1.length) {
6085
+ while (buffer[i] !== 0x00 && i < buffer.length) {
7154
6086
  i++;
7155
6087
  }
7156
6088
  // If are at the end of the buffer there is a problem with the document
7157
- if (i >= buffer$1.length)
6089
+ if (i >= buffer.length)
7158
6090
  throw new Error('Bad BSON Document: illegal CString');
7159
6091
  // Return the C string
7160
- var source = buffer$1.toString('utf8', index, i);
6092
+ var source = buffer.toString('utf8', index, i);
7161
6093
  index = i + 1;
7162
6094
  // Get the start search index
7163
6095
  i = index;
7164
6096
  // Locate the end of the c string
7165
- while (buffer$1[i] !== 0x00 && i < buffer$1.length) {
6097
+ while (buffer[i] !== 0x00 && i < buffer.length) {
7166
6098
  i++;
7167
6099
  }
7168
6100
  // If are at the end of the buffer there is a problem with the document
7169
- if (i >= buffer$1.length)
6101
+ if (i >= buffer.length)
7170
6102
  throw new Error('Bad BSON Document: illegal CString');
7171
6103
  // Return the C string
7172
- var regExpOptions = buffer$1.toString('utf8', index, i);
6104
+ var regExpOptions = buffer.toString('utf8', index, i);
7173
6105
  index = i + 1;
7174
6106
  // Set the object
7175
- object[name] = new regexp.BSONRegExp(source, regExpOptions);
6107
+ value = new BSONRegExp(source, regExpOptions);
7176
6108
  }
7177
- else if (elementType === constants.BSON_DATA_SYMBOL) {
7178
- var stringSize = buffer$1[index++] |
7179
- (buffer$1[index++] << 8) |
7180
- (buffer$1[index++] << 16) |
7181
- (buffer$1[index++] << 24);
6109
+ else if (elementType === BSON_DATA_SYMBOL) {
6110
+ var stringSize = buffer[index++] |
6111
+ (buffer[index++] << 8) |
6112
+ (buffer[index++] << 16) |
6113
+ (buffer[index++] << 24);
7182
6114
  if (stringSize <= 0 ||
7183
- stringSize > buffer$1.length - index ||
7184
- buffer$1[index + stringSize - 1] !== 0)
6115
+ stringSize > buffer.length - index ||
6116
+ buffer[index + stringSize - 1] !== 0)
7185
6117
  throw new Error('bad string length in bson');
7186
- var symbol$1 = buffer$1.toString('utf8', index, index + stringSize - 1);
7187
- object[name] = promoteValues ? symbol$1 : new symbol.BSONSymbol(symbol$1);
6118
+ var symbol = buffer.toString('utf8', index, index + stringSize - 1);
6119
+ value = promoteValues ? symbol : new BSONSymbol(symbol);
7188
6120
  index = index + stringSize;
7189
6121
  }
7190
- else if (elementType === constants.BSON_DATA_TIMESTAMP) {
7191
- var lowBits = buffer$1[index++] |
7192
- (buffer$1[index++] << 8) |
7193
- (buffer$1[index++] << 16) |
7194
- (buffer$1[index++] << 24);
7195
- var highBits = buffer$1[index++] |
7196
- (buffer$1[index++] << 8) |
7197
- (buffer$1[index++] << 16) |
7198
- (buffer$1[index++] << 24);
7199
- object[name] = new timestamp$1.Timestamp(lowBits, highBits);
7200
- }
7201
- else if (elementType === constants.BSON_DATA_MIN_KEY) {
7202
- object[name] = new min_key.MinKey();
7203
- }
7204
- else if (elementType === constants.BSON_DATA_MAX_KEY) {
7205
- object[name] = new max_key.MaxKey();
7206
- }
7207
- else if (elementType === constants.BSON_DATA_CODE) {
7208
- var stringSize = buffer$1[index++] |
7209
- (buffer$1[index++] << 8) |
7210
- (buffer$1[index++] << 16) |
7211
- (buffer$1[index++] << 24);
6122
+ else if (elementType === BSON_DATA_TIMESTAMP) {
6123
+ var lowBits = buffer[index++] |
6124
+ (buffer[index++] << 8) |
6125
+ (buffer[index++] << 16) |
6126
+ (buffer[index++] << 24);
6127
+ var highBits = buffer[index++] |
6128
+ (buffer[index++] << 8) |
6129
+ (buffer[index++] << 16) |
6130
+ (buffer[index++] << 24);
6131
+ value = new Timestamp(lowBits, highBits);
6132
+ }
6133
+ else if (elementType === BSON_DATA_MIN_KEY) {
6134
+ value = new MinKey();
6135
+ }
6136
+ else if (elementType === BSON_DATA_MAX_KEY) {
6137
+ value = new MaxKey();
6138
+ }
6139
+ else if (elementType === BSON_DATA_CODE) {
6140
+ var stringSize = buffer[index++] |
6141
+ (buffer[index++] << 8) |
6142
+ (buffer[index++] << 16) |
6143
+ (buffer[index++] << 24);
7212
6144
  if (stringSize <= 0 ||
7213
- stringSize > buffer$1.length - index ||
7214
- buffer$1[index + stringSize - 1] !== 0)
6145
+ stringSize > buffer.length - index ||
6146
+ buffer[index + stringSize - 1] !== 0)
7215
6147
  throw new Error('bad string length in bson');
7216
- var functionString = buffer$1.toString('utf8', index, index + stringSize - 1);
6148
+ var functionString = buffer.toString('utf8', index, index + stringSize - 1);
7217
6149
  // If we are evaluating the functions
7218
6150
  if (evalFunctions) {
7219
6151
  // If we have cache enabled let's look for the md5 of the function in the cache
7220
6152
  if (cacheFunctions) {
7221
6153
  // Got to do this to avoid V8 deoptimizing the call due to finding eval
7222
- object[name] = isolateEval(functionString, functionCache, object);
6154
+ value = isolateEval(functionString, functionCache, object);
7223
6155
  }
7224
6156
  else {
7225
- object[name] = isolateEval(functionString);
6157
+ value = isolateEval(functionString);
7226
6158
  }
7227
6159
  }
7228
6160
  else {
7229
- object[name] = new code$1.Code(functionString);
6161
+ value = new Code(functionString);
7230
6162
  }
7231
6163
  // Update parse index position
7232
6164
  index = index + stringSize;
7233
6165
  }
7234
- else if (elementType === constants.BSON_DATA_CODE_W_SCOPE) {
7235
- var totalSize = buffer$1[index++] |
7236
- (buffer$1[index++] << 8) |
7237
- (buffer$1[index++] << 16) |
7238
- (buffer$1[index++] << 24);
6166
+ else if (elementType === BSON_DATA_CODE_W_SCOPE) {
6167
+ var totalSize = buffer[index++] |
6168
+ (buffer[index++] << 8) |
6169
+ (buffer[index++] << 16) |
6170
+ (buffer[index++] << 24);
7239
6171
  // Element cannot be shorter than totalSize + stringSize + documentSize + terminator
7240
6172
  if (totalSize < 4 + 4 + 4 + 1) {
7241
6173
  throw new Error('code_w_scope total size shorter minimum expected length');
7242
6174
  }
7243
6175
  // Get the code string size
7244
- var stringSize = buffer$1[index++] |
7245
- (buffer$1[index++] << 8) |
7246
- (buffer$1[index++] << 16) |
7247
- (buffer$1[index++] << 24);
6176
+ var stringSize = buffer[index++] |
6177
+ (buffer[index++] << 8) |
6178
+ (buffer[index++] << 16) |
6179
+ (buffer[index++] << 24);
7248
6180
  // Check if we have a valid string
7249
6181
  if (stringSize <= 0 ||
7250
- stringSize > buffer$1.length - index ||
7251
- buffer$1[index + stringSize - 1] !== 0)
6182
+ stringSize > buffer.length - index ||
6183
+ buffer[index + stringSize - 1] !== 0)
7252
6184
  throw new Error('bad string length in bson');
7253
6185
  // Javascript function
7254
- var functionString = buffer$1.toString('utf8', index, index + stringSize - 1);
6186
+ var functionString = buffer.toString('utf8', index, index + stringSize - 1);
7255
6187
  // Update parse index position
7256
6188
  index = index + stringSize;
7257
6189
  // Parse the element
7258
6190
  var _index = index;
7259
6191
  // Decode the size of the object document
7260
- var objectSize = buffer$1[index] |
7261
- (buffer$1[index + 1] << 8) |
7262
- (buffer$1[index + 2] << 16) |
7263
- (buffer$1[index + 3] << 24);
6192
+ var objectSize = buffer[index] |
6193
+ (buffer[index + 1] << 8) |
6194
+ (buffer[index + 2] << 16) |
6195
+ (buffer[index + 3] << 24);
7264
6196
  // Decode the scope object
7265
- var scopeObject = deserializeObject(buffer$1, _index, options, false);
6197
+ var scopeObject = deserializeObject(buffer, _index, options, false);
7266
6198
  // Adjust the index
7267
6199
  index = index + objectSize;
7268
6200
  // Check if field length is too short
@@ -7278,47 +6210,58 @@ function deserializeObject(buffer$1, index, options, isArray) {
7278
6210
  // If we have cache enabled let's look for the md5 of the function in the cache
7279
6211
  if (cacheFunctions) {
7280
6212
  // Got to do this to avoid V8 deoptimizing the call due to finding eval
7281
- object[name] = isolateEval(functionString, functionCache, object);
6213
+ value = isolateEval(functionString, functionCache, object);
7282
6214
  }
7283
6215
  else {
7284
- object[name] = isolateEval(functionString);
6216
+ value = isolateEval(functionString);
7285
6217
  }
7286
- object[name].scope = scopeObject;
6218
+ value.scope = scopeObject;
7287
6219
  }
7288
6220
  else {
7289
- object[name] = new code$1.Code(functionString, scopeObject);
6221
+ value = new Code(functionString, scopeObject);
7290
6222
  }
7291
6223
  }
7292
- else if (elementType === constants.BSON_DATA_DBPOINTER) {
6224
+ else if (elementType === BSON_DATA_DBPOINTER) {
7293
6225
  // Get the code string size
7294
- var stringSize = buffer$1[index++] |
7295
- (buffer$1[index++] << 8) |
7296
- (buffer$1[index++] << 16) |
7297
- (buffer$1[index++] << 24);
6226
+ var stringSize = buffer[index++] |
6227
+ (buffer[index++] << 8) |
6228
+ (buffer[index++] << 16) |
6229
+ (buffer[index++] << 24);
7298
6230
  // Check if we have a valid string
7299
6231
  if (stringSize <= 0 ||
7300
- stringSize > buffer$1.length - index ||
7301
- buffer$1[index + stringSize - 1] !== 0)
6232
+ stringSize > buffer.length - index ||
6233
+ buffer[index + stringSize - 1] !== 0)
7302
6234
  throw new Error('bad string length in bson');
7303
6235
  // Namespace
7304
- if (!validate_utf8.validateUtf8(buffer$1, index, index + stringSize - 1)) {
6236
+ if (!validateUtf8(buffer, index, index + stringSize - 1)) {
7305
6237
  throw new Error('Invalid UTF-8 string in BSON document');
7306
6238
  }
7307
- var namespace = buffer$1.toString('utf8', index, index + stringSize - 1);
6239
+ var namespace = buffer.toString('utf8', index, index + stringSize - 1);
7308
6240
  // Update parse index position
7309
6241
  index = index + stringSize;
7310
6242
  // Read the oid
7311
- var oidBuffer = buffer.Buffer.alloc(12);
7312
- buffer$1.copy(oidBuffer, 0, index, index + 12);
7313
- var oid = new objectid.ObjectId(oidBuffer);
6243
+ var oidBuffer = buffer_1.alloc(12);
6244
+ buffer.copy(oidBuffer, 0, index, index + 12);
6245
+ var oid = new ObjectId(oidBuffer);
7314
6246
  // Update the index
7315
6247
  index = index + 12;
7316
6248
  // Upgrade to DBRef type
7317
- object[name] = new db_ref.DBRef(namespace, oid);
6249
+ value = new DBRef(namespace, oid);
7318
6250
  }
7319
6251
  else {
7320
6252
  throw new Error('Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"');
7321
6253
  }
6254
+ if (name === '__proto__') {
6255
+ Object.defineProperty(object, name, {
6256
+ value: value,
6257
+ writable: true,
6258
+ enumerable: true,
6259
+ configurable: true
6260
+ });
6261
+ }
6262
+ else {
6263
+ object[name] = value;
6264
+ }
7322
6265
  }
7323
6266
  // Check if the deserialization was against a valid array/object
7324
6267
  if (size !== index - startIndex) {
@@ -7326,22 +6269,15 @@ function deserializeObject(buffer$1, index, options, isArray) {
7326
6269
  throw new Error('corrupt array bson');
7327
6270
  throw new Error('corrupt object bson');
7328
6271
  }
7329
- // check if object's $ keys are those of a DBRef
7330
- var dollarKeys = Object.keys(object).filter(function (k) { return k.startsWith('$'); });
7331
- var valid = true;
7332
- dollarKeys.forEach(function (k) {
7333
- if (['$ref', '$id', '$db'].indexOf(k) === -1)
7334
- valid = false;
7335
- });
7336
- // if a $key not in "$ref", "$id", "$db", don't make a DBRef
7337
- if (!valid)
6272
+ // if we did not find "$ref", "$id", "$db", or found an extraneous $key, don't make a DBRef
6273
+ if (!isPossibleDBRef)
7338
6274
  return object;
7339
- if (db_ref.isDBRefLike(object)) {
6275
+ if (isDBRefLike(object)) {
7340
6276
  var copy = Object.assign({}, object);
7341
6277
  delete copy.$ref;
7342
6278
  delete copy.$id;
7343
6279
  delete copy.$db;
7344
- return new db_ref.DBRef(object.$ref, object.$id, object.$db, copy);
6280
+ return new DBRef(object.$ref, object.$id, object.$db, copy);
7345
6281
  }
7346
6282
  return object;
7347
6283
  }
@@ -7361,80 +6297,7 @@ function isolateEval(functionString, functionCache, object) {
7361
6297
  return functionCache[functionString].bind(object);
7362
6298
  }
7363
6299
 
7364
- });
7365
-
7366
- unwrapExports(deserializer);
7367
- var deserializer_1 = deserializer.deserialize;
7368
-
7369
- var float_parser = createCommonjsModule(function (module, exports) {
7370
6300
  // Copyright (c) 2008, Fair Oaks Labs, Inc.
7371
- // All rights reserved.
7372
- //
7373
- // Redistribution and use in source and binary forms, with or without
7374
- // modification, are permitted provided that the following conditions are met:
7375
- //
7376
- // * Redistributions of source code must retain the above copyright notice,
7377
- // this list of conditions and the following disclaimer.
7378
- //
7379
- // * Redistributions in binary form must reproduce the above copyright notice,
7380
- // this list of conditions and the following disclaimer in the documentation
7381
- // and/or other materials provided with the distribution.
7382
- //
7383
- // * Neither the name of Fair Oaks Labs, Inc. nor the names of its contributors
7384
- // may be used to endorse or promote products derived from this software
7385
- // without specific prior written permission.
7386
- //
7387
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
7388
- // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7389
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7390
- // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
7391
- // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
7392
- // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
7393
- // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
7394
- // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
7395
- // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
7396
- // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
7397
- // POSSIBILITY OF SUCH DAMAGE.
7398
- //
7399
- //
7400
- // Modifications to writeIEEE754 to support negative zeroes made by Brian White
7401
- Object.defineProperty(exports, "__esModule", { value: true });
7402
- exports.writeIEEE754 = exports.readIEEE754 = void 0;
7403
- function readIEEE754(buffer, offset, endian, mLen, nBytes) {
7404
- var e;
7405
- var m;
7406
- var bBE = endian === 'big';
7407
- var eLen = nBytes * 8 - mLen - 1;
7408
- var eMax = (1 << eLen) - 1;
7409
- var eBias = eMax >> 1;
7410
- var nBits = -7;
7411
- var i = bBE ? 0 : nBytes - 1;
7412
- var d = bBE ? 1 : -1;
7413
- var s = buffer[offset + i];
7414
- i += d;
7415
- e = s & ((1 << -nBits) - 1);
7416
- s >>= -nBits;
7417
- nBits += eLen;
7418
- for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8)
7419
- ;
7420
- m = e & ((1 << -nBits) - 1);
7421
- e >>= -nBits;
7422
- nBits += mLen;
7423
- for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8)
7424
- ;
7425
- if (e === 0) {
7426
- e = 1 - eBias;
7427
- }
7428
- else if (e === eMax) {
7429
- return m ? NaN : (s ? -1 : 1) * Infinity;
7430
- }
7431
- else {
7432
- m = m + Math.pow(2, mLen);
7433
- e = e - eBias;
7434
- }
7435
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
7436
- }
7437
- exports.readIEEE754 = readIEEE754;
7438
6301
  function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
7439
6302
  var e;
7440
6303
  var m;
@@ -7501,30 +6364,9 @@ function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
7501
6364
  }
7502
6365
  buffer[offset + i - d] |= s * 128;
7503
6366
  }
7504
- exports.writeIEEE754 = writeIEEE754;
7505
-
7506
- });
7507
-
7508
- unwrapExports(float_parser);
7509
- var float_parser_1 = float_parser.writeIEEE754;
7510
- var float_parser_2 = float_parser.readIEEE754;
7511
-
7512
- var serializer = createCommonjsModule(function (module, exports) {
7513
- Object.defineProperty(exports, "__esModule", { value: true });
7514
- exports.serializeInto = void 0;
7515
-
7516
-
7517
-
7518
-
7519
-
7520
-
7521
-
7522
6367
 
7523
6368
  var regexp = /\x00/; // eslint-disable-line no-control-regex
7524
6369
  var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
7525
- function isRegExp(d) {
7526
- return Object.prototype.toString.call(d) === '[object RegExp]';
7527
- }
7528
6370
  /*
7529
6371
  * isArray indicates if we are writing to a BSON array (type 0x04)
7530
6372
  * which forces the "key" which really an array index as a string to be written as ascii
@@ -7532,7 +6374,7 @@ function isRegExp(d) {
7532
6374
  */
7533
6375
  function serializeString(buffer, key, value, index, isArray) {
7534
6376
  // Encode String type
7535
- buffer[index++] = constants.BSON_DATA_STRING;
6377
+ buffer[index++] = BSON_DATA_STRING;
7536
6378
  // Number of written bytes
7537
6379
  var numberOfWrittenBytes = !isArray
7538
6380
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7557,11 +6399,11 @@ function serializeNumber(buffer, key, value, index, isArray) {
7557
6399
  // We have an integer value
7558
6400
  // TODO(NODE-2529): Add support for big int
7559
6401
  if (Number.isInteger(value) &&
7560
- value >= constants.BSON_INT32_MIN &&
7561
- value <= constants.BSON_INT32_MAX) {
6402
+ value >= BSON_INT32_MIN &&
6403
+ value <= BSON_INT32_MAX) {
7562
6404
  // If the value fits in 32 bits encode as int32
7563
6405
  // Set int type 32 bits or less
7564
- buffer[index++] = constants.BSON_DATA_INT;
6406
+ buffer[index++] = BSON_DATA_INT;
7565
6407
  // Number of written bytes
7566
6408
  var numberOfWrittenBytes = !isArray
7567
6409
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7577,7 +6419,7 @@ function serializeNumber(buffer, key, value, index, isArray) {
7577
6419
  }
7578
6420
  else {
7579
6421
  // Encode as double
7580
- buffer[index++] = constants.BSON_DATA_NUMBER;
6422
+ buffer[index++] = BSON_DATA_NUMBER;
7581
6423
  // Number of written bytes
7582
6424
  var numberOfWrittenBytes = !isArray
7583
6425
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7586,7 +6428,7 @@ function serializeNumber(buffer, key, value, index, isArray) {
7586
6428
  index = index + numberOfWrittenBytes;
7587
6429
  buffer[index++] = 0;
7588
6430
  // Write float
7589
- float_parser.writeIEEE754(buffer, value, index, 'little', 52, 8);
6431
+ writeIEEE754(buffer, value, index, 'little', 52, 8);
7590
6432
  // Adjust index
7591
6433
  index = index + 8;
7592
6434
  }
@@ -7594,7 +6436,7 @@ function serializeNumber(buffer, key, value, index, isArray) {
7594
6436
  }
7595
6437
  function serializeNull(buffer, key, _, index, isArray) {
7596
6438
  // Set long type
7597
- buffer[index++] = constants.BSON_DATA_NULL;
6439
+ buffer[index++] = BSON_DATA_NULL;
7598
6440
  // Number of written bytes
7599
6441
  var numberOfWrittenBytes = !isArray
7600
6442
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7606,7 +6448,7 @@ function serializeNull(buffer, key, _, index, isArray) {
7606
6448
  }
7607
6449
  function serializeBoolean(buffer, key, value, index, isArray) {
7608
6450
  // Write the type
7609
- buffer[index++] = constants.BSON_DATA_BOOLEAN;
6451
+ buffer[index++] = BSON_DATA_BOOLEAN;
7610
6452
  // Number of written bytes
7611
6453
  var numberOfWrittenBytes = !isArray
7612
6454
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7620,7 +6462,7 @@ function serializeBoolean(buffer, key, value, index, isArray) {
7620
6462
  }
7621
6463
  function serializeDate(buffer, key, value, index, isArray) {
7622
6464
  // Write the type
7623
- buffer[index++] = constants.BSON_DATA_DATE;
6465
+ buffer[index++] = BSON_DATA_DATE;
7624
6466
  // Number of written bytes
7625
6467
  var numberOfWrittenBytes = !isArray
7626
6468
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7629,7 +6471,7 @@ function serializeDate(buffer, key, value, index, isArray) {
7629
6471
  index = index + numberOfWrittenBytes;
7630
6472
  buffer[index++] = 0;
7631
6473
  // Write the date
7632
- var dateInMilis = long_1.Long.fromNumber(value.getTime());
6474
+ var dateInMilis = Long.fromNumber(value.getTime());
7633
6475
  var lowBits = dateInMilis.getLowBits();
7634
6476
  var highBits = dateInMilis.getHighBits();
7635
6477
  // Encode low bits
@@ -7646,7 +6488,7 @@ function serializeDate(buffer, key, value, index, isArray) {
7646
6488
  }
7647
6489
  function serializeRegExp(buffer, key, value, index, isArray) {
7648
6490
  // Write the type
7649
- buffer[index++] = constants.BSON_DATA_REGEXP;
6491
+ buffer[index++] = BSON_DATA_REGEXP;
7650
6492
  // Number of written bytes
7651
6493
  var numberOfWrittenBytes = !isArray
7652
6494
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7674,7 +6516,7 @@ function serializeRegExp(buffer, key, value, index, isArray) {
7674
6516
  }
7675
6517
  function serializeBSONRegExp(buffer, key, value, index, isArray) {
7676
6518
  // Write the type
7677
- buffer[index++] = constants.BSON_DATA_REGEXP;
6519
+ buffer[index++] = BSON_DATA_REGEXP;
7678
6520
  // Number of written bytes
7679
6521
  var numberOfWrittenBytes = !isArray
7680
6522
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7701,13 +6543,13 @@ function serializeBSONRegExp(buffer, key, value, index, isArray) {
7701
6543
  function serializeMinMax(buffer, key, value, index, isArray) {
7702
6544
  // Write the type of either min or max key
7703
6545
  if (value === null) {
7704
- buffer[index++] = constants.BSON_DATA_NULL;
6546
+ buffer[index++] = BSON_DATA_NULL;
7705
6547
  }
7706
6548
  else if (value._bsontype === 'MinKey') {
7707
- buffer[index++] = constants.BSON_DATA_MIN_KEY;
6549
+ buffer[index++] = BSON_DATA_MIN_KEY;
7708
6550
  }
7709
6551
  else {
7710
- buffer[index++] = constants.BSON_DATA_MAX_KEY;
6552
+ buffer[index++] = BSON_DATA_MAX_KEY;
7711
6553
  }
7712
6554
  // Number of written bytes
7713
6555
  var numberOfWrittenBytes = !isArray
@@ -7720,7 +6562,7 @@ function serializeMinMax(buffer, key, value, index, isArray) {
7720
6562
  }
7721
6563
  function serializeObjectId(buffer, key, value, index, isArray) {
7722
6564
  // Write the type
7723
- buffer[index++] = constants.BSON_DATA_OID;
6565
+ buffer[index++] = BSON_DATA_OID;
7724
6566
  // Number of written bytes
7725
6567
  var numberOfWrittenBytes = !isArray
7726
6568
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7732,8 +6574,10 @@ function serializeObjectId(buffer, key, value, index, isArray) {
7732
6574
  if (typeof value.id === 'string') {
7733
6575
  buffer.write(value.id, index, undefined, 'binary');
7734
6576
  }
7735
- else if (value.id && value.id.copy) {
7736
- value.id.copy(buffer, index, 0, 12);
6577
+ else if (isUint8Array(value.id)) {
6578
+ // Use the standard JS methods here because buffer.copy() is buggy with the
6579
+ // browser polyfill
6580
+ buffer.set(value.id.subarray(0, 12), index);
7737
6581
  }
7738
6582
  else {
7739
6583
  throw new TypeError('object [' + JSON.stringify(value) + '] is not a valid ObjectId');
@@ -7743,7 +6587,7 @@ function serializeObjectId(buffer, key, value, index, isArray) {
7743
6587
  }
7744
6588
  function serializeBuffer(buffer, key, value, index, isArray) {
7745
6589
  // Write the type
7746
- buffer[index++] = constants.BSON_DATA_BINARY;
6590
+ buffer[index++] = BSON_DATA_BINARY;
7747
6591
  // Number of written bytes
7748
6592
  var numberOfWrittenBytes = !isArray
7749
6593
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7759,9 +6603,9 @@ function serializeBuffer(buffer, key, value, index, isArray) {
7759
6603
  buffer[index++] = (size >> 16) & 0xff;
7760
6604
  buffer[index++] = (size >> 24) & 0xff;
7761
6605
  // Write the default subtype
7762
- buffer[index++] = constants.BSON_BINARY_SUBTYPE_DEFAULT;
6606
+ buffer[index++] = BSON_BINARY_SUBTYPE_DEFAULT;
7763
6607
  // Copy the content form the binary field to the buffer
7764
- buffer.set(ensure_buffer.ensureBuffer(value), index);
6608
+ buffer.set(ensureBuffer(value), index);
7765
6609
  // Adjust the index
7766
6610
  index = index + size;
7767
6611
  return index;
@@ -7780,7 +6624,7 @@ function serializeObject(buffer, key, value, index, checkKeys, depth, serializeF
7780
6624
  // Push value to stack
7781
6625
  path.push(value);
7782
6626
  // Write the type
7783
- buffer[index++] = Array.isArray(value) ? constants.BSON_DATA_ARRAY : constants.BSON_DATA_OBJECT;
6627
+ buffer[index++] = Array.isArray(value) ? BSON_DATA_ARRAY : BSON_DATA_OBJECT;
7784
6628
  // Number of written bytes
7785
6629
  var numberOfWrittenBytes = !isArray
7786
6630
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7794,7 +6638,7 @@ function serializeObject(buffer, key, value, index, checkKeys, depth, serializeF
7794
6638
  return endIndex;
7795
6639
  }
7796
6640
  function serializeDecimal128(buffer, key, value, index, isArray) {
7797
- buffer[index++] = constants.BSON_DATA_DECIMAL128;
6641
+ buffer[index++] = BSON_DATA_DECIMAL128;
7798
6642
  // Number of written bytes
7799
6643
  var numberOfWrittenBytes = !isArray
7800
6644
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7803,13 +6647,15 @@ function serializeDecimal128(buffer, key, value, index, isArray) {
7803
6647
  index = index + numberOfWrittenBytes;
7804
6648
  buffer[index++] = 0;
7805
6649
  // Write the data from the value
7806
- value.bytes.copy(buffer, index, 0, 16);
6650
+ // Prefer the standard JS methods because their typechecking is not buggy,
6651
+ // unlike the `buffer` polyfill's.
6652
+ buffer.set(value.bytes.subarray(0, 16), index);
7807
6653
  return index + 16;
7808
6654
  }
7809
6655
  function serializeLong(buffer, key, value, index, isArray) {
7810
6656
  // Write the type
7811
6657
  buffer[index++] =
7812
- value._bsontype === 'Long' ? constants.BSON_DATA_LONG : constants.BSON_DATA_TIMESTAMP;
6658
+ value._bsontype === 'Long' ? BSON_DATA_LONG : BSON_DATA_TIMESTAMP;
7813
6659
  // Number of written bytes
7814
6660
  var numberOfWrittenBytes = !isArray
7815
6661
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7835,7 +6681,7 @@ function serializeLong(buffer, key, value, index, isArray) {
7835
6681
  function serializeInt32(buffer, key, value, index, isArray) {
7836
6682
  value = value.valueOf();
7837
6683
  // Set int type 32 bits or less
7838
- buffer[index++] = constants.BSON_DATA_INT;
6684
+ buffer[index++] = BSON_DATA_INT;
7839
6685
  // Number of written bytes
7840
6686
  var numberOfWrittenBytes = !isArray
7841
6687
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7852,7 +6698,7 @@ function serializeInt32(buffer, key, value, index, isArray) {
7852
6698
  }
7853
6699
  function serializeDouble(buffer, key, value, index, isArray) {
7854
6700
  // Encode as double
7855
- buffer[index++] = constants.BSON_DATA_NUMBER;
6701
+ buffer[index++] = BSON_DATA_NUMBER;
7856
6702
  // Number of written bytes
7857
6703
  var numberOfWrittenBytes = !isArray
7858
6704
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7861,13 +6707,13 @@ function serializeDouble(buffer, key, value, index, isArray) {
7861
6707
  index = index + numberOfWrittenBytes;
7862
6708
  buffer[index++] = 0;
7863
6709
  // Write float
7864
- float_parser.writeIEEE754(buffer, value.value, index, 'little', 52, 8);
6710
+ writeIEEE754(buffer, value.value, index, 'little', 52, 8);
7865
6711
  // Adjust index
7866
6712
  index = index + 8;
7867
6713
  return index;
7868
6714
  }
7869
6715
  function serializeFunction(buffer, key, value, index, _checkKeys, _depth, isArray) {
7870
- buffer[index++] = constants.BSON_DATA_CODE;
6716
+ buffer[index++] = BSON_DATA_CODE;
7871
6717
  // Number of written bytes
7872
6718
  var numberOfWrittenBytes = !isArray
7873
6719
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7876,7 +6722,7 @@ function serializeFunction(buffer, key, value, index, _checkKeys, _depth, isArra
7876
6722
  index = index + numberOfWrittenBytes;
7877
6723
  buffer[index++] = 0;
7878
6724
  // Function string
7879
- var functionString = utils.normalizedFunctionString(value);
6725
+ var functionString = normalizedFunctionString(value);
7880
6726
  // Write the string
7881
6727
  var size = buffer.write(functionString, index + 4, undefined, 'utf8') + 1;
7882
6728
  // Write the size of the string to buffer
@@ -7898,7 +6744,7 @@ function serializeCode(buffer, key, value, index, checkKeys, depth, serializeFun
7898
6744
  if (isArray === void 0) { isArray = false; }
7899
6745
  if (value.scope && typeof value.scope === 'object') {
7900
6746
  // Write the type
7901
- buffer[index++] = constants.BSON_DATA_CODE_W_SCOPE;
6747
+ buffer[index++] = BSON_DATA_CODE_W_SCOPE;
7902
6748
  // Number of written bytes
7903
6749
  var numberOfWrittenBytes = !isArray
7904
6750
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7939,7 +6785,7 @@ function serializeCode(buffer, key, value, index, checkKeys, depth, serializeFun
7939
6785
  buffer[index++] = 0;
7940
6786
  }
7941
6787
  else {
7942
- buffer[index++] = constants.BSON_DATA_CODE;
6788
+ buffer[index++] = BSON_DATA_CODE;
7943
6789
  // Number of written bytes
7944
6790
  var numberOfWrittenBytes = !isArray
7945
6791
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7965,7 +6811,7 @@ function serializeCode(buffer, key, value, index, checkKeys, depth, serializeFun
7965
6811
  }
7966
6812
  function serializeBinary(buffer, key, value, index, isArray) {
7967
6813
  // Write the type
7968
- buffer[index++] = constants.BSON_DATA_BINARY;
6814
+ buffer[index++] = BSON_DATA_BINARY;
7969
6815
  // Number of written bytes
7970
6816
  var numberOfWrittenBytes = !isArray
7971
6817
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7978,7 +6824,7 @@ function serializeBinary(buffer, key, value, index, isArray) {
7978
6824
  // Calculate size
7979
6825
  var size = value.position;
7980
6826
  // Add the deprecated 02 type 4 bytes of size to total
7981
- if (value.sub_type === binary.Binary.SUBTYPE_BYTE_ARRAY)
6827
+ if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY)
7982
6828
  size = size + 4;
7983
6829
  // Write the size of the string to buffer
7984
6830
  buffer[index++] = size & 0xff;
@@ -7988,7 +6834,7 @@ function serializeBinary(buffer, key, value, index, isArray) {
7988
6834
  // Write the subtype to the buffer
7989
6835
  buffer[index++] = value.sub_type;
7990
6836
  // If we have binary type 2 the 4 first bytes are the size
7991
- if (value.sub_type === binary.Binary.SUBTYPE_BYTE_ARRAY) {
6837
+ if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
7992
6838
  size = size - 4;
7993
6839
  buffer[index++] = size & 0xff;
7994
6840
  buffer[index++] = (size >> 8) & 0xff;
@@ -8003,7 +6849,7 @@ function serializeBinary(buffer, key, value, index, isArray) {
8003
6849
  }
8004
6850
  function serializeSymbol(buffer, key, value, index, isArray) {
8005
6851
  // Write the type
8006
- buffer[index++] = constants.BSON_DATA_SYMBOL;
6852
+ buffer[index++] = BSON_DATA_SYMBOL;
8007
6853
  // Number of written bytes
8008
6854
  var numberOfWrittenBytes = !isArray
8009
6855
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8026,7 +6872,7 @@ function serializeSymbol(buffer, key, value, index, isArray) {
8026
6872
  }
8027
6873
  function serializeDBRef(buffer, key, value, index, depth, serializeFunctions, isArray) {
8028
6874
  // Write the type
8029
- buffer[index++] = constants.BSON_DATA_OBJECT;
6875
+ buffer[index++] = BSON_DATA_OBJECT;
8030
6876
  // Number of written bytes
8031
6877
  var numberOfWrittenBytes = !isArray
8032
6878
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8091,7 +6937,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8091
6937
  else if (typeof value === 'boolean') {
8092
6938
  index = serializeBoolean(buffer, key, value, index, true);
8093
6939
  }
8094
- else if (value instanceof Date || utils.isDate(value)) {
6940
+ else if (value instanceof Date || isDate(value)) {
8095
6941
  index = serializeDate(buffer, key, value, index, true);
8096
6942
  }
8097
6943
  else if (value === undefined) {
@@ -8103,7 +6949,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8103
6949
  else if (value['_bsontype'] === 'ObjectId' || value['_bsontype'] === 'ObjectID') {
8104
6950
  index = serializeObjectId(buffer, key, value, index, true);
8105
6951
  }
8106
- else if (utils.isBuffer(value) || utils.isUint8Array(value)) {
6952
+ else if (isUint8Array(value)) {
8107
6953
  index = serializeBuffer(buffer, key, value, index, true);
8108
6954
  }
8109
6955
  else if (value instanceof RegExp || isRegExp(value)) {
@@ -8113,7 +6959,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8113
6959
  index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, true, path);
8114
6960
  }
8115
6961
  else if (typeof value === 'object' &&
8116
- extended_json.isBSONType(value) &&
6962
+ isBSONType(value) &&
8117
6963
  value._bsontype === 'Decimal128') {
8118
6964
  index = serializeDecimal128(buffer, key, value, index, true);
8119
6965
  }
@@ -8152,7 +6998,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8152
6998
  }
8153
6999
  }
8154
7000
  }
8155
- else if (object instanceof map.Map) {
7001
+ else if (object instanceof bsonMap || isMap(object)) {
8156
7002
  var iterator = object.entries();
8157
7003
  var done = false;
8158
7004
  while (!done) {
@@ -8189,13 +7035,13 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8189
7035
  else if (type === 'number') {
8190
7036
  index = serializeNumber(buffer, key, value, index);
8191
7037
  }
8192
- else if (type === 'bigint' || utils.isBigInt64Array(value) || utils.isBigUInt64Array(value)) {
7038
+ else if (type === 'bigint' || isBigInt64Array(value) || isBigUInt64Array(value)) {
8193
7039
  throw new TypeError('Unsupported type BigInt, please use Decimal128');
8194
7040
  }
8195
7041
  else if (type === 'boolean') {
8196
7042
  index = serializeBoolean(buffer, key, value, index);
8197
7043
  }
8198
- else if (value instanceof Date || utils.isDate(value)) {
7044
+ else if (value instanceof Date || isDate(value)) {
8199
7045
  index = serializeDate(buffer, key, value, index);
8200
7046
  }
8201
7047
  else if (value === null || (value === undefined && ignoreUndefined === false)) {
@@ -8204,7 +7050,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8204
7050
  else if (value['_bsontype'] === 'ObjectId' || value['_bsontype'] === 'ObjectID') {
8205
7051
  index = serializeObjectId(buffer, key, value, index);
8206
7052
  }
8207
- else if (utils.isBuffer(value) || utils.isUint8Array(value)) {
7053
+ else if (isUint8Array(value)) {
8208
7054
  index = serializeBuffer(buffer, key, value, index);
8209
7055
  }
8210
7056
  else if (value instanceof RegExp || isRegExp(value)) {
@@ -8299,7 +7145,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8299
7145
  else if (type === 'boolean') {
8300
7146
  index = serializeBoolean(buffer, key, value, index);
8301
7147
  }
8302
- else if (value instanceof Date || utils.isDate(value)) {
7148
+ else if (value instanceof Date || isDate(value)) {
8303
7149
  index = serializeDate(buffer, key, value, index);
8304
7150
  }
8305
7151
  else if (value === undefined) {
@@ -8312,7 +7158,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8312
7158
  else if (value['_bsontype'] === 'ObjectId' || value['_bsontype'] === 'ObjectID') {
8313
7159
  index = serializeObjectId(buffer, key, value, index);
8314
7160
  }
8315
- else if (utils.isBuffer(value) || utils.isUint8Array(value)) {
7161
+ else if (isUint8Array(value)) {
8316
7162
  index = serializeBuffer(buffer, key, value, index);
8317
7163
  }
8318
7164
  else if (value instanceof RegExp || isRegExp(value)) {
@@ -8372,94 +7218,12 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8372
7218
  buffer[startingIndex++] = (size >> 24) & 0xff;
8373
7219
  return index;
8374
7220
  }
8375
- exports.serializeInto = serializeInto;
8376
-
8377
- });
8378
-
8379
- unwrapExports(serializer);
8380
- var serializer_1 = serializer.serializeInto;
8381
-
8382
- var bson = createCommonjsModule(function (module, exports) {
8383
- Object.defineProperty(exports, "__esModule", { value: true });
8384
- exports.deserializeStream = exports.calculateObjectSize = exports.deserialize = exports.serializeWithBufferAndIndex = exports.serialize = exports.setInternalBufferSize = exports.ObjectID = exports.Decimal128 = exports.BSONRegExp = exports.MaxKey = exports.MinKey = exports.Int32 = exports.Double = exports.Timestamp = exports.Long = exports.ObjectId = exports.Binary = exports.DBRef = exports.BSONSymbol = exports.Map = exports.Code = exports.LongWithoutOverridesClass = exports.EJSON = exports.BSON_INT64_MIN = exports.BSON_INT64_MAX = exports.BSON_INT32_MIN = exports.BSON_INT32_MAX = exports.BSON_DATA_UNDEFINED = exports.BSON_DATA_TIMESTAMP = exports.BSON_DATA_SYMBOL = exports.BSON_DATA_STRING = exports.BSON_DATA_REGEXP = exports.BSON_DATA_OID = exports.BSON_DATA_OBJECT = exports.BSON_DATA_NUMBER = exports.BSON_DATA_NULL = exports.BSON_DATA_MIN_KEY = exports.BSON_DATA_MAX_KEY = exports.BSON_DATA_LONG = exports.BSON_DATA_INT = exports.BSON_DATA_DECIMAL128 = exports.BSON_DATA_DBPOINTER = exports.BSON_DATA_DATE = exports.BSON_DATA_CODE_W_SCOPE = exports.BSON_DATA_CODE = exports.BSON_DATA_BOOLEAN = exports.BSON_DATA_BINARY = exports.BSON_DATA_ARRAY = exports.BSON_BINARY_SUBTYPE_UUID_NEW = exports.BSON_BINARY_SUBTYPE_UUID = exports.BSON_BINARY_SUBTYPE_USER_DEFINED = exports.BSON_BINARY_SUBTYPE_MD5 = exports.BSON_BINARY_SUBTYPE_FUNCTION = exports.BSON_BINARY_SUBTYPE_DEFAULT = exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = void 0;
8385
-
8386
-
8387
- Object.defineProperty(exports, "Binary", { enumerable: true, get: function () { return binary.Binary; } });
8388
-
8389
- Object.defineProperty(exports, "Code", { enumerable: true, get: function () { return code$1.Code; } });
8390
-
8391
- Object.defineProperty(exports, "DBRef", { enumerable: true, get: function () { return db_ref.DBRef; } });
8392
-
8393
- Object.defineProperty(exports, "Decimal128", { enumerable: true, get: function () { return decimal128.Decimal128; } });
8394
-
8395
- Object.defineProperty(exports, "Double", { enumerable: true, get: function () { return double_1.Double; } });
8396
7221
 
8397
-
8398
-
8399
- Object.defineProperty(exports, "Int32", { enumerable: true, get: function () { return int_32.Int32; } });
8400
-
8401
- Object.defineProperty(exports, "Long", { enumerable: true, get: function () { return long_1.Long; } });
8402
-
8403
- Object.defineProperty(exports, "Map", { enumerable: true, get: function () { return map.Map; } });
8404
-
8405
- Object.defineProperty(exports, "MaxKey", { enumerable: true, get: function () { return max_key.MaxKey; } });
8406
-
8407
- Object.defineProperty(exports, "MinKey", { enumerable: true, get: function () { return min_key.MinKey; } });
8408
-
8409
- Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return objectid.ObjectId; } });
8410
- Object.defineProperty(exports, "ObjectID", { enumerable: true, get: function () { return objectid.ObjectId; } });
8411
-
8412
- // Parts of the parser
8413
-
8414
-
8415
-
8416
- Object.defineProperty(exports, "BSONRegExp", { enumerable: true, get: function () { return regexp.BSONRegExp; } });
8417
-
8418
- Object.defineProperty(exports, "BSONSymbol", { enumerable: true, get: function () { return symbol.BSONSymbol; } });
8419
-
8420
- Object.defineProperty(exports, "Timestamp", { enumerable: true, get: function () { return timestamp$1.Timestamp; } });
8421
-
8422
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_BYTE_ARRAY", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_BYTE_ARRAY; } });
8423
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_DEFAULT", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_DEFAULT; } });
8424
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_FUNCTION", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_FUNCTION; } });
8425
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_MD5", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_MD5; } });
8426
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_USER_DEFINED", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_USER_DEFINED; } });
8427
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_UUID", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_UUID; } });
8428
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_UUID_NEW", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_UUID_NEW; } });
8429
- Object.defineProperty(exports, "BSON_DATA_ARRAY", { enumerable: true, get: function () { return constants.BSON_DATA_ARRAY; } });
8430
- Object.defineProperty(exports, "BSON_DATA_BINARY", { enumerable: true, get: function () { return constants.BSON_DATA_BINARY; } });
8431
- Object.defineProperty(exports, "BSON_DATA_BOOLEAN", { enumerable: true, get: function () { return constants.BSON_DATA_BOOLEAN; } });
8432
- Object.defineProperty(exports, "BSON_DATA_CODE", { enumerable: true, get: function () { return constants.BSON_DATA_CODE; } });
8433
- Object.defineProperty(exports, "BSON_DATA_CODE_W_SCOPE", { enumerable: true, get: function () { return constants.BSON_DATA_CODE_W_SCOPE; } });
8434
- Object.defineProperty(exports, "BSON_DATA_DATE", { enumerable: true, get: function () { return constants.BSON_DATA_DATE; } });
8435
- Object.defineProperty(exports, "BSON_DATA_DBPOINTER", { enumerable: true, get: function () { return constants.BSON_DATA_DBPOINTER; } });
8436
- Object.defineProperty(exports, "BSON_DATA_DECIMAL128", { enumerable: true, get: function () { return constants.BSON_DATA_DECIMAL128; } });
8437
- Object.defineProperty(exports, "BSON_DATA_INT", { enumerable: true, get: function () { return constants.BSON_DATA_INT; } });
8438
- Object.defineProperty(exports, "BSON_DATA_LONG", { enumerable: true, get: function () { return constants.BSON_DATA_LONG; } });
8439
- Object.defineProperty(exports, "BSON_DATA_MAX_KEY", { enumerable: true, get: function () { return constants.BSON_DATA_MAX_KEY; } });
8440
- Object.defineProperty(exports, "BSON_DATA_MIN_KEY", { enumerable: true, get: function () { return constants.BSON_DATA_MIN_KEY; } });
8441
- Object.defineProperty(exports, "BSON_DATA_NULL", { enumerable: true, get: function () { return constants.BSON_DATA_NULL; } });
8442
- Object.defineProperty(exports, "BSON_DATA_NUMBER", { enumerable: true, get: function () { return constants.BSON_DATA_NUMBER; } });
8443
- Object.defineProperty(exports, "BSON_DATA_OBJECT", { enumerable: true, get: function () { return constants.BSON_DATA_OBJECT; } });
8444
- Object.defineProperty(exports, "BSON_DATA_OID", { enumerable: true, get: function () { return constants.BSON_DATA_OID; } });
8445
- Object.defineProperty(exports, "BSON_DATA_REGEXP", { enumerable: true, get: function () { return constants.BSON_DATA_REGEXP; } });
8446
- Object.defineProperty(exports, "BSON_DATA_STRING", { enumerable: true, get: function () { return constants.BSON_DATA_STRING; } });
8447
- Object.defineProperty(exports, "BSON_DATA_SYMBOL", { enumerable: true, get: function () { return constants.BSON_DATA_SYMBOL; } });
8448
- Object.defineProperty(exports, "BSON_DATA_TIMESTAMP", { enumerable: true, get: function () { return constants.BSON_DATA_TIMESTAMP; } });
8449
- Object.defineProperty(exports, "BSON_DATA_UNDEFINED", { enumerable: true, get: function () { return constants.BSON_DATA_UNDEFINED; } });
8450
- Object.defineProperty(exports, "BSON_INT32_MAX", { enumerable: true, get: function () { return constants.BSON_INT32_MAX; } });
8451
- Object.defineProperty(exports, "BSON_INT32_MIN", { enumerable: true, get: function () { return constants.BSON_INT32_MIN; } });
8452
- Object.defineProperty(exports, "BSON_INT64_MAX", { enumerable: true, get: function () { return constants.BSON_INT64_MAX; } });
8453
- Object.defineProperty(exports, "BSON_INT64_MIN", { enumerable: true, get: function () { return constants.BSON_INT64_MIN; } });
8454
- var extended_json_2 = extended_json;
8455
- Object.defineProperty(exports, "EJSON", { enumerable: true, get: function () { return extended_json_2.EJSON; } });
8456
- var timestamp_2 = timestamp$1;
8457
- Object.defineProperty(exports, "LongWithoutOverridesClass", { enumerable: true, get: function () { return timestamp_2.LongWithoutOverridesClass; } });
8458
7222
  /** @internal */
8459
7223
  // Default Max Size
8460
7224
  var MAXSIZE = 1024 * 1024 * 17;
8461
7225
  // Current Internal Temporary Serialization Buffer
8462
- var buffer$1 = buffer.Buffer.alloc(MAXSIZE);
7226
+ var buffer = buffer_1.alloc(MAXSIZE);
8463
7227
  /**
8464
7228
  * Sets the size of the internal serialization buffer.
8465
7229
  *
@@ -8468,11 +7232,10 @@ var buffer$1 = buffer.Buffer.alloc(MAXSIZE);
8468
7232
  */
8469
7233
  function setInternalBufferSize(size) {
8470
7234
  // Resize the internal serialization buffer if needed
8471
- if (buffer$1.length < size) {
8472
- buffer$1 = buffer.Buffer.alloc(size);
7235
+ if (buffer.length < size) {
7236
+ buffer = buffer_1.alloc(size);
8473
7237
  }
8474
7238
  }
8475
- exports.setInternalBufferSize = setInternalBufferSize;
8476
7239
  /**
8477
7240
  * Serialize a Javascript object.
8478
7241
  *
@@ -8488,19 +7251,18 @@ function serialize(object, options) {
8488
7251
  var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
8489
7252
  var minInternalBufferSize = typeof options.minInternalBufferSize === 'number' ? options.minInternalBufferSize : MAXSIZE;
8490
7253
  // Resize the internal serialization buffer if needed
8491
- if (buffer$1.length < minInternalBufferSize) {
8492
- buffer$1 = buffer.Buffer.alloc(minInternalBufferSize);
7254
+ if (buffer.length < minInternalBufferSize) {
7255
+ buffer = buffer_1.alloc(minInternalBufferSize);
8493
7256
  }
8494
7257
  // Attempt to serialize
8495
- var serializationIndex = serializer.serializeInto(buffer$1, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined, []);
7258
+ var serializationIndex = serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined, []);
8496
7259
  // Create the final buffer
8497
- var finishedBuffer = buffer.Buffer.alloc(serializationIndex);
7260
+ var finishedBuffer = buffer_1.alloc(serializationIndex);
8498
7261
  // Copy into the finished buffer
8499
- buffer$1.copy(finishedBuffer, 0, 0, finishedBuffer.length);
7262
+ buffer.copy(finishedBuffer, 0, 0, finishedBuffer.length);
8500
7263
  // Return the buffer
8501
7264
  return finishedBuffer;
8502
7265
  }
8503
- exports.serialize = serialize;
8504
7266
  /**
8505
7267
  * Serialize a Javascript object using a predefined Buffer and index into the buffer,
8506
7268
  * useful when pre-allocating the space for serialization.
@@ -8518,12 +7280,11 @@ function serializeWithBufferAndIndex(object, finalBuffer, options) {
8518
7280
  var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
8519
7281
  var startIndex = typeof options.index === 'number' ? options.index : 0;
8520
7282
  // Attempt to serialize
8521
- var serializationIndex = serializer.serializeInto(buffer$1, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined);
8522
- buffer$1.copy(finalBuffer, startIndex, 0, serializationIndex);
7283
+ var serializationIndex = serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined);
7284
+ buffer.copy(finalBuffer, startIndex, 0, serializationIndex);
8523
7285
  // Return the index
8524
7286
  return startIndex + serializationIndex - 1;
8525
7287
  }
8526
- exports.serializeWithBufferAndIndex = serializeWithBufferAndIndex;
8527
7288
  /**
8528
7289
  * Deserialize data as BSON.
8529
7290
  *
@@ -8533,9 +7294,8 @@ exports.serializeWithBufferAndIndex = serializeWithBufferAndIndex;
8533
7294
  */
8534
7295
  function deserialize(buffer, options) {
8535
7296
  if (options === void 0) { options = {}; }
8536
- return deserializer.deserialize(ensure_buffer.ensureBuffer(buffer), options);
7297
+ return deserialize$1(buffer instanceof buffer_1 ? buffer : ensureBuffer(buffer), options);
8537
7298
  }
8538
- exports.deserialize = deserialize;
8539
7299
  /**
8540
7300
  * Calculate the bson size for a passed in Javascript object.
8541
7301
  *
@@ -8548,9 +7308,8 @@ function calculateObjectSize(object, options) {
8548
7308
  options = options || {};
8549
7309
  var serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
8550
7310
  var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
8551
- return calculate_size.calculateObjectSize(object, serializeFunctions, ignoreUndefined);
7311
+ return calculateObjectSize$1(object, serializeFunctions, ignoreUndefined);
8552
7312
  }
8553
- exports.calculateObjectSize = calculateObjectSize;
8554
7313
  /**
8555
7314
  * Deserialize stream data as BSON documents.
8556
7315
  *
@@ -8565,7 +7324,7 @@ exports.calculateObjectSize = calculateObjectSize;
8565
7324
  */
8566
7325
  function deserializeStream(data, startIndex, numberOfDocuments, documents, docStartIndex, options) {
8567
7326
  var internalOptions = Object.assign({ allowObjectSmallerThanBufferSize: true, index: 0 }, options);
8568
- var bufferData = ensure_buffer.ensureBuffer(data);
7327
+ var bufferData = ensureBuffer(data);
8569
7328
  var index = startIndex;
8570
7329
  // Loop over all documents
8571
7330
  for (var i = 0; i < numberOfDocuments; i++) {
@@ -8577,14 +7336,13 @@ function deserializeStream(data, startIndex, numberOfDocuments, documents, docSt
8577
7336
  // Update options with index
8578
7337
  internalOptions.index = index;
8579
7338
  // Parse the document at this point
8580
- documents[docStartIndex + i] = deserializer.deserialize(bufferData, internalOptions);
7339
+ documents[docStartIndex + i] = deserialize$1(bufferData, internalOptions);
8581
7340
  // Adjust index by the document size
8582
7341
  index = index + size;
8583
7342
  }
8584
7343
  // Return object containing end index of parsing and list of documents
8585
7344
  return index;
8586
7345
  }
8587
- exports.deserializeStream = deserializeStream;
8588
7346
  /**
8589
7347
  * BSON default export
8590
7348
  * @deprecated Please use named exports
@@ -8594,22 +7352,23 @@ exports.deserializeStream = deserializeStream;
8594
7352
  * @public
8595
7353
  */
8596
7354
  var BSON = {
8597
- Binary: binary.Binary,
8598
- Code: code$1.Code,
8599
- DBRef: db_ref.DBRef,
8600
- Decimal128: decimal128.Decimal128,
8601
- Double: double_1.Double,
8602
- Int32: int_32.Int32,
8603
- Long: long_1.Long,
8604
- Map: map.Map,
8605
- MaxKey: max_key.MaxKey,
8606
- MinKey: min_key.MinKey,
8607
- ObjectId: objectid.ObjectId,
8608
- ObjectID: objectid.ObjectId,
8609
- BSONRegExp: regexp.BSONRegExp,
8610
- BSONSymbol: symbol.BSONSymbol,
8611
- Timestamp: timestamp$1.Timestamp,
8612
- EJSON: extended_json.EJSON,
7355
+ Binary: Binary,
7356
+ Code: Code,
7357
+ DBRef: DBRef,
7358
+ Decimal128: Decimal128,
7359
+ Double: Double,
7360
+ Int32: Int32,
7361
+ Long: Long,
7362
+ UUID: UUID,
7363
+ Map: bsonMap,
7364
+ MaxKey: MaxKey,
7365
+ MinKey: MinKey,
7366
+ ObjectId: ObjectId,
7367
+ ObjectID: ObjectId,
7368
+ BSONRegExp: BSONRegExp,
7369
+ BSONSymbol: BSONSymbol,
7370
+ Timestamp: Timestamp,
7371
+ EJSON: EJSON,
8613
7372
  setInternalBufferSize: setInternalBufferSize,
8614
7373
  serialize: serialize,
8615
7374
  serializeWithBufferAndIndex: serializeWithBufferAndIndex,
@@ -8617,67 +7376,7 @@ var BSON = {
8617
7376
  calculateObjectSize: calculateObjectSize,
8618
7377
  deserializeStream: deserializeStream
8619
7378
  };
8620
- exports.default = BSON;
8621
-
8622
- });
8623
7379
 
8624
- var bson$1 = unwrapExports(bson);
8625
- var bson_1 = bson.deserializeStream;
8626
- var bson_2 = bson.calculateObjectSize;
8627
- var bson_3 = bson.deserialize;
8628
- var bson_4 = bson.serializeWithBufferAndIndex;
8629
- var bson_5 = bson.serialize;
8630
- var bson_6 = bson.setInternalBufferSize;
8631
- var bson_7 = bson.ObjectID;
8632
- var bson_8 = bson.Decimal128;
8633
- var bson_9 = bson.BSONRegExp;
8634
- var bson_10 = bson.MaxKey;
8635
- var bson_11 = bson.MinKey;
8636
- var bson_12 = bson.Int32;
8637
- var bson_13 = bson.Double;
8638
- var bson_14 = bson.Timestamp;
8639
- var bson_15 = bson.Long;
8640
- var bson_16 = bson.ObjectId;
8641
- var bson_17 = bson.Binary;
8642
- var bson_18 = bson.DBRef;
8643
- var bson_19 = bson.BSONSymbol;
8644
- var bson_20 = bson.Map;
8645
- var bson_21 = bson.Code;
8646
- var bson_22 = bson.LongWithoutOverridesClass;
8647
- var bson_23 = bson.EJSON;
8648
- var bson_24 = bson.BSON_INT64_MIN;
8649
- var bson_25 = bson.BSON_INT64_MAX;
8650
- var bson_26 = bson.BSON_INT32_MIN;
8651
- var bson_27 = bson.BSON_INT32_MAX;
8652
- var bson_28 = bson.BSON_DATA_UNDEFINED;
8653
- var bson_29 = bson.BSON_DATA_TIMESTAMP;
8654
- var bson_30 = bson.BSON_DATA_SYMBOL;
8655
- var bson_31 = bson.BSON_DATA_STRING;
8656
- var bson_32 = bson.BSON_DATA_REGEXP;
8657
- var bson_33 = bson.BSON_DATA_OID;
8658
- var bson_34 = bson.BSON_DATA_OBJECT;
8659
- var bson_35 = bson.BSON_DATA_NUMBER;
8660
- var bson_36 = bson.BSON_DATA_NULL;
8661
- var bson_37 = bson.BSON_DATA_MIN_KEY;
8662
- var bson_38 = bson.BSON_DATA_MAX_KEY;
8663
- var bson_39 = bson.BSON_DATA_LONG;
8664
- var bson_40 = bson.BSON_DATA_INT;
8665
- var bson_41 = bson.BSON_DATA_DECIMAL128;
8666
- var bson_42 = bson.BSON_DATA_DBPOINTER;
8667
- var bson_43 = bson.BSON_DATA_DATE;
8668
- var bson_44 = bson.BSON_DATA_CODE_W_SCOPE;
8669
- var bson_45 = bson.BSON_DATA_CODE;
8670
- var bson_46 = bson.BSON_DATA_BOOLEAN;
8671
- var bson_47 = bson.BSON_DATA_BINARY;
8672
- var bson_48 = bson.BSON_DATA_ARRAY;
8673
- var bson_49 = bson.BSON_BINARY_SUBTYPE_UUID_NEW;
8674
- var bson_50 = bson.BSON_BINARY_SUBTYPE_UUID;
8675
- var bson_51 = bson.BSON_BINARY_SUBTYPE_USER_DEFINED;
8676
- var bson_52 = bson.BSON_BINARY_SUBTYPE_MD5;
8677
- var bson_53 = bson.BSON_BINARY_SUBTYPE_FUNCTION;
8678
- var bson_54 = bson.BSON_BINARY_SUBTYPE_DEFAULT;
8679
- var bson_55 = bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY;
8680
-
8681
- export default bson$1;
8682
- export { bson_9 as BSONRegExp, bson_19 as BSONSymbol, bson_55 as BSON_BINARY_SUBTYPE_BYTE_ARRAY, bson_54 as BSON_BINARY_SUBTYPE_DEFAULT, bson_53 as BSON_BINARY_SUBTYPE_FUNCTION, bson_52 as BSON_BINARY_SUBTYPE_MD5, bson_51 as BSON_BINARY_SUBTYPE_USER_DEFINED, bson_50 as BSON_BINARY_SUBTYPE_UUID, bson_49 as BSON_BINARY_SUBTYPE_UUID_NEW, bson_48 as BSON_DATA_ARRAY, bson_47 as BSON_DATA_BINARY, bson_46 as BSON_DATA_BOOLEAN, bson_45 as BSON_DATA_CODE, bson_44 as BSON_DATA_CODE_W_SCOPE, bson_43 as BSON_DATA_DATE, bson_42 as BSON_DATA_DBPOINTER, bson_41 as BSON_DATA_DECIMAL128, bson_40 as BSON_DATA_INT, bson_39 as BSON_DATA_LONG, bson_38 as BSON_DATA_MAX_KEY, bson_37 as BSON_DATA_MIN_KEY, bson_36 as BSON_DATA_NULL, bson_35 as BSON_DATA_NUMBER, bson_34 as BSON_DATA_OBJECT, bson_33 as BSON_DATA_OID, bson_32 as BSON_DATA_REGEXP, bson_31 as BSON_DATA_STRING, bson_30 as BSON_DATA_SYMBOL, bson_29 as BSON_DATA_TIMESTAMP, bson_28 as BSON_DATA_UNDEFINED, bson_27 as BSON_INT32_MAX, bson_26 as BSON_INT32_MIN, bson_25 as BSON_INT64_MAX, bson_24 as BSON_INT64_MIN, bson_17 as Binary, bson_21 as Code, bson_18 as DBRef, bson_8 as Decimal128, bson_13 as Double, bson_23 as EJSON, bson_12 as Int32, bson_15 as Long, bson_22 as LongWithoutOverridesClass, bson_20 as Map, bson_10 as MaxKey, bson_11 as MinKey, bson_7 as ObjectID, bson_16 as ObjectId, bson_14 as Timestamp, bson_2 as calculateObjectSize, bson_3 as deserialize, bson_1 as deserializeStream, bson_5 as serialize, bson_4 as serializeWithBufferAndIndex, bson_6 as setInternalBufferSize };
7380
+ export default BSON;
7381
+ export { BSONRegExp, BSONSymbol, BSON_BINARY_SUBTYPE_BYTE_ARRAY, BSON_BINARY_SUBTYPE_DEFAULT, 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 };
8683
7382
  //# sourceMappingURL=bson.browser.esm.js.map