bson 4.4.0 → 4.5.2

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 (70) hide show
  1. package/bower.json +1 -1
  2. package/bson.d.ts +42 -14
  3. package/dist/bson.browser.esm.js +628 -2199
  4. package/dist/bson.browser.esm.js.map +1 -1
  5. package/dist/bson.browser.umd.js +681 -2254
  6. package/dist/bson.browser.umd.js.map +1 -1
  7. package/dist/bson.bundle.js +681 -2254
  8. package/dist/bson.bundle.js.map +1 -1
  9. package/dist/bson.esm.js +622 -2197
  10. package/dist/bson.esm.js.map +1 -1
  11. package/lib/binary.js +0 -3
  12. package/lib/binary.js.map +1 -1
  13. package/lib/bson.js +1 -1
  14. package/lib/bson.js.map +1 -1
  15. package/lib/code.js +0 -1
  16. package/lib/code.js.map +1 -1
  17. package/lib/db_ref.js +4 -2
  18. package/lib/db_ref.js.map +1 -1
  19. package/lib/decimal128.js +4 -49
  20. package/lib/decimal128.js.map +1 -1
  21. package/lib/double.js +3 -1
  22. package/lib/double.js.map +1 -1
  23. package/lib/extended_json.js +3 -3
  24. package/lib/extended_json.js.map +1 -1
  25. package/lib/int_32.js +3 -1
  26. package/lib/int_32.js.map +1 -1
  27. package/lib/long.js.map +1 -1
  28. package/lib/map.js +3 -15
  29. package/lib/map.js.map +1 -1
  30. package/lib/objectid.js +1 -5
  31. package/lib/objectid.js.map +1 -1
  32. package/lib/parser/deserializer.js +15 -12
  33. package/lib/parser/deserializer.js.map +1 -1
  34. package/lib/parser/serializer.js +7 -3
  35. package/lib/parser/serializer.js.map +1 -1
  36. package/lib/parser/utils.js +8 -8
  37. package/lib/parser/utils.js.map +1 -1
  38. package/lib/regexp.js +1 -3
  39. package/lib/regexp.js.map +1 -1
  40. package/lib/symbol.js +0 -2
  41. package/lib/symbol.js.map +1 -1
  42. package/lib/timestamp.js +6 -2
  43. package/lib/timestamp.js.map +1 -1
  44. package/lib/utils/global.js +18 -0
  45. package/lib/utils/global.js.map +1 -0
  46. package/lib/uuid.js +2 -3
  47. package/lib/uuid.js.map +1 -1
  48. package/lib/uuid_utils.js.map +1 -1
  49. package/package.json +22 -9
  50. package/src/binary.ts +1 -4
  51. package/src/bson.ts +1 -1
  52. package/src/code.ts +0 -1
  53. package/src/db_ref.ts +6 -2
  54. package/src/decimal128.ts +4 -49
  55. package/src/double.ts +4 -1
  56. package/src/extended_json.ts +6 -6
  57. package/src/int_32.ts +4 -1
  58. package/src/long.ts +2 -2
  59. package/src/map.ts +5 -25
  60. package/src/objectid.ts +1 -5
  61. package/src/parser/deserializer.ts +23 -16
  62. package/src/parser/serializer.ts +7 -3
  63. package/src/parser/utils.ts +9 -11
  64. package/src/regexp.ts +2 -4
  65. package/src/symbol.ts +0 -2
  66. package/src/timestamp.ts +15 -7
  67. package/src/utils/global.ts +22 -0
  68. package/src/uuid.ts +2 -3
  69. package/src/uuid_utils.ts +2 -1
  70. package/HISTORY.md +0 -505
@@ -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
  }
@@ -14,11 +8,11 @@ var fromByteArray_1 = fromByteArray;
14
8
  var lookup = [];
15
9
  var revLookup = [];
16
10
  var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
17
- var code$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
11
+ var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
18
12
 
19
- for (var i = 0, len = code$1.length; i < len; ++i) {
20
- lookup[i] = code$1[i];
21
- revLookup[code$1.charCodeAt(i)] = i;
13
+ for (var i = 0, len = code.length; i < len; ++i) {
14
+ lookup[i] = code[i];
15
+ revLookup[code.charCodeAt(i)] = i;
22
16
  } // Support decoding URL-safe base64 strings, as Node.js does.
23
17
  // See: https://en.wikipedia.org/wiki/Base64#URL_applications
24
18
 
@@ -227,7 +221,7 @@ var ieee754 = {
227
221
  write: write
228
222
  };
229
223
 
230
- var buffer = createCommonjsModule(function (module, exports) {
224
+ var buffer$1 = createCommonjsModule(function (module, exports) {
231
225
 
232
226
  var customInspectSymbol = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' ? // eslint-disable-line dot-notation
233
227
  Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
@@ -2032,569 +2026,25 @@ var buffer = createCommonjsModule(function (module, exports) {
2032
2026
  return table;
2033
2027
  }();
2034
2028
  });
2035
- buffer.Buffer;
2036
- buffer.SlowBuffer;
2037
- buffer.INSPECT_MAX_BYTES;
2038
- buffer.kMaxLength;
2039
-
2040
- var require$$0 = {};
2041
-
2042
- var inherits;
2043
-
2044
- if (typeof Object.create === 'function') {
2045
- inherits = function inherits(ctor, superCtor) {
2046
- // implementation from standard node.js 'util' module
2047
- ctor.super_ = superCtor;
2048
- ctor.prototype = Object.create(superCtor.prototype, {
2049
- constructor: {
2050
- value: ctor,
2051
- enumerable: false,
2052
- writable: true,
2053
- configurable: true
2054
- }
2055
- });
2056
- };
2057
- } else {
2058
- inherits = function inherits(ctor, superCtor) {
2059
- ctor.super_ = superCtor;
2060
-
2061
- var TempCtor = function TempCtor() {};
2062
-
2063
- TempCtor.prototype = superCtor.prototype;
2064
- ctor.prototype = new TempCtor();
2065
- ctor.prototype.constructor = ctor;
2066
- };
2067
- }
2068
-
2069
- var inherits$1 = inherits;
2070
-
2071
- // Copyright Joyent, Inc. and other Node contributors.
2072
- var formatRegExp = /%[sdj%]/g;
2073
- function format(f) {
2074
- if (!isString(f)) {
2075
- var objects = [];
2076
-
2077
- for (var i = 0; i < arguments.length; i++) {
2078
- objects.push(inspect(arguments[i]));
2079
- }
2080
-
2081
- return objects.join(' ');
2082
- }
2083
-
2084
- var i = 1;
2085
- var args = arguments;
2086
- var len = args.length;
2087
- var str = String(f).replace(formatRegExp, function (x) {
2088
- if (x === '%%') return '%';
2089
- if (i >= len) return x;
2090
-
2091
- switch (x) {
2092
- case '%s':
2093
- return String(args[i++]);
2094
-
2095
- case '%d':
2096
- return Number(args[i++]);
2097
-
2098
- case '%j':
2099
- try {
2100
- return JSON.stringify(args[i++]);
2101
- } catch (_) {
2102
- return '[Circular]';
2103
- }
2104
-
2105
- default:
2106
- return x;
2107
- }
2108
- });
2109
-
2110
- for (var x = args[i]; i < len; x = args[++i]) {
2111
- if (isNull(x) || !isObject(x)) {
2112
- str += ' ' + x;
2113
- } else {
2114
- str += ' ' + inspect(x);
2115
- }
2116
- }
2117
-
2118
- return str;
2119
- }
2120
- // Returns a modified function which warns once by default.
2121
- // If --no-deprecation is set, then it is a no-op.
2122
-
2123
- function deprecate(fn, msg) {
2124
- // Allow for deprecating things in the process of starting up.
2125
- if (isUndefined(global.process)) {
2126
- return function () {
2127
- return deprecate(fn, msg).apply(this, arguments);
2128
- };
2129
- }
2130
-
2131
- var warned = false;
2132
-
2133
- function deprecated() {
2134
- if (!warned) {
2135
- {
2136
- console.error(msg);
2137
- }
2138
-
2139
- warned = true;
2140
- }
2141
-
2142
- return fn.apply(this, arguments);
2143
- }
2144
-
2145
- return deprecated;
2146
- }
2147
- var debugs = {};
2148
- var debugEnviron;
2149
- function debuglog(set) {
2150
- if (isUndefined(debugEnviron)) debugEnviron = '';
2151
- set = set.toUpperCase();
2152
-
2153
- if (!debugs[set]) {
2154
- if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
2155
- var pid = 0;
2156
-
2157
- debugs[set] = function () {
2158
- var msg = format.apply(null, arguments);
2159
- console.error('%s %d: %s', set, pid, msg);
2160
- };
2161
- } else {
2162
- debugs[set] = function () {};
2163
- }
2164
- }
2165
-
2166
- return debugs[set];
2167
- }
2168
- /**
2169
- * Echos the value of a value. Trys to print the value out
2170
- * in the best way possible given the different types.
2171
- *
2172
- * @param {Object} obj The object to print out.
2173
- * @param {Object} opts Optional options object that alters the output.
2174
- */
2175
-
2176
- /* legacy: obj, showHidden, depth, colors*/
2177
-
2178
- function inspect(obj, opts) {
2179
- // default options
2180
- var ctx = {
2181
- seen: [],
2182
- stylize: stylizeNoColor
2183
- }; // legacy...
2184
-
2185
- if (arguments.length >= 3) ctx.depth = arguments[2];
2186
- if (arguments.length >= 4) ctx.colors = arguments[3];
2187
-
2188
- if (isBoolean(opts)) {
2189
- // legacy...
2190
- ctx.showHidden = opts;
2191
- } else if (opts) {
2192
- // got an "options" object
2193
- _extend(ctx, opts);
2194
- } // set default options
2195
-
2196
-
2197
- if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
2198
- if (isUndefined(ctx.depth)) ctx.depth = 2;
2199
- if (isUndefined(ctx.colors)) ctx.colors = false;
2200
- if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
2201
- if (ctx.colors) ctx.stylize = stylizeWithColor;
2202
- return formatValue(ctx, obj, ctx.depth);
2203
- } // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
2204
-
2205
- inspect.colors = {
2206
- 'bold': [1, 22],
2207
- 'italic': [3, 23],
2208
- 'underline': [4, 24],
2209
- 'inverse': [7, 27],
2210
- 'white': [37, 39],
2211
- 'grey': [90, 39],
2212
- 'black': [30, 39],
2213
- 'blue': [34, 39],
2214
- 'cyan': [36, 39],
2215
- 'green': [32, 39],
2216
- 'magenta': [35, 39],
2217
- 'red': [31, 39],
2218
- 'yellow': [33, 39]
2219
- }; // Don't use 'blue' not visible on cmd.exe
2220
-
2221
- inspect.styles = {
2222
- 'special': 'cyan',
2223
- 'number': 'yellow',
2224
- 'boolean': 'yellow',
2225
- 'undefined': 'grey',
2226
- 'null': 'bold',
2227
- 'string': 'green',
2228
- 'date': 'magenta',
2229
- // "name": intentionally not styling
2230
- 'regexp': 'red'
2231
- };
2232
-
2233
- function stylizeWithColor(str, styleType) {
2234
- var style = inspect.styles[styleType];
2235
-
2236
- if (style) {
2237
- return "\x1B[" + inspect.colors[style][0] + 'm' + str + "\x1B[" + inspect.colors[style][1] + 'm';
2238
- } else {
2239
- return str;
2240
- }
2241
- }
2242
-
2243
- function stylizeNoColor(str, styleType) {
2244
- return str;
2245
- }
2246
-
2247
- function arrayToHash(array) {
2248
- var hash = {};
2249
- array.forEach(function (val, idx) {
2250
- hash[val] = true;
2251
- });
2252
- return hash;
2253
- }
2254
-
2255
- function formatValue(ctx, value, recurseTimes) {
2256
- // Provide a hook for user-specified inspect functions.
2257
- // Check that value is an object with an inspect function on it
2258
- if (ctx.customInspect && value && isFunction(value.inspect) && // Filter out the util module, it's inspect function is special
2259
- value.inspect !== inspect && // Also filter out any prototype objects using the circular check.
2260
- !(value.constructor && value.constructor.prototype === value)) {
2261
- var ret = value.inspect(recurseTimes, ctx);
2262
-
2263
- if (!isString(ret)) {
2264
- ret = formatValue(ctx, ret, recurseTimes);
2265
- }
2266
-
2267
- return ret;
2268
- } // Primitive types cannot have properties
2269
-
2270
-
2271
- var primitive = formatPrimitive(ctx, value);
2272
-
2273
- if (primitive) {
2274
- return primitive;
2275
- } // Look up the keys of the object.
2276
-
2277
-
2278
- var keys = Object.keys(value);
2279
- var visibleKeys = arrayToHash(keys);
2280
-
2281
- if (ctx.showHidden) {
2282
- keys = Object.getOwnPropertyNames(value);
2283
- } // IE doesn't make error fields non-enumerable
2284
- // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
2285
-
2286
-
2287
- if (isError(value) && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
2288
- return formatError(value);
2289
- } // Some type of object without properties can be shortcutted.
2290
-
2291
-
2292
- if (keys.length === 0) {
2293
- if (isFunction(value)) {
2294
- var name = value.name ? ': ' + value.name : '';
2295
- return ctx.stylize('[Function' + name + ']', 'special');
2296
- }
2297
-
2298
- if (isRegExp(value)) {
2299
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
2300
- }
2301
-
2302
- if (isDate(value)) {
2303
- return ctx.stylize(Date.prototype.toString.call(value), 'date');
2304
- }
2305
-
2306
- if (isError(value)) {
2307
- return formatError(value);
2308
- }
2309
- }
2310
-
2311
- var base = '',
2312
- array = false,
2313
- braces = ['{', '}']; // Make Array say that they are Array
2314
-
2315
- if (isArray(value)) {
2316
- array = true;
2317
- braces = ['[', ']'];
2318
- } // Make functions say that they are functions
2319
-
2320
-
2321
- if (isFunction(value)) {
2322
- var n = value.name ? ': ' + value.name : '';
2323
- base = ' [Function' + n + ']';
2324
- } // Make RegExps say that they are RegExps
2325
-
2326
-
2327
- if (isRegExp(value)) {
2328
- base = ' ' + RegExp.prototype.toString.call(value);
2329
- } // Make dates with properties first say the date
2330
-
2331
-
2332
- if (isDate(value)) {
2333
- base = ' ' + Date.prototype.toUTCString.call(value);
2334
- } // Make error with message first say the error
2335
-
2336
-
2337
- if (isError(value)) {
2338
- base = ' ' + formatError(value);
2339
- }
2340
-
2341
- if (keys.length === 0 && (!array || value.length == 0)) {
2342
- return braces[0] + base + braces[1];
2343
- }
2344
-
2345
- if (recurseTimes < 0) {
2346
- if (isRegExp(value)) {
2347
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
2348
- } else {
2349
- return ctx.stylize('[Object]', 'special');
2350
- }
2351
- }
2352
-
2353
- ctx.seen.push(value);
2354
- var output;
2355
-
2356
- if (array) {
2357
- output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
2358
- } else {
2359
- output = keys.map(function (key) {
2360
- return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
2361
- });
2362
- }
2363
-
2364
- ctx.seen.pop();
2365
- return reduceToSingleString(output, base, braces);
2366
- }
2367
-
2368
- function formatPrimitive(ctx, value) {
2369
- if (isUndefined(value)) return ctx.stylize('undefined', 'undefined');
2370
-
2371
- if (isString(value)) {
2372
- var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\'';
2373
- return ctx.stylize(simple, 'string');
2374
- }
2375
-
2376
- if (isNumber(value)) return ctx.stylize('' + value, 'number');
2377
- if (isBoolean(value)) return ctx.stylize('' + value, 'boolean'); // For some reason typeof null is "object", so special case here.
2378
-
2379
- if (isNull(value)) return ctx.stylize('null', 'null');
2380
- }
2381
-
2382
- function formatError(value) {
2383
- return '[' + Error.prototype.toString.call(value) + ']';
2384
- }
2385
-
2386
- function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
2387
- var output = [];
2388
-
2389
- for (var i = 0, l = value.length; i < l; ++i) {
2390
- if (hasOwnProperty(value, String(i))) {
2391
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true));
2392
- } else {
2393
- output.push('');
2394
- }
2395
- }
2396
-
2397
- keys.forEach(function (key) {
2398
- if (!key.match(/^\d+$/)) {
2399
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true));
2400
- }
2401
- });
2402
- return output;
2403
- }
2404
-
2405
- function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
2406
- var name, str, desc;
2407
- desc = Object.getOwnPropertyDescriptor(value, key) || {
2408
- value: value[key]
2409
- };
2410
-
2411
- if (desc.get) {
2412
- if (desc.set) {
2413
- str = ctx.stylize('[Getter/Setter]', 'special');
2414
- } else {
2415
- str = ctx.stylize('[Getter]', 'special');
2416
- }
2417
- } else {
2418
- if (desc.set) {
2419
- str = ctx.stylize('[Setter]', 'special');
2420
- }
2421
- }
2422
-
2423
- if (!hasOwnProperty(visibleKeys, key)) {
2424
- name = '[' + key + ']';
2425
- }
2426
-
2427
- if (!str) {
2428
- if (ctx.seen.indexOf(desc.value) < 0) {
2429
- if (isNull(recurseTimes)) {
2430
- str = formatValue(ctx, desc.value, null);
2431
- } else {
2432
- str = formatValue(ctx, desc.value, recurseTimes - 1);
2433
- }
2434
-
2435
- if (str.indexOf('\n') > -1) {
2436
- if (array) {
2437
- str = str.split('\n').map(function (line) {
2438
- return ' ' + line;
2439
- }).join('\n').substr(2);
2440
- } else {
2441
- str = '\n' + str.split('\n').map(function (line) {
2442
- return ' ' + line;
2443
- }).join('\n');
2444
- }
2445
- }
2446
- } else {
2447
- str = ctx.stylize('[Circular]', 'special');
2448
- }
2449
- }
2450
-
2451
- if (isUndefined(name)) {
2452
- if (array && key.match(/^\d+$/)) {
2453
- return str;
2454
- }
2455
-
2456
- name = JSON.stringify('' + key);
2457
-
2458
- if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
2459
- name = name.substr(1, name.length - 2);
2460
- name = ctx.stylize(name, 'name');
2461
- } else {
2462
- name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
2463
- name = ctx.stylize(name, 'string');
2464
- }
2465
- }
2466
-
2467
- return name + ': ' + str;
2468
- }
2469
-
2470
- function reduceToSingleString(output, base, braces) {
2471
- var length = output.reduce(function (prev, cur) {
2472
- if (cur.indexOf('\n') >= 0) ;
2473
- return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
2474
- }, 0);
2475
-
2476
- if (length > 60) {
2477
- return braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1];
2478
- }
2479
-
2480
- return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
2481
- } // NOTE: These type checking functions intentionally don't use `instanceof`
2482
- // because it is fragile and can be easily faked with `Object.create()`.
2483
-
2484
-
2485
- function isArray(ar) {
2486
- return Array.isArray(ar);
2487
- }
2488
- function isBoolean(arg) {
2489
- return typeof arg === 'boolean';
2490
- }
2491
- function isNull(arg) {
2492
- return arg === null;
2493
- }
2494
- function isNullOrUndefined(arg) {
2495
- return arg == null;
2496
- }
2497
- function isNumber(arg) {
2498
- return typeof arg === 'number';
2499
- }
2500
- function isString(arg) {
2501
- return typeof arg === 'string';
2502
- }
2503
- function isSymbol(arg) {
2504
- return babelHelpers["typeof"](arg) === 'symbol';
2505
- }
2506
- function isUndefined(arg) {
2507
- return arg === void 0;
2508
- }
2509
- function isRegExp(re) {
2510
- return isObject(re) && objectToString(re) === '[object RegExp]';
2511
- }
2512
- function isObject(arg) {
2513
- return babelHelpers["typeof"](arg) === 'object' && arg !== null;
2514
- }
2515
- function isDate(d) {
2516
- return isObject(d) && objectToString(d) === '[object Date]';
2517
- }
2518
- function isError(e) {
2519
- return isObject(e) && (objectToString(e) === '[object Error]' || e instanceof Error);
2520
- }
2521
- function isFunction(arg) {
2522
- return typeof arg === 'function';
2523
- }
2524
- function isPrimitive(arg) {
2525
- return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || babelHelpers["typeof"](arg) === 'symbol' || // ES6 symbol
2526
- typeof arg === 'undefined';
2527
- }
2528
- function isBuffer(maybeBuf) {
2529
- return Buffer.isBuffer(maybeBuf);
2530
- }
2531
-
2532
- function objectToString(o) {
2533
- return Object.prototype.toString.call(o);
2534
- }
2535
-
2536
- function pad(n) {
2537
- return n < 10 ? '0' + n.toString(10) : n.toString(10);
2538
- }
2539
-
2540
- var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; // 26 Feb 16:19:34
2541
-
2542
- function timestamp$1() {
2543
- var d = new Date();
2544
- var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':');
2545
- return [d.getDate(), months[d.getMonth()], time].join(' ');
2546
- } // log is just a thin wrapper to console.log that prepends a timestamp
2547
-
2548
-
2549
- function log() {
2550
- console.log('%s - %s', timestamp$1(), format.apply(null, arguments));
2551
- }
2552
- function _extend(origin, add) {
2553
- // Don't do anything if add isn't an object
2554
- if (!add || !isObject(add)) return origin;
2555
- var keys = Object.keys(add);
2556
- var i = keys.length;
2557
-
2558
- while (i--) {
2559
- origin[keys[i]] = add[keys[i]];
2560
- }
2029
+ var buffer_1 = buffer$1.Buffer;
2030
+ buffer$1.SlowBuffer;
2031
+ buffer$1.INSPECT_MAX_BYTES;
2032
+ buffer$1.kMaxLength;
2561
2033
 
2562
- return origin;
2034
+ function checkForMath(potentialGlobal) {
2035
+ // eslint-disable-next-line eqeqeq
2036
+ return potentialGlobal && potentialGlobal.Math == Math && potentialGlobal;
2563
2037
  }
2564
-
2565
- function hasOwnProperty(obj, prop) {
2566
- 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')());
2567
2046
  }
2568
2047
 
2569
- var require$$1 = {
2570
- inherits: inherits$1,
2571
- _extend: _extend,
2572
- log: log,
2573
- isBuffer: isBuffer,
2574
- isPrimitive: isPrimitive,
2575
- isFunction: isFunction,
2576
- isError: isError,
2577
- isDate: isDate,
2578
- isObject: isObject,
2579
- isRegExp: isRegExp,
2580
- isUndefined: isUndefined,
2581
- isSymbol: isSymbol,
2582
- isString: isString,
2583
- isNumber: isNumber,
2584
- isNullOrUndefined: isNullOrUndefined,
2585
- isNull: isNull,
2586
- isBoolean: isBoolean,
2587
- isArray: isArray,
2588
- inspect: inspect,
2589
- deprecate: deprecate,
2590
- format: format,
2591
- debuglog: debuglog
2592
- };
2593
-
2594
- var utils = createCommonjsModule(function (module, exports) {
2595
- Object.defineProperty(exports, "__esModule", { value: true });
2596
- exports.deprecate = exports.isObjectLike = exports.isDate = exports.haveBuffer = exports.isMap = exports.isRegExp = exports.isBigUInt64Array = exports.isBigInt64Array = exports.isUint8Array = exports.isAnyArrayBuffer = exports.randomBytes = exports.normalizedFunctionString = void 0;
2597
-
2598
2048
  /**
2599
2049
  * Normalizes our expected stringified form of a function across versions of node
2600
2050
  * @param fn - The function to stringify
@@ -2602,14 +2052,16 @@ exports.deprecate = exports.isObjectLike = exports.isDate = exports.haveBuffer =
2602
2052
  function normalizedFunctionString(fn) {
2603
2053
  return fn.toString().replace('function(', 'function (');
2604
2054
  }
2605
- exports.normalizedFunctionString = normalizedFunctionString;
2606
- var isReactNative = typeof commonjsGlobal.navigator === 'object' && commonjsGlobal.navigator.product === 'ReactNative';
2607
- var insecureWarning = isReactNative
2608
- ? 'BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.'
2609
- : 'BSON: No cryptographic implementation for random bytes present, falling back to a less secure implementation.';
2055
+ function isReactNative() {
2056
+ var g = getGlobal();
2057
+ return typeof g.navigator === 'object' && g.navigator.product === 'ReactNative';
2058
+ }
2610
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.';
2611
2063
  console.warn(insecureWarning);
2612
- var result = buffer.Buffer.alloc(size);
2064
+ var result = buffer_1.alloc(size);
2613
2065
  for (var i = 0; i < size; ++i)
2614
2066
  result[i] = Math.floor(Math.random() * 256);
2615
2067
  return result;
@@ -2619,17 +2071,17 @@ var detectRandomBytes = function () {
2619
2071
  // browser crypto implementation(s)
2620
2072
  var target_1 = window.crypto || window.msCrypto; // allow for IE11
2621
2073
  if (target_1 && target_1.getRandomValues) {
2622
- return function (size) { return target_1.getRandomValues(buffer.Buffer.alloc(size)); };
2074
+ return function (size) { return target_1.getRandomValues(buffer_1.alloc(size)); };
2623
2075
  }
2624
2076
  }
2625
- if (typeof commonjsGlobal !== 'undefined' && commonjsGlobal.crypto && commonjsGlobal.crypto.getRandomValues) {
2077
+ if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
2626
2078
  // allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
2627
- return function (size) { return commonjsGlobal.crypto.getRandomValues(buffer.Buffer.alloc(size)); };
2079
+ return function (size) { return global.crypto.getRandomValues(buffer_1.alloc(size)); };
2628
2080
  }
2629
2081
  var requiredRandomBytes;
2630
2082
  try {
2631
2083
  // eslint-disable-next-line @typescript-eslint/no-var-requires
2632
- requiredRandomBytes = require$$0.randomBytes;
2084
+ requiredRandomBytes = require('crypto').randomBytes;
2633
2085
  }
2634
2086
  catch (e) {
2635
2087
  // keep the fallback
@@ -2637,41 +2089,29 @@ var detectRandomBytes = function () {
2637
2089
  // NOTE: in transpiled cases the above require might return null/undefined
2638
2090
  return requiredRandomBytes || insecureRandomBytes;
2639
2091
  };
2640
- exports.randomBytes = detectRandomBytes();
2092
+ var randomBytes = detectRandomBytes();
2641
2093
  function isAnyArrayBuffer(value) {
2642
2094
  return ['[object ArrayBuffer]', '[object SharedArrayBuffer]'].includes(Object.prototype.toString.call(value));
2643
2095
  }
2644
- exports.isAnyArrayBuffer = isAnyArrayBuffer;
2645
2096
  function isUint8Array(value) {
2646
2097
  return Object.prototype.toString.call(value) === '[object Uint8Array]';
2647
2098
  }
2648
- exports.isUint8Array = isUint8Array;
2649
2099
  function isBigInt64Array(value) {
2650
2100
  return Object.prototype.toString.call(value) === '[object BigInt64Array]';
2651
2101
  }
2652
- exports.isBigInt64Array = isBigInt64Array;
2653
2102
  function isBigUInt64Array(value) {
2654
2103
  return Object.prototype.toString.call(value) === '[object BigUint64Array]';
2655
2104
  }
2656
- exports.isBigUInt64Array = isBigUInt64Array;
2657
2105
  function isRegExp(d) {
2658
2106
  return Object.prototype.toString.call(d) === '[object RegExp]';
2659
2107
  }
2660
- exports.isRegExp = isRegExp;
2661
2108
  function isMap(d) {
2662
2109
  return Object.prototype.toString.call(d) === '[object Map]';
2663
2110
  }
2664
- exports.isMap = isMap;
2665
- /** Call to check if your environment has `Buffer` */
2666
- function haveBuffer() {
2667
- return typeof commonjsGlobal !== 'undefined' && typeof commonjsGlobal.Buffer !== 'undefined';
2668
- }
2669
- exports.haveBuffer = haveBuffer;
2670
2111
  // To ensure that 0.4 of node works correctly
2671
2112
  function isDate(d) {
2672
2113
  return isObjectLike(d) && Object.prototype.toString.call(d) === '[object Date]';
2673
2114
  }
2674
- exports.isDate = isDate;
2675
2115
  /**
2676
2116
  * @internal
2677
2117
  * this is to solve the `'someKey' in x` problem where x is unknown.
@@ -2680,12 +2120,7 @@ exports.isDate = isDate;
2680
2120
  function isObjectLike(candidate) {
2681
2121
  return typeof candidate === 'object' && candidate !== null;
2682
2122
  }
2683
- exports.isObjectLike = isObjectLike;
2684
2123
  function deprecate(fn, message) {
2685
- if (typeof window === 'undefined' && typeof self === 'undefined') {
2686
- // eslint-disable-next-line @typescript-eslint/no-var-requires
2687
- return require$$1.deprecate(fn, message);
2688
- }
2689
2124
  var warned = false;
2690
2125
  function deprecated() {
2691
2126
  var args = [];
@@ -2700,28 +2135,6 @@ function deprecate(fn, message) {
2700
2135
  }
2701
2136
  return deprecated;
2702
2137
  }
2703
- exports.deprecate = deprecate;
2704
- //# sourceMappingURL=utils.js.map
2705
- });
2706
-
2707
- unwrapExports(utils);
2708
- utils.deprecate;
2709
- utils.isObjectLike;
2710
- utils.isDate;
2711
- utils.haveBuffer;
2712
- utils.isMap;
2713
- utils.isRegExp;
2714
- utils.isBigUInt64Array;
2715
- utils.isBigInt64Array;
2716
- utils.isUint8Array;
2717
- utils.isAnyArrayBuffer;
2718
- utils.randomBytes;
2719
- utils.normalizedFunctionString;
2720
-
2721
- var ensure_buffer = createCommonjsModule(function (module, exports) {
2722
- Object.defineProperty(exports, "__esModule", { value: true });
2723
- exports.ensureBuffer = void 0;
2724
-
2725
2138
 
2726
2139
  /**
2727
2140
  * Makes sure that, if a Uint8Array is passed in, it is wrapped in a Buffer.
@@ -2733,38 +2146,26 @@ exports.ensureBuffer = void 0;
2733
2146
  */
2734
2147
  function ensureBuffer(potentialBuffer) {
2735
2148
  if (ArrayBuffer.isView(potentialBuffer)) {
2736
- return buffer.Buffer.from(potentialBuffer.buffer, potentialBuffer.byteOffset, potentialBuffer.byteLength);
2149
+ return buffer_1.from(potentialBuffer.buffer, potentialBuffer.byteOffset, potentialBuffer.byteLength);
2737
2150
  }
2738
- if (utils.isAnyArrayBuffer(potentialBuffer)) {
2739
- return buffer.Buffer.from(potentialBuffer);
2151
+ if (isAnyArrayBuffer(potentialBuffer)) {
2152
+ return buffer_1.from(potentialBuffer);
2740
2153
  }
2741
2154
  throw new TypeError('Must use either Buffer or TypedArray');
2742
2155
  }
2743
- exports.ensureBuffer = ensureBuffer;
2744
- //# sourceMappingURL=ensure_buffer.js.map
2745
- });
2746
-
2747
- unwrapExports(ensure_buffer);
2748
- ensure_buffer.ensureBuffer;
2749
-
2750
- var uuid_utils = createCommonjsModule(function (module, exports) {
2751
- Object.defineProperty(exports, "__esModule", { value: true });
2752
- exports.bufferToUuidHexString = exports.uuidHexStringToBuffer = exports.uuidValidateString = void 0;
2753
2156
 
2754
2157
  // Validation regex for v4 uuid (validates with or without dashes)
2755
2158
  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;
2756
2159
  var uuidValidateString = function (str) {
2757
2160
  return typeof str === 'string' && VALIDATION_REGEX.test(str);
2758
2161
  };
2759
- exports.uuidValidateString = uuidValidateString;
2760
2162
  var uuidHexStringToBuffer = function (hexString) {
2761
- if (!exports.uuidValidateString(hexString)) {
2163
+ if (!uuidValidateString(hexString)) {
2762
2164
  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".');
2763
2165
  }
2764
2166
  var sanitizedHexString = hexString.replace(/-/g, '');
2765
- return buffer.Buffer.from(sanitizedHexString, 'hex');
2167
+ return buffer_1.from(sanitizedHexString, 'hex');
2766
2168
  };
2767
- exports.uuidHexStringToBuffer = uuidHexStringToBuffer;
2768
2169
  var bufferToUuidHexString = function (buffer, includeDashes) {
2769
2170
  if (includeDashes === void 0) { includeDashes = true; }
2770
2171
  return includeDashes
@@ -2779,25 +2180,9 @@ var bufferToUuidHexString = function (buffer, includeDashes) {
2779
2180
  buffer.toString('hex', 10, 16)
2780
2181
  : buffer.toString('hex');
2781
2182
  };
2782
- exports.bufferToUuidHexString = bufferToUuidHexString;
2783
- //# sourceMappingURL=uuid_utils.js.map
2784
- });
2785
-
2786
- unwrapExports(uuid_utils);
2787
- uuid_utils.bufferToUuidHexString;
2788
- uuid_utils.uuidHexStringToBuffer;
2789
- uuid_utils.uuidValidateString;
2790
-
2791
- var uuid = createCommonjsModule(function (module, exports) {
2792
- Object.defineProperty(exports, "__esModule", { value: true });
2793
- exports.UUID = void 0;
2794
-
2795
-
2796
-
2797
-
2798
2183
 
2799
2184
  var BYTE_LENGTH = 16;
2800
- var kId = Symbol('id');
2185
+ var kId$1 = Symbol('id');
2801
2186
  /**
2802
2187
  * A class representation of the BSON UUID type.
2803
2188
  * @public
@@ -2814,14 +2199,14 @@ var UUID = /** @class */ (function () {
2814
2199
  this.id = UUID.generate();
2815
2200
  }
2816
2201
  else if (input instanceof UUID) {
2817
- this[kId] = buffer.Buffer.from(input.id);
2202
+ this[kId$1] = buffer_1.from(input.id);
2818
2203
  this.__id = input.__id;
2819
2204
  }
2820
2205
  else if (ArrayBuffer.isView(input) && input.byteLength === BYTE_LENGTH) {
2821
- this.id = ensure_buffer.ensureBuffer(input);
2206
+ this.id = ensureBuffer(input);
2822
2207
  }
2823
2208
  else if (typeof input === 'string') {
2824
- this.id = uuid_utils.uuidHexStringToBuffer(input);
2209
+ this.id = uuidHexStringToBuffer(input);
2825
2210
  }
2826
2211
  else {
2827
2212
  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).');
@@ -2833,12 +2218,12 @@ var UUID = /** @class */ (function () {
2833
2218
  * @readonly
2834
2219
  */
2835
2220
  get: function () {
2836
- return this[kId];
2221
+ return this[kId$1];
2837
2222
  },
2838
2223
  set: function (value) {
2839
- this[kId] = value;
2224
+ this[kId$1] = value;
2840
2225
  if (UUID.cacheHexString) {
2841
- this.__id = uuid_utils.bufferToUuidHexString(value);
2226
+ this.__id = bufferToUuidHexString(value);
2842
2227
  }
2843
2228
  },
2844
2229
  enumerable: false,
@@ -2856,7 +2241,7 @@ var UUID = /** @class */ (function () {
2856
2241
  if (UUID.cacheHexString && this.__id) {
2857
2242
  return this.__id;
2858
2243
  }
2859
- var uuidHexString = uuid_utils.bufferToUuidHexString(this.id, includeDashes);
2244
+ var uuidHexString = bufferToUuidHexString(this.id, includeDashes);
2860
2245
  if (UUID.cacheHexString) {
2861
2246
  this.__id = uuidHexString;
2862
2247
  }
@@ -2864,14 +2249,13 @@ var UUID = /** @class */ (function () {
2864
2249
  };
2865
2250
  /**
2866
2251
  * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
2867
- * @internal
2868
2252
  */
2869
2253
  UUID.prototype.toString = function (encoding) {
2870
2254
  return encoding ? this.id.toString(encoding) : this.toHexString();
2871
2255
  };
2872
2256
  /**
2873
- * Converts the id into its JSON string representation. A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
2874
- * @internal
2257
+ * Converts the id into its JSON string representation.
2258
+ * A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
2875
2259
  */
2876
2260
  UUID.prototype.toJSON = function () {
2877
2261
  return this.toHexString();
@@ -2899,18 +2283,18 @@ var UUID = /** @class */ (function () {
2899
2283
  * Creates a Binary instance from the current UUID.
2900
2284
  */
2901
2285
  UUID.prototype.toBinary = function () {
2902
- return new binary.Binary(this.id, binary.Binary.SUBTYPE_UUID);
2286
+ return new Binary(this.id, Binary.SUBTYPE_UUID);
2903
2287
  };
2904
2288
  /**
2905
2289
  * Generates a populated buffer containing a v4 uuid
2906
2290
  */
2907
2291
  UUID.generate = function () {
2908
- var bytes = utils.randomBytes(BYTE_LENGTH);
2292
+ var bytes = randomBytes(BYTE_LENGTH);
2909
2293
  // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
2910
2294
  // Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
2911
2295
  bytes[6] = (bytes[6] & 0x0f) | 0x40;
2912
2296
  bytes[8] = (bytes[8] & 0x3f) | 0x80;
2913
- return buffer.Buffer.from(bytes);
2297
+ return buffer_1.from(bytes);
2914
2298
  };
2915
2299
  /**
2916
2300
  * Checks if a value is a valid bson UUID
@@ -2924,9 +2308,9 @@ var UUID = /** @class */ (function () {
2924
2308
  return true;
2925
2309
  }
2926
2310
  if (typeof input === 'string') {
2927
- return uuid_utils.uuidValidateString(input);
2311
+ return uuidValidateString(input);
2928
2312
  }
2929
- if (utils.isUint8Array(input)) {
2313
+ if (isUint8Array(input)) {
2930
2314
  // check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
2931
2315
  if (input.length !== BYTE_LENGTH) {
2932
2316
  return false;
@@ -2934,7 +2318,7 @@ var UUID = /** @class */ (function () {
2934
2318
  try {
2935
2319
  // get this byte as hex: xxxxxxxx-xxxx-XXxx-xxxx-xxxxxxxxxxxx
2936
2320
  // check first part as uuid version: xxxxxxxx-xxxx-Xxxx-xxxx-xxxxxxxxxxxx
2937
- return parseInt(input[6].toString(16)[0], 10) === binary.Binary.SUBTYPE_UUID;
2321
+ return parseInt(input[6].toString(16)[0], 10) === Binary.SUBTYPE_UUID;
2938
2322
  }
2939
2323
  catch (_a) {
2940
2324
  return false;
@@ -2947,7 +2331,7 @@ var UUID = /** @class */ (function () {
2947
2331
  * @param hexString - 32 or 36 character hex string (dashes excluded/included).
2948
2332
  */
2949
2333
  UUID.createFromHexString = function (hexString) {
2950
- var buffer = uuid_utils.uuidHexStringToBuffer(hexString);
2334
+ var buffer = uuidHexStringToBuffer(hexString);
2951
2335
  return new UUID(buffer);
2952
2336
  };
2953
2337
  /**
@@ -2964,20 +2348,7 @@ var UUID = /** @class */ (function () {
2964
2348
  };
2965
2349
  return UUID;
2966
2350
  }());
2967
- exports.UUID = UUID;
2968
2351
  Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
2969
- //# sourceMappingURL=uuid.js.map
2970
- });
2971
-
2972
- unwrapExports(uuid);
2973
- uuid.UUID;
2974
-
2975
- var binary = createCommonjsModule(function (module, exports) {
2976
- Object.defineProperty(exports, "__esModule", { value: true });
2977
- exports.Binary = void 0;
2978
-
2979
-
2980
-
2981
2352
 
2982
2353
  /**
2983
2354
  * A class representation of the BSON Binary type.
@@ -2988,34 +2359,34 @@ var Binary = /** @class */ (function () {
2988
2359
  * @param buffer - a buffer object containing the binary data.
2989
2360
  * @param subType - the option binary type.
2990
2361
  */
2991
- function Binary(buffer$1, subType) {
2362
+ function Binary(buffer, subType) {
2992
2363
  if (!(this instanceof Binary))
2993
- return new Binary(buffer$1, subType);
2994
- if (!(buffer$1 == null) &&
2995
- !(typeof buffer$1 === 'string') &&
2996
- !ArrayBuffer.isView(buffer$1) &&
2997
- !(buffer$1 instanceof ArrayBuffer) &&
2998
- !Array.isArray(buffer$1)) {
2364
+ return new Binary(buffer, subType);
2365
+ if (!(buffer == null) &&
2366
+ !(typeof buffer === 'string') &&
2367
+ !ArrayBuffer.isView(buffer) &&
2368
+ !(buffer instanceof ArrayBuffer) &&
2369
+ !Array.isArray(buffer)) {
2999
2370
  throw new TypeError('Binary can only be constructed from string, Buffer, TypedArray, or Array<number>');
3000
2371
  }
3001
2372
  this.sub_type = subType !== null && subType !== void 0 ? subType : Binary.BSON_BINARY_SUBTYPE_DEFAULT;
3002
- if (buffer$1 == null) {
2373
+ if (buffer == null) {
3003
2374
  // create an empty binary buffer
3004
- this.buffer = buffer.Buffer.alloc(Binary.BUFFER_SIZE);
2375
+ this.buffer = buffer_1.alloc(Binary.BUFFER_SIZE);
3005
2376
  this.position = 0;
3006
2377
  }
3007
2378
  else {
3008
- if (typeof buffer$1 === 'string') {
2379
+ if (typeof buffer === 'string') {
3009
2380
  // string
3010
- this.buffer = buffer.Buffer.from(buffer$1, 'binary');
2381
+ this.buffer = buffer_1.from(buffer, 'binary');
3011
2382
  }
3012
- else if (Array.isArray(buffer$1)) {
2383
+ else if (Array.isArray(buffer)) {
3013
2384
  // number[]
3014
- this.buffer = buffer.Buffer.from(buffer$1);
2385
+ this.buffer = buffer_1.from(buffer);
3015
2386
  }
3016
2387
  else {
3017
2388
  // Buffer | TypedArray | ArrayBuffer
3018
- this.buffer = ensure_buffer.ensureBuffer(buffer$1);
2389
+ this.buffer = ensureBuffer(buffer);
3019
2390
  }
3020
2391
  this.position = this.buffer.byteLength;
3021
2392
  }
@@ -3050,10 +2421,10 @@ var Binary = /** @class */ (function () {
3050
2421
  this.buffer[this.position++] = decodedByte;
3051
2422
  }
3052
2423
  else {
3053
- var buffer$1 = buffer.Buffer.alloc(Binary.BUFFER_SIZE + this.buffer.length);
2424
+ var buffer = buffer_1.alloc(Binary.BUFFER_SIZE + this.buffer.length);
3054
2425
  // Combine the two buffers together
3055
- this.buffer.copy(buffer$1, 0, 0, this.buffer.length);
3056
- this.buffer = buffer$1;
2426
+ this.buffer.copy(buffer, 0, 0, this.buffer.length);
2427
+ this.buffer = buffer;
3057
2428
  this.buffer[this.position++] = decodedByte;
3058
2429
  }
3059
2430
  };
@@ -3067,13 +2438,13 @@ var Binary = /** @class */ (function () {
3067
2438
  offset = typeof offset === 'number' ? offset : this.position;
3068
2439
  // If the buffer is to small let's extend the buffer
3069
2440
  if (this.buffer.length < offset + sequence.length) {
3070
- var buffer$1 = buffer.Buffer.alloc(this.buffer.length + sequence.length);
3071
- this.buffer.copy(buffer$1, 0, 0, this.buffer.length);
2441
+ var buffer = buffer_1.alloc(this.buffer.length + sequence.length);
2442
+ this.buffer.copy(buffer, 0, 0, this.buffer.length);
3072
2443
  // Assign the new buffer
3073
- this.buffer = buffer$1;
2444
+ this.buffer = buffer;
3074
2445
  }
3075
2446
  if (ArrayBuffer.isView(sequence)) {
3076
- this.buffer.set(ensure_buffer.ensureBuffer(sequence), offset);
2447
+ this.buffer.set(ensureBuffer(sequence), offset);
3077
2448
  this.position =
3078
2449
  offset + sequence.byteLength > this.position ? offset + sequence.length : this.position;
3079
2450
  }
@@ -3116,11 +2487,9 @@ var Binary = /** @class */ (function () {
3116
2487
  Binary.prototype.length = function () {
3117
2488
  return this.position;
3118
2489
  };
3119
- /** @internal */
3120
2490
  Binary.prototype.toJSON = function () {
3121
2491
  return this.buffer.toString('base64');
3122
2492
  };
3123
- /** @internal */
3124
2493
  Binary.prototype.toString = function (format) {
3125
2494
  return this.buffer.toString(format);
3126
2495
  };
@@ -3142,10 +2511,9 @@ var Binary = /** @class */ (function () {
3142
2511
  }
3143
2512
  };
3144
2513
  };
3145
- /** @internal */
3146
2514
  Binary.prototype.toUUID = function () {
3147
2515
  if (this.sub_type === Binary.SUBTYPE_UUID) {
3148
- return new uuid.UUID(this.buffer.slice(0, this.position));
2516
+ return new UUID(this.buffer.slice(0, this.position));
3149
2517
  }
3150
2518
  throw new Error("Binary sub_type \"" + this.sub_type + "\" is not supported for converting to UUID. Only \"" + Binary.SUBTYPE_UUID + "\" is currently supported.");
3151
2519
  };
@@ -3157,18 +2525,18 @@ var Binary = /** @class */ (function () {
3157
2525
  if ('$binary' in doc) {
3158
2526
  if (options.legacy && typeof doc.$binary === 'string' && '$type' in doc) {
3159
2527
  type = doc.$type ? parseInt(doc.$type, 16) : 0;
3160
- data = buffer.Buffer.from(doc.$binary, 'base64');
2528
+ data = buffer_1.from(doc.$binary, 'base64');
3161
2529
  }
3162
2530
  else {
3163
2531
  if (typeof doc.$binary !== 'string') {
3164
2532
  type = doc.$binary.subType ? parseInt(doc.$binary.subType, 16) : 0;
3165
- data = buffer.Buffer.from(doc.$binary.base64, 'base64');
2533
+ data = buffer_1.from(doc.$binary.base64, 'base64');
3166
2534
  }
3167
2535
  }
3168
2536
  }
3169
2537
  else if ('$uuid' in doc) {
3170
2538
  type = 4;
3171
- data = uuid_utils.uuidHexStringToBuffer(doc.$uuid);
2539
+ data = uuidHexStringToBuffer(doc.$uuid);
3172
2540
  }
3173
2541
  if (!data) {
3174
2542
  throw new TypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc));
@@ -3206,17 +2574,8 @@ var Binary = /** @class */ (function () {
3206
2574
  Binary.SUBTYPE_USER_DEFINED = 128;
3207
2575
  return Binary;
3208
2576
  }());
3209
- exports.Binary = Binary;
3210
2577
  Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' });
3211
- //# sourceMappingURL=binary.js.map
3212
- });
3213
2578
 
3214
- unwrapExports(binary);
3215
- binary.Binary;
3216
-
3217
- var code = createCommonjsModule(function (module, exports) {
3218
- Object.defineProperty(exports, "__esModule", { value: true });
3219
- exports.Code = void 0;
3220
2579
  /**
3221
2580
  * A class representation of the BSON Code type.
3222
2581
  * @public
@@ -3232,7 +2591,6 @@ var Code = /** @class */ (function () {
3232
2591
  this.code = code;
3233
2592
  this.scope = scope;
3234
2593
  }
3235
- /** @internal */
3236
2594
  Code.prototype.toJSON = function () {
3237
2595
  return { code: this.code, scope: this.scope };
3238
2596
  };
@@ -3257,23 +2615,15 @@ var Code = /** @class */ (function () {
3257
2615
  };
3258
2616
  return Code;
3259
2617
  }());
3260
- exports.Code = Code;
3261
2618
  Object.defineProperty(Code.prototype, '_bsontype', { value: 'Code' });
3262
- //# sourceMappingURL=code.js.map
3263
- });
3264
-
3265
- unwrapExports(code);
3266
- code.Code;
3267
-
3268
- var db_ref = createCommonjsModule(function (module, exports) {
3269
- Object.defineProperty(exports, "__esModule", { value: true });
3270
- exports.DBRef = exports.isDBRefLike = void 0;
3271
2619
 
3272
2620
  /** @internal */
3273
2621
  function isDBRefLike(value) {
3274
- return utils.isObjectLike(value) && value['$id'] != null && value['$ref'] != null;
2622
+ return (isObjectLike(value) &&
2623
+ value.$id != null &&
2624
+ typeof value.$ref === 'string' &&
2625
+ (value.$db == null || typeof value.$db === 'string'));
3275
2626
  }
3276
- exports.isDBRefLike = isDBRefLike;
3277
2627
  /**
3278
2628
  * A class representation of the BSON DBRef type.
3279
2629
  * @public
@@ -3312,7 +2662,6 @@ var DBRef = /** @class */ (function () {
3312
2662
  enumerable: false,
3313
2663
  configurable: true
3314
2664
  });
3315
- /** @internal */
3316
2665
  DBRef.prototype.toJSON = function () {
3317
2666
  var o = Object.assign({
3318
2667
  $ref: this.collection,
@@ -3356,18 +2705,7 @@ var DBRef = /** @class */ (function () {
3356
2705
  };
3357
2706
  return DBRef;
3358
2707
  }());
3359
- exports.DBRef = DBRef;
3360
2708
  Object.defineProperty(DBRef.prototype, '_bsontype', { value: 'DBRef' });
3361
- //# sourceMappingURL=db_ref.js.map
3362
- });
3363
-
3364
- unwrapExports(db_ref);
3365
- db_ref.DBRef;
3366
- db_ref.isDBRefLike;
3367
-
3368
- var long_1 = createCommonjsModule(function (module, exports) {
3369
- Object.defineProperty(exports, "__esModule", { value: true });
3370
- exports.Long = void 0;
3371
2709
 
3372
2710
  /**
3373
2711
  * wasm optimizations, to do native i64 multiplication and divide
@@ -3601,7 +2939,7 @@ var Long = /** @class */ (function () {
3601
2939
  */
3602
2940
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
3603
2941
  Long.isLong = function (value) {
3604
- return utils.isObjectLike(value) && value['__isLong__'] === true;
2942
+ return isObjectLike(value) && value['__isLong__'] === true;
3605
2943
  };
3606
2944
  /**
3607
2945
  * Converts the specified value to a Long.
@@ -4260,19 +3598,8 @@ var Long = /** @class */ (function () {
4260
3598
  Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false);
4261
3599
  return Long;
4262
3600
  }());
4263
- exports.Long = Long;
4264
3601
  Object.defineProperty(Long.prototype, '__isLong__', { value: true });
4265
3602
  Object.defineProperty(Long.prototype, '_bsontype', { value: 'Long' });
4266
- //# sourceMappingURL=long.js.map
4267
- });
4268
-
4269
- unwrapExports(long_1);
4270
- long_1.Long;
4271
-
4272
- var decimal128 = createCommonjsModule(function (module, exports) {
4273
- Object.defineProperty(exports, "__esModule", { value: true });
4274
- exports.Decimal128 = void 0;
4275
-
4276
3603
 
4277
3604
  var PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
4278
3605
  var PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i;
@@ -4283,59 +3610,14 @@ var EXPONENT_BIAS = 6176;
4283
3610
  var MAX_DIGITS = 34;
4284
3611
  // Nan value bits as 32 bit values (due to lack of longs)
4285
3612
  var NAN_BUFFER = [
4286
- 0x7c,
4287
- 0x00,
4288
- 0x00,
4289
- 0x00,
4290
- 0x00,
4291
- 0x00,
4292
- 0x00,
4293
- 0x00,
4294
- 0x00,
4295
- 0x00,
4296
- 0x00,
4297
- 0x00,
4298
- 0x00,
4299
- 0x00,
4300
- 0x00,
4301
- 0x00
3613
+ 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4302
3614
  ].reverse();
4303
3615
  // Infinity value bits 32 bit values (due to lack of longs)
4304
3616
  var INF_NEGATIVE_BUFFER = [
4305
- 0xf8,
4306
- 0x00,
4307
- 0x00,
4308
- 0x00,
4309
- 0x00,
4310
- 0x00,
4311
- 0x00,
4312
- 0x00,
4313
- 0x00,
4314
- 0x00,
4315
- 0x00,
4316
- 0x00,
4317
- 0x00,
4318
- 0x00,
4319
- 0x00,
4320
- 0x00
3617
+ 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4321
3618
  ].reverse();
4322
3619
  var INF_POSITIVE_BUFFER = [
4323
- 0x78,
4324
- 0x00,
4325
- 0x00,
4326
- 0x00,
4327
- 0x00,
4328
- 0x00,
4329
- 0x00,
4330
- 0x00,
4331
- 0x00,
4332
- 0x00,
4333
- 0x00,
4334
- 0x00,
4335
- 0x00,
4336
- 0x00,
4337
- 0x00,
4338
- 0x00
3620
+ 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4339
3621
  ].reverse();
4340
3622
  var EXPONENT_REGEX = /^([-+])?(\d+)?$/;
4341
3623
  // Extract least significant 5 bits
@@ -4352,8 +3634,8 @@ function isDigit(value) {
4352
3634
  }
4353
3635
  // Divide two uint128 values
4354
3636
  function divideu128(value) {
4355
- var DIVISOR = long_1.Long.fromNumber(1000 * 1000 * 1000);
4356
- var _rem = long_1.Long.fromNumber(0);
3637
+ var DIVISOR = Long.fromNumber(1000 * 1000 * 1000);
3638
+ var _rem = Long.fromNumber(0);
4357
3639
  if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) {
4358
3640
  return { quotient: value, rem: _rem };
4359
3641
  }
@@ -4361,7 +3643,7 @@ function divideu128(value) {
4361
3643
  // Adjust remainder to match value of next dividend
4362
3644
  _rem = _rem.shiftLeft(32);
4363
3645
  // Add the divided to _rem
4364
- _rem = _rem.add(new long_1.Long(value.parts[i], 0));
3646
+ _rem = _rem.add(new Long(value.parts[i], 0));
4365
3647
  value.parts[i] = _rem.div(DIVISOR).low;
4366
3648
  _rem = _rem.modulo(DIVISOR);
4367
3649
  }
@@ -4370,22 +3652,22 @@ function divideu128(value) {
4370
3652
  // Multiply two Long values and return the 128 bit value
4371
3653
  function multiply64x2(left, right) {
4372
3654
  if (!left && !right) {
4373
- return { high: long_1.Long.fromNumber(0), low: long_1.Long.fromNumber(0) };
3655
+ return { high: Long.fromNumber(0), low: Long.fromNumber(0) };
4374
3656
  }
4375
3657
  var leftHigh = left.shiftRightUnsigned(32);
4376
- var leftLow = new long_1.Long(left.getLowBits(), 0);
3658
+ var leftLow = new Long(left.getLowBits(), 0);
4377
3659
  var rightHigh = right.shiftRightUnsigned(32);
4378
- var rightLow = new long_1.Long(right.getLowBits(), 0);
3660
+ var rightLow = new Long(right.getLowBits(), 0);
4379
3661
  var productHigh = leftHigh.multiply(rightHigh);
4380
3662
  var productMid = leftHigh.multiply(rightLow);
4381
3663
  var productMid2 = leftLow.multiply(rightHigh);
4382
3664
  var productLow = leftLow.multiply(rightLow);
4383
3665
  productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
4384
- productMid = new long_1.Long(productMid.getLowBits(), 0)
3666
+ productMid = new Long(productMid.getLowBits(), 0)
4385
3667
  .add(productMid2)
4386
3668
  .add(productLow.shiftRightUnsigned(32));
4387
3669
  productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
4388
- productLow = productMid.shiftLeft(32).add(new long_1.Long(productLow.getLowBits(), 0));
3670
+ productLow = productMid.shiftLeft(32).add(new Long(productLow.getLowBits(), 0));
4389
3671
  // Return the 128 bit result
4390
3672
  return { high: productHigh, low: productLow };
4391
3673
  }
@@ -4462,9 +3744,9 @@ var Decimal128 = /** @class */ (function () {
4462
3744
  // loop index over array
4463
3745
  var i = 0;
4464
3746
  // The high 17 digits of the significand
4465
- var significandHigh = new long_1.Long(0, 0);
3747
+ var significandHigh = new Long(0, 0);
4466
3748
  // The low 17 digits of the significand
4467
- var significandLow = new long_1.Long(0, 0);
3749
+ var significandLow = new Long(0, 0);
4468
3750
  // The biased exponent
4469
3751
  var biasedExponent = 0;
4470
3752
  // Read index
@@ -4509,10 +3791,10 @@ var Decimal128 = /** @class */ (function () {
4509
3791
  // Check if user passed Infinity or NaN
4510
3792
  if (!isDigit(representation[index]) && representation[index] !== '.') {
4511
3793
  if (representation[index] === 'i' || representation[index] === 'I') {
4512
- return new Decimal128(buffer.Buffer.from(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
3794
+ return new Decimal128(buffer_1.from(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
4513
3795
  }
4514
3796
  else if (representation[index] === 'N') {
4515
- return new Decimal128(buffer.Buffer.from(NAN_BUFFER));
3797
+ return new Decimal128(buffer_1.from(NAN_BUFFER));
4516
3798
  }
4517
3799
  }
4518
3800
  // Read all the digits
@@ -4550,7 +3832,7 @@ var Decimal128 = /** @class */ (function () {
4550
3832
  var match = representation.substr(++index).match(EXPONENT_REGEX);
4551
3833
  // No digits read
4552
3834
  if (!match || !match[2])
4553
- return new Decimal128(buffer.Buffer.from(NAN_BUFFER));
3835
+ return new Decimal128(buffer_1.from(NAN_BUFFER));
4554
3836
  // Get exponent
4555
3837
  exponent = parseInt(match[0], 10);
4556
3838
  // Adjust the index
@@ -4558,7 +3840,7 @@ var Decimal128 = /** @class */ (function () {
4558
3840
  }
4559
3841
  // Return not a number
4560
3842
  if (representation[index])
4561
- return new Decimal128(buffer.Buffer.from(NAN_BUFFER));
3843
+ return new Decimal128(buffer_1.from(NAN_BUFFER));
4562
3844
  // Done reading input
4563
3845
  // Find first non-zero digit in digits
4564
3846
  firstDigit = 0;
@@ -4574,7 +3856,7 @@ var Decimal128 = /** @class */ (function () {
4574
3856
  lastDigit = nDigitsStored - 1;
4575
3857
  significantDigits = nDigits;
4576
3858
  if (significantDigits !== 1) {
4577
- while (representation[firstNonZero + significantDigits - 1] === '0') {
3859
+ while (digits[firstNonZero + significantDigits - 1] === 0) {
4578
3860
  significantDigits = significantDigits - 1;
4579
3861
  }
4580
3862
  }
@@ -4674,7 +3956,7 @@ var Decimal128 = /** @class */ (function () {
4674
3956
  digits[dIdx] = 1;
4675
3957
  }
4676
3958
  else {
4677
- return new Decimal128(buffer.Buffer.from(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
3959
+ return new Decimal128(buffer_1.from(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
4678
3960
  }
4679
3961
  }
4680
3962
  }
@@ -4683,87 +3965,87 @@ var Decimal128 = /** @class */ (function () {
4683
3965
  }
4684
3966
  // Encode significand
4685
3967
  // The high 17 digits of the significand
4686
- significandHigh = long_1.Long.fromNumber(0);
3968
+ significandHigh = Long.fromNumber(0);
4687
3969
  // The low 17 digits of the significand
4688
- significandLow = long_1.Long.fromNumber(0);
3970
+ significandLow = Long.fromNumber(0);
4689
3971
  // read a zero
4690
3972
  if (significantDigits === 0) {
4691
- significandHigh = long_1.Long.fromNumber(0);
4692
- significandLow = long_1.Long.fromNumber(0);
3973
+ significandHigh = Long.fromNumber(0);
3974
+ significandLow = Long.fromNumber(0);
4693
3975
  }
4694
3976
  else if (lastDigit - firstDigit < 17) {
4695
3977
  var dIdx = firstDigit;
4696
- significandLow = long_1.Long.fromNumber(digits[dIdx++]);
4697
- significandHigh = new long_1.Long(0, 0);
3978
+ significandLow = Long.fromNumber(digits[dIdx++]);
3979
+ significandHigh = new Long(0, 0);
4698
3980
  for (; dIdx <= lastDigit; dIdx++) {
4699
- significandLow = significandLow.multiply(long_1.Long.fromNumber(10));
4700
- significandLow = significandLow.add(long_1.Long.fromNumber(digits[dIdx]));
3981
+ significandLow = significandLow.multiply(Long.fromNumber(10));
3982
+ significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
4701
3983
  }
4702
3984
  }
4703
3985
  else {
4704
3986
  var dIdx = firstDigit;
4705
- significandHigh = long_1.Long.fromNumber(digits[dIdx++]);
3987
+ significandHigh = Long.fromNumber(digits[dIdx++]);
4706
3988
  for (; dIdx <= lastDigit - 17; dIdx++) {
4707
- significandHigh = significandHigh.multiply(long_1.Long.fromNumber(10));
4708
- significandHigh = significandHigh.add(long_1.Long.fromNumber(digits[dIdx]));
3989
+ significandHigh = significandHigh.multiply(Long.fromNumber(10));
3990
+ significandHigh = significandHigh.add(Long.fromNumber(digits[dIdx]));
4709
3991
  }
4710
- significandLow = long_1.Long.fromNumber(digits[dIdx++]);
3992
+ significandLow = Long.fromNumber(digits[dIdx++]);
4711
3993
  for (; dIdx <= lastDigit; dIdx++) {
4712
- significandLow = significandLow.multiply(long_1.Long.fromNumber(10));
4713
- significandLow = significandLow.add(long_1.Long.fromNumber(digits[dIdx]));
3994
+ significandLow = significandLow.multiply(Long.fromNumber(10));
3995
+ significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
4714
3996
  }
4715
3997
  }
4716
- var significand = multiply64x2(significandHigh, long_1.Long.fromString('100000000000000000'));
3998
+ var significand = multiply64x2(significandHigh, Long.fromString('100000000000000000'));
4717
3999
  significand.low = significand.low.add(significandLow);
4718
4000
  if (lessThan(significand.low, significandLow)) {
4719
- significand.high = significand.high.add(long_1.Long.fromNumber(1));
4001
+ significand.high = significand.high.add(Long.fromNumber(1));
4720
4002
  }
4721
4003
  // Biased exponent
4722
4004
  biasedExponent = exponent + EXPONENT_BIAS;
4723
- var dec = { low: long_1.Long.fromNumber(0), high: long_1.Long.fromNumber(0) };
4005
+ var dec = { low: Long.fromNumber(0), high: Long.fromNumber(0) };
4724
4006
  // Encode combination, exponent, and significand.
4725
- if (significand.high.shiftRightUnsigned(49).and(long_1.Long.fromNumber(1)).equals(long_1.Long.fromNumber(1))) {
4007
+ if (significand.high.shiftRightUnsigned(49).and(Long.fromNumber(1)).equals(Long.fromNumber(1))) {
4726
4008
  // Encode '11' into bits 1 to 3
4727
- dec.high = dec.high.or(long_1.Long.fromNumber(0x3).shiftLeft(61));
4728
- dec.high = dec.high.or(long_1.Long.fromNumber(biasedExponent).and(long_1.Long.fromNumber(0x3fff).shiftLeft(47)));
4729
- dec.high = dec.high.or(significand.high.and(long_1.Long.fromNumber(0x7fffffffffff)));
4009
+ dec.high = dec.high.or(Long.fromNumber(0x3).shiftLeft(61));
4010
+ dec.high = dec.high.or(Long.fromNumber(biasedExponent).and(Long.fromNumber(0x3fff).shiftLeft(47)));
4011
+ dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x7fffffffffff)));
4730
4012
  }
4731
4013
  else {
4732
- dec.high = dec.high.or(long_1.Long.fromNumber(biasedExponent & 0x3fff).shiftLeft(49));
4733
- dec.high = dec.high.or(significand.high.and(long_1.Long.fromNumber(0x1ffffffffffff)));
4014
+ dec.high = dec.high.or(Long.fromNumber(biasedExponent & 0x3fff).shiftLeft(49));
4015
+ dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x1ffffffffffff)));
4734
4016
  }
4735
4017
  dec.low = significand.low;
4736
4018
  // Encode sign
4737
4019
  if (isNegative) {
4738
- dec.high = dec.high.or(long_1.Long.fromString('9223372036854775808'));
4020
+ dec.high = dec.high.or(Long.fromString('9223372036854775808'));
4739
4021
  }
4740
4022
  // Encode into a buffer
4741
- var buffer$1 = buffer.Buffer.alloc(16);
4023
+ var buffer = buffer_1.alloc(16);
4742
4024
  index = 0;
4743
4025
  // Encode the low 64 bits of the decimal
4744
4026
  // Encode low bits
4745
- buffer$1[index++] = dec.low.low & 0xff;
4746
- buffer$1[index++] = (dec.low.low >> 8) & 0xff;
4747
- buffer$1[index++] = (dec.low.low >> 16) & 0xff;
4748
- buffer$1[index++] = (dec.low.low >> 24) & 0xff;
4027
+ buffer[index++] = dec.low.low & 0xff;
4028
+ buffer[index++] = (dec.low.low >> 8) & 0xff;
4029
+ buffer[index++] = (dec.low.low >> 16) & 0xff;
4030
+ buffer[index++] = (dec.low.low >> 24) & 0xff;
4749
4031
  // Encode high bits
4750
- buffer$1[index++] = dec.low.high & 0xff;
4751
- buffer$1[index++] = (dec.low.high >> 8) & 0xff;
4752
- buffer$1[index++] = (dec.low.high >> 16) & 0xff;
4753
- buffer$1[index++] = (dec.low.high >> 24) & 0xff;
4032
+ buffer[index++] = dec.low.high & 0xff;
4033
+ buffer[index++] = (dec.low.high >> 8) & 0xff;
4034
+ buffer[index++] = (dec.low.high >> 16) & 0xff;
4035
+ buffer[index++] = (dec.low.high >> 24) & 0xff;
4754
4036
  // Encode the high 64 bits of the decimal
4755
4037
  // Encode low bits
4756
- buffer$1[index++] = dec.high.low & 0xff;
4757
- buffer$1[index++] = (dec.high.low >> 8) & 0xff;
4758
- buffer$1[index++] = (dec.high.low >> 16) & 0xff;
4759
- buffer$1[index++] = (dec.high.low >> 24) & 0xff;
4038
+ buffer[index++] = dec.high.low & 0xff;
4039
+ buffer[index++] = (dec.high.low >> 8) & 0xff;
4040
+ buffer[index++] = (dec.high.low >> 16) & 0xff;
4041
+ buffer[index++] = (dec.high.low >> 24) & 0xff;
4760
4042
  // Encode high bits
4761
- buffer$1[index++] = dec.high.high & 0xff;
4762
- buffer$1[index++] = (dec.high.high >> 8) & 0xff;
4763
- buffer$1[index++] = (dec.high.high >> 16) & 0xff;
4764
- buffer$1[index++] = (dec.high.high >> 24) & 0xff;
4043
+ buffer[index++] = dec.high.high & 0xff;
4044
+ buffer[index++] = (dec.high.high >> 8) & 0xff;
4045
+ buffer[index++] = (dec.high.high >> 16) & 0xff;
4046
+ buffer[index++] = (dec.high.high >> 24) & 0xff;
4765
4047
  // Return the new Decimal128
4766
- return new Decimal128(buffer$1);
4048
+ return new Decimal128(buffer);
4767
4049
  };
4768
4050
  /** Create a string representation of the raw Decimal128 value */
4769
4051
  Decimal128.prototype.toString = function () {
@@ -4807,10 +4089,10 @@ var Decimal128 = /** @class */ (function () {
4807
4089
  index = 0;
4808
4090
  // Create the state of the decimal
4809
4091
  var dec = {
4810
- low: new long_1.Long(low, midl),
4811
- high: new long_1.Long(midh, high)
4092
+ low: new Long(low, midl),
4093
+ high: new Long(midh, high)
4812
4094
  };
4813
- if (dec.high.lessThan(long_1.Long.ZERO)) {
4095
+ if (dec.high.lessThan(Long.ZERO)) {
4814
4096
  string.push('-');
4815
4097
  }
4816
4098
  // Decode combination field and exponent
@@ -4971,17 +4253,8 @@ var Decimal128 = /** @class */ (function () {
4971
4253
  };
4972
4254
  return Decimal128;
4973
4255
  }());
4974
- exports.Decimal128 = Decimal128;
4975
4256
  Object.defineProperty(Decimal128.prototype, '_bsontype', { value: 'Decimal128' });
4976
- //# sourceMappingURL=decimal128.js.map
4977
- });
4978
4257
 
4979
- unwrapExports(decimal128);
4980
- decimal128.Decimal128;
4981
-
4982
- var double_1 = createCommonjsModule(function (module, exports) {
4983
- Object.defineProperty(exports, "__esModule", { value: true });
4984
- exports.Double = void 0;
4985
4258
  /**
4986
4259
  * A class representation of the BSON Double type.
4987
4260
  * @public
@@ -5008,10 +4281,12 @@ var Double = /** @class */ (function () {
5008
4281
  Double.prototype.valueOf = function () {
5009
4282
  return this.value;
5010
4283
  };
5011
- /** @internal */
5012
4284
  Double.prototype.toJSON = function () {
5013
4285
  return this.value;
5014
4286
  };
4287
+ Double.prototype.toString = function (radix) {
4288
+ return this.value.toString(radix);
4289
+ };
5015
4290
  /** @internal */
5016
4291
  Double.prototype.toExtendedJSON = function (options) {
5017
4292
  if (options && (options.legacy || (options.relaxed && isFinite(this.value)))) {
@@ -5049,17 +4324,8 @@ var Double = /** @class */ (function () {
5049
4324
  };
5050
4325
  return Double;
5051
4326
  }());
5052
- exports.Double = Double;
5053
4327
  Object.defineProperty(Double.prototype, '_bsontype', { value: 'Double' });
5054
- //# sourceMappingURL=double.js.map
5055
- });
5056
4328
 
5057
- unwrapExports(double_1);
5058
- double_1.Double;
5059
-
5060
- var int_32 = createCommonjsModule(function (module, exports) {
5061
- Object.defineProperty(exports, "__esModule", { value: true });
5062
- exports.Int32 = void 0;
5063
4329
  /**
5064
4330
  * A class representation of a BSON Int32 type.
5065
4331
  * @public
@@ -5086,7 +4352,9 @@ var Int32 = /** @class */ (function () {
5086
4352
  Int32.prototype.valueOf = function () {
5087
4353
  return this.value;
5088
4354
  };
5089
- /** @internal */
4355
+ Int32.prototype.toString = function (radix) {
4356
+ return this.value.toString(radix);
4357
+ };
5090
4358
  Int32.prototype.toJSON = function () {
5091
4359
  return this.value;
5092
4360
  };
@@ -5109,17 +4377,8 @@ var Int32 = /** @class */ (function () {
5109
4377
  };
5110
4378
  return Int32;
5111
4379
  }());
5112
- exports.Int32 = Int32;
5113
4380
  Object.defineProperty(Int32.prototype, '_bsontype', { value: 'Int32' });
5114
- //# sourceMappingURL=int_32.js.map
5115
- });
5116
-
5117
- unwrapExports(int_32);
5118
- int_32.Int32;
5119
4381
 
5120
- var max_key = createCommonjsModule(function (module, exports) {
5121
- Object.defineProperty(exports, "__esModule", { value: true });
5122
- exports.MaxKey = void 0;
5123
4382
  /**
5124
4383
  * A class representation of the BSON MaxKey type.
5125
4384
  * @public
@@ -5146,17 +4405,8 @@ var MaxKey = /** @class */ (function () {
5146
4405
  };
5147
4406
  return MaxKey;
5148
4407
  }());
5149
- exports.MaxKey = MaxKey;
5150
4408
  Object.defineProperty(MaxKey.prototype, '_bsontype', { value: 'MaxKey' });
5151
- //# sourceMappingURL=max_key.js.map
5152
- });
5153
-
5154
- unwrapExports(max_key);
5155
- max_key.MaxKey;
5156
4409
 
5157
- var min_key = createCommonjsModule(function (module, exports) {
5158
- Object.defineProperty(exports, "__esModule", { value: true });
5159
- exports.MinKey = void 0;
5160
4410
  /**
5161
4411
  * A class representation of the BSON MinKey type.
5162
4412
  * @public
@@ -5183,19 +4433,7 @@ var MinKey = /** @class */ (function () {
5183
4433
  };
5184
4434
  return MinKey;
5185
4435
  }());
5186
- exports.MinKey = MinKey;
5187
4436
  Object.defineProperty(MinKey.prototype, '_bsontype', { value: 'MinKey' });
5188
- //# sourceMappingURL=min_key.js.map
5189
- });
5190
-
5191
- unwrapExports(min_key);
5192
- min_key.MinKey;
5193
-
5194
- var objectid = createCommonjsModule(function (module, exports) {
5195
- Object.defineProperty(exports, "__esModule", { value: true });
5196
- exports.ObjectId = void 0;
5197
-
5198
-
5199
4437
 
5200
4438
  // Regular expression that checks for hex value
5201
4439
  var checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');
@@ -5222,10 +4460,10 @@ var ObjectId = /** @class */ (function () {
5222
4460
  }
5223
4461
  if (typeof id === 'object' && id && 'id' in id) {
5224
4462
  if ('toHexString' in id && typeof id.toHexString === 'function') {
5225
- this[kId] = buffer.Buffer.from(id.toHexString(), 'hex');
4463
+ this[kId] = buffer_1.from(id.toHexString(), 'hex');
5226
4464
  }
5227
4465
  else {
5228
- this[kId] = typeof id.id === 'string' ? buffer.Buffer.from(id.id) : id.id;
4466
+ this[kId] = typeof id.id === 'string' ? buffer_1.from(id.id) : id.id;
5229
4467
  }
5230
4468
  }
5231
4469
  // The most common use case (blank id, new objectId instance)
@@ -5238,17 +4476,17 @@ var ObjectId = /** @class */ (function () {
5238
4476
  }
5239
4477
  }
5240
4478
  if (ArrayBuffer.isView(id) && id.byteLength === 12) {
5241
- this[kId] = ensure_buffer.ensureBuffer(id);
4479
+ this[kId] = ensureBuffer(id);
5242
4480
  }
5243
4481
  if (typeof id === 'string') {
5244
4482
  if (id.length === 12) {
5245
- var bytes = buffer.Buffer.from(id);
4483
+ var bytes = buffer_1.from(id);
5246
4484
  if (bytes.byteLength === 12) {
5247
4485
  this[kId] = bytes;
5248
4486
  }
5249
4487
  }
5250
4488
  else if (id.length === 24 && checkForHexRegExp.test(id)) {
5251
- this[kId] = buffer.Buffer.from(id, 'hex');
4489
+ this[kId] = buffer_1.from(id, 'hex');
5252
4490
  }
5253
4491
  else {
5254
4492
  throw new TypeError('Argument passed in must be a Buffer or string of 12 bytes or a string of 24 hex characters');
@@ -5320,30 +4558,29 @@ var ObjectId = /** @class */ (function () {
5320
4558
  time = ~~(Date.now() / 1000);
5321
4559
  }
5322
4560
  var inc = ObjectId.getInc();
5323
- var buffer$1 = buffer.Buffer.alloc(12);
4561
+ var buffer = buffer_1.alloc(12);
5324
4562
  // 4-byte timestamp
5325
- buffer$1.writeUInt32BE(time, 0);
4563
+ buffer.writeUInt32BE(time, 0);
5326
4564
  // set PROCESS_UNIQUE if yet not initialized
5327
4565
  if (PROCESS_UNIQUE === null) {
5328
- PROCESS_UNIQUE = utils.randomBytes(5);
4566
+ PROCESS_UNIQUE = randomBytes(5);
5329
4567
  }
5330
4568
  // 5-byte process unique
5331
- buffer$1[4] = PROCESS_UNIQUE[0];
5332
- buffer$1[5] = PROCESS_UNIQUE[1];
5333
- buffer$1[6] = PROCESS_UNIQUE[2];
5334
- buffer$1[7] = PROCESS_UNIQUE[3];
5335
- buffer$1[8] = PROCESS_UNIQUE[4];
4569
+ buffer[4] = PROCESS_UNIQUE[0];
4570
+ buffer[5] = PROCESS_UNIQUE[1];
4571
+ buffer[6] = PROCESS_UNIQUE[2];
4572
+ buffer[7] = PROCESS_UNIQUE[3];
4573
+ buffer[8] = PROCESS_UNIQUE[4];
5336
4574
  // 3-byte counter
5337
- buffer$1[11] = inc & 0xff;
5338
- buffer$1[10] = (inc >> 8) & 0xff;
5339
- buffer$1[9] = (inc >> 16) & 0xff;
5340
- return buffer$1;
4575
+ buffer[11] = inc & 0xff;
4576
+ buffer[10] = (inc >> 8) & 0xff;
4577
+ buffer[9] = (inc >> 16) & 0xff;
4578
+ return buffer;
5341
4579
  };
5342
4580
  /**
5343
4581
  * Converts the id into a 24 character hex string for printing
5344
4582
  *
5345
4583
  * @param format - The Buffer toString format parameter.
5346
- * @internal
5347
4584
  */
5348
4585
  ObjectId.prototype.toString = function (format) {
5349
4586
  // Is the id a buffer then use the buffer toString method to return the format
@@ -5351,10 +4588,7 @@ var ObjectId = /** @class */ (function () {
5351
4588
  return this.id.toString(format);
5352
4589
  return this.toHexString();
5353
4590
  };
5354
- /**
5355
- * Converts to its JSON the 24 character hex string representation.
5356
- * @internal
5357
- */
4591
+ /** Converts to its JSON the 24 character hex string representation. */
5358
4592
  ObjectId.prototype.toJSON = function () {
5359
4593
  return this.toHexString();
5360
4594
  };
@@ -5373,14 +4607,14 @@ var ObjectId = /** @class */ (function () {
5373
4607
  if (typeof otherId === 'string' &&
5374
4608
  ObjectId.isValid(otherId) &&
5375
4609
  otherId.length === 12 &&
5376
- utils.isUint8Array(this.id)) {
5377
- return otherId === buffer.Buffer.prototype.toString.call(this.id, 'latin1');
4610
+ isUint8Array(this.id)) {
4611
+ return otherId === buffer_1.prototype.toString.call(this.id, 'latin1');
5378
4612
  }
5379
4613
  if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 24) {
5380
4614
  return otherId.toLowerCase() === this.toHexString();
5381
4615
  }
5382
4616
  if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 12) {
5383
- return buffer.Buffer.from(otherId).equals(this.id);
4617
+ return buffer_1.from(otherId).equals(this.id);
5384
4618
  }
5385
4619
  if (typeof otherId === 'object' &&
5386
4620
  'toHexString' in otherId &&
@@ -5406,11 +4640,11 @@ var ObjectId = /** @class */ (function () {
5406
4640
  * @param time - an integer number representing a number of seconds.
5407
4641
  */
5408
4642
  ObjectId.createFromTime = function (time) {
5409
- var buffer$1 = buffer.Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
4643
+ var buffer = buffer_1.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
5410
4644
  // Encode time into first 4 bytes
5411
- buffer$1.writeUInt32BE(time, 0);
4645
+ buffer.writeUInt32BE(time, 0);
5412
4646
  // Return the new objectId
5413
- return new ObjectId(buffer$1);
4647
+ return new ObjectId(buffer);
5414
4648
  };
5415
4649
  /**
5416
4650
  * Creates an ObjectId from a hex string representation of an ObjectId.
@@ -5422,7 +4656,7 @@ var ObjectId = /** @class */ (function () {
5422
4656
  if (typeof hexString === 'undefined' || (hexString != null && hexString.length !== 24)) {
5423
4657
  throw new TypeError('Argument passed in must be a single String of 12 bytes or a string of 24 hex characters');
5424
4658
  }
5425
- return new ObjectId(buffer.Buffer.from(hexString, 'hex'));
4659
+ return new ObjectId(buffer_1.from(hexString, 'hex'));
5426
4660
  };
5427
4661
  /**
5428
4662
  * Checks if a value is a valid bson ObjectId
@@ -5441,7 +4675,7 @@ var ObjectId = /** @class */ (function () {
5441
4675
  if (id instanceof ObjectId) {
5442
4676
  return true;
5443
4677
  }
5444
- if (utils.isUint8Array(id) && id.length === 12) {
4678
+ if (isUint8Array(id) && id.length === 12) {
5445
4679
  return true;
5446
4680
  }
5447
4681
  // Duck-Typing detection of ObjectId like objects
@@ -5479,30 +4713,21 @@ var ObjectId = /** @class */ (function () {
5479
4713
  ObjectId.index = ~~(Math.random() * 0xffffff);
5480
4714
  return ObjectId;
5481
4715
  }());
5482
- exports.ObjectId = ObjectId;
5483
4716
  // Deprecated methods
5484
4717
  Object.defineProperty(ObjectId.prototype, 'generate', {
5485
- value: utils.deprecate(function (time) { return ObjectId.generate(time); }, 'Please use the static `ObjectId.generate(time)` instead')
4718
+ value: deprecate(function (time) { return ObjectId.generate(time); }, 'Please use the static `ObjectId.generate(time)` instead')
5486
4719
  });
5487
4720
  Object.defineProperty(ObjectId.prototype, 'getInc', {
5488
- value: utils.deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead')
4721
+ value: deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead')
5489
4722
  });
5490
4723
  Object.defineProperty(ObjectId.prototype, 'get_inc', {
5491
- value: utils.deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead')
4724
+ value: deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead')
5492
4725
  });
5493
4726
  Object.defineProperty(ObjectId, 'get_inc', {
5494
- value: utils.deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead')
4727
+ value: deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead')
5495
4728
  });
5496
4729
  Object.defineProperty(ObjectId.prototype, '_bsontype', { value: 'ObjectID' });
5497
- //# sourceMappingURL=objectid.js.map
5498
- });
5499
-
5500
- unwrapExports(objectid);
5501
- objectid.ObjectId;
5502
4730
 
5503
- var regexp = createCommonjsModule(function (module, exports) {
5504
- Object.defineProperty(exports, "__esModule", { value: true });
5505
- exports.BSONRegExp = void 0;
5506
4731
  function alphabetize(str) {
5507
4732
  return str.split('').sort().join('');
5508
4733
  }
@@ -5519,9 +4744,7 @@ var BSONRegExp = /** @class */ (function () {
5519
4744
  if (!(this instanceof BSONRegExp))
5520
4745
  return new BSONRegExp(pattern, options);
5521
4746
  this.pattern = pattern;
5522
- this.options = options !== null && options !== void 0 ? options : '';
5523
- // Execute
5524
- alphabetize(this.options);
4747
+ this.options = alphabetize(options !== null && options !== void 0 ? options : '');
5525
4748
  // Validate options
5526
4749
  for (var i = 0; i < this.options.length; i++) {
5527
4750
  if (!(this.options[i] === 'i' ||
@@ -5565,17 +4788,8 @@ var BSONRegExp = /** @class */ (function () {
5565
4788
  };
5566
4789
  return BSONRegExp;
5567
4790
  }());
5568
- exports.BSONRegExp = BSONRegExp;
5569
4791
  Object.defineProperty(BSONRegExp.prototype, '_bsontype', { value: 'BSONRegExp' });
5570
- //# sourceMappingURL=regexp.js.map
5571
- });
5572
-
5573
- unwrapExports(regexp);
5574
- regexp.BSONRegExp;
5575
4792
 
5576
- var symbol = createCommonjsModule(function (module, exports) {
5577
- Object.defineProperty(exports, "__esModule", { value: true });
5578
- exports.BSONSymbol = void 0;
5579
4793
  /**
5580
4794
  * A class representation of the BSON Symbol type.
5581
4795
  * @public
@@ -5593,7 +4807,6 @@ var BSONSymbol = /** @class */ (function () {
5593
4807
  BSONSymbol.prototype.valueOf = function () {
5594
4808
  return this.value;
5595
4809
  };
5596
- /** @internal */
5597
4810
  BSONSymbol.prototype.toString = function () {
5598
4811
  return this.value;
5599
4812
  };
@@ -5601,7 +4814,6 @@ var BSONSymbol = /** @class */ (function () {
5601
4814
  BSONSymbol.prototype.inspect = function () {
5602
4815
  return "new BSONSymbol(\"" + this.value + "\")";
5603
4816
  };
5604
- /** @internal */
5605
4817
  BSONSymbol.prototype.toJSON = function () {
5606
4818
  return this.value;
5607
4819
  };
@@ -5619,13 +4831,7 @@ var BSONSymbol = /** @class */ (function () {
5619
4831
  };
5620
4832
  return BSONSymbol;
5621
4833
  }());
5622
- exports.BSONSymbol = BSONSymbol;
5623
4834
  Object.defineProperty(BSONSymbol.prototype, '_bsontype', { value: 'Symbol' });
5624
- //# sourceMappingURL=symbol.js.map
5625
- });
5626
-
5627
- unwrapExports(symbol);
5628
- symbol.BSONSymbol;
5629
4835
 
5630
4836
  /*! *****************************************************************************
5631
4837
  Copyright (c) Microsoft Corporation.
@@ -5667,435 +4873,23 @@ function __extends(d, b) {
5667
4873
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
5668
4874
  }
5669
4875
 
5670
- var _assign = function __assign() {
5671
- _assign = Object.assign || function __assign(t) {
5672
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5673
- s = arguments[i];
5674
-
5675
- for (var p in s) {
5676
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
5677
- }
5678
- }
5679
-
5680
- return t;
5681
- };
5682
-
5683
- return _assign.apply(this, arguments);
5684
- };
5685
- function __rest(s, e) {
5686
- var t = {};
5687
-
5688
- for (var p in s) {
5689
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
5690
- }
5691
-
5692
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
5693
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
5694
- }
5695
- return t;
5696
- }
5697
- function __decorate(decorators, target, key, desc) {
5698
- var c = arguments.length,
5699
- r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
5700
- d;
5701
- 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--) {
5702
- if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5703
- }
5704
- return c > 3 && r && Object.defineProperty(target, key, r), r;
5705
- }
5706
- function __param(paramIndex, decorator) {
5707
- return function (target, key) {
5708
- decorator(target, key, paramIndex);
5709
- };
5710
- }
5711
- function __metadata(metadataKey, metadataValue) {
5712
- if ((typeof Reflect === "undefined" ? "undefined" : babelHelpers["typeof"](Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
5713
- }
5714
- function __awaiter(thisArg, _arguments, P, generator) {
5715
- function adopt(value) {
5716
- return value instanceof P ? value : new P(function (resolve) {
5717
- resolve(value);
5718
- });
5719
- }
5720
-
5721
- return new (P || (P = Promise))(function (resolve, reject) {
5722
- function fulfilled(value) {
5723
- try {
5724
- step(generator.next(value));
5725
- } catch (e) {
5726
- reject(e);
5727
- }
5728
- }
5729
-
5730
- function rejected(value) {
5731
- try {
5732
- step(generator["throw"](value));
5733
- } catch (e) {
5734
- reject(e);
5735
- }
5736
- }
5737
-
5738
- function step(result) {
5739
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
5740
- }
5741
-
5742
- step((generator = generator.apply(thisArg, _arguments || [])).next());
5743
- });
5744
- }
5745
- function __generator(thisArg, body) {
5746
- var _ = {
5747
- label: 0,
5748
- sent: function sent() {
5749
- if (t[0] & 1) throw t[1];
5750
- return t[1];
5751
- },
5752
- trys: [],
5753
- ops: []
5754
- },
5755
- f,
5756
- y,
5757
- t,
5758
- g;
5759
- return g = {
5760
- next: verb(0),
5761
- "throw": verb(1),
5762
- "return": verb(2)
5763
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
5764
- return this;
5765
- }), g;
5766
-
5767
- function verb(n) {
5768
- return function (v) {
5769
- return step([n, v]);
5770
- };
5771
- }
5772
-
5773
- function step(op) {
5774
- if (f) throw new TypeError("Generator is already executing.");
5775
-
5776
- while (_) {
5777
- try {
5778
- 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;
5779
- if (y = 0, t) op = [op[0] & 2, t.value];
5780
-
5781
- switch (op[0]) {
5782
- case 0:
5783
- case 1:
5784
- t = op;
5785
- break;
5786
-
5787
- case 4:
5788
- _.label++;
5789
- return {
5790
- value: op[1],
5791
- done: false
5792
- };
5793
-
5794
- case 5:
5795
- _.label++;
5796
- y = op[1];
5797
- op = [0];
5798
- continue;
5799
-
5800
- case 7:
5801
- op = _.ops.pop();
5802
-
5803
- _.trys.pop();
5804
-
5805
- continue;
5806
-
5807
- default:
5808
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
5809
- _ = 0;
5810
- continue;
5811
- }
5812
-
5813
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
5814
- _.label = op[1];
5815
- break;
5816
- }
5817
-
5818
- if (op[0] === 6 && _.label < t[1]) {
5819
- _.label = t[1];
5820
- t = op;
5821
- break;
5822
- }
5823
-
5824
- if (t && _.label < t[2]) {
5825
- _.label = t[2];
5826
-
5827
- _.ops.push(op);
5828
-
5829
- break;
5830
- }
5831
-
5832
- if (t[2]) _.ops.pop();
5833
-
5834
- _.trys.pop();
5835
-
5836
- continue;
5837
- }
5838
-
5839
- op = body.call(thisArg, _);
5840
- } catch (e) {
5841
- op = [6, e];
5842
- y = 0;
5843
- } finally {
5844
- f = t = 0;
5845
- }
5846
- }
5847
-
5848
- if (op[0] & 5) throw op[1];
5849
- return {
5850
- value: op[0] ? op[1] : void 0,
5851
- done: true
5852
- };
5853
- }
5854
- }
5855
- function __createBinding(o, m, k, k2) {
5856
- if (k2 === undefined) k2 = k;
5857
- o[k2] = m[k];
5858
- }
5859
- function __exportStar(m, exports) {
5860
- for (var p in m) {
5861
- if (p !== "default" && !exports.hasOwnProperty(p)) exports[p] = m[p];
5862
- }
5863
- }
5864
- function __values(o) {
5865
- var s = typeof Symbol === "function" && Symbol.iterator,
5866
- m = s && o[s],
5867
- i = 0;
5868
- if (m) return m.call(o);
5869
- if (o && typeof o.length === "number") return {
5870
- next: function next() {
5871
- if (o && i >= o.length) o = void 0;
5872
- return {
5873
- value: o && o[i++],
5874
- done: !o
5875
- };
5876
- }
5877
- };
5878
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
5879
- }
5880
- function __read(o, n) {
5881
- var m = typeof Symbol === "function" && o[Symbol.iterator];
5882
- if (!m) return o;
5883
- var i = m.call(o),
5884
- r,
5885
- ar = [],
5886
- e;
5887
-
5888
- try {
5889
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
5890
- ar.push(r.value);
5891
- }
5892
- } catch (error) {
5893
- e = {
5894
- error: error
5895
- };
5896
- } finally {
5897
- try {
5898
- if (r && !r.done && (m = i["return"])) m.call(i);
5899
- } finally {
5900
- if (e) throw e.error;
5901
- }
5902
- }
5903
-
5904
- return ar;
5905
- }
5906
- function __spread() {
5907
- for (var ar = [], i = 0; i < arguments.length; i++) {
5908
- ar = ar.concat(__read(arguments[i]));
5909
- }
5910
-
5911
- return ar;
5912
- }
5913
- function __spreadArrays() {
5914
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) {
5915
- s += arguments[i].length;
5916
- }
5917
-
5918
- for (var r = Array(s), k = 0, i = 0; i < il; i++) {
5919
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) {
5920
- r[k] = a[j];
5921
- }
5922
- }
5923
-
5924
- return r;
5925
- }
5926
- function __await(v) {
5927
- return this instanceof __await ? (this.v = v, this) : new __await(v);
5928
- }
5929
- function __asyncGenerator(thisArg, _arguments, generator) {
5930
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
5931
- var g = generator.apply(thisArg, _arguments || []),
5932
- i,
5933
- q = [];
5934
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
5935
- return this;
5936
- }, i;
5937
-
5938
- function verb(n) {
5939
- if (g[n]) i[n] = function (v) {
5940
- return new Promise(function (a, b) {
5941
- q.push([n, v, a, b]) > 1 || resume(n, v);
5942
- });
5943
- };
5944
- }
5945
-
5946
- function resume(n, v) {
5947
- try {
5948
- step(g[n](v));
5949
- } catch (e) {
5950
- settle(q[0][3], e);
5951
- }
5952
- }
5953
-
5954
- function step(r) {
5955
- r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
5956
- }
5957
-
5958
- function fulfill(value) {
5959
- resume("next", value);
5960
- }
5961
-
5962
- function reject(value) {
5963
- resume("throw", value);
5964
- }
5965
-
5966
- function settle(f, v) {
5967
- if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
5968
- }
5969
- }
5970
- function __asyncDelegator(o) {
5971
- var i, p;
5972
- return i = {}, verb("next"), verb("throw", function (e) {
5973
- throw e;
5974
- }), verb("return"), i[Symbol.iterator] = function () {
5975
- return this;
5976
- }, i;
5977
-
5978
- function verb(n, f) {
5979
- i[n] = o[n] ? function (v) {
5980
- return (p = !p) ? {
5981
- value: __await(o[n](v)),
5982
- done: n === "return"
5983
- } : f ? f(v) : v;
5984
- } : f;
5985
- }
5986
- }
5987
- function __asyncValues(o) {
5988
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
5989
- var m = o[Symbol.asyncIterator],
5990
- i;
5991
- 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 () {
5992
- return this;
5993
- }, i);
5994
-
5995
- function verb(n) {
5996
- i[n] = o[n] && function (v) {
5997
- return new Promise(function (resolve, reject) {
5998
- v = o[n](v), settle(resolve, reject, v.done, v.value);
5999
- });
6000
- };
6001
- }
6002
-
6003
- function settle(resolve, reject, d, v) {
6004
- Promise.resolve(v).then(function (v) {
6005
- resolve({
6006
- value: v,
6007
- done: d
6008
- });
6009
- }, reject);
6010
- }
6011
- }
6012
- function __makeTemplateObject(cooked, raw) {
6013
- if (Object.defineProperty) {
6014
- Object.defineProperty(cooked, "raw", {
6015
- value: raw
6016
- });
6017
- } else {
6018
- cooked.raw = raw;
6019
- }
6020
-
6021
- return cooked;
6022
- }
6023
- function __importStar(mod) {
6024
- if (mod && mod.__esModule) return mod;
6025
- var result = {};
6026
- if (mod != null) for (var k in mod) {
6027
- if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
6028
- }
6029
- result["default"] = mod;
6030
- return result;
6031
- }
6032
- function __importDefault(mod) {
6033
- return mod && mod.__esModule ? mod : {
6034
- "default": mod
6035
- };
6036
- }
6037
- function __classPrivateFieldGet(receiver, privateMap) {
6038
- if (!privateMap.has(receiver)) {
6039
- throw new TypeError("attempted to get private field on non-instance");
6040
- }
6041
-
6042
- return privateMap.get(receiver);
6043
- }
6044
- function __classPrivateFieldSet(receiver, privateMap, value) {
6045
- if (!privateMap.has(receiver)) {
6046
- throw new TypeError("attempted to set private field on non-instance");
6047
- }
6048
-
6049
- privateMap.set(receiver, value);
6050
- return value;
6051
- }
6052
-
6053
- var tslib_es6 = /*#__PURE__*/Object.freeze({
6054
- __proto__: null,
6055
- __extends: __extends,
6056
- get __assign () { return _assign; },
6057
- __rest: __rest,
6058
- __decorate: __decorate,
6059
- __param: __param,
6060
- __metadata: __metadata,
6061
- __awaiter: __awaiter,
6062
- __generator: __generator,
6063
- __createBinding: __createBinding,
6064
- __exportStar: __exportStar,
6065
- __values: __values,
6066
- __read: __read,
6067
- __spread: __spread,
6068
- __spreadArrays: __spreadArrays,
6069
- __await: __await,
6070
- __asyncGenerator: __asyncGenerator,
6071
- __asyncDelegator: __asyncDelegator,
6072
- __asyncValues: __asyncValues,
6073
- __makeTemplateObject: __makeTemplateObject,
6074
- __importStar: __importStar,
6075
- __importDefault: __importDefault,
6076
- __classPrivateFieldGet: __classPrivateFieldGet,
6077
- __classPrivateFieldSet: __classPrivateFieldSet
6078
- });
6079
-
6080
- var timestamp = createCommonjsModule(function (module, exports) {
6081
- Object.defineProperty(exports, "__esModule", { value: true });
6082
- exports.Timestamp = exports.LongWithoutOverridesClass = void 0;
6083
-
6084
-
6085
4876
  /** @public */
6086
- exports.LongWithoutOverridesClass = long_1.Long;
4877
+ var LongWithoutOverridesClass = Long;
6087
4878
  /** @public */
6088
4879
  var Timestamp = /** @class */ (function (_super) {
6089
- tslib_es6.__extends(Timestamp, _super);
4880
+ __extends(Timestamp, _super);
6090
4881
  function Timestamp(low, high) {
6091
4882
  var _this = this;
6092
4883
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6093
4884
  ///@ts-expect-error
6094
4885
  if (!(_this instanceof Timestamp))
6095
4886
  return new Timestamp(low, high);
6096
- if (long_1.Long.isLong(low)) {
4887
+ if (Long.isLong(low)) {
6097
4888
  _this = _super.call(this, low.low, low.high, true) || this;
6098
4889
  }
4890
+ else if (isObjectLike(low) && typeof low.t !== 'undefined' && typeof low.i !== 'undefined') {
4891
+ _this = _super.call(this, low.i, low.t, true) || this;
4892
+ }
6099
4893
  else {
6100
4894
  _this = _super.call(this, low, high, true) || this;
6101
4895
  }
@@ -6114,11 +4908,11 @@ var Timestamp = /** @class */ (function (_super) {
6114
4908
  };
6115
4909
  /** Returns a Timestamp represented by the given (32-bit) integer value. */
6116
4910
  Timestamp.fromInt = function (value) {
6117
- return new Timestamp(long_1.Long.fromInt(value, true));
4911
+ return new Timestamp(Long.fromInt(value, true));
6118
4912
  };
6119
4913
  /** Returns a Timestamp representing the given number value, provided that it is a finite number. Otherwise, zero is returned. */
6120
4914
  Timestamp.fromNumber = function (value) {
6121
- return new Timestamp(long_1.Long.fromNumber(value, true));
4915
+ return new Timestamp(Long.fromNumber(value, true));
6122
4916
  };
6123
4917
  /**
6124
4918
  * Returns a Timestamp for the given high and low bits. Each is assumed to use 32 bits.
@@ -6136,7 +4930,7 @@ var Timestamp = /** @class */ (function (_super) {
6136
4930
  * @param optRadix - the radix in which the text is written.
6137
4931
  */
6138
4932
  Timestamp.fromString = function (str, optRadix) {
6139
- return new Timestamp(long_1.Long.fromString(str, true, optRadix));
4933
+ return new Timestamp(Long.fromString(str, true, optRadix));
6140
4934
  };
6141
4935
  /** @internal */
6142
4936
  Timestamp.prototype.toExtendedJSON = function () {
@@ -6144,69 +4938,44 @@ var Timestamp = /** @class */ (function (_super) {
6144
4938
  };
6145
4939
  /** @internal */
6146
4940
  Timestamp.fromExtendedJSON = function (doc) {
6147
- return new Timestamp(doc.$timestamp.i, doc.$timestamp.t);
4941
+ return new Timestamp(doc.$timestamp);
6148
4942
  };
6149
4943
  /** @internal */
6150
4944
  Timestamp.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
6151
4945
  return this.inspect();
6152
4946
  };
6153
4947
  Timestamp.prototype.inspect = function () {
6154
- return "new Timestamp(" + this.getLowBits().toString() + ", " + this.getHighBits().toString() + ")";
4948
+ return "new Timestamp({ t: " + this.getHighBits() + ", i: " + this.getLowBits() + " })";
6155
4949
  };
6156
- Timestamp.MAX_VALUE = long_1.Long.MAX_UNSIGNED_VALUE;
4950
+ Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
6157
4951
  return Timestamp;
6158
- }(exports.LongWithoutOverridesClass));
6159
- exports.Timestamp = Timestamp;
6160
- //# sourceMappingURL=timestamp.js.map
6161
- });
6162
-
6163
- unwrapExports(timestamp);
6164
- timestamp.Timestamp;
6165
- timestamp.LongWithoutOverridesClass;
6166
-
6167
- var extended_json = createCommonjsModule(function (module, exports) {
6168
- Object.defineProperty(exports, "__esModule", { value: true });
6169
- exports.EJSON = exports.isBSONType = void 0;
6170
-
6171
-
6172
-
6173
-
6174
-
6175
-
6176
-
6177
-
6178
-
6179
-
6180
-
6181
-
6182
-
4952
+ }(LongWithoutOverridesClass));
6183
4953
 
6184
4954
  function isBSONType(value) {
6185
- return (utils.isObjectLike(value) && Reflect.has(value, '_bsontype') && typeof value._bsontype === 'string');
4955
+ return (isObjectLike(value) && Reflect.has(value, '_bsontype') && typeof value._bsontype === 'string');
6186
4956
  }
6187
- exports.isBSONType = isBSONType;
6188
4957
  // INT32 boundaries
6189
- var BSON_INT32_MAX = 0x7fffffff;
6190
- var BSON_INT32_MIN = -0x80000000;
4958
+ var BSON_INT32_MAX$1 = 0x7fffffff;
4959
+ var BSON_INT32_MIN$1 = -0x80000000;
6191
4960
  // INT64 boundaries
6192
- var BSON_INT64_MAX = 0x7fffffffffffffff;
6193
- var BSON_INT64_MIN = -0x8000000000000000;
4961
+ var BSON_INT64_MAX$1 = 0x7fffffffffffffff;
4962
+ var BSON_INT64_MIN$1 = -0x8000000000000000;
6194
4963
  // all the types where we don't need to do any special processing and can just pass the EJSON
6195
4964
  //straight to type.fromExtendedJSON
6196
4965
  var keysToCodecs = {
6197
- $oid: objectid.ObjectId,
6198
- $binary: binary.Binary,
6199
- $uuid: binary.Binary,
6200
- $symbol: symbol.BSONSymbol,
6201
- $numberInt: int_32.Int32,
6202
- $numberDecimal: decimal128.Decimal128,
6203
- $numberDouble: double_1.Double,
6204
- $numberLong: long_1.Long,
6205
- $minKey: min_key.MinKey,
6206
- $maxKey: max_key.MaxKey,
6207
- $regex: regexp.BSONRegExp,
6208
- $regularExpression: regexp.BSONRegExp,
6209
- $timestamp: timestamp.Timestamp
4966
+ $oid: ObjectId,
4967
+ $binary: Binary,
4968
+ $uuid: Binary,
4969
+ $symbol: BSONSymbol,
4970
+ $numberInt: Int32,
4971
+ $numberDecimal: Decimal128,
4972
+ $numberDouble: Double,
4973
+ $numberLong: Long,
4974
+ $minKey: MinKey,
4975
+ $maxKey: MaxKey,
4976
+ $regex: BSONRegExp,
4977
+ $regularExpression: BSONRegExp,
4978
+ $timestamp: Timestamp
6210
4979
  };
6211
4980
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6212
4981
  function deserializeValue(value, options) {
@@ -6218,13 +4987,13 @@ function deserializeValue(value, options) {
6218
4987
  // if it's an integer, should interpret as smallest BSON integer
6219
4988
  // that can represent it exactly. (if out of range, interpret as double.)
6220
4989
  if (Math.floor(value) === value) {
6221
- if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX)
6222
- return new int_32.Int32(value);
6223
- if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX)
6224
- return long_1.Long.fromNumber(value);
4990
+ if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1)
4991
+ return new Int32(value);
4992
+ if (value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1)
4993
+ return Long.fromNumber(value);
6225
4994
  }
6226
4995
  // If the number is a non-integer or out of integer range, should interpret as BSON Double.
6227
- return new double_1.Double(value);
4996
+ return new Double(value);
6228
4997
  }
6229
4998
  // from here on out we're looking for bson types, so bail if its not an object
6230
4999
  if (value == null || typeof value !== 'object')
@@ -6250,7 +5019,7 @@ function deserializeValue(value, options) {
6250
5019
  else {
6251
5020
  if (typeof d === 'string')
6252
5021
  date.setTime(Date.parse(d));
6253
- else if (long_1.Long.isLong(d))
5022
+ else if (Long.isLong(d))
6254
5023
  date.setTime(d.toNumber());
6255
5024
  else if (typeof d === 'number' && options.relaxed)
6256
5025
  date.setTime(d);
@@ -6262,13 +5031,13 @@ function deserializeValue(value, options) {
6262
5031
  if (value.$scope) {
6263
5032
  copy.$scope = deserializeValue(value.$scope);
6264
5033
  }
6265
- return code.Code.fromExtendedJSON(value);
5034
+ return Code.fromExtendedJSON(value);
6266
5035
  }
6267
- if (value.$ref != null || value.$dbPointer != null) {
5036
+ if (isDBRefLike(value) || value.$dbPointer) {
6268
5037
  var v = value.$ref ? value : value.$dbPointer;
6269
5038
  // we run into this in a "degenerate EJSON" case (with $id and $ref order flipped)
6270
5039
  // because of the order JSON.parse goes through the document
6271
- if (v instanceof db_ref.DBRef)
5040
+ if (v instanceof DBRef)
6272
5041
  return v;
6273
5042
  var dollarKeys = Object.keys(v).filter(function (k) { return k.startsWith('$'); });
6274
5043
  var valid_1 = true;
@@ -6278,7 +5047,7 @@ function deserializeValue(value, options) {
6278
5047
  });
6279
5048
  // only make DBRef if $ keys are all valid
6280
5049
  if (valid_1)
6281
- return db_ref.DBRef.fromExtendedJSON(v);
5050
+ return DBRef.fromExtendedJSON(v);
6282
5051
  }
6283
5052
  return value;
6284
5053
  }
@@ -6328,7 +5097,7 @@ function serializeValue(value, options) {
6328
5097
  return serializeArray(value, options);
6329
5098
  if (value === undefined)
6330
5099
  return null;
6331
- if (value instanceof Date || utils.isDate(value)) {
5100
+ if (value instanceof Date || isDate(value)) {
6332
5101
  var dateNum = value.getTime(),
6333
5102
  // is it in year range 1970-9999?
6334
5103
  inRange = dateNum > -1 && dateNum < 253402318800000;
@@ -6341,10 +5110,10 @@ function serializeValue(value, options) {
6341
5110
  ? { $date: getISOString(value) }
6342
5111
  : { $date: { $numberLong: value.getTime().toString() } };
6343
5112
  }
6344
- if (typeof value === 'number' && !options.relaxed) {
5113
+ if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) {
6345
5114
  // it's an integer
6346
5115
  if (Math.floor(value) === value) {
6347
- var int32Range = value >= BSON_INT32_MIN && value <= BSON_INT32_MAX, int64Range = value >= BSON_INT64_MIN && value <= BSON_INT64_MAX;
5116
+ var int32Range = value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1, int64Range = value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1;
6348
5117
  // interpret as being of the smallest BSON integer type that can represent the number exactly
6349
5118
  if (int32Range)
6350
5119
  return { $numberInt: value.toString() };
@@ -6353,7 +5122,7 @@ function serializeValue(value, options) {
6353
5122
  }
6354
5123
  return { $numberDouble: value.toString() };
6355
5124
  }
6356
- if (value instanceof RegExp || utils.isRegExp(value)) {
5125
+ if (value instanceof RegExp || isRegExp(value)) {
6357
5126
  var flags = value.flags;
6358
5127
  if (flags === undefined) {
6359
5128
  var match = value.toString().match(/[gimuy]*$/);
@@ -6361,7 +5130,7 @@ function serializeValue(value, options) {
6361
5130
  flags = match[0];
6362
5131
  }
6363
5132
  }
6364
- var rx = new regexp.BSONRegExp(value.source, flags);
5133
+ var rx = new BSONRegExp(value.source, flags);
6365
5134
  return rx.toExtendedJSON(options);
6366
5135
  }
6367
5136
  if (value != null && typeof value === 'object')
@@ -6369,24 +5138,24 @@ function serializeValue(value, options) {
6369
5138
  return value;
6370
5139
  }
6371
5140
  var BSON_TYPE_MAPPINGS = {
6372
- Binary: function (o) { return new binary.Binary(o.value(), o.sub_type); },
6373
- Code: function (o) { return new code.Code(o.code, o.scope); },
6374
- DBRef: function (o) { return new db_ref.DBRef(o.collection || o.namespace, o.oid, o.db, o.fields); },
6375
- Decimal128: function (o) { return new decimal128.Decimal128(o.bytes); },
6376
- Double: function (o) { return new double_1.Double(o.value); },
6377
- Int32: function (o) { return new int_32.Int32(o.value); },
5141
+ Binary: function (o) { return new Binary(o.value(), o.sub_type); },
5142
+ Code: function (o) { return new Code(o.code, o.scope); },
5143
+ DBRef: function (o) { return new DBRef(o.collection || o.namespace, o.oid, o.db, o.fields); },
5144
+ Decimal128: function (o) { return new Decimal128(o.bytes); },
5145
+ Double: function (o) { return new Double(o.value); },
5146
+ Int32: function (o) { return new Int32(o.value); },
6378
5147
  Long: function (o) {
6379
- return long_1.Long.fromBits(
5148
+ return Long.fromBits(
6380
5149
  // underscore variants for 1.x backwards compatibility
6381
5150
  o.low != null ? o.low : o.low_, o.low != null ? o.high : o.high_, o.low != null ? o.unsigned : o.unsigned_);
6382
5151
  },
6383
- MaxKey: function () { return new max_key.MaxKey(); },
6384
- MinKey: function () { return new min_key.MinKey(); },
6385
- ObjectID: function (o) { return new objectid.ObjectId(o); },
6386
- ObjectId: function (o) { return new objectid.ObjectId(o); },
6387
- BSONRegExp: function (o) { return new regexp.BSONRegExp(o.pattern, o.options); },
6388
- Symbol: function (o) { return new symbol.BSONSymbol(o.value); },
6389
- Timestamp: function (o) { return timestamp.Timestamp.fromBits(o.low, o.high); }
5152
+ MaxKey: function () { return new MaxKey(); },
5153
+ MinKey: function () { return new MinKey(); },
5154
+ ObjectID: function (o) { return new ObjectId(o); },
5155
+ ObjectId: function (o) { return new ObjectId(o); },
5156
+ BSONRegExp: function (o) { return new BSONRegExp(o.pattern, o.options); },
5157
+ Symbol: function (o) { return new BSONSymbol(o.value); },
5158
+ Timestamp: function (o) { return Timestamp.fromBits(o.low, o.high); }
6390
5159
  };
6391
5160
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6392
5161
  function serializeDocument(doc, options) {
@@ -6424,10 +5193,10 @@ function serializeDocument(doc, options) {
6424
5193
  }
6425
5194
  // Two BSON types may have nested objects that may need to be serialized too
6426
5195
  if (bsontype === 'Code' && outDoc.scope) {
6427
- outDoc = new code.Code(outDoc.code, serializeValue(outDoc.scope, options));
5196
+ outDoc = new Code(outDoc.code, serializeValue(outDoc.scope, options));
6428
5197
  }
6429
5198
  else if (bsontype === 'DBRef' && outDoc.oid) {
6430
- outDoc = new db_ref.DBRef(outDoc.collection, serializeValue(outDoc.oid, options), outDoc.db, outDoc.fields);
5199
+ outDoc = new DBRef(serializeValue(outDoc.collection, options), serializeValue(outDoc.oid, options), serializeValue(outDoc.db, options), serializeValue(outDoc.fields, options));
6431
5200
  }
6432
5201
  return outDoc.toExtendedJSON(options);
6433
5202
  }
@@ -6435,6 +5204,14 @@ function serializeDocument(doc, options) {
6435
5204
  throw new Error('_bsontype must be a string, but was: ' + typeof bsontype);
6436
5205
  }
6437
5206
  }
5207
+ /**
5208
+ * EJSON parse / stringify API
5209
+ * @public
5210
+ */
5211
+ // the namespace here is used to emulate `export * as EJSON from '...'`
5212
+ // which as of now (sept 2020) api-extractor does not support
5213
+ // eslint-disable-next-line @typescript-eslint/no-namespace
5214
+ var EJSON;
6438
5215
  (function (EJSON) {
6439
5216
  /**
6440
5217
  * Parse an Extended JSON string, constructing the JavaScript value or object described by that
@@ -6526,42 +5303,18 @@ function serializeDocument(doc, options) {
6526
5303
  return parse(JSON.stringify(ejson), options);
6527
5304
  }
6528
5305
  EJSON.deserialize = deserialize;
6529
- })(exports.EJSON || (exports.EJSON = {}));
6530
- //# sourceMappingURL=extended_json.js.map
6531
- });
5306
+ })(EJSON || (EJSON = {}));
6532
5307
 
6533
- unwrapExports(extended_json);
6534
- extended_json.EJSON;
6535
- extended_json.isBSONType;
6536
-
6537
- var map = createCommonjsModule(function (module, exports) {
6538
5308
  /* eslint-disable @typescript-eslint/no-explicit-any */
6539
- // We have an ES6 Map available, return the native instance
6540
- Object.defineProperty(exports, "__esModule", { value: true });
6541
- exports.Map = void 0;
6542
5309
  /** @public */
6543
5310
  var bsonMap;
6544
- exports.Map = bsonMap;
6545
- var check = function (potentialGlobal) {
6546
- // eslint-disable-next-line eqeqeq
6547
- return potentialGlobal && potentialGlobal.Math == Math && potentialGlobal;
6548
- };
6549
- // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
6550
- function getGlobal() {
6551
- // eslint-disable-next-line no-undef
6552
- return (check(typeof globalThis === 'object' && globalThis) ||
6553
- check(typeof window === 'object' && window) ||
6554
- check(typeof self === 'object' && self) ||
6555
- check(typeof commonjsGlobal === 'object' && commonjsGlobal) ||
6556
- Function('return this')());
6557
- }
6558
5311
  var bsonGlobal = getGlobal();
6559
- if (Object.prototype.hasOwnProperty.call(bsonGlobal, 'Map')) {
6560
- exports.Map = bsonMap = bsonGlobal.Map;
5312
+ if (bsonGlobal.Map) {
5313
+ bsonMap = bsonGlobal.Map;
6561
5314
  }
6562
5315
  else {
6563
5316
  // We will return a polyfill
6564
- exports.Map = bsonMap = /** @class */ (function () {
5317
+ bsonMap = /** @class */ (function () {
6565
5318
  function Map(array) {
6566
5319
  if (array === void 0) { array = []; }
6567
5320
  this._keys = [];
@@ -6668,136 +5421,83 @@ else {
6668
5421
  return Map;
6669
5422
  }());
6670
5423
  }
6671
- //# sourceMappingURL=map.js.map
6672
- });
6673
-
6674
- unwrapExports(map);
6675
- map.Map;
6676
5424
 
6677
- var constants = createCommonjsModule(function (module, exports) {
6678
- Object.defineProperty(exports, "__esModule", { value: true });
6679
- 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;
6680
5425
  /** @internal */
6681
- exports.BSON_INT32_MAX = 0x7fffffff;
5426
+ var BSON_INT32_MAX = 0x7fffffff;
6682
5427
  /** @internal */
6683
- exports.BSON_INT32_MIN = -0x80000000;
5428
+ var BSON_INT32_MIN = -0x80000000;
6684
5429
  /** @internal */
6685
- exports.BSON_INT64_MAX = Math.pow(2, 63) - 1;
5430
+ var BSON_INT64_MAX = Math.pow(2, 63) - 1;
6686
5431
  /** @internal */
6687
- exports.BSON_INT64_MIN = -Math.pow(2, 63);
5432
+ var BSON_INT64_MIN = -Math.pow(2, 63);
6688
5433
  /**
6689
5434
  * Any integer up to 2^53 can be precisely represented by a double.
6690
5435
  * @internal
6691
5436
  */
6692
- exports.JS_INT_MAX = Math.pow(2, 53);
5437
+ var JS_INT_MAX = Math.pow(2, 53);
6693
5438
  /**
6694
5439
  * Any integer down to -2^53 can be precisely represented by a double.
6695
5440
  * @internal
6696
5441
  */
6697
- exports.JS_INT_MIN = -Math.pow(2, 53);
5442
+ var JS_INT_MIN = -Math.pow(2, 53);
6698
5443
  /** Number BSON Type @internal */
6699
- exports.BSON_DATA_NUMBER = 1;
5444
+ var BSON_DATA_NUMBER = 1;
6700
5445
  /** String BSON Type @internal */
6701
- exports.BSON_DATA_STRING = 2;
5446
+ var BSON_DATA_STRING = 2;
6702
5447
  /** Object BSON Type @internal */
6703
- exports.BSON_DATA_OBJECT = 3;
5448
+ var BSON_DATA_OBJECT = 3;
6704
5449
  /** Array BSON Type @internal */
6705
- exports.BSON_DATA_ARRAY = 4;
5450
+ var BSON_DATA_ARRAY = 4;
6706
5451
  /** Binary BSON Type @internal */
6707
- exports.BSON_DATA_BINARY = 5;
5452
+ var BSON_DATA_BINARY = 5;
6708
5453
  /** Binary BSON Type @internal */
6709
- exports.BSON_DATA_UNDEFINED = 6;
5454
+ var BSON_DATA_UNDEFINED = 6;
6710
5455
  /** ObjectId BSON Type @internal */
6711
- exports.BSON_DATA_OID = 7;
5456
+ var BSON_DATA_OID = 7;
6712
5457
  /** Boolean BSON Type @internal */
6713
- exports.BSON_DATA_BOOLEAN = 8;
5458
+ var BSON_DATA_BOOLEAN = 8;
6714
5459
  /** Date BSON Type @internal */
6715
- exports.BSON_DATA_DATE = 9;
5460
+ var BSON_DATA_DATE = 9;
6716
5461
  /** null BSON Type @internal */
6717
- exports.BSON_DATA_NULL = 10;
5462
+ var BSON_DATA_NULL = 10;
6718
5463
  /** RegExp BSON Type @internal */
6719
- exports.BSON_DATA_REGEXP = 11;
5464
+ var BSON_DATA_REGEXP = 11;
6720
5465
  /** Code BSON Type @internal */
6721
- exports.BSON_DATA_DBPOINTER = 12;
5466
+ var BSON_DATA_DBPOINTER = 12;
6722
5467
  /** Code BSON Type @internal */
6723
- exports.BSON_DATA_CODE = 13;
5468
+ var BSON_DATA_CODE = 13;
6724
5469
  /** Symbol BSON Type @internal */
6725
- exports.BSON_DATA_SYMBOL = 14;
5470
+ var BSON_DATA_SYMBOL = 14;
6726
5471
  /** Code with Scope BSON Type @internal */
6727
- exports.BSON_DATA_CODE_W_SCOPE = 15;
5472
+ var BSON_DATA_CODE_W_SCOPE = 15;
6728
5473
  /** 32 bit Integer BSON Type @internal */
6729
- exports.BSON_DATA_INT = 16;
5474
+ var BSON_DATA_INT = 16;
6730
5475
  /** Timestamp BSON Type @internal */
6731
- exports.BSON_DATA_TIMESTAMP = 17;
5476
+ var BSON_DATA_TIMESTAMP = 17;
6732
5477
  /** Long BSON Type @internal */
6733
- exports.BSON_DATA_LONG = 18;
5478
+ var BSON_DATA_LONG = 18;
6734
5479
  /** Decimal128 BSON Type @internal */
6735
- exports.BSON_DATA_DECIMAL128 = 19;
5480
+ var BSON_DATA_DECIMAL128 = 19;
6736
5481
  /** MinKey BSON Type @internal */
6737
- exports.BSON_DATA_MIN_KEY = 0xff;
5482
+ var BSON_DATA_MIN_KEY = 0xff;
6738
5483
  /** MaxKey BSON Type @internal */
6739
- exports.BSON_DATA_MAX_KEY = 0x7f;
5484
+ var BSON_DATA_MAX_KEY = 0x7f;
6740
5485
  /** Binary Default Type @internal */
6741
- exports.BSON_BINARY_SUBTYPE_DEFAULT = 0;
5486
+ var BSON_BINARY_SUBTYPE_DEFAULT = 0;
6742
5487
  /** Binary Function Type @internal */
6743
- exports.BSON_BINARY_SUBTYPE_FUNCTION = 1;
5488
+ var BSON_BINARY_SUBTYPE_FUNCTION = 1;
6744
5489
  /** Binary Byte Array Type @internal */
6745
- exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
5490
+ var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
6746
5491
  /** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
6747
- exports.BSON_BINARY_SUBTYPE_UUID = 3;
5492
+ var BSON_BINARY_SUBTYPE_UUID = 3;
6748
5493
  /** Binary UUID Type @internal */
6749
- exports.BSON_BINARY_SUBTYPE_UUID_NEW = 4;
5494
+ var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
6750
5495
  /** Binary MD5 Type @internal */
6751
- exports.BSON_BINARY_SUBTYPE_MD5 = 5;
5496
+ var BSON_BINARY_SUBTYPE_MD5 = 5;
6752
5497
  /** Binary User Defined Type @internal */
6753
- exports.BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
6754
- //# sourceMappingURL=constants.js.map
6755
- });
5498
+ var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
6756
5499
 
6757
- unwrapExports(constants);
6758
- constants.BSON_BINARY_SUBTYPE_USER_DEFINED;
6759
- constants.BSON_BINARY_SUBTYPE_MD5;
6760
- constants.BSON_BINARY_SUBTYPE_UUID_NEW;
6761
- constants.BSON_BINARY_SUBTYPE_UUID;
6762
- constants.BSON_BINARY_SUBTYPE_BYTE_ARRAY;
6763
- constants.BSON_BINARY_SUBTYPE_FUNCTION;
6764
- constants.BSON_BINARY_SUBTYPE_DEFAULT;
6765
- constants.BSON_DATA_MAX_KEY;
6766
- constants.BSON_DATA_MIN_KEY;
6767
- constants.BSON_DATA_DECIMAL128;
6768
- constants.BSON_DATA_LONG;
6769
- constants.BSON_DATA_TIMESTAMP;
6770
- constants.BSON_DATA_INT;
6771
- constants.BSON_DATA_CODE_W_SCOPE;
6772
- constants.BSON_DATA_SYMBOL;
6773
- constants.BSON_DATA_CODE;
6774
- constants.BSON_DATA_DBPOINTER;
6775
- constants.BSON_DATA_REGEXP;
6776
- constants.BSON_DATA_NULL;
6777
- constants.BSON_DATA_DATE;
6778
- constants.BSON_DATA_BOOLEAN;
6779
- constants.BSON_DATA_OID;
6780
- constants.BSON_DATA_UNDEFINED;
6781
- constants.BSON_DATA_BINARY;
6782
- constants.BSON_DATA_ARRAY;
6783
- constants.BSON_DATA_OBJECT;
6784
- constants.BSON_DATA_STRING;
6785
- constants.BSON_DATA_NUMBER;
6786
- constants.JS_INT_MIN;
6787
- constants.JS_INT_MAX;
6788
- constants.BSON_INT64_MIN;
6789
- constants.BSON_INT64_MAX;
6790
- constants.BSON_INT32_MIN;
6791
- constants.BSON_INT32_MAX;
6792
-
6793
- var calculate_size = createCommonjsModule(function (module, exports) {
6794
- Object.defineProperty(exports, "__esModule", { value: true });
6795
- exports.calculateObjectSize = void 0;
6796
-
6797
-
6798
-
6799
-
6800
- function calculateObjectSize(object, serializeFunctions, ignoreUndefined) {
5500
+ function calculateObjectSize$1(object, serializeFunctions, ignoreUndefined) {
6801
5501
  var totalLength = 4 + 1;
6802
5502
  if (Array.isArray(object)) {
6803
5503
  for (var i = 0; i < object.length; i++) {
@@ -6816,7 +5516,6 @@ function calculateObjectSize(object, serializeFunctions, ignoreUndefined) {
6816
5516
  }
6817
5517
  return totalLength;
6818
5518
  }
6819
- exports.calculateObjectSize = calculateObjectSize;
6820
5519
  /** @internal */
6821
5520
  function calculateElement(name,
6822
5521
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -6830,84 +5529,84 @@ value, serializeFunctions, isArray, ignoreUndefined) {
6830
5529
  }
6831
5530
  switch (typeof value) {
6832
5531
  case 'string':
6833
- return 1 + buffer.Buffer.byteLength(name, 'utf8') + 1 + 4 + buffer.Buffer.byteLength(value, 'utf8') + 1;
5532
+ return 1 + buffer_1.byteLength(name, 'utf8') + 1 + 4 + buffer_1.byteLength(value, 'utf8') + 1;
6834
5533
  case 'number':
6835
5534
  if (Math.floor(value) === value &&
6836
- value >= constants.JS_INT_MIN &&
6837
- value <= constants.JS_INT_MAX) {
6838
- if (value >= constants.BSON_INT32_MIN && value <= constants.BSON_INT32_MAX) {
5535
+ value >= JS_INT_MIN &&
5536
+ value <= JS_INT_MAX) {
5537
+ if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
6839
5538
  // 32 bit
6840
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (4 + 1);
5539
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (4 + 1);
6841
5540
  }
6842
5541
  else {
6843
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
5542
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
6844
5543
  }
6845
5544
  }
6846
5545
  else {
6847
5546
  // 64 bit
6848
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
5547
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
6849
5548
  }
6850
5549
  case 'undefined':
6851
5550
  if (isArray || !ignoreUndefined)
6852
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + 1;
5551
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1;
6853
5552
  return 0;
6854
5553
  case 'boolean':
6855
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (1 + 1);
5554
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (1 + 1);
6856
5555
  case 'object':
6857
5556
  if (value == null || value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
6858
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + 1;
5557
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1;
6859
5558
  }
6860
5559
  else if (value['_bsontype'] === 'ObjectId' || value['_bsontype'] === 'ObjectID') {
6861
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (12 + 1);
5560
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (12 + 1);
6862
5561
  }
6863
- else if (value instanceof Date || utils.isDate(value)) {
6864
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
5562
+ else if (value instanceof Date || isDate(value)) {
5563
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
6865
5564
  }
6866
5565
  else if (ArrayBuffer.isView(value) ||
6867
5566
  value instanceof ArrayBuffer ||
6868
- utils.isAnyArrayBuffer(value)) {
6869
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (1 + 4 + 1) + value.byteLength);
5567
+ isAnyArrayBuffer(value)) {
5568
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (1 + 4 + 1) + value.byteLength);
6870
5569
  }
6871
5570
  else if (value['_bsontype'] === 'Long' ||
6872
5571
  value['_bsontype'] === 'Double' ||
6873
5572
  value['_bsontype'] === 'Timestamp') {
6874
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
5573
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
6875
5574
  }
6876
5575
  else if (value['_bsontype'] === 'Decimal128') {
6877
- return (name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (16 + 1);
5576
+ return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (16 + 1);
6878
5577
  }
6879
5578
  else if (value['_bsontype'] === 'Code') {
6880
5579
  // Calculate size depending on the availability of a scope
6881
5580
  if (value.scope != null && Object.keys(value.scope).length > 0) {
6882
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5581
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6883
5582
  1 +
6884
5583
  4 +
6885
5584
  4 +
6886
- buffer.Buffer.byteLength(value.code.toString(), 'utf8') +
5585
+ buffer_1.byteLength(value.code.toString(), 'utf8') +
6887
5586
  1 +
6888
- calculateObjectSize(value.scope, serializeFunctions, ignoreUndefined));
5587
+ calculateObjectSize$1(value.scope, serializeFunctions, ignoreUndefined));
6889
5588
  }
6890
5589
  else {
6891
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5590
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6892
5591
  1 +
6893
5592
  4 +
6894
- buffer.Buffer.byteLength(value.code.toString(), 'utf8') +
5593
+ buffer_1.byteLength(value.code.toString(), 'utf8') +
6895
5594
  1);
6896
5595
  }
6897
5596
  }
6898
5597
  else if (value['_bsontype'] === 'Binary') {
6899
5598
  // Check what kind of subtype we have
6900
- if (value.sub_type === binary.Binary.SUBTYPE_BYTE_ARRAY) {
6901
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5599
+ if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
5600
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6902
5601
  (value.position + 1 + 4 + 1 + 4));
6903
5602
  }
6904
5603
  else {
6905
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1));
5604
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1));
6906
5605
  }
6907
5606
  }
6908
5607
  else if (value['_bsontype'] === 'Symbol') {
6909
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
6910
- buffer.Buffer.byteLength(value.value, 'utf8') +
5608
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
5609
+ buffer_1.byteLength(value.value, 'utf8') +
6911
5610
  4 +
6912
5611
  1 +
6913
5612
  1);
@@ -6922,14 +5621,14 @@ value, serializeFunctions, isArray, ignoreUndefined) {
6922
5621
  if (value.db != null) {
6923
5622
  ordered_values['$db'] = value.db;
6924
5623
  }
6925
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5624
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6926
5625
  1 +
6927
- calculateObjectSize(ordered_values, serializeFunctions, ignoreUndefined));
5626
+ calculateObjectSize$1(ordered_values, serializeFunctions, ignoreUndefined));
6928
5627
  }
6929
- else if (value instanceof RegExp || utils.isRegExp(value)) {
6930
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5628
+ else if (value instanceof RegExp || isRegExp(value)) {
5629
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6931
5630
  1 +
6932
- buffer.Buffer.byteLength(value.source, 'utf8') +
5631
+ buffer_1.byteLength(value.source, 'utf8') +
6933
5632
  1 +
6934
5633
  (value.global ? 1 : 0) +
6935
5634
  (value.ignoreCase ? 1 : 0) +
@@ -6937,24 +5636,24 @@ value, serializeFunctions, isArray, ignoreUndefined) {
6937
5636
  1);
6938
5637
  }
6939
5638
  else if (value['_bsontype'] === 'BSONRegExp') {
6940
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5639
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6941
5640
  1 +
6942
- buffer.Buffer.byteLength(value.pattern, 'utf8') +
5641
+ buffer_1.byteLength(value.pattern, 'utf8') +
6943
5642
  1 +
6944
- buffer.Buffer.byteLength(value.options, 'utf8') +
5643
+ buffer_1.byteLength(value.options, 'utf8') +
6945
5644
  1);
6946
5645
  }
6947
5646
  else {
6948
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
6949
- calculateObjectSize(value, serializeFunctions, ignoreUndefined) +
5647
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
5648
+ calculateObjectSize$1(value, serializeFunctions, ignoreUndefined) +
6950
5649
  1);
6951
5650
  }
6952
5651
  case 'function':
6953
5652
  // WTF for 0.4.X where typeof /someregexp/ === 'function'
6954
- if (value instanceof RegExp || utils.isRegExp(value) || String.call(value) === '[object RegExp]') {
6955
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5653
+ if (value instanceof RegExp || isRegExp(value) || String.call(value) === '[object RegExp]') {
5654
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6956
5655
  1 +
6957
- buffer.Buffer.byteLength(value.source, 'utf8') +
5656
+ buffer_1.byteLength(value.source, 'utf8') +
6958
5657
  1 +
6959
5658
  (value.global ? 1 : 0) +
6960
5659
  (value.ignoreCase ? 1 : 0) +
@@ -6963,34 +5662,26 @@ value, serializeFunctions, isArray, ignoreUndefined) {
6963
5662
  }
6964
5663
  else {
6965
5664
  if (serializeFunctions && value.scope != null && Object.keys(value.scope).length > 0) {
6966
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5665
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6967
5666
  1 +
6968
5667
  4 +
6969
5668
  4 +
6970
- buffer.Buffer.byteLength(utils.normalizedFunctionString(value), 'utf8') +
5669
+ buffer_1.byteLength(normalizedFunctionString(value), 'utf8') +
6971
5670
  1 +
6972
- calculateObjectSize(value.scope, serializeFunctions, ignoreUndefined));
5671
+ calculateObjectSize$1(value.scope, serializeFunctions, ignoreUndefined));
6973
5672
  }
6974
5673
  else if (serializeFunctions) {
6975
- return ((name != null ? buffer.Buffer.byteLength(name, 'utf8') + 1 : 0) +
5674
+ return ((name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) +
6976
5675
  1 +
6977
5676
  4 +
6978
- buffer.Buffer.byteLength(utils.normalizedFunctionString(value), 'utf8') +
5677
+ buffer_1.byteLength(normalizedFunctionString(value), 'utf8') +
6979
5678
  1);
6980
5679
  }
6981
5680
  }
6982
5681
  }
6983
5682
  return 0;
6984
5683
  }
6985
- //# sourceMappingURL=calculate_size.js.map
6986
- });
6987
5684
 
6988
- unwrapExports(calculate_size);
6989
- calculate_size.calculateObjectSize;
6990
-
6991
- var validate_utf8 = createCommonjsModule(function (module, exports) {
6992
- Object.defineProperty(exports, "__esModule", { value: true });
6993
- exports.validateUtf8 = void 0;
6994
5685
  var FIRST_BIT = 0x80;
6995
5686
  var FIRST_TWO_BITS = 0xc0;
6996
5687
  var FIRST_THREE_BITS = 0xe0;
@@ -7033,37 +5724,12 @@ function validateUtf8(bytes, start, end) {
7033
5724
  }
7034
5725
  return !continuation;
7035
5726
  }
7036
- exports.validateUtf8 = validateUtf8;
7037
- //# sourceMappingURL=validate_utf8.js.map
7038
- });
7039
-
7040
- unwrapExports(validate_utf8);
7041
- validate_utf8.validateUtf8;
7042
-
7043
- var deserializer = createCommonjsModule(function (module, exports) {
7044
- Object.defineProperty(exports, "__esModule", { value: true });
7045
- exports.deserialize = void 0;
7046
-
7047
-
7048
-
7049
-
7050
-
7051
-
7052
-
7053
-
7054
-
7055
-
7056
-
7057
-
7058
-
7059
-
7060
-
7061
5727
 
7062
5728
  // Internal long versions
7063
- var JS_INT_MAX_LONG = long_1.Long.fromNumber(constants.JS_INT_MAX);
7064
- var JS_INT_MIN_LONG = long_1.Long.fromNumber(constants.JS_INT_MIN);
5729
+ var JS_INT_MAX_LONG = Long.fromNumber(JS_INT_MAX);
5730
+ var JS_INT_MIN_LONG = Long.fromNumber(JS_INT_MIN);
7065
5731
  var functionCache = {};
7066
- function deserialize(buffer, options, isArray) {
5732
+ function deserialize$1(buffer, options, isArray) {
7067
5733
  options = options == null ? {} : options;
7068
5734
  var index = options && options.index ? options.index : 0;
7069
5735
  // Read the document size
@@ -7090,8 +5756,8 @@ function deserialize(buffer, options, isArray) {
7090
5756
  // Start deserializtion
7091
5757
  return deserializeObject(buffer, index, options, isArray);
7092
5758
  }
7093
- exports.deserialize = deserialize;
7094
- function deserializeObject(buffer$1, index, options, isArray) {
5759
+ var allowedDBRefKeys = /^\$ref$|^\$id$|^\$db$/;
5760
+ function deserializeObject(buffer, index, options, isArray) {
7095
5761
  if (isArray === void 0) { isArray = false; }
7096
5762
  var evalFunctions = options['evalFunctions'] == null ? false : options['evalFunctions'];
7097
5763
  var cacheFunctions = options['cacheFunctions'] == null ? false : options['cacheFunctions'];
@@ -7107,115 +5773,124 @@ function deserializeObject(buffer$1, index, options, isArray) {
7107
5773
  // Set the start index
7108
5774
  var startIndex = index;
7109
5775
  // Validate that we have at least 4 bytes of buffer
7110
- if (buffer$1.length < 5)
5776
+ if (buffer.length < 5)
7111
5777
  throw new Error('corrupt bson message < 5 bytes long');
7112
5778
  // Read the document size
7113
- var size = buffer$1[index++] | (buffer$1[index++] << 8) | (buffer$1[index++] << 16) | (buffer$1[index++] << 24);
5779
+ var size = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
7114
5780
  // Ensure buffer is valid size
7115
- if (size < 5 || size > buffer$1.length)
5781
+ if (size < 5 || size > buffer.length)
7116
5782
  throw new Error('corrupt bson message');
7117
5783
  // Create holding object
7118
5784
  var object = isArray ? [] : {};
7119
5785
  // Used for arrays to skip having to perform utf8 decoding
7120
5786
  var arrayIndex = 0;
7121
5787
  var done = false;
5788
+ var isPossibleDBRef = isArray ? false : null;
7122
5789
  // While we have more left data left keep parsing
7123
5790
  while (!done) {
7124
5791
  // Read the type
7125
- var elementType = buffer$1[index++];
5792
+ var elementType = buffer[index++];
7126
5793
  // If we get a zero it's the last byte, exit
7127
5794
  if (elementType === 0)
7128
5795
  break;
7129
5796
  // Get the start search index
7130
5797
  var i = index;
7131
5798
  // Locate the end of the c string
7132
- while (buffer$1[i] !== 0x00 && i < buffer$1.length) {
5799
+ while (buffer[i] !== 0x00 && i < buffer.length) {
7133
5800
  i++;
7134
5801
  }
7135
5802
  // If are at the end of the buffer there is a problem with the document
7136
- if (i >= buffer$1.byteLength)
5803
+ if (i >= buffer.byteLength)
7137
5804
  throw new Error('Bad BSON Document: illegal CString');
7138
- var name = isArray ? arrayIndex++ : buffer$1.toString('utf8', index, i);
5805
+ var name = isArray ? arrayIndex++ : buffer.toString('utf8', index, i);
5806
+ if (isPossibleDBRef !== false && name[0] === '$') {
5807
+ isPossibleDBRef = allowedDBRefKeys.test(name);
5808
+ }
7139
5809
  var value = void 0;
7140
5810
  index = i + 1;
7141
- if (elementType === constants.BSON_DATA_STRING) {
7142
- var stringSize = buffer$1[index++] |
7143
- (buffer$1[index++] << 8) |
7144
- (buffer$1[index++] << 16) |
7145
- (buffer$1[index++] << 24);
5811
+ if (elementType === BSON_DATA_STRING) {
5812
+ var stringSize = buffer[index++] |
5813
+ (buffer[index++] << 8) |
5814
+ (buffer[index++] << 16) |
5815
+ (buffer[index++] << 24);
7146
5816
  if (stringSize <= 0 ||
7147
- stringSize > buffer$1.length - index ||
7148
- buffer$1[index + stringSize - 1] !== 0)
5817
+ stringSize > buffer.length - index ||
5818
+ buffer[index + stringSize - 1] !== 0)
7149
5819
  throw new Error('bad string length in bson');
7150
- if (!validate_utf8.validateUtf8(buffer$1, index, index + stringSize - 1)) {
7151
- throw new Error('Invalid UTF-8 string in BSON document');
5820
+ value = buffer.toString('utf8', index, index + stringSize - 1);
5821
+ for (var i_1 = 0; i_1 < value.length; i_1++) {
5822
+ if (value.charCodeAt(i_1) === 0xfffd) {
5823
+ if (!validateUtf8(buffer, index, index + stringSize - 1)) {
5824
+ throw new Error('Invalid UTF-8 string in BSON document');
5825
+ }
5826
+ break;
5827
+ }
7152
5828
  }
7153
- value = buffer$1.toString('utf8', index, index + stringSize - 1);
7154
5829
  index = index + stringSize;
7155
5830
  }
7156
- else if (elementType === constants.BSON_DATA_OID) {
7157
- var oid = buffer.Buffer.alloc(12);
7158
- buffer$1.copy(oid, 0, index, index + 12);
7159
- value = new objectid.ObjectId(oid);
5831
+ else if (elementType === BSON_DATA_OID) {
5832
+ var oid = buffer_1.alloc(12);
5833
+ buffer.copy(oid, 0, index, index + 12);
5834
+ value = new ObjectId(oid);
7160
5835
  index = index + 12;
7161
5836
  }
7162
- else if (elementType === constants.BSON_DATA_INT && promoteValues === false) {
7163
- value = new int_32.Int32(buffer$1[index++] | (buffer$1[index++] << 8) | (buffer$1[index++] << 16) | (buffer$1[index++] << 24));
5837
+ else if (elementType === BSON_DATA_INT && promoteValues === false) {
5838
+ value = new Int32(buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24));
7164
5839
  }
7165
- else if (elementType === constants.BSON_DATA_INT) {
5840
+ else if (elementType === BSON_DATA_INT) {
7166
5841
  value =
7167
- buffer$1[index++] |
7168
- (buffer$1[index++] << 8) |
7169
- (buffer$1[index++] << 16) |
7170
- (buffer$1[index++] << 24);
5842
+ buffer[index++] |
5843
+ (buffer[index++] << 8) |
5844
+ (buffer[index++] << 16) |
5845
+ (buffer[index++] << 24);
7171
5846
  }
7172
- else if (elementType === constants.BSON_DATA_NUMBER && promoteValues === false) {
7173
- value = new double_1.Double(buffer$1.readDoubleLE(index));
5847
+ else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
5848
+ value = new Double(buffer.readDoubleLE(index));
7174
5849
  index = index + 8;
7175
5850
  }
7176
- else if (elementType === constants.BSON_DATA_NUMBER) {
7177
- value = buffer$1.readDoubleLE(index);
5851
+ else if (elementType === BSON_DATA_NUMBER) {
5852
+ value = buffer.readDoubleLE(index);
7178
5853
  index = index + 8;
7179
5854
  }
7180
- else if (elementType === constants.BSON_DATA_DATE) {
7181
- var lowBits = buffer$1[index++] |
7182
- (buffer$1[index++] << 8) |
7183
- (buffer$1[index++] << 16) |
7184
- (buffer$1[index++] << 24);
7185
- var highBits = buffer$1[index++] |
7186
- (buffer$1[index++] << 8) |
7187
- (buffer$1[index++] << 16) |
7188
- (buffer$1[index++] << 24);
7189
- value = new Date(new long_1.Long(lowBits, highBits).toNumber());
7190
- }
7191
- else if (elementType === constants.BSON_DATA_BOOLEAN) {
7192
- if (buffer$1[index] !== 0 && buffer$1[index] !== 1)
5855
+ else if (elementType === BSON_DATA_DATE) {
5856
+ var lowBits = buffer[index++] |
5857
+ (buffer[index++] << 8) |
5858
+ (buffer[index++] << 16) |
5859
+ (buffer[index++] << 24);
5860
+ var highBits = buffer[index++] |
5861
+ (buffer[index++] << 8) |
5862
+ (buffer[index++] << 16) |
5863
+ (buffer[index++] << 24);
5864
+ value = new Date(new Long(lowBits, highBits).toNumber());
5865
+ }
5866
+ else if (elementType === BSON_DATA_BOOLEAN) {
5867
+ if (buffer[index] !== 0 && buffer[index] !== 1)
7193
5868
  throw new Error('illegal boolean type value');
7194
- value = buffer$1[index++] === 1;
5869
+ value = buffer[index++] === 1;
7195
5870
  }
7196
- else if (elementType === constants.BSON_DATA_OBJECT) {
5871
+ else if (elementType === BSON_DATA_OBJECT) {
7197
5872
  var _index = index;
7198
- var objectSize = buffer$1[index] |
7199
- (buffer$1[index + 1] << 8) |
7200
- (buffer$1[index + 2] << 16) |
7201
- (buffer$1[index + 3] << 24);
7202
- if (objectSize <= 0 || objectSize > buffer$1.length - index)
5873
+ var objectSize = buffer[index] |
5874
+ (buffer[index + 1] << 8) |
5875
+ (buffer[index + 2] << 16) |
5876
+ (buffer[index + 3] << 24);
5877
+ if (objectSize <= 0 || objectSize > buffer.length - index)
7203
5878
  throw new Error('bad embedded document length in bson');
7204
5879
  // We have a raw value
7205
5880
  if (raw) {
7206
- value = buffer$1.slice(index, index + objectSize);
5881
+ value = buffer.slice(index, index + objectSize);
7207
5882
  }
7208
5883
  else {
7209
- value = deserializeObject(buffer$1, _index, options, false);
5884
+ value = deserializeObject(buffer, _index, options, false);
7210
5885
  }
7211
5886
  index = index + objectSize;
7212
5887
  }
7213
- else if (elementType === constants.BSON_DATA_ARRAY) {
5888
+ else if (elementType === BSON_DATA_ARRAY) {
7214
5889
  var _index = index;
7215
- var objectSize = buffer$1[index] |
7216
- (buffer$1[index + 1] << 8) |
7217
- (buffer$1[index + 2] << 16) |
7218
- (buffer$1[index + 3] << 24);
5890
+ var objectSize = buffer[index] |
5891
+ (buffer[index + 1] << 8) |
5892
+ (buffer[index + 2] << 16) |
5893
+ (buffer[index + 3] << 24);
7219
5894
  var arrayOptions = options;
7220
5895
  // Stop index
7221
5896
  var stopIndex = index + objectSize;
@@ -7227,30 +5902,30 @@ function deserializeObject(buffer$1, index, options, isArray) {
7227
5902
  }
7228
5903
  arrayOptions['raw'] = true;
7229
5904
  }
7230
- value = deserializeObject(buffer$1, _index, arrayOptions, true);
5905
+ value = deserializeObject(buffer, _index, arrayOptions, true);
7231
5906
  index = index + objectSize;
7232
- if (buffer$1[index - 1] !== 0)
5907
+ if (buffer[index - 1] !== 0)
7233
5908
  throw new Error('invalid array terminator byte');
7234
5909
  if (index !== stopIndex)
7235
5910
  throw new Error('corrupted array bson');
7236
5911
  }
7237
- else if (elementType === constants.BSON_DATA_UNDEFINED) {
5912
+ else if (elementType === BSON_DATA_UNDEFINED) {
7238
5913
  value = undefined;
7239
5914
  }
7240
- else if (elementType === constants.BSON_DATA_NULL) {
5915
+ else if (elementType === BSON_DATA_NULL) {
7241
5916
  value = null;
7242
5917
  }
7243
- else if (elementType === constants.BSON_DATA_LONG) {
5918
+ else if (elementType === BSON_DATA_LONG) {
7244
5919
  // Unpack the low and high bits
7245
- var lowBits = buffer$1[index++] |
7246
- (buffer$1[index++] << 8) |
7247
- (buffer$1[index++] << 16) |
7248
- (buffer$1[index++] << 24);
7249
- var highBits = buffer$1[index++] |
7250
- (buffer$1[index++] << 8) |
7251
- (buffer$1[index++] << 16) |
7252
- (buffer$1[index++] << 24);
7253
- var long = new long_1.Long(lowBits, highBits);
5920
+ var lowBits = buffer[index++] |
5921
+ (buffer[index++] << 8) |
5922
+ (buffer[index++] << 16) |
5923
+ (buffer[index++] << 24);
5924
+ var highBits = buffer[index++] |
5925
+ (buffer[index++] << 8) |
5926
+ (buffer[index++] << 16) |
5927
+ (buffer[index++] << 24);
5928
+ var long = new Long(lowBits, highBits);
7254
5929
  // Promote the long if possible
7255
5930
  if (promoteLongs && promoteValues === true) {
7256
5931
  value =
@@ -7262,45 +5937,45 @@ function deserializeObject(buffer$1, index, options, isArray) {
7262
5937
  value = long;
7263
5938
  }
7264
5939
  }
7265
- else if (elementType === constants.BSON_DATA_DECIMAL128) {
5940
+ else if (elementType === BSON_DATA_DECIMAL128) {
7266
5941
  // Buffer to contain the decimal bytes
7267
- var bytes = buffer.Buffer.alloc(16);
5942
+ var bytes = buffer_1.alloc(16);
7268
5943
  // Copy the next 16 bytes into the bytes buffer
7269
- buffer$1.copy(bytes, 0, index, index + 16);
5944
+ buffer.copy(bytes, 0, index, index + 16);
7270
5945
  // Update index
7271
5946
  index = index + 16;
7272
5947
  // Assign the new Decimal128 value
7273
- var decimal128$1 = new decimal128.Decimal128(bytes);
5948
+ var decimal128 = new Decimal128(bytes);
7274
5949
  // If we have an alternative mapper use that
7275
- if ('toObject' in decimal128$1 && typeof decimal128$1.toObject === 'function') {
7276
- value = decimal128$1.toObject();
5950
+ if ('toObject' in decimal128 && typeof decimal128.toObject === 'function') {
5951
+ value = decimal128.toObject();
7277
5952
  }
7278
5953
  else {
7279
- value = decimal128$1;
5954
+ value = decimal128;
7280
5955
  }
7281
5956
  }
7282
- else if (elementType === constants.BSON_DATA_BINARY) {
7283
- var binarySize = buffer$1[index++] |
7284
- (buffer$1[index++] << 8) |
7285
- (buffer$1[index++] << 16) |
7286
- (buffer$1[index++] << 24);
5957
+ else if (elementType === BSON_DATA_BINARY) {
5958
+ var binarySize = buffer[index++] |
5959
+ (buffer[index++] << 8) |
5960
+ (buffer[index++] << 16) |
5961
+ (buffer[index++] << 24);
7287
5962
  var totalBinarySize = binarySize;
7288
- var subType = buffer$1[index++];
5963
+ var subType = buffer[index++];
7289
5964
  // Did we have a negative binary size, throw
7290
5965
  if (binarySize < 0)
7291
5966
  throw new Error('Negative binary type element size found');
7292
5967
  // Is the length longer than the document
7293
- if (binarySize > buffer$1.byteLength)
5968
+ if (binarySize > buffer.byteLength)
7294
5969
  throw new Error('Binary type size larger than document size');
7295
5970
  // Decode as raw Buffer object if options specifies it
7296
- if (buffer$1['slice'] != null) {
5971
+ if (buffer['slice'] != null) {
7297
5972
  // If we have subtype 2 skip the 4 bytes for the size
7298
- if (subType === binary.Binary.SUBTYPE_BYTE_ARRAY) {
5973
+ if (subType === Binary.SUBTYPE_BYTE_ARRAY) {
7299
5974
  binarySize =
7300
- buffer$1[index++] |
7301
- (buffer$1[index++] << 8) |
7302
- (buffer$1[index++] << 16) |
7303
- (buffer$1[index++] << 24);
5975
+ buffer[index++] |
5976
+ (buffer[index++] << 8) |
5977
+ (buffer[index++] << 16) |
5978
+ (buffer[index++] << 24);
7304
5979
  if (binarySize < 0)
7305
5980
  throw new Error('Negative binary type element size found for subtype 0x02');
7306
5981
  if (binarySize > totalBinarySize - 4)
@@ -7309,21 +5984,21 @@ function deserializeObject(buffer$1, index, options, isArray) {
7309
5984
  throw new Error('Binary type with subtype 0x02 contains too short binary size');
7310
5985
  }
7311
5986
  if (promoteBuffers && promoteValues) {
7312
- value = buffer$1.slice(index, index + binarySize);
5987
+ value = buffer.slice(index, index + binarySize);
7313
5988
  }
7314
5989
  else {
7315
- value = new binary.Binary(buffer$1.slice(index, index + binarySize), subType);
5990
+ value = new Binary(buffer.slice(index, index + binarySize), subType);
7316
5991
  }
7317
5992
  }
7318
5993
  else {
7319
- var _buffer = buffer.Buffer.alloc(binarySize);
5994
+ var _buffer = buffer_1.alloc(binarySize);
7320
5995
  // If we have subtype 2 skip the 4 bytes for the size
7321
- if (subType === binary.Binary.SUBTYPE_BYTE_ARRAY) {
5996
+ if (subType === Binary.SUBTYPE_BYTE_ARRAY) {
7322
5997
  binarySize =
7323
- buffer$1[index++] |
7324
- (buffer$1[index++] << 8) |
7325
- (buffer$1[index++] << 16) |
7326
- (buffer$1[index++] << 24);
5998
+ buffer[index++] |
5999
+ (buffer[index++] << 8) |
6000
+ (buffer[index++] << 16) |
6001
+ (buffer[index++] << 24);
7327
6002
  if (binarySize < 0)
7328
6003
  throw new Error('Negative binary type element size found for subtype 0x02');
7329
6004
  if (binarySize > totalBinarySize - 4)
@@ -7333,43 +6008,43 @@ function deserializeObject(buffer$1, index, options, isArray) {
7333
6008
  }
7334
6009
  // Copy the data
7335
6010
  for (i = 0; i < binarySize; i++) {
7336
- _buffer[i] = buffer$1[index + i];
6011
+ _buffer[i] = buffer[index + i];
7337
6012
  }
7338
6013
  if (promoteBuffers && promoteValues) {
7339
6014
  value = _buffer;
7340
6015
  }
7341
6016
  else {
7342
- value = new binary.Binary(_buffer, subType);
6017
+ value = new Binary(_buffer, subType);
7343
6018
  }
7344
6019
  }
7345
6020
  // Update the index
7346
6021
  index = index + binarySize;
7347
6022
  }
7348
- else if (elementType === constants.BSON_DATA_REGEXP && bsonRegExp === false) {
6023
+ else if (elementType === BSON_DATA_REGEXP && bsonRegExp === false) {
7349
6024
  // Get the start search index
7350
6025
  i = index;
7351
6026
  // Locate the end of the c string
7352
- while (buffer$1[i] !== 0x00 && i < buffer$1.length) {
6027
+ while (buffer[i] !== 0x00 && i < buffer.length) {
7353
6028
  i++;
7354
6029
  }
7355
6030
  // If are at the end of the buffer there is a problem with the document
7356
- if (i >= buffer$1.length)
6031
+ if (i >= buffer.length)
7357
6032
  throw new Error('Bad BSON Document: illegal CString');
7358
6033
  // Return the C string
7359
- var source = buffer$1.toString('utf8', index, i);
6034
+ var source = buffer.toString('utf8', index, i);
7360
6035
  // Create the regexp
7361
6036
  index = i + 1;
7362
6037
  // Get the start search index
7363
6038
  i = index;
7364
6039
  // Locate the end of the c string
7365
- while (buffer$1[i] !== 0x00 && i < buffer$1.length) {
6040
+ while (buffer[i] !== 0x00 && i < buffer.length) {
7366
6041
  i++;
7367
6042
  }
7368
6043
  // If are at the end of the buffer there is a problem with the document
7369
- if (i >= buffer$1.length)
6044
+ if (i >= buffer.length)
7370
6045
  throw new Error('Bad BSON Document: illegal CString');
7371
6046
  // Return the C string
7372
- var regExpOptions = buffer$1.toString('utf8', index, i);
6047
+ var regExpOptions = buffer.toString('utf8', index, i);
7373
6048
  index = i + 1;
7374
6049
  // For each option add the corresponding one for javascript
7375
6050
  var optionsArray = new Array(regExpOptions.length);
@@ -7389,74 +6064,74 @@ function deserializeObject(buffer$1, index, options, isArray) {
7389
6064
  }
7390
6065
  value = new RegExp(source, optionsArray.join(''));
7391
6066
  }
7392
- else if (elementType === constants.BSON_DATA_REGEXP && bsonRegExp === true) {
6067
+ else if (elementType === BSON_DATA_REGEXP && bsonRegExp === true) {
7393
6068
  // Get the start search index
7394
6069
  i = index;
7395
6070
  // Locate the end of the c string
7396
- while (buffer$1[i] !== 0x00 && i < buffer$1.length) {
6071
+ while (buffer[i] !== 0x00 && i < buffer.length) {
7397
6072
  i++;
7398
6073
  }
7399
6074
  // If are at the end of the buffer there is a problem with the document
7400
- if (i >= buffer$1.length)
6075
+ if (i >= buffer.length)
7401
6076
  throw new Error('Bad BSON Document: illegal CString');
7402
6077
  // Return the C string
7403
- var source = buffer$1.toString('utf8', index, i);
6078
+ var source = buffer.toString('utf8', index, i);
7404
6079
  index = i + 1;
7405
6080
  // Get the start search index
7406
6081
  i = index;
7407
6082
  // Locate the end of the c string
7408
- while (buffer$1[i] !== 0x00 && i < buffer$1.length) {
6083
+ while (buffer[i] !== 0x00 && i < buffer.length) {
7409
6084
  i++;
7410
6085
  }
7411
6086
  // If are at the end of the buffer there is a problem with the document
7412
- if (i >= buffer$1.length)
6087
+ if (i >= buffer.length)
7413
6088
  throw new Error('Bad BSON Document: illegal CString');
7414
6089
  // Return the C string
7415
- var regExpOptions = buffer$1.toString('utf8', index, i);
6090
+ var regExpOptions = buffer.toString('utf8', index, i);
7416
6091
  index = i + 1;
7417
6092
  // Set the object
7418
- value = new regexp.BSONRegExp(source, regExpOptions);
6093
+ value = new BSONRegExp(source, regExpOptions);
7419
6094
  }
7420
- else if (elementType === constants.BSON_DATA_SYMBOL) {
7421
- var stringSize = buffer$1[index++] |
7422
- (buffer$1[index++] << 8) |
7423
- (buffer$1[index++] << 16) |
7424
- (buffer$1[index++] << 24);
6095
+ else if (elementType === BSON_DATA_SYMBOL) {
6096
+ var stringSize = buffer[index++] |
6097
+ (buffer[index++] << 8) |
6098
+ (buffer[index++] << 16) |
6099
+ (buffer[index++] << 24);
7425
6100
  if (stringSize <= 0 ||
7426
- stringSize > buffer$1.length - index ||
7427
- buffer$1[index + stringSize - 1] !== 0)
6101
+ stringSize > buffer.length - index ||
6102
+ buffer[index + stringSize - 1] !== 0)
7428
6103
  throw new Error('bad string length in bson');
7429
- var symbol$1 = buffer$1.toString('utf8', index, index + stringSize - 1);
7430
- value = promoteValues ? symbol$1 : new symbol.BSONSymbol(symbol$1);
6104
+ var symbol = buffer.toString('utf8', index, index + stringSize - 1);
6105
+ value = promoteValues ? symbol : new BSONSymbol(symbol);
7431
6106
  index = index + stringSize;
7432
6107
  }
7433
- else if (elementType === constants.BSON_DATA_TIMESTAMP) {
7434
- var lowBits = buffer$1[index++] |
7435
- (buffer$1[index++] << 8) |
7436
- (buffer$1[index++] << 16) |
7437
- (buffer$1[index++] << 24);
7438
- var highBits = buffer$1[index++] |
7439
- (buffer$1[index++] << 8) |
7440
- (buffer$1[index++] << 16) |
7441
- (buffer$1[index++] << 24);
7442
- value = new timestamp.Timestamp(lowBits, highBits);
7443
- }
7444
- else if (elementType === constants.BSON_DATA_MIN_KEY) {
7445
- value = new min_key.MinKey();
7446
- }
7447
- else if (elementType === constants.BSON_DATA_MAX_KEY) {
7448
- value = new max_key.MaxKey();
7449
- }
7450
- else if (elementType === constants.BSON_DATA_CODE) {
7451
- var stringSize = buffer$1[index++] |
7452
- (buffer$1[index++] << 8) |
7453
- (buffer$1[index++] << 16) |
7454
- (buffer$1[index++] << 24);
6108
+ else if (elementType === BSON_DATA_TIMESTAMP) {
6109
+ var lowBits = buffer[index++] |
6110
+ (buffer[index++] << 8) |
6111
+ (buffer[index++] << 16) |
6112
+ (buffer[index++] << 24);
6113
+ var highBits = buffer[index++] |
6114
+ (buffer[index++] << 8) |
6115
+ (buffer[index++] << 16) |
6116
+ (buffer[index++] << 24);
6117
+ value = new Timestamp(lowBits, highBits);
6118
+ }
6119
+ else if (elementType === BSON_DATA_MIN_KEY) {
6120
+ value = new MinKey();
6121
+ }
6122
+ else if (elementType === BSON_DATA_MAX_KEY) {
6123
+ value = new MaxKey();
6124
+ }
6125
+ else if (elementType === BSON_DATA_CODE) {
6126
+ var stringSize = buffer[index++] |
6127
+ (buffer[index++] << 8) |
6128
+ (buffer[index++] << 16) |
6129
+ (buffer[index++] << 24);
7455
6130
  if (stringSize <= 0 ||
7456
- stringSize > buffer$1.length - index ||
7457
- buffer$1[index + stringSize - 1] !== 0)
6131
+ stringSize > buffer.length - index ||
6132
+ buffer[index + stringSize - 1] !== 0)
7458
6133
  throw new Error('bad string length in bson');
7459
- var functionString = buffer$1.toString('utf8', index, index + stringSize - 1);
6134
+ var functionString = buffer.toString('utf8', index, index + stringSize - 1);
7460
6135
  // If we are evaluating the functions
7461
6136
  if (evalFunctions) {
7462
6137
  // If we have cache enabled let's look for the md5 of the function in the cache
@@ -7469,43 +6144,43 @@ function deserializeObject(buffer$1, index, options, isArray) {
7469
6144
  }
7470
6145
  }
7471
6146
  else {
7472
- value = new code.Code(functionString);
6147
+ value = new Code(functionString);
7473
6148
  }
7474
6149
  // Update parse index position
7475
6150
  index = index + stringSize;
7476
6151
  }
7477
- else if (elementType === constants.BSON_DATA_CODE_W_SCOPE) {
7478
- var totalSize = buffer$1[index++] |
7479
- (buffer$1[index++] << 8) |
7480
- (buffer$1[index++] << 16) |
7481
- (buffer$1[index++] << 24);
6152
+ else if (elementType === BSON_DATA_CODE_W_SCOPE) {
6153
+ var totalSize = buffer[index++] |
6154
+ (buffer[index++] << 8) |
6155
+ (buffer[index++] << 16) |
6156
+ (buffer[index++] << 24);
7482
6157
  // Element cannot be shorter than totalSize + stringSize + documentSize + terminator
7483
6158
  if (totalSize < 4 + 4 + 4 + 1) {
7484
6159
  throw new Error('code_w_scope total size shorter minimum expected length');
7485
6160
  }
7486
6161
  // Get the code string size
7487
- var stringSize = buffer$1[index++] |
7488
- (buffer$1[index++] << 8) |
7489
- (buffer$1[index++] << 16) |
7490
- (buffer$1[index++] << 24);
6162
+ var stringSize = buffer[index++] |
6163
+ (buffer[index++] << 8) |
6164
+ (buffer[index++] << 16) |
6165
+ (buffer[index++] << 24);
7491
6166
  // Check if we have a valid string
7492
6167
  if (stringSize <= 0 ||
7493
- stringSize > buffer$1.length - index ||
7494
- buffer$1[index + stringSize - 1] !== 0)
6168
+ stringSize > buffer.length - index ||
6169
+ buffer[index + stringSize - 1] !== 0)
7495
6170
  throw new Error('bad string length in bson');
7496
6171
  // Javascript function
7497
- var functionString = buffer$1.toString('utf8', index, index + stringSize - 1);
6172
+ var functionString = buffer.toString('utf8', index, index + stringSize - 1);
7498
6173
  // Update parse index position
7499
6174
  index = index + stringSize;
7500
6175
  // Parse the element
7501
6176
  var _index = index;
7502
6177
  // Decode the size of the object document
7503
- var objectSize = buffer$1[index] |
7504
- (buffer$1[index + 1] << 8) |
7505
- (buffer$1[index + 2] << 16) |
7506
- (buffer$1[index + 3] << 24);
6178
+ var objectSize = buffer[index] |
6179
+ (buffer[index + 1] << 8) |
6180
+ (buffer[index + 2] << 16) |
6181
+ (buffer[index + 3] << 24);
7507
6182
  // Decode the scope object
7508
- var scopeObject = deserializeObject(buffer$1, _index, options, false);
6183
+ var scopeObject = deserializeObject(buffer, _index, options, false);
7509
6184
  // Adjust the index
7510
6185
  index = index + objectSize;
7511
6186
  // Check if field length is too short
@@ -7529,35 +6204,35 @@ function deserializeObject(buffer$1, index, options, isArray) {
7529
6204
  value.scope = scopeObject;
7530
6205
  }
7531
6206
  else {
7532
- value = new code.Code(functionString, scopeObject);
6207
+ value = new Code(functionString, scopeObject);
7533
6208
  }
7534
6209
  }
7535
- else if (elementType === constants.BSON_DATA_DBPOINTER) {
6210
+ else if (elementType === BSON_DATA_DBPOINTER) {
7536
6211
  // Get the code string size
7537
- var stringSize = buffer$1[index++] |
7538
- (buffer$1[index++] << 8) |
7539
- (buffer$1[index++] << 16) |
7540
- (buffer$1[index++] << 24);
6212
+ var stringSize = buffer[index++] |
6213
+ (buffer[index++] << 8) |
6214
+ (buffer[index++] << 16) |
6215
+ (buffer[index++] << 24);
7541
6216
  // Check if we have a valid string
7542
6217
  if (stringSize <= 0 ||
7543
- stringSize > buffer$1.length - index ||
7544
- buffer$1[index + stringSize - 1] !== 0)
6218
+ stringSize > buffer.length - index ||
6219
+ buffer[index + stringSize - 1] !== 0)
7545
6220
  throw new Error('bad string length in bson');
7546
6221
  // Namespace
7547
- if (!validate_utf8.validateUtf8(buffer$1, index, index + stringSize - 1)) {
6222
+ if (!validateUtf8(buffer, index, index + stringSize - 1)) {
7548
6223
  throw new Error('Invalid UTF-8 string in BSON document');
7549
6224
  }
7550
- var namespace = buffer$1.toString('utf8', index, index + stringSize - 1);
6225
+ var namespace = buffer.toString('utf8', index, index + stringSize - 1);
7551
6226
  // Update parse index position
7552
6227
  index = index + stringSize;
7553
6228
  // Read the oid
7554
- var oidBuffer = buffer.Buffer.alloc(12);
7555
- buffer$1.copy(oidBuffer, 0, index, index + 12);
7556
- var oid = new objectid.ObjectId(oidBuffer);
6229
+ var oidBuffer = buffer_1.alloc(12);
6230
+ buffer.copy(oidBuffer, 0, index, index + 12);
6231
+ var oid = new ObjectId(oidBuffer);
7557
6232
  // Update the index
7558
6233
  index = index + 12;
7559
6234
  // Upgrade to DBRef type
7560
- value = new db_ref.DBRef(namespace, oid);
6235
+ value = new DBRef(namespace, oid);
7561
6236
  }
7562
6237
  else {
7563
6238
  throw new Error('Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"');
@@ -7580,22 +6255,15 @@ function deserializeObject(buffer$1, index, options, isArray) {
7580
6255
  throw new Error('corrupt array bson');
7581
6256
  throw new Error('corrupt object bson');
7582
6257
  }
7583
- // check if object's $ keys are those of a DBRef
7584
- var dollarKeys = Object.keys(object).filter(function (k) { return k.startsWith('$'); });
7585
- var valid = true;
7586
- dollarKeys.forEach(function (k) {
7587
- if (['$ref', '$id', '$db'].indexOf(k) === -1)
7588
- valid = false;
7589
- });
7590
- // if a $key not in "$ref", "$id", "$db", don't make a DBRef
7591
- if (!valid)
6258
+ // if we did not find "$ref", "$id", "$db", or found an extraneous $key, don't make a DBRef
6259
+ if (!isPossibleDBRef)
7592
6260
  return object;
7593
- if (db_ref.isDBRefLike(object)) {
6261
+ if (isDBRefLike(object)) {
7594
6262
  var copy = Object.assign({}, object);
7595
6263
  delete copy.$ref;
7596
6264
  delete copy.$id;
7597
6265
  delete copy.$db;
7598
- return new db_ref.DBRef(object.$ref, object.$id, object.$db, copy);
6266
+ return new DBRef(object.$ref, object.$id, object.$db, copy);
7599
6267
  }
7600
6268
  return object;
7601
6269
  }
@@ -7614,81 +6282,8 @@ function isolateEval(functionString, functionCache, object) {
7614
6282
  // Set the object
7615
6283
  return functionCache[functionString].bind(object);
7616
6284
  }
7617
- //# sourceMappingURL=deserializer.js.map
7618
- });
7619
6285
 
7620
- unwrapExports(deserializer);
7621
- deserializer.deserialize;
7622
-
7623
- var float_parser = createCommonjsModule(function (module, exports) {
7624
6286
  // Copyright (c) 2008, Fair Oaks Labs, Inc.
7625
- // All rights reserved.
7626
- //
7627
- // Redistribution and use in source and binary forms, with or without
7628
- // modification, are permitted provided that the following conditions are met:
7629
- //
7630
- // * Redistributions of source code must retain the above copyright notice,
7631
- // this list of conditions and the following disclaimer.
7632
- //
7633
- // * Redistributions in binary form must reproduce the above copyright notice,
7634
- // this list of conditions and the following disclaimer in the documentation
7635
- // and/or other materials provided with the distribution.
7636
- //
7637
- // * Neither the name of Fair Oaks Labs, Inc. nor the names of its contributors
7638
- // may be used to endorse or promote products derived from this software
7639
- // without specific prior written permission.
7640
- //
7641
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
7642
- // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7643
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7644
- // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
7645
- // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
7646
- // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
7647
- // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
7648
- // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
7649
- // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
7650
- // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
7651
- // POSSIBILITY OF SUCH DAMAGE.
7652
- //
7653
- //
7654
- // Modifications to writeIEEE754 to support negative zeroes made by Brian White
7655
- Object.defineProperty(exports, "__esModule", { value: true });
7656
- exports.writeIEEE754 = exports.readIEEE754 = void 0;
7657
- function readIEEE754(buffer, offset, endian, mLen, nBytes) {
7658
- var e;
7659
- var m;
7660
- var bBE = endian === 'big';
7661
- var eLen = nBytes * 8 - mLen - 1;
7662
- var eMax = (1 << eLen) - 1;
7663
- var eBias = eMax >> 1;
7664
- var nBits = -7;
7665
- var i = bBE ? 0 : nBytes - 1;
7666
- var d = bBE ? 1 : -1;
7667
- var s = buffer[offset + i];
7668
- i += d;
7669
- e = s & ((1 << -nBits) - 1);
7670
- s >>= -nBits;
7671
- nBits += eLen;
7672
- for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8)
7673
- ;
7674
- m = e & ((1 << -nBits) - 1);
7675
- e >>= -nBits;
7676
- nBits += mLen;
7677
- for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8)
7678
- ;
7679
- if (e === 0) {
7680
- e = 1 - eBias;
7681
- }
7682
- else if (e === eMax) {
7683
- return m ? NaN : (s ? -1 : 1) * Infinity;
7684
- }
7685
- else {
7686
- m = m + Math.pow(2, mLen);
7687
- e = e - eBias;
7688
- }
7689
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
7690
- }
7691
- exports.readIEEE754 = readIEEE754;
7692
6287
  function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
7693
6288
  var e;
7694
6289
  var m;
@@ -7755,24 +6350,6 @@ function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
7755
6350
  }
7756
6351
  buffer[offset + i - d] |= s * 128;
7757
6352
  }
7758
- exports.writeIEEE754 = writeIEEE754;
7759
- //# sourceMappingURL=float_parser.js.map
7760
- });
7761
-
7762
- unwrapExports(float_parser);
7763
- float_parser.writeIEEE754;
7764
- float_parser.readIEEE754;
7765
-
7766
- var serializer = createCommonjsModule(function (module, exports) {
7767
- Object.defineProperty(exports, "__esModule", { value: true });
7768
- exports.serializeInto = void 0;
7769
-
7770
-
7771
-
7772
-
7773
-
7774
-
7775
-
7776
6353
 
7777
6354
  var regexp = /\x00/; // eslint-disable-line no-control-regex
7778
6355
  var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
@@ -7783,7 +6360,7 @@ var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
7783
6360
  */
7784
6361
  function serializeString(buffer, key, value, index, isArray) {
7785
6362
  // Encode String type
7786
- buffer[index++] = constants.BSON_DATA_STRING;
6363
+ buffer[index++] = BSON_DATA_STRING;
7787
6364
  // Number of written bytes
7788
6365
  var numberOfWrittenBytes = !isArray
7789
6366
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7808,11 +6385,11 @@ function serializeNumber(buffer, key, value, index, isArray) {
7808
6385
  // We have an integer value
7809
6386
  // TODO(NODE-2529): Add support for big int
7810
6387
  if (Number.isInteger(value) &&
7811
- value >= constants.BSON_INT32_MIN &&
7812
- value <= constants.BSON_INT32_MAX) {
6388
+ value >= BSON_INT32_MIN &&
6389
+ value <= BSON_INT32_MAX) {
7813
6390
  // If the value fits in 32 bits encode as int32
7814
6391
  // Set int type 32 bits or less
7815
- buffer[index++] = constants.BSON_DATA_INT;
6392
+ buffer[index++] = BSON_DATA_INT;
7816
6393
  // Number of written bytes
7817
6394
  var numberOfWrittenBytes = !isArray
7818
6395
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7828,7 +6405,7 @@ function serializeNumber(buffer, key, value, index, isArray) {
7828
6405
  }
7829
6406
  else {
7830
6407
  // Encode as double
7831
- buffer[index++] = constants.BSON_DATA_NUMBER;
6408
+ buffer[index++] = BSON_DATA_NUMBER;
7832
6409
  // Number of written bytes
7833
6410
  var numberOfWrittenBytes = !isArray
7834
6411
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7837,7 +6414,7 @@ function serializeNumber(buffer, key, value, index, isArray) {
7837
6414
  index = index + numberOfWrittenBytes;
7838
6415
  buffer[index++] = 0;
7839
6416
  // Write float
7840
- float_parser.writeIEEE754(buffer, value, index, 'little', 52, 8);
6417
+ writeIEEE754(buffer, value, index, 'little', 52, 8);
7841
6418
  // Adjust index
7842
6419
  index = index + 8;
7843
6420
  }
@@ -7845,7 +6422,7 @@ function serializeNumber(buffer, key, value, index, isArray) {
7845
6422
  }
7846
6423
  function serializeNull(buffer, key, _, index, isArray) {
7847
6424
  // Set long type
7848
- buffer[index++] = constants.BSON_DATA_NULL;
6425
+ buffer[index++] = BSON_DATA_NULL;
7849
6426
  // Number of written bytes
7850
6427
  var numberOfWrittenBytes = !isArray
7851
6428
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7857,7 +6434,7 @@ function serializeNull(buffer, key, _, index, isArray) {
7857
6434
  }
7858
6435
  function serializeBoolean(buffer, key, value, index, isArray) {
7859
6436
  // Write the type
7860
- buffer[index++] = constants.BSON_DATA_BOOLEAN;
6437
+ buffer[index++] = BSON_DATA_BOOLEAN;
7861
6438
  // Number of written bytes
7862
6439
  var numberOfWrittenBytes = !isArray
7863
6440
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7871,7 +6448,7 @@ function serializeBoolean(buffer, key, value, index, isArray) {
7871
6448
  }
7872
6449
  function serializeDate(buffer, key, value, index, isArray) {
7873
6450
  // Write the type
7874
- buffer[index++] = constants.BSON_DATA_DATE;
6451
+ buffer[index++] = BSON_DATA_DATE;
7875
6452
  // Number of written bytes
7876
6453
  var numberOfWrittenBytes = !isArray
7877
6454
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7880,7 +6457,7 @@ function serializeDate(buffer, key, value, index, isArray) {
7880
6457
  index = index + numberOfWrittenBytes;
7881
6458
  buffer[index++] = 0;
7882
6459
  // Write the date
7883
- var dateInMilis = long_1.Long.fromNumber(value.getTime());
6460
+ var dateInMilis = Long.fromNumber(value.getTime());
7884
6461
  var lowBits = dateInMilis.getLowBits();
7885
6462
  var highBits = dateInMilis.getHighBits();
7886
6463
  // Encode low bits
@@ -7897,7 +6474,7 @@ function serializeDate(buffer, key, value, index, isArray) {
7897
6474
  }
7898
6475
  function serializeRegExp(buffer, key, value, index, isArray) {
7899
6476
  // Write the type
7900
- buffer[index++] = constants.BSON_DATA_REGEXP;
6477
+ buffer[index++] = BSON_DATA_REGEXP;
7901
6478
  // Number of written bytes
7902
6479
  var numberOfWrittenBytes = !isArray
7903
6480
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7925,7 +6502,7 @@ function serializeRegExp(buffer, key, value, index, isArray) {
7925
6502
  }
7926
6503
  function serializeBSONRegExp(buffer, key, value, index, isArray) {
7927
6504
  // Write the type
7928
- buffer[index++] = constants.BSON_DATA_REGEXP;
6505
+ buffer[index++] = BSON_DATA_REGEXP;
7929
6506
  // Number of written bytes
7930
6507
  var numberOfWrittenBytes = !isArray
7931
6508
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7952,13 +6529,13 @@ function serializeBSONRegExp(buffer, key, value, index, isArray) {
7952
6529
  function serializeMinMax(buffer, key, value, index, isArray) {
7953
6530
  // Write the type of either min or max key
7954
6531
  if (value === null) {
7955
- buffer[index++] = constants.BSON_DATA_NULL;
6532
+ buffer[index++] = BSON_DATA_NULL;
7956
6533
  }
7957
6534
  else if (value._bsontype === 'MinKey') {
7958
- buffer[index++] = constants.BSON_DATA_MIN_KEY;
6535
+ buffer[index++] = BSON_DATA_MIN_KEY;
7959
6536
  }
7960
6537
  else {
7961
- buffer[index++] = constants.BSON_DATA_MAX_KEY;
6538
+ buffer[index++] = BSON_DATA_MAX_KEY;
7962
6539
  }
7963
6540
  // Number of written bytes
7964
6541
  var numberOfWrittenBytes = !isArray
@@ -7971,7 +6548,7 @@ function serializeMinMax(buffer, key, value, index, isArray) {
7971
6548
  }
7972
6549
  function serializeObjectId(buffer, key, value, index, isArray) {
7973
6550
  // Write the type
7974
- buffer[index++] = constants.BSON_DATA_OID;
6551
+ buffer[index++] = BSON_DATA_OID;
7975
6552
  // Number of written bytes
7976
6553
  var numberOfWrittenBytes = !isArray
7977
6554
  ? buffer.write(key, index, undefined, 'utf8')
@@ -7983,8 +6560,10 @@ function serializeObjectId(buffer, key, value, index, isArray) {
7983
6560
  if (typeof value.id === 'string') {
7984
6561
  buffer.write(value.id, index, undefined, 'binary');
7985
6562
  }
7986
- else if (value.id && value.id.copy) {
7987
- value.id.copy(buffer, index, 0, 12);
6563
+ else if (isUint8Array(value.id)) {
6564
+ // Use the standard JS methods here because buffer.copy() is buggy with the
6565
+ // browser polyfill
6566
+ buffer.set(value.id.subarray(0, 12), index);
7988
6567
  }
7989
6568
  else {
7990
6569
  throw new TypeError('object [' + JSON.stringify(value) + '] is not a valid ObjectId');
@@ -7994,7 +6573,7 @@ function serializeObjectId(buffer, key, value, index, isArray) {
7994
6573
  }
7995
6574
  function serializeBuffer(buffer, key, value, index, isArray) {
7996
6575
  // Write the type
7997
- buffer[index++] = constants.BSON_DATA_BINARY;
6576
+ buffer[index++] = BSON_DATA_BINARY;
7998
6577
  // Number of written bytes
7999
6578
  var numberOfWrittenBytes = !isArray
8000
6579
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8010,9 +6589,9 @@ function serializeBuffer(buffer, key, value, index, isArray) {
8010
6589
  buffer[index++] = (size >> 16) & 0xff;
8011
6590
  buffer[index++] = (size >> 24) & 0xff;
8012
6591
  // Write the default subtype
8013
- buffer[index++] = constants.BSON_BINARY_SUBTYPE_DEFAULT;
6592
+ buffer[index++] = BSON_BINARY_SUBTYPE_DEFAULT;
8014
6593
  // Copy the content form the binary field to the buffer
8015
- buffer.set(ensure_buffer.ensureBuffer(value), index);
6594
+ buffer.set(ensureBuffer(value), index);
8016
6595
  // Adjust the index
8017
6596
  index = index + size;
8018
6597
  return index;
@@ -8031,7 +6610,7 @@ function serializeObject(buffer, key, value, index, checkKeys, depth, serializeF
8031
6610
  // Push value to stack
8032
6611
  path.push(value);
8033
6612
  // Write the type
8034
- buffer[index++] = Array.isArray(value) ? constants.BSON_DATA_ARRAY : constants.BSON_DATA_OBJECT;
6613
+ buffer[index++] = Array.isArray(value) ? BSON_DATA_ARRAY : BSON_DATA_OBJECT;
8035
6614
  // Number of written bytes
8036
6615
  var numberOfWrittenBytes = !isArray
8037
6616
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8045,7 +6624,7 @@ function serializeObject(buffer, key, value, index, checkKeys, depth, serializeF
8045
6624
  return endIndex;
8046
6625
  }
8047
6626
  function serializeDecimal128(buffer, key, value, index, isArray) {
8048
- buffer[index++] = constants.BSON_DATA_DECIMAL128;
6627
+ buffer[index++] = BSON_DATA_DECIMAL128;
8049
6628
  // Number of written bytes
8050
6629
  var numberOfWrittenBytes = !isArray
8051
6630
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8054,13 +6633,15 @@ function serializeDecimal128(buffer, key, value, index, isArray) {
8054
6633
  index = index + numberOfWrittenBytes;
8055
6634
  buffer[index++] = 0;
8056
6635
  // Write the data from the value
8057
- value.bytes.copy(buffer, index, 0, 16);
6636
+ // Prefer the standard JS methods because their typechecking is not buggy,
6637
+ // unlike the `buffer` polyfill's.
6638
+ buffer.set(value.bytes.subarray(0, 16), index);
8058
6639
  return index + 16;
8059
6640
  }
8060
6641
  function serializeLong(buffer, key, value, index, isArray) {
8061
6642
  // Write the type
8062
6643
  buffer[index++] =
8063
- value._bsontype === 'Long' ? constants.BSON_DATA_LONG : constants.BSON_DATA_TIMESTAMP;
6644
+ value._bsontype === 'Long' ? BSON_DATA_LONG : BSON_DATA_TIMESTAMP;
8064
6645
  // Number of written bytes
8065
6646
  var numberOfWrittenBytes = !isArray
8066
6647
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8086,7 +6667,7 @@ function serializeLong(buffer, key, value, index, isArray) {
8086
6667
  function serializeInt32(buffer, key, value, index, isArray) {
8087
6668
  value = value.valueOf();
8088
6669
  // Set int type 32 bits or less
8089
- buffer[index++] = constants.BSON_DATA_INT;
6670
+ buffer[index++] = BSON_DATA_INT;
8090
6671
  // Number of written bytes
8091
6672
  var numberOfWrittenBytes = !isArray
8092
6673
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8103,7 +6684,7 @@ function serializeInt32(buffer, key, value, index, isArray) {
8103
6684
  }
8104
6685
  function serializeDouble(buffer, key, value, index, isArray) {
8105
6686
  // Encode as double
8106
- buffer[index++] = constants.BSON_DATA_NUMBER;
6687
+ buffer[index++] = BSON_DATA_NUMBER;
8107
6688
  // Number of written bytes
8108
6689
  var numberOfWrittenBytes = !isArray
8109
6690
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8112,13 +6693,13 @@ function serializeDouble(buffer, key, value, index, isArray) {
8112
6693
  index = index + numberOfWrittenBytes;
8113
6694
  buffer[index++] = 0;
8114
6695
  // Write float
8115
- float_parser.writeIEEE754(buffer, value.value, index, 'little', 52, 8);
6696
+ writeIEEE754(buffer, value.value, index, 'little', 52, 8);
8116
6697
  // Adjust index
8117
6698
  index = index + 8;
8118
6699
  return index;
8119
6700
  }
8120
6701
  function serializeFunction(buffer, key, value, index, _checkKeys, _depth, isArray) {
8121
- buffer[index++] = constants.BSON_DATA_CODE;
6702
+ buffer[index++] = BSON_DATA_CODE;
8122
6703
  // Number of written bytes
8123
6704
  var numberOfWrittenBytes = !isArray
8124
6705
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8127,7 +6708,7 @@ function serializeFunction(buffer, key, value, index, _checkKeys, _depth, isArra
8127
6708
  index = index + numberOfWrittenBytes;
8128
6709
  buffer[index++] = 0;
8129
6710
  // Function string
8130
- var functionString = utils.normalizedFunctionString(value);
6711
+ var functionString = normalizedFunctionString(value);
8131
6712
  // Write the string
8132
6713
  var size = buffer.write(functionString, index + 4, undefined, 'utf8') + 1;
8133
6714
  // Write the size of the string to buffer
@@ -8149,7 +6730,7 @@ function serializeCode(buffer, key, value, index, checkKeys, depth, serializeFun
8149
6730
  if (isArray === void 0) { isArray = false; }
8150
6731
  if (value.scope && typeof value.scope === 'object') {
8151
6732
  // Write the type
8152
- buffer[index++] = constants.BSON_DATA_CODE_W_SCOPE;
6733
+ buffer[index++] = BSON_DATA_CODE_W_SCOPE;
8153
6734
  // Number of written bytes
8154
6735
  var numberOfWrittenBytes = !isArray
8155
6736
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8190,7 +6771,7 @@ function serializeCode(buffer, key, value, index, checkKeys, depth, serializeFun
8190
6771
  buffer[index++] = 0;
8191
6772
  }
8192
6773
  else {
8193
- buffer[index++] = constants.BSON_DATA_CODE;
6774
+ buffer[index++] = BSON_DATA_CODE;
8194
6775
  // Number of written bytes
8195
6776
  var numberOfWrittenBytes = !isArray
8196
6777
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8216,7 +6797,7 @@ function serializeCode(buffer, key, value, index, checkKeys, depth, serializeFun
8216
6797
  }
8217
6798
  function serializeBinary(buffer, key, value, index, isArray) {
8218
6799
  // Write the type
8219
- buffer[index++] = constants.BSON_DATA_BINARY;
6800
+ buffer[index++] = BSON_DATA_BINARY;
8220
6801
  // Number of written bytes
8221
6802
  var numberOfWrittenBytes = !isArray
8222
6803
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8229,7 +6810,7 @@ function serializeBinary(buffer, key, value, index, isArray) {
8229
6810
  // Calculate size
8230
6811
  var size = value.position;
8231
6812
  // Add the deprecated 02 type 4 bytes of size to total
8232
- if (value.sub_type === binary.Binary.SUBTYPE_BYTE_ARRAY)
6813
+ if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY)
8233
6814
  size = size + 4;
8234
6815
  // Write the size of the string to buffer
8235
6816
  buffer[index++] = size & 0xff;
@@ -8239,7 +6820,7 @@ function serializeBinary(buffer, key, value, index, isArray) {
8239
6820
  // Write the subtype to the buffer
8240
6821
  buffer[index++] = value.sub_type;
8241
6822
  // If we have binary type 2 the 4 first bytes are the size
8242
- if (value.sub_type === binary.Binary.SUBTYPE_BYTE_ARRAY) {
6823
+ if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
8243
6824
  size = size - 4;
8244
6825
  buffer[index++] = size & 0xff;
8245
6826
  buffer[index++] = (size >> 8) & 0xff;
@@ -8254,7 +6835,7 @@ function serializeBinary(buffer, key, value, index, isArray) {
8254
6835
  }
8255
6836
  function serializeSymbol(buffer, key, value, index, isArray) {
8256
6837
  // Write the type
8257
- buffer[index++] = constants.BSON_DATA_SYMBOL;
6838
+ buffer[index++] = BSON_DATA_SYMBOL;
8258
6839
  // Number of written bytes
8259
6840
  var numberOfWrittenBytes = !isArray
8260
6841
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8277,7 +6858,7 @@ function serializeSymbol(buffer, key, value, index, isArray) {
8277
6858
  }
8278
6859
  function serializeDBRef(buffer, key, value, index, depth, serializeFunctions, isArray) {
8279
6860
  // Write the type
8280
- buffer[index++] = constants.BSON_DATA_OBJECT;
6861
+ buffer[index++] = BSON_DATA_OBJECT;
8281
6862
  // Number of written bytes
8282
6863
  var numberOfWrittenBytes = !isArray
8283
6864
  ? buffer.write(key, index, undefined, 'utf8')
@@ -8342,7 +6923,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8342
6923
  else if (typeof value === 'boolean') {
8343
6924
  index = serializeBoolean(buffer, key, value, index, true);
8344
6925
  }
8345
- else if (value instanceof Date || utils.isDate(value)) {
6926
+ else if (value instanceof Date || isDate(value)) {
8346
6927
  index = serializeDate(buffer, key, value, index, true);
8347
6928
  }
8348
6929
  else if (value === undefined) {
@@ -8354,17 +6935,17 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8354
6935
  else if (value['_bsontype'] === 'ObjectId' || value['_bsontype'] === 'ObjectID') {
8355
6936
  index = serializeObjectId(buffer, key, value, index, true);
8356
6937
  }
8357
- else if (utils.isUint8Array(value)) {
6938
+ else if (isUint8Array(value)) {
8358
6939
  index = serializeBuffer(buffer, key, value, index, true);
8359
6940
  }
8360
- else if (value instanceof RegExp || utils.isRegExp(value)) {
6941
+ else if (value instanceof RegExp || isRegExp(value)) {
8361
6942
  index = serializeRegExp(buffer, key, value, index, true);
8362
6943
  }
8363
6944
  else if (typeof value === 'object' && value['_bsontype'] == null) {
8364
6945
  index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, true, path);
8365
6946
  }
8366
6947
  else if (typeof value === 'object' &&
8367
- extended_json.isBSONType(value) &&
6948
+ isBSONType(value) &&
8368
6949
  value._bsontype === 'Decimal128') {
8369
6950
  index = serializeDecimal128(buffer, key, value, index, true);
8370
6951
  }
@@ -8403,7 +6984,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8403
6984
  }
8404
6985
  }
8405
6986
  }
8406
- else if (object instanceof map.Map || utils.isMap(object)) {
6987
+ else if (object instanceof bsonMap || isMap(object)) {
8407
6988
  var iterator = object.entries();
8408
6989
  var done = false;
8409
6990
  while (!done) {
@@ -8440,13 +7021,13 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8440
7021
  else if (type === 'number') {
8441
7022
  index = serializeNumber(buffer, key, value, index);
8442
7023
  }
8443
- else if (type === 'bigint' || utils.isBigInt64Array(value) || utils.isBigUInt64Array(value)) {
7024
+ else if (type === 'bigint' || isBigInt64Array(value) || isBigUInt64Array(value)) {
8444
7025
  throw new TypeError('Unsupported type BigInt, please use Decimal128');
8445
7026
  }
8446
7027
  else if (type === 'boolean') {
8447
7028
  index = serializeBoolean(buffer, key, value, index);
8448
7029
  }
8449
- else if (value instanceof Date || utils.isDate(value)) {
7030
+ else if (value instanceof Date || isDate(value)) {
8450
7031
  index = serializeDate(buffer, key, value, index);
8451
7032
  }
8452
7033
  else if (value === null || (value === undefined && ignoreUndefined === false)) {
@@ -8455,10 +7036,10 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8455
7036
  else if (value['_bsontype'] === 'ObjectId' || value['_bsontype'] === 'ObjectID') {
8456
7037
  index = serializeObjectId(buffer, key, value, index);
8457
7038
  }
8458
- else if (utils.isUint8Array(value)) {
7039
+ else if (isUint8Array(value)) {
8459
7040
  index = serializeBuffer(buffer, key, value, index);
8460
7041
  }
8461
- else if (value instanceof RegExp || utils.isRegExp(value)) {
7042
+ else if (value instanceof RegExp || isRegExp(value)) {
8462
7043
  index = serializeRegExp(buffer, key, value, index);
8463
7044
  }
8464
7045
  else if (type === 'object' && value['_bsontype'] == null) {
@@ -8550,7 +7131,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8550
7131
  else if (type === 'boolean') {
8551
7132
  index = serializeBoolean(buffer, key, value, index);
8552
7133
  }
8553
- else if (value instanceof Date || utils.isDate(value)) {
7134
+ else if (value instanceof Date || isDate(value)) {
8554
7135
  index = serializeDate(buffer, key, value, index);
8555
7136
  }
8556
7137
  else if (value === undefined) {
@@ -8563,10 +7144,10 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8563
7144
  else if (value['_bsontype'] === 'ObjectId' || value['_bsontype'] === 'ObjectID') {
8564
7145
  index = serializeObjectId(buffer, key, value, index);
8565
7146
  }
8566
- else if (utils.isUint8Array(value)) {
7147
+ else if (isUint8Array(value)) {
8567
7148
  index = serializeBuffer(buffer, key, value, index);
8568
7149
  }
8569
- else if (value instanceof RegExp || utils.isRegExp(value)) {
7150
+ else if (value instanceof RegExp || isRegExp(value)) {
8570
7151
  index = serializeRegExp(buffer, key, value, index);
8571
7152
  }
8572
7153
  else if (type === 'object' && value['_bsontype'] == null) {
@@ -8623,97 +7204,12 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
8623
7204
  buffer[startingIndex++] = (size >> 24) & 0xff;
8624
7205
  return index;
8625
7206
  }
8626
- exports.serializeInto = serializeInto;
8627
- //# sourceMappingURL=serializer.js.map
8628
- });
8629
-
8630
- unwrapExports(serializer);
8631
- serializer.serializeInto;
8632
-
8633
- var bson = createCommonjsModule(function (module, exports) {
8634
- Object.defineProperty(exports, "__esModule", { value: true });
8635
- exports.ObjectID = exports.Decimal128 = exports.BSONRegExp = exports.MaxKey = exports.MinKey = exports.Int32 = exports.Double = exports.Timestamp = exports.Long = exports.UUID = 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;
8636
- exports.deserializeStream = exports.calculateObjectSize = exports.deserialize = exports.serializeWithBufferAndIndex = exports.serialize = exports.setInternalBufferSize = void 0;
8637
-
8638
-
8639
- Object.defineProperty(exports, "Binary", { enumerable: true, get: function () { return binary.Binary; } });
8640
-
8641
- Object.defineProperty(exports, "Code", { enumerable: true, get: function () { return code.Code; } });
8642
-
8643
- Object.defineProperty(exports, "DBRef", { enumerable: true, get: function () { return db_ref.DBRef; } });
8644
-
8645
- Object.defineProperty(exports, "Decimal128", { enumerable: true, get: function () { return decimal128.Decimal128; } });
8646
7207
 
8647
- Object.defineProperty(exports, "Double", { enumerable: true, get: function () { return double_1.Double; } });
8648
-
8649
-
8650
-
8651
- Object.defineProperty(exports, "Int32", { enumerable: true, get: function () { return int_32.Int32; } });
8652
-
8653
- Object.defineProperty(exports, "Long", { enumerable: true, get: function () { return long_1.Long; } });
8654
-
8655
- Object.defineProperty(exports, "Map", { enumerable: true, get: function () { return map.Map; } });
8656
-
8657
- Object.defineProperty(exports, "MaxKey", { enumerable: true, get: function () { return max_key.MaxKey; } });
8658
-
8659
- Object.defineProperty(exports, "MinKey", { enumerable: true, get: function () { return min_key.MinKey; } });
8660
-
8661
- Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return objectid.ObjectId; } });
8662
- Object.defineProperty(exports, "ObjectID", { enumerable: true, get: function () { return objectid.ObjectId; } });
8663
-
8664
- // Parts of the parser
8665
-
8666
-
8667
-
8668
- Object.defineProperty(exports, "BSONRegExp", { enumerable: true, get: function () { return regexp.BSONRegExp; } });
8669
-
8670
- Object.defineProperty(exports, "BSONSymbol", { enumerable: true, get: function () { return symbol.BSONSymbol; } });
8671
-
8672
- Object.defineProperty(exports, "Timestamp", { enumerable: true, get: function () { return timestamp.Timestamp; } });
8673
-
8674
- Object.defineProperty(exports, "UUID", { enumerable: true, get: function () { return uuid.UUID; } });
8675
-
8676
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_BYTE_ARRAY", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_BYTE_ARRAY; } });
8677
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_DEFAULT", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_DEFAULT; } });
8678
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_FUNCTION", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_FUNCTION; } });
8679
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_MD5", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_MD5; } });
8680
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_USER_DEFINED", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_USER_DEFINED; } });
8681
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_UUID", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_UUID; } });
8682
- Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_UUID_NEW", { enumerable: true, get: function () { return constants.BSON_BINARY_SUBTYPE_UUID_NEW; } });
8683
- Object.defineProperty(exports, "BSON_DATA_ARRAY", { enumerable: true, get: function () { return constants.BSON_DATA_ARRAY; } });
8684
- Object.defineProperty(exports, "BSON_DATA_BINARY", { enumerable: true, get: function () { return constants.BSON_DATA_BINARY; } });
8685
- Object.defineProperty(exports, "BSON_DATA_BOOLEAN", { enumerable: true, get: function () { return constants.BSON_DATA_BOOLEAN; } });
8686
- Object.defineProperty(exports, "BSON_DATA_CODE", { enumerable: true, get: function () { return constants.BSON_DATA_CODE; } });
8687
- Object.defineProperty(exports, "BSON_DATA_CODE_W_SCOPE", { enumerable: true, get: function () { return constants.BSON_DATA_CODE_W_SCOPE; } });
8688
- Object.defineProperty(exports, "BSON_DATA_DATE", { enumerable: true, get: function () { return constants.BSON_DATA_DATE; } });
8689
- Object.defineProperty(exports, "BSON_DATA_DBPOINTER", { enumerable: true, get: function () { return constants.BSON_DATA_DBPOINTER; } });
8690
- Object.defineProperty(exports, "BSON_DATA_DECIMAL128", { enumerable: true, get: function () { return constants.BSON_DATA_DECIMAL128; } });
8691
- Object.defineProperty(exports, "BSON_DATA_INT", { enumerable: true, get: function () { return constants.BSON_DATA_INT; } });
8692
- Object.defineProperty(exports, "BSON_DATA_LONG", { enumerable: true, get: function () { return constants.BSON_DATA_LONG; } });
8693
- Object.defineProperty(exports, "BSON_DATA_MAX_KEY", { enumerable: true, get: function () { return constants.BSON_DATA_MAX_KEY; } });
8694
- Object.defineProperty(exports, "BSON_DATA_MIN_KEY", { enumerable: true, get: function () { return constants.BSON_DATA_MIN_KEY; } });
8695
- Object.defineProperty(exports, "BSON_DATA_NULL", { enumerable: true, get: function () { return constants.BSON_DATA_NULL; } });
8696
- Object.defineProperty(exports, "BSON_DATA_NUMBER", { enumerable: true, get: function () { return constants.BSON_DATA_NUMBER; } });
8697
- Object.defineProperty(exports, "BSON_DATA_OBJECT", { enumerable: true, get: function () { return constants.BSON_DATA_OBJECT; } });
8698
- Object.defineProperty(exports, "BSON_DATA_OID", { enumerable: true, get: function () { return constants.BSON_DATA_OID; } });
8699
- Object.defineProperty(exports, "BSON_DATA_REGEXP", { enumerable: true, get: function () { return constants.BSON_DATA_REGEXP; } });
8700
- Object.defineProperty(exports, "BSON_DATA_STRING", { enumerable: true, get: function () { return constants.BSON_DATA_STRING; } });
8701
- Object.defineProperty(exports, "BSON_DATA_SYMBOL", { enumerable: true, get: function () { return constants.BSON_DATA_SYMBOL; } });
8702
- Object.defineProperty(exports, "BSON_DATA_TIMESTAMP", { enumerable: true, get: function () { return constants.BSON_DATA_TIMESTAMP; } });
8703
- Object.defineProperty(exports, "BSON_DATA_UNDEFINED", { enumerable: true, get: function () { return constants.BSON_DATA_UNDEFINED; } });
8704
- Object.defineProperty(exports, "BSON_INT32_MAX", { enumerable: true, get: function () { return constants.BSON_INT32_MAX; } });
8705
- Object.defineProperty(exports, "BSON_INT32_MIN", { enumerable: true, get: function () { return constants.BSON_INT32_MIN; } });
8706
- Object.defineProperty(exports, "BSON_INT64_MAX", { enumerable: true, get: function () { return constants.BSON_INT64_MAX; } });
8707
- Object.defineProperty(exports, "BSON_INT64_MIN", { enumerable: true, get: function () { return constants.BSON_INT64_MIN; } });
8708
- var extended_json_2 = extended_json;
8709
- Object.defineProperty(exports, "EJSON", { enumerable: true, get: function () { return extended_json_2.EJSON; } });
8710
- var timestamp_2 = timestamp;
8711
- Object.defineProperty(exports, "LongWithoutOverridesClass", { enumerable: true, get: function () { return timestamp_2.LongWithoutOverridesClass; } });
8712
7208
  /** @internal */
8713
7209
  // Default Max Size
8714
7210
  var MAXSIZE = 1024 * 1024 * 17;
8715
7211
  // Current Internal Temporary Serialization Buffer
8716
- var buffer$1 = buffer.Buffer.alloc(MAXSIZE);
7212
+ var buffer = buffer_1.alloc(MAXSIZE);
8717
7213
  /**
8718
7214
  * Sets the size of the internal serialization buffer.
8719
7215
  *
@@ -8722,11 +7218,10 @@ var buffer$1 = buffer.Buffer.alloc(MAXSIZE);
8722
7218
  */
8723
7219
  function setInternalBufferSize(size) {
8724
7220
  // Resize the internal serialization buffer if needed
8725
- if (buffer$1.length < size) {
8726
- buffer$1 = buffer.Buffer.alloc(size);
7221
+ if (buffer.length < size) {
7222
+ buffer = buffer_1.alloc(size);
8727
7223
  }
8728
7224
  }
8729
- exports.setInternalBufferSize = setInternalBufferSize;
8730
7225
  /**
8731
7226
  * Serialize a Javascript object.
8732
7227
  *
@@ -8742,19 +7237,18 @@ function serialize(object, options) {
8742
7237
  var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
8743
7238
  var minInternalBufferSize = typeof options.minInternalBufferSize === 'number' ? options.minInternalBufferSize : MAXSIZE;
8744
7239
  // Resize the internal serialization buffer if needed
8745
- if (buffer$1.length < minInternalBufferSize) {
8746
- buffer$1 = buffer.Buffer.alloc(minInternalBufferSize);
7240
+ if (buffer.length < minInternalBufferSize) {
7241
+ buffer = buffer_1.alloc(minInternalBufferSize);
8747
7242
  }
8748
7243
  // Attempt to serialize
8749
- var serializationIndex = serializer.serializeInto(buffer$1, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined, []);
7244
+ var serializationIndex = serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined, []);
8750
7245
  // Create the final buffer
8751
- var finishedBuffer = buffer.Buffer.alloc(serializationIndex);
7246
+ var finishedBuffer = buffer_1.alloc(serializationIndex);
8752
7247
  // Copy into the finished buffer
8753
- buffer$1.copy(finishedBuffer, 0, 0, finishedBuffer.length);
7248
+ buffer.copy(finishedBuffer, 0, 0, finishedBuffer.length);
8754
7249
  // Return the buffer
8755
7250
  return finishedBuffer;
8756
7251
  }
8757
- exports.serialize = serialize;
8758
7252
  /**
8759
7253
  * Serialize a Javascript object using a predefined Buffer and index into the buffer,
8760
7254
  * useful when pre-allocating the space for serialization.
@@ -8772,12 +7266,11 @@ function serializeWithBufferAndIndex(object, finalBuffer, options) {
8772
7266
  var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
8773
7267
  var startIndex = typeof options.index === 'number' ? options.index : 0;
8774
7268
  // Attempt to serialize
8775
- var serializationIndex = serializer.serializeInto(buffer$1, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined);
8776
- buffer$1.copy(finalBuffer, startIndex, 0, serializationIndex);
7269
+ var serializationIndex = serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined);
7270
+ buffer.copy(finalBuffer, startIndex, 0, serializationIndex);
8777
7271
  // Return the index
8778
7272
  return startIndex + serializationIndex - 1;
8779
7273
  }
8780
- exports.serializeWithBufferAndIndex = serializeWithBufferAndIndex;
8781
7274
  /**
8782
7275
  * Deserialize data as BSON.
8783
7276
  *
@@ -8787,9 +7280,8 @@ exports.serializeWithBufferAndIndex = serializeWithBufferAndIndex;
8787
7280
  */
8788
7281
  function deserialize(buffer, options) {
8789
7282
  if (options === void 0) { options = {}; }
8790
- return deserializer.deserialize(ensure_buffer.ensureBuffer(buffer), options);
7283
+ return deserialize$1(buffer instanceof buffer_1 ? buffer : ensureBuffer(buffer), options);
8791
7284
  }
8792
- exports.deserialize = deserialize;
8793
7285
  /**
8794
7286
  * Calculate the bson size for a passed in Javascript object.
8795
7287
  *
@@ -8802,9 +7294,8 @@ function calculateObjectSize(object, options) {
8802
7294
  options = options || {};
8803
7295
  var serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
8804
7296
  var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
8805
- return calculate_size.calculateObjectSize(object, serializeFunctions, ignoreUndefined);
7297
+ return calculateObjectSize$1(object, serializeFunctions, ignoreUndefined);
8806
7298
  }
8807
- exports.calculateObjectSize = calculateObjectSize;
8808
7299
  /**
8809
7300
  * Deserialize stream data as BSON documents.
8810
7301
  *
@@ -8819,7 +7310,7 @@ exports.calculateObjectSize = calculateObjectSize;
8819
7310
  */
8820
7311
  function deserializeStream(data, startIndex, numberOfDocuments, documents, docStartIndex, options) {
8821
7312
  var internalOptions = Object.assign({ allowObjectSmallerThanBufferSize: true, index: 0 }, options);
8822
- var bufferData = ensure_buffer.ensureBuffer(data);
7313
+ var bufferData = ensureBuffer(data);
8823
7314
  var index = startIndex;
8824
7315
  // Loop over all documents
8825
7316
  for (var i = 0; i < numberOfDocuments; i++) {
@@ -8831,14 +7322,13 @@ function deserializeStream(data, startIndex, numberOfDocuments, documents, docSt
8831
7322
  // Update options with index
8832
7323
  internalOptions.index = index;
8833
7324
  // Parse the document at this point
8834
- documents[docStartIndex + i] = deserializer.deserialize(bufferData, internalOptions);
7325
+ documents[docStartIndex + i] = deserialize$1(bufferData, internalOptions);
8835
7326
  // Adjust index by the document size
8836
7327
  index = index + size;
8837
7328
  }
8838
7329
  // Return object containing end index of parsing and list of documents
8839
7330
  return index;
8840
7331
  }
8841
- exports.deserializeStream = deserializeStream;
8842
7332
  /**
8843
7333
  * BSON default export
8844
7334
  * @deprecated Please use named exports
@@ -8848,23 +7338,23 @@ exports.deserializeStream = deserializeStream;
8848
7338
  * @public
8849
7339
  */
8850
7340
  var BSON = {
8851
- Binary: binary.Binary,
8852
- Code: code.Code,
8853
- DBRef: db_ref.DBRef,
8854
- Decimal128: decimal128.Decimal128,
8855
- Double: double_1.Double,
8856
- Int32: int_32.Int32,
8857
- Long: long_1.Long,
8858
- UUID: uuid.UUID,
8859
- Map: map.Map,
8860
- MaxKey: max_key.MaxKey,
8861
- MinKey: min_key.MinKey,
8862
- ObjectId: objectid.ObjectId,
8863
- ObjectID: objectid.ObjectId,
8864
- BSONRegExp: regexp.BSONRegExp,
8865
- BSONSymbol: symbol.BSONSymbol,
8866
- Timestamp: timestamp.Timestamp,
8867
- EJSON: extended_json.EJSON,
7341
+ Binary: Binary,
7342
+ Code: Code,
7343
+ DBRef: DBRef,
7344
+ Decimal128: Decimal128,
7345
+ Double: Double,
7346
+ Int32: Int32,
7347
+ Long: Long,
7348
+ UUID: UUID,
7349
+ Map: bsonMap,
7350
+ MaxKey: MaxKey,
7351
+ MinKey: MinKey,
7352
+ ObjectId: ObjectId,
7353
+ ObjectID: ObjectId,
7354
+ BSONRegExp: BSONRegExp,
7355
+ BSONSymbol: BSONSymbol,
7356
+ Timestamp: Timestamp,
7357
+ EJSON: EJSON,
8868
7358
  setInternalBufferSize: setInternalBufferSize,
8869
7359
  serialize: serialize,
8870
7360
  serializeWithBufferAndIndex: serializeWithBufferAndIndex,
@@ -8872,68 +7362,7 @@ var BSON = {
8872
7362
  calculateObjectSize: calculateObjectSize,
8873
7363
  deserializeStream: deserializeStream
8874
7364
  };
8875
- exports.default = BSON;
8876
- //# sourceMappingURL=bson.js.map
8877
- });
8878
7365
 
8879
- var bson$1 = unwrapExports(bson);
8880
- var bson_1 = bson.ObjectID;
8881
- var bson_2 = bson.Decimal128;
8882
- var bson_3 = bson.BSONRegExp;
8883
- var bson_4 = bson.MaxKey;
8884
- var bson_5 = bson.MinKey;
8885
- var bson_6 = bson.Int32;
8886
- var bson_7 = bson.Double;
8887
- var bson_8 = bson.Timestamp;
8888
- var bson_9 = bson.Long;
8889
- var bson_10 = bson.UUID;
8890
- var bson_11 = bson.ObjectId;
8891
- var bson_12 = bson.Binary;
8892
- var bson_13 = bson.DBRef;
8893
- var bson_14 = bson.BSONSymbol;
8894
- var bson_15 = bson.Map;
8895
- var bson_16 = bson.Code;
8896
- var bson_17 = bson.LongWithoutOverridesClass;
8897
- var bson_18 = bson.EJSON;
8898
- var bson_19 = bson.BSON_INT64_MIN;
8899
- var bson_20 = bson.BSON_INT64_MAX;
8900
- var bson_21 = bson.BSON_INT32_MIN;
8901
- var bson_22 = bson.BSON_INT32_MAX;
8902
- var bson_23 = bson.BSON_DATA_UNDEFINED;
8903
- var bson_24 = bson.BSON_DATA_TIMESTAMP;
8904
- var bson_25 = bson.BSON_DATA_SYMBOL;
8905
- var bson_26 = bson.BSON_DATA_STRING;
8906
- var bson_27 = bson.BSON_DATA_REGEXP;
8907
- var bson_28 = bson.BSON_DATA_OID;
8908
- var bson_29 = bson.BSON_DATA_OBJECT;
8909
- var bson_30 = bson.BSON_DATA_NUMBER;
8910
- var bson_31 = bson.BSON_DATA_NULL;
8911
- var bson_32 = bson.BSON_DATA_MIN_KEY;
8912
- var bson_33 = bson.BSON_DATA_MAX_KEY;
8913
- var bson_34 = bson.BSON_DATA_LONG;
8914
- var bson_35 = bson.BSON_DATA_INT;
8915
- var bson_36 = bson.BSON_DATA_DECIMAL128;
8916
- var bson_37 = bson.BSON_DATA_DBPOINTER;
8917
- var bson_38 = bson.BSON_DATA_DATE;
8918
- var bson_39 = bson.BSON_DATA_CODE_W_SCOPE;
8919
- var bson_40 = bson.BSON_DATA_CODE;
8920
- var bson_41 = bson.BSON_DATA_BOOLEAN;
8921
- var bson_42 = bson.BSON_DATA_BINARY;
8922
- var bson_43 = bson.BSON_DATA_ARRAY;
8923
- var bson_44 = bson.BSON_BINARY_SUBTYPE_UUID_NEW;
8924
- var bson_45 = bson.BSON_BINARY_SUBTYPE_UUID;
8925
- var bson_46 = bson.BSON_BINARY_SUBTYPE_USER_DEFINED;
8926
- var bson_47 = bson.BSON_BINARY_SUBTYPE_MD5;
8927
- var bson_48 = bson.BSON_BINARY_SUBTYPE_FUNCTION;
8928
- var bson_49 = bson.BSON_BINARY_SUBTYPE_DEFAULT;
8929
- var bson_50 = bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY;
8930
- var bson_51 = bson.deserializeStream;
8931
- var bson_52 = bson.calculateObjectSize;
8932
- var bson_53 = bson.deserialize;
8933
- var bson_54 = bson.serializeWithBufferAndIndex;
8934
- var bson_55 = bson.serialize;
8935
- var bson_56 = bson.setInternalBufferSize;
8936
-
8937
- export default bson$1;
8938
- export { bson_3 as BSONRegExp, bson_14 as BSONSymbol, bson_50 as BSON_BINARY_SUBTYPE_BYTE_ARRAY, bson_49 as BSON_BINARY_SUBTYPE_DEFAULT, bson_48 as BSON_BINARY_SUBTYPE_FUNCTION, bson_47 as BSON_BINARY_SUBTYPE_MD5, bson_46 as BSON_BINARY_SUBTYPE_USER_DEFINED, bson_45 as BSON_BINARY_SUBTYPE_UUID, bson_44 as BSON_BINARY_SUBTYPE_UUID_NEW, bson_43 as BSON_DATA_ARRAY, bson_42 as BSON_DATA_BINARY, bson_41 as BSON_DATA_BOOLEAN, bson_40 as BSON_DATA_CODE, bson_39 as BSON_DATA_CODE_W_SCOPE, bson_38 as BSON_DATA_DATE, bson_37 as BSON_DATA_DBPOINTER, bson_36 as BSON_DATA_DECIMAL128, bson_35 as BSON_DATA_INT, bson_34 as BSON_DATA_LONG, bson_33 as BSON_DATA_MAX_KEY, bson_32 as BSON_DATA_MIN_KEY, bson_31 as BSON_DATA_NULL, bson_30 as BSON_DATA_NUMBER, bson_29 as BSON_DATA_OBJECT, bson_28 as BSON_DATA_OID, bson_27 as BSON_DATA_REGEXP, bson_26 as BSON_DATA_STRING, bson_25 as BSON_DATA_SYMBOL, bson_24 as BSON_DATA_TIMESTAMP, bson_23 as BSON_DATA_UNDEFINED, bson_22 as BSON_INT32_MAX, bson_21 as BSON_INT32_MIN, bson_20 as BSON_INT64_MAX, bson_19 as BSON_INT64_MIN, bson_12 as Binary, bson_16 as Code, bson_13 as DBRef, bson_2 as Decimal128, bson_7 as Double, bson_18 as EJSON, bson_6 as Int32, bson_9 as Long, bson_17 as LongWithoutOverridesClass, bson_15 as Map, bson_4 as MaxKey, bson_5 as MinKey, bson_1 as ObjectID, bson_11 as ObjectId, bson_8 as Timestamp, bson_10 as UUID, bson_52 as calculateObjectSize, bson_53 as deserialize, bson_51 as deserializeStream, bson_55 as serialize, bson_54 as serializeWithBufferAndIndex, bson_56 as setInternalBufferSize };
7366
+ export default BSON;
7367
+ 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 };
8939
7368
  //# sourceMappingURL=bson.browser.esm.js.map