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 181 kB
!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(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=15)}([function(e,t,r){"use strict";function n(e,t){var r=t.serviceName,n=void 0===r?e.serviceName:r,i=t.action,o=t.args,u=e.client;if(!u)throw new Error("Service has no client");return u.executeServiceFunction(n,i,o)}function i(e){return encodeURIComponent(u.btoa(JSON.stringify(e)))}Object.defineProperty(t,"__esModule",{value:!0}),t.uriEncodeObject=t.serviceResponse=void 0;var o=r(12),u=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(o);t.serviceResponse=n,t.uriEncodeObject=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.USER_AUTH_KEY="_stitch_ua",t.REFRESH_TOKEN_KEY="_stitch_rt",t.DEVICE_ID_KEY="_stitch_did",t.STATE_KEY="_stitch_state",t.USER_AUTH_COOKIE_NAME="stitch_ua",t.STITCH_ERROR_KEY="_stitch_error",t.STITCH_LINK_KEY="_stitch_link",t.USER_LOGGED_IN_PT_KEY="_stitch_pt",t.STITCH_REDIRECT_PROVIDER="_stitch_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,r){"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 n=r(3),i=t.JSONTYPE="application/json",o=(t.APP_CLIENT_TYPE="app",t.ADMIN_CLIENT_TYPE="admin",t.DEFAULT_STITCH_SERVER_URL="https://stitch.mongodb.com","unknown");o="3.2.23";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 r=new n.StitchError(t.error,t.error_code);return r.response=e,r.json=t,Promise.reject(r)});var t=new Error(e.statusText);return t.response=e,Promise.reject(t)},t.makeFetchArgs=function(e,t,r){var n={method:e,headers:{Accept:i,"Content-Type":i}};return r&&r.credentials&&(n.credentials=r.credentials),t&&(n.body=t),n.cors=!0,n}},function(e,t,r){"use strict";function n(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 u=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)};u.prototype=Object.create(Error.prototype);var s=function(e){function t(){return n(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return o(t,e),t}(u);t.StitchError=s,t.ErrAuthProviderNotFound="AuthProviderNotFound",t.ErrInvalidSession="InvalidSession",t.ErrUnauthorized="Unauthorized"},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){var r,n,o,u,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},f=Object.create(e),l=d.DEFAULT_STITCH_SERVER_URL;s.baseUrl&&(l=s.baseUrl),f.clientAppID=t,f.authUrl=t?l+"/api/client/v2.0/app/"+t+"/auth":l+"/api/admin/v3.0/auth",f.rootURLsByAPIVersion=(u={},i(u,m,(r={},i(r,E,l+"/api/public/v1.0"),i(r,w,l+"/api/client/v1.0"),i(r,O,l+"/api/private/v1.0"),i(r,N,t?l+"/api/client/v1.0/app/"+t:l+"/api/public/v1.0"),r)),i(u,B,(n={},i(n,E,l+"/api/public/v2.0"),i(n,w,l+"/api/client/v2.0"),i(n,O,l+"/api/private/v2.0"),i(n,N,t?l+"/api/client/v2.0/app/"+t:l+"/api/public/v2.0"),n)),i(u,S,(o={},i(o,E,l+"/api/public/v3.0"),i(o,w,l+"/api/client/v3.0"),i(o,N,t?l+"/api/client/v3.0/app/"+t:l+"/api/admin/v3.0"),o)),u);var h={codec:c.APP_CLIENT_CODEC,storage:s.storage};return s.storageType&&(h.storageType=s.storageType),s.platform&&(h.platform=s.platform),s.authCodec&&(h.codec=s.authCodec),s.requestOrigin&&(h.requestOrigin=s.requestOrigin),a.AuthFactory.create(f,f.authUrl,h).then(function(e){return f.auth=e,Promise.all([f.auth.handleRedirect(),f.auth.handleCookie()])}).then(function(){return f})}Object.defineProperty(t,"__esModule",{value:!0}),t.StitchClient=t.StitchClientFactory=void 0;var s=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.newStitchClient=u,r(9);var a=r(13),f=r(7),c=r(1),l=r(19),h=n(l),p=r(2),d=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(p),g=r(5),_=n(g),y=r(36),b=n(y),v=r(3),m=1,B=2,S=3,E="public",O="private",w="client",N="app",A=(t.StitchClientFactory=function(){function e(){throw o(this,e),new v.StitchError("StitchClient can only be made from the StitchClientFactory.create function")}return s(e,null,[{key:"create",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return u(A.prototype,e,t)}}]),e}(),t.StitchClient=function(){function e(){o(this,e);var t=this.constructor.name;throw new v.StitchError(t+" can only be made from the "+t+"Factory.create function")}return s(e,[{key:"login",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return void 0===e||void 0===t?this.authenticate(f.PROVIDER_TYPE_ANON,r):this.authenticate("userpass",Object.assign({username:e,password:t},r))}},{key:"register",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.auth.provider("userpass").register(e,t,r)}},{key:"linkWithProvider",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!this.isAuthenticated())throw new v.StitchError("Must be authenticated to link an account");return this.auth.provider(e).authenticate(r,!0).then(function(){return t.authedId()})}},{key:"authenticate",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=function(){return t.auth.provider(e).authenticate(r).then(function(){return t.authedId()})};return this.isAuthenticated()?e===f.PROVIDER_TYPE_ANON&&this.auth.getLoggedInProviderType()===f.PROVIDER_TYPE_ANON?Promise.resolve(this.auth.authedId):this.logout().then(function(){return n()}):n()}},{key:"logout",value:function(){var e=this;return this._do("/auth/session","DELETE",{refreshOnFailure:!1,useRefreshToken:!0,rootURL:this.rootURLsByAPIVersion[B][w]}).then(function(){return e.auth.clear()},function(){return e.auth.clear()})}},{key:"authError",value:function(){return this.auth.error()}},{key:"userProfile",value:function(){return this._do("/auth/profile","GET",{rootURL:this.rootURLsByAPIVersion[B][w]}).then(function(e){return e.json()})}},{key:"isAuthenticated",value:function(){return!!this.authedId()}},{key:"authedId",value:function(){return this.auth.authedId}},{key:"service",value:function(t,r){if(this.constructor!==e)throw new v.StitchError("`service` is a factory method, do not use `new`");if(!h.default.hasOwnProperty(t))throw new v.StitchError("Invalid service type specified: "+t);return new(0,h.default[t])(this,r)}},{key:"executeFunction",value:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return this._doFunctionCall({name:e,arguments:r})}},{key:"executeServiceFunction",value:function(e,t){for(var r=arguments.length,n=Array(r>2?r-2:0),i=2;i<r;i++)n[i-2]=arguments[i];return this._doFunctionCall({service:e,name:t,arguments:n})}},{key:"_doFunctionCall",value:function(e){var t=function(e){return _.default.parse(e,{relaxed:!0})};return this._do("/functions/call","POST",{body:function(e){return _.default.stringify(e,{strict:!0})}(e)}).then(function(e){return e.text()}).then(function(e){return t(e)})}},{key:"doSessionPost",value:function(){return this._do("/auth/session","POST",{refreshOnFailure:!1,useRefreshToken:!0,rootURL:this.rootURLsByAPIVersion[B][w]}).then(function(e){return e.json()})}},{key:"getApiKeys",value:function(){return this._do("/auth/api_keys","GET",{rootURL:this.rootURLsByAPIVersion[B][w],useRefreshToken:!0}).then(function(e){return e.json()})}},{key:"createApiKey",value:function(e){return this._do("/auth/api_keys","POST",{rootURL:this.rootURLsByAPIVersion[B][w],useRefreshToken:!0,body:JSON.stringify({name:e})}).then(function(e){return e.json()})}},{key:"getApiKeyByID",value:function(e){return this._do("/auth/api_keys/"+e,"GET",{rootURL:this.rootURLsByAPIVersion[B][w],useRefreshToken:!0}).then(function(e){return e.json()})}},{key:"deleteApiKeyByID",value:function(e){return this._do("/auth/api_keys/"+e,"DELETE",{rootURL:this.rootURLsByAPIVersion[B][w],useRefreshToken:!0})}},{key:"enableApiKeyByID",value:function(e){return this._do("/auth/api_keys/"+e+"/enable","PUT",{rootURL:this.rootURLsByAPIVersion[B][w],useRefreshToken:!0})}},{key:"disableApiKeyByID",value:function(e){return this._do("/auth/api_keys/"+e+"/disable","PUT",{rootURL:this.rootURLsByAPIVersion[B][w],useRefreshToken:!0})}},{key:"_fetch",value:function(e,t,r,n,i){var o=this;return fetch(e,t).then(function(e){if(e.status>=200&&e.status<300)return Promise.resolve(e);if(e.headers.get("Content-Type")===d.JSONTYPE)return e.json().then(function(t){if("error_code"in t&&t.error_code===v.ErrInvalidSession)return i.refreshOnFailure?o.auth.refreshToken().then(function(){return i.refreshOnFailure=!1,o._do(r,n,i)}):o.auth.clear().then(function(){var r=new v.StitchError(t.error,t.error_code);throw r.response=e,r.json=t,r});var u=new v.StitchError(t.error,t.error_code);return u.response=e,u.json=t,Promise.reject(u)});var t=new Error(e.statusText);return t.response=e,Promise.reject(t)})}},{key:"_fetchArgs",value:function(e,t,r){var n=this.rootURLsByAPIVersion[r.apiVersion][r.apiType],i=""+n+e;r.rootURL&&(i=""+r.rootURL+e);var o=d.makeFetchArgs(t,r.body,r);return r.headers&&Object.assign(o.headers,r.headers),r.queryParams&&(i=i+"?"+b.default.stringify(r.queryParams)),r.multipart&&delete o.headers["Content-Type"],{url:i,fetchArgs:o}}},{key:"_do",value:function(e,t,r){r=Object.assign({},{refreshOnFailure:!0,useRefreshToken:!1,apiVersion:B,apiType:N,rootURL:void 0},r);var n=this._fetchArgs(e,t,r),i=n.url,o=n.fetchArgs;if(r.noAuth)return this._fetch(i,o,e,t,r);if(!this.isAuthenticated())return Promise.reject(new v.StitchError("Must auth first",v.ErrUnauthorized));this.auth.requestOrigin&&(o.headers["X-STITCH-Request-Origin"]=this.auth.requestOrigin);var u=r.useRefreshToken?this.auth.getRefreshToken():this.auth.getAccessToken();return o.headers.Authorization="Bearer "+u,this._fetch(i,o,e,t,r)}},{key:"type",get:function(){return d.APP_CLIENT_TYPE}}]),e}())},function(e,t,r){"use strict";(function(n){var i,o,u,s="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};!function(n,a){"object"===s(t)&&void 0!==e?e.exports=a(r(6)):(o=[r(6)],i=a,void 0!==(u="function"==typeof i?i.apply(t,o):i)&&(e.exports=u))}(0,function(e){function t(e){var t=Number(e).toString(16);return 1===t.length?"0"+t:t}function r(e){return{$binary:{base64:n.isBuffer(e.buffer)?e.buffer.toString("base64"):n.from(e.buffer).toString("base64"),subType:t(e.sub_type)}}}function i(e,t){var r=t.$binary.subType?parseInt(t.$binary.subType,16):0,i=new n(t.$binary.base64,"base64");return new e.Binary(i,r)}function o(e){return e.scope?{$code:e.code,$scope:e.scope}:{$code:e.code}}function u(e,t){return new e.Code(t.$code,t.$scope)}function a(e){var t={$ref:e.collection,$id:e.oid};return e.db&&(t.$db=e.db),t=Object.assign(t,e.fields)}function f(e,t){var r=Object.assign({},t);return["$ref","$id","$db"].forEach(function(e){return delete r[e]}),new e.DBRef(t.$ref,t.$id,t.$db,r)}function c(e){return{$numberDecimal:e.toString()}}function l(e,t){return new e.Decimal128.fromString(t.$numberDecimal)}function h(e,t){return t&&t.relaxed&&isFinite(e.value)?e.value:{$numberDouble:e.value.toString()}}function p(e,t,r){return r&&r.relaxed?parseFloat(t.$numberDouble):new e.Double(parseFloat(t.$numberDouble))}function d(e,t){return t&&t.relaxed?e.value:{$numberInt:e.value.toString()}}function g(e,t,r){return r&&r.relaxed?parseInt(t.$numberInt,10):new e.Int32(t.$numberInt)}function _(e,t){return t&&t.relaxed?e.toNumber():{$numberLong:e.toString()}}function y(e,t,r){var n=e.Long.fromString(t.$numberLong);return r&&r.relaxed?n.toNumber():n}function b(){return{$maxKey:1}}function v(e){return new e.MaxKey}function m(){return{$minKey:1}}function B(e){return new e.MinKey}function S(e){return e.toHexString?{$oid:e.toHexString()}:{$oid:e.toString("hex")}}function E(e,t){return new e.ObjectID(t.$oid)}function O(e){return{$regularExpression:{pattern:e.pattern,options:e.options}}}function w(e,t){return new e.BSONRegExp(t.$regularExpression.pattern,t.$regularExpression.options.split("").sort().join(""))}function N(e){return{$symbol:e.value}}function A(e,t){return new e.Symbol(t.$symbol)}function T(e){return{$timestamp:{t:e.high_,i:e.low_}}}function I(e,t){return new e.Timestamp(t.$timestamp.i,t.$timestamp.t)}function R(e){Z.forEach(function(t){if(!e[t])throw new Error("passed in module does not contain all BSON types required")}),q=e}function D(e,t,r,n){if("number"==typeof r){if(Math.floor(r)===r){var i=r>=re&&r<=te,o=r>=ie&&r<=ne;if(i)return n.strict?new q.Int32(r):r;if(o)return n.strict?new q.Long.fromNumber(r):r}return new q.Double(r)}if(null==r||"object"!==(void 0===r?"undefined":G(r)))return r;if(r.$undefined)return null;for(var u=Object.keys(r).filter(function(e){return e.startsWith("$")&&null!=r[e]}),s=0;s<u.length;s++){var a=Q[u[s]];if(a)return a.fromExtendedJSON(q,r,n)}if(null!=r.$date){var f=r.$date,c=new Date;return"string"==typeof f?c.setTime(Date.parse(f)):f instanceof q.Long?c.setTime(f.toNumber()):"number"==typeof f&&n.relaxed&&c.setTime(f),c}if(null!=r.$code){if(r.$scope)var l=D(e,null,r.$scope);return Object.assign({},r).$scope=l,H.Code.fromExtendedJSON(q,r)}if(null!=r.$ref||null!=r.$dbPointer){var h=r.$ref?r:r.$dbPointer;if(h instanceof q.DBRef)return h;var p=Object.keys(h).filter(function(e){return e.startsWith("$")}),d=!0;if(p.forEach(function(e){-1===["$ref","$id","$db"].indexOf(e)&&(d=!1)}),d)return H.DBRef.fromExtendedJSON(q,h)}return r}function P(e,t){return e.map(function(e){return $(e,t)})}function L(e){var t=e.toISOString();return 0!==e.getUTCMilliseconds()?t:t.slice(0,-5)+"Z"}function $(e,t){if(Array.isArray(e))return P(e,t);if(void 0===e)return null;if(e instanceof Date){var r=e.getTime(),n=r>-1&&r<2534023188e5;return t.relaxed&&n?{$date:L(e)}:{$date:{$numberLong:e.getTime().toString()}}}if("number"==typeof e&&!t.relaxed){if(Math.floor(e)===e){var i=e>=re&&e<=te,o=e>=ie&&e<=ne;if(i)return{$numberInt:e.toString()};if(o)return{$numberLong:e.toString()}}return{$numberDouble:e.toString()}}return null!=e&&"object"===(void 0===e?"undefined":G(e))?k(e,t):e}function k(e,t){if(null==e||"object"!==(void 0===e?"undefined":G(e)))throw new Error("not an object instance");if(e._bsontype&&-1!==Z.indexOf(e._bsontype)){if("Code"===e._bsontype&&e.scope){var r=k(e.scope,t),n=Object.assign({},e,{scope:r});return H.Code.toExtendedJSON(n,t)}if("DBRef"===e._bsontype&&e.oid){var i=k(e.oid,t),o=Object.assign({},e,{oid:i});return H.DBRef.toExtendedJSON(o,t)}return H[e._bsontype].toExtendedJSON(e,t)}var u={};for(var s in e){var a=e[s];if(Array.isArray(a))u[s]=P(a,t);else if(null!=a&&a._bsontype&&-1!==Z.indexOf(a._bsontype))if("Code"===a._bsontype&&a.scope){var f=k(a.scope,t),c=Object.assign({},a,{scope:f});u[s]=H.Code.toExtendedJSON(c,t)}else if("DBRef"===a._bsontype&&a.oid){var l=k(a.oid,t),h=Object.assign({},a,{oid:l});u[s]=H.DBRef.toExtendedJSON(h,t)}else u[s]=H[a._bsontype].toExtendedJSON(a,t);else a instanceof Date?u[s]=$(a,t):null!=a&&"object"===(void 0===a?"undefined":G(a))&&(u[s]=k(a,t));if(u[s]=$(a,t),a instanceof RegExp){var p=a.flags;void 0===p&&(p=a.toString().match(/[gimuy]*$/)[0]),u[s]=H.BSONRegExp.toExtendedJSON({pattern:a.source,options:p})}}return u}e=e&&e.hasOwnProperty("default")?e.default:e;var U={toExtendedJSON:r,fromExtendedJSON:i},x={toExtendedJSON:o,fromExtendedJSON:u},M={toExtendedJSON:a,fromExtendedJSON:f},j={toExtendedJSON:c,fromExtendedJSON:l},C={toExtendedJSON:h,fromExtendedJSON:p},Y={toExtendedJSON:d,fromExtendedJSON:g},F={toExtendedJSON:_,fromExtendedJSON:y},z={toExtendedJSON:b,fromExtendedJSON:v},K={toExtendedJSON:m,fromExtendedJSON:B},W={toExtendedJSON:S,fromExtendedJSON:E},J={toExtendedJSON:O,fromExtendedJSON:w},V={toExtendedJSON:N,fromExtendedJSON:A},X={toExtendedJSON:T,fromExtendedJSON:I},H={Binary:U,Code:x,DBRef:M,Decimal128:j,Double:C,Int32:Y,Long:F,MaxKey:z,MinKey:K,ObjectID:W,BSONRegExp:J,Symbol:V,Timestamp:X},G="function"==typeof Symbol&&"symbol"===s(Symbol.iterator)?function(e){return void 0===e?"undefined":s(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":s(e)},q=e,Z=["Binary","Code","DBRef","Decimal128","Double","Int32","Long","MaxKey","MinKey","ObjectID","BSONRegExp","Symbol","Timestamp"];R(q);var Q={$oid:H.ObjectID,$binary:H.Binary,$symbol:H.Symbol,$numberInt:H.Int32,$numberDecimal:H.Decimal128,$numberDouble:H.Double,$numberLong:H.Long,$minKey:H.MinKey,$maxKey:H.MaxKey,$regularExpression:H.BSONRegExp,$timestamp:H.Timestamp},ee=function(e,t){var r=this;return t=t||{relaxed:!1},"boolean"==typeof t.relaxed&&(t.strict=!t.relaxed),"boolean"==typeof t.strict&&(t.relaxed=!t.strict),JSON.parse(e,function(e,n){return D(r,e,n,t)})},te=2147483647,re=-2147483648,ne=0x8000000000000000,ie=-0x8000000000000000;return{parse:ee,stringify:function(e,t,r,n){var i={};null!=n&&"object"===(void 0===n?"undefined":G(n))?i=n:null!=r&&"object"===(void 0===r?"undefined":G(r))?(i=r,r=0):null!=t&&"object"===(void 0===t?"undefined":G(t))&&(i=t,t=null);var o=Array.isArray(e)?P(e,i):k(e,i);return JSON.stringify(o,t,r)},setBSONModule:R,BSON:q}})}).call(t,r(8).Buffer)},function(module,exports,__webpack_require__){"use strict";(function(global,Buffer,process){var __WEBPACK_AMD_DEFINE_FACTORY__,__WEBPACK_AMD_DEFINE_RESULT__,_typeof2="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};!function(e,t){"object"===_typeof2(exports)&&void 0!==module?module.exports=t():(__WEBPACK_AMD_DEFINE_FACTORY__=t,void 0!==(__WEBPACK_AMD_DEFINE_RESULT__="function"==typeof __WEBPACK_AMD_DEFINE_FACTORY__?__WEBPACK_AMD_DEFINE_FACTORY__.call(exports,__webpack_require__,exports,module):__WEBPACK_AMD_DEFINE_FACTORY__)&&(module.exports=__WEBPACK_AMD_DEFINE_RESULT__))}(0,function(){function createCommonjsModule(e,t){return t={exports:{}},e(t,t.exports),t.exports}function Long(e,t){if(!(this instanceof Long))return new Long(e,t);this._bsontype="Long",this.low_=0|e,this.high_=0|t}function Double(e){if(!(this instanceof Double))return new Double(e);this._bsontype="Double",this.value=e}function Timestamp(e,t){e instanceof long_1?long_1.call(this,e.low_,e.high_):long_1.call(this,e,t),this._bsontype="Timestamp"}function endianness(){if(void 0===_endianness){var e=new ArrayBuffer(2),t=new Uint8Array(e),r=new Uint16Array(e);if(t[0]=1,t[1]=2,258===r[0])_endianness="BE";else{if(513!==r[0])throw new Error("unable to figure out endianess");_endianness="LE"}}return _endianness}function hostname(){return void 0!==global.location?global.location.hostname:""}function loadavg(){return[]}function uptime(){return 0}function freemem(){return Number.MAX_VALUE}function totalmem(){return Number.MAX_VALUE}function cpus(){return[]}function type(){return"Browser"}function release(){return void 0!==global.navigator?global.navigator.appVersion:""}function networkInterfaces(){}function getNetworkInterfaces(){}function arch(){return"javascript"}function platform(){return"browser"}function tmpDir(){return"/tmp"}function fnv1a32(e,t){t=t||"utf8";for(var r=Buffer.from(e,t),n=OFFSET_BASIS,i=0;i<r.length;i+=1)n=n.xor(new long_1(r[i],0)),n=n.multiply(FNV_PRIME),n=n.and(FNV_MASK);return n.getLowBitsUnsigned()}function fnv1a24(e,t){var r=fnv1a32(e,t);return(r&MASK_24^r>>>24&MASK_8)&MASK_24}function ObjectID(e){if(e instanceof ObjectID)return e;if(!(this instanceof ObjectID))return new ObjectID(e);if(this._bsontype="ObjectID",null==e||"number"==typeof e)return this.id=this.generate(e),void(ObjectID.cacheHexString&&(this.__id=this.toString("hex")));var t=ObjectID.isValid(e);if(!t&&null!=e)throw new TypeError("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");if(t&&"string"==typeof e&&24===e.length&&hasBufferType)return new ObjectID(new Buffer(e,"hex"));if(t&&"string"==typeof e&&24===e.length)return ObjectID.createFromHexString(e);if(null==e||12!==e.length){if(null!=e&&e.toHexString)return e;throw new TypeError("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters")}this.id=e,ObjectID.cacheHexString&&(this.__id=this.toString("hex"))}function alphabetize(e){return e.split("").sort().join("")}function BSONRegExp(e,t){if(!(this instanceof BSONRegExp))return new BSONRegExp(e,t);this._bsontype="BSONRegExp",this.pattern=e||"",this.options=t?alphabetize(t):"";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 options ["+this.options[r]+"] is not supported")}function _Symbol(e){if(!(this instanceof _Symbol))return new _Symbol(e);this._bsontype="Symbol",this.value=e}function Int32(e){if(!(this instanceof Int32))return new Int32(e);this._bsontype="Int32",this.value=e}function Code(e,t){if(!(this instanceof Code))return new Code(e,t);this._bsontype="Code",this.code=e,this.scope=t}function Decimal128(e){this._bsontype="Decimal128",this.bytes=e}function MinKey(){if(!(this instanceof MinKey))return new MinKey;this._bsontype="MinKey"}function MaxKey(){if(!(this instanceof MaxKey))return new MaxKey;this._bsontype="MaxKey"}function DBRef(e,t,r,n){if(!(this instanceof DBRef))return new DBRef(e,t,r,n);var i=e.split(".");2===i.length&&(r=i.shift(),e=i.shift()),this._bsontype="DBRef",this.collection=e,this.oid=t,this.db=r,this.fields=n||{}}function init(){inited=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,r=e.length;t<r;++t)lookup[t]=e[t],revLookup[e.charCodeAt(t)]=t;revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63}function toByteArray(e){inited||init();var t,r,n,i,o,u,s=e.length;if(s%4>0)throw new Error("Invalid string. Length must be a multiple of 4");o="="===e[s-2]?2:"="===e[s-1]?1:0,u=new Arr(3*s/4-o),n=o>0?s-4:s;var a=0;for(t=0,r=0;t<n;t+=4,r+=3)i=revLookup[e.charCodeAt(t)]<<18|revLookup[e.charCodeAt(t+1)]<<12|revLookup[e.charCodeAt(t+2)]<<6|revLookup[e.charCodeAt(t+3)],u[a++]=i>>16&255,u[a++]=i>>8&255,u[a++]=255&i;return 2===o?(i=revLookup[e.charCodeAt(t)]<<2|revLookup[e.charCodeAt(t+1)]>>4,u[a++]=255&i):1===o&&(i=revLookup[e.charCodeAt(t)]<<10|revLookup[e.charCodeAt(t+1)]<<4|revLookup[e.charCodeAt(t+2)]>>2,u[a++]=i>>8&255,u[a++]=255&i),u}function tripletToBase64(e){return lookup[e>>18&63]+lookup[e>>12&63]+lookup[e>>6&63]+lookup[63&e]}function encodeChunk(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16)+(e[o+1]<<8)+e[o+2],i.push(tripletToBase64(n));return i.join("")}function fromByteArray(e){inited||init();for(var t,r=e.length,n=r%3,i="",o=[],u=0,s=r-n;u<s;u+=16383)o.push(encodeChunk(e,u,u+16383>s?s:u+16383));return 1===n?(t=e[r-1],i+=lookup[t>>2],i+=lookup[t<<4&63],i+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],i+=lookup[t>>10],i+=lookup[t>>4&63],i+=lookup[t<<2&63],i+="="),o.push(i),o.join("")}function read(e,t,r,n,i){var o,u,s=8*i-n-1,a=(1<<s)-1,f=a>>1,c=-7,l=r?i-1:0,h=r?-1:1,p=e[t+l];for(l+=h,o=p&(1<<-c)-1,p>>=-c,c+=s;c>0;o=256*o+e[t+l],l+=h,c-=8);for(u=o&(1<<-c)-1,o>>=-c,c+=n;c>0;u=256*u+e[t+l],l+=h,c-=8);if(0===o)o=1-f;else{if(o===a)return u?NaN:1/0*(p?-1:1);u+=Math.pow(2,n),o-=f}return(p?-1:1)*u*Math.pow(2,o-n)}function write(e,t,r,n,i,o){var u,s,a,f=8*o-i-1,c=(1<<f)-1,l=c>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,u=c):(u=Math.floor(Math.log(t)/Math.LN2),t*(a=Math.pow(2,-u))<1&&(u--,a*=2),t+=u+l>=1?h/a:h*Math.pow(2,1-l),t*a>=2&&(u++,a/=2),u+l>=c?(s=0,u=c):u+l>=1?(s=(t*a-1)*Math.pow(2,i),u+=l):(s=t*Math.pow(2,l-1)*Math.pow(2,i),u=0));i>=8;e[r+p]=255&s,p+=d,s/=256,i-=8);for(u=u<<i|s,f+=i;f>0;e[r+p]=255&u,p+=d,u/=256,f-=8);e[r+p-d]|=128*g}function kMaxLength(){return Buffer$1.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function createBuffer(e,t){if(kMaxLength()<t)throw new RangeError("Invalid typed array length");return Buffer$1.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t),e.__proto__=Buffer$1.prototype):(null===e&&(e=new Buffer$1(t)),e.length=t),e}function Buffer$1(e,t,r){if(!(Buffer$1.TYPED_ARRAY_SUPPORT||this instanceof Buffer$1))return new Buffer$1(e,t,r);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return allocUnsafe(this,e)}return from(this,e,t,r)}function from(e,t,r,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?fromArrayBuffer(e,t,r,n):"string"==typeof t?fromString(e,t,r):fromObject(e,t)}function assertSize(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function alloc(e,t,r,n){return assertSize(t),t<=0?createBuffer(e,t):void 0!==r?"string"==typeof n?createBuffer(e,t).fill(r,n):createBuffer(e,t).fill(r):createBuffer(e,t)}function allocUnsafe(e,t){if(assertSize(t),e=createBuffer(e,t<0?0:0|checked(t)),!Buffer$1.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function fromString(e,t,r){if("string"==typeof r&&""!==r||(r="utf8"),!Buffer$1.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|byteLength(t,r);e=createBuffer(e,n);var i=e.write(t,r);return i!==n&&(e=e.slice(0,i)),e}function fromArrayLike(e,t){var r=t.length<0?0:0|checked(t.length);e=createBuffer(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function fromArrayBuffer(e,t,r,n){if(t.byteLength,r<0||t.byteLength<r)throw new RangeError("'offset' is out of bounds");if(t.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");return t=void 0===r&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,r):new Uint8Array(t,r,n),Buffer$1.TYPED_ARRAY_SUPPORT?(e=t,e.__proto__=Buffer$1.prototype):e=fromArrayLike(e,t),e}function fromObject(e,t){if(internalIsBuffer(t)){var r=0|checked(t.length);return e=createBuffer(e,r),0===e.length?e:(t.copy(e,0,0,r),e)}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||isnan(t.length)?createBuffer(e,0):fromArrayLike(e,t);if("Buffer"===t.type&&isArray(t.data))return fromArrayLike(e,t.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function checked(e){if(e>=kMaxLength())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+kMaxLength().toString(16)+" bytes");return 0|e}function SlowBuffer(e){return+e!=e&&(e=0),Buffer$1.alloc(+e)}function internalIsBuffer(e){return!(null==e||!e._isBuffer)}function byteLength(e,t){if(internalIsBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return utf8ToBytes(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return base64ToBytes(e).length;default:if(n)return utf8ToBytes(e).length;t=(""+t).toLowerCase(),n=!0}}function slowToString(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if(r>>>=0,t>>>=0,r<=t)return"";for(e||(e="utf8");;)switch(e){case"hex":return hexSlice(this,t,r);case"utf8":case"utf-8":return utf8Slice(this,t,r);case"ascii":return asciiSlice(this,t,r);case"latin1":case"binary":return latin1Slice(this,t,r);case"base64":return base64Slice(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function swap(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function bidirectionalIndexOf(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=Buffer$1.from(t,n)),internalIsBuffer(t))return 0===t.length?-1:arrayIndexOf(e,t,r,n,i);if("number"==typeof t)return t&=255,Buffer$1.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):arrayIndexOf(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function arrayIndexOf(e,t,r,n,i){function o(e,t){return 1===u?e[t]:e.readUInt16BE(t*u)}var u=1,s=e.length,a=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;u=2,s/=2,a/=2,r/=2}var f;if(i){var c=-1;for(f=r;f<s;f++)if(o(e,f)===o(t,-1===c?0:f-c)){if(-1===c&&(c=f),f-c+1===a)return c*u}else-1!==c&&(f-=f-c),c=-1}else for(r+a>s&&(r=s-a),f=r;f>=0;f--){for(var l=!0,h=0;h<a;h++)if(o(e,f+h)!==o(t,h)){l=!1;break}if(l)return f}return-1}function hexWrite(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var u=0;u<n;++u){var s=parseInt(t.substr(2*u,2),16);if(isNaN(s))return u;e[r+u]=s}return u}function utf8Write(e,t,r,n){return blitBuffer(utf8ToBytes(t,e.length-r),e,r,n)}function asciiWrite(e,t,r,n){return blitBuffer(asciiToBytes(t),e,r,n)}function latin1Write(e,t,r,n){return asciiWrite(e,t,r,n)}function base64Write(e,t,r,n){return blitBuffer(base64ToBytes(t),e,r,n)}function ucs2Write(e,t,r,n){return blitBuffer(utf16leToBytes(t,e.length-r),e,r,n)}function base64Slice(e,t,r){return fromByteArray(0===t&&r===e.length?e:e.slice(t,r))}function utf8Slice(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var o=e[i],u=null,s=o>239?4:o>223?3:o>191?2:1;if(i+s<=r){var a,f,c,l;switch(s){case 1:o<128&&(u=o);break;case 2:a=e[i+1],128==(192&a)&&(l=(31&o)<<6|63&a)>127&&(u=l);break;case 3:a=e[i+1],f=e[i+2],128==(192&a)&&128==(192&f)&&(l=(15&o)<<12|(63&a)<<6|63&f)>2047&&(l<55296||l>57343)&&(u=l);break;case 4:a=e[i+1],f=e[i+2],c=e[i+3],128==(192&a)&&128==(192&f)&&128==(192&c)&&(l=(15&o)<<18|(63&a)<<12|(63&f)<<6|63&c)>65535&&l<1114112&&(u=l)}}null===u?(u=65533,s=1):u>65535&&(u-=65536,n.push(u>>>10&1023|55296),u=56320|1023&u),n.push(u),i+=s}return decodeCodePointsArray(n)}function decodeCodePointsArray(e){var t=e.length;if(t<=MAX_ARGUMENTS_LENGTH)return String.fromCharCode.apply(String,e);for(var r="",n=0;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=MAX_ARGUMENTS_LENGTH));return r}function asciiSlice(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function latin1Slice(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function hexSlice(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=t;o<r;++o)i+=toHex(e[o]);return i}function utf16leSlice(e,t,r){for(var n=e.slice(t,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function checkOffset(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function checkInt(e,t,r,n,i,o){if(!internalIsBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function objectWriteUInt16(e,t,r,n){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-r,2);i<o;++i)e[r+i]=(t&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function objectWriteUInt32(e,t,r,n){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-r,4);i<o;++i)e[r+i]=t>>>8*(n?i:3-i)&255}function checkIEEE754(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function writeFloat(e,t,r,n,i){return i||checkIEEE754(e,t,r,4,3.4028234663852886e38,-3.4028234663852886e38),write(e,t,r,n,23,4),r+4}function writeDouble(e,t,r,n,i){return i||checkIEEE754(e,t,r,8,1.7976931348623157e308,-1.7976931348623157e308),write(e,t,r,n,52,8),r+8}function base64clean(e){if(e=stringtrim(e).replace(INVALID_BASE64_RE,""),e.length<2)return"";for(;e.length%4!=0;)e+="=";return e}function stringtrim(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function toHex(e){return e<16?"0"+e.toString(16):e.toString(16)}function utf8ToBytes(e,t){t=t||1/0;for(var r,n=e.length,i=null,o=[],u=0;u<n;++u){if((r=e.charCodeAt(u))>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(u+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function asciiToBytes(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}function utf16leToBytes(e,t){for(var r,n,i,o=[],u=0;u<e.length&&!((t-=2)<0);++u)r=e.charCodeAt(u),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function base64ToBytes(e){return toByteArray(base64clean(e))}function blitBuffer(e,t,r,n){for(var i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function isnan(e){return e!==e}function isBuffer(e){return null!=e&&(!!e._isBuffer||isFastBuffer(e)||isSlowBuffer(e))}function isFastBuffer(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function isSlowBuffer(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&isFastBuffer(e.slice(0,0))}function Binary(e,t){if(!(this instanceof Binary))return new Binary(e,t);if(!(null==e||"string"==typeof e||Buffer$2.isBuffer(e)||e instanceof Uint8Array||Array.isArray(e)))throw new Error("only String, Buffer, Uint8Array or Array accepted");if(this._bsontype="Binary",e instanceof Number?(this.sub_type=e,this.position=0):(this.sub_type=null==t?BSON_BINARY_SUBTYPE_DEFAULT:t,this.position=0),null==e||e instanceof Number)void 0!==Buffer$2?this.buffer=new Buffer$2(Binary.BUFFER_SIZE):"undefined"!=typeof Uint8Array?this.buffer=new Uint8Array(new ArrayBuffer(Binary.BUFFER_SIZE)):this.buffer=new Array(Binary.BUFFER_SIZE),this.position=0;else{if("string"==typeof e)if(void 0!==Buffer$2)this.buffer=new Buffer$2(e);else{if("undefined"==typeof Uint8Array&&"[object Array]"!==Object.prototype.toString.call(e))throw new TypeError("only String, Buffer, Uint8Array or Array accepted");this.buffer=writeStringToArray(e)}else this.buffer=e;this.position=e.length}}function normalizedFunctionString(e){return e.toString().replace("function(","function (")}function calculateElement(e,t,r,n,i){switch(t&&t.toBSON&&(t=t.toBSON()),void 0===t?"undefined":_typeof(t)){case"string":return 1+Buffer.byteLength(e,"utf8")+1+4+Buffer.byteLength(t,"utf8")+1;case"number":return Math.floor(t)===t&&t>=BSON$2.JS_INT_MIN&&t<=BSON$2.JS_INT_MAX&&t>=BSON$2.BSON_INT32_MIN&&t<=BSON$2.BSON_INT32_MAX?(null!=e?Buffer.byteLength(e,"utf8")+1:0)+5:(null!=e?Buffer.byteLength(e,"utf8")+1:0)+9;case"undefined":return n||!i?(null!=e?Buffer.byteLength(e,"utf8")+1:0)+1:0;case"boolean":return(null!=e?Buffer.byteLength(e,"utf8")+1:0)+2;case"object":if(null==t||t instanceof MinKey$3||t instanceof MaxKey$2||"MinKey"===t._bsontype||"MaxKey"===t._bsontype)return(null!=e?Buffer.byteLength(e,"utf8")+1:0)+1;if(t instanceof ObjectID$2||"ObjectID"===t._bsontype)return(null!=e?Buffer.byteLength(e,"utf8")+1:0)+13;if(t instanceof Date||isDate$1(t))return(null!=e?Buffer.byteLength(e,"utf8")+1:0)+9;if(void 0!==Buffer&&Buffer.isBuffer(t))return(null!=e?Buffer.byteLength(e,"utf8")+1:0)+6+t.length;if(t instanceof Long$3||t instanceof Double$2||t instanceof Timestamp$2||"Long"===t._bsontype||"Double"===t._bsontype||"Timestamp"===t._bsontype)return(null!=e?Buffer.byteLength(e,"utf8")+1:0)+9;if(t instanceof decimal128||"Decimal128"===t._bsontype)return(null!=e?Buffer.byteLength(e,"utf8")+1:0)+17;if(t instanceof Code$2||"Code"===t._bsontype)return null!=t.scope&&Object.keys(t.scope).length>0?(null!=e?Buffer.byteLength(e,"utf8")+1:0)+1+4+4+Buffer.byteLength(t.code.toString(),"utf8")+1+calculateObjectSize(t.scope,r,i):(null!=e?Buffer.byteLength(e,"utf8")+1:0)+1+4+Buffer.byteLength(t.code.toString(),"utf8")+1;if(t instanceof Binary$3||"Binary"===t._bsontype)return t.sub_type===Binary$3.SUBTYPE_BYTE_ARRAY?(null!=e?Buffer.byteLength(e,"utf8")+1:0)+(t.position+1+4+1+4):(null!=e?Buffer.byteLength(e,"utf8")+1:0)+(t.position+1+4+1);if(t instanceof _Symbol$1||"Symbol"===t._bsontype)return(null!=e?Buffer.byteLength(e,"utf8")+1:0)+Buffer.byteLength(t.value,"utf8")+4+1+1;if(t instanceof DBRef$2||"DBRef"===t._bsontype){var o={$ref:t.collection,$id:t.oid};return null!=t.db&&(o.$db=t.db),o=Object.assign(o,t.fields),(null!=e?Buffer.byteLength(e,"utf8")+1:0)+1+calculateObjectSize(o,r,i)}return t instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(t)?(null!=e?Buffer.byteLength(e,"utf8")+1:0)+1+Buffer.byteLength(t.source,"utf8")+1+(t.global?1:0)+(t.ignoreCase?1:0)+(t.multiline?1:0)+1:t instanceof BSONRegExp$2||"BSONRegExp"===t._bsontype?(null!=e?Buffer.byteLength(e,"utf8")+1:0)+1+Buffer.byteLength(t.pattern,"utf8")+1+Buffer.byteLength(t.options,"utf8")+1:(null!=e?Buffer.byteLength(e,"utf8")+1:0)+calculateObjectSize(t,r,i)+1;case"function":if(t instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(t)||"[object RegExp]"===String.call(t))return(null!=e?Buffer.byteLength(e,"utf8")+1:0)+1+Buffer.byteLength(t.source,"utf8")+1+(t.global?1:0)+(t.ignoreCase?1:0)+(t.multiline?1:0)+1;if(r&&null!=t.scope&&Object.keys(t.scope).length>0)return(null!=e?Buffer.byteLength(e,"utf8")+1:0)+1+4+4+Buffer.byteLength(normalizedFunctionString$2(t),"utf8")+1+calculateObjectSize(t.scope,r,i);if(r)return(null!=e?Buffer.byteLength(e,"utf8")+1:0)+1+4+Buffer.byteLength(normalizedFunctionString$2(t),"utf8")+1}return 0}var commonjsGlobal="undefined"!=typeof window?window:void 0!==global?global:"undefined"!=typeof self?self:{},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 r=e[t],n=r[0],i=r[1];this._keys.push(n),this._values[n]={v:i,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 r=e._keys[t++];return{value:void 0!==r?[r,e._values[r].v]:void 0,done:void 0===r}}}},t.prototype.forEach=function(e,t){t=t||this;for(var r=0;r<this._keys.length;r++){var n=this._keys[r];e.call(t,this._values[n].v,n,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 r=e._keys[t++];return{value:void 0!==r?r:void 0,done:void 0===r}}}},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 r=e._keys[t++];return{value:void 0!==r?e._values[r].v:void 0,done:void 0===r}}}},Object.defineProperty(t.prototype,"size",{enumerable:!0,get:function(){return this._keys.length}}),e.exports=t,e.exports.Map=t}}),map_1=map.Map;Long.prototype.toInt=function(){return this.low_},Long.prototype.toNumber=function(){return this.high_*Long.TWO_PWR_32_DBL_+this.getLowBitsUnsigned()},Long.prototype.toJSON=function(){return this.toString()},Long.prototype.toString=function(e){var t=e||10;if(t<2||36<t)throw Error("radix out of range: "+t);if(this.isZero())return"0";if(this.isNegative()){if(this.equals(Long.MIN_VALUE)){var r=Long.fromNumber(t),n=this.div(r),i=n.multiply(r).subtract(this);return n.toString(t)+i.toInt().toString(t)}return"-"+this.negate().toString(t)}var o=Long.fromNumber(Math.pow(t,6));i=this;for(var u="";!i.isZero();){var s=i.div(o),a=i.subtract(s.multiply(o)).toInt(),f=a.toString(t);if(i=s,i.isZero())return f+u;for(;f.length<6;)f="0"+f;u=""+f+u}},Long.prototype.getHighBits=function(){return this.high_},Long.prototype.getLowBits=function(){return this.low_},Long.prototype.getLowBitsUnsigned=function(){return this.low_>=0?this.low_:Long.TWO_PWR_32_DBL_+this.low_},Long.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.equals(Long.MIN_VALUE)?64:this.negate().getNumBitsAbs();for(var e=0!==this.high_?this.high_:this.low_,t=31;t>0&&0==(e&1<<t);t--);return 0!==this.high_?t+33:t+1},Long.prototype.isZero=function(){return 0===this.high_&&0===this.low_},Long.prototype.isNegative=function(){return this.high_<0},Long.prototype.isOdd=function(){return 1==(1&this.low_)},Long.prototype.equals=function(e){return this.high_===e.high_&&this.low_===e.low_},Long.prototype.notEquals=function(e){return this.high_!==e.high_||this.low_!==e.low_},Long.prototype.lessThan=function(e){return this.compare(e)<0},Long.prototype.lessThanOrEqual=function(e){return this.compare(e)<=0},Long.prototype.greaterThan=function(e){return this.compare(e)>0},Long.prototype.greaterThanOrEqual=function(e){return this.compare(e)>=0},Long.prototype.compare=function(e){if(this.equals(e))return 0;var t=this.isNegative(),r=e.isNegative();return t&&!r?-1:!t&&r?1:this.subtract(e).isNegative()?-1:1},Long.prototype.negate=function(){return this.equals(Long.MIN_VALUE)?Long.MIN_VALUE:this.not().add(Long.ONE)},Long.prototype.add=function(e){var t=this.high_>>>16,r=65535&this.high_,n=this.low_>>>16,i=65535&this.low_,o=e.high_>>>16,u=65535&e.high_,s=e.low_>>>16,a=65535&e.low_,f=0,c=0,l=0,h=0;return h+=i+a,l+=h>>>16,h&=65535,l+=n+s,c+=l>>>16,l&=65535,c+=r+u,f+=c>>>16,c&=65535,f+=t+o,f&=65535,Long.fromBits(l<<16|h,f<<16|c)},Long.prototype.subtract=function(e){return this.add(e.negate())},Long.prototype.multiply=function(e){if(this.isZero())return Long.ZERO;if(e.isZero())return Long.ZERO;if(this.equals(Long.MIN_VALUE))return e.isOdd()?Long.MIN_VALUE:Long.ZERO;if(e.equals(Long.MIN_VALUE))return this.isOdd()?Long.MIN_VALUE:Long.ZERO;if(this.isNegative())return e.isNegative()?this.negate().multiply(e.negate()):this.negate().multiply(e).negate();if(e.isNegative())return this.multiply(e.negate()).negate();if(this.lessThan(Long.TWO_PWR_24_)&&e.lessThan(Long.TWO_PWR_24_))return Long.fromNumber(this.toNumber()*e.toNumber());var t=this.high_>>>16,r=65535&this.high_,n=this.low_>>>16,i=65535&this.low_,o=e.high_>>>16,u=65535&e.high_,s=e.low_>>>16,a=65535&e.low_,f=0,c=0,l=0,h=0;return h+=i*a,l+=h>>>16,h&=65535,l+=n*a,c+=l>>>16,l&=65535,l+=i*s,c+=l>>>16,l&=65535,c+=r*a,f+=c>>>16,c&=65535,c+=n*s,f+=c>>>16,c&=65535,c+=i*u,f+=c>>>16,c&=65535,f+=t*a+r*s+n*u+i*o,f&=65535,Long.fromBits(l<<16|h,f<<16|c)},Long.prototype.div=function(e){if(e.isZero())throw Error("division by zero");if(this.isZero())return Long.ZERO;if(this.equals(Long.MIN_VALUE)){if(e.equals(Long.ONE)||e.equals(Long.NEG_ONE))return Long.MIN_VALUE;if(e.equals(Long.MIN_VALUE))return Long.ONE;var t=this.shiftRight(1),r=t.div(e).shiftLeft(1);if(r.equals(Long.ZERO))return e.isNegative()?Long.ONE:Long.NEG_ONE;var n=this.subtract(e.multiply(r));return r.add(n.div(e))}if(e.equals(Long.MIN_VALUE))return Long.ZERO;if(this.isNegative())return e.isNegative()?this.negate().div(e.negate()):this.negate().div(e).negate();if(e.isNegative())return this.div(e.negate()).negate();var i=Long.ZERO;for(n=this;n.greaterThanOrEqual(e);){r=Math.max(1,Math.floor(n.toNumber()/e.toNumber()));for(var o=Math.ceil(Math.log(r)/Math.LN2),u=o<=48?1:Math.pow(2,o-48),s=Long.fromNumber(r),a=s.multiply(e);a.isNegative()||a.greaterThan(n);)r-=u,s=Long.fromNumber(r),a=s.multiply(e);s.isZero()&&(s=Long.ONE),i=i.add(s),n=n.subtract(a)}return i},Long.prototype.modulo=function(e){return this.subtract(this.div(e).multiply(e))},Long.prototype.not=function(){return Long.fromBits(~this.low_,~this.high_)},Long.prototype.and=function(e){return Long.fromBits(this.low_&e.low_,this.high_&e.high_)},Long.prototype.or=function(e){return Long.fromBits(this.low_|e.low_,this.high_|e.high_)},Long.prototype.xor=function(e){return Long.fromBits(this.low_^e.low_,this.high_^e.high_)},Long.prototype.shiftLeft=function(e){if(0===(e&=63))return this;var t=this.low_;if(e<32){var r=this.high_;return Long.fromBits(t<<e,r<<e|t>>>32-e)}return Long.fromBits(0,t<<e-32)},Long.prototype.shiftRight=function(e){if(0===(e&=63))return this;var t=this.high_;if(e<32){var r=this.low_;return Long.fromBits(r>>>e|t<<32-e,t>>e)}return Long.fromBits(t>>e-32,t>=0?0:-1)},Long.prototype.shiftRightUnsigned=function(e){if(0===(e&=63))return this;var t=this.high_;if(e<32){var r=this.low_;return Long.fromBits(r>>>e|t<<32-e,t>>>e)}return 32===e?Long.fromBits(t,0):Long.fromBits(t>>>e-32,0)},Long.fromInt=function(e){if(-128<=e&&e<128){var t=Long.INT_CACHE_[e];if(t)return t}var r=new Long(0|e,e<0?-1:0);return-128<=e&&e<128&&(Long.INT_CACHE_[e]=r),r},Long.fromNumber=function(e){return isNaN(e)||!isFinite(e)?Long.ZERO:e<=-Long.TWO_PWR_63_DBL_?Long.MIN_VALUE:e+1>=Long.TWO_PWR_63_DBL_?Long.MAX_VALUE:e<0?Long.fromNumber(-e).negate():new Long(e%Long.TWO_PWR_32_DBL_|0,e/Long.TWO_PWR_32_DBL_|0)},Long.fromBits=function(e,t){return new Long(e,t)},Long.fromString=function(e,t){if(0===e.length)throw Error("number format error: empty string");var r=t||10;if(r<2||36<r)throw Error("radix out of range: "+r);if("-"===e.charAt(0))return Long.fromString(e.substring(1),r).negate();if(e.indexOf("-")>=0)throw Error('number format error: interior "-" character: '+e);for(var n=Long.fromNumber(Math.pow(r,8)),i=Long.ZERO,o=0;o<e.length;o+=8){var u=Math.min(8,e.length-o),s=parseInt(e.substring(o,o+u),r);if(u<8){var a=Long.fromNumber(Math.pow(r,u));i=i.multiply(a).add(Long.fromNumber(s))}else i=i.multiply(n),i=i.add(Long.fromNumber(s))}return i},Long.INT_CACHE_={},Long.TWO_PWR_16_DBL_=65536,Long.TWO_PWR_24_DBL_=1<<24,Long.TWO_PWR_32_DBL_=Long.TWO_PWR_16_DBL_*Long.TWO_PWR_16_DBL_,Long.TWO_PWR_31_DBL_=Long.TWO_PWR_32_DBL_/2,Long.TWO_PWR_48_DBL_=Long.TWO_PWR_32_DBL_*Long.TWO_PWR_16_DBL_,Long.TWO_PWR_64_DBL_=Long.TWO_PWR_32_DBL_*Long.TWO_PWR_32_DBL_,Long.TWO_PWR_63_DBL_=Long.TWO_PWR_64_DBL_/2,Long.ZERO=Long.fromInt(0),Long.ONE=Long.fromInt(1),Long.NEG_ONE=Long.fromInt(-1),Long.MAX_VALUE=Long.fromBits(-1,2147483647),Long.MIN_VALUE=Long.fromBits(0,-2147483648),Long.TWO_PWR_24_=Long.fromInt(1<<24);var long_1=Long,Long_1=Long;long_1.Long=Long_1,Double.prototype.valueOf=function(){return this.value},Double.prototype.toJSON=function(){return this.value};var double_1=Double,Double_1=Double;double_1.Double=Double_1,Timestamp.prototype=Object.create(long_1.prototype),Timestamp.prototype.constructor=Timestamp,Timestamp.prototype.toJSON=function(){return{$timestamp:this.toString()}},Timestamp.fromInt=function(e){return new Timestamp(long_1.fromInt(e))},Timestamp.fromNumber=function(e){return new Timestamp(long_1.fromNumber(e))},Timestamp.fromBits=function(e,t){return new Timestamp(e,t)},Timestamp.fromString=function(e,t){return new Timestamp(long_1.fromString(e,t))};var timestamp=Timestamp,Timestamp_1=Timestamp;timestamp.Timestamp=Timestamp_1;var _endianness,tmpdir=tmpDir,EOL="\n",os={EOL:EOL,tmpdir:tmpdir,tmpDir:tmpDir,networkInterfaces:networkInterfaces,getNetworkInterfaces:getNetworkInterfaces,release:release,type:type,cpus:cpus,totalmem:totalmem,freemem:freemem,