@cloudbase/js-sdk 3.6.4-alpha.0 → 3.6.4-alpha.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.
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- import*as t from"@cloudbase/app";import*as e from"@cloudbase/auth";import*as n from"@cloudbase/functions";import*as r from"@cloudbase/storage";import*as o from"@cloudbase/realtime";import*as i from"@cloudbase/model";import*as a from"@cloudbase/ai";import*as u from"@cloudbase/cloudrun";import*as s from"@cloudbase/mysql";import*as c from"@cloudbase/apis";import*as l from"bson";var f={d:(t,e)=>{for(var n in e)f.o(e,n)&&!f.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})}},d={};f.d(d,{Z:()=>He});var p={};f.r(p),f.d(p,{LineString:()=>dt,MultiLineString:()=>vt,MultiPoint:()=>yt,MultiPolygon:()=>gt,Point:()=>It,Polygon:()=>ht});const h=(y={default:()=>t.default},m={},f.d(m,y),m);var y,m;const v=(t=>{var e={};return f.d(e,t),e})({registerAuth:()=>e.registerAuth}),w=(t=>{var e={};return f.d(e,t),e})({registerFunctions:()=>n.registerFunctions}),g=(t=>{var e={};return f.d(e,t),e})({registerStorage:()=>r.registerStorage}),b=(t=>{var e={};return f.d(e,t),e})({registerRealtime:()=>o.registerRealtime}),_=(t=>{var e={};return f.d(e,t),e})({registerModel:()=>i.registerModel}),O=(t=>{var e={};return f.d(e,t),e})({registerAi:()=>a.registerAi}),E=(t=>{var e={};return f.d(e,t),e})({registerCloudrun:()=>u.registerCloudrun}),N=(t=>{var e={};return f.d(e,t),e})({registerMySQL:()=>s.registerMySQL}),S=(t=>{var e={};return f.d(e,t),e})({registerApis:()=>c.registerApis});var I,T;!function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined"}(T||(T={}));var P,q,A="Object",x="GeoPoint",j="GeoLineString",D="GeoPolygon",C="GeoMultiPoint",R="GeoMultiLineString",L="GeoMultiPolygon",M="Date",F="ServerDate",$=["desc","asc"],k=["<","<=","==",">=",">"];!function(t){t.lt="<",t.gt=">",t.lte="<=",t.gte=">=",t.eq="=="}(P||(P={})),(I={})[P.eq]="$eq",I[P.lt]="$lt",I[P.lte]="$lte",I[P.gt]="$gt",I[P.gte]="$gte",function(t){t.WHERE="WHERE",t.DOC="DOC"}(q||(q={}));var J,U=(J=function(t,e){return J=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])},J(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}J(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),G=[],W={},Q=function(t){function e(e,n){if(n!==W)throw new TypeError("InternalSymbol cannot be constructed with new operator");return t.call(this,e)||this}return U(e,t),e.for=function(t){for(var n=0,r=G.length;n<r;n++)if(G[n].target===t)return G[n].instance;var o=new e(t,W);return G.push({target:t,instance:o}),o},e}(function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})});const H=Q;var B=H.for("UNSET_FIELD_NAME"),V=H.for("UPDATE_COMMAND"),Y=H.for("QUERY_COMMAND"),z=H.for("LOGIC_COMMAND"),Z=H.for("GEO_POINT"),X=H.for("SYMBOL_GEO_LINE_STRING"),K=H.for("SYMBOL_GEO_POLYGON"),tt=H.for("SYMBOL_GEO_MULTI_POINT"),et=H.for("SYMBOL_GEO_MULTI_LINE_STRING"),nt=H.for("SYMBOL_GEO_MULTI_POLYGON"),rt=H.for("SERVER_DATE"),ot=H.for("REGEXP"),it=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},at=function(t){return"object"===it(t)},ut=function(t){return"number"===it(t)},st=function(t){return Array.isArray(t)},ct=function(t){return"date"===it(t)},lt=function(t){return"regexp"===it(t)},ft=function(t){return t&&t._internalType instanceof Q},dt=function(){function t(t){if(!st(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 It))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||!st(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(!ut(i[0])||!ut(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}(),pt=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.")},ht=function(){function t(t){if(!st(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 dt))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"));if(!dt.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||!st(t.coordinates))return!1;try{for(var i=pt(t.coordinates),a=i.next();!a.done;a=i.next()){var u=a.value;if(!this.isCloseLineString(u))return!1;try{for(var s=(r=void 0,pt(u)),c=s.next();!c.done;c=s.next()){var l=c.value;if(!ut(l[0])||!ut(l[1]))return!1}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}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 nt},enumerable:!1,configurable:!0}),t}(),yt=function(){function t(t){if(!st(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 It))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||!st(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(!ut(i[0])||!ut(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 tt},enumerable:!1,configurable:!0}),t}(),mt=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},vt=function(){function t(t){if(!st(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 dt))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||!st(t.coordinates))return!1;try{for(var i=mt(t.coordinates),a=i.next();!a.done;a=i.next()){var u=a.value;try{for(var s=(r=void 0,mt(u)),c=s.next();!c.done;c=s.next()){var l=c.value;if(!ut(l[0])||!ut(l[1]))return!1}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}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 et},enumerable:!1,configurable:!0}),t}(),wt=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},gt=function(){function t(t){var e,n;if(!st(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=wt(t),o=r.next();!o.done;o=r.next()){var i=o.value;if(!(i instanceof ht))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||!st(t.coordinates))return!1;try{for(var u=wt(t.coordinates),s=u.next();!s.done;s=u.next()){var c=s.value;try{for(var l=(r=void 0,wt(c)),f=l.next();!f.done;f=l.next()){var d=f.value;try{for(var p=(i=void 0,wt(d)),h=p.next();!h.done;h=p.next()){var y=h.value;if(!ut(y[0])||!ut(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{s&&!s.done&&(n=u.return)&&n.call(u)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return K},enumerable:!1,configurable:!0}),t}(),bt=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 rt},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$date:{offset:this.offset}}},t}();function _t(t){return new bt(t)}var Ot,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 x:o=new It(i.coordinates[0],i.coordinates[1]);break;case j:o=new dt(i.coordinates.map(function(t){return new It(t[0],t[1])}));break;case D:o=new ht(i.coordinates.map(function(t){return new dt(t.map(function(t){var e=Et(t,2),n=e[0],r=e[1];return new It(n,r)}))}));break;case C:o=new yt(i.coordinates.map(function(t){return new It(t[0],t[1])}));break;case R:o=new vt(i.coordinates.map(function(t){return new dt(t.map(function(t){var e=Et(t,2),n=e[0],r=e[1];return new It(n,r)}))}));break;case L:o=new gt(i.coordinates.map(function(t){return new ht(t.map(function(t){return new dt(t.map(function(t){var e=Et(t,2),n=e[0],r=e[1];return new It(n,r)}))}))}));break;case M:o=new Date(1e3*i.$timestamp);break;case A:case"Array":o=t.formatField(i);break;case F:o=new Date(i.$date);break;default:o=i}Array.isArray(r)?r.push(o):r[n]=o}),r},t.whichType=function(t){var e=Object.prototype.toString.call(t).slice(8,-1);if(e===M)return"BsonDate";if(e===A){if(t instanceof It)return x;if(t instanceof Date)return M;if(t instanceof bt)return F;t.$timestamp?e=M:t.$date?e=F:It.validate(t)?e=x:dt.validate(t)?e=j:ht.validate(t)?e=D:yt.validate(t)?e=C:vt.validate(t)?e=R:gt.validate(t)&&(e=L)}return e},t.generateDocId=function(){for(var t="",e=0;e<24;e++)t+="ABCDEFabcdef0123456789".charAt(Math.floor(22*Math.random()));return t},t}(),St=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+T.IntergerError);return!0},t.isFieldOrder=function(t){if(-1===$.indexOf(t))throw new Error(T.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===k.indexOf(t))throw new Error(T.OpStrError);return!0},t.isCollName=function(t){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(t))throw new Error(T.CollNameError);return!0},t.isDocID=function(t){if(!/^([a-fA-F0-9]){24}$/.test(t))throw new Error(T.DocIDError);return!0},t}(),It=function(){function t(t,e){St.isGeopoint("longitude",t),St.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&&st(t.coordinates)&&St.isGeopoint("longitude",t.coordinates[0])&&St.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return Z},enumerable:!1,configurable:!0}),t}(),Tt=function(){var t=function(){};if(!Promise){t.promise={};var e=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(t.promise,"then",{get:e}),Object.defineProperty(t.promise,"catch",{get:e}),t}var n=new Promise(function(e,n){t=function(t,r){return t?n(t):e(r)}});return t.promise=n,t};!function(t){t.SET="set",t.REMOVE="remove",t.INC="inc",t.MUL="mul",t.PUSH="push",t.PULL="pull",t.PULL_ALL="pullAll",t.POP="pop",t.SHIFT="shift",t.UNSHIFT="unshift",t.ADD_TO_SET="addToSet",t.BIT="bit",t.RENAME="rename",t.MAX="max",t.MIN="min"}(Ot||(Ot={}));var Pt,qt=function(){function t(t,e,n){this._internalType=V,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||B}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function At(t){return t&&t instanceof qt&&t._internalType===V}!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(Pt||(Pt={}));var xt=function(){function t(t,e,n){if(this._internalType=z,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||B,this.fieldName!==B)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,o=e.length;r<o;r++)(jt(i=e[r])||Lt(i))&&(e[r]=i._setFieldName(this.fieldName))}else{var i;(jt(i=e)||Lt(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(Pt.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(Pt.OR,r,this.fieldName)},t}();function jt(t){return t&&t instanceof xt&&t._internalType===z}var Dt,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)}}();!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"}(Dt||(Dt={}));var Rt=function(t){function e(e,n,r){var o=t.call(this,e,n,r)||this;return o.operator=e,o._internalType=Y,o}return Ct(e,t),e.prototype.toJSON=function(){var t,e;switch(this.operator){case Dt.IN:case Dt.NIN:return(t={})["$"+this.operator]=this.operands,t;default:return(e={})["$"+this.operator]=this.operands[0],e}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(Dt.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(Dt.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(Dt.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(Dt.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(Dt.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(Dt.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(Dt.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(Dt.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof It))throw new TypeError('"geometry" must be of type Point. Received type '.concat(typeof t.geometry));if(void 0!==t.maxDistance&&!ut(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '.concat(typeof t.maxDistance));if(void 0!==t.minDistance&&!ut(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '.concat(typeof t.minDistance));var n=new e(Dt.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof gt||t.geometry instanceof ht))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(Dt.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof It||t.geometry instanceof dt||t.geometry instanceof ht||t.geometry instanceof yt||t.geometry instanceof vt||t.geometry instanceof gt))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(Dt.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(xt);function Lt(t){return t&&t instanceof Rt&&t._internalType===Y}function Mt(t){return Lt(t)}var Ft={};for(var $t in Dt)Ft[$t]="$"+$t;for(var $t in Pt)Ft[$t]="$"+$t;for(var $t in Ot)Ft[$t]="$"+$t;function kt(t){return Ft[t]||"$"+t}Ft[Dt.NEQ]="$ne",Ft[Ot.REMOVE]="$unset",Ft[Ot.SHIFT]="$pop",Ft[Ot.UNSHIFT]="$push";var Jt=function(){return Jt=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},Jt.apply(this,arguments)},Ut=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},Gt=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 Wt(t){return Qt(t,[t])}function Qt(t,e){if(!ft(t)){if(ct(t))return{$date:+t};if(lt(t))return{$regex:t.source,$options:t.flags};if(st(t))return t.map(function(t){if(e.indexOf(t)>-1)throw new Error("Cannot convert circular structure to JSON");return Qt(t,Gt(Gt([],Ut(e),!1),[t],!1))});if(at(t)){var n=Jt({},t);for(var r in n){if(e.indexOf(n[r])>-1)throw new Error("Cannot convert circular structure to JSON");n[r]=Qt(n[r],Gt(Gt([],Ut(e),!1),[n[r]],!1))}return n}return t}switch(t._internalType){case Z:return t.toJSON();case rt:case ot:return t.parse();default:return t.toJSON?t.toJSON():t}}var Ht=function(){return Ht=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},Ht.apply(this,arguments)},Bt=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},Vt=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Yt(t,e,n,r){var o=Ht({},t);for(var i in t)if(!/^\$/.test(i)){var a=t[i];if(a&&at(a)&&!e(a)){if(r.indexOf(a)>-1)throw new Error("Cannot convert circular structure to JSON");var u=Yt(a,e,Vt(Vt([],Bt(n),!1),[i],!1),Vt(Vt([],Bt(r),!1),[a],!1));o[i]=u;var s=!1;for(var c in u)/^\$/.test(c)?s=!0:(o["".concat(i,".").concat(c)]=u[c],delete o[i][c]);s||delete o[i]}}return o}function zt(t){return Yt(t,Xt,[],[t])}function Zt(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?st(t[r])?t[r].push(e[r]):at(t[r])?at(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is ".concat(it(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(it(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]}function Xt(t){return ft(t)||ct(t)||lt(t)}function Kt(t){return Wt(t)}var te=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.prototype.encodeUpdate=function(t){return At(t)?this.encodeUpdateCommand(t):"object"===it(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===B)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case Ot.PUSH:case Ot.PULL:case Ot.PULL_ALL:case Ot.POP:case Ot.SHIFT:case Ot.UNSHIFT:case Ot.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,o,i=kt(t.operator);return t.operator===Ot.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,u,s,c,l,f=kt(t.operator);switch(t.operator){case Ot.PUSH:var d=void 0;return d=st(t.operands)?{$each:t.operands.map(Kt)}:t.operands,(e={})[f]=((n={})[t.fieldName]=d,n),e;case Ot.UNSHIFT:return d={$each:t.operands.map(Kt),$position:0},(r={})[f]=((o={})[t.fieldName]=d,o),r;case Ot.POP:return(i={})[f]=((a={})[t.fieldName]=1,a),i;case Ot.SHIFT:return(u={})[f]=((s={})[t.fieldName]=-1,s),u;default:return(c={})[f]=((l={})[t.fieldName]=Kt(t.operands),l),c}},t.prototype.encodeUpdateObject=function(t){var e=zt(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(At(r))e[n]=r._setFieldName(n),Zt(e,this.encodeUpdateCommand(e[n]),n);else{e[n]=r=Kt(r);var o=new qt(Ot.SET,[r],n);Zt(e,this.encodeUpdateCommand(o),n)}}return e},t}(),ee={};function ne(t){if(!Fe.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return ee[e]||(ee[e]=new Fe.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:Fe.createRequest(t.config)}}})),ee[e]}var re=function(){return re=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},re.apply(this,arguments)},oe=function(){function t(t,e,n,r){void 0===r&&(r={});var o=this;this.watch=function(t){return ne(o._db).watch(re(re({},t),{envId:o._db.config.env,collectionName:o._coll,query:JSON.stringify({_id:o.id})}))},this._db=t,this._coll=e,this.id=n,this.request=Fe.createRequest(this._db.config),this.projection=r}return t.prototype.create=function(t,e){e=e||Tt();var n=Array.isArray(t),r={collectionName:this._coll,data:n?t.map(function(t){return Wt(t)}):Wt(t)};return!n&&this.id&&(r._id=this.id),this.request.send("database.addDocument",r).then(function(t){var r;t.code?e(0,t):e(0,n?{ids:(null===(r=t.data)||void 0===r?void 0:r.insertedIds)||[],requestId:t.requestId}:{id:t.data._id,requestId:t.requestId})}).catch(function(t){e(t)}),e.promise},t.prototype.set=function(t,e){if(e=e||Tt(),!this.id)return Promise.resolve({code:"INVALID_PARAM",message:"docId不能为空"});if(!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n=!1,r=function(t){if("object"==typeof t)for(var e in t)t[e]instanceof qt?n=!0:"object"==typeof t[e]&&r(t[e])};if(r(t),n)return Promise.resolve({code:"DATABASE_REQUEST_FAILED",message:"update operator complicit"});var o={collectionName:this._coll,queryType:q.DOC,data:Wt(t),multi:!1,merge:!1,upsert:!0};return this.id&&(o.query={_id:this.id}),this.request.send("database.updateDocument",o).then(function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})}).catch(function(t){e(t)}),e.promise},t.prototype.update=function(t,e){if(e=e||Tt(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={_id:this.id},r={collectionName:this._coll,data:te.encode(t),query:n,queryType:q.DOC,multi:!1,merge:!0,upsert:!1};return this.request.send("database.updateDocument",r).then(function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})}).catch(function(t){e(t)}),e.promise},t.prototype.remove=function(t){t=t||Tt();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:q.DOC,multi:!1};return this.request.send("database.deleteDocument",n).then(function(e){e.code?t(0,e):t(0,{deleted:e.data.deleted,requestId:e.requestId})}).catch(function(e){t(e)}),t.promise},t.prototype.get=function(t){t=t||Tt();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:q.DOC,multi:!1,projection:this.projection};return this.request.send("database.queryDocument",n).then(function(e){if(e.code)t(0,e);else{var n=Nt.formatResDocumentData(e.data.list);t(0,{data:n,requestId:e.requestId})}}).catch(function(e){t(e)}),t.promise},t.prototype.field=function(e){for(var n in e)e[n]?e[n]=1:e[n]=0;return new t(this._db,this._coll,this.id,e)},t}(),ie=function(){function t(){}return t.encode=function(t){return(new ae).encodeQuery(t)},t}(),ae=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n;return Xt(t)?jt(t)?this.encodeLogicCommand(t):Lt(t)?this.encodeQueryCommand(t):((n={})[e]=this.encodeQueryObject(t),n):at(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regex:t.source,$options:t.flags}},t.prototype.encodeLogicCommand=function(t){var e,n,r,o,i,a,u,s=this;switch(t.operator){case Pt.NOR:case Pt.AND:case Pt.OR:var c=kt(t.operator),l=t.operands.map(function(e){return s.encodeQuery(e,t.fieldName)});return(e={})[c]=l,e;case Pt.NOT:c=kt(t.operator);var f=t.operands[0];return lt(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=kt(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)),(u={})[c]=l,u}},t.prototype.encodeQueryCommand=function(t){return Mt(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,o,i,a,u,s,c;if(t.fieldName===B)throw new Error("Cannot encode a comparison command with unset field name");var l=kt(t.operator);switch(t.operator){case Dt.EQ:case Dt.NEQ:case Dt.LT:case Dt.LTE:case Dt.GT:case Dt.GTE:case Dt.ELEM_MATCH:case Dt.EXISTS:case Dt.SIZE:case Dt.MOD:return(e={})[t.fieldName]=((n={})[l]=Kt(t.operands[0]),n),e;case Dt.IN:case Dt.NIN:case Dt.ALL:return(r={})[t.fieldName]=((o={})[l]=Kt(t.operands),o),r;case Dt.GEO_NEAR:var f=t.operands[0];return(i={})[t.fieldName]={$nearSphere:{$geometry:f.geometry.toJSON(),$maxDistance:f.maxDistance,$minDistance:f.minDistance}},i;case Dt.GEO_WITHIN:return f=t.operands[0],(a={})[t.fieldName]={$geoWithin:{$geometry:f.geometry.toJSON()}},a;case Dt.GEO_INTERSECTS:return f=t.operands[0],(u={})[t.fieldName]={$geoIntersects:{$geometry:f.geometry.toJSON()}},u;default:return(s={})[t.fieldName]=((c={})[l]=Kt(t.operands[0]),c),s}},t.prototype.encodeQueryObject=function(t){var e=zt(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 Mt(r)?(e[n]=r._setFieldName(n),o=this.encodeComparisonCommand(e[n]),this.mergeConditionAfterEncode(e,o,n)):Xt(r)&&(e[n]=Kt(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?st(t[r])?t[r]=t[r].concat(e[r]):at(t[r])?at(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is ".concat(it(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(it(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),ue=function(){return ue=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},ue.apply(this,arguments)},se=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){return ne(i._db).watch(ue(ue({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify(i._fieldFilters||{}),limit:i._queryOptions.limit,orderBy:i._fieldOrders?i._fieldOrders.reduce(function(t,e){return t[e.field]=e.direction,t},{}):void 0}))},this._db=t,this._coll=e,this._fieldFilters=n,this._fieldOrders=r||[],this._queryOptions=o||{},this._request=Fe.createRequest(this._db.config)}return t.prototype.get=function(t){t=t||Tt();var e=[];this._fieldOrders&&this._fieldOrders.forEach(function(t){e.push(t)});var n={collectionName:this._coll,queryType:q.WHERE};return this._fieldFilters&&(n.query=this._fieldFilters),e.length>0&&(n.order=e),this._queryOptions.offset&&(n.offset=this._queryOptions.offset),this._queryOptions.limit?n.limit=this._queryOptions.limit<1e3?this._queryOptions.limit:1e3:n.limit=100,this._queryOptions.projection&&(n.projection=this._queryOptions.projection),this._request.send("database.queryDocument",n).then(function(e){if(e.code)t(0,e);else{var n={data:Nt.formatResDocumentData(e.data.list),requestId:e.requestId};void 0!==e.total&&(n.total=e.total),void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset),t(0,n)}}).catch(function(e){t(e)}),t.promise},t.prototype.count=function(t){t=t||Tt();var e={collectionName:this._coll,queryType:q.WHERE};return this._fieldFilters&&(e.query=this._fieldFilters),this._request.send("database.countDocument",e).then(function(e){e.code?t(0,e):t(0,{requestId:e.requestId,total:e.data.total})}).catch(function(e){t(e)}),t.promise},t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(T.QueryParamTypeError);var n=Object.keys(e),r=n.some(function(t){return void 0!==e[t]});if(n.length&&!r)throw Error(T.QueryParamValueError);return new t(this._db,this._coll,ie.encode(e),this._fieldOrders,this._queryOptions)},t.prototype.orderBy=function(e,n){St.isFieldPath(e),St.isFieldOrder(n);var r={field:e,direction:n},o=this._fieldOrders.concat(r);return new t(this._db,this._coll,this._fieldFilters,o,this._queryOptions)},t.prototype.limit=function(e){St.isInteger("limit",e);var n=ue({},this._queryOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.skip=function(e){St.isInteger("offset",e);var n=ue({},this._queryOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.update=function(t,e){if(e=e||Tt(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={collectionName:this._coll,query:this._fieldFilters,queryType:q.WHERE,multi:!0,merge:!0,upsert:!1,data:te.encode(t)};return this._request.send("database.updateDocument",n).then(function(t){t.code?e(0,t):e(0,{requestId:t.requestId,updated:t.data.updated,upsertId:t.data.upsert_id})}).catch(function(t){e(t)}),e.promise},t.prototype.field=function(e){for(var n in e)e[n]?"object"!=typeof e[n]&&(e[n]=1):e[n]=0;var r=ue({},this._queryOptions);return r.projection=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,r)},t.prototype.remove=function(t){t=t||Tt(),Object.keys(this._queryOptions).length>0&&console.warn("`offset`, `limit` and `projection` are not supported in remove() operation"),this._fieldOrders.length>0&&console.warn("`orderBy` is not supported in remove() operation");var e={collectionName:this._coll,query:ie.encode(this._fieldFilters),queryType:q.WHERE,multi:!0};return this._request.send("database.deleteDocument",e).then(function(e){e.code?t(0,e):t(0,{requestId:e.requestId,deleted:e.data.deleted})}).catch(function(e){t(e)}),t.promise},t}();const ce=(t=>{var e={};return f.d(e,t),e})({EJSON:()=>l.EJSON});var le=function(){function t(t,e){this._stages=[],t&&e&&(this._db=t,this._request=Fe.createRequest(this._db.config),this._collectionName=e)}return t.prototype.end=function(){return t=this,e=void 0,r=function(){var t;return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}(this,function(e){switch(e.label){case 0:if(!this._collectionName||!this._db)throw new Error("Aggregation pipeline cannot send request");return[4,this._request.send("database.aggregate",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:JSON.parse(t.data.list).map(ce.EJSON.parse)}]:[2,t]}})},new((n=void 0)||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())});var t,e,n,r},t.prototype.unwrap=function(){return this._stages},t.prototype.done=function(){return this._stages.map(function(t){var e,n=t.stageKey,r=t.stageValue;return(e={})[n]=JSON.parse(r),e})},t.prototype._pipe=function(t,e){return this._stages.push({stageKey:"$".concat(t),stageValue:JSON.stringify(e)}),this},t.prototype.addFields=function(t){return this._pipe("addFields",t)},t.prototype.bucket=function(t){return this._pipe("bucket",t)},t.prototype.bucketAuto=function(t){return this._pipe("bucketAuto",t)},t.prototype.count=function(t){return this._pipe("count",t)},t.prototype.geoNear=function(t){return t.query&&(t.query=ie.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new It(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",ie.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 fe=le;var de=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)}}(),pe=function(t){function e(e,n){return t.call(this,e,n)||this}return de(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 oe(this._db,this._coll,t)},e.prototype.add=function(t,e){return new oe(this._db,this._coll,void 0).create(t,e)},e.prototype.aggregate=function(){return new fe(this._db,this._coll)},e}(se),he={eq:function(t){return new Rt(Dt.EQ,[t])},neq:function(t){return new Rt(Dt.NEQ,[t])},lt:function(t){return new Rt(Dt.LT,[t])},lte:function(t){return new Rt(Dt.LTE,[t])},gt:function(t){return new Rt(Dt.GT,[t])},gte:function(t){return new Rt(Dt.GTE,[t])},in:function(t){return new Rt(Dt.IN,t)},nin:function(t){return new Rt(Dt.NIN,t)},all:function(t){return new Rt(Dt.ALL,t)},elemMatch:function(t){return new Rt(Dt.ELEM_MATCH,[t])},exists:function(t){return new Rt(Dt.EXISTS,[t])},size:function(t){return new Rt(Dt.SIZE,[t])},mod:function(t){return new Rt(Dt.MOD,[t])},geoNear:function(t){return new Rt(Dt.GEO_NEAR,[t])},geoWithin:function(t){return new Rt(Dt.GEO_WITHIN,[t])},geoIntersects:function(t){return new Rt(Dt.GEO_INTERSECTS,[t])},and:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=st(arguments[0])?arguments[0]:Array.from(arguments);return new xt(Pt.AND,n)},nor:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=st(arguments[0])?arguments[0]:Array.from(arguments);return new xt(Pt.NOR,n)},or:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=st(arguments[0])?arguments[0]:Array.from(arguments);return new xt(Pt.OR,n)},not:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=st(arguments[0])?arguments[0]:Array.from(arguments);return new xt(Pt.NOT,n)},set:function(t){return new qt(Ot.SET,[t])},remove:function(){return new qt(Ot.REMOVE,[])},inc:function(t){return new qt(Ot.INC,[t])},mul:function(t){return new qt(Ot.MUL,[t])},push:function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(at(e[0])&&e[0].hasOwnProperty("each")){var r=e[0];t={$each:r.each,$position:r.position,$sort:r.sort,$slice:r.slice}}else t=st(e[0])?e[0]:Array.from(e);return new qt(Ot.PUSH,t)},pull:function(t){return new qt(Ot.PULL,t)},pullAll:function(t){return new qt(Ot.PULL_ALL,t)},pop:function(){return new qt(Ot.POP,[])},shift:function(){return new qt(Ot.SHIFT,[])},unshift:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=st(arguments[0])?arguments[0]:Array.from(arguments);return new qt(Ot.UNSHIFT,n)},addToSet:function(t){return new qt(Ot.ADD_TO_SET,t)},rename:function(t){return new qt(Ot.RENAME,[t])},bit:function(t){return new qt(Ot.BIT,[t])},max:function(t){return new qt(Ot.MAX,[t])},min:function(t){return new qt(Ot.MIN,[t])},expr:function(t){return{$expr:t}},jsonSchema:function(t){return{$jsonSchema:t}},text:function(t){return function(t){return"string"===it(t)}(t)?{$search:t.search}:{$search:t.search,$language:t.language,$caseSensitive:t.caseSensitive,$diacriticSensitive:t.diacriticSensitive}},aggregate:{pipeline:function(){return new fe},abs:function(t){return new ye("abs",t)},add:function(t){return new ye("add",t)},ceil:function(t){return new ye("ceil",t)},divide:function(t){return new ye("divide",t)},exp:function(t){return new ye("exp",t)},floor:function(t){return new ye("floor",t)},ln:function(t){return new ye("ln",t)},log:function(t){return new ye("log",t)},log10:function(t){return new ye("log10",t)},mod:function(t){return new ye("mod",t)},multiply:function(t){return new ye("multiply",t)},pow:function(t){return new ye("pow",t)},sqrt:function(t){return new ye("sqrt",t)},subtract:function(t){return new ye("subtract",t)},trunc:function(t){return new ye("trunc",t)},arrayElemAt:function(t){return new ye("arrayElemAt",t)},arrayToObject:function(t){return new ye("arrayToObject",t)},concatArrays:function(t){return new ye("concatArrays",t)},filter:function(t){return new ye("filter",t)},in:function(t){return new ye("in",t)},indexOfArray:function(t){return new ye("indexOfArray",t)},isArray:function(t){return new ye("isArray",t)},map:function(t){return new ye("map",t)},range:function(t){return new ye("range",t)},reduce:function(t){return new ye("reduce",t)},reverseArray:function(t){return new ye("reverseArray",t)},size:function(t){return new ye("size",t)},slice:function(t){return new ye("slice",t)},zip:function(t){return new ye("zip",t)},and:function(t){return new ye("and",t)},not:function(t){return new ye("not",t)},or:function(t){return new ye("or",t)},cmp:function(t){return new ye("cmp",t)},eq:function(t){return new ye("eq",t)},gt:function(t){return new ye("gt",t)},gte:function(t){return new ye("gte",t)},lt:function(t){return new ye("lt",t)},lte:function(t){return new ye("lte",t)},neq:function(t){return new ye("ne",t)},cond:function(t){return new ye("cond",t)},ifNull:function(t){return new ye("ifNull",t)},switch:function(t){return new ye("switch",t)},dateFromParts:function(t){return new ye("dateFromParts",t)},dateFromString:function(t){return new ye("dateFromString",t)},dayOfMonth:function(t){return new ye("dayOfMonth",t)},dayOfWeek:function(t){return new ye("dayOfWeek",t)},dayOfYear:function(t){return new ye("dayOfYear",t)},isoDayOfWeek:function(t){return new ye("isoDayOfWeek",t)},isoWeek:function(t){return new ye("isoWeek",t)},isoWeekYear:function(t){return new ye("isoWeekYear",t)},millisecond:function(t){return new ye("millisecond",t)},minute:function(t){return new ye("minute",t)},month:function(t){return new ye("month",t)},second:function(t){return new ye("second",t)},hour:function(t){return new ye("hour",t)},week:function(t){return new ye("week",t)},year:function(t){return new ye("year",t)},literal:function(t){return new ye("literal",t)},mergeObjects:function(t){return new ye("mergeObjects",t)},objectToArray:function(t){return new ye("objectToArray",t)},allElementsTrue:function(t){return new ye("allElementsTrue",t)},anyElementTrue:function(t){return new ye("anyElementTrue",t)},setDifference:function(t){return new ye("setDifference",t)},setEquals:function(t){return new ye("setEquals",t)},setIntersection:function(t){return new ye("setIntersection",t)},setIsSubset:function(t){return new ye("setIsSubset",t)},setUnion:function(t){return new ye("setUnion",t)},concat:function(t){return new ye("concat",t)},dateToString:function(t){return new ye("dateToString",t)},indexOfBytes:function(t){return new ye("indexOfBytes",t)},indexOfCP:function(t){return new ye("indexOfCP",t)},split:function(t){return new ye("split",t)},strLenBytes:function(t){return new ye("strLenBytes",t)},strLenCP:function(t){return new ye("strLenCP",t)},strcasecmp:function(t){return new ye("strcasecmp",t)},substr:function(t){return new ye("substr",t)},substrBytes:function(t){return new ye("substrBytes",t)},substrCP:function(t){return new ye("substrCP",t)},toLower:function(t){return new ye("toLower",t)},toUpper:function(t){return new ye("toUpper",t)},meta:function(t){return new ye("meta",t)},addToSet:function(t){return new ye("addToSet",t)},avg:function(t){return new ye("avg",t)},first:function(t){return new ye("first",t)},last:function(t){return new ye("last",t)},max:function(t){return new ye("max",t)},min:function(t){return new ye("min",t)},push:function(t){return new ye("push",t)},stdDevPop:function(t){return new ye("stdDevPop",t)},stdDevSamp:function(t){return new ye("stdDevSamp",t)},sum:function(t){return new ye("sum",t)},let:function(t){return new ye("let",t)}},project:{slice:function(t){return new me("slice",t)},elemMatch:function(t){return new me("elemMatch",t)}}},ye=function(t,e){this["$"+t]=e},me=function(t,e){this["$"+t]=e},ve=function(){function t(t){var e=t.regexp,n=t.options;if(!e)throw new TypeError("regexp must be a string");this.$regex=e,this.$options=n}return t.prototype.parse=function(){return{$regex:this.$regex,$options:this.$options}},Object.defineProperty(t.prototype,"_internalType",{get:function(){return ot},enumerable:!1,configurable:!0}),t}();function we(t){return new ve(t)}var ge="insert document failed",be="DATABASE_TRANSACTION_CONFLICT",_e=function(){return _e=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},_e.apply(this,arguments)},Oe=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},Ee=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:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Ne="database.updateDocInTransaction",Se=function(){function t(t,e,n){this._coll=e,this.id=n,this._transaction=t,this._request=this._transaction.getRequestMethod(),this._transactionId=this._transaction.getTransactionId()}return t.prototype.create=function(t){return Oe(this,void 0,void 0,function(){var e,n,r,o;return Ee(this,function(i){switch(i.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,data:ce.EJSON.stringify(Wt(t),{relaxed:!1})},this.id&&(e._id=this.id),[4,this._request.send("database.insertDocInTransaction",e)];case 1:if((n=i.sent()).code)throw n;if(r=ce.EJSON.parse(n.inserted),1==(o=ce.EJSON.parse(n.ok))&&1==r)return[2,_e(_e({},n),{ok:o,inserted:r})];throw new Error(ge)}})})},t.prototype.get=function(){return Oe(this,void 0,void 0,function(){var t,e;return Ee(this,function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.getInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,{data:"null"!==e.data?Nt.formatField(ce.EJSON.parse(e.data)):ce.EJSON.parse(e.data),requestId:e.requestId}]}})})},t.prototype.set=function(t){return Oe(this,void 0,void 0,function(){var e,n;return Ee(this,function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:ce.EJSON.stringify(Wt(t),{relaxed:!1}),upsert:!0},[4,this._request.send(Ne,e)];case 1:if((n=r.sent()).code)throw n;return[2,_e(_e({},n),{updated:ce.EJSON.parse(n.updated),upserted:n.upserted?JSON.parse(n.upserted):null})]}})})},t.prototype.update=function(t){return Oe(this,void 0,void 0,function(){var e,n;return Ee(this,function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:ce.EJSON.stringify(te.encode(t),{relaxed:!1})},[4,this._request.send(Ne,e)];case 1:if((n=r.sent()).code)throw n;return[2,_e(_e({},n),{updated:ce.EJSON.parse(n.updated)})]}})})},t.prototype.delete=function(){return Oe(this,void 0,void 0,function(){var t,e;return Ee(this,function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.deleteDocInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,_e(_e({},e),{deleted:ce.EJSON.parse(e.deleted)})]}})})},t}(),Ie=function(){return Ie=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},Ie.apply(this,arguments)},Te=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},Pe=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:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},qe="database.getInTransaction",Ae=function(){function t(t,e,n,r,o){this._coll=e,this._transaction=t,this._fieldFilters=n,this._fieldOrders=r||[],this._queryOptions=o||{},this._request=this._transaction.getRequestMethod(),this._transactionId=this._transaction.getTransactionId()}return t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(T.QueryParamTypeError);var n=Object.keys(e),r=n.some(function(t){return void 0!==e[t]});if(n.length&&!r)throw Error(T.QueryParamValueError);return new t(this._transaction,this._coll,ie.encode(e),this._fieldOrders,this._queryOptions)},t.prototype.orderBy=function(e,n){St.isFieldPath(e),St.isFieldOrder(n);var r={field:e,direction:n},o=this._fieldOrders.concat(r);return new t(this._transaction,this._coll,this._fieldFilters,o,this._queryOptions)},t.prototype.limit=function(e){St.isInteger("limit",e);var n=Ie({},this._queryOptions);return n.limit=e,new t(this._transaction,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.skip=function(e){St.isInteger("offset",e);var n=Ie({},this._queryOptions);return n.offset=e,new t(this._transaction,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.field=function(e){for(var n in e)e[n]?"object"!=typeof e[n]&&(e[n]=1):e[n]=0;var r=Ie({},this._queryOptions);return r.projection=e,new t(this._transaction,this._coll,this._fieldFilters,this._fieldOrders,r)},t.prototype.get=function(){return Te(this,void 0,void 0,function(){var t,e,n,r,o,i;return Pe(this,function(a){switch(a.label){case 0:return t=[],this._fieldOrders&&this._fieldOrders.forEach(function(e){t.push(e)}),e={collectionName:this._coll,transactionId:this._transactionId},this._fieldFilters&&(e.query=this._fieldFilters),t.length>0&&(e.order=t),this._queryOptions.offset&&(e.offset=this._queryOptions.offset),this._queryOptions.limit?e.limit=this._queryOptions.limit<1e3?this._queryOptions.limit:1e3:e.limit=100,this._queryOptions.projection&&(e.projection=this._queryOptions.projection),[4,this._request.send(qe,e)];case 1:if((n=a.sent()).code)throw n;return r="null"!==n.data?ce.EJSON.parse(n.data):null,o=r?Array.isArray(r)?Nt.formatResDocumentData(r):[Nt.formatField(r)]:[],i={data:o,requestId:n.requestId},void 0!==n.total&&(i.total=n.total),void 0!==n.limit&&(i.limit=n.limit),void 0!==n.offset&&(i.offset=n.offset),[2,i]}})})},t.prototype.count=function(){return Te(this,void 0,void 0,function(){var t,e,n,r;return Pe(this,function(o){switch(o.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId},this._fieldFilters&&(t.query=this._fieldFilters),[4,this._request.send(qe,t)];case 1:if((e=o.sent()).code)throw e;return n="null"!==e.data?ce.EJSON.parse(e.data):null,r=Array.isArray(n)?n.length:n?1:0,[2,{requestId:e.requestId,total:void 0!==e.total?e.total:r}]}})})},t.prototype.update=function(t){return Te(this,void 0,void 0,function(){var e,n;return Pe(this,function(r){switch(r.label){case 0:if(!t||"object"!=typeof t)throw new Error("参数必需是非空对象");if(t.hasOwnProperty("_id"))throw new Error("不能更新_id的值");return e={collectionName:this._coll,transactionId:this._transactionId,query:this._fieldFilters,data:ce.EJSON.stringify(te.encode(t),{relaxed:!1})},[4,this._request.send("database.updateDocInTransaction",e)];case 1:if((n=r.sent()).code)throw n;return[2,Ie(Ie({},n),{updated:ce.EJSON.parse(n.updated)})]}})})},t.prototype.remove=function(){return Te(this,void 0,void 0,function(){var t,e;return Pe(this,function(n){switch(n.label){case 0:return Object.keys(this._queryOptions).length>0&&console.warn("`offset`, `limit` and `projection` are not supported in remove() operation"),this._fieldOrders.length>0&&console.warn("`orderBy` is not supported in remove() operation"),t={collectionName:this._coll,transactionId:this._transactionId,query:this._fieldFilters},[4,this._request.send("database.deleteDocInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,Ie(Ie({},e),{deleted:ce.EJSON.parse(e.deleted)})]}})})},t}(),xe=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)}}(),je=function(t){function e(e,n){return t.call(this,e,n)||this}return xe(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 Se(this._transaction,this._coll,t)},e.prototype.add=function(t){var e;return void 0!==t._id&&(e=t._id),new Se(this._transaction,this._coll,e).create(t)},e}(Ae),De=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},Ce=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:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Re=function(){function t(t){this._db=t,this._request=Fe.createRequest(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return t.prototype.init=function(){return De(this,void 0,void 0,function(){var t;return Ce(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 je(this,t)},t.prototype.getTransactionId=function(){return this._id},t.prototype.getRequestMethod=function(){return this._request},t.prototype.commit=function(){return De(this,void 0,void 0,function(){var t,e;return Ce(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 De(this,void 0,void 0,function(){var e,n;return Ce(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 Le(){return De(this,void 0,void 0,function(){var t;return Ce(this,function(e){switch(e.label){case 0:return[4,(t=new Re(this)).init()];case 1:return e.sent(),[2,t]}})})}function Me(t,e){return void 0===e&&(e=3),De(this,void 0,void 0,function(){var n,r,o,i,a=this;return Ce(this,function(u){switch(u.label){case 0:return u.trys.push([0,4,,10]),[4,(n=new Re(this)).init()];case 1:return u.sent(),[4,t(n)];case 2:if(r=u.sent(),!0===n.aborted)throw n.abortReason;return[4,n.commit()];case 3:return u.sent(),[2,r];case 4:if(o=u.sent(),!1===n.inited)throw o;return i=function(t){return De(a,void 0,void 0,function(){return Ce(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:u.sent(),u.label=6;case 6:return o&&o.code===be?[4,Me.bind(this)(t,--e)]:[3,8];case 7:return[2,u.sent()];case 8:return[4,i(o)];case 9:return u.sent(),[3,10];case 10:return[2]}})})}var Fe=function(){function t(t){this.config=t,this.Geo=p,this.serverDate=_t,this.command=he,this.RegExp=we,this.startTransaction=Le,this.runTransaction=Me,this.logicCommand=xt,this.updateCommand=qt,this.queryCommand=Rt}return t.createRequest=function(e){var n=new t.reqClass(e),r=n.send;return n.send=function(t,n){return e.instance&&(n.instance=e.instance),e.database&&(n.database=e.database),r.call(this,t,n)},n},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new pe(this,t)},t.prototype.createCollection=function(e){var n={collectionName:e};return t.createRequest(this.config).send("database.addCollection",n)},t}(),$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)}}(),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{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((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:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Ge={filterRes:function(t){return delete t.header,delete t.statusCode,t},flattenResData:function(t){if("object"==typeof t.data&&null!==t.data){var e=ke(ke({},t),t.data);return delete e.data,e}return t},safeParseEJSON:function(t){if("string"!=typeof t)return t;try{return ce.EJSON.parse(t)}catch(e){return 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){var e,n,r,o,i,a,u,s;return Je(this,void 0,Promise,function(){var c,l,f,d;return Ue(this,function(p){switch(p.label){case 0:return c=!!(null===(n=null===(e=t.query)||void 0===e?void 0:e._id)||void 0===n?void 0:n.$eq),l=Ge.buildQueryParams(ke({projection:t.projection,transactionId:t.transactionId},c?{}:{offset:null!==(r=t.offset)&&void 0!==r?r:0,limit:null!==(o=t.limit)&&void 0!==o?o:100,order:t.order,query:t.query?ce.EJSON.stringify(t.query,{relaxed:!1}):void 0})),f="".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(l),c&&(f="".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/").concat((null===(i=t.query._id)||void 0===i?void 0:i.$eq)||t.query._id,"?").concat(l)),[4,this.gateWay({url:f,method:"GET"})];case 1:return(d=p.sent()).data=Ge.safeParseEJSON(JSON.stringify(d.data)),!c||d.code||(null===(a=d.data)||void 0===a?void 0:a.code)?(d.code||(null===(u=d.data)||void 0===u?void 0:u.code)?d=ke(ke({},d),{code:d.code||(null===(s=d.data)||void 0===s?void 0:s.code),data:ke(ke({},d.data),{list:[]})}):Array.isArray(d.data)?d=ke(ke({},d),{data:{list:d.data}}):d.data&&!Array.isArray(d.data.list)&&(d=ke(ke({},d),{data:ke(ke({},d.data),{list:[]})})),[2,Ge.filterRes(d)]):[2,ke(ke({},d),{data:{list:[d.data]}})]}})})},"database.addDocument":function(t){var e,n,r;return Je(this,void 0,Promise,function(){var o;return Ue(this,function(i){switch(i.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"POST",data:ke({data:Array.isArray(t.data)?t.data:[t.data]},t.transactionId&&{transactionId:t.transactionId})})];case 1:return o=i.sent(),Array.isArray(t.data)?o=ke(ke({},o),{data:ke({ids:(null===(e=o.data)||void 0===e?void 0:e.insertedIds)||[]},o.data)}):(null===(r=null===(n=o.data)||void 0===n?void 0:n.insertedIds)||void 0===r?void 0:r[0])&&(o=ke(ke({},o),{data:ke({_id:o.data.insertedIds[0]},o.data)})),[2,Ge.filterRes(o)]}})})},"database.updateDocument":function(t){return Je(this,void 0,Promise,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"PATCH",data:ke({query:t.query,data:t.data,multi:!!t.multi,upsert:!!t.upsert,replaceMode:!!t.replaceMode},t.transactionId&&{transactionId:t.transactionId})})];case 1:return e=n.sent(),[2,Ge.filterRes(e)]}})})},"database.deleteDocument":function(t){return Je(this,void 0,Promise,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/remove"),method:"POST",data:ke({query:t.query,multi:!!t.multi},t.transactionId&&{transactionId:t.transactionId})})];case 1:return e=n.sent(),[2,Ge.filterRes(e)]}})})},"database.countDocument":function(t){return Je(this,void 0,Promise,function(){var e,n;return Ue(this,function(r){switch(r.label){case 0:return e=Ge.buildQueryParams({count:!0,query:t.query?ce.EJSON.stringify(t.query,{relaxed:!1}):void 0}),[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(e),method:"GET"})];case 1:return n=r.sent(),[2,Ge.filterRes(n)]}})})},"database.addCollection":function(t){return Je(this,void 0,Promise,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/collections"),method:"POST",data:{collectionName:t.collectionName}})];case 1:return e=n.sent(),[2,Ge.filterRes(e)]}})})},"database.aggregate":function(t){var e;return Je(this,void 0,Promise,function(){var n,r;return Ue(this,function(o){switch(o.label){case 0:return n=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]=ce.EJSON.serialize(r),e}catch(e){return(n={})[t.stageKey]=t.stageValue,n}}),[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/aggregations"),method:"POST",data:{pipeline:n}})];case 1:return r=o.sent(),Array.isArray(null===(e=r.data)||void 0===e?void 0:e.list)&&(r.data.list=JSON.stringify(r.data.list.map(function(t){return JSON.stringify(t)}))),[2,Ge.filterRes(r)]}})})},"database.startTransaction":function(t){return Je(this,void 0,void 0,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/transactions"),method:"POST"})];case 1:return e=n.sent(),[2,Ge.filterRes(Ge.flattenResData(e))]}})})},"database.commitTransaction":function(t){return Je(this,void 0,void 0,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/commit"),method:"POST"})];case 1:return e=n.sent(),[2,Ge.filterRes(e)]}})})},"database.abortTransaction":function(t){return Je(this,void 0,void 0,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/rollback"),method:"POST"})];case 1:return e=n.sent(),[2,Ge.filterRes(e)]}})})},"database.getInTransaction":function(t){var e;return Je(this,void 0,void 0,function(){var n;return Ue(this,function(r){switch(r.label){case 0:return[4,Ge["database.queryDocument"].call(this,t)];case 1:return"object"==typeof(n=r.sent()).data&&null!==n.data?(null===(e=n.data)||void 0===e?void 0:e.code)?[2,Ge.flattenResData(n)]:[2,ke(ke({},n),{data:JSON.stringify(n.data)})]:[2,n]}})})},"database.updateDocInTransaction":function(t){return Je(this,void 0,void 0,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return t.data=Ge.safeParseEJSON(t.data),[4,Ge["database.updateDocument"].call(this,t)];case 1:return e=n.sent(),[2,Ge.flattenResData(e)]}})})},"database.deleteDocInTransaction":function(t){return Je(this,void 0,void 0,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,Ge["database.deleteDocument"].call(this,t)];case 1:return e=n.sent(),[2,Ge.flattenResData(e)]}})})},"database.insertDocInTransaction":function(t){var e;return Je(this,void 0,Promise,function(){var n,r;return Ue(this,function(o){switch(o.label){case 0:return t.data=Ge.safeParseEJSON(t.data),[4,Ge["database.addDocument"].call(this,t)];case 1:return"object"==typeof(n=o.sent()).data&&null!==n.data?(r=!!(null===(e=n.data)||void 0===e?void 0:e._id),n=ke(ke(ke({},n),{inserted:r?1:0,ok:r?1:0}),n.data)):n=ke({inserted:0,ok:0},n),delete n.data,[2,n]}})})},"database.runCommands":function(t){return Je(this,void 0,Promise,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/commands"),method:"POST",data:ke({commands:ce.EJSON.serialize(t.commands)},t.transactionId&&{transactionId:t.transactionId})})];case 1:"object"==typeof(e=n.sent()).data&&null!==e.data&&(delete(e=ke(ke({},e),e.data)).data,delete e.request_id);try{e=ce.EJSON.deserialize(e)}catch(t){}return[2,Ge.filterRes(e)]}})})}},We={name:"database",entity:{database:function(t){var e=this.platform,n=e.adapter,r=e.runtime,o=function(t){function e(e){return t.call(this,e)||this}return $e(e,t),e.prototype.send=function(e,n){return Je(this,void 0,void 0,function(){var r;return Ue(this,function(o){switch(o.label){case 0:return r=null,"GATEWAY"===this.config.endPointMode&&Ge[e]?[4,Ge[e].call(this,n)]:[3,2];case 1:return r=o.sent(),[3,4];case 2:return[4,t.prototype.send.call(this,e,n)];case 3:r=o.sent(),o.label=4;case 4:return[2,r]}})})},e}(this.request.constructor);return Fe.reqClass=o,Fe.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},Fe.runtime=r,this.wsClientClass&&(Fe.wsClass=n.wsClass,Fe.wsClientClass=this.wsClientClass),Fe.ws||(Fe.ws=null),new(function(t){function e(e){return t.call(this,e)||this}return $e(e,t),e.prototype.runCommands=function(t){return Je(this,void 0,Promise,function(){return Ue(this,function(e){return[2,Fe.createRequest(this.config).send("database.runCommands",t)]})})},e}(Fe))(ke(ke(ke({},this.config),{_fromApp:this}),t))}}};try{cloudbase.registerComponent(We)}catch(t){}function Qe(t){try{t.registerComponent(We)}catch(t){console.warn(t)}}try{window.registerDatabase=Qe}catch(t){}h.default.registerVersion("3.6.3");try{(0,v.registerAuth)(h.default),(0,w.registerFunctions)(h.default),(0,g.registerStorage)(h.default),Qe(h.default),(0,b.registerRealtime)(h.default),(0,_.registerModel)(h.default),(0,O.registerAi)(h.default),(0,E.registerCloudrun)(h.default),(0,N.registerMySQL)(h.default),(0,S.registerApis)(h.default)}catch(t){}try{window.cloudbase=h.default}catch(t){}const He=h.default;var Be=d.Z;export{Be as default};
1
+ import*as t from"@cloudbase/app";import*as e from"@cloudbase/auth";import*as n from"@cloudbase/functions";import*as r from"@cloudbase/storage";import*as o from"@cloudbase/realtime";import*as i from"@cloudbase/model";import*as a from"@cloudbase/ai";import*as u from"@cloudbase/cloudrun";import*as s from"@cloudbase/mysql";import*as c from"@cloudbase/apis";import*as l from"bson";var f={d:(t,e)=>{for(var n in e)f.o(e,n)&&!f.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})}},d={};f.d(d,{Z:()=>He});var p={};f.r(p),f.d(p,{LineString:()=>dt,MultiLineString:()=>vt,MultiPoint:()=>yt,MultiPolygon:()=>gt,Point:()=>It,Polygon:()=>ht});const h=(y={default:()=>t.default},m={},f.d(m,y),m);var y,m;const v=(t=>{var e={};return f.d(e,t),e})({registerAuth:()=>e.registerAuth}),w=(t=>{var e={};return f.d(e,t),e})({registerFunctions:()=>n.registerFunctions}),g=(t=>{var e={};return f.d(e,t),e})({registerStorage:()=>r.registerStorage}),b=(t=>{var e={};return f.d(e,t),e})({registerRealtime:()=>o.registerRealtime}),_=(t=>{var e={};return f.d(e,t),e})({registerModel:()=>i.registerModel}),O=(t=>{var e={};return f.d(e,t),e})({registerAi:()=>a.registerAi}),E=(t=>{var e={};return f.d(e,t),e})({registerCloudrun:()=>u.registerCloudrun}),N=(t=>{var e={};return f.d(e,t),e})({registerMySQL:()=>s.registerMySQL}),S=(t=>{var e={};return f.d(e,t),e})({registerApis:()=>c.registerApis});var I,T;!function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined"}(T||(T={}));var P,q,A="Object",x="GeoPoint",j="GeoLineString",D="GeoPolygon",C="GeoMultiPoint",R="GeoMultiLineString",L="GeoMultiPolygon",M="Date",F="ServerDate",$=["desc","asc"],k=["<","<=","==",">=",">"];!function(t){t.lt="<",t.gt=">",t.lte="<=",t.gte=">=",t.eq="=="}(P||(P={})),(I={})[P.eq]="$eq",I[P.lt]="$lt",I[P.lte]="$lte",I[P.gt]="$gt",I[P.gte]="$gte",function(t){t.WHERE="WHERE",t.DOC="DOC"}(q||(q={}));var J,U=(J=function(t,e){return J=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])},J(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}J(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),G=[],W={},Q=function(t){function e(e,n){if(n!==W)throw new TypeError("InternalSymbol cannot be constructed with new operator");return t.call(this,e)||this}return U(e,t),e.for=function(t){for(var n=0,r=G.length;n<r;n++)if(G[n].target===t)return G[n].instance;var o=new e(t,W);return G.push({target:t,instance:o}),o},e}(function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})});const H=Q;var B=H.for("UNSET_FIELD_NAME"),V=H.for("UPDATE_COMMAND"),Y=H.for("QUERY_COMMAND"),z=H.for("LOGIC_COMMAND"),Z=H.for("GEO_POINT"),X=H.for("SYMBOL_GEO_LINE_STRING"),K=H.for("SYMBOL_GEO_POLYGON"),tt=H.for("SYMBOL_GEO_MULTI_POINT"),et=H.for("SYMBOL_GEO_MULTI_LINE_STRING"),nt=H.for("SYMBOL_GEO_MULTI_POLYGON"),rt=H.for("SERVER_DATE"),ot=H.for("REGEXP"),it=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},at=function(t){return"object"===it(t)},ut=function(t){return"number"===it(t)},st=function(t){return Array.isArray(t)},ct=function(t){return"date"===it(t)},lt=function(t){return"regexp"===it(t)},ft=function(t){return t&&t._internalType instanceof Q},dt=function(){function t(t){if(!st(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 It))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||!st(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(!ut(i[0])||!ut(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}(),pt=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.")},ht=function(){function t(t){if(!st(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 dt))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"));if(!dt.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||!st(t.coordinates))return!1;try{for(var i=pt(t.coordinates),a=i.next();!a.done;a=i.next()){var u=a.value;if(!this.isCloseLineString(u))return!1;try{for(var s=(r=void 0,pt(u)),c=s.next();!c.done;c=s.next()){var l=c.value;if(!ut(l[0])||!ut(l[1]))return!1}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}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 nt},enumerable:!1,configurable:!0}),t}(),yt=function(){function t(t){if(!st(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 It))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||!st(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(!ut(i[0])||!ut(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 tt},enumerable:!1,configurable:!0}),t}(),mt=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},vt=function(){function t(t){if(!st(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 dt))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||!st(t.coordinates))return!1;try{for(var i=mt(t.coordinates),a=i.next();!a.done;a=i.next()){var u=a.value;try{for(var s=(r=void 0,mt(u)),c=s.next();!c.done;c=s.next()){var l=c.value;if(!ut(l[0])||!ut(l[1]))return!1}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}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 et},enumerable:!1,configurable:!0}),t}(),wt=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},gt=function(){function t(t){var e,n;if(!st(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=wt(t),o=r.next();!o.done;o=r.next()){var i=o.value;if(!(i instanceof ht))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||!st(t.coordinates))return!1;try{for(var u=wt(t.coordinates),s=u.next();!s.done;s=u.next()){var c=s.value;try{for(var l=(r=void 0,wt(c)),f=l.next();!f.done;f=l.next()){var d=f.value;try{for(var p=(i=void 0,wt(d)),h=p.next();!h.done;h=p.next()){var y=h.value;if(!ut(y[0])||!ut(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{s&&!s.done&&(n=u.return)&&n.call(u)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return K},enumerable:!1,configurable:!0}),t}(),bt=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 rt},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$date:{offset:this.offset}}},t}();function _t(t){return new bt(t)}var Ot,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 x:o=new It(i.coordinates[0],i.coordinates[1]);break;case j:o=new dt(i.coordinates.map(function(t){return new It(t[0],t[1])}));break;case D:o=new ht(i.coordinates.map(function(t){return new dt(t.map(function(t){var e=Et(t,2),n=e[0],r=e[1];return new It(n,r)}))}));break;case C:o=new yt(i.coordinates.map(function(t){return new It(t[0],t[1])}));break;case R:o=new vt(i.coordinates.map(function(t){return new dt(t.map(function(t){var e=Et(t,2),n=e[0],r=e[1];return new It(n,r)}))}));break;case L:o=new gt(i.coordinates.map(function(t){return new ht(t.map(function(t){return new dt(t.map(function(t){var e=Et(t,2),n=e[0],r=e[1];return new It(n,r)}))}))}));break;case M:o=new Date(1e3*i.$timestamp);break;case A:case"Array":o=t.formatField(i);break;case F:o=new Date(i.$date);break;default:o=i}Array.isArray(r)?r.push(o):r[n]=o}),r},t.whichType=function(t){var e=Object.prototype.toString.call(t).slice(8,-1);if(e===M)return"BsonDate";if(e===A){if(t instanceof It)return x;if(t instanceof Date)return M;if(t instanceof bt)return F;t.$timestamp?e=M:t.$date?e=F:It.validate(t)?e=x:dt.validate(t)?e=j:ht.validate(t)?e=D:yt.validate(t)?e=C:vt.validate(t)?e=R:gt.validate(t)&&(e=L)}return e},t.generateDocId=function(){for(var t="",e=0;e<24;e++)t+="ABCDEFabcdef0123456789".charAt(Math.floor(22*Math.random()));return t},t}(),St=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+T.IntergerError);return!0},t.isFieldOrder=function(t){if(-1===$.indexOf(t))throw new Error(T.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===k.indexOf(t))throw new Error(T.OpStrError);return!0},t.isCollName=function(t){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(t))throw new Error(T.CollNameError);return!0},t.isDocID=function(t){if(!/^([a-fA-F0-9]){24}$/.test(t))throw new Error(T.DocIDError);return!0},t}(),It=function(){function t(t,e){St.isGeopoint("longitude",t),St.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&&st(t.coordinates)&&St.isGeopoint("longitude",t.coordinates[0])&&St.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return Z},enumerable:!1,configurable:!0}),t}(),Tt=function(){var t=function(){};if(!Promise){t.promise={};var e=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(t.promise,"then",{get:e}),Object.defineProperty(t.promise,"catch",{get:e}),t}var n=new Promise(function(e,n){t=function(t,r){return t?n(t):e(r)}});return t.promise=n,t};!function(t){t.SET="set",t.REMOVE="remove",t.INC="inc",t.MUL="mul",t.PUSH="push",t.PULL="pull",t.PULL_ALL="pullAll",t.POP="pop",t.SHIFT="shift",t.UNSHIFT="unshift",t.ADD_TO_SET="addToSet",t.BIT="bit",t.RENAME="rename",t.MAX="max",t.MIN="min"}(Ot||(Ot={}));var Pt,qt=function(){function t(t,e,n){this._internalType=V,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||B}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function At(t){return t&&t instanceof qt&&t._internalType===V}!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(Pt||(Pt={}));var xt=function(){function t(t,e,n){if(this._internalType=z,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||B,this.fieldName!==B)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,o=e.length;r<o;r++)(jt(i=e[r])||Lt(i))&&(e[r]=i._setFieldName(this.fieldName))}else{var i;(jt(i=e)||Lt(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(Pt.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(Pt.OR,r,this.fieldName)},t}();function jt(t){return t&&t instanceof xt&&t._internalType===z}var Dt,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)}}();!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"}(Dt||(Dt={}));var Rt=function(t){function e(e,n,r){var o=t.call(this,e,n,r)||this;return o.operator=e,o._internalType=Y,o}return Ct(e,t),e.prototype.toJSON=function(){var t,e;switch(this.operator){case Dt.IN:case Dt.NIN:return(t={})["$"+this.operator]=this.operands,t;default:return(e={})["$"+this.operator]=this.operands[0],e}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(Dt.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(Dt.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(Dt.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(Dt.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(Dt.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(Dt.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(Dt.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(Dt.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof It))throw new TypeError('"geometry" must be of type Point. Received type '.concat(typeof t.geometry));if(void 0!==t.maxDistance&&!ut(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '.concat(typeof t.maxDistance));if(void 0!==t.minDistance&&!ut(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '.concat(typeof t.minDistance));var n=new e(Dt.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof gt||t.geometry instanceof ht))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(Dt.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof It||t.geometry instanceof dt||t.geometry instanceof ht||t.geometry instanceof yt||t.geometry instanceof vt||t.geometry instanceof gt))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(Dt.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(xt);function Lt(t){return t&&t instanceof Rt&&t._internalType===Y}function Mt(t){return Lt(t)}var Ft={};for(var $t in Dt)Ft[$t]="$"+$t;for(var $t in Pt)Ft[$t]="$"+$t;for(var $t in Ot)Ft[$t]="$"+$t;function kt(t){return Ft[t]||"$"+t}Ft[Dt.NEQ]="$ne",Ft[Ot.REMOVE]="$unset",Ft[Ot.SHIFT]="$pop",Ft[Ot.UNSHIFT]="$push";var Jt=function(){return Jt=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},Jt.apply(this,arguments)},Ut=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},Gt=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 Wt(t){return Qt(t,[t])}function Qt(t,e){if(!ft(t)){if(ct(t))return{$date:+t};if(lt(t))return{$regex:t.source,$options:t.flags};if(st(t))return t.map(function(t){if(e.indexOf(t)>-1)throw new Error("Cannot convert circular structure to JSON");return Qt(t,Gt(Gt([],Ut(e),!1),[t],!1))});if(at(t)){var n=Jt({},t);for(var r in n){if(e.indexOf(n[r])>-1)throw new Error("Cannot convert circular structure to JSON");n[r]=Qt(n[r],Gt(Gt([],Ut(e),!1),[n[r]],!1))}return n}return t}switch(t._internalType){case Z:return t.toJSON();case rt:case ot:return t.parse();default:return t.toJSON?t.toJSON():t}}var Ht=function(){return Ht=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},Ht.apply(this,arguments)},Bt=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},Vt=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Yt(t,e,n,r){var o=Ht({},t);for(var i in t)if(!/^\$/.test(i)){var a=t[i];if(a&&at(a)&&!e(a)){if(r.indexOf(a)>-1)throw new Error("Cannot convert circular structure to JSON");var u=Yt(a,e,Vt(Vt([],Bt(n),!1),[i],!1),Vt(Vt([],Bt(r),!1),[a],!1));o[i]=u;var s=!1;for(var c in u)/^\$/.test(c)?s=!0:(o["".concat(i,".").concat(c)]=u[c],delete o[i][c]);s||delete o[i]}}return o}function zt(t){return Yt(t,Xt,[],[t])}function Zt(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?st(t[r])?t[r].push(e[r]):at(t[r])?at(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is ".concat(it(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(it(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]}function Xt(t){return ft(t)||ct(t)||lt(t)}function Kt(t){return Wt(t)}var te=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.prototype.encodeUpdate=function(t){return At(t)?this.encodeUpdateCommand(t):"object"===it(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===B)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case Ot.PUSH:case Ot.PULL:case Ot.PULL_ALL:case Ot.POP:case Ot.SHIFT:case Ot.UNSHIFT:case Ot.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,o,i=kt(t.operator);return t.operator===Ot.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,u,s,c,l,f=kt(t.operator);switch(t.operator){case Ot.PUSH:var d=void 0;return d=st(t.operands)?{$each:t.operands.map(Kt)}:t.operands,(e={})[f]=((n={})[t.fieldName]=d,n),e;case Ot.UNSHIFT:return d={$each:t.operands.map(Kt),$position:0},(r={})[f]=((o={})[t.fieldName]=d,o),r;case Ot.POP:return(i={})[f]=((a={})[t.fieldName]=1,a),i;case Ot.SHIFT:return(u={})[f]=((s={})[t.fieldName]=-1,s),u;default:return(c={})[f]=((l={})[t.fieldName]=Kt(t.operands),l),c}},t.prototype.encodeUpdateObject=function(t){var e=zt(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(At(r))e[n]=r._setFieldName(n),Zt(e,this.encodeUpdateCommand(e[n]),n);else{e[n]=r=Kt(r);var o=new qt(Ot.SET,[r],n);Zt(e,this.encodeUpdateCommand(o),n)}}return e},t}(),ee={};function ne(t){if(!Fe.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return ee[e]||(ee[e]=new Fe.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:Fe.createRequest(t.config)}}})),ee[e]}var re=function(){return re=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},re.apply(this,arguments)},oe=function(){function t(t,e,n,r){void 0===r&&(r={});var o=this;this.watch=function(t){return ne(o._db).watch(re(re({},t),{envId:o._db.config.env,collectionName:o._coll,query:JSON.stringify({_id:o.id})}))},this._db=t,this._coll=e,this.id=n,this.request=Fe.createRequest(this._db.config),this.projection=r}return t.prototype.create=function(t,e){e=e||Tt();var n=Array.isArray(t),r={collectionName:this._coll,data:n?t.map(function(t){return Wt(t)}):Wt(t)};return!n&&this.id&&(r._id=this.id),this.request.send("database.addDocument",r).then(function(t){var r;t.code?e(0,t):e(0,n?{ids:(null===(r=t.data)||void 0===r?void 0:r.insertedIds)||[],requestId:t.requestId}:{id:t.data._id,requestId:t.requestId})}).catch(function(t){e(t)}),e.promise},t.prototype.set=function(t,e){if(e=e||Tt(),!this.id)return Promise.resolve({code:"INVALID_PARAM",message:"docId不能为空"});if(!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n=!1,r=function(t){if("object"==typeof t)for(var e in t)t[e]instanceof qt?n=!0:"object"==typeof t[e]&&r(t[e])};if(r(t),n)return Promise.resolve({code:"DATABASE_REQUEST_FAILED",message:"update operator complicit"});var o={collectionName:this._coll,queryType:q.DOC,data:Wt(t),multi:!1,merge:!1,upsert:!0};return this.id&&(o.query={_id:this.id}),this.request.send("database.updateDocument",o).then(function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})}).catch(function(t){e(t)}),e.promise},t.prototype.update=function(t,e){if(e=e||Tt(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={_id:this.id},r={collectionName:this._coll,data:te.encode(t),query:n,queryType:q.DOC,multi:!1,merge:!0,upsert:!1};return this.request.send("database.updateDocument",r).then(function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})}).catch(function(t){e(t)}),e.promise},t.prototype.remove=function(t){t=t||Tt();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:q.DOC,multi:!1};return this.request.send("database.deleteDocument",n).then(function(e){e.code?t(0,e):t(0,{deleted:e.data.deleted,requestId:e.requestId})}).catch(function(e){t(e)}),t.promise},t.prototype.get=function(t){t=t||Tt();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:q.DOC,multi:!1,projection:this.projection};return this.request.send("database.queryDocument",n).then(function(e){if(e.code)t(0,e);else{var n=Nt.formatResDocumentData(e.data.list);t(0,{data:n,requestId:e.requestId})}}).catch(function(e){t(e)}),t.promise},t.prototype.field=function(e){for(var n in e)e[n]?e[n]=1:e[n]=0;return new t(this._db,this._coll,this.id,e)},t}(),ie=function(){function t(){}return t.encode=function(t){return(new ae).encodeQuery(t)},t}(),ae=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n;return Xt(t)?jt(t)?this.encodeLogicCommand(t):Lt(t)?this.encodeQueryCommand(t):((n={})[e]=this.encodeQueryObject(t),n):at(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regex:t.source,$options:t.flags}},t.prototype.encodeLogicCommand=function(t){var e,n,r,o,i,a,u,s=this;switch(t.operator){case Pt.NOR:case Pt.AND:case Pt.OR:var c=kt(t.operator),l=t.operands.map(function(e){return s.encodeQuery(e,t.fieldName)});return(e={})[c]=l,e;case Pt.NOT:c=kt(t.operator);var f=t.operands[0];return lt(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=kt(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)),(u={})[c]=l,u}},t.prototype.encodeQueryCommand=function(t){return Mt(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,o,i,a,u,s,c;if(t.fieldName===B)throw new Error("Cannot encode a comparison command with unset field name");var l=kt(t.operator);switch(t.operator){case Dt.EQ:case Dt.NEQ:case Dt.LT:case Dt.LTE:case Dt.GT:case Dt.GTE:case Dt.ELEM_MATCH:case Dt.EXISTS:case Dt.SIZE:case Dt.MOD:return(e={})[t.fieldName]=((n={})[l]=Kt(t.operands[0]),n),e;case Dt.IN:case Dt.NIN:case Dt.ALL:return(r={})[t.fieldName]=((o={})[l]=Kt(t.operands),o),r;case Dt.GEO_NEAR:var f=t.operands[0];return(i={})[t.fieldName]={$nearSphere:{$geometry:f.geometry.toJSON(),$maxDistance:f.maxDistance,$minDistance:f.minDistance}},i;case Dt.GEO_WITHIN:return f=t.operands[0],(a={})[t.fieldName]={$geoWithin:{$geometry:f.geometry.toJSON()}},a;case Dt.GEO_INTERSECTS:return f=t.operands[0],(u={})[t.fieldName]={$geoIntersects:{$geometry:f.geometry.toJSON()}},u;default:return(s={})[t.fieldName]=((c={})[l]=Kt(t.operands[0]),c),s}},t.prototype.encodeQueryObject=function(t){var e=zt(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 Mt(r)?(e[n]=r._setFieldName(n),o=this.encodeComparisonCommand(e[n]),this.mergeConditionAfterEncode(e,o,n)):Xt(r)&&(e[n]=Kt(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?st(t[r])?t[r]=t[r].concat(e[r]):at(t[r])?at(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is ".concat(it(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(it(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),ue=function(){return ue=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},ue.apply(this,arguments)},se=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){return ne(i._db).watch(ue(ue({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify(i._fieldFilters||{}),limit:i._queryOptions.limit,orderBy:i._fieldOrders?i._fieldOrders.reduce(function(t,e){return t[e.field]=e.direction,t},{}):void 0}))},this._db=t,this._coll=e,this._fieldFilters=n,this._fieldOrders=r||[],this._queryOptions=o||{},this._request=Fe.createRequest(this._db.config)}return t.prototype.get=function(t){t=t||Tt();var e=[];this._fieldOrders&&this._fieldOrders.forEach(function(t){e.push(t)});var n={collectionName:this._coll,queryType:q.WHERE};return this._fieldFilters&&(n.query=this._fieldFilters),e.length>0&&(n.order=e),this._queryOptions.offset&&(n.offset=this._queryOptions.offset),this._queryOptions.limit?n.limit=this._queryOptions.limit<1e3?this._queryOptions.limit:1e3:n.limit=100,this._queryOptions.projection&&(n.projection=this._queryOptions.projection),this._request.send("database.queryDocument",n).then(function(e){if(e.code)t(0,e);else{var n={data:Nt.formatResDocumentData(e.data.list),requestId:e.requestId};void 0!==e.total&&(n.total=e.total),void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset),t(0,n)}}).catch(function(e){t(e)}),t.promise},t.prototype.count=function(t){t=t||Tt();var e={collectionName:this._coll,queryType:q.WHERE};return this._fieldFilters&&(e.query=this._fieldFilters),this._request.send("database.countDocument",e).then(function(e){e.code?t(0,e):t(0,{requestId:e.requestId,total:e.data.total})}).catch(function(e){t(e)}),t.promise},t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(T.QueryParamTypeError);var n=Object.keys(e),r=n.some(function(t){return void 0!==e[t]});if(n.length&&!r)throw Error(T.QueryParamValueError);return new t(this._db,this._coll,ie.encode(e),this._fieldOrders,this._queryOptions)},t.prototype.orderBy=function(e,n){St.isFieldPath(e),St.isFieldOrder(n);var r={field:e,direction:n},o=this._fieldOrders.concat(r);return new t(this._db,this._coll,this._fieldFilters,o,this._queryOptions)},t.prototype.limit=function(e){St.isInteger("limit",e);var n=ue({},this._queryOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.skip=function(e){St.isInteger("offset",e);var n=ue({},this._queryOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.update=function(t,e){if(e=e||Tt(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={collectionName:this._coll,query:this._fieldFilters,queryType:q.WHERE,multi:!0,merge:!0,upsert:!1,data:te.encode(t)};return this._request.send("database.updateDocument",n).then(function(t){t.code?e(0,t):e(0,{requestId:t.requestId,updated:t.data.updated,upsertId:t.data.upsert_id})}).catch(function(t){e(t)}),e.promise},t.prototype.field=function(e){for(var n in e)e[n]?"object"!=typeof e[n]&&(e[n]=1):e[n]=0;var r=ue({},this._queryOptions);return r.projection=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,r)},t.prototype.remove=function(t){t=t||Tt(),Object.keys(this._queryOptions).length>0&&console.warn("`offset`, `limit` and `projection` are not supported in remove() operation"),this._fieldOrders.length>0&&console.warn("`orderBy` is not supported in remove() operation");var e={collectionName:this._coll,query:ie.encode(this._fieldFilters),queryType:q.WHERE,multi:!0};return this._request.send("database.deleteDocument",e).then(function(e){e.code?t(0,e):t(0,{requestId:e.requestId,deleted:e.data.deleted})}).catch(function(e){t(e)}),t.promise},t}();const ce=(t=>{var e={};return f.d(e,t),e})({EJSON:()=>l.EJSON});var le=function(){function t(t,e){this._stages=[],t&&e&&(this._db=t,this._request=Fe.createRequest(this._db.config),this._collectionName=e)}return t.prototype.end=function(){return t=this,e=void 0,r=function(){var t;return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}(this,function(e){switch(e.label){case 0:if(!this._collectionName||!this._db)throw new Error("Aggregation pipeline cannot send request");return[4,this._request.send("database.aggregate",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:JSON.parse(t.data.list).map(ce.EJSON.parse)}]:[2,t]}})},new((n=void 0)||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())});var t,e,n,r},t.prototype.unwrap=function(){return this._stages},t.prototype.done=function(){return this._stages.map(function(t){var e,n=t.stageKey,r=t.stageValue;return(e={})[n]=JSON.parse(r),e})},t.prototype._pipe=function(t,e){return this._stages.push({stageKey:"$".concat(t),stageValue:JSON.stringify(e)}),this},t.prototype.addFields=function(t){return this._pipe("addFields",t)},t.prototype.bucket=function(t){return this._pipe("bucket",t)},t.prototype.bucketAuto=function(t){return this._pipe("bucketAuto",t)},t.prototype.count=function(t){return this._pipe("count",t)},t.prototype.geoNear=function(t){return t.query&&(t.query=ie.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new It(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",ie.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 fe=le;var de=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)}}(),pe=function(t){function e(e,n){return t.call(this,e,n)||this}return de(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 oe(this._db,this._coll,t)},e.prototype.add=function(t,e){return new oe(this._db,this._coll,void 0).create(t,e)},e.prototype.aggregate=function(){return new fe(this._db,this._coll)},e}(se),he={eq:function(t){return new Rt(Dt.EQ,[t])},neq:function(t){return new Rt(Dt.NEQ,[t])},lt:function(t){return new Rt(Dt.LT,[t])},lte:function(t){return new Rt(Dt.LTE,[t])},gt:function(t){return new Rt(Dt.GT,[t])},gte:function(t){return new Rt(Dt.GTE,[t])},in:function(t){return new Rt(Dt.IN,t)},nin:function(t){return new Rt(Dt.NIN,t)},all:function(t){return new Rt(Dt.ALL,t)},elemMatch:function(t){return new Rt(Dt.ELEM_MATCH,[t])},exists:function(t){return new Rt(Dt.EXISTS,[t])},size:function(t){return new Rt(Dt.SIZE,[t])},mod:function(t){return new Rt(Dt.MOD,[t])},geoNear:function(t){return new Rt(Dt.GEO_NEAR,[t])},geoWithin:function(t){return new Rt(Dt.GEO_WITHIN,[t])},geoIntersects:function(t){return new Rt(Dt.GEO_INTERSECTS,[t])},and:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=st(arguments[0])?arguments[0]:Array.from(arguments);return new xt(Pt.AND,n)},nor:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=st(arguments[0])?arguments[0]:Array.from(arguments);return new xt(Pt.NOR,n)},or:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=st(arguments[0])?arguments[0]:Array.from(arguments);return new xt(Pt.OR,n)},not:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=st(arguments[0])?arguments[0]:Array.from(arguments);return new xt(Pt.NOT,n)},set:function(t){return new qt(Ot.SET,[t])},remove:function(){return new qt(Ot.REMOVE,[])},inc:function(t){return new qt(Ot.INC,[t])},mul:function(t){return new qt(Ot.MUL,[t])},push:function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(at(e[0])&&e[0].hasOwnProperty("each")){var r=e[0];t={$each:r.each,$position:r.position,$sort:r.sort,$slice:r.slice}}else t=st(e[0])?e[0]:Array.from(e);return new qt(Ot.PUSH,t)},pull:function(t){return new qt(Ot.PULL,t)},pullAll:function(t){return new qt(Ot.PULL_ALL,t)},pop:function(){return new qt(Ot.POP,[])},shift:function(){return new qt(Ot.SHIFT,[])},unshift:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=st(arguments[0])?arguments[0]:Array.from(arguments);return new qt(Ot.UNSHIFT,n)},addToSet:function(t){return new qt(Ot.ADD_TO_SET,t)},rename:function(t){return new qt(Ot.RENAME,[t])},bit:function(t){return new qt(Ot.BIT,[t])},max:function(t){return new qt(Ot.MAX,[t])},min:function(t){return new qt(Ot.MIN,[t])},expr:function(t){return{$expr:t}},jsonSchema:function(t){return{$jsonSchema:t}},text:function(t){return function(t){return"string"===it(t)}(t)?{$search:t.search}:{$search:t.search,$language:t.language,$caseSensitive:t.caseSensitive,$diacriticSensitive:t.diacriticSensitive}},aggregate:{pipeline:function(){return new fe},abs:function(t){return new ye("abs",t)},add:function(t){return new ye("add",t)},ceil:function(t){return new ye("ceil",t)},divide:function(t){return new ye("divide",t)},exp:function(t){return new ye("exp",t)},floor:function(t){return new ye("floor",t)},ln:function(t){return new ye("ln",t)},log:function(t){return new ye("log",t)},log10:function(t){return new ye("log10",t)},mod:function(t){return new ye("mod",t)},multiply:function(t){return new ye("multiply",t)},pow:function(t){return new ye("pow",t)},sqrt:function(t){return new ye("sqrt",t)},subtract:function(t){return new ye("subtract",t)},trunc:function(t){return new ye("trunc",t)},arrayElemAt:function(t){return new ye("arrayElemAt",t)},arrayToObject:function(t){return new ye("arrayToObject",t)},concatArrays:function(t){return new ye("concatArrays",t)},filter:function(t){return new ye("filter",t)},in:function(t){return new ye("in",t)},indexOfArray:function(t){return new ye("indexOfArray",t)},isArray:function(t){return new ye("isArray",t)},map:function(t){return new ye("map",t)},range:function(t){return new ye("range",t)},reduce:function(t){return new ye("reduce",t)},reverseArray:function(t){return new ye("reverseArray",t)},size:function(t){return new ye("size",t)},slice:function(t){return new ye("slice",t)},zip:function(t){return new ye("zip",t)},and:function(t){return new ye("and",t)},not:function(t){return new ye("not",t)},or:function(t){return new ye("or",t)},cmp:function(t){return new ye("cmp",t)},eq:function(t){return new ye("eq",t)},gt:function(t){return new ye("gt",t)},gte:function(t){return new ye("gte",t)},lt:function(t){return new ye("lt",t)},lte:function(t){return new ye("lte",t)},neq:function(t){return new ye("ne",t)},cond:function(t){return new ye("cond",t)},ifNull:function(t){return new ye("ifNull",t)},switch:function(t){return new ye("switch",t)},dateFromParts:function(t){return new ye("dateFromParts",t)},dateFromString:function(t){return new ye("dateFromString",t)},dayOfMonth:function(t){return new ye("dayOfMonth",t)},dayOfWeek:function(t){return new ye("dayOfWeek",t)},dayOfYear:function(t){return new ye("dayOfYear",t)},isoDayOfWeek:function(t){return new ye("isoDayOfWeek",t)},isoWeek:function(t){return new ye("isoWeek",t)},isoWeekYear:function(t){return new ye("isoWeekYear",t)},millisecond:function(t){return new ye("millisecond",t)},minute:function(t){return new ye("minute",t)},month:function(t){return new ye("month",t)},second:function(t){return new ye("second",t)},hour:function(t){return new ye("hour",t)},week:function(t){return new ye("week",t)},year:function(t){return new ye("year",t)},literal:function(t){return new ye("literal",t)},mergeObjects:function(t){return new ye("mergeObjects",t)},objectToArray:function(t){return new ye("objectToArray",t)},allElementsTrue:function(t){return new ye("allElementsTrue",t)},anyElementTrue:function(t){return new ye("anyElementTrue",t)},setDifference:function(t){return new ye("setDifference",t)},setEquals:function(t){return new ye("setEquals",t)},setIntersection:function(t){return new ye("setIntersection",t)},setIsSubset:function(t){return new ye("setIsSubset",t)},setUnion:function(t){return new ye("setUnion",t)},concat:function(t){return new ye("concat",t)},dateToString:function(t){return new ye("dateToString",t)},indexOfBytes:function(t){return new ye("indexOfBytes",t)},indexOfCP:function(t){return new ye("indexOfCP",t)},split:function(t){return new ye("split",t)},strLenBytes:function(t){return new ye("strLenBytes",t)},strLenCP:function(t){return new ye("strLenCP",t)},strcasecmp:function(t){return new ye("strcasecmp",t)},substr:function(t){return new ye("substr",t)},substrBytes:function(t){return new ye("substrBytes",t)},substrCP:function(t){return new ye("substrCP",t)},toLower:function(t){return new ye("toLower",t)},toUpper:function(t){return new ye("toUpper",t)},meta:function(t){return new ye("meta",t)},addToSet:function(t){return new ye("addToSet",t)},avg:function(t){return new ye("avg",t)},first:function(t){return new ye("first",t)},last:function(t){return new ye("last",t)},max:function(t){return new ye("max",t)},min:function(t){return new ye("min",t)},push:function(t){return new ye("push",t)},stdDevPop:function(t){return new ye("stdDevPop",t)},stdDevSamp:function(t){return new ye("stdDevSamp",t)},sum:function(t){return new ye("sum",t)},let:function(t){return new ye("let",t)}},project:{slice:function(t){return new me("slice",t)},elemMatch:function(t){return new me("elemMatch",t)}}},ye=function(t,e){this["$"+t]=e},me=function(t,e){this["$"+t]=e},ve=function(){function t(t){var e=t.regexp,n=t.options;if(!e)throw new TypeError("regexp must be a string");this.$regex=e,this.$options=n}return t.prototype.parse=function(){return{$regex:this.$regex,$options:this.$options}},Object.defineProperty(t.prototype,"_internalType",{get:function(){return ot},enumerable:!1,configurable:!0}),t}();function we(t){return new ve(t)}var ge="insert document failed",be="DATABASE_TRANSACTION_CONFLICT",_e=function(){return _e=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},_e.apply(this,arguments)},Oe=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},Ee=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:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Ne="database.updateDocInTransaction",Se=function(){function t(t,e,n){this._coll=e,this.id=n,this._transaction=t,this._request=this._transaction.getRequestMethod(),this._transactionId=this._transaction.getTransactionId()}return t.prototype.create=function(t){return Oe(this,void 0,void 0,function(){var e,n,r,o;return Ee(this,function(i){switch(i.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,data:ce.EJSON.stringify(Wt(t),{relaxed:!1})},this.id&&(e._id=this.id),[4,this._request.send("database.insertDocInTransaction",e)];case 1:if((n=i.sent()).code)throw n;if(r=ce.EJSON.parse(n.inserted),1==(o=ce.EJSON.parse(n.ok))&&1==r)return[2,_e(_e({},n),{ok:o,inserted:r})];throw new Error(ge)}})})},t.prototype.get=function(){return Oe(this,void 0,void 0,function(){var t,e;return Ee(this,function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.getInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,{data:"null"!==e.data?Nt.formatField(ce.EJSON.parse(e.data)):ce.EJSON.parse(e.data),requestId:e.requestId}]}})})},t.prototype.set=function(t){return Oe(this,void 0,void 0,function(){var e,n;return Ee(this,function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:ce.EJSON.stringify(Wt(t),{relaxed:!1}),upsert:!0},[4,this._request.send(Ne,e)];case 1:if((n=r.sent()).code)throw n;return[2,_e(_e({},n),{updated:ce.EJSON.parse(n.updated),upserted:n.upserted?JSON.parse(n.upserted):null})]}})})},t.prototype.update=function(t){return Oe(this,void 0,void 0,function(){var e,n;return Ee(this,function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:ce.EJSON.stringify(te.encode(t),{relaxed:!1})},[4,this._request.send(Ne,e)];case 1:if((n=r.sent()).code)throw n;return[2,_e(_e({},n),{updated:ce.EJSON.parse(n.updated)})]}})})},t.prototype.delete=function(){return Oe(this,void 0,void 0,function(){var t,e;return Ee(this,function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.deleteDocInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,_e(_e({},e),{deleted:ce.EJSON.parse(e.deleted)})]}})})},t}(),Ie=function(){return Ie=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},Ie.apply(this,arguments)},Te=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},Pe=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:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},qe="database.getInTransaction",Ae=function(){function t(t,e,n,r,o){this._coll=e,this._transaction=t,this._fieldFilters=n,this._fieldOrders=r||[],this._queryOptions=o||{},this._request=this._transaction.getRequestMethod(),this._transactionId=this._transaction.getTransactionId()}return t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(T.QueryParamTypeError);var n=Object.keys(e),r=n.some(function(t){return void 0!==e[t]});if(n.length&&!r)throw Error(T.QueryParamValueError);return new t(this._transaction,this._coll,ie.encode(e),this._fieldOrders,this._queryOptions)},t.prototype.orderBy=function(e,n){St.isFieldPath(e),St.isFieldOrder(n);var r={field:e,direction:n},o=this._fieldOrders.concat(r);return new t(this._transaction,this._coll,this._fieldFilters,o,this._queryOptions)},t.prototype.limit=function(e){St.isInteger("limit",e);var n=Ie({},this._queryOptions);return n.limit=e,new t(this._transaction,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.skip=function(e){St.isInteger("offset",e);var n=Ie({},this._queryOptions);return n.offset=e,new t(this._transaction,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.field=function(e){for(var n in e)e[n]?"object"!=typeof e[n]&&(e[n]=1):e[n]=0;var r=Ie({},this._queryOptions);return r.projection=e,new t(this._transaction,this._coll,this._fieldFilters,this._fieldOrders,r)},t.prototype.get=function(){return Te(this,void 0,void 0,function(){var t,e,n,r,o,i;return Pe(this,function(a){switch(a.label){case 0:return t=[],this._fieldOrders&&this._fieldOrders.forEach(function(e){t.push(e)}),e={collectionName:this._coll,transactionId:this._transactionId},this._fieldFilters&&(e.query=this._fieldFilters),t.length>0&&(e.order=t),this._queryOptions.offset&&(e.offset=this._queryOptions.offset),this._queryOptions.limit?e.limit=this._queryOptions.limit<1e3?this._queryOptions.limit:1e3:e.limit=100,this._queryOptions.projection&&(e.projection=this._queryOptions.projection),[4,this._request.send(qe,e)];case 1:if((n=a.sent()).code)throw n;return r="null"!==n.data?ce.EJSON.parse(n.data):null,o=r?Array.isArray(r)?Nt.formatResDocumentData(r):[Nt.formatField(r)]:[],i={data:o,requestId:n.requestId},void 0!==n.total&&(i.total=n.total),void 0!==n.limit&&(i.limit=n.limit),void 0!==n.offset&&(i.offset=n.offset),[2,i]}})})},t.prototype.count=function(){return Te(this,void 0,void 0,function(){var t,e,n,r;return Pe(this,function(o){switch(o.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId},this._fieldFilters&&(t.query=this._fieldFilters),[4,this._request.send(qe,t)];case 1:if((e=o.sent()).code)throw e;return n="null"!==e.data?ce.EJSON.parse(e.data):null,r=Array.isArray(n)?n.length:n?1:0,[2,{requestId:e.requestId,total:void 0!==e.total?e.total:r}]}})})},t.prototype.update=function(t){return Te(this,void 0,void 0,function(){var e,n;return Pe(this,function(r){switch(r.label){case 0:if(!t||"object"!=typeof t)throw new Error("参数必需是非空对象");if(t.hasOwnProperty("_id"))throw new Error("不能更新_id的值");return e={collectionName:this._coll,transactionId:this._transactionId,query:this._fieldFilters,data:ce.EJSON.stringify(te.encode(t),{relaxed:!1})},[4,this._request.send("database.updateDocInTransaction",e)];case 1:if((n=r.sent()).code)throw n;return[2,Ie(Ie({},n),{updated:ce.EJSON.parse(n.updated)})]}})})},t.prototype.remove=function(){return Te(this,void 0,void 0,function(){var t,e;return Pe(this,function(n){switch(n.label){case 0:return Object.keys(this._queryOptions).length>0&&console.warn("`offset`, `limit` and `projection` are not supported in remove() operation"),this._fieldOrders.length>0&&console.warn("`orderBy` is not supported in remove() operation"),t={collectionName:this._coll,transactionId:this._transactionId,query:this._fieldFilters},[4,this._request.send("database.deleteDocInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,Ie(Ie({},e),{deleted:ce.EJSON.parse(e.deleted)})]}})})},t}(),xe=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)}}(),je=function(t){function e(e,n){return t.call(this,e,n)||this}return xe(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 Se(this._transaction,this._coll,t)},e.prototype.add=function(t){var e;return void 0!==t._id&&(e=t._id),new Se(this._transaction,this._coll,e).create(t)},e}(Ae),De=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},Ce=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:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Re=function(){function t(t){this._db=t,this._request=Fe.createRequest(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return t.prototype.init=function(){return De(this,void 0,void 0,function(){var t;return Ce(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 je(this,t)},t.prototype.getTransactionId=function(){return this._id},t.prototype.getRequestMethod=function(){return this._request},t.prototype.commit=function(){return De(this,void 0,void 0,function(){var t,e;return Ce(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 De(this,void 0,void 0,function(){var e,n;return Ce(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 Le(){return De(this,void 0,void 0,function(){var t;return Ce(this,function(e){switch(e.label){case 0:return[4,(t=new Re(this)).init()];case 1:return e.sent(),[2,t]}})})}function Me(t,e){return void 0===e&&(e=3),De(this,void 0,void 0,function(){var n,r,o,i,a=this;return Ce(this,function(u){switch(u.label){case 0:return u.trys.push([0,4,,10]),[4,(n=new Re(this)).init()];case 1:return u.sent(),[4,t(n)];case 2:if(r=u.sent(),!0===n.aborted)throw n.abortReason;return[4,n.commit()];case 3:return u.sent(),[2,r];case 4:if(o=u.sent(),!1===n.inited)throw o;return i=function(t){return De(a,void 0,void 0,function(){return Ce(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:u.sent(),u.label=6;case 6:return o&&o.code===be?[4,Me.bind(this)(t,--e)]:[3,8];case 7:return[2,u.sent()];case 8:return[4,i(o)];case 9:return u.sent(),[3,10];case 10:return[2]}})})}var Fe=function(){function t(t){this.config=t,this.Geo=p,this.serverDate=_t,this.command=he,this.RegExp=we,this.startTransaction=Le,this.runTransaction=Me,this.logicCommand=xt,this.updateCommand=qt,this.queryCommand=Rt}return t.createRequest=function(e){var n=new t.reqClass(e),r=n.send;return n.send=function(t,n){return e.instance&&(n.instance=e.instance),e.database&&(n.database=e.database),r.call(this,t,n)},n},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new pe(this,t)},t.prototype.createCollection=function(e){var n={collectionName:e};return t.createRequest(this.config).send("database.addCollection",n)},t}(),$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)}}(),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{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((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:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Ge={filterRes:function(t){return delete t.header,delete t.statusCode,t},flattenResData:function(t){if("object"==typeof t.data&&null!==t.data){var e=ke(ke({},t),t.data);return delete e.data,e}return t},safeParseEJSON:function(t){if("string"!=typeof t)return t;try{return ce.EJSON.parse(t)}catch(e){return 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){var e,n,r,o,i,a,u,s;return Je(this,void 0,Promise,function(){var c,l,f,d;return Ue(this,function(p){switch(p.label){case 0:return c=!!(null===(n=null===(e=t.query)||void 0===e?void 0:e._id)||void 0===n?void 0:n.$eq),l=Ge.buildQueryParams(ke({projection:t.projection,transactionId:t.transactionId},c?{}:{offset:null!==(r=t.offset)&&void 0!==r?r:0,limit:null!==(o=t.limit)&&void 0!==o?o:100,order:t.order,query:t.query?ce.EJSON.stringify(t.query,{relaxed:!1}):void 0})),f="".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(l),c&&(f="".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/").concat((null===(i=t.query._id)||void 0===i?void 0:i.$eq)||t.query._id,"?").concat(l)),[4,this.gateWay({url:f,method:"GET"})];case 1:return(d=p.sent()).data=Ge.safeParseEJSON(JSON.stringify(d.data)),!c||d.code||(null===(a=d.data)||void 0===a?void 0:a.code)?(d.code||(null===(u=d.data)||void 0===u?void 0:u.code)?d=ke(ke({},d),{code:d.code||(null===(s=d.data)||void 0===s?void 0:s.code),data:ke(ke({},d.data),{list:[]})}):Array.isArray(d.data)?d=ke(ke({},d),{data:{list:d.data}}):d.data&&!Array.isArray(d.data.list)&&(d=ke(ke({},d),{data:ke(ke({},d.data),{list:[]})})),[2,Ge.filterRes(d)]):[2,ke(ke({},d),{data:{list:[d.data]}})]}})})},"database.addDocument":function(t){var e,n,r;return Je(this,void 0,Promise,function(){var o;return Ue(this,function(i){switch(i.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"POST",data:ke({data:Array.isArray(t.data)?t.data:[t.data]},t.transactionId&&{transactionId:t.transactionId})})];case 1:return o=i.sent(),Array.isArray(t.data)?o=ke(ke({},o),{data:ke({ids:(null===(e=o.data)||void 0===e?void 0:e.insertedIds)||[]},o.data)}):(null===(r=null===(n=o.data)||void 0===n?void 0:n.insertedIds)||void 0===r?void 0:r[0])&&(o=ke(ke({},o),{data:ke({_id:o.data.insertedIds[0]},o.data)})),[2,Ge.filterRes(o)]}})})},"database.updateDocument":function(t){return Je(this,void 0,Promise,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"PATCH",data:ke({query:t.query,data:t.data,multi:!!t.multi,upsert:!!t.upsert,replaceMode:!!t.replaceMode},t.transactionId&&{transactionId:t.transactionId})})];case 1:return e=n.sent(),[2,Ge.filterRes(e)]}})})},"database.deleteDocument":function(t){return Je(this,void 0,Promise,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/remove"),method:"POST",data:ke({query:t.query,multi:!!t.multi},t.transactionId&&{transactionId:t.transactionId})})];case 1:return e=n.sent(),[2,Ge.filterRes(e)]}})})},"database.countDocument":function(t){return Je(this,void 0,Promise,function(){var e,n;return Ue(this,function(r){switch(r.label){case 0:return e=Ge.buildQueryParams({count:!0,query:t.query?ce.EJSON.stringify(t.query,{relaxed:!1}):void 0}),[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(e),method:"GET"})];case 1:return n=r.sent(),[2,Ge.filterRes(n)]}})})},"database.addCollection":function(t){return Je(this,void 0,Promise,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/collections"),method:"POST",data:{collectionName:t.collectionName}})];case 1:return e=n.sent(),[2,Ge.filterRes(e)]}})})},"database.aggregate":function(t){var e;return Je(this,void 0,Promise,function(){var n,r;return Ue(this,function(o){switch(o.label){case 0:return n=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]=ce.EJSON.serialize(r),e}catch(e){return(n={})[t.stageKey]=t.stageValue,n}}),[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/aggregations"),method:"POST",data:{pipeline:n}})];case 1:return r=o.sent(),Array.isArray(null===(e=r.data)||void 0===e?void 0:e.list)&&(r.data.list=JSON.stringify(r.data.list.map(function(t){return JSON.stringify(t)}))),[2,Ge.filterRes(r)]}})})},"database.startTransaction":function(t){return Je(this,void 0,void 0,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/transactions"),method:"POST"})];case 1:return e=n.sent(),[2,Ge.filterRes(Ge.flattenResData(e))]}})})},"database.commitTransaction":function(t){return Je(this,void 0,void 0,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/commit"),method:"POST"})];case 1:return e=n.sent(),[2,Ge.filterRes(e)]}})})},"database.abortTransaction":function(t){return Je(this,void 0,void 0,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/rollback"),method:"POST"})];case 1:return e=n.sent(),[2,Ge.filterRes(e)]}})})},"database.getInTransaction":function(t){var e;return Je(this,void 0,void 0,function(){var n;return Ue(this,function(r){switch(r.label){case 0:return[4,Ge["database.queryDocument"].call(this,t)];case 1:return"object"==typeof(n=r.sent()).data&&null!==n.data?(null===(e=n.data)||void 0===e?void 0:e.code)?[2,Ge.flattenResData(n)]:[2,ke(ke({},n),{data:JSON.stringify(n.data)})]:[2,n]}})})},"database.updateDocInTransaction":function(t){return Je(this,void 0,void 0,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return t.data=Ge.safeParseEJSON(t.data),[4,Ge["database.updateDocument"].call(this,t)];case 1:return e=n.sent(),[2,Ge.flattenResData(e)]}})})},"database.deleteDocInTransaction":function(t){return Je(this,void 0,void 0,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,Ge["database.deleteDocument"].call(this,t)];case 1:return e=n.sent(),[2,Ge.flattenResData(e)]}})})},"database.insertDocInTransaction":function(t){var e;return Je(this,void 0,Promise,function(){var n,r;return Ue(this,function(o){switch(o.label){case 0:return t.data=Ge.safeParseEJSON(t.data),[4,Ge["database.addDocument"].call(this,t)];case 1:return"object"==typeof(n=o.sent()).data&&null!==n.data?(r=!!(null===(e=n.data)||void 0===e?void 0:e._id),n=ke(ke(ke({},n),{inserted:r?1:0,ok:r?1:0}),n.data)):n=ke({inserted:0,ok:0},n),delete n.data,[2,n]}})})},"database.runCommands":function(t){return Je(this,void 0,Promise,function(){var e;return Ue(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(Ge.getUrlPrefix(t),"/commands"),method:"POST",data:ke({commands:ce.EJSON.serialize(t.commands)},t.transactionId&&{transactionId:t.transactionId})})];case 1:"object"==typeof(e=n.sent()).data&&null!==e.data&&(delete(e=ke(ke({},e),e.data)).data,delete e.request_id);try{e=ce.EJSON.deserialize(e)}catch(t){}return[2,Ge.filterRes(e)]}})})}},We={name:"database",entity:{database:function(t){var e=this.platform,n=e.adapter,r=e.runtime,o=function(t){function e(e){return t.call(this,e)||this}return $e(e,t),e.prototype.send=function(e,n){return Je(this,void 0,void 0,function(){var r;return Ue(this,function(o){switch(o.label){case 0:return r=null,"GATEWAY"===this.config.endPointMode&&Ge[e]?[4,Ge[e].call(this,n)]:[3,2];case 1:return r=o.sent(),[3,4];case 2:return[4,t.prototype.send.call(this,e,n)];case 3:r=o.sent(),o.label=4;case 4:return[2,r]}})})},e}(this.request.constructor);return Fe.reqClass=o,Fe.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},Fe.runtime=r,this.wsClientClass&&(Fe.wsClass=n.wsClass,Fe.wsClientClass=this.wsClientClass),Fe.ws||(Fe.ws=null),new(function(t){function e(e){return t.call(this,e)||this}return $e(e,t),e.prototype.runCommands=function(t){return Je(this,void 0,Promise,function(){return Ue(this,function(e){return[2,Fe.createRequest(this.config).send("database.runCommands",t)]})})},e}(Fe))(ke(ke(ke({},this.config),{_fromApp:this}),t))}}};try{cloudbase.registerComponent(We)}catch(t){}function Qe(t){try{t.registerComponent(We)}catch(t){console.warn(t)}}try{window.registerDatabase=Qe}catch(t){}h.default.registerVersion("3.6.4-alpha.0");try{(0,v.registerAuth)(h.default),(0,w.registerFunctions)(h.default),(0,g.registerStorage)(h.default),Qe(h.default),(0,b.registerRealtime)(h.default),(0,_.registerModel)(h.default),(0,O.registerAi)(h.default),(0,E.registerCloudrun)(h.default),(0,N.registerMySQL)(h.default),(0,S.registerApis)(h.default)}catch(t){}try{window.cloudbase=h.default}catch(t){}const He=h.default;var Be=d.Z;export{Be as default};
2
2
  //# sourceMappingURL=index.esm.js.map