mongodb-stitch
Version:
[](https://gitter.im/mongodb/stitch?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
1 lines • 176 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("stitch",[],t):"object"==typeof exports?exports.stitch=t():e.stitch=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=15)}([function(e,t,n){"use strict";function r(e,t){var n=t.serviceName,r=void 0===n?e.serviceName:n,i=t.action,o=t.args,s=e.client;if(!s)throw new Error("Service has no client");return s.executeServiceFunction(r,i,o)}function i(e){return encodeURIComponent(s.btoa(JSON.stringify(e)))}Object.defineProperty(t,"__esModule",{value:!0}),t.uriEncodeObject=t.serviceResponse=void 0;var o=n(12),s=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}(o);t.serviceResponse=r,t.uriEncodeObject=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.USER_AUTH_KEY="_baas_ua",t.REFRESH_TOKEN_KEY="_baas_rt",t.DEVICE_ID_KEY="_baas_did",t.STATE_KEY="_baas_state",t.USER_AUTH_COOKIE_NAME="baas_ua",t.STITCH_ERROR_KEY="_baas_error",t.STITCH_LINK_KEY="_baas_link",t.USER_LOGGED_IN_PT_KEY="_baas_pt",t.STITCH_REDIRECT_PROVIDER="_baas_rp",t.DEFAULT_ACCESS_TOKEN_EXPIRE_WITHIN_SECS=10,t.APP_CLIENT_CODEC={accessToken:"access_token",refreshToken:"refresh_token",deviceId:"device_id",userId:"user_id"},t.ADMIN_CLIENT_CODEC={accessToken:"access_token",refreshToken:"refresh_token",deviceId:"device_id",userId:"user_id"}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.makeFetchArgs=t.checkStatus=t.SDK_VERSION=t.DEFAULT_STITCH_SERVER_URL=t.ADMIN_CLIENT_TYPE=t.APP_CLIENT_TYPE=t.JSONTYPE=void 0;var r=n(3),i=t.JSONTYPE="application/json",o=(t.APP_CLIENT_TYPE="app",t.ADMIN_CLIENT_TYPE="admin",t.DEFAULT_STITCH_SERVER_URL="https://realm.mongodb.com","unknown");o="3.18.0";t.SDK_VERSION=o,t.checkStatus=function(e){if(e.status>=200&&e.status<300)return e;if(e.headers.get("Content-Type")===i)return e.json().then(function(t){var n=new r.StitchError(t.error,t.error_code);return n.response=e,n.json=t,Promise.reject(n)});var t=new Error(e.statusText);return t.response=e,Promise.reject(t)},t.makeFetchArgs=function(e,t,n){var r={method:e,headers:{Accept:i,"Content-Type":i}};return n&&n.credentials&&(r.credentials=n.credentials),t&&(r.body=t),r.cors=!0,r}},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var s=function(e,t){Error.call(this,e),Error.captureStackTrace&&Error.captureStackTrace(this),this.message=e,this.name=this.constructor.name,void 0!==t&&(this.code=t)};s.prototype=Object.create(Error.prototype);var u=function(e){function t(){return r(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return o(t,e),t}(s);t.StitchError=u,t.ErrAuthProviderNotFound="AuthProviderNotFound",t.ErrInvalidSession="InvalidSession",t.ErrUnauthorized="Unauthorized"},function(module,exports,__webpack_require__){"use strict";(function(global,Buffer){function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function createCommonjsModule(e,t){return t={exports:{}},e(t,t.exports),t.exports}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"===_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)})(e)}function _classCallCheck$1(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$1(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass$1(e,t,n){return t&&_defineProperties$1(e.prototype,t),n&&_defineProperties$1(e,n),e}function _possibleConstructorReturn(e,t){return!t||"object"!==_typeof(t)&&"function"!=typeof t?_assertThisInitialized(e):t}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function normalizedFunctionString(e){return e.toString().replace("function(","function (")}function insecureRandomBytes(e){for(var t=new Uint8Array(e),n=0;n<e;++n)t[n]=Math.floor(256*Math.random());return t}function defaultSetTimout(){throw new Error("setTimeout has not been defined")}function defaultClearTimeout(){throw new Error("clearTimeout has not been defined")}function runTimeout(e){if(cachedSetTimeout===setTimeout)return setTimeout(e,0);if((cachedSetTimeout===defaultSetTimout||!cachedSetTimeout)&&setTimeout)return cachedSetTimeout=setTimeout,setTimeout(e,0);try{return cachedSetTimeout(e,0)}catch(t){try{return cachedSetTimeout.call(null,e,0)}catch(t){return cachedSetTimeout.call(this,e,0)}}}function runClearTimeout(e){if(cachedClearTimeout===clearTimeout)return clearTimeout(e);if((cachedClearTimeout===defaultClearTimeout||!cachedClearTimeout)&&clearTimeout)return cachedClearTimeout=clearTimeout,clearTimeout(e);try{return cachedClearTimeout(e)}catch(t){try{return cachedClearTimeout.call(null,e)}catch(t){return cachedClearTimeout.call(this,e)}}}function cleanUpNextTick(){draining&¤tQueue&&(draining=!1,currentQueue.length?queue=currentQueue.concat(queue):queueIndex=-1,queue.length&&drainQueue())}function drainQueue(){if(!draining){var e=runTimeout(cleanUpNextTick);draining=!0;for(var t=queue.length;t;){for(currentQueue=queue,queue=[];++queueIndex<t;)currentQueue&¤tQueue[queueIndex].run();queueIndex=-1,t=queue.length}currentQueue=null,draining=!1,runClearTimeout(e)}}function nextTick(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];queue.push(new Item(e,t)),1!==queue.length||draining||runTimeout(drainQueue)}function Item(e,t){this.fun=e,this.array=t}function noop(){}function binding(e){throw new Error("process.binding is not supported")}function cwd(){return"/"}function chdir(e){throw new Error("process.chdir is not supported")}function umask(){return 0}function hrtime(e){var t=.001*performanceNow.call(performance),n=Math.floor(t),r=Math.floor(t%1*1e9);return e&&(n-=e[0],(r-=e[1])<0&&(n--,r+=1e9)),[n,r]}function uptime(){return(new Date-startTime)/1e3}function _typeof$1(e){return(_typeof$1="function"==typeof Symbol&&"symbol"===_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)})(e)}function format(e){if(!isString(e)){for(var t=[],n=0;n<arguments.length;n++)t.push(inspect(arguments[n]));return t.join(" ")}for(var n=1,r=arguments,i=r.length,o=String(e).replace(formatRegExp,function(e){if("%%"===e)return"%";if(n>=i)return e;switch(e){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(e){return"[Circular]"}default:return e}}),s=r[n];n<i;s=r[++n])isNull(s)||!isObject(s)?o+=" "+s:o+=" "+inspect(s);return o}function deprecate(e,t){function n(){return r||(console.error(t),r=!0),e.apply(this,arguments)}if(isUndefined(global.process))return function(){return deprecate(e,t).apply(this,arguments)};var r=!1;return n}function debuglog(e){if(isUndefined(debugEnviron)&&(debugEnviron=process.env.NODE_DEBUG||""),e=e.toUpperCase(),!debugs[e])if(new RegExp("\\b"+e+"\\b","i").test(debugEnviron)){debugs[e]=function(){var t=format.apply(null,arguments);console.error("%s %d: %s",e,0,t)}}else debugs[e]=function(){};return debugs[e]}function inspect(e,t){var n={seen:[],stylize:stylizeNoColor};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),isBoolean(t)?n.showHidden=t:t&&_extend(n,t),isUndefined(n.showHidden)&&(n.showHidden=!1),isUndefined(n.depth)&&(n.depth=2),isUndefined(n.colors)&&(n.colors=!1),isUndefined(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=stylizeWithColor),formatValue(n,e,n.depth)}function stylizeWithColor(e,t){var n=inspect.styles[t];return n?"["+inspect.colors[n][0]+"m"+e+"["+inspect.colors[n][1]+"m":e}function stylizeNoColor(e,t){return e}function arrayToHash(e){var t={};return e.forEach(function(e,n){t[e]=!0}),t}function formatValue(e,t,n){if(e.customInspect&&t&&isFunction(t.inspect)&&t.inspect!==inspect&&(!t.constructor||t.constructor.prototype!==t)){var r=t.inspect(n,e);return isString(r)||(r=formatValue(e,r,n)),r}var i=formatPrimitive(e,t);if(i)return i;var o=Object.keys(t),s=arrayToHash(o);if(e.showHidden&&(o=Object.getOwnPropertyNames(t)),isError(t)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return formatError(t);if(0===o.length){if(isFunction(t)){var u=t.name?": "+t.name:"";return e.stylize("[Function"+u+"]","special")}if(isRegExp(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(isDate(t))return e.stylize(Date.prototype.toString.call(t),"date");if(isError(t))return formatError(t)}var a="",f=!1,c=["{","}"];if(isArray(t)&&(f=!0,c=["[","]"]),isFunction(t)){a=" [Function"+(t.name?": "+t.name:"")+"]"}if(isRegExp(t)&&(a=" "+RegExp.prototype.toString.call(t)),isDate(t)&&(a=" "+Date.prototype.toUTCString.call(t)),isError(t)&&(a=" "+formatError(t)),0===o.length&&(!f||0==t.length))return c[0]+a+c[1];if(n<0)return isRegExp(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);var l;return l=f?formatArray(e,t,n,s,o):o.map(function(r){return formatProperty(e,t,n,s,r,f)}),e.seen.pop(),reduceToSingleString(l,a,c)}function formatPrimitive(e,t){if(isUndefined(t))return e.stylize("undefined","undefined");if(isString(t)){var n="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(n,"string")}return isNumber(t)?e.stylize(""+t,"number"):isBoolean(t)?e.stylize(""+t,"boolean"):isNull(t)?e.stylize("null","null"):void 0}function formatError(e){return"["+Error.prototype.toString.call(e)+"]"}function formatArray(e,t,n,r,i){for(var o=[],s=0,u=t.length;s<u;++s)hasOwnProperty(t,String(s))?o.push(formatProperty(e,t,n,r,String(s),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(formatProperty(e,t,n,r,i,!0))}),o}function formatProperty(e,t,n,r,i,o){var s,u,a;if(a=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]},a.get?u=a.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):a.set&&(u=e.stylize("[Setter]","special")),hasOwnProperty(r,i)||(s="["+i+"]"),u||(e.seen.indexOf(a.value)<0?(u=isNull(n)?formatValue(e,a.value,null):formatValue(e,a.value,n-1),u.indexOf("\n")>-1&&(u=o?u.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+u.split("\n").map(function(e){return" "+e}).join("\n"))):u=e.stylize("[Circular]","special")),isUndefined(s)){if(o&&i.match(/^\d+$/))return u;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+u}function reduceToSingleString(e,t,n){return e.reduce(function(e,t){return t.indexOf("\n"),e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60?n[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+n[1]:n[0]+t+" "+e.join(", ")+" "+n[1]}function isArray(e){return Array.isArray(e)}function isBoolean(e){return"boolean"==typeof e}function isNull(e){return null===e}function isNullOrUndefined(e){return null==e}function isNumber(e){return"number"==typeof e}function isString(e){return"string"==typeof e}function isSymbol(e){return"symbol"===_typeof$1(e)}function isUndefined(e){return void 0===e}function isRegExp(e){return isObject(e)&&"[object RegExp]"===objectToString(e)}function isObject(e){return"object"===_typeof$1(e)&&null!==e}function isDate(e){return isObject(e)&&"[object Date]"===objectToString(e)}function isError(e){return isObject(e)&&("[object Error]"===objectToString(e)||e instanceof Error)}function isFunction(e){return"function"==typeof e}function isPrimitive(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"===_typeof$1(e)||void 0===e}function isBuffer(e){return Buffer.isBuffer(e)}function objectToString(e){return Object.prototype.toString.call(e)}function pad(e){return e<10?"0"+e.toString(10):e.toString(10)}function timestamp$1(){var e=new Date,t=[pad(e.getHours()),pad(e.getMinutes()),pad(e.getSeconds())].join(":");return[e.getDate(),months[e.getMonth()],t].join(" ")}function log(){console.log("%s - %s",timestamp$1(),format.apply(null,arguments))}function _extend(e,t){if(!t||!isObject(t))return e;for(var n=Object.keys(t),r=n.length;r--;)e[n[r]]=t[n[r]];return e}function hasOwnProperty(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function _classCallCheck$2(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$2(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass$2(e,t,n){return t&&_defineProperties$2(e.prototype,t),n&&_defineProperties$2(e,n),e}function convertToHex(e){return e.toString("hex")}function makeObjectIdError(e,t){var n=e[t];return new TypeError('ObjectId string "'.concat(e,'" contains invalid character "').concat(n,'" with character code (').concat(e.charCodeAt(t),"). All character codes for a non-hex string must be less than 256."))}function _classCallCheck$3(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$3(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass$3(e,t,n){return t&&_defineProperties$3(e.prototype,t),n&&_defineProperties$3(e,n),e}function alphabetize(e){return e.split("").sort().join("")}function _classCallCheck$4(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$4(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass$4(e,t,n){return t&&_defineProperties$4(e.prototype,t),n&&_defineProperties$4(e,n),e}function _classCallCheck$5(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$5(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass$5(e,t,n){return t&&_defineProperties$5(e.prototype,t),n&&_defineProperties$5(e,n),e}function _classCallCheck$6(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$6(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass$6(e,t,n){return t&&_defineProperties$6(e.prototype,t),n&&_defineProperties$6(e,n),e}function isDigit(e){return!isNaN(parseInt(e,10))}function divideu128(e){var t=long_1.fromNumber(1e9),n=long_1.fromNumber(0);if(!(e.parts[0]||e.parts[1]||e.parts[2]||e.parts[3]))return{quotient:e,rem:n};for(var r=0;r<=3;r++)n=n.shiftLeft(32),n=n.add(new long_1(e.parts[r],0)),e.parts[r]=n.div(t).low,n=n.modulo(t);return{quotient:e,rem:n}}function multiply64x2(e,t){if(!e&&!t)return{high:long_1.fromNumber(0),low:long_1.fromNumber(0)};var n=e.shiftRightUnsigned(32),r=new long_1(e.getLowBits(),0),i=t.shiftRightUnsigned(32),o=new long_1(t.getLowBits(),0),s=n.multiply(i),u=n.multiply(o),a=r.multiply(i),f=r.multiply(o);return s=s.add(u.shiftRightUnsigned(32)),u=new long_1(u.getLowBits(),0).add(a).add(f.shiftRightUnsigned(32)),s=s.add(u.shiftRightUnsigned(32)),f=u.shiftLeft(32).add(new long_1(f.getLowBits(),0)),{high:s,low:f}}function lessThan(e,t){var n=e.high>>>0,r=t.high>>>0;if(n<r)return!0;if(n===r){if(e.low>>>0<t.low>>>0)return!0}return!1}function invalidErr(e,t){throw new TypeError('"'.concat(e,'" is not a valid Decimal128 string - ').concat(t))}function Decimal128(e){this.bytes=e}function _classCallCheck$7(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$7(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass$7(e,t,n){return t&&_defineProperties$7(e.prototype,t),n&&_defineProperties$7(e,n),e}function _classCallCheck$8(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$8(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass$8(e,t,n){return t&&_defineProperties$8(e.prototype,t),n&&_defineProperties$8(e,n),e}function _classCallCheck$9(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$9(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass$9(e,t,n){return t&&_defineProperties$9(e.prototype,t),n&&_defineProperties$9(e,n),e}function _classCallCheck$a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass$a(e,t,n){return t&&_defineProperties$a(e.prototype,t),n&&_defineProperties$a(e,n),e}function isUint8Array(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)}function writeStringToArray(e){for(var t="undefined"!=typeof Uint8Array?new Uint8Array(new ArrayBuffer(e.length)):new Array(e.length),n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return t}function convertArraytoUtf8BinaryString(e,t,n){for(var r="",i=t;i<n;i++)r+=String.fromCharCode(e[i]);return r}function _typeof$2(e){return(_typeof$2="function"==typeof Symbol&&"symbol"===_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)})(e)}function deserializeValue(e,t,n,r){if("number"==typeof n){if(r.relaxed||r.legacy)return n;if(Math.floor(n)===n){if(n>=BSON_INT32_MIN&&n<=BSON_INT32_MAX)return new int_32(n);if(n>=BSON_INT64_MIN&&n<=BSON_INT64_MAX)return new long_1.fromNumber(n)}return new double_1(n)}if(null==n||"object"!==_typeof$2(n))return n;if(n.$undefined)return null;for(var i=Object.keys(n).filter(function(e){return e.startsWith("$")&&null!=n[e]}),o=0;o<i.length;o++){var s=keysToCodecs[i[o]];if(s)return s.fromExtendedJSON(n,r)}if(null!=n.$date){var u=n.$date,a=new Date;return r.legacy?"number"==typeof u?a.setTime(u):"string"==typeof u&&a.setTime(Date.parse(u)):"string"==typeof u?a.setTime(Date.parse(u)):long_1.isLong(u)?a.setTime(u.toNumber()):"number"==typeof u&&r.relaxed&&a.setTime(u),a}if(null!=n.$code){var f=Object.assign({},n);return n.$scope&&(f.$scope=deserializeValue(e,null,n.$scope)),code.fromExtendedJSON(n)}if(null!=n.$ref||null!=n.$dbPointer){var c=n.$ref?n:n.$dbPointer;if(c instanceof db_ref)return c;var l=Object.keys(c).filter(function(e){return e.startsWith("$")}),h=!0;if(l.forEach(function(e){-1===["$ref","$id","$db"].indexOf(e)&&(h=!1)}),h)return db_ref.fromExtendedJSON(c)}return n}function parse(e,t){var n=this;return t=Object.assign({},{relaxed:!0,legacy:!1},t),"boolean"==typeof t.relaxed&&(t.strict=!t.relaxed),"boolean"==typeof t.strict&&(t.relaxed=!t.strict),JSON.parse(e,function(e,r){return deserializeValue(n,e,r,t)})}function stringify(e,t,n,r){null!=n&&"object"===_typeof$2(n)&&(r=n,n=0),null==t||"object"!==_typeof$2(t)||Array.isArray(t)||(r=t,t=null,n=0),r=Object.assign({},{relaxed:!0,legacy:!1},r);var i=Array.isArray(e)?serializeArray(e,r):serializeDocument(e,r);return JSON.stringify(i,t,n)}function serialize(e,t){return t=t||{},JSON.parse(stringify(e,t))}function deserialize(e,t){return t=t||{},parse(JSON.stringify(e),t)}function serializeArray(e,t){return e.map(function(e){return serializeValue(e,t)})}function getISOString(e){var t=e.toISOString();return 0!==e.getUTCMilliseconds()?t:t.slice(0,-5)+"Z"}function serializeValue(e,t){if(Array.isArray(e))return serializeArray(e,t);if(void 0===e)return null;if(e instanceof Date){var n=e.getTime(),r=n>-1&&n<2534023188e5;return t.legacy?t.relaxed&&r?{$date:e.getTime()}:{$date:getISOString(e)}:t.relaxed&&r?{$date:getISOString(e)}:{$date:{$numberLong:e.getTime().toString()}}}if("number"==typeof e&&!t.relaxed){if(Math.floor(e)===e){var i=e>=BSON_INT32_MIN&&e<=BSON_INT32_MAX,o=e>=BSON_INT64_MIN&&e<=BSON_INT64_MAX;if(i)return{$numberInt:e.toString()};if(o)return{$numberLong:e.toString()}}return{$numberDouble:e.toString()}}if(e instanceof RegExp){var s=e.flags;void 0===s&&(s=e.toString().match(/[gimuy]*$/)[0]);return new regexp(e.source,s).toExtendedJSON(t)}return null!=e&&"object"===_typeof$2(e)?serializeDocument(e,t):e}function serializeDocument(e,t){if(null==e||"object"!==_typeof$2(e))throw new Error("not an object instance");var n=e._bsontype;if(void 0===n){var r={};for(var i in e)r[i]=serializeValue(e[i],t);return r}if("string"==typeof n){var o=e;if("function"!=typeof o.toExtendedJSON){var s=BSON_TYPE_MAPPINGS[n];if(!s)throw new TypeError("Unrecognized or invalid _bsontype: "+n);o=s(o)}return"Code"===n&&o.scope?o=new code(o.code,serializeValue(o.scope,t)):"DBRef"===n&&o.oid&&(o=new db_ref(o.collection,serializeValue(o.oid,t),o.db,o.fields)),o.toExtendedJSON(t)}throw new Error("_bsontype must be a string, but was: "+_typeof$2(n))}function validateUtf8(e,t,n){for(var r=0,i=t;i<n;i+=1){var o=e[i];if(r){if((o&FIRST_TWO_BITS)!==CONTINUING_CHAR)return!1;r-=1}else if(o&FIRST_BIT)if((o&FIRST_THREE_BITS)===TWO_BIT_CHAR)r=1;else if((o&FIRST_FOUR_BITS)===THREE_BIT_CHAR)r=2;else{if((o&FIRST_FIVE_BITS)!==FOUR_BIT_CHAR)return!1;r=3}}return!r}function deserialize$1(e,t,n){t=null==t?{}:t;var r=t&&t.index?t.index:0,i=e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24;if(i<5)throw new Error("bson size must be >= 5, is ".concat(i));if(t.allowObjectSmallerThanBufferSize&&e.length<i)throw new Error("buffer length ".concat(e.length," must be >= bson size ").concat(i));if(!t.allowObjectSmallerThanBufferSize&&e.length!==i)throw new Error("buffer length ".concat(e.length," must === bson size ").concat(i));if(i+r>e.length)throw new Error("(bson size ".concat(i," + options.index ").concat(r," must be <= buffer length ").concat(Buffer$4.byteLength(e),")"));if(0!==e[r+i-1])throw new Error("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");return deserializeObject(e,r,t,n)}function deserializeObject(e,t,n,r){var i=null!=n.evalFunctions&&n.evalFunctions,o=null!=n.cacheFunctions&&n.cacheFunctions,s=null!=n.cacheFunctionsCrc32&&n.cacheFunctionsCrc32;if(!s)var u=null;var a=null==n.fieldsAsRaw?null:n.fieldsAsRaw,f=null!=n.raw&&n.raw,c="boolean"==typeof n.bsonRegExp&&n.bsonRegExp,l=null!=n.promoteBuffers&&n.promoteBuffers,h=null==n.promoteLongs||n.promoteLongs,p=null==n.promoteValues||n.promoteValues,_=t;if(e.length<5)throw new Error("corrupt bson message < 5 bytes long");var d=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(d<5||d>e.length)throw new Error("corrupt bson message");for(var g=r?[]:{},y=0;;){var b=e[t++];if(0===b)break;for(var v=t;0!==e[v]&&v<e.length;)v++;if(v>=Buffer$4.byteLength(e))throw new Error("Bad BSON Document: illegal CString");var m=r?y++:e.toString("utf8",t,v);if(t=v+1,b===constants.BSON_DATA_STRING){var S=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(S<=0||S>e.length-t||0!==e[t+S-1])throw new Error("bad string length in bson");if(!validateUtf8$1(e,t,t+S-1))throw new Error("Invalid UTF-8 string in BSON document");var E=e.toString("utf8",t,t+S-1);g[m]=E,t+=S}else if(b===constants.BSON_DATA_OID){var O=Buffer$4.alloc(12);e.copy(O,0,t,t+12),g[m]=new objectid(O),t+=12}else if(b===constants.BSON_DATA_INT&&!1===p)g[m]=new int_32(e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24);else if(b===constants.BSON_DATA_INT)g[m]=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;else if(b===constants.BSON_DATA_NUMBER&&!1===p)g[m]=new double_1(e.readDoubleLE(t)),t+=8;else if(b===constants.BSON_DATA_NUMBER)g[m]=e.readDoubleLE(t),t+=8;else if(b===constants.BSON_DATA_DATE){var A=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,N=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;g[m]=new Date(new long_1(A,N).toNumber())}else if(b===constants.BSON_DATA_BOOLEAN){if(0!==e[t]&&1!==e[t])throw new Error("illegal boolean type value");g[m]=1===e[t++]}else if(b===constants.BSON_DATA_OBJECT){var T=t,w=e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24;if(w<=0||w>e.length-t)throw new Error("bad embedded document length in bson");g[m]=f?e.slice(t,t+w):deserializeObject(e,T,n,!1),t+=w}else if(b===constants.BSON_DATA_ARRAY){var B=t,I=e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24,P=n,R=t+I;if(a&&a[m]){P={};for(var D in n)P[D]=n[D];P.raw=!0}if(g[m]=deserializeObject(e,B,P,!0),t+=I,0!==e[t-1])throw new Error("invalid array terminator byte");if(t!==R)throw new Error("corrupted array bson")}else if(b===constants.BSON_DATA_UNDEFINED)g[m]=void 0;else if(b===constants.BSON_DATA_NULL)g[m]=null;else if(b===constants.BSON_DATA_LONG){var x=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,k=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,U=new long_1(x,k);g[m]=h&&!0===p&&U.lessThanOrEqual(JS_INT_MAX_LONG)&&U.greaterThanOrEqual(JS_INT_MIN_LONG)?U.toNumber():U}else if(b===constants.BSON_DATA_DECIMAL128){var C=Buffer$4.alloc(16);e.copy(C,0,t,t+16),t+=16;var $=new decimal128(C);g[m]=$.toObject?$.toObject():$}else if(b===constants.BSON_DATA_BINARY){var j=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,M=j,L=e[t++];if(j<0)throw new Error("Negative binary type element size found");if(j>Buffer$4.byteLength(e))throw new Error("Binary type size larger than document size");if(null!=e.slice){if(L===binary.SUBTYPE_BYTE_ARRAY){if((j=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24)<0)throw new Error("Negative binary type element size found for subtype 0x02");if(j>M-4)throw new Error("Binary type with subtype 0x02 contains to long binary size");if(j<M-4)throw new Error("Binary type with subtype 0x02 contains to short binary size")}g[m]=l&&p?e.slice(t,t+j):new binary(e.slice(t,t+j),L)}else{var Y="undefined"!=typeof Uint8Array?new Uint8Array(new ArrayBuffer(j)):new Array(j);if(L===binary.SUBTYPE_BYTE_ARRAY){if((j=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24)<0)throw new Error("Negative binary type element size found for subtype 0x02");if(j>M-4)throw new Error("Binary type with subtype 0x02 contains to long binary size");if(j<M-4)throw new Error("Binary type with subtype 0x02 contains to short binary size")}for(v=0;v<j;v++)Y[v]=e[t+v];g[m]=l&&p?Y:new binary(Y,L)}t+=j}else if(b===constants.BSON_DATA_REGEXP&&!1===c){for(v=t;0!==e[v]&&v<e.length;)v++;if(v>=e.length)throw new Error("Bad BSON Document: illegal CString");var z=e.toString("utf8",t,v);for(t=v+1,v=t;0!==e[v]&&v<e.length;)v++;if(v>=e.length)throw new Error("Bad BSON Document: illegal CString");var F=e.toString("utf8",t,v);t=v+1;var J=new Array(F.length);for(v=0;v<F.length;v++)switch(F[v]){case"m":J[v]="m";break;case"s":J[v]="g";break;case"i":J[v]="i"}g[m]=new RegExp(z,J.join(""))}else if(b===constants.BSON_DATA_REGEXP&&!0===c){for(v=t;0!==e[v]&&v<e.length;)v++;if(v>=e.length)throw new Error("Bad BSON Document: illegal CString");var K=e.toString("utf8",t,v);for(t=v+1,v=t;0!==e[v]&&v<e.length;)v++;if(v>=e.length)throw new Error("Bad BSON Document: illegal CString");var V=e.toString("utf8",t,v);t=v+1,g[m]=new regexp(K,V)}else if(b===constants.BSON_DATA_SYMBOL){var X=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(X<=0||X>e.length-t||0!==e[t+X-1])throw new Error("bad string length in bson");var q=e.toString("utf8",t,t+X-1);g[m]=p?q:new symbol(q),t+=X}else if(b===constants.BSON_DATA_TIMESTAMP){var H=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,G=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;g[m]=new timestamp(H,G)}else if(b===constants.BSON_DATA_MIN_KEY)g[m]=new min_key;else if(b===constants.BSON_DATA_MAX_KEY)g[m]=new max_key;else if(b===constants.BSON_DATA_CODE){var W=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(W<=0||W>e.length-t||0!==e[t+W-1])throw new Error("bad string length in bson");var Z=e.toString("utf8",t,t+W-1);if(i)if(o){var Q=s?u(Z):Z;g[m]=isolateEvalWithHash(functionCache,Q,Z,g)}else g[m]=isolateEval(Z);else g[m]=new code(Z);t+=W}else if(b===constants.BSON_DATA_CODE_W_SCOPE){var ee=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(ee<13)throw new Error("code_w_scope total size shorter minimum expected length");var te=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(te<=0||te>e.length-t||0!==e[t+te-1])throw new Error("bad string length in bson");var ne=e.toString("utf8",t,t+te-1);t+=te;var re=t,ie=e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24,oe=deserializeObject(e,re,n,!1);if(t+=ie,ee<8+ie+te)throw new Error("code_w_scope total size is to short, truncating scope");if(ee>8+ie+te)throw new Error("code_w_scope total size is to long, clips outer document");if(i){if(o){var se=s?u(ne):ne;g[m]=isolateEvalWithHash(functionCache,se,ne,g)}else g[m]=isolateEval(ne);g[m].scope=oe}else g[m]=new code(ne,oe)}else{if(b!==constants.BSON_DATA_DBPOINTER)throw new Error("Detected unknown BSON type "+b.toString(16)+' for fieldname "'+m+'", are you using the latest BSON parser?');var ue=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(ue<=0||ue>e.length-t||0!==e[t+ue-1])throw new Error("bad string length in bson");if(!validateUtf8$1(e,t,t+ue-1))throw new Error("Invalid UTF-8 string in BSON document");var ae=e.toString("utf8",t,t+ue-1);t+=ue;var fe=Buffer$4.alloc(12);e.copy(fe,0,t,t+12);var ce=new objectid(fe);t+=12,g[m]=new db_ref(ae,ce)}}if(d!==t-_){if(r)throw new Error("corrupt array bson");throw new Error("corrupt object bson")}var le=Object.keys(g).filter(function(e){return e.startsWith("$")}),he=!0;if(le.forEach(function(e){-1===["$ref","$id","$db"].indexOf(e)&&(he=!1)}),!he)return g;if(null!=g.$id&&null!=g.$ref){var pe=Object.assign({},g);return delete pe.$ref,delete pe.$id,delete pe.$db,new db_ref(g.$ref,g.$id,g.$db||null,pe)}return g}function isolateEvalWithHash(functionCache,hash,functionString,object){var value=null;return null==functionCache[hash]&&(eval("value = "+functionString),functionCache[hash]=value),functionCache[hash].bind(object)}function isolateEval(functionString){var value=null;return eval("value = "+functionString),value}function readIEEE754(e,t,n,r,i){var o,s,u="big"===n,a=8*i-r-1,f=(1<<a)-1,c=f>>1,l=-7,h=u?0:i-1,p=u?1:-1,_=e[t+h];for(h+=p,o=_&(1<<-l)-1,_>>=-l,l+=a;l>0;o=256*o+e[t+h],h+=p,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=r;l>0;s=256*s+e[t+h],h+=p,l-=8);if(0===o)o=1-c;else{if(o===f)return s?NaN:1/0*(_?-1:1);s+=Math.pow(2,r),o-=c}return(_?-1:1)*s*Math.pow(2,o-r)}function writeIEEE754(e,t,n,r,i,o){var s,u,a,f="big"===r,c=8*o-i-1,l=(1<<c)-1,h=l>>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,_=f?o-1:0,d=f?-1:1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(u=isNaN(t)?1:0,s=l):(s=Math.floor(Math.log(t)/Math.LN2),t*(a=Math.pow(2,-s))<1&&(s--,a*=2),t+=s+h>=1?p/a:p*Math.pow(2,1-h),t*a>=2&&(s++,a/=2),s+h>=l?(u=0,s=l):s+h>=1?(u=(t*a-1)*Math.pow(2,i),s+=h):(u=t*Math.pow(2,h-1)*Math.pow(2,i),s=0)),isNaN(t)&&(u=0);i>=8;)e[n+_]=255&u,_+=d,u/=256,i-=8;for(s=s<<i|u,isNaN(t)&&(s+=8),c+=i;c>0;)e[n+_]=255&s,_+=d,s/=256,c-=8;e[n+_-d]|=128*g}function _typeof$3(e){return(_typeof$3="function"==typeof Symbol&&"symbol"===_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)})(e)}function serializeString(e,t,n,r,i){e[r++]=constants.BSON_DATA_STRING,r=r+(i?e.write(t,r,"ascii"):e.write(t,r,"utf8"))+1,e[r-1]=0;var o=e.write(n,r+4,"utf8");return e[r+3]=o+1>>24&255,e[r+2]=o+1>>16&255,e[r+1]=o+1>>8&255,e[r]=o+1&255,r=r+4+o,e[r++]=0,r}function serializeNumber(e,t,n,r,i){if(Math.floor(n)===n&&n>=constants.JS_INT_MIN&&n<=constants.JS_INT_MAX)if(n>=constants.BSON_INT32_MIN&&n<=constants.BSON_INT32_MAX){e[r++]=constants.BSON_DATA_INT;var o=i?e.write(t,r,"ascii"):e.write(t,r,"utf8");r+=o,e[r++]=0,e[r++]=255&n,e[r++]=n>>8&255,e[r++]=n>>16&255,e[r++]=n>>24&255}else if(n>=constants.JS_INT_MIN&&n<=constants.JS_INT_MAX){e[r++]=constants.BSON_DATA_NUMBER;var s=i?e.write(t,r,"ascii"):e.write(t,r,"utf8");r+=s,e[r++]=0,writeIEEE754$1(e,n,r,"little",52,8),r+=8}else{e[r++]=constants.BSON_DATA_LONG;var u=i?e.write(t,r,"ascii"):e.write(t,r,"utf8");r+=u,e[r++]=0;var a=long_1.fromNumber(n),f=a.getLowBits(),c=a.getHighBits();e[r++]=255&f,e[r++]=f>>8&255,e[r++]=f>>16&255,e[r++]=f>>24&255,e[r++]=255&c,e[r++]=c>>8&255,e[r++]=c>>16&255,e[r++]=c>>24&255}else{e[r++]=constants.BSON_DATA_NUMBER;r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0,writeIEEE754$1(e,n,r,"little",52,8),r+=8}return r}function serializeNull(e,t,n,r,i){return e[r++]=constants.BSON_DATA_NULL,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0,r}function serializeBoolean(e,t,n,r,i){return e[r++]=constants.BSON_DATA_BOOLEAN,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0,e[r++]=n?1:0,r}function serializeDate(e,t,n,r,i){e[r++]=constants.BSON_DATA_DATE,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var o=long_1.fromNumber(n.getTime()),s=o.getLowBits(),u=o.getHighBits();return e[r++]=255&s,e[r++]=s>>8&255,e[r++]=s>>16&255,e[r++]=s>>24&255,e[r++]=255&u,e[r++]=u>>8&255,e[r++]=u>>16&255,e[r++]=u>>24&255,r}function serializeRegExp(e,t,n,r,i){if(e[r++]=constants.BSON_DATA_REGEXP,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0,n.source&&null!=n.source.match(regexp$1))throw Error("value "+n.source+" must not contain null bytes");return r+=e.write(n.source,r,"utf8"),e[r++]=0,n.ignoreCase&&(e[r++]=105),n.global&&(e[r++]=115),n.multiline&&(e[r++]=109),e[r++]=0,r}function serializeBSONRegExp(e,t,n,r,i){if(e[r++]=constants.BSON_DATA_REGEXP,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0,null!=n.pattern.match(regexp$1))throw Error("pattern "+n.pattern+" must not contain null bytes");return r+=e.write(n.pattern,r,"utf8"),e[r++]=0,r+=e.write(n.options.split("").sort().join(""),r,"utf8"),e[r++]=0,r}function serializeMinMax(e,t,n,r,i){return null===n?e[r++]=constants.BSON_DATA_NULL:"MinKey"===n._bsontype?e[r++]=constants.BSON_DATA_MIN_KEY:e[r++]=constants.BSON_DATA_MAX_KEY,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0,r}function serializeObjectId(e,t,n,r,i){if(e[r++]=constants.BSON_DATA_OID,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0,"string"==typeof n.id)e.write(n.id,r,"binary");else{if(!n.id||!n.id.copy)throw new TypeError("object ["+JSON.stringify(n)+"] is not a valid ObjectId");n.id.copy(e,r,0,12)}return r+12}function serializeBuffer(e,t,n,r,i){e[r++]=constants.BSON_DATA_BINARY,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var o=n.length;return e[r++]=255&o,e[r++]=o>>8&255,e[r++]=o>>16&255,e[r++]=o>>24&255,e[r++]=constants.BSON_BINARY_SUBTYPE_DEFAULT,n.copy(e,r,0,o),r+=o}function serializeObject(e,t,n,r,i,o,s,u,a,f){for(var c=0;c<f.length;c++)if(f[c]===n)throw new Error("cyclic dependency detected");f.push(n),e[r++]=Array.isArray(n)?constants.BSON_DATA_ARRAY:constants.BSON_DATA_OBJECT,r+=a?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var l=serializeInto(e,n,i,r,o+1,s,u,f);return f.pop(),l}function serializeDecimal128(e,t,n,r,i){return e[r++]=constants.BSON_DATA_DECIMAL128,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0,n.bytes.copy(e,r,0,16),r+16}function serializeLong(e,t,n,r,i){e[r++]="Long"===n._bsontype?constants.BSON_DATA_LONG:constants.BSON_DATA_TIMESTAMP,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var o=n.getLowBits(),s=n.getHighBits();return e[r++]=255&o,e[r++]=o>>8&255,e[r++]=o>>16&255,e[r++]=o>>24&255,e[r++]=255&s,e[r++]=s>>8&255,e[r++]=s>>16&255,e[r++]=s>>24&255,r}function serializeInt32(e,t,n,r,i){return e[r++]=constants.BSON_DATA_INT,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0,e[r++]=255&n,e[r++]=n>>8&255,e[r++]=n>>16&255,e[r++]=n>>24&255,r}function serializeDouble(e,t,n,r,i){return e[r++]=constants.BSON_DATA_NUMBER,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0,writeIEEE754$1(e,n.value,r,"little",52,8),r+=8}function serializeFunction(e,t,n,r,i,o,s){e[r++]=constants.BSON_DATA_CODE,r+=s?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var u=normalizedFunctionString$1(n),a=e.write(u,r+4,"utf8")+1;return e[r]=255&a,e[r+1]=a>>8&255,e[r+2]=a>>16&255,e[r+3]=a>>24&255,r=r+4+a-1,e[r++]=0,r}function serializeCode(e,t,n,r,i,o,s,u,a){if(n.scope&&"object"===_typeof$3(n.scope)){e[r++]=constants.BSON_DATA_CODE_W_SCOPE;r+=a?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var f=r,c="string"==typeof n.code?n.code:n.code.toString();r+=4;var l=e.write(c,r+4,"utf8")+1;e[r]=255&l,e[r+1]=l>>8&255,e[r+2]=l>>16&255,e[r+3]=l>>24&255,e[r+4+l-1]=0,r=r+l+4;var h=serializeInto(e,n.scope,i,r,o+1,s,u);r=h-1;var p=h-f;e[f++]=255&p,e[f++]=p>>8&255,e[f++]=p>>16&255,e[f++]=p>>24&255,e[r++]=0}else{e[r++]=constants.BSON_DATA_CODE;r+=a?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var _=n.code.toString(),d=e.write(_,r+4,"utf8")+1;e[r]=255&d,e[r+1]=d>>8&255,e[r+2]=d>>16&255,e[r+3]=d>>24&255,r=r+4+d-1,e[r++]=0}return r}function serializeBinary(e,t,n,r,i){e[r++]=constants.BSON_DATA_BINARY,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var o=n.value(!0),s=n.position;return n.sub_type===binary.SUBTYPE_BYTE_ARRAY&&(s+=4),e[r++]=255&s,e[r++]=s>>8&255,e[r++]=s>>16&255,e[r++]=s>>24&255,e[r++]=n.sub_type,n.sub_type===binary.SUBTYPE_BYTE_ARRAY&&(s-=4,e[r++]=255&s,e[r++]=s>>8&255,e[r++]=s>>16&255,e[r++]=s>>24&255),o.copy(e,r,0,n.position),r+=n.position}function serializeSymbol(e,t,n,r,i){e[r++]=constants.BSON_DATA_SYMBOL,r+=i?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var o=e.write(n.value,r+4,"utf8")+1;return e[r]=255&o,e[r+1]=o>>8&255,e[r+2]=o>>16&255,e[r+3]=o>>24&255,r=r+4+o-1,e[r++]=0,r}function serializeDBRef(e,t,n,r,i,o,s){e[r++]=constants.BSON_DATA_OBJECT,r+=s?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var u,a=r,f={$ref:n.collection||n.namespace,$id:n.oid};null!=n.db&&(f.$db=n.db),f=Object.assign(f,n.fields),u=serializeInto(e,f,!1,r,i+1,o);var c=u-a;return e[a++]=255&c,e[a++]=c>>8&255,e[a++]=c>>16&255,e[a++]=c>>24&255,u}function serializeInto(e,t,n,r,i,o,s,u){r=r||0,u=u||[],u.push(t);var a=r+4;if(Array.isArray(t))for(var f=0;f<t.length;f++){var c=""+f,l=t[f];if(l&&l.toBSON){if("function"!=typeof l.toBSON)throw new TypeError("toBSON is not a function");l=l.toBSON()}var h=_typeof$3(l);if("string"===h)a=serializeString(e,c,l,a,!0);else if("number"===h)a=serializeNumber(e,c,l,a,!0);else if("boolean"===h)a=serializeBoolean(e,c,l,a,!0);else if(l instanceof Date||isDate$1(l))a=serializeDate(e,c,l,a,!0);else if(void 0===l)a=serializeNull(e,c,l,a,!0);else if(null===l)a=serializeNull(e,c,l,a,!0);else if("ObjectId"===l._bsontype||"ObjectID"===l._bsontype)a=serializeObjectId(e,c,l,a,!0);else if(Buffer$5.isBuffer(l))a=serializeBuffer(e,c,l,a,!0);else if(l instanceof RegExp||isRegExp$1(l))a=serializeRegExp(e,c,l,a,!0);else if("object"===h&&null==l._bsontype)a=serializeObject(e,c,l,a,n,i,o,s,!0,u);else if("object"===h&&"Decimal128"===l._bsontype)a=serializeDecimal128(e,c,l,a,!0);else if("Long"===l._bsontype||"Timestamp"===l._bsontype)a=serializeLong(e,c,l,a,!0);else if("Double"===l._bsontype)a=serializeDouble(e,c,l,a,!0);else if("function"==typeof l&&o)a=serializeFunction(e,c,l,a,n,i,o,!0);else if("Code"===l._bsontype)a=serializeCode(e,c,l,a,n,i,o,s,!0);else if("Binary"===l._bsontype)a=serializeBinary(e,c,l,a,!0);else if("Symbol"===l._bsontype)a=serializeSymbol(e,c,l,a,!0);else if("DBRef"===l._bsontype)a=serializeDBRef(e,c,l,a,i,o,!0);else if("BSONRegExp"===l._bsontype)a=serializeBSONRegExp(e,c,l,a,!0);else if("Int32"===l._bsontype)a=serializeInt32(e,c,l,a,!0);else if("MinKey"===l._bsontype||"MaxKey"===l._bsontype)a=serializeMinMax(e,c,l,a,!0);else if(void 0!==l._bsontype)throw new TypeError("Unrecognized or invalid _bsontype: "+l._bsontype)}else if(t instanceof map)for(var p=t.entries(),_=!1;!_;){var d=p.next();if(!(_=d.done)){var g=d.value[0],y=d.value[1],b=_typeof$3(y);if("string"==typeof g&&!ignoreKeys.has(g)){if(null!=g.match(regexp$1))throw Error("key "+g+" must not contain null bytes");if(n){if("$"===g[0])throw Error("key "+g+" must not start with '$'");if(~g.indexOf("."))throw Error("key "+g+" must not contain '.'")}}if("string"===b)a=serializeString(e,g,y,a);else if("number"===b)a=serializeNumber(e,g,y,a);else if("boolean"===b)a=serializeBoolean(e,g,y,a);else if(y instanceof Date||isDate$1(y))a=serializeDate(e,g,y,a);else if(null===y||void 0===y&&!1===s)a=serializeNull(e,g,y,a);else if("ObjectId"===y._bsontype||"ObjectID"===y._bsontype)a=serializeObjectId(e,g,y,a);else if(Buffer$5.isBuffer(y))a=serializeBuffer(e,g,y,a);else if(y instanceof RegExp||isRegExp$1(y))a=serializeRegExp(e,g,y,a);else if("object"===b&&null==y._bsontype)a=serializeObject(e,g,y,a,n,i,o,s,!1,u);else if("object"===b&&"Decimal128"===y._bsontype)a=serializeDecimal128(e,g,y,a);else if("Long"===y._bsontype||"Timestamp"===y._bsontype)a=serializeLong(e,g,y,a);else if("Double"===y._bsontype)a=serializeDouble(e,g,y,a);else if("Code"===y._bsontype)a=serializeCode(e,g,y,a,n,i,o,s);else if("function"==typeof y&&o)a=serializeFunction(e,g,y,a,n,i,o);else if("Binary"===y._bsontype)a=serializeBinary(e,g,y,a);else if("Symbol"===y._bsontype)a=serializeSymbol(e,g,y,a);else if("DBRef"===y._bsontype)a=serializeDBRef(e,g,y,a,i,o);else if("BSONRegExp"===y._bsontype)a=serializeBSONRegExp(e,g,y,a);else if("Int32"===y._bsontype)a=serializeInt32(e,g,y,a);else if("MinKey"===y._bsontype||"MaxKey"===y._bsontype)a=serializeMinMax(e,g,y,a);else if(void 0!==y._bsontype)throw new TypeError("Unrecognized or invalid _bsontype: "+y._bsontype)}}else{if(t.toBSON){if("function"!=typeof t.toBSON)throw new TypeError("toBSON is not a function");if(null!=(t=t.toBSON())&&"object"!==_typeof$3(t))throw new TypeError("toBSON function did not return an object")}for(var v in t){var m=t[v];if(m&&m.toBSON){if("function"!=typeof m.toBSON)throw new TypeError("toBSON is not a function");m=m.toBSON()}var S=_typeof$3(m);if("string"==typeof v&&!ignoreKeys.has(v)){if(null!=v.match(regexp$1))throw Error("key "+v+" must not contain null bytes");if(n){if("$"===v[0])throw Error("key "+v+" must not start with '$'");if(~v.indexOf("."))throw Error("key "+v+" must not contain '.'")}}if("string"===S)a=serializeString(e,v,m,a);else if("number"===S)a=serializeNumber(e,v,m,a);else if("boolean"===S)a=serializeBoolean(e,v,m,a);else if(m instanceof Date||isDate$1(m))a=serializeDate(e,v,m,a);else if(void 0===m)!1===s&&(a=serializeNull(e,v,m,a));else if(null===m)a=serializeNull(e,v,m,a);else if("ObjectId"===m._bsontype||"ObjectID"===m._bsontype)a=serializeObjectId(e,v,m,a);else if(Buffer$5.isBuffer(m))a=serializeBuffer(e,v,m,a);else if(m instanceof RegExp||isRegExp$1(m))a=serializeRegExp(e,v,m,a);else if("object"===S&&null==m._bsontype)a=serializeObject(e,v,m,a,n,i,o,s,!1,u);else if("object"===S&&"Decimal128"===m._bsontype)a=serializeDecimal128(e,v,m,a);else if("Long"===m._bsontype||"Timestamp"===m._bsontype)a=serializeLong(e,v,m,a);else if("Double"===m._bsontype)a=serializeDouble(e,v,m,a);else if("Code"===m._bsontype)a=serializeCode(e,v,m,a,n,i,o,s);else if("function"==typeof m&&o)a=serializeFunction(e,v,m,a,n,i,o);else if("Binary"===m._bsontype)a=serializeBinary(e,v,m,a);else if("Symbol"===m._bsontype)a=serializeSymbol(e,v,m,a);else if("DBRef"===m._bsontype)a=serializeDBRef(e,v,m,a,i,o);else if("BSONRegExp"===m._bsontype)a=serializeBSONRegExp(e,v,m,a);else if("Int32"===m._bsontype)a=serializeInt32(e,v,m,a);else if("MinKey"===m._bsontype||"MaxKey"===m._bsontype)a=serializeMinMax(e,v,m,a);else if(void 0!==m._bsontype)throw new TypeError("Unrecognized or invalid _bsontype: "+m._bsontype)}}u.pop(),e[a++]=0;var E=a-r;return e[r++]=255&E,e[r++]=E>>8&255,e[r++]=E>>16&255,e[r++]=E>>24&255,a}function _typeof$4(e){return(_typeof$4="function"==typeof Symbol&&"symbol"===_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)})(e)}function isDate$2(e){return"object"===_typeof$4(e)&&"[object Date]"===Object.prototype.toString.call(e)}function calculateObjectSize(e,t,n){var r=5;if(Array.isArray(e))for(var i=0;i<e.length;i++)r+=calculateElement(i.toString(),e[i],t,!0,n);else{e.toBSON&&(e=e.toBSON());for(var o in e)r+=calculateElement(o,e[o],t,!1,n)}return r}function calculateElement(e,t,n,r,i){switch(t&&t.toBSON&&(t=t.toBSON()),_typeof$4(t)){case"string":return 1+Buffer$6.byteLength(e,"utf8")+1+4+Buffer$6.byteLength(t,"utf8")+1;case"number":return Math.floor(t)===t&&t>=constants.JS_INT_MIN&&t<=constants.JS_INT_MAX&&t>=constants.BSON_INT32_MIN&&t<=constants.BSON_INT32_MAX?(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+5:(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+9;case"undefined":return r||!i?(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+1:0;case"boolean":return(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+2;case"object":if(null==t||"MinKey"===t._bsontype||"MaxKey"===t._bsontype)return(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+1;if("ObjectId"===t._bsontype||"ObjectID"===t._bsontype)return(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+13;if(t instanceof Date||isDate$2(t))return(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+9;if(void 0!==Buffer$6&&Buffer$6.isBuffer(t))return(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+6+t.length;if("Long"===t._bsontype||"Double"===t._bsontype||"Timestamp"===t._bsontype)return(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+9;if("Decimal128"===t._bsontype)return(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+17;if("Code"===t._bsontype)return null!=t.scope&&Object.keys(t.scope).length>0?(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+1+4+4+Buffer$6.byteLength(t.code.toString(),"utf8")+1+calculateObjectSize(t.scope,n,i):(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+1+4+Buffer$6.byteLength(t.code.toString(),"utf8")+1;if("Binary"===t._bsontype)return t.sub_type===binary.SUBTYPE_BYTE_ARRAY?(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+(t.position+1+4+1+4):(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+(t.position+1+4+1);if("Symbol"===t._bsontype)return(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+Buffer$6.byteLength(t.value,"utf8")+4+1+1;if("DBRef"===t._bsontype){var o=Object.assign({$ref:t.collection,$id:t.oid},t.fields);return null!=t.db&&(o.$db=t.db),(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+1+calculateObjectSize(o,n,i)}return t instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(t)?(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+1+Buffer$6.byteLength(t.source,"utf8")+1+(t.global?1:0)+(t.ignoreCase?1:0)+(t.multiline?1:0)+1:"BSONRegExp"===t._bsontype?(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+1+Buffer$6.byteLength(t.pattern,"utf8")+1+Buffer$6.byteLength(t.options,"utf8")+1:(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+calculateObjectSize(t,n,i)+1;case"function":if(t instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(t)||"[object RegExp]"===String.call(t))return(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+1+Buffer$6.byteLength(t.source,"utf8")+1+(t.global?1:0)+(t.ignoreCase?1:0)+(t.multiline?1:0)+1;if(n&&null!=t.scope&&Object.keys(t.scope).length>0)return(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+1+4+4+Buffer$6.byteLength(normalizedFunctionString$2(t),"utf8")+1+calculateObjectSize(t.scope,n,i);if(n)return(null!=e?Buffer$6.byteLength(e,"utf8")+1:0)+1+4+Buffer$6.byteLength(normalizedFunctionString$2(t),"utf8")+1}return 0}function setInternalBufferSize(e){buffer$1.length<e&&(buffer$1=Buffer$8.alloc(e))}function serialize$1(e,t){t=t||{};var n="boolean"==typeof t.checkKeys&&t.checkKeys,r="boolean"==typeof t.serializeFunctions&&t.serializeFunctions,i="boolean"!=typeof t.ignoreUndefi