@cloudbase/js-sdk 3.9.0 → 3.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import*as t from"bson";import*as e from"@cloudbase/adapter-interface";import*as n from"jwt-decode";var r={d:(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},o={};r.d(o,{I:()=>nn});var i,a,s={};r.r(s),r.d(s,{LineString:()=>Q,MultiLineString:()=>K,MultiPoint:()=>Y,MultiPolygon:()=>tt,Point:()=>St,Polygon:()=>z}),function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.BooleanError="must be boolean",t.ArrayError="must be array",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined",t.CentersPhereError="centersPhere结构不合法"}(a||(a={}));var u,c,l="Object",f="GeoPoint",d="GeoLineString",p="GeoPolygon",h="GeoMultiPoint",y="GeoMultiLineString",m="GeoMultiPolygon",v="Date",b="ServerDate",w=["desc","asc"],g=["<","<=","==",">=",">"];!function(t){t.lt="<",t.gt=">",t.lte="<=",t.gte=">=",t.eq="=="}(u||(u={})),(i={})[u.eq]="$eq",i[u.lt]="$lt",i[u.lte]="$lte",i[u.gt]="$gt",i[u.gte]="$gte",function(t){t.WHERE="WHERE",t.DOC="DOC"}(c||(c={}));var _,O=(_=function(t,e){return _=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)},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}_(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),E=[],S={},I=function(t){function e(e,n){if(n!==S)throw new TypeError("InternalSymbol cannot be constructed with new operator");return t.call(this,e)||this}return O(e,t),e.for=function(t){for(var n=0,r=E.length;n<r;n++)if(E[n].target===t)return E[n].instance;var o=new e(t,S);return E.push({target:t,instance:o}),o},e}(function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})});const N=I;var P=N.for("UNSET_FIELD_NAME"),T=N.for("UPDATE_COMMAND"),j=N.for("QUERY_COMMAND"),A=N.for("LOGIC_COMMAND"),q=N.for("GEO_POINT"),x=N.for("SYMBOL_GEO_LINE_STRING"),C=N.for("SYMBOL_GEO_POLYGON"),D=N.for("SYMBOL_GEO_MULTI_POINT"),R=N.for("SYMBOL_GEO_MULTI_LINE_STRING"),L=N.for("SYMBOL_GEO_MULTI_POLYGON"),M=N.for("SERVER_DATE"),k=N.for("REGEXP"),J=N.for("OBJECTID"),U=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},$=function(t){return"object"===U(t)},F=function(t){return"number"===U(t)},G=function(t){return Array.isArray(t)},W=function(t){return"date"===U(t)},B=function(t){return"regexp"===U(t)},H=function(t){return t&&t._internalType instanceof I},Q=function(){function t(t){if(!G(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 St))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||!G(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(!F(i[0])||!F(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 x},enumerable:!1,configurable:!0}),t}(),V=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.")},z=function(){function t(t){if(!G(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,o;if("Polygon"!==t.type||!G(t.coordinates))return!1;try{for(var i=V(t.coordinates),a=i.next();!a.done;a=i.next()){var s=a.value;if(!this.isCloseLineString(s))return!1;try{for(var u=(r=void 0,V(s)),c=u.next();!c.done;c=u.next()){var l=c.value;if(!F(l[0])||!F(l[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{a&&!a.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 C},enumerable:!1,configurable:!0}),t}(),Y=function(){function t(t){if(!G(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 St))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||!G(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(!F(i[0])||!F(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 D},enumerable:!1,configurable:!0}),t}(),X=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.")},K=function(){function t(t){if(!G(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,o;if("MultiLineString"!==t.type||!G(t.coordinates))return!1;try{for(var i=X(t.coordinates),a=i.next();!a.done;a=i.next()){var s=a.value;try{for(var u=(r=void 0,X(s)),c=u.next();!c.done;c=u.next()){var l=c.value;if(!F(l[0])||!F(l[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{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return R},enumerable:!1,configurable:!0}),t}(),Z=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.")},tt=function(){function t(t){var e,n;if(!G(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=Z(t),o=r.next();!o.done;o=r.next()){var i=o.value;if(!(i instanceof z))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,a;if("MultiPolygon"!==t.type||!G(t.coordinates))return!1;try{for(var s=Z(t.coordinates),u=s.next();!u.done;u=s.next()){var c=u.value;try{for(var l=(r=void 0,Z(c)),f=l.next();!f.done;f=l.next()){var d=f.value;try{for(var p=(i=void 0,Z(d)),h=p.next();!h.done;h=p.next()){var y=h.value;if(!F(y[0])||!F(y[1]))return!1}}catch(t){i={error:t}}finally{try{h&&!h.done&&(a=p.return)&&a.call(p)}finally{if(i)throw i.error}}}}catch(t){r={error:t}}finally{try{f&&!f.done&&(o=l.return)&&o.call(l)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=s.return)&&n.call(s)}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,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.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 a},nt=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 f:o=new St(i.coordinates[0],i.coordinates[1]);break;case d:o=new Q(i.coordinates.map(function(t){return new St(t[0],t[1])}));break;case p:o=new z(i.coordinates.map(function(t){return new Q(t.map(function(t){var e=et(t,2),n=e[0],r=e[1];return new St(n,r)}))}));break;case h:o=new Y(i.coordinates.map(function(t){return new St(t[0],t[1])}));break;case y:o=new K(i.coordinates.map(function(t){return new Q(t.map(function(t){var e=et(t,2),n=e[0],r=e[1];return new St(n,r)}))}));break;case m:o=new tt(i.coordinates.map(function(t){return new z(t.map(function(t){return new Q(t.map(function(t){var e=et(t,2),n=e[0],r=e[1];return new St(n,r)}))}))}));break;case v:o=i;break;case l:case"Array":o=t.formatField(i);break;case b:o=new Date(i.$date);break;default:o=i}Array.isArray(r)?r.push(o):r[n]=o}),r},t.whichType=function(t){var e=Object.prototype.toString.call(t).slice(8,-1);return e===v?v:(e===l&&(t.$date?e=b:St.validate(t)?e=f:Q.validate(t)?e=d:z.validate(t)?e=p:Y.validate(t)?e=h:K.validate(t)?e=y:tt.validate(t)&&(e=m)),e)},t.generateDocId=function(){for(var t="",e=0;e<24;e++)t+="ABCDEFabcdef0123456789".charAt(Math.floor(22*Math.random()));return t},t}(),rt={code:"INVALID_PARAM",message:"Invalid request param"},ot="DATABASE_TRANSACTION_CONFLICT",it={code:"DATABASE_REQUEST_FAILED",message:"database request failed"};const at=(st={EJSON:()=>t.EJSON},ut={},r.d(ut,st),ut);var st,ut,ct=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)}}(),lt=function(){return lt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},lt.apply(this,arguments)};function ft(t,e){if("function"!=typeof e)return t;t.then(function(t){return e(0,t)},function(t){return e(t)})}var dt={};function pt(t){if(!Ne.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return dt[e]||(dt[e]=new Ne.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:Ne.createRequest(t.config)}}})),dt[e]}var ht=function(t){return void 0!==t.timeout?{timeout:t.timeout}:{}},yt=function(t){if(!$(t))return t;for(var e in t)void 0===t[e]?delete t[e]:$(t[e])&&(t[e]=yt(t[e]));return t},mt=function(t){return t=yt(t),at.EJSON.stringify(t,{relaxed:!1})},vt=function(t){function e(e){var n=t.call(this,e.message)||this;return n.code=e.code,n.message=e.message,n}return ct(e,t),e}(Error),bt=function(t){return new vt(t)};function wt(t,e){if(!1===t)return e;throw bt(lt({},e))}var gt,_t=function(){return _t=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},_t.apply(this,arguments)},Ot=["limit","offset","projection","order","multiple","timeout","raw"],Et=function(){function t(){}return t.isGeopoint=function(t,e){if("Number"!==nt.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+a.IntergerError);return!0},t.mustBeBoolean=function(t,e){if("boolean"!=typeof e)throw new Error(t+a.BooleanError);return!0},t.isProjection=function(t,e){if("object"!==U(e))throw bt(_t(_t({},rt),{message:"".concat(t," projection must be an object")}));for(var n in e){var r=e[n];if("number"===U(r)){if(0!==r&&1!==r)throw bt(_t(_t({},rt),{message:"if the value in projection is of number, it must be 0 or 1"}))}else if("object"!==U(r))throw bt(_t(_t({},rt),{message:"invalid projection"}))}return!0},t.isOrder=function(t,e){if("object"!==U(e))throw bt(_t(_t({},rt),{message:"".concat(t," order must be an object")}));for(var n in e){var r=e[n];if(1!==r&&-1!==r)throw bt(_t(_t({},rt),{message:"order value must be 1 or -1"}))}return!0},t.isFieldOrder=function(t){if(-1===w.indexOf(t))throw new Error(a.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===g.indexOf(t))throw new Error(a.OpStrError);return!0},t.isCollName=function(t){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(t))throw new Error(a.CollNameError);return!0},t.isDocID=function(t){if(!/^([a-fA-F0-9]){24}$/.test(t))throw new Error(a.DocIDError);return!0},t.isValidOptions=function(e){if(void 0===e&&(e={}),"object"!==U(e))throw bt(_t(_t({},rt),{message:"options must be an object"}));var n=Object.keys(e);for(var r in n)if(Ot.indexOf(n[r])<0)throw bt(_t(_t({},rt),{message:"".concat(n[r]," is invalid options key")}));var o=e,i=o.limit,a=o.offset,s=o.projection,u=o.order,c=e.multiple;return void 0!==i&&t.isInteger("limit",i),void 0!==a&&t.isInteger("offset",a),void 0!==s&&t.isProjection("projection",s),void 0!==u&&t.isOrder("order",u),void 0!==c&&t.mustBeBoolean("multiple",c),void 0!==e.timeout&&t.isInteger("timeout",e.timeout),!0},t.isValidAggregation=function(t){if(1!==Object.keys(t).length)throw bt(_t(_t({},rt),{message:"aggregation stage must have one key"}));return!0},t.isCentersPhere=function(e){if(Array.isArray(e)&&2===e.length){if("object"===U(e[0])&&e[0]._internalType===q&&"number"==typeof e[1])return!0;if(Array.isArray(e[0])&&2===e[0].length){var n=e[0][0],r=e[0][1];if(t.isGeopoint("longitude",n),t.isGeopoint("latitude",r),"number"==typeof e[1])return!0}}throw new Error("".concat(a.CentersPhereError))},t}(),St=function(){function t(t,e){Et.isGeopoint("longitude",t),Et.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&&G(t.coordinates)&&Et.isGeopoint("longitude",t.coordinates[0])&&Et.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return q},enumerable:!1,configurable:!0}),t}();!function(t){t.SET="set",t.REMOVE="remove",t.INC="inc",t.MUL="mul",t.PUSH="push",t.PULL="pull",t.PULL_ALL="pullAll",t.POP="pop",t.SHIFT="shift",t.UNSHIFT="unshift",t.ADD_TO_SET="addToSet",t.BIT="bit",t.RENAME="rename",t.MAX="max",t.MIN="min"}(gt||(gt={}));var It,Nt=function(){function t(t,e,n){this._internalType=T,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||P}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function Pt(t){return t&&t instanceof Nt&&t._internalType===T}!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(It||(It={}));var Tt=function(){function t(t,e,n){if(this._internalType=A,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||P,this.fieldName!==P)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,o=e.length;r<o;r++)(jt(i=e[r])||Ct(i))&&(e[r]=i._setFieldName(this.fieldName))}else{var i;(jt(i=e)||Ct(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(It.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(It.OR,r,this.fieldName)},t}();function jt(t){return t&&t instanceof Tt&&t._internalType===A}var At,qt=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"}(At||(At={}));var xt=function(t){function e(e,n,r){var o=t.call(this,e,n,r)||this;return o.operator=e,o._internalType=j,o}return qt(e,t),e.prototype.toJSON=function(){var t,e,n;switch(this.operator){case At.IN:case At.NIN:return(t={})["$"+this.operator]=this.operands,t;case At.NEQ:return(e={}).$ne=this.operands[0],e;default:return(n={})["$"+this.operator]=this.operands[0],n}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(At.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(At.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(At.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(At.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(At.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(At.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(At.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(At.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof St))throw new TypeError('"geometry" must be of type Point. Received type '.concat(typeof t.geometry));if(void 0!==t.maxDistance&&!F(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '.concat(typeof t.maxDistance));if(void 0!==t.minDistance&&!F(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '.concat(typeof t.minDistance));var n=new e(At.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof tt||t.geometry instanceof z||Et.isCentersPhere(t.centerSphere)))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(At.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof St||t.geometry instanceof Q||t.geometry instanceof z||t.geometry instanceof Y||t.geometry instanceof K||t.geometry instanceof tt))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(At.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(Tt);function Ct(t){return t&&t instanceof xt&&t._internalType===j}function Dt(t){return Ct(t)}var Rt={};for(var Lt in At)Rt[Lt]="$"+Lt;for(var Lt in It)Rt[Lt]="$"+Lt;for(var Lt in gt)Rt[Lt]="$"+Lt;function Mt(t){return Rt[t]||"$"+t}Rt[At.NEQ]="$ne",Rt[gt.REMOVE]="$unset",Rt[gt.SHIFT]="$pop",Rt[gt.UNSHIFT]="$push";var kt=function(){return kt=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},kt.apply(this,arguments)},Jt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.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 a},Ut=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 $t(t){return Ft(t,[t])}function Ft(t,e){if(!H(t)){if(W(t))return t;if(B(t))return{$regularExpression:{pattern:t.source,options:t.flags}};if(G(t))return t.map(function(t){if(e.indexOf(t)>-1)throw new Error("Cannot convert circular structure to JSON");return Ft(t,Ut(Ut([],Jt(e),!1),[t],!1))});if($(t)){var n=kt({},t),r={};for(var o in n){if(e.indexOf(n[o])>-1)throw new Error("Cannot convert circular structure to JSON");void 0!==n[o]&&(r[o]=Ft(n[o],Ut(Ut([],Jt(e),!1),[n[o]],!1)))}return r}return t}switch(t._internalType){case q:return t.toJSON();case M:case k:case J:return t.parse();default:return t.toJSON?t.toJSON():t}}var Gt=function(){return Gt=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},Gt.apply(this,arguments)},Wt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.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 a},Bt=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Ht(t,e,n,r){var o=Gt({},t);for(var i in t)if(!/^\$/.test(i)){var a=t[i];if(void 0!==a){if(a&&$(a)&&!e(a)){if(r.indexOf(a)>-1)throw new Error("Cannot convert circular structure to JSON");var s=Ht(a,e,Bt(Bt([],Wt(n),!1),[i],!1),Bt(Bt([],Wt(r),!1),[a],!1));o[i]=s;var u=!1;for(var c in s)/^\$/.test(c)?u=!0:(o["".concat(i,".").concat(c)]=s[c],delete o[i][c]);u||delete o[i]}}else delete o[i]}return o}function Qt(t){return Ht(t,zt,[],[t])}function Vt(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?G(t[r])?t[r].push(e[r]):$(t[r])?$(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is ".concat(U(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(U(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]}function zt(t){return H(t)||W(t)||B(t)}function Yt(t){return $t(t)}var Xt=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.encodeEJSON=function(e,n){var r=new t;return mt(n?e:r.encodeUpdate(e))},t.prototype.encodeUpdate=function(t){return Pt(t)?this.encodeUpdateCommand(t):"object"===U(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===P)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case gt.PUSH:case gt.PULL:case gt.PULL_ALL:case gt.POP:case gt.SHIFT:case gt.UNSHIFT:case gt.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,o,i=Mt(t.operator);return t.operator===gt.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,a,s,u,c,l,f=Mt(t.operator);switch(t.operator){case gt.PUSH:var d=void 0;return d=G(t.operands)?{$each:t.operands.map(Yt)}:t.operands,(e={})[f]=((n={})[t.fieldName]=d,n),e;case gt.UNSHIFT:return d={$each:t.operands.map(Yt),$position:0},(r={})[f]=((o={})[t.fieldName]=d,o),r;case gt.POP:return(i={})[f]=((a={})[t.fieldName]=1,a),i;case gt.SHIFT:return(s={})[f]=((u={})[t.fieldName]=-1,u),s;default:return(c={})[f]=((l={})[t.fieldName]=Yt(t.operands),l),c}},t.prototype.encodeUpdateObject=function(t){var e=Qt(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(Pt(r))e[n]=r._setFieldName(n),Vt(e,this.encodeUpdateCommand(e[n]),n);else{e[n]=r=Yt(r);var o=new Nt(gt.SET,[r],n);Vt(e,this.encodeUpdateCommand(o),n)}}return e},t}(),Kt=function(){return Kt=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},Kt.apply(this,arguments)},Zt=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())})},te=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},ee=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){return pt(i._db).watch(Kt(Kt({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify({_id:i.id})}))},this._db=t,this._coll=e,this.id=r,this._transactionId=o,this.request=Ne.createRequest(this._db.config),this._apiOptions=n}return t.prototype.create=function(t,e){return ft(this._create(t),e)},t.prototype._create=function(t){return Zt(this,void 0,void 0,function(){var e,n,r;return te(this,function(o){switch(o.label){case 0:return!(e=Array.isArray(t))&&this.id&&(t._id=this.id),n={collectionName:this._coll,data:e?t.map(function(t){return mt($t(t))}):[mt($t(t))],transactionId:this._transactionId},[4,this.request.send("database.insertDocument",n,ht(this._apiOptions))];case 1:return(r=o.sent()).code?[2,r]:this._transactionId?[2,{inserted:1,ok:1,id:r.data.insertedIds[0],requestId:r.requestId}]:e?[2,{ids:r.data&&r.data.insertedIds||[],requestId:r.requestId}]:[2,{id:r.data.insertedIds[0],requestId:r.requestId}]}})})},t.prototype.set=function(t,e){return ft(this._set(t),e)},t.prototype._set=function(t){return Zt(this,void 0,void 0,function(){var e,n,r,o;return te(this,function(i){switch(i.label){case 0:return this.id?t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,wt(this._db.config.throwOnCode,Kt(Kt({},rt),{message:"不能更新_id的值"}))]:(e=!1,n=function(t){if("object"==typeof t)for(var r in t)t[r]instanceof Nt?e=!0:"object"==typeof t[r]&&n(t[r])},n(t),e?[2,wt(this._db.config.throwOnCode,Kt(Kt({},it),{message:"update operator complicit"}))]:(r={collectionName:this._coll,queryType:c.DOC,data:mt($t(t)),transactionId:this._transactionId,multi:!1,merge:!1,upsert:!0},this.id&&(r.query=mt({_id:this.id})),[4,this.request.send("database.modifyDocument",r,ht(this._apiOptions))])):[2,wt(this._db.config.throwOnCode,Kt(Kt({},rt),{message:"参数必需是非空对象"}))]:[2,wt(this._db.config.throwOnCode,Kt(Kt({},rt),{message:"docId不能为空"}))];case 1:return(o=i.sent()).code?[2,o]:this._transactionId?[2,{updated:o.data.updated,upserted:[{_id:o.data.upsert_id}],requestId:o.requestId}]:[2,{updated:o.data.updated,upsertedId:o.data.upsert_id,requestId:o.requestId}]}})})},t.prototype.update=function(t,e){return ft(this._update(t),e)},t.prototype._update=function(t){return Zt(this,void 0,void 0,function(){var e,n,r;return te(this,function(o){switch(o.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,wt(this._db.config.throwOnCode,Kt(Kt({},rt),{message:"不能更新_id的值"}))]:(e=mt({_id:this.id}),n={collectionName:this._coll,transactionId:this._transactionId,data:Xt.encodeEJSON(t,this._apiOptions.raw||!1),query:e,queryType:c.DOC,multi:!1,merge:!0,upsert:!1},[4,this.request.send("database.modifyDocument",n,ht(this._apiOptions))]):[2,wt(this._db.config.throwOnCode,Kt(Kt({},rt),{message:"参数必需是非空对象"}))];case 1:return(r=o.sent()).code?[2,r]:[2,{updated:r.data.updated,requestId:r.requestId}]}})})},t.prototype.delete=function(t){return this.remove(t)},t.prototype.remove=function(t){return ft(this._remove(),t)},t.prototype._remove=function(){return Zt(this,void 0,void 0,function(){var t,e,n;return te(this,function(r){switch(r.label){case 0:return t=mt({_id:this.id}),e={collectionName:this._coll,transactionId:this._transactionId,query:t,queryType:c.DOC,multi:!1},[4,this.request.send("database.removeDocument",e,ht(this._apiOptions))];case 1:return(n=r.sent()).code?[2,n]:[2,{deleted:n.data.deleted,requestId:n.requestId}]}})})},t.prototype.get=function(t){return ft(this._get(),t)},t.prototype._get=function(){return Zt(this,void 0,void 0,function(){var t,e,n,r,o,i;return te(this,function(a){switch(a.label){case 0:return t=mt({_id:this.id}),e=this._apiOptions.projection,n={collectionName:this._coll,query:t,transactionId:this._transactionId,queryType:c.DOC,multi:!1},e&&(n.projection=mt(e)),[4,this.request.send("database.getDocument",n,ht(this._apiOptions))];case 1:return(r=a.sent()).code?[2,r]:(o=r.data.list.map(function(t){return at.EJSON.parse(t)}),i=nt.formatResDocumentData(o),this._transactionId?[2,{data:i[0]||null,requestId:r.requestId}]:[2,{data:i,requestId:r.requestId}])}})})},t.prototype.field=function(e){var n={};for(var r in e)"boolean"==typeof e[r]&&(n[r]=!0===e[r]?1:0),"number"==typeof e[r]&&(n[r]=e[r]>0?1:0),"object"==typeof e[r]&&(n[r]=e[r]);var o=Kt({},this._apiOptions);return o.projection=n,new t(this._db,this._coll,o,this.id,this._transactionId)},t}(),ne=function(){function t(){}return t.encode=function(t){return(new re).encodeQuery(t)},t.encodeEJSON=function(t,e){var n=new re;return mt(e?t:n.encodeQuery(t))},t}(),re=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n,r,o;return zt(t)?jt(t)?this.encodeLogicCommand(t):Ct(t)?this.encodeQueryCommand(t):B(t)?((n={})[e]=this.encodeRegExp(t),n):W(t)?((r={})[e]=Yt(t),r):((o={})[e]=this.encodeQueryObject(t),o):$(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regularExpression:{pattern:t.source,options:t.flags}}},t.prototype.encodeLogicCommand=function(t){var e,n,r,o,i,a,s,u=this;switch(t.operator){case It.NOR:case It.AND:case It.OR:var c=Mt(t.operator),l=t.operands.map(function(e){return u.encodeQuery(e,t.fieldName)});return(e={})[c]=l,e;case It.NOT:c=Mt(t.operator);var f=t.operands[0];return B(f)?((n={})[t.fieldName]=((r={})[c]=this.encodeRegExp(f),r),n):(l=this.encodeQuery(f)[t.fieldName],(o={})[t.fieldName]=((i={})[c]=l,i),o);default:if(c=Mt(t.operator),1===t.operands.length){var d=this.encodeQuery(t.operands[0]);return(a={})[c]=d,a}return l=t.operands.map(this.encodeQuery.bind(this)),(s={})[c]=l,s}},t.prototype.encodeQueryCommand=function(t){return Dt(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,o,i,a,s,u,c,l,f;if(t.fieldName===P)throw new Error("Cannot encode a comparison command with unset field name");var d=Mt(t.operator);switch(t.operator){case At.EQ:case At.NEQ:case At.LT:case At.LTE:case At.GT:case At.GTE:case At.ELEM_MATCH:case At.EXISTS:case At.SIZE:case At.MOD:return(e={})[t.fieldName]=((n={})[d]=Yt(t.operands[0]),n),e;case At.IN:case At.NIN:case At.ALL:return(r={})[t.fieldName]=((o={})[d]=Yt(t.operands),o),r;case At.GEO_NEAR:var p=t.operands[0];return(i={})[t.fieldName]={$nearSphere:{$geometry:p.geometry.toJSON(),$maxDistance:p.maxDistance,$minDistance:p.minDistance}},i;case At.GEO_WITHIN:if((p=t.operands[0]).centerSphere){Et.isCentersPhere(p.centerSphere);var h=p.centerSphere;return h[0]._internalType===q?((a={})[t.fieldName]={$geoWithin:{$centerSphere:[h[0].toJSON().coordinates,h[1]]}},a):((s={})[t.fieldName]={$geoWithin:{$centerSphere:p.centerSphere}},s)}return(u={})[t.fieldName]={$geoWithin:{$geometry:p.geometry.toJSON()}},u;case At.GEO_INTERSECTS:return p=t.operands[0],(c={})[t.fieldName]={$geoIntersects:{$geometry:p.geometry.toJSON()}},c;default:return(l={})[t.fieldName]=((f={})[d]=Yt(t.operands[0]),f),l}},t.prototype.encodeQueryObject=function(t){var e=Qt(t);for(var n in e){var r=e[n];if(jt(r)){e[n]=r._setFieldName(n);var o=this.encodeLogicCommand(e[n]);this.mergeConditionAfterEncode(e,o,n)}else Dt(r)?(e[n]=r._setFieldName(n),o=this.encodeComparisonCommand(e[n]),this.mergeConditionAfterEncode(e,o,n)):zt(r)&&(e[n]=Yt(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?G(t[r])?t[r]=t[r].concat(e[r]):$(t[r])?$(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is ".concat(U(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(U(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),oe=function(){return oe=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},oe.apply(this,arguments)},ie=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())})},ae=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},se=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){var e=pt(i._db),n=i._apiOptions,r=n.limit,o=n.order;return e.watch(oe(oe({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify(i._fieldFilters),limit:r,orderBy:o?o.reduce(function(t,e){return t[e.field]=e.direction,t},{}):void 0}))},this._db=t,this._coll=e,this._fieldFilters=n,this._apiOptions=r||{},this._request=Ne.createRequest(this._db.config),this._transactionId=o}return t.prototype.get=function(t){return ft(this._get(),t)},t.prototype._get=function(){return ie(this,void 0,void 0,function(){var t,e,n,r,o,i,a,s,u;return ae(this,function(l){switch(l.label){case 0:return t=this._apiOptions.order,e={collectionName:this._coll,queryType:c.WHERE,transactionId:this._transactionId},this._fieldFilters&&(e.query=this._fieldFilters),t&&(e.order=mt(t)),(n=this._apiOptions.offset)&&(e.offset=n),r=this._apiOptions.limit,e.limit=r?r<1e3?r:1e3:100,(o=this._apiOptions.projection)&&(e.projection=mt(o)),[4,this._request.send("database.getDocument",e,ht(this._apiOptions))];case 1:return(i=l.sent()).code?[2,i]:(a=i.data.list.map(function(t){return at.EJSON.parse(t)}),s=nt.formatResDocumentData(a),u={data:s,requestId:i.requestId},i.total&&(u.total=i.total),i.limit&&(u.limit=i.limit),i.offset&&(u.offset=i.offset),[2,u])}})})},t.prototype.count=function(t){return ft(this._count(),t)},t.prototype._count=function(){return ie(this,void 0,void 0,function(){var t,e;return ae(this,function(n){switch(n.label){case 0:return t={collectionName:this._coll,queryType:c.WHERE},this._fieldFilters&&(t.query=this._fieldFilters),[4,this._request.send("database.calculateDocument",t,ht(this._apiOptions))];case 1:return(e=n.sent()).code?[2,e]:[2,{requestId:e.requestId,total:e.data.total}]}})})},t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(a.QueryParamTypeError);var n=Object.keys(e),r=n.some(function(t){return void 0!==e[t]});if(n.length&&!r)throw Error(a.QueryParamValueError);return new t(this._db,this._coll,ne.encodeEJSON(e,this._apiOptions.raw||!1),this._apiOptions,this._transactionId)},t.prototype.options=function(e){return Et.isValidOptions(e),new t(this._db,this._coll,this._fieldFilters,e,this._transactionId)},t.prototype.orderBy=function(e,n){var r;Et.isFieldPath(e),Et.isFieldOrder(n);var o=((r={})[e]="desc"===n?-1:1,r),i=this._apiOptions.order||{},a=Object.assign({},this._apiOptions,{order:Object.assign({},i,o)});return new t(this._db,this._coll,this._fieldFilters,a,this._transactionId)},t.prototype.limit=function(e){Et.isInteger("limit",e);var n=oe({},this._apiOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,n,this._transactionId)},t.prototype.skip=function(e){Et.isInteger("offset",e);var n=oe({},this._apiOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,n,this._transactionId)},t.prototype.update=function(t,e){return ft(this._update(t),e)},t.prototype._update=function(t){return ie(this,void 0,void 0,function(){var e,n,r,o;return ae(this,function(i){switch(i.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,wt(this._db.config.throwOnCode,oe(oe({},rt),{message:"不能更新_id的值"}))]:(e=this._apiOptions.multiple,n=void 0===e||e,r={collectionName:this._coll,queryType:c.WHERE,multi:n,merge:!0,upsert:!1,data:Xt.encodeEJSON(t,this._apiOptions.raw||!1)},this._transactionId&&(r.transactionId=this._transactionId),this._fieldFilters&&(r.query=this._fieldFilters),[4,this._request.send("database.modifyDocument",r,ht(this._apiOptions))]):[2,wt(this._db.config.throwOnCode,oe(oe({},rt),{message:"参数必需是非空对象"}))];case 1:return(o=i.sent()).code?[2,o]:[2,{requestId:o.requestId,updated:o.data.updated,upsertId:o.data.upsert_id}]}})})},t.prototype.field=function(e){var n={};for(var r in e)"boolean"==typeof e[r]&&(n[r]=!0===e[r]?1:0),"number"==typeof e[r]&&(n[r]=e[r]>0?1:0),"object"==typeof e[r]&&(n[r]=e[r]);var o=oe({},this._apiOptions);return o.projection=n,new t(this._db,this._coll,this._fieldFilters,o,this._transactionId)},t.prototype.remove=function(t){return ft(this._remove(),t)},t.prototype._remove=function(){return ie(this,void 0,void 0,function(){var t,e,n,r,o,i,a,s,u;return ae(this,function(l){switch(l.label){case 0:return t=this._apiOptions,e=t.offset,n=t.limit,r=t.projection,o=t.order,void 0===e&&void 0===n&&void 0===r&&void 0===o||console.warn("`offset`, `limit`, `projection`, `orderBy` are not supported in remove() operation"),i=this._apiOptions.multiple,a=void 0===i||i,s={collectionName:this._coll,query:this._fieldFilters,queryType:c.WHERE,multi:a},this._transactionId&&(s.transactionId=this._transactionId),[4,this._request.send("database.removeDocument",s,ht(this._apiOptions))];case 1:return(u=l.sent()).code?[2,u]:[2,{requestId:u.requestId,deleted:u.data.deleted}]}})})},t.prototype.updateAndReturn=function(t){return ie(this,void 0,void 0,function(){var e,n;return ae(this,function(r){switch(r.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,wt(this._db.config.throwOnCode,oe(oe({},rt),{message:"不能更新_id的值"}))]:(e={collectionName:this._coll,queryType:c.WHERE,data:Xt.encodeEJSON(t,!1)},this._transactionId&&(e.transactionId=this._transactionId),this._fieldFilters&&(e.query=this._fieldFilters),[4,this._request.send("database.modifyAndReturnDoc",e,ht(this._apiOptions))]):[2,wt(this._db.config.throwOnCode,oe(oe({},rt),{message:"参数必需是非空对象"}))];case 1:return(n=r.sent()).code?[2,n]:[2,{requestId:n.requestId,updated:n.data.updated,doc:n.data.doc&&at.EJSON.parse(n.data.doc)}]}})})},t}(),ue=function(){function t(t,e,n){var r=this;this._stages=[],t&&e&&(this._db=t,this._request=Ne.createRequest(this._db.config),this._collectionName=e,n&&n.length>0&&n.forEach(function(t){Et.isValidAggregation(t);var e=Object.keys(t)[0];r._pipe(e,t[e],!0)}))}return t.prototype.end=function(){return t=this,e=void 0,r=function(){var t;return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}(this,function(e){switch(e.label){case 0:if(!this._collectionName||!this._db)throw new Error("Aggregation pipeline cannot send request");return[4,this._request.send("database.aggregateDocuments",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:t.data.list.map(at.EJSON.parse)}]:[2,t]}})},new((n=void 0)||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())});var t,e,n,r},t.prototype.unwrap=function(){return this._stages},t.prototype.done=function(){return this._stages.map(function(t){var e,n=t.stageKey,r=t.stageValue;return(e={})[n]=JSON.parse(r),e})},t.prototype._pipe=function(t,e,n){void 0===n&&(n=!1);var r;return r="object"===U(e)?mt(e):JSON.stringify(e),this._stages.push({stageKey:n?t:"$".concat(t),stageValue:r}),this},t.prototype.addFields=function(t){return this._pipe("addFields",t)},t.prototype.bucket=function(t){return this._pipe("bucket",t)},t.prototype.bucketAuto=function(t){return this._pipe("bucketAuto",t)},t.prototype.count=function(t){return this._pipe("count",t)},t.prototype.geoNear=function(t){return t.query&&(t.query=ne.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new St(t.near.longitude,t.near.latitude).toJSON()),this._pipe("geoNear",t)},t.prototype.group=function(t){return this._pipe("group",t)},t.prototype.limit=function(t){return this._pipe("limit",t)},t.prototype.match=function(t){return this._pipe("match",ne.encode(t))},t.prototype.project=function(t){return this._pipe("project",t)},t.prototype.lookup=function(t){return this._pipe("lookup",t)},t.prototype.replaceRoot=function(t){return this._pipe("replaceRoot",t)},t.prototype.sample=function(t){return this._pipe("sample",t)},t.prototype.skip=function(t){return this._pipe("skip",t)},t.prototype.sort=function(t){return this._pipe("sort",t)},t.prototype.sortByCount=function(t){return this._pipe("sortByCount",t)},t.prototype.unwind=function(t){return this._pipe("unwind",t)},t}();const ce=ue;var le=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)}}(),fe=function(t){function e(e,n,r,o){var i=t.call(this,e,n,"",r,o)||this;return o&&(i._transactionId=o),i}return le(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!1,configurable:!0}),e.prototype.doc=function(t){if("string"!=typeof t&&"number"!=typeof t)throw new Error("docId必须为字符串或数字");return new ee(this._db,this._coll,this._apiOptions,t,this._transactionId)},e.prototype.add=function(t,e){return ft(this._add(t),e)},e.prototype._add=function(t){return e=this,n=void 0,o=function(){var e,n,r;return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}(this,function(o){switch(o.label){case 0:return e=t,G(t)||(e=[t]),e=e.map(function(t){return mt($t(t))}),n={collectionName:this._coll,data:e},this._transactionId&&(n.transactionId=this._transactionId),[4,this._request.send("database.insertDocument",n,ht(this._apiOptions))];case 1:return(r=o.sent()).code?[2,r]:G(t)?[2,{ids:r.data.insertedIds,requestId:r.requestId}]:this._transactionId?[2,{inserted:1,ok:1,id:r.data.insertedIds[0],requestId:r.requestId}]:[2,{id:r.data.insertedIds[0],requestId:r.requestId}]}})},new((r=void 0)||(r=Promise))(function(t,i){function a(t){try{u(o.next(t))}catch(t){i(t)}}function s(t){try{u(o.throw(t))}catch(t){i(t)}}function u(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r(function(t){t(n)})).then(a,s)}u((o=o.apply(e,n||[])).next())});var e,n,r,o},e.prototype.aggregate=function(t){return void 0===t&&(t=[]),new ce(this._db,this._coll,this._apiOptions.raw?t:[])},e.prototype.options=function(t){return Et.isValidOptions(t),new e(this._db,this._coll,t,this._transactionId)},e}(se),de={eq:function(t){return new xt(At.EQ,[t])},neq:function(t){return new xt(At.NEQ,[t])},lt:function(t){return new xt(At.LT,[t])},lte:function(t){return new xt(At.LTE,[t])},gt:function(t){return new xt(At.GT,[t])},gte:function(t){return new xt(At.GTE,[t])},in:function(t){return new xt(At.IN,t)},nin:function(t){return new xt(At.NIN,t)},all:function(t){return new xt(At.ALL,t)},elemMatch:function(t){return new xt(At.ELEM_MATCH,[t])},exists:function(t){return new xt(At.EXISTS,[t])},size:function(t){return new xt(At.SIZE,[t])},mod:function(){return new xt(At.MOD,1==arguments.length?[arguments[0]]:2==arguments.length?[[arguments[0],arguments[1]]]:arguments)},geoNear:function(t){return new xt(At.GEO_NEAR,[t])},geoWithin:function(t){return new xt(At.GEO_WITHIN,[t])},geoIntersects:function(t){return new xt(At.GEO_INTERSECTS,[t])},and:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=G(arguments[0])?arguments[0]:Array.from(arguments);return new Tt(It.AND,n)},nor:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=G(arguments[0])?arguments[0]:Array.from(arguments);return new Tt(It.NOR,n)},or:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=G(arguments[0])?arguments[0]:Array.from(arguments);return new Tt(It.OR,n)},not:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=G(arguments[0])?arguments[0]:Array.from(arguments);return new Tt(It.NOT,n)},set:function(t){return new Nt(gt.SET,[t])},remove:function(){return new Nt(gt.REMOVE,[])},inc:function(t){return new Nt(gt.INC,[t])},mul:function(t){return new Nt(gt.MUL,[t])},push:function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if($(e[0])&&e[0].hasOwnProperty("each")){t={};var r=e[0];void 0!==r.each&&(t.$each=r.each),void 0!==r.position&&(t.$position=r.position),void 0!==r.sort&&(t.$sort=r.sort),void 0!==r.slice&&(t.$slice=r.slice)}else t=G(e[0])?e[0]:Array.from(e);return new Nt(gt.PUSH,t)},pull:function(t){return new Nt(gt.PULL,t)},pullAll:function(t){return new Nt(gt.PULL_ALL,t)},pop:function(){return new Nt(gt.POP,[])},shift:function(){return new Nt(gt.SHIFT,[])},unshift:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=G(arguments[0])?arguments[0]:Array.from(arguments);return new Nt(gt.UNSHIFT,n)},addToSet:function(t){return new Nt(gt.ADD_TO_SET,t)},rename:function(t){return new Nt(gt.RENAME,[t])},bit:function(t){return new Nt(gt.BIT,[t])},max:function(t){return new Nt(gt.MAX,[t])},min:function(t){return new Nt(gt.MIN,[t])},expr:function(t){return{$expr:t}},jsonSchema:function(t){return{$jsonSchema:t}},text:function(t){return function(t){return"string"===U(t)}(t)?{$search:t.search}:{$search:t.search,$language:t.language,$caseSensitive:t.caseSensitive,$diacriticSensitive:t.diacriticSensitive}},aggregate:{pipeline:function(){return new ce},abs:function(t){return new pe("abs",t)},add:function(t){return new pe("add",t)},ceil:function(t){return new pe("ceil",t)},divide:function(t){return new pe("divide",t)},exp:function(t){return new pe("exp",t)},floor:function(t){return new pe("floor",t)},ln:function(t){return new pe("ln",t)},log:function(t){return new pe("log",t)},log10:function(t){return new pe("log10",t)},mod:function(t){return new pe("mod",t)},multiply:function(t){return new pe("multiply",t)},pow:function(t){return new pe("pow",t)},sqrt:function(t){return new pe("sqrt",t)},subtract:function(t){return new pe("subtract",t)},trunc:function(t){return new pe("trunc",t)},arrayElemAt:function(t){return new pe("arrayElemAt",t)},arrayToObject:function(t){return new pe("arrayToObject",t)},concatArrays:function(t){return new pe("concatArrays",t)},filter:function(t){return new pe("filter",t)},in:function(t){return new pe("in",t)},indexOfArray:function(t){return new pe("indexOfArray",t)},isArray:function(t){return new pe("isArray",t)},map:function(t){return new pe("map",t)},range:function(t){return new pe("range",t)},reduce:function(t){return new pe("reduce",t)},reverseArray:function(t){return new pe("reverseArray",t)},size:function(t){return new pe("size",t)},slice:function(t){return new pe("slice",t)},zip:function(t){return new pe("zip",t)},and:function(t){return new pe("and",t)},not:function(t){return new pe("not",t)},or:function(t){return new pe("or",t)},cmp:function(t){return new pe("cmp",t)},eq:function(t){return new pe("eq",t)},gt:function(t){return new pe("gt",t)},gte:function(t){return new pe("gte",t)},lt:function(t){return new pe("lt",t)},lte:function(t){return new pe("lte",t)},neq:function(t){return new pe("ne",t)},cond:function(t){return new pe("cond",t)},ifNull:function(t){return new pe("ifNull",t)},switch:function(t){return new pe("switch",t)},dateFromParts:function(t){return new pe("dateFromParts",t)},dateFromString:function(t){return new pe("dateFromString",t)},dayOfMonth:function(t){return new pe("dayOfMonth",t)},dayOfWeek:function(t){return new pe("dayOfWeek",t)},dayOfYear:function(t){return new pe("dayOfYear",t)},isoDayOfWeek:function(t){return new pe("isoDayOfWeek",t)},isoWeek:function(t){return new pe("isoWeek",t)},isoWeekYear:function(t){return new pe("isoWeekYear",t)},millisecond:function(t){return new pe("millisecond",t)},minute:function(t){return new pe("minute",t)},month:function(t){return new pe("month",t)},second:function(t){return new pe("second",t)},hour:function(t){return new pe("hour",t)},week:function(t){return new pe("week",t)},year:function(t){return new pe("year",t)},literal:function(t){return new pe("literal",t)},mergeObjects:function(t){return new pe("mergeObjects",t)},objectToArray:function(t){return new pe("objectToArray",t)},allElementsTrue:function(t){return new pe("allElementsTrue",t)},anyElementTrue:function(t){return new pe("anyElementTrue",t)},setDifference:function(t){return new pe("setDifference",t)},setEquals:function(t){return new pe("setEquals",t)},setIntersection:function(t){return new pe("setIntersection",t)},setIsSubset:function(t){return new pe("setIsSubset",t)},setUnion:function(t){return new pe("setUnion",t)},concat:function(t){return new pe("concat",t)},dateToString:function(t){return new pe("dateToString",t)},indexOfBytes:function(t){return new pe("indexOfBytes",t)},indexOfCP:function(t){return new pe("indexOfCP",t)},split:function(t){return new pe("split",t)},strLenBytes:function(t){return new pe("strLenBytes",t)},strLenCP:function(t){return new pe("strLenCP",t)},strcasecmp:function(t){return new pe("strcasecmp",t)},substr:function(t){return new pe("substr",t)},substrBytes:function(t){return new pe("substrBytes",t)},substrCP:function(t){return new pe("substrCP",t)},toLower:function(t){return new pe("toLower",t)},toUpper:function(t){return new pe("toUpper",t)},meta:function(t){return new pe("meta",t)},addToSet:function(t){return new pe("addToSet",t)},avg:function(t){return new pe("avg",t)},first:function(t){return new pe("first",t)},last:function(t){return new pe("last",t)},max:function(t){return new pe("max",t)},min:function(t){return new pe("min",t)},push:function(t){return new pe("push",t)},stdDevPop:function(t){return new pe("stdDevPop",t)},stdDevSamp:function(t){return new pe("stdDevSamp",t)},sum:function(t){return new pe("sum",t)},let:function(t){return new pe("let",t)}},project:{slice:function(t){return new he("slice",t)},elemMatch:function(t){return new he("elemMatch",t)}}},pe=function(t,e){this["$"+t]=e},he=function(t,e){this["$"+t]=e},ye=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 M},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$tcb_server_date:{offset:this.offset}}},t}();function me(t){return new ye(t)}var ve=function(){function t(t){var e=t.regexp,n=t.options;if(!e)throw new TypeError("regexp must be a string");this.$regularExpression={pattern:e||"",options:n||""}}return t.prototype.parse=function(){return{$regularExpression:{pattern:this.$regularExpression.pattern,options:this.$regularExpression.options}}},Object.defineProperty(t.prototype,"_internalType",{get:function(){return k},enumerable:!1,configurable:!0}),t}();function be(t){return new ve(t)}var we=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())})},ge=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},_e=function(){function t(t){this._db=t,this._request=Ne.createRequest(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return t.prototype.init=function(){return we(this,void 0,void 0,function(){var t;return ge(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 fe(this._db,t,{},this._id)},t.prototype.getTransactionId=function(){return this._id},t.prototype.getRequestMethod=function(){return this._request},t.prototype.commit=function(){return we(this,void 0,void 0,function(){var t,e;return ge(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 we(this,void 0,void 0,function(){var e,n;return ge(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 Oe(){return we(this,void 0,void 0,function(){var t;return ge(this,function(e){switch(e.label){case 0:return[4,(t=new _e(this)).init()];case 1:return e.sent(),[2,t]}})})}function Ee(t,e){return void 0===e&&(e=3),we(this,void 0,void 0,function(){var n,r,o,i,a=this;return ge(this,function(s){switch(s.label){case 0:return s.trys.push([0,4,,10]),[4,(n=new _e(this)).init()];case 1:return s.sent(),[4,t(n)];case 2:if(r=s.sent(),!0===n.aborted)throw n.abortReason;return[4,n.commit()];case 3:return s.sent(),[2,r];case 4:if(o=s.sent(),!1===n.inited)throw o;return i=function(t){return we(a,void 0,void 0,function(){return ge(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:s.sent(),s.label=6;case 6:return o&&o.code===ot?[4,Ee.bind(this)(t,--e)]:[3,8];case 7:return[2,s.sent()];case 8:return[4,i(o)];case 9:return s.sent(),[3,10];case 10:return[2]}})})}var Se=function(){function t(t){var e=(void 0===t?{}:t).id,n=void 0===e?"":e;this.id=n}return Object.defineProperty(t.prototype,"_internalType",{get:function(){return J},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$oid:this.id}},t}();function Ie(t){return new Se(t)}var Ne=function(){function t(t){this.config=t,this.Geo=s,this.serverDate=me,this.command=de,this.RegExp=be,this.ObjectId=Ie,this.startTransaction=Oe,this.runTransaction=Ee,this.logicCommand=Tt,this.updateCommand=Nt,this.queryCommand=xt}return t.createRequest=function(e){var n=new t.reqClass(e),r=n.send;return n.send=function(t,n){for(var o=[],i=2;i<arguments.length;i++)o[i-2]=arguments[i];return n&&(e.instance&&(n.instance=e.instance),e.database&&(n.database=e.database)),r.call.apply(r,function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([this,t,n],function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.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 a}(o),!1))},n},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new fe(this,t)},t.prototype.createCollection=function(e){var n={collectionName:e};return t.createRequest(this.config).send("database.addCollection",n)},t}();var Pe="INVALID_OPERATION",Te="OPERATION_FAIL";const je=(t=>{var e={};return r.d(e,t),e})({AbstractSDKRequest:()=>e.AbstractSDKRequest,AbstractStorage:()=>e.AbstractStorage});var Ae=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)}}(),qe=function(){return qe=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},qe.apply(this,arguments)};function xe(t,e){console.warn("[".concat("@cloudbase/js-sdk","][").concat(t,"]:").concat(e))}var Ce=function(t){function e(e){var n=t.call(this,e.msg||e.message||"")||this;return n.code=e.code||"",n.requestId=e.requestId||"",Object.defineProperty(n,"message",{value:e.msg||e.message||"",enumerable:!0,writable:!0,configurable:!0}),n}return Ae(e,t),e}(Error),De=function(t){return new Ce(t)};function Re(t,e){return(e||De)(t)}var Le,Me=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)}}(),ke=function(){return ke=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},ke.apply(this,arguments)},Je=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())})},Ue=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};!function(t){function e(e){var n=t.call(this)||this,r=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=r||0,n.timeoutMsg=o||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}Me(e,t),e.prototype.get=function(t){return this.request(ke(ke({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(ke(ke({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(ke(ke({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t.data,n=t.file,r=t.name,o=t.method,i=t.headers,a=void 0===i?{}:i,s={post:"post",put:"put"}[null==o?void 0:o.toLowerCase()]||"put",u=new FormData;return"post"===s?(Object.keys(e).forEach(function(t){u.append(t,e[t])}),u.append("key",r),u.append("file",n),this.request(ke(ke({},t),{data:u,method:s}),this.restrictedMethods.includes("upload"))):this.request(ke(ke({},t),{method:"put",headers:a,body:n}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return Je(this,void 0,Promise,function(){var e,n,r,o;return Ue(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(ke(ke({},t),{headers:{},responseType:"blob"}))];case 1:return e=i.sent().data,n=window.URL.createObjectURL(new Blob([e])),r=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=n,o.setAttribute("download",r),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n),document.body.removeChild(o),[3,3];case 2:return i.sent(),[3,3];case 3:return[2,new Promise(function(e){e({statusCode:200,tempFilePath:t.url})})]}})})},e.prototype.fetch=function(t){var e;return Je(this,void 0,Promise,function(){var n,r,o,i,a,s,u,c,l,f,d,p,h,y=this;return Ue(this,function(m){switch(m.label){case 0:return n=new AbortController,r=t.url,o=t.enableAbort,i=void 0!==o&&o,a=t.stream,s=void 0!==a&&a,u=t.signal,c=t.timeout,l=t.shouldThrowOnError,f=void 0===l||l,d=null!=c?c:this.timeout,u&&(u.aborted&&n.abort(),u.addEventListener("abort",function(){return n.abort()})),p=null,i&&d&&(p=setTimeout(function(){console.warn(y.timeoutMsg),n.abort(new Error(y.timeoutMsg))},d)),[4,fetch(r,ke(ke({},t),{signal:n.signal})).then(function(t){return Je(y,void 0,void 0,function(){var e,n,r;return Ue(this,function(o){switch(o.label){case 0:return clearTimeout(p),f?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return r=(n=Promise).reject,[4,t.json()];case 2:e=r.apply(n,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}})})}).catch(function(t){return clearTimeout(p),Promise.reject(t)})];case 1:return h=m.sent(),[2,{data:s?h.body:(null===(e=h.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?h.json():h.text(),statusCode:h.status,header:h.headers,response:h}]}})})},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var r=String(t.method).toLowerCase()||"get";return new Promise(function(o){var i=t.url,a=t.headers,s=void 0===a?{}:a,u=t.data,c=t.responseType,l=t.withCredentials,f=t.body,d=t.onUploadProgress,p=function(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";return Object.keys(n).forEach(function(t){""===o?!r&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(n[t]))}),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)}("https:",i,"get"===r?u:{}),h=new XMLHttpRequest;h.open(r,p),c&&(h.responseType=c);var y,m,v,b=t.signal;b&&(b.aborted?h.abort():b.addEventListener("abort",function(){return h.abort()},{once:!0})),Object.keys(s).forEach(function(t){h.setRequestHeader(t,s[t])}),d&&h.upload.addEventListener("progress",d),h.onreadystatechange=function(){var t={};if(4===h.readyState){var e=h.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};e.forEach(function(t){var e=t.split(": "),r=e.shift().toLowerCase(),o=e.join(": ");n[r]=o}),t.header=n,t.statusCode=h.status;try{t.data="blob"===c?h.response:JSON.parse(h.responseText)}catch(e){t.data="blob"===c?h.response:h.responseText}clearTimeout(y),o(t)}},e&&n.timeout&&(y=setTimeout(function(){console.warn(n.timeoutMsg),h.abort()},n.timeout)),v=u,m="[object FormData]"===Object.prototype.toString.call(v)?u:"application/x-www-form-urlencoded"===s["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach(function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))}),e.join("&")}(u):f||(u?JSON.stringify(u):void 0),l&&(h.withCredentials=!0),h.send(m)})}}(je.AbstractSDKRequest),function(t){t.WEB="web",t.WX_MP="wx_mp"}(Le||(Le={}));var $e=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)}}(),Fe=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())})},Ge=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},We=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return $e(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(je.AbstractStorage);!function(){function t(t){this.keys={};var e=t.persistence,n=t.platformInfo,r=void 0===n?{}:n,o=t.keys,i=void 0===o?{}:o;this.platformInfo=r,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:(xe("INVALID_PARAMS","localStorage is not supported on current platform"),new We(e.root));case"none":return new We(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,n){if("async"!==this.mode){if(this.storage)try{var r={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(r))}catch(t){throw new Error(JSON.stringify({code:Te,msg:"[".concat("@cloudbase/js-sdk","][").concat(Te,"]setStore failed"),info:t}))}}else xe(Pe,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return Fe(this,void 0,void 0,function(){var r;return Ge(this,function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}})})},t.prototype.getStore=function(t,e){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var r=this.storage.getItem(t);return r&&r.indexOf(e)>=0?JSON.parse(r).content:""}xe(Pe,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return Fe(this,void 0,void 0,function(){var r;return Ge(this,function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(r=o.sent())&&r.indexOf(e)>=0?[2,JSON.parse(r).content]:[2,""]}})})},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):xe(Pe,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return Fe(this,void 0,void 0,function(){return Ge(this,function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}})})}}();var Be=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)}}(),He=function(t,e){this.data=e||null,this.name=t},Qe=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return Be(e,t),e}(He),Ve=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof Qe)return console.error(t.error),this;var n="string"==typeof t?new He(t,e||{}):t,r=n.name;if(this.listens(r)){n.target=this;for(var o=0,i=this.listeners[r]?function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([],this.listeners[r],!0):[];o<i.length;o++)i[o].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();new Ve,new Ve,"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");const ze=(t=>{var e={};return r.d(e,t),e})({default:()=>n.default});ze.default;var Ye=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)}}(),Xe=function(){return Xe=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},Xe.apply(this,arguments)},Ke=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())})},Ze=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},tn={filterRes:function(t){return t=function(t){if(t&&"object"==typeof t&&t.data&&"object"==typeof t.data){var e=t.data,n=e.code,r=e.message;if(!t.code&&n||!t.message&&r)return qe(qe(qe({},t),!t.code&&n?{code:n}:{}),!t.message&&r?{message:r}:{})}return t}(t),delete t.header,delete t.statusCode,t},flattenResData:function(t){if("object"==typeof t.data&&null!==t.data){var e=Xe(Xe({},t),t.data);return delete e.data,e}return t},safeParseEJSON:function(t){if("string"!=typeof t)return t;try{return at.EJSON.parse(t)}catch(e){return t}},parseEJSONParam:function(t){if("string"!=typeof t)return t;try{return JSON.parse(t)}catch(e){return t}},toLegacyRegExp:function(t){if(!t||"object"!=typeof t)return t;if(t.$regularExpression&&"object"==typeof t.$regularExpression){var e=t.$regularExpression;return{$regex:e.pattern,$options:e.options}}if(Array.isArray(t))return t.map(function(t){return tn.toLegacyRegExp(t)});var n={};for(var r in t)n[r]=tn.toLegacyRegExp(t[r]);return n},parseWriteParam:function(t){return tn.toLegacyRegExp(tn.parseEJSONParam(t))},buildQueryParams:function(t){return Object.entries(t).filter(function(t){t[0];var e=t[1];return null!=e&&""!==e}).map(function(t){var e=t[0],n=t[1],r="object"==typeof n?JSON.stringify(n):String(n);return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(r))}).join("&")},getUrlPrefix:function(t){var e=(null==t?void 0:t.instance)||"(default)",n=(null==t?void 0:t.database)||"(default)";return"/database/instances/".concat(e,"/databases/").concat(n)},"database.queryDocument":function(t,e){var n,r,o,i,a,s,u;return Ke(this,void 0,Promise,function(){var c,l,f,d;return Ze(this,function(p){switch(p.label){case 0:return c=!!(null===(r=null===(n=t.query)||void 0===n?void 0:n._id)||void 0===r?void 0:r.$eq),l=tn.buildQueryParams(Xe({projection:t.projection,transactionId:t.transactionId},c?{}:{offset:null!==(o=t.offset)&&void 0!==o?o:0,limit:null!==(i=t.limit)&&void 0!==i?i:100,order:t.order,query:t.query?at.EJSON.stringify(t.query,{relaxed:!1}):void 0})),f="".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(l),c&&(f="".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/").concat((null===(a=t.query._id)||void 0===a?void 0:a.$eq)||t.query._id,"?").concat(l)),[4,this.gateWay({url:f,method:"GET"},e)];case 1:return(d=p.sent()).data=tn.safeParseEJSON(JSON.stringify(d.data)),!c||d.code||(null===(s=d.data)||void 0===s?void 0:s.code)?(d.code||(null===(u=d.data)||void 0===u?void 0:u.code)?d=Xe(Xe({},d),{data:Xe(Xe({},d.data),{list:[]})}):Array.isArray(d.data)?d=Xe(Xe({},d),{data:{list:d.data}}):d.data&&!Array.isArray(d.data.list)&&(d=Xe(Xe({},d),{data:Xe(Xe({},d.data),{list:[]})})),[2,tn.filterRes(d)]):[2,Xe(Xe({},d),{data:{list:[d.data]}})]}})})},"database.addDocument":function(t,e){var n,r,o;return Ke(this,void 0,Promise,function(){var i;return Ze(this,function(a){switch(a.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"POST",data:Xe({data:Array.isArray(t.data)?t.data:[t.data]},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:return i=a.sent(),Array.isArray(t.data)?i=Xe(Xe({},i),{data:Xe({ids:(null===(n=i.data)||void 0===n?void 0:n.insertedIds)||[]},i.data)}):(null===(o=null===(r=i.data)||void 0===r?void 0:r.insertedIds)||void 0===o?void 0:o[0])&&(i=Xe(Xe({},i),{data:Xe({_id:i.data.insertedIds[0]},i.data)})),[2,tn.filterRes(i)]}})})},"database.updateDocument":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"PATCH",data:Xe({query:t.query,data:t.data,multi:!!t.multi,upsert:!!t.upsert,replaceMode:!!t.replaceMode},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:return n=r.sent(),[2,tn.filterRes(n)]}})})},"database.deleteDocument":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/remove"),method:"POST",data:Xe({query:t.query,multi:!!t.multi},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:return n=r.sent(),[2,tn.filterRes(n)]}})})},"database.countDocument":function(t,e){return Ke(this,void 0,Promise,function(){var n,r;return Ze(this,function(o){switch(o.label){case 0:return n=tn.buildQueryParams({count:!0,query:t.query?at.EJSON.stringify(t.query,{relaxed:!1}):void 0}),[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(n),method:"GET"},e)];case 1:return r=o.sent(),[2,tn.filterRes(r)]}})})},"database.addCollection":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/collections"),method:"POST",data:{collectionName:t.collectionName}},e)];case 1:return n=r.sent(),[2,tn.filterRes(n)]}})})},"database.aggregate":function(t,e){var n;return Ke(this,void 0,Promise,function(){var r,o;return Ze(this,function(i){switch(i.label){case 0:return r=t.stages.map(function(t){var e,n;try{var r="string"==typeof t.stageValue?JSON.parse(t.stageValue):t.stageValue;return(e={})[t.stageKey]=at.EJSON.serialize(r),e}catch(e){return(n={})[t.stageKey]=t.stageValue,n}}),[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/aggregations"),method:"POST",data:{pipeline:r}},e)];case 1:return o=i.sent(),Array.isArray(null===(n=o.data)||void 0===n?void 0:n.list)&&(o.data.list=JSON.stringify(o.data.list.map(function(t){return JSON.stringify(t)}))),[2,tn.filterRes(o)]}})})},"database.startTransaction":function(t,e){return Ke(this,void 0,void 0,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/transactions"),method:"POST"},e)];case 1:return n=r.sent(),[2,tn.filterRes(tn.flattenResData(n))]}})})},"database.commitTransaction":function(t,e){return Ke(this,void 0,void 0,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/commit"),method:"POST"},e)];case 1:return n=r.sent(),[2,tn.filterRes(n)]}})})},"database.abortTransaction":function(t,e){return Ke(this,void 0,void 0,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/rollback"),method:"POST"},e)];case 1:return n=r.sent(),[2,tn.filterRes(n)]}})})},"database.getInTransaction":function(t,e){var n;return Ke(this,void 0,void 0,function(){var r;return Ze(this,function(o){switch(o.label){case 0:return[4,tn["database.queryDocument"].call(this,t,e)];case 1:return"object"==typeof(r=o.sent()).data&&null!==r.data?(null===(n=r.data)||void 0===n?void 0:n.code)?[2,tn.flattenResData(r)]:[2,Xe(Xe({},r),{data:JSON.stringify(r.data)})]:[2,r]}})})},"database.updateDocInTransaction":function(t,e){return Ke(this,void 0,void 0,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return t.data=tn.safeParseEJSON(t.data),[4,tn["database.updateDocument"].call(this,t,e)];case 1:return n=r.sent(),[2,tn.flattenResData(n)]}})})},"database.deleteDocInTransaction":function(t,e){return Ke(this,void 0,void 0,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,tn["database.deleteDocument"].call(this,t,e)];case 1:return n=r.sent(),[2,tn.flattenResData(n)]}})})},"database.insertDocInTransaction":function(t,e){var n;return Ke(this,void 0,Promise,function(){var r,o;return Ze(this,function(i){switch(i.label){case 0:return t.data=tn.safeParseEJSON(t.data),[4,tn["database.addDocument"].call(this,t,e)];case 1:return"object"==typeof(r=i.sent()).data&&null!==r.data?(o=!!(null===(n=r.data)||void 0===n?void 0:n._id),r=Xe(Xe(Xe({},r),{inserted:o?1:0,ok:o?1:0}),r.data)):r=Xe({inserted:0,ok:0},r),delete r.data,[2,r]}})})},"database.runCommands":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/commands"),method:"POST",data:Xe({commands:at.EJSON.serialize(t.commands)},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:"object"==typeof(n=r.sent()).data&&null!==n.data&&(delete(n=Xe(Xe({},n),n.data)).data,delete n.request_id);try{n=at.EJSON.deserialize(n)}catch(t){}return[2,tn.filterRes(n)]}})})},"database.getDocument":function(t,e){var n;return Ke(this,void 0,Promise,function(){var r,o;return Ze(this,function(i){switch(i.label){case 0:return(r=Xe({},t)).query=tn.parseEJSONParam(r.query),r.order=tn.parseEJSONParam(r.order),r.projection=tn.parseEJSONParam(r.projection),[4,tn["database.queryDocument"].call(this,r,e)];case 1:return o=i.sent(),Array.isArray(null===(n=o.data)||void 0===n?void 0:n.list)&&(o.data.list=o.data.list.map(function(t){return at.EJSON.stringify(t,{relaxed:!1})})),[2,o]}})})},"database.insertDocument":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){return(n=Xe({},t)).data=Array.isArray(n.data)?n.data.map(function(t){return tn.parseWriteParam(t)}):tn.parseWriteParam(n.data),[2,tn["database.addDocument"].call(this,n,e)]})})},"database.modifyDocument":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){return(n=Xe({},t)).query=tn.parseEJSONParam(n.query),n.data=tn.parseEJSONParam(n.data),[2,tn["database.updateDocument"].call(this,n,e)]})})},"database.removeDocument":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){return(n=Xe({},t)).query=tn.parseEJSONParam(n.query),[2,tn["database.deleteDocument"].call(this,n,e)]})})},"database.calculateDocument":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){return(n=Xe({},t)).query=tn.parseEJSONParam(n.query),[2,tn["database.countDocument"].call(this,n,e)]})})},"database.aggregateDocuments":function(t,e){var n;return Ke(this,void 0,Promise,function(){var r,o;return Ze(this,function(i){switch(i.label){case 0:return r=Xe({},t),Array.isArray(r.stages)&&(r.stages=r.stages.map(function(t){return Xe(Xe({},t),{stageValue:tn.parseEJSONParam(t.stageValue)})})),[4,tn["database.aggregate"].call(this,r,e)];case 1:if(o=i.sent(),"string"==typeof(null===(n=o.data)||void 0===n?void 0:n.list))try{o.data.list=JSON.parse(o.data.list)}catch(t){}return[2,o]}})})}},en={name:"database",entity:{database:function(t){var e;if(void 0!==t&&"Object"!==Object.prototype.toString.call(t).slice(8,-1))throw Re({code:"INVALID_PARAM",msg:"dbConfig must be an object"},null===(e=this.config)||void 0===e?void 0:e.errorFactory);var n=this.platform,r=n.adapter,o=n.runtime,i=function(t){function e(e){return t.call(this,e)||this}return Ye(e,t),e.prototype.send=function(e,n,r){var o,i,a,s;return Ke(this,void 0,void 0,function(){var u,c,l;return Ze(this,function(f){switch(f.label){case 0:return u=null,c=r&&"number"==typeof r.timeout?{timeout:r.timeout}:void 0,"GATEWAY"===this.config.endPointMode&&tn[e]?[4,tn[e].call(this,n,c)]:[3,2];case 1:return u=f.sent(),[3,4];case 2:return[4,t.prototype.send.call(this,e,n,void 0,c)];case 3:u=f.sent(),f.label=4;case 4:if(d=null!==(a=null===(i=null===(o=this.config)||void 0===o?void 0:o._fromApp)||void 0===i?void 0:i.config)&&void 0!==a?a:this.config,l=!d||"boolean"!=typeof d.throw||d.throw,u&&u.code&&l)throw Re({code:u.code,msg:u.message||u.data&&u.data.message||"",requestId:u.requestId},null===(s=this.config)||void 0===s?void 0:s.errorFactory);return[2,u]}var d})})},e}(this.request.constructor);return Ne.reqClass=i,Ne.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},Ne.runtime=o,this.wsClientClass&&(Ne.wsClass=r.wsClass,Ne.wsClientClass=this.wsClientClass),Ne.ws||(Ne.ws=null),new(function(t){function e(e){return t.call(this,e)||this}return Ye(e,t),e.prototype.runCommands=function(t){return Ke(this,void 0,Promise,function(){return Ze(this,function(e){return[2,Ne.createRequest(this.config).send("database.runCommands",t)]})})},e}(Ne))(Xe(Xe(Xe({},this.config),{_fromApp:this}),t))}}};try{cloudbase.registerComponent(en)}catch(t){}function nn(t){try{t.registerComponent(en)}catch(t){console.warn(t)}}try{window.registerDatabase=nn}catch(t){}var rn=o.I;export{rn as registerDatabase};
1
+ import*as t from"bson";import*as e from"@cloudbase/adapter-interface";import*as n from"jwt-decode";var r={d:(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},o={};r.d(o,{f:()=>tn,I:()=>nn});var i,a,s={};r.r(s),r.d(s,{LineString:()=>Q,MultiLineString:()=>K,MultiPoint:()=>Y,MultiPolygon:()=>tt,Point:()=>St,Polygon:()=>z}),function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.BooleanError="must be boolean",t.ArrayError="must be array",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined",t.CentersPhereError="centersPhere结构不合法"}(a||(a={}));var u,c,l="Object",f="GeoPoint",d="GeoLineString",p="GeoPolygon",h="GeoMultiPoint",y="GeoMultiLineString",m="GeoMultiPolygon",v="Date",b="ServerDate",w=["desc","asc"],g=["<","<=","==",">=",">"];!function(t){t.lt="<",t.gt=">",t.lte="<=",t.gte=">=",t.eq="=="}(u||(u={})),(i={})[u.eq]="$eq",i[u.lt]="$lt",i[u.lte]="$lte",i[u.gt]="$gt",i[u.gte]="$gte",function(t){t.WHERE="WHERE",t.DOC="DOC"}(c||(c={}));var _,O=(_=function(t,e){return _=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)},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}_(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),E=[],S={},I=function(t){function e(e,n){if(n!==S)throw new TypeError("InternalSymbol cannot be constructed with new operator");return t.call(this,e)||this}return O(e,t),e.for=function(t){for(var n=0,r=E.length;n<r;n++)if(E[n].target===t)return E[n].instance;var o=new e(t,S);return E.push({target:t,instance:o}),o},e}(function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})});const N=I;var P=N.for("UNSET_FIELD_NAME"),T=N.for("UPDATE_COMMAND"),j=N.for("QUERY_COMMAND"),A=N.for("LOGIC_COMMAND"),x=N.for("GEO_POINT"),q=N.for("SYMBOL_GEO_LINE_STRING"),C=N.for("SYMBOL_GEO_POLYGON"),D=N.for("SYMBOL_GEO_MULTI_POINT"),R=N.for("SYMBOL_GEO_MULTI_LINE_STRING"),L=N.for("SYMBOL_GEO_MULTI_POLYGON"),M=N.for("SERVER_DATE"),k=N.for("REGEXP"),J=N.for("OBJECTID"),U=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},$=function(t){return"object"===U(t)},F=function(t){return"number"===U(t)},G=function(t){return Array.isArray(t)},W=function(t){return"date"===U(t)},B=function(t){return"regexp"===U(t)},H=function(t){return t&&t._internalType instanceof I},Q=function(){function t(t){if(!G(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 St))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||!G(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(!F(i[0])||!F(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 q},enumerable:!1,configurable:!0}),t}(),V=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.")},z=function(){function t(t){if(!G(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,o;if("Polygon"!==t.type||!G(t.coordinates))return!1;try{for(var i=V(t.coordinates),a=i.next();!a.done;a=i.next()){var s=a.value;if(!this.isCloseLineString(s))return!1;try{for(var u=(r=void 0,V(s)),c=u.next();!c.done;c=u.next()){var l=c.value;if(!F(l[0])||!F(l[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{a&&!a.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 C},enumerable:!1,configurable:!0}),t}(),Y=function(){function t(t){if(!G(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 St))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||!G(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(!F(i[0])||!F(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 D},enumerable:!1,configurable:!0}),t}(),X=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.")},K=function(){function t(t){if(!G(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,o;if("MultiLineString"!==t.type||!G(t.coordinates))return!1;try{for(var i=X(t.coordinates),a=i.next();!a.done;a=i.next()){var s=a.value;try{for(var u=(r=void 0,X(s)),c=u.next();!c.done;c=u.next()){var l=c.value;if(!F(l[0])||!F(l[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{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return R},enumerable:!1,configurable:!0}),t}(),Z=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.")},tt=function(){function t(t){var e,n;if(!G(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=Z(t),o=r.next();!o.done;o=r.next()){var i=o.value;if(!(i instanceof z))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,a;if("MultiPolygon"!==t.type||!G(t.coordinates))return!1;try{for(var s=Z(t.coordinates),u=s.next();!u.done;u=s.next()){var c=u.value;try{for(var l=(r=void 0,Z(c)),f=l.next();!f.done;f=l.next()){var d=f.value;try{for(var p=(i=void 0,Z(d)),h=p.next();!h.done;h=p.next()){var y=h.value;if(!F(y[0])||!F(y[1]))return!1}}catch(t){i={error:t}}finally{try{h&&!h.done&&(a=p.return)&&a.call(p)}finally{if(i)throw i.error}}}}catch(t){r={error:t}}finally{try{f&&!f.done&&(o=l.return)&&o.call(l)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=s.return)&&n.call(s)}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,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.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 a},nt=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 f:o=new St(i.coordinates[0],i.coordinates[1]);break;case d:o=new Q(i.coordinates.map(function(t){return new St(t[0],t[1])}));break;case p:o=new z(i.coordinates.map(function(t){return new Q(t.map(function(t){var e=et(t,2),n=e[0],r=e[1];return new St(n,r)}))}));break;case h:o=new Y(i.coordinates.map(function(t){return new St(t[0],t[1])}));break;case y:o=new K(i.coordinates.map(function(t){return new Q(t.map(function(t){var e=et(t,2),n=e[0],r=e[1];return new St(n,r)}))}));break;case m:o=new tt(i.coordinates.map(function(t){return new z(t.map(function(t){return new Q(t.map(function(t){var e=et(t,2),n=e[0],r=e[1];return new St(n,r)}))}))}));break;case v:o=i;break;case l:case"Array":o=t.formatField(i);break;case b:o=new Date(i.$date);break;default:o=i}Array.isArray(r)?r.push(o):r[n]=o}),r},t.whichType=function(t){var e=Object.prototype.toString.call(t).slice(8,-1);return e===v?v:(e===l&&(t.$date?e=b:St.validate(t)?e=f:Q.validate(t)?e=d:z.validate(t)?e=p:Y.validate(t)?e=h:K.validate(t)?e=y:tt.validate(t)&&(e=m)),e)},t.generateDocId=function(){for(var t="",e=0;e<24;e++)t+="ABCDEFabcdef0123456789".charAt(Math.floor(22*Math.random()));return t},t}(),rt={code:"INVALID_PARAM",message:"Invalid request param"},ot="DATABASE_TRANSACTION_CONFLICT",it={code:"DATABASE_REQUEST_FAILED",message:"database request failed"};const at=(st={EJSON:()=>t.EJSON},ut={},r.d(ut,st),ut);var st,ut,ct=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)}}(),lt=function(){return lt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},lt.apply(this,arguments)};function ft(t,e){if("function"!=typeof e)return t;t.then(function(t){return e(0,t)},function(t){return e(t)})}var dt={};function pt(t){if(!Ne.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return dt[e]||(dt[e]=new Ne.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:Ne.createRequest(t.config)}}})),dt[e]}var ht=function(t){return void 0!==t.timeout?{timeout:t.timeout}:{}},yt=function(t){if(!$(t))return t;for(var e in t)void 0===t[e]?delete t[e]:$(t[e])&&(t[e]=yt(t[e]));return t},mt=function(t){return t=yt(t),at.EJSON.stringify(t,{relaxed:!1})},vt=function(t){function e(e){var n=t.call(this,e.message)||this;return n.code=e.code,n.message=e.message,n}return ct(e,t),e}(Error),bt=function(t){return new vt(t)};function wt(t,e){if(!1===t)return e;throw bt(lt({},e))}var gt,_t=function(){return _t=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},_t.apply(this,arguments)},Ot=["limit","offset","projection","order","multiple","timeout","raw"],Et=function(){function t(){}return t.isGeopoint=function(t,e){if("Number"!==nt.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+a.IntergerError);return!0},t.mustBeBoolean=function(t,e){if("boolean"!=typeof e)throw new Error(t+a.BooleanError);return!0},t.isProjection=function(t,e){if("object"!==U(e))throw bt(_t(_t({},rt),{message:"".concat(t," projection must be an object")}));for(var n in e){var r=e[n];if("number"===U(r)){if(0!==r&&1!==r)throw bt(_t(_t({},rt),{message:"if the value in projection is of number, it must be 0 or 1"}))}else if("object"!==U(r))throw bt(_t(_t({},rt),{message:"invalid projection"}))}return!0},t.isOrder=function(t,e){if("object"!==U(e))throw bt(_t(_t({},rt),{message:"".concat(t," order must be an object")}));for(var n in e){var r=e[n];if(1!==r&&-1!==r)throw bt(_t(_t({},rt),{message:"order value must be 1 or -1"}))}return!0},t.isFieldOrder=function(t){if(-1===w.indexOf(t))throw new Error(a.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===g.indexOf(t))throw new Error(a.OpStrError);return!0},t.isCollName=function(t){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(t))throw new Error(a.CollNameError);return!0},t.isDocID=function(t){if(!/^([a-fA-F0-9]){24}$/.test(t))throw new Error(a.DocIDError);return!0},t.isValidOptions=function(e){if(void 0===e&&(e={}),"object"!==U(e))throw bt(_t(_t({},rt),{message:"options must be an object"}));var n=Object.keys(e);for(var r in n)if(Ot.indexOf(n[r])<0)throw bt(_t(_t({},rt),{message:"".concat(n[r]," is invalid options key")}));var o=e,i=o.limit,a=o.offset,s=o.projection,u=o.order,c=e.multiple;return void 0!==i&&t.isInteger("limit",i),void 0!==a&&t.isInteger("offset",a),void 0!==s&&t.isProjection("projection",s),void 0!==u&&t.isOrder("order",u),void 0!==c&&t.mustBeBoolean("multiple",c),void 0!==e.timeout&&t.isInteger("timeout",e.timeout),!0},t.isValidAggregation=function(t){if(1!==Object.keys(t).length)throw bt(_t(_t({},rt),{message:"aggregation stage must have one key"}));return!0},t.isCentersPhere=function(e){if(Array.isArray(e)&&2===e.length){if("object"===U(e[0])&&e[0]._internalType===x&&"number"==typeof e[1])return!0;if(Array.isArray(e[0])&&2===e[0].length){var n=e[0][0],r=e[0][1];if(t.isGeopoint("longitude",n),t.isGeopoint("latitude",r),"number"==typeof e[1])return!0}}throw new Error("".concat(a.CentersPhereError))},t}(),St=function(){function t(t,e){Et.isGeopoint("longitude",t),Et.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&&G(t.coordinates)&&Et.isGeopoint("longitude",t.coordinates[0])&&Et.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return x},enumerable:!1,configurable:!0}),t}();!function(t){t.SET="set",t.REMOVE="remove",t.INC="inc",t.MUL="mul",t.PUSH="push",t.PULL="pull",t.PULL_ALL="pullAll",t.POP="pop",t.SHIFT="shift",t.UNSHIFT="unshift",t.ADD_TO_SET="addToSet",t.BIT="bit",t.RENAME="rename",t.MAX="max",t.MIN="min"}(gt||(gt={}));var It,Nt=function(){function t(t,e,n){this._internalType=T,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||P}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function Pt(t){return t&&t instanceof Nt&&t._internalType===T}!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(It||(It={}));var Tt=function(){function t(t,e,n){if(this._internalType=A,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||P,this.fieldName!==P)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,o=e.length;r<o;r++)(jt(i=e[r])||Ct(i))&&(e[r]=i._setFieldName(this.fieldName))}else{var i;(jt(i=e)||Ct(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(It.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(It.OR,r,this.fieldName)},t}();function jt(t){return t&&t instanceof Tt&&t._internalType===A}var At,xt=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"}(At||(At={}));var qt=function(t){function e(e,n,r){var o=t.call(this,e,n,r)||this;return o.operator=e,o._internalType=j,o}return xt(e,t),e.prototype.toJSON=function(){var t,e,n;switch(this.operator){case At.IN:case At.NIN:return(t={})["$"+this.operator]=this.operands,t;case At.NEQ:return(e={}).$ne=this.operands[0],e;default:return(n={})["$"+this.operator]=this.operands[0],n}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(At.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(At.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(At.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(At.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(At.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(At.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(At.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(At.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof St))throw new TypeError('"geometry" must be of type Point. Received type '.concat(typeof t.geometry));if(void 0!==t.maxDistance&&!F(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '.concat(typeof t.maxDistance));if(void 0!==t.minDistance&&!F(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '.concat(typeof t.minDistance));var n=new e(At.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof tt||t.geometry instanceof z||Et.isCentersPhere(t.centerSphere)))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(At.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof St||t.geometry instanceof Q||t.geometry instanceof z||t.geometry instanceof Y||t.geometry instanceof K||t.geometry instanceof tt))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(At.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(Tt);function Ct(t){return t&&t instanceof qt&&t._internalType===j}function Dt(t){return Ct(t)}var Rt={};for(var Lt in At)Rt[Lt]="$"+Lt;for(var Lt in It)Rt[Lt]="$"+Lt;for(var Lt in gt)Rt[Lt]="$"+Lt;function Mt(t){return Rt[t]||"$"+t}Rt[At.NEQ]="$ne",Rt[gt.REMOVE]="$unset",Rt[gt.SHIFT]="$pop",Rt[gt.UNSHIFT]="$push";var kt=function(){return kt=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},kt.apply(this,arguments)},Jt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.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 a},Ut=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 $t(t){return Ft(t,[t])}function Ft(t,e){if(!H(t)){if(W(t))return t;if(B(t))return{$regularExpression:{pattern:t.source,options:t.flags}};if(G(t))return t.map(function(t){if(e.indexOf(t)>-1)throw new Error("Cannot convert circular structure to JSON");return Ft(t,Ut(Ut([],Jt(e),!1),[t],!1))});if($(t)){var n=kt({},t),r={};for(var o in n){if(e.indexOf(n[o])>-1)throw new Error("Cannot convert circular structure to JSON");void 0!==n[o]&&(r[o]=Ft(n[o],Ut(Ut([],Jt(e),!1),[n[o]],!1)))}return r}return t}switch(t._internalType){case x:return t.toJSON();case M:case k:case J:return t.parse();default:return t.toJSON?t.toJSON():t}}var Gt=function(){return Gt=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},Gt.apply(this,arguments)},Wt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.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 a},Bt=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Ht(t,e,n,r){var o=Gt({},t);for(var i in t)if(!/^\$/.test(i)){var a=t[i];if(void 0!==a){if(a&&$(a)&&!e(a)){if(r.indexOf(a)>-1)throw new Error("Cannot convert circular structure to JSON");var s=Ht(a,e,Bt(Bt([],Wt(n),!1),[i],!1),Bt(Bt([],Wt(r),!1),[a],!1));o[i]=s;var u=!1;for(var c in s)/^\$/.test(c)?u=!0:(o["".concat(i,".").concat(c)]=s[c],delete o[i][c]);u||delete o[i]}}else delete o[i]}return o}function Qt(t){return Ht(t,zt,[],[t])}function Vt(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?G(t[r])?t[r].push(e[r]):$(t[r])?$(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is ".concat(U(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(U(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]}function zt(t){return H(t)||W(t)||B(t)}function Yt(t){return $t(t)}var Xt=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.encodeEJSON=function(e,n){var r=new t;return mt(n?e:r.encodeUpdate(e))},t.prototype.encodeUpdate=function(t){return Pt(t)?this.encodeUpdateCommand(t):"object"===U(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===P)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case gt.PUSH:case gt.PULL:case gt.PULL_ALL:case gt.POP:case gt.SHIFT:case gt.UNSHIFT:case gt.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,o,i=Mt(t.operator);return t.operator===gt.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,a,s,u,c,l,f=Mt(t.operator);switch(t.operator){case gt.PUSH:var d=void 0;return d=G(t.operands)?{$each:t.operands.map(Yt)}:t.operands,(e={})[f]=((n={})[t.fieldName]=d,n),e;case gt.UNSHIFT:return d={$each:t.operands.map(Yt),$position:0},(r={})[f]=((o={})[t.fieldName]=d,o),r;case gt.POP:return(i={})[f]=((a={})[t.fieldName]=1,a),i;case gt.SHIFT:return(s={})[f]=((u={})[t.fieldName]=-1,u),s;default:return(c={})[f]=((l={})[t.fieldName]=Yt(t.operands),l),c}},t.prototype.encodeUpdateObject=function(t){var e=Qt(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(Pt(r))e[n]=r._setFieldName(n),Vt(e,this.encodeUpdateCommand(e[n]),n);else{e[n]=r=Yt(r);var o=new Nt(gt.SET,[r],n);Vt(e,this.encodeUpdateCommand(o),n)}}return e},t}(),Kt=function(){return Kt=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},Kt.apply(this,arguments)},Zt=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())})},te=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},ee=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){return pt(i._db).watch(Kt(Kt({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify({_id:i.id})}))},this._db=t,this._coll=e,this.id=r,this._transactionId=o,this.request=Ne.createRequest(this._db.config),this._apiOptions=n}return t.prototype.create=function(t,e){return ft(this._create(t),e)},t.prototype._create=function(t){return Zt(this,void 0,void 0,function(){var e,n,r;return te(this,function(o){switch(o.label){case 0:return!(e=Array.isArray(t))&&this.id&&(t._id=this.id),n={collectionName:this._coll,data:e?t.map(function(t){return mt($t(t))}):[mt($t(t))],transactionId:this._transactionId},[4,this.request.send("database.insertDocument",n,ht(this._apiOptions))];case 1:return(r=o.sent()).code?[2,r]:this._transactionId?[2,{inserted:1,ok:1,id:r.data.insertedIds[0],requestId:r.requestId}]:e?[2,{ids:r.data&&r.data.insertedIds||[],requestId:r.requestId}]:[2,{id:r.data.insertedIds[0],requestId:r.requestId}]}})})},t.prototype.set=function(t,e){return ft(this._set(t),e)},t.prototype._set=function(t){return Zt(this,void 0,void 0,function(){var e,n,r,o;return te(this,function(i){switch(i.label){case 0:return this.id?t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,wt(this._db.config.throwOnCode,Kt(Kt({},rt),{message:"不能更新_id的值"}))]:(e=!1,n=function(t){if("object"==typeof t)for(var r in t)t[r]instanceof Nt?e=!0:"object"==typeof t[r]&&n(t[r])},n(t),e?[2,wt(this._db.config.throwOnCode,Kt(Kt({},it),{message:"update operator complicit"}))]:(r={collectionName:this._coll,queryType:c.DOC,data:mt($t(t)),transactionId:this._transactionId,multi:!1,merge:!1,upsert:!0},this.id&&(r.query=mt({_id:this.id})),[4,this.request.send("database.modifyDocument",r,ht(this._apiOptions))])):[2,wt(this._db.config.throwOnCode,Kt(Kt({},rt),{message:"参数必需是非空对象"}))]:[2,wt(this._db.config.throwOnCode,Kt(Kt({},rt),{message:"docId不能为空"}))];case 1:return(o=i.sent()).code?[2,o]:this._transactionId?[2,{updated:o.data.updated,upserted:[{_id:o.data.upsert_id}],requestId:o.requestId}]:[2,{updated:o.data.updated,upsertedId:o.data.upsert_id,requestId:o.requestId}]}})})},t.prototype.update=function(t,e){return ft(this._update(t),e)},t.prototype._update=function(t){return Zt(this,void 0,void 0,function(){var e,n,r;return te(this,function(o){switch(o.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,wt(this._db.config.throwOnCode,Kt(Kt({},rt),{message:"不能更新_id的值"}))]:(e=mt({_id:this.id}),n={collectionName:this._coll,transactionId:this._transactionId,data:Xt.encodeEJSON(t,this._apiOptions.raw||!1),query:e,queryType:c.DOC,multi:!1,merge:!0,upsert:!1},[4,this.request.send("database.modifyDocument",n,ht(this._apiOptions))]):[2,wt(this._db.config.throwOnCode,Kt(Kt({},rt),{message:"参数必需是非空对象"}))];case 1:return(r=o.sent()).code?[2,r]:[2,{updated:r.data.updated,requestId:r.requestId}]}})})},t.prototype.delete=function(t){return this.remove(t)},t.prototype.remove=function(t){return ft(this._remove(),t)},t.prototype._remove=function(){return Zt(this,void 0,void 0,function(){var t,e,n;return te(this,function(r){switch(r.label){case 0:return t=mt({_id:this.id}),e={collectionName:this._coll,transactionId:this._transactionId,query:t,queryType:c.DOC,multi:!1},[4,this.request.send("database.removeDocument",e,ht(this._apiOptions))];case 1:return(n=r.sent()).code?[2,n]:[2,{deleted:n.data.deleted,requestId:n.requestId}]}})})},t.prototype.get=function(t){return ft(this._get(),t)},t.prototype._get=function(){return Zt(this,void 0,void 0,function(){var t,e,n,r,o,i;return te(this,function(a){switch(a.label){case 0:return t=mt({_id:this.id}),e=this._apiOptions.projection,n={collectionName:this._coll,query:t,transactionId:this._transactionId,queryType:c.DOC,multi:!1},e&&(n.projection=mt(e)),[4,this.request.send("database.getDocument",n,ht(this._apiOptions))];case 1:return(r=a.sent()).code?[2,r]:(o=r.data.list.map(function(t){return at.EJSON.parse(t)}),i=nt.formatResDocumentData(o),this._transactionId?[2,{data:i[0]||null,requestId:r.requestId}]:[2,{data:i,requestId:r.requestId}])}})})},t.prototype.field=function(e){var n={};for(var r in e)"boolean"==typeof e[r]&&(n[r]=!0===e[r]?1:0),"number"==typeof e[r]&&(n[r]=e[r]>0?1:0),"object"==typeof e[r]&&(n[r]=e[r]);var o=Kt({},this._apiOptions);return o.projection=n,new t(this._db,this._coll,o,this.id,this._transactionId)},t}(),ne=function(){function t(){}return t.encode=function(t){return(new re).encodeQuery(t)},t.encodeEJSON=function(t,e){var n=new re;return mt(e?t:n.encodeQuery(t))},t}(),re=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n,r,o;return zt(t)?jt(t)?this.encodeLogicCommand(t):Ct(t)?this.encodeQueryCommand(t):B(t)?((n={})[e]=this.encodeRegExp(t),n):W(t)?((r={})[e]=Yt(t),r):((o={})[e]=this.encodeQueryObject(t),o):$(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regularExpression:{pattern:t.source,options:t.flags}}},t.prototype.encodeLogicCommand=function(t){var e,n,r,o,i,a,s,u=this;switch(t.operator){case It.NOR:case It.AND:case It.OR:var c=Mt(t.operator),l=t.operands.map(function(e){return u.encodeQuery(e,t.fieldName)});return(e={})[c]=l,e;case It.NOT:c=Mt(t.operator);var f=t.operands[0];return B(f)?((n={})[t.fieldName]=((r={})[c]=this.encodeRegExp(f),r),n):(l=this.encodeQuery(f)[t.fieldName],(o={})[t.fieldName]=((i={})[c]=l,i),o);default:if(c=Mt(t.operator),1===t.operands.length){var d=this.encodeQuery(t.operands[0]);return(a={})[c]=d,a}return l=t.operands.map(this.encodeQuery.bind(this)),(s={})[c]=l,s}},t.prototype.encodeQueryCommand=function(t){return Dt(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,o,i,a,s,u,c,l,f;if(t.fieldName===P)throw new Error("Cannot encode a comparison command with unset field name");var d=Mt(t.operator);switch(t.operator){case At.EQ:case At.NEQ:case At.LT:case At.LTE:case At.GT:case At.GTE:case At.ELEM_MATCH:case At.EXISTS:case At.SIZE:case At.MOD:return(e={})[t.fieldName]=((n={})[d]=Yt(t.operands[0]),n),e;case At.IN:case At.NIN:case At.ALL:return(r={})[t.fieldName]=((o={})[d]=Yt(t.operands),o),r;case At.GEO_NEAR:var p=t.operands[0];return(i={})[t.fieldName]={$nearSphere:{$geometry:p.geometry.toJSON(),$maxDistance:p.maxDistance,$minDistance:p.minDistance}},i;case At.GEO_WITHIN:if((p=t.operands[0]).centerSphere){Et.isCentersPhere(p.centerSphere);var h=p.centerSphere;return h[0]._internalType===x?((a={})[t.fieldName]={$geoWithin:{$centerSphere:[h[0].toJSON().coordinates,h[1]]}},a):((s={})[t.fieldName]={$geoWithin:{$centerSphere:p.centerSphere}},s)}return(u={})[t.fieldName]={$geoWithin:{$geometry:p.geometry.toJSON()}},u;case At.GEO_INTERSECTS:return p=t.operands[0],(c={})[t.fieldName]={$geoIntersects:{$geometry:p.geometry.toJSON()}},c;default:return(l={})[t.fieldName]=((f={})[d]=Yt(t.operands[0]),f),l}},t.prototype.encodeQueryObject=function(t){var e=Qt(t);for(var n in e){var r=e[n];if(jt(r)){e[n]=r._setFieldName(n);var o=this.encodeLogicCommand(e[n]);this.mergeConditionAfterEncode(e,o,n)}else Dt(r)?(e[n]=r._setFieldName(n),o=this.encodeComparisonCommand(e[n]),this.mergeConditionAfterEncode(e,o,n)):zt(r)&&(e[n]=Yt(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?G(t[r])?t[r]=t[r].concat(e[r]):$(t[r])?$(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is ".concat(U(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(U(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),oe=function(){return oe=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},oe.apply(this,arguments)},ie=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())})},ae=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},se=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){var e=pt(i._db),n=i._apiOptions,r=n.limit,o=n.order;return e.watch(oe(oe({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify(i._fieldFilters),limit:r,orderBy:o?o.reduce(function(t,e){return t[e.field]=e.direction,t},{}):void 0}))},this._db=t,this._coll=e,this._fieldFilters=n,this._apiOptions=r||{},this._request=Ne.createRequest(this._db.config),this._transactionId=o}return t.prototype.get=function(t){return ft(this._get(),t)},t.prototype._get=function(){return ie(this,void 0,void 0,function(){var t,e,n,r,o,i,a,s,u;return ae(this,function(l){switch(l.label){case 0:return t=this._apiOptions.order,e={collectionName:this._coll,queryType:c.WHERE,transactionId:this._transactionId},this._fieldFilters&&(e.query=this._fieldFilters),t&&(e.order=mt(t)),(n=this._apiOptions.offset)&&(e.offset=n),r=this._apiOptions.limit,e.limit=r?r<1e3?r:1e3:100,(o=this._apiOptions.projection)&&(e.projection=mt(o)),[4,this._request.send("database.getDocument",e,ht(this._apiOptions))];case 1:return(i=l.sent()).code?[2,i]:(a=i.data.list.map(function(t){return at.EJSON.parse(t)}),s=nt.formatResDocumentData(a),u={data:s,requestId:i.requestId},i.total&&(u.total=i.total),i.limit&&(u.limit=i.limit),i.offset&&(u.offset=i.offset),[2,u])}})})},t.prototype.count=function(t){return ft(this._count(),t)},t.prototype._count=function(){return ie(this,void 0,void 0,function(){var t,e;return ae(this,function(n){switch(n.label){case 0:return t={collectionName:this._coll,queryType:c.WHERE},this._fieldFilters&&(t.query=this._fieldFilters),[4,this._request.send("database.calculateDocument",t,ht(this._apiOptions))];case 1:return(e=n.sent()).code?[2,e]:[2,{requestId:e.requestId,total:e.data.total}]}})})},t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(a.QueryParamTypeError);var n=Object.keys(e),r=n.some(function(t){return void 0!==e[t]});if(n.length&&!r)throw Error(a.QueryParamValueError);return new t(this._db,this._coll,ne.encodeEJSON(e,this._apiOptions.raw||!1),this._apiOptions,this._transactionId)},t.prototype.options=function(e){return Et.isValidOptions(e),new t(this._db,this._coll,this._fieldFilters,e,this._transactionId)},t.prototype.orderBy=function(e,n){var r;Et.isFieldPath(e),Et.isFieldOrder(n);var o=((r={})[e]="desc"===n?-1:1,r),i=this._apiOptions.order||{},a=Object.assign({},this._apiOptions,{order:Object.assign({},i,o)});return new t(this._db,this._coll,this._fieldFilters,a,this._transactionId)},t.prototype.limit=function(e){Et.isInteger("limit",e);var n=oe({},this._apiOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,n,this._transactionId)},t.prototype.skip=function(e){Et.isInteger("offset",e);var n=oe({},this._apiOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,n,this._transactionId)},t.prototype.update=function(t,e){return ft(this._update(t),e)},t.prototype._update=function(t){return ie(this,void 0,void 0,function(){var e,n,r,o;return ae(this,function(i){switch(i.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,wt(this._db.config.throwOnCode,oe(oe({},rt),{message:"不能更新_id的值"}))]:(e=this._apiOptions.multiple,n=void 0===e||e,r={collectionName:this._coll,queryType:c.WHERE,multi:n,merge:!0,upsert:!1,data:Xt.encodeEJSON(t,this._apiOptions.raw||!1)},this._transactionId&&(r.transactionId=this._transactionId),this._fieldFilters&&(r.query=this._fieldFilters),[4,this._request.send("database.modifyDocument",r,ht(this._apiOptions))]):[2,wt(this._db.config.throwOnCode,oe(oe({},rt),{message:"参数必需是非空对象"}))];case 1:return(o=i.sent()).code?[2,o]:[2,{requestId:o.requestId,updated:o.data.updated,upsertId:o.data.upsert_id}]}})})},t.prototype.field=function(e){var n={};for(var r in e)"boolean"==typeof e[r]&&(n[r]=!0===e[r]?1:0),"number"==typeof e[r]&&(n[r]=e[r]>0?1:0),"object"==typeof e[r]&&(n[r]=e[r]);var o=oe({},this._apiOptions);return o.projection=n,new t(this._db,this._coll,this._fieldFilters,o,this._transactionId)},t.prototype.remove=function(t){return ft(this._remove(),t)},t.prototype._remove=function(){return ie(this,void 0,void 0,function(){var t,e,n,r,o,i,a,s,u;return ae(this,function(l){switch(l.label){case 0:return t=this._apiOptions,e=t.offset,n=t.limit,r=t.projection,o=t.order,void 0===e&&void 0===n&&void 0===r&&void 0===o||console.warn("`offset`, `limit`, `projection`, `orderBy` are not supported in remove() operation"),i=this._apiOptions.multiple,a=void 0===i||i,s={collectionName:this._coll,query:this._fieldFilters,queryType:c.WHERE,multi:a},this._transactionId&&(s.transactionId=this._transactionId),[4,this._request.send("database.removeDocument",s,ht(this._apiOptions))];case 1:return(u=l.sent()).code?[2,u]:[2,{requestId:u.requestId,deleted:u.data.deleted}]}})})},t.prototype.updateAndReturn=function(t){return ie(this,void 0,void 0,function(){var e,n;return ae(this,function(r){switch(r.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,wt(this._db.config.throwOnCode,oe(oe({},rt),{message:"不能更新_id的值"}))]:(e={collectionName:this._coll,queryType:c.WHERE,data:Xt.encodeEJSON(t,!1)},this._transactionId&&(e.transactionId=this._transactionId),this._fieldFilters&&(e.query=this._fieldFilters),[4,this._request.send("database.modifyAndReturnDoc",e,ht(this._apiOptions))]):[2,wt(this._db.config.throwOnCode,oe(oe({},rt),{message:"参数必需是非空对象"}))];case 1:return(n=r.sent()).code?[2,n]:[2,{requestId:n.requestId,updated:n.data.updated,doc:n.data.doc&&at.EJSON.parse(n.data.doc)}]}})})},t}(),ue=function(){function t(t,e,n){var r=this;this._stages=[],t&&e&&(this._db=t,this._request=Ne.createRequest(this._db.config),this._collectionName=e,n&&n.length>0&&n.forEach(function(t){Et.isValidAggregation(t);var e=Object.keys(t)[0];r._pipe(e,t[e],!0)}))}return t.prototype.end=function(){return t=this,e=void 0,r=function(){var t;return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}(this,function(e){switch(e.label){case 0:if(!this._collectionName||!this._db)throw new Error("Aggregation pipeline cannot send request");return[4,this._request.send("database.aggregateDocuments",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:t.data.list.map(at.EJSON.parse)}]:[2,t]}})},new((n=void 0)||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())});var t,e,n,r},t.prototype.unwrap=function(){return this._stages},t.prototype.done=function(){return this._stages.map(function(t){var e,n=t.stageKey,r=t.stageValue;return(e={})[n]=JSON.parse(r),e})},t.prototype._pipe=function(t,e,n){void 0===n&&(n=!1);var r;return r="object"===U(e)?mt(e):JSON.stringify(e),this._stages.push({stageKey:n?t:"$".concat(t),stageValue:r}),this},t.prototype.addFields=function(t){return this._pipe("addFields",t)},t.prototype.bucket=function(t){return this._pipe("bucket",t)},t.prototype.bucketAuto=function(t){return this._pipe("bucketAuto",t)},t.prototype.count=function(t){return this._pipe("count",t)},t.prototype.geoNear=function(t){return t.query&&(t.query=ne.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new St(t.near.longitude,t.near.latitude).toJSON()),this._pipe("geoNear",t)},t.prototype.group=function(t){return this._pipe("group",t)},t.prototype.limit=function(t){return this._pipe("limit",t)},t.prototype.match=function(t){return this._pipe("match",ne.encode(t))},t.prototype.project=function(t){return this._pipe("project",t)},t.prototype.lookup=function(t){return this._pipe("lookup",t)},t.prototype.replaceRoot=function(t){return this._pipe("replaceRoot",t)},t.prototype.sample=function(t){return this._pipe("sample",t)},t.prototype.skip=function(t){return this._pipe("skip",t)},t.prototype.sort=function(t){return this._pipe("sort",t)},t.prototype.sortByCount=function(t){return this._pipe("sortByCount",t)},t.prototype.unwind=function(t){return this._pipe("unwind",t)},t}();const ce=ue;var le=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)}}(),fe=function(t){function e(e,n,r,o){var i=t.call(this,e,n,"",r,o)||this;return o&&(i._transactionId=o),i}return le(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!1,configurable:!0}),e.prototype.doc=function(t){if("string"!=typeof t&&"number"!=typeof t)throw new Error("docId必须为字符串或数字");return new ee(this._db,this._coll,this._apiOptions,t,this._transactionId)},e.prototype.add=function(t,e){return ft(this._add(t),e)},e.prototype._add=function(t){return e=this,n=void 0,o=function(){var e,n,r;return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}(this,function(o){switch(o.label){case 0:return e=t,G(t)||(e=[t]),e=e.map(function(t){return mt($t(t))}),n={collectionName:this._coll,data:e},this._transactionId&&(n.transactionId=this._transactionId),[4,this._request.send("database.insertDocument",n,ht(this._apiOptions))];case 1:return(r=o.sent()).code?[2,r]:G(t)?[2,{ids:r.data.insertedIds,requestId:r.requestId}]:this._transactionId?[2,{inserted:1,ok:1,id:r.data.insertedIds[0],requestId:r.requestId}]:[2,{id:r.data.insertedIds[0],requestId:r.requestId}]}})},new((r=void 0)||(r=Promise))(function(t,i){function a(t){try{u(o.next(t))}catch(t){i(t)}}function s(t){try{u(o.throw(t))}catch(t){i(t)}}function u(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r(function(t){t(n)})).then(a,s)}u((o=o.apply(e,n||[])).next())});var e,n,r,o},e.prototype.aggregate=function(t){return void 0===t&&(t=[]),new ce(this._db,this._coll,this._apiOptions.raw?t:[])},e.prototype.options=function(t){return Et.isValidOptions(t),new e(this._db,this._coll,t,this._transactionId)},e}(se),de={eq:function(t){return new qt(At.EQ,[t])},neq:function(t){return new qt(At.NEQ,[t])},lt:function(t){return new qt(At.LT,[t])},lte:function(t){return new qt(At.LTE,[t])},gt:function(t){return new qt(At.GT,[t])},gte:function(t){return new qt(At.GTE,[t])},in:function(t){return new qt(At.IN,t)},nin:function(t){return new qt(At.NIN,t)},all:function(t){return new qt(At.ALL,t)},elemMatch:function(t){return new qt(At.ELEM_MATCH,[t])},exists:function(t){return new qt(At.EXISTS,[t])},size:function(t){return new qt(At.SIZE,[t])},mod:function(){return new qt(At.MOD,1==arguments.length?[arguments[0]]:2==arguments.length?[[arguments[0],arguments[1]]]:arguments)},geoNear:function(t){return new qt(At.GEO_NEAR,[t])},geoWithin:function(t){return new qt(At.GEO_WITHIN,[t])},geoIntersects:function(t){return new qt(At.GEO_INTERSECTS,[t])},and:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=G(arguments[0])?arguments[0]:Array.from(arguments);return new Tt(It.AND,n)},nor:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=G(arguments[0])?arguments[0]:Array.from(arguments);return new Tt(It.NOR,n)},or:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=G(arguments[0])?arguments[0]:Array.from(arguments);return new Tt(It.OR,n)},not:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=G(arguments[0])?arguments[0]:Array.from(arguments);return new Tt(It.NOT,n)},set:function(t){return new Nt(gt.SET,[t])},remove:function(){return new Nt(gt.REMOVE,[])},inc:function(t){return new Nt(gt.INC,[t])},mul:function(t){return new Nt(gt.MUL,[t])},push:function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if($(e[0])&&e[0].hasOwnProperty("each")){t={};var r=e[0];void 0!==r.each&&(t.$each=r.each),void 0!==r.position&&(t.$position=r.position),void 0!==r.sort&&(t.$sort=r.sort),void 0!==r.slice&&(t.$slice=r.slice)}else t=G(e[0])?e[0]:Array.from(e);return new Nt(gt.PUSH,t)},pull:function(t){return new Nt(gt.PULL,t)},pullAll:function(t){return new Nt(gt.PULL_ALL,t)},pop:function(){return new Nt(gt.POP,[])},shift:function(){return new Nt(gt.SHIFT,[])},unshift:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=G(arguments[0])?arguments[0]:Array.from(arguments);return new Nt(gt.UNSHIFT,n)},addToSet:function(t){return new Nt(gt.ADD_TO_SET,t)},rename:function(t){return new Nt(gt.RENAME,[t])},bit:function(t){return new Nt(gt.BIT,[t])},max:function(t){return new Nt(gt.MAX,[t])},min:function(t){return new Nt(gt.MIN,[t])},expr:function(t){return{$expr:t}},jsonSchema:function(t){return{$jsonSchema:t}},text:function(t){return function(t){return"string"===U(t)}(t)?{$search:t.search}:{$search:t.search,$language:t.language,$caseSensitive:t.caseSensitive,$diacriticSensitive:t.diacriticSensitive}},aggregate:{pipeline:function(){return new ce},abs:function(t){return new pe("abs",t)},add:function(t){return new pe("add",t)},ceil:function(t){return new pe("ceil",t)},divide:function(t){return new pe("divide",t)},exp:function(t){return new pe("exp",t)},floor:function(t){return new pe("floor",t)},ln:function(t){return new pe("ln",t)},log:function(t){return new pe("log",t)},log10:function(t){return new pe("log10",t)},mod:function(t){return new pe("mod",t)},multiply:function(t){return new pe("multiply",t)},pow:function(t){return new pe("pow",t)},sqrt:function(t){return new pe("sqrt",t)},subtract:function(t){return new pe("subtract",t)},trunc:function(t){return new pe("trunc",t)},arrayElemAt:function(t){return new pe("arrayElemAt",t)},arrayToObject:function(t){return new pe("arrayToObject",t)},concatArrays:function(t){return new pe("concatArrays",t)},filter:function(t){return new pe("filter",t)},in:function(t){return new pe("in",t)},indexOfArray:function(t){return new pe("indexOfArray",t)},isArray:function(t){return new pe("isArray",t)},map:function(t){return new pe("map",t)},range:function(t){return new pe("range",t)},reduce:function(t){return new pe("reduce",t)},reverseArray:function(t){return new pe("reverseArray",t)},size:function(t){return new pe("size",t)},slice:function(t){return new pe("slice",t)},zip:function(t){return new pe("zip",t)},and:function(t){return new pe("and",t)},not:function(t){return new pe("not",t)},or:function(t){return new pe("or",t)},cmp:function(t){return new pe("cmp",t)},eq:function(t){return new pe("eq",t)},gt:function(t){return new pe("gt",t)},gte:function(t){return new pe("gte",t)},lt:function(t){return new pe("lt",t)},lte:function(t){return new pe("lte",t)},neq:function(t){return new pe("ne",t)},cond:function(t){return new pe("cond",t)},ifNull:function(t){return new pe("ifNull",t)},switch:function(t){return new pe("switch",t)},dateFromParts:function(t){return new pe("dateFromParts",t)},dateFromString:function(t){return new pe("dateFromString",t)},dayOfMonth:function(t){return new pe("dayOfMonth",t)},dayOfWeek:function(t){return new pe("dayOfWeek",t)},dayOfYear:function(t){return new pe("dayOfYear",t)},isoDayOfWeek:function(t){return new pe("isoDayOfWeek",t)},isoWeek:function(t){return new pe("isoWeek",t)},isoWeekYear:function(t){return new pe("isoWeekYear",t)},millisecond:function(t){return new pe("millisecond",t)},minute:function(t){return new pe("minute",t)},month:function(t){return new pe("month",t)},second:function(t){return new pe("second",t)},hour:function(t){return new pe("hour",t)},week:function(t){return new pe("week",t)},year:function(t){return new pe("year",t)},literal:function(t){return new pe("literal",t)},mergeObjects:function(t){return new pe("mergeObjects",t)},objectToArray:function(t){return new pe("objectToArray",t)},allElementsTrue:function(t){return new pe("allElementsTrue",t)},anyElementTrue:function(t){return new pe("anyElementTrue",t)},setDifference:function(t){return new pe("setDifference",t)},setEquals:function(t){return new pe("setEquals",t)},setIntersection:function(t){return new pe("setIntersection",t)},setIsSubset:function(t){return new pe("setIsSubset",t)},setUnion:function(t){return new pe("setUnion",t)},concat:function(t){return new pe("concat",t)},dateToString:function(t){return new pe("dateToString",t)},indexOfBytes:function(t){return new pe("indexOfBytes",t)},indexOfCP:function(t){return new pe("indexOfCP",t)},split:function(t){return new pe("split",t)},strLenBytes:function(t){return new pe("strLenBytes",t)},strLenCP:function(t){return new pe("strLenCP",t)},strcasecmp:function(t){return new pe("strcasecmp",t)},substr:function(t){return new pe("substr",t)},substrBytes:function(t){return new pe("substrBytes",t)},substrCP:function(t){return new pe("substrCP",t)},toLower:function(t){return new pe("toLower",t)},toUpper:function(t){return new pe("toUpper",t)},meta:function(t){return new pe("meta",t)},addToSet:function(t){return new pe("addToSet",t)},avg:function(t){return new pe("avg",t)},first:function(t){return new pe("first",t)},last:function(t){return new pe("last",t)},max:function(t){return new pe("max",t)},min:function(t){return new pe("min",t)},push:function(t){return new pe("push",t)},stdDevPop:function(t){return new pe("stdDevPop",t)},stdDevSamp:function(t){return new pe("stdDevSamp",t)},sum:function(t){return new pe("sum",t)},let:function(t){return new pe("let",t)}},project:{slice:function(t){return new he("slice",t)},elemMatch:function(t){return new he("elemMatch",t)}}},pe=function(t,e){this["$"+t]=e},he=function(t,e){this["$"+t]=e},ye=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 M},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$tcb_server_date:{offset:this.offset}}},t}();function me(t){return new ye(t)}var ve=function(){function t(t){var e=t.regexp,n=t.options;if(!e)throw new TypeError("regexp must be a string");this.$regularExpression={pattern:e||"",options:n||""}}return t.prototype.parse=function(){return{$regularExpression:{pattern:this.$regularExpression.pattern,options:this.$regularExpression.options}}},Object.defineProperty(t.prototype,"_internalType",{get:function(){return k},enumerable:!1,configurable:!0}),t}();function be(t){return new ve(t)}var we=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())})},ge=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},_e=function(){function t(t){this._db=t,this._request=Ne.createRequest(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return t.prototype.init=function(){return we(this,void 0,void 0,function(){var t;return ge(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 fe(this._db,t,{},this._id)},t.prototype.getTransactionId=function(){return this._id},t.prototype.getRequestMethod=function(){return this._request},t.prototype.commit=function(){return we(this,void 0,void 0,function(){var t,e;return ge(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 we(this,void 0,void 0,function(){var e,n;return ge(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 Oe(){return we(this,void 0,void 0,function(){var t;return ge(this,function(e){switch(e.label){case 0:return[4,(t=new _e(this)).init()];case 1:return e.sent(),[2,t]}})})}function Ee(t,e){return void 0===e&&(e=3),we(this,void 0,void 0,function(){var n,r,o,i,a=this;return ge(this,function(s){switch(s.label){case 0:return s.trys.push([0,4,,10]),[4,(n=new _e(this)).init()];case 1:return s.sent(),[4,t(n)];case 2:if(r=s.sent(),!0===n.aborted)throw n.abortReason;return[4,n.commit()];case 3:return s.sent(),[2,r];case 4:if(o=s.sent(),!1===n.inited)throw o;return i=function(t){return we(a,void 0,void 0,function(){return ge(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:s.sent(),s.label=6;case 6:return o&&o.code===ot?[4,Ee.bind(this)(t,--e)]:[3,8];case 7:return[2,s.sent()];case 8:return[4,i(o)];case 9:return s.sent(),[3,10];case 10:return[2]}})})}var Se=function(){function t(t){var e=(void 0===t?{}:t).id,n=void 0===e?"":e;this.id=n}return Object.defineProperty(t.prototype,"_internalType",{get:function(){return J},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$oid:this.id}},t}();function Ie(t){return new Se(t)}var Ne=function(){function t(t){this.config=t,this.Geo=s,this.serverDate=me,this.command=de,this.RegExp=be,this.ObjectId=Ie,this.startTransaction=Oe,this.runTransaction=Ee,this.logicCommand=Tt,this.updateCommand=Nt,this.queryCommand=qt}return t.createRequest=function(e){var n=new t.reqClass(e),r=n.send;return n.send=function(t,n){for(var o=[],i=2;i<arguments.length;i++)o[i-2]=arguments[i];return n&&(e.instance&&(n.instance=e.instance),e.database&&(n.database=e.database)),r.call.apply(r,function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([this,t,n],function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.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 a}(o),!1))},n},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new fe(this,t)},t.prototype.createCollection=function(e){var n={collectionName:e};return t.createRequest(this.config).send("database.addCollection",n)},t}();var Pe="INVALID_OPERATION",Te="OPERATION_FAIL";const je=(t=>{var e={};return r.d(e,t),e})({AbstractSDKRequest:()=>e.AbstractSDKRequest,AbstractStorage:()=>e.AbstractStorage});var Ae=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)}}(),xe=function(){return xe=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},xe.apply(this,arguments)};function qe(t,e){console.warn("[".concat("@cloudbase/js-sdk","][").concat(t,"]:").concat(e))}var Ce=function(t){function e(e){var n=t.call(this,e.msg||e.message||"")||this;return n.code=e.code||"",n.requestId=e.requestId||"",Object.defineProperty(n,"message",{value:e.msg||e.message||"",enumerable:!0,writable:!0,configurable:!0}),n}return Ae(e,t),e}(Error),De=function(t){return new Ce(t)};function Re(t,e){return(e||De)(t)}var Le,Me=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)}}(),ke=function(){return ke=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},ke.apply(this,arguments)},Je=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())})},Ue=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};!function(t){function e(e){var n=t.call(this)||this,r=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=r||0,n.timeoutMsg=o||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}Me(e,t),e.prototype.get=function(t){return this.request(ke(ke({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(ke(ke({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(ke(ke({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t.data,n=t.file,r=t.name,o=t.method,i=t.headers,a=void 0===i?{}:i,s={post:"post",put:"put"}[null==o?void 0:o.toLowerCase()]||"put",u=new FormData;return"post"===s?(Object.keys(e).forEach(function(t){u.append(t,e[t])}),u.append("key",r),u.append("file",n),this.request(ke(ke({},t),{data:u,method:s}),this.restrictedMethods.includes("upload"))):this.request(ke(ke({},t),{method:"put",headers:a,body:n}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return Je(this,void 0,Promise,function(){var e,n,r,o;return Ue(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(ke(ke({},t),{headers:{},responseType:"blob"}))];case 1:return e=i.sent().data,n=window.URL.createObjectURL(new Blob([e])),r=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=n,o.setAttribute("download",r),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n),document.body.removeChild(o),[3,3];case 2:return i.sent(),[3,3];case 3:return[2,new Promise(function(e){e({statusCode:200,tempFilePath:t.url})})]}})})},e.prototype.fetch=function(t){var e;return Je(this,void 0,Promise,function(){var n,r,o,i,a,s,u,c,l,f,d,p,h,y=this;return Ue(this,function(m){switch(m.label){case 0:return n=new AbortController,r=t.url,o=t.enableAbort,i=void 0!==o&&o,a=t.stream,s=void 0!==a&&a,u=t.signal,c=t.timeout,l=t.shouldThrowOnError,f=void 0===l||l,d=null!=c?c:this.timeout,u&&(u.aborted&&n.abort(),u.addEventListener("abort",function(){return n.abort()})),p=null,i&&d&&(p=setTimeout(function(){console.warn(y.timeoutMsg),n.abort(new Error(y.timeoutMsg))},d)),[4,fetch(r,ke(ke({},t),{signal:n.signal})).then(function(t){return Je(y,void 0,void 0,function(){var e,n,r;return Ue(this,function(o){switch(o.label){case 0:return clearTimeout(p),f?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return r=(n=Promise).reject,[4,t.json()];case 2:e=r.apply(n,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}})})}).catch(function(t){return clearTimeout(p),Promise.reject(t)})];case 1:return h=m.sent(),[2,{data:s?h.body:(null===(e=h.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?h.json():h.text(),statusCode:h.status,header:h.headers,response:h}]}})})},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var r=String(t.method).toLowerCase()||"get";return new Promise(function(o){var i=t.url,a=t.headers,s=void 0===a?{}:a,u=t.data,c=t.responseType,l=t.withCredentials,f=t.body,d=t.onUploadProgress,p=function(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";return Object.keys(n).forEach(function(t){""===o?!r&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(n[t]))}),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)}("https:",i,"get"===r?u:{}),h=new XMLHttpRequest;h.open(r,p),c&&(h.responseType=c);var y,m,v,b=t.signal;b&&(b.aborted?h.abort():b.addEventListener("abort",function(){return h.abort()},{once:!0})),Object.keys(s).forEach(function(t){h.setRequestHeader(t,s[t])}),d&&h.upload.addEventListener("progress",d),h.onreadystatechange=function(){var t={};if(4===h.readyState){var e=h.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};e.forEach(function(t){var e=t.split(": "),r=e.shift().toLowerCase(),o=e.join(": ");n[r]=o}),t.header=n,t.statusCode=h.status;try{t.data="blob"===c?h.response:JSON.parse(h.responseText)}catch(e){t.data="blob"===c?h.response:h.responseText}clearTimeout(y),o(t)}},e&&n.timeout&&(y=setTimeout(function(){console.warn(n.timeoutMsg),h.abort()},n.timeout)),v=u,m="[object FormData]"===Object.prototype.toString.call(v)?u:"application/x-www-form-urlencoded"===s["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach(function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))}),e.join("&")}(u):f||(u?JSON.stringify(u):void 0),l&&(h.withCredentials=!0),h.send(m)})}}(je.AbstractSDKRequest),function(t){t.WEB="web",t.WX_MP="wx_mp"}(Le||(Le={}));var $e=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)}}(),Fe=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())})},Ge=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},We=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return $e(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(je.AbstractStorage);!function(){function t(t){this.keys={};var e=t.persistence,n=t.platformInfo,r=void 0===n?{}:n,o=t.keys,i=void 0===o?{}:o;this.platformInfo=r,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:(qe("INVALID_PARAMS","localStorage is not supported on current platform"),new We(e.root));case"none":return new We(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,n){if("async"!==this.mode){if(this.storage)try{var r={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(r))}catch(t){throw new Error(JSON.stringify({code:Te,msg:"[".concat("@cloudbase/js-sdk","][").concat(Te,"]setStore failed"),info:t}))}}else qe(Pe,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return Fe(this,void 0,void 0,function(){var r;return Ge(this,function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}})})},t.prototype.getStore=function(t,e){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var r=this.storage.getItem(t);return r&&r.indexOf(e)>=0?JSON.parse(r).content:""}qe(Pe,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return Fe(this,void 0,void 0,function(){var r;return Ge(this,function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(r=o.sent())&&r.indexOf(e)>=0?[2,JSON.parse(r).content]:[2,""]}})})},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):qe(Pe,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return Fe(this,void 0,void 0,function(){return Ge(this,function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}})})}}();var Be=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)}}(),He=function(t,e){this.data=e||null,this.name=t},Qe=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return Be(e,t),e}(He),Ve=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof Qe)return console.error(t.error),this;var n="string"==typeof t?new He(t,e||{}):t,r=n.name;if(this.listens(r)){n.target=this;for(var o=0,i=this.listeners[r]?function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([],this.listeners[r],!0):[];o<i.length;o++)i[o].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();new Ve,new Ve,"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");const ze=(t=>{var e={};return r.d(e,t),e})({default:()=>n.default});ze.default;var Ye=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)}}(),Xe=function(){return Xe=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},Xe.apply(this,arguments)},Ke=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(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(a,s)}u((r=r.apply(t,e||[])).next())})},Ze=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},tn={filterRes:function(t){return t=function(t){if(t&&"object"==typeof t&&t.data&&"object"==typeof t.data){var e=t.data,n=e.code,r=e.message;if(!t.code&&n||!t.message&&r)return xe(xe(xe({},t),!t.code&&n?{code:n}:{}),!t.message&&r?{message:r}:{})}return t}(t),delete t.header,delete t.statusCode,t},flattenResData:function(t){if("object"==typeof t.data&&null!==t.data){var e=Xe(Xe({},t),t.data);return delete e.data,e}return t},safeParseEJSON:function(t){if("string"!=typeof t)return t;try{return at.EJSON.parse(t)}catch(e){return t}},parseEJSONParam:function(t){if("string"!=typeof t)return t;try{return JSON.parse(t)}catch(e){return t}},parseEJSONValue:function(t){if("string"!=typeof t)return t;try{return at.EJSON.parse(t)}catch(e){return tn.parseEJSONParam(t)}},normalizeOrderParam:function(t){if(null!=t&&""!==t){for(var e=tn.parseEJSONValue(t),n=function(t){var e=t&&"object"==typeof t?Number(t):t;if("number"==typeof e&&!isNaN(e))return e<0?"desc":"asc";if("string"==typeof e){var n=e.toLowerCase();if("desc"===n||"-1"===n)return"desc";if("asc"===n||"1"===n)return"asc"}},r=[],o=0,i=Array.isArray(e)?e:[e];o<i.length;o++){var a=i[o];if(a&&"object"==typeof a)if(void 0!==a.field)(c=n(a.direction))&&r.push({field:a.field,direction:c});else for(var s=0,u=Object.entries(a);s<u.length;s++){var c,l=u[s],f=l[0];(c=n(l[1]))&&r.push({field:f,direction:c})}}return r.length?r:void 0}},extractDocId:function(t){if(t&&"object"==typeof t&&!Array.isArray(t)&&1===Object.keys(t).length&&"_id"in t){var e=t._id;if("string"==typeof e||"number"==typeof e)return String(e);if(e&&"object"==typeof e){if("string"==typeof e.$oid)return e.$oid;var n=e.$eq;if("string"==typeof n||"number"==typeof n)return String(n);if(n&&"object"==typeof n&&"string"==typeof n.$oid)return n.$oid}}},toLegacyRegExp:function(t){if(!t||"object"!=typeof t)return t;if(t.$regularExpression&&"object"==typeof t.$regularExpression){var e=t.$regularExpression;return{$regex:e.pattern,$options:e.options}}if(Array.isArray(t))return t.map(function(t){return tn.toLegacyRegExp(t)});var n={};for(var r in t)n[r]=tn.toLegacyRegExp(t[r]);return n},parseWriteParam:function(t){return tn.toLegacyRegExp(tn.parseEJSONParam(t))},buildQueryParams:function(t){return Object.entries(t).filter(function(t){t[0];var e=t[1];return null!=e&&""!==e}).map(function(t){var e=t[0],n=t[1],r="object"==typeof n?JSON.stringify(n):String(n);return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(r))}).join("&")},getUrlPrefix:function(t){var e=(null==t?void 0:t.instance)||"(default)",n=(null==t?void 0:t.database)||"(default)";return"/database/instances/".concat(e,"/databases/").concat(n)},"database.queryDocument":function(t,e){var n,r,o,i;return Ke(this,void 0,Promise,function(){var a,s,u,c,l,f,d;return Ze(this,function(p){switch(p.label){case 0:return a=tn.parseEJSONParam(t.query),s=tn.parseEJSONValue(t.projection),u=tn.extractDocId(a),c=void 0!==u,l=tn.buildQueryParams(Xe({projection:s,transactionId:t.transactionId},c?{}:{offset:null!==(n=t.offset)&&void 0!==n?n:0,limit:null!==(r=t.limit)&&void 0!==r?r:100,order:tn.normalizeOrderParam(t.order),query:a?at.EJSON.stringify(a,{relaxed:!1}):void 0})),f="".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(l),c&&(f="".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/").concat(u,"?").concat(l)),[4,this.gateWay({url:f,method:"GET"},e)];case 1:return(d=p.sent()).data=tn.safeParseEJSON(JSON.stringify(d.data)),!c||d.code||(null===(o=d.data)||void 0===o?void 0:o.code)?(d.code||(null===(i=d.data)||void 0===i?void 0:i.code)?d=Xe(Xe({},d),{data:Xe(Xe({},d.data),{list:[]})}):Array.isArray(d.data)?d=Xe(Xe({},d),{data:{list:d.data}}):d.data&&!Array.isArray(d.data.list)&&(d=Xe(Xe({},d),{data:Xe(Xe({},d.data),{list:[]})})),[2,tn.filterRes(d)]):[2,Xe(Xe({},d),{data:{list:[d.data]}})]}})})},"database.addDocument":function(t,e){var n,r,o;return Ke(this,void 0,Promise,function(){var i,a;return Ze(this,function(s){switch(s.label){case 0:return i=(Array.isArray(t.data)?t.data:[t.data]).map(function(t){return tn.parseWriteParam(t)}),[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"POST",data:Xe({data:i},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:return a=s.sent(),Array.isArray(t.data)?a=Xe(Xe({},a),{data:Xe({ids:(null===(n=a.data)||void 0===n?void 0:n.insertedIds)||[]},a.data)}):(null===(o=null===(r=a.data)||void 0===r?void 0:r.insertedIds)||void 0===o?void 0:o[0])&&(a=Xe(Xe({},a),{data:Xe({_id:a.data.insertedIds[0]},a.data)})),[2,tn.filterRes(a)]}})})},"database.updateDocument":function(t,e){var n;return Ke(this,void 0,Promise,function(){var r;return Ze(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"PATCH",data:Xe({query:tn.parseEJSONParam(t.query),data:tn.parseEJSONParam(t.data),multi:!!t.multi,upsert:!!t.upsert,replaceMode:null!==(n=t.replaceMode)&&void 0!==n?n:!1===t.merge},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:return r=o.sent(),[2,tn.filterRes(r)]}})})},"database.deleteDocument":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/remove"),method:"POST",data:Xe({query:tn.parseEJSONParam(t.query),multi:!!t.multi},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:return n=r.sent(),[2,tn.filterRes(n)]}})})},"database.countDocument":function(t,e){return Ke(this,void 0,Promise,function(){var n,r,o;return Ze(this,function(i){switch(i.label){case 0:return n=tn.parseEJSONParam(t.query),r=tn.buildQueryParams({count:!0,query:n?at.EJSON.stringify(n,{relaxed:!1}):void 0}),[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(r),method:"GET"},e)];case 1:return o=i.sent(),[2,tn.filterRes(o)]}})})},"database.addCollection":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/collections"),method:"POST",data:{collectionName:t.collectionName}},e)];case 1:return n=r.sent(),[2,tn.filterRes(n)]}})})},"database.aggregate":function(t,e){var n;return Ke(this,void 0,Promise,function(){var r,o;return Ze(this,function(i){switch(i.label){case 0:return r=t.stages.map(function(t){var e,n;try{var r="string"==typeof t.stageValue?JSON.parse(t.stageValue):t.stageValue;return(e={})[t.stageKey]=at.EJSON.serialize(r),e}catch(e){return(n={})[t.stageKey]=t.stageValue,n}}),[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/aggregations"),method:"POST",data:{pipeline:r}},e)];case 1:return o=i.sent(),Array.isArray(null===(n=o.data)||void 0===n?void 0:n.list)&&(o.data.list=JSON.stringify(o.data.list.map(function(t){return JSON.stringify(t)}))),[2,tn.filterRes(o)]}})})},"database.startTransaction":function(t,e){return Ke(this,void 0,void 0,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/transactions"),method:"POST"},e)];case 1:return n=r.sent(),[2,tn.filterRes(tn.flattenResData(n))]}})})},"database.commitTransaction":function(t,e){return Ke(this,void 0,void 0,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/commit"),method:"POST"},e)];case 1:return n=r.sent(),[2,tn.filterRes(n)]}})})},"database.abortTransaction":function(t,e){return Ke(this,void 0,void 0,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/rollback"),method:"POST"},e)];case 1:return n=r.sent(),[2,tn.filterRes(n)]}})})},"database.getInTransaction":function(t,e){var n;return Ke(this,void 0,void 0,function(){var r;return Ze(this,function(o){switch(o.label){case 0:return[4,tn["database.queryDocument"].call(this,t,e)];case 1:return"object"==typeof(r=o.sent()).data&&null!==r.data?(null===(n=r.data)||void 0===n?void 0:n.code)?[2,tn.flattenResData(r)]:[2,Xe(Xe({},r),{data:JSON.stringify(r.data)})]:[2,r]}})})},"database.updateDocInTransaction":function(t,e){return Ke(this,void 0,void 0,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,tn["database.updateDocument"].call(this,t,e)];case 1:return n=r.sent(),[2,tn.flattenResData(n)]}})})},"database.deleteDocInTransaction":function(t,e){return Ke(this,void 0,void 0,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,tn["database.deleteDocument"].call(this,t,e)];case 1:return n=r.sent(),[2,tn.flattenResData(n)]}})})},"database.insertDocInTransaction":function(t,e){var n;return Ke(this,void 0,Promise,function(){var r,o;return Ze(this,function(i){switch(i.label){case 0:return[4,tn["database.addDocument"].call(this,t,e)];case 1:return"object"==typeof(r=i.sent()).data&&null!==r.data?(o=!!(null===(n=r.data)||void 0===n?void 0:n._id),r=Xe(Xe(Xe({},r),{inserted:o?1:0,ok:o?1:0}),r.data)):r=Xe({inserted:0,ok:0},r),delete r.data,[2,r]}})})},"database.runCommands":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(tn.getUrlPrefix(t),"/commands"),method:"POST",data:Xe({commands:at.EJSON.serialize(Array.isArray(t.commands)?t.commands.map(function(t){return tn.parseEJSONParam(t)}):t.commands)},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:"object"==typeof(n=r.sent()).data&&null!==n.data&&(delete(n=Xe(Xe({},n),n.data)).data,delete n.request_id);try{n=at.EJSON.deserialize(n)}catch(t){}return[2,tn.filterRes(n)]}})})},"database.getDocument":function(t,e){var n;return Ke(this,void 0,Promise,function(){var r,o;return Ze(this,function(i){switch(i.label){case 0:return(r=Xe({},t)).query=tn.parseEJSONParam(r.query),r.projection=tn.parseEJSONValue(r.projection),[4,tn["database.queryDocument"].call(this,r,e)];case 1:return o=i.sent(),Array.isArray(null===(n=o.data)||void 0===n?void 0:n.list)&&(o.data.list=o.data.list.map(function(t){return at.EJSON.stringify(t,{relaxed:!1})})),[2,o]}})})},"database.insertDocument":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){return(n=Xe({},t)).data=Array.isArray(n.data)?n.data.map(function(t){return tn.parseWriteParam(t)}):tn.parseWriteParam(n.data),[2,tn["database.addDocument"].call(this,n,e)]})})},"database.modifyDocument":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){return(n=Xe({},t)).query=tn.parseEJSONParam(n.query),n.data=tn.parseEJSONParam(n.data),[2,tn["database.updateDocument"].call(this,n,e)]})})},"database.modifyAndReturnDoc":function(t,e){var n,r;return Ke(this,void 0,Promise,function(){var o,i,a;return Ze(this,function(s){switch(s.label){case 0:return(o=Xe({},t)).query=tn.parseEJSONParam(o.query),o.data=tn.parseEJSONParam(o.data),(i=tn.extractDocId(o.query))?[4,this.gateWay({url:"".concat(tn.getUrlPrefix(o),"/collections/").concat(o.collectionName,"/documents/").concat(i),method:"PATCH",data:Xe({data:o.data,replaceMode:null!==(n=o.replaceMode)&&void 0!==n&&n,upsert:!!o.upsert,returnDoc:!0},o.transactionId&&{transactionId:o.transactionId})},e)]:[2,tn["database.updateDocument"].call(this,o,e)];case 1:return a=s.sent(),void 0!==(null===(r=a.data)||void 0===r?void 0:r.doc)&&"string"!=typeof a.data.doc&&(a.data.doc=at.EJSON.stringify(a.data.doc,{relaxed:!1})),[2,tn.filterRes(a)]}})})},"database.removeDocument":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){return(n=Xe({},t)).query=tn.parseEJSONParam(n.query),[2,tn["database.deleteDocument"].call(this,n,e)]})})},"database.calculateDocument":function(t,e){return Ke(this,void 0,Promise,function(){var n;return Ze(this,function(r){return(n=Xe({},t)).query=tn.parseEJSONParam(n.query),[2,tn["database.countDocument"].call(this,n,e)]})})},"database.aggregateDocuments":function(t,e){var n;return Ke(this,void 0,Promise,function(){var r,o;return Ze(this,function(i){switch(i.label){case 0:return r=Xe({},t),Array.isArray(r.stages)&&(r.stages=r.stages.map(function(t){return Xe(Xe({},t),{stageValue:tn.parseEJSONParam(t.stageValue)})})),[4,tn["database.aggregate"].call(this,r,e)];case 1:if(o=i.sent(),"string"==typeof(null===(n=o.data)||void 0===n?void 0:n.list))try{o.data.list=JSON.parse(o.data.list)}catch(t){}return[2,o]}})})}},en={name:"database",entity:{database:function(t){var e;if(void 0!==t&&"Object"!==Object.prototype.toString.call(t).slice(8,-1))throw Re({code:"INVALID_PARAM",msg:"dbConfig must be an object"},null===(e=this.config)||void 0===e?void 0:e.errorFactory);var n=this.platform,r=n.adapter,o=n.runtime,i=function(t){function e(e){return t.call(this,e)||this}return Ye(e,t),e.prototype.send=function(e,n,r){var o,i,a,s;return Ke(this,void 0,void 0,function(){var u,c,l;return Ze(this,function(f){switch(f.label){case 0:return u=null,c=r&&"number"==typeof r.timeout?{timeout:r.timeout}:void 0,"GATEWAY"===this.config.endPointMode&&tn[e]?[4,tn[e].call(this,n,c)]:[3,2];case 1:return u=f.sent(),[3,4];case 2:return[4,t.prototype.send.call(this,e,n,void 0,c)];case 3:u=f.sent(),f.label=4;case 4:if(d=null!==(a=null===(i=null===(o=this.config)||void 0===o?void 0:o._fromApp)||void 0===i?void 0:i.config)&&void 0!==a?a:this.config,l=!d||"boolean"!=typeof d.throw||d.throw,u&&u.code&&l)throw Re({code:u.code,msg:u.message||u.data&&u.data.message||"",requestId:u.requestId},null===(s=this.config)||void 0===s?void 0:s.errorFactory);return[2,u]}var d})})},e}(this.request.constructor);return Ne.reqClass=i,Ne.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},Ne.runtime=o,this.wsClientClass&&(Ne.wsClass=r.wsClass,Ne.wsClientClass=this.wsClientClass),Ne.ws||(Ne.ws=null),new(function(t){function e(e){return t.call(this,e)||this}return Ye(e,t),e.prototype.runCommands=function(t){return Ke(this,void 0,Promise,function(){return Ze(this,function(e){return[2,Ne.createRequest(this.config).send("database.runCommands",t)]})})},e}(Ne))(Xe(Xe(Xe({},this.config),{_fromApp:this}),t))}}};try{cloudbase.registerComponent(en)}catch(t){}function nn(t){try{t.registerComponent(en)}catch(t){console.warn(t)}}try{window.registerDatabase=nn}catch(t){}var rn=o.f,on=o.I;export{rn as gateWayFunc,on as registerDatabase};
2
2
  //# sourceMappingURL=index.esm.js.map