@cloudbase/js-sdk 2.25.5-alpha.1 → 2.25.6
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.
- package/database/dist/index.esm.js +3 -421
- package/database/dist/index.js +4 -422
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/index.d.ts +21 -37
- package/miniprogram_dist/app.js +1 -1
- package/miniprogram_dist/auth.js +1 -1
- package/miniprogram_dist/database.js +1 -1
- package/miniprogram_dist/index.js +1 -1
- package/package.json +15 -15
|
@@ -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,(()=>(()=>{"use strict";var t={258:function(t,e,n){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=void 0;var u=n(543),c=n(249),f={getUrlPrefix:function(t){return"/database/instances/".concat((null==t?void 0:t.instance)||"(default)","/databases/").concat((null==t?void 0:t.database)||"(default)")},"database.queryDocument":function(t){return s(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?projection=").concat(t.projection?JSON.stringify(t.projection):"","&offset=").concat(t.offset||0,"&limit=").concat(t.limit||100,"&order=").concat(t.order?JSON.stringify(t.order):"","&query=").concat(t.query?c.EJSON.stringify(t.query,{relaxed:!1}):"","&transactionId=").concat(t.transactionId||""),method:"GET"})];case 1:return delete(e=n.sent()).header,[2,e]}}))}))},"database.addDocument":function(t){var e,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(f.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"POST",data:i({data:Array.isArray(t.data)?t.data:[t.data]},t.transactionId?{transactionId:t.transactionId}:{})})];case 1:return r=o.sent(),Array.isArray(t.data)||(r=i(i({},r),{data:i({_id:null===(n=null===(e=r.data)||void 0===e?void 0:e.insertedIds)||void 0===n?void 0:n[0]},r.data)})),delete r.header,[2,r]}}))}))},"database.updateDocument":function(t){return s(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"PATCH",data:i({query:t.query,data:t.data,multi:!!t.multi,upsert:!!t.upsert,replaceMode:!!t.replaceMode},t.transactionId?{transactionId:t.transactionId}:{})})];case 1:return delete(e=n.sent()).header,[2,e]}}))}))},"database.deleteDocument":function(t){return s(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/remove"),method:"POST",data:i({query:t.query,multi:!!t.multi},t.transactionId?{transactionId:t.transactionId}:{})})];case 1:return delete(e=n.sent()).header,[2,e]}}))}))},"database.countDocument":function(t){return s(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?count=true&query=").concat(t.query?c.EJSON.stringify(t.query,{relaxed:!1}):""),method:"GET"})];case 1:return delete(e=n.sent()).header,[2,e]}}))}))},"database.addCollection":function(t){return s(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/collections"),method:"POST",data:{collectionName:t.collectionName}})];case 1:return delete(e=n.sent()).header,[2,e]}}))}))},"database.aggregate":function(t){var e,n;return s(this,void 0,void 0,(function(){var r,o;return a(this,(function(i){switch(i.label){case 0:return r=t.stages.map((function(t){var e;try{return(e={})[t.stageKey]=JSON.parse(c.EJSON.stringify(JSON.parse(t.stageValue),{relaxed:!1})),e}catch(e){return t}})),[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/aggregations"),method:"POST",data:{pipeline:r}})];case 1:return o=i.sent(),Array.isArray(null===(e=o.data)||void 0===e?void 0:e.list)&&(o.data.list=JSON.stringify(null===(n=o.data.list)||void 0===n?void 0:n.map((function(t){return JSON.stringify(t)})))),delete o.header,[2,o]}}))}))},"database.startTransaction":function(t){return s(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/transactions"),method:"POST"})];case 1:return"object"==typeof(e=n.sent()).data&&delete(e=i(i({},e),e.data)).data,delete e.header,[2,e]}}))}))},"database.commitTransaction":function(t){return s(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/commit"),method:"POST"})];case 1:return delete(e=n.sent()).header,[2,e]}}))}))},"database.abortTransaction":function(t){return s(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/rollback"),method:"POST"})];case 1:return delete(e=n.sent()).header,[2,e]}}))}))},"database.getInTransaction":function(t){var e;return s(this,void 0,void 0,(function(){var n;return a(this,(function(r){switch(r.label){case 0:return[4,f["database.queryDocument"].bind(this)(t)];case 1:return"object"==typeof(n=r.sent()).data&&((null===(e=n.data)||void 0===e?void 0:e.code)?delete(n=i(i({},n),n.data)).data:n.data=JSON.stringify(n.data)),[2,n]}}))}))},"database.updateDocInTransaction":function(t){return s(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:try{t.data=c.EJSON.parse(t.data)}catch(t){}return[4,f["database.updateDocument"].bind(this)(t)];case 1:return"object"==typeof(e=n.sent()).data&&delete(e=i(i({},e),e.data)).data,[2,e]}}))}))},"database.deleteDocInTransaction":function(t){return s(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,f["database.deleteDocument"].bind(this)(t)];case 1:return"object"==typeof(e=n.sent()).data&&delete(e=i(i({},e),e.data)).data,[2,e]}}))}))},"database.insertDocInTransaction":function(t){var e,n;return s(this,void 0,void 0,(function(){var r,o;return a(this,(function(s){switch(s.label){case 0:try{t.data=c.EJSON.parse(t.data)}catch(t){}return[4,f["database.addDocument"].bind(this)(t)];case 1:return"object"==typeof(r=s.sent()).data&&delete(o=i(i(i({},r),{inserted:+!!(null===(e=r.data)||void 0===e?void 0:e._id),ok:+!!(null===(n=r.data)||void 0===n?void 0:n._id)}),r.data)).data,[2,o]}}))}))},"database.runCommands":function(t){return s(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/commands"),method:"POST",data:i({commands:JSON.parse(c.EJSON.stringify(t.commands,{relaxed:!1}))},t.transactionId?{transactionId:t.transactionId}:{})})];case 1:delete(e=n.sent()).header,"object"==typeof e.data&&(delete(e=i(i({},e),e.data)).data,delete e.request_id);try{return[2,c.EJSON.parse(JSON.stringify(e))]}catch(t){}return[2,e]}}))}))}},l={name:"database",entity:{database:function(t){var e=this.platform,n=e.adapter,r=e.runtime,c=function(t){function e(e){return t.call(this,e)||this}return o(e,t),e.prototype.send=function(e,n){return s(this,void 0,void 0,(function(){var r;return a(this,(function(o){switch(o.label){case 0:return r=null,"GATEWAY"===this.config.endPointMode&&f[e]?[4,f[e].call(this,n)]:[3,2];case 1:return r=o.sent(),[3,4];case 2:return[4,t.prototype.send.call(this,e,n)];case 3:r=o.sent(),o.label=4;case 4:return[2,r]}}))}))},e}(this.request.constructor);return u.Db.reqClass=c,u.Db.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},u.Db.runtime=r,this.wsClientClass&&(u.Db.wsClass=n.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,void 0,(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 h(t){try{t.registerComponent(l)}catch(t){console.warn(t)}}e.registerDatabase=h;try{window.registerDatabase=h}catch(t){}},543:(t,e,n)=>{n.r(e),n.d(e,{CollectionReference:()=>zt,Db:()=>le,DocumentReference:()=>Dt,Query:()=>Ft});var r,o,i={};n.r(i),n.d(i,{LineString:()=>K,MultiLineString:()=>nt,MultiPoint:()=>tt,MultiPolygon:()=>ot,Point:()=>Z,Polygon:()=>X}),function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined"}(o||(o={}));var s,a,u="Object",c="GeoPoint",f="GeoLineString",l="GeoPolygon",h="GeoMultiPoint",d="GeoMultiLineString",p="GeoMultiPolygon",y="Date",g="ServerDate",m=["desc","asc"],b=["<","<=","==",">=",">"];!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=(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)}),_=[],O={},S=function(t){function e(e,n){if(n!==O)throw new TypeError("InternalSymbol cannot be constructed with new operator");return t.call(this,e)||this}return v(e,t),e.for=function(t){for(var n=0,r=_.length;n<r;n++)if(_[n].target===t)return _[n].instance;var o=new e(t,O);return _.push({target:t,instance:o}),o},e}((function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})}));const E=S;var N=E.for("UNSET_FIELD_NAME"),I=E.for("UPDATE_COMMAND"),T=E.for("QUERY_COMMAND"),B=E.for("LOGIC_COMMAND"),x=E.for("GEO_POINT"),L=E.for("SYMBOL_GEO_LINE_STRING"),$=E.for("SYMBOL_GEO_POLYGON"),U=E.for("SYMBOL_GEO_MULTI_POINT"),A=E.for("SYMBOL_GEO_MULTI_LINE_STRING"),j=E.for("SYMBOL_GEO_MULTI_POLYGON"),P=E.for("SERVER_DATE"),D=E.for("REGEXP"),R=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 P},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$date:{offset:this.offset}}},t}();function q(t){return new R(t)}var C,F=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},M=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 Z(i.coordinates[0],i.coordinates[1]);break;case f:o=new K(i.coordinates.map((function(t){return new Z(t[0],t[1])})));break;case l:o=new X(i.coordinates.map((function(t){return new K(t.map((function(t){var e=F(t,2),n=e[0],r=e[1];return new Z(n,r)})))})));break;case h:o=new tt(i.coordinates.map((function(t){return new Z(t[0],t[1])})));break;case d:o=new nt(i.coordinates.map((function(t){return new K(t.map((function(t){var e=F(t,2),n=e[0],r=e[1];return new Z(n,r)})))})));break;case p:o=new ot(i.coordinates.map((function(t){return new X(t.map((function(t){return new K(t.map((function(t){var e=F(t,2),n=e[0],r=e[1];return new Z(n,r)})))})))})));break;case y:o=new Date(1e3*i.$timestamp);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);if(e===y)return"BsonDate";if(e===u){if(t instanceof Z)return c;if(t instanceof Date)return y;if(t instanceof R)return g;t.$timestamp?e=y:t.$date?e=g:Z.validate(t)?e=c:K.validate(t)?e=f:X.validate(t)?e=l:tt.validate(t)?e=h:nt.validate(t)?e=d:ot.validate(t)&&(e=p)}return e},t.generateDocId=function(){for(var t="",e=0;e<24;e++)t+="ABCDEFabcdef0123456789".charAt(Math.floor(22*Math.random()));return t},t}(),J=function(){function t(){}return t.isGeopoint=function(t,e){if("Number"!==M.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.isFieldOrder=function(t){if(-1===m.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===b.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}(),k=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},V=function(t){return"object"===k(t)},z=function(t){return"number"===k(t)},H=function(t){return Array.isArray(t)},Y=function(t){return"date"===k(t)},G=function(t){return"regexp"===k(t)},W=function(t){return t&&t._internalType instanceof S},Z=function(){function t(t,e){J.isGeopoint("longitude",t),J.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&&H(t.coordinates)&&J.isGeopoint("longitude",t.coordinates[0])&&J.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return x},enumerable:!1,configurable:!0}),t}(),K=function(){function t(t){if(!H(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 Z))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||!H(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(!z(i[0])||!z(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 L},enumerable:!1,configurable:!0}),t}(),Q=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.")},X=function(){function t(t){if(!H(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 K))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"));if(!K.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||!H(t.coordinates))return!1;try{for(var i=Q(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,Q(a)),c=u.next();!c.done;c=u.next()){var f=c.value;if(!z(f[0])||!z(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 j},enumerable:!1,configurable:!0}),t}(),tt=function(){function t(t){if(!H(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 Z))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||!H(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(!z(i[0])||!z(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 U},enumerable:!1,configurable:!0}),t}(),et=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.")},nt=function(){function t(t){if(!H(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 K))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||!H(t.coordinates))return!1;try{for(var i=et(t.coordinates),s=i.next();!s.done;s=i.next()){var a=s.value;try{for(var u=(r=void 0,et(a)),c=u.next();!c.done;c=u.next()){var f=c.value;if(!z(f[0])||!z(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 A},enumerable:!1,configurable:!0}),t}(),rt=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(!H(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=rt(t),o=r.next();!o.done;o=r.next()){var i=o.value;if(!(i instanceof X))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||!H(t.coordinates))return!1;try{for(var a=rt(t.coordinates),u=a.next();!u.done;u=a.next()){var c=u.value;try{for(var f=(r=void 0,rt(c)),l=f.next();!l.done;l=f.next()){var h=l.value;try{for(var d=(i=void 0,rt(h)),p=d.next();!p.done;p=d.next()){var y=p.value;if(!z(y[0])||!z(y[1]))return!1}}catch(t){i={error:t}}finally{try{p&&!p.done&&(s=d.return)&&s.call(d)}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 $},enumerable:!1,configurable:!0}),t}(),it=function(){var t=function(){};if(!Promise){t.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};!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"}(C||(C={}));var st,at=function(){function t(t,e,n){this._internalType=I,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||N}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function ut(t){return t&&t instanceof at&&t._internalType===I}!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(st||(st={}));var ct=function(){function t(t,e,n){if(this._internalType=B,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||N,this.fieldName!==N)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,o=e.length;r<o;r++)(ft(i=e[r])||pt(i))&&(e[r]=i._setFieldName(this.fieldName))}else{var i;(ft(i=e)||pt(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(st.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(st.OR,r,this.fieldName)},t}();function ft(t){return t&&t instanceof ct&&t._internalType===B}var lt,ht=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"}(lt||(lt={}));var dt=function(t){function e(e,n,r){var o=t.call(this,e,n,r)||this;return o.operator=e,o._internalType=T,o}return ht(e,t),e.prototype.toJSON=function(){var t,e;switch(this.operator){case lt.IN:case lt.NIN:return(t={})["$"+this.operator]=this.operands,t;default:return(e={})["$"+this.operator]=this.operands[0],e}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(lt.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(lt.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(lt.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(lt.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(lt.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(lt.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(lt.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(lt.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof Z))throw new TypeError('"geometry" must be of type Point. Received type '.concat(typeof t.geometry));if(void 0!==t.maxDistance&&!z(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '.concat(typeof t.maxDistance));if(void 0!==t.minDistance&&!z(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '.concat(typeof t.minDistance));var n=new e(lt.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof ot||t.geometry instanceof X))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(lt.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof Z||t.geometry instanceof K||t.geometry instanceof X||t.geometry instanceof tt||t.geometry instanceof nt||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(lt.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(ct);function pt(t){return t&&t instanceof dt&&t._internalType===T}function yt(t){return pt(t)}var gt={};for(var mt in lt)gt[mt]="$"+mt;for(var mt in st)gt[mt]="$"+mt;for(var mt in C)gt[mt]="$"+mt;function bt(t){return gt[t]||"$"+t}gt[lt.NEQ]="$ne",gt[C.REMOVE]="$unset",gt[C.SHIFT]="$pop",gt[C.UNSHIFT]="$push";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)},vt=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},_t=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 Ot(t){return St(t,[t])}function St(t,e){if(!W(t)){if(Y(t))return{$date:+t};if(G(t))return{$regex:t.source,$options:t.flags};if(H(t))return t.map((function(t){if(e.indexOf(t)>-1)throw new Error("Cannot convert circular structure to JSON");return St(t,_t(_t([],vt(e),!1),[t],!1))}));if(V(t)){var n=wt({},t);for(var r in n){if(e.indexOf(n[r])>-1)throw new Error("Cannot convert circular structure to JSON");n[r]=St(n[r],_t(_t([],vt(e),!1),[n[r]],!1))}return n}return t}switch(t._internalType){case x:return t.toJSON();case P:case D:return t.parse();default:return t.toJSON?t.toJSON():t}}var Et=function(){return Et=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},Et.apply(this,arguments)},Nt=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},It=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 Tt(t,e,n,r){var o=Et({},t);for(var i in t)if(!/^\$/.test(i)){var s=t[i];if(s&&V(s)&&!e(s)){if(r.indexOf(s)>-1)throw new Error("Cannot convert circular structure to JSON");var a=Tt(s,e,It(It([],Nt(n),!1),[i],!1),It(It([],Nt(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]}}return o}function Bt(t){return Tt(t,Lt,[],[t])}function xt(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?H(t[r])?t[r].push(e[r]):V(t[r])?V(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is ".concat(k(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(k(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]}function Lt(t){return W(t)||Y(t)||G(t)}function $t(t){return Ot(t)}var Ut=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.prototype.encodeUpdate=function(t){return ut(t)?this.encodeUpdateCommand(t):"object"===k(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===N)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case C.PUSH:case C.PULL:case C.PULL_ALL:case C.POP:case C.SHIFT:case C.UNSHIFT:case C.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,o,i=bt(t.operator);return t.operator===C.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=bt(t.operator);switch(t.operator){case C.PUSH:var h=void 0;return h=H(t.operands)?{$each:t.operands.map($t)}:t.operands,(e={})[l]=((n={})[t.fieldName]=h,n),e;case C.UNSHIFT:return h={$each:t.operands.map($t),$position:0},(r={})[l]=((o={})[t.fieldName]=h,o),r;case C.POP:return(i={})[l]=((s={})[t.fieldName]=1,s),i;case C.SHIFT:return(a={})[l]=((u={})[t.fieldName]=-1,u),a;default:return(c={})[l]=((f={})[t.fieldName]=$t(t.operands),f),c}},t.prototype.encodeUpdateObject=function(t){var e=Bt(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(ut(r))e[n]=r._setFieldName(n),xt(e,this.encodeUpdateCommand(e[n]),n);else{e[n]=r=$t(r);var o=new at(C.SET,[r],n);xt(e,this.encodeUpdateCommand(o),n)}}return e},t}(),At={};function jt(t){if(!le.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return At[e]||(At[e]=new le.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:le.createRequest(t.config)}}})),At[e]}var Pt=function(){return Pt=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},Pt.apply(this,arguments)},Dt=function(){function t(t,e,n,r){void 0===r&&(r={});var o=this;this.watch=function(t){return jt(o._db).watch(Pt(Pt({},t),{envId:o._db.config.env,collectionName:o._coll,query:JSON.stringify({_id:o.id})}))},this._db=t,this._coll=e,this.id=n,this.request=le.createRequest(this._db.config),this.projection=r}return t.prototype.create=function(t,e){e=e||it();var n={collectionName:this._coll,data:Ot(t)};return this.id&&(n._id=this.id),this.request.send("database.addDocument",n).then((function(t){t.code?e(0,t):e(0,{id:t.data._id,requestId:t.requestId})})).catch((function(t){e(t)})),e.promise},t.prototype.set=function(t,e){if(e=e||it(),!this.id)return Promise.resolve({code:"INVALID_PARAM",message:"docId不能为空"});if(!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n=!1,r=function(t){if("object"==typeof t)for(var e in t)t[e]instanceof at?n=!0:"object"==typeof t[e]&&r(t[e])};if(r(t),n)return Promise.resolve({code:"DATABASE_REQUEST_FAILED",message:"update operator complicit"});var o={collectionName:this._coll,queryType:a.DOC,data:Ot(t),multi:!1,merge:!1,upsert:!0};return this.id&&(o.query={_id:this.id}),this.request.send("database.updateDocument",o).then((function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})})).catch((function(t){e(t)})),e.promise},t.prototype.update=function(t,e){if(e=e||it(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={_id:this.id},r={collectionName:this._coll,data:Ut.encode(t),query:n,queryType:a.DOC,multi:!1,merge:!0,upsert:!1};return this.request.send("database.updateDocument",r).then((function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})})).catch((function(t){e(t)})),e.promise},t.prototype.remove=function(t){t=t||it();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:a.DOC,multi:!1};return this.request.send("database.deleteDocument",n).then((function(e){e.code?t(0,e):t(0,{deleted:e.data.deleted,requestId:e.requestId})})).catch((function(e){t(e)})),t.promise},t.prototype.get=function(t){t=t||it();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:a.DOC,multi:!1,projection:this.projection};return this.request.send("database.queryDocument",n).then((function(e){if(e.code)t(0,e);else{var n=M.formatResDocumentData(e.data.list);t(0,{data:n,requestId:e.requestId})}})).catch((function(e){t(e)})),t.promise},t.prototype.field=function(e){for(var n in e)e[n]?e[n]=1:e[n]=0;return new t(this._db,this._coll,this.id,e)},t}(),Rt=function(){function t(){}return t.encode=function(t){return(new qt).encodeQuery(t)},t}(),qt=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n;return Lt(t)?ft(t)?this.encodeLogicCommand(t):pt(t)?this.encodeQueryCommand(t):((n={})[e]=this.encodeQueryObject(t),n):V(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regex:t.source,$options:t.flags}},t.prototype.encodeLogicCommand=function(t){var e,n,r,o,i,s,a,u=this;switch(t.operator){case st.NOR:case st.AND:case st.OR:var c=bt(t.operator),f=t.operands.map((function(e){return u.encodeQuery(e,t.fieldName)}));return(e={})[c]=f,e;case st.NOT:c=bt(t.operator);var l=t.operands[0];return G(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=bt(t.operator),1===t.operands.length){var h=this.encodeQuery(t.operands[0]);return(s={})[c]=h,s}return f=t.operands.map(this.encodeQuery.bind(this)),(a={})[c]=f,a}},t.prototype.encodeQueryCommand=function(t){return yt(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,o,i,s,a,u,c;if(t.fieldName===N)throw new Error("Cannot encode a comparison command with unset field name");var f=bt(t.operator);switch(t.operator){case lt.EQ:case lt.NEQ:case lt.LT:case lt.LTE:case lt.GT:case lt.GTE:case lt.ELEM_MATCH:case lt.EXISTS:case lt.SIZE:case lt.MOD:return(e={})[t.fieldName]=((n={})[f]=$t(t.operands[0]),n),e;case lt.IN:case lt.NIN:case lt.ALL:return(r={})[t.fieldName]=((o={})[f]=$t(t.operands),o),r;case lt.GEO_NEAR:var l=t.operands[0];return(i={})[t.fieldName]={$nearSphere:{$geometry:l.geometry.toJSON(),$maxDistance:l.maxDistance,$minDistance:l.minDistance}},i;case lt.GEO_WITHIN:return l=t.operands[0],(s={})[t.fieldName]={$geoWithin:{$geometry:l.geometry.toJSON()}},s;case lt.GEO_INTERSECTS:return l=t.operands[0],(a={})[t.fieldName]={$geoIntersects:{$geometry:l.geometry.toJSON()}},a;default:return(u={})[t.fieldName]=((c={})[f]=$t(t.operands[0]),c),u}},t.prototype.encodeQueryObject=function(t){var e=Bt(t);for(var n in e){var r=e[n];if(ft(r)){e[n]=r._setFieldName(n);var o=this.encodeLogicCommand(e[n]);this.mergeConditionAfterEncode(e,o,n)}else yt(r)?(e[n]=r._setFieldName(n),o=this.encodeComparisonCommand(e[n]),this.mergeConditionAfterEncode(e,o,n)):Lt(r)&&(e[n]=$t(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?H(t[r])?t[r]=t[r].concat(e[r]):V(t[r])?V(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is ".concat(k(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(k(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),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(){function t(t,e,n,r,o){var i=this;this.watch=function(t){return jt(i._db).watch(Ct(Ct({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify(i._fieldFilters||{}),limit:i._queryOptions.limit,orderBy:i._fieldOrders?i._fieldOrders.reduce((function(t,e){return t[e.field]=e.direction,t}),{}):void 0}))},this._db=t,this._coll=e,this._fieldFilters=n,this._fieldOrders=r||[],this._queryOptions=o||{},this._request=le.createRequest(this._db.config)}return t.prototype.get=function(t){t=t||it();var e=[];this._fieldOrders&&this._fieldOrders.forEach((function(t){e.push(t)}));var n={collectionName:this._coll,queryType:a.WHERE};return this._fieldFilters&&(n.query=this._fieldFilters),e.length>0&&(n.order=e),this._queryOptions.offset&&(n.offset=this._queryOptions.offset),this._queryOptions.limit?n.limit=this._queryOptions.limit<1e3?this._queryOptions.limit:1e3:n.limit=100,this._queryOptions.projection&&(n.projection=this._queryOptions.projection),this._request.send("database.queryDocument",n).then((function(e){if(e.code)t(0,e);else{var n={data:M.formatResDocumentData(e.data.list),requestId:e.requestId};void 0!==e.total&&(n.total=e.total),void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset),t(0,n)}})).catch((function(e){t(e)})),t.promise},t.prototype.count=function(t){t=t||it();var e={collectionName:this._coll,queryType:a.WHERE};return this._fieldFilters&&(e.query=this._fieldFilters),this._request.send("database.countDocument",e).then((function(e){e.code?t(0,e):t(0,{requestId:e.requestId,total:e.data.total})})).catch((function(e){t(e)})),t.promise},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,Rt.encode(e),this._fieldOrders,this._queryOptions)},t.prototype.orderBy=function(e,n){J.isFieldPath(e),J.isFieldOrder(n);var r={field:e,direction:n},o=this._fieldOrders.concat(r);return new t(this._db,this._coll,this._fieldFilters,o,this._queryOptions)},t.prototype.limit=function(e){J.isInteger("limit",e);var n=Ct({},this._queryOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.skip=function(e){J.isInteger("offset",e);var n=Ct({},this._queryOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.update=function(t,e){if(e=e||it(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={collectionName:this._coll,query:this._fieldFilters,queryType:a.WHERE,multi:!0,merge:!0,upsert:!1,data:Ut.encode(t)};return this._request.send("database.updateDocument",n).then((function(t){t.code?e(0,t):e(0,{requestId:t.requestId,updated:t.data.updated,upsertId:t.data.upsert_id})})).catch((function(t){e(t)})),e.promise},t.prototype.field=function(e){for(var n in e)e[n]?"object"!=typeof e[n]&&(e[n]=1):e[n]=0;var r=Ct({},this._queryOptions);return r.projection=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,r)},t.prototype.remove=function(t){t=t||it(),Object.keys(this._queryOptions).length>0&&console.warn("`offset`, `limit` and `projection` are not supported in remove() operation"),this._fieldOrders.length>0&&console.warn("`orderBy` is not supported in remove() operation");var e={collectionName:this._coll,query:Rt.encode(this._fieldFilters),queryType:a.WHERE,multi:!0};return this._request.send("database.deleteDocument",e).then((function(e){e.code?t(0,e):t(0,{requestId:e.requestId,deleted:e.data.deleted})})).catch((function(e){t(e)})),t.promise},t}(),Mt=n(249),Jt=function(){function t(t,e){this._stages=[],t&&e&&(this._db=t,this._request=le.createRequest(this._db.config),this._collectionName=e)}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.aggregate",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:JSON.parse(t.data.list).map(Mt.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){return this._stages.push({stageKey:"$".concat(t),stageValue:JSON.stringify(e)}),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=Rt.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new Z(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",Rt.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 kt=Jt;var Vt=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)}}(),zt=function(t){function e(e,n){return t.call(this,e,n)||this}return Vt(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 Dt(this._db,this._coll,t)},e.prototype.add=function(t,e){return new Dt(this._db,this._coll,void 0).create(t,e)},e.prototype.aggregate=function(){return new kt(this._db,this._coll)},e}(Ft),Ht={eq:function(t){return new dt(lt.EQ,[t])},neq:function(t){return new dt(lt.NEQ,[t])},lt:function(t){return new dt(lt.LT,[t])},lte:function(t){return new dt(lt.LTE,[t])},gt:function(t){return new dt(lt.GT,[t])},gte:function(t){return new dt(lt.GTE,[t])},in:function(t){return new dt(lt.IN,t)},nin:function(t){return new dt(lt.NIN,t)},all:function(t){return new dt(lt.ALL,t)},elemMatch:function(t){return new dt(lt.ELEM_MATCH,[t])},exists:function(t){return new dt(lt.EXISTS,[t])},size:function(t){return new dt(lt.SIZE,[t])},mod:function(t){return new dt(lt.MOD,[t])},geoNear:function(t){return new dt(lt.GEO_NEAR,[t])},geoWithin:function(t){return new dt(lt.GEO_WITHIN,[t])},geoIntersects:function(t){return new dt(lt.GEO_INTERSECTS,[t])},and:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=H(arguments[0])?arguments[0]:Array.from(arguments);return new ct(st.AND,n)},nor:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=H(arguments[0])?arguments[0]:Array.from(arguments);return new ct(st.NOR,n)},or:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=H(arguments[0])?arguments[0]:Array.from(arguments);return new ct(st.OR,n)},not:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=H(arguments[0])?arguments[0]:Array.from(arguments);return new ct(st.NOT,n)},set:function(t){return new at(C.SET,[t])},remove:function(){return new at(C.REMOVE,[])},inc:function(t){return new at(C.INC,[t])},mul:function(t){return new at(C.MUL,[t])},push:function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(V(e[0])&&e[0].hasOwnProperty("each")){var r=e[0];t={$each:r.each,$position:r.position,$sort:r.sort,$slice:r.slice}}else t=H(e[0])?e[0]:Array.from(e);return new at(C.PUSH,t)},pull:function(t){return new at(C.PULL,t)},pullAll:function(t){return new at(C.PULL_ALL,t)},pop:function(){return new at(C.POP,[])},shift:function(){return new at(C.SHIFT,[])},unshift:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=H(arguments[0])?arguments[0]:Array.from(arguments);return new at(C.UNSHIFT,n)},addToSet:function(t){return new at(C.ADD_TO_SET,t)},rename:function(t){return new at(C.RENAME,[t])},bit:function(t){return new at(C.BIT,[t])},max:function(t){return new at(C.MAX,[t])},min:function(t){return new at(C.MIN,[t])},expr:function(t){return{$expr:t}},jsonSchema:function(t){return{$jsonSchema:t}},text:function(t){return"string"===k(t)?{$search:t.search}:{$search:t.search,$language:t.language,$caseSensitive:t.caseSensitive,$diacriticSensitive:t.diacriticSensitive}},aggregate:{pipeline:function(){return new kt},abs:function(t){return new Yt("abs",t)},add:function(t){return new Yt("add",t)},ceil:function(t){return new Yt("ceil",t)},divide:function(t){return new Yt("divide",t)},exp:function(t){return new Yt("exp",t)},floor:function(t){return new Yt("floor",t)},ln:function(t){return new Yt("ln",t)},log:function(t){return new Yt("log",t)},log10:function(t){return new Yt("log10",t)},mod:function(t){return new Yt("mod",t)},multiply:function(t){return new Yt("multiply",t)},pow:function(t){return new Yt("pow",t)},sqrt:function(t){return new Yt("sqrt",t)},subtract:function(t){return new Yt("subtract",t)},trunc:function(t){return new Yt("trunc",t)},arrayElemAt:function(t){return new Yt("arrayElemAt",t)},arrayToObject:function(t){return new Yt("arrayToObject",t)},concatArrays:function(t){return new Yt("concatArrays",t)},filter:function(t){return new Yt("filter",t)},in:function(t){return new Yt("in",t)},indexOfArray:function(t){return new Yt("indexOfArray",t)},isArray:function(t){return new Yt("isArray",t)},map:function(t){return new Yt("map",t)},range:function(t){return new Yt("range",t)},reduce:function(t){return new Yt("reduce",t)},reverseArray:function(t){return new Yt("reverseArray",t)},size:function(t){return new Yt("size",t)},slice:function(t){return new Yt("slice",t)},zip:function(t){return new Yt("zip",t)},and:function(t){return new Yt("and",t)},not:function(t){return new Yt("not",t)},or:function(t){return new Yt("or",t)},cmp:function(t){return new Yt("cmp",t)},eq:function(t){return new Yt("eq",t)},gt:function(t){return new Yt("gt",t)},gte:function(t){return new Yt("gte",t)},lt:function(t){return new Yt("lt",t)},lte:function(t){return new Yt("lte",t)},neq:function(t){return new Yt("ne",t)},cond:function(t){return new Yt("cond",t)},ifNull:function(t){return new Yt("ifNull",t)},switch:function(t){return new Yt("switch",t)},dateFromParts:function(t){return new Yt("dateFromParts",t)},dateFromString:function(t){return new Yt("dateFromString",t)},dayOfMonth:function(t){return new Yt("dayOfMonth",t)},dayOfWeek:function(t){return new Yt("dayOfWeek",t)},dayOfYear:function(t){return new Yt("dayOfYear",t)},isoDayOfWeek:function(t){return new Yt("isoDayOfWeek",t)},isoWeek:function(t){return new Yt("isoWeek",t)},isoWeekYear:function(t){return new Yt("isoWeekYear",t)},millisecond:function(t){return new Yt("millisecond",t)},minute:function(t){return new Yt("minute",t)},month:function(t){return new Yt("month",t)},second:function(t){return new Yt("second",t)},hour:function(t){return new Yt("hour",t)},week:function(t){return new Yt("week",t)},year:function(t){return new Yt("year",t)},literal:function(t){return new Yt("literal",t)},mergeObjects:function(t){return new Yt("mergeObjects",t)},objectToArray:function(t){return new Yt("objectToArray",t)},allElementsTrue:function(t){return new Yt("allElementsTrue",t)},anyElementTrue:function(t){return new Yt("anyElementTrue",t)},setDifference:function(t){return new Yt("setDifference",t)},setEquals:function(t){return new Yt("setEquals",t)},setIntersection:function(t){return new Yt("setIntersection",t)},setIsSubset:function(t){return new Yt("setIsSubset",t)},setUnion:function(t){return new Yt("setUnion",t)},concat:function(t){return new Yt("concat",t)},dateToString:function(t){return new Yt("dateToString",t)},indexOfBytes:function(t){return new Yt("indexOfBytes",t)},indexOfCP:function(t){return new Yt("indexOfCP",t)},split:function(t){return new Yt("split",t)},strLenBytes:function(t){return new Yt("strLenBytes",t)},strLenCP:function(t){return new Yt("strLenCP",t)},strcasecmp:function(t){return new Yt("strcasecmp",t)},substr:function(t){return new Yt("substr",t)},substrBytes:function(t){return new Yt("substrBytes",t)},substrCP:function(t){return new Yt("substrCP",t)},toLower:function(t){return new Yt("toLower",t)},toUpper:function(t){return new Yt("toUpper",t)},meta:function(t){return new Yt("meta",t)},addToSet:function(t){return new Yt("addToSet",t)},avg:function(t){return new Yt("avg",t)},first:function(t){return new Yt("first",t)},last:function(t){return new Yt("last",t)},max:function(t){return new Yt("max",t)},min:function(t){return new Yt("min",t)},push:function(t){return new Yt("push",t)},stdDevPop:function(t){return new Yt("stdDevPop",t)},stdDevSamp:function(t){return new Yt("stdDevSamp",t)},sum:function(t){return new Yt("sum",t)},let:function(t){return new Yt("let",t)}},project:{slice:function(t){return new Gt("slice",t)},elemMatch:function(t){return new Gt("elemMatch",t)}}},Yt=function(t,e){this["$"+t]=e},Gt=function(t,e){this["$"+t]=e},Wt=function(){function t(t){var e=t.regexp,n=t.options;if(!e)throw new TypeError("regexp must be a string");this.$regex=e,this.$options=n}return t.prototype.parse=function(){return{$regex:this.$regex,$options:this.$options}},Object.defineProperty(t.prototype,"_internalType",{get:function(){return D},enumerable:!1,configurable:!0}),t}();function Zt(t){return new Wt(t)}var Kt="insert document failed",Qt="DATABASE_TRANSACTION_CONFLICT",Xt=function(){return Xt=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},Xt.apply(this,arguments)},te=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())}))},ee=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])}}},ne="database.updateDocInTransaction",re=function(){function t(t,e,n){this._coll=e,this.id=n,this._transaction=t,this._request=this._transaction.getRequestMethod(),this._transactionId=this._transaction.getTransactionId()}return t.prototype.create=function(t){return te(this,void 0,void 0,(function(){var e,n,r,o;return ee(this,(function(i){switch(i.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,data:Mt.EJSON.stringify(Ot(t),{relaxed:!1})},this.id&&(e._id=this.id),[4,this._request.send("database.insertDocInTransaction",e)];case 1:if((n=i.sent()).code)throw n;if(r=Mt.EJSON.parse(n.inserted),1==(o=Mt.EJSON.parse(n.ok))&&1==r)return[2,Xt(Xt({},n),{ok:o,inserted:r})];throw new Error(Kt)}}))}))},t.prototype.get=function(){return te(this,void 0,void 0,(function(){var t,e;return ee(this,(function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.getInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,{data:"null"!==e.data?M.formatField(Mt.EJSON.parse(e.data)):Mt.EJSON.parse(e.data),requestId:e.requestId}]}}))}))},t.prototype.set=function(t){return te(this,void 0,void 0,(function(){var e,n;return ee(this,(function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:Mt.EJSON.stringify(Ot(t),{relaxed:!1}),upsert:!0},[4,this._request.send(ne,e)];case 1:if((n=r.sent()).code)throw n;return[2,Xt(Xt({},n),{updated:Mt.EJSON.parse(n.updated),upserted:n.upserted?JSON.parse(n.upserted):null})]}}))}))},t.prototype.update=function(t){return te(this,void 0,void 0,(function(){var e,n;return ee(this,(function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:Mt.EJSON.stringify(Ut.encode(t),{relaxed:!1})},[4,this._request.send(ne,e)];case 1:if((n=r.sent()).code)throw n;return[2,Xt(Xt({},n),{updated:Mt.EJSON.parse(n.updated)})]}}))}))},t.prototype.delete=function(){return te(this,void 0,void 0,(function(){var t,e;return ee(this,(function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.deleteDocInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,Xt(Xt({},e),{deleted:Mt.EJSON.parse(e.deleted)})]}}))}))},t}(),oe=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)}}(),ie=function(t){function e(e,n){return t.call(this,e,n)||this}return oe(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 re(this._transaction,this._coll,t)},e.prototype.add=function(t){var e;return void 0!==t._id&&(e=t._id),new re(this._transaction,this._coll,e).create(t)},e}((function(t,e){this._coll=e,this._transaction=t})),se=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())}))},ae=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])}}},ue=function(){function t(t){this._db=t,this._request=le.createRequest(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return t.prototype.init=function(){return se(this,void 0,void 0,(function(){var t;return ae(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 ie(this,t)},t.prototype.getTransactionId=function(){return this._id},t.prototype.getRequestMethod=function(){return this._request},t.prototype.commit=function(){return se(this,void 0,void 0,(function(){var t,e;return ae(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 se(this,void 0,void 0,(function(){var e,n;return ae(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 ce(){return se(this,void 0,void 0,(function(){var t;return ae(this,(function(e){switch(e.label){case 0:return[4,(t=new ue(this)).init()];case 1:return e.sent(),[2,t]}}))}))}function fe(t,e){return void 0===e&&(e=3),se(this,void 0,void 0,(function(){var n,r,o,i,s=this;return ae(this,(function(a){switch(a.label){case 0:return a.trys.push([0,4,,10]),[4,(n=new ue(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 se(s,void 0,void 0,(function(){return ae(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===Qt?[4,fe.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 le=function(){function t(t){this.config=t,this.Geo=i,this.serverDate=q,this.command=Ht,this.RegExp=Zt,this.startTransaction=ce,this.runTransaction=fe,this.logicCommand=ct,this.updateCommand=at,this.queryCommand=dt}return t.createRequest=function(e){var n=new t.reqClass(e),r=n.send;return n.send=function(t,n){return e.instance&&(n.instance=e.instance),e.database&&(n.database=e.database),r.call(this,t,n)},n},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new zt(this,t)},t.prototype.createCollection=function(e){var n={collectionName:e};return t.createRequest(this.config).send("database.addCollection",n)},t}()},249:(t,e,n)=>{n.r(e),n.d(e,{BSON:()=>Ge,BSONError:()=>J,BSONOffsetError:()=>z,BSONRegExp:()=>Zt,BSONRuntimeError:()=>V,BSONSymbol:()=>Kt,BSONType:()=>M,BSONValue:()=>st,BSONVersionError:()=>k,Binary:()=>lt,ByteUtils:()=>ot,Code:()=>gt,DBRef:()=>bt,Decimal128:()=>Ft,Double:()=>Mt,EJSON:()=>De,Int32:()=>Jt,Long:()=>Tt,MaxKey:()=>kt,MinKey:()=>Vt,NumberUtils:()=>ft,ObjectId:()=>Yt,Timestamp:()=>Xt,UUID:()=>yt,bsonType:()=>it,calculateObjectSize:()=>He,deserialize:()=>ze,deserializeStream:()=>Ye,onDemand:()=>Ce,serialize:()=>ke,serializeWithBufferAndIndex:()=>Ve,setInternalBufferSize:()=>Je});const r=(()=>{const t=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),Symbol.toStringTag).get;return e=>t.call(e)})();function o(t){return"Uint8Array"===r(t)}function i(t){return"object"==typeof t&&null!=t&&Symbol.toStringTag in t&&("ArrayBuffer"===t[Symbol.toStringTag]||"SharedArrayBuffer"===t[Symbol.toStringTag])}function s(t){return t instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(t)}function a(t){return"object"==typeof t&&null!=t&&Symbol.toStringTag in t&&"Map"===t[Symbol.toStringTag]}function u(t){return t instanceof Date||"[object Date]"===Object.prototype.toString.call(t)}function c(t,e){return JSON.stringify(t,((t,e)=>"bigint"==typeof e?{$numberLong:`${e}`}:a(e)?Object.fromEntries(e):e))}const f=7,l=Symbol.for("@@mdb.bson.version"),h=2147483647,d=-2147483648,p=Math.pow(2,63)-1,y=-Math.pow(2,63),g=Math.pow(2,53),m=-Math.pow(2,53),b=1,w=2,v=3,_=4,O=5,S=6,E=7,N=8,I=9,T=10,B=11,x=12,L=13,$=14,U=15,A=16,j=17,P=18,D=19,R=255,q=127,C=0,F=4,M=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 J 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 k extends J{get name(){return"BSONVersionError"}constructor(){super(`Unsupported BSON version, bson types must be from bson ${f}.x.x`)}}class V extends J{get name(){return"BSONRuntimeError"}constructor(t){super(t)}}class z extends J{get name(){return"BSONOffsetError"}offset;constructor(t,e,n){super(`${t}. offset: ${e}`,n),this.offset=e}}let H,Y;function G(t,e,n,r){if(r){H??=new TextDecoder("utf8",{fatal:!0});try{return H.decode(t.subarray(e,n))}catch(t){throw new J("Invalid UTF-8 string in BSON document",{cause:t})}}return Y??=new TextDecoder("utf8",{fatal:!1}),Y.decode(t.subarray(e,n))}function W(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)}function Z(t){return X.fromNumberArray(Array.from({length:t},(()=>Math.floor(256*Math.random()))))}function K(t){return crypto.getRandomValues(X.allocate(t))}const Q=(()=>{const{crypto:t}=globalThis;return null!=t&&"function"==typeof t.getRandomValues?K:Z})(),X={isUint8Array:o,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 J("Cannot create Buffer from the passed potentialBuffer.")},allocate:t=>Buffer.alloc(t),allocateUnsafe:t=>Buffer.allocUnsafe(t),compare:(t,e)=>X.toLocalBufferType(t).compare(e),concat:t=>Buffer.concat(t),equals:(t,e)=>X.toLocalBufferType(t).equals(e),fromNumberArray:t=>Buffer.from(t),fromBase64:t=>Buffer.from(t,"base64"),fromUTF8:t=>Buffer.from(t,"utf8"),toBase64:t=>X.toLocalBufferType(t).toString("base64"),fromISO88591:t=>Buffer.from(t,"binary"),toISO88591:t=>X.toLocalBufferType(t).toString("binary"),fromHex:t=>Buffer.from(t,"hex"),toHex:t=>X.toLocalBufferType(t).toString("hex"),toUTF8(t,e,n,r){const o=n-e<=20?W(t,e,n):null;if(null!=o)return o;const i=X.toLocalBufferType(t).toString("utf8",e,n);if(r)for(let r=0;r<i.length;r++)if(65533===i.charCodeAt(r)){G(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:X.toLocalBufferType(t).write(e,n,void 0,"utf8")},randomBytes:Q,swap32:t=>X.toLocalBufferType(t).swap32()};function tt(t){if(t<0)throw new RangeError(`The argument 'byteLength' is invalid. Received ${t}`);return rt.fromNumberArray(Array.from({length:t},(()=>Math.floor(256*Math.random()))))}const et=(()=>{const{crypto:t}=globalThis;if(null!=t&&"function"==typeof t.getRandomValues)return e=>t.getRandomValues(rt.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 tt})(),nt=/(\d|[a-f])/i,rt={isUint8Array:o,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 J("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=>rt.allocate(t),compare(t,e){if(t===e)return 0;const n=Math.min(t.length,e.length);for(let r=0;r<n;r++){if(t[r]<e[r])return-1;if(t[r]>e[r])return 1}return t.length<e.length?-1:t.length>e.length?1:0},concat(t){if(0===t.length)return rt.allocate(0);let e=0;for(const n of t)e+=n.length;const n=rt.allocate(e);let r=0;for(const e of t)n.set(e,r),r+=e.length;return n},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))),fromUTF8:t=>(new TextEncoder).encode(t),toBase64:t=>btoa(rt.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(!nt.test(r))break;if(!nt.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?W(t,e,n):null;return null!=o?o:G(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:et,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}},ot="function"==typeof Buffer&&!0!==Buffer.prototype?._isBuffer?X:rt,it=Symbol.for("@@mdb.bson.type");class st{get[it](){return this._bsontype}get[l](){return f}[Symbol.for("nodejs.util.inspect.custom")](t,e,n){return this.inspect(t,e,n)}}const at=new Float64Array(1),ut=new Uint8Array(at.buffer,0,8);at[0]=-1;const ct=0===ut[7],ft={isBigEndian:ct,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)=>(BigInt(t[e+4]+256*t[e+5]+65536*t[e+6]+(t[e+7]<<24))<<32n)+BigInt(t[e]+256*t[e+1]+65536*t[e+2]+16777216*t[e+3]),getFloat64LE:ct?(t,e)=>(ut[7]=t[e],ut[6]=t[e+1],ut[5]=t[e+2],ut[4]=t[e+3],ut[3]=t[e+4],ut[2]=t[e+5],ut[1]=t[e+6],ut[0]=t[e+7],at[0]):(t,e)=>(ut[0]=t[e],ut[1]=t[e+1],ut[2]=t[e+2],ut[3]=t[e+3],ut[4]=t[e+4],ut[5]=t[e+5],ut[6]=t[e+6],ut[7]=t[e+7],at[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=0xffffffffn;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>>32n&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:ct?(t,e,n)=>(at[0]=n,t[e]=ut[7],t[e+1]=ut[6],t[e+2]=ut[5],t[e+3]=ut[4],t[e+4]=ut[3],t[e+5]=ut[2],t[e+6]=ut[1],t[e+7]=ut[0],8):(t,e,n)=>(at[0]=n,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7],8)};class lt extends st{get _bsontype(){return"Binary"}static BSON_BINARY_SUBTYPE_DEFAULT=0;static BUFFER_SIZE=256;static SUBTYPE_DEFAULT=0;static SUBTYPE_FUNCTION=1;static SUBTYPE_BYTE_ARRAY=2;static SUBTYPE_UUID_OLD=3;static SUBTYPE_UUID=4;static SUBTYPE_MD5=5;static SUBTYPE_ENCRYPTED=6;static SUBTYPE_COLUMN=7;static SUBTYPE_SENSITIVE=8;static SUBTYPE_VECTOR=9;static SUBTYPE_USER_DEFINED=128;static VECTOR_TYPE=Object.freeze({Int8:3,Float32:39,PackedBit:16});buffer;sub_type;position;constructor(t,e){if(super(),null!=t&&"string"==typeof t&&!ArrayBuffer.isView(t)&&!i(t)&&!Array.isArray(t))throw new J("Binary can only be constructed from Uint8Array or number[]");this.sub_type=e??lt.BSON_BINARY_SUBTYPE_DEFAULT,null==t?(this.buffer=ot.allocate(lt.BUFFER_SIZE),this.position=0):(this.buffer=Array.isArray(t)?ot.fromNumberArray(t):ot.toLocalBufferType(t),this.position=this.buffer.byteLength)}put(t){if("string"==typeof t&&1!==t.length)throw new J("only accepts single character String");if("number"!=typeof t&&1!==t.length)throw new J("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 J("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=ot.allocate(lt.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=ot.allocate(this.buffer.byteLength+t.length);e.set(this.buffer,0),this.buffer=e}if(ArrayBuffer.isView(t))this.buffer.set(ot.toLocalBufferType(t),e),this.position=e+t.byteLength>this.position?e+t.length:this.position;else if("string"==typeof t)throw new J("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 ot.toBase64(this.buffer.subarray(0,this.position))}toString(t){return"hex"===t?ot.toHex(this.buffer.subarray(0,this.position)):"base64"===t?ot.toBase64(this.buffer.subarray(0,this.position)):ot.toUTF8(this.buffer,0,this.position,!1)}toExtendedJSON(t){t=t||{},this.sub_type===lt.SUBTYPE_VECTOR&&ht(this);const e=ot.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===lt.SUBTYPE_UUID)return new yt(this.buffer.subarray(0,this.position));throw new J(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${lt.SUBTYPE_UUID}" is currently supported.`)}static createFromHexString(t,e){return new lt(ot.fromHex(t),e)}static createFromBase64(t,e){return new lt(ot.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=ot.fromBase64(t.$binary)):"string"!=typeof t.$binary&&(r=t.$binary.subType?parseInt(t.$binary.subType,16):0,n=ot.fromBase64(t.$binary.base64)):"$uuid"in t&&(r=4,n=yt.bytesFromString(t.$uuid)),!n)throw new J(`Unexpected Binary Extended JSON format ${JSON.stringify(t)}`);return r===F?new yt(n):new lt(n,r)}inspect(t,e,n){return n??=c,`Binary.createFromBase64(${n(ot.toBase64(this.buffer.subarray(0,this.position)),e)}, ${n(this.sub_type,e)})`}toInt8Array(){if(this.sub_type!==lt.SUBTYPE_VECTOR)throw new J("Binary sub_type is not Vector");if(this.buffer[0]!==lt.VECTOR_TYPE.Int8)throw new J("Binary datatype field is not Int8");return ht(this),new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toFloat32Array(){if(this.sub_type!==lt.SUBTYPE_VECTOR)throw new J("Binary sub_type is not Vector");if(this.buffer[0]!==lt.VECTOR_TYPE.Float32)throw new J("Binary datatype field is not Float32");ht(this);const t=new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position));return ft.isBigEndian&&ot.swap32(t),new Float32Array(t.buffer)}toPackedBits(){if(this.sub_type!==lt.SUBTYPE_VECTOR)throw new J("Binary sub_type is not Vector");if(this.buffer[0]!==lt.VECTOR_TYPE.PackedBit)throw new J("Binary datatype field is not packed bit");return ht(this),new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toBits(){if(this.sub_type!==lt.SUBTYPE_VECTOR)throw new J("Binary sub_type is not Vector");if(this.buffer[0]!==lt.VECTOR_TYPE.PackedBit)throw new J("Binary datatype field is not packed bit");ht(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=ot.allocate(t.byteLength+2);e[0]=lt.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 ht(r),r}static fromFloat32Array(t){const e=ot.allocate(t.byteLength+2);e[0]=lt.VECTOR_TYPE.Float32,e[1]=0;const n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);e.set(n,2),ft.isBigEndian&&ot.swap32(new Uint8Array(e.buffer,2));const r=new this(e,this.SUBTYPE_VECTOR);return ht(r),r}static fromPackedBits(t,e=0){const n=ot.allocate(t.byteLength+2);n[0]=lt.VECTOR_TYPE.PackedBit,n[1]=e,n.set(t,2);const r=new this(n,this.SUBTYPE_VECTOR);return ht(r),r}static fromBits(t){const e=t.length+7>>>3,n=new Uint8Array(e+2);n[0]=lt.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 J(`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,lt.SUBTYPE_VECTOR)}}function ht(t){if(t.sub_type!==lt.SUBTYPE_VECTOR)return;const e=t.position,n=t.buffer[0],r=t.buffer[1];if((n===lt.VECTOR_TYPE.Float32||n===lt.VECTOR_TYPE.Int8)&&0!==r)throw new J("Invalid Vector: padding must be zero for int8 and float32 vectors");if(n===lt.VECTOR_TYPE.Float32&&0!==e&&e-2!=0&&(e-2)%4!=0)throw new J("Invalid Vector: Float32 vector must contain a multiple of 4 bytes");if(n===lt.VECTOR_TYPE.PackedBit&&0!==r&&2===e)throw new J("Invalid Vector: padding must be zero for packed bit vectors that are empty");if(n===lt.VECTOR_TYPE.PackedBit&&r>7)throw new J(`Invalid Vector: padding must be a value between 0 and 7. found: ${r}`)}const dt=/^[0-9A-F]{32}$/i,pt=/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;class yt extends lt{constructor(t){let e;if(null==t)e=yt.generate();else if(t instanceof yt)e=ot.toLocalBufferType(new Uint8Array(t.buffer));else if(ArrayBuffer.isView(t)&&16===t.byteLength)e=ot.toLocalBufferType(t);else{if("string"!=typeof t)throw new J("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=yt.bytesFromString(t)}super(e,F)}get id(){return this.buffer}set id(t){this.buffer=t}toHexString(t=!0){return t?[ot.toHex(this.buffer.subarray(0,4)),ot.toHex(this.buffer.subarray(4,6)),ot.toHex(this.buffer.subarray(6,8)),ot.toHex(this.buffer.subarray(8,10)),ot.toHex(this.buffer.subarray(10,16))].join("-"):ot.toHex(this.buffer)}toString(t){return"hex"===t?ot.toHex(this.id):"base64"===t?ot.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(t){if(!t)return!1;if(t instanceof yt)return ot.equals(t.id,this.id);try{return ot.equals(new yt(t).id,this.id)}catch{return!1}}toBinary(){return new lt(this.id,lt.SUBTYPE_UUID)}static generate(){const t=ot.randomBytes(16);return t[6]=15&t[6]|64,t[8]=63&t[8]|128,t}static isValid(t){return!!t&&("string"==typeof t?yt.isValidUUIDString(t):o(t)?16===t.byteLength:"Binary"===t._bsontype&&t.sub_type===this.SUBTYPE_UUID&&16===t.buffer.byteLength)}static createFromHexString(t){const e=yt.bytesFromString(t);return new yt(e)}static createFromBase64(t){return new yt(ot.fromBase64(t))}static bytesFromString(t){if(!yt.isValidUUIDString(t))throw new J("UUID string representation must be 32 hex digits or canonical hyphenated representation");return ot.fromHex(t.replace(/-/g,""))}static isValidUUIDString(t){return dt.test(t)||pt.test(t)}inspect(t,e,n){return n??=c,`new UUID(${n(this.toHexString(),e)})`}}class gt extends st{get _bsontype(){return"Code"}code;scope;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 gt(t.$code,t.$scope)}inspect(t,e,n){n??=c;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 mt(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 bt extends st{get _bsontype(){return"DBRef"}collection;oid;db;fields;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 bt(t.$ref,t.$id,t.$db,e)}inspect(t,e,n){n??=c;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===c?`new ObjectId(${r[1]})`:r[1],`new DBRef(${r.join(", ")})`}}function wt(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 vt;try{vt=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 _t=4294967296,Ot=0x10000000000000000,St=Ot/2,Et={},Nt={},It=/^(\+?0|(\+|-)?[1-9][0-9]*)$/;class Tt extends st{get _bsontype(){return"Long"}get __isLong__(){return!0}high;low;unsigned;constructor(t=0,e,n){super();const r="boolean"==typeof e?e:Boolean(n),o="number"==typeof e?e:0,i="string"==typeof t?Tt.fromString(t,r):"bigint"==typeof t?Tt.fromBigInt(t,r):{low:0|t,high:0|o,unsigned:r};this.low=i.low,this.high=i.high,this.unsigned=i.unsigned}static TWO_PWR_24=Tt.fromInt(16777216);static MAX_UNSIGNED_VALUE=Tt.fromBits(-1,-1,!0);static ZERO=Tt.fromInt(0);static UZERO=Tt.fromInt(0,!0);static ONE=Tt.fromInt(1);static UONE=Tt.fromInt(1,!0);static NEG_ONE=Tt.fromInt(-1);static MAX_VALUE=Tt.fromBits(-1,2147483647,!1);static MIN_VALUE=Tt.fromBits(0,-2147483648,!1);static fromBits(t,e,n){return new Tt(t,e,n)}static fromInt(t,e){let n,r,o;return e?(o=0<=(t>>>=0)&&t<256)&&(r=Nt[t],r)?r:(n=Tt.fromBits(t,(0|t)<0?-1:0,!0),o&&(Nt[t]=n),n):(o=-128<=(t|=0)&&t<128)&&(r=Et[t],r)?r:(n=Tt.fromBits(t,t<0?-1:0,!1),o&&(Et[t]=n),n)}static fromNumber(t,e){if(isNaN(t))return e?Tt.UZERO:Tt.ZERO;if(e){if(t<0)return Tt.UZERO;if(t>=Ot)return Tt.MAX_UNSIGNED_VALUE}else{if(t<=-St)return Tt.MIN_VALUE;if(t+1>=St)return Tt.MAX_VALUE}return t<0?Tt.fromNumber(-t,e).neg():Tt.fromBits(t%_t|0,t/_t|0,e)}static fromBigInt(t,e){const n=0xffffffffn;return new Tt(Number(t&n),Number(t>>32n&n),e)}static _fromString(t,e,n){if(0===t.length)throw new J("empty string");if(n<2||36<n)throw new J("radix");let r;if((r=t.indexOf("-"))>0)throw new J("interior hyphen");if(0===r)return Tt._fromString(t.substring(1),e,n).neg();const o=Tt.fromNumber(Math.pow(n,8));let i=Tt.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=Tt.fromNumber(Math.pow(n,r));i=i.mul(t).add(Tt.fromNumber(s))}else i=i.mul(o),i=i.add(Tt.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 J(`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 J(`Input: '${t}' contains invalid characters for radix: ${n}`);const o=wt(t),i=Tt._fromString(o,r,n);if(i.toString(n).toLowerCase()!==o.toLowerCase())throw new J(`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?Tt.ZERO:Tt._fromString(t,r,n)}static fromBytes(t,e,n){return n?Tt.fromBytesLE(t,e):Tt.fromBytesBE(t,e)}static fromBytesLE(t,e){return new Tt(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 Tt(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?Tt.fromNumber(t,e):"string"==typeof t?Tt.fromString(t,e):Tt.fromBits(t.low,t.high,"boolean"==typeof e?e:t.unsigned)}add(t){Tt.isLong(t)||(t=Tt.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,Tt.fromBits(f<<16|l,u<<16|c,this.unsigned)}and(t){return Tt.isLong(t)||(t=Tt.fromValue(t)),Tt.fromBits(this.low&t.low,this.high&t.high,this.unsigned)}compare(t){if(Tt.isLong(t)||(t=Tt.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(Tt.isLong(t)||(t=Tt.fromValue(t)),t.isZero())throw new J("division by zero");if(vt){if(!this.unsigned&&-2147483648===this.high&&-1===t.low&&-1===t.high)return this;const e=(this.unsigned?vt.div_u:vt.div_s)(this.low,this.high,t.low,t.high);return Tt.fromBits(e,vt.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?Tt.UZERO:Tt.ZERO;let e,n,r;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return Tt.UZERO;if(t.gt(this.shru(1)))return Tt.UONE;r=Tt.UZERO}else{if(this.eq(Tt.MIN_VALUE))return t.eq(Tt.ONE)||t.eq(Tt.NEG_ONE)?Tt.MIN_VALUE:t.eq(Tt.MIN_VALUE)?Tt.ONE:(e=this.shr(1).div(t).shl(1),e.eq(Tt.ZERO)?t.isNegative()?Tt.ONE:Tt.NEG_ONE:(n=this.sub(t.mul(e)),r=e.add(n.div(t)),r));if(t.eq(Tt.MIN_VALUE))return this.unsigned?Tt.UZERO:Tt.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=Tt.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=Tt.fromNumber(e),a=s.mul(t);for(;a.isNegative()||a.gt(n);)e-=i,s=Tt.fromNumber(e,this.unsigned),a=s.mul(t);s.isZero()&&(s=Tt.ONE),r=r.add(s),n=n.sub(a)}return r}div(t){return this.divide(t)}equals(t){return Tt.isLong(t)||(t=Tt.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(Tt.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(Tt.isLong(t)||(t=Tt.fromValue(t)),vt){const e=(this.unsigned?vt.rem_u:vt.rem_s)(this.low,this.high,t.low,t.high);return Tt.fromBits(e,vt.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 Tt.ZERO;if(Tt.isLong(t)||(t=Tt.fromValue(t)),vt){const e=vt.mul(this.low,this.high,t.low,t.high);return Tt.fromBits(e,vt.get_high(),this.unsigned)}if(t.isZero())return Tt.ZERO;if(this.eq(Tt.MIN_VALUE))return t.isOdd()?Tt.MIN_VALUE:Tt.ZERO;if(t.eq(Tt.MIN_VALUE))return this.isOdd()?Tt.MIN_VALUE:Tt.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(Tt.TWO_PWR_24)&&t.lt(Tt.TWO_PWR_24))return Tt.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,h=0;return h+=o*u,l+=h>>>16,h&=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,Tt.fromBits(l<<16|h,c<<16|f,this.unsigned)}mul(t){return this.multiply(t)}negate(){return!this.unsigned&&this.eq(Tt.MIN_VALUE)?Tt.MIN_VALUE:this.not().add(Tt.ONE)}neg(){return this.negate()}not(){return Tt.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 Tt.isLong(t)||(t=Tt.fromValue(t)),Tt.fromBits(this.low|t.low,this.high|t.high,this.unsigned)}shiftLeft(t){return Tt.isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?Tt.fromBits(this.low<<t,this.high<<t|this.low>>>32-t,this.unsigned):Tt.fromBits(0,this.low<<t-32,this.unsigned)}shl(t){return this.shiftLeft(t)}shiftRight(t){return Tt.isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?Tt.fromBits(this.low>>>t|this.high<<32-t,this.high>>t,this.unsigned):Tt.fromBits(this.high>>t-32,this.high>=0?0:-1,this.unsigned)}shr(t){return this.shiftRight(t)}shiftRightUnsigned(t){if(Tt.isLong(t)&&(t=t.toInt()),0==(t&=63))return this;{const e=this.high;if(t<32){const n=this.low;return Tt.fromBits(n>>>t|e<<32-t,e>>>t,this.unsigned)}return 32===t?Tt.fromBits(e,0,this.unsigned):Tt.fromBits(e>>>t-32,0,this.unsigned)}}shr_u(t){return this.shiftRightUnsigned(t)}shru(t){return this.shiftRightUnsigned(t)}subtract(t){return Tt.isLong(t)||(t=Tt.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)*_t+(this.low>>>0):this.high*_t+(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?Tt.fromBits(this.low,this.high,!1):this}toString(t){if((t=t||10)<2||36<t)throw new J("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(Tt.MIN_VALUE)){const e=Tt.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=Tt.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:Tt.fromBits(this.low,this.high,!0)}xor(t){return Tt.isLong(t)||(t=Tt.fromValue(t)),Tt.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 J("$numberLong string is too long");if(!It.test(t.$numberLong))throw new J(`$numberLong string "${t.$numberLong}" is in an invalid format`);if(n){const e=BigInt(t.$numberLong);return BigInt.asIntN(64,e)}const o=Tt.fromString(t.$numberLong);return r?o.toNumber():o}inspect(t,e,n){return n??=c,`new Long(${n(this.toString(),e)}${this.unsigned?`, ${n(this.unsigned,e)}`:""})`}}const Bt=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,xt=/^(\+|-)?(Infinity|inf)$/i,Lt=/^(\+|-)?NaN$/i,$t=6111,Ut=-6176,At=ot.fromNumberArray([124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),jt=ot.fromNumberArray([248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Pt=ot.fromNumberArray([120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Dt=/^([-+])?(\d+)?$/;function Rt(t){return!isNaN(parseInt(t,10))}function qt(t){const e=Tt.fromNumber(1e9);let n=Tt.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 Tt(t.parts[r],0)),t.parts[r]=n.div(e).low,n=n.modulo(e);return{quotient:t,rem:n}}function Ct(t,e){throw new J(`"${t}" is not a valid Decimal128 string - ${e}`)}class Ft extends st{get _bsontype(){return"Decimal128"}bytes;constructor(t){if(super(),"string"==typeof t)this.bytes=Ft.fromString(t).bytes;else{if(!(t instanceof Uint8Array||o(t)))throw new J("Decimal128 must take a Buffer or string");if(16!==t.byteLength)throw new J("Decimal128 must take a Buffer of 16 bytes");this.bytes=t}}static fromString(t){return Ft._fromString(t,{allowRounding:!1})}static fromStringWithRounding(t){return Ft._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 h=0,d=0,p=0,y=0,g=new Tt(0,0),m=new Tt(0,0),b=0,w=0;if(t.length>=7e3)throw new J(t+" not a valid Decimal128 string");const v=t.match(Bt),_=t.match(xt),O=t.match(Lt);if(!v&&!_&&!O||0===t.length)throw new J(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&&Ct(t,"missing exponent power"),n&&void 0===e&&Ct(t,"missing exponent base"),void 0===n&&(r||o)&&Ct(t,"missing e before exponent")}if("+"!==t[w]&&"-"!==t[w]||(r=!0,n="-"===t[w++]),!Rt(t[w])&&"."!==t[w]){if("i"===t[w]||"I"===t[w])return new Ft(n?jt:Pt);if("N"===t[w])return new Ft(At)}for(;Rt(t[w])||"."===t[w];)"."!==t[w]?(h<34&&("0"!==t[w]||i)&&(i||(f=a),i=!0,l[d++]=parseInt(t[w],10),h+=1),i&&(u+=1),o&&(c+=1),a+=1,w+=1):(o&&Ct(t,"contains multiple periods"),o=!0,w+=1);if(o&&!a)throw new J(t+" not a valid Decimal128 string");if("e"===t[w]||"E"===t[w]){const e=t.substr(++w).match(Dt);if(!e||!e[2])return new Ft(At);y=parseInt(e[0],10),w+=e[0].length}if(t[w])return new Ft(At);if(h){if(p=h-1,s=u,1!==s)for(;"0"===t[f+s-1+Number(r)+Number(o)];)s-=1}else l[0]=0,u=1,h=1,s=0;for(y<=c&&c>y+16384?y=Ut:y-=c;y>$t;){if(p+=1,p>=34){if(0===s){y=$t;break}Ct(t,"overflow")}y-=1}if(e.allowRounding){for(;y<Ut||h<u;){if(0===p&&s<h){y=Ut,s=0;break}if(h<u?u-=1:p-=1,y<$t)y+=1;else{if(l.join("").match(/^0+$/)){y=$t;break}Ct(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<$t))return new Ft(n?jt:Pt);y+=1,l[t]=1}}}}else{for(;y<Ut||h<u;){if(0===p){if(0===s){y=Ut;break}Ct(t,"exponent underflow")}h<u?("0"!==t[u-1+Number(r)+Number(o)]&&0!==s&&Ct(t,"inexact rounding"),u-=1):(0!==l[p]&&Ct(t,"inexact rounding"),p-=1),y<$t?y+=1:Ct(t,"overflow")}p+1<s&&(o&&(f+=1),r&&(f+=1),0!==parseInt(t[f+p+1],10)&&Ct(t,"inexact rounding"))}if(g=Tt.fromNumber(0),m=Tt.fromNumber(0),0===s)g=Tt.fromNumber(0),m=Tt.fromNumber(0);else if(p<17){let t=0;for(m=Tt.fromNumber(l[t++]),g=new Tt(0,0);t<=p;t++)m=m.multiply(Tt.fromNumber(10)),m=m.add(Tt.fromNumber(l[t]))}else{let t=0;for(g=Tt.fromNumber(l[t++]);t<=p-17;t++)g=g.multiply(Tt.fromNumber(10)),g=g.add(Tt.fromNumber(l[t]));for(m=Tt.fromNumber(l[t++]);t<=p;t++)m=m.multiply(Tt.fromNumber(10)),m=m.add(Tt.fromNumber(l[t]))}const S=function(t,e){if(!t&&!e)return{high:Tt.fromNumber(0),low:Tt.fromNumber(0)};const n=t.shiftRightUnsigned(32),r=new Tt(t.getLowBits(),0),o=e.shiftRightUnsigned(32),i=new Tt(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 Tt(a.getLowBits(),0).add(u).add(c.shiftRightUnsigned(32)),s=s.add(a.shiftRightUnsigned(32)),c=a.shiftLeft(32).add(new Tt(c.getLowBits(),0)),{high:s,low:c}}(g,Tt.fromString("100000000000000000"));S.low=S.low.add(m),function(t,e){const n=t.high>>>0,r=e.high>>>0;return n<r||n===r&&t.low>>>0<e.low>>>0}(S.low,m)&&(S.high=S.high.add(Tt.fromNumber(1))),b=y+6176;const E={low:Tt.fromNumber(0),high:Tt.fromNumber(0)};S.high.shiftRightUnsigned(49).and(Tt.fromNumber(1)).equals(Tt.fromNumber(1))?(E.high=E.high.or(Tt.fromNumber(3).shiftLeft(61)),E.high=E.high.or(Tt.fromNumber(b).and(Tt.fromNumber(16383).shiftLeft(47))),E.high=E.high.or(S.high.and(Tt.fromNumber(0x7fffffffffff)))):(E.high=E.high.or(Tt.fromNumber(16383&b).shiftLeft(49)),E.high=E.high.or(S.high.and(Tt.fromNumber(562949953421311)))),E.low=S.low,n&&(E.high=E.high.or(Tt.fromString("9223372036854775808")));const N=ot.allocateUnsafe(16);return w=0,N[w++]=255&E.low.low,N[w++]=E.low.low>>8&255,N[w++]=E.low.low>>16&255,N[w++]=E.low.low>>24&255,N[w++]=255&E.low.high,N[w++]=E.low.high>>8&255,N[w++]=E.low.high>>16&255,N[w++]=E.low.high>>24&255,N[w++]=255&E.high.low,N[w++]=E.high.low>>8&255,N[w++]=E.high.low>>16&255,N[w++]=E.high.low>>24&255,N[w++]=255&E.high.high,N[w++]=E.high.high>>8&255,N[w++]=E.high.high>>16&255,N[w++]=E.high.high>>24&255,new Ft(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,h=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,d=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 Tt(l,h),new Tt(d,p)).lessThan(Tt.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]=d,u.parts[2]=h,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=qt(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 m=e-1+g;if(m>=34||m<=-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"),m>0?c.push(`+${m}`):c.push(`${m}`)}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 Ft.fromString(t.$numberDecimal)}inspect(t,e,n){return n??=c,`new Decimal128(${n(this.toString(),e)})`}}class Mt extends st{get _bsontype(){return"Double"}value;constructor(t){super(),t instanceof Number&&(t=t.valueOf()),this.value=+t}static fromString(t){const e=Number(t);if("NaN"===t)return new Mt(NaN);if("Infinity"===t)return new Mt(1/0);if("-Infinity"===t)return new Mt(-1/0);if(!Number.isFinite(e))throw new J(`Input: ${t} is not representable as a Double`);if(t.trim()!==t)throw new J(`Input: '${t}' contains whitespace`);if(""===t)throw new J("Input is an empty string");if(/[^-0-9.+eE]/.test(t))throw new J(`Input: '${t}' is not in decimal or exponential notation`);return new Mt(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 Mt(n)}inspect(t,e,n){return n??=c,`new Double(${n(this.value,e)})`}}class Jt extends st{get _bsontype(){return"Int32"}value;constructor(t){super(),t instanceof Number&&(t=t.valueOf()),this.value=0|+t}static fromString(t){const e=wt(t),n=Number(t);if(h<n)throw new J(`Input: '${t}' is larger than the maximum value for Int32`);if(d>n)throw new J(`Input: '${t}' is smaller than the minimum value for Int32`);if(!Number.isSafeInteger(n))throw new J(`Input: '${t}' is not a safe integer`);if(n.toString()!==e)throw new J(`Input: '${t}' is not a valid Int32 string`);return new Jt(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 Jt(t.$numberInt)}inspect(t,e,n){return n??=c,`new Int32(${n(this.value,e)})`}}class kt extends st{get _bsontype(){return"MaxKey"}toExtendedJSON(){return{$maxKey:1}}static fromExtendedJSON(){return new kt}inspect(){return"new MaxKey()"}}class Vt extends st{get _bsontype(){return"MinKey"}toExtendedJSON(){return{$minKey:1}}static fromExtendedJSON(){return new Vt}inspect(){return"new MinKey()"}}let zt=null;const Ht=new WeakMap;class Yt extends st{get _bsontype(){return"ObjectId"}static index=Math.floor(16777215*Math.random());static cacheHexString;buffer;constructor(t){let e;if(super(),"object"==typeof t&&t&&"id"in t){if("string"!=typeof t.id&&!ArrayBuffer.isView(t.id))throw new J("Argument passed in must have an id that is of type string or Buffer");e="toHexString"in t&&"function"==typeof t.toHexString?ot.fromHex(t.toHexString()):t.id}else e=t;if(null==e)this.buffer=Yt.generate();else if(ArrayBuffer.isView(e)&&12===e.byteLength)this.buffer=ot.toLocalBufferType(e);else{if("string"!=typeof e)throw new J("Argument passed in does not match the accepted types");if(!Yt.validateHexString(e))throw new J("input must be a 24 character hex string, 12 byte Uint8Array, or an integer");this.buffer=ot.fromHex(e),Yt.cacheHexString&&Ht.set(this,e)}}get id(){return this.buffer}set id(t){this.buffer=t,Yt.cacheHexString&&Ht.set(this,ot.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(Yt.cacheHexString){const t=Ht.get(this);if(t)return t}const t=ot.toHex(this.id);return Yt.cacheHexString&&Ht.set(this,t),t}static getInc(){return Yt.index=(Yt.index+1)%16777215}static generate(t){"number"!=typeof t&&(t=Math.floor(Date.now()/1e3));const e=Yt.getInc(),n=ot.allocateUnsafe(12);return ft.setInt32BE(n,0,t),null===zt&&(zt=ot.randomBytes(5)),n[4]=zt[0],n[5]=zt[1],n[6]=zt[2],n[7]=zt[3],n[8]=zt[4],n[11]=255&e,n[10]=e>>8&255,n[9]=e>>16&255,n}toString(t){return"base64"===t?ot.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(Yt.is(t))return this.buffer[11]===t.buffer[11]&&ot.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=ft.getUint32BE(this.buffer,0);return t.setTime(1e3*Math.floor(e)),t}static createPk(){return new Yt}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=ot.allocate(12);for(let t=11;t>=4;t--)e[t]=0;return ft.setInt32BE(e,0,t),new Yt(e)}static createFromHexString(t){if(24!==t?.length)throw new J("hex string must be 24 characters");return new Yt(ot.fromHex(t))}static createFromBase64(t){if(16!==t?.length)throw new J("base64 string must be 16 characters");return new Yt(ot.fromBase64(t))}static isValid(t){if(null==t)return!1;if("string"==typeof t)return Yt.validateHexString(t);try{return new Yt(t),!0}catch{return!1}}toExtendedJSON(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}}static fromExtendedJSON(t){return new Yt(t.$oid)}isCached(){return Yt.cacheHexString&&Ht.has(this)}inspect(t,e,n){return n??=c,`new ObjectId(${n(this.toHexString(),e)})`}}function Gt(t,e,n){let r=5;if(Array.isArray(t))for(let o=0;o<t.length;o++)r+=Wt(o.toString(),t[o],e,!0,n);else{"function"==typeof t?.toBSON&&(t=t.toBSON());for(const o of Object.keys(t))r+=Wt(o,t[o],e,!1,n)}return r}function Wt(t,e,n=!1,r=!1,o=!1){switch("function"==typeof e?.toBSON&&(e=e.toBSON()),typeof e){case"string":return 1+ot.utf8ByteLength(t)+1+4+ot.utf8ByteLength(e)+1;case"number":return Math.floor(e)===e&&e>=m&&e<=g&&e>=d&&e<=h?(null!=t?ot.utf8ByteLength(t)+1:0)+5:(null!=t?ot.utf8ByteLength(t)+1:0)+9;case"undefined":return r||!o?(null!=t?ot.utf8ByteLength(t)+1:0)+1:0;case"boolean":return(null!=t?ot.utf8ByteLength(t)+1:0)+2;case"object":if(null!=e&&"string"==typeof e._bsontype&&e[l]!==f)throw new k;if(null==e||"MinKey"===e._bsontype||"MaxKey"===e._bsontype)return(null!=t?ot.utf8ByteLength(t)+1:0)+1;if("ObjectId"===e._bsontype)return(null!=t?ot.utf8ByteLength(t)+1:0)+13;if(e instanceof Date||u(e))return(null!=t?ot.utf8ByteLength(t)+1:0)+9;if(ArrayBuffer.isView(e)||e instanceof ArrayBuffer||i(e))return(null!=t?ot.utf8ByteLength(t)+1:0)+6+e.byteLength;if("Long"===e._bsontype||"Double"===e._bsontype||"Timestamp"===e._bsontype)return(null!=t?ot.utf8ByteLength(t)+1:0)+9;if("Decimal128"===e._bsontype)return(null!=t?ot.utf8ByteLength(t)+1:0)+17;if("Code"===e._bsontype)return null!=e.scope&&Object.keys(e.scope).length>0?(null!=t?ot.utf8ByteLength(t)+1:0)+1+4+4+ot.utf8ByteLength(e.code.toString())+1+Gt(e.scope,n,o):(null!=t?ot.utf8ByteLength(t)+1:0)+1+4+ot.utf8ByteLength(e.code.toString())+1;if("Binary"===e._bsontype){const n=e;return n.sub_type===lt.SUBTYPE_BYTE_ARRAY?(null!=t?ot.utf8ByteLength(t)+1:0)+(n.position+1+4+1+4):(null!=t?ot.utf8ByteLength(t)+1:0)+(n.position+1+4+1)}if("Symbol"===e._bsontype)return(null!=t?ot.utf8ByteLength(t)+1:0)+ot.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?ot.utf8ByteLength(t)+1:0)+1+Gt(r,n,o)}return e instanceof RegExp||s(e)?(null!=t?ot.utf8ByteLength(t)+1:0)+1+ot.utf8ByteLength(e.source)+1+(e.global?1:0)+(e.ignoreCase?1:0)+(e.multiline?1:0)+1:"BSONRegExp"===e._bsontype?(null!=t?ot.utf8ByteLength(t)+1:0)+1+ot.utf8ByteLength(e.pattern)+1+ot.utf8ByteLength(e.options)+1:(null!=t?ot.utf8ByteLength(t)+1:0)+Gt(e,n,o)+1;case"function":return n?(null!=t?ot.utf8ByteLength(t)+1:0)+1+4+ot.utf8ByteLength(e.toString())+1:0;case"bigint":return(null!=t?ot.utf8ByteLength(t)+1:0)+9;case"symbol":return 0;default:throw new J("Unrecognized JS type: "+typeof e)}}class Zt extends st{get _bsontype(){return"BSONRegExp"}pattern;options;constructor(t,e){if(super(),this.pattern=t,this.options=(e??"").split("").sort().join(""),-1!==this.pattern.indexOf("\0"))throw new J(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);if(-1!==this.options.indexOf("\0"))throw new J(`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 J(`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 J(`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??=c,`new BSONRegExp(${r(n(this.pattern),"regexp")}, ${r(n(this.options),"regexp")})`}}class Kt extends st{get _bsontype(){return"BSONSymbol"}value;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 Kt(t.$symbol)}inspect(t,e,n){return n??=c,`new BSONSymbol(${n(this.value,e)})`}}const Qt=Tt;class Xt extends Qt{get _bsontype(){return"Timestamp"}get[it](){return"Timestamp"}static MAX_VALUE=Tt.MAX_UNSIGNED_VALUE;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(Tt.isLong(t))super(t.low,t.high,!0);else{if("object"!=typeof t||!("t"in t)||!("i"in t))throw new J("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 J("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 J("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 J("Timestamp constructed from { t, i } must provide a positive t");if(n<0||Number.isNaN(n))throw new J("Timestamp constructed from { t, i } must provide a positive i");if(e>4294967295)throw new J("Timestamp constructed from { t, i } must provide t equal or less than uint32 max");if(n>4294967295)throw new J("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 Xt(Tt.fromInt(t,!0))}static fromNumber(t){return new Xt(Tt.fromNumber(t,!0))}static fromBits(t,e){return new Xt({i:t,t:e})}static fromString(t,e){return new Xt(Tt.fromString(t,!0,e))}toExtendedJSON(){return{$timestamp:{t:this.t,i:this.i}}}static fromExtendedJSON(t){const e=Tt.isLong(t.$timestamp.i)?t.$timestamp.i.getLowBitsUnsigned():t.$timestamp.i,n=Tt.isLong(t.$timestamp.t)?t.$timestamp.t.getLowBitsUnsigned():t.$timestamp.t;return new Xt({t:n,i:e})}inspect(t,e,n){return n??=c,`new Timestamp({ t: ${n(this.t,e)}, i: ${n(this.i,e)} })`}}const te=Tt.fromNumber(g),ee=Tt.fromNumber(m);function ne(t,e,n){const r=(e=null==e?{}:e)&&e.index?e.index:0,o=ft.getInt32LE(t,r);if(o<5)throw new J(`bson size must be >= 5, is ${o}`);if(e.allowObjectSmallerThanBufferSize&&t.length<o)throw new J(`buffer length ${t.length} must be >= bson size ${o}`);if(!e.allowObjectSmallerThanBufferSize&&t.length!==o)throw new J(`buffer length ${t.length} must === bson size ${o}`);if(o+r>t.byteLength)throw new J(`(bson size ${o} + options.index ${r} must be <= buffer length ${t.byteLength})`);if(0!==t[r+o-1])throw new J("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");return oe(t,r,e,n)}const re=/^\$ref$|^\$id$|^\$db$/;function oe(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 J("Must either request bigint or Long for int64 deserialization");if(f&&!u)throw new J("Must either request bigint or Long for int64 deserialization");let l,h,d=!0;const p=(null==n.validation?{utf8:!0}:n.validation).utf8;if("boolean"==typeof p)l=p;else{d=!1;const t=Object.keys(p).map((function(t){return p[t]}));if(0===t.length)throw new J("UTF-8 validation setting cannot be empty");if("boolean"!=typeof t[0])throw new J("Invalid UTF-8 validation option, must specify boolean values");if(l=t[0],!t.every((t=>t===l)))throw new J("Invalid UTF-8 validation option - keys must be all true or all false")}if(!d){h=new Set;for(const t of Object.keys(p))h.add(t)}const y=e;if(t.length<5)throw new J("corrupt bson message < 5 bytes long");const g=ft.getInt32LE(t,e);if(e+=4,g<5||g>t.length)throw new J("corrupt bson message");const m=r?[]:{};let C=0,M=!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 J("Bad BSON Document: illegal CString");const g=r?C++:ot.toUTF8(t,e,y,!1);let k,V=!0;if(V=d||h?.has(g)?l:!l,!1!==M&&"$"===g[0]&&(M=re.test(g)),e=y+1,p===w){const n=ft.getInt32LE(t,e);if(e+=4,n<=0||n>t.length-e||0!==t[e+n-1])throw new J("bad string length in bson");k=ot.toUTF8(t,e,e+n-1,V),e+=n}else if(p===E){const n=ot.allocateUnsafe(12);for(let r=0;r<12;r++)n[r]=t[e+r];k=new Yt(n),e+=12}else if(p===A&&!1===c)k=new Jt(ft.getInt32LE(t,e)),e+=4;else if(p===A)k=ft.getInt32LE(t,e),e+=4;else if(p===b)k=ft.getFloat64LE(t,e),e+=8,!1===c&&(k=new Mt(k));else if(p===I){const n=ft.getInt32LE(t,e),r=ft.getInt32LE(t,e+4);e+=8,k=new Date(new Tt(n,r).toNumber())}else if(p===N){if(0!==t[e]&&1!==t[e])throw new J("illegal boolean type value");k=1===t[e++]}else if(p===v){const r=e,o=ft.getInt32LE(t,e);if(o<=0||o>t.length-e)throw new J("bad embedded document length in bson");if(i)k=t.subarray(e,e+o);else{let e=n;d||(e={...n,validation:{utf8:V}}),k=oe(t,r,e,!1)}e+=o}else if(p===_){const r=e,i=ft.getInt32LE(t,e);let s=n;const a=e+i;if(o&&o[g]&&(s={...n,raw:!0}),d||(s={...s,validation:{utf8:V}}),k=oe(t,r,s,!0),0!==t[(e+=i)-1])throw new J("invalid array terminator byte");if(e!==a)throw new J("corrupted array bson")}else if(p===S)k=void 0;else if(p===T)k=null;else if(p===P)if(f)k=ft.getBigInt64LE(t,e),e+=8;else{const n=ft.getInt32LE(t,e),r=ft.getInt32LE(t,e+4);e+=8;const o=new Tt(n,r);k=u&&!0===c&&o.lessThanOrEqual(te)&&o.greaterThanOrEqual(ee)?o.toNumber():o}else if(p===D){const n=ot.allocateUnsafe(16);for(let r=0;r<16;r++)n[r]=t[e+r];e+=16,k=new Ft(n)}else if(p===O){let n=ft.getInt32LE(t,e);e+=4;const r=n,o=t[e++];if(n<0)throw new J("Negative binary type element size found");if(n>t.byteLength)throw new J("Binary type size larger than document size");if(o===lt.SUBTYPE_BYTE_ARRAY){if(n=ft.getInt32LE(t,e),e+=4,n<0)throw new J("Negative binary type element size found for subtype 0x02");if(n>r-4)throw new J("Binary type with subtype 0x02 contains too long binary size");if(n<r-4)throw new J("Binary type with subtype 0x02 contains too short binary size")}a&&c?k=ot.toLocalBufferType(t.subarray(e,e+n)):(k=new lt(t.subarray(e,e+n),o),o===F&&yt.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 J("Bad BSON Document: illegal CString");const n=ot.toUTF8(t,e,y,!1);for(y=e=y+1;0!==t[y]&&y<t.length;)y++;if(y>=t.length)throw new J("Bad BSON Document: illegal CString");const r=ot.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 J("Bad BSON Document: illegal CString");const n=ot.toUTF8(t,e,y,!1);for(y=e=y+1;0!==t[y]&&y<t.length;)y++;if(y>=t.length)throw new J("Bad BSON Document: illegal CString");const r=ot.toUTF8(t,e,y,!1);e=y+1,k=new Zt(n,r)}else if(p===$){const n=ft.getInt32LE(t,e);if(e+=4,n<=0||n>t.length-e||0!==t[e+n-1])throw new J("bad string length in bson");const r=ot.toUTF8(t,e,e+n-1,V);k=c?r:new Kt(r),e+=n}else if(p===j)k=new Xt({i:ft.getUint32LE(t,e),t:ft.getUint32LE(t,e+4)}),e+=8;else if(p===R)k=new Vt;else if(p===q)k=new kt;else if(p===L){const n=ft.getInt32LE(t,e);if(e+=4,n<=0||n>t.length-e||0!==t[e+n-1])throw new J("bad string length in bson");const r=ot.toUTF8(t,e,e+n-1,V);k=new gt(r),e+=n}else if(p===U){const r=ft.getInt32LE(t,e);if(e+=4,r<13)throw new J("code_w_scope total size shorter minimum expected length");const o=ft.getInt32LE(t,e);if(e+=4,o<=0||o>t.length-e||0!==t[e+o-1])throw new J("bad string length in bson");const i=ot.toUTF8(t,e,e+o-1,V),s=e+=o,a=ft.getInt32LE(t,e),u=oe(t,s,n,!1);if(e+=a,r<8+a+o)throw new J("code_w_scope total size is too short, truncating scope");if(r>8+a+o)throw new J("code_w_scope total size is too long, clips outer document");k=new gt(i,u)}else{if(p!==x)throw new J(`Detected unknown BSON type ${p.toString(16)} for fieldname "${g}"`);{const n=ft.getInt32LE(t,e);if(e+=4,n<=0||n>t.length-e||0!==t[e+n-1])throw new J("bad string length in bson");const r=ot.toUTF8(t,e,e+n-1,V);e+=n;const o=ot.allocateUnsafe(12);for(let n=0;n<12;n++)o[n]=t[e+n];const i=new Yt(o);e+=12,k=new bt(r,i)}}"__proto__"===g?Object.defineProperty(m,g,{value:k,writable:!0,enumerable:!0,configurable:!0}):m[g]=k}if(g!==e-y){if(r)throw new J("corrupt array bson");throw new J("corrupt object bson")}if(!M)return m;if(mt(m)){const t=Object.assign({},m);return delete t.$ref,delete t.$id,delete t.$db,new bt(m.$ref,m.$id,m.$db,t)}return m}const ie=/\x00/,se=new Set(["$db","$ref","$id","$clusterTime"]);function ae(t,e,n,r){t[r++]=w,t[(r=r+ot.encodeUTF8Into(t,e,r)+1)-1]=0;const o=ot.encodeUTF8Into(t,n,r+4);return ft.setInt32LE(t,r,o+1),r=r+4+o,t[r++]=0,r}function ue(t,e,n,r){const o=!Object.is(n,-0)&&Number.isSafeInteger(n)&&n<=h&&n>=d?A:b;return t[r++]=o,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0,r+(o===A?ft.setInt32LE(t,r,n):ft.setFloat64LE(t,r,n))}function ce(t,e,n,r){return t[r++]=P,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0,r+ft.setBigInt64LE(t,r,n)}function fe(t,e,n,r){return t[r++]=T,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0,r}function le(t,e,n,r){return t[r++]=N,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0,t[r++]=n?1:0,r}function he(t,e,n,r){t[r++]=I,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0;const o=Tt.fromNumber(n.getTime()),i=o.getLowBits(),s=o.getHighBits();return(r+=ft.setInt32LE(t,r,i))+ft.setInt32LE(t,r,s)}function de(t,e,n,r){if(t[r++]=B,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0,n.source&&null!=n.source.match(ie))throw new J("value "+n.source+" must not contain null bytes");return r+=ot.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 pe(t,e,n,r){if(t[r++]=B,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0,null!=n.pattern.match(ie))throw new J("pattern "+n.pattern+" must not contain null bytes");r+=ot.encodeUTF8Into(t,n.pattern,r),t[r++]=0;const o=n.options.split("").sort().join("");return r+=ot.encodeUTF8Into(t,o,r),t[r++]=0,r}function ye(t,e,n,r){return null===n?t[r++]=T:"MinKey"===n._bsontype?t[r++]=R:t[r++]=q,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0,r}function ge(t,e,n,r){return t[r++]=E,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0,r+n.serializeInto(t,r)}function me(t,e,n,r){t[r++]=O,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.length;if(r+=ft.setInt32LE(t,r,o),t[r++]=C,o<=16)for(let e=0;e<o;e++)t[r+e]=n[e];else t.set(n,r);return r+o}function be(t,e,n,r,o,i,s,a,u){if(u.has(n))throw new J("Cannot convert circular structure to BSON");u.add(n),t[r++]=Array.isArray(n)?_:v,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0;const c=Be(t,n,o,r,i+1,s,a,u);return u.delete(n),c}function we(t,e,n,r){t[r++]=D,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0;for(let e=0;e<16;e++)t[r+e]=n.bytes[e];return r+16}function ve(t,e,n,r){t[r++]="Long"===n._bsontype?P:j,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.getLowBits(),i=n.getHighBits();return(r+=ft.setInt32LE(t,r,o))+ft.setInt32LE(t,r,i)}function _e(t,e,n,r){return n=n.valueOf(),t[r++]=A,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0,r+ft.setInt32LE(t,r,n)}function Oe(t,e,n,r){return t[r++]=b,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0,r+ft.setFloat64LE(t,r,n.value)}function Se(t,e,n,r){t[r++]=L,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.toString(),i=ot.encodeUTF8Into(t,o,r+4)+1;return ft.setInt32LE(t,r,i),r=r+4+i-1,t[r++]=0,r}function Ee(t,e,n,r,o=!1,i=0,s=!1,a=!0,u){if(n.scope&&"object"==typeof n.scope){t[r++]=U,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0;let c=r;const f=n.code;r+=4;const l=ot.encodeUTF8Into(t,f,r+4)+1;ft.setInt32LE(t,r,l),t[r+4+l-1]=0,r=r+l+4;const h=Be(t,n.scope,o,r,i+1,s,a,u);r=h-1;const d=h-c;c+=ft.setInt32LE(t,c,d),t[r++]=0}else{t[r++]=L,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.code.toString(),i=ot.encodeUTF8Into(t,o,r+4)+1;ft.setInt32LE(t,r,i),r=r+4+i-1,t[r++]=0}return r}function Ne(t,e,n,r){t[r++]=O,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0;const o=n.buffer;let i=n.position;if(n.sub_type===lt.SUBTYPE_BYTE_ARRAY&&(i+=4),r+=ft.setInt32LE(t,r,i),t[r++]=n.sub_type,n.sub_type===lt.SUBTYPE_BYTE_ARRAY&&(i-=4,r+=ft.setInt32LE(t,r,i)),n.sub_type===lt.SUBTYPE_VECTOR&&ht(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 Ie(t,e,n,r){t[r++]=$,r+=ot.encodeUTF8Into(t,e,r),t[r++]=0;const o=ot.encodeUTF8Into(t,n.value,r+4)+1;return ft.setInt32LE(t,r,o),r=r+4+o-1,t[r++]=0,r}function Te(t,e,n,r,o,i,s){t[r++]=v,r+=ot.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=Be(t,u,!1,r,o+1,i,!0,s),f=c-a;return a+=ft.setInt32LE(t,r,f),c}function Be(t,e,n,r,c,h,d,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 J("serialize does not support an array as the root input");if("object"!=typeof e)throw new J("serialize does not support non-object as the root input");if("_bsontype"in e&&"string"==typeof e._bsontype)throw new J("BSON types cannot be serialized as a document");if(u(e)||s(e)||o(e)||i(e))throw new J("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 i=`${r}`;let a=e[r];"function"==typeof a?.toBSON&&(a=a.toBSON());const g=typeof a;if(void 0===a)y=fe(t,i,0,y);else if(null===a)y=fe(t,i,0,y);else if("string"===g)y=ae(t,i,a,y);else if("number"===g)y=ue(t,i,a,y);else if("bigint"===g)y=ce(t,i,a,y);else if("boolean"===g)y=le(t,i,a,y);else if("object"===g&&null==a._bsontype)y=a instanceof Date||u(a)?he(t,i,a,y):a instanceof Uint8Array||o(a)?me(t,i,a,y):a instanceof RegExp||s(a)?de(t,i,a,y):be(t,i,a,y,n,c,h,d,p);else if("object"===g){if(a[l]!==f)throw new k;if("ObjectId"===a._bsontype)y=ge(t,i,a,y);else if("Decimal128"===a._bsontype)y=we(t,i,a,y);else if("Long"===a._bsontype||"Timestamp"===a._bsontype)y=ve(t,i,a,y);else if("Double"===a._bsontype)y=Oe(t,i,a,y);else if("Code"===a._bsontype)y=Ee(t,i,a,y,n,c,h,d,p);else if("Binary"===a._bsontype)y=Ne(t,i,a,y);else if("BSONSymbol"===a._bsontype)y=Ie(t,i,a,y);else if("DBRef"===a._bsontype)y=Te(t,i,a,y,c,h,p);else if("BSONRegExp"===a._bsontype)y=pe(t,i,a,y);else if("Int32"===a._bsontype)y=_e(t,i,a,y);else if("MinKey"===a._bsontype||"MaxKey"===a._bsontype)y=ye(t,i,a,y);else if(void 0!==a._bsontype)throw new J(`Unrecognized or invalid _bsontype: ${String(a._bsontype)}`)}else"function"===g&&h&&(y=Se(t,i,a,y))}else if(e instanceof Map||a(e)){const r=e.entries();let i=!1;for(;!i;){const e=r.next();if(i=!!e.done,i)continue;const a=e.value?e.value[0]:void 0;let g=e.value?e.value[1]:void 0;"function"==typeof g?.toBSON&&(g=g.toBSON());const m=typeof g;if("string"==typeof a&&!se.has(a)){if(null!=a.match(ie))throw new J("key "+a+" must not contain null bytes");if(n){if("$"===a[0])throw new J("key "+a+" must not start with '$'");if(a.includes("."))throw new J("key "+a+" must not contain '.'")}}if(void 0===g)!1===d&&(y=fe(t,a,0,y));else if(null===g)y=fe(t,a,0,y);else if("string"===m)y=ae(t,a,g,y);else if("number"===m)y=ue(t,a,g,y);else if("bigint"===m)y=ce(t,a,g,y);else if("boolean"===m)y=le(t,a,g,y);else if("object"===m&&null==g._bsontype)y=g instanceof Date||u(g)?he(t,a,g,y):g instanceof Uint8Array||o(g)?me(t,a,g,y):g instanceof RegExp||s(g)?de(t,a,g,y):be(t,a,g,y,n,c,h,d,p);else if("object"===m){if(g[l]!==f)throw new k;if("ObjectId"===g._bsontype)y=ge(t,a,g,y);else if("Decimal128"===g._bsontype)y=we(t,a,g,y);else if("Long"===g._bsontype||"Timestamp"===g._bsontype)y=ve(t,a,g,y);else if("Double"===g._bsontype)y=Oe(t,a,g,y);else if("Code"===g._bsontype)y=Ee(t,a,g,y,n,c,h,d,p);else if("Binary"===g._bsontype)y=Ne(t,a,g,y);else if("BSONSymbol"===g._bsontype)y=Ie(t,a,g,y);else if("DBRef"===g._bsontype)y=Te(t,a,g,y,c,h,p);else if("BSONRegExp"===g._bsontype)y=pe(t,a,g,y);else if("Int32"===g._bsontype)y=_e(t,a,g,y);else if("MinKey"===g._bsontype||"MaxKey"===g._bsontype)y=ye(t,a,g,y);else if(void 0!==g._bsontype)throw new J(`Unrecognized or invalid _bsontype: ${String(g._bsontype)}`)}else"function"===m&&h&&(y=Se(t,a,g,y))}}else{if("function"==typeof e?.toBSON&&null!=(e=e.toBSON())&&"object"!=typeof e)throw new J("toBSON function did not return an object");for(const r of Object.keys(e)){let i=e[r];"function"==typeof i?.toBSON&&(i=i.toBSON());const a=typeof i;if("string"==typeof r&&!se.has(r)){if(null!=r.match(ie))throw new J("key "+r+" must not contain null bytes");if(n){if("$"===r[0])throw new J("key "+r+" must not start with '$'");if(r.includes("."))throw new J("key "+r+" must not contain '.'")}}if(void 0===i)!1===d&&(y=fe(t,r,0,y));else if(null===i)y=fe(t,r,0,y);else if("string"===a)y=ae(t,r,i,y);else if("number"===a)y=ue(t,r,i,y);else if("bigint"===a)y=ce(t,r,i,y);else if("boolean"===a)y=le(t,r,i,y);else if("object"===a&&null==i._bsontype)y=i instanceof Date||u(i)?he(t,r,i,y):i instanceof Uint8Array||o(i)?me(t,r,i,y):i instanceof RegExp||s(i)?de(t,r,i,y):be(t,r,i,y,n,c,h,d,p);else if("object"===a){if(i[l]!==f)throw new k;if("ObjectId"===i._bsontype)y=ge(t,r,i,y);else if("Decimal128"===i._bsontype)y=we(t,r,i,y);else if("Long"===i._bsontype||"Timestamp"===i._bsontype)y=ve(t,r,i,y);else if("Double"===i._bsontype)y=Oe(t,r,i,y);else if("Code"===i._bsontype)y=Ee(t,r,i,y,n,c,h,d,p);else if("Binary"===i._bsontype)y=Ne(t,r,i,y);else if("BSONSymbol"===i._bsontype)y=Ie(t,r,i,y);else if("DBRef"===i._bsontype)y=Te(t,r,i,y,c,h,p);else if("BSONRegExp"===i._bsontype)y=pe(t,r,i,y);else if("Int32"===i._bsontype)y=_e(t,r,i,y);else if("MinKey"===i._bsontype||"MaxKey"===i._bsontype)y=ye(t,r,i,y);else if(void 0!==i._bsontype)throw new J(`Unrecognized or invalid _bsontype: ${String(i._bsontype)}`)}else"function"===a&&h&&(y=Se(t,r,i,y))}}p.delete(e),t[y++]=0;const g=y-r;return r+=ft.setInt32LE(t,r,g),y}const xe={$oid:Yt,$binary:lt,$uuid:lt,$symbol:Kt,$numberInt:Jt,$numberDecimal:Ft,$numberDouble:Mt,$numberLong:Tt,$minKey:Vt,$maxKey:kt,$regex:Zt,$regularExpression:Zt,$timestamp:Xt};function Le(t,e={}){if("number"==typeof t){const n=t<=h&&t>=d,r=t<=p&&t>=y;if(e.relaxed||e.legacy)return t;if(Number.isInteger(t)&&!Object.is(t,-0)){if(n)return new Jt(t);if(r)return e.useBigInt64?BigInt(t):Tt.fromNumber(t)}return new Mt(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=xe[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(Tt.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=Le(t.$scope)),gt.fromExtendedJSON(t)}if(mt(t)||t.$dbPointer){const e=t.$ref?t:t.$dbPointer;if(e instanceof bt)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 bt.fromExtendedJSON(e)}return t}function $e(t){const e=t.toISOString();return 0!==t.getUTCMilliseconds()?e:e.slice(0,-5)+"Z"}function Ue(t,e){if(t instanceof Map||a(t)){const n=Object.create(null);for(const[e,r]of t){if("string"!=typeof e)throw new J("Can only serialize maps with string keys");n[e]=r}return Ue(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 J(`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 Ue(t,e)}finally{e.seenObjects.pop()}}))}(t,e);if(void 0===t)return null;if(t instanceof Date||u(t)){const n=t.getTime(),r=n>-1&&n<2534023188e5;return e.legacy?e.relaxed&&r?{$date:t.getTime()}:{$date:$e(t)}:e.relaxed&&r?{$date:$e(t)}:{$date:{$numberLong:t.getTime().toString()}}}if(!("number"!=typeof t||e.relaxed&&isFinite(t))){if(Number.isInteger(t)&&!Object.is(t,-0)){if(t>=d&&t<=h)return{$numberInt:t.toString()};if(t>=y&&t<=p)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||s(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 J("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=Ue(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[l]!==f)throw new k;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=Ae[t._bsontype];if(!e)throw new J("Unrecognized or invalid _bsontype: "+t._bsontype);r=e(r)}return"Code"===n&&r.scope?r=new gt(r.code,Ue(r.scope,e)):"DBRef"===n&&r.oid&&(r=new bt(Ue(r.collection,e),Ue(r.oid,e),Ue(r.db,e),Ue(r.fields,e))),r.toExtendedJSON(e)}throw new J("_bsontype must be a string, but was: "+typeof n)}(t,e):t}const Ae={Binary:t=>new lt(t.value(),t.sub_type),Code:t=>new gt(t.code,t.scope),DBRef:t=>new bt(t.collection||t.namespace,t.oid,t.db,t.fields),Decimal128:t=>new Ft(t.bytes),Double:t=>new Mt(t.value),Int32:t=>new Jt(t.value),Long:t=>Tt.fromBits(null!=t.low?t.low:t.low_,null!=t.low?t.high:t.high_,null!=t.low?t.unsigned:t.unsigned_),MaxKey:()=>new kt,MinKey:()=>new Vt,ObjectId:t=>new Yt(t),BSONRegExp:t=>new Zt(t.pattern,t.options),BSONSymbol:t=>new Kt(t.value),Timestamp:t=>Xt.fromBits(t.low,t.high)};function je(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 J(`BSON Document field names cannot contain null bytes, found: ${JSON.stringify(t)}`);return Le(e,n)}))}function Pe(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=Ue(t,Object.assign({relaxed:!0,legacy:!1},r,{seenObjects:[{propertyName:"(root)",obj:null}]}));return JSON.stringify(o,e,n)}const De=Object.create(null);De.parse=je,De.stringify=Pe,De.serialize=function(t,e){return e=e||{},JSON.parse(Pe(t,e))},De.deserialize=function(t,e){return e=e||{},je(JSON.stringify(t),e)},Object.freeze(De);function Re(t,e){try{return ft.getNonnegativeInt32LE(t,e)}catch(t){throw new z("BSON size cannot be negative",e,{cause:t})}}function qe(t,e){let n=e;for(;0!==t[n];n++);if(n===t.length-1)throw new z("Null terminator not found",e);return n}const Ce=Object.create(null);Ce.parseToElements=function(t,e=0){if(e??=0,t.length<5)throw new z(`Input must be at least 5 bytes, got ${t.length} bytes`,e);const n=Re(t,e);if(n>t.length-e)throw new z(`Parsed documentSize (${n} bytes) does not match input length (${t.length} bytes)`,e);if(0!==t[e+n-1])throw new z("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 z("Invalid 0x00 type byte",o);break}const s=o,a=qe(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=qe(t,qe(t,o)+1)+1-o;else if(3===i||4===i||15===i)u=Re(t,o);else{if(2!==i&&5!==i&&12!==i&&13!==i&&14!==i)throw new z(`Invalid 0x${i.toString(16).padStart(2,"0")} type byte`,o);u=Re(t,o)+4,5===i&&(u+=1),12===i&&(u+=12)}if(u>n)throw new z("value reports length larger than document",o);r.push([i,s,a,o,u]),o+=u}return r},Ce.ByteUtils=ot,Ce.NumberUtils=ft,Object.freeze(Ce);const Fe=17825792;let Me=ot.allocate(Fe);function Je(t){Me.length<t&&(Me=ot.allocate(t))}function ke(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:Fe;Me.length<i&&(Me=ot.allocate(i));const s=Be(Me,t,n,0,0,r,o,null),a=ot.allocateUnsafe(s);return a.set(Me.subarray(0,s),0),a}function Ve(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=Be(Me,t,r,0,0,o,i,null);return e.set(Me.subarray(0,a),s),s+a-1}function ze(t,e={}){return ne(ot.toLocalBufferType(t),e)}function He(t,e={}){return Gt(t,"boolean"==typeof(e=e||{}).serializeFunctions&&e.serializeFunctions,"boolean"!=typeof e.ignoreUndefined||e.ignoreUndefined)}function Ye(t,e,n,r,o,i){const s=Object.assign({allowObjectSmallerThanBufferSize:!0,index:0},i),a=ot.toLocalBufferType(t);let u=e;for(let t=0;t<n;t++){const e=ft.getInt32LE(a,u);s.index=u,r[o+t]=ne(a,s),u+=e}return u}var Ge=Object.freeze({__proto__:null,BSONError:J,BSONOffsetError:z,BSONRegExp:Zt,BSONRuntimeError:V,BSONSymbol:Kt,BSONType:M,BSONValue:st,BSONVersionError:k,Binary:lt,ByteUtils:ot,Code:gt,DBRef:bt,Decimal128:Ft,Double:Mt,EJSON:De,Int32:Jt,Long:Tt,MaxKey:kt,MinKey:Vt,NumberUtils:ft,ObjectId:Yt,Timestamp:Xt,UUID:yt,bsonType:it,calculateObjectSize:He,deserialize:ze,deserializeStream:Ye,onDemand:Ce,serialize:ke,serializeWithBufferAndIndex:Ve,setInternalBufferSize:Je})}},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(258)})()));
|
|
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,(()=>(()=>{"use strict";var t={258:function(t,e,n){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 i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},r.apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0}),e.registerDatabase=void 0;var i=n(836),o={name:"database",entity:{database:function(t){var e=this.platform,n=e.adapter,o=e.runtime;return i.Db.reqClass=this.request.constructor,i.Db.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},i.Db.runtime=o,this.wsClientClass&&(i.Db.wsClass=n.wsClass,i.Db.wsClientClass=this.wsClientClass),i.Db.ws||(i.Db.ws=null),new i.Db(r(r(r({},this.config),{_fromApp:this}),t))}}};try{cloudbase.registerComponent(o)}catch(t){}function s(t){try{t.registerComponent(o)}catch(t){console.warn(t)}}e.registerDatabase=s;try{window.registerDatabase=s}catch(t){}},836:(t,e,n)=>{n.r(e),n.d(e,{CollectionReference:()=>En,Db:()=>Jn,DocumentReference:()=>Rt,Query:()=>Mt});var r,i,o={};n.r(o),n.d(o,{LineString:()=>Q,MultiLineString:()=>nt,MultiPoint:()=>tt,MultiPolygon:()=>it,Point:()=>z,Polygon:()=>X}),function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined"}(i||(i={}));var s,u,a="Object",f="GeoPoint",c="GeoLineString",l="GeoPolygon",h="GeoMultiPoint",d="GeoMultiLineString",p="GeoMultiPolygon",y="Date",m="ServerDate",g=["desc","asc"],b=["<","<=","==",">=",">"];!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"}(u||(u={}));var w,v=(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)}),_=[],O={},E=function(t){function e(e,n){if(n!==O)throw new TypeError("InternalSymbol cannot be constructed with new operator");return t.call(this,e)||this}return v(e,t),e.for=function(t){for(var n=0,r=_.length;n<r;n++)if(_[n].target===t)return _[n].instance;var i=new e(t,O);return _.push({target:t,instance:i}),i},e}((function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})}));const N=E;var S=N.for("UNSET_FIELD_NAME"),x=N.for("UPDATE_COMMAND"),T=N.for("QUERY_COMMAND"),I=N.for("LOGIC_COMMAND"),$=N.for("GEO_POINT"),B=N.for("SYMBOL_GEO_LINE_STRING"),A=N.for("SYMBOL_GEO_POLYGON"),L=N.for("SYMBOL_GEO_MULTI_POINT"),U=N.for("SYMBOL_GEO_MULTI_LINE_STRING"),P=N.for("SYMBOL_GEO_MULTI_POLYGON"),j=N.for("SERVER_DATE"),R=N.for("REGEXP"),q=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 j},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$date:{offset:this.offset}}},t}();function D(t){return new q(t)}var C,M=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s},F=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 i,o=e[n];switch(t.whichType(o)){case f:i=new z(o.coordinates[0],o.coordinates[1]);break;case c:i=new Q(o.coordinates.map((function(t){return new z(t[0],t[1])})));break;case l:i=new X(o.coordinates.map((function(t){return new Q(t.map((function(t){var e=M(t,2),n=e[0],r=e[1];return new z(n,r)})))})));break;case h:i=new tt(o.coordinates.map((function(t){return new z(t[0],t[1])})));break;case d:i=new nt(o.coordinates.map((function(t){return new Q(t.map((function(t){var e=M(t,2),n=e[0],r=e[1];return new z(n,r)})))})));break;case p:i=new it(o.coordinates.map((function(t){return new X(t.map((function(t){return new Q(t.map((function(t){var e=M(t,2),n=e[0],r=e[1];return new z(n,r)})))})))})));break;case y:i=new Date(1e3*o.$timestamp);break;case a:case"Array":i=t.formatField(o);break;case m:i=new Date(o.$date);break;default:i=o}Array.isArray(r)?r.push(i):r[n]=i})),r},t.whichType=function(t){var e=Object.prototype.toString.call(t).slice(8,-1);if(e===y)return"BsonDate";if(e===a){if(t instanceof z)return f;if(t instanceof Date)return y;if(t instanceof q)return m;t.$timestamp?e=y:t.$date?e=m:z.validate(t)?e=f:Q.validate(t)?e=c:X.validate(t)?e=l:tt.validate(t)?e=h:nt.validate(t)?e=d:it.validate(t)&&(e=p)}return e},t.generateDocId=function(){for(var t="",e=0;e<24;e++)t+="ABCDEFabcdef0123456789".charAt(Math.floor(22*Math.random()));return t},t}(),V=function(){function t(){}return t.isGeopoint=function(t,e){if("Number"!==F.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+i.IntergerError);return!0},t.isFieldOrder=function(t){if(-1===g.indexOf(t))throw new Error(i.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===b.indexOf(t))throw new Error(i.OpStrError);return!0},t.isCollName=function(t){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(t))throw new Error(i.CollNameError);return!0},t.isDocID=function(t){if(!/^([a-fA-F0-9]){24}$/.test(t))throw new Error(i.DocIDError);return!0},t}(),J=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},k=function(t){return"object"===J(t)},H=function(t){return"number"===J(t)},Y=function(t){return Array.isArray(t)},G=function(t){return"date"===J(t)},Z=function(t){return"regexp"===J(t)},W=function(t){return t&&t._internalType instanceof E},z=function(){function t(t,e){V.isGeopoint("longitude",t),V.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&&Y(t.coordinates)&&V.isGeopoint("longitude",t.coordinates[0])&&V.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return $},enumerable:!1,configurable:!0}),t}(),Q=function(){function t(t){if(!Y(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 z))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||!Y(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),i=r.next();!i.done;i=r.next()){var o=i.value;if(!H(o[0])||!H(o[1]))return!1}}catch(t){e={error:t}}finally{try{i&&!i.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 B},enumerable:!1,configurable:!0}),t}(),K=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.")},X=function(){function t(t){if(!Y(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 Q))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"));if(!Q.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,i;if("Polygon"!==t.type||!Y(t.coordinates))return!1;try{for(var o=K(t.coordinates),s=o.next();!s.done;s=o.next()){var u=s.value;if(!this.isCloseLineString(u))return!1;try{for(var a=(r=void 0,K(u)),f=a.next();!f.done;f=a.next()){var c=f.value;if(!H(c[0])||!H(c[1]))return!1}}catch(t){r={error:t}}finally{try{f&&!f.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}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 P},enumerable:!1,configurable:!0}),t}(),tt=function(){function t(t){if(!Y(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 z))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||!Y(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),i=r.next();!i.done;i=r.next()){var o=i.value;if(!H(o[0])||!H(o[1]))return!1}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return L},enumerable:!1,configurable:!0}),t}(),et=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.")},nt=function(){function t(t){if(!Y(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 Q))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,i;if("MultiLineString"!==t.type||!Y(t.coordinates))return!1;try{for(var o=et(t.coordinates),s=o.next();!s.done;s=o.next()){var u=s.value;try{for(var a=(r=void 0,et(u)),f=a.next();!f.done;f=a.next()){var c=f.value;if(!H(c[0])||!H(c[1]))return!1}}catch(t){r={error:t}}finally{try{f&&!f.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return U},enumerable:!1,configurable:!0}),t}(),rt=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.")},it=function(){function t(t){var e,n;if(!Y(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=rt(t),i=r.next();!i.done;i=r.next()){var o=i.value;if(!(o instanceof X))throw new TypeError('"polygon" must be of type Polygon[]. Received type '.concat(typeof o,"[]"))}}catch(t){e={error:t}}finally{try{i&&!i.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,i,o,s;if("MultiPolygon"!==t.type||!Y(t.coordinates))return!1;try{for(var u=rt(t.coordinates),a=u.next();!a.done;a=u.next()){var f=a.value;try{for(var c=(r=void 0,rt(f)),l=c.next();!l.done;l=c.next()){var h=l.value;try{for(var d=(o=void 0,rt(h)),p=d.next();!p.done;p=d.next()){var y=p.value;if(!H(y[0])||!H(y[1]))return!1}}catch(t){o={error:t}}finally{try{p&&!p.done&&(s=d.return)&&s.call(d)}finally{if(o)throw o.error}}}}catch(t){r={error:t}}finally{try{l&&!l.done&&(i=c.return)&&i.call(c)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=u.return)&&n.call(u)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return A},enumerable:!1,configurable:!0}),t}(),ot=function(){var t=function(){};if(!Promise){t.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};!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"}(C||(C={}));var st,ut=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||S}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function at(t){return t&&t instanceof ut&&t._internalType===x}!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(st||(st={}));var ft=function(){function t(t,e,n){if(this._internalType=I,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||S,this.fieldName!==S)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,i=e.length;r<i;r++)(ct(o=e[r])||pt(o))&&(e[r]=o._setFieldName(this.fieldName))}else{var o;(ct(o=e)||pt(o))&&(e=o._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(st.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(st.OR,r,this.fieldName)},t}();function ct(t){return t&&t instanceof ft&&t._internalType===I}var lt,ht=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"}(lt||(lt={}));var dt=function(t){function e(e,n,r){var i=t.call(this,e,n,r)||this;return i.operator=e,i._internalType=T,i}return ht(e,t),e.prototype.toJSON=function(){var t,e;switch(this.operator){case lt.IN:case lt.NIN:return(t={})["$"+this.operator]=this.operands,t;default:return(e={})["$"+this.operator]=this.operands[0],e}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(lt.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(lt.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(lt.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(lt.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(lt.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(lt.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(lt.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(lt.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof z))throw new TypeError('"geometry" must be of type Point. Received type '.concat(typeof t.geometry));if(void 0!==t.maxDistance&&!H(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '.concat(typeof t.maxDistance));if(void 0!==t.minDistance&&!H(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '.concat(typeof t.minDistance));var n=new e(lt.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof it||t.geometry instanceof X))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(lt.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof z||t.geometry instanceof Q||t.geometry instanceof X||t.geometry instanceof tt||t.geometry instanceof nt||t.geometry instanceof it))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(lt.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(ft);function pt(t){return t&&t instanceof dt&&t._internalType===T}function yt(t){return pt(t)}var mt={};for(var gt in lt)mt[gt]="$"+gt;for(var gt in st)mt[gt]="$"+gt;for(var gt in C)mt[gt]="$"+gt;function bt(t){return mt[t]||"$"+t}mt[lt.NEQ]="$ne",mt[C.REMOVE]="$unset",mt[C.SHIFT]="$pop",mt[C.UNSHIFT]="$push";var wt=function(){return wt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},wt.apply(this,arguments)},vt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s},_t=function(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))};function Ot(t){return Et(t,[t])}function Et(t,e){if(!W(t)){if(G(t))return{$date:+t};if(Z(t))return{$regex:t.source,$options:t.flags};if(Y(t))return t.map((function(t){if(e.indexOf(t)>-1)throw new Error("Cannot convert circular structure to JSON");return Et(t,_t(_t([],vt(e),!1),[t],!1))}));if(k(t)){var n=wt({},t);for(var r in n){if(e.indexOf(n[r])>-1)throw new Error("Cannot convert circular structure to JSON");n[r]=Et(n[r],_t(_t([],vt(e),!1),[n[r]],!1))}return n}return t}switch(t._internalType){case $:return t.toJSON();case j:case R:return t.parse();default:return t.toJSON?t.toJSON():t}}var Nt=function(){return Nt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},Nt.apply(this,arguments)},St=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s},xt=function(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))};function Tt(t,e,n,r){var i=Nt({},t);for(var o in t)if(!/^\$/.test(o)){var s=t[o];if(s&&k(s)&&!e(s)){if(r.indexOf(s)>-1)throw new Error("Cannot convert circular structure to JSON");var u=Tt(s,e,xt(xt([],St(n),!1),[o],!1),xt(xt([],St(r),!1),[s],!1));i[o]=u;var a=!1;for(var f in u)/^\$/.test(f)?a=!0:(i["".concat(o,".").concat(f)]=u[f],delete i[o][f]);a||delete i[o]}}return i}function It(t){return Tt(t,Bt,[],[t])}function $t(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?Y(t[r])?t[r].push(e[r]):k(t[r])?k(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is ".concat(J(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(J(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]}function Bt(t){return W(t)||G(t)||Z(t)}function At(t){return Ot(t)}var Lt=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.prototype.encodeUpdate=function(t){return at(t)?this.encodeUpdateCommand(t):"object"===J(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===S)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case C.PUSH:case C.PULL:case C.PULL_ALL:case C.POP:case C.SHIFT:case C.UNSHIFT:case C.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,i,o=bt(t.operator);return t.operator===C.REMOVE?((e={})[o]=((n={})[t.fieldName]="",n),e):((r={})[o]=((i={})[t.fieldName]=t.operands[0],i),r)},t.prototype.encodeArrayUpdateCommand=function(t){var e,n,r,i,o,s,u,a,f,c,l=bt(t.operator);switch(t.operator){case C.PUSH:var h=void 0;return h=Y(t.operands)?{$each:t.operands.map(At)}:t.operands,(e={})[l]=((n={})[t.fieldName]=h,n),e;case C.UNSHIFT:return h={$each:t.operands.map(At),$position:0},(r={})[l]=((i={})[t.fieldName]=h,i),r;case C.POP:return(o={})[l]=((s={})[t.fieldName]=1,s),o;case C.SHIFT:return(u={})[l]=((a={})[t.fieldName]=-1,a),u;default:return(f={})[l]=((c={})[t.fieldName]=At(t.operands),c),f}},t.prototype.encodeUpdateObject=function(t){var e=It(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(at(r))e[n]=r._setFieldName(n),$t(e,this.encodeUpdateCommand(e[n]),n);else{e[n]=r=At(r);var i=new ut(C.SET,[r],n);$t(e,this.encodeUpdateCommand(i),n)}}return e},t}(),Ut={};function Pt(t){if(!Jn.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return Ut[e]||(Ut[e]=new Jn.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:Jn.createRequest(t.config)}}})),Ut[e]}var jt=function(){return jt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},jt.apply(this,arguments)},Rt=function(){function t(t,e,n,r){void 0===r&&(r={});var i=this;this.watch=function(t){return Pt(i._db).watch(jt(jt({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify({_id:i.id})}))},this._db=t,this._coll=e,this.id=n,this.request=Jn.createRequest(this._db.config),this.projection=r}return t.prototype.create=function(t,e){e=e||ot();var n={collectionName:this._coll,data:Ot(t)};return this.id&&(n._id=this.id),this.request.send("database.addDocument",n).then((function(t){t.code?e(0,t):e(0,{id:t.data._id,requestId:t.requestId})})).catch((function(t){e(t)})),e.promise},t.prototype.set=function(t,e){if(e=e||ot(),!this.id)return Promise.resolve({code:"INVALID_PARAM",message:"docId不能为空"});if(!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n=!1,r=function(t){if("object"==typeof t)for(var e in t)t[e]instanceof ut?n=!0:"object"==typeof t[e]&&r(t[e])};if(r(t),n)return Promise.resolve({code:"DATABASE_REQUEST_FAILED",message:"update operator complicit"});var i={collectionName:this._coll,queryType:u.DOC,data:Ot(t),multi:!1,merge:!1,upsert:!0};return this.id&&(i.query={_id:this.id}),this.request.send("database.updateDocument",i).then((function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})})).catch((function(t){e(t)})),e.promise},t.prototype.update=function(t,e){if(e=e||ot(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={_id:this.id},r={collectionName:this._coll,data:Lt.encode(t),query:n,queryType:u.DOC,multi:!1,merge:!0,upsert:!1};return this.request.send("database.updateDocument",r).then((function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})})).catch((function(t){e(t)})),e.promise},t.prototype.remove=function(t){t=t||ot();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:u.DOC,multi:!1};return this.request.send("database.deleteDocument",n).then((function(e){e.code?t(0,e):t(0,{deleted:e.data.deleted,requestId:e.requestId})})).catch((function(e){t(e)})),t.promise},t.prototype.get=function(t){t=t||ot();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:u.DOC,multi:!1,projection:this.projection};return this.request.send("database.queryDocument",n).then((function(e){if(e.code)t(0,e);else{var n=F.formatResDocumentData(e.data.list);t(0,{data:n,requestId:e.requestId})}})).catch((function(e){t(e)})),t.promise},t.prototype.field=function(e){for(var n in e)e[n]?e[n]=1:e[n]=0;return new t(this._db,this._coll,this.id,e)},t}(),qt=function(){function t(){}return t.encode=function(t){return(new Dt).encodeQuery(t)},t}(),Dt=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n;return Bt(t)?ct(t)?this.encodeLogicCommand(t):pt(t)?this.encodeQueryCommand(t):((n={})[e]=this.encodeQueryObject(t),n):k(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regex:t.source,$options:t.flags}},t.prototype.encodeLogicCommand=function(t){var e,n,r,i,o,s,u,a=this;switch(t.operator){case st.NOR:case st.AND:case st.OR:var f=bt(t.operator),c=t.operands.map((function(e){return a.encodeQuery(e,t.fieldName)}));return(e={})[f]=c,e;case st.NOT:f=bt(t.operator);var l=t.operands[0];return Z(l)?((n={})[t.fieldName]=((r={})[f]=this.encodeRegExp(l),r),n):(c=this.encodeQuery(l)[t.fieldName],(i={})[t.fieldName]=((o={})[f]=c,o),i);default:if(f=bt(t.operator),1===t.operands.length){var h=this.encodeQuery(t.operands[0]);return(s={})[f]=h,s}return c=t.operands.map(this.encodeQuery.bind(this)),(u={})[f]=c,u}},t.prototype.encodeQueryCommand=function(t){return yt(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,i,o,s,u,a,f;if(t.fieldName===S)throw new Error("Cannot encode a comparison command with unset field name");var c=bt(t.operator);switch(t.operator){case lt.EQ:case lt.NEQ:case lt.LT:case lt.LTE:case lt.GT:case lt.GTE:case lt.ELEM_MATCH:case lt.EXISTS:case lt.SIZE:case lt.MOD:return(e={})[t.fieldName]=((n={})[c]=At(t.operands[0]),n),e;case lt.IN:case lt.NIN:case lt.ALL:return(r={})[t.fieldName]=((i={})[c]=At(t.operands),i),r;case lt.GEO_NEAR:var l=t.operands[0];return(o={})[t.fieldName]={$nearSphere:{$geometry:l.geometry.toJSON(),$maxDistance:l.maxDistance,$minDistance:l.minDistance}},o;case lt.GEO_WITHIN:return l=t.operands[0],(s={})[t.fieldName]={$geoWithin:{$geometry:l.geometry.toJSON()}},s;case lt.GEO_INTERSECTS:return l=t.operands[0],(u={})[t.fieldName]={$geoIntersects:{$geometry:l.geometry.toJSON()}},u;default:return(a={})[t.fieldName]=((f={})[c]=At(t.operands[0]),f),a}},t.prototype.encodeQueryObject=function(t){var e=It(t);for(var n in e){var r=e[n];if(ct(r)){e[n]=r._setFieldName(n);var i=this.encodeLogicCommand(e[n]);this.mergeConditionAfterEncode(e,i,n)}else yt(r)?(e[n]=r._setFieldName(n),i=this.encodeComparisonCommand(e[n]),this.mergeConditionAfterEncode(e,i,n)):Bt(r)&&(e[n]=At(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?Y(t[r])?t[r]=t[r].concat(e[r]):k(t[r])?k(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is ".concat(J(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(J(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),Ct=function(){return Ct=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},Ct.apply(this,arguments)},Mt=function(){function t(t,e,n,r,i){var o=this;this.watch=function(t){return Pt(o._db).watch(Ct(Ct({},t),{envId:o._db.config.env,collectionName:o._coll,query:JSON.stringify(o._fieldFilters||{}),limit:o._queryOptions.limit,orderBy:o._fieldOrders?o._fieldOrders.reduce((function(t,e){return t[e.field]=e.direction,t}),{}):void 0}))},this._db=t,this._coll=e,this._fieldFilters=n,this._fieldOrders=r||[],this._queryOptions=i||{},this._request=Jn.createRequest(this._db.config)}return t.prototype.get=function(t){t=t||ot();var e=[];this._fieldOrders&&this._fieldOrders.forEach((function(t){e.push(t)}));var n={collectionName:this._coll,queryType:u.WHERE};return this._fieldFilters&&(n.query=this._fieldFilters),e.length>0&&(n.order=e),this._queryOptions.offset&&(n.offset=this._queryOptions.offset),this._queryOptions.limit?n.limit=this._queryOptions.limit<1e3?this._queryOptions.limit:1e3:n.limit=100,this._queryOptions.projection&&(n.projection=this._queryOptions.projection),this._request.send("database.queryDocument",n).then((function(e){if(e.code)t(0,e);else{var n={data:F.formatResDocumentData(e.data.list),requestId:e.requestId};void 0!==e.total&&(n.total=e.total),void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset),t(0,n)}})).catch((function(e){t(e)})),t.promise},t.prototype.count=function(t){t=t||ot();var e={collectionName:this._coll,queryType:u.WHERE};return this._fieldFilters&&(e.query=this._fieldFilters),this._request.send("database.countDocument",e).then((function(e){e.code?t(0,e):t(0,{requestId:e.requestId,total:e.data.total})})).catch((function(e){t(e)})),t.promise},t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(i.QueryParamTypeError);var n=Object.keys(e),r=n.some((function(t){return void 0!==e[t]}));if(n.length&&!r)throw Error(i.QueryParamValueError);return new t(this._db,this._coll,qt.encode(e),this._fieldOrders,this._queryOptions)},t.prototype.orderBy=function(e,n){V.isFieldPath(e),V.isFieldOrder(n);var r={field:e,direction:n},i=this._fieldOrders.concat(r);return new t(this._db,this._coll,this._fieldFilters,i,this._queryOptions)},t.prototype.limit=function(e){V.isInteger("limit",e);var n=Ct({},this._queryOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.skip=function(e){V.isInteger("offset",e);var n=Ct({},this._queryOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.update=function(t,e){if(e=e||ot(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={collectionName:this._coll,query:this._fieldFilters,queryType:u.WHERE,multi:!0,merge:!0,upsert:!1,data:Lt.encode(t)};return this._request.send("database.updateDocument",n).then((function(t){t.code?e(0,t):e(0,{requestId:t.requestId,updated:t.data.updated,upsertId:t.data.upsert_id})})).catch((function(t){e(t)})),e.promise},t.prototype.field=function(e){for(var n in e)e[n]?"object"!=typeof e[n]&&(e[n]=1):e[n]=0;var r=Ct({},this._queryOptions);return r.projection=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,r)},t.prototype.remove=function(t){t=t||ot(),Object.keys(this._queryOptions).length>0&&console.warn("`offset`, `limit` and `projection` are not supported in remove() operation"),this._fieldOrders.length>0&&console.warn("`orderBy` is not supported in remove() operation");var e={collectionName:this._coll,query:qt.encode(this._fieldFilters),queryType:u.WHERE,multi:!0};return this._request.send("database.deleteDocument",e).then((function(e){e.code?t(0,e):t(0,{requestId:e.requestId,deleted:e.data.deleted})})).catch((function(e){t(e)})),t.promise},t}();const Ft=(()=>{const t=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),Symbol.toStringTag).get;return e=>t.call(e)})();function Vt(t){return"Uint8Array"===Ft(t)}function Jt(t){return"object"==typeof t&&null!=t&&Symbol.toStringTag in t&&"Map"===t[Symbol.toStringTag]}function kt(t,e){return JSON.stringify(t,((t,e)=>"bigint"==typeof e?{$numberLong:`${e}`}:Jt(e)?Object.fromEntries(e):e))}const Ht=7,Yt=Symbol.for("@@mdb.bson.version"),Gt=2147483647,Zt=-2147483648,Wt=Math.pow(2,63)-1,zt=-Math.pow(2,63),Qt=Math.pow(2,53),Kt=-Math.pow(2,53);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 Xt 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 te extends Xt{get name(){return"BSONVersionError"}constructor(){super(`Unsupported BSON version, bson types must be from bson ${Ht}.x.x`)}}class ee extends Xt{get name(){return"BSONRuntimeError"}constructor(t){super(t)}}class ne extends Xt{get name(){return"BSONOffsetError"}offset;constructor(t,e,n){super(`${t}. offset: ${e}`,n),this.offset=e}}let re,ie;function oe(t,e,n,r){if(r){re??=new TextDecoder("utf8",{fatal:!0});try{return re.decode(t.subarray(e,n))}catch(t){throw new Xt("Invalid UTF-8 string in BSON document",{cause:t})}}return ie??=new TextDecoder("utf8",{fatal:!1}),ie.decode(t.subarray(e,n))}function se(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 i=[];for(let r=e;r<n;r++){const e=t[r];if(e>127)return null;i.push(e)}return String.fromCharCode(...i)}function ue(t){return ce.fromNumberArray(Array.from({length:t},(()=>Math.floor(256*Math.random()))))}function ae(t){return crypto.getRandomValues(ce.allocate(t))}const fe=(()=>{const{crypto:t}=globalThis;return null!=t&&"function"==typeof t.getRandomValues?ae:ue})(),ce={isUint8Array:Vt,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 Xt("Cannot create Buffer from the passed potentialBuffer.")},allocate:t=>Buffer.alloc(t),allocateUnsafe:t=>Buffer.allocUnsafe(t),compare:(t,e)=>ce.toLocalBufferType(t).compare(e),concat:t=>Buffer.concat(t),equals:(t,e)=>ce.toLocalBufferType(t).equals(e),fromNumberArray:t=>Buffer.from(t),fromBase64:t=>Buffer.from(t,"base64"),fromUTF8:t=>Buffer.from(t,"utf8"),toBase64:t=>ce.toLocalBufferType(t).toString("base64"),fromISO88591:t=>Buffer.from(t,"binary"),toISO88591:t=>ce.toLocalBufferType(t).toString("binary"),fromHex:t=>Buffer.from(t,"hex"),toHex:t=>ce.toLocalBufferType(t).toString("hex"),toUTF8(t,e,n,r){const i=n-e<=20?se(t,e,n):null;if(null!=i)return i;const o=ce.toLocalBufferType(t).toString("utf8",e,n);if(r)for(let r=0;r<o.length;r++)if(65533===o.charCodeAt(r)){oe(t,e,n,!0);break}return o},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,i=n;r<e.length;r++,i++){const n=e.charCodeAt(r);if(n>127)return null;t[i]=n}return e.length}(t,e,n);return null!=r?r:ce.toLocalBufferType(t).write(e,n,void 0,"utf8")},randomBytes:fe,swap32:t=>ce.toLocalBufferType(t).swap32()};function le(t){if(t<0)throw new RangeError(`The argument 'byteLength' is invalid. Received ${t}`);return pe.fromNumberArray(Array.from({length:t},(()=>Math.floor(256*Math.random()))))}const he=(()=>{const{crypto:t}=globalThis;if(null!=t&&"function"==typeof t.getRandomValues)return e=>t.getRandomValues(pe.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 le})(),de=/(\d|[a-f])/i,pe={isUint8Array:Vt,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 Xt("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=>pe.allocate(t),compare(t,e){if(t===e)return 0;const n=Math.min(t.length,e.length);for(let r=0;r<n;r++){if(t[r]<e[r])return-1;if(t[r]>e[r])return 1}return t.length<e.length?-1:t.length>e.length?1:0},concat(t){if(0===t.length)return pe.allocate(0);let e=0;for(const n of t)e+=n.length;const n=pe.allocate(e);let r=0;for(const e of t)n.set(e,r),r+=e.length;return n},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))),fromUTF8:t=>(new TextEncoder).encode(t),toBase64:t=>btoa(pe.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],i=e[t+1];if(!de.test(r))break;if(!de.test(i))break;const o=Number.parseInt(`${r}${i}`,16);n.push(o)}return Uint8Array.from(n)},toHex:t=>Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join(""),toUTF8(t,e,n,r){const i=n-e<=20?se(t,e,n):null;return null!=i?i:oe(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:he,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],i=t[e+2],o=t[e+3];t[e]=o,t[e+1]=i,t[e+2]=r,t[e+3]=n}return t}},ye="function"==typeof Buffer&&!0!==Buffer.prototype?._isBuffer?ce:pe,me=Symbol.for("@@mdb.bson.type");class ge{get[me](){return this._bsontype}get[Yt](){return Ht}[Symbol.for("nodejs.util.inspect.custom")](t,e,n){return this.inspect(t,e,n)}}const be=new Float64Array(1),we=new Uint8Array(be.buffer,0,8);be[0]=-1;const ve=0===we[7],_e={isBigEndian:ve,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)=>(BigInt(t[e+4]+256*t[e+5]+65536*t[e+6]+(t[e+7]<<24))<<32n)+BigInt(t[e]+256*t[e+1]+65536*t[e+2]+16777216*t[e+3]),getFloat64LE:ve?(t,e)=>(we[7]=t[e],we[6]=t[e+1],we[5]=t[e+2],we[4]=t[e+3],we[3]=t[e+4],we[2]=t[e+5],we[1]=t[e+6],we[0]=t[e+7],be[0]):(t,e)=>(we[0]=t[e],we[1]=t[e+1],we[2]=t[e+2],we[3]=t[e+3],we[4]=t[e+4],we[5]=t[e+5],we[6]=t[e+6],we[7]=t[e+7],be[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=0xffffffffn;let i=Number(n&r);t[e]=i,i>>=8,t[e+1]=i,i>>=8,t[e+2]=i,i>>=8,t[e+3]=i;let o=Number(n>>32n&r);return t[e+4]=o,o>>=8,t[e+5]=o,o>>=8,t[e+6]=o,o>>=8,t[e+7]=o,8},setFloat64LE:ve?(t,e,n)=>(be[0]=n,t[e]=we[7],t[e+1]=we[6],t[e+2]=we[5],t[e+3]=we[4],t[e+4]=we[3],t[e+5]=we[2],t[e+6]=we[1],t[e+7]=we[0],8):(t,e,n)=>(be[0]=n,t[e]=we[0],t[e+1]=we[1],t[e+2]=we[2],t[e+3]=we[3],t[e+4]=we[4],t[e+5]=we[5],t[e+6]=we[6],t[e+7]=we[7],8)};class Oe extends ge{get _bsontype(){return"Binary"}static BSON_BINARY_SUBTYPE_DEFAULT=0;static BUFFER_SIZE=256;static SUBTYPE_DEFAULT=0;static SUBTYPE_FUNCTION=1;static SUBTYPE_BYTE_ARRAY=2;static SUBTYPE_UUID_OLD=3;static SUBTYPE_UUID=4;static SUBTYPE_MD5=5;static SUBTYPE_ENCRYPTED=6;static SUBTYPE_COLUMN=7;static SUBTYPE_SENSITIVE=8;static SUBTYPE_VECTOR=9;static SUBTYPE_USER_DEFINED=128;static VECTOR_TYPE=Object.freeze({Int8:3,Float32:39,PackedBit:16});buffer;sub_type;position;constructor(t,e){if(super(),null!=t&&"string"==typeof t&&!ArrayBuffer.isView(t)&&("object"!=typeof(n=t)||null==n||!(Symbol.toStringTag in n)||"ArrayBuffer"!==n[Symbol.toStringTag]&&"SharedArrayBuffer"!==n[Symbol.toStringTag])&&!Array.isArray(t))throw new Xt("Binary can only be constructed from Uint8Array or number[]");var n;this.sub_type=e??Oe.BSON_BINARY_SUBTYPE_DEFAULT,null==t?(this.buffer=ye.allocate(Oe.BUFFER_SIZE),this.position=0):(this.buffer=Array.isArray(t)?ye.fromNumberArray(t):ye.toLocalBufferType(t),this.position=this.buffer.byteLength)}put(t){if("string"==typeof t&&1!==t.length)throw new Xt("only accepts single character String");if("number"!=typeof t&&1!==t.length)throw new Xt("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 Xt("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=ye.allocate(Oe.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=ye.allocate(this.buffer.byteLength+t.length);e.set(this.buffer,0),this.buffer=e}if(ArrayBuffer.isView(t))this.buffer.set(ye.toLocalBufferType(t),e),this.position=e+t.byteLength>this.position?e+t.length:this.position;else if("string"==typeof t)throw new Xt("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 ye.toBase64(this.buffer.subarray(0,this.position))}toString(t){return"hex"===t?ye.toHex(this.buffer.subarray(0,this.position)):"base64"===t?ye.toBase64(this.buffer.subarray(0,this.position)):ye.toUTF8(this.buffer,0,this.position,!1)}toExtendedJSON(t){t=t||{},this.sub_type===Oe.SUBTYPE_VECTOR&&Ee(this);const e=ye.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===Oe.SUBTYPE_UUID)return new xe(this.buffer.subarray(0,this.position));throw new Xt(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${Oe.SUBTYPE_UUID}" is currently supported.`)}static createFromHexString(t,e){return new Oe(ye.fromHex(t),e)}static createFromBase64(t,e){return new Oe(ye.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=ye.fromBase64(t.$binary)):"string"!=typeof t.$binary&&(r=t.$binary.subType?parseInt(t.$binary.subType,16):0,n=ye.fromBase64(t.$binary.base64)):"$uuid"in t&&(r=4,n=xe.bytesFromString(t.$uuid)),!n)throw new Xt(`Unexpected Binary Extended JSON format ${JSON.stringify(t)}`);return 4===r?new xe(n):new Oe(n,r)}inspect(t,e,n){return n??=kt,`Binary.createFromBase64(${n(ye.toBase64(this.buffer.subarray(0,this.position)),e)}, ${n(this.sub_type,e)})`}toInt8Array(){if(this.sub_type!==Oe.SUBTYPE_VECTOR)throw new Xt("Binary sub_type is not Vector");if(this.buffer[0]!==Oe.VECTOR_TYPE.Int8)throw new Xt("Binary datatype field is not Int8");return Ee(this),new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toFloat32Array(){if(this.sub_type!==Oe.SUBTYPE_VECTOR)throw new Xt("Binary sub_type is not Vector");if(this.buffer[0]!==Oe.VECTOR_TYPE.Float32)throw new Xt("Binary datatype field is not Float32");Ee(this);const t=new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position));return _e.isBigEndian&&ye.swap32(t),new Float32Array(t.buffer)}toPackedBits(){if(this.sub_type!==Oe.SUBTYPE_VECTOR)throw new Xt("Binary sub_type is not Vector");if(this.buffer[0]!==Oe.VECTOR_TYPE.PackedBit)throw new Xt("Binary datatype field is not packed bit");return Ee(this),new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toBits(){if(this.sub_type!==Oe.SUBTYPE_VECTOR)throw new Xt("Binary sub_type is not Vector");if(this.buffer[0]!==Oe.VECTOR_TYPE.PackedBit)throw new Xt("Binary datatype field is not packed bit");Ee(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=ye.allocate(t.byteLength+2);e[0]=Oe.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 Ee(r),r}static fromFloat32Array(t){const e=ye.allocate(t.byteLength+2);e[0]=Oe.VECTOR_TYPE.Float32,e[1]=0;const n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);e.set(n,2),_e.isBigEndian&&ye.swap32(new Uint8Array(e.buffer,2));const r=new this(e,this.SUBTYPE_VECTOR);return Ee(r),r}static fromPackedBits(t,e=0){const n=ye.allocate(t.byteLength+2);n[0]=Oe.VECTOR_TYPE.PackedBit,n[1]=e,n.set(t,2);const r=new this(n,this.SUBTYPE_VECTOR);return Ee(r),r}static fromBits(t){const e=t.length+7>>>3,n=new Uint8Array(e+2);n[0]=Oe.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,i=t[e];if(0!==i&&1!==i)throw new Xt(`Invalid bit value at ${e}: must be 0 or 1, found ${t[e]}`);if(0===i)continue;const o=7-e%8;n[r+2]|=i<<o}return new this(n,Oe.SUBTYPE_VECTOR)}}function Ee(t){if(t.sub_type!==Oe.SUBTYPE_VECTOR)return;const e=t.position,n=t.buffer[0],r=t.buffer[1];if((n===Oe.VECTOR_TYPE.Float32||n===Oe.VECTOR_TYPE.Int8)&&0!==r)throw new Xt("Invalid Vector: padding must be zero for int8 and float32 vectors");if(n===Oe.VECTOR_TYPE.Float32&&0!==e&&e-2!=0&&(e-2)%4!=0)throw new Xt("Invalid Vector: Float32 vector must contain a multiple of 4 bytes");if(n===Oe.VECTOR_TYPE.PackedBit&&0!==r&&2===e)throw new Xt("Invalid Vector: padding must be zero for packed bit vectors that are empty");if(n===Oe.VECTOR_TYPE.PackedBit&&r>7)throw new Xt(`Invalid Vector: padding must be a value between 0 and 7. found: ${r}`)}const Ne=/^[0-9A-F]{32}$/i,Se=/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;class xe extends Oe{constructor(t){let e;if(null==t)e=xe.generate();else if(t instanceof xe)e=ye.toLocalBufferType(new Uint8Array(t.buffer));else if(ArrayBuffer.isView(t)&&16===t.byteLength)e=ye.toLocalBufferType(t);else{if("string"!=typeof t)throw new Xt("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=xe.bytesFromString(t)}super(e,4)}get id(){return this.buffer}set id(t){this.buffer=t}toHexString(t=!0){return t?[ye.toHex(this.buffer.subarray(0,4)),ye.toHex(this.buffer.subarray(4,6)),ye.toHex(this.buffer.subarray(6,8)),ye.toHex(this.buffer.subarray(8,10)),ye.toHex(this.buffer.subarray(10,16))].join("-"):ye.toHex(this.buffer)}toString(t){return"hex"===t?ye.toHex(this.id):"base64"===t?ye.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(t){if(!t)return!1;if(t instanceof xe)return ye.equals(t.id,this.id);try{return ye.equals(new xe(t).id,this.id)}catch{return!1}}toBinary(){return new Oe(this.id,Oe.SUBTYPE_UUID)}static generate(){const t=ye.randomBytes(16);return t[6]=15&t[6]|64,t[8]=63&t[8]|128,t}static isValid(t){return!!t&&("string"==typeof t?xe.isValidUUIDString(t):Vt(t)?16===t.byteLength:"Binary"===t._bsontype&&t.sub_type===this.SUBTYPE_UUID&&16===t.buffer.byteLength)}static createFromHexString(t){const e=xe.bytesFromString(t);return new xe(e)}static createFromBase64(t){return new xe(ye.fromBase64(t))}static bytesFromString(t){if(!xe.isValidUUIDString(t))throw new Xt("UUID string representation must be 32 hex digits or canonical hyphenated representation");return ye.fromHex(t.replace(/-/g,""))}static isValidUUIDString(t){return Ne.test(t)||Se.test(t)}inspect(t,e,n){return n??=kt,`new UUID(${n(this.toHexString(),e)})`}}class Te extends ge{get _bsontype(){return"Code"}code;scope;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 Te(t.$code,t.$scope)}inspect(t,e,n){n??=kt;let r=n(this.code,e);const i=r.includes("\n");return null!=this.scope&&(r+=`,${i?"\n":" "}${n(this.scope,e)}`),`new Code(${i?"\n":""}${r}${i&&null===this.scope?"\n":""})`}}class Ie extends ge{get _bsontype(){return"DBRef"}collection;oid;db;fields;constructor(t,e,n,r){super();const i=t.split(".");2===i.length&&(n=i.shift(),t=i.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 Ie(t.$ref,t.$id,t.$db,e)}inspect(t,e,n){n??=kt;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===kt?`new ObjectId(${r[1]})`:r[1],`new DBRef(${r.join(", ")})`}}function $e(t){if(""===t)return t;let e=0;const n="-"===t[e],r="+"===t[e];(r||n)&&(e+=1);let i=!1;for(;e<t.length&&"0"===t[e];++e)i=!0;return i?`${n?"-":""}${t.length===e?"0":t.slice(e)}`:r?t.slice(1):t}let Be;try{Be=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 Ae=4294967296,Le=0x10000000000000000,Ue=Le/2,Pe={},je={},Re=/^(\+?0|(\+|-)?[1-9][0-9]*)$/;class qe extends ge{get _bsontype(){return"Long"}get __isLong__(){return!0}high;low;unsigned;constructor(t=0,e,n){super();const r="boolean"==typeof e?e:Boolean(n),i="number"==typeof e?e:0,o="string"==typeof t?qe.fromString(t,r):"bigint"==typeof t?qe.fromBigInt(t,r):{low:0|t,high:0|i,unsigned:r};this.low=o.low,this.high=o.high,this.unsigned=o.unsigned}static TWO_PWR_24=qe.fromInt(16777216);static MAX_UNSIGNED_VALUE=qe.fromBits(-1,-1,!0);static ZERO=qe.fromInt(0);static UZERO=qe.fromInt(0,!0);static ONE=qe.fromInt(1);static UONE=qe.fromInt(1,!0);static NEG_ONE=qe.fromInt(-1);static MAX_VALUE=qe.fromBits(-1,2147483647,!1);static MIN_VALUE=qe.fromBits(0,-2147483648,!1);static fromBits(t,e,n){return new qe(t,e,n)}static fromInt(t,e){let n,r,i;return e?(i=0<=(t>>>=0)&&t<256)&&(r=je[t],r)?r:(n=qe.fromBits(t,(0|t)<0?-1:0,!0),i&&(je[t]=n),n):(i=-128<=(t|=0)&&t<128)&&(r=Pe[t],r)?r:(n=qe.fromBits(t,t<0?-1:0,!1),i&&(Pe[t]=n),n)}static fromNumber(t,e){if(isNaN(t))return e?qe.UZERO:qe.ZERO;if(e){if(t<0)return qe.UZERO;if(t>=Le)return qe.MAX_UNSIGNED_VALUE}else{if(t<=-Ue)return qe.MIN_VALUE;if(t+1>=Ue)return qe.MAX_VALUE}return t<0?qe.fromNumber(-t,e).neg():qe.fromBits(t%Ae|0,t/Ae|0,e)}static fromBigInt(t,e){const n=0xffffffffn;return new qe(Number(t&n),Number(t>>32n&n),e)}static _fromString(t,e,n){if(0===t.length)throw new Xt("empty string");if(n<2||36<n)throw new Xt("radix");let r;if((r=t.indexOf("-"))>0)throw new Xt("interior hyphen");if(0===r)return qe._fromString(t.substring(1),e,n).neg();const i=qe.fromNumber(Math.pow(n,8));let o=qe.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=qe.fromNumber(Math.pow(n,r));o=o.mul(t).add(qe.fromNumber(s))}else o=o.mul(i),o=o.add(qe.fromNumber(s))}return o.unsigned=e,o}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 Xt(`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 Xt(`Input: '${t}' contains invalid characters for radix: ${n}`);const i=$e(t),o=qe._fromString(i,r,n);if(o.toString(n).toLowerCase()!==i.toLowerCase())throw new Xt(`Input: ${t} is not representable as ${o.unsigned?"an unsigned":"a signed"} 64-bit Long ${null!=n?`with radix: ${n}`:""}`);return o}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?qe.ZERO:qe._fromString(t,r,n)}static fromBytes(t,e,n){return n?qe.fromBytesLE(t,e):qe.fromBytesBE(t,e)}static fromBytesLE(t,e){return new qe(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 qe(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?qe.fromNumber(t,e):"string"==typeof t?qe.fromString(t,e):qe.fromBits(t.low,t.high,"boolean"==typeof e?e:t.unsigned)}add(t){qe.isLong(t)||(t=qe.fromValue(t));const e=this.high>>>16,n=65535&this.high,r=this.low>>>16,i=65535&this.low,o=t.high>>>16,s=65535&t.high,u=t.low>>>16;let a=0,f=0,c=0,l=0;return l+=i+(65535&t.low),c+=l>>>16,l&=65535,c+=r+u,f+=c>>>16,c&=65535,f+=n+s,a+=f>>>16,f&=65535,a+=e+o,a&=65535,qe.fromBits(c<<16|l,a<<16|f,this.unsigned)}and(t){return qe.isLong(t)||(t=qe.fromValue(t)),qe.fromBits(this.low&t.low,this.high&t.high,this.unsigned)}compare(t){if(qe.isLong(t)||(t=qe.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(qe.isLong(t)||(t=qe.fromValue(t)),t.isZero())throw new Xt("division by zero");if(Be){if(!this.unsigned&&-2147483648===this.high&&-1===t.low&&-1===t.high)return this;const e=(this.unsigned?Be.div_u:Be.div_s)(this.low,this.high,t.low,t.high);return qe.fromBits(e,Be.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?qe.UZERO:qe.ZERO;let e,n,r;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return qe.UZERO;if(t.gt(this.shru(1)))return qe.UONE;r=qe.UZERO}else{if(this.eq(qe.MIN_VALUE))return t.eq(qe.ONE)||t.eq(qe.NEG_ONE)?qe.MIN_VALUE:t.eq(qe.MIN_VALUE)?qe.ONE:(e=this.shr(1).div(t).shl(1),e.eq(qe.ZERO)?t.isNegative()?qe.ONE:qe.NEG_ONE:(n=this.sub(t.mul(e)),r=e.add(n.div(t)),r));if(t.eq(qe.MIN_VALUE))return this.unsigned?qe.UZERO:qe.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=qe.ZERO}for(n=this;n.gte(t);){e=Math.max(1,Math.floor(n.toNumber()/t.toNumber()));const i=Math.ceil(Math.log(e)/Math.LN2),o=i<=48?1:Math.pow(2,i-48);let s=qe.fromNumber(e),u=s.mul(t);for(;u.isNegative()||u.gt(n);)e-=o,s=qe.fromNumber(e,this.unsigned),u=s.mul(t);s.isZero()&&(s=qe.ONE),r=r.add(s),n=n.sub(u)}return r}div(t){return this.divide(t)}equals(t){return qe.isLong(t)||(t=qe.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(qe.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(qe.isLong(t)||(t=qe.fromValue(t)),Be){const e=(this.unsigned?Be.rem_u:Be.rem_s)(this.low,this.high,t.low,t.high);return qe.fromBits(e,Be.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 qe.ZERO;if(qe.isLong(t)||(t=qe.fromValue(t)),Be){const e=Be.mul(this.low,this.high,t.low,t.high);return qe.fromBits(e,Be.get_high(),this.unsigned)}if(t.isZero())return qe.ZERO;if(this.eq(qe.MIN_VALUE))return t.isOdd()?qe.MIN_VALUE:qe.ZERO;if(t.eq(qe.MIN_VALUE))return this.isOdd()?qe.MIN_VALUE:qe.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(qe.TWO_PWR_24)&&t.lt(qe.TWO_PWR_24))return qe.fromNumber(this.toNumber()*t.toNumber(),this.unsigned);const e=this.high>>>16,n=65535&this.high,r=this.low>>>16,i=65535&this.low,o=t.high>>>16,s=65535&t.high,u=t.low>>>16,a=65535&t.low;let f=0,c=0,l=0,h=0;return h+=i*a,l+=h>>>16,h&=65535,l+=r*a,c+=l>>>16,l&=65535,l+=i*u,c+=l>>>16,l&=65535,c+=n*a,f+=c>>>16,c&=65535,c+=r*u,f+=c>>>16,c&=65535,c+=i*s,f+=c>>>16,c&=65535,f+=e*a+n*u+r*s+i*o,f&=65535,qe.fromBits(l<<16|h,f<<16|c,this.unsigned)}mul(t){return this.multiply(t)}negate(){return!this.unsigned&&this.eq(qe.MIN_VALUE)?qe.MIN_VALUE:this.not().add(qe.ONE)}neg(){return this.negate()}not(){return qe.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 qe.isLong(t)||(t=qe.fromValue(t)),qe.fromBits(this.low|t.low,this.high|t.high,this.unsigned)}shiftLeft(t){return qe.isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?qe.fromBits(this.low<<t,this.high<<t|this.low>>>32-t,this.unsigned):qe.fromBits(0,this.low<<t-32,this.unsigned)}shl(t){return this.shiftLeft(t)}shiftRight(t){return qe.isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?qe.fromBits(this.low>>>t|this.high<<32-t,this.high>>t,this.unsigned):qe.fromBits(this.high>>t-32,this.high>=0?0:-1,this.unsigned)}shr(t){return this.shiftRight(t)}shiftRightUnsigned(t){if(qe.isLong(t)&&(t=t.toInt()),0==(t&=63))return this;{const e=this.high;if(t<32){const n=this.low;return qe.fromBits(n>>>t|e<<32-t,e>>>t,this.unsigned)}return 32===t?qe.fromBits(e,0,this.unsigned):qe.fromBits(e>>>t-32,0,this.unsigned)}}shr_u(t){return this.shiftRightUnsigned(t)}shru(t){return this.shiftRightUnsigned(t)}subtract(t){return qe.isLong(t)||(t=qe.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)*Ae+(this.low>>>0):this.high*Ae+(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?qe.fromBits(this.low,this.high,!1):this}toString(t){if((t=t||10)<2||36<t)throw new Xt("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(qe.MIN_VALUE)){const e=qe.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=qe.fromNumber(Math.pow(t,6),this.unsigned);let n=this,r="";for(;;){const i=n.div(e);let o=(n.sub(i.mul(e)).toInt()>>>0).toString(t);if(n=i,n.isZero())return o+r;for(;o.length<6;)o="0"+o;r=""+o+r}}toUnsigned(){return this.unsigned?this:qe.fromBits(this.low,this.high,!0)}xor(t){return qe.isLong(t)||(t=qe.fromValue(t)),qe.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 Xt("$numberLong string is too long");if(!Re.test(t.$numberLong))throw new Xt(`$numberLong string "${t.$numberLong}" is in an invalid format`);if(n){const e=BigInt(t.$numberLong);return BigInt.asIntN(64,e)}const i=qe.fromString(t.$numberLong);return r?i.toNumber():i}inspect(t,e,n){return n??=kt,`new Long(${n(this.toString(),e)}${this.unsigned?`, ${n(this.unsigned,e)}`:""})`}}const De=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,Ce=/^(\+|-)?(Infinity|inf)$/i,Me=/^(\+|-)?NaN$/i,Fe=6111,Ve=-6176,Je=ye.fromNumberArray([124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),ke=ye.fromNumberArray([248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),He=ye.fromNumberArray([120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Ye=/^([-+])?(\d+)?$/;function Ge(t){return!isNaN(parseInt(t,10))}function Ze(t){const e=qe.fromNumber(1e9);let n=qe.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 qe(t.parts[r],0)),t.parts[r]=n.div(e).low,n=n.modulo(e);return{quotient:t,rem:n}}function We(t,e){throw new Xt(`"${t}" is not a valid Decimal128 string - ${e}`)}class ze extends ge{get _bsontype(){return"Decimal128"}bytes;constructor(t){if(super(),"string"==typeof t)this.bytes=ze.fromString(t).bytes;else{if(!(t instanceof Uint8Array||Vt(t)))throw new Xt("Decimal128 must take a Buffer or string");if(16!==t.byteLength)throw new Xt("Decimal128 must take a Buffer of 16 bytes");this.bytes=t}}static fromString(t){return ze._fromString(t,{allowRounding:!1})}static fromStringWithRounding(t){return ze._fromString(t,{allowRounding:!0})}static _fromString(t,e){let n=!1,r=!1,i=!1,o=!1,s=0,u=0,a=0,f=0,c=0;const l=[0];let h=0,d=0,p=0,y=0,m=new qe(0,0),g=new qe(0,0),b=0,w=0;if(t.length>=7e3)throw new Xt(t+" not a valid Decimal128 string");const v=t.match(De),_=t.match(Ce),O=t.match(Me);if(!v&&!_&&!O||0===t.length)throw new Xt(t+" not a valid Decimal128 string");if(v){const e=v[2],n=v[4],r=v[5],i=v[6];n&&void 0===i&&We(t,"missing exponent power"),n&&void 0===e&&We(t,"missing exponent base"),void 0===n&&(r||i)&&We(t,"missing e before exponent")}if("+"!==t[w]&&"-"!==t[w]||(r=!0,n="-"===t[w++]),!Ge(t[w])&&"."!==t[w]){if("i"===t[w]||"I"===t[w])return new ze(n?ke:He);if("N"===t[w])return new ze(Je)}for(;Ge(t[w])||"."===t[w];)"."!==t[w]?(h<34&&("0"!==t[w]||o)&&(o||(c=u),o=!0,l[d++]=parseInt(t[w],10),h+=1),o&&(a+=1),i&&(f+=1),u+=1,w+=1):(i&&We(t,"contains multiple periods"),i=!0,w+=1);if(i&&!u)throw new Xt(t+" not a valid Decimal128 string");if("e"===t[w]||"E"===t[w]){const e=t.substr(++w).match(Ye);if(!e||!e[2])return new ze(Je);y=parseInt(e[0],10),w+=e[0].length}if(t[w])return new ze(Je);if(h){if(p=h-1,s=a,1!==s)for(;"0"===t[c+s-1+Number(r)+Number(i)];)s-=1}else l[0]=0,a=1,h=1,s=0;for(y<=f&&f>y+16384?y=Ve:y-=f;y>Fe;){if(p+=1,p>=34){if(0===s){y=Fe;break}We(t,"overflow")}y-=1}if(e.allowRounding){for(;y<Ve||h<a;){if(0===p&&s<h){y=Ve,s=0;break}if(h<a?a-=1:p-=1,y<Fe)y+=1;else{if(l.join("").match(/^0+$/)){y=Fe;break}We(t,"overflow")}}if(p+1<s){let e=u;i&&(c+=1,e+=1),r&&(c+=1,e+=1);const o=parseInt(t[c+p+1],10);let s=0;if(o>=5&&(s=1,5===o)){s=l[p]%2==1?1:0;for(let n=c+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<Fe))return new ze(n?ke:He);y+=1,l[t]=1}}}}else{for(;y<Ve||h<a;){if(0===p){if(0===s){y=Ve;break}We(t,"exponent underflow")}h<a?("0"!==t[a-1+Number(r)+Number(i)]&&0!==s&&We(t,"inexact rounding"),a-=1):(0!==l[p]&&We(t,"inexact rounding"),p-=1),y<Fe?y+=1:We(t,"overflow")}p+1<s&&(i&&(c+=1),r&&(c+=1),0!==parseInt(t[c+p+1],10)&&We(t,"inexact rounding"))}if(m=qe.fromNumber(0),g=qe.fromNumber(0),0===s)m=qe.fromNumber(0),g=qe.fromNumber(0);else if(p<17){let t=0;for(g=qe.fromNumber(l[t++]),m=new qe(0,0);t<=p;t++)g=g.multiply(qe.fromNumber(10)),g=g.add(qe.fromNumber(l[t]))}else{let t=0;for(m=qe.fromNumber(l[t++]);t<=p-17;t++)m=m.multiply(qe.fromNumber(10)),m=m.add(qe.fromNumber(l[t]));for(g=qe.fromNumber(l[t++]);t<=p;t++)g=g.multiply(qe.fromNumber(10)),g=g.add(qe.fromNumber(l[t]))}const E=function(t,e){if(!t&&!e)return{high:qe.fromNumber(0),low:qe.fromNumber(0)};const n=t.shiftRightUnsigned(32),r=new qe(t.getLowBits(),0),i=e.shiftRightUnsigned(32),o=new qe(e.getLowBits(),0);let s=n.multiply(i),u=n.multiply(o);const a=r.multiply(i);let f=r.multiply(o);return s=s.add(u.shiftRightUnsigned(32)),u=new qe(u.getLowBits(),0).add(a).add(f.shiftRightUnsigned(32)),s=s.add(u.shiftRightUnsigned(32)),f=u.shiftLeft(32).add(new qe(f.getLowBits(),0)),{high:s,low:f}}(m,qe.fromString("100000000000000000"));E.low=E.low.add(g),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,g)&&(E.high=E.high.add(qe.fromNumber(1))),b=y+6176;const N={low:qe.fromNumber(0),high:qe.fromNumber(0)};E.high.shiftRightUnsigned(49).and(qe.fromNumber(1)).equals(qe.fromNumber(1))?(N.high=N.high.or(qe.fromNumber(3).shiftLeft(61)),N.high=N.high.or(qe.fromNumber(b).and(qe.fromNumber(16383).shiftLeft(47))),N.high=N.high.or(E.high.and(qe.fromNumber(0x7fffffffffff)))):(N.high=N.high.or(qe.fromNumber(16383&b).shiftLeft(49)),N.high=N.high.or(E.high.and(qe.fromNumber(562949953421311)))),N.low=E.low,n&&(N.high=N.high.or(qe.fromString("9223372036854775808")));const S=ye.allocateUnsafe(16);return w=0,S[w++]=255&N.low.low,S[w++]=N.low.low>>8&255,S[w++]=N.low.low>>16&255,S[w++]=N.low.low>>24&255,S[w++]=255&N.low.high,S[w++]=N.low.high>>8&255,S[w++]=N.low.high>>16&255,S[w++]=N.low.high>>24&255,S[w++]=255&N.high.low,S[w++]=N.high.low>>8&255,S[w++]=N.high.low>>16&255,S[w++]=N.high.low>>24&255,S[w++]=255&N.high.high,S[w++]=N.high.high>>8&255,S[w++]=N.high.high>>16&255,S[w++]=N.high.high>>24&255,new ze(S)}toString(){let t,e=0;const n=new Array(36);for(let t=0;t<n.length;t++)n[t]=0;let r,i,o,s=0,u=!1,a={parts:[0,0,0,0]};const f=[];s=0;const c=this.bytes,l=c[s++]|c[s++]<<8|c[s++]<<16|c[s++]<<24,h=c[s++]|c[s++]<<8|c[s++]<<16|c[s++]<<24,d=c[s++]|c[s++]<<8|c[s++]<<16|c[s++]<<24,p=c[s++]|c[s++]<<8|c[s++]<<16|c[s++]<<24;s=0,(new qe(l,h),new qe(d,p)).lessThan(qe.ZERO)&&f.push("-");const y=p>>26&31;if(y>>3==3){if(30===y)return f.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 m=t-6176;if(a.parts[0]=(16383&p)+((15&r)<<14),a.parts[1]=d,a.parts[2]=h,a.parts[3]=l,0===a.parts[0]&&0===a.parts[1]&&0===a.parts[2]&&0===a.parts[3])u=!0;else for(o=3;o>=0;o--){let t=0;const e=Ze(a);if(a=e.quotient,t=e.rem.low,t)for(i=8;i>=0;i--)n[9*o+i]=t%10,t=Math.floor(t/10)}if(u)e=1,n[s]=0;else for(e=36;!n[s];)e-=1,s+=1;const g=e-1+m;if(g>=34||g<=-7||m>0){if(e>34)return f.push("0"),m>0?f.push(`E+${m}`):m<0&&f.push(`E${m}`),f.join("");f.push(`${n[s++]}`),e-=1,e&&f.push(".");for(let t=0;t<e;t++)f.push(`${n[s++]}`);f.push("E"),g>0?f.push(`+${g}`):f.push(`${g}`)}else if(m>=0)for(let t=0;t<e;t++)f.push(`${n[s++]}`);else{let t=e+m;if(t>0)for(let e=0;e<t;e++)f.push(`${n[s++]}`);else f.push("0");for(f.push(".");t++<0;)f.push("0");for(let r=0;r<e-Math.max(t-1,0);r++)f.push(`${n[s++]}`)}return f.join("")}toJSON(){return{$numberDecimal:this.toString()}}toExtendedJSON(){return{$numberDecimal:this.toString()}}static fromExtendedJSON(t){return ze.fromString(t.$numberDecimal)}inspect(t,e,n){return n??=kt,`new Decimal128(${n(this.toString(),e)})`}}class Qe extends ge{get _bsontype(){return"Double"}value;constructor(t){super(),t instanceof Number&&(t=t.valueOf()),this.value=+t}static fromString(t){const e=Number(t);if("NaN"===t)return new Qe(NaN);if("Infinity"===t)return new Qe(1/0);if("-Infinity"===t)return new Qe(-1/0);if(!Number.isFinite(e))throw new Xt(`Input: ${t} is not representable as a Double`);if(t.trim()!==t)throw new Xt(`Input: '${t}' contains whitespace`);if(""===t)throw new Xt("Input is an empty string");if(/[^-0-9.+eE]/.test(t))throw new Xt(`Input: '${t}' is not in decimal or exponential notation`);return new Qe(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 Qe(n)}inspect(t,e,n){return n??=kt,`new Double(${n(this.value,e)})`}}class Ke extends ge{get _bsontype(){return"Int32"}value;constructor(t){super(),t instanceof Number&&(t=t.valueOf()),this.value=0|+t}static fromString(t){const e=$e(t),n=Number(t);if(Gt<n)throw new Xt(`Input: '${t}' is larger than the maximum value for Int32`);if(Zt>n)throw new Xt(`Input: '${t}' is smaller than the minimum value for Int32`);if(!Number.isSafeInteger(n))throw new Xt(`Input: '${t}' is not a safe integer`);if(n.toString()!==e)throw new Xt(`Input: '${t}' is not a valid Int32 string`);return new Ke(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 Ke(t.$numberInt)}inspect(t,e,n){return n??=kt,`new Int32(${n(this.value,e)})`}}class Xe extends ge{get _bsontype(){return"MaxKey"}toExtendedJSON(){return{$maxKey:1}}static fromExtendedJSON(){return new Xe}inspect(){return"new MaxKey()"}}class tn extends ge{get _bsontype(){return"MinKey"}toExtendedJSON(){return{$minKey:1}}static fromExtendedJSON(){return new tn}inspect(){return"new MinKey()"}}let en=null;const nn=new WeakMap;class rn extends ge{get _bsontype(){return"ObjectId"}static index=Math.floor(16777215*Math.random());static cacheHexString;buffer;constructor(t){let e;if(super(),"object"==typeof t&&t&&"id"in t){if("string"!=typeof t.id&&!ArrayBuffer.isView(t.id))throw new Xt("Argument passed in must have an id that is of type string or Buffer");e="toHexString"in t&&"function"==typeof t.toHexString?ye.fromHex(t.toHexString()):t.id}else e=t;if(null==e)this.buffer=rn.generate();else if(ArrayBuffer.isView(e)&&12===e.byteLength)this.buffer=ye.toLocalBufferType(e);else{if("string"!=typeof e)throw new Xt("Argument passed in does not match the accepted types");if(!rn.validateHexString(e))throw new Xt("input must be a 24 character hex string, 12 byte Uint8Array, or an integer");this.buffer=ye.fromHex(e),rn.cacheHexString&&nn.set(this,e)}}get id(){return this.buffer}set id(t){this.buffer=t,rn.cacheHexString&&nn.set(this,ye.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(rn.cacheHexString){const t=nn.get(this);if(t)return t}const t=ye.toHex(this.id);return rn.cacheHexString&&nn.set(this,t),t}static getInc(){return rn.index=(rn.index+1)%16777215}static generate(t){"number"!=typeof t&&(t=Math.floor(Date.now()/1e3));const e=rn.getInc(),n=ye.allocateUnsafe(12);return _e.setInt32BE(n,0,t),null===en&&(en=ye.randomBytes(5)),n[4]=en[0],n[5]=en[1],n[6]=en[2],n[7]=en[3],n[8]=en[4],n[11]=255&e,n[10]=e>>8&255,n[9]=e>>16&255,n}toString(t){return"base64"===t?ye.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(rn.is(t))return this.buffer[11]===t.buffer[11]&&ye.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=_e.getUint32BE(this.buffer,0);return t.setTime(1e3*Math.floor(e)),t}static createPk(){return new rn}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=ye.allocate(12);for(let t=11;t>=4;t--)e[t]=0;return _e.setInt32BE(e,0,t),new rn(e)}static createFromHexString(t){if(24!==t?.length)throw new Xt("hex string must be 24 characters");return new rn(ye.fromHex(t))}static createFromBase64(t){if(16!==t?.length)throw new Xt("base64 string must be 16 characters");return new rn(ye.fromBase64(t))}static isValid(t){if(null==t)return!1;if("string"==typeof t)return rn.validateHexString(t);try{return new rn(t),!0}catch{return!1}}toExtendedJSON(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}}static fromExtendedJSON(t){return new rn(t.$oid)}isCached(){return rn.cacheHexString&&nn.has(this)}inspect(t,e,n){return n??=kt,`new ObjectId(${n(this.toHexString(),e)})`}}class on extends ge{get _bsontype(){return"BSONRegExp"}pattern;options;constructor(t,e){if(super(),this.pattern=t,this.options=(e??"").split("").sort().join(""),-1!==this.pattern.indexOf("\0"))throw new Xt(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);if(-1!==this.options.indexOf("\0"))throw new Xt(`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 Xt(`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 on(t.$regex,on.parseOptions(t.$options));if("BSONRegExp"===t.$regex._bsontype)return t}if("$regularExpression"in t)return new on(t.$regularExpression.pattern,on.parseOptions(t.$regularExpression.options));throw new Xt(`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??=kt,`new BSONRegExp(${r(n(this.pattern),"regexp")}, ${r(n(this.options),"regexp")})`}}class sn extends ge{get _bsontype(){return"BSONSymbol"}value;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 sn(t.$symbol)}inspect(t,e,n){return n??=kt,`new BSONSymbol(${n(this.value,e)})`}}const un=qe;class an extends un{get _bsontype(){return"Timestamp"}get[me](){return"Timestamp"}static MAX_VALUE=qe.MAX_UNSIGNED_VALUE;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(qe.isLong(t))super(t.low,t.high,!0);else{if("object"!=typeof t||!("t"in t)||!("i"in t))throw new Xt("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 Xt("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 Xt("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 Xt("Timestamp constructed from { t, i } must provide a positive t");if(n<0||Number.isNaN(n))throw new Xt("Timestamp constructed from { t, i } must provide a positive i");if(e>4294967295)throw new Xt("Timestamp constructed from { t, i } must provide t equal or less than uint32 max");if(n>4294967295)throw new Xt("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 an(qe.fromInt(t,!0))}static fromNumber(t){return new an(qe.fromNumber(t,!0))}static fromBits(t,e){return new an({i:t,t:e})}static fromString(t,e){return new an(qe.fromString(t,!0,e))}toExtendedJSON(){return{$timestamp:{t:this.t,i:this.i}}}static fromExtendedJSON(t){const e=qe.isLong(t.$timestamp.i)?t.$timestamp.i.getLowBitsUnsigned():t.$timestamp.i,n=qe.isLong(t.$timestamp.t)?t.$timestamp.t.getLowBitsUnsigned():t.$timestamp.t;return new an({t:n,i:e})}inspect(t,e,n){return n??=kt,`new Timestamp({ t: ${n(this.t,e)}, i: ${n(this.i,e)} })`}}qe.fromNumber(Qt),qe.fromNumber(Kt),new Set(["$db","$ref","$id","$clusterTime"]);const fn={$oid:rn,$binary:Oe,$uuid:Oe,$symbol:sn,$numberInt:Ke,$numberDecimal:ze,$numberDouble:Qe,$numberLong:qe,$minKey:tn,$maxKey:Xe,$regex:on,$regularExpression:on,$timestamp:an};function cn(t,e={}){if("number"==typeof t){const n=t<=Gt&&t>=Zt,r=t<=Wt&&t>=zt;if(e.relaxed||e.legacy)return t;if(Number.isInteger(t)&&!Object.is(t,-0)){if(n)return new Ke(t);if(r)return e.useBigInt64?BigInt(t):qe.fromNumber(t)}return new Qe(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 i=fn[n[r]];if(i)return i.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 ee("Unrecognized type for EJSON date: "+typeof n);r.setTime(Number(n))}else if("string"==typeof n)r.setTime(Date.parse(n));else if(qe.isLong(n))r.setTime(n.toNumber());else if("number"==typeof n&&e.relaxed)r.setTime(n);else{if("bigint"!=typeof n)throw new ee("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=cn(t.$scope)),Te.fromExtendedJSON(t)}if(function(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)}(t)||t.$dbPointer){const e=t.$ref?t:t.$dbPointer;if(e instanceof Ie)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 Ie.fromExtendedJSON(e)}return t}function ln(t){const e=t.toISOString();return 0!==t.getUTCMilliseconds()?e:e.slice(0,-5)+"Z"}function hn(t,e){if(t instanceof Map||Jt(t)){const n=Object.create(null);for(const[e,r]of t){if("string"!=typeof e)throw new Xt("Can only serialize maps with string keys");n[e]=r}return hn(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(""),i=t[n],o=" -> "+t.slice(n+1,t.length-1).map((t=>`${t} -> `)).join(""),s=t[t.length-1],u=" ".repeat(r.length+i.length/2),a="-".repeat(o.length+(i.length+s.length)/2-1);throw new Xt(`Converting circular structure to EJSON:\n ${r}${i}${o}${s}\n ${u}\\${a}/`)}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 hn(t,e)}finally{e.seenObjects.pop()}}))}(t,e);if(void 0===t)return null;if(t instanceof Date||((n=t)instanceof Date||"[object Date]"===Object.prototype.toString.call(n))){const n=t.getTime(),r=n>-1&&n<2534023188e5;return e.legacy?e.relaxed&&r?{$date:t.getTime()}:{$date:ln(t)}:e.relaxed&&r?{$date:ln(t)}:{$date:{$numberLong:t.getTime().toString()}}}var n,r;if(!("number"!=typeof t||e.relaxed&&isFinite(t))){if(Number.isInteger(t)&&!Object.is(t,-0)){if(t>=Zt&&t<=Gt)return{$numberInt:t.toString()};if(t>=zt&&t<=Wt)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||((r=t)instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(r))){let n=t.flags;if(void 0===n){const e=t.toString().match(/[gimuy]*$/);e&&(n=e[0])}return new on(t.source,n).toExtendedJSON(e)}return null!=t&&"object"==typeof t?function(t,e){if(null==t||"object"!=typeof t)throw new Xt("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 i=hn(t[r],e);"__proto__"===r?Object.defineProperty(n,r,{value:i,writable:!0,enumerable:!0,configurable:!0}):n[r]=i}finally{e.seenObjects.pop()}}return n}if(null!=t&&"object"==typeof t&&"string"==typeof t._bsontype&&t[Yt]!==Ht)throw new te;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=dn[t._bsontype];if(!e)throw new Xt("Unrecognized or invalid _bsontype: "+t._bsontype);r=e(r)}return"Code"===n&&r.scope?r=new Te(r.code,hn(r.scope,e)):"DBRef"===n&&r.oid&&(r=new Ie(hn(r.collection,e),hn(r.oid,e),hn(r.db,e),hn(r.fields,e))),r.toExtendedJSON(e)}throw new Xt("_bsontype must be a string, but was: "+typeof n)}(t,e):t}const dn={Binary:t=>new Oe(t.value(),t.sub_type),Code:t=>new Te(t.code,t.scope),DBRef:t=>new Ie(t.collection||t.namespace,t.oid,t.db,t.fields),Decimal128:t=>new ze(t.bytes),Double:t=>new Qe(t.value),Int32:t=>new Ke(t.value),Long:t=>qe.fromBits(null!=t.low?t.low:t.low_,null!=t.low?t.high:t.high_,null!=t.low?t.unsigned:t.unsigned_),MaxKey:()=>new Xe,MinKey:()=>new tn,ObjectId:t=>new rn(t),BSONRegExp:t=>new on(t.pattern,t.options),BSONSymbol:t=>new sn(t.value),Timestamp:t=>an.fromBits(t.low,t.high)};function pn(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 Xt(`BSON Document field names cannot contain null bytes, found: ${JSON.stringify(t)}`);return cn(e,n)}))}function yn(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 i=hn(t,Object.assign({relaxed:!0,legacy:!1},r,{seenObjects:[{propertyName:"(root)",obj:null}]}));return JSON.stringify(i,e,n)}const mn=Object.create(null);mn.parse=pn,mn.stringify=yn,mn.serialize=function(t,e){return e=e||{},JSON.parse(yn(t,e))},mn.deserialize=function(t,e){return e=e||{},pn(JSON.stringify(t),e)},Object.freeze(mn);function gn(t,e){try{return _e.getNonnegativeInt32LE(t,e)}catch(t){throw new ne("BSON size cannot be negative",e,{cause:t})}}function bn(t,e){let n=e;for(;0!==t[n];n++);if(n===t.length-1)throw new ne("Null terminator not found",e);return n}const wn=Object.create(null);wn.parseToElements=function(t,e=0){if(e??=0,t.length<5)throw new ne(`Input must be at least 5 bytes, got ${t.length} bytes`,e);const n=gn(t,e);if(n>t.length-e)throw new ne(`Parsed documentSize (${n} bytes) does not match input length (${t.length} bytes)`,e);if(0!==t[e+n-1])throw new ne("BSON documents must end in 0x00",e+n);const r=[];let i=e+4;for(;i<=n+e;){const o=t[i];if(i+=1,0===o){if(i-e!==n)throw new ne("Invalid 0x00 type byte",i);break}const s=i,u=bn(t,i)-s;let a;if(i+=u+1,1===o||18===o||9===o||17===o)a=8;else if(16===o)a=4;else if(7===o)a=12;else if(19===o)a=16;else if(8===o)a=1;else if(10===o||6===o||127===o||255===o)a=0;else if(11===o)a=bn(t,bn(t,i)+1)+1-i;else if(3===o||4===o||15===o)a=gn(t,i);else{if(2!==o&&5!==o&&12!==o&&13!==o&&14!==o)throw new ne(`Invalid 0x${o.toString(16).padStart(2,"0")} type byte`,i);a=gn(t,i)+4,5===o&&(a+=1),12===o&&(a+=12)}if(a>n)throw new ne("value reports length larger than document",i);r.push([o,s,u,i,a]),i+=a}return r},wn.ByteUtils=ye,wn.NumberUtils=_e,Object.freeze(wn);ye.allocate(17825792);var vn=function(){function t(t,e){this._stages=[],t&&e&&(this._db=t,this._request=Jn.createRequest(this._db.config),this._collectionName=e)}return t.prototype.end=function(){return t=this,e=void 0,r=function(){var t;return function(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(a){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,r=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){s.label=u[1];break}if(6===u[0]&&s.label<i[1]){s.label=i[1],i=u;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(u);break}i[2]&&s.ops.pop(),s.trys.pop();continue}u=e.call(t,s)}catch(t){u=[6,t],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}(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.aggregate",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:JSON.parse(t.data.list).map(mn.parse)}]:[2,t]}}))},new((n=void 0)||(n=Promise))((function(i,o){function s(t){try{a(r.next(t))}catch(t){o(t)}}function u(t){try{a(r.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}a((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){return this._stages.push({stageKey:"$".concat(t),stageValue:JSON.stringify(e)}),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=qt.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new z(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",qt.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 _n=vn;var On=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)}}(),En=function(t){function e(e,n){return t.call(this,e,n)||this}return On(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 Rt(this._db,this._coll,t)},e.prototype.add=function(t,e){return new Rt(this._db,this._coll,void 0).create(t,e)},e.prototype.aggregate=function(){return new _n(this._db,this._coll)},e}(Mt),Nn={eq:function(t){return new dt(lt.EQ,[t])},neq:function(t){return new dt(lt.NEQ,[t])},lt:function(t){return new dt(lt.LT,[t])},lte:function(t){return new dt(lt.LTE,[t])},gt:function(t){return new dt(lt.GT,[t])},gte:function(t){return new dt(lt.GTE,[t])},in:function(t){return new dt(lt.IN,t)},nin:function(t){return new dt(lt.NIN,t)},all:function(t){return new dt(lt.ALL,t)},elemMatch:function(t){return new dt(lt.ELEM_MATCH,[t])},exists:function(t){return new dt(lt.EXISTS,[t])},size:function(t){return new dt(lt.SIZE,[t])},mod:function(t){return new dt(lt.MOD,[t])},geoNear:function(t){return new dt(lt.GEO_NEAR,[t])},geoWithin:function(t){return new dt(lt.GEO_WITHIN,[t])},geoIntersects:function(t){return new dt(lt.GEO_INTERSECTS,[t])},and:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Y(arguments[0])?arguments[0]:Array.from(arguments);return new ft(st.AND,n)},nor:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Y(arguments[0])?arguments[0]:Array.from(arguments);return new ft(st.NOR,n)},or:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Y(arguments[0])?arguments[0]:Array.from(arguments);return new ft(st.OR,n)},not:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Y(arguments[0])?arguments[0]:Array.from(arguments);return new ft(st.NOT,n)},set:function(t){return new ut(C.SET,[t])},remove:function(){return new ut(C.REMOVE,[])},inc:function(t){return new ut(C.INC,[t])},mul:function(t){return new ut(C.MUL,[t])},push:function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(k(e[0])&&e[0].hasOwnProperty("each")){var r=e[0];t={$each:r.each,$position:r.position,$sort:r.sort,$slice:r.slice}}else t=Y(e[0])?e[0]:Array.from(e);return new ut(C.PUSH,t)},pull:function(t){return new ut(C.PULL,t)},pullAll:function(t){return new ut(C.PULL_ALL,t)},pop:function(){return new ut(C.POP,[])},shift:function(){return new ut(C.SHIFT,[])},unshift:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Y(arguments[0])?arguments[0]:Array.from(arguments);return new ut(C.UNSHIFT,n)},addToSet:function(t){return new ut(C.ADD_TO_SET,t)},rename:function(t){return new ut(C.RENAME,[t])},bit:function(t){return new ut(C.BIT,[t])},max:function(t){return new ut(C.MAX,[t])},min:function(t){return new ut(C.MIN,[t])},expr:function(t){return{$expr:t}},jsonSchema:function(t){return{$jsonSchema:t}},text:function(t){return"string"===J(t)?{$search:t.search}:{$search:t.search,$language:t.language,$caseSensitive:t.caseSensitive,$diacriticSensitive:t.diacriticSensitive}},aggregate:{pipeline:function(){return new _n},abs:function(t){return new Sn("abs",t)},add:function(t){return new Sn("add",t)},ceil:function(t){return new Sn("ceil",t)},divide:function(t){return new Sn("divide",t)},exp:function(t){return new Sn("exp",t)},floor:function(t){return new Sn("floor",t)},ln:function(t){return new Sn("ln",t)},log:function(t){return new Sn("log",t)},log10:function(t){return new Sn("log10",t)},mod:function(t){return new Sn("mod",t)},multiply:function(t){return new Sn("multiply",t)},pow:function(t){return new Sn("pow",t)},sqrt:function(t){return new Sn("sqrt",t)},subtract:function(t){return new Sn("subtract",t)},trunc:function(t){return new Sn("trunc",t)},arrayElemAt:function(t){return new Sn("arrayElemAt",t)},arrayToObject:function(t){return new Sn("arrayToObject",t)},concatArrays:function(t){return new Sn("concatArrays",t)},filter:function(t){return new Sn("filter",t)},in:function(t){return new Sn("in",t)},indexOfArray:function(t){return new Sn("indexOfArray",t)},isArray:function(t){return new Sn("isArray",t)},map:function(t){return new Sn("map",t)},range:function(t){return new Sn("range",t)},reduce:function(t){return new Sn("reduce",t)},reverseArray:function(t){return new Sn("reverseArray",t)},size:function(t){return new Sn("size",t)},slice:function(t){return new Sn("slice",t)},zip:function(t){return new Sn("zip",t)},and:function(t){return new Sn("and",t)},not:function(t){return new Sn("not",t)},or:function(t){return new Sn("or",t)},cmp:function(t){return new Sn("cmp",t)},eq:function(t){return new Sn("eq",t)},gt:function(t){return new Sn("gt",t)},gte:function(t){return new Sn("gte",t)},lt:function(t){return new Sn("lt",t)},lte:function(t){return new Sn("lte",t)},neq:function(t){return new Sn("ne",t)},cond:function(t){return new Sn("cond",t)},ifNull:function(t){return new Sn("ifNull",t)},switch:function(t){return new Sn("switch",t)},dateFromParts:function(t){return new Sn("dateFromParts",t)},dateFromString:function(t){return new Sn("dateFromString",t)},dayOfMonth:function(t){return new Sn("dayOfMonth",t)},dayOfWeek:function(t){return new Sn("dayOfWeek",t)},dayOfYear:function(t){return new Sn("dayOfYear",t)},isoDayOfWeek:function(t){return new Sn("isoDayOfWeek",t)},isoWeek:function(t){return new Sn("isoWeek",t)},isoWeekYear:function(t){return new Sn("isoWeekYear",t)},millisecond:function(t){return new Sn("millisecond",t)},minute:function(t){return new Sn("minute",t)},month:function(t){return new Sn("month",t)},second:function(t){return new Sn("second",t)},hour:function(t){return new Sn("hour",t)},week:function(t){return new Sn("week",t)},year:function(t){return new Sn("year",t)},literal:function(t){return new Sn("literal",t)},mergeObjects:function(t){return new Sn("mergeObjects",t)},objectToArray:function(t){return new Sn("objectToArray",t)},allElementsTrue:function(t){return new Sn("allElementsTrue",t)},anyElementTrue:function(t){return new Sn("anyElementTrue",t)},setDifference:function(t){return new Sn("setDifference",t)},setEquals:function(t){return new Sn("setEquals",t)},setIntersection:function(t){return new Sn("setIntersection",t)},setIsSubset:function(t){return new Sn("setIsSubset",t)},setUnion:function(t){return new Sn("setUnion",t)},concat:function(t){return new Sn("concat",t)},dateToString:function(t){return new Sn("dateToString",t)},indexOfBytes:function(t){return new Sn("indexOfBytes",t)},indexOfCP:function(t){return new Sn("indexOfCP",t)},split:function(t){return new Sn("split",t)},strLenBytes:function(t){return new Sn("strLenBytes",t)},strLenCP:function(t){return new Sn("strLenCP",t)},strcasecmp:function(t){return new Sn("strcasecmp",t)},substr:function(t){return new Sn("substr",t)},substrBytes:function(t){return new Sn("substrBytes",t)},substrCP:function(t){return new Sn("substrCP",t)},toLower:function(t){return new Sn("toLower",t)},toUpper:function(t){return new Sn("toUpper",t)},meta:function(t){return new Sn("meta",t)},addToSet:function(t){return new Sn("addToSet",t)},avg:function(t){return new Sn("avg",t)},first:function(t){return new Sn("first",t)},last:function(t){return new Sn("last",t)},max:function(t){return new Sn("max",t)},min:function(t){return new Sn("min",t)},push:function(t){return new Sn("push",t)},stdDevPop:function(t){return new Sn("stdDevPop",t)},stdDevSamp:function(t){return new Sn("stdDevSamp",t)},sum:function(t){return new Sn("sum",t)},let:function(t){return new Sn("let",t)}},project:{slice:function(t){return new xn("slice",t)},elemMatch:function(t){return new xn("elemMatch",t)}}},Sn=function(t,e){this["$"+t]=e},xn=function(t,e){this["$"+t]=e},Tn=function(){function t(t){var e=t.regexp,n=t.options;if(!e)throw new TypeError("regexp must be a string");this.$regex=e,this.$options=n}return t.prototype.parse=function(){return{$regex:this.$regex,$options:this.$options}},Object.defineProperty(t.prototype,"_internalType",{get:function(){return R},enumerable:!1,configurable:!0}),t}();function In(t){return new Tn(t)}var $n="insert document failed",Bn="DATABASE_TRANSACTION_CONFLICT",An=function(){return An=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},An.apply(this,arguments)},Ln=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{a(r.next(t))}catch(t){o(t)}}function u(t){try{a(r.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}a((r=r.apply(t,e||[])).next())}))},Un=function(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(a){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,r=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){s.label=u[1];break}if(6===u[0]&&s.label<i[1]){s.label=i[1],i=u;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(u);break}i[2]&&s.ops.pop(),s.trys.pop();continue}u=e.call(t,s)}catch(t){u=[6,t],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}},Pn="database.updateDocInTransaction",jn=function(){function t(t,e,n){this._coll=e,this.id=n,this._transaction=t,this._request=this._transaction.getRequestMethod(),this._transactionId=this._transaction.getTransactionId()}return t.prototype.create=function(t){return Ln(this,void 0,void 0,(function(){var e,n,r,i;return Un(this,(function(o){switch(o.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,data:mn.stringify(Ot(t),{relaxed:!1})},this.id&&(e._id=this.id),[4,this._request.send("database.insertDocInTransaction",e)];case 1:if((n=o.sent()).code)throw n;if(r=mn.parse(n.inserted),1==(i=mn.parse(n.ok))&&1==r)return[2,An(An({},n),{ok:i,inserted:r})];throw new Error($n)}}))}))},t.prototype.get=function(){return Ln(this,void 0,void 0,(function(){var t,e;return Un(this,(function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.getInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,{data:"null"!==e.data?F.formatField(mn.parse(e.data)):mn.parse(e.data),requestId:e.requestId}]}}))}))},t.prototype.set=function(t){return Ln(this,void 0,void 0,(function(){var e,n;return Un(this,(function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:mn.stringify(Ot(t),{relaxed:!1}),upsert:!0},[4,this._request.send(Pn,e)];case 1:if((n=r.sent()).code)throw n;return[2,An(An({},n),{updated:mn.parse(n.updated),upserted:n.upserted?JSON.parse(n.upserted):null})]}}))}))},t.prototype.update=function(t){return Ln(this,void 0,void 0,(function(){var e,n;return Un(this,(function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:mn.stringify(Lt.encode(t),{relaxed:!1})},[4,this._request.send(Pn,e)];case 1:if((n=r.sent()).code)throw n;return[2,An(An({},n),{updated:mn.parse(n.updated)})]}}))}))},t.prototype.delete=function(){return Ln(this,void 0,void 0,(function(){var t,e;return Un(this,(function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.deleteDocInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,An(An({},e),{deleted:mn.parse(e.deleted)})]}}))}))},t}(),Rn=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)}}(),qn=function(t){function e(e,n){return t.call(this,e,n)||this}return Rn(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 jn(this._transaction,this._coll,t)},e.prototype.add=function(t){var e;return void 0!==t._id&&(e=t._id),new jn(this._transaction,this._coll,e).create(t)},e}((function(t,e){this._coll=e,this._transaction=t})),Dn=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{a(r.next(t))}catch(t){o(t)}}function u(t){try{a(r.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}a((r=r.apply(t,e||[])).next())}))},Cn=function(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(a){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,r=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){s.label=u[1];break}if(6===u[0]&&s.label<i[1]){s.label=i[1],i=u;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(u);break}i[2]&&s.ops.pop(),s.trys.pop();continue}u=e.call(t,s)}catch(t){u=[6,t],r=0}finally{n=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}},Mn=function(){function t(t){this._db=t,this._request=Jn.createRequest(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return t.prototype.init=function(){return Dn(this,void 0,void 0,(function(){var t;return Cn(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 qn(this,t)},t.prototype.getTransactionId=function(){return this._id},t.prototype.getRequestMethod=function(){return this._request},t.prototype.commit=function(){return Dn(this,void 0,void 0,(function(){var t,e;return Cn(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 Dn(this,void 0,void 0,(function(){var e,n;return Cn(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 Fn(){return Dn(this,void 0,void 0,(function(){var t;return Cn(this,(function(e){switch(e.label){case 0:return[4,(t=new Mn(this)).init()];case 1:return e.sent(),[2,t]}}))}))}function Vn(t,e){return void 0===e&&(e=3),Dn(this,void 0,void 0,(function(){var n,r,i,o,s=this;return Cn(this,(function(u){switch(u.label){case 0:return u.trys.push([0,4,,10]),[4,(n=new Mn(this)).init()];case 1:return u.sent(),[4,t(n)];case 2:if(r=u.sent(),!0===n.aborted)throw n.abortReason;return[4,n.commit()];case 3:return u.sent(),[2,r];case 4:if(i=u.sent(),!1===n.inited)throw i;return o=function(t){return Dn(s,void 0,void 0,(function(){return Cn(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,o(i)]:[3,6];case 5:u.sent(),u.label=6;case 6:return i&&i.code===Bn?[4,Vn.bind(this)(t,--e)]:[3,8];case 7:return[2,u.sent()];case 8:return[4,o(i)];case 9:return u.sent(),[3,10];case 10:return[2]}}))}))}var Jn=function(){function t(t){this.config=t,this.Geo=o,this.serverDate=D,this.command=Nn,this.RegExp=In,this.startTransaction=Fn,this.runTransaction=Vn,this.logicCommand=ft,this.updateCommand=ut,this.queryCommand=dt}return t.createRequest=function(e){var n=new t.reqClass(e),r=n.send;return n.send=function(t,n){return e.instance&&(n.instance=e.instance),e.database&&(n.database=e.database),r.call(this,t,n)},n},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new En(this,t)},t.prototype.createCollection=function(e){var n={collectionName:e};return t.createRequest(this.config).send("database.addCollection",n)},t}()}},e={};function n(r){var i=e[r];if(void 0!==i)return i.exports;var o=e[r]={exports:{}};return t[r].call(o.exports,o,o.exports,n),o.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(258)})()));
|