UNPKG

mongodb-stitch

Version:

[![Join the chat at https://gitter.im/mongodb/stitch](https://badges.gitter.im/mongodb/stitch.svg)](https://gitter.im/mongodb/stitch?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

1 lines 276 kB
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=26)}([function(module,__webpack_exports__,__webpack_require__){"use strict";(function(global,Buffer){__webpack_require__.d(__webpack_exports__,"a",function(){return bson_54});var long__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(2),long__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(long__WEBPACK_IMPORTED_MODULE_0__),buffer__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(1),buffer__WEBPACK_IMPORTED_MODULE_1___default=__webpack_require__.n(buffer__WEBPACK_IMPORTED_MODULE_1__),commonjsGlobal="undefined"!=typeof window?window:void 0!==global?global:"undefined"!=typeof self?self:{};function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}var map=createCommonjsModule(function(e){if(void 0!==commonjsGlobal.Map)e.exports=commonjsGlobal.Map,e.exports.Map=commonjsGlobal.Map;else{var t=function(e){this._keys=[],this._values={};for(var t=0;t<e.length;t++)if(null!=e[t]){var n=e[t],r=n[0],o=n[1];this._keys.push(r),this._values[r]={v:o,i:this._keys.length-1}}};t.prototype.clear=function(){this._keys=[],this._values={}},t.prototype.delete=function(e){var t=this._values[e];return null!=t&&(delete this._values[e],this._keys.splice(t.i,1),!0)},t.prototype.entries=function(){var e=this,t=0;return{next:function(){var n=e._keys[t++];return{value:void 0!==n?[n,e._values[n].v]:void 0,done:void 0===n}}}},t.prototype.forEach=function(e,t){t=t||this;for(var n=0;n<this._keys.length;n++){var r=this._keys[n];e.call(t,this._values[r].v,r,t)}},t.prototype.get=function(e){return this._values[e]?this._values[e].v:void 0},t.prototype.has=function(e){return null!=this._values[e]},t.prototype.keys=function(){var e=this,t=0;return{next:function(){var n=e._keys[t++];return{value:void 0!==n?n:void 0,done:void 0===n}}}},t.prototype.set=function(e,t){return this._values[e]?(this._values[e].v=t,this):(this._keys.push(e),this._values[e]={v:t,i:this._keys.length-1},this)},t.prototype.values=function(){var e=this,t=0;return{next:function(){var n=e._keys[t++];return{value:void 0!==n?e._values[n].v:void 0,done:void 0===n}}}},Object.defineProperty(t.prototype,"size",{enumerable:!0,get:function(){return this._keys.length}}),e.exports=t}}),map_1=map.Map;long__WEBPACK_IMPORTED_MODULE_0___default.a.prototype.toExtendedJSON=function(e){return e&&e.relaxed?this.toNumber():{$numberLong:this.toString()}},long__WEBPACK_IMPORTED_MODULE_0___default.a.fromExtendedJSON=function(e,t){var n=long__WEBPACK_IMPORTED_MODULE_0___default.a.fromString(e.$numberLong);return t&&t.relaxed?n.toNumber():n},Object.defineProperty(long__WEBPACK_IMPORTED_MODULE_0___default.a.prototype,"_bsontype",{value:"Long"});var long_1=long__WEBPACK_IMPORTED_MODULE_0___default.a;function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}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 _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 _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(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 _possibleConstructorReturn(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?_assertThisInitialized(e):t}var Double=function(){function e(t){_classCallCheck(this,e),this.value=t}return _createClass(e,[{key:"valueOf",value:function(){return this.value}},{key:"toJSON",value:function(){return this.value}},{key:"toExtendedJSON",value:function(e){return e&&e.relaxed&&isFinite(this.value)?this.value:{$numberDouble:this.value.toString()}}}],[{key:"fromExtendedJSON",value:function(t,n){return n&&n.relaxed?parseFloat(t.$numberDouble):new e(parseFloat(t.$numberDouble))}}]),e}();Object.defineProperty(Double.prototype,"_bsontype",{value:"Double"});var double_1=Double,Timestamp=function(e){function t(e,n){return _classCallCheck(this,t),_possibleConstructorReturn(_possibleConstructorReturn(this,e instanceof long_1?_getPrototypeOf(t).call(this,e.low,e.high):_getPrototypeOf(t).call(this,e,n)))}return _inherits(t,long_1),_createClass(t,[{key:"toJSON",value:function(){return{$timestamp:this.toString()}}},{key:"toExtendedJSON",value:function(){return{$timestamp:{t:this.high,i:this.low}}}}],[{key:"fromInt",value:function(e){return new t(long_1.fromInt(e))}},{key:"fromNumber",value:function(e){return new t(long_1.fromNumber(e))}},{key:"fromBits",value:function(e,n){return new t(e,n)}},{key:"fromString",value:function(e,n){return new t(long_1.fromString(e,n))}},{key:"fromExtendedJSON",value:function(e){return new t(e.$timestamp.i,e.$timestamp.t)}}]),t}();Object.defineProperty(Timestamp.prototype,"_bsontype",{value:"Timestamp"});var timestamp=Timestamp,require$$0={};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}var randomBytes=insecureRandomBytes;if("undefined"!=typeof window&&window.crypto&&window.crypto.getRandomValues)randomBytes=function(e){return window.crypto.getRandomValues(new Uint8Array(e))};else{try{randomBytes=require$$0.randomBytes}catch(e){}null==randomBytes&&(randomBytes=insecureRandomBytes)}var utils={normalizedFunctionString:normalizedFunctionString,randomBytes:randomBytes},Buffer$1=buffer__WEBPACK_IMPORTED_MODULE_1___default.a.Buffer,randomBytes$1=utils.randomBytes,PROCESS_UNIQUE=randomBytes$1(5),checkForHexRegExp=new RegExp("^[0-9a-fA-F]{24}$"),hasBufferType=!1;try{Buffer$1&&Buffer$1.from&&(hasBufferType=!0)}catch(e){hasBufferType=!1}for(var hexTable=[],_i=0;_i<256;_i++)hexTable[_i]=(_i<=15?"0":"")+_i.toString(16);for(var decodeLookup=[],i=0;i<10;)decodeLookup[48+i]=i++;for(;i<16;)decodeLookup[55+i]=decodeLookup[87+i]=i++;var _Buffer=Buffer$1;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."))}var ObjectId=function(){function e(t){if(_classCallCheck(this,e),t instanceof e)return t;if(null==t||"number"==typeof t)return this.id=this.generate(t),void(e.cacheHexString&&(this.__id=this.toString("hex")));var n=e.isValid(t);if(!n&&null!=t)throw new TypeError("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");if(n&&"string"==typeof t&&24===t.length&&hasBufferType)return new e(Buffer$1.from(t,"hex"));if(n&&"string"==typeof t&&24===t.length)return e.createFromHexString(t);if(null==t||12!==t.length){if(null!=t&&t.toHexString)return t;throw new TypeError("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters")}this.id=t,e.cacheHexString&&(this.__id=this.toString("hex"))}return _createClass(e,[{key:"toHexString",value:function(){if(e.cacheHexString&&this.__id)return this.__id;var t="";if(!this.id||!this.id.length)throw new TypeError("invalid ObjectId, ObjectId.id must be either a string or a Buffer, but is ["+JSON.stringify(this.id)+"]");if(this.id instanceof _Buffer)return t=convertToHex(this.id),e.cacheHexString&&(this.__id=t),t;for(var n=0;n<this.id.length;n++){var r=hexTable[this.id.charCodeAt(n)];if("string"!=typeof r)throw makeObjectIdError(this.id,n);t+=r}return e.cacheHexString&&(this.__id=t),t}},{key:"get_inc",value:function(){return e.index=(e.index+1)%16777215}},{key:"getInc",value:function(){return this.get_inc()}},{key:"generate",value:function(e){"number"!=typeof e&&(e=~~(Date.now()/1e3));var t=this.get_inc(),n=Buffer$1.alloc(12);return n[3]=255&e,n[2]=e>>8&255,n[1]=e>>16&255,n[0]=e>>24&255,n[4]=PROCESS_UNIQUE[0],n[5]=PROCESS_UNIQUE[1],n[6]=PROCESS_UNIQUE[2],n[7]=PROCESS_UNIQUE[3],n[8]=PROCESS_UNIQUE[4],n[11]=255&t,n[10]=t>>8&255,n[9]=t>>16&255,n}},{key:"toString",value:function(e){return this.id&&this.id.copy?this.id.toString("string"==typeof e?e:"hex"):this.toHexString()}},{key:"toJSON",value:function(){return this.toHexString()}},{key:"equals",value:function(t){return t instanceof e?this.toString()===t.toString():"string"==typeof t&&e.isValid(t)&&12===t.length&&this.id instanceof _Buffer?t===this.id.toString("binary"):"string"==typeof t&&e.isValid(t)&&24===t.length?t.toLowerCase()===this.toHexString():"string"==typeof t&&e.isValid(t)&&12===t.length?t===this.id:!(null==t||!(t instanceof e||t.toHexString))&&t.toHexString()===this.toHexString()}},{key:"getTimestamp",value:function(){var e=new Date,t=this.id[3]|this.id[2]<<8|this.id[1]<<16|this.id[0]<<24;return e.setTime(1e3*Math.floor(t)),e}},{key:"toExtendedJSON",value:function(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}}}],[{key:"createPk",value:function(){return new e}},{key:"createFromTime",value:function(t){var n=Buffer$1.from([0,0,0,0,0,0,0,0,0,0,0,0]);return n[3]=255&t,n[2]=t>>8&255,n[1]=t>>16&255,n[0]=t>>24&255,new e(n)}},{key:"createFromHexString",value:function(t){if(void 0===t||null!=t&&24!==t.length)throw new TypeError("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");if(hasBufferType)return new e(Buffer$1.from(t,"hex"));for(var n=new _Buffer(12),r=0,o=0;o<24;)n[r++]=decodeLookup[t.charCodeAt(o++)]<<4|decodeLookup[t.charCodeAt(o++)];return new e(n)}},{key:"isValid",value:function(t){return null!=t&&("number"==typeof t||("string"==typeof t?12===t.length||24===t.length&&checkForHexRegExp.test(t):t instanceof e||(t instanceof _Buffer&&12===t.length||!!t.toHexString&&(12===t.id.length||24===t.id.length&&checkForHexRegExp.test(t.id)))))}},{key:"fromExtendedJSON",value:function(t){return new e(t.$oid)}}]),e}();Object.defineProperty(ObjectId.prototype,"generationTime",{enumerable:!0,get:function(){return this.id[3]|this.id[2]<<8|this.id[1]<<16|this.id[0]<<24},set:function(e){this.id[3]=255&e,this.id[2]=e>>8&255,this.id[1]=e>>16&255,this.id[0]=e>>24&255}}),ObjectId.prototype.inspect=ObjectId.prototype.toString,ObjectId.index=~~(16777215*Math.random()),Object.defineProperty(ObjectId.prototype,"_bsontype",{value:"ObjectId"});var objectid=ObjectId;function alphabetize(e){return e.split("").sort().join("")}var BSONRegExp=function(){function e(t,n){_classCallCheck(this,e),this.pattern=t||"",this.options=n?alphabetize(n):"";for(var r=0;r<this.options.length;r++)if("i"!==this.options[r]&&"m"!==this.options[r]&&"x"!==this.options[r]&&"l"!==this.options[r]&&"s"!==this.options[r]&&"u"!==this.options[r])throw new Error("The regular expression option [".concat(this.options[r],"] is not supported"))}return _createClass(e,[{key:"toExtendedJSON",value:function(){return{$regularExpression:{pattern:this.pattern,options:this.options}}}}],[{key:"fromExtendedJSON",value:function(t){return new e(t.$regularExpression.pattern,t.$regularExpression.options.split("").sort().join(""))}}]),e}();Object.defineProperty(BSONRegExp.prototype,"_bsontype",{value:"BSONRegExp"});var regexp=BSONRegExp,BSONSymbol=function(){function e(t){_classCallCheck(this,e),this.value=t}return _createClass(e,[{key:"valueOf",value:function(){return this.value}},{key:"toString",value:function(){return this.value}},{key:"inspect",value:function(){return this.value}},{key:"toJSON",value:function(){return this.value}},{key:"toExtendedJSON",value:function(){return{$symbol:this.value}}}],[{key:"fromExtendedJSON",value:function(t){return new e(t.$symbol)}}]),e}();Object.defineProperty(BSONSymbol.prototype,"_bsontype",{value:"Symbol"});var symbol=BSONSymbol,Int32=function(){function e(t){_classCallCheck(this,e),this.value=t}return _createClass(e,[{key:"valueOf",value:function(){return this.value}},{key:"toJSON",value:function(){return this.value}},{key:"toExtendedJSON",value:function(e){return e&&e.relaxed?this.value:{$numberInt:this.value.toString()}}}],[{key:"fromExtendedJSON",value:function(t,n){return n&&n.relaxed?parseInt(t.$numberInt,10):new e(t.$numberInt)}}]),e}();Object.defineProperty(Int32.prototype,"_bsontype",{value:"Int32"});var int_32=Int32,Code=function(){function e(t,n){_classCallCheck(this,e),this.code=t,this.scope=n}return _createClass(e,[{key:"toJSON",value:function(){return{scope:this.scope,code:this.code}}},{key:"toExtendedJSON",value:function(){return this.scope?{$code:this.code,$scope:this.scope}:{$code:this.code}}}],[{key:"fromExtendedJSON",value:function(t){return new e(t.$code,t.$scope)}}]),e}();Object.defineProperty(Code.prototype,"_bsontype",{value:"Code"});var code=Code,PARSE_STRING_REGEXP=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,PARSE_INF_REGEXP=/^(\+|-)?(Infinity|inf)$/i,PARSE_NAN_REGEXP=/^(\+|-)?NaN$/i,EXPONENT_MAX=6111,EXPONENT_MIN=-6176,EXPONENT_BIAS=6176,MAX_DIGITS=34,NAN_BUFFER=[124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),INF_NEGATIVE_BUFFER=[248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),INF_POSITIVE_BUFFER=[120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),EXPONENT_REGEX=/^([-+])?(\d+)?$/;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=n.shiftLeft(32)).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),o=t.shiftRightUnsigned(32),i=new long_1(t.getLowBits(),0),a=n.multiply(o),u=n.multiply(i),s=r.multiply(o),l=r.multiply(i);return a=a.add(u.shiftRightUnsigned(32)),u=new long_1(u.getLowBits(),0).add(s).add(l.shiftRightUnsigned(32)),{high:a=a.add(u.shiftRightUnsigned(32)),low:l=u.shiftLeft(32).add(new long_1(l.getLowBits(),0))}}function lessThan(e,t){var n=e.high>>>0,r=t.high>>>0;return n<r||n===r&&e.low>>>0<t.low>>>0}function invalidErr(e,t){throw new TypeError('"'.concat(e,'" is not a valid Decimal128 string - ').concat(t))}function Decimal128(e){this.bytes=e}Decimal128.fromString=function(e){var t,n=!1,r=!1,o=!1,i=0,a=0,u=0,s=0,l=0,c=[0],f=0,d=0,h=0,p=0,y=0,g=0,m=[0,0],v=[0,0],_=0;if(e.length>=7e3)throw new TypeError(e+" not a valid Decimal128 string");var b=e.match(PARSE_STRING_REGEXP),w=e.match(PARSE_INF_REGEXP),E=e.match(PARSE_NAN_REGEXP);if(!b&&!w&&!E||0===e.length)throw new TypeError(e+" not a valid Decimal128 string");if(b){var A=b[2],N=b[4],T=b[5],S=b[6];N&&void 0===S&&invalidErr(e,"missing exponent power"),N&&void 0===A&&invalidErr(e,"missing exponent base"),void 0===N&&(T||S)&&invalidErr(e,"missing e before exponent")}if("+"!==e[_]&&"-"!==e[_]||(n="-"===e[_++]),!isDigit(e[_])&&"."!==e[_]){if("i"===e[_]||"I"===e[_])return new Decimal128(Buffer.from(n?INF_NEGATIVE_BUFFER:INF_POSITIVE_BUFFER));if("N"===e[_])return new Decimal128(Buffer.from(NAN_BUFFER))}for(;isDigit(e[_])||"."===e[_];)"."!==e[_]?(f<34&&("0"!==e[_]||o)&&(o||(l=a),o=!0,c[d++]=parseInt(e[_],10),f+=1),o&&(u+=1),r&&(s+=1),a+=1,_+=1):(r&&invalidErr(e,"contains multiple periods"),r=!0,_+=1);if(r&&!a)throw new TypeError(e+" not a valid Decimal128 string");if("e"===e[_]||"E"===e[_]){var O=e.substr(++_).match(EXPONENT_REGEX);if(!O||!O[2])return new Decimal128(Buffer.from(NAN_BUFFER));y=parseInt(O[0],10),_+=O[0].length}if(e[_])return new Decimal128(Buffer.from(NAN_BUFFER));if(h=0,f){if(p=f-1,1!==(i=u))for(;"0"===e[l+i-1];)i-=1}else h=0,p=0,c[0]=0,u=1,f=1,i=0;for(y<=s&&s-y>16384?y=EXPONENT_MIN:y-=s;y>EXPONENT_MAX;){if((p+=1)-h>MAX_DIGITS){if(c.join("").match(/^0+$/)){y=EXPONENT_MAX;break}invalidErr(e,"overflow")}y-=1}for(;y<EXPONENT_MIN||f<u;){if(0===p&&i<f){y=EXPONENT_MIN,i=0;break}if(f<u?u-=1:p-=1,y<EXPONENT_MAX)y+=1;else{if(c.join("").match(/^0+$/)){y=EXPONENT_MAX;break}invalidErr(e,"overflow")}}if(p-h+1<i){var I=a;r&&(l+=1,I+=1),n&&(l+=1,I+=1);var R=parseInt(e[l+p+1],10),B=0;if(R>=5&&(B=1,5===R))for(B=c[p]%2==1,g=l+p+2;g<I;g++)if(parseInt(e[g],10)){B=1;break}if(B)for(var P=p;P>=0;P--)if(++c[P]>9&&(c[P]=0,0===P)){if(!(y<EXPONENT_MAX))return new Decimal128(Buffer.from(n?INF_NEGATIVE_BUFFER:INF_POSITIVE_BUFFER));y+=1,c[P]=1}}if(m=long_1.fromNumber(0),v=long_1.fromNumber(0),0===i)m=long_1.fromNumber(0),v=long_1.fromNumber(0);else if(p-h<17){var C=h;for(v=long_1.fromNumber(c[C++]),m=new long_1(0,0);C<=p;C++)v=(v=v.multiply(long_1.fromNumber(10))).add(long_1.fromNumber(c[C]))}else{var k=h;for(m=long_1.fromNumber(c[k++]);k<=p-17;k++)m=(m=m.multiply(long_1.fromNumber(10))).add(long_1.fromNumber(c[k]));for(v=long_1.fromNumber(c[k++]);k<=p;k++)v=(v=v.multiply(long_1.fromNumber(10))).add(long_1.fromNumber(c[k]))}var x=multiply64x2(m,long_1.fromString("100000000000000000"));x.low=x.low.add(v),lessThan(x.low,v)&&(x.high=x.high.add(long_1.fromNumber(1))),t=y+EXPONENT_BIAS;var D={low:long_1.fromNumber(0),high:long_1.fromNumber(0)};x.high.shiftRightUnsigned(49).and(long_1.fromNumber(1)).equals(long_1.fromNumber(1))?(D.high=D.high.or(long_1.fromNumber(3).shiftLeft(61)),D.high=D.high.or(long_1.fromNumber(t).and(long_1.fromNumber(16383).shiftLeft(47))),D.high=D.high.or(x.high.and(long_1.fromNumber(0x7fffffffffff)))):(D.high=D.high.or(long_1.fromNumber(16383&t).shiftLeft(49)),D.high=D.high.or(x.high.and(long_1.fromNumber(562949953421311)))),D.low=x.low,n&&(D.high=D.high.or(long_1.fromString("9223372036854775808")));var U=Buffer.alloc(16);return _=0,U[_++]=255&D.low.low,U[_++]=D.low.low>>8&255,U[_++]=D.low.low>>16&255,U[_++]=D.low.low>>24&255,U[_++]=255&D.low.high,U[_++]=D.low.high>>8&255,U[_++]=D.low.high>>16&255,U[_++]=D.low.high>>24&255,U[_++]=255&D.high.low,U[_++]=D.high.low>>8&255,U[_++]=D.high.low>>16&255,U[_++]=D.high.low>>24&255,U[_++]=255&D.high.high,U[_++]=D.high.high>>8&255,U[_++]=D.high.high>>16&255,U[_++]=D.high.high>>24&255,new Decimal128(U)};var COMBINATION_MASK=31,EXPONENT_MASK=16383,COMBINATION_INFINITY=30,COMBINATION_NAN=31;Decimal128.prototype.toString=function(){for(var e,t,n,r,o,i,a=0,u=new Array(36),s=0;s<u.length;s++)u[s]=0;var l,c,f,d,h,p=0,y=!1,g={parts:new Array(4)},m=[];p=0;var v=this.bytes;if(r=v[p++]|v[p++]<<8|v[p++]<<16|v[p++]<<24,n=v[p++]|v[p++]<<8|v[p++]<<16|v[p++]<<24,t=v[p++]|v[p++]<<8|v[p++]<<16|v[p++]<<24,e=v[p++]|v[p++]<<8|v[p++]<<16|v[p++]<<24,p=0,{low:new long_1(r,n),high:new long_1(t,e)}.high.lessThan(long_1.ZERO)&&m.push("-"),(o=e>>26&COMBINATION_MASK)>>3==3){if(o===COMBINATION_INFINITY)return m.join("")+"Infinity";if(o===COMBINATION_NAN)return"NaN";i=e>>15&EXPONENT_MASK,f=8+(e>>14&1)}else f=e>>14&7,i=e>>17&EXPONENT_MASK;if(l=i-EXPONENT_BIAS,g.parts[0]=(16383&e)+((15&f)<<14),g.parts[1]=t,g.parts[2]=n,g.parts[3]=r,0===g.parts[0]&&0===g.parts[1]&&0===g.parts[2]&&0===g.parts[3])y=!0;else for(h=3;h>=0;h--){var _=0,b=divideu128(g);if(g=b.quotient,_=b.rem.low)for(d=8;d>=0;d--)u[9*h+d]=_%10,_=Math.floor(_/10)}if(y)a=1,u[p]=0;else for(a=36;!u[p];)a-=1,p+=1;if((c=a-1+l)>=34||c<=-7||l>0){if(a>34)return m.push(0),l>0?m.push("E+"+l):l<0&&m.push("E"+l),m.join("");m.push(u[p++]),(a-=1)&&m.push(".");for(var w=0;w<a;w++)m.push(u[p++]);m.push("E"),c>0?m.push("+"+c):m.push(c)}else if(l>=0)for(var E=0;E<a;E++)m.push(u[p++]);else{var A=a+l;if(A>0)for(var N=0;N<A;N++)m.push(u[p++]);else m.push("0");for(m.push(".");A++<0;)m.push("0");for(var T=0;T<a-Math.max(A-1,0);T++)m.push(u[p++])}return m.join("")},Decimal128.prototype.toJSON=function(){return{$numberDecimal:this.toString()}},Decimal128.prototype.toExtendedJSON=function(){return{$numberDecimal:this.toString()}},Decimal128.fromExtendedJSON=function(e){return Decimal128.fromString(e.$numberDecimal)},Object.defineProperty(Decimal128.prototype,"_bsontype",{value:"Decimal128"});var decimal128=Decimal128,MinKey=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"toExtendedJSON",value:function(){return{$minKey:1}}}],[{key:"fromExtendedJSON",value:function(){return new e}}]),e}();Object.defineProperty(MinKey.prototype,"_bsontype",{value:"MinKey"});var min_key=MinKey,MaxKey=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"toExtendedJSON",value:function(){return{$maxKey:1}}}],[{key:"fromExtendedJSON",value:function(){return new e}}]),e}();Object.defineProperty(MaxKey.prototype,"_bsontype",{value:"MaxKey"});var max_key=MaxKey,DBRef=function(){function e(t,n,r,o){_classCallCheck(this,e);var i=t.split(".");2===i.length&&(r=i.shift(),t=i.shift()),this.collection=t,this.oid=n,this.db=r,this.fields=o||{}}return _createClass(e,[{key:"toJSON",value:function(){var e=Object.assign({$ref:this.collection,$id:this.oid},this.fields);return null!=this.db&&(e.$db=this.db),e}},{key:"toExtendedJSON",value:function(){var e={$ref:this.collection,$id:this.oid};return this.db&&(e.$db=this.db),e=Object.assign(e,this.fields)}}],[{key:"fromExtendedJSON",value:function(t){var n=Object.assign({},t);return["$ref","$id","$db"].forEach(function(e){return delete n[e]}),new e(t.$ref,t.$id,t.$db,n)}}]),e}();Object.defineProperty(DBRef.prototype,"_bsontype",{value:"DBRef"});var db_ref=DBRef,Binary=function(){function e(t,n){if(_classCallCheck(this,e),!(null==t||"string"==typeof t||Buffer.isBuffer(t)||t instanceof Uint8Array||Array.isArray(t)))throw new TypeError("only String, Buffer, Uint8Array or Array accepted");if(this.sub_type=null==n?BSON_BINARY_SUBTYPE_DEFAULT:n,this.position=0,null==t||t instanceof Number)void 0!==Buffer?this.buffer=Buffer.alloc(e.BUFFER_SIZE):"undefined"!=typeof Uint8Array?this.buffer=new Uint8Array(new ArrayBuffer(e.BUFFER_SIZE)):this.buffer=new Array(e.BUFFER_SIZE);else{if("string"==typeof t)if(void 0!==Buffer)this.buffer=Buffer.from(t);else{if("undefined"==typeof Uint8Array&&!Array.isArray(t))throw new TypeError("only String, Buffer, Uint8Array or Array accepted");this.buffer=writeStringToArray(t)}else this.buffer=t;this.position=t.length}}return _createClass(e,[{key:"put",value:function(t){if(null!=t.length&&"number"!=typeof t&&1!==t.length)throw new TypeError("only accepts single character String, Uint8Array or Array");if("number"!=typeof t&&t<0||t>255)throw new TypeError("only accepts number in a valid unsigned byte range 0-255");var n=null;if(n="string"==typeof t?t.charCodeAt(0):null!=t.length?t[0]:t,this.buffer.length>this.position)this.buffer[this.position++]=n;else if(void 0!==Buffer&&Buffer.isBuffer(this.buffer)){var r=Buffer.alloc(e.BUFFER_SIZE+this.buffer.length);this.buffer.copy(r,0,0,this.buffer.length),this.buffer=r,this.buffer[this.position++]=n}else{var o=null;o=isUint8Array(this.buffer)?new Uint8Array(new ArrayBuffer(e.BUFFER_SIZE+this.buffer.length)):new Array(e.BUFFER_SIZE+this.buffer.length);for(var i=0;i<this.buffer.length;i++)o[i]=this.buffer[i];this.buffer=o,this.buffer[this.position++]=n}}},{key:"write",value:function(e,t){if(t="number"==typeof t?t:this.position,this.buffer.length<t+e.length){var n=null;if(void 0!==Buffer&&Buffer.isBuffer(this.buffer))n=Buffer.alloc(this.buffer.length+e.length),this.buffer.copy(n,0,0,this.buffer.length);else if(isUint8Array(this.buffer)){n=new Uint8Array(new ArrayBuffer(this.buffer.length+e.length));for(var r=0;r<this.position;r++)n[r]=this.buffer[r]}this.buffer=n}if(void 0!==Buffer&&Buffer.isBuffer(e)&&Buffer.isBuffer(this.buffer))e.copy(this.buffer,t,0,e.length),this.position=t+e.length>this.position?t+e.length:this.position;else if(void 0!==Buffer&&"string"==typeof e&&Buffer.isBuffer(this.buffer))this.buffer.write(e,t,"binary"),this.position=t+e.length>this.position?t+e.length:this.position;else if(isUint8Array(e)||Array.isArray(e)&&"string"!=typeof e){for(var o=0;o<e.length;o++)this.buffer[t++]=e[o];this.position=t>this.position?t:this.position}else if("string"==typeof e){for(var i=0;i<e.length;i++)this.buffer[t++]=e.charCodeAt(i);this.position=t>this.position?t:this.position}}},{key:"read",value:function(e,t){if(t=t&&t>0?t:this.position,this.buffer.slice)return this.buffer.slice(e,e+t);for(var n="undefined"!=typeof Uint8Array?new Uint8Array(new ArrayBuffer(t)):new Array(t),r=0;r<t;r++)n[r]=this.buffer[e++];return n}},{key:"value",value:function(e){if((e=null!=e&&e)&&void 0!==Buffer&&Buffer.isBuffer(this.buffer)&&this.buffer.length===this.position)return this.buffer;if(void 0!==Buffer&&Buffer.isBuffer(this.buffer))return e?this.buffer.slice(0,this.position):this.buffer.toString("binary",0,this.position);if(e){if(null!=this.buffer.slice)return this.buffer.slice(0,this.position);for(var t=isUint8Array(this.buffer)?new Uint8Array(new ArrayBuffer(this.position)):new Array(this.position),n=0;n<this.position;n++)t[n]=this.buffer[n];return t}return convertArraytoUtf8BinaryString(this.buffer,0,this.position)}},{key:"length",value:function(){return this.position}},{key:"toJSON",value:function(){return null!=this.buffer?this.buffer.toString("base64"):""}},{key:"toString",value:function(e){return null!=this.buffer?this.buffer.slice(0,this.position).toString(e):""}},{key:"toExtendedJSON",value:function(){var e=Buffer.isBuffer(this.buffer)?this.buffer.toString("base64"):Buffer.from(this.buffer).toString("base64"),t=Number(this.sub_type).toString(16);return{$binary:{base64:e,subType:1===t.length?"0"+t:t}}}}],[{key:"fromExtendedJSON",value:function(t){var n=t.$binary.subType?parseInt(t.$binary.subType,16):0;return new e(new Buffer(t.$binary.base64,"base64"),n)}}]),e}(),BSON_BINARY_SUBTYPE_DEFAULT=0;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="",o=t;o<n;o++)r+=String.fromCharCode(e[o]);return r}Binary.BUFFER_SIZE=256,Binary.SUBTYPE_DEFAULT=0,Binary.SUBTYPE_FUNCTION=1,Binary.SUBTYPE_BYTE_ARRAY=2,Binary.SUBTYPE_UUID_OLD=3,Binary.SUBTYPE_UUID=4,Binary.SUBTYPE_MD5=5,Binary.SUBTYPE_USER_DEFINED=128,Object.defineProperty(Binary.prototype,"_bsontype",{value:"Binary"});var binary=Binary,constants={BSON_INT32_MAX:2147483647,BSON_INT32_MIN:-2147483648,BSON_INT64_MAX:Math.pow(2,63)-1,BSON_INT64_MIN:-Math.pow(2,63),JS_INT_MAX:9007199254740992,JS_INT_MIN:-9007199254740992,BSON_DATA_NUMBER:1,BSON_DATA_STRING:2,BSON_DATA_OBJECT:3,BSON_DATA_ARRAY:4,BSON_DATA_BINARY:5,BSON_DATA_UNDEFINED:6,BSON_DATA_OID:7,BSON_DATA_BOOLEAN:8,BSON_DATA_DATE:9,BSON_DATA_NULL:10,BSON_DATA_REGEXP:11,BSON_DATA_DBPOINTER:12,BSON_DATA_CODE:13,BSON_DATA_SYMBOL:14,BSON_DATA_CODE_W_SCOPE:15,BSON_DATA_INT:16,BSON_DATA_TIMESTAMP:17,BSON_DATA_LONG:18,BSON_DATA_DECIMAL128:19,BSON_DATA_MIN_KEY:255,BSON_DATA_MAX_KEY:127,BSON_BINARY_SUBTYPE_DEFAULT:0,BSON_BINARY_SUBTYPE_FUNCTION:1,BSON_BINARY_SUBTYPE_BYTE_ARRAY:2,BSON_BINARY_SUBTYPE_UUID:3,BSON_BINARY_SUBTYPE_MD5:4,BSON_BINARY_SUBTYPE_USER_DEFINED:128},keysToCodecs={$oid:objectid,$binary:binary,$symbol:symbol,$numberInt:int_32,$numberDecimal:decimal128,$numberDouble:double_1,$numberLong:long_1,$minKey:min_key,$maxKey:max_key,$regularExpression:regexp,$timestamp:timestamp};function deserializeValue(e,t,n,r){if("number"==typeof n){if(r.relaxed)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(n))return n;if(n.$undefined)return null;for(var o=Object.keys(n).filter(function(e){return e.startsWith("$")&&null!=n[e]}),i=0;i<o.length;i++){var a=keysToCodecs[o[i]];if(a)return a.fromExtendedJSON(n,r)}if(null!=n.$date){var u=n.$date,s=new Date;return"string"==typeof u?s.setTime(Date.parse(u)):u instanceof long_1?s.setTime(u.toNumber()):"number"==typeof u&&r.relaxed&&s.setTime(u),s}if(null!=n.$code){var l=Object.assign({},n);return n.$scope&&(l.$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 f=!0;if(Object.keys(c).filter(function(e){return e.startsWith("$")}).forEach(function(e){-1===["$ref","$id","$db"].indexOf(e)&&(f=!1)}),f)return db_ref.fromExtendedJSON(c)}return n}function parse(e,t){var n=this;return"boolean"==typeof(t=Object.assign({},{relaxed:!0},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)})}var BSON_INT32_MAX=2147483647,BSON_INT32_MIN=-2147483648,BSON_INT64_MAX=0x8000000000000000,BSON_INT64_MIN=-0x8000000000000000;function stringify(e,t,n,r){null!=n&&"object"===_typeof(n)&&(r=n,n=0),null!=t&&"object"===_typeof(t)&&(r=t,t=null,n=0),r=Object.assign({},{relaxed:!0},r);var o=Array.isArray(e)?serializeArray(e,r):serializeDocument(e,r);return JSON.stringify(o,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.relaxed&&r?{$date:getISOString(e)}:{$date:{$numberLong:e.getTime().toString()}}}if("number"==typeof e&&!t.relaxed){if(Math.floor(e)===e){var o=e>=BSON_INT64_MIN&&e<=BSON_INT64_MAX;if(e>=BSON_INT32_MIN&&e<=BSON_INT32_MAX)return{$numberInt:e.toString()};if(o)return{$numberLong:e.toString()}}return{$numberDouble:e.toString()}}return null!=e&&"object"===_typeof(e)?serializeDocument(e,t):e}function serializeDocument(e,t){if(null==e||"object"!==_typeof(e))throw new Error("not an object instance");if(e._bsontype&&"function"==typeof e.toExtendedJSON)return"Code"===e._bsontype&&e.scope?e.scope=serializeDocument(e.scope,t):"DBRef"===e._bsontype&&e.oid&&(e.oid=serializeDocument(e.oid,t)),e.toExtendedJSON(t);var n={};for(var r in e){var o=e[r];if(Array.isArray(o)?n[r]=serializeArray(o,t):null!=o&&"function"==typeof o.toExtendedJSON?("Code"===o._bsontype&&o.scope?o.scope=serializeDocument(o.scope,t):"DBRef"===o._bsontype&&o.oid&&(o.oid=serializeDocument(o.oid,t)),n[r]=o.toExtendedJSON(t)):o instanceof Date?n[r]=serializeValue(o,t):null!=o&&"object"===_typeof(o)&&(n[r]=serializeDocument(o,t)),n[r]=serializeValue(o,t),o instanceof RegExp){var i=o.flags;void 0===i&&(i=o.toString().match(/[gimuy]*$/)[0]);var a=new regexp(o.source,i);n[r]=a.toExtendedJSON()}}return n}var extended_json={parse:parse,deserialize:deserialize,serialize:serialize,stringify:stringify},FIRST_BIT=128,FIRST_TWO_BITS=192,FIRST_THREE_BITS=224,FIRST_FOUR_BITS=240,FIRST_FIVE_BITS=248,TWO_BIT_CHAR=192,THREE_BIT_CHAR=224,FOUR_BIT_CHAR=240,CONTINUING_CHAR=128;function validateUtf8(e,t,n){for(var r=0,o=t;o<n;o+=1){var i=e[o];if(r){if((i&FIRST_TWO_BITS)!==CONTINUING_CHAR)return!1;r-=1}else if(i&FIRST_BIT)if((i&FIRST_THREE_BITS)===TWO_BIT_CHAR)r=1;else if((i&FIRST_FOUR_BITS)===THREE_BIT_CHAR)r=2;else{if((i&FIRST_FIVE_BITS)!==FOUR_BIT_CHAR)return!1;r=3}}return!r}var validateUtf8_1=validateUtf8,validate_utf8={validateUtf8:validateUtf8_1},Buffer$2=buffer__WEBPACK_IMPORTED_MODULE_1___default.a.Buffer,validateUtf8$1=validate_utf8.validateUtf8,JS_INT_MAX_LONG=long_1.fromNumber(constants.JS_INT_MAX),JS_INT_MIN_LONG=long_1.fromNumber(constants.JS_INT_MIN),functionCache={};function deserialize$1(e,t,n){var r=(t=null==t?{}:t)&&t.index?t.index:0,o=e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24;if(o<5)throw new Error("bson size must be >= 5, is ".concat(o));if(t.allowObjectSmallerThanBufferSize&&e.length<o)throw new Error("buffer length ".concat(e.length," must be >= bson size ").concat(o));if(!t.allowObjectSmallerThanBufferSize&&e.length!==o)throw new Error("buffer length ".concat(e.length," must === bson size ").concat(o));if(o+r>e.length)throw new Error("(bson size ".concat(o," + options.index ").concat(r," must be <= buffer length ").concat(Buffer$2.byteLength(e),")"));if(0!==e[r+o-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 o=null!=n.evalFunctions&&n.evalFunctions,i=null!=n.cacheFunctions&&n.cacheFunctions,a=null!=n.cacheFunctionsCrc32&&n.cacheFunctionsCrc32;if(!a)var u=null;var s=null==n.fieldsAsRaw?null:n.fieldsAsRaw,l=null!=n.raw&&n.raw,c="boolean"==typeof n.bsonRegExp&&n.bsonRegExp,f=null!=n.promoteBuffers&&n.promoteBuffers,d=null==n.promoteLongs||n.promoteLongs,h=null==n.promoteValues||n.promoteValues,p=t;if(e.length<5)throw new Error("corrupt bson message < 5 bytes long");var y=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(y<5||y>e.length)throw new Error("corrupt bson message");for(var g=r?[]:{},m=0;;){var v=e[t++];if(0===v)break;for(var _=t;0!==e[_]&&_<e.length;)_++;if(_>=Buffer$2.byteLength(e))throw new Error("Bad BSON Document: illegal CString");var b=r?m++:e.toString("utf8",t,_);if(t=_+1,v===constants.BSON_DATA_STRING){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");if(!validateUtf8$1(e,t,t+w-1))throw new Error("Invalid UTF-8 string in BSON document");var E=e.toString("utf8",t,t+w-1);g[b]=E,t+=w}else if(v===constants.BSON_DATA_OID){var A=Buffer$2.alloc(12);e.copy(A,0,t,t+12),g[b]=new objectid(A),t+=12}else if(v===constants.BSON_DATA_INT&&!1===h)g[b]=new int_32(e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24);else if(v===constants.BSON_DATA_INT)g[b]=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;else if(v===constants.BSON_DATA_NUMBER&&!1===h)g[b]=new double_1(e.readDoubleLE(t)),t+=8;else if(v===constants.BSON_DATA_NUMBER)g[b]=e.readDoubleLE(t),t+=8;else if(v===constants.BSON_DATA_DATE){var N=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,T=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;g[b]=new Date(new long_1(N,T).toNumber())}else if(v===constants.BSON_DATA_BOOLEAN){if(0!==e[t]&&1!==e[t])throw new Error("illegal boolean type value");g[b]=1===e[t++]}else if(v===constants.BSON_DATA_OBJECT){var S=t,O=e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24;if(O<=0||O>e.length-t)throw new Error("bad embedded document length in bson");g[b]=l?e.slice(t,t+O):deserializeObject(e,S,n,!1),t+=O}else if(v===constants.BSON_DATA_ARRAY){var I=t,R=e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24,B=n,P=t+R;if(s&&s[b]){for(var C in B={},n)B[C]=n[C];B.raw=!0}if(g[b]=deserializeObject(e,I,B,!0),0!==e[(t+=R)-1])throw new Error("invalid array terminator byte");if(t!==P)throw new Error("corrupted array bson")}else if(v===constants.BSON_DATA_UNDEFINED)g[b]=void 0;else if(v===constants.BSON_DATA_NULL)g[b]=null;else if(v===constants.BSON_DATA_LONG){var k=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,x=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,D=new long_1(k,x);g[b]=d&&!0===h&&D.lessThanOrEqual(JS_INT_MAX_LONG)&&D.greaterThanOrEqual(JS_INT_MIN_LONG)?D.toNumber():D}else if(v===constants.BSON_DATA_DECIMAL128){var U=Buffer$2.alloc(16);e.copy(U,0,t,t+16),t+=16;var M=new decimal128(U);g[b]=M.toObject?M.toObject():M}else if(v===constants.BSON_DATA_BINARY){var L=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,F=L,j=e[t++];if(L<0)throw new Error("Negative binary type element size found");if(L>Buffer$2.byteLength(e))throw new Error("Binary type size larger than document size");if(null!=e.slice){if(j===binary.SUBTYPE_BYTE_ARRAY){if((L=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(L>F-4)throw new Error("Binary type with subtype 0x02 contains to long binary size");if(L<F-4)throw new Error("Binary type with subtype 0x02 contains to short binary size")}g[b]=f&&h?e.slice(t,t+L):new binary(e.slice(t,t+L),j)}else{var z="undefined"!=typeof Uint8Array?new Uint8Array(new ArrayBuffer(L)):new Array(L);if(j===binary.SUBTYPE_BYTE_ARRAY){if((L=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(L>F-4)throw new Error("Binary type with subtype 0x02 contains to long binary size");if(L<F-4)throw new Error("Binary type with subtype 0x02 contains to short binary size")}for(_=0;_<L;_++)z[_]=e[t+_];g[b]=f&&h?z:new binary(z,j)}t+=L}else if(v===constants.BSON_DATA_REGEXP&&!1===c){for(_=t;0!==e[_]&&_<e.length;)_++;if(_>=e.length)throw new Error("Bad BSON Document: illegal CString");var $=e.toString("utf8",t,_);for(_=t=_+1;0!==e[_]&&_<e.length;)_++;if(_>=e.length)throw new Error("Bad BSON Document: illegal CString");var Y=e.toString("utf8",t,_);t=_+1;var W=new Array(Y.length);for(_=0;_<Y.length;_++)switch(Y[_]){case"m":W[_]="m";break;case"s":W[_]="g";break;case"i":W[_]="i"}g[b]=new RegExp($,W.join(""))}else if(v===constants.BSON_DATA_REGEXP&&!0===c){for(_=t;0!==e[_]&&_<e.length;)_++;if(_>=e.length)throw new Error("Bad BSON Document: illegal CString");var K=e.toString("utf8",t,_);for(_=t=_+1;0!==e[_]&&_<e.length;)_++;if(_>=e.length)throw new Error("Bad BSON Document: illegal CString");var V=e.toString("utf8",t,_);t=_+1,g[b]=new regexp(K,V)}else if(v===constants.BSON_DATA_SYMBOL){var q=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(q<=0||q>e.length-t||0!==e[t+q-1])throw new Error("bad string length in bson");g[b]=e.toString("utf8",t,t+q-1),t+=q}else if(v===constants.BSON_DATA_TIMESTAMP){var H=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,J=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;g[b]=new timestamp(H,J)}else if(v===constants.BSON_DATA_MIN_KEY)g[b]=new min_key;else if(v===constants.BSON_DATA_MAX_KEY)g[b]=new max_key;else if(v===constants.BSON_DATA_CODE){var G=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(G<=0||G>e.length-t||0!==e[t+G-1])throw new Error("bad string length in bson");var X=e.toString("utf8",t,t+G-1);if(o)if(i){var Q=a?u(X):X;g[b]=isolateEvalWithHash(functionCache,Q,X,g)}else g[b]=isolateEval(X);else g[b]=new code(X);t+=G}else if(v===constants.BSON_DATA_CODE_W_SCOPE){var Z=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(Z<13)throw new Error("code_w_scope total size shorter minimum expected length");var ee=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(ee<=0||ee>e.length-t||0!==e[t+ee-1])throw new Error("bad string length in bson");var te=e.toString("utf8",t,t+ee-1),ne=t+=ee,re=e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24,oe=deserializeObject(e,ne,n,!1);if(t+=re,Z<8+re+ee)throw new Error("code_w_scope total size is to short, truncating scope");if(Z>8+re+ee)throw new Error("code_w_scope total size is to long, clips outer document");if(o){if(i){var ie=a?u(te):te;g[b]=isolateEvalWithHash(functionCache,ie,te,g)}else g[b]=isolateEval(te);g[b].scope=oe}else g[b]=new code(te,oe)}else{if(v!==constants.BSON_DATA_DBPOINTER)throw new Error("Detected unknown BSON type "+v.toString(16)+' for fieldname "'+b+'", are you using the latest BSON parser?');var ae=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(ae<=0||ae>e.length-t||0!==e[t+ae-1])throw new Error("bad string length in bson");if(!validateUtf8$1(e,t,t+ae-1))throw new Error("Invalid UTF-8 string in BSON document");var ue=e.toString("utf8",t,t+ae-1);t+=ae;var se=Buffer$2.alloc(12);e.copy(se,0,t,t+12);var le=new objectid(se);t+=12,g[b]=new db_ref(ue,le)}}if(y!==t-p){if(r)throw new Error("corrupt array bson");throw new Error("corrupt object bson")}var ce=!0;if(Object.keys(g).filter(function(e){return e.startsWith("$")}).forEach(function(e){-1===["$ref","$id","$db"].indexOf(e)&&(ce=!1)}),!ce)return g;if(null!=g.$id&&null!=g.$ref){var fe=Object.assign({},g);return delete fe.$ref,delete fe.$id,delete fe.$db,new db_ref(g.$ref,g.$id,g.$db||null,fe)}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}var deserializer=deserialize$1;function readIEEE754(e,t,n,r,o){var i,a,u="big"===n,s=8*o-r-1,l=(1<<s)-1,c=l>>1,f=-7,d=u?0:o-1,h=u?1:-1,p=e[t+d];for(d+=h,i=p&(1<<-f)-1,p>>=-f,f+=s;f>0;i=256*i+e[t+d],d+=h,f-=8);for(a=i&(1<<-f)-1,i>>=-f,f+=r;f>0;a=256*a+e[t+d],d+=h,f-=8);if(0===i)i=1-c;else{if(i===l)return a?NaN:1/0*(p?-1:1);a+=Math.pow(2,r),i-=c}return(p?-1:1)*a*Math.pow(2,i-r)}function writeIEEE754(e,t,n,r,o,i){var a,u,s,l="big"===r,c=8*i-o-1,f=(1<<c)-1,d=f>>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=l?i-1:0,y=l?-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,a=f):(a=Math.floor(Math.log(t)/Math.LN2),t*(s=Math.pow(2,-a))<1&&(a--,s*=2),(t+=a+d>=1?h/s:h*Math.pow(2,1-d))*s>=2&&(a++,s/=2),a+d>=f?(u=0,a=f):a+d>=1?(u=(t*s-1)*Math.pow(2,o),a+=d):(u=t*Math.pow(2,d-1)*Math.pow(2,o),a=0)),isNaN(t)&&(u=0);o>=8;)e[n+p]=255&u,p+=y,u/=256,o-=8;for(a=a<<o|u,isNaN(t)&&(a+=8),c+=o;c>0;)e[n+p]=255&a,p+=y,a/=256,c-=8;e[n+p-y]|=128*g}var float_parser={readIEEE754:readIEEE754,writeIEEE754:writeIEEE754},Buffer$3=buffer__WEBPACK_IMPORTED_MODULE_1___default.a.Buffer,writeIEEE754$1=float_parser.writeIEEE754,normalizedFunctionString$1=utils.normalizedFunctionString,regexp$1=/\x00/,ignoreKeys=new Set(["$db","$ref","$id","$clusterTime"]),isDate=function(e){return"object"===_typeof(e)&&"[object Date]"===Object.prototype.toString.call(e)},isRegExp=function(e){return"[object RegExp]"===Object.prototype.toString.call(e)};function serializeString(e,t,n,r,o){e[r++]=constants.BSON_DATA_STRING,e[(r=r+(o?e.write(t,r,"ascii"):e.write(t,r,"utf8"))+1)-1]=0;var i=e.write(n,r+4,"utf8");return e[r+3]=i+1>>24&255,e[r+2]=i+1>>16&255,e[r+1]=i+1>>8&255,e[r]=i+1&255,r=r+4+i,e[r++]=0,r}function serializeNumber(e,t,n,r,o){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,r+=o?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;else if(n>=constants.JS_INT_MIN&&n<=constants.JS_INT_MAX){e[r++]=constants.BSON_DATA_NUMBER,r+=o?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0,writeIEEE754$1(e,n,r,"little",52,8),r+=8}else{e[r++]=constants.BSON_DATA_LONG,r+=o?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var i=long_1.fromNumber(n),a=i.getLowBits(),u=i.getHighBits();e[r++]=255&a,e[r++]=a>>8&255,e[r++]=a>>16&255,e[r++]=a>>24&255,e[r++]=255&u,e[r++]=u>>8&255,e[r++]=u>>16&255,e[r++]=u>>24&255}else e[r++]=constants.BSON_DATA_NUMBER,r+=o?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,o){return e[r++]=constants.BSON_DATA_NULL,r+=o?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0,r}function serializeBoolean(e,t,n,r,o){return e[r++]=constants.BSON_DATA_BOOLEAN,r+=o?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,o){e[r++]=constants.BSON_DATA_DATE,r+=o?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var i=long_1.fromNumber(n.getTime()),a=i.getLowBits(),u=i.getHighBits();return e[r++]=255&a,e[r++]=a>>8&255,e[r++]=a>>16&255,e[r++]=a>>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,o){if(e[r++]=constants.BSON_DATA_REGEXP,r+=o?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,o){if(e[r++]=constants.BSON_DATA_REGEXP,r+=o?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,o){return console.log({value:n,MinKey:min_key,isMinKey:n instanceof min_key}),e[r++]=null===n?constants.BSON_DATA_NULL:n instanceof min_key?constants.BSON_DATA_MIN_KEY:constants.BSON_DATA_MAX_KEY,r+=o?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0,r}function serializeObjectId(e,t,n,r,o){if(e[r++]=constants.BSON_DATA_OID,r+=o?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,o){e[r++]=constants.BSON_DATA_BINARY,r+=o?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var i=n.length;return e[r++]=255&i,e[r++]=i>>8&255,e[r++]=i>>16&255,e[r++]=i>>24&255,e[r++]=constants.BSON_BINARY_SUBTYPE_DEFAULT,n.copy(e,r,0,i),r+=i}function serializeObject(e,t,n,r,o,i,a,u,s,l){for(var c=0;c<l.length;c++)if(l[c]===n)throw new Error("cyclic dependency detected");l.push(n),e[r++]=Array.isArray(n)?constants.BSON_DATA_ARRAY:constants.BSON_DATA_OBJECT,r+=s?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var f=serializeInto(e,n,o,r,i+1,a,u,l);return l.pop(),f}function serializeDecimal128(e,t,n,r,o){return e[r++]=constants.BSON_DATA_DECIMAL128,r+=o?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,o){e[r++]="Long"===n._bsontype?constants.BSON_DATA_LONG:constants.BSON_DATA_TIMESTAMP,r+=o?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var i=n.getLowBits(),a=n.getHighBits();return e[r++]=255&i,e[r++]=i>>8&255,e[r++]=i>>16&255,e[r++]=i>>24&255,e[r++]=255&a,e[r++]=a>>8&255,e[r++]=a>>16&255,e[r++]=a>>24&255,r}function serializeInt32(e,t,n,r,o){return e[r++]=constants.BSON_DATA_INT,r+=o?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,o){return e[r++]=constants.BSON_DATA_NUMBER,r+=o?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,o,i,a){e[r++]=constants.BSON_DATA_CODE,r+=a?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var u=normalizedFunctionString$1(n),s=e.write(u,r+4,"utf8")+1;return e[r]=255&s,e[r+1]=s>>8&255,e[r+2]=s>>16&255,e[r+3]=s>>24&255,r=r+4+s-1,e[r++]=0,r}function serializeCode(e,t,n,r,o,i,a,u,s){if(n.scope&&"object"===_typeof(n.scope)){e[r++]=constants.BSON_DATA_CODE_W_SCOPE,r+=s?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var l=r,c="string"==typeof n.code?n.code:n.code.toString();r+=4;var f=e.write(c,r+4,"utf8")+1;e[r]=255&f,e[r+1]=f>>8&255,e[r+2]=f>>16&255,e[r+3]=f>>24&255,e[r+4+f-1]=0,r=r+f+4;var d=serializeInto(e,n.scope,o,r,i+1,a,u);r=d-1;var h=d-l;e[l++]=255&h,e[l++]=h>>8&255,e[l++]=h>>16&255,e[l++]=h>>24&255,e[r++]=0}else{e[r++]=constants.BSON_DATA_CODE,r+=s?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var p=n.code.toString(),y=e.write(p,r+4,"utf8")+1;e[r]=255&y,e[r+1]=y>>8&255,e[r+2]=y>>16&255,e[r+3]=y>>24&255,r=r+4+y-1,e[r++]=0}return r}function serializeBinary(e,t,n,r,o){e[r++]=constants.BSON_DATA_BINARY,r+=o?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var i=n.value(!0),a=n.position;return n.sub_type===binary.SUBTYPE_BYTE_ARRAY&&(a+=4),e[r++]=255&a,e[r++]=a>>8&255,e[r++]=a>>16&255,e[r++]=a>>24&255,e[r++]=n.sub_type,n.sub_type===binary.SUBTYPE_BYTE_ARRAY&&(a-=4,e[r++]=255&a,e[r++]=a>>8&255,e[r++]=a>>16&255,e[r++]=a>>24&255),i.copy(e,r,0,n.position),r+=n.position}function serializeSymbol(e,t,n,r,o){e[r++]=constants.BSON_DATA_SYMBOL,r+=o?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var i=e.write(n.value,r+4,"utf8")+1;return e[r]=255&i,e[r+1]=i>>8&255,e[r+2]=i>>16&255,e[r+3]=i>>24&255,r=r+4+i-1,e[r++]=0,r}function serializeDBRef(e,t,n,r,o,i,a){e[r++]=constants.BSON_DATA_OBJECT,r+=a?e.write(t,r,"ascii"):e.write(t,r,"utf8"),e[r++]=0;var u,s=r,l={$ref:n.collection,$id:n.oid};null!=n.db&&(l.$db=n.db);var c=(u=serializeInto(e,l=Object.assign(l,n.fields),!1,r,o+1,i))-s;return e[s++]=255&c,e[s++]=c>>8&255,e[s++]=c>>16&255,e[s++]=c>>24&255,u}function serializeInto(e,t,n,r,o,i,a,u){r=r||0,(u=u||[]).push(t);var s=r+4;if(Array.isArray(t))for(var l=0;l<t.length;l++){var c=""+l,f=t[l];if(f&&f.toBSON){if("function"!=typeof f.toBSON)throw new TypeError("toBSON is not a function");f=f.toBSON()}var d=_typeof(f);"string"===d?s=serializeString(e,c,f,s,!0):"number"===d?s=serializeNumber(e,c,f,s,!0):"boolean"===d?s=serializeBoolean(e,c,f,s,!0):f instanceof Date||isDate(f)?s=serializeDate(e,c,f,s,!0):void 0===f?s=serializeNull(e,c,f,s,!0):null===f?s=serializeNull(e,c,f,s,!0):"ObjectId"===f._bsontype?s=serializeObjectId(e,c,f,s,!0):Buffer$3.isBuffer(f)?s=serializeBuffer(e,c,f,s,!0):f instanceof RegExp||isRegExp(f)?s=serializeRegExp(e,c,f,s,