@cloudbase/js-sdk 3.10.1 → 3.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("cloudbase_database",[],e):"object"==typeof exports?exports.cloudbase_database=e():t.cloudbase_database=e()}("undefined"!=typeof window?window:this,()=>(()=>{var t={829:(t,e,n)=>{"use strict";var r;n.r(e),n.d(e,{AbstractSDKRequest:()=>o,AbstractStorage:()=>i,StorageType:()=>r,formatUrl:()=>s}),function(t){t.local="local",t.none="none",t.session="session"}(r||(r={}));var o=function(){},i=function(){};function s(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";for(var i in n)""===o?!r&&(e+="?"):o+="&",o+=i+"="+encodeURIComponent(n[i]);return/^http(s)?\:\/\//.test(e+=o)?e:""+t+e}},198:function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},i.apply(this,arguments)},s=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},a=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.registerDatabase=e.gateWayFunc=void 0;var u=n(954),c=n(804),f=n(877);e.gateWayFunc={filterRes:function(t){return delete(t=f.utils.promoteGatewayError(t)).header,delete t.statusCode,t},flattenResData:function(t){if("object"==typeof t.data&&null!==t.data){var e=i(i({},t),t.data);return delete e.data,e}return t},safeParseEJSON:function(t){if("string"!=typeof t)return t;try{return c.EJSON.parse(t)}catch(e){return t}},parseEJSONParam:function(t){if("string"!=typeof t)return t;try{return JSON.parse(t)}catch(e){return t}},parseEJSONValue:function(t){if("string"!=typeof t)return t;try{return c.EJSON.parse(t)}catch(n){return e.gateWayFunc.parseEJSONParam(t)}},normalizeOrderParam:function(t){if(null!=t&&""!==t){for(var n=e.gateWayFunc.parseEJSONValue(t),r=function(t){var e=t&&"object"==typeof t?Number(t):t;if("number"==typeof e&&!isNaN(e))return e<0?"desc":"asc";if("string"==typeof e){var n=e.toLowerCase();if("desc"===n||"-1"===n)return"desc";if("asc"===n||"1"===n)return"asc"}},o=[],i=0,s=Array.isArray(n)?n:[n];i<s.length;i++){var a=s[i];if(a&&"object"==typeof a)if(void 0!==a.field)(f=r(a.direction))&&o.push({field:a.field,direction:f});else for(var u=0,c=Object.entries(a);u<c.length;u++){var f,l=c[u],d=l[0];(f=r(l[1]))&&o.push({field:d,direction:f})}}return o.length?o:void 0}},extractDocId:function(t){if(t&&"object"==typeof t&&!Array.isArray(t)&&1===Object.keys(t).length&&"_id"in t){var e=t._id;if("string"==typeof e||"number"==typeof e)return String(e);if(e&&"object"==typeof e){if("string"==typeof e.$oid)return e.$oid;var n=e.$eq;if("string"==typeof n||"number"==typeof n)return String(n);if(n&&"object"==typeof n&&"string"==typeof n.$oid)return n.$oid}}},toLegacyRegExp:function(t){if(!t||"object"!=typeof t)return t;if(t.$regularExpression&&"object"==typeof t.$regularExpression){var n=t.$regularExpression;return{$regex:n.pattern,$options:n.options}}if(Array.isArray(t))return t.map(function(t){return e.gateWayFunc.toLegacyRegExp(t)});var r={};for(var o in t)r[o]=e.gateWayFunc.toLegacyRegExp(t[o]);return r},parseWriteParam:function(t){return e.gateWayFunc.toLegacyRegExp(e.gateWayFunc.parseEJSONParam(t))},buildQueryParams:function(t){return Object.entries(t).filter(function(t){t[0];var e=t[1];return null!=e&&""!==e}).map(function(t){var e=t[0],n=t[1],r="object"==typeof n?JSON.stringify(n):String(n);return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(r))}).join("&")},getUrlPrefix:function(t){var e=(null==t?void 0:t.instance)||"(default)",n=(null==t?void 0:t.database)||"(default)";return"/database/instances/".concat(e,"/databases/").concat(n)},"database.queryDocument":function(t,n){var r,o,u,f;return s(this,void 0,Promise,function(){var s,l,d,h,p,y,g;return a(this,function(a){switch(a.label){case 0:return s=e.gateWayFunc.parseEJSONParam(t.query),l=e.gateWayFunc.parseEJSONValue(t.projection),d=e.gateWayFunc.extractDocId(s),h=void 0!==d,p=e.gateWayFunc.buildQueryParams(i({projection:l,transactionId:t.transactionId},h?{}:{offset:null!==(r=t.offset)&&void 0!==r?r:0,limit:null!==(o=t.limit)&&void 0!==o?o:100,order:e.gateWayFunc.normalizeOrderParam(t.order),query:s?c.EJSON.stringify(s,{relaxed:!1}):void 0})),y="".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(p),h&&(y="".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/").concat(d,"?").concat(p)),[4,this.gateWay({url:y,method:"GET"},n)];case 1:return(g=a.sent()).data=e.gateWayFunc.safeParseEJSON(JSON.stringify(g.data)),!h||g.code||(null===(u=g.data)||void 0===u?void 0:u.code)?(g.code||(null===(f=g.data)||void 0===f?void 0:f.code)?g=i(i({},g),{data:i(i({},g.data),{list:[]})}):Array.isArray(g.data)?g=i(i({},g),{data:{list:g.data}}):g.data&&!Array.isArray(g.data.list)&&(g=i(i({},g),{data:i(i({},g.data),{list:[]})})),[2,e.gateWayFunc.filterRes(g)]):[2,i(i({},g),{data:{list:[g.data]}})]}})})},"database.addDocument":function(t,n){var r,o,u;return s(this,void 0,Promise,function(){var s,c;return a(this,function(a){switch(a.label){case 0:return s=(Array.isArray(t.data)?t.data:[t.data]).map(function(t){return e.gateWayFunc.parseWriteParam(t)}),[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"POST",data:i({data:s},t.transactionId&&{transactionId:t.transactionId})},n)];case 1:return c=a.sent(),Array.isArray(t.data)?c=i(i({},c),{data:i({ids:(null===(r=c.data)||void 0===r?void 0:r.insertedIds)||[]},c.data)}):(null===(u=null===(o=c.data)||void 0===o?void 0:o.insertedIds)||void 0===u?void 0:u[0])&&(c=i(i({},c),{data:i({_id:c.data.insertedIds[0]},c.data)})),[2,e.gateWayFunc.filterRes(c)]}})})},"database.updateDocument":function(t,n){var r;return s(this,void 0,Promise,function(){var o;return a(this,function(s){switch(s.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"PATCH",data:i({query:e.gateWayFunc.parseEJSONParam(t.query),data:e.gateWayFunc.parseEJSONParam(t.data),multi:!!t.multi,upsert:!!t.upsert,replaceMode:null!==(r=t.replaceMode)&&void 0!==r?r:!1===t.merge},t.transactionId&&{transactionId:t.transactionId})},n)];case 1:return o=s.sent(),[2,e.gateWayFunc.filterRes(o)]}})})},"database.deleteDocument":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/remove"),method:"POST",data:i({query:e.gateWayFunc.parseEJSONParam(t.query),multi:!!t.multi},t.transactionId&&{transactionId:t.transactionId})},n)];case 1:return r=o.sent(),[2,e.gateWayFunc.filterRes(r)]}})})},"database.countDocument":function(t,n){return s(this,void 0,Promise,function(){var r,o,i;return a(this,function(s){switch(s.label){case 0:return r=e.gateWayFunc.parseEJSONParam(t.query),o=e.gateWayFunc.buildQueryParams({count:!0,query:r?c.EJSON.stringify(r,{relaxed:!1}):void 0}),[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(o),method:"GET"},n)];case 1:return i=s.sent(),[2,e.gateWayFunc.filterRes(i)]}})})},"database.addCollection":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/collections"),method:"POST",data:{collectionName:t.collectionName}},n)];case 1:return r=o.sent(),[2,e.gateWayFunc.filterRes(r)]}})})},"database.aggregate":function(t,n){var r;return s(this,void 0,Promise,function(){var o,i;return a(this,function(s){switch(s.label){case 0:return o=t.stages.map(function(t){var e,n;try{var r="string"==typeof t.stageValue?JSON.parse(t.stageValue):t.stageValue;return(e={})[t.stageKey]=c.EJSON.serialize(r),e}catch(e){return(n={})[t.stageKey]=t.stageValue,n}}),[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/aggregations"),method:"POST",data:{pipeline:o}},n)];case 1:return i=s.sent(),Array.isArray(null===(r=i.data)||void 0===r?void 0:r.list)&&(i.data.list=JSON.stringify(i.data.list.map(function(t){return JSON.stringify(t)}))),[2,e.gateWayFunc.filterRes(i)]}})})},"database.startTransaction":function(t,n){return s(this,void 0,void 0,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/transactions"),method:"POST"},n)];case 1:return r=o.sent(),[2,e.gateWayFunc.filterRes(e.gateWayFunc.flattenResData(r))]}})})},"database.commitTransaction":function(t,n){return s(this,void 0,void 0,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/commit"),method:"POST"},n)];case 1:return r=o.sent(),[2,e.gateWayFunc.filterRes(r)]}})})},"database.abortTransaction":function(t,n){return s(this,void 0,void 0,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/rollback"),method:"POST"},n)];case 1:return r=o.sent(),[2,e.gateWayFunc.filterRes(r)]}})})},"database.getInTransaction":function(t,n){var r;return s(this,void 0,void 0,function(){var o;return a(this,function(s){switch(s.label){case 0:return[4,e.gateWayFunc["database.queryDocument"].call(this,t,n)];case 1:return"object"==typeof(o=s.sent()).data&&null!==o.data?(null===(r=o.data)||void 0===r?void 0:r.code)?[2,e.gateWayFunc.flattenResData(o)]:[2,i(i({},o),{data:JSON.stringify(o.data)})]:[2,o]}})})},"database.updateDocInTransaction":function(t,n){return s(this,void 0,void 0,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,e.gateWayFunc["database.updateDocument"].call(this,t,n)];case 1:return r=o.sent(),[2,e.gateWayFunc.flattenResData(r)]}})})},"database.deleteDocInTransaction":function(t,n){return s(this,void 0,void 0,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,e.gateWayFunc["database.deleteDocument"].call(this,t,n)];case 1:return r=o.sent(),[2,e.gateWayFunc.flattenResData(r)]}})})},"database.insertDocInTransaction":function(t,n){var r;return s(this,void 0,Promise,function(){var o,s;return a(this,function(a){switch(a.label){case 0:return[4,e.gateWayFunc["database.addDocument"].call(this,t,n)];case 1:return"object"==typeof(o=a.sent()).data&&null!==o.data?(s=!!(null===(r=o.data)||void 0===r?void 0:r._id),o=i(i(i({},o),{inserted:s?1:0,ok:s?1:0}),o.data)):o=i({inserted:0,ok:0},o),delete o.data,[2,o]}})})},"database.runCommands":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/commands"),method:"POST",data:i({commands:c.EJSON.serialize(Array.isArray(t.commands)?t.commands.map(function(t){return e.gateWayFunc.parseEJSONParam(t)}):t.commands)},t.transactionId&&{transactionId:t.transactionId})},n)];case 1:"object"==typeof(r=o.sent()).data&&null!==r.data&&(delete(r=i(i({},r),r.data)).data,delete r.request_id);try{r=c.EJSON.deserialize(r)}catch(t){}return[2,e.gateWayFunc.filterRes(r)]}})})},"database.getDocument":function(t,n){var r;return s(this,void 0,Promise,function(){var o,s;return a(this,function(a){switch(a.label){case 0:return(o=i({},t)).query=e.gateWayFunc.parseEJSONParam(o.query),o.projection=e.gateWayFunc.parseEJSONValue(o.projection),[4,e.gateWayFunc["database.queryDocument"].call(this,o,n)];case 1:return s=a.sent(),Array.isArray(null===(r=s.data)||void 0===r?void 0:r.list)&&(s.data.list=s.data.list.map(function(t){return c.EJSON.stringify(t,{relaxed:!1})})),[2,s]}})})},"database.insertDocument":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){return(r=i({},t)).data=Array.isArray(r.data)?r.data.map(function(t){return e.gateWayFunc.parseWriteParam(t)}):e.gateWayFunc.parseWriteParam(r.data),[2,e.gateWayFunc["database.addDocument"].call(this,r,n)]})})},"database.modifyDocument":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){return(r=i({},t)).query=e.gateWayFunc.parseEJSONParam(r.query),r.data=e.gateWayFunc.parseEJSONParam(r.data),[2,e.gateWayFunc["database.updateDocument"].call(this,r,n)]})})},"database.modifyAndReturnDoc":function(t,n){var r,o;return s(this,void 0,Promise,function(){var s,u,f;return a(this,function(a){switch(a.label){case 0:return(s=i({},t)).query=e.gateWayFunc.parseEJSONParam(s.query),s.data=e.gateWayFunc.parseEJSONParam(s.data),(u=e.gateWayFunc.extractDocId(s.query))?[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(s),"/collections/").concat(s.collectionName,"/documents/").concat(u),method:"PATCH",data:i({data:s.data,replaceMode:null!==(r=s.replaceMode)&&void 0!==r&&r,upsert:!!s.upsert,returnDoc:!0},s.transactionId&&{transactionId:s.transactionId})},n)]:[2,e.gateWayFunc["database.updateDocument"].call(this,s,n)];case 1:return f=a.sent(),void 0!==(null===(o=f.data)||void 0===o?void 0:o.doc)&&"string"!=typeof f.data.doc&&(f.data.doc=c.EJSON.stringify(f.data.doc,{relaxed:!1})),[2,e.gateWayFunc.filterRes(f)]}})})},"database.removeDocument":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){return(r=i({},t)).query=e.gateWayFunc.parseEJSONParam(r.query),[2,e.gateWayFunc["database.deleteDocument"].call(this,r,n)]})})},"database.calculateDocument":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){return(r=i({},t)).query=e.gateWayFunc.parseEJSONParam(r.query),[2,e.gateWayFunc["database.countDocument"].call(this,r,n)]})})},"database.aggregateDocuments":function(t,n){var r;return s(this,void 0,Promise,function(){var o,s;return a(this,function(a){switch(a.label){case 0:return o=i({},t),Array.isArray(o.stages)&&(o.stages=o.stages.map(function(t){return i(i({},t),{stageValue:e.gateWayFunc.parseEJSONParam(t.stageValue)})})),[4,e.gateWayFunc["database.aggregate"].call(this,o,n)];case 1:if(s=a.sent(),"string"==typeof(null===(r=s.data)||void 0===r?void 0:r.list))try{s.data.list=JSON.parse(s.data.list)}catch(t){}return[2,s]}})})}};var l={name:"database",entity:{database:function(t){var n;if(void 0!==t&&"Object"!==Object.prototype.toString.call(t).slice(8,-1))throw f.utils.createCloudbaseError({code:"INVALID_PARAM",msg:"dbConfig must be an object"},null===(n=this.config)||void 0===n?void 0:n.errorFactory);var r=this.platform,c=r.adapter,l=r.runtime,d=function(t){function n(e){return t.call(this,e)||this}return o(n,t),n.prototype.send=function(n,r,o){var i,u,c,l;return s(this,void 0,void 0,function(){var s,d,h;return a(this,function(a){switch(a.label){case 0:return s=null,d=o&&"number"==typeof o.timeout?{timeout:o.timeout}:void 0,"GATEWAY"===this.config.endPointMode&&e.gateWayFunc[n]?[4,e.gateWayFunc[n].call(this,r,d)]:[3,2];case 1:return s=a.sent(),[3,4];case 2:return[4,t.prototype.send.call(this,n,r,void 0,d)];case 3:s=a.sent(),a.label=4;case 4:if(h=f.utils.resolveThrow(null!==(c=null===(u=null===(i=this.config)||void 0===i?void 0:i._fromApp)||void 0===u?void 0:u.config)&&void 0!==c?c:this.config),s&&s.code&&h)throw f.utils.createCloudbaseError({code:s.code,msg:s.message||s.data&&s.data.message||"",requestId:s.requestId},null===(l=this.config)||void 0===l?void 0:l.errorFactory);return[2,s]}})})},n}(this.request.constructor);return u.Db.reqClass=d,u.Db.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},u.Db.runtime=l,this.wsClientClass&&(u.Db.wsClass=c.wsClass,u.Db.wsClientClass=this.wsClientClass),u.Db.ws||(u.Db.ws=null),new(function(t){function e(e){return t.call(this,e)||this}return o(e,t),e.prototype.runCommands=function(t){return s(this,void 0,Promise,function(){return a(this,function(e){return[2,u.Db.createRequest(this.config).send("database.runCommands",t)]})})},e}(u.Db))(i(i(i({},this.config),{_fromApp:this}),t))}}};try{cloudbase.registerComponent(l)}catch(t){}function d(t){try{t.registerComponent(l)}catch(t){console.warn(t)}}e.registerDatabase=d;try{window.registerDatabase=d}catch(t){}},563:function(t,e,n){"use strict";var r=this&&this.__assign||function(){return r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)},o=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),i=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&o(e,t,n);return i(e,t),e};Object.defineProperty(e,"__esModule",{value:!0}),e.useDefaultAdapter=e.useAdapters=e.RUNTIME=void 0;var a,u=s(n(92)),c=n(962);!function(t){t.WEB="web",t.WX_MP="wx_mp"}(a=e.RUNTIME||(e.RUNTIME={})),e.useAdapters=function(t,e){for(var n=0,o=(0,c.isArray)(t)?t:[t];n<o.length;n++){var i=o[n],s=i.isMatch,a=i.genAdapter,u=i.runtime;if(s())return{adapter:r({isMatch:s},a(e)),runtime:u}}},e.useDefaultAdapter=function(){return{adapter:r({},u.genAdapter()),runtime:a.WEB}}},92:function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},i.apply(this,arguments)},s=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},a=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.WebRequest=e.genAdapter=void 0;var u=n(829),c=n(962),f=n(464),l=function(t){function e(e){var n=t.call(this)||this,r=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=r||0,n.timeoutMsg=o||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}return o(e,t),e.prototype.get=function(t){return this.request(i(i({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(i(i({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(i(i({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t,n=e.data,r=e.file,o=e.fileContent,s=e.name,a=e.method,u=e.headers,c=void 0===u?{}:u,f=null!=r?r:o,l={post:"post",put:"put"}[null==a?void 0:a.toLowerCase()]||"put",d=new FormData;return"post"===l?(Object.keys(n).forEach(function(t){d.append(t,n[t])}),d.append("key",s),d.append("file",f instanceof Blob?f:new Blob([f])),this.request(i(i({},t),{data:d,method:l}),this.restrictedMethods.includes("upload"))):this.request(i(i({},t),{method:"put",headers:c,body:f}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return s(this,void 0,Promise,function(){var e,n,r,o;return a(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,this.get(i(i({},t),{headers:{},responseType:"blob"}))];case 1:return e=s.sent().data,n=window.URL.createObjectURL(new Blob([e])),r=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=n,o.setAttribute("download",r),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n),document.body.removeChild(o),[3,3];case 2:return s.sent(),[3,3];case 3:return[2,new Promise(function(e){e({statusCode:200,tempFilePath:t.url})})]}})})},e.prototype.fetch=function(t){var e;return s(this,void 0,Promise,function(){var n,r,o,u,c,f,l,d,h,p,y,g,b,m=this;return a(this,function(w){switch(w.label){case 0:return n=new AbortController,r=t.url,o=t.enableAbort,u=void 0!==o&&o,c=t.stream,f=void 0!==c&&c,l=t.signal,d=t.timeout,h=t.shouldThrowOnError,p=void 0===h||h,y=null!=d?d:this.timeout,l&&(l.aborted&&n.abort(),l.addEventListener("abort",function(){return n.abort()})),g=null,u&&y&&(g=setTimeout(function(){console.warn(m.timeoutMsg),n.abort(new Error(m.timeoutMsg))},y)),[4,fetch(r,i(i({},t),{signal:n.signal})).then(function(t){return s(m,void 0,void 0,function(){var e,n,r;return a(this,function(o){switch(o.label){case 0:return clearTimeout(g),p?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return r=(n=Promise).reject,[4,t.json()];case 2:e=r.apply(n,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}})})}).catch(function(t){return clearTimeout(g),Promise.reject(t)})];case 1:return b=w.sent(),[2,{data:f?b.body:(null===(e=b.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?b.json():b.text(),statusCode:b.status,header:b.headers,response:b}]}})})},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var r=String(t.method).toLowerCase()||"get";return new Promise(function(o){var i=t.url,s=t.headers,a=void 0===s?{}:s,u=t.data,l=t.responseType,d=t.withCredentials,h=t.body,p=t.onUploadProgress,y=(0,c.formatUrl)((0,f.getProtocol)(),i,"get"===r?u:{}),g=new XMLHttpRequest;g.open(r,y),l&&(g.responseType=l);var b,m,w=t.signal;w&&(w.aborted?g.abort():w.addEventListener("abort",function(){return g.abort()},{once:!0})),Object.keys(a).forEach(function(t){g.setRequestHeader(t,a[t])}),p&&g.upload.addEventListener("progress",p),g.onreadystatechange=function(){var t={};if(4===g.readyState){var e=g.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};e.forEach(function(t){var e=t.split(": "),r=e.shift().toLowerCase(),o=e.join(": ");n[r]=o}),t.header=n,t.statusCode=g.status;try{t.data="blob"===l?g.response:JSON.parse(g.responseText)}catch(e){t.data="blob"===l?g.response:g.responseText}clearTimeout(b),o(t)}},e&&n.timeout&&(b=setTimeout(function(){console.warn(n.timeoutMsg),g.abort()},n.timeout)),m=(0,c.isFormData)(u)?u:"application/x-www-form-urlencoded"===a["content-type"]?(0,c.toQueryString)(u):h||(u?JSON.stringify(u):void 0),d&&(g.withCredentials=!0),g.send(m)})},e}(u.AbstractSDKRequest);e.WebRequest=l,e.genAdapter=function(){return{type:"default",root:window,reqClass:l,wsClass:WebSocket,localStorage}}},464:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.COMMUNITY_SITE_URL=e.IS_DEBUG_MODE=e.getProtocol=e.setProtocol=e.getSdkName=e.setSdkName=void 0;var n="@cloudbase/js-sdk";e.setSdkName=function(t){n=t},e.getSdkName=function(){return n};var r="https:";e.setProtocol=function(t){r=t},e.getProtocol=function(){return r},e.IS_DEBUG_MODE=!1,e.COMMUNITY_SITE_URL="https://support.qq.com/products/148793"},519:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ERRORS=void 0,e.ERRORS={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"}},778:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),e.OATUH_LOGINTYPE=void 0,o(n(464),e),o(n(519),e),e.OATUH_LOGINTYPE="constants"},517:function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},o=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.catchErrorsDecorator=void 0;var i=n(962),s=n(778),a=!1;"undefined"!=typeof navigator&&navigator.userAgent&&(a=-1!==navigator.userAgent.indexOf("Firefox"));var u=a?/(\.js\/)?__decorate(\$\d+)?<@.*\d$/:/(\/\w+\.js\.)?__decorate(\$\d+)?\s*\(.*\)$/,c=/https?:\/\/.+:\d*\/.*\.js:\d+:\d+/;function f(t){var e=t.err,n=t.className,r=t.methodName,o=t.sourceLink;if(!o)return null;var i,s=e.stack.split("\n"),u=a?/^catchErrorsDecorator\/<\/descriptor.value@.*\d$/:new RegExp("".concat(n,"\\.descriptor.value\\s*\\[as\\s").concat(r,"\\]\\s*\\(.*\\)$")),f=a?/^catchErrorsDecorator\/<\/descriptor.value/:new RegExp("".concat(n,"\\.descriptor.value\\s*\\[as\\s").concat(r,"\\]")),l=s.findIndex(function(t){return u.test(t)});if(-1!==l){var d=s.filter(function(t,e){return e>l});d.unshift(s[l].replace(f,"".concat(n,".").concat(r)).replace(c,o)),(i=new Error).stack="".concat(a?"@debugger":"Error","\n").concat(d.join("\n"))}return i}e.catchErrorsDecorator=function(t){var e=t.mode,n=void 0===e?"async":e,a=t.customInfo,l=void 0===a?{}:a,d=t.title,h=t.messages,p=void 0===h?[]:h;return function(t,e,a){if(s.IS_DEBUG_MODE){var h=l.className||t.constructor.name,y=l.methodName||e,g=a.value,b=function(){var t="",e=(new Error).stack.split("\n"),n=e.findIndex(function(t){return u.test(t)});if(-1!==n){var r=c.exec(e[n+1]||"");t=r?r[0]:""}return t}();a.value="sync"===n?function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=f({err:new Error,className:h,methodName:y,sourceLink:b});try{return g.apply(this,t)}catch(t){var r=t,o=t.message,s=t.error,a=t.error_description,u={title:d||"".concat(h,".").concat(y," failed"),content:[{type:"error",body:t}]};if(o&&/^\{.*\}$/.test(o)){var c=JSON.parse(o);u.subtitle=o,c.code&&(n?(n.code=c.code,n.msg=c.msg):(t.code=c.code,t.message=c.msg),r=n||t,u.content=p.map(function(t){return{type:"info",body:t}}))}throw s&&a&&(u.subtitle=a,n?(n.code=s,n.msg=a):(t.code=s,t.message=a),r=n||t,u.content=p.map(function(t){return{type:"info",body:t}})),(0,i.printGroupLog)(u),r}}:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return r(this,void 0,void 0,function(){var e,n,r,s,a,u,c,l;return o(this,function(o){switch(o.label){case 0:e=f({err:new Error,className:h,methodName:y,sourceLink:b}),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,g.apply(this,t)];case 2:return[2,o.sent()];case 3:throw n=o.sent(),r=n,s=n.message,a=n.error,u=n.error_description,c={title:d||"".concat(h,".").concat(y," failed"),content:[{type:"error",body:n}]},s&&/^\{.*\}$/.test(s)&&(l=JSON.parse(s),c.subtitle=l,l.code&&(e?(e.code=l.code,e.message=l.msg):(n.code=l.code,n.message=l.msg),r=e||n,c.content=p.map(function(t){return{type:"info",body:t}}))),a&&u&&(c.subtitle=u,e?(e.code=a,e.msg=u):(n.code=a,n.message=u),r=e||n,c.content=p.map(function(t){return{type:"info",body:t}})),(0,i.printGroupLog)(c),r;case 4:return[2]}})})}}}}},260:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),o(n(517),e)},877:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&r(e,t,n);return o(e,t),e},s=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.langEvent=e.AbortController=e.jwt=e.helpers=e.utils=e.events=e.cache=e.adapters=e.constants=void 0;var a=i(n(778));e.constants=a;var u=i(n(563));e.adapters=u;var c=i(n(865));e.cache=c;var f=i(n(940));e.events=f;var l=i(n(991));e.langEvent=l;var d=i(n(962));e.utils=d;var h=i(n(260));e.helpers=h;var p=s(n(644));e.AbortController=p.default;var y={decode:s(n(949)).default};e.jwt=y},644:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){var t=this;this.listeners=[],this.signal={aborted:!1,addEventListener:function(e,n){"abort"===e&&t.listeners.push(n)}}}return t.prototype.abort=function(){this.signal.aborted||(this.signal.aborted=!0,this.listeners.forEach(function(t){return t()}))},t}();e.default=n},865:function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},s=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.CloudbaseCache=void 0;var a=n(829),u=n(962),c=n(778),f=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return o(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(a.AbstractStorage),l=function(){function t(t){this.keys={};var e=t.persistence,n=t.platformInfo,r=void 0===n?{}:n,o=t.keys,i=void 0===o?{}:o;this.platformInfo=r,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:((0,u.printWarn)(c.ERRORS.INVALID_PARAMS,"localStorage is not supported on current platform"),new f(e.root));case"none":return new f(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}return Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,n){if("async"!==this.mode){if(this.storage)try{var r={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(r))}catch(t){throw new Error(JSON.stringify({code:c.ERRORS.OPERATION_FAIL,msg:"[".concat((0,c.getSdkName)(),"][").concat(c.ERRORS.OPERATION_FAIL,"]setStore failed"),info:t}))}}else(0,u.printWarn)(c.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return i(this,void 0,void 0,function(){var r;return s(this,function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}})})},t.prototype.getStore=function(t,e){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!0,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!0,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var r=this.storage.getItem(t);return r&&r.indexOf(e)>=0?JSON.parse(r).content:""}(0,u.printWarn)(c.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return i(this,void 0,void 0,function(){var r;return s(this,function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!0,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!0,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(r=o.sent())&&r.indexOf(e)>=0?[2,JSON.parse(r).content]:[2,""]}})})},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):(0,u.printWarn)(c.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return i(this,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}})})},t}();e.CloudbaseCache=l},940:function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};Object.defineProperty(e,"__esModule",{value:!0}),e.removeEventListener=e.activateEvent=e.addEventListener=e.CloudbaseEventEmitter=e.IErrorEvent=e.CloudbaseEvent=void 0;var s=n(962),a=function(t,e){this.data=e||null,this.name=t};e.CloudbaseEvent=a;var u=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return o(e,t),e}(a);e.IErrorEvent=u;var c=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if((0,s.isInstanceOf)(t,u))return console.error(t.error),this;var n=(0,s.isString)(t)?new a(t,e||{}):t,r=n.name;if(this.listens(r)){n.target=this;for(var o=0,c=this.listeners[r]?i([],this.listeners[r],!0):[];o<c.length;o++)c[o].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();e.CloudbaseEventEmitter=c;var f=new c;e.addEventListener=function(t,e){f.on(t,e)},e.activateEvent=function(t,e){void 0===e&&(e={}),f.fire(t,e)},e.removeEventListener=function(t,e){f.off(t,e)}},991:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.LANG_CHANGE_EVENT=e.bus=void 0;var r=n(940);e.bus=new r.CloudbaseEventEmitter,e.LANG_CHANGE_EVENT="lang_change"},962:function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},i.apply(this,arguments)},s=this&&this.__rest||function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n};Object.defineProperty(e,"__esModule",{value:!0}),e.parseCaptcha=e.parseQueryString=e.transformPhone=e.sleep=e.printGroupLog=e.errorToResult=e.promoteGatewayError=e.maybeThrow=e.resolveThrow=e.createCloudbaseError=e.CloudbaseError=e.throwError=e.printInfo=e.printError=e.printWarn=e.execCallback=e.createPromiseCallback=e.removeParam=e.getHash=e.getQuery=e.toQueryString=e.formatUrl=e.generateRequestId=e.genSeqId=e.isFormData=e.isInstanceOf=e.isNull=e.isPalinObject=e.isUndefined=e.isString=e.isArray=void 0;var a=n(778);e.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)},e.isString=function(t){return"string"==typeof t},e.isUndefined=function(t){return void 0===t},e.isPalinObject=function(t){return"[object Object]"===Object.prototype.toString.call(t)},e.isNull=function(t){return"[object Null]"===Object.prototype.toString.call(t)},e.isInstanceOf=function(t,e){return t instanceof e},e.isFormData=function(t){return"[object FormData]"===Object.prototype.toString.call(t)},e.genSeqId=function(){return Math.random().toString(16).slice(2)},e.generateRequestId=function(){var t=(new Date).getTime(),e=(null===Date||void 0===Date?void 0:Date.now)&&1e3*Date.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){var r=16*Math.random();return t>0?(r=(t+r)%16|0,t=Math.floor(t/16)):(r=(e+r)%16|0,e=Math.floor(e/16)),("x"===n?r:7&r|8).toString(16)})},e.formatUrl=function(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";return Object.keys(n).forEach(function(t){""===o?!r&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(n[t]))}),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)},e.toQueryString=function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach(function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))}),e.join("&")},e.getQuery=function(t,e){if("undefined"==typeof window)return!1;var n=e||decodeURIComponent(window.location.search),r=new RegExp("(^|&)".concat(t,"=([^&]*)(&|$)")),o=n.substr(n.indexOf("?")+1).match(r);return null!=o?o[2]:""},e.getHash=function(t){if("undefined"==typeof window)return"";var e=window.location.hash.match(new RegExp("[#?&/]".concat(t,"=([^&#]*)")));return e?e[1]:""},e.removeParam=function(t,e){var n=e.split("?")[0],r=[],o=-1!==e.indexOf("?")?e.split("?")[1]:"";if(""!==o){for(var i=(r=o.split("&")).length-1;i>=0;i-=1)r[i].split("=")[0]===t&&r.splice(i,1);n="".concat(n,"?").concat(r.join("&"))}return n},e.createPromiseCallback=function(){var t={};if(!Promise){(t=function(){}).promise={};var e=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(t.promise,"then",{get:e}),Object.defineProperty(t.promise,"catch",{get:e}),t}var n=new Promise(function(e,n){t=function(t,r){return t?n(t):e(r)}});return t.promise=n,t},e.execCallback=function(t,e,n){if(void 0===n&&(n=null),t&&"function"==typeof t)return t(e,n);if(e)throw e;return n},e.printWarn=function(t,e){console.warn("[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e))},e.printError=function(t,e){console.error({code:t,msg:"[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e)})},e.printInfo=function(t,e){console.log("[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e))},e.throwError=function(t,e){var n=new Error(JSON.stringify({code:t,msg:"[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e)}));throw n.code=t,n};var u=function(t){function e(e){var n=t.call(this,e.msg||e.message||"")||this;return n.code=e.code||"",n.requestId=e.requestId||"",Object.defineProperty(n,"message",{value:e.msg||e.message||"",enumerable:!0,writable:!0,configurable:!0}),n}return o(e,t),e}(Error);e.CloudbaseError=u;var c=function(t){return new u(t)};function f(t,e){return(e||c)(t)}function l(t){return!t||"boolean"!=typeof t.throw||t.throw}e.createCloudbaseError=f,e.resolveThrow=l,e.maybeThrow=function(t,e){if(l(t))throw f(i(i({},e),{msg:e.message}),null==t?void 0:t.errorFactory);return i({code:e.code,message:e.message},e.requestId?{requestId:e.requestId}:{})},e.promoteGatewayError=function(t){if(t&&"object"==typeof t&&t.data&&"object"==typeof t.data){var e=t.data,n=e.code,r=e.message;if(!t.code&&n||!t.message&&r)return i(i(i({},t),!t.code&&n?{code:n}:{}),!t.message&&r?{message:r}:{})}return t},e.errorToResult=function(t){if(t instanceof Error&&"string"==typeof t.message)try{var e=JSON.parse(t.message);if(e&&"string"==typeof e.code)return{code:e.code,message:e.msg||e.message||"",requestId:e.requestId}}catch(t){}return t&&"string"==typeof t.code?{code:t.code,message:t.message||"",requestId:t.requestId}:{code:"UNKNOWN_ERROR",message:String((null==t?void 0:t.message)||t||"")}},e.printGroupLog=function(t){var e,n=t.title,r=t.subtitle,o=void 0===r?"":r,i=t.content,s=void 0===i?[]:i,a=t.printTrace,u=void 0!==a&&a,c=t.collapsed;void 0!==c&&c?(console.groupCollapsed||console.error)(n,o):(console.group||console.error)(n,o);for(var f=0,l=s;f<l.length;f++){var d=l[f],h=d.type,p=d.body;switch(h){case"info":console.log(p);break;case"warn":console.warn(p);break;case"error":console.error(p)}}u&&(console.trace||console.log)("stack trace:"),null===(e=console.groupEnd)||void 0===e||e.call(console)},e.sleep=function(t){return void 0===t&&(t=0),new Promise(function(e){return setTimeout(e,t)})},e.transformPhone=function(t){return"+86".concat(t)},e.parseQueryString=function(t){t=t.replace(/^\?/,"");var e={};return t.split("&").forEach(function(t){var n=t.split("="),r=n[0],o=n[1];r=decodeURIComponent(r),o=decodeURIComponent(o),r&&(e[r]?Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]:e[r]=o)}),e},e.parseCaptcha=function(t){var n={},r=t.match(/^(data:.*?)(\?[^#\s]*)?$/);if(r){t=r[1];var o=r[2];o&&(n=(0,e.parseQueryString)(o))}var i=n.token,a=s(n,["token"]);return/^data:/.test(t)&&!i?{error:"invalid_argument",error_description:"invalid captcha data: ".concat(t)}:i?{state:a.state,token:i,captchaData:t}:{error:"unimplemented",error_description:"need to impl captcha data"}}},954:(t,e,n)=>{"use strict";n.r(e),n.d(e,{CollectionReference:()=>le,Db:()=>Se,DocumentReference:()=>ee,Query:()=>ae});var r,o,i={};n.r(i),n.d(i,{LineString:()=>yt,MultiLineString:()=>vt,MultiPoint:()=>mt,MultiPolygon:()=>Ot,Point:()=>pt,Polygon:()=>bt}),function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.BooleanError="must be boolean",t.ArrayError="must be array",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined",t.CentersPhereError="centersPhere结构不合法"}(o||(o={}));var s,a,u="Object",c="GeoPoint",f="GeoLineString",l="GeoPolygon",d="GeoMultiPoint",h="GeoMultiLineString",p="GeoMultiPolygon",y="Date",g="ServerDate",b=["desc","asc"],m=["<","<=","==",">=",">"];!function(t){t.lt="<",t.gt=">",t.lte="<=",t.gte=">=",t.eq="=="}(s||(s={})),(r={})[s.eq]="$eq",r[s.lt]="$lt",r[s.lte]="$lte",r[s.gt]="$gt",r[s.gte]="$gte",function(t){t.WHERE="WHERE",t.DOC="DOC"}(a||(a={}));var w,v=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},_=function(){function t(){}return t.formatResDocumentData=function(e){return e.map(function(e){return t.formatField(e)})},t.formatField=function(e){var n=Object.keys(e),r={};return Array.isArray(e)&&(r=[]),n.forEach(function(n){var o,i=e[n];switch(t.whichType(i)){case c:o=new pt(i.coordinates[0],i.coordinates[1]);break;case f:o=new yt(i.coordinates.map(function(t){return new pt(t[0],t[1])}));break;case l:o=new bt(i.coordinates.map(function(t){return new yt(t.map(function(t){var e=v(t,2),n=e[0],r=e[1];return new pt(n,r)}))}));break;case d:o=new mt(i.coordinates.map(function(t){return new pt(t[0],t[1])}));break;case h:o=new vt(i.coordinates.map(function(t){return new yt(t.map(function(t){var e=v(t,2),n=e[0],r=e[1];return new pt(n,r)}))}));break;case p:o=new Ot(i.coordinates.map(function(t){return new bt(t.map(function(t){return new yt(t.map(function(t){var e=v(t,2),n=e[0],r=e[1];return new pt(n,r)}))}))}));break;case y:o=i;break;case u:case"Array":o=t.formatField(i);break;case g:o=new Date(i.$date);break;default:o=i}Array.isArray(r)?r.push(o):r[n]=o}),r},t.whichType=function(t){var e=Object.prototype.toString.call(t).slice(8,-1);return e===y?y:(e===u&&(t.$date?e=g:pt.validate(t)?e=c:yt.validate(t)?e=f:bt.validate(t)?e=l:mt.validate(t)?e=d:vt.validate(t)?e=h:Ot.validate(t)&&(e=p)),e)},t.generateDocId=function(){for(var t="",e=0;e<24;e++)t+="ABCDEFabcdef0123456789".charAt(Math.floor(22*Math.random()));return t},t}(),O={code:"INVALID_PARAM",message:"Invalid request param"},E="DATABASE_TRANSACTION_CONFLICT",S={code:"DATABASE_REQUEST_FAILED",message:"database request failed"},N=n(804),I=(w=function(t,e){return w=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},w(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}w(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),x=[],T={},B=function(t){function e(e,n){if(n!==T)throw new TypeError("InternalSymbol cannot be constructed with new operator");return t.call(this,e)||this}return I(e,t),e.for=function(t){for(var n=0,r=x.length;n<r;n++)if(x[n].target===t)return x[n].instance;var o=new e(t,T);return x.push({target:t,instance:o}),o},e}(function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})});const j=B;var A=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},L=function(t){return"object"===A(t)},P=function(t){return"number"===A(t)},$=function(t){return Array.isArray(t)},U=function(t){return"date"===A(t)},R=function(t){return"regexp"===A(t)},D=function(t){return t&&t._internalType instanceof B},C=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),F=function(){return F=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},F.apply(this,arguments)};function q(t,e){if("function"!=typeof e)return t;t.then(function(t){return e(0,t)},function(t){return e(t)})}var M={};function k(t){if(!Se.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return M[e]||(M[e]=new Se.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:Se.createRequest(t.config)}}})),M[e]}var W=function(t){return void 0!==t.timeout?{timeout:t.timeout}:{}},J=function(t){if(!L(t))return t;for(var e in t)void 0===t[e]?delete t[e]:L(t[e])&&(t[e]=J(t[e]));return t},V=function(t){return t=J(t),N.EJSON.stringify(t,{relaxed:!1})},H=function(t){var e,n;if(t instanceof Date)return{$date:+t};if(t instanceof RegExp)return{$regex:t.source,$options:t.flags};if(t&&"object"==typeof t){if("ObjectId"===t._bsontype)return{$oid:t.toHexString()};if("BSONRegExp"===t._bsontype)return{$regex:t.pattern,$options:t.options};if(Array.isArray(t))return t.map(H);var r={};try{for(var o=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(Object.keys(t)),i=o.next();!i.done;i=o.next()){var s=i.value;r[s]=H(t[s])}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return r}return t},z=function(t){if(!t)return"{}";try{var e=N.EJSON.parse(t);return JSON.stringify(H(e))}catch(e){return t}},G=function(t){function e(e){var n=t.call(this,e.message)||this;return n.code=e.code,n.message=e.message,n}return C(e,t),e}(Error),Y=function(t){return new G(t)};function K(t,e){if(!1===t)return e;throw Y(F({},e))}var Q,Z=j.for("UNSET_FIELD_NAME"),X=j.for("UPDATE_COMMAND"),tt=j.for("QUERY_COMMAND"),et=j.for("LOGIC_COMMAND"),nt=j.for("GEO_POINT"),rt=j.for("SYMBOL_GEO_LINE_STRING"),ot=j.for("SYMBOL_GEO_POLYGON"),it=j.for("SYMBOL_GEO_MULTI_POINT"),st=j.for("SYMBOL_GEO_MULTI_LINE_STRING"),at=j.for("SYMBOL_GEO_MULTI_POLYGON"),ut=j.for("SERVER_DATE"),ct=j.for("REGEXP"),ft=j.for("OBJECTID"),lt=function(){return lt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},lt.apply(this,arguments)},dt=["limit","offset","projection","order","multiple","timeout","raw"],ht=function(){function t(){}return t.isGeopoint=function(t,e){if("Number"!==_.whichType(e))throw new Error("Geo Point must be number type");var n=Math.abs(e);if("latitude"===t&&n>90)throw new Error("latitude should be a number ranges from -90 to 90");if("longitude"===t&&n>180)throw new Error("longitude should be a number ranges from -180 to 180");return!0},t.isInteger=function(t,e){if(!Number.isInteger(e))throw new Error(t+o.IntergerError);return!0},t.mustBeBoolean=function(t,e){if("boolean"!=typeof e)throw new Error(t+o.BooleanError);return!0},t.isProjection=function(t,e){if("object"!==A(e))throw Y(lt(lt({},O),{message:"".concat(t," projection must be an object")}));for(var n in e){var r=e[n];if("number"===A(r)){if(0!==r&&1!==r)throw Y(lt(lt({},O),{message:"if the value in projection is of number, it must be 0 or 1"}))}else if("object"!==A(r))throw Y(lt(lt({},O),{message:"invalid projection"}))}return!0},t.isOrder=function(t,e){if("object"!==A(e))throw Y(lt(lt({},O),{message:"".concat(t," order must be an object")}));for(var n in e){var r=e[n];if(1!==r&&-1!==r)throw Y(lt(lt({},O),{message:"order value must be 1 or -1"}))}return!0},t.isFieldOrder=function(t){if(-1===b.indexOf(t))throw new Error(o.DirectionError);return!0},t.isFieldPath=function(t){if(!/^[a-zA-Z0-9-_\.]/.test(t))throw new Error;return!0},t.isOperator=function(t){if(-1===m.indexOf(t))throw new Error(o.OpStrError);return!0},t.isCollName=function(t){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(t))throw new Error(o.CollNameError);return!0},t.isDocID=function(t){if(!/^([a-fA-F0-9]){24}$/.test(t))throw new Error(o.DocIDError);return!0},t.isValidOptions=function(e){if(void 0===e&&(e={}),"object"!==A(e))throw Y(lt(lt({},O),{message:"options must be an object"}));var n=Object.keys(e);for(var r in n)if(dt.indexOf(n[r])<0)throw Y(lt(lt({},O),{message:"".concat(n[r]," is invalid options key")}));var o=e,i=o.limit,s=o.offset,a=o.projection,u=o.order,c=e.multiple;return void 0!==i&&t.isInteger("limit",i),void 0!==s&&t.isInteger("offset",s),void 0!==a&&t.isProjection("projection",a),void 0!==u&&t.isOrder("order",u),void 0!==c&&t.mustBeBoolean("multiple",c),void 0!==e.timeout&&t.isInteger("timeout",e.timeout),!0},t.isValidAggregation=function(t){if(1!==Object.keys(t).length)throw Y(lt(lt({},O),{message:"aggregation stage must have one key"}));return!0},t.isCentersPhere=function(e){if(Array.isArray(e)&&2===e.length){if("object"===A(e[0])&&e[0]._internalType===nt&&"number"==typeof e[1])return!0;if(Array.isArray(e[0])&&2===e[0].length){var n=e[0][0],r=e[0][1];if(t.isGeopoint("longitude",n),t.isGeopoint("latitude",r),"number"==typeof e[1])return!0}}throw new Error("".concat(o.CentersPhereError))},t}(),pt=function(){function t(t,e){ht.isGeopoint("longitude",t),ht.isGeopoint("latitude",e),this.longitude=t,this.latitude=e}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"Point",coordinates:[this.longitude,this.latitude]},e},t.prototype.toJSON=function(){return{type:"Point",coordinates:[this.longitude,this.latitude]}},t.prototype.toReadableString=function(){return"[".concat(this.longitude,",").concat(this.latitude,"]")},t.validate=function(t){return"Point"===t.type&&$(t.coordinates)&&ht.isGeopoint("longitude",t.coordinates[0])&&ht.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return nt},enumerable:!1,configurable:!0}),t}(),yt=function(){function t(t){if(!$(t))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t));if(t.length<2)throw new Error('"points" must contain 2 points at least');t.forEach(function(t){if(!(t instanceof pt))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t,"[]"))}),this.points=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"LineString",coordinates:this.points.map(function(t){return t.toJSON().coordinates})},e},t.prototype.toJSON=function(){return{type:"LineString",coordinates:this.points.map(function(t){return t.toJSON().coordinates})}},t.validate=function(t){var e,n;if("LineString"!==t.type||!$(t.coordinates))return!1;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!P(i[0])||!P(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},t.isClosed=function(t){var e=t.points[0],n=t.points[t.points.length-1];if(e.latitude===n.latitude&&e.longitude===n.longitude)return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return rt},enumerable:!1,configurable:!0}),t}(),gt=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},bt=function(){function t(t){if(!$(t))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach(function(t){if(!(t instanceof yt))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"));if(!yt.isClosed(t))throw new Error("LineString ".concat(t.points.map(function(t){return t.toReadableString()})," is not a closed cycle"))}),this.lines=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"Polygon",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})},e},t.prototype.toJSON=function(){return{type:"Polygon",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})}},t.validate=function(t){var e,n,r,o;if("Polygon"!==t.type||!$(t.coordinates))return!1;try{for(var i=gt(t.coordinates),s=i.next();!s.done;s=i.next()){var a=s.value;if(!this.isCloseLineString(a))return!1;try{for(var u=(r=void 0,gt(a)),c=u.next();!c.done;c=u.next()){var f=c.value;if(!P(f[0])||!P(f[1]))return!1}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=u.return)&&o.call(u)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},t.isCloseLineString=function(t){var e=t[0],n=t[t.length-1];return e[0]===n[0]&&e[1]===n[1]},Object.defineProperty(t.prototype,"_internalType",{get:function(){return ot},enumerable:!1,configurable:!0}),t}(),mt=function(){function t(t){if(!$(t))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t));if(0===t.length)throw new Error('"points" must contain 1 point at least');t.forEach(function(t){if(!(t instanceof pt))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t,"[]"))}),this.points=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiPoint",coordinates:this.points.map(function(t){return t.toJSON().coordinates})},e},t.prototype.toJSON=function(){return{type:"MultiPoint",coordinates:this.points.map(function(t){return t.toJSON().coordinates})}},t.validate=function(t){var e,n;if("MultiPoint"!==t.type||!$(t.coordinates))return!1;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!P(i[0])||!P(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return it},enumerable:!1,configurable:!0}),t}(),wt=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},vt=function(){function t(t){if(!$(t))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach(function(t){if(!(t instanceof yt))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"))}),this.lines=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiLineString",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})},e},t.prototype.toJSON=function(){return{type:"MultiLineString",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})}},t.validate=function(t){var e,n,r,o;if("MultiLineString"!==t.type||!$(t.coordinates))return!1;try{for(var i=wt(t.coordinates),s=i.next();!s.done;s=i.next()){var a=s.value;try{for(var u=(r=void 0,wt(a)),c=u.next();!c.done;c=u.next()){var f=c.value;if(!P(f[0])||!P(f[1]))return!1}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=u.return)&&o.call(u)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return st},enumerable:!1,configurable:!0}),t}(),_t=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ot=function(){function t(t){var e,n;if(!$(t))throw new TypeError('"polygons" must be of type Polygon[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("MultiPolygon must contain 1 polygon at least");try{for(var r=_t(t),o=r.next();!o.done;o=r.next()){var i=o.value;if(!(i instanceof bt))throw new TypeError('"polygon" must be of type Polygon[]. Received type '.concat(typeof i,"[]"))}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}this.polygons=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiPolygon",coordinates:this.polygons.map(function(t){return t.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})})},e},t.prototype.toJSON=function(){return{type:"MultiPolygon",coordinates:this.polygons.map(function(t){return t.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})})}},t.validate=function(t){var e,n,r,o,i,s;if("MultiPolygon"!==t.type||!$(t.coordinates))return!1;try{for(var a=_t(t.coordinates),u=a.next();!u.done;u=a.next()){var c=u.value;try{for(var f=(r=void 0,_t(c)),l=f.next();!l.done;l=f.next()){var d=l.value;try{for(var h=(i=void 0,_t(d)),p=h.next();!p.done;p=h.next()){var y=p.value;if(!P(y[0])||!P(y[1]))return!1}}catch(t){i={error:t}}finally{try{p&&!p.done&&(s=h.return)&&s.call(h)}finally{if(i)throw i.error}}}}catch(t){r={error:t}}finally{try{l&&!l.done&&(o=f.return)&&o.call(f)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return at},enumerable:!1,configurable:!0}),t}();!function(t){t.SET="set",t.REMOVE="remove",t.INC="inc",t.MUL="mul",t.PUSH="push",t.PULL="pull",t.PULL_ALL="pullAll",t.POP="pop",t.SHIFT="shift",t.UNSHIFT="unshift",t.ADD_TO_SET="addToSet",t.BIT="bit",t.RENAME="rename",t.MAX="max",t.MIN="min"}(Q||(Q={}));var Et,St=function(){function t(t,e,n){this._internalType=X,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||Z}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function Nt(t){return t&&t instanceof St&&t._internalType===X}!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(Et||(Et={}));var It=function(){function t(t,e,n){if(this._internalType=et,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||Z,this.fieldName!==Z)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,o=e.length;r<o;r++)(xt(i=e[r])||At(i))&&(e[r]=i._setFieldName(this.fieldName))}else{var i;(xt(i=e)||At(i))&&(e=i._setFieldName(this.fieldName))}}return t.prototype._setFieldName=function(e){var n=this.operands.map(function(n){return n instanceof t?n._setFieldName(e):n});return new t(this.operator,n,e)},t.prototype.and=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return r.unshift(this),new t(Et.AND,r,this.fieldName)},t.prototype.or=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return r.unshift(this),new t(Et.OR,r,this.fieldName)},t}();function xt(t){return t&&t instanceof It&&t._internalType===et}var Tt,Bt=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();!function(t){t.EQ="eq",t.NEQ="neq",t.GT="gt",t.GTE="gte",t.LT="lt",t.LTE="lte",t.IN="in",t.NIN="nin",t.ALL="all",t.ELEM_MATCH="elemMatch",t.EXISTS="exists",t.SIZE="size",t.MOD="mod",t.GEO_NEAR="geoNear",t.GEO_WITHIN="geoWithin",t.GEO_INTERSECTS="geoIntersects"}(Tt||(Tt={}));var jt=function(t){function e(e,n,r){var o=t.call(this,e,n,r)||this;return o.operator=e,o._internalType=tt,o}return Bt(e,t),e.prototype.toJSON=function(){var t,e,n;switch(this.operator){case Tt.IN:case Tt.NIN:return(t={})["$"+this.operator]=this.operands,t;case Tt.NEQ:return(e={}).$ne=this.operands[0],e;default:return(n={})["$"+this.operator]=this.operands[0],n}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(Tt.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(Tt.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(Tt.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(Tt.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(Tt.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(Tt.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(Tt.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(Tt.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof pt))throw new TypeError('"geometry" must be of type Point. Received type '.concat(typeof t.geometry));if(void 0!==t.maxDistance&&!P(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '.concat(typeof t.maxDistance));if(void 0!==t.minDistance&&!P(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '.concat(typeof t.minDistance));var n=new e(Tt.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof Ot||t.geometry instanceof bt||ht.isCentersPhere(t.centerSphere)))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(Tt.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof pt||t.geometry instanceof yt||t.geometry instanceof bt||t.geometry instanceof mt||t.geometry instanceof vt||t.geometry instanceof Ot))throw new TypeError('"geometry" must be of type Point, LineString, Polygon, MultiPoint, MultiLineString or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(Tt.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(It);function At(t){return t&&t instanceof jt&&t._internalType===tt}function Lt(t){return At(t)}var Pt={};for(var $t in Tt)Pt[$t]="$"+$t;for(var $t in Et)Pt[$t]="$"+$t;for(var $t in Q)Pt[$t]="$"+$t;function Ut(t){return Pt[t]||"$"+t}Pt[Tt.NEQ]="$ne",Pt[Q.REMOVE]="$unset",Pt[Q.SHIFT]="$pop",Pt[Q.UNSHIFT]="$push";var Rt=function(){function t(t){var e=(void 0===t?{}:t).offset,n=void 0===e?0:e;this.offset=n}return Object.defineProperty(t.prototype,"_internalType",{get:function(){return ut},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$tcb_server_date:{offset:this.offset}}},t}();function Dt(t){return new Rt(t)}var Ct=function(){return Ct=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ct.apply(this,arguments)},Ft=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},qt=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Mt(t){return kt(t,[t])}function kt(t,e){if(!D(t)){if(U(t))return t;if(R(t))return{$regularExpression:{pattern:t.source,options:t.flags}};if($(t))return t.map(function(t){if(e.indexOf(t)>-1)throw new Error("Cannot convert circular structure to JSON");return kt(t,qt(qt([],Ft(e),!1),[t],!1))});if(L(t)){var n=Ct({},t),r={};for(var o in n){if(e.indexOf(n[o])>-1)throw new Error("Cannot convert circular structure to JSON");void 0!==n[o]&&(r[o]=kt(n[o],qt(qt([],Ft(e),!1),[n[o]],!1)))}return r}return t}switch(t._internalType){case nt:return t.toJSON();case ut:case ct:case ft:return t.parse();default:return t.toJSON?t.toJSON():t}}var Wt=function(){return Wt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Wt.apply(this,arguments)},Jt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},Vt=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Ht(t,e,n,r){var o=Wt({},t);for(var i in t)if(!/^\$/.test(i)){var s=t[i];if(void 0!==s){if(s&&L(s)&&!e(s)){if(r.indexOf(s)>-1)throw new Error("Cannot convert circular structure to JSON");var a=Ht(s,e,Vt(Vt([],Jt(n),!1),[i],!1),Vt(Vt([],Jt(r),!1),[s],!1));o[i]=a;var u=!1;for(var c in a)/^\$/.test(c)?u=!0:(o["".concat(i,".").concat(c)]=a[c],delete o[i][c]);u||delete o[i]}}else delete o[i]}return o}function zt(t){return Ht(t,Yt,[],[t])}function Gt(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?$(t[r])?t[r].push(e[r]):L(t[r])?L(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is ".concat(A(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(A(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]}function Yt(t){return D(t)||U(t)||R(t)}function Kt(t){return Mt(t)}var Qt=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.encodeEJSON=function(e,n){var r=new t;return V(n?e:r.encodeUpdate(e))},t.prototype.encodeUpdate=function(t){return Nt(t)?this.encodeUpdateCommand(t):"object"===A(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===Z)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case Q.PUSH:case Q.PULL:case Q.PULL_ALL:case Q.POP:case Q.SHIFT:case Q.UNSHIFT:case Q.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,o,i=Ut(t.operator);return t.operator===Q.REMOVE?((e={})[i]=((n={})[t.fieldName]="",n),e):((r={})[i]=((o={})[t.fieldName]=t.operands[0],o),r)},t.prototype.encodeArrayUpdateCommand=function(t){var e,n,r,o,i,s,a,u,c,f,l=Ut(t.operator);switch(t.operator){case Q.PUSH:var d=void 0;return d=$(t.operands)?{$each:t.operands.map(Kt)}:t.operands,(e={})[l]=((n={})[t.fieldName]=d,n),e;case Q.UNSHIFT:return d={$each:t.operands.map(Kt),$position:0},(r={})[l]=((o={})[t.fieldName]=d,o),r;case Q.POP:return(i={})[l]=((s={})[t.fieldName]=1,s),i;case Q.SHIFT:return(a={})[l]=((u={})[t.fieldName]=-1,u),a;default:return(c={})[l]=((f={})[t.fieldName]=Kt(t.operands),f),c}},t.prototype.encodeUpdateObject=function(t){var e=zt(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(Nt(r))e[n]=r._setFieldName(n),Gt(e,this.encodeUpdateCommand(e[n]),n);else{e[n]=r=Kt(r);var o=new St(Q.SET,[r],n);Gt(e,this.encodeUpdateCommand(o),n)}}return e},t}(),Zt=function(){return Zt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Zt.apply(this,arguments)},Xt=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},te=function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},ee=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){return k(i._db).watch(Zt(Zt({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify({_id:i.id})}))},this._db=t,this._coll=e,this.id=r,this._transactionId=o,this.request=Se.createRequest(this._db.config),this._apiOptions=n}return t.prototype.create=function(t,e){return q(this._create(t),e)},t.prototype._create=function(t){return Xt(this,void 0,void 0,function(){var e,n,r;return te(this,function(o){switch(o.label){case 0:return!(e=Array.isArray(t))&&this.id&&(t._id=this.id),n={collectionName:this._coll,data:e?t.map(function(t){return V(Mt(t))}):[V(Mt(t))],transactionId:this._transactionId},[4,this.request.send("database.insertDocument",n,W(this._apiOptions))];case 1:return(r=o.sent()).code?[2,r]:this._transactionId?[2,{inserted:1,ok:1,id:r.data.insertedIds[0],requestId:r.requestId}]:e?[2,{ids:r.data&&r.data.insertedIds||[],requestId:r.requestId}]:[2,{id:r.data.insertedIds[0],requestId:r.requestId}]}})})},t.prototype.set=function(t,e){return q(this._set(t),e)},t.prototype._set=function(t){return Xt(this,void 0,void 0,function(){var e,n,r,o;return te(this,function(i){switch(i.label){case 0:return this.id?t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,K(this._db.config.throwOnCode,Zt(Zt({},O),{message:"不能更新_id的值"}))]:(e=!1,n=function(t){if("object"==typeof t)for(var r in t)t[r]instanceof St?e=!0:"object"==typeof t[r]&&n(t[r])},n(t),e?[2,K(this._db.config.throwOnCode,Zt(Zt({},S),{message:"update operator complicit"}))]:(r={collectionName:this._coll,queryType:a.DOC,data:V(Mt(t)),transactionId:this._transactionId,multi:!1,merge:!1,upsert:!0},this.id&&(r.query=V({_id:this.id})),[4,this.request.send("database.modifyDocument",r,W(this._apiOptions))])):[2,K(this._db.config.throwOnCode,Zt(Zt({},O),{message:"参数必需是非空对象"}))]:[2,K(this._db.config.throwOnCode,Zt(Zt({},O),{message:"docId不能为空"}))];case 1:return(o=i.sent()).code?[2,o]:this._transactionId?[2,{updated:o.data.updated,upserted:[{_id:o.data.upsert_id}],requestId:o.requestId}]:[2,{updated:o.data.updated,upsertedId:o.data.upsert_id,requestId:o.requestId}]}})})},t.prototype.update=function(t,e){return q(this._update(t),e)},t.prototype._update=function(t){return Xt(this,void 0,void 0,function(){var e,n,r;return te(this,function(o){switch(o.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,K(this._db.config.throwOnCode,Zt(Zt({},O),{message:"不能更新_id的值"}))]:(e=V({_id:this.id}),n={collectionName:this._coll,transactionId:this._transactionId,data:Qt.encodeEJSON(t,this._apiOptions.raw||!1),query:e,queryType:a.DOC,multi:!1,merge:!0,upsert:!1},[4,this.request.send("database.modifyDocument",n,W(this._apiOptions))]):[2,K(this._db.config.throwOnCode,Zt(Zt({},O),{message:"参数必需是非空对象"}))];case 1:return(r=o.sent()).code?[2,r]:[2,{updated:r.data.updated,requestId:r.requestId}]}})})},t.prototype.delete=function(t){return this.remove(t)},t.prototype.remove=function(t){return q(this._remove(),t)},t.prototype._remove=function(){return Xt(this,void 0,void 0,function(){var t,e,n;return te(this,function(r){switch(r.label){case 0:return t=V({_id:this.id}),e={collectionName:this._coll,transactionId:this._transactionId,query:t,queryType:a.DOC,multi:!1},[4,this.request.send("database.removeDocument",e,W(this._apiOptions))];case 1:return(n=r.sent()).code?[2,n]:[2,{deleted:n.data.deleted,requestId:n.requestId}]}})})},t.prototype.get=function(t){return q(this._get(),t)},t.prototype._get=function(){return Xt(this,void 0,void 0,function(){var t,e,n,r,o,i;return te(this,function(s){switch(s.label){case 0:return t=V({_id:this.id}),e=this._apiOptions.projection,n={collectionName:this._coll,query:t,transactionId:this._transactionId,queryType:a.DOC,multi:!1},e&&(n.projection=V(e)),[4,this.request.send("database.getDocument",n,W(this._apiOptions))];case 1:return(r=s.sent()).code?[2,r]:(o=r.data.list.map(function(t){return N.EJSON.parse(t)}),i=_.formatResDocumentData(o),this._transactionId?[2,{data:i[0]||null,requestId:r.requestId}]:[2,{data:i,requestId:r.requestId}])}})})},t.prototype.field=function(e){var n={};for(var r in e)"boolean"==typeof e[r]&&(n[r]=!0===e[r]?1:0),"number"==typeof e[r]&&(n[r]=e[r]>0?1:0),"object"==typeof e[r]&&(n[r]=e[r]);var o=Zt({},this._apiOptions);return o.projection=n,new t(this._db,this._coll,o,this.id,this._transactionId)},t}(),ne=function(){function t(){}return t.encode=function(t){return(new re).encodeQuery(t)},t.encodeEJSON=function(t,e){var n=new re;return V(e?t:n.encodeQuery(t))},t}(),re=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n,r,o;return Yt(t)?xt(t)?this.encodeLogicCommand(t):At(t)?this.encodeQueryCommand(t):R(t)?((n={})[e]=this.encodeRegExp(t),n):U(t)?((r={})[e]=Kt(t),r):((o={})[e]=this.encodeQueryObject(t),o):L(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regularExpression:{pattern:t.source,options:t.flags}}},t.prototype.encodeLogicCommand=function(t){var e,n,r,o,i,s,a,u=this;switch(t.operator){case Et.NOR:case Et.AND:case Et.OR:var c=Ut(t.operator),f=t.operands.map(function(e){return u.encodeQuery(e,t.fieldName)});return(e={})[c]=f,e;case Et.NOT:c=Ut(t.operator);var l=t.operands[0];return R(l)?((n={})[t.fieldName]=((r={})[c]=this.encodeRegExp(l),r),n):(f=this.encodeQuery(l)[t.fieldName],(o={})[t.fieldName]=((i={})[c]=f,i),o);default:if(c=Ut(t.operator),1===t.operands.length){var d=this.encodeQuery(t.operands[0]);return(s={})[c]=d,s}return f=t.operands.map(this.encodeQuery.bind(this)),(a={})[c]=f,a}},t.prototype.encodeQueryCommand=function(t){return Lt(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,o,i,s,a,u,c,f,l;if(t.fieldName===Z)throw new Error("Cannot encode a comparison command with unset field name");var d=Ut(t.operator);switch(t.operator){case Tt.EQ:case Tt.NEQ:case Tt.LT:case Tt.LTE:case Tt.GT:case Tt.GTE:case Tt.ELEM_MATCH:case Tt.EXISTS:case Tt.SIZE:case Tt.MOD:return(e={})[t.fieldName]=((n={})[d]=Kt(t.operands[0]),n),e;case Tt.IN:case Tt.NIN:case Tt.ALL:return(r={})[t.fieldName]=((o={})[d]=Kt(t.operands),o),r;case Tt.GEO_NEAR:var h=t.operands[0];return(i={})[t.fieldName]={$nearSphere:{$geometry:h.geometry.toJSON(),$maxDistance:h.maxDistance,$minDistance:h.minDistance}},i;case Tt.GEO_WITHIN:if((h=t.operands[0]).centerSphere){ht.isCentersPhere(h.centerSphere);var p=h.centerSphere;return p[0]._internalType===nt?((s={})[t.fieldName]={$geoWithin:{$centerSphere:[p[0].toJSON().coordinates,p[1]]}},s):((a={})[t.fieldName]={$geoWithin:{$centerSphere:h.centerSphere}},a)}return(u={})[t.fieldName]={$geoWithin:{$geometry:h.geometry.toJSON()}},u;case Tt.GEO_INTERSECTS:return h=t.operands[0],(c={})[t.fieldName]={$geoIntersects:{$geometry:h.geometry.toJSON()}},c;default:return(f={})[t.fieldName]=((l={})[d]=Kt(t.operands[0]),l),f}},t.prototype.encodeQueryObject=function(t){var e=zt(t);for(var n in e){var r=e[n];if(xt(r)){e[n]=r._setFieldName(n);var o=this.encodeLogicCommand(e[n]);this.mergeConditionAfterEncode(e,o,n)}else Lt(r)?(e[n]=r._setFieldName(n),o=this.encodeComparisonCommand(e[n]),this.mergeConditionAfterEncode(e,o,n)):Yt(r)&&(e[n]=Kt(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?$(t[r])?t[r]=t[r].concat(e[r]):L(t[r])?L(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is ".concat(A(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(A(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),oe=function(){return oe=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},oe.apply(this,arguments)},ie=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},se=function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},ae=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){var e=k(i._db),n=i._apiOptions,r=n.limit,o=n.order,s=o?Object.entries(o).reduce(function(t,e){var n=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(e,2),r=n[0],o=n[1];return t[r]=-1===o?"desc":"asc",t},{}):void 0;return e.watch(oe(oe({},t),{envId:i._db.config.env,collectionName:i._coll,query:z(i._fieldFilters),limit:r,orderBy:s}))},this._db=t,this._coll=e,this._fieldFilters=n,this._apiOptions=r||{},this._request=Se.createRequest(this._db.config),this._transactionId=o}return t.prototype.get=function(t){return q(this._get(),t)},t.prototype._get=function(){return ie(this,void 0,void 0,function(){var t,e,n,r,o,i,s,u,c;return se(this,function(f){switch(f.label){case 0:return t=this._apiOptions.order,e={collectionName:this._coll,queryType:a.WHERE,transactionId:this._transactionId},this._fieldFilters&&(e.query=this._fieldFilters),t&&(e.order=V(t)),(n=this._apiOptions.offset)&&(e.offset=n),r=this._apiOptions.limit,e.limit=r?r<1e3?r:1e3:100,(o=this._apiOptions.projection)&&(e.projection=V(o)),[4,this._request.send("database.getDocument",e,W(this._apiOptions))];case 1:return(i=f.sent()).code?[2,i]:(s=i.data.list.map(function(t){return N.EJSON.parse(t)}),u=_.formatResDocumentData(s),c={data:u,requestId:i.requestId},i.total&&(c.total=i.total),i.limit&&(c.limit=i.limit),i.offset&&(c.offset=i.offset),[2,c])}})})},t.prototype.count=function(t){return q(this._count(),t)},t.prototype._count=function(){return ie(this,void 0,void 0,function(){var t,e;return se(this,function(n){switch(n.label){case 0:return t={collectionName:this._coll,queryType:a.WHERE},this._fieldFilters&&(t.query=this._fieldFilters),[4,this._request.send("database.calculateDocument",t,W(this._apiOptions))];case 1:return(e=n.sent()).code?[2,e]:[2,{requestId:e.requestId,total:e.data.total}]}})})},t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(o.QueryParamTypeError);var n=Object.keys(e),r=n.some(function(t){return void 0!==e[t]});if(n.length&&!r)throw Error(o.QueryParamValueError);return new t(this._db,this._coll,ne.encodeEJSON(e,this._apiOptions.raw||!1),this._apiOptions,this._transactionId)},t.prototype.options=function(e){return ht.isValidOptions(e),new t(this._db,this._coll,this._fieldFilters,e,this._transactionId)},t.prototype.orderBy=function(e,n){var r;ht.isFieldPath(e),ht.isFieldOrder(n);var o=((r={})[e]="desc"===n?-1:1,r),i=this._apiOptions.order||{},s=Object.assign({},this._apiOptions,{order:Object.assign({},i,o)});return new t(this._db,this._coll,this._fieldFilters,s,this._transactionId)},t.prototype.limit=function(e){ht.isInteger("limit",e);var n=oe({},this._apiOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,n,this._transactionId)},t.prototype.skip=function(e){ht.isInteger("offset",e);var n=oe({},this._apiOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,n,this._transactionId)},t.prototype.update=function(t,e){return q(this._update(t),e)},t.prototype._update=function(t){return ie(this,void 0,void 0,function(){var e,n,r,o;return se(this,function(i){switch(i.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,K(this._db.config.throwOnCode,oe(oe({},O),{message:"不能更新_id的值"}))]:(e=this._apiOptions.multiple,n=void 0===e||e,r={collectionName:this._coll,queryType:a.WHERE,multi:n,merge:!0,upsert:!1,data:Qt.encodeEJSON(t,this._apiOptions.raw||!1)},this._transactionId&&(r.transactionId=this._transactionId),this._fieldFilters&&(r.query=this._fieldFilters),[4,this._request.send("database.modifyDocument",r,W(this._apiOptions))]):[2,K(this._db.config.throwOnCode,oe(oe({},O),{message:"参数必需是非空对象"}))];case 1:return(o=i.sent()).code?[2,o]:[2,{requestId:o.requestId,updated:o.data.updated,upsertId:o.data.upsert_id}]}})})},t.prototype.field=function(e){var n={};for(var r in e)"boolean"==typeof e[r]&&(n[r]=!0===e[r]?1:0),"number"==typeof e[r]&&(n[r]=e[r]>0?1:0),"object"==typeof e[r]&&(n[r]=e[r]);var o=oe({},this._apiOptions);return o.projection=n,new t(this._db,this._coll,this._fieldFilters,o,this._transactionId)},t.prototype.remove=function(t){return q(this._remove(),t)},t.prototype._remove=function(){return ie(this,void 0,void 0,function(){var t,e,n,r,o,i,s,u,c;return se(this,function(f){switch(f.label){case 0:return t=this._apiOptions,e=t.offset,n=t.limit,r=t.projection,o=t.order,void 0===e&&void 0===n&&void 0===r&&void 0===o||console.warn("`offset`, `limit`, `projection`, `orderBy` are not supported in remove() operation"),i=this._apiOptions.multiple,s=void 0===i||i,u={collectionName:this._coll,query:this._fieldFilters,queryType:a.WHERE,multi:s},this._transactionId&&(u.transactionId=this._transactionId),[4,this._request.send("database.removeDocument",u,W(this._apiOptions))];case 1:return(c=f.sent()).code?[2,c]:[2,{requestId:c.requestId,deleted:c.data.deleted}]}})})},t.prototype.updateAndReturn=function(t){return ie(this,void 0,void 0,function(){var e,n;return se(this,function(r){switch(r.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,K(this._db.config.throwOnCode,oe(oe({},O),{message:"不能更新_id的值"}))]:(e={collectionName:this._coll,queryType:a.WHERE,data:Qt.encodeEJSON(t,!1)},this._transactionId&&(e.transactionId=this._transactionId),this._fieldFilters&&(e.query=this._fieldFilters),[4,this._request.send("database.modifyAndReturnDoc",e,W(this._apiOptions))]):[2,K(this._db.config.throwOnCode,oe(oe({},O),{message:"参数必需是非空对象"}))];case 1:return(n=r.sent()).code?[2,n]:[2,{requestId:n.requestId,updated:n.data.updated,doc:n.data.doc&&N.EJSON.parse(n.data.doc)}]}})})},t}(),ue=function(){function t(t,e,n){var r=this;this._stages=[],t&&e&&(this._db=t,this._request=Se.createRequest(this._db.config),this._collectionName=e,n&&n.length>0&&n.forEach(function(t){ht.isValidAggregation(t);var e=Object.keys(t)[0];r._pipe(e,t[e],!0)}))}return t.prototype.end=function(){return t=this,e=void 0,r=function(){var t;return function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,function(e){switch(e.label){case 0:if(!this._collectionName||!this._db)throw new Error("Aggregation pipeline cannot send request");return[4,this._request.send("database.aggregateDocuments",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:t.data.list.map(N.EJSON.parse)}]:[2,t]}})},new((n=void 0)||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())});var t,e,n,r},t.prototype.unwrap=function(){return this._stages},t.prototype.done=function(){return this._stages.map(function(t){var e,n=t.stageKey,r=t.stageValue;return(e={})[n]=JSON.parse(r),e})},t.prototype._pipe=function(t,e,n){void 0===n&&(n=!1);var r;return r="object"===A(e)?V(e):JSON.stringify(e),this._stages.push({stageKey:n?t:"$".concat(t),stageValue:r}),this},t.prototype.addFields=function(t){return this._pipe("addFields",t)},t.prototype.bucket=function(t){return this._pipe("bucket",t)},t.prototype.bucketAuto=function(t){return this._pipe("bucketAuto",t)},t.prototype.count=function(t){return this._pipe("count",t)},t.prototype.geoNear=function(t){return t.query&&(t.query=ne.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new pt(t.near.longitude,t.near.latitude).toJSON()),this._pipe("geoNear",t)},t.prototype.group=function(t){return this._pipe("group",t)},t.prototype.limit=function(t){return this._pipe("limit",t)},t.prototype.match=function(t){return this._pipe("match",ne.encode(t))},t.prototype.project=function(t){return this._pipe("project",t)},t.prototype.lookup=function(t){return this._pipe("lookup",t)},t.prototype.replaceRoot=function(t){return this._pipe("replaceRoot",t)},t.prototype.sample=function(t){return this._pipe("sample",t)},t.prototype.skip=function(t){return this._pipe("skip",t)},t.prototype.sort=function(t){return this._pipe("sort",t)},t.prototype.sortByCount=function(t){return this._pipe("sortByCount",t)},t.prototype.unwind=function(t){return this._pipe("unwind",t)},t}();const ce=ue;var fe=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),le=function(t){function e(e,n,r,o){var i=t.call(this,e,n,"",r,o)||this;return o&&(i._transactionId=o),i}return fe(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!1,configurable:!0}),e.prototype.doc=function(t){if("string"!=typeof t&&"number"!=typeof t)throw new Error("docId必须为字符串或数字");return new ee(this._db,this._coll,this._apiOptions,t,this._transactionId)},e.prototype.add=function(t,e){return q(this._add(t),e)},e.prototype._add=function(t){return e=this,n=void 0,o=function(){var e,n,r;return function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,function(o){switch(o.label){case 0:return e=t,$(t)||(e=[t]),e=e.map(function(t){return V(Mt(t))}),n={collectionName:this._coll,data:e},this._transactionId&&(n.transactionId=this._transactionId),[4,this._request.send("database.insertDocument",n,W(this._apiOptions))];case 1:return(r=o.sent()).code?[2,r]:$(t)?[2,{ids:r.data.insertedIds,requestId:r.requestId}]:this._transactionId?[2,{inserted:1,ok:1,id:r.data.insertedIds[0],requestId:r.requestId}]:[2,{id:r.data.insertedIds[0],requestId:r.requestId}]}})},new((r=void 0)||(r=Promise))(function(t,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r(function(t){t(n)})).then(s,a)}u((o=o.apply(e,n||[])).next())});var e,n,r,o},e.prototype.aggregate=function(t){return void 0===t&&(t=[]),new ce(this._db,this._coll,this._apiOptions.raw?t:[])},e.prototype.options=function(t){return ht.isValidOptions(t),new e(this._db,this._coll,t,this._transactionId)},e}(ae),de={eq:function(t){return new jt(Tt.EQ,[t])},neq:function(t){return new jt(Tt.NEQ,[t])},lt:function(t){return new jt(Tt.LT,[t])},lte:function(t){return new jt(Tt.LTE,[t])},gt:function(t){return new jt(Tt.GT,[t])},gte:function(t){return new jt(Tt.GTE,[t])},in:function(t){return new jt(Tt.IN,t)},nin:function(t){return new jt(Tt.NIN,t)},all:function(t){return new jt(Tt.ALL,t)},elemMatch:function(t){return new jt(Tt.ELEM_MATCH,[t])},exists:function(t){return new jt(Tt.EXISTS,[t])},size:function(t){return new jt(Tt.SIZE,[t])},mod:function(){return new jt(Tt.MOD,1==arguments.length?[arguments[0]]:2==arguments.length?[[arguments[0],arguments[1]]]:arguments)},geoNear:function(t){return new jt(Tt.GEO_NEAR,[t])},geoWithin:function(t){return new jt(Tt.GEO_WITHIN,[t])},geoIntersects:function(t){return new jt(Tt.GEO_INTERSECTS,[t])},and:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=$(arguments[0])?arguments[0]:Array.from(arguments);return new It(Et.AND,n)},nor:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=$(arguments[0])?arguments[0]:Array.from(arguments);return new It(Et.NOR,n)},or:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=$(arguments[0])?arguments[0]:Array.from(arguments);return new It(Et.OR,n)},not:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=$(arguments[0])?arguments[0]:Array.from(arguments);return new It(Et.NOT,n)},set:function(t){return new St(Q.SET,[t])},remove:function(){return new St(Q.REMOVE,[])},inc:function(t){return new St(Q.INC,[t])},mul:function(t){return new St(Q.MUL,[t])},push:function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(L(e[0])&&e[0].hasOwnProperty("each")){t={};var r=e[0];void 0!==r.each&&(t.$each=r.each),void 0!==r.position&&(t.$position=r.position),void 0!==r.sort&&(t.$sort=r.sort),void 0!==r.slice&&(t.$slice=r.slice)}else t=$(e[0])?e[0]:Array.from(e);return new St(Q.PUSH,t)},pull:function(t){return new St(Q.PULL,t)},pullAll:function(t){return new St(Q.PULL_ALL,t)},pop:function(){return new St(Q.POP,[])},shift:function(){return new St(Q.SHIFT,[])},unshift:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=$(arguments[0])?arguments[0]:Array.from(arguments);return new St(Q.UNSHIFT,n)},addToSet:function(t){return new St(Q.ADD_TO_SET,t)},rename:function(t){return new St(Q.RENAME,[t])},bit:function(t){return new St(Q.BIT,[t])},max:function(t){return new St(Q.MAX,[t])},min:function(t){return new St(Q.MIN,[t])},expr:function(t){return{$expr:t}},jsonSchema:function(t){return{$jsonSchema:t}},text:function(t){return"string"===A(t)?{$search:t.search}:{$search:t.search,$language:t.language,$caseSensitive:t.caseSensitive,$diacriticSensitive:t.diacriticSensitive}},aggregate:{pipeline:function(){return new ce},abs:function(t){return new he("abs",t)},add:function(t){return new he("add",t)},ceil:function(t){return new he("ceil",t)},divide:function(t){return new he("divide",t)},exp:function(t){return new he("exp",t)},floor:function(t){return new he("floor",t)},ln:function(t){return new he("ln",t)},log:function(t){return new he("log",t)},log10:function(t){return new he("log10",t)},mod:function(t){return new he("mod",t)},multiply:function(t){return new he("multiply",t)},pow:function(t){return new he("pow",t)},sqrt:function(t){return new he("sqrt",t)},subtract:function(t){return new he("subtract",t)},trunc:function(t){return new he("trunc",t)},arrayElemAt:function(t){return new he("arrayElemAt",t)},arrayToObject:function(t){return new he("arrayToObject",t)},concatArrays:function(t){return new he("concatArrays",t)},filter:function(t){return new he("filter",t)},in:function(t){return new he("in",t)},indexOfArray:function(t){return new he("indexOfArray",t)},isArray:function(t){return new he("isArray",t)},map:function(t){return new he("map",t)},range:function(t){return new he("range",t)},reduce:function(t){return new he("reduce",t)},reverseArray:function(t){return new he("reverseArray",t)},size:function(t){return new he("size",t)},slice:function(t){return new he("slice",t)},zip:function(t){return new he("zip",t)},and:function(t){return new he("and",t)},not:function(t){return new he("not",t)},or:function(t){return new he("or",t)},cmp:function(t){return new he("cmp",t)},eq:function(t){return new he("eq",t)},gt:function(t){return new he("gt",t)},gte:function(t){return new he("gte",t)},lt:function(t){return new he("lt",t)},lte:function(t){return new he("lte",t)},neq:function(t){return new he("ne",t)},cond:function(t){return new he("cond",t)},ifNull:function(t){return new he("ifNull",t)},switch:function(t){return new he("switch",t)},dateFromParts:function(t){return new he("dateFromParts",t)},dateFromString:function(t){return new he("dateFromString",t)},dayOfMonth:function(t){return new he("dayOfMonth",t)},dayOfWeek:function(t){return new he("dayOfWeek",t)},dayOfYear:function(t){return new he("dayOfYear",t)},isoDayOfWeek:function(t){return new he("isoDayOfWeek",t)},isoWeek:function(t){return new he("isoWeek",t)},isoWeekYear:function(t){return new he("isoWeekYear",t)},millisecond:function(t){return new he("millisecond",t)},minute:function(t){return new he("minute",t)},month:function(t){return new he("month",t)},second:function(t){return new he("second",t)},hour:function(t){return new he("hour",t)},week:function(t){return new he("week",t)},year:function(t){return new he("year",t)},literal:function(t){return new he("literal",t)},mergeObjects:function(t){return new he("mergeObjects",t)},objectToArray:function(t){return new he("objectToArray",t)},allElementsTrue:function(t){return new he("allElementsTrue",t)},anyElementTrue:function(t){return new he("anyElementTrue",t)},setDifference:function(t){return new he("setDifference",t)},setEquals:function(t){return new he("setEquals",t)},setIntersection:function(t){return new he("setIntersection",t)},setIsSubset:function(t){return new he("setIsSubset",t)},setUnion:function(t){return new he("setUnion",t)},concat:function(t){return new he("concat",t)},dateToString:function(t){return new he("dateToString",t)},indexOfBytes:function(t){return new he("indexOfBytes",t)},indexOfCP:function(t){return new he("indexOfCP",t)},split:function(t){return new he("split",t)},strLenBytes:function(t){return new he("strLenBytes",t)},strLenCP:function(t){return new he("strLenCP",t)},strcasecmp:function(t){return new he("strcasecmp",t)},substr:function(t){return new he("substr",t)},substrBytes:function(t){return new he("substrBytes",t)},substrCP:function(t){return new he("substrCP",t)},toLower:function(t){return new he("toLower",t)},toUpper:function(t){return new he("toUpper",t)},meta:function(t){return new he("meta",t)},addToSet:function(t){return new he("addToSet",t)},avg:function(t){return new he("avg",t)},first:function(t){return new he("first",t)},last:function(t){return new he("last",t)},max:function(t){return new he("max",t)},min:function(t){return new he("min",t)},push:function(t){return new he("push",t)},stdDevPop:function(t){return new he("stdDevPop",t)},stdDevSamp:function(t){return new he("stdDevSamp",t)},sum:function(t){return new he("sum",t)},let:function(t){return new he("let",t)}},project:{slice:function(t){return new pe("slice",t)},elemMatch:function(t){return new pe("elemMatch",t)}}},he=function(t,e){this["$"+t]=e},pe=function(t,e){this["$"+t]=e},ye=function(){function t(t){var e=t.regexp,n=t.options;if(!e)throw new TypeError("regexp must be a string");this.$regularExpression={pattern:e||"",options:n||""}}return t.prototype.parse=function(){return{$regularExpression:{pattern:this.$regularExpression.pattern,options:this.$regularExpression.options}}},Object.defineProperty(t.prototype,"_internalType",{get:function(){return ct},enumerable:!1,configurable:!0}),t}();function ge(t){return new ye(t)}var be=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},me=function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},we=function(){function t(t){this._db=t,this._request=Se.createRequest(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return t.prototype.init=function(){return be(this,void 0,void 0,function(){var t;return me(this,function(e){switch(e.label){case 0:return[4,this._request.send("database.startTransaction")];case 1:if((t=e.sent()).code)throw t;return this.inited=!0,this._id=t.transactionId,[2]}})})},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new le(this._db,t,{},this._id)},t.prototype.getTransactionId=function(){return this._id},t.prototype.getRequestMethod=function(){return this._request},t.prototype.commit=function(){return be(this,void 0,void 0,function(){var t,e;return me(this,function(n){switch(n.label){case 0:return t={transactionId:this._id},[4,this._request.send("database.commitTransaction",t)];case 1:if((e=n.sent()).code)throw e;return this.commited=!0,[2,e]}})})},t.prototype.rollback=function(t){return be(this,void 0,void 0,function(){var e,n;return me(this,function(r){switch(r.label){case 0:return e={transactionId:this._id},[4,this._request.send("database.abortTransaction",e)];case 1:if((n=r.sent()).code)throw n;return this.aborted=!0,this.abortReason=t,[2,n]}})})},t}();function ve(){return be(this,void 0,void 0,function(){var t;return me(this,function(e){switch(e.label){case 0:return[4,(t=new we(this)).init()];case 1:return e.sent(),[2,t]}})})}function _e(t,e){return void 0===e&&(e=3),be(this,void 0,void 0,function(){var n,r,o,i,s=this;return me(this,function(a){switch(a.label){case 0:return a.trys.push([0,4,,10]),[4,(n=new we(this)).init()];case 1:return a.sent(),[4,t(n)];case 2:if(r=a.sent(),!0===n.aborted)throw n.abortReason;return[4,n.commit()];case 3:return a.sent(),[2,r];case 4:if(o=a.sent(),!1===n.inited)throw o;return i=function(t){return be(s,void 0,void 0,function(){return me(this,function(e){switch(e.label){case 0:if(n.aborted||n.commited)return[3,5];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,n.rollback()];case 2:case 3:return e.sent(),[3,4];case 4:throw t;case 5:if(!0===n.aborted)throw n.abortReason;throw t}})})},e<=0?[4,i(o)]:[3,6];case 5:a.sent(),a.label=6;case 6:return o&&o.code===E?[4,_e.bind(this)(t,--e)]:[3,8];case 7:return[2,a.sent()];case 8:return[4,i(o)];case 9:return a.sent(),[3,10];case 10:return[2]}})})}var Oe=function(){function t(t){var e=(void 0===t?{}:t).id,n=void 0===e?"":e;this.id=n}return Object.defineProperty(t.prototype,"_internalType",{get:function(){return ft},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$oid:this.id}},t}();function Ee(t){return new Oe(t)}var Se=function(){function t(t){this.config=t,this.Geo=i,this.serverDate=Dt,this.command=de,this.RegExp=ge,this.ObjectId=Ee,this.startTransaction=ve,this.runTransaction=_e,this.logicCommand=It,this.updateCommand=St,this.queryCommand=jt}return t.createRequest=function(e){var n=new t.reqClass(e),r=n.send;return n.send=function(t,n){for(var o=[],i=2;i<arguments.length;i++)o[i-2]=arguments[i];return n&&(e.instance&&(n.instance=e.instance),e.database&&(n.database=e.database)),r.call.apply(r,function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([this,t,n],function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(o),!1))},n},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new le(this,t)},t.prototype.createCollection=function(e){var n={collectionName:e};return t.createRequest(this.config).send("database.addCollection",n)},t}()},949:(t,e,n)=>{"use strict";function r(t){this.message=t}n.r(e),n.d(e,{InvalidTokenError:()=>s,default:()=>a}),r.prototype=new Error,r.prototype.name="InvalidCharacterError";var o="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new r("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,i=0,s=0,a="";o=e.charAt(s++);~o&&(n=i%4?64*n+o:o,i++%4)?a+=String.fromCharCode(255&n>>(-2*i&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return a};function i(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(o(t).replace(/(.)/g,function(t,e){var n=e.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n}))}(e)}catch(t){return o(e)}}function s(t){this.message=t}s.prototype=new Error,s.prototype.name="InvalidTokenError";const a=function(t,e){if("string"!=typeof t)throw new s("Invalid token specified");var n=!0===(e=e||{}).header?0:1;try{return JSON.parse(i(t.split(".")[n]))}catch(t){throw new s("Invalid token specified: "+t.message)}}},273:()=>{},804:(t,e,n)=>{"use strict";n.r(e),n.d(e,{BSON:()=>Ve,BSONError:()=>W,BSONOffsetError:()=>H,BSONRegExp:()=>zt,BSONRuntimeError:()=>V,BSONSymbol:()=>Gt,BSONType:()=>k,BSONValue:()=>rt,BSONVersionError:()=>J,Binary:()=>ut,Code:()=>ht,DBRef:()=>yt,Decimal128:()=>Dt,Double:()=>Ct,EJSON:()=>Pe,Int32:()=>Ft,Long:()=>St,MaxKey:()=>qt,MinKey:()=>Mt,ObjectId:()=>Jt,Timestamp:()=>Kt,UUID:()=>dt,calculateObjectSize:()=>We,deserialize:()=>ke,deserializeStream:()=>Je,onDemand:()=>Re,serialize:()=>qe,serializeWithBufferAndIndex:()=>Me,setInternalBufferSize:()=>Fe});var r=n(273);const o=(()=>{const t=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),Symbol.toStringTag).get;return e=>t.call(e)})();function i(t){return"Uint8Array"===o(t)}function s(t){return"object"==typeof t&&null!=t&&Symbol.toStringTag in t&&("ArrayBuffer"===t[Symbol.toStringTag]||"SharedArrayBuffer"===t[Symbol.toStringTag])}function a(t){return t instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(t)}function u(t){return"object"==typeof t&&null!=t&&Symbol.toStringTag in t&&"Map"===t[Symbol.toStringTag]}function c(t){return t instanceof Date||"[object Date]"===Object.prototype.toString.call(t)}function f(t,e){return JSON.stringify(t,(t,e)=>"bigint"==typeof e?{$numberLong:`${e}`}:u(e)?Object.fromEntries(e):e)}const l=6,d=Symbol.for("@@mdb.bson.version"),h=2147483647,p=-2147483648,y=Math.pow(2,63)-1,g=-Math.pow(2,63),b=Math.pow(2,53),m=-Math.pow(2,53),w=1,v=2,_=3,O=4,E=5,S=6,N=7,I=8,x=9,T=10,B=11,j=12,A=13,L=14,P=15,$=16,U=17,R=18,D=19,C=255,F=127,q=0,M=4,k=Object.freeze({double:1,string:2,object:3,array:4,binData:5,undefined:6,objectId:7,bool:8,date:9,null:10,regex:11,dbPointer:12,javascript:13,symbol:14,javascriptWithScope:15,int:16,timestamp:17,long:18,decimal:19,minKey:-1,maxKey:127});class W extends Error{get bsonError(){return!0}get name(){return"BSONError"}constructor(t,e){super(t,e)}static isBSONError(t){return null!=t&&"object"==typeof t&&"bsonError"in t&&!0===t.bsonError&&"name"in t&&"message"in t&&"stack"in t}}class J extends W{get name(){return"BSONVersionError"}constructor(){super(`Unsupported BSON version, bson types must be from bson ${l}.x.x`)}}class V extends W{get name(){return"BSONRuntimeError"}constructor(t){super(t)}}class H extends W{get name(){return"BSONOffsetError"}constructor(t,e,n){super(`${t}. offset: ${e}`,n),this.offset=e}}let z,G;function Y(t,e,n,r){if(r){z??=new TextDecoder("utf8",{fatal:!0});try{return z.decode(t.subarray(e,n))}catch(t){throw new W("Invalid UTF-8 string in BSON document",{cause:t})}}return G??=new TextDecoder("utf8",{fatal:!1}),G.decode(t.subarray(e,n))}function K(t,e,n){if(0===t.length)return"";const r=n-e;if(0===r)return"";if(r>20)return null;if(1===r&&t[e]<128)return String.fromCharCode(t[e]);if(2===r&&t[e]<128&&t[e+1]<128)return String.fromCharCode(t[e])+String.fromCharCode(t[e+1]);if(3===r&&t[e]<128&&t[e+1]<128&&t[e+2]<128)return String.fromCharCode(t[e])+String.fromCharCode(t[e+1])+String.fromCharCode(t[e+2]);const o=[];for(let r=e;r<n;r++){const e=t[r];if(e>127)return null;o.push(e)}return String.fromCharCode(...o)}const Q={toLocalBufferType(t){if(Buffer.isBuffer(t))return t;if(ArrayBuffer.isView(t))return Buffer.from(t.buffer,t.byteOffset,t.byteLength);const e=t?.[Symbol.toStringTag]??Object.prototype.toString.call(t);if("ArrayBuffer"===e||"SharedArrayBuffer"===e||"[object ArrayBuffer]"===e||"[object SharedArrayBuffer]"===e)return Buffer.from(t);throw new W("Cannot create Buffer from the passed potentialBuffer.")},allocate:t=>Buffer.alloc(t),allocateUnsafe:t=>Buffer.allocUnsafe(t),equals:(t,e)=>Q.toLocalBufferType(t).equals(e),fromNumberArray:t=>Buffer.from(t),fromBase64:t=>Buffer.from(t,"base64"),toBase64:t=>Q.toLocalBufferType(t).toString("base64"),fromISO88591:t=>Buffer.from(t,"binary"),toISO88591:t=>Q.toLocalBufferType(t).toString("binary"),fromHex:t=>Buffer.from(t,"hex"),toHex:t=>Q.toLocalBufferType(t).toString("hex"),toUTF8(t,e,n,r){const o=n-e<=20?K(t,e,n):null;if(null!=o)return o;const i=Q.toLocalBufferType(t).toString("utf8",e,n);if(r)for(let r=0;r<i.length;r++)if(65533===i.charCodeAt(r)){Y(t,e,n,!0);break}return i},utf8ByteLength:t=>Buffer.byteLength(t,"utf8"),encodeUTF8Into(t,e,n){const r=function(t,e,n){if(0===e.length)return 0;if(e.length>25)return null;if(t.length-n<e.length)return null;for(let r=0,o=n;r<e.length;r++,o++){const n=e.charCodeAt(r);if(n>127)return null;t[o]=n}return e.length}(t,e,n);return null!=r?r:Q.toLocalBufferType(t).write(e,n,void 0,"utf8")},randomBytes:r.randomBytes,swap32:t=>Q.toLocalBufferType(t).swap32()};function Z(t){if(t<0)throw new RangeError(`The argument 'byteLength' is invalid. Received ${t}`);return et.fromNumberArray(Array.from({length:t},()=>Math.floor(256*Math.random())))}const X=(()=>{const{crypto:t}=globalThis;if(null!=t&&"function"==typeof t.getRandomValues)return e=>t.getRandomValues(et.allocate(e));if(function(){const{navigator:t}=globalThis;return"object"==typeof t&&"ReactNative"===t.product}()){const{console:t}=globalThis;t?.warn?.("BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.")}return Z})(),tt=/(\d|[a-f])/i,et={toLocalBufferType(t){const e=t?.[Symbol.toStringTag]??Object.prototype.toString.call(t);if("Uint8Array"===e)return t;if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength));if("ArrayBuffer"===e||"SharedArrayBuffer"===e||"[object ArrayBuffer]"===e||"[object SharedArrayBuffer]"===e)return new Uint8Array(t);throw new W("Cannot make a Uint8Array from passed potentialBuffer.")},allocate(t){if("number"!=typeof t)throw new TypeError(`The "size" argument must be of type number. Received ${String(t)}`);return new Uint8Array(t)},allocateUnsafe:t=>et.allocate(t),equals(t,e){if(t.byteLength!==e.byteLength)return!1;for(let n=0;n<t.byteLength;n++)if(t[n]!==e[n])return!1;return!0},fromNumberArray:t=>Uint8Array.from(t),fromBase64:t=>Uint8Array.from(atob(t),t=>t.charCodeAt(0)),toBase64:t=>btoa(et.toISO88591(t)),fromISO88591:t=>Uint8Array.from(t,t=>255&t.charCodeAt(0)),toISO88591:t=>Array.from(Uint16Array.from(t),t=>String.fromCharCode(t)).join(""),fromHex(t){const e=t.length%2==0?t:t.slice(0,t.length-1),n=[];for(let t=0;t<e.length;t+=2){const r=e[t],o=e[t+1];if(!tt.test(r))break;if(!tt.test(o))break;const i=Number.parseInt(`${r}${o}`,16);n.push(i)}return Uint8Array.from(n)},toHex:t=>Array.from(t,t=>t.toString(16).padStart(2,"0")).join(""),toUTF8(t,e,n,r){const o=n-e<=20?K(t,e,n):null;return null!=o?o:Y(t,e,n,r)},utf8ByteLength:t=>(new TextEncoder).encode(t).byteLength,encodeUTF8Into(t,e,n){const r=(new TextEncoder).encode(e);return t.set(r,n),r.byteLength},randomBytes:X,swap32(t){if(t.length%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t.length;e+=4){const n=t[e],r=t[e+1],o=t[e+2],i=t[e+3];t[e]=i,t[e+1]=o,t[e+2]=r,t[e+3]=n}return t}},nt="function"==typeof Buffer&&!0!==Buffer.prototype?._isBuffer?Q:et;class rt{get[d](){return l}[Symbol.for("nodejs.util.inspect.custom")](t,e,n){return this.inspect(t,e,n)}}const ot=new Float64Array(1),it=new Uint8Array(ot.buffer,0,8);ot[0]=-1;const st=0===it[7],at={isBigEndian:st,getNonnegativeInt32LE(t,e){if(t[e+3]>127)throw new RangeError(`Size cannot be negative at offset: ${e}`);return t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24},getInt32LE:(t,e)=>t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24,getUint32LE:(t,e)=>t[e]+256*t[e+1]+65536*t[e+2]+16777216*t[e+3],getUint32BE:(t,e)=>t[e+3]+256*t[e+2]+65536*t[e+1]+16777216*t[e],getBigInt64LE(t,e){const n=BigInt(t[e+4]+256*t[e+5]+65536*t[e+6]+(t[e+7]<<24)),r=BigInt(t[e]+256*t[e+1]+65536*t[e+2]+16777216*t[e+3]);return(n<<BigInt(32))+r},getFloat64LE:st?(t,e)=>(it[7]=t[e],it[6]=t[e+1],it[5]=t[e+2],it[4]=t[e+3],it[3]=t[e+4],it[2]=t[e+5],it[1]=t[e+6],it[0]=t[e+7],ot[0]):(t,e)=>(it[0]=t[e],it[1]=t[e+1],it[2]=t[e+2],it[3]=t[e+3],it[4]=t[e+4],it[5]=t[e+5],it[6]=t[e+6],it[7]=t[e+7],ot[0]),setInt32BE:(t,e,n)=>(t[e+3]=n,n>>>=8,t[e+2]=n,n>>>=8,t[e+1]=n,n>>>=8,t[e]=n,4),setInt32LE:(t,e,n)=>(t[e]=n,n>>>=8,t[e+1]=n,n>>>=8,t[e+2]=n,n>>>=8,t[e+3]=n,4),setBigInt64LE(t,e,n){const r=BigInt(4294967295);let o=Number(n&r);t[e]=o,o>>=8,t[e+1]=o,o>>=8,t[e+2]=o,o>>=8,t[e+3]=o;let i=Number(n>>BigInt(32)&r);return t[e+4]=i,i>>=8,t[e+5]=i,i>>=8,t[e+6]=i,i>>=8,t[e+7]=i,8},setFloat64LE:st?(t,e,n)=>(ot[0]=n,t[e]=it[7],t[e+1]=it[6],t[e+2]=it[5],t[e+3]=it[4],t[e+4]=it[3],t[e+5]=it[2],t[e+6]=it[1],t[e+7]=it[0],8):(t,e,n)=>(ot[0]=n,t[e]=it[0],t[e+1]=it[1],t[e+2]=it[2],t[e+3]=it[3],t[e+4]=it[4],t[e+5]=it[5],t[e+6]=it[6],t[e+7]=it[7],8)};class ut extends rt{get _bsontype(){return"Binary"}constructor(t,e){if(super(),null!=t&&"string"==typeof t&&!ArrayBuffer.isView(t)&&!s(t)&&!Array.isArray(t))throw new W("Binary can only be constructed from Uint8Array or number[]");this.sub_type=e??ut.BSON_BINARY_SUBTYPE_DEFAULT,null==t?(this.buffer=nt.allocate(ut.BUFFER_SIZE),this.position=0):(this.buffer=Array.isArray(t)?nt.fromNumberArray(t):nt.toLocalBufferType(t),this.position=this.buffer.byteLength)}put(t){if("string"==typeof t&&1!==t.length)throw new W("only accepts single character String");if("number"!=typeof t&&1!==t.length)throw new W("only accepts single character Uint8Array or Array");let e;if(e="string"==typeof t?t.charCodeAt(0):"number"==typeof t?t:t[0],e<0||e>255)throw new W("only accepts number in a valid unsigned byte range 0-255");if(this.buffer.byteLength>this.position)this.buffer[this.position++]=e;else{const t=nt.allocate(ut.BUFFER_SIZE+this.buffer.length);t.set(this.buffer,0),this.buffer=t,this.buffer[this.position++]=e}}write(t,e){if(e="number"==typeof e?e:this.position,this.buffer.byteLength<e+t.length){const e=nt.allocate(this.buffer.byteLength+t.length);e.set(this.buffer,0),this.buffer=e}if(ArrayBuffer.isView(t))this.buffer.set(nt.toLocalBufferType(t),e),this.position=e+t.byteLength>this.position?e+t.length:this.position;else if("string"==typeof t)throw new W("input cannot be string")}read(t,e){const n=t+(e=e&&e>0?e:this.position);return this.buffer.subarray(t,n>this.position?this.position:n)}value(){return this.buffer.length===this.position?this.buffer:this.buffer.subarray(0,this.position)}length(){return this.position}toJSON(){return nt.toBase64(this.buffer.subarray(0,this.position))}toString(t){return"hex"===t?nt.toHex(this.buffer.subarray(0,this.position)):"base64"===t?nt.toBase64(this.buffer.subarray(0,this.position)):nt.toUTF8(this.buffer,0,this.position,!1)}toExtendedJSON(t){t=t||{},this.sub_type===ut.SUBTYPE_VECTOR&&ct(this);const e=nt.toBase64(this.buffer),n=Number(this.sub_type).toString(16);return t.legacy?{$binary:e,$type:1===n.length?"0"+n:n}:{$binary:{base64:e,subType:1===n.length?"0"+n:n}}}toUUID(){if(this.sub_type===ut.SUBTYPE_UUID)return new dt(this.buffer.subarray(0,this.position));throw new W(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${ut.SUBTYPE_UUID}" is currently supported.`)}static createFromHexString(t,e){return new ut(nt.fromHex(t),e)}static createFromBase64(t,e){return new ut(nt.fromBase64(t),e)}static fromExtendedJSON(t,e){let n,r;if(e=e||{},"$binary"in t?e.legacy&&"string"==typeof t.$binary&&"$type"in t?(r=t.$type?parseInt(t.$type,16):0,n=nt.fromBase64(t.$binary)):"string"!=typeof t.$binary&&(r=t.$binary.subType?parseInt(t.$binary.subType,16):0,n=nt.fromBase64(t.$binary.base64)):"$uuid"in t&&(r=4,n=dt.bytesFromString(t.$uuid)),!n)throw new W(`Unexpected Binary Extended JSON format ${JSON.stringify(t)}`);return r===M?new dt(n):new ut(n,r)}inspect(t,e,n){return n??=f,`Binary.createFromBase64(${n(nt.toBase64(this.buffer.subarray(0,this.position)),e)}, ${n(this.sub_type,e)})`}toInt8Array(){if(this.sub_type!==ut.SUBTYPE_VECTOR)throw new W("Binary sub_type is not Vector");if(this.buffer[0]!==ut.VECTOR_TYPE.Int8)throw new W("Binary datatype field is not Int8");return ct(this),new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toFloat32Array(){if(this.sub_type!==ut.SUBTYPE_VECTOR)throw new W("Binary sub_type is not Vector");if(this.buffer[0]!==ut.VECTOR_TYPE.Float32)throw new W("Binary datatype field is not Float32");ct(this);const t=new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position));return at.isBigEndian&&nt.swap32(t),new Float32Array(t.buffer)}toPackedBits(){if(this.sub_type!==ut.SUBTYPE_VECTOR)throw new W("Binary sub_type is not Vector");if(this.buffer[0]!==ut.VECTOR_TYPE.PackedBit)throw new W("Binary datatype field is not packed bit");return ct(this),new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toBits(){if(this.sub_type!==ut.SUBTYPE_VECTOR)throw new W("Binary sub_type is not Vector");if(this.buffer[0]!==ut.VECTOR_TYPE.PackedBit)throw new W("Binary datatype field is not packed bit");ct(this);const t=8*(this.length()-2)-this.buffer[1],e=new Int8Array(t);for(let t=0;t<e.length;t++){const n=t/8|0,r=this.buffer[n+2]>>7-t%8&1;e[t]=r}return e}static fromInt8Array(t){const e=nt.allocate(t.byteLength+2);e[0]=ut.VECTOR_TYPE.Int8,e[1]=0;const n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);e.set(n,2);const r=new this(e,this.SUBTYPE_VECTOR);return ct(r),r}static fromFloat32Array(t){const e=nt.allocate(t.byteLength+2);e[0]=ut.VECTOR_TYPE.Float32,e[1]=0;const n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);e.set(n,2),at.isBigEndian&&nt.swap32(new Uint8Array(e.buffer,2));const r=new this(e,this.SUBTYPE_VECTOR);return ct(r),r}static fromPackedBits(t,e=0){const n=nt.allocate(t.byteLength+2);n[0]=ut.VECTOR_TYPE.PackedBit,n[1]=e,n.set(t,2);const r=new this(n,this.SUBTYPE_VECTOR);return ct(r),r}static fromBits(t){const e=t.length+7>>>3,n=new Uint8Array(e+2);n[0]=ut.VECTOR_TYPE.PackedBit;const r=t.length%8;n[1]=0===r?0:8-r;for(let e=0;e<t.length;e++){const r=e>>>3,o=t[e];if(0!==o&&1!==o)throw new W(`Invalid bit value at ${e}: must be 0 or 1, found ${t[e]}`);if(0===o)continue;const i=7-e%8;n[r+2]|=o<<i}return new this(n,ut.SUBTYPE_VECTOR)}}function ct(t){if(t.sub_type!==ut.SUBTYPE_VECTOR)return;const e=t.position,n=t.buffer[0],r=t.buffer[1];if((n===ut.VECTOR_TYPE.Float32||n===ut.VECTOR_TYPE.Int8)&&0!==r)throw new W("Invalid Vector: padding must be zero for int8 and float32 vectors");if(n===ut.VECTOR_TYPE.Float32&&0!==e&&e-2!=0&&(e-2)%4!=0)throw new W("Invalid Vector: Float32 vector must contain a multiple of 4 bytes");if(n===ut.VECTOR_TYPE.PackedBit&&0!==r&&2===e)throw new W("Invalid Vector: padding must be zero for packed bit vectors that are empty");if(n===ut.VECTOR_TYPE.PackedBit&&r>7)throw new W(`Invalid Vector: padding must be a value between 0 and 7. found: ${r}`)}ut.BSON_BINARY_SUBTYPE_DEFAULT=0,ut.BUFFER_SIZE=256,ut.SUBTYPE_DEFAULT=0,ut.SUBTYPE_FUNCTION=1,ut.SUBTYPE_BYTE_ARRAY=2,ut.SUBTYPE_UUID_OLD=3,ut.SUBTYPE_UUID=4,ut.SUBTYPE_MD5=5,ut.SUBTYPE_ENCRYPTED=6,ut.SUBTYPE_COLUMN=7,ut.SUBTYPE_SENSITIVE=8,ut.SUBTYPE_VECTOR=9,ut.SUBTYPE_USER_DEFINED=128,ut.VECTOR_TYPE=Object.freeze({Int8:3,Float32:39,PackedBit:16});const ft=/^[0-9A-F]{32}$/i,lt=/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;class dt extends ut{constructor(t){let e;if(null==t)e=dt.generate();else if(t instanceof dt)e=nt.toLocalBufferType(new Uint8Array(t.buffer));else if(ArrayBuffer.isView(t)&&16===t.byteLength)e=nt.toLocalBufferType(t);else{if("string"!=typeof t)throw new W("Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).");e=dt.bytesFromString(t)}super(e,M)}get id(){return this.buffer}set id(t){this.buffer=t}toHexString(t=!0){return t?[nt.toHex(this.buffer.subarray(0,4)),nt.toHex(this.buffer.subarray(4,6)),nt.toHex(this.buffer.subarray(6,8)),nt.toHex(this.buffer.subarray(8,10)),nt.toHex(this.buffer.subarray(10,16))].join("-"):nt.toHex(this.buffer)}toString(t){return"hex"===t?nt.toHex(this.id):"base64"===t?nt.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(t){if(!t)return!1;if(t instanceof dt)return nt.equals(t.id,this.id);try{return nt.equals(new dt(t).id,this.id)}catch{return!1}}toBinary(){return new ut(this.id,ut.SUBTYPE_UUID)}static generate(){const t=nt.randomBytes(16);return t[6]=15&t[6]|64,t[8]=63&t[8]|128,t}static isValid(t){return!!t&&("string"==typeof t?dt.isValidUUIDString(t):i(t)?16===t.byteLength:"Binary"===t._bsontype&&t.sub_type===this.SUBTYPE_UUID&&16===t.buffer.byteLength)}static createFromHexString(t){const e=dt.bytesFromString(t);return new dt(e)}static createFromBase64(t){return new dt(nt.fromBase64(t))}static bytesFromString(t){if(!dt.isValidUUIDString(t))throw new W("UUID string representation must be 32 hex digits or canonical hyphenated representation");return nt.fromHex(t.replace(/-/g,""))}static isValidUUIDString(t){return ft.test(t)||lt.test(t)}inspect(t,e,n){return n??=f,`new UUID(${n(this.toHexString(),e)})`}}class ht extends rt{get _bsontype(){return"Code"}constructor(t,e){super(),this.code=t.toString(),this.scope=e??null}toJSON(){return null!=this.scope?{code:this.code,scope:this.scope}:{code:this.code}}toExtendedJSON(){return this.scope?{$code:this.code,$scope:this.scope}:{$code:this.code}}static fromExtendedJSON(t){return new ht(t.$code,t.$scope)}inspect(t,e,n){n??=f;let r=n(this.code,e);const o=r.includes("\n");return null!=this.scope&&(r+=`,${o?"\n":" "}${n(this.scope,e)}`),`new Code(${o?"\n":""}${r}${o&&null===this.scope?"\n":""})`}}function pt(t){return null!=t&&"object"==typeof t&&"$id"in t&&null!=t.$id&&"$ref"in t&&"string"==typeof t.$ref&&(!("$db"in t)||"$db"in t&&"string"==typeof t.$db)}class yt extends rt{get _bsontype(){return"DBRef"}constructor(t,e,n,r){super();const o=t.split(".");2===o.length&&(n=o.shift(),t=o.shift()),this.collection=t,this.oid=e,this.db=n,this.fields=r||{}}get namespace(){return this.collection}set namespace(t){this.collection=t}toJSON(){const t=Object.assign({$ref:this.collection,$id:this.oid},this.fields);return null!=this.db&&(t.$db=this.db),t}toExtendedJSON(t){t=t||{};let e={$ref:this.collection,$id:this.oid};return t.legacy||(this.db&&(e.$db=this.db),e=Object.assign(e,this.fields)),e}static fromExtendedJSON(t){const e=Object.assign({},t);return delete e.$ref,delete e.$id,delete e.$db,new yt(t.$ref,t.$id,t.$db,e)}inspect(t,e,n){n??=f;const r=[n(this.namespace,e),n(this.oid,e),...this.db?[n(this.db,e)]:[],...Object.keys(this.fields).length>0?[n(this.fields,e)]:[]];return r[1]=n===f?`new ObjectId(${r[1]})`:r[1],`new DBRef(${r.join(", ")})`}}function gt(t){if(""===t)return t;let e=0;const n="-"===t[e],r="+"===t[e];(r||n)&&(e+=1);let o=!1;for(;e<t.length&&"0"===t[e];++e)o=!0;return o?`${n?"-":""}${t.length===e?"0":t.slice(e)}`:r?t.slice(1):t}let bt;try{bt=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}const mt=4294967296,wt=0x10000000000000000,vt=wt/2,_t={},Ot={},Et=/^(\+?0|(\+|-)?[1-9][0-9]*)$/;class St extends rt{get _bsontype(){return"Long"}get __isLong__(){return!0}constructor(t=0,e,n){super();const r="boolean"==typeof e?e:Boolean(n),o="number"==typeof e?e:0,i="string"==typeof t?St.fromString(t,r):"bigint"==typeof t?St.fromBigInt(t,r):{low:0|t,high:0|o,unsigned:r};this.low=i.low,this.high=i.high,this.unsigned=i.unsigned}static fromBits(t,e,n){return new St(t,e,n)}static fromInt(t,e){let n,r,o;return e?(o=0<=(t>>>=0)&&t<256)&&(r=Ot[t],r)?r:(n=St.fromBits(t,(0|t)<0?-1:0,!0),o&&(Ot[t]=n),n):(o=-128<=(t|=0)&&t<128)&&(r=_t[t],r)?r:(n=St.fromBits(t,t<0?-1:0,!1),o&&(_t[t]=n),n)}static fromNumber(t,e){if(isNaN(t))return e?St.UZERO:St.ZERO;if(e){if(t<0)return St.UZERO;if(t>=wt)return St.MAX_UNSIGNED_VALUE}else{if(t<=-0x8000000000000000)return St.MIN_VALUE;if(t+1>=vt)return St.MAX_VALUE}return t<0?St.fromNumber(-t,e).neg():St.fromBits(t%mt|0,t/mt|0,e)}static fromBigInt(t,e){const n=BigInt(4294967295),r=BigInt(32);return new St(Number(t&n),Number(t>>r&n),e)}static _fromString(t,e,n){if(0===t.length)throw new W("empty string");if(n<2||36<n)throw new W("radix");let r;if((r=t.indexOf("-"))>0)throw new W("interior hyphen");if(0===r)return St._fromString(t.substring(1),e,n).neg();const o=St.fromNumber(Math.pow(n,8));let i=St.ZERO;for(let e=0;e<t.length;e+=8){const r=Math.min(8,t.length-e),s=parseInt(t.substring(e,e+r),n);if(r<8){const t=St.fromNumber(Math.pow(n,r));i=i.mul(t).add(St.fromNumber(s))}else i=i.mul(o),i=i.add(St.fromNumber(s))}return i.unsigned=e,i}static fromStringStrict(t,e,n){let r=!1;if("number"==typeof e?(n=e,e=!1):r=!!e,n??=10,t.trim()!==t)throw new W(`Input: '${t}' contains leading and/or trailing whitespace`);if(!function(t,e){const n="0123456789abcdefghijklmnopqrstuvwxyz".slice(0,e=e??10);return!new RegExp(`[^-+${n}]`,"i").test(t)&&t}(t,n))throw new W(`Input: '${t}' contains invalid characters for radix: ${n}`);const o=gt(t),i=St._fromString(o,r,n);if(i.toString(n).toLowerCase()!==o.toLowerCase())throw new W(`Input: ${t} is not representable as ${i.unsigned?"an unsigned":"a signed"} 64-bit Long ${null!=n?`with radix: ${n}`:""}`);return i}static fromString(t,e,n){let r=!1;return"number"==typeof e?(n=e,e=!1):r=!!e,n??=10,"NaN"===t&&n<24||("Infinity"===t||"+Infinity"===t||"-Infinity"===t)&&n<35?St.ZERO:St._fromString(t,r,n)}static fromBytes(t,e,n){return n?St.fromBytesLE(t,e):St.fromBytesBE(t,e)}static fromBytesLE(t,e){return new St(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,e)}static fromBytesBE(t,e){return new St(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],e)}static isLong(t){return null!=t&&"object"==typeof t&&"__isLong__"in t&&!0===t.__isLong__}static fromValue(t,e){return"number"==typeof t?St.fromNumber(t,e):"string"==typeof t?St.fromString(t,e):St.fromBits(t.low,t.high,"boolean"==typeof e?e:t.unsigned)}add(t){St.isLong(t)||(t=St.fromValue(t));const e=this.high>>>16,n=65535&this.high,r=this.low>>>16,o=65535&this.low,i=t.high>>>16,s=65535&t.high,a=t.low>>>16;let u=0,c=0,f=0,l=0;return l+=o+(65535&t.low),f+=l>>>16,l&=65535,f+=r+a,c+=f>>>16,f&=65535,c+=n+s,u+=c>>>16,c&=65535,u+=e+i,u&=65535,St.fromBits(f<<16|l,u<<16|c,this.unsigned)}and(t){return St.isLong(t)||(t=St.fromValue(t)),St.fromBits(this.low&t.low,this.high&t.high,this.unsigned)}compare(t){if(St.isLong(t)||(t=St.fromValue(t)),this.eq(t))return 0;const e=this.isNegative(),n=t.isNegative();return e&&!n?-1:!e&&n?1:this.unsigned?t.high>>>0>this.high>>>0||t.high===this.high&&t.low>>>0>this.low>>>0?-1:1:this.sub(t).isNegative()?-1:1}comp(t){return this.compare(t)}divide(t){if(St.isLong(t)||(t=St.fromValue(t)),t.isZero())throw new W("division by zero");if(bt){if(!this.unsigned&&-2147483648===this.high&&-1===t.low&&-1===t.high)return this;const e=(this.unsigned?bt.div_u:bt.div_s)(this.low,this.high,t.low,t.high);return St.fromBits(e,bt.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?St.UZERO:St.ZERO;let e,n,r;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return St.UZERO;if(t.gt(this.shru(1)))return St.UONE;r=St.UZERO}else{if(this.eq(St.MIN_VALUE))return t.eq(St.ONE)||t.eq(St.NEG_ONE)?St.MIN_VALUE:t.eq(St.MIN_VALUE)?St.ONE:(e=this.shr(1).div(t).shl(1),e.eq(St.ZERO)?t.isNegative()?St.ONE:St.NEG_ONE:(n=this.sub(t.mul(e)),r=e.add(n.div(t)),r));if(t.eq(St.MIN_VALUE))return this.unsigned?St.UZERO:St.ZERO;if(this.isNegative())return t.isNegative()?this.neg().div(t.neg()):this.neg().div(t).neg();if(t.isNegative())return this.div(t.neg()).neg();r=St.ZERO}for(n=this;n.gte(t);){e=Math.max(1,Math.floor(n.toNumber()/t.toNumber()));const o=Math.ceil(Math.log(e)/Math.LN2),i=o<=48?1:Math.pow(2,o-48);let s=St.fromNumber(e),a=s.mul(t);for(;a.isNegative()||a.gt(n);)e-=i,s=St.fromNumber(e,this.unsigned),a=s.mul(t);s.isZero()&&(s=St.ONE),r=r.add(s),n=n.sub(a)}return r}div(t){return this.divide(t)}equals(t){return St.isLong(t)||(t=St.fromValue(t)),(this.unsigned===t.unsigned||this.high>>>31!=1||t.high>>>31!=1)&&this.high===t.high&&this.low===t.low}eq(t){return this.equals(t)}getHighBits(){return this.high}getHighBitsUnsigned(){return this.high>>>0}getLowBits(){return this.low}getLowBitsUnsigned(){return this.low>>>0}getNumBitsAbs(){if(this.isNegative())return this.eq(St.MIN_VALUE)?64:this.neg().getNumBitsAbs();const t=0!==this.high?this.high:this.low;let e;for(e=31;e>0&&!(t&1<<e);e--);return 0!==this.high?e+33:e+1}greaterThan(t){return this.comp(t)>0}gt(t){return this.greaterThan(t)}greaterThanOrEqual(t){return this.comp(t)>=0}gte(t){return this.greaterThanOrEqual(t)}ge(t){return this.greaterThanOrEqual(t)}isEven(){return!(1&this.low)}isNegative(){return!this.unsigned&&this.high<0}isOdd(){return!(1&~this.low)}isPositive(){return this.unsigned||this.high>=0}isZero(){return 0===this.high&&0===this.low}lessThan(t){return this.comp(t)<0}lt(t){return this.lessThan(t)}lessThanOrEqual(t){return this.comp(t)<=0}lte(t){return this.lessThanOrEqual(t)}modulo(t){if(St.isLong(t)||(t=St.fromValue(t)),bt){const e=(this.unsigned?bt.rem_u:bt.rem_s)(this.low,this.high,t.low,t.high);return St.fromBits(e,bt.get_high(),this.unsigned)}return this.sub(this.div(t).mul(t))}mod(t){return this.modulo(t)}rem(t){return this.modulo(t)}multiply(t){if(this.isZero())return St.ZERO;if(St.isLong(t)||(t=St.fromValue(t)),bt){const e=bt.mul(this.low,this.high,t.low,t.high);return St.fromBits(e,bt.get_high(),this.unsigned)}if(t.isZero())return St.ZERO;if(this.eq(St.MIN_VALUE))return t.isOdd()?St.MIN_VALUE:St.ZERO;if(t.eq(St.MIN_VALUE))return this.isOdd()?St.MIN_VALUE:St.ZERO;if(this.isNegative())return t.isNegative()?this.neg().mul(t.neg()):this.neg().mul(t).neg();if(t.isNegative())return this.mul(t.neg()).neg();if(this.lt(St.TWO_PWR_24)&&t.lt(St.TWO_PWR_24))return St.fromNumber(this.toNumber()*t.toNumber(),this.unsigned);const e=this.high>>>16,n=65535&this.high,r=this.low>>>16,o=65535&this.low,i=t.high>>>16,s=65535&t.high,a=t.low>>>16,u=65535&t.low;let c=0,f=0,l=0,d=0;return d+=o*u,l+=d>>>16,d&=65535,l+=r*u,f+=l>>>16,l&=65535,l+=o*a,f+=l>>>16,l&=65535,f+=n*u,c+=f>>>16,f&=65535,f+=r*a,c+=f>>>16,f&=65535,f+=o*s,c+=f>>>16,f&=65535,c+=e*u+n*a+r*s+o*i,c&=65535,St.fromBits(l<<16|d,c<<16|f,this.unsigned)}mul(t){return this.multiply(t)}negate(){return!this.unsigned&&this.eq(St.MIN_VALUE)?St.MIN_VALUE:this.not().add(St.ONE)}neg(){return this.negate()}not(){return St.fromBits(~this.low,~this.high,this.unsigned)}notEquals(t){return!this.equals(t)}neq(t){return this.notEquals(t)}ne(t){return this.notEquals(t)}or(t){return St.isLong(t)||(t=St.fromValue(t)),St.fromBits(this.low|t.low,this.high|t.high,this.unsigned)}shiftLeft(t){return St.isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?St.fromBits(this.low<<t,this.high<<t|this.low>>>32-t,this.unsigned):St.fromBits(0,this.low<<t-32,this.unsigned)}shl(t){return this.shiftLeft(t)}shiftRight(t){return St.isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?St.fromBits(this.low>>>t|this.high<<32-t,this.high>>t,this.unsigned):St.fromBits(this.high>>t-32,this.high>=0?0:-1,this.unsigned)}shr(t){return this.shiftRight(t)}shiftRightUnsigned(t){if(St.isLong(t)&&(t=t.toInt()),0==(t&=63))return this;{const e=this.high;if(t<32){const n=this.low;return St.fromBits(n>>>t|e<<32-t,e>>>t,this.unsigned)}return 32===t?St.fromBits(e,0,this.unsigned):St.fromBits(e>>>t-32,0,this.unsigned)}}shr_u(t){return this.shiftRightUnsigned(t)}shru(t){return this.shiftRightUnsigned(t)}subtract(t){return St.isLong(t)||(t=St.fromValue(t)),this.add(t.neg())}sub(t){return this.subtract(t)}toInt(){return this.unsigned?this.low>>>0:this.low}toNumber(){return this.unsigned?(this.high>>>0)*mt+(this.low>>>0):this.high*mt+(this.low>>>0)}toBigInt(){return BigInt(this.toString())}toBytes(t){return t?this.toBytesLE():this.toBytesBE()}toBytesLE(){const t=this.high,e=this.low;return[255&e,e>>>8&255,e>>>16&255,e>>>24,255&t,t>>>8&255,t>>>16&255,t>>>24]}toBytesBE(){const t=this.high,e=this.low;return[t>>>24,t>>>16&255,t>>>8&255,255&t,e>>>24,e>>>16&255,e>>>8&255,255&e]}toSigned(){return this.unsigned?St.fromBits(this.low,this.high,!1):this}toString(t){if((t=t||10)<2||36<t)throw new W("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(St.MIN_VALUE)){const e=St.fromNumber(t),n=this.div(e),r=n.mul(e).sub(this);return n.toString(t)+r.toInt().toString(t)}return"-"+this.neg().toString(t)}const e=St.fromNumber(Math.pow(t,6),this.unsigned);let n=this,r="";for(;;){const o=n.div(e);let i=(n.sub(o.mul(e)).toInt()>>>0).toString(t);if(n=o,n.isZero())return i+r;for(;i.length<6;)i="0"+i;r=""+i+r}}toUnsigned(){return this.unsigned?this:St.fromBits(this.low,this.high,!0)}xor(t){return St.isLong(t)||(t=St.fromValue(t)),St.fromBits(this.low^t.low,this.high^t.high,this.unsigned)}eqz(){return this.isZero()}le(t){return this.lessThanOrEqual(t)}toExtendedJSON(t){return t&&t.relaxed?this.toNumber():{$numberLong:this.toString()}}static fromExtendedJSON(t,e){const{useBigInt64:n=!1,relaxed:r=!0}={...e};if(t.$numberLong.length>20)throw new W("$numberLong string is too long");if(!Et.test(t.$numberLong))throw new W(`$numberLong string "${t.$numberLong}" is in an invalid format`);if(n){const e=BigInt(t.$numberLong);return BigInt.asIntN(64,e)}const o=St.fromString(t.$numberLong);return r?o.toNumber():o}inspect(t,e,n){return n??=f,`new Long(${n(this.toString(),e)}${this.unsigned?`, ${n(this.unsigned,e)}`:""})`}}St.TWO_PWR_24=St.fromInt(1<<24),St.MAX_UNSIGNED_VALUE=St.fromBits(-1,-1,!0),St.ZERO=St.fromInt(0),St.UZERO=St.fromInt(0,!0),St.ONE=St.fromInt(1),St.UONE=St.fromInt(1,!0),St.NEG_ONE=St.fromInt(-1),St.MAX_VALUE=St.fromBits(-1,2147483647,!1),St.MIN_VALUE=St.fromBits(0,-2147483648,!1);const Nt=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,It=/^(\+|-)?(Infinity|inf)$/i,xt=/^(\+|-)?NaN$/i,Tt=6111,Bt=-6176,jt=nt.fromNumberArray([124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),At=nt.fromNumberArray([248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Lt=nt.fromNumberArray([120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Pt=/^([-+])?(\d+)?$/;function $t(t){return!isNaN(parseInt(t,10))}function Ut(t){const e=St.fromNumber(1e9);let n=St.fromNumber(0);if(!(t.parts[0]||t.parts[1]||t.parts[2]||t.parts[3]))return{quotient:t,rem:n};for(let r=0;r<=3;r++)n=n.shiftLeft(32),n=n.add(new St(t.parts[r],0)),t.parts[r]=n.div(e).low,n=n.modulo(e);return{quotient:t,rem:n}}function Rt(t,e){throw new W(`"${t}" is not a valid Decimal128 string - ${e}`)}class Dt extends rt{get _bsontype(){return"Decimal128"}constructor(t){if(super(),"string"==typeof t)this.bytes=Dt.fromString(t).bytes;else{if(!(t instanceof Uint8Array||i(t)))throw new W("Decimal128 must take a Buffer or string");if(16!==t.byteLength)throw new W("Decimal128 must take a Buffer of 16 bytes");this.bytes=t}}static fromString(t){return Dt._fromString(t,{allowRounding:!1})}static fromStringWithRounding(t){return Dt._fromString(t,{allowRounding:!0})}static _fromString(t,e){let n=!1,r=!1,o=!1,i=!1,s=0,a=0,u=0,c=0,f=0;const l=[0];let d=0,h=0,p=0,y=0,g=new St(0,0),b=new St(0,0),m=0,w=0;if(t.length>=7e3)throw new W(t+" not a valid Decimal128 string");const v=t.match(Nt),_=t.match(It),O=t.match(xt);if(!v&&!_&&!O||0===t.length)throw new W(t+" not a valid Decimal128 string");if(v){const e=v[2],n=v[4],r=v[5],o=v[6];n&&void 0===o&&Rt(t,"missing exponent power"),n&&void 0===e&&Rt(t,"missing exponent base"),void 0===n&&(r||o)&&Rt(t,"missing e before exponent")}if("+"!==t[w]&&"-"!==t[w]||(r=!0,n="-"===t[w++]),!$t(t[w])&&"."!==t[w]){if("i"===t[w]||"I"===t[w])return new Dt(n?At:Lt);if("N"===t[w])return new Dt(jt)}for(;$t(t[w])||"."===t[w];)"."!==t[w]?(d<34&&("0"!==t[w]||i)&&(i||(f=a),i=!0,l[h++]=parseInt(t[w],10),d+=1),i&&(u+=1),o&&(c+=1),a+=1,w+=1):(o&&Rt(t,"contains multiple periods"),o=!0,w+=1);if(o&&!a)throw new W(t+" not a valid Decimal128 string");if("e"===t[w]||"E"===t[w]){const e=t.substr(++w).match(Pt);if(!e||!e[2])return new Dt(jt);y=parseInt(e[0],10),w+=e[0].length}if(t[w])return new Dt(jt);if(d){if(p=d-1,s=u,1!==s)for(;"0"===t[f+s-1+Number(r)+Number(o)];)s-=1}else l[0]=0,u=1,d=1,s=0;for(y<=c&&c>y+16384?y=Bt:y-=c;y>Tt;){if(p+=1,p>=34){if(0===s){y=Tt;break}Rt(t,"overflow")}y-=1}if(e.allowRounding){for(;y<Bt||d<u;){if(0===p&&s<d){y=Bt,s=0;break}if(d<u?u-=1:p-=1,y<Tt)y+=1;else{if(l.join("").match(/^0+$/)){y=Tt;break}Rt(t,"overflow")}}if(p+1<s){let e=a;o&&(f+=1,e+=1),r&&(f+=1,e+=1);const i=parseInt(t[f+p+1],10);let s=0;if(i>=5&&(s=1,5===i)){s=l[p]%2==1?1:0;for(let n=f+p+2;n<e;n++)if(parseInt(t[n],10)){s=1;break}}if(s){let t=p;for(;t>=0&&++l[t]>9;t--)if(l[t]=0,0===t){if(!(y<Tt))return new Dt(n?At:Lt);y+=1,l[t]=1}}}}else{for(;y<Bt||d<u;){if(0===p){if(0===s){y=Bt;break}Rt(t,"exponent underflow")}d<u?("0"!==t[u-1+Number(r)+Number(o)]&&0!==s&&Rt(t,"inexact rounding"),u-=1):(0!==l[p]&&Rt(t,"inexact rounding"),p-=1),y<Tt?y+=1:Rt(t,"overflow")}p+1<s&&(o&&(f+=1),r&&(f+=1),0!==parseInt(t[f+p+1],10)&&Rt(t,"inexact rounding"))}if(g=St.fromNumber(0),b=St.fromNumber(0),0===s)g=St.fromNumber(0),b=St.fromNumber(0);else if(p<17){let t=0;for(b=St.fromNumber(l[t++]),g=new St(0,0);t<=p;t++)b=b.multiply(St.fromNumber(10)),b=b.add(St.fromNumber(l[t]))}else{let t=0;for(g=St.fromNumber(l[t++]);t<=p-17;t++)g=g.multiply(St.fromNumber(10)),g=g.add(St.fromNumber(l[t]));for(b=St.fromNumber(l[t++]);t<=p;t++)b=b.multiply(St.fromNumber(10)),b=b.add(St.fromNumber(l[t]))}const E=function(t,e){if(!t&&!e)return{high:St.fromNumber(0),low:St.fromNumber(0)};const n=t.shiftRightUnsigned(32),r=new St(t.getLowBits(),0),o=e.shiftRightUnsigned(32),i=new St(e.getLowBits(),0);let s=n.multiply(o),a=n.multiply(i);const u=r.multiply(o);let c=r.multiply(i);return s=s.add(a.shiftRightUnsigned(32)),a=new St(a.getLowBits(),0).add(u).add(c.shiftRightUnsigned(32)),s=s.add(a.shiftRightUnsigned(32)),c=a.shiftLeft(32).add(new St(c.getLowBits(),0)),{high:s,low:c}}(g,St.fromString("100000000000000000"));E.low=E.low.add(b),function(t,e){const n=t.high>>>0,r=e.high>>>0;return n<r||n===r&&t.low>>>0<e.low>>>0}(E.low,b)&&(E.high=E.high.add(St.fromNumber(1))),m=y+6176;const S={low:St.fromNumber(0),high:St.fromNumber(0)};E.high.shiftRightUnsigned(49).and(St.fromNumber(1)).equals(St.fromNumber(1))?(S.high=S.high.or(St.fromNumber(3).shiftLeft(61)),S.high=S.high.or(St.fromNumber(m).and(St.fromNumber(16383).shiftLeft(47))),S.high=S.high.or(E.high.and(St.fromNumber(0x7fffffffffff)))):(S.high=S.high.or(St.fromNumber(16383&m).shiftLeft(49)),S.high=S.high.or(E.high.and(St.fromNumber(562949953421311)))),S.low=E.low,n&&(S.high=S.high.or(St.fromString("9223372036854775808")));const N=nt.allocateUnsafe(16);return w=0,N[w++]=255&S.low.low,N[w++]=S.low.low>>8&255,N[w++]=S.low.low>>16&255,N[w++]=S.low.low>>24&255,N[w++]=255&S.low.high,N[w++]=S.low.high>>8&255,N[w++]=S.low.high>>16&255,N[w++]=S.low.high>>24&255,N[w++]=255&S.high.low,N[w++]=S.high.low>>8&255,N[w++]=S.high.low>>16&255,N[w++]=S.high.low>>24&255,N[w++]=255&S.high.high,N[w++]=S.high.high>>8&255,N[w++]=S.high.high>>16&255,N[w++]=S.high.high>>24&255,new Dt(N)}toString(){let t,e=0;const n=new Array(36);for(let t=0;t<n.length;t++)n[t]=0;let r,o,i,s=0,a=!1,u={parts:[0,0,0,0]};const c=[];s=0;const f=this.bytes,l=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,d=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,h=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,p=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24;s=0,(new St(l,d),new St(h,p)).lessThan(St.ZERO)&&c.push("-");const y=p>>26&31;if(y>>3==3){if(30===y)return c.join("")+"Infinity";if(31===y)return"NaN";t=p>>15&16383,r=8+(p>>14&1)}else r=p>>14&7,t=p>>17&16383;const g=t-6176;if(u.parts[0]=(16383&p)+((15&r)<<14),u.parts[1]=h,u.parts[2]=d,u.parts[3]=l,0===u.parts[0]&&0===u.parts[1]&&0===u.parts[2]&&0===u.parts[3])a=!0;else for(i=3;i>=0;i--){let t=0;const e=Ut(u);if(u=e.quotient,t=e.rem.low,t)for(o=8;o>=0;o--)n[9*i+o]=t%10,t=Math.floor(t/10)}if(a)e=1,n[s]=0;else for(e=36;!n[s];)e-=1,s+=1;const b=e-1+g;if(b>=34||b<=-7||g>0){if(e>34)return c.push("0"),g>0?c.push(`E+${g}`):g<0&&c.push(`E${g}`),c.join("");c.push(`${n[s++]}`),e-=1,e&&c.push(".");for(let t=0;t<e;t++)c.push(`${n[s++]}`);c.push("E"),b>0?c.push(`+${b}`):c.push(`${b}`)}else if(g>=0)for(let t=0;t<e;t++)c.push(`${n[s++]}`);else{let t=e+g;if(t>0)for(let e=0;e<t;e++)c.push(`${n[s++]}`);else c.push("0");for(c.push(".");t++<0;)c.push("0");for(let r=0;r<e-Math.max(t-1,0);r++)c.push(`${n[s++]}`)}return c.join("")}toJSON(){return{$numberDecimal:this.toString()}}toExtendedJSON(){return{$numberDecimal:this.toString()}}static fromExtendedJSON(t){return Dt.fromString(t.$numberDecimal)}inspect(t,e,n){return n??=f,`new Decimal128(${n(this.toString(),e)})`}}class Ct extends rt{get _bsontype(){return"Double"}constructor(t){super(),t instanceof Number&&(t=t.valueOf()),this.value=+t}static fromString(t){const e=Number(t);if("NaN"===t)return new Ct(NaN);if("Infinity"===t)return new Ct(1/0);if("-Infinity"===t)return new Ct(-1/0);if(!Number.isFinite(e))throw new W(`Input: ${t} is not representable as a Double`);if(t.trim()!==t)throw new W(`Input: '${t}' contains whitespace`);if(""===t)throw new W("Input is an empty string");if(/[^-0-9.+eE]/.test(t))throw new W(`Input: '${t}' is not in decimal or exponential notation`);return new Ct(e)}valueOf(){return this.value}toJSON(){return this.value}toString(t){return this.value.toString(t)}toExtendedJSON(t){return t&&(t.legacy||t.relaxed&&isFinite(this.value))?this.value:Object.is(Math.sign(this.value),-0)?{$numberDouble:"-0.0"}:{$numberDouble:Number.isInteger(this.value)?this.value.toFixed(1):this.value.toString()}}static fromExtendedJSON(t,e){const n=parseFloat(t.$numberDouble);return e&&e.relaxed?n:new Ct(n)}inspect(t,e,n){return n??=f,`new Double(${n(this.value,e)})`}}class Ft extends rt{get _bsontype(){return"Int32"}constructor(t){super(),t instanceof Number&&(t=t.valueOf()),this.value=0|+t}static fromString(t){const e=gt(t),n=Number(t);if(h<n)throw new W(`Input: '${t}' is larger than the maximum value for Int32`);if(p>n)throw new W(`Input: '${t}' is smaller than the minimum value for Int32`);if(!Number.isSafeInteger(n))throw new W(`Input: '${t}' is not a safe integer`);if(n.toString()!==e)throw new W(`Input: '${t}' is not a valid Int32 string`);return new Ft(n)}valueOf(){return this.value}toString(t){return this.value.toString(t)}toJSON(){return this.value}toExtendedJSON(t){return t&&(t.relaxed||t.legacy)?this.value:{$numberInt:this.value.toString()}}static fromExtendedJSON(t,e){return e&&e.relaxed?parseInt(t.$numberInt,10):new Ft(t.$numberInt)}inspect(t,e,n){return n??=f,`new Int32(${n(this.value,e)})`}}class qt extends rt{get _bsontype(){return"MaxKey"}toExtendedJSON(){return{$maxKey:1}}static fromExtendedJSON(){return new qt}inspect(){return"new MaxKey()"}}class Mt extends rt{get _bsontype(){return"MinKey"}toExtendedJSON(){return{$minKey:1}}static fromExtendedJSON(){return new Mt}inspect(){return"new MinKey()"}}let kt=null;const Wt=new WeakMap;class Jt extends rt{get _bsontype(){return"ObjectId"}constructor(t){let e;if(super(),"object"==typeof t&&t&&"id"in t){if("string"!=typeof t.id&&!ArrayBuffer.isView(t.id))throw new W("Argument passed in must have an id that is of type string or Buffer");e="toHexString"in t&&"function"==typeof t.toHexString?nt.fromHex(t.toHexString()):t.id}else e=t;if(null==e||"number"==typeof e)this.buffer=Jt.generate("number"==typeof e?e:void 0);else if(ArrayBuffer.isView(e)&&12===e.byteLength)this.buffer=nt.toLocalBufferType(e);else{if("string"!=typeof e)throw new W("Argument passed in does not match the accepted types");if(!Jt.validateHexString(e))throw new W("input must be a 24 character hex string, 12 byte Uint8Array, or an integer");this.buffer=nt.fromHex(e),Jt.cacheHexString&&Wt.set(this,e)}}get id(){return this.buffer}set id(t){this.buffer=t,Jt.cacheHexString&&Wt.set(this,nt.toHex(t))}static validateHexString(t){if(24!==t?.length)return!1;for(let e=0;e<24;e++){const n=t.charCodeAt(e);if(!(n>=48&&n<=57||n>=97&&n<=102||n>=65&&n<=70))return!1}return!0}toHexString(){if(Jt.cacheHexString){const t=Wt.get(this);if(t)return t}const t=nt.toHex(this.id);return Jt.cacheHexString&&Wt.set(this,t),t}static getInc(){return Jt.index=(Jt.index+1)%16777215}static generate(t){"number"!=typeof t&&(t=Math.floor(Date.now()/1e3));const e=Jt.getInc(),n=nt.allocateUnsafe(12);return at.setInt32BE(n,0,t),null===kt&&(kt=nt.randomBytes(5)),n[4]=kt[0],n[5]=kt[1],n[6]=kt[2],n[7]=kt[3],n[8]=kt[4],n[11]=255&e,n[10]=e>>8&255,n[9]=e>>16&255,n}toString(t){return"base64"===t?nt.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}static is(t){return null!=t&&"object"==typeof t&&"_bsontype"in t&&"ObjectId"===t._bsontype}equals(t){if(null==t)return!1;if(Jt.is(t))return this.buffer[11]===t.buffer[11]&&nt.equals(this.buffer,t.buffer);if("string"==typeof t)return t.toLowerCase()===this.toHexString();if("object"==typeof t&&"function"==typeof t.toHexString){const e=t.toHexString(),n=this.toHexString();return"string"==typeof e&&e.toLowerCase()===n}return!1}getTimestamp(){const t=new Date,e=at.getUint32BE(this.buffer,0);return t.setTime(1e3*Math.floor(e)),t}static createPk(){return new Jt}serializeInto(t,e){return t[e]=this.buffer[0],t[e+1]=this.buffer[1],t[e+2]=this.buffer[2],t[e+3]=this.buffer[3],t[e+4]=this.buffer[4],t[e+5]=this.buffer[5],t[e+6]=this.buffer[6],t[e+7]=this.buffer[7],t[e+8]=this.buffer[8],t[e+9]=this.buffer[9],t[e+10]=this.buffer[10],t[e+11]=this.buffer[11],12}static createFromTime(t){const e=nt.allocate(12);for(let t=11;t>=4;t--)e[t]=0;return at.setInt32BE(e,0,t),new Jt(e)}static createFromHexString(t){if(24!==t?.length)throw new W("hex string must be 24 characters");return new Jt(nt.fromHex(t))}static createFromBase64(t){if(16!==t?.length)throw new W("base64 string must be 16 characters");return new Jt(nt.fromBase64(t))}static isValid(t){if(null==t)return!1;if("string"==typeof t)return Jt.validateHexString(t);try{return new Jt(t),!0}catch{return!1}}toExtendedJSON(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}}static fromExtendedJSON(t){return new Jt(t.$oid)}isCached(){return Jt.cacheHexString&&Wt.has(this)}inspect(t,e,n){return n??=f,`new ObjectId(${n(this.toHexString(),e)})`}}function Vt(t,e,n){let r=5;if(Array.isArray(t))for(let o=0;o<t.length;o++)r+=Ht(o.toString(),t[o],e,!0,n);else{"function"==typeof t?.toBSON&&(t=t.toBSON());for(const o of Object.keys(t))r+=Ht(o,t[o],e,!1,n)}return r}function Ht(t,e,n=!1,r=!1,o=!1){switch("function"==typeof e?.toBSON&&(e=e.toBSON()),typeof e){case"string":return 1+nt.utf8ByteLength(t)+1+4+nt.utf8ByteLength(e)+1;case"number":return Math.floor(e)===e&&e>=m&&e<=b&&e>=p&&e<=h?(null!=t?nt.utf8ByteLength(t)+1:0)+5:(null!=t?nt.utf8ByteLength(t)+1:0)+9;case"undefined":return r||!o?(null!=t?nt.utf8ByteLength(t)+1:0)+1:0;case"boolean":return(null!=t?nt.utf8ByteLength(t)+1:0)+2;case"object":if(null!=e&&"string"==typeof e._bsontype&&e[d]!==l)throw new J;if(null==e||"MinKey"===e._bsontype||"MaxKey"===e._bsontype)return(null!=t?nt.utf8ByteLength(t)+1:0)+1;if("ObjectId"===e._bsontype)return(null!=t?nt.utf8ByteLength(t)+1:0)+13;if(e instanceof Date||c(e))return(null!=t?nt.utf8ByteLength(t)+1:0)+9;if(ArrayBuffer.isView(e)||e instanceof ArrayBuffer||s(e))return(null!=t?nt.utf8ByteLength(t)+1:0)+6+e.byteLength;if("Long"===e._bsontype||"Double"===e._bsontype||"Timestamp"===e._bsontype)return(null!=t?nt.utf8ByteLength(t)+1:0)+9;if("Decimal128"===e._bsontype)return(null!=t?nt.utf8ByteLength(t)+1:0)+17;if("Code"===e._bsontype)return null!=e.scope&&Object.keys(e.scope).length>0?(null!=t?nt.utf8ByteLength(t)+1:0)+1+4+4+nt.utf8ByteLength(e.code.toString())+1+Vt(e.scope,n,o):(null!=t?nt.utf8ByteLength(t)+1:0)+1+4+nt.utf8ByteLength(e.code.toString())+1;if("Binary"===e._bsontype){const n=e;return n.sub_type===ut.SUBTYPE_BYTE_ARRAY?(null!=t?nt.utf8ByteLength(t)+1:0)+(n.position+1+4+1+4):(null!=t?nt.utf8ByteLength(t)+1:0)+(n.position+1+4+1)}if("Symbol"===e._bsontype)return(null!=t?nt.utf8ByteLength(t)+1:0)+nt.utf8ByteLength(e.value)+4+1+1;if("DBRef"===e._bsontype){const r=Object.assign({$ref:e.collection,$id:e.oid},e.fields);return null!=e.db&&(r.$db=e.db),(null!=t?nt.utf8ByteLength(t)+1:0)+1+Vt(r,n,o)}return e instanceof RegExp||a(e)?(null!=t?nt.utf8ByteLength(t)+1:0)+1+nt.utf8ByteLength(e.source)+1+(e.global?1:0)+(e.ignoreCase?1:0)+(e.multiline?1:0)+1:"BSONRegExp"===e._bsontype?(null!=t?nt.utf8ByteLength(t)+1:0)+1+nt.utf8ByteLength(e.pattern)+1+nt.utf8ByteLength(e.options)+1:(null!=t?nt.utf8ByteLength(t)+1:0)+Vt(e,n,o)+1;case"function":return n?(null!=t?nt.utf8ByteLength(t)+1:0)+1+4+nt.utf8ByteLength(e.toString())+1:0;case"bigint":return(null!=t?nt.utf8ByteLength(t)+1:0)+9;case"symbol":return 0;default:throw new W("Unrecognized JS type: "+typeof e)}}Jt.index=Math.floor(16777215*Math.random());class zt extends rt{get _bsontype(){return"BSONRegExp"}constructor(t,e){if(super(),this.pattern=t,this.options=(e??"").split("").sort().join(""),-1!==this.pattern.indexOf("\0"))throw new W(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);if(-1!==this.options.indexOf("\0"))throw new W(`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`);for(let t=0;t<this.options.length;t++)if("i"!==this.options[t]&&"m"!==this.options[t]&&"x"!==this.options[t]&&"l"!==this.options[t]&&"s"!==this.options[t]&&"u"!==this.options[t])throw new W(`The regular expression option [${this.options[t]}] is not supported`)}static parseOptions(t){return t?t.split("").sort().join(""):""}toExtendedJSON(t){return(t=t||{}).legacy?{$regex:this.pattern,$options:this.options}:{$regularExpression:{pattern:this.pattern,options:this.options}}}static fromExtendedJSON(t){if("$regex"in t){if("string"==typeof t.$regex)return new zt(t.$regex,zt.parseOptions(t.$options));if("BSONRegExp"===t.$regex._bsontype)return t}if("$regularExpression"in t)return new zt(t.$regularExpression.pattern,zt.parseOptions(t.$regularExpression.options));throw new W(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(t)}`)}inspect(t,e,n){const r=function(t){if(null!=t&&"object"==typeof t&&"stylize"in t&&"function"==typeof t.stylize)return t.stylize}(e)??(t=>t);return n??=f,`new BSONRegExp(${r(n(this.pattern),"regexp")}, ${r(n(this.options),"regexp")})`}}class Gt extends rt{get _bsontype(){return"BSONSymbol"}constructor(t){super(),this.value=t}valueOf(){return this.value}toString(){return this.value}toJSON(){return this.value}toExtendedJSON(){return{$symbol:this.value}}static fromExtendedJSON(t){return new Gt(t.$symbol)}inspect(t,e,n){return n??=f,`new BSONSymbol(${n(this.value,e)})`}}const Yt=St;class Kt extends Yt{get _bsontype(){return"Timestamp"}get i(){return this.low>>>0}get t(){return this.high>>>0}constructor(t){if(null==t)super(0,0,!0);else if("bigint"==typeof t)super(t,!0);else if(St.isLong(t))super(t.low,t.high,!0);else{if("object"!=typeof t||!("t"in t)||!("i"in t))throw new W("A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }");{if("number"!=typeof t.t&&("object"!=typeof t.t||"Int32"!==t.t._bsontype))throw new W("Timestamp constructed from { t, i } must provide t as a number");if("number"!=typeof t.i&&("object"!=typeof t.i||"Int32"!==t.i._bsontype))throw new W("Timestamp constructed from { t, i } must provide i as a number");const e=Number(t.t),n=Number(t.i);if(e<0||Number.isNaN(e))throw new W("Timestamp constructed from { t, i } must provide a positive t");if(n<0||Number.isNaN(n))throw new W("Timestamp constructed from { t, i } must provide a positive i");if(e>4294967295)throw new W("Timestamp constructed from { t, i } must provide t equal or less than uint32 max");if(n>4294967295)throw new W("Timestamp constructed from { t, i } must provide i equal or less than uint32 max");super(n,e,!0)}}}toJSON(){return{$timestamp:this.toString()}}static fromInt(t){return new Kt(St.fromInt(t,!0))}static fromNumber(t){return new Kt(St.fromNumber(t,!0))}static fromBits(t,e){return new Kt({i:t,t:e})}static fromString(t,e){return new Kt(St.fromString(t,!0,e))}toExtendedJSON(){return{$timestamp:{t:this.t,i:this.i}}}static fromExtendedJSON(t){const e=St.isLong(t.$timestamp.i)?t.$timestamp.i.getLowBitsUnsigned():t.$timestamp.i,n=St.isLong(t.$timestamp.t)?t.$timestamp.t.getLowBitsUnsigned():t.$timestamp.t;return new Kt({t:n,i:e})}inspect(t,e,n){return n??=f,`new Timestamp({ t: ${n(this.t,e)}, i: ${n(this.i,e)} })`}}Kt.MAX_VALUE=St.MAX_UNSIGNED_VALUE;const Qt=St.fromNumber(b),Zt=St.fromNumber(m);function Xt(t,e,n){const r=(e=null==e?{}:e)&&e.index?e.index:0,o=at.getInt32LE(t,r);if(o<5)throw new W(`bson size must be >= 5, is ${o}`);if(e.allowObjectSmallerThanBufferSize&&t.length<o)throw new W(`buffer length ${t.length} must be >= bson size ${o}`);if(!e.allowObjectSmallerThanBufferSize&&t.length!==o)throw new W(`buffer length ${t.length} must === bson size ${o}`);if(o+r>t.byteLength)throw new W(`(bson size ${o} + options.index ${r} must be <= buffer length ${t.byteLength})`);if(0!==t[r+o-1])throw new W("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");return ee(t,r,e,n)}const te=/^\$ref$|^\$id$|^\$db$/;function ee(t,e,n,r=!1){const o=null==n.fieldsAsRaw?null:n.fieldsAsRaw,i=null!=n.raw&&n.raw,s="boolean"==typeof n.bsonRegExp&&n.bsonRegExp,a=n.promoteBuffers??!1,u=n.promoteLongs??!0,c=n.promoteValues??!0,f=n.useBigInt64??!1;if(f&&!c)throw new W("Must either request bigint or Long for int64 deserialization");if(f&&!u)throw new W("Must either request bigint or Long for int64 deserialization");let l,d,h=!0;const p=(null==n.validation?{utf8:!0}:n.validation).utf8;if("boolean"==typeof p)l=p;else{h=!1;const t=Object.keys(p).map(function(t){return p[t]});if(0===t.length)throw new W("UTF-8 validation setting cannot be empty");if("boolean"!=typeof t[0])throw new W("Invalid UTF-8 validation option, must specify boolean values");if(l=t[0],!t.every(t=>t===l))throw new W("Invalid UTF-8 validation option - keys must be all true or all false")}if(!h){d=new Set;for(const t of Object.keys(p))d.add(t)}const y=e;if(t.length<5)throw new W("corrupt bson message < 5 bytes long");const g=at.getInt32LE(t,e);if(e+=4,g<5||g>t.length)throw new W("corrupt bson message");const b=r?[]:{};let m=0,q=!r&&null;for(;;){const p=t[e++];if(0===p)break;let y=e;for(;0!==t[y]&&y<t.length;)y++;if(y>=t.byteLength)throw new W("Bad BSON Document: illegal CString");const g=r?m++:nt.toUTF8(t,e,y,!1);let k,J=!0;if(J=h||d?.has(g)?l:!l,!1!==q&&"$"===g[0]&&(q=te.test(g)),e=y+1,p===v){const n=at.getInt32LE(t,e);if(e+=4,n<=0||n>t.length-e||0!==t[e+n-1])throw new W("bad string length in bson");k=nt.toUTF8(t,e,e+n-1,J),e+=n}else if(p===N){const n=nt.allocateUnsafe(12);for(let r=0;r<12;r++)n[r]=t[e+r];k=new Jt(n),e+=12}else if(p===$&&!1===c)k=new Ft(at.getInt32LE(t,e)),e+=4;else if(p===$)k=at.getInt32LE(t,e),e+=4;else if(p===w)k=at.getFloat64LE(t,e),e+=8,!1===c&&(k=new Ct(k));else if(p===x){const n=at.getInt32LE(t,e),r=at.getInt32LE(t,e+4);e+=8,k=new Date(new St(n,r).toNumber())}else if(p===I){if(0!==t[e]&&1!==t[e])throw new W("illegal boolean type value");k=1===t[e++]}else if(p===_){const r=e,o=at.getInt32LE(t,e);if(o<=0||o>t.length-e)throw new W("bad embedded document length in bson");if(i)k=t.subarray(e,e+o);else{let e=n;h||(e={...n,validation:{utf8:J}}),k=ee(t,r,e,!1)}e+=o}else if(p===O){const r=e,i=at.getInt32LE(t,e);let s=n;const a=e+i;if(o&&o[g]&&(s={...n,raw:!0}),h||(s={...s,validation:{utf8:J}}),k=ee(t,r,s,!0),0!==t[(e+=i)-1])throw new W("invalid array terminator byte");if(e!==a)throw new W("corrupted array bson")}else if(p===S)k=void 0;else if(p===T)k=null;else if(p===R)if(f)k=at.getBigInt64LE(t,e),e+=8;else{const n=at.getInt32LE(t,e),r=at.getInt32LE(t,e+4);e+=8;const o=new St(n,r);k=u&&!0===c&&o.lessThanOrEqual(Qt)&&o.greaterThanOrEqual(Zt)?o.toNumber():o}else if(p===D){const n=nt.allocateUnsafe(16);for(let r=0;r<16;r++)n[r]=t[e+r];e+=16,k=new Dt(n)}else if(p===E){let n=at.getInt32LE(t,e);e+=4;const r=n,o=t[e++];if(n<0)throw new W("Negative binary type element size found");if(n>t.byteLength)throw new W("Binary type size larger than document size");if(o===ut.SUBTYPE_BYTE_ARRAY){if(n=at.getInt32LE(t,e),e+=4,n<0)throw new W("Negative binary type element size found for subtype 0x02");if(n>r-4)throw new W("Binary type with subtype 0x02 contains too long binary size");if(n<r-4)throw new W("Binary type with subtype 0x02 contains too short binary size")}a&&c?k=nt.toLocalBufferType(t.subarray(e,e+n)):(k=new ut(t.subarray(e,e+n),o),o===M&&dt.isValid(k)&&(k=k.toUUID())),e+=n}else if(p===B&&!1===s){for(y=e;0!==t[y]&&y<t.length;)y++;if(y>=t.length)throw new W("Bad BSON Document: illegal CString");const n=nt.toUTF8(t,e,y,!1);for(y=e=y+1;0!==t[y]&&y<t.length;)y++;if(y>=t.length)throw new W("Bad BSON Document: illegal CString");const r=nt.toUTF8(t,e,y,!1);e=y+1;const o=new Array(r.length);for(y=0;y<r.length;y++)switch(r[y]){case"m":o[y]="m";break;case"s":o[y]="g";break;case"i":o[y]="i"}k=new RegExp(n,o.join(""))}else if(p===B&&!0===s){for(y=e;0!==t[y]&&y<t.length;)y++;if(y>=t.length)throw new W("Bad BSON Document: illegal CString");const n=nt.toUTF8(t,e,y,!1);for(y=e=y+1;0!==t[y]&&y<t.length;)y++;if(y>=t.length)throw new W("Bad BSON Document: illegal CString");const r=nt.toUTF8(t,e,y,!1);e=y+1,k=new zt(n,r)}else if(p===L){const n=at.getInt32LE(t,e);if(e+=4,n<=0||n>t.length-e||0!==t[e+n-1])throw new W("bad string length in bson");const r=nt.toUTF8(t,e,e+n-1,J);k=c?r:new Gt(r),e+=n}else if(p===U)k=new Kt({i:at.getUint32LE(t,e),t:at.getUint32LE(t,e+4)}),e+=8;else if(p===C)k=new Mt;else if(p===F)k=new qt;else if(p===A){const n=at.getInt32LE(t,e);if(e+=4,n<=0||n>t.length-e||0!==t[e+n-1])throw new W("bad string length in bson");const r=nt.toUTF8(t,e,e+n-1,J);k=new ht(r),e+=n}else if(p===P){const r=at.getInt32LE(t,e);if(e+=4,r<13)throw new W("code_w_scope total size shorter minimum expected length");const o=at.getInt32LE(t,e);if(e+=4,o<=0||o>t.length-e||0!==t[e+o-1])throw new W("bad string length in bson");const i=nt.toUTF8(t,e,e+o-1,J),s=e+=o,a=at.getInt32LE(t,e),u=ee(t,s,n,!1);if(e+=a,r<8+a+o)throw new W("code_w_scope total size is too short, truncating scope");if(r>8+a+o)throw new W("code_w_scope total size is too long, clips outer document");k=new ht(i,u)}else{if(p!==j)throw new W(`Detected unknown BSON type ${p.toString(16)} for fieldname "${g}"`);{const n=at.getInt32LE(t,e);if(e+=4,n<=0||n>t.length-e||0!==t[e+n-1])throw new W("bad string length in bson");const r=nt.toUTF8(t,e,e+n-1,J);e+=n;const o=nt.allocateUnsafe(12);for(let n=0;n<12;n++)o[n]=t[e+n];const i=new Jt(o);e+=12,k=new yt(r,i)}}"__proto__"===g?Object.defineProperty(b,g,{value:k,writable:!0,enumerable:!0,configurable:!0}):b[g]=k}if(g!==e-y){if(r)throw new W("corrupt array bson");throw new W("corrupt object bson")}if(!q)return b;if(pt(b)){const t=Object.assign({},b);return delete t.$ref,delete t.$id,delete t.$db,new yt(b.$ref,b.$id,b.$db,t)}return b}const ne=/\x00/,re=new Set(["$db","$ref","$id","$clusterTime"]);function oe(t,e,n,r){t[r++]=v,t[(r=r+nt.encodeUTF8Into(t,e,r)+1)-1]=0;const o=nt.encodeUTF8Into(t,n,r+4);return at.setInt32LE(t,r,o+1),r=r+4+o,t[r++]=0,r}function ie(t,e,n,r){const o=!Object.is(n,-0)&&Number.isSafeInteger(n)&&n<=h&&n>=p?$:w;return t[r++]=o,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r+(o===$?at.setInt32LE(t,r,n):at.setFloat64LE(t,r,n))}function se(t,e,n,r){return t[r++]=R,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r+at.setBigInt64LE(t,r,n)}function ae(t,e,n,r){return t[r++]=T,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r}function ue(t,e,n,r){return t[r++]=I,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,t[r++]=n?1:0,r}function ce(t,e,n,r){t[r++]=x,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=St.fromNumber(n.getTime()),i=o.getLowBits(),s=o.getHighBits();return(r+=at.setInt32LE(t,r,i))+at.setInt32LE(t,r,s)}function fe(t,e,n,r){if(t[r++]=B,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,n.source&&null!=n.source.match(ne))throw new W("value "+n.source+" must not contain null bytes");return r+=nt.encodeUTF8Into(t,n.source,r),t[r++]=0,n.ignoreCase&&(t[r++]=105),n.global&&(t[r++]=115),n.multiline&&(t[r++]=109),t[r++]=0,r}function le(t,e,n,r){if(t[r++]=B,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,null!=n.pattern.match(ne))throw new W("pattern "+n.pattern+" must not contain null bytes");r+=nt.encodeUTF8Into(t,n.pattern,r),t[r++]=0;const o=n.options.split("").sort().join("");return r+=nt.encodeUTF8Into(t,o,r),t[r++]=0,r}function de(t,e,n,r){return null===n?t[r++]=T:"MinKey"===n._bsontype?t[r++]=C:t[r++]=F,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r}function he(t,e,n,r){return t[r++]=N,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r+n.serializeInto(t,r)}function pe(t,e,n,r){t[r++]=E,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.length;if(r+=at.setInt32LE(t,r,o),t[r++]=q,o<=16)for(let e=0;e<o;e++)t[r+e]=n[e];else t.set(n,r);return r+o}function ye(t,e,n,r,o,i,s,a,u){if(u.has(n))throw new W("Cannot convert circular structure to BSON");u.add(n),t[r++]=Array.isArray(n)?O:_,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const c=Ne(t,n,o,r,i+1,s,a,u);return u.delete(n),c}function ge(t,e,n,r){t[r++]=D,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;for(let e=0;e<16;e++)t[r+e]=n.bytes[e];return r+16}function be(t,e,n,r){t[r++]="Long"===n._bsontype?R:U,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.getLowBits(),i=n.getHighBits();return(r+=at.setInt32LE(t,r,o))+at.setInt32LE(t,r,i)}function me(t,e,n,r){return n=n.valueOf(),t[r++]=$,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r+at.setInt32LE(t,r,n)}function we(t,e,n,r){return t[r++]=w,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r+at.setFloat64LE(t,r,n.value)}function ve(t,e,n,r){t[r++]=A,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.toString(),i=nt.encodeUTF8Into(t,o,r+4)+1;return at.setInt32LE(t,r,i),r=r+4+i-1,t[r++]=0,r}function _e(t,e,n,r,o=!1,i=0,s=!1,a=!0,u){if(n.scope&&"object"==typeof n.scope){t[r++]=P,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;let c=r;const f=n.code;r+=4;const l=nt.encodeUTF8Into(t,f,r+4)+1;at.setInt32LE(t,r,l),t[r+4+l-1]=0,r=r+l+4;const d=Ne(t,n.scope,o,r,i+1,s,a,u);r=d-1;const h=d-c;c+=at.setInt32LE(t,c,h),t[r++]=0}else{t[r++]=A,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.code.toString(),i=nt.encodeUTF8Into(t,o,r+4)+1;at.setInt32LE(t,r,i),r=r+4+i-1,t[r++]=0}return r}function Oe(t,e,n,r){t[r++]=E,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.buffer;let i=n.position;if(n.sub_type===ut.SUBTYPE_BYTE_ARRAY&&(i+=4),r+=at.setInt32LE(t,r,i),t[r++]=n.sub_type,n.sub_type===ut.SUBTYPE_BYTE_ARRAY&&(i-=4,r+=at.setInt32LE(t,r,i)),n.sub_type===ut.SUBTYPE_VECTOR&&ct(n),i<=16)for(let e=0;e<i;e++)t[r+e]=o[e];else t.set(o,r);return r+n.position}function Ee(t,e,n,r){t[r++]=L,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=nt.encodeUTF8Into(t,n.value,r+4)+1;return at.setInt32LE(t,r,o),r=r+4+o-1,t[r++]=0,r}function Se(t,e,n,r,o,i,s){t[r++]=_,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;let a=r,u={$ref:n.collection||n.namespace,$id:n.oid};null!=n.db&&(u.$db=n.db),u=Object.assign(u,n.fields);const c=Ne(t,u,!1,r,o+1,i,!0,s),f=c-a;return a+=at.setInt32LE(t,r,f),c}function Ne(t,e,n,r,o,f,h,p){if(null==p){if(null==e)return t[0]=5,t[1]=0,t[2]=0,t[3]=0,t[4]=0,5;if(Array.isArray(e))throw new W("serialize does not support an array as the root input");if("object"!=typeof e)throw new W("serialize does not support non-object as the root input");if("_bsontype"in e&&"string"==typeof e._bsontype)throw new W("BSON types cannot be serialized as a document");if(c(e)||a(e)||i(e)||s(e))throw new W("date, regexp, typedarray, and arraybuffer cannot be BSON documents");p=new Set}p.add(e);let y=r+4;if(Array.isArray(e))for(let r=0;r<e.length;r++){const s=`${r}`;let u=e[r];"function"==typeof u?.toBSON&&(u=u.toBSON());const g=typeof u;if(void 0===u)y=ae(t,s,0,y);else if(null===u)y=ae(t,s,0,y);else if("string"===g)y=oe(t,s,u,y);else if("number"===g)y=ie(t,s,u,y);else if("bigint"===g)y=se(t,s,u,y);else if("boolean"===g)y=ue(t,s,u,y);else if("object"===g&&null==u._bsontype)y=u instanceof Date||c(u)?ce(t,s,u,y):u instanceof Uint8Array||i(u)?pe(t,s,u,y):u instanceof RegExp||a(u)?fe(t,s,u,y):ye(t,s,u,y,n,o,f,h,p);else if("object"===g){if(u[d]!==l)throw new J;if("ObjectId"===u._bsontype)y=he(t,s,u,y);else if("Decimal128"===u._bsontype)y=ge(t,s,u,y);else if("Long"===u._bsontype||"Timestamp"===u._bsontype)y=be(t,s,u,y);else if("Double"===u._bsontype)y=we(t,s,u,y);else if("Code"===u._bsontype)y=_e(t,s,u,y,n,o,f,h,p);else if("Binary"===u._bsontype)y=Oe(t,s,u,y);else if("BSONSymbol"===u._bsontype)y=Ee(t,s,u,y);else if("DBRef"===u._bsontype)y=Se(t,s,u,y,o,f,p);else if("BSONRegExp"===u._bsontype)y=le(t,s,u,y);else if("Int32"===u._bsontype)y=me(t,s,u,y);else if("MinKey"===u._bsontype||"MaxKey"===u._bsontype)y=de(t,s,u,y);else if(void 0!==u._bsontype)throw new W(`Unrecognized or invalid _bsontype: ${String(u._bsontype)}`)}else"function"===g&&f&&(y=ve(t,s,u,y))}else if(e instanceof Map||u(e)){const r=e.entries();let s=!1;for(;!s;){const e=r.next();if(s=!!e.done,s)continue;const u=e.value?e.value[0]:void 0;let g=e.value?e.value[1]:void 0;"function"==typeof g?.toBSON&&(g=g.toBSON());const b=typeof g;if("string"==typeof u&&!re.has(u)){if(null!=u.match(ne))throw new W("key "+u+" must not contain null bytes");if(n){if("$"===u[0])throw new W("key "+u+" must not start with '$'");if(u.includes("."))throw new W("key "+u+" must not contain '.'")}}if(void 0===g)!1===h&&(y=ae(t,u,0,y));else if(null===g)y=ae(t,u,0,y);else if("string"===b)y=oe(t,u,g,y);else if("number"===b)y=ie(t,u,g,y);else if("bigint"===b)y=se(t,u,g,y);else if("boolean"===b)y=ue(t,u,g,y);else if("object"===b&&null==g._bsontype)y=g instanceof Date||c(g)?ce(t,u,g,y):g instanceof Uint8Array||i(g)?pe(t,u,g,y):g instanceof RegExp||a(g)?fe(t,u,g,y):ye(t,u,g,y,n,o,f,h,p);else if("object"===b){if(g[d]!==l)throw new J;if("ObjectId"===g._bsontype)y=he(t,u,g,y);else if("Decimal128"===g._bsontype)y=ge(t,u,g,y);else if("Long"===g._bsontype||"Timestamp"===g._bsontype)y=be(t,u,g,y);else if("Double"===g._bsontype)y=we(t,u,g,y);else if("Code"===g._bsontype)y=_e(t,u,g,y,n,o,f,h,p);else if("Binary"===g._bsontype)y=Oe(t,u,g,y);else if("BSONSymbol"===g._bsontype)y=Ee(t,u,g,y);else if("DBRef"===g._bsontype)y=Se(t,u,g,y,o,f,p);else if("BSONRegExp"===g._bsontype)y=le(t,u,g,y);else if("Int32"===g._bsontype)y=me(t,u,g,y);else if("MinKey"===g._bsontype||"MaxKey"===g._bsontype)y=de(t,u,g,y);else if(void 0!==g._bsontype)throw new W(`Unrecognized or invalid _bsontype: ${String(g._bsontype)}`)}else"function"===b&&f&&(y=ve(t,u,g,y))}}else{if("function"==typeof e?.toBSON&&null!=(e=e.toBSON())&&"object"!=typeof e)throw new W("toBSON function did not return an object");for(const r of Object.keys(e)){let s=e[r];"function"==typeof s?.toBSON&&(s=s.toBSON());const u=typeof s;if("string"==typeof r&&!re.has(r)){if(null!=r.match(ne))throw new W("key "+r+" must not contain null bytes");if(n){if("$"===r[0])throw new W("key "+r+" must not start with '$'");if(r.includes("."))throw new W("key "+r+" must not contain '.'")}}if(void 0===s)!1===h&&(y=ae(t,r,0,y));else if(null===s)y=ae(t,r,0,y);else if("string"===u)y=oe(t,r,s,y);else if("number"===u)y=ie(t,r,s,y);else if("bigint"===u)y=se(t,r,s,y);else if("boolean"===u)y=ue(t,r,s,y);else if("object"===u&&null==s._bsontype)y=s instanceof Date||c(s)?ce(t,r,s,y):s instanceof Uint8Array||i(s)?pe(t,r,s,y):s instanceof RegExp||a(s)?fe(t,r,s,y):ye(t,r,s,y,n,o,f,h,p);else if("object"===u){if(s[d]!==l)throw new J;if("ObjectId"===s._bsontype)y=he(t,r,s,y);else if("Decimal128"===s._bsontype)y=ge(t,r,s,y);else if("Long"===s._bsontype||"Timestamp"===s._bsontype)y=be(t,r,s,y);else if("Double"===s._bsontype)y=we(t,r,s,y);else if("Code"===s._bsontype)y=_e(t,r,s,y,n,o,f,h,p);else if("Binary"===s._bsontype)y=Oe(t,r,s,y);else if("BSONSymbol"===s._bsontype)y=Ee(t,r,s,y);else if("DBRef"===s._bsontype)y=Se(t,r,s,y,o,f,p);else if("BSONRegExp"===s._bsontype)y=le(t,r,s,y);else if("Int32"===s._bsontype)y=me(t,r,s,y);else if("MinKey"===s._bsontype||"MaxKey"===s._bsontype)y=de(t,r,s,y);else if(void 0!==s._bsontype)throw new W(`Unrecognized or invalid _bsontype: ${String(s._bsontype)}`)}else"function"===u&&f&&(y=ve(t,r,s,y))}}p.delete(e),t[y++]=0;const g=y-r;return r+=at.setInt32LE(t,r,g),y}const Ie={$oid:Jt,$binary:ut,$uuid:ut,$symbol:Gt,$numberInt:Ft,$numberDecimal:Dt,$numberDouble:Ct,$numberLong:St,$minKey:Mt,$maxKey:qt,$regex:zt,$regularExpression:zt,$timestamp:Kt};function xe(t,e={}){if("number"==typeof t){const n=t<=h&&t>=p,r=t<=y&&t>=g;if(e.relaxed||e.legacy)return t;if(Number.isInteger(t)&&!Object.is(t,-0)){if(n)return new Ft(t);if(r)return e.useBigInt64?BigInt(t):St.fromNumber(t)}return new Ct(t)}if(null==t||"object"!=typeof t)return t;if(t.$undefined)return null;const n=Object.keys(t).filter(e=>e.startsWith("$")&&null!=t[e]);for(let r=0;r<n.length;r++){const o=Ie[n[r]];if(o)return o.fromExtendedJSON(t,e)}if(null!=t.$date){const n=t.$date,r=new Date;if(e.legacy)if("number"==typeof n)r.setTime(n);else if("string"==typeof n)r.setTime(Date.parse(n));else{if("bigint"!=typeof n)throw new V("Unrecognized type for EJSON date: "+typeof n);r.setTime(Number(n))}else if("string"==typeof n)r.setTime(Date.parse(n));else if(St.isLong(n))r.setTime(n.toNumber());else if("number"==typeof n&&e.relaxed)r.setTime(n);else{if("bigint"!=typeof n)throw new V("Unrecognized type for EJSON date: "+typeof n);r.setTime(Number(n))}return r}if(null!=t.$code){const e=Object.assign({},t);return t.$scope&&(e.$scope=xe(t.$scope)),ht.fromExtendedJSON(t)}if(pt(t)||t.$dbPointer){const e=t.$ref?t:t.$dbPointer;if(e instanceof yt)return e;const n=Object.keys(e).filter(t=>t.startsWith("$"));let r=!0;if(n.forEach(t=>{-1===["$ref","$id","$db"].indexOf(t)&&(r=!1)}),r)return yt.fromExtendedJSON(e)}return t}function Te(t){const e=t.toISOString();return 0!==t.getUTCMilliseconds()?e:e.slice(0,-5)+"Z"}function Be(t,e){if(t instanceof Map||u(t)){const n=Object.create(null);for(const[e,r]of t){if("string"!=typeof e)throw new W("Can only serialize maps with string keys");n[e]=r}return Be(n,e)}if(("object"==typeof t||"function"==typeof t)&&null!==t){const n=e.seenObjects.findIndex(e=>e.obj===t);if(-1!==n){const t=e.seenObjects.map(t=>t.propertyName),r=t.slice(0,n).map(t=>`${t} -> `).join(""),o=t[n],i=" -> "+t.slice(n+1,t.length-1).map(t=>`${t} -> `).join(""),s=t[t.length-1],a=" ".repeat(r.length+o.length/2),u="-".repeat(i.length+(o.length+s.length)/2-1);throw new W(`Converting circular structure to EJSON:\n ${r}${o}${i}${s}\n ${a}\\${u}/`)}e.seenObjects[e.seenObjects.length-1].obj=t}if(Array.isArray(t))return function(t,e){return t.map((t,n)=>{e.seenObjects.push({propertyName:`index ${n}`,obj:null});try{return Be(t,e)}finally{e.seenObjects.pop()}})}(t,e);if(void 0===t)return null;if(t instanceof Date||c(t)){const n=t.getTime(),r=n>-1&&n<2534023188e5;return e.legacy?e.relaxed&&r?{$date:t.getTime()}:{$date:Te(t)}:e.relaxed&&r?{$date:Te(t)}:{$date:{$numberLong:t.getTime().toString()}}}if(!("number"!=typeof t||e.relaxed&&isFinite(t))){if(Number.isInteger(t)&&!Object.is(t,-0)){if(t>=p&&t<=h)return{$numberInt:t.toString()};if(t>=g&&t<=y)return{$numberLong:t.toString()}}return{$numberDouble:Object.is(t,-0)?"-0.0":t.toString()}}if("bigint"==typeof t)return e.relaxed?Number(BigInt.asIntN(64,t)):{$numberLong:BigInt.asIntN(64,t).toString()};if(t instanceof RegExp||a(t)){let n=t.flags;if(void 0===n){const e=t.toString().match(/[gimuy]*$/);e&&(n=e[0])}return new zt(t.source,n).toExtendedJSON(e)}return null!=t&&"object"==typeof t?function(t,e){if(null==t||"object"!=typeof t)throw new W("not an object instance");const n=t._bsontype;if(void 0===n){const n={};for(const r of Object.keys(t)){e.seenObjects.push({propertyName:r,obj:null});try{const o=Be(t[r],e);"__proto__"===r?Object.defineProperty(n,r,{value:o,writable:!0,enumerable:!0,configurable:!0}):n[r]=o}finally{e.seenObjects.pop()}}return n}if(null!=t&&"object"==typeof t&&"string"==typeof t._bsontype&&t[d]!==l)throw new J;if(function(t){return null!=t&&"object"==typeof t&&"_bsontype"in t&&"string"==typeof t._bsontype}(t)){let r=t;if("function"!=typeof r.toExtendedJSON){const e=je[t._bsontype];if(!e)throw new W("Unrecognized or invalid _bsontype: "+t._bsontype);r=e(r)}return"Code"===n&&r.scope?r=new ht(r.code,Be(r.scope,e)):"DBRef"===n&&r.oid&&(r=new yt(Be(r.collection,e),Be(r.oid,e),Be(r.db,e),Be(r.fields,e))),r.toExtendedJSON(e)}throw new W("_bsontype must be a string, but was: "+typeof n)}(t,e):t}const je={Binary:t=>new ut(t.value(),t.sub_type),Code:t=>new ht(t.code,t.scope),DBRef:t=>new yt(t.collection||t.namespace,t.oid,t.db,t.fields),Decimal128:t=>new Dt(t.bytes),Double:t=>new Ct(t.value),Int32:t=>new Ft(t.value),Long:t=>St.fromBits(null!=t.low?t.low:t.low_,null!=t.low?t.high:t.high_,null!=t.low?t.unsigned:t.unsigned_),MaxKey:()=>new qt,MinKey:()=>new Mt,ObjectId:t=>new Jt(t),BSONRegExp:t=>new zt(t.pattern,t.options),BSONSymbol:t=>new Gt(t.value),Timestamp:t=>Kt.fromBits(t.low,t.high)};function Ae(t,e){const n={useBigInt64:e?.useBigInt64??!1,relaxed:e?.relaxed??!0,legacy:e?.legacy??!1};return JSON.parse(t,(t,e)=>{if(-1!==t.indexOf("\0"))throw new W(`BSON Document field names cannot contain null bytes, found: ${JSON.stringify(t)}`);return xe(e,n)})}function Le(t,e,n,r){null!=n&&"object"==typeof n&&(r=n,n=0),null==e||"object"!=typeof e||Array.isArray(e)||(r=e,e=void 0,n=0);const o=Be(t,Object.assign({relaxed:!0,legacy:!1},r,{seenObjects:[{propertyName:"(root)",obj:null}]}));return JSON.stringify(o,e,n)}const Pe=Object.create(null);Pe.parse=Ae,Pe.stringify=Le,Pe.serialize=function(t,e){return e=e||{},JSON.parse(Le(t,e))},Pe.deserialize=function(t,e){return e=e||{},Ae(JSON.stringify(t),e)},Object.freeze(Pe);function $e(t,e){try{return at.getNonnegativeInt32LE(t,e)}catch(t){throw new H("BSON size cannot be negative",e,{cause:t})}}function Ue(t,e){let n=e;for(;0!==t[n];n++);if(n===t.length-1)throw new H("Null terminator not found",e);return n}const Re=Object.create(null);Re.parseToElements=function(t,e=0){if(e??=0,t.length<5)throw new H(`Input must be at least 5 bytes, got ${t.length} bytes`,e);const n=$e(t,e);if(n>t.length-e)throw new H(`Parsed documentSize (${n} bytes) does not match input length (${t.length} bytes)`,e);if(0!==t[e+n-1])throw new H("BSON documents must end in 0x00",e+n);const r=[];let o=e+4;for(;o<=n+e;){const i=t[o];if(o+=1,0===i){if(o-e!==n)throw new H("Invalid 0x00 type byte",o);break}const s=o,a=Ue(t,o)-s;let u;if(o+=a+1,1===i||18===i||9===i||17===i)u=8;else if(16===i)u=4;else if(7===i)u=12;else if(19===i)u=16;else if(8===i)u=1;else if(10===i||6===i||127===i||255===i)u=0;else if(11===i)u=Ue(t,Ue(t,o)+1)+1-o;else if(3===i||4===i||15===i)u=$e(t,o);else{if(2!==i&&5!==i&&12!==i&&13!==i&&14!==i)throw new H(`Invalid 0x${i.toString(16).padStart(2,"0")} type byte`,o);u=$e(t,o)+4,5===i&&(u+=1),12===i&&(u+=12)}if(u>n)throw new H("value reports length larger than document",o);r.push([i,s,a,o,u]),o+=u}return r},Re.ByteUtils=nt,Re.NumberUtils=at,Object.freeze(Re);const De=17825792;let Ce=nt.allocate(De);function Fe(t){Ce.length<t&&(Ce=nt.allocate(t))}function qe(t,e={}){const n="boolean"==typeof e.checkKeys&&e.checkKeys,r="boolean"==typeof e.serializeFunctions&&e.serializeFunctions,o="boolean"!=typeof e.ignoreUndefined||e.ignoreUndefined,i="number"==typeof e.minInternalBufferSize?e.minInternalBufferSize:De;Ce.length<i&&(Ce=nt.allocate(i));const s=Ne(Ce,t,n,0,0,r,o,null),a=nt.allocateUnsafe(s);return a.set(Ce.subarray(0,s),0),a}function Me(t,e,n={}){const r="boolean"==typeof n.checkKeys&&n.checkKeys,o="boolean"==typeof n.serializeFunctions&&n.serializeFunctions,i="boolean"!=typeof n.ignoreUndefined||n.ignoreUndefined,s="number"==typeof n.index?n.index:0,a=Ne(Ce,t,r,0,0,o,i,null);return e.set(Ce.subarray(0,a),s),s+a-1}function ke(t,e={}){return Xt(nt.toLocalBufferType(t),e)}function We(t,e={}){return Vt(t,"boolean"==typeof(e=e||{}).serializeFunctions&&e.serializeFunctions,"boolean"!=typeof e.ignoreUndefined||e.ignoreUndefined)}function Je(t,e,n,r,o,i){const s=Object.assign({allowObjectSmallerThanBufferSize:!0,index:0},i),a=nt.toLocalBufferType(t);let u=e;for(let t=0;t<n;t++){const e=at.getInt32LE(a,u);s.index=u,r[o+t]=Xt(a,s),u+=e}return u}var Ve=Object.freeze({__proto__:null,BSONError:W,BSONOffsetError:H,BSONRegExp:zt,BSONRuntimeError:V,BSONSymbol:Gt,BSONType:k,BSONValue:rt,BSONVersionError:J,Binary:ut,Code:ht,DBRef:yt,Decimal128:Dt,Double:Ct,EJSON:Pe,Int32:Ft,Long:St,MaxKey:qt,MinKey:Mt,ObjectId:Jt,Timestamp:Kt,UUID:dt,calculateObjectSize:We,deserialize:ke,deserializeStream:Je,onDemand:Re,serialize:qe,serializeWithBufferAndIndex:Me,setInternalBufferSize:Fe})}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,n),i.exports}return n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n(198)})());
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("cloudbase_database",[],e):"object"==typeof exports?exports.cloudbase_database=e():t.cloudbase_database=e()}("undefined"!=typeof window?window:this,()=>(()=>{var t={829:(t,e,n)=>{"use strict";var r;n.r(e),n.d(e,{AbstractSDKRequest:()=>o,AbstractStorage:()=>i,StorageType:()=>r,formatUrl:()=>s}),function(t){t.local="local",t.none="none",t.session="session"}(r||(r={}));var o=function(){},i=function(){};function s(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";for(var i in n)""===o?!r&&(e+="?"):o+="&",o+=i+"="+encodeURIComponent(n[i]);return/^http(s)?\:\/\//.test(e+=o)?e:""+t+e}},198:function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},i.apply(this,arguments)},s=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},a=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.registerDatabase=e.gateWayFunc=void 0;var u=n(954),c=n(804),f=n(877);e.gateWayFunc={filterRes:function(t){return delete(t=f.utils.promoteGatewayError(t)).header,delete t.statusCode,t},flattenResData:function(t){if("object"==typeof t.data&&null!==t.data){var e=i(i({},t),t.data);return delete e.data,e}return t},safeParseEJSON:function(t){if("string"!=typeof t)return t;try{return c.EJSON.parse(t)}catch(e){return t}},parseEJSONParam:function(t){if("string"!=typeof t)return t;try{return JSON.parse(t)}catch(e){return t}},parseEJSONValue:function(t){if("string"!=typeof t)return t;try{return c.EJSON.parse(t)}catch(n){return e.gateWayFunc.parseEJSONParam(t)}},normalizeOrderParam:function(t){if(null!=t&&""!==t){for(var n=e.gateWayFunc.parseEJSONValue(t),r=function(t){var e=t&&"object"==typeof t?Number(t):t;if("number"==typeof e&&!isNaN(e))return e<0?"desc":"asc";if("string"==typeof e){var n=e.toLowerCase();if("desc"===n||"-1"===n)return"desc";if("asc"===n||"1"===n)return"asc"}},o=[],i=0,s=Array.isArray(n)?n:[n];i<s.length;i++){var a=s[i];if(a&&"object"==typeof a)if(void 0!==a.field)(f=r(a.direction))&&o.push({field:a.field,direction:f});else for(var u=0,c=Object.entries(a);u<c.length;u++){var f,l=c[u],d=l[0];(f=r(l[1]))&&o.push({field:d,direction:f})}}return o.length?o:void 0}},extractDocId:function(t){if(t&&"object"==typeof t&&!Array.isArray(t)&&1===Object.keys(t).length&&"_id"in t){var e=t._id;if("string"==typeof e||"number"==typeof e)return String(e);if(e&&"object"==typeof e){if("string"==typeof e.$oid)return e.$oid;var n=e.$eq;if("string"==typeof n||"number"==typeof n)return String(n);if(n&&"object"==typeof n&&"string"==typeof n.$oid)return n.$oid}}},toLegacyRegExp:function(t){if(!t||"object"!=typeof t)return t;if(t.$regularExpression&&"object"==typeof t.$regularExpression){var n=t.$regularExpression;return{$regex:n.pattern,$options:n.options}}if(Array.isArray(t))return t.map(function(t){return e.gateWayFunc.toLegacyRegExp(t)});var r={};for(var o in t)r[o]=e.gateWayFunc.toLegacyRegExp(t[o]);return r},parseWriteParam:function(t){return e.gateWayFunc.toLegacyRegExp(e.gateWayFunc.parseEJSONParam(t))},buildQueryParams:function(t){return Object.entries(t).filter(function(t){t[0];var e=t[1];return null!=e&&""!==e}).map(function(t){var e=t[0],n=t[1],r="object"==typeof n?JSON.stringify(n):String(n);return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(r))}).join("&")},getUrlPrefix:function(t){var e=(null==t?void 0:t.instance)||"(default)",n=(null==t?void 0:t.database)||"(default)";return"/database/instances/".concat(e,"/databases/").concat(n)},"database.queryDocument":function(t,n){var r,o,u,f;return s(this,void 0,Promise,function(){var s,l,d,h,p,y,g;return a(this,function(a){switch(a.label){case 0:return s=e.gateWayFunc.parseEJSONParam(t.query),l=e.gateWayFunc.parseEJSONValue(t.projection),d=e.gateWayFunc.extractDocId(s),h=void 0!==d,p=e.gateWayFunc.buildQueryParams(i({projection:l,transactionId:t.transactionId},h?{}:{offset:null!==(r=t.offset)&&void 0!==r?r:0,limit:null!==(o=t.limit)&&void 0!==o?o:100,order:e.gateWayFunc.normalizeOrderParam(t.order),query:s?c.EJSON.stringify(s,{relaxed:!1}):void 0})),y="".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(p),h&&(y="".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/").concat(d,"?").concat(p)),[4,this.gateWay({url:y,method:"GET"},n)];case 1:return(g=a.sent()).data=e.gateWayFunc.safeParseEJSON(JSON.stringify(g.data)),!h||g.code||(null===(u=g.data)||void 0===u?void 0:u.code)?(g.code||(null===(f=g.data)||void 0===f?void 0:f.code)?g=i(i({},g),{data:i(i({},g.data),{list:[]})}):Array.isArray(g.data)?g=i(i({},g),{data:{list:g.data}}):g.data&&!Array.isArray(g.data.list)&&(g=i(i({},g),{data:i(i({},g.data),{list:[]})})),[2,e.gateWayFunc.filterRes(g)]):[2,i(i({},g),{data:{list:[g.data]}})]}})})},"database.addDocument":function(t,n){var r,o,u;return s(this,void 0,Promise,function(){var s,c;return a(this,function(a){switch(a.label){case 0:return s=(Array.isArray(t.data)?t.data:[t.data]).map(function(t){return e.gateWayFunc.parseWriteParam(t)}),[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"POST",data:i({data:s},t.transactionId&&{transactionId:t.transactionId})},n)];case 1:return c=a.sent(),Array.isArray(t.data)?c=i(i({},c),{data:i({ids:(null===(r=c.data)||void 0===r?void 0:r.insertedIds)||[]},c.data)}):(null===(u=null===(o=c.data)||void 0===o?void 0:o.insertedIds)||void 0===u?void 0:u[0])&&(c=i(i({},c),{data:i({_id:c.data.insertedIds[0]},c.data)})),[2,e.gateWayFunc.filterRes(c)]}})})},"database.updateDocument":function(t,n){var r;return s(this,void 0,Promise,function(){var o;return a(this,function(s){switch(s.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"PATCH",data:i({query:e.gateWayFunc.parseEJSONParam(t.query),data:e.gateWayFunc.parseEJSONParam(t.data),multi:!!t.multi,upsert:!!t.upsert,replaceMode:null!==(r=t.replaceMode)&&void 0!==r?r:!1===t.merge},t.transactionId&&{transactionId:t.transactionId})},n)];case 1:return o=s.sent(),[2,e.gateWayFunc.filterRes(o)]}})})},"database.deleteDocument":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/remove"),method:"POST",data:i({query:e.gateWayFunc.parseEJSONParam(t.query),multi:!!t.multi},t.transactionId&&{transactionId:t.transactionId})},n)];case 1:return r=o.sent(),[2,e.gateWayFunc.filterRes(r)]}})})},"database.countDocument":function(t,n){return s(this,void 0,Promise,function(){var r,o,i;return a(this,function(s){switch(s.label){case 0:return r=e.gateWayFunc.parseEJSONParam(t.query),o=e.gateWayFunc.buildQueryParams({count:!0,query:r?c.EJSON.stringify(r,{relaxed:!1}):void 0}),[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(o),method:"GET"},n)];case 1:return i=s.sent(),[2,e.gateWayFunc.filterRes(i)]}})})},"database.addCollection":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/collections"),method:"POST",data:{collectionName:t.collectionName}},n)];case 1:return r=o.sent(),[2,e.gateWayFunc.filterRes(r)]}})})},"database.aggregate":function(t,n){var r;return s(this,void 0,Promise,function(){var o,i;return a(this,function(s){switch(s.label){case 0:return o=t.stages.map(function(t){var e,n;try{var r="string"==typeof t.stageValue?JSON.parse(t.stageValue):t.stageValue;return(e={})[t.stageKey]=c.EJSON.serialize(r),e}catch(e){return(n={})[t.stageKey]=t.stageValue,n}}),[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/aggregations"),method:"POST",data:{pipeline:o}},n)];case 1:return i=s.sent(),Array.isArray(null===(r=i.data)||void 0===r?void 0:r.list)&&(i.data.list=JSON.stringify(i.data.list.map(function(t){return JSON.stringify(t)}))),[2,e.gateWayFunc.filterRes(i)]}})})},"database.startTransaction":function(t,n){return s(this,void 0,void 0,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/transactions"),method:"POST"},n)];case 1:return r=o.sent(),[2,e.gateWayFunc.filterRes(e.gateWayFunc.flattenResData(r))]}})})},"database.commitTransaction":function(t,n){return s(this,void 0,void 0,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/commit"),method:"POST"},n)];case 1:return r=o.sent(),[2,e.gateWayFunc.filterRes(r)]}})})},"database.abortTransaction":function(t,n){return s(this,void 0,void 0,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/rollback"),method:"POST"},n)];case 1:return r=o.sent(),[2,e.gateWayFunc.filterRes(r)]}})})},"database.getInTransaction":function(t,n){var r;return s(this,void 0,void 0,function(){var o;return a(this,function(s){switch(s.label){case 0:return[4,e.gateWayFunc["database.queryDocument"].call(this,t,n)];case 1:return"object"==typeof(o=s.sent()).data&&null!==o.data?(null===(r=o.data)||void 0===r?void 0:r.code)?[2,e.gateWayFunc.flattenResData(o)]:[2,i(i({},o),{data:JSON.stringify(o.data)})]:[2,o]}})})},"database.updateDocInTransaction":function(t,n){return s(this,void 0,void 0,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,e.gateWayFunc["database.updateDocument"].call(this,t,n)];case 1:return r=o.sent(),[2,e.gateWayFunc.flattenResData(r)]}})})},"database.deleteDocInTransaction":function(t,n){return s(this,void 0,void 0,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,e.gateWayFunc["database.deleteDocument"].call(this,t,n)];case 1:return r=o.sent(),[2,e.gateWayFunc.flattenResData(r)]}})})},"database.insertDocInTransaction":function(t,n){var r;return s(this,void 0,Promise,function(){var o,s;return a(this,function(a){switch(a.label){case 0:return[4,e.gateWayFunc["database.addDocument"].call(this,t,n)];case 1:return"object"==typeof(o=a.sent()).data&&null!==o.data?(s=!!(null===(r=o.data)||void 0===r?void 0:r._id),o=i(i(i({},o),{inserted:s?1:0,ok:s?1:0}),o.data)):o=i({inserted:0,ok:0},o),delete o.data,[2,o]}})})},"database.runCommands":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(t),"/commands"),method:"POST",data:i({commands:c.EJSON.serialize(Array.isArray(t.commands)?t.commands.map(function(t){return e.gateWayFunc.parseEJSONParam(t)}):t.commands)},t.transactionId&&{transactionId:t.transactionId})},n)];case 1:"object"==typeof(r=o.sent()).data&&null!==r.data&&(delete(r=i(i({},r),r.data)).data,delete r.request_id);try{r=c.EJSON.deserialize(r)}catch(t){}return[2,e.gateWayFunc.filterRes(r)]}})})},"database.getDocument":function(t,n){var r;return s(this,void 0,Promise,function(){var o,s;return a(this,function(a){switch(a.label){case 0:return(o=i({},t)).query=e.gateWayFunc.parseEJSONParam(o.query),o.projection=e.gateWayFunc.parseEJSONValue(o.projection),[4,e.gateWayFunc["database.queryDocument"].call(this,o,n)];case 1:return s=a.sent(),Array.isArray(null===(r=s.data)||void 0===r?void 0:r.list)&&(s.data.list=s.data.list.map(function(t){return c.EJSON.stringify(t,{relaxed:!1})})),[2,s]}})})},"database.insertDocument":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){return(r=i({},t)).data=Array.isArray(r.data)?r.data.map(function(t){return e.gateWayFunc.parseWriteParam(t)}):e.gateWayFunc.parseWriteParam(r.data),[2,e.gateWayFunc["database.addDocument"].call(this,r,n)]})})},"database.modifyDocument":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){return(r=i({},t)).query=e.gateWayFunc.parseEJSONParam(r.query),r.data=e.gateWayFunc.parseEJSONParam(r.data),[2,e.gateWayFunc["database.updateDocument"].call(this,r,n)]})})},"database.modifyAndReturnDoc":function(t,n){var r,o;return s(this,void 0,Promise,function(){var s,u,f;return a(this,function(a){switch(a.label){case 0:return(s=i({},t)).query=e.gateWayFunc.parseEJSONParam(s.query),s.data=e.gateWayFunc.parseEJSONParam(s.data),(u=e.gateWayFunc.extractDocId(s.query))?[4,this.gateWay({url:"".concat(e.gateWayFunc.getUrlPrefix(s),"/collections/").concat(s.collectionName,"/documents/").concat(u),method:"PATCH",data:i({data:s.data,replaceMode:null!==(r=s.replaceMode)&&void 0!==r&&r,upsert:!!s.upsert,returnDoc:!0},s.transactionId&&{transactionId:s.transactionId})},n)]:[2,e.gateWayFunc["database.updateDocument"].call(this,s,n)];case 1:return f=a.sent(),void 0!==(null===(o=f.data)||void 0===o?void 0:o.doc)&&"string"!=typeof f.data.doc&&(f.data.doc=c.EJSON.stringify(f.data.doc,{relaxed:!1})),[2,e.gateWayFunc.filterRes(f)]}})})},"database.removeDocument":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){return(r=i({},t)).query=e.gateWayFunc.parseEJSONParam(r.query),void 0!==r.query&&null!==r.query&&""!==r.query||(r.query={_id:{$exists:!0}}),[2,e.gateWayFunc["database.deleteDocument"].call(this,r,n)]})})},"database.calculateDocument":function(t,n){return s(this,void 0,Promise,function(){var r;return a(this,function(o){return(r=i({},t)).query=e.gateWayFunc.parseEJSONParam(r.query),[2,e.gateWayFunc["database.countDocument"].call(this,r,n)]})})},"database.aggregateDocuments":function(t,n){var r;return s(this,void 0,Promise,function(){var o,s;return a(this,function(a){switch(a.label){case 0:return o=i({},t),Array.isArray(o.stages)&&(o.stages=o.stages.map(function(t){return i(i({},t),{stageValue:e.gateWayFunc.parseEJSONParam(t.stageValue)})})),[4,e.gateWayFunc["database.aggregate"].call(this,o,n)];case 1:if(s=a.sent(),"string"==typeof(null===(r=s.data)||void 0===r?void 0:r.list))try{s.data.list=JSON.parse(s.data.list)}catch(t){}return[2,s]}})})}};var l={name:"database",entity:{database:function(t){var n;if(void 0!==t&&"Object"!==Object.prototype.toString.call(t).slice(8,-1))throw f.utils.createCloudbaseError({code:"INVALID_PARAM",msg:"dbConfig must be an object"},null===(n=this.config)||void 0===n?void 0:n.errorFactory);var r=this.platform,c=r.adapter,l=r.runtime,d=function(t){function n(e){return t.call(this,e)||this}return o(n,t),n.prototype.send=function(n,r,o){var i,u,c,l;return s(this,void 0,void 0,function(){var s,d,h;return a(this,function(a){switch(a.label){case 0:return s=null,d=o&&"number"==typeof o.timeout?{timeout:o.timeout}:void 0,"GATEWAY"===this.config.endPointMode&&e.gateWayFunc[n]?[4,e.gateWayFunc[n].call(this,r,d)]:[3,2];case 1:return s=a.sent(),[3,4];case 2:return[4,t.prototype.send.call(this,n,r,void 0,d)];case 3:s=a.sent(),a.label=4;case 4:if(h=f.utils.resolveThrow(null!==(c=null===(u=null===(i=this.config)||void 0===i?void 0:i._fromApp)||void 0===u?void 0:u.config)&&void 0!==c?c:this.config),s&&s.code&&h)throw f.utils.createCloudbaseError({code:s.code,msg:s.message||s.data&&s.data.message||"",requestId:s.requestId},null===(l=this.config)||void 0===l?void 0:l.errorFactory);return[2,s]}})})},n}(this.request.constructor);return u.Db.reqClass=d,u.Db.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},u.Db.runtime=l,this.wsClientClass&&(u.Db.wsClass=c.wsClass,u.Db.wsClientClass=this.wsClientClass),u.Db.ws||(u.Db.ws=null),new(function(t){function e(e){return t.call(this,e)||this}return o(e,t),e.prototype.runCommands=function(t){return s(this,void 0,Promise,function(){return a(this,function(e){return[2,u.Db.createRequest(this.config).send("database.runCommands",t)]})})},e}(u.Db))(i(i(i({},this.config),{_fromApp:this}),t))}}};try{cloudbase.registerComponent(l)}catch(t){}function d(t){try{t.registerComponent(l)}catch(t){console.warn(t)}}e.registerDatabase=d;try{window.registerDatabase=d}catch(t){}},563:function(t,e,n){"use strict";var r=this&&this.__assign||function(){return r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)},o=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),i=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&o(e,t,n);return i(e,t),e};Object.defineProperty(e,"__esModule",{value:!0}),e.useDefaultAdapter=e.useAdapters=e.RUNTIME=void 0;var a,u=s(n(92)),c=n(962);!function(t){t.WEB="web",t.WX_MP="wx_mp"}(a=e.RUNTIME||(e.RUNTIME={})),e.useAdapters=function(t,e){for(var n=0,o=(0,c.isArray)(t)?t:[t];n<o.length;n++){var i=o[n],s=i.isMatch,a=i.genAdapter,u=i.runtime;if(s())return{adapter:r({isMatch:s},a(e)),runtime:u}}},e.useDefaultAdapter=function(){return{adapter:r({},u.genAdapter()),runtime:a.WEB}}},92:function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},i.apply(this,arguments)},s=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},a=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.WebRequest=e.genAdapter=void 0;var u=n(829),c=n(962),f=n(464),l=function(t){function e(e){var n=t.call(this)||this,r=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=r||0,n.timeoutMsg=o||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}return o(e,t),e.prototype.get=function(t){return this.request(i(i({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(i(i({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(i(i({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t,n=e.data,r=e.file,o=e.fileContent,s=e.name,a=e.method,u=e.headers,c=void 0===u?{}:u,f=null!=r?r:o,l={post:"post",put:"put"}[null==a?void 0:a.toLowerCase()]||"put",d=new FormData;return"post"===l?(Object.keys(n).forEach(function(t){d.append(t,n[t])}),d.append("key",s),d.append("file",f instanceof Blob?f:new Blob([f])),this.request(i(i({},t),{data:d,method:l}),this.restrictedMethods.includes("upload"))):this.request(i(i({},t),{method:"put",headers:c,body:f}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return s(this,void 0,Promise,function(){var e,n,r,o;return a(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,this.get(i(i({},t),{headers:{},responseType:"blob"}))];case 1:return e=s.sent().data,n=window.URL.createObjectURL(new Blob([e])),r=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=n,o.setAttribute("download",r),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n),document.body.removeChild(o),[3,3];case 2:return s.sent(),[3,3];case 3:return[2,new Promise(function(e){e({statusCode:200,tempFilePath:t.url})})]}})})},e.prototype.fetch=function(t){var e;return s(this,void 0,Promise,function(){var n,r,o,u,c,f,l,d,h,p,y,g,b,m=this;return a(this,function(w){switch(w.label){case 0:return n=new AbortController,r=t.url,o=t.enableAbort,u=void 0!==o&&o,c=t.stream,f=void 0!==c&&c,l=t.signal,d=t.timeout,h=t.shouldThrowOnError,p=void 0===h||h,y=null!=d?d:this.timeout,l&&(l.aborted&&n.abort(),l.addEventListener("abort",function(){return n.abort()})),g=null,u&&y&&(g=setTimeout(function(){console.warn(m.timeoutMsg),n.abort(new Error(m.timeoutMsg))},y)),[4,fetch(r,i(i({},t),{signal:n.signal})).then(function(t){return s(m,void 0,void 0,function(){var e,n,r;return a(this,function(o){switch(o.label){case 0:return clearTimeout(g),p?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return r=(n=Promise).reject,[4,t.json()];case 2:e=r.apply(n,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}})})}).catch(function(t){return clearTimeout(g),Promise.reject(t)})];case 1:return b=w.sent(),[2,{data:f?b.body:(null===(e=b.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?b.json():b.text(),statusCode:b.status,header:b.headers,response:b}]}})})},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var r=String(t.method).toLowerCase()||"get";return new Promise(function(o){var i=t.url,s=t.headers,a=void 0===s?{}:s,u=t.data,l=t.responseType,d=t.withCredentials,h=t.body,p=t.onUploadProgress,y=(0,c.formatUrl)((0,f.getProtocol)(),i,"get"===r?u:{}),g=new XMLHttpRequest;g.open(r,y),l&&(g.responseType=l);var b,m,w=t.signal;w&&(w.aborted?g.abort():w.addEventListener("abort",function(){return g.abort()},{once:!0})),Object.keys(a).forEach(function(t){g.setRequestHeader(t,a[t])}),p&&g.upload.addEventListener("progress",p),g.onreadystatechange=function(){var t={};if(4===g.readyState){var e=g.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};e.forEach(function(t){var e=t.split(": "),r=e.shift().toLowerCase(),o=e.join(": ");n[r]=o}),t.header=n,t.statusCode=g.status;try{t.data="blob"===l?g.response:JSON.parse(g.responseText)}catch(e){t.data="blob"===l?g.response:g.responseText}clearTimeout(b),o(t)}},e&&n.timeout&&(b=setTimeout(function(){console.warn(n.timeoutMsg),g.abort()},n.timeout)),m=(0,c.isFormData)(u)?u:"application/x-www-form-urlencoded"===a["content-type"]?(0,c.toQueryString)(u):h||(u?JSON.stringify(u):void 0),d&&(g.withCredentials=!0),g.send(m)})},e}(u.AbstractSDKRequest);e.WebRequest=l,e.genAdapter=function(){return{type:"default",root:window,reqClass:l,wsClass:WebSocket,localStorage}}},464:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.COMMUNITY_SITE_URL=e.IS_DEBUG_MODE=e.getProtocol=e.setProtocol=e.getSdkName=e.setSdkName=void 0;var n="@cloudbase/js-sdk";e.setSdkName=function(t){n=t},e.getSdkName=function(){return n};var r="https:";e.setProtocol=function(t){r=t},e.getProtocol=function(){return r},e.IS_DEBUG_MODE=!1,e.COMMUNITY_SITE_URL="https://support.qq.com/products/148793"},519:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ERRORS=void 0,e.ERRORS={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"}},778:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),e.OATUH_LOGINTYPE=void 0,o(n(464),e),o(n(519),e),e.OATUH_LOGINTYPE="constants"},517:function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},o=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.catchErrorsDecorator=void 0;var i=n(962),s=n(778),a=!1;"undefined"!=typeof navigator&&navigator.userAgent&&(a=-1!==navigator.userAgent.indexOf("Firefox"));var u=a?/(\.js\/)?__decorate(\$\d+)?<@.*\d$/:/(\/\w+\.js\.)?__decorate(\$\d+)?\s*\(.*\)$/,c=/https?:\/\/.+:\d*\/.*\.js:\d+:\d+/;function f(t){var e=t.err,n=t.className,r=t.methodName,o=t.sourceLink;if(!o)return null;var i,s=e.stack.split("\n"),u=a?/^catchErrorsDecorator\/<\/descriptor.value@.*\d$/:new RegExp("".concat(n,"\\.descriptor.value\\s*\\[as\\s").concat(r,"\\]\\s*\\(.*\\)$")),f=a?/^catchErrorsDecorator\/<\/descriptor.value/:new RegExp("".concat(n,"\\.descriptor.value\\s*\\[as\\s").concat(r,"\\]")),l=s.findIndex(function(t){return u.test(t)});if(-1!==l){var d=s.filter(function(t,e){return e>l});d.unshift(s[l].replace(f,"".concat(n,".").concat(r)).replace(c,o)),(i=new Error).stack="".concat(a?"@debugger":"Error","\n").concat(d.join("\n"))}return i}e.catchErrorsDecorator=function(t){var e=t.mode,n=void 0===e?"async":e,a=t.customInfo,l=void 0===a?{}:a,d=t.title,h=t.messages,p=void 0===h?[]:h;return function(t,e,a){if(s.IS_DEBUG_MODE){var h=l.className||t.constructor.name,y=l.methodName||e,g=a.value,b=function(){var t="",e=(new Error).stack.split("\n"),n=e.findIndex(function(t){return u.test(t)});if(-1!==n){var r=c.exec(e[n+1]||"");t=r?r[0]:""}return t}();a.value="sync"===n?function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=f({err:new Error,className:h,methodName:y,sourceLink:b});try{return g.apply(this,t)}catch(t){var r=t,o=t.message,s=t.error,a=t.error_description,u={title:d||"".concat(h,".").concat(y," failed"),content:[{type:"error",body:t}]};if(o&&/^\{.*\}$/.test(o)){var c=JSON.parse(o);u.subtitle=o,c.code&&(n?(n.code=c.code,n.msg=c.msg):(t.code=c.code,t.message=c.msg),r=n||t,u.content=p.map(function(t){return{type:"info",body:t}}))}throw s&&a&&(u.subtitle=a,n?(n.code=s,n.msg=a):(t.code=s,t.message=a),r=n||t,u.content=p.map(function(t){return{type:"info",body:t}})),(0,i.printGroupLog)(u),r}}:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return r(this,void 0,void 0,function(){var e,n,r,s,a,u,c,l;return o(this,function(o){switch(o.label){case 0:e=f({err:new Error,className:h,methodName:y,sourceLink:b}),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,g.apply(this,t)];case 2:return[2,o.sent()];case 3:throw n=o.sent(),r=n,s=n.message,a=n.error,u=n.error_description,c={title:d||"".concat(h,".").concat(y," failed"),content:[{type:"error",body:n}]},s&&/^\{.*\}$/.test(s)&&(l=JSON.parse(s),c.subtitle=l,l.code&&(e?(e.code=l.code,e.message=l.msg):(n.code=l.code,n.message=l.msg),r=e||n,c.content=p.map(function(t){return{type:"info",body:t}}))),a&&u&&(c.subtitle=u,e?(e.code=a,e.msg=u):(n.code=a,n.message=u),r=e||n,c.content=p.map(function(t){return{type:"info",body:t}})),(0,i.printGroupLog)(c),r;case 4:return[2]}})})}}}}},260:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),o(n(517),e)},877:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&r(e,t,n);return o(e,t),e},s=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.langEvent=e.AbortController=e.jwt=e.helpers=e.utils=e.events=e.cache=e.adapters=e.constants=void 0;var a=i(n(778));e.constants=a;var u=i(n(563));e.adapters=u;var c=i(n(865));e.cache=c;var f=i(n(940));e.events=f;var l=i(n(991));e.langEvent=l;var d=i(n(962));e.utils=d;var h=i(n(260));e.helpers=h;var p=s(n(644));e.AbortController=p.default;var y={decode:s(n(949)).default};e.jwt=y},644:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){var t=this;this.listeners=[],this.signal={aborted:!1,addEventListener:function(e,n){"abort"===e&&t.listeners.push(n)}}}return t.prototype.abort=function(){this.signal.aborted||(this.signal.aborted=!0,this.listeners.forEach(function(t){return t()}))},t}();e.default=n},865:function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},s=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.CloudbaseCache=void 0;var a=n(829),u=n(962),c=n(778),f=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return o(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(a.AbstractStorage),l=function(){function t(t){this.keys={};var e=t.persistence,n=t.platformInfo,r=void 0===n?{}:n,o=t.keys,i=void 0===o?{}:o;this.platformInfo=r,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:((0,u.printWarn)(c.ERRORS.INVALID_PARAMS,"localStorage is not supported on current platform"),new f(e.root));case"none":return new f(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}return Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,n){if("async"!==this.mode){if(this.storage)try{var r={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(r))}catch(t){throw new Error(JSON.stringify({code:c.ERRORS.OPERATION_FAIL,msg:"[".concat((0,c.getSdkName)(),"][").concat(c.ERRORS.OPERATION_FAIL,"]setStore failed"),info:t}))}}else(0,u.printWarn)(c.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return i(this,void 0,void 0,function(){var r;return s(this,function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}})})},t.prototype.getStore=function(t,e){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!0,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!0,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var r=this.storage.getItem(t);return r&&r.indexOf(e)>=0?JSON.parse(r).content:""}(0,u.printWarn)(c.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return i(this,void 0,void 0,function(){var r;return s(this,function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!0,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!0,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(r=o.sent())&&r.indexOf(e)>=0?[2,JSON.parse(r).content]:[2,""]}})})},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):(0,u.printWarn)(c.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return i(this,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}})})},t}();e.CloudbaseCache=l},940:function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};Object.defineProperty(e,"__esModule",{value:!0}),e.removeEventListener=e.activateEvent=e.addEventListener=e.CloudbaseEventEmitter=e.IErrorEvent=e.CloudbaseEvent=void 0;var s=n(962),a=function(t,e){this.data=e||null,this.name=t};e.CloudbaseEvent=a;var u=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return o(e,t),e}(a);e.IErrorEvent=u;var c=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if((0,s.isInstanceOf)(t,u))return console.error(t.error),this;var n=(0,s.isString)(t)?new a(t,e||{}):t,r=n.name;if(this.listens(r)){n.target=this;for(var o=0,c=this.listeners[r]?i([],this.listeners[r],!0):[];o<c.length;o++)c[o].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();e.CloudbaseEventEmitter=c;var f=new c;e.addEventListener=function(t,e){f.on(t,e)},e.activateEvent=function(t,e){void 0===e&&(e={}),f.fire(t,e)},e.removeEventListener=function(t,e){f.off(t,e)}},991:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.LANG_CHANGE_EVENT=e.bus=void 0;var r=n(940);e.bus=new r.CloudbaseEventEmitter,e.LANG_CHANGE_EVENT="lang_change"},962:function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},i.apply(this,arguments)},s=this&&this.__rest||function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n};Object.defineProperty(e,"__esModule",{value:!0}),e.parseCaptcha=e.parseQueryString=e.transformPhone=e.sleep=e.printGroupLog=e.errorToResult=e.promoteGatewayError=e.maybeThrow=e.resolveThrow=e.createCloudbaseError=e.CloudbaseError=e.throwError=e.printInfo=e.printError=e.printWarn=e.execCallback=e.createPromiseCallback=e.removeParam=e.getHash=e.getQuery=e.toQueryString=e.formatUrl=e.generateRequestId=e.genSeqId=e.isFormData=e.isInstanceOf=e.isNull=e.isPalinObject=e.isUndefined=e.isString=e.isArray=void 0;var a=n(778);e.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)},e.isString=function(t){return"string"==typeof t},e.isUndefined=function(t){return void 0===t},e.isPalinObject=function(t){return"[object Object]"===Object.prototype.toString.call(t)},e.isNull=function(t){return"[object Null]"===Object.prototype.toString.call(t)},e.isInstanceOf=function(t,e){return t instanceof e},e.isFormData=function(t){return"[object FormData]"===Object.prototype.toString.call(t)},e.genSeqId=function(){return Math.random().toString(16).slice(2)},e.generateRequestId=function(){var t=(new Date).getTime(),e=(null===Date||void 0===Date?void 0:Date.now)&&1e3*Date.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){var r=16*Math.random();return t>0?(r=(t+r)%16|0,t=Math.floor(t/16)):(r=(e+r)%16|0,e=Math.floor(e/16)),("x"===n?r:7&r|8).toString(16)})},e.formatUrl=function(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";return Object.keys(n).forEach(function(t){""===o?!r&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(n[t]))}),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)},e.toQueryString=function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach(function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))}),e.join("&")},e.getQuery=function(t,e){if("undefined"==typeof window)return!1;var n=e||decodeURIComponent(window.location.search),r=new RegExp("(^|&)".concat(t,"=([^&]*)(&|$)")),o=n.substr(n.indexOf("?")+1).match(r);return null!=o?o[2]:""},e.getHash=function(t){if("undefined"==typeof window)return"";var e=window.location.hash.match(new RegExp("[#?&/]".concat(t,"=([^&#]*)")));return e?e[1]:""},e.removeParam=function(t,e){var n=e.split("?")[0],r=[],o=-1!==e.indexOf("?")?e.split("?")[1]:"";if(""!==o){for(var i=(r=o.split("&")).length-1;i>=0;i-=1)r[i].split("=")[0]===t&&r.splice(i,1);n="".concat(n,"?").concat(r.join("&"))}return n},e.createPromiseCallback=function(){var t={};if(!Promise){(t=function(){}).promise={};var e=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(t.promise,"then",{get:e}),Object.defineProperty(t.promise,"catch",{get:e}),t}var n=new Promise(function(e,n){t=function(t,r){return t?n(t):e(r)}});return t.promise=n,t},e.execCallback=function(t,e,n){if(void 0===n&&(n=null),t&&"function"==typeof t)return t(e,n);if(e)throw e;return n},e.printWarn=function(t,e){console.warn("[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e))},e.printError=function(t,e){console.error({code:t,msg:"[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e)})},e.printInfo=function(t,e){console.log("[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e))},e.throwError=function(t,e){var n=new Error(JSON.stringify({code:t,msg:"[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e)}));throw n.code=t,n};var u=function(t){function e(e){var n=t.call(this,e.msg||e.message||"")||this;return n.code=e.code||"",n.requestId=e.requestId||"",Object.defineProperty(n,"message",{value:e.msg||e.message||"",enumerable:!0,writable:!0,configurable:!0}),n}return o(e,t),e}(Error);e.CloudbaseError=u;var c=function(t){return new u(t)};function f(t,e){return(e||c)(t)}function l(t){return!t||"boolean"!=typeof t.throw||t.throw}e.createCloudbaseError=f,e.resolveThrow=l,e.maybeThrow=function(t,e){if(l(t))throw f(i(i({},e),{msg:e.message}),null==t?void 0:t.errorFactory);return i({code:e.code,message:e.message},e.requestId?{requestId:e.requestId}:{})},e.promoteGatewayError=function(t){if(t&&"object"==typeof t&&t.data&&"object"==typeof t.data){var e=t.data,n=e.code,r=e.message;if(!t.code&&n||!t.message&&r)return i(i(i({},t),!t.code&&n?{code:n}:{}),!t.message&&r?{message:r}:{})}return t},e.errorToResult=function(t){if(t instanceof Error&&"string"==typeof t.message)try{var e=JSON.parse(t.message);if(e&&"string"==typeof e.code)return{code:e.code,message:e.msg||e.message||"",requestId:e.requestId}}catch(t){}return t&&"string"==typeof t.code?{code:t.code,message:t.message||"",requestId:t.requestId}:{code:"UNKNOWN_ERROR",message:String((null==t?void 0:t.message)||t||"")}},e.printGroupLog=function(t){var e,n=t.title,r=t.subtitle,o=void 0===r?"":r,i=t.content,s=void 0===i?[]:i,a=t.printTrace,u=void 0!==a&&a,c=t.collapsed;void 0!==c&&c?(console.groupCollapsed||console.error)(n,o):(console.group||console.error)(n,o);for(var f=0,l=s;f<l.length;f++){var d=l[f],h=d.type,p=d.body;switch(h){case"info":console.log(p);break;case"warn":console.warn(p);break;case"error":console.error(p)}}u&&(console.trace||console.log)("stack trace:"),null===(e=console.groupEnd)||void 0===e||e.call(console)},e.sleep=function(t){return void 0===t&&(t=0),new Promise(function(e){return setTimeout(e,t)})},e.transformPhone=function(t){return"+86".concat(t)},e.parseQueryString=function(t){t=t.replace(/^\?/,"");var e={};return t.split("&").forEach(function(t){var n=t.split("="),r=n[0],o=n[1];r=decodeURIComponent(r),o=decodeURIComponent(o),r&&(e[r]?Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]:e[r]=o)}),e},e.parseCaptcha=function(t){var n={},r=t.match(/^(data:.*?)(\?[^#\s]*)?$/);if(r){t=r[1];var o=r[2];o&&(n=(0,e.parseQueryString)(o))}var i=n.token,a=s(n,["token"]);return/^data:/.test(t)&&!i?{error:"invalid_argument",error_description:"invalid captcha data: ".concat(t)}:i?{state:a.state,token:i,captchaData:t}:{error:"unimplemented",error_description:"need to impl captcha data"}}},954:(t,e,n)=>{"use strict";n.r(e),n.d(e,{CollectionReference:()=>le,Db:()=>Se,DocumentReference:()=>ee,Query:()=>ae});var r,o,i={};n.r(i),n.d(i,{LineString:()=>yt,MultiLineString:()=>vt,MultiPoint:()=>mt,MultiPolygon:()=>Ot,Point:()=>pt,Polygon:()=>bt}),function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.BooleanError="must be boolean",t.ArrayError="must be array",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined",t.CentersPhereError="centersPhere结构不合法"}(o||(o={}));var s,a,u="Object",c="GeoPoint",f="GeoLineString",l="GeoPolygon",d="GeoMultiPoint",h="GeoMultiLineString",p="GeoMultiPolygon",y="Date",g="ServerDate",b=["desc","asc"],m=["<","<=","==",">=",">"];!function(t){t.lt="<",t.gt=">",t.lte="<=",t.gte=">=",t.eq="=="}(s||(s={})),(r={})[s.eq]="$eq",r[s.lt]="$lt",r[s.lte]="$lte",r[s.gt]="$gt",r[s.gte]="$gte",function(t){t.WHERE="WHERE",t.DOC="DOC"}(a||(a={}));var w,v=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},_=function(){function t(){}return t.formatResDocumentData=function(e){return e.map(function(e){return t.formatField(e)})},t.formatField=function(e){var n=Object.keys(e),r={};return Array.isArray(e)&&(r=[]),n.forEach(function(n){var o,i=e[n];switch(t.whichType(i)){case c:o=new pt(i.coordinates[0],i.coordinates[1]);break;case f:o=new yt(i.coordinates.map(function(t){return new pt(t[0],t[1])}));break;case l:o=new bt(i.coordinates.map(function(t){return new yt(t.map(function(t){var e=v(t,2),n=e[0],r=e[1];return new pt(n,r)}))}));break;case d:o=new mt(i.coordinates.map(function(t){return new pt(t[0],t[1])}));break;case h:o=new vt(i.coordinates.map(function(t){return new yt(t.map(function(t){var e=v(t,2),n=e[0],r=e[1];return new pt(n,r)}))}));break;case p:o=new Ot(i.coordinates.map(function(t){return new bt(t.map(function(t){return new yt(t.map(function(t){var e=v(t,2),n=e[0],r=e[1];return new pt(n,r)}))}))}));break;case y:o=i;break;case u:case"Array":o=t.formatField(i);break;case g:o=new Date(i.$date);break;default:o=i}Array.isArray(r)?r.push(o):r[n]=o}),r},t.whichType=function(t){var e=Object.prototype.toString.call(t).slice(8,-1);return e===y?y:(e===u&&(t.$date?e=g:pt.validate(t)?e=c:yt.validate(t)?e=f:bt.validate(t)?e=l:mt.validate(t)?e=d:vt.validate(t)?e=h:Ot.validate(t)&&(e=p)),e)},t.generateDocId=function(){for(var t="",e=0;e<24;e++)t+="ABCDEFabcdef0123456789".charAt(Math.floor(22*Math.random()));return t},t}(),O={code:"INVALID_PARAM",message:"Invalid request param"},E="DATABASE_TRANSACTION_CONFLICT",S={code:"DATABASE_REQUEST_FAILED",message:"database request failed"},N=n(804),I=(w=function(t,e){return w=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},w(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}w(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),x=[],T={},B=function(t){function e(e,n){if(n!==T)throw new TypeError("InternalSymbol cannot be constructed with new operator");return t.call(this,e)||this}return I(e,t),e.for=function(t){for(var n=0,r=x.length;n<r;n++)if(x[n].target===t)return x[n].instance;var o=new e(t,T);return x.push({target:t,instance:o}),o},e}(function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})});const j=B;var A=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},L=function(t){return"object"===A(t)},P=function(t){return"number"===A(t)},$=function(t){return Array.isArray(t)},U=function(t){return"date"===A(t)},R=function(t){return"regexp"===A(t)},D=function(t){return t&&t._internalType instanceof B},C=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),F=function(){return F=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},F.apply(this,arguments)};function q(t,e){if("function"!=typeof e)return t;t.then(function(t){return e(0,t)},function(t){return e(t)})}var M={};function k(t){if(!Se.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return M[e]||(M[e]=new Se.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:Se.createRequest(t.config)}}})),M[e]}var W=function(t){return void 0!==t.timeout?{timeout:t.timeout}:{}},J=function(t){if(!L(t))return t;for(var e in t)void 0===t[e]?delete t[e]:L(t[e])&&(t[e]=J(t[e]));return t},V=function(t){return t=J(t),N.EJSON.stringify(t,{relaxed:!1})},H=function(t){var e,n;if(t instanceof Date)return{$date:+t};if(t instanceof RegExp)return{$regex:t.source,$options:t.flags};if(t&&"object"==typeof t){if("ObjectId"===t._bsontype)return{$oid:t.toHexString()};if("BSONRegExp"===t._bsontype)return{$regex:t.pattern,$options:t.options};if(Array.isArray(t))return t.map(H);var r={};try{for(var o=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(Object.keys(t)),i=o.next();!i.done;i=o.next()){var s=i.value;r[s]=H(t[s])}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return r}return t},z=function(t){if(!t)return"{}";try{var e=N.EJSON.parse(t);return JSON.stringify(H(e))}catch(e){return t}},G=function(t){function e(e){var n=t.call(this,e.message)||this;return n.code=e.code,n.message=e.message,n}return C(e,t),e}(Error),Y=function(t){return new G(t)};function K(t,e){if(!1===t)return e;throw Y(F({},e))}var Q,Z=j.for("UNSET_FIELD_NAME"),X=j.for("UPDATE_COMMAND"),tt=j.for("QUERY_COMMAND"),et=j.for("LOGIC_COMMAND"),nt=j.for("GEO_POINT"),rt=j.for("SYMBOL_GEO_LINE_STRING"),ot=j.for("SYMBOL_GEO_POLYGON"),it=j.for("SYMBOL_GEO_MULTI_POINT"),st=j.for("SYMBOL_GEO_MULTI_LINE_STRING"),at=j.for("SYMBOL_GEO_MULTI_POLYGON"),ut=j.for("SERVER_DATE"),ct=j.for("REGEXP"),ft=j.for("OBJECTID"),lt=function(){return lt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},lt.apply(this,arguments)},dt=["limit","offset","projection","order","multiple","timeout","raw"],ht=function(){function t(){}return t.isGeopoint=function(t,e){if("Number"!==_.whichType(e))throw new Error("Geo Point must be number type");var n=Math.abs(e);if("latitude"===t&&n>90)throw new Error("latitude should be a number ranges from -90 to 90");if("longitude"===t&&n>180)throw new Error("longitude should be a number ranges from -180 to 180");return!0},t.isInteger=function(t,e){if(!Number.isInteger(e))throw new Error(t+o.IntergerError);return!0},t.mustBeBoolean=function(t,e){if("boolean"!=typeof e)throw new Error(t+o.BooleanError);return!0},t.isProjection=function(t,e){if("object"!==A(e))throw Y(lt(lt({},O),{message:"".concat(t," projection must be an object")}));for(var n in e){var r=e[n];if("number"===A(r)){if(0!==r&&1!==r)throw Y(lt(lt({},O),{message:"if the value in projection is of number, it must be 0 or 1"}))}else if("object"!==A(r))throw Y(lt(lt({},O),{message:"invalid projection"}))}return!0},t.isOrder=function(t,e){if("object"!==A(e))throw Y(lt(lt({},O),{message:"".concat(t," order must be an object")}));for(var n in e){var r=e[n];if(1!==r&&-1!==r)throw Y(lt(lt({},O),{message:"order value must be 1 or -1"}))}return!0},t.isFieldOrder=function(t){if(-1===b.indexOf(t))throw new Error(o.DirectionError);return!0},t.isFieldPath=function(t){if(!/^[a-zA-Z0-9-_\.]/.test(t))throw new Error;return!0},t.isOperator=function(t){if(-1===m.indexOf(t))throw new Error(o.OpStrError);return!0},t.isCollName=function(t){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(t))throw new Error(o.CollNameError);return!0},t.isDocID=function(t){if(!/^([a-fA-F0-9]){24}$/.test(t))throw new Error(o.DocIDError);return!0},t.isValidOptions=function(e){if(void 0===e&&(e={}),"object"!==A(e))throw Y(lt(lt({},O),{message:"options must be an object"}));var n=Object.keys(e);for(var r in n)if(dt.indexOf(n[r])<0)throw Y(lt(lt({},O),{message:"".concat(n[r]," is invalid options key")}));var o=e,i=o.limit,s=o.offset,a=o.projection,u=o.order,c=e.multiple;return void 0!==i&&t.isInteger("limit",i),void 0!==s&&t.isInteger("offset",s),void 0!==a&&t.isProjection("projection",a),void 0!==u&&t.isOrder("order",u),void 0!==c&&t.mustBeBoolean("multiple",c),void 0!==e.timeout&&t.isInteger("timeout",e.timeout),!0},t.isValidAggregation=function(t){if(1!==Object.keys(t).length)throw Y(lt(lt({},O),{message:"aggregation stage must have one key"}));return!0},t.isCentersPhere=function(e){if(Array.isArray(e)&&2===e.length){if("object"===A(e[0])&&e[0]._internalType===nt&&"number"==typeof e[1])return!0;if(Array.isArray(e[0])&&2===e[0].length){var n=e[0][0],r=e[0][1];if(t.isGeopoint("longitude",n),t.isGeopoint("latitude",r),"number"==typeof e[1])return!0}}throw new Error("".concat(o.CentersPhereError))},t}(),pt=function(){function t(t,e){ht.isGeopoint("longitude",t),ht.isGeopoint("latitude",e),this.longitude=t,this.latitude=e}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"Point",coordinates:[this.longitude,this.latitude]},e},t.prototype.toJSON=function(){return{type:"Point",coordinates:[this.longitude,this.latitude]}},t.prototype.toReadableString=function(){return"[".concat(this.longitude,",").concat(this.latitude,"]")},t.validate=function(t){return"Point"===t.type&&$(t.coordinates)&&ht.isGeopoint("longitude",t.coordinates[0])&&ht.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return nt},enumerable:!1,configurable:!0}),t}(),yt=function(){function t(t){if(!$(t))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t));if(t.length<2)throw new Error('"points" must contain 2 points at least');t.forEach(function(t){if(!(t instanceof pt))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t,"[]"))}),this.points=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"LineString",coordinates:this.points.map(function(t){return t.toJSON().coordinates})},e},t.prototype.toJSON=function(){return{type:"LineString",coordinates:this.points.map(function(t){return t.toJSON().coordinates})}},t.validate=function(t){var e,n;if("LineString"!==t.type||!$(t.coordinates))return!1;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!P(i[0])||!P(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},t.isClosed=function(t){var e=t.points[0],n=t.points[t.points.length-1];if(e.latitude===n.latitude&&e.longitude===n.longitude)return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return rt},enumerable:!1,configurable:!0}),t}(),gt=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},bt=function(){function t(t){if(!$(t))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach(function(t){if(!(t instanceof yt))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"));if(!yt.isClosed(t))throw new Error("LineString ".concat(t.points.map(function(t){return t.toReadableString()})," is not a closed cycle"))}),this.lines=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"Polygon",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})},e},t.prototype.toJSON=function(){return{type:"Polygon",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})}},t.validate=function(t){var e,n,r,o;if("Polygon"!==t.type||!$(t.coordinates))return!1;try{for(var i=gt(t.coordinates),s=i.next();!s.done;s=i.next()){var a=s.value;if(!this.isCloseLineString(a))return!1;try{for(var u=(r=void 0,gt(a)),c=u.next();!c.done;c=u.next()){var f=c.value;if(!P(f[0])||!P(f[1]))return!1}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=u.return)&&o.call(u)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},t.isCloseLineString=function(t){var e=t[0],n=t[t.length-1];return e[0]===n[0]&&e[1]===n[1]},Object.defineProperty(t.prototype,"_internalType",{get:function(){return ot},enumerable:!1,configurable:!0}),t}(),mt=function(){function t(t){if(!$(t))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t));if(0===t.length)throw new Error('"points" must contain 1 point at least');t.forEach(function(t){if(!(t instanceof pt))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t,"[]"))}),this.points=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiPoint",coordinates:this.points.map(function(t){return t.toJSON().coordinates})},e},t.prototype.toJSON=function(){return{type:"MultiPoint",coordinates:this.points.map(function(t){return t.toJSON().coordinates})}},t.validate=function(t){var e,n;if("MultiPoint"!==t.type||!$(t.coordinates))return!1;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!P(i[0])||!P(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return it},enumerable:!1,configurable:!0}),t}(),wt=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},vt=function(){function t(t){if(!$(t))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach(function(t){if(!(t instanceof yt))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"))}),this.lines=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiLineString",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})},e},t.prototype.toJSON=function(){return{type:"MultiLineString",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})}},t.validate=function(t){var e,n,r,o;if("MultiLineString"!==t.type||!$(t.coordinates))return!1;try{for(var i=wt(t.coordinates),s=i.next();!s.done;s=i.next()){var a=s.value;try{for(var u=(r=void 0,wt(a)),c=u.next();!c.done;c=u.next()){var f=c.value;if(!P(f[0])||!P(f[1]))return!1}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=u.return)&&o.call(u)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return st},enumerable:!1,configurable:!0}),t}(),_t=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ot=function(){function t(t){var e,n;if(!$(t))throw new TypeError('"polygons" must be of type Polygon[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("MultiPolygon must contain 1 polygon at least");try{for(var r=_t(t),o=r.next();!o.done;o=r.next()){var i=o.value;if(!(i instanceof bt))throw new TypeError('"polygon" must be of type Polygon[]. Received type '.concat(typeof i,"[]"))}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}this.polygons=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiPolygon",coordinates:this.polygons.map(function(t){return t.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})})},e},t.prototype.toJSON=function(){return{type:"MultiPolygon",coordinates:this.polygons.map(function(t){return t.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})})}},t.validate=function(t){var e,n,r,o,i,s;if("MultiPolygon"!==t.type||!$(t.coordinates))return!1;try{for(var a=_t(t.coordinates),u=a.next();!u.done;u=a.next()){var c=u.value;try{for(var f=(r=void 0,_t(c)),l=f.next();!l.done;l=f.next()){var d=l.value;try{for(var h=(i=void 0,_t(d)),p=h.next();!p.done;p=h.next()){var y=p.value;if(!P(y[0])||!P(y[1]))return!1}}catch(t){i={error:t}}finally{try{p&&!p.done&&(s=h.return)&&s.call(h)}finally{if(i)throw i.error}}}}catch(t){r={error:t}}finally{try{l&&!l.done&&(o=f.return)&&o.call(f)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return at},enumerable:!1,configurable:!0}),t}();!function(t){t.SET="set",t.REMOVE="remove",t.INC="inc",t.MUL="mul",t.PUSH="push",t.PULL="pull",t.PULL_ALL="pullAll",t.POP="pop",t.SHIFT="shift",t.UNSHIFT="unshift",t.ADD_TO_SET="addToSet",t.BIT="bit",t.RENAME="rename",t.MAX="max",t.MIN="min"}(Q||(Q={}));var Et,St=function(){function t(t,e,n){this._internalType=X,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||Z}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function Nt(t){return t&&t instanceof St&&t._internalType===X}!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(Et||(Et={}));var It=function(){function t(t,e,n){if(this._internalType=et,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||Z,this.fieldName!==Z)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,o=e.length;r<o;r++)(xt(i=e[r])||At(i))&&(e[r]=i._setFieldName(this.fieldName))}else{var i;(xt(i=e)||At(i))&&(e=i._setFieldName(this.fieldName))}}return t.prototype._setFieldName=function(e){var n=this.operands.map(function(n){return n instanceof t?n._setFieldName(e):n});return new t(this.operator,n,e)},t.prototype.and=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return r.unshift(this),new t(Et.AND,r,this.fieldName)},t.prototype.or=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return r.unshift(this),new t(Et.OR,r,this.fieldName)},t}();function xt(t){return t&&t instanceof It&&t._internalType===et}var Tt,Bt=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();!function(t){t.EQ="eq",t.NEQ="neq",t.GT="gt",t.GTE="gte",t.LT="lt",t.LTE="lte",t.IN="in",t.NIN="nin",t.ALL="all",t.ELEM_MATCH="elemMatch",t.EXISTS="exists",t.SIZE="size",t.MOD="mod",t.GEO_NEAR="geoNear",t.GEO_WITHIN="geoWithin",t.GEO_INTERSECTS="geoIntersects"}(Tt||(Tt={}));var jt=function(t){function e(e,n,r){var o=t.call(this,e,n,r)||this;return o.operator=e,o._internalType=tt,o}return Bt(e,t),e.prototype.toJSON=function(){var t,e,n;switch(this.operator){case Tt.IN:case Tt.NIN:return(t={})["$"+this.operator]=this.operands,t;case Tt.NEQ:return(e={}).$ne=this.operands[0],e;default:return(n={})["$"+this.operator]=this.operands[0],n}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(Tt.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(Tt.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(Tt.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(Tt.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(Tt.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(Tt.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(Tt.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(Tt.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof pt))throw new TypeError('"geometry" must be of type Point. Received type '.concat(typeof t.geometry));if(void 0!==t.maxDistance&&!P(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '.concat(typeof t.maxDistance));if(void 0!==t.minDistance&&!P(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '.concat(typeof t.minDistance));var n=new e(Tt.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof Ot||t.geometry instanceof bt||ht.isCentersPhere(t.centerSphere)))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(Tt.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof pt||t.geometry instanceof yt||t.geometry instanceof bt||t.geometry instanceof mt||t.geometry instanceof vt||t.geometry instanceof Ot))throw new TypeError('"geometry" must be of type Point, LineString, Polygon, MultiPoint, MultiLineString or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(Tt.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(It);function At(t){return t&&t instanceof jt&&t._internalType===tt}function Lt(t){return At(t)}var Pt={};for(var $t in Tt)Pt[$t]="$"+$t;for(var $t in Et)Pt[$t]="$"+$t;for(var $t in Q)Pt[$t]="$"+$t;function Ut(t){return Pt[t]||"$"+t}Pt[Tt.NEQ]="$ne",Pt[Q.REMOVE]="$unset",Pt[Q.SHIFT]="$pop",Pt[Q.UNSHIFT]="$push";var Rt=function(){function t(t){var e=(void 0===t?{}:t).offset,n=void 0===e?0:e;this.offset=n}return Object.defineProperty(t.prototype,"_internalType",{get:function(){return ut},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$tcb_server_date:{offset:this.offset}}},t}();function Dt(t){return new Rt(t)}var Ct=function(){return Ct=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ct.apply(this,arguments)},Ft=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},qt=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Mt(t){return kt(t,[t])}function kt(t,e){if(!D(t)){if(U(t))return t;if(R(t))return{$regularExpression:{pattern:t.source,options:t.flags}};if($(t))return t.map(function(t){if(e.indexOf(t)>-1)throw new Error("Cannot convert circular structure to JSON");return kt(t,qt(qt([],Ft(e),!1),[t],!1))});if(L(t)){var n=Ct({},t),r={};for(var o in n){if(e.indexOf(n[o])>-1)throw new Error("Cannot convert circular structure to JSON");void 0!==n[o]&&(r[o]=kt(n[o],qt(qt([],Ft(e),!1),[n[o]],!1)))}return r}return t}switch(t._internalType){case nt:return t.toJSON();case ut:case ct:case ft:return t.parse();default:return t.toJSON?t.toJSON():t}}var Wt=function(){return Wt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Wt.apply(this,arguments)},Jt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},Vt=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Ht(t,e,n,r){var o=Wt({},t);for(var i in t)if(!/^\$/.test(i)){var s=t[i];if(void 0!==s){if(s&&L(s)&&!e(s)){if(r.indexOf(s)>-1)throw new Error("Cannot convert circular structure to JSON");var a=Ht(s,e,Vt(Vt([],Jt(n),!1),[i],!1),Vt(Vt([],Jt(r),!1),[s],!1));o[i]=a;var u=!1;for(var c in a)/^\$/.test(c)?u=!0:(o["".concat(i,".").concat(c)]=a[c],delete o[i][c]);u||delete o[i]}}else delete o[i]}return o}function zt(t){return Ht(t,Yt,[],[t])}function Gt(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?$(t[r])?t[r].push(e[r]):L(t[r])?L(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is ".concat(A(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(A(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]}function Yt(t){return D(t)||U(t)||R(t)}function Kt(t){return Mt(t)}var Qt=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.encodeEJSON=function(e,n){var r=new t;return V(n?e:r.encodeUpdate(e))},t.prototype.encodeUpdate=function(t){return Nt(t)?this.encodeUpdateCommand(t):"object"===A(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===Z)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case Q.PUSH:case Q.PULL:case Q.PULL_ALL:case Q.POP:case Q.SHIFT:case Q.UNSHIFT:case Q.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,o,i=Ut(t.operator);return t.operator===Q.REMOVE?((e={})[i]=((n={})[t.fieldName]="",n),e):((r={})[i]=((o={})[t.fieldName]=t.operands[0],o),r)},t.prototype.encodeArrayUpdateCommand=function(t){var e,n,r,o,i,s,a,u,c,f,l=Ut(t.operator);switch(t.operator){case Q.PUSH:var d=void 0;return d=$(t.operands)?{$each:t.operands.map(Kt)}:t.operands,(e={})[l]=((n={})[t.fieldName]=d,n),e;case Q.UNSHIFT:return d={$each:t.operands.map(Kt),$position:0},(r={})[l]=((o={})[t.fieldName]=d,o),r;case Q.POP:return(i={})[l]=((s={})[t.fieldName]=1,s),i;case Q.SHIFT:return(a={})[l]=((u={})[t.fieldName]=-1,u),a;default:return(c={})[l]=((f={})[t.fieldName]=Kt(t.operands),f),c}},t.prototype.encodeUpdateObject=function(t){var e=zt(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(Nt(r))e[n]=r._setFieldName(n),Gt(e,this.encodeUpdateCommand(e[n]),n);else{e[n]=r=Kt(r);var o=new St(Q.SET,[r],n);Gt(e,this.encodeUpdateCommand(o),n)}}return e},t}(),Zt=function(){return Zt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Zt.apply(this,arguments)},Xt=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},te=function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},ee=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){return k(i._db).watch(Zt(Zt({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify({_id:i.id})}))},this._db=t,this._coll=e,this.id=r,this._transactionId=o,this.request=Se.createRequest(this._db.config),this._apiOptions=n}return t.prototype.create=function(t,e){return q(this._create(t),e)},t.prototype._create=function(t){return Xt(this,void 0,void 0,function(){var e,n,r;return te(this,function(o){switch(o.label){case 0:return!(e=Array.isArray(t))&&this.id&&(t._id=this.id),n={collectionName:this._coll,data:e?t.map(function(t){return V(Mt(t))}):[V(Mt(t))],transactionId:this._transactionId},[4,this.request.send("database.insertDocument",n,W(this._apiOptions))];case 1:return(r=o.sent()).code?[2,r]:this._transactionId?[2,{inserted:1,ok:1,id:r.data.insertedIds[0],requestId:r.requestId}]:e?[2,{ids:r.data&&r.data.insertedIds||[],requestId:r.requestId}]:[2,{id:r.data.insertedIds[0],requestId:r.requestId}]}})})},t.prototype.set=function(t,e){return q(this._set(t),e)},t.prototype._set=function(t){return Xt(this,void 0,void 0,function(){var e,n,r,o;return te(this,function(i){switch(i.label){case 0:return this.id?t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,K(this._db.config.throwOnCode,Zt(Zt({},O),{message:"不能更新_id的值"}))]:(e=!1,n=function(t){if("object"==typeof t)for(var r in t)t[r]instanceof St?e=!0:"object"==typeof t[r]&&n(t[r])},n(t),e?[2,K(this._db.config.throwOnCode,Zt(Zt({},S),{message:"update operator complicit"}))]:(r={collectionName:this._coll,queryType:a.DOC,data:V(Mt(t)),transactionId:this._transactionId,multi:!1,merge:!1,upsert:!0},this.id&&(r.query=V({_id:this.id})),[4,this.request.send("database.modifyDocument",r,W(this._apiOptions))])):[2,K(this._db.config.throwOnCode,Zt(Zt({},O),{message:"参数必需是非空对象"}))]:[2,K(this._db.config.throwOnCode,Zt(Zt({},O),{message:"docId不能为空"}))];case 1:return(o=i.sent()).code?[2,o]:this._transactionId?[2,{updated:o.data.updated,upserted:[{_id:o.data.upsert_id}],requestId:o.requestId}]:[2,{updated:o.data.updated,upsertedId:o.data.upsert_id,requestId:o.requestId}]}})})},t.prototype.update=function(t,e){return q(this._update(t),e)},t.prototype._update=function(t){return Xt(this,void 0,void 0,function(){var e,n,r;return te(this,function(o){switch(o.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,K(this._db.config.throwOnCode,Zt(Zt({},O),{message:"不能更新_id的值"}))]:(e=V({_id:this.id}),n={collectionName:this._coll,transactionId:this._transactionId,data:Qt.encodeEJSON(t,this._apiOptions.raw||!1),query:e,queryType:a.DOC,multi:!1,merge:!0,upsert:!1},[4,this.request.send("database.modifyDocument",n,W(this._apiOptions))]):[2,K(this._db.config.throwOnCode,Zt(Zt({},O),{message:"参数必需是非空对象"}))];case 1:return(r=o.sent()).code?[2,r]:[2,{updated:r.data.updated,requestId:r.requestId}]}})})},t.prototype.delete=function(t){return this.remove(t)},t.prototype.remove=function(t){return q(this._remove(),t)},t.prototype._remove=function(){return Xt(this,void 0,void 0,function(){var t,e,n;return te(this,function(r){switch(r.label){case 0:return t=V({_id:this.id}),e={collectionName:this._coll,transactionId:this._transactionId,query:t,queryType:a.DOC,multi:!1},[4,this.request.send("database.removeDocument",e,W(this._apiOptions))];case 1:return(n=r.sent()).code?[2,n]:[2,{deleted:n.data.deleted,requestId:n.requestId}]}})})},t.prototype.get=function(t){return q(this._get(),t)},t.prototype._get=function(){return Xt(this,void 0,void 0,function(){var t,e,n,r,o,i;return te(this,function(s){switch(s.label){case 0:return t=V({_id:this.id}),e=this._apiOptions.projection,n={collectionName:this._coll,query:t,transactionId:this._transactionId,queryType:a.DOC,multi:!1},e&&(n.projection=V(e)),[4,this.request.send("database.getDocument",n,W(this._apiOptions))];case 1:return(r=s.sent()).code?[2,r]:(o=r.data.list.map(function(t){return N.EJSON.parse(t)}),i=_.formatResDocumentData(o),this._transactionId?[2,{data:i[0]||null,requestId:r.requestId}]:[2,{data:i,requestId:r.requestId}])}})})},t.prototype.field=function(e){var n={};for(var r in e)"boolean"==typeof e[r]&&(n[r]=!0===e[r]?1:0),"number"==typeof e[r]&&(n[r]=e[r]>0?1:0),"object"==typeof e[r]&&(n[r]=e[r]);var o=Zt({},this._apiOptions);return o.projection=n,new t(this._db,this._coll,o,this.id,this._transactionId)},t}(),ne=function(){function t(){}return t.encode=function(t){return(new re).encodeQuery(t)},t.encodeEJSON=function(t,e){var n=new re;return V(e?t:n.encodeQuery(t))},t}(),re=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n,r,o;return Yt(t)?xt(t)?this.encodeLogicCommand(t):At(t)?this.encodeQueryCommand(t):R(t)?((n={})[e]=this.encodeRegExp(t),n):U(t)?((r={})[e]=Kt(t),r):((o={})[e]=this.encodeQueryObject(t),o):L(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regularExpression:{pattern:t.source,options:t.flags}}},t.prototype.encodeLogicCommand=function(t){var e,n,r,o,i,s,a,u=this;switch(t.operator){case Et.NOR:case Et.AND:case Et.OR:var c=Ut(t.operator),f=t.operands.map(function(e){return u.encodeQuery(e,t.fieldName)});return(e={})[c]=f,e;case Et.NOT:c=Ut(t.operator);var l=t.operands[0];return R(l)?((n={})[t.fieldName]=((r={})[c]=this.encodeRegExp(l),r),n):(f=this.encodeQuery(l)[t.fieldName],(o={})[t.fieldName]=((i={})[c]=f,i),o);default:if(c=Ut(t.operator),1===t.operands.length){var d=this.encodeQuery(t.operands[0]);return(s={})[c]=d,s}return f=t.operands.map(this.encodeQuery.bind(this)),(a={})[c]=f,a}},t.prototype.encodeQueryCommand=function(t){return Lt(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,o,i,s,a,u,c,f,l;if(t.fieldName===Z)throw new Error("Cannot encode a comparison command with unset field name");var d=Ut(t.operator);switch(t.operator){case Tt.EQ:case Tt.NEQ:case Tt.LT:case Tt.LTE:case Tt.GT:case Tt.GTE:case Tt.ELEM_MATCH:case Tt.EXISTS:case Tt.SIZE:case Tt.MOD:return(e={})[t.fieldName]=((n={})[d]=Kt(t.operands[0]),n),e;case Tt.IN:case Tt.NIN:case Tt.ALL:return(r={})[t.fieldName]=((o={})[d]=Kt(t.operands),o),r;case Tt.GEO_NEAR:var h=t.operands[0];return(i={})[t.fieldName]={$nearSphere:{$geometry:h.geometry.toJSON(),$maxDistance:h.maxDistance,$minDistance:h.minDistance}},i;case Tt.GEO_WITHIN:if((h=t.operands[0]).centerSphere){ht.isCentersPhere(h.centerSphere);var p=h.centerSphere;return p[0]._internalType===nt?((s={})[t.fieldName]={$geoWithin:{$centerSphere:[p[0].toJSON().coordinates,p[1]]}},s):((a={})[t.fieldName]={$geoWithin:{$centerSphere:h.centerSphere}},a)}return(u={})[t.fieldName]={$geoWithin:{$geometry:h.geometry.toJSON()}},u;case Tt.GEO_INTERSECTS:return h=t.operands[0],(c={})[t.fieldName]={$geoIntersects:{$geometry:h.geometry.toJSON()}},c;default:return(f={})[t.fieldName]=((l={})[d]=Kt(t.operands[0]),l),f}},t.prototype.encodeQueryObject=function(t){var e=zt(t);for(var n in e){var r=e[n];if(xt(r)){e[n]=r._setFieldName(n);var o=this.encodeLogicCommand(e[n]);this.mergeConditionAfterEncode(e,o,n)}else Lt(r)?(e[n]=r._setFieldName(n),o=this.encodeComparisonCommand(e[n]),this.mergeConditionAfterEncode(e,o,n)):Yt(r)&&(e[n]=Kt(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?$(t[r])?t[r]=t[r].concat(e[r]):L(t[r])?L(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is ".concat(A(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(A(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),oe=function(){return oe=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},oe.apply(this,arguments)},ie=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},se=function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},ae=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){var e=k(i._db),n=i._apiOptions,r=n.limit,o=n.order,s=o?Object.entries(o).reduce(function(t,e){var n=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(e,2),r=n[0],o=n[1];return t[r]=-1===o?"desc":"asc",t},{}):void 0;return e.watch(oe(oe({},t),{envId:i._db.config.env,collectionName:i._coll,query:z(i._fieldFilters),limit:r,orderBy:s}))},this._db=t,this._coll=e,this._fieldFilters=n,this._apiOptions=r||{},this._request=Se.createRequest(this._db.config),this._transactionId=o}return t.prototype.get=function(t){return q(this._get(),t)},t.prototype._get=function(){return ie(this,void 0,void 0,function(){var t,e,n,r,o,i,s,u,c;return se(this,function(f){switch(f.label){case 0:return t=this._apiOptions.order,e={collectionName:this._coll,queryType:a.WHERE,transactionId:this._transactionId},this._fieldFilters&&(e.query=this._fieldFilters),t&&(e.order=V(t)),(n=this._apiOptions.offset)&&(e.offset=n),r=this._apiOptions.limit,e.limit=r?r<1e3?r:1e3:100,(o=this._apiOptions.projection)&&(e.projection=V(o)),[4,this._request.send("database.getDocument",e,W(this._apiOptions))];case 1:return(i=f.sent()).code?[2,i]:(s=i.data.list.map(function(t){return N.EJSON.parse(t)}),u=_.formatResDocumentData(s),c={data:u,requestId:i.requestId},i.total&&(c.total=i.total),i.limit&&(c.limit=i.limit),i.offset&&(c.offset=i.offset),[2,c])}})})},t.prototype.count=function(t){return q(this._count(),t)},t.prototype._count=function(){return ie(this,void 0,void 0,function(){var t,e;return se(this,function(n){switch(n.label){case 0:return t={collectionName:this._coll,queryType:a.WHERE},this._fieldFilters&&(t.query=this._fieldFilters),[4,this._request.send("database.calculateDocument",t,W(this._apiOptions))];case 1:return(e=n.sent()).code?[2,e]:[2,{requestId:e.requestId,total:e.data.total}]}})})},t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(o.QueryParamTypeError);var n=Object.keys(e),r=n.some(function(t){return void 0!==e[t]});if(n.length&&!r)throw Error(o.QueryParamValueError);return new t(this._db,this._coll,ne.encodeEJSON(e,this._apiOptions.raw||!1),this._apiOptions,this._transactionId)},t.prototype.options=function(e){return ht.isValidOptions(e),new t(this._db,this._coll,this._fieldFilters,e,this._transactionId)},t.prototype.orderBy=function(e,n){var r;ht.isFieldPath(e),ht.isFieldOrder(n);var o=((r={})[e]="desc"===n?-1:1,r),i=this._apiOptions.order||{},s=Object.assign({},this._apiOptions,{order:Object.assign({},i,o)});return new t(this._db,this._coll,this._fieldFilters,s,this._transactionId)},t.prototype.limit=function(e){ht.isInteger("limit",e);var n=oe({},this._apiOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,n,this._transactionId)},t.prototype.skip=function(e){ht.isInteger("offset",e);var n=oe({},this._apiOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,n,this._transactionId)},t.prototype.update=function(t,e){return q(this._update(t),e)},t.prototype._update=function(t){return ie(this,void 0,void 0,function(){var e,n,r,o;return se(this,function(i){switch(i.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,K(this._db.config.throwOnCode,oe(oe({},O),{message:"不能更新_id的值"}))]:(e=this._apiOptions.multiple,n=void 0===e||e,r={collectionName:this._coll,queryType:a.WHERE,multi:n,merge:!0,upsert:!1,data:Qt.encodeEJSON(t,this._apiOptions.raw||!1)},this._transactionId&&(r.transactionId=this._transactionId),this._fieldFilters&&(r.query=this._fieldFilters),[4,this._request.send("database.modifyDocument",r,W(this._apiOptions))]):[2,K(this._db.config.throwOnCode,oe(oe({},O),{message:"参数必需是非空对象"}))];case 1:return(o=i.sent()).code?[2,o]:[2,{requestId:o.requestId,updated:o.data.updated,upsertId:o.data.upsert_id}]}})})},t.prototype.field=function(e){var n={};for(var r in e)"boolean"==typeof e[r]&&(n[r]=!0===e[r]?1:0),"number"==typeof e[r]&&(n[r]=e[r]>0?1:0),"object"==typeof e[r]&&(n[r]=e[r]);var o=oe({},this._apiOptions);return o.projection=n,new t(this._db,this._coll,this._fieldFilters,o,this._transactionId)},t.prototype.remove=function(t){return q(this._remove(),t)},t.prototype._remove=function(){return ie(this,void 0,void 0,function(){var t,e,n,r,o,i,s,u,c;return se(this,function(f){switch(f.label){case 0:return t=this._apiOptions,e=t.offset,n=t.limit,r=t.projection,o=t.order,void 0===e&&void 0===n&&void 0===r&&void 0===o||console.warn("`offset`, `limit`, `projection`, `orderBy` are not supported in remove() operation"),i=this._apiOptions.multiple,s=void 0===i||i,u={collectionName:this._coll,query:this._fieldFilters,queryType:a.WHERE,multi:s},this._transactionId&&(u.transactionId=this._transactionId),[4,this._request.send("database.removeDocument",u,W(this._apiOptions))];case 1:return(c=f.sent()).code?[2,c]:[2,{requestId:c.requestId,deleted:c.data.deleted}]}})})},t.prototype.updateAndReturn=function(t){return ie(this,void 0,void 0,function(){var e,n;return se(this,function(r){switch(r.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,K(this._db.config.throwOnCode,oe(oe({},O),{message:"不能更新_id的值"}))]:(e={collectionName:this._coll,queryType:a.WHERE,data:Qt.encodeEJSON(t,!1)},this._transactionId&&(e.transactionId=this._transactionId),this._fieldFilters&&(e.query=this._fieldFilters),[4,this._request.send("database.modifyAndReturnDoc",e,W(this._apiOptions))]):[2,K(this._db.config.throwOnCode,oe(oe({},O),{message:"参数必需是非空对象"}))];case 1:return(n=r.sent()).code?[2,n]:[2,{requestId:n.requestId,updated:n.data.updated,doc:n.data.doc&&N.EJSON.parse(n.data.doc)}]}})})},t}(),ue=function(){function t(t,e,n){var r=this;this._stages=[],t&&e&&(this._db=t,this._request=Se.createRequest(this._db.config),this._collectionName=e,n&&n.length>0&&n.forEach(function(t){ht.isValidAggregation(t);var e=Object.keys(t)[0];r._pipe(e,t[e],!0)}))}return t.prototype.end=function(){return t=this,e=void 0,r=function(){var t;return function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,function(e){switch(e.label){case 0:if(!this._collectionName||!this._db)throw new Error("Aggregation pipeline cannot send request");return[4,this._request.send("database.aggregateDocuments",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:t.data.list.map(N.EJSON.parse)}]:[2,t]}})},new((n=void 0)||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())});var t,e,n,r},t.prototype.unwrap=function(){return this._stages},t.prototype.done=function(){return this._stages.map(function(t){var e,n=t.stageKey,r=t.stageValue;return(e={})[n]=JSON.parse(r),e})},t.prototype._pipe=function(t,e,n){void 0===n&&(n=!1);var r;return r="object"===A(e)?V(e):JSON.stringify(e),this._stages.push({stageKey:n?t:"$".concat(t),stageValue:r}),this},t.prototype.addFields=function(t){return this._pipe("addFields",t)},t.prototype.bucket=function(t){return this._pipe("bucket",t)},t.prototype.bucketAuto=function(t){return this._pipe("bucketAuto",t)},t.prototype.count=function(t){return this._pipe("count",t)},t.prototype.geoNear=function(t){return t.query&&(t.query=ne.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new pt(t.near.longitude,t.near.latitude).toJSON()),this._pipe("geoNear",t)},t.prototype.group=function(t){return this._pipe("group",t)},t.prototype.limit=function(t){return this._pipe("limit",t)},t.prototype.match=function(t){return this._pipe("match",ne.encode(t))},t.prototype.project=function(t){return this._pipe("project",t)},t.prototype.lookup=function(t){return this._pipe("lookup",t)},t.prototype.replaceRoot=function(t){return this._pipe("replaceRoot",t)},t.prototype.sample=function(t){return this._pipe("sample",t)},t.prototype.skip=function(t){return this._pipe("skip",t)},t.prototype.sort=function(t){return this._pipe("sort",t)},t.prototype.sortByCount=function(t){return this._pipe("sortByCount",t)},t.prototype.unwind=function(t){return this._pipe("unwind",t)},t}();const ce=ue;var fe=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),le=function(t){function e(e,n,r,o){var i=t.call(this,e,n,"",r,o)||this;return o&&(i._transactionId=o),i}return fe(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!1,configurable:!0}),e.prototype.doc=function(t){if("string"!=typeof t&&"number"!=typeof t)throw new Error("docId必须为字符串或数字");return new ee(this._db,this._coll,this._apiOptions,t,this._transactionId)},e.prototype.add=function(t,e){return q(this._add(t),e)},e.prototype._add=function(t){return e=this,n=void 0,o=function(){var e,n,r;return function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,function(o){switch(o.label){case 0:return e=t,$(t)||(e=[t]),e=e.map(function(t){return V(Mt(t))}),n={collectionName:this._coll,data:e},this._transactionId&&(n.transactionId=this._transactionId),[4,this._request.send("database.insertDocument",n,W(this._apiOptions))];case 1:return(r=o.sent()).code?[2,r]:$(t)?[2,{ids:r.data.insertedIds,requestId:r.requestId}]:this._transactionId?[2,{inserted:1,ok:1,id:r.data.insertedIds[0],requestId:r.requestId}]:[2,{id:r.data.insertedIds[0],requestId:r.requestId}]}})},new((r=void 0)||(r=Promise))(function(t,i){function s(t){try{u(o.next(t))}catch(t){i(t)}}function a(t){try{u(o.throw(t))}catch(t){i(t)}}function u(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r(function(t){t(n)})).then(s,a)}u((o=o.apply(e,n||[])).next())});var e,n,r,o},e.prototype.aggregate=function(t){return void 0===t&&(t=[]),new ce(this._db,this._coll,this._apiOptions.raw?t:[])},e.prototype.options=function(t){return ht.isValidOptions(t),new e(this._db,this._coll,t,this._transactionId)},e}(ae),de={eq:function(t){return new jt(Tt.EQ,[t])},neq:function(t){return new jt(Tt.NEQ,[t])},lt:function(t){return new jt(Tt.LT,[t])},lte:function(t){return new jt(Tt.LTE,[t])},gt:function(t){return new jt(Tt.GT,[t])},gte:function(t){return new jt(Tt.GTE,[t])},in:function(t){return new jt(Tt.IN,t)},nin:function(t){return new jt(Tt.NIN,t)},all:function(t){return new jt(Tt.ALL,t)},elemMatch:function(t){return new jt(Tt.ELEM_MATCH,[t])},exists:function(t){return new jt(Tt.EXISTS,[t])},size:function(t){return new jt(Tt.SIZE,[t])},mod:function(){return new jt(Tt.MOD,1==arguments.length?[arguments[0]]:2==arguments.length?[[arguments[0],arguments[1]]]:arguments)},geoNear:function(t){return new jt(Tt.GEO_NEAR,[t])},geoWithin:function(t){return new jt(Tt.GEO_WITHIN,[t])},geoIntersects:function(t){return new jt(Tt.GEO_INTERSECTS,[t])},and:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=$(arguments[0])?arguments[0]:Array.from(arguments);return new It(Et.AND,n)},nor:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=$(arguments[0])?arguments[0]:Array.from(arguments);return new It(Et.NOR,n)},or:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=$(arguments[0])?arguments[0]:Array.from(arguments);return new It(Et.OR,n)},not:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=$(arguments[0])?arguments[0]:Array.from(arguments);return new It(Et.NOT,n)},set:function(t){return new St(Q.SET,[t])},remove:function(){return new St(Q.REMOVE,[])},inc:function(t){return new St(Q.INC,[t])},mul:function(t){return new St(Q.MUL,[t])},push:function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(L(e[0])&&e[0].hasOwnProperty("each")){t={};var r=e[0];void 0!==r.each&&(t.$each=r.each),void 0!==r.position&&(t.$position=r.position),void 0!==r.sort&&(t.$sort=r.sort),void 0!==r.slice&&(t.$slice=r.slice)}else t=$(e[0])?e[0]:Array.from(e);return new St(Q.PUSH,t)},pull:function(t){return new St(Q.PULL,t)},pullAll:function(t){return new St(Q.PULL_ALL,t)},pop:function(){return new St(Q.POP,[])},shift:function(){return new St(Q.SHIFT,[])},unshift:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=$(arguments[0])?arguments[0]:Array.from(arguments);return new St(Q.UNSHIFT,n)},addToSet:function(t){return new St(Q.ADD_TO_SET,t)},rename:function(t){return new St(Q.RENAME,[t])},bit:function(t){return new St(Q.BIT,[t])},max:function(t){return new St(Q.MAX,[t])},min:function(t){return new St(Q.MIN,[t])},expr:function(t){return{$expr:t}},jsonSchema:function(t){return{$jsonSchema:t}},text:function(t){return"string"===A(t)?{$search:t.search}:{$search:t.search,$language:t.language,$caseSensitive:t.caseSensitive,$diacriticSensitive:t.diacriticSensitive}},aggregate:{pipeline:function(){return new ce},abs:function(t){return new he("abs",t)},add:function(t){return new he("add",t)},ceil:function(t){return new he("ceil",t)},divide:function(t){return new he("divide",t)},exp:function(t){return new he("exp",t)},floor:function(t){return new he("floor",t)},ln:function(t){return new he("ln",t)},log:function(t){return new he("log",t)},log10:function(t){return new he("log10",t)},mod:function(t){return new he("mod",t)},multiply:function(t){return new he("multiply",t)},pow:function(t){return new he("pow",t)},sqrt:function(t){return new he("sqrt",t)},subtract:function(t){return new he("subtract",t)},trunc:function(t){return new he("trunc",t)},arrayElemAt:function(t){return new he("arrayElemAt",t)},arrayToObject:function(t){return new he("arrayToObject",t)},concatArrays:function(t){return new he("concatArrays",t)},filter:function(t){return new he("filter",t)},in:function(t){return new he("in",t)},indexOfArray:function(t){return new he("indexOfArray",t)},isArray:function(t){return new he("isArray",t)},map:function(t){return new he("map",t)},range:function(t){return new he("range",t)},reduce:function(t){return new he("reduce",t)},reverseArray:function(t){return new he("reverseArray",t)},size:function(t){return new he("size",t)},slice:function(t){return new he("slice",t)},zip:function(t){return new he("zip",t)},and:function(t){return new he("and",t)},not:function(t){return new he("not",t)},or:function(t){return new he("or",t)},cmp:function(t){return new he("cmp",t)},eq:function(t){return new he("eq",t)},gt:function(t){return new he("gt",t)},gte:function(t){return new he("gte",t)},lt:function(t){return new he("lt",t)},lte:function(t){return new he("lte",t)},neq:function(t){return new he("ne",t)},cond:function(t){return new he("cond",t)},ifNull:function(t){return new he("ifNull",t)},switch:function(t){return new he("switch",t)},dateFromParts:function(t){return new he("dateFromParts",t)},dateFromString:function(t){return new he("dateFromString",t)},dayOfMonth:function(t){return new he("dayOfMonth",t)},dayOfWeek:function(t){return new he("dayOfWeek",t)},dayOfYear:function(t){return new he("dayOfYear",t)},isoDayOfWeek:function(t){return new he("isoDayOfWeek",t)},isoWeek:function(t){return new he("isoWeek",t)},isoWeekYear:function(t){return new he("isoWeekYear",t)},millisecond:function(t){return new he("millisecond",t)},minute:function(t){return new he("minute",t)},month:function(t){return new he("month",t)},second:function(t){return new he("second",t)},hour:function(t){return new he("hour",t)},week:function(t){return new he("week",t)},year:function(t){return new he("year",t)},literal:function(t){return new he("literal",t)},mergeObjects:function(t){return new he("mergeObjects",t)},objectToArray:function(t){return new he("objectToArray",t)},allElementsTrue:function(t){return new he("allElementsTrue",t)},anyElementTrue:function(t){return new he("anyElementTrue",t)},setDifference:function(t){return new he("setDifference",t)},setEquals:function(t){return new he("setEquals",t)},setIntersection:function(t){return new he("setIntersection",t)},setIsSubset:function(t){return new he("setIsSubset",t)},setUnion:function(t){return new he("setUnion",t)},concat:function(t){return new he("concat",t)},dateToString:function(t){return new he("dateToString",t)},indexOfBytes:function(t){return new he("indexOfBytes",t)},indexOfCP:function(t){return new he("indexOfCP",t)},split:function(t){return new he("split",t)},strLenBytes:function(t){return new he("strLenBytes",t)},strLenCP:function(t){return new he("strLenCP",t)},strcasecmp:function(t){return new he("strcasecmp",t)},substr:function(t){return new he("substr",t)},substrBytes:function(t){return new he("substrBytes",t)},substrCP:function(t){return new he("substrCP",t)},toLower:function(t){return new he("toLower",t)},toUpper:function(t){return new he("toUpper",t)},meta:function(t){return new he("meta",t)},addToSet:function(t){return new he("addToSet",t)},avg:function(t){return new he("avg",t)},first:function(t){return new he("first",t)},last:function(t){return new he("last",t)},max:function(t){return new he("max",t)},min:function(t){return new he("min",t)},push:function(t){return new he("push",t)},stdDevPop:function(t){return new he("stdDevPop",t)},stdDevSamp:function(t){return new he("stdDevSamp",t)},sum:function(t){return new he("sum",t)},let:function(t){return new he("let",t)}},project:{slice:function(t){return new pe("slice",t)},elemMatch:function(t){return new pe("elemMatch",t)}}},he=function(t,e){this["$"+t]=e},pe=function(t,e){this["$"+t]=e},ye=function(){function t(t){var e=t.regexp,n=t.options;if(!e)throw new TypeError("regexp must be a string");this.$regularExpression={pattern:e||"",options:n||""}}return t.prototype.parse=function(){return{$regularExpression:{pattern:this.$regularExpression.pattern,options:this.$regularExpression.options}}},Object.defineProperty(t.prototype,"_internalType",{get:function(){return ct},enumerable:!1,configurable:!0}),t}();function ge(t){return new ye(t)}var be=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},me=function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},we=function(){function t(t){this._db=t,this._request=Se.createRequest(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return t.prototype.init=function(){return be(this,void 0,void 0,function(){var t;return me(this,function(e){switch(e.label){case 0:return[4,this._request.send("database.startTransaction")];case 1:if((t=e.sent()).code)throw t;return this.inited=!0,this._id=t.transactionId,[2]}})})},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new le(this._db,t,{},this._id)},t.prototype.getTransactionId=function(){return this._id},t.prototype.getRequestMethod=function(){return this._request},t.prototype.commit=function(){return be(this,void 0,void 0,function(){var t,e;return me(this,function(n){switch(n.label){case 0:return t={transactionId:this._id},[4,this._request.send("database.commitTransaction",t)];case 1:if((e=n.sent()).code)throw e;return this.commited=!0,[2,e]}})})},t.prototype.rollback=function(t){return be(this,void 0,void 0,function(){var e,n;return me(this,function(r){switch(r.label){case 0:return e={transactionId:this._id},[4,this._request.send("database.abortTransaction",e)];case 1:if((n=r.sent()).code)throw n;return this.aborted=!0,this.abortReason=t,[2,n]}})})},t}();function ve(){return be(this,void 0,void 0,function(){var t;return me(this,function(e){switch(e.label){case 0:return[4,(t=new we(this)).init()];case 1:return e.sent(),[2,t]}})})}function _e(t,e){return void 0===e&&(e=3),be(this,void 0,void 0,function(){var n,r,o,i,s=this;return me(this,function(a){switch(a.label){case 0:return a.trys.push([0,4,,10]),[4,(n=new we(this)).init()];case 1:return a.sent(),[4,t(n)];case 2:if(r=a.sent(),!0===n.aborted)throw n.abortReason;return[4,n.commit()];case 3:return a.sent(),[2,r];case 4:if(o=a.sent(),!1===n.inited)throw o;return i=function(t){return be(s,void 0,void 0,function(){return me(this,function(e){switch(e.label){case 0:if(n.aborted||n.commited)return[3,5];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,n.rollback()];case 2:case 3:return e.sent(),[3,4];case 4:throw t;case 5:if(!0===n.aborted)throw n.abortReason;throw t}})})},e<=0?[4,i(o)]:[3,6];case 5:a.sent(),a.label=6;case 6:return o&&o.code===E?[4,_e.bind(this)(t,--e)]:[3,8];case 7:return[2,a.sent()];case 8:return[4,i(o)];case 9:return a.sent(),[3,10];case 10:return[2]}})})}var Oe=function(){function t(t){var e=(void 0===t?{}:t).id,n=void 0===e?"":e;this.id=n}return Object.defineProperty(t.prototype,"_internalType",{get:function(){return ft},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$oid:this.id}},t}();function Ee(t){return new Oe(t)}var Se=function(){function t(t){this.config=t,this.Geo=i,this.serverDate=Dt,this.command=de,this.RegExp=ge,this.ObjectId=Ee,this.startTransaction=ve,this.runTransaction=_e,this.logicCommand=It,this.updateCommand=St,this.queryCommand=jt}return t.createRequest=function(e){var n=new t.reqClass(e),r=n.send;return n.send=function(t,n){for(var o=[],i=2;i<arguments.length;i++)o[i-2]=arguments[i];return n&&(e.instance&&(n.instance=e.instance),e.database&&(n.database=e.database)),r.call.apply(r,function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([this,t,n],function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(o),!1))},n},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new le(this,t)},t.prototype.createCollection=function(e){var n={collectionName:e};return t.createRequest(this.config).send("database.addCollection",n)},t}()},949:(t,e,n)=>{"use strict";function r(t){this.message=t}n.r(e),n.d(e,{InvalidTokenError:()=>s,default:()=>a}),r.prototype=new Error,r.prototype.name="InvalidCharacterError";var o="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new r("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,i=0,s=0,a="";o=e.charAt(s++);~o&&(n=i%4?64*n+o:o,i++%4)?a+=String.fromCharCode(255&n>>(-2*i&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return a};function i(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(o(t).replace(/(.)/g,function(t,e){var n=e.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n}))}(e)}catch(t){return o(e)}}function s(t){this.message=t}s.prototype=new Error,s.prototype.name="InvalidTokenError";const a=function(t,e){if("string"!=typeof t)throw new s("Invalid token specified");var n=!0===(e=e||{}).header?0:1;try{return JSON.parse(i(t.split(".")[n]))}catch(t){throw new s("Invalid token specified: "+t.message)}}},273:()=>{},804:(t,e,n)=>{"use strict";n.r(e),n.d(e,{BSON:()=>Ve,BSONError:()=>W,BSONOffsetError:()=>H,BSONRegExp:()=>zt,BSONRuntimeError:()=>V,BSONSymbol:()=>Gt,BSONType:()=>k,BSONValue:()=>rt,BSONVersionError:()=>J,Binary:()=>ut,Code:()=>ht,DBRef:()=>yt,Decimal128:()=>Dt,Double:()=>Ct,EJSON:()=>Pe,Int32:()=>Ft,Long:()=>St,MaxKey:()=>qt,MinKey:()=>Mt,ObjectId:()=>Jt,Timestamp:()=>Kt,UUID:()=>dt,calculateObjectSize:()=>We,deserialize:()=>ke,deserializeStream:()=>Je,onDemand:()=>Re,serialize:()=>qe,serializeWithBufferAndIndex:()=>Me,setInternalBufferSize:()=>Fe});var r=n(273);const o=(()=>{const t=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),Symbol.toStringTag).get;return e=>t.call(e)})();function i(t){return"Uint8Array"===o(t)}function s(t){return"object"==typeof t&&null!=t&&Symbol.toStringTag in t&&("ArrayBuffer"===t[Symbol.toStringTag]||"SharedArrayBuffer"===t[Symbol.toStringTag])}function a(t){return t instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(t)}function u(t){return"object"==typeof t&&null!=t&&Symbol.toStringTag in t&&"Map"===t[Symbol.toStringTag]}function c(t){return t instanceof Date||"[object Date]"===Object.prototype.toString.call(t)}function f(t,e){return JSON.stringify(t,(t,e)=>"bigint"==typeof e?{$numberLong:`${e}`}:u(e)?Object.fromEntries(e):e)}const l=6,d=Symbol.for("@@mdb.bson.version"),h=2147483647,p=-2147483648,y=Math.pow(2,63)-1,g=-Math.pow(2,63),b=Math.pow(2,53),m=-Math.pow(2,53),w=1,v=2,_=3,O=4,E=5,S=6,N=7,I=8,x=9,T=10,B=11,j=12,A=13,L=14,P=15,$=16,U=17,R=18,D=19,C=255,F=127,q=0,M=4,k=Object.freeze({double:1,string:2,object:3,array:4,binData:5,undefined:6,objectId:7,bool:8,date:9,null:10,regex:11,dbPointer:12,javascript:13,symbol:14,javascriptWithScope:15,int:16,timestamp:17,long:18,decimal:19,minKey:-1,maxKey:127});class W extends Error{get bsonError(){return!0}get name(){return"BSONError"}constructor(t,e){super(t,e)}static isBSONError(t){return null!=t&&"object"==typeof t&&"bsonError"in t&&!0===t.bsonError&&"name"in t&&"message"in t&&"stack"in t}}class J extends W{get name(){return"BSONVersionError"}constructor(){super(`Unsupported BSON version, bson types must be from bson ${l}.x.x`)}}class V extends W{get name(){return"BSONRuntimeError"}constructor(t){super(t)}}class H extends W{get name(){return"BSONOffsetError"}constructor(t,e,n){super(`${t}. offset: ${e}`,n),this.offset=e}}let z,G;function Y(t,e,n,r){if(r){z??=new TextDecoder("utf8",{fatal:!0});try{return z.decode(t.subarray(e,n))}catch(t){throw new W("Invalid UTF-8 string in BSON document",{cause:t})}}return G??=new TextDecoder("utf8",{fatal:!1}),G.decode(t.subarray(e,n))}function K(t,e,n){if(0===t.length)return"";const r=n-e;if(0===r)return"";if(r>20)return null;if(1===r&&t[e]<128)return String.fromCharCode(t[e]);if(2===r&&t[e]<128&&t[e+1]<128)return String.fromCharCode(t[e])+String.fromCharCode(t[e+1]);if(3===r&&t[e]<128&&t[e+1]<128&&t[e+2]<128)return String.fromCharCode(t[e])+String.fromCharCode(t[e+1])+String.fromCharCode(t[e+2]);const o=[];for(let r=e;r<n;r++){const e=t[r];if(e>127)return null;o.push(e)}return String.fromCharCode(...o)}const Q={toLocalBufferType(t){if(Buffer.isBuffer(t))return t;if(ArrayBuffer.isView(t))return Buffer.from(t.buffer,t.byteOffset,t.byteLength);const e=t?.[Symbol.toStringTag]??Object.prototype.toString.call(t);if("ArrayBuffer"===e||"SharedArrayBuffer"===e||"[object ArrayBuffer]"===e||"[object SharedArrayBuffer]"===e)return Buffer.from(t);throw new W("Cannot create Buffer from the passed potentialBuffer.")},allocate:t=>Buffer.alloc(t),allocateUnsafe:t=>Buffer.allocUnsafe(t),equals:(t,e)=>Q.toLocalBufferType(t).equals(e),fromNumberArray:t=>Buffer.from(t),fromBase64:t=>Buffer.from(t,"base64"),toBase64:t=>Q.toLocalBufferType(t).toString("base64"),fromISO88591:t=>Buffer.from(t,"binary"),toISO88591:t=>Q.toLocalBufferType(t).toString("binary"),fromHex:t=>Buffer.from(t,"hex"),toHex:t=>Q.toLocalBufferType(t).toString("hex"),toUTF8(t,e,n,r){const o=n-e<=20?K(t,e,n):null;if(null!=o)return o;const i=Q.toLocalBufferType(t).toString("utf8",e,n);if(r)for(let r=0;r<i.length;r++)if(65533===i.charCodeAt(r)){Y(t,e,n,!0);break}return i},utf8ByteLength:t=>Buffer.byteLength(t,"utf8"),encodeUTF8Into(t,e,n){const r=function(t,e,n){if(0===e.length)return 0;if(e.length>25)return null;if(t.length-n<e.length)return null;for(let r=0,o=n;r<e.length;r++,o++){const n=e.charCodeAt(r);if(n>127)return null;t[o]=n}return e.length}(t,e,n);return null!=r?r:Q.toLocalBufferType(t).write(e,n,void 0,"utf8")},randomBytes:r.randomBytes,swap32:t=>Q.toLocalBufferType(t).swap32()};function Z(t){if(t<0)throw new RangeError(`The argument 'byteLength' is invalid. Received ${t}`);return et.fromNumberArray(Array.from({length:t},()=>Math.floor(256*Math.random())))}const X=(()=>{const{crypto:t}=globalThis;if(null!=t&&"function"==typeof t.getRandomValues)return e=>t.getRandomValues(et.allocate(e));if(function(){const{navigator:t}=globalThis;return"object"==typeof t&&"ReactNative"===t.product}()){const{console:t}=globalThis;t?.warn?.("BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.")}return Z})(),tt=/(\d|[a-f])/i,et={toLocalBufferType(t){const e=t?.[Symbol.toStringTag]??Object.prototype.toString.call(t);if("Uint8Array"===e)return t;if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength));if("ArrayBuffer"===e||"SharedArrayBuffer"===e||"[object ArrayBuffer]"===e||"[object SharedArrayBuffer]"===e)return new Uint8Array(t);throw new W("Cannot make a Uint8Array from passed potentialBuffer.")},allocate(t){if("number"!=typeof t)throw new TypeError(`The "size" argument must be of type number. Received ${String(t)}`);return new Uint8Array(t)},allocateUnsafe:t=>et.allocate(t),equals(t,e){if(t.byteLength!==e.byteLength)return!1;for(let n=0;n<t.byteLength;n++)if(t[n]!==e[n])return!1;return!0},fromNumberArray:t=>Uint8Array.from(t),fromBase64:t=>Uint8Array.from(atob(t),t=>t.charCodeAt(0)),toBase64:t=>btoa(et.toISO88591(t)),fromISO88591:t=>Uint8Array.from(t,t=>255&t.charCodeAt(0)),toISO88591:t=>Array.from(Uint16Array.from(t),t=>String.fromCharCode(t)).join(""),fromHex(t){const e=t.length%2==0?t:t.slice(0,t.length-1),n=[];for(let t=0;t<e.length;t+=2){const r=e[t],o=e[t+1];if(!tt.test(r))break;if(!tt.test(o))break;const i=Number.parseInt(`${r}${o}`,16);n.push(i)}return Uint8Array.from(n)},toHex:t=>Array.from(t,t=>t.toString(16).padStart(2,"0")).join(""),toUTF8(t,e,n,r){const o=n-e<=20?K(t,e,n):null;return null!=o?o:Y(t,e,n,r)},utf8ByteLength:t=>(new TextEncoder).encode(t).byteLength,encodeUTF8Into(t,e,n){const r=(new TextEncoder).encode(e);return t.set(r,n),r.byteLength},randomBytes:X,swap32(t){if(t.length%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t.length;e+=4){const n=t[e],r=t[e+1],o=t[e+2],i=t[e+3];t[e]=i,t[e+1]=o,t[e+2]=r,t[e+3]=n}return t}},nt="function"==typeof Buffer&&!0!==Buffer.prototype?._isBuffer?Q:et;class rt{get[d](){return l}[Symbol.for("nodejs.util.inspect.custom")](t,e,n){return this.inspect(t,e,n)}}const ot=new Float64Array(1),it=new Uint8Array(ot.buffer,0,8);ot[0]=-1;const st=0===it[7],at={isBigEndian:st,getNonnegativeInt32LE(t,e){if(t[e+3]>127)throw new RangeError(`Size cannot be negative at offset: ${e}`);return t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24},getInt32LE:(t,e)=>t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24,getUint32LE:(t,e)=>t[e]+256*t[e+1]+65536*t[e+2]+16777216*t[e+3],getUint32BE:(t,e)=>t[e+3]+256*t[e+2]+65536*t[e+1]+16777216*t[e],getBigInt64LE(t,e){const n=BigInt(t[e+4]+256*t[e+5]+65536*t[e+6]+(t[e+7]<<24)),r=BigInt(t[e]+256*t[e+1]+65536*t[e+2]+16777216*t[e+3]);return(n<<BigInt(32))+r},getFloat64LE:st?(t,e)=>(it[7]=t[e],it[6]=t[e+1],it[5]=t[e+2],it[4]=t[e+3],it[3]=t[e+4],it[2]=t[e+5],it[1]=t[e+6],it[0]=t[e+7],ot[0]):(t,e)=>(it[0]=t[e],it[1]=t[e+1],it[2]=t[e+2],it[3]=t[e+3],it[4]=t[e+4],it[5]=t[e+5],it[6]=t[e+6],it[7]=t[e+7],ot[0]),setInt32BE:(t,e,n)=>(t[e+3]=n,n>>>=8,t[e+2]=n,n>>>=8,t[e+1]=n,n>>>=8,t[e]=n,4),setInt32LE:(t,e,n)=>(t[e]=n,n>>>=8,t[e+1]=n,n>>>=8,t[e+2]=n,n>>>=8,t[e+3]=n,4),setBigInt64LE(t,e,n){const r=BigInt(4294967295);let o=Number(n&r);t[e]=o,o>>=8,t[e+1]=o,o>>=8,t[e+2]=o,o>>=8,t[e+3]=o;let i=Number(n>>BigInt(32)&r);return t[e+4]=i,i>>=8,t[e+5]=i,i>>=8,t[e+6]=i,i>>=8,t[e+7]=i,8},setFloat64LE:st?(t,e,n)=>(ot[0]=n,t[e]=it[7],t[e+1]=it[6],t[e+2]=it[5],t[e+3]=it[4],t[e+4]=it[3],t[e+5]=it[2],t[e+6]=it[1],t[e+7]=it[0],8):(t,e,n)=>(ot[0]=n,t[e]=it[0],t[e+1]=it[1],t[e+2]=it[2],t[e+3]=it[3],t[e+4]=it[4],t[e+5]=it[5],t[e+6]=it[6],t[e+7]=it[7],8)};class ut extends rt{get _bsontype(){return"Binary"}constructor(t,e){if(super(),null!=t&&"string"==typeof t&&!ArrayBuffer.isView(t)&&!s(t)&&!Array.isArray(t))throw new W("Binary can only be constructed from Uint8Array or number[]");this.sub_type=e??ut.BSON_BINARY_SUBTYPE_DEFAULT,null==t?(this.buffer=nt.allocate(ut.BUFFER_SIZE),this.position=0):(this.buffer=Array.isArray(t)?nt.fromNumberArray(t):nt.toLocalBufferType(t),this.position=this.buffer.byteLength)}put(t){if("string"==typeof t&&1!==t.length)throw new W("only accepts single character String");if("number"!=typeof t&&1!==t.length)throw new W("only accepts single character Uint8Array or Array");let e;if(e="string"==typeof t?t.charCodeAt(0):"number"==typeof t?t:t[0],e<0||e>255)throw new W("only accepts number in a valid unsigned byte range 0-255");if(this.buffer.byteLength>this.position)this.buffer[this.position++]=e;else{const t=nt.allocate(ut.BUFFER_SIZE+this.buffer.length);t.set(this.buffer,0),this.buffer=t,this.buffer[this.position++]=e}}write(t,e){if(e="number"==typeof e?e:this.position,this.buffer.byteLength<e+t.length){const e=nt.allocate(this.buffer.byteLength+t.length);e.set(this.buffer,0),this.buffer=e}if(ArrayBuffer.isView(t))this.buffer.set(nt.toLocalBufferType(t),e),this.position=e+t.byteLength>this.position?e+t.length:this.position;else if("string"==typeof t)throw new W("input cannot be string")}read(t,e){const n=t+(e=e&&e>0?e:this.position);return this.buffer.subarray(t,n>this.position?this.position:n)}value(){return this.buffer.length===this.position?this.buffer:this.buffer.subarray(0,this.position)}length(){return this.position}toJSON(){return nt.toBase64(this.buffer.subarray(0,this.position))}toString(t){return"hex"===t?nt.toHex(this.buffer.subarray(0,this.position)):"base64"===t?nt.toBase64(this.buffer.subarray(0,this.position)):nt.toUTF8(this.buffer,0,this.position,!1)}toExtendedJSON(t){t=t||{},this.sub_type===ut.SUBTYPE_VECTOR&&ct(this);const e=nt.toBase64(this.buffer),n=Number(this.sub_type).toString(16);return t.legacy?{$binary:e,$type:1===n.length?"0"+n:n}:{$binary:{base64:e,subType:1===n.length?"0"+n:n}}}toUUID(){if(this.sub_type===ut.SUBTYPE_UUID)return new dt(this.buffer.subarray(0,this.position));throw new W(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${ut.SUBTYPE_UUID}" is currently supported.`)}static createFromHexString(t,e){return new ut(nt.fromHex(t),e)}static createFromBase64(t,e){return new ut(nt.fromBase64(t),e)}static fromExtendedJSON(t,e){let n,r;if(e=e||{},"$binary"in t?e.legacy&&"string"==typeof t.$binary&&"$type"in t?(r=t.$type?parseInt(t.$type,16):0,n=nt.fromBase64(t.$binary)):"string"!=typeof t.$binary&&(r=t.$binary.subType?parseInt(t.$binary.subType,16):0,n=nt.fromBase64(t.$binary.base64)):"$uuid"in t&&(r=4,n=dt.bytesFromString(t.$uuid)),!n)throw new W(`Unexpected Binary Extended JSON format ${JSON.stringify(t)}`);return r===M?new dt(n):new ut(n,r)}inspect(t,e,n){return n??=f,`Binary.createFromBase64(${n(nt.toBase64(this.buffer.subarray(0,this.position)),e)}, ${n(this.sub_type,e)})`}toInt8Array(){if(this.sub_type!==ut.SUBTYPE_VECTOR)throw new W("Binary sub_type is not Vector");if(this.buffer[0]!==ut.VECTOR_TYPE.Int8)throw new W("Binary datatype field is not Int8");return ct(this),new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toFloat32Array(){if(this.sub_type!==ut.SUBTYPE_VECTOR)throw new W("Binary sub_type is not Vector");if(this.buffer[0]!==ut.VECTOR_TYPE.Float32)throw new W("Binary datatype field is not Float32");ct(this);const t=new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position));return at.isBigEndian&&nt.swap32(t),new Float32Array(t.buffer)}toPackedBits(){if(this.sub_type!==ut.SUBTYPE_VECTOR)throw new W("Binary sub_type is not Vector");if(this.buffer[0]!==ut.VECTOR_TYPE.PackedBit)throw new W("Binary datatype field is not packed bit");return ct(this),new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toBits(){if(this.sub_type!==ut.SUBTYPE_VECTOR)throw new W("Binary sub_type is not Vector");if(this.buffer[0]!==ut.VECTOR_TYPE.PackedBit)throw new W("Binary datatype field is not packed bit");ct(this);const t=8*(this.length()-2)-this.buffer[1],e=new Int8Array(t);for(let t=0;t<e.length;t++){const n=t/8|0,r=this.buffer[n+2]>>7-t%8&1;e[t]=r}return e}static fromInt8Array(t){const e=nt.allocate(t.byteLength+2);e[0]=ut.VECTOR_TYPE.Int8,e[1]=0;const n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);e.set(n,2);const r=new this(e,this.SUBTYPE_VECTOR);return ct(r),r}static fromFloat32Array(t){const e=nt.allocate(t.byteLength+2);e[0]=ut.VECTOR_TYPE.Float32,e[1]=0;const n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);e.set(n,2),at.isBigEndian&&nt.swap32(new Uint8Array(e.buffer,2));const r=new this(e,this.SUBTYPE_VECTOR);return ct(r),r}static fromPackedBits(t,e=0){const n=nt.allocate(t.byteLength+2);n[0]=ut.VECTOR_TYPE.PackedBit,n[1]=e,n.set(t,2);const r=new this(n,this.SUBTYPE_VECTOR);return ct(r),r}static fromBits(t){const e=t.length+7>>>3,n=new Uint8Array(e+2);n[0]=ut.VECTOR_TYPE.PackedBit;const r=t.length%8;n[1]=0===r?0:8-r;for(let e=0;e<t.length;e++){const r=e>>>3,o=t[e];if(0!==o&&1!==o)throw new W(`Invalid bit value at ${e}: must be 0 or 1, found ${t[e]}`);if(0===o)continue;const i=7-e%8;n[r+2]|=o<<i}return new this(n,ut.SUBTYPE_VECTOR)}}function ct(t){if(t.sub_type!==ut.SUBTYPE_VECTOR)return;const e=t.position,n=t.buffer[0],r=t.buffer[1];if((n===ut.VECTOR_TYPE.Float32||n===ut.VECTOR_TYPE.Int8)&&0!==r)throw new W("Invalid Vector: padding must be zero for int8 and float32 vectors");if(n===ut.VECTOR_TYPE.Float32&&0!==e&&e-2!=0&&(e-2)%4!=0)throw new W("Invalid Vector: Float32 vector must contain a multiple of 4 bytes");if(n===ut.VECTOR_TYPE.PackedBit&&0!==r&&2===e)throw new W("Invalid Vector: padding must be zero for packed bit vectors that are empty");if(n===ut.VECTOR_TYPE.PackedBit&&r>7)throw new W(`Invalid Vector: padding must be a value between 0 and 7. found: ${r}`)}ut.BSON_BINARY_SUBTYPE_DEFAULT=0,ut.BUFFER_SIZE=256,ut.SUBTYPE_DEFAULT=0,ut.SUBTYPE_FUNCTION=1,ut.SUBTYPE_BYTE_ARRAY=2,ut.SUBTYPE_UUID_OLD=3,ut.SUBTYPE_UUID=4,ut.SUBTYPE_MD5=5,ut.SUBTYPE_ENCRYPTED=6,ut.SUBTYPE_COLUMN=7,ut.SUBTYPE_SENSITIVE=8,ut.SUBTYPE_VECTOR=9,ut.SUBTYPE_USER_DEFINED=128,ut.VECTOR_TYPE=Object.freeze({Int8:3,Float32:39,PackedBit:16});const ft=/^[0-9A-F]{32}$/i,lt=/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;class dt extends ut{constructor(t){let e;if(null==t)e=dt.generate();else if(t instanceof dt)e=nt.toLocalBufferType(new Uint8Array(t.buffer));else if(ArrayBuffer.isView(t)&&16===t.byteLength)e=nt.toLocalBufferType(t);else{if("string"!=typeof t)throw new W("Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).");e=dt.bytesFromString(t)}super(e,M)}get id(){return this.buffer}set id(t){this.buffer=t}toHexString(t=!0){return t?[nt.toHex(this.buffer.subarray(0,4)),nt.toHex(this.buffer.subarray(4,6)),nt.toHex(this.buffer.subarray(6,8)),nt.toHex(this.buffer.subarray(8,10)),nt.toHex(this.buffer.subarray(10,16))].join("-"):nt.toHex(this.buffer)}toString(t){return"hex"===t?nt.toHex(this.id):"base64"===t?nt.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(t){if(!t)return!1;if(t instanceof dt)return nt.equals(t.id,this.id);try{return nt.equals(new dt(t).id,this.id)}catch{return!1}}toBinary(){return new ut(this.id,ut.SUBTYPE_UUID)}static generate(){const t=nt.randomBytes(16);return t[6]=15&t[6]|64,t[8]=63&t[8]|128,t}static isValid(t){return!!t&&("string"==typeof t?dt.isValidUUIDString(t):i(t)?16===t.byteLength:"Binary"===t._bsontype&&t.sub_type===this.SUBTYPE_UUID&&16===t.buffer.byteLength)}static createFromHexString(t){const e=dt.bytesFromString(t);return new dt(e)}static createFromBase64(t){return new dt(nt.fromBase64(t))}static bytesFromString(t){if(!dt.isValidUUIDString(t))throw new W("UUID string representation must be 32 hex digits or canonical hyphenated representation");return nt.fromHex(t.replace(/-/g,""))}static isValidUUIDString(t){return ft.test(t)||lt.test(t)}inspect(t,e,n){return n??=f,`new UUID(${n(this.toHexString(),e)})`}}class ht extends rt{get _bsontype(){return"Code"}constructor(t,e){super(),this.code=t.toString(),this.scope=e??null}toJSON(){return null!=this.scope?{code:this.code,scope:this.scope}:{code:this.code}}toExtendedJSON(){return this.scope?{$code:this.code,$scope:this.scope}:{$code:this.code}}static fromExtendedJSON(t){return new ht(t.$code,t.$scope)}inspect(t,e,n){n??=f;let r=n(this.code,e);const o=r.includes("\n");return null!=this.scope&&(r+=`,${o?"\n":" "}${n(this.scope,e)}`),`new Code(${o?"\n":""}${r}${o&&null===this.scope?"\n":""})`}}function pt(t){return null!=t&&"object"==typeof t&&"$id"in t&&null!=t.$id&&"$ref"in t&&"string"==typeof t.$ref&&(!("$db"in t)||"$db"in t&&"string"==typeof t.$db)}class yt extends rt{get _bsontype(){return"DBRef"}constructor(t,e,n,r){super();const o=t.split(".");2===o.length&&(n=o.shift(),t=o.shift()),this.collection=t,this.oid=e,this.db=n,this.fields=r||{}}get namespace(){return this.collection}set namespace(t){this.collection=t}toJSON(){const t=Object.assign({$ref:this.collection,$id:this.oid},this.fields);return null!=this.db&&(t.$db=this.db),t}toExtendedJSON(t){t=t||{};let e={$ref:this.collection,$id:this.oid};return t.legacy||(this.db&&(e.$db=this.db),e=Object.assign(e,this.fields)),e}static fromExtendedJSON(t){const e=Object.assign({},t);return delete e.$ref,delete e.$id,delete e.$db,new yt(t.$ref,t.$id,t.$db,e)}inspect(t,e,n){n??=f;const r=[n(this.namespace,e),n(this.oid,e),...this.db?[n(this.db,e)]:[],...Object.keys(this.fields).length>0?[n(this.fields,e)]:[]];return r[1]=n===f?`new ObjectId(${r[1]})`:r[1],`new DBRef(${r.join(", ")})`}}function gt(t){if(""===t)return t;let e=0;const n="-"===t[e],r="+"===t[e];(r||n)&&(e+=1);let o=!1;for(;e<t.length&&"0"===t[e];++e)o=!0;return o?`${n?"-":""}${t.length===e?"0":t.slice(e)}`:r?t.slice(1):t}let bt;try{bt=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}const mt=4294967296,wt=0x10000000000000000,vt=wt/2,_t={},Ot={},Et=/^(\+?0|(\+|-)?[1-9][0-9]*)$/;class St extends rt{get _bsontype(){return"Long"}get __isLong__(){return!0}constructor(t=0,e,n){super();const r="boolean"==typeof e?e:Boolean(n),o="number"==typeof e?e:0,i="string"==typeof t?St.fromString(t,r):"bigint"==typeof t?St.fromBigInt(t,r):{low:0|t,high:0|o,unsigned:r};this.low=i.low,this.high=i.high,this.unsigned=i.unsigned}static fromBits(t,e,n){return new St(t,e,n)}static fromInt(t,e){let n,r,o;return e?(o=0<=(t>>>=0)&&t<256)&&(r=Ot[t],r)?r:(n=St.fromBits(t,(0|t)<0?-1:0,!0),o&&(Ot[t]=n),n):(o=-128<=(t|=0)&&t<128)&&(r=_t[t],r)?r:(n=St.fromBits(t,t<0?-1:0,!1),o&&(_t[t]=n),n)}static fromNumber(t,e){if(isNaN(t))return e?St.UZERO:St.ZERO;if(e){if(t<0)return St.UZERO;if(t>=wt)return St.MAX_UNSIGNED_VALUE}else{if(t<=-0x8000000000000000)return St.MIN_VALUE;if(t+1>=vt)return St.MAX_VALUE}return t<0?St.fromNumber(-t,e).neg():St.fromBits(t%mt|0,t/mt|0,e)}static fromBigInt(t,e){const n=BigInt(4294967295),r=BigInt(32);return new St(Number(t&n),Number(t>>r&n),e)}static _fromString(t,e,n){if(0===t.length)throw new W("empty string");if(n<2||36<n)throw new W("radix");let r;if((r=t.indexOf("-"))>0)throw new W("interior hyphen");if(0===r)return St._fromString(t.substring(1),e,n).neg();const o=St.fromNumber(Math.pow(n,8));let i=St.ZERO;for(let e=0;e<t.length;e+=8){const r=Math.min(8,t.length-e),s=parseInt(t.substring(e,e+r),n);if(r<8){const t=St.fromNumber(Math.pow(n,r));i=i.mul(t).add(St.fromNumber(s))}else i=i.mul(o),i=i.add(St.fromNumber(s))}return i.unsigned=e,i}static fromStringStrict(t,e,n){let r=!1;if("number"==typeof e?(n=e,e=!1):r=!!e,n??=10,t.trim()!==t)throw new W(`Input: '${t}' contains leading and/or trailing whitespace`);if(!function(t,e){const n="0123456789abcdefghijklmnopqrstuvwxyz".slice(0,e=e??10);return!new RegExp(`[^-+${n}]`,"i").test(t)&&t}(t,n))throw new W(`Input: '${t}' contains invalid characters for radix: ${n}`);const o=gt(t),i=St._fromString(o,r,n);if(i.toString(n).toLowerCase()!==o.toLowerCase())throw new W(`Input: ${t} is not representable as ${i.unsigned?"an unsigned":"a signed"} 64-bit Long ${null!=n?`with radix: ${n}`:""}`);return i}static fromString(t,e,n){let r=!1;return"number"==typeof e?(n=e,e=!1):r=!!e,n??=10,"NaN"===t&&n<24||("Infinity"===t||"+Infinity"===t||"-Infinity"===t)&&n<35?St.ZERO:St._fromString(t,r,n)}static fromBytes(t,e,n){return n?St.fromBytesLE(t,e):St.fromBytesBE(t,e)}static fromBytesLE(t,e){return new St(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,e)}static fromBytesBE(t,e){return new St(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],e)}static isLong(t){return null!=t&&"object"==typeof t&&"__isLong__"in t&&!0===t.__isLong__}static fromValue(t,e){return"number"==typeof t?St.fromNumber(t,e):"string"==typeof t?St.fromString(t,e):St.fromBits(t.low,t.high,"boolean"==typeof e?e:t.unsigned)}add(t){St.isLong(t)||(t=St.fromValue(t));const e=this.high>>>16,n=65535&this.high,r=this.low>>>16,o=65535&this.low,i=t.high>>>16,s=65535&t.high,a=t.low>>>16;let u=0,c=0,f=0,l=0;return l+=o+(65535&t.low),f+=l>>>16,l&=65535,f+=r+a,c+=f>>>16,f&=65535,c+=n+s,u+=c>>>16,c&=65535,u+=e+i,u&=65535,St.fromBits(f<<16|l,u<<16|c,this.unsigned)}and(t){return St.isLong(t)||(t=St.fromValue(t)),St.fromBits(this.low&t.low,this.high&t.high,this.unsigned)}compare(t){if(St.isLong(t)||(t=St.fromValue(t)),this.eq(t))return 0;const e=this.isNegative(),n=t.isNegative();return e&&!n?-1:!e&&n?1:this.unsigned?t.high>>>0>this.high>>>0||t.high===this.high&&t.low>>>0>this.low>>>0?-1:1:this.sub(t).isNegative()?-1:1}comp(t){return this.compare(t)}divide(t){if(St.isLong(t)||(t=St.fromValue(t)),t.isZero())throw new W("division by zero");if(bt){if(!this.unsigned&&-2147483648===this.high&&-1===t.low&&-1===t.high)return this;const e=(this.unsigned?bt.div_u:bt.div_s)(this.low,this.high,t.low,t.high);return St.fromBits(e,bt.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?St.UZERO:St.ZERO;let e,n,r;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return St.UZERO;if(t.gt(this.shru(1)))return St.UONE;r=St.UZERO}else{if(this.eq(St.MIN_VALUE))return t.eq(St.ONE)||t.eq(St.NEG_ONE)?St.MIN_VALUE:t.eq(St.MIN_VALUE)?St.ONE:(e=this.shr(1).div(t).shl(1),e.eq(St.ZERO)?t.isNegative()?St.ONE:St.NEG_ONE:(n=this.sub(t.mul(e)),r=e.add(n.div(t)),r));if(t.eq(St.MIN_VALUE))return this.unsigned?St.UZERO:St.ZERO;if(this.isNegative())return t.isNegative()?this.neg().div(t.neg()):this.neg().div(t).neg();if(t.isNegative())return this.div(t.neg()).neg();r=St.ZERO}for(n=this;n.gte(t);){e=Math.max(1,Math.floor(n.toNumber()/t.toNumber()));const o=Math.ceil(Math.log(e)/Math.LN2),i=o<=48?1:Math.pow(2,o-48);let s=St.fromNumber(e),a=s.mul(t);for(;a.isNegative()||a.gt(n);)e-=i,s=St.fromNumber(e,this.unsigned),a=s.mul(t);s.isZero()&&(s=St.ONE),r=r.add(s),n=n.sub(a)}return r}div(t){return this.divide(t)}equals(t){return St.isLong(t)||(t=St.fromValue(t)),(this.unsigned===t.unsigned||this.high>>>31!=1||t.high>>>31!=1)&&this.high===t.high&&this.low===t.low}eq(t){return this.equals(t)}getHighBits(){return this.high}getHighBitsUnsigned(){return this.high>>>0}getLowBits(){return this.low}getLowBitsUnsigned(){return this.low>>>0}getNumBitsAbs(){if(this.isNegative())return this.eq(St.MIN_VALUE)?64:this.neg().getNumBitsAbs();const t=0!==this.high?this.high:this.low;let e;for(e=31;e>0&&!(t&1<<e);e--);return 0!==this.high?e+33:e+1}greaterThan(t){return this.comp(t)>0}gt(t){return this.greaterThan(t)}greaterThanOrEqual(t){return this.comp(t)>=0}gte(t){return this.greaterThanOrEqual(t)}ge(t){return this.greaterThanOrEqual(t)}isEven(){return!(1&this.low)}isNegative(){return!this.unsigned&&this.high<0}isOdd(){return!(1&~this.low)}isPositive(){return this.unsigned||this.high>=0}isZero(){return 0===this.high&&0===this.low}lessThan(t){return this.comp(t)<0}lt(t){return this.lessThan(t)}lessThanOrEqual(t){return this.comp(t)<=0}lte(t){return this.lessThanOrEqual(t)}modulo(t){if(St.isLong(t)||(t=St.fromValue(t)),bt){const e=(this.unsigned?bt.rem_u:bt.rem_s)(this.low,this.high,t.low,t.high);return St.fromBits(e,bt.get_high(),this.unsigned)}return this.sub(this.div(t).mul(t))}mod(t){return this.modulo(t)}rem(t){return this.modulo(t)}multiply(t){if(this.isZero())return St.ZERO;if(St.isLong(t)||(t=St.fromValue(t)),bt){const e=bt.mul(this.low,this.high,t.low,t.high);return St.fromBits(e,bt.get_high(),this.unsigned)}if(t.isZero())return St.ZERO;if(this.eq(St.MIN_VALUE))return t.isOdd()?St.MIN_VALUE:St.ZERO;if(t.eq(St.MIN_VALUE))return this.isOdd()?St.MIN_VALUE:St.ZERO;if(this.isNegative())return t.isNegative()?this.neg().mul(t.neg()):this.neg().mul(t).neg();if(t.isNegative())return this.mul(t.neg()).neg();if(this.lt(St.TWO_PWR_24)&&t.lt(St.TWO_PWR_24))return St.fromNumber(this.toNumber()*t.toNumber(),this.unsigned);const e=this.high>>>16,n=65535&this.high,r=this.low>>>16,o=65535&this.low,i=t.high>>>16,s=65535&t.high,a=t.low>>>16,u=65535&t.low;let c=0,f=0,l=0,d=0;return d+=o*u,l+=d>>>16,d&=65535,l+=r*u,f+=l>>>16,l&=65535,l+=o*a,f+=l>>>16,l&=65535,f+=n*u,c+=f>>>16,f&=65535,f+=r*a,c+=f>>>16,f&=65535,f+=o*s,c+=f>>>16,f&=65535,c+=e*u+n*a+r*s+o*i,c&=65535,St.fromBits(l<<16|d,c<<16|f,this.unsigned)}mul(t){return this.multiply(t)}negate(){return!this.unsigned&&this.eq(St.MIN_VALUE)?St.MIN_VALUE:this.not().add(St.ONE)}neg(){return this.negate()}not(){return St.fromBits(~this.low,~this.high,this.unsigned)}notEquals(t){return!this.equals(t)}neq(t){return this.notEquals(t)}ne(t){return this.notEquals(t)}or(t){return St.isLong(t)||(t=St.fromValue(t)),St.fromBits(this.low|t.low,this.high|t.high,this.unsigned)}shiftLeft(t){return St.isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?St.fromBits(this.low<<t,this.high<<t|this.low>>>32-t,this.unsigned):St.fromBits(0,this.low<<t-32,this.unsigned)}shl(t){return this.shiftLeft(t)}shiftRight(t){return St.isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?St.fromBits(this.low>>>t|this.high<<32-t,this.high>>t,this.unsigned):St.fromBits(this.high>>t-32,this.high>=0?0:-1,this.unsigned)}shr(t){return this.shiftRight(t)}shiftRightUnsigned(t){if(St.isLong(t)&&(t=t.toInt()),0==(t&=63))return this;{const e=this.high;if(t<32){const n=this.low;return St.fromBits(n>>>t|e<<32-t,e>>>t,this.unsigned)}return 32===t?St.fromBits(e,0,this.unsigned):St.fromBits(e>>>t-32,0,this.unsigned)}}shr_u(t){return this.shiftRightUnsigned(t)}shru(t){return this.shiftRightUnsigned(t)}subtract(t){return St.isLong(t)||(t=St.fromValue(t)),this.add(t.neg())}sub(t){return this.subtract(t)}toInt(){return this.unsigned?this.low>>>0:this.low}toNumber(){return this.unsigned?(this.high>>>0)*mt+(this.low>>>0):this.high*mt+(this.low>>>0)}toBigInt(){return BigInt(this.toString())}toBytes(t){return t?this.toBytesLE():this.toBytesBE()}toBytesLE(){const t=this.high,e=this.low;return[255&e,e>>>8&255,e>>>16&255,e>>>24,255&t,t>>>8&255,t>>>16&255,t>>>24]}toBytesBE(){const t=this.high,e=this.low;return[t>>>24,t>>>16&255,t>>>8&255,255&t,e>>>24,e>>>16&255,e>>>8&255,255&e]}toSigned(){return this.unsigned?St.fromBits(this.low,this.high,!1):this}toString(t){if((t=t||10)<2||36<t)throw new W("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(St.MIN_VALUE)){const e=St.fromNumber(t),n=this.div(e),r=n.mul(e).sub(this);return n.toString(t)+r.toInt().toString(t)}return"-"+this.neg().toString(t)}const e=St.fromNumber(Math.pow(t,6),this.unsigned);let n=this,r="";for(;;){const o=n.div(e);let i=(n.sub(o.mul(e)).toInt()>>>0).toString(t);if(n=o,n.isZero())return i+r;for(;i.length<6;)i="0"+i;r=""+i+r}}toUnsigned(){return this.unsigned?this:St.fromBits(this.low,this.high,!0)}xor(t){return St.isLong(t)||(t=St.fromValue(t)),St.fromBits(this.low^t.low,this.high^t.high,this.unsigned)}eqz(){return this.isZero()}le(t){return this.lessThanOrEqual(t)}toExtendedJSON(t){return t&&t.relaxed?this.toNumber():{$numberLong:this.toString()}}static fromExtendedJSON(t,e){const{useBigInt64:n=!1,relaxed:r=!0}={...e};if(t.$numberLong.length>20)throw new W("$numberLong string is too long");if(!Et.test(t.$numberLong))throw new W(`$numberLong string "${t.$numberLong}" is in an invalid format`);if(n){const e=BigInt(t.$numberLong);return BigInt.asIntN(64,e)}const o=St.fromString(t.$numberLong);return r?o.toNumber():o}inspect(t,e,n){return n??=f,`new Long(${n(this.toString(),e)}${this.unsigned?`, ${n(this.unsigned,e)}`:""})`}}St.TWO_PWR_24=St.fromInt(1<<24),St.MAX_UNSIGNED_VALUE=St.fromBits(-1,-1,!0),St.ZERO=St.fromInt(0),St.UZERO=St.fromInt(0,!0),St.ONE=St.fromInt(1),St.UONE=St.fromInt(1,!0),St.NEG_ONE=St.fromInt(-1),St.MAX_VALUE=St.fromBits(-1,2147483647,!1),St.MIN_VALUE=St.fromBits(0,-2147483648,!1);const Nt=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,It=/^(\+|-)?(Infinity|inf)$/i,xt=/^(\+|-)?NaN$/i,Tt=6111,Bt=-6176,jt=nt.fromNumberArray([124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),At=nt.fromNumberArray([248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Lt=nt.fromNumberArray([120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Pt=/^([-+])?(\d+)?$/;function $t(t){return!isNaN(parseInt(t,10))}function Ut(t){const e=St.fromNumber(1e9);let n=St.fromNumber(0);if(!(t.parts[0]||t.parts[1]||t.parts[2]||t.parts[3]))return{quotient:t,rem:n};for(let r=0;r<=3;r++)n=n.shiftLeft(32),n=n.add(new St(t.parts[r],0)),t.parts[r]=n.div(e).low,n=n.modulo(e);return{quotient:t,rem:n}}function Rt(t,e){throw new W(`"${t}" is not a valid Decimal128 string - ${e}`)}class Dt extends rt{get _bsontype(){return"Decimal128"}constructor(t){if(super(),"string"==typeof t)this.bytes=Dt.fromString(t).bytes;else{if(!(t instanceof Uint8Array||i(t)))throw new W("Decimal128 must take a Buffer or string");if(16!==t.byteLength)throw new W("Decimal128 must take a Buffer of 16 bytes");this.bytes=t}}static fromString(t){return Dt._fromString(t,{allowRounding:!1})}static fromStringWithRounding(t){return Dt._fromString(t,{allowRounding:!0})}static _fromString(t,e){let n=!1,r=!1,o=!1,i=!1,s=0,a=0,u=0,c=0,f=0;const l=[0];let d=0,h=0,p=0,y=0,g=new St(0,0),b=new St(0,0),m=0,w=0;if(t.length>=7e3)throw new W(t+" not a valid Decimal128 string");const v=t.match(Nt),_=t.match(It),O=t.match(xt);if(!v&&!_&&!O||0===t.length)throw new W(t+" not a valid Decimal128 string");if(v){const e=v[2],n=v[4],r=v[5],o=v[6];n&&void 0===o&&Rt(t,"missing exponent power"),n&&void 0===e&&Rt(t,"missing exponent base"),void 0===n&&(r||o)&&Rt(t,"missing e before exponent")}if("+"!==t[w]&&"-"!==t[w]||(r=!0,n="-"===t[w++]),!$t(t[w])&&"."!==t[w]){if("i"===t[w]||"I"===t[w])return new Dt(n?At:Lt);if("N"===t[w])return new Dt(jt)}for(;$t(t[w])||"."===t[w];)"."!==t[w]?(d<34&&("0"!==t[w]||i)&&(i||(f=a),i=!0,l[h++]=parseInt(t[w],10),d+=1),i&&(u+=1),o&&(c+=1),a+=1,w+=1):(o&&Rt(t,"contains multiple periods"),o=!0,w+=1);if(o&&!a)throw new W(t+" not a valid Decimal128 string");if("e"===t[w]||"E"===t[w]){const e=t.substr(++w).match(Pt);if(!e||!e[2])return new Dt(jt);y=parseInt(e[0],10),w+=e[0].length}if(t[w])return new Dt(jt);if(d){if(p=d-1,s=u,1!==s)for(;"0"===t[f+s-1+Number(r)+Number(o)];)s-=1}else l[0]=0,u=1,d=1,s=0;for(y<=c&&c>y+16384?y=Bt:y-=c;y>Tt;){if(p+=1,p>=34){if(0===s){y=Tt;break}Rt(t,"overflow")}y-=1}if(e.allowRounding){for(;y<Bt||d<u;){if(0===p&&s<d){y=Bt,s=0;break}if(d<u?u-=1:p-=1,y<Tt)y+=1;else{if(l.join("").match(/^0+$/)){y=Tt;break}Rt(t,"overflow")}}if(p+1<s){let e=a;o&&(f+=1,e+=1),r&&(f+=1,e+=1);const i=parseInt(t[f+p+1],10);let s=0;if(i>=5&&(s=1,5===i)){s=l[p]%2==1?1:0;for(let n=f+p+2;n<e;n++)if(parseInt(t[n],10)){s=1;break}}if(s){let t=p;for(;t>=0&&++l[t]>9;t--)if(l[t]=0,0===t){if(!(y<Tt))return new Dt(n?At:Lt);y+=1,l[t]=1}}}}else{for(;y<Bt||d<u;){if(0===p){if(0===s){y=Bt;break}Rt(t,"exponent underflow")}d<u?("0"!==t[u-1+Number(r)+Number(o)]&&0!==s&&Rt(t,"inexact rounding"),u-=1):(0!==l[p]&&Rt(t,"inexact rounding"),p-=1),y<Tt?y+=1:Rt(t,"overflow")}p+1<s&&(o&&(f+=1),r&&(f+=1),0!==parseInt(t[f+p+1],10)&&Rt(t,"inexact rounding"))}if(g=St.fromNumber(0),b=St.fromNumber(0),0===s)g=St.fromNumber(0),b=St.fromNumber(0);else if(p<17){let t=0;for(b=St.fromNumber(l[t++]),g=new St(0,0);t<=p;t++)b=b.multiply(St.fromNumber(10)),b=b.add(St.fromNumber(l[t]))}else{let t=0;for(g=St.fromNumber(l[t++]);t<=p-17;t++)g=g.multiply(St.fromNumber(10)),g=g.add(St.fromNumber(l[t]));for(b=St.fromNumber(l[t++]);t<=p;t++)b=b.multiply(St.fromNumber(10)),b=b.add(St.fromNumber(l[t]))}const E=function(t,e){if(!t&&!e)return{high:St.fromNumber(0),low:St.fromNumber(0)};const n=t.shiftRightUnsigned(32),r=new St(t.getLowBits(),0),o=e.shiftRightUnsigned(32),i=new St(e.getLowBits(),0);let s=n.multiply(o),a=n.multiply(i);const u=r.multiply(o);let c=r.multiply(i);return s=s.add(a.shiftRightUnsigned(32)),a=new St(a.getLowBits(),0).add(u).add(c.shiftRightUnsigned(32)),s=s.add(a.shiftRightUnsigned(32)),c=a.shiftLeft(32).add(new St(c.getLowBits(),0)),{high:s,low:c}}(g,St.fromString("100000000000000000"));E.low=E.low.add(b),function(t,e){const n=t.high>>>0,r=e.high>>>0;return n<r||n===r&&t.low>>>0<e.low>>>0}(E.low,b)&&(E.high=E.high.add(St.fromNumber(1))),m=y+6176;const S={low:St.fromNumber(0),high:St.fromNumber(0)};E.high.shiftRightUnsigned(49).and(St.fromNumber(1)).equals(St.fromNumber(1))?(S.high=S.high.or(St.fromNumber(3).shiftLeft(61)),S.high=S.high.or(St.fromNumber(m).and(St.fromNumber(16383).shiftLeft(47))),S.high=S.high.or(E.high.and(St.fromNumber(0x7fffffffffff)))):(S.high=S.high.or(St.fromNumber(16383&m).shiftLeft(49)),S.high=S.high.or(E.high.and(St.fromNumber(562949953421311)))),S.low=E.low,n&&(S.high=S.high.or(St.fromString("9223372036854775808")));const N=nt.allocateUnsafe(16);return w=0,N[w++]=255&S.low.low,N[w++]=S.low.low>>8&255,N[w++]=S.low.low>>16&255,N[w++]=S.low.low>>24&255,N[w++]=255&S.low.high,N[w++]=S.low.high>>8&255,N[w++]=S.low.high>>16&255,N[w++]=S.low.high>>24&255,N[w++]=255&S.high.low,N[w++]=S.high.low>>8&255,N[w++]=S.high.low>>16&255,N[w++]=S.high.low>>24&255,N[w++]=255&S.high.high,N[w++]=S.high.high>>8&255,N[w++]=S.high.high>>16&255,N[w++]=S.high.high>>24&255,new Dt(N)}toString(){let t,e=0;const n=new Array(36);for(let t=0;t<n.length;t++)n[t]=0;let r,o,i,s=0,a=!1,u={parts:[0,0,0,0]};const c=[];s=0;const f=this.bytes,l=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,d=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,h=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,p=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24;s=0,(new St(l,d),new St(h,p)).lessThan(St.ZERO)&&c.push("-");const y=p>>26&31;if(y>>3==3){if(30===y)return c.join("")+"Infinity";if(31===y)return"NaN";t=p>>15&16383,r=8+(p>>14&1)}else r=p>>14&7,t=p>>17&16383;const g=t-6176;if(u.parts[0]=(16383&p)+((15&r)<<14),u.parts[1]=h,u.parts[2]=d,u.parts[3]=l,0===u.parts[0]&&0===u.parts[1]&&0===u.parts[2]&&0===u.parts[3])a=!0;else for(i=3;i>=0;i--){let t=0;const e=Ut(u);if(u=e.quotient,t=e.rem.low,t)for(o=8;o>=0;o--)n[9*i+o]=t%10,t=Math.floor(t/10)}if(a)e=1,n[s]=0;else for(e=36;!n[s];)e-=1,s+=1;const b=e-1+g;if(b>=34||b<=-7||g>0){if(e>34)return c.push("0"),g>0?c.push(`E+${g}`):g<0&&c.push(`E${g}`),c.join("");c.push(`${n[s++]}`),e-=1,e&&c.push(".");for(let t=0;t<e;t++)c.push(`${n[s++]}`);c.push("E"),b>0?c.push(`+${b}`):c.push(`${b}`)}else if(g>=0)for(let t=0;t<e;t++)c.push(`${n[s++]}`);else{let t=e+g;if(t>0)for(let e=0;e<t;e++)c.push(`${n[s++]}`);else c.push("0");for(c.push(".");t++<0;)c.push("0");for(let r=0;r<e-Math.max(t-1,0);r++)c.push(`${n[s++]}`)}return c.join("")}toJSON(){return{$numberDecimal:this.toString()}}toExtendedJSON(){return{$numberDecimal:this.toString()}}static fromExtendedJSON(t){return Dt.fromString(t.$numberDecimal)}inspect(t,e,n){return n??=f,`new Decimal128(${n(this.toString(),e)})`}}class Ct extends rt{get _bsontype(){return"Double"}constructor(t){super(),t instanceof Number&&(t=t.valueOf()),this.value=+t}static fromString(t){const e=Number(t);if("NaN"===t)return new Ct(NaN);if("Infinity"===t)return new Ct(1/0);if("-Infinity"===t)return new Ct(-1/0);if(!Number.isFinite(e))throw new W(`Input: ${t} is not representable as a Double`);if(t.trim()!==t)throw new W(`Input: '${t}' contains whitespace`);if(""===t)throw new W("Input is an empty string");if(/[^-0-9.+eE]/.test(t))throw new W(`Input: '${t}' is not in decimal or exponential notation`);return new Ct(e)}valueOf(){return this.value}toJSON(){return this.value}toString(t){return this.value.toString(t)}toExtendedJSON(t){return t&&(t.legacy||t.relaxed&&isFinite(this.value))?this.value:Object.is(Math.sign(this.value),-0)?{$numberDouble:"-0.0"}:{$numberDouble:Number.isInteger(this.value)?this.value.toFixed(1):this.value.toString()}}static fromExtendedJSON(t,e){const n=parseFloat(t.$numberDouble);return e&&e.relaxed?n:new Ct(n)}inspect(t,e,n){return n??=f,`new Double(${n(this.value,e)})`}}class Ft extends rt{get _bsontype(){return"Int32"}constructor(t){super(),t instanceof Number&&(t=t.valueOf()),this.value=0|+t}static fromString(t){const e=gt(t),n=Number(t);if(h<n)throw new W(`Input: '${t}' is larger than the maximum value for Int32`);if(p>n)throw new W(`Input: '${t}' is smaller than the minimum value for Int32`);if(!Number.isSafeInteger(n))throw new W(`Input: '${t}' is not a safe integer`);if(n.toString()!==e)throw new W(`Input: '${t}' is not a valid Int32 string`);return new Ft(n)}valueOf(){return this.value}toString(t){return this.value.toString(t)}toJSON(){return this.value}toExtendedJSON(t){return t&&(t.relaxed||t.legacy)?this.value:{$numberInt:this.value.toString()}}static fromExtendedJSON(t,e){return e&&e.relaxed?parseInt(t.$numberInt,10):new Ft(t.$numberInt)}inspect(t,e,n){return n??=f,`new Int32(${n(this.value,e)})`}}class qt extends rt{get _bsontype(){return"MaxKey"}toExtendedJSON(){return{$maxKey:1}}static fromExtendedJSON(){return new qt}inspect(){return"new MaxKey()"}}class Mt extends rt{get _bsontype(){return"MinKey"}toExtendedJSON(){return{$minKey:1}}static fromExtendedJSON(){return new Mt}inspect(){return"new MinKey()"}}let kt=null;const Wt=new WeakMap;class Jt extends rt{get _bsontype(){return"ObjectId"}constructor(t){let e;if(super(),"object"==typeof t&&t&&"id"in t){if("string"!=typeof t.id&&!ArrayBuffer.isView(t.id))throw new W("Argument passed in must have an id that is of type string or Buffer");e="toHexString"in t&&"function"==typeof t.toHexString?nt.fromHex(t.toHexString()):t.id}else e=t;if(null==e||"number"==typeof e)this.buffer=Jt.generate("number"==typeof e?e:void 0);else if(ArrayBuffer.isView(e)&&12===e.byteLength)this.buffer=nt.toLocalBufferType(e);else{if("string"!=typeof e)throw new W("Argument passed in does not match the accepted types");if(!Jt.validateHexString(e))throw new W("input must be a 24 character hex string, 12 byte Uint8Array, or an integer");this.buffer=nt.fromHex(e),Jt.cacheHexString&&Wt.set(this,e)}}get id(){return this.buffer}set id(t){this.buffer=t,Jt.cacheHexString&&Wt.set(this,nt.toHex(t))}static validateHexString(t){if(24!==t?.length)return!1;for(let e=0;e<24;e++){const n=t.charCodeAt(e);if(!(n>=48&&n<=57||n>=97&&n<=102||n>=65&&n<=70))return!1}return!0}toHexString(){if(Jt.cacheHexString){const t=Wt.get(this);if(t)return t}const t=nt.toHex(this.id);return Jt.cacheHexString&&Wt.set(this,t),t}static getInc(){return Jt.index=(Jt.index+1)%16777215}static generate(t){"number"!=typeof t&&(t=Math.floor(Date.now()/1e3));const e=Jt.getInc(),n=nt.allocateUnsafe(12);return at.setInt32BE(n,0,t),null===kt&&(kt=nt.randomBytes(5)),n[4]=kt[0],n[5]=kt[1],n[6]=kt[2],n[7]=kt[3],n[8]=kt[4],n[11]=255&e,n[10]=e>>8&255,n[9]=e>>16&255,n}toString(t){return"base64"===t?nt.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}static is(t){return null!=t&&"object"==typeof t&&"_bsontype"in t&&"ObjectId"===t._bsontype}equals(t){if(null==t)return!1;if(Jt.is(t))return this.buffer[11]===t.buffer[11]&&nt.equals(this.buffer,t.buffer);if("string"==typeof t)return t.toLowerCase()===this.toHexString();if("object"==typeof t&&"function"==typeof t.toHexString){const e=t.toHexString(),n=this.toHexString();return"string"==typeof e&&e.toLowerCase()===n}return!1}getTimestamp(){const t=new Date,e=at.getUint32BE(this.buffer,0);return t.setTime(1e3*Math.floor(e)),t}static createPk(){return new Jt}serializeInto(t,e){return t[e]=this.buffer[0],t[e+1]=this.buffer[1],t[e+2]=this.buffer[2],t[e+3]=this.buffer[3],t[e+4]=this.buffer[4],t[e+5]=this.buffer[5],t[e+6]=this.buffer[6],t[e+7]=this.buffer[7],t[e+8]=this.buffer[8],t[e+9]=this.buffer[9],t[e+10]=this.buffer[10],t[e+11]=this.buffer[11],12}static createFromTime(t){const e=nt.allocate(12);for(let t=11;t>=4;t--)e[t]=0;return at.setInt32BE(e,0,t),new Jt(e)}static createFromHexString(t){if(24!==t?.length)throw new W("hex string must be 24 characters");return new Jt(nt.fromHex(t))}static createFromBase64(t){if(16!==t?.length)throw new W("base64 string must be 16 characters");return new Jt(nt.fromBase64(t))}static isValid(t){if(null==t)return!1;if("string"==typeof t)return Jt.validateHexString(t);try{return new Jt(t),!0}catch{return!1}}toExtendedJSON(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}}static fromExtendedJSON(t){return new Jt(t.$oid)}isCached(){return Jt.cacheHexString&&Wt.has(this)}inspect(t,e,n){return n??=f,`new ObjectId(${n(this.toHexString(),e)})`}}function Vt(t,e,n){let r=5;if(Array.isArray(t))for(let o=0;o<t.length;o++)r+=Ht(o.toString(),t[o],e,!0,n);else{"function"==typeof t?.toBSON&&(t=t.toBSON());for(const o of Object.keys(t))r+=Ht(o,t[o],e,!1,n)}return r}function Ht(t,e,n=!1,r=!1,o=!1){switch("function"==typeof e?.toBSON&&(e=e.toBSON()),typeof e){case"string":return 1+nt.utf8ByteLength(t)+1+4+nt.utf8ByteLength(e)+1;case"number":return Math.floor(e)===e&&e>=m&&e<=b&&e>=p&&e<=h?(null!=t?nt.utf8ByteLength(t)+1:0)+5:(null!=t?nt.utf8ByteLength(t)+1:0)+9;case"undefined":return r||!o?(null!=t?nt.utf8ByteLength(t)+1:0)+1:0;case"boolean":return(null!=t?nt.utf8ByteLength(t)+1:0)+2;case"object":if(null!=e&&"string"==typeof e._bsontype&&e[d]!==l)throw new J;if(null==e||"MinKey"===e._bsontype||"MaxKey"===e._bsontype)return(null!=t?nt.utf8ByteLength(t)+1:0)+1;if("ObjectId"===e._bsontype)return(null!=t?nt.utf8ByteLength(t)+1:0)+13;if(e instanceof Date||c(e))return(null!=t?nt.utf8ByteLength(t)+1:0)+9;if(ArrayBuffer.isView(e)||e instanceof ArrayBuffer||s(e))return(null!=t?nt.utf8ByteLength(t)+1:0)+6+e.byteLength;if("Long"===e._bsontype||"Double"===e._bsontype||"Timestamp"===e._bsontype)return(null!=t?nt.utf8ByteLength(t)+1:0)+9;if("Decimal128"===e._bsontype)return(null!=t?nt.utf8ByteLength(t)+1:0)+17;if("Code"===e._bsontype)return null!=e.scope&&Object.keys(e.scope).length>0?(null!=t?nt.utf8ByteLength(t)+1:0)+1+4+4+nt.utf8ByteLength(e.code.toString())+1+Vt(e.scope,n,o):(null!=t?nt.utf8ByteLength(t)+1:0)+1+4+nt.utf8ByteLength(e.code.toString())+1;if("Binary"===e._bsontype){const n=e;return n.sub_type===ut.SUBTYPE_BYTE_ARRAY?(null!=t?nt.utf8ByteLength(t)+1:0)+(n.position+1+4+1+4):(null!=t?nt.utf8ByteLength(t)+1:0)+(n.position+1+4+1)}if("Symbol"===e._bsontype)return(null!=t?nt.utf8ByteLength(t)+1:0)+nt.utf8ByteLength(e.value)+4+1+1;if("DBRef"===e._bsontype){const r=Object.assign({$ref:e.collection,$id:e.oid},e.fields);return null!=e.db&&(r.$db=e.db),(null!=t?nt.utf8ByteLength(t)+1:0)+1+Vt(r,n,o)}return e instanceof RegExp||a(e)?(null!=t?nt.utf8ByteLength(t)+1:0)+1+nt.utf8ByteLength(e.source)+1+(e.global?1:0)+(e.ignoreCase?1:0)+(e.multiline?1:0)+1:"BSONRegExp"===e._bsontype?(null!=t?nt.utf8ByteLength(t)+1:0)+1+nt.utf8ByteLength(e.pattern)+1+nt.utf8ByteLength(e.options)+1:(null!=t?nt.utf8ByteLength(t)+1:0)+Vt(e,n,o)+1;case"function":return n?(null!=t?nt.utf8ByteLength(t)+1:0)+1+4+nt.utf8ByteLength(e.toString())+1:0;case"bigint":return(null!=t?nt.utf8ByteLength(t)+1:0)+9;case"symbol":return 0;default:throw new W("Unrecognized JS type: "+typeof e)}}Jt.index=Math.floor(16777215*Math.random());class zt extends rt{get _bsontype(){return"BSONRegExp"}constructor(t,e){if(super(),this.pattern=t,this.options=(e??"").split("").sort().join(""),-1!==this.pattern.indexOf("\0"))throw new W(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);if(-1!==this.options.indexOf("\0"))throw new W(`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`);for(let t=0;t<this.options.length;t++)if("i"!==this.options[t]&&"m"!==this.options[t]&&"x"!==this.options[t]&&"l"!==this.options[t]&&"s"!==this.options[t]&&"u"!==this.options[t])throw new W(`The regular expression option [${this.options[t]}] is not supported`)}static parseOptions(t){return t?t.split("").sort().join(""):""}toExtendedJSON(t){return(t=t||{}).legacy?{$regex:this.pattern,$options:this.options}:{$regularExpression:{pattern:this.pattern,options:this.options}}}static fromExtendedJSON(t){if("$regex"in t){if("string"==typeof t.$regex)return new zt(t.$regex,zt.parseOptions(t.$options));if("BSONRegExp"===t.$regex._bsontype)return t}if("$regularExpression"in t)return new zt(t.$regularExpression.pattern,zt.parseOptions(t.$regularExpression.options));throw new W(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(t)}`)}inspect(t,e,n){const r=function(t){if(null!=t&&"object"==typeof t&&"stylize"in t&&"function"==typeof t.stylize)return t.stylize}(e)??(t=>t);return n??=f,`new BSONRegExp(${r(n(this.pattern),"regexp")}, ${r(n(this.options),"regexp")})`}}class Gt extends rt{get _bsontype(){return"BSONSymbol"}constructor(t){super(),this.value=t}valueOf(){return this.value}toString(){return this.value}toJSON(){return this.value}toExtendedJSON(){return{$symbol:this.value}}static fromExtendedJSON(t){return new Gt(t.$symbol)}inspect(t,e,n){return n??=f,`new BSONSymbol(${n(this.value,e)})`}}const Yt=St;class Kt extends Yt{get _bsontype(){return"Timestamp"}get i(){return this.low>>>0}get t(){return this.high>>>0}constructor(t){if(null==t)super(0,0,!0);else if("bigint"==typeof t)super(t,!0);else if(St.isLong(t))super(t.low,t.high,!0);else{if("object"!=typeof t||!("t"in t)||!("i"in t))throw new W("A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }");{if("number"!=typeof t.t&&("object"!=typeof t.t||"Int32"!==t.t._bsontype))throw new W("Timestamp constructed from { t, i } must provide t as a number");if("number"!=typeof t.i&&("object"!=typeof t.i||"Int32"!==t.i._bsontype))throw new W("Timestamp constructed from { t, i } must provide i as a number");const e=Number(t.t),n=Number(t.i);if(e<0||Number.isNaN(e))throw new W("Timestamp constructed from { t, i } must provide a positive t");if(n<0||Number.isNaN(n))throw new W("Timestamp constructed from { t, i } must provide a positive i");if(e>4294967295)throw new W("Timestamp constructed from { t, i } must provide t equal or less than uint32 max");if(n>4294967295)throw new W("Timestamp constructed from { t, i } must provide i equal or less than uint32 max");super(n,e,!0)}}}toJSON(){return{$timestamp:this.toString()}}static fromInt(t){return new Kt(St.fromInt(t,!0))}static fromNumber(t){return new Kt(St.fromNumber(t,!0))}static fromBits(t,e){return new Kt({i:t,t:e})}static fromString(t,e){return new Kt(St.fromString(t,!0,e))}toExtendedJSON(){return{$timestamp:{t:this.t,i:this.i}}}static fromExtendedJSON(t){const e=St.isLong(t.$timestamp.i)?t.$timestamp.i.getLowBitsUnsigned():t.$timestamp.i,n=St.isLong(t.$timestamp.t)?t.$timestamp.t.getLowBitsUnsigned():t.$timestamp.t;return new Kt({t:n,i:e})}inspect(t,e,n){return n??=f,`new Timestamp({ t: ${n(this.t,e)}, i: ${n(this.i,e)} })`}}Kt.MAX_VALUE=St.MAX_UNSIGNED_VALUE;const Qt=St.fromNumber(b),Zt=St.fromNumber(m);function Xt(t,e,n){const r=(e=null==e?{}:e)&&e.index?e.index:0,o=at.getInt32LE(t,r);if(o<5)throw new W(`bson size must be >= 5, is ${o}`);if(e.allowObjectSmallerThanBufferSize&&t.length<o)throw new W(`buffer length ${t.length} must be >= bson size ${o}`);if(!e.allowObjectSmallerThanBufferSize&&t.length!==o)throw new W(`buffer length ${t.length} must === bson size ${o}`);if(o+r>t.byteLength)throw new W(`(bson size ${o} + options.index ${r} must be <= buffer length ${t.byteLength})`);if(0!==t[r+o-1])throw new W("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");return ee(t,r,e,n)}const te=/^\$ref$|^\$id$|^\$db$/;function ee(t,e,n,r=!1){const o=null==n.fieldsAsRaw?null:n.fieldsAsRaw,i=null!=n.raw&&n.raw,s="boolean"==typeof n.bsonRegExp&&n.bsonRegExp,a=n.promoteBuffers??!1,u=n.promoteLongs??!0,c=n.promoteValues??!0,f=n.useBigInt64??!1;if(f&&!c)throw new W("Must either request bigint or Long for int64 deserialization");if(f&&!u)throw new W("Must either request bigint or Long for int64 deserialization");let l,d,h=!0;const p=(null==n.validation?{utf8:!0}:n.validation).utf8;if("boolean"==typeof p)l=p;else{h=!1;const t=Object.keys(p).map(function(t){return p[t]});if(0===t.length)throw new W("UTF-8 validation setting cannot be empty");if("boolean"!=typeof t[0])throw new W("Invalid UTF-8 validation option, must specify boolean values");if(l=t[0],!t.every(t=>t===l))throw new W("Invalid UTF-8 validation option - keys must be all true or all false")}if(!h){d=new Set;for(const t of Object.keys(p))d.add(t)}const y=e;if(t.length<5)throw new W("corrupt bson message < 5 bytes long");const g=at.getInt32LE(t,e);if(e+=4,g<5||g>t.length)throw new W("corrupt bson message");const b=r?[]:{};let m=0,q=!r&&null;for(;;){const p=t[e++];if(0===p)break;let y=e;for(;0!==t[y]&&y<t.length;)y++;if(y>=t.byteLength)throw new W("Bad BSON Document: illegal CString");const g=r?m++:nt.toUTF8(t,e,y,!1);let k,J=!0;if(J=h||d?.has(g)?l:!l,!1!==q&&"$"===g[0]&&(q=te.test(g)),e=y+1,p===v){const n=at.getInt32LE(t,e);if(e+=4,n<=0||n>t.length-e||0!==t[e+n-1])throw new W("bad string length in bson");k=nt.toUTF8(t,e,e+n-1,J),e+=n}else if(p===N){const n=nt.allocateUnsafe(12);for(let r=0;r<12;r++)n[r]=t[e+r];k=new Jt(n),e+=12}else if(p===$&&!1===c)k=new Ft(at.getInt32LE(t,e)),e+=4;else if(p===$)k=at.getInt32LE(t,e),e+=4;else if(p===w)k=at.getFloat64LE(t,e),e+=8,!1===c&&(k=new Ct(k));else if(p===x){const n=at.getInt32LE(t,e),r=at.getInt32LE(t,e+4);e+=8,k=new Date(new St(n,r).toNumber())}else if(p===I){if(0!==t[e]&&1!==t[e])throw new W("illegal boolean type value");k=1===t[e++]}else if(p===_){const r=e,o=at.getInt32LE(t,e);if(o<=0||o>t.length-e)throw new W("bad embedded document length in bson");if(i)k=t.subarray(e,e+o);else{let e=n;h||(e={...n,validation:{utf8:J}}),k=ee(t,r,e,!1)}e+=o}else if(p===O){const r=e,i=at.getInt32LE(t,e);let s=n;const a=e+i;if(o&&o[g]&&(s={...n,raw:!0}),h||(s={...s,validation:{utf8:J}}),k=ee(t,r,s,!0),0!==t[(e+=i)-1])throw new W("invalid array terminator byte");if(e!==a)throw new W("corrupted array bson")}else if(p===S)k=void 0;else if(p===T)k=null;else if(p===R)if(f)k=at.getBigInt64LE(t,e),e+=8;else{const n=at.getInt32LE(t,e),r=at.getInt32LE(t,e+4);e+=8;const o=new St(n,r);k=u&&!0===c&&o.lessThanOrEqual(Qt)&&o.greaterThanOrEqual(Zt)?o.toNumber():o}else if(p===D){const n=nt.allocateUnsafe(16);for(let r=0;r<16;r++)n[r]=t[e+r];e+=16,k=new Dt(n)}else if(p===E){let n=at.getInt32LE(t,e);e+=4;const r=n,o=t[e++];if(n<0)throw new W("Negative binary type element size found");if(n>t.byteLength)throw new W("Binary type size larger than document size");if(o===ut.SUBTYPE_BYTE_ARRAY){if(n=at.getInt32LE(t,e),e+=4,n<0)throw new W("Negative binary type element size found for subtype 0x02");if(n>r-4)throw new W("Binary type with subtype 0x02 contains too long binary size");if(n<r-4)throw new W("Binary type with subtype 0x02 contains too short binary size")}a&&c?k=nt.toLocalBufferType(t.subarray(e,e+n)):(k=new ut(t.subarray(e,e+n),o),o===M&&dt.isValid(k)&&(k=k.toUUID())),e+=n}else if(p===B&&!1===s){for(y=e;0!==t[y]&&y<t.length;)y++;if(y>=t.length)throw new W("Bad BSON Document: illegal CString");const n=nt.toUTF8(t,e,y,!1);for(y=e=y+1;0!==t[y]&&y<t.length;)y++;if(y>=t.length)throw new W("Bad BSON Document: illegal CString");const r=nt.toUTF8(t,e,y,!1);e=y+1;const o=new Array(r.length);for(y=0;y<r.length;y++)switch(r[y]){case"m":o[y]="m";break;case"s":o[y]="g";break;case"i":o[y]="i"}k=new RegExp(n,o.join(""))}else if(p===B&&!0===s){for(y=e;0!==t[y]&&y<t.length;)y++;if(y>=t.length)throw new W("Bad BSON Document: illegal CString");const n=nt.toUTF8(t,e,y,!1);for(y=e=y+1;0!==t[y]&&y<t.length;)y++;if(y>=t.length)throw new W("Bad BSON Document: illegal CString");const r=nt.toUTF8(t,e,y,!1);e=y+1,k=new zt(n,r)}else if(p===L){const n=at.getInt32LE(t,e);if(e+=4,n<=0||n>t.length-e||0!==t[e+n-1])throw new W("bad string length in bson");const r=nt.toUTF8(t,e,e+n-1,J);k=c?r:new Gt(r),e+=n}else if(p===U)k=new Kt({i:at.getUint32LE(t,e),t:at.getUint32LE(t,e+4)}),e+=8;else if(p===C)k=new Mt;else if(p===F)k=new qt;else if(p===A){const n=at.getInt32LE(t,e);if(e+=4,n<=0||n>t.length-e||0!==t[e+n-1])throw new W("bad string length in bson");const r=nt.toUTF8(t,e,e+n-1,J);k=new ht(r),e+=n}else if(p===P){const r=at.getInt32LE(t,e);if(e+=4,r<13)throw new W("code_w_scope total size shorter minimum expected length");const o=at.getInt32LE(t,e);if(e+=4,o<=0||o>t.length-e||0!==t[e+o-1])throw new W("bad string length in bson");const i=nt.toUTF8(t,e,e+o-1,J),s=e+=o,a=at.getInt32LE(t,e),u=ee(t,s,n,!1);if(e+=a,r<8+a+o)throw new W("code_w_scope total size is too short, truncating scope");if(r>8+a+o)throw new W("code_w_scope total size is too long, clips outer document");k=new ht(i,u)}else{if(p!==j)throw new W(`Detected unknown BSON type ${p.toString(16)} for fieldname "${g}"`);{const n=at.getInt32LE(t,e);if(e+=4,n<=0||n>t.length-e||0!==t[e+n-1])throw new W("bad string length in bson");const r=nt.toUTF8(t,e,e+n-1,J);e+=n;const o=nt.allocateUnsafe(12);for(let n=0;n<12;n++)o[n]=t[e+n];const i=new Jt(o);e+=12,k=new yt(r,i)}}"__proto__"===g?Object.defineProperty(b,g,{value:k,writable:!0,enumerable:!0,configurable:!0}):b[g]=k}if(g!==e-y){if(r)throw new W("corrupt array bson");throw new W("corrupt object bson")}if(!q)return b;if(pt(b)){const t=Object.assign({},b);return delete t.$ref,delete t.$id,delete t.$db,new yt(b.$ref,b.$id,b.$db,t)}return b}const ne=/\x00/,re=new Set(["$db","$ref","$id","$clusterTime"]);function oe(t,e,n,r){t[r++]=v,t[(r=r+nt.encodeUTF8Into(t,e,r)+1)-1]=0;const o=nt.encodeUTF8Into(t,n,r+4);return at.setInt32LE(t,r,o+1),r=r+4+o,t[r++]=0,r}function ie(t,e,n,r){const o=!Object.is(n,-0)&&Number.isSafeInteger(n)&&n<=h&&n>=p?$:w;return t[r++]=o,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r+(o===$?at.setInt32LE(t,r,n):at.setFloat64LE(t,r,n))}function se(t,e,n,r){return t[r++]=R,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r+at.setBigInt64LE(t,r,n)}function ae(t,e,n,r){return t[r++]=T,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r}function ue(t,e,n,r){return t[r++]=I,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,t[r++]=n?1:0,r}function ce(t,e,n,r){t[r++]=x,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=St.fromNumber(n.getTime()),i=o.getLowBits(),s=o.getHighBits();return(r+=at.setInt32LE(t,r,i))+at.setInt32LE(t,r,s)}function fe(t,e,n,r){if(t[r++]=B,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,n.source&&null!=n.source.match(ne))throw new W("value "+n.source+" must not contain null bytes");return r+=nt.encodeUTF8Into(t,n.source,r),t[r++]=0,n.ignoreCase&&(t[r++]=105),n.global&&(t[r++]=115),n.multiline&&(t[r++]=109),t[r++]=0,r}function le(t,e,n,r){if(t[r++]=B,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,null!=n.pattern.match(ne))throw new W("pattern "+n.pattern+" must not contain null bytes");r+=nt.encodeUTF8Into(t,n.pattern,r),t[r++]=0;const o=n.options.split("").sort().join("");return r+=nt.encodeUTF8Into(t,o,r),t[r++]=0,r}function de(t,e,n,r){return null===n?t[r++]=T:"MinKey"===n._bsontype?t[r++]=C:t[r++]=F,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r}function he(t,e,n,r){return t[r++]=N,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r+n.serializeInto(t,r)}function pe(t,e,n,r){t[r++]=E,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.length;if(r+=at.setInt32LE(t,r,o),t[r++]=q,o<=16)for(let e=0;e<o;e++)t[r+e]=n[e];else t.set(n,r);return r+o}function ye(t,e,n,r,o,i,s,a,u){if(u.has(n))throw new W("Cannot convert circular structure to BSON");u.add(n),t[r++]=Array.isArray(n)?O:_,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const c=Ne(t,n,o,r,i+1,s,a,u);return u.delete(n),c}function ge(t,e,n,r){t[r++]=D,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;for(let e=0;e<16;e++)t[r+e]=n.bytes[e];return r+16}function be(t,e,n,r){t[r++]="Long"===n._bsontype?R:U,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.getLowBits(),i=n.getHighBits();return(r+=at.setInt32LE(t,r,o))+at.setInt32LE(t,r,i)}function me(t,e,n,r){return n=n.valueOf(),t[r++]=$,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r+at.setInt32LE(t,r,n)}function we(t,e,n,r){return t[r++]=w,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0,r+at.setFloat64LE(t,r,n.value)}function ve(t,e,n,r){t[r++]=A,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.toString(),i=nt.encodeUTF8Into(t,o,r+4)+1;return at.setInt32LE(t,r,i),r=r+4+i-1,t[r++]=0,r}function _e(t,e,n,r,o=!1,i=0,s=!1,a=!0,u){if(n.scope&&"object"==typeof n.scope){t[r++]=P,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;let c=r;const f=n.code;r+=4;const l=nt.encodeUTF8Into(t,f,r+4)+1;at.setInt32LE(t,r,l),t[r+4+l-1]=0,r=r+l+4;const d=Ne(t,n.scope,o,r,i+1,s,a,u);r=d-1;const h=d-c;c+=at.setInt32LE(t,c,h),t[r++]=0}else{t[r++]=A,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.code.toString(),i=nt.encodeUTF8Into(t,o,r+4)+1;at.setInt32LE(t,r,i),r=r+4+i-1,t[r++]=0}return r}function Oe(t,e,n,r){t[r++]=E,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.buffer;let i=n.position;if(n.sub_type===ut.SUBTYPE_BYTE_ARRAY&&(i+=4),r+=at.setInt32LE(t,r,i),t[r++]=n.sub_type,n.sub_type===ut.SUBTYPE_BYTE_ARRAY&&(i-=4,r+=at.setInt32LE(t,r,i)),n.sub_type===ut.SUBTYPE_VECTOR&&ct(n),i<=16)for(let e=0;e<i;e++)t[r+e]=o[e];else t.set(o,r);return r+n.position}function Ee(t,e,n,r){t[r++]=L,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;const o=nt.encodeUTF8Into(t,n.value,r+4)+1;return at.setInt32LE(t,r,o),r=r+4+o-1,t[r++]=0,r}function Se(t,e,n,r,o,i,s){t[r++]=_,r+=nt.encodeUTF8Into(t,e,r),t[r++]=0;let a=r,u={$ref:n.collection||n.namespace,$id:n.oid};null!=n.db&&(u.$db=n.db),u=Object.assign(u,n.fields);const c=Ne(t,u,!1,r,o+1,i,!0,s),f=c-a;return a+=at.setInt32LE(t,r,f),c}function Ne(t,e,n,r,o,f,h,p){if(null==p){if(null==e)return t[0]=5,t[1]=0,t[2]=0,t[3]=0,t[4]=0,5;if(Array.isArray(e))throw new W("serialize does not support an array as the root input");if("object"!=typeof e)throw new W("serialize does not support non-object as the root input");if("_bsontype"in e&&"string"==typeof e._bsontype)throw new W("BSON types cannot be serialized as a document");if(c(e)||a(e)||i(e)||s(e))throw new W("date, regexp, typedarray, and arraybuffer cannot be BSON documents");p=new Set}p.add(e);let y=r+4;if(Array.isArray(e))for(let r=0;r<e.length;r++){const s=`${r}`;let u=e[r];"function"==typeof u?.toBSON&&(u=u.toBSON());const g=typeof u;if(void 0===u)y=ae(t,s,0,y);else if(null===u)y=ae(t,s,0,y);else if("string"===g)y=oe(t,s,u,y);else if("number"===g)y=ie(t,s,u,y);else if("bigint"===g)y=se(t,s,u,y);else if("boolean"===g)y=ue(t,s,u,y);else if("object"===g&&null==u._bsontype)y=u instanceof Date||c(u)?ce(t,s,u,y):u instanceof Uint8Array||i(u)?pe(t,s,u,y):u instanceof RegExp||a(u)?fe(t,s,u,y):ye(t,s,u,y,n,o,f,h,p);else if("object"===g){if(u[d]!==l)throw new J;if("ObjectId"===u._bsontype)y=he(t,s,u,y);else if("Decimal128"===u._bsontype)y=ge(t,s,u,y);else if("Long"===u._bsontype||"Timestamp"===u._bsontype)y=be(t,s,u,y);else if("Double"===u._bsontype)y=we(t,s,u,y);else if("Code"===u._bsontype)y=_e(t,s,u,y,n,o,f,h,p);else if("Binary"===u._bsontype)y=Oe(t,s,u,y);else if("BSONSymbol"===u._bsontype)y=Ee(t,s,u,y);else if("DBRef"===u._bsontype)y=Se(t,s,u,y,o,f,p);else if("BSONRegExp"===u._bsontype)y=le(t,s,u,y);else if("Int32"===u._bsontype)y=me(t,s,u,y);else if("MinKey"===u._bsontype||"MaxKey"===u._bsontype)y=de(t,s,u,y);else if(void 0!==u._bsontype)throw new W(`Unrecognized or invalid _bsontype: ${String(u._bsontype)}`)}else"function"===g&&f&&(y=ve(t,s,u,y))}else if(e instanceof Map||u(e)){const r=e.entries();let s=!1;for(;!s;){const e=r.next();if(s=!!e.done,s)continue;const u=e.value?e.value[0]:void 0;let g=e.value?e.value[1]:void 0;"function"==typeof g?.toBSON&&(g=g.toBSON());const b=typeof g;if("string"==typeof u&&!re.has(u)){if(null!=u.match(ne))throw new W("key "+u+" must not contain null bytes");if(n){if("$"===u[0])throw new W("key "+u+" must not start with '$'");if(u.includes("."))throw new W("key "+u+" must not contain '.'")}}if(void 0===g)!1===h&&(y=ae(t,u,0,y));else if(null===g)y=ae(t,u,0,y);else if("string"===b)y=oe(t,u,g,y);else if("number"===b)y=ie(t,u,g,y);else if("bigint"===b)y=se(t,u,g,y);else if("boolean"===b)y=ue(t,u,g,y);else if("object"===b&&null==g._bsontype)y=g instanceof Date||c(g)?ce(t,u,g,y):g instanceof Uint8Array||i(g)?pe(t,u,g,y):g instanceof RegExp||a(g)?fe(t,u,g,y):ye(t,u,g,y,n,o,f,h,p);else if("object"===b){if(g[d]!==l)throw new J;if("ObjectId"===g._bsontype)y=he(t,u,g,y);else if("Decimal128"===g._bsontype)y=ge(t,u,g,y);else if("Long"===g._bsontype||"Timestamp"===g._bsontype)y=be(t,u,g,y);else if("Double"===g._bsontype)y=we(t,u,g,y);else if("Code"===g._bsontype)y=_e(t,u,g,y,n,o,f,h,p);else if("Binary"===g._bsontype)y=Oe(t,u,g,y);else if("BSONSymbol"===g._bsontype)y=Ee(t,u,g,y);else if("DBRef"===g._bsontype)y=Se(t,u,g,y,o,f,p);else if("BSONRegExp"===g._bsontype)y=le(t,u,g,y);else if("Int32"===g._bsontype)y=me(t,u,g,y);else if("MinKey"===g._bsontype||"MaxKey"===g._bsontype)y=de(t,u,g,y);else if(void 0!==g._bsontype)throw new W(`Unrecognized or invalid _bsontype: ${String(g._bsontype)}`)}else"function"===b&&f&&(y=ve(t,u,g,y))}}else{if("function"==typeof e?.toBSON&&null!=(e=e.toBSON())&&"object"!=typeof e)throw new W("toBSON function did not return an object");for(const r of Object.keys(e)){let s=e[r];"function"==typeof s?.toBSON&&(s=s.toBSON());const u=typeof s;if("string"==typeof r&&!re.has(r)){if(null!=r.match(ne))throw new W("key "+r+" must not contain null bytes");if(n){if("$"===r[0])throw new W("key "+r+" must not start with '$'");if(r.includes("."))throw new W("key "+r+" must not contain '.'")}}if(void 0===s)!1===h&&(y=ae(t,r,0,y));else if(null===s)y=ae(t,r,0,y);else if("string"===u)y=oe(t,r,s,y);else if("number"===u)y=ie(t,r,s,y);else if("bigint"===u)y=se(t,r,s,y);else if("boolean"===u)y=ue(t,r,s,y);else if("object"===u&&null==s._bsontype)y=s instanceof Date||c(s)?ce(t,r,s,y):s instanceof Uint8Array||i(s)?pe(t,r,s,y):s instanceof RegExp||a(s)?fe(t,r,s,y):ye(t,r,s,y,n,o,f,h,p);else if("object"===u){if(s[d]!==l)throw new J;if("ObjectId"===s._bsontype)y=he(t,r,s,y);else if("Decimal128"===s._bsontype)y=ge(t,r,s,y);else if("Long"===s._bsontype||"Timestamp"===s._bsontype)y=be(t,r,s,y);else if("Double"===s._bsontype)y=we(t,r,s,y);else if("Code"===s._bsontype)y=_e(t,r,s,y,n,o,f,h,p);else if("Binary"===s._bsontype)y=Oe(t,r,s,y);else if("BSONSymbol"===s._bsontype)y=Ee(t,r,s,y);else if("DBRef"===s._bsontype)y=Se(t,r,s,y,o,f,p);else if("BSONRegExp"===s._bsontype)y=le(t,r,s,y);else if("Int32"===s._bsontype)y=me(t,r,s,y);else if("MinKey"===s._bsontype||"MaxKey"===s._bsontype)y=de(t,r,s,y);else if(void 0!==s._bsontype)throw new W(`Unrecognized or invalid _bsontype: ${String(s._bsontype)}`)}else"function"===u&&f&&(y=ve(t,r,s,y))}}p.delete(e),t[y++]=0;const g=y-r;return r+=at.setInt32LE(t,r,g),y}const Ie={$oid:Jt,$binary:ut,$uuid:ut,$symbol:Gt,$numberInt:Ft,$numberDecimal:Dt,$numberDouble:Ct,$numberLong:St,$minKey:Mt,$maxKey:qt,$regex:zt,$regularExpression:zt,$timestamp:Kt};function xe(t,e={}){if("number"==typeof t){const n=t<=h&&t>=p,r=t<=y&&t>=g;if(e.relaxed||e.legacy)return t;if(Number.isInteger(t)&&!Object.is(t,-0)){if(n)return new Ft(t);if(r)return e.useBigInt64?BigInt(t):St.fromNumber(t)}return new Ct(t)}if(null==t||"object"!=typeof t)return t;if(t.$undefined)return null;const n=Object.keys(t).filter(e=>e.startsWith("$")&&null!=t[e]);for(let r=0;r<n.length;r++){const o=Ie[n[r]];if(o)return o.fromExtendedJSON(t,e)}if(null!=t.$date){const n=t.$date,r=new Date;if(e.legacy)if("number"==typeof n)r.setTime(n);else if("string"==typeof n)r.setTime(Date.parse(n));else{if("bigint"!=typeof n)throw new V("Unrecognized type for EJSON date: "+typeof n);r.setTime(Number(n))}else if("string"==typeof n)r.setTime(Date.parse(n));else if(St.isLong(n))r.setTime(n.toNumber());else if("number"==typeof n&&e.relaxed)r.setTime(n);else{if("bigint"!=typeof n)throw new V("Unrecognized type for EJSON date: "+typeof n);r.setTime(Number(n))}return r}if(null!=t.$code){const e=Object.assign({},t);return t.$scope&&(e.$scope=xe(t.$scope)),ht.fromExtendedJSON(t)}if(pt(t)||t.$dbPointer){const e=t.$ref?t:t.$dbPointer;if(e instanceof yt)return e;const n=Object.keys(e).filter(t=>t.startsWith("$"));let r=!0;if(n.forEach(t=>{-1===["$ref","$id","$db"].indexOf(t)&&(r=!1)}),r)return yt.fromExtendedJSON(e)}return t}function Te(t){const e=t.toISOString();return 0!==t.getUTCMilliseconds()?e:e.slice(0,-5)+"Z"}function Be(t,e){if(t instanceof Map||u(t)){const n=Object.create(null);for(const[e,r]of t){if("string"!=typeof e)throw new W("Can only serialize maps with string keys");n[e]=r}return Be(n,e)}if(("object"==typeof t||"function"==typeof t)&&null!==t){const n=e.seenObjects.findIndex(e=>e.obj===t);if(-1!==n){const t=e.seenObjects.map(t=>t.propertyName),r=t.slice(0,n).map(t=>`${t} -> `).join(""),o=t[n],i=" -> "+t.slice(n+1,t.length-1).map(t=>`${t} -> `).join(""),s=t[t.length-1],a=" ".repeat(r.length+o.length/2),u="-".repeat(i.length+(o.length+s.length)/2-1);throw new W(`Converting circular structure to EJSON:\n ${r}${o}${i}${s}\n ${a}\\${u}/`)}e.seenObjects[e.seenObjects.length-1].obj=t}if(Array.isArray(t))return function(t,e){return t.map((t,n)=>{e.seenObjects.push({propertyName:`index ${n}`,obj:null});try{return Be(t,e)}finally{e.seenObjects.pop()}})}(t,e);if(void 0===t)return null;if(t instanceof Date||c(t)){const n=t.getTime(),r=n>-1&&n<2534023188e5;return e.legacy?e.relaxed&&r?{$date:t.getTime()}:{$date:Te(t)}:e.relaxed&&r?{$date:Te(t)}:{$date:{$numberLong:t.getTime().toString()}}}if(!("number"!=typeof t||e.relaxed&&isFinite(t))){if(Number.isInteger(t)&&!Object.is(t,-0)){if(t>=p&&t<=h)return{$numberInt:t.toString()};if(t>=g&&t<=y)return{$numberLong:t.toString()}}return{$numberDouble:Object.is(t,-0)?"-0.0":t.toString()}}if("bigint"==typeof t)return e.relaxed?Number(BigInt.asIntN(64,t)):{$numberLong:BigInt.asIntN(64,t).toString()};if(t instanceof RegExp||a(t)){let n=t.flags;if(void 0===n){const e=t.toString().match(/[gimuy]*$/);e&&(n=e[0])}return new zt(t.source,n).toExtendedJSON(e)}return null!=t&&"object"==typeof t?function(t,e){if(null==t||"object"!=typeof t)throw new W("not an object instance");const n=t._bsontype;if(void 0===n){const n={};for(const r of Object.keys(t)){e.seenObjects.push({propertyName:r,obj:null});try{const o=Be(t[r],e);"__proto__"===r?Object.defineProperty(n,r,{value:o,writable:!0,enumerable:!0,configurable:!0}):n[r]=o}finally{e.seenObjects.pop()}}return n}if(null!=t&&"object"==typeof t&&"string"==typeof t._bsontype&&t[d]!==l)throw new J;if(function(t){return null!=t&&"object"==typeof t&&"_bsontype"in t&&"string"==typeof t._bsontype}(t)){let r=t;if("function"!=typeof r.toExtendedJSON){const e=je[t._bsontype];if(!e)throw new W("Unrecognized or invalid _bsontype: "+t._bsontype);r=e(r)}return"Code"===n&&r.scope?r=new ht(r.code,Be(r.scope,e)):"DBRef"===n&&r.oid&&(r=new yt(Be(r.collection,e),Be(r.oid,e),Be(r.db,e),Be(r.fields,e))),r.toExtendedJSON(e)}throw new W("_bsontype must be a string, but was: "+typeof n)}(t,e):t}const je={Binary:t=>new ut(t.value(),t.sub_type),Code:t=>new ht(t.code,t.scope),DBRef:t=>new yt(t.collection||t.namespace,t.oid,t.db,t.fields),Decimal128:t=>new Dt(t.bytes),Double:t=>new Ct(t.value),Int32:t=>new Ft(t.value),Long:t=>St.fromBits(null!=t.low?t.low:t.low_,null!=t.low?t.high:t.high_,null!=t.low?t.unsigned:t.unsigned_),MaxKey:()=>new qt,MinKey:()=>new Mt,ObjectId:t=>new Jt(t),BSONRegExp:t=>new zt(t.pattern,t.options),BSONSymbol:t=>new Gt(t.value),Timestamp:t=>Kt.fromBits(t.low,t.high)};function Ae(t,e){const n={useBigInt64:e?.useBigInt64??!1,relaxed:e?.relaxed??!0,legacy:e?.legacy??!1};return JSON.parse(t,(t,e)=>{if(-1!==t.indexOf("\0"))throw new W(`BSON Document field names cannot contain null bytes, found: ${JSON.stringify(t)}`);return xe(e,n)})}function Le(t,e,n,r){null!=n&&"object"==typeof n&&(r=n,n=0),null==e||"object"!=typeof e||Array.isArray(e)||(r=e,e=void 0,n=0);const o=Be(t,Object.assign({relaxed:!0,legacy:!1},r,{seenObjects:[{propertyName:"(root)",obj:null}]}));return JSON.stringify(o,e,n)}const Pe=Object.create(null);Pe.parse=Ae,Pe.stringify=Le,Pe.serialize=function(t,e){return e=e||{},JSON.parse(Le(t,e))},Pe.deserialize=function(t,e){return e=e||{},Ae(JSON.stringify(t),e)},Object.freeze(Pe);function $e(t,e){try{return at.getNonnegativeInt32LE(t,e)}catch(t){throw new H("BSON size cannot be negative",e,{cause:t})}}function Ue(t,e){let n=e;for(;0!==t[n];n++);if(n===t.length-1)throw new H("Null terminator not found",e);return n}const Re=Object.create(null);Re.parseToElements=function(t,e=0){if(e??=0,t.length<5)throw new H(`Input must be at least 5 bytes, got ${t.length} bytes`,e);const n=$e(t,e);if(n>t.length-e)throw new H(`Parsed documentSize (${n} bytes) does not match input length (${t.length} bytes)`,e);if(0!==t[e+n-1])throw new H("BSON documents must end in 0x00",e+n);const r=[];let o=e+4;for(;o<=n+e;){const i=t[o];if(o+=1,0===i){if(o-e!==n)throw new H("Invalid 0x00 type byte",o);break}const s=o,a=Ue(t,o)-s;let u;if(o+=a+1,1===i||18===i||9===i||17===i)u=8;else if(16===i)u=4;else if(7===i)u=12;else if(19===i)u=16;else if(8===i)u=1;else if(10===i||6===i||127===i||255===i)u=0;else if(11===i)u=Ue(t,Ue(t,o)+1)+1-o;else if(3===i||4===i||15===i)u=$e(t,o);else{if(2!==i&&5!==i&&12!==i&&13!==i&&14!==i)throw new H(`Invalid 0x${i.toString(16).padStart(2,"0")} type byte`,o);u=$e(t,o)+4,5===i&&(u+=1),12===i&&(u+=12)}if(u>n)throw new H("value reports length larger than document",o);r.push([i,s,a,o,u]),o+=u}return r},Re.ByteUtils=nt,Re.NumberUtils=at,Object.freeze(Re);const De=17825792;let Ce=nt.allocate(De);function Fe(t){Ce.length<t&&(Ce=nt.allocate(t))}function qe(t,e={}){const n="boolean"==typeof e.checkKeys&&e.checkKeys,r="boolean"==typeof e.serializeFunctions&&e.serializeFunctions,o="boolean"!=typeof e.ignoreUndefined||e.ignoreUndefined,i="number"==typeof e.minInternalBufferSize?e.minInternalBufferSize:De;Ce.length<i&&(Ce=nt.allocate(i));const s=Ne(Ce,t,n,0,0,r,o,null),a=nt.allocateUnsafe(s);return a.set(Ce.subarray(0,s),0),a}function Me(t,e,n={}){const r="boolean"==typeof n.checkKeys&&n.checkKeys,o="boolean"==typeof n.serializeFunctions&&n.serializeFunctions,i="boolean"!=typeof n.ignoreUndefined||n.ignoreUndefined,s="number"==typeof n.index?n.index:0,a=Ne(Ce,t,r,0,0,o,i,null);return e.set(Ce.subarray(0,a),s),s+a-1}function ke(t,e={}){return Xt(nt.toLocalBufferType(t),e)}function We(t,e={}){return Vt(t,"boolean"==typeof(e=e||{}).serializeFunctions&&e.serializeFunctions,"boolean"!=typeof e.ignoreUndefined||e.ignoreUndefined)}function Je(t,e,n,r,o,i){const s=Object.assign({allowObjectSmallerThanBufferSize:!0,index:0},i),a=nt.toLocalBufferType(t);let u=e;for(let t=0;t<n;t++){const e=at.getInt32LE(a,u);s.index=u,r[o+t]=Xt(a,s),u+=e}return u}var Ve=Object.freeze({__proto__:null,BSONError:W,BSONOffsetError:H,BSONRegExp:zt,BSONRuntimeError:V,BSONSymbol:Gt,BSONType:k,BSONValue:rt,BSONVersionError:J,Binary:ut,Code:ht,DBRef:yt,Decimal128:Dt,Double:Ct,EJSON:Pe,Int32:Ft,Long:St,MaxKey:qt,MinKey:Mt,ObjectId:Jt,Timestamp:Kt,UUID:dt,calculateObjectSize:We,deserialize:ke,deserializeStream:Je,onDemand:Re,serialize:qe,serializeWithBufferAndIndex:Me,setInternalBufferSize:Fe})}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,n),i.exports}return n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n(198)})());