@cloudbase/js-sdk
Version:
cloudbase javascript sdk
1 lines • 147 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("cloudbase_database",[],e):"object"==typeof exports?exports.cloudbase_database=e():t.cloudbase_database=e()}("undefined"!=typeof window?window:this,()=>(()=>{var t={198:function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},i.apply(this,arguments)},s=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())})},a=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.registerDatabase=void 0;var u=n(543),c=n(804),f={filterRes:function(t){return delete t.header,delete t.statusCode,t},flattenResData:function(t){if("object"==typeof t.data&&null!==t.data){var e=i(i({},t),t.data);return delete e.data,e}return t},safeParseEJSON:function(t){if("string"!=typeof t)return t;try{return c.EJSON.parse(t)}catch(e){return t}},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,u,l,h,d;return s(this,void 0,Promise,function(){var s,p,y,g;return a(this,function(a){switch(a.label){case 0:return s=!!(null===(n=null===(e=t.query)||void 0===e?void 0:e._id)||void 0===n?void 0:n.$eq),p=f.buildQueryParams(i({projection:t.projection,transactionId:t.transactionId},s?{}:{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?c.EJSON.stringify(t.query,{relaxed:!1}):void 0})),y="".concat(f.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(p),s&&(y="".concat(f.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/").concat((null===(u=t.query._id)||void 0===u?void 0:u.$eq)||t.query._id,"?").concat(p)),[4,this.gateWay({url:y,method:"GET"})];case 1:return(g=a.sent()).data=f.safeParseEJSON(JSON.stringify(g.data)),!s||g.code||(null===(l=g.data)||void 0===l?void 0:l.code)?(g.code||(null===(h=g.data)||void 0===h?void 0:h.code)?g=i(i({},g),{code:g.code||(null===(d=g.data)||void 0===d?void 0:d.code),data:i(i({},g.data),{list:[]})}):Array.isArray(g.data)?g=i(i({},g),{data:{list:g.data}}):g.data&&!Array.isArray(g.data.list)&&(g=i(i({},g),{data:i(i({},g.data),{list:[]})})),[2,f.filterRes(g)]):[2,i(i({},g),{data:{list:[g.data]}})]}})})},"database.addDocument":function(t){var e,n,r;return s(this,void 0,Promise,function(){var o;return a(this,function(s){switch(s.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"POST",data:i({data:Array.isArray(t.data)?t.data:[t.data]},t.transactionId&&{transactionId:t.transactionId})})];case 1:return o=s.sent(),Array.isArray(t.data)?o=i(i({},o),{data:i({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=i(i({},o),{data:i({_id:o.data.insertedIds[0]},o.data)})),[2,f.filterRes(o)]}})})},"database.updateDocument":function(t){return s(this,void 0,Promise,function(){var e;return a(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"PATCH",data:i({query:t.query,data:t.data,multi:!!t.multi,upsert:!!t.upsert,replaceMode:!!t.replaceMode},t.transactionId&&{transactionId:t.transactionId})})];case 1:return e=n.sent(),[2,f.filterRes(e)]}})})},"database.deleteDocument":function(t){return s(this,void 0,Promise,function(){var e;return a(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/remove"),method:"POST",data:i({query:t.query,multi:!!t.multi},t.transactionId&&{transactionId:t.transactionId})})];case 1:return e=n.sent(),[2,f.filterRes(e)]}})})},"database.countDocument":function(t){return s(this,void 0,Promise,function(){var e,n;return a(this,function(r){switch(r.label){case 0:return e=f.buildQueryParams({count:!0,query:t.query?c.EJSON.stringify(t.query,{relaxed:!1}):void 0}),[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(e),method:"GET"})];case 1:return n=r.sent(),[2,f.filterRes(n)]}})})},"database.addCollection":function(t){return s(this,void 0,Promise,function(){var e;return a(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/collections"),method:"POST",data:{collectionName:t.collectionName}})];case 1:return e=n.sent(),[2,f.filterRes(e)]}})})},"database.aggregate":function(t){var e;return s(this,void 0,Promise,function(){var n,r;return a(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]=c.EJSON.serialize(r),e}catch(e){return(n={})[t.stageKey]=t.stageValue,n}}),[4,this.gateWay({url:"".concat(f.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,f.filterRes(r)]}})})},"database.startTransaction":function(t){return s(this,void 0,void 0,function(){var e;return a(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/transactions"),method:"POST"})];case 1:return e=n.sent(),[2,f.filterRes(f.flattenResData(e))]}})})},"database.commitTransaction":function(t){return s(this,void 0,void 0,function(){var e;return a(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/commit"),method:"POST"})];case 1:return e=n.sent(),[2,f.filterRes(e)]}})})},"database.abortTransaction":function(t){return s(this,void 0,void 0,function(){var e;return a(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/rollback"),method:"POST"})];case 1:return e=n.sent(),[2,f.filterRes(e)]}})})},"database.getInTransaction":function(t){var e;return s(this,void 0,void 0,function(){var n;return a(this,function(r){switch(r.label){case 0:return[4,f["database.queryDocument"].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,f.flattenResData(n)]:[2,i(i({},n),{data:JSON.stringify(n.data)})]:[2,n]}})})},"database.updateDocInTransaction":function(t){return s(this,void 0,void 0,function(){var e;return a(this,function(n){switch(n.label){case 0:return t.data=f.safeParseEJSON(t.data),[4,f["database.updateDocument"].call(this,t)];case 1:return e=n.sent(),[2,f.flattenResData(e)]}})})},"database.deleteDocInTransaction":function(t){return s(this,void 0,void 0,function(){var e;return a(this,function(n){switch(n.label){case 0:return[4,f["database.deleteDocument"].call(this,t)];case 1:return e=n.sent(),[2,f.flattenResData(e)]}})})},"database.insertDocInTransaction":function(t){var e;return s(this,void 0,Promise,function(){var n,r;return a(this,function(o){switch(o.label){case 0:return t.data=f.safeParseEJSON(t.data),[4,f["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=i(i(i({},n),{inserted:r?1:0,ok:r?1:0}),n.data)):n=i({inserted:0,ok:0},n),delete n.data,[2,n]}})})},"database.runCommands":function(t){return s(this,void 0,Promise,function(){var e;return a(this,function(n){switch(n.label){case 0:return[4,this.gateWay({url:"".concat(f.getUrlPrefix(t),"/commands"),method:"POST",data:i({commands:c.EJSON.serialize(t.commands)},t.transactionId&&{transactionId:t.transactionId})})];case 1:"object"==typeof(e=n.sent()).data&&null!==e.data&&(delete(e=i(i({},e),e.data)).data,delete e.request_id);try{e=c.EJSON.deserialize(e)}catch(t){}return[2,f.filterRes(e)]}})})}},l={name:"database",entity:{database:function(t){var e=this.platform,n=e.adapter,r=e.runtime,c=function(t){function e(e){return t.call(this,e)||this}return o(e,t),e.prototype.send=function(e,n){return s(this,void 0,void 0,function(){var r;return a(this,function(o){switch(o.label){case 0:return r=null,"GATEWAY"===this.config.endPointMode&&f[e]?[4,f[e].call(this,n)]:[3,2];case 1:return r=o.sent(),[3,4];case 2:return[4,t.prototype.send.call(this,e,n)];case 3:r=o.sent(),o.label=4;case 4:return[2,r]}})})},e}(this.request.constructor);return u.Db.reqClass=c,u.Db.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},u.Db.runtime=r,this.wsClientClass&&(u.Db.wsClass=n.wsClass,u.Db.wsClientClass=this.wsClientClass),u.Db.ws||(u.Db.ws=null),new(function(t){function e(e){return t.call(this,e)||this}return o(e,t),e.prototype.runCommands=function(t){return s(this,void 0,Promise,function(){return a(this,function(e){return[2,u.Db.createRequest(this.config).send("database.runCommands",t)]})})},e}(u.Db))(i(i(i({},this.config),{_fromApp:this}),t))}}};try{cloudbase.registerComponent(l)}catch(t){}function h(t){try{t.registerComponent(l)}catch(t){console.warn(t)}}e.registerDatabase=h;try{window.registerDatabase=h}catch(t){}},543:(t,e,n)=>{"use strict";n.r(e),n.d(e,{CollectionReference:()=>zt,Db:()=>ge,DocumentReference:()=>Rt,Query:()=>Ft});var r,o,i={};n.r(i),n.d(i,{LineString:()=>K,MultiLineString:()=>nt,MultiPoint:()=>tt,MultiPolygon:()=>ot,Point:()=>Z,Polygon:()=>X}),function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined"}(o||(o={}));var s,a,u="Object",c="GeoPoint",f="GeoLineString",l="GeoPolygon",h="GeoMultiPoint",d="GeoMultiLineString",p="GeoMultiPolygon",y="Date",g="ServerDate",m=["desc","asc"],b=["<","<=","==",">=",">"];!function(t){t.lt="<",t.gt=">",t.lte="<=",t.gte=">=",t.eq="=="}(s||(s={})),(r={})[s.eq]="$eq",r[s.lt]="$lt",r[s.lte]="$lte",r[s.gt]="$gt",r[s.gte]="$gte",function(t){t.WHERE="WHERE",t.DOC="DOC"}(a||(a={}));var w,v=(w=function(t,e){return w=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},w(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}w(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),_=[],O={},E=function(t){function e(e,n){if(n!==O)throw new TypeError("InternalSymbol cannot be constructed with new operator");return t.call(this,e)||this}return v(e,t),e.for=function(t){for(var n=0,r=_.length;n<r;n++)if(_[n].target===t)return _[n].instance;var o=new e(t,O);return _.push({target:t,instance:o}),o},e}(function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})});const S=E;var N=S.for("UNSET_FIELD_NAME"),I=S.for("UPDATE_COMMAND"),T=S.for("QUERY_COMMAND"),B=S.for("LOGIC_COMMAND"),x=S.for("GEO_POINT"),L=S.for("SYMBOL_GEO_LINE_STRING"),$=S.for("SYMBOL_GEO_POLYGON"),A=S.for("SYMBOL_GEO_MULTI_POINT"),U=S.for("SYMBOL_GEO_MULTI_LINE_STRING"),P=S.for("SYMBOL_GEO_MULTI_POLYGON"),j=S.for("SERVER_DATE"),R=S.for("REGEXP"),D=function(){function t(t){var e=(void 0===t?{}:t).offset,n=void 0===e?0:e;this.offset=n}return Object.defineProperty(t.prototype,"_internalType",{get:function(){return j},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$date:{offset:this.offset}}},t}();function q(t){return new D(t)}var C,F=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},M=function(){function t(){}return t.formatResDocumentData=function(e){return e.map(function(e){return t.formatField(e)})},t.formatField=function(e){var n=Object.keys(e),r={};return Array.isArray(e)&&(r=[]),n.forEach(function(n){var o,i=e[n];switch(t.whichType(i)){case c:o=new Z(i.coordinates[0],i.coordinates[1]);break;case f:o=new K(i.coordinates.map(function(t){return new Z(t[0],t[1])}));break;case l:o=new X(i.coordinates.map(function(t){return new K(t.map(function(t){var e=F(t,2),n=e[0],r=e[1];return new Z(n,r)}))}));break;case h:o=new tt(i.coordinates.map(function(t){return new Z(t[0],t[1])}));break;case d:o=new nt(i.coordinates.map(function(t){return new K(t.map(function(t){var e=F(t,2),n=e[0],r=e[1];return new Z(n,r)}))}));break;case p:o=new ot(i.coordinates.map(function(t){return new X(t.map(function(t){return new K(t.map(function(t){var e=F(t,2),n=e[0],r=e[1];return new Z(n,r)}))}))}));break;case y:o=new Date(1e3*i.$timestamp);break;case u:case"Array":o=t.formatField(i);break;case g:o=new Date(i.$date);break;default:o=i}Array.isArray(r)?r.push(o):r[n]=o}),r},t.whichType=function(t){var e=Object.prototype.toString.call(t).slice(8,-1);if(e===y)return"BsonDate";if(e===u){if(t instanceof Z)return c;if(t instanceof Date)return y;if(t instanceof D)return g;t.$timestamp?e=y:t.$date?e=g:Z.validate(t)?e=c:K.validate(t)?e=f:X.validate(t)?e=l:tt.validate(t)?e=h:nt.validate(t)?e=d:ot.validate(t)&&(e=p)}return e},t.generateDocId=function(){for(var t="",e=0;e<24;e++)t+="ABCDEFabcdef0123456789".charAt(Math.floor(22*Math.random()));return t},t}(),J=function(){function t(){}return t.isGeopoint=function(t,e){if("Number"!==M.whichType(e))throw new Error("Geo Point must be number type");var n=Math.abs(e);if("latitude"===t&&n>90)throw new Error("latitude should be a number ranges from -90 to 90");if("longitude"===t&&n>180)throw new Error("longitude should be a number ranges from -180 to 180");return!0},t.isInteger=function(t,e){if(!Number.isInteger(e))throw new Error(t+o.IntergerError);return!0},t.isFieldOrder=function(t){if(-1===m.indexOf(t))throw new Error(o.DirectionError);return!0},t.isFieldPath=function(t){if(!/^[a-zA-Z0-9-_\.]/.test(t))throw new Error;return!0},t.isOperator=function(t){if(-1===b.indexOf(t))throw new Error(o.OpStrError);return!0},t.isCollName=function(t){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(t))throw new Error(o.CollNameError);return!0},t.isDocID=function(t){if(!/^([a-fA-F0-9]){24}$/.test(t))throw new Error(o.DocIDError);return!0},t}(),k=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},V=function(t){return"object"===k(t)},z=function(t){return"number"===k(t)},H=function(t){return Array.isArray(t)},Y=function(t){return"date"===k(t)},G=function(t){return"regexp"===k(t)},W=function(t){return t&&t._internalType instanceof E},Z=function(){function t(t,e){J.isGeopoint("longitude",t),J.isGeopoint("latitude",e),this.longitude=t,this.latitude=e}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"Point",coordinates:[this.longitude,this.latitude]},e},t.prototype.toJSON=function(){return{type:"Point",coordinates:[this.longitude,this.latitude]}},t.prototype.toReadableString=function(){return"[".concat(this.longitude,",").concat(this.latitude,"]")},t.validate=function(t){return"Point"===t.type&&H(t.coordinates)&&J.isGeopoint("longitude",t.coordinates[0])&&J.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return x},enumerable:!1,configurable:!0}),t}(),K=function(){function t(t){if(!H(t))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t));if(t.length<2)throw new Error('"points" must contain 2 points at least');t.forEach(function(t){if(!(t instanceof Z))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t,"[]"))}),this.points=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"LineString",coordinates:this.points.map(function(t){return t.toJSON().coordinates})},e},t.prototype.toJSON=function(){return{type:"LineString",coordinates:this.points.map(function(t){return t.toJSON().coordinates})}},t.validate=function(t){var e,n;if("LineString"!==t.type||!H(t.coordinates))return!1;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!z(i[0])||!z(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},t.isClosed=function(t){var e=t.points[0],n=t.points[t.points.length-1];if(e.latitude===n.latitude&&e.longitude===n.longitude)return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return L},enumerable:!1,configurable:!0}),t}(),Q=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},X=function(){function t(t){if(!H(t))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach(function(t){if(!(t instanceof K))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"));if(!K.isClosed(t))throw new Error("LineString ".concat(t.points.map(function(t){return t.toReadableString()})," is not a closed cycle"))}),this.lines=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"Polygon",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})},e},t.prototype.toJSON=function(){return{type:"Polygon",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})}},t.validate=function(t){var e,n,r,o;if("Polygon"!==t.type||!H(t.coordinates))return!1;try{for(var i=Q(t.coordinates),s=i.next();!s.done;s=i.next()){var a=s.value;if(!this.isCloseLineString(a))return!1;try{for(var u=(r=void 0,Q(a)),c=u.next();!c.done;c=u.next()){var f=c.value;if(!z(f[0])||!z(f[1]))return!1}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=u.return)&&o.call(u)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},t.isCloseLineString=function(t){var e=t[0],n=t[t.length-1];return e[0]===n[0]&&e[1]===n[1]},Object.defineProperty(t.prototype,"_internalType",{get:function(){return P},enumerable:!1,configurable:!0}),t}(),tt=function(){function t(t){if(!H(t))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t));if(0===t.length)throw new Error('"points" must contain 1 point at least');t.forEach(function(t){if(!(t instanceof Z))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t,"[]"))}),this.points=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiPoint",coordinates:this.points.map(function(t){return t.toJSON().coordinates})},e},t.prototype.toJSON=function(){return{type:"MultiPoint",coordinates:this.points.map(function(t){return t.toJSON().coordinates})}},t.validate=function(t){var e,n;if("MultiPoint"!==t.type||!H(t.coordinates))return!1;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!z(i[0])||!z(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return A},enumerable:!1,configurable:!0}),t}(),et=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},nt=function(){function t(t){if(!H(t))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach(function(t){if(!(t instanceof K))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"))}),this.lines=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiLineString",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})},e},t.prototype.toJSON=function(){return{type:"MultiLineString",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})}},t.validate=function(t){var e,n,r,o;if("MultiLineString"!==t.type||!H(t.coordinates))return!1;try{for(var i=et(t.coordinates),s=i.next();!s.done;s=i.next()){var a=s.value;try{for(var u=(r=void 0,et(a)),c=u.next();!c.done;c=u.next()){var f=c.value;if(!z(f[0])||!z(f[1]))return!1}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=u.return)&&o.call(u)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return U},enumerable:!1,configurable:!0}),t}(),rt=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},ot=function(){function t(t){var e,n;if(!H(t))throw new TypeError('"polygons" must be of type Polygon[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("MultiPolygon must contain 1 polygon at least");try{for(var r=rt(t),o=r.next();!o.done;o=r.next()){var i=o.value;if(!(i instanceof X))throw new TypeError('"polygon" must be of type Polygon[]. Received type '.concat(typeof i,"[]"))}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}this.polygons=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiPolygon",coordinates:this.polygons.map(function(t){return t.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})})},e},t.prototype.toJSON=function(){return{type:"MultiPolygon",coordinates:this.polygons.map(function(t){return t.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})})}},t.validate=function(t){var e,n,r,o,i,s;if("MultiPolygon"!==t.type||!H(t.coordinates))return!1;try{for(var a=rt(t.coordinates),u=a.next();!u.done;u=a.next()){var c=u.value;try{for(var f=(r=void 0,rt(c)),l=f.next();!l.done;l=f.next()){var h=l.value;try{for(var d=(i=void 0,rt(h)),p=d.next();!p.done;p=d.next()){var y=p.value;if(!z(y[0])||!z(y[1]))return!1}}catch(t){i={error:t}}finally{try{p&&!p.done&&(s=d.return)&&s.call(d)}finally{if(i)throw i.error}}}}catch(t){r={error:t}}finally{try{l&&!l.done&&(o=f.return)&&o.call(f)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return $},enumerable:!1,configurable:!0}),t}(),it=function(){var t=function(){};if(!Promise){t.promise={};var e=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(t.promise,"then",{get:e}),Object.defineProperty(t.promise,"catch",{get:e}),t}var n=new Promise(function(e,n){t=function(t,r){return t?n(t):e(r)}});return t.promise=n,t};!function(t){t.SET="set",t.REMOVE="remove",t.INC="inc",t.MUL="mul",t.PUSH="push",t.PULL="pull",t.PULL_ALL="pullAll",t.POP="pop",t.SHIFT="shift",t.UNSHIFT="unshift",t.ADD_TO_SET="addToSet",t.BIT="bit",t.RENAME="rename",t.MAX="max",t.MIN="min"}(C||(C={}));var st,at=function(){function t(t,e,n){this._internalType=I,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||N}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function ut(t){return t&&t instanceof at&&t._internalType===I}!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(st||(st={}));var ct=function(){function t(t,e,n){if(this._internalType=B,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||N,this.fieldName!==N)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,o=e.length;r<o;r++)(ft(i=e[r])||pt(i))&&(e[r]=i._setFieldName(this.fieldName))}else{var i;(ft(i=e)||pt(i))&&(e=i._setFieldName(this.fieldName))}}return t.prototype._setFieldName=function(e){var n=this.operands.map(function(n){return n instanceof t?n._setFieldName(e):n});return new t(this.operator,n,e)},t.prototype.and=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return r.unshift(this),new t(st.AND,r,this.fieldName)},t.prototype.or=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return r.unshift(this),new t(st.OR,r,this.fieldName)},t}();function ft(t){return t&&t instanceof ct&&t._internalType===B}var lt,ht=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();!function(t){t.EQ="eq",t.NEQ="neq",t.GT="gt",t.GTE="gte",t.LT="lt",t.LTE="lte",t.IN="in",t.NIN="nin",t.ALL="all",t.ELEM_MATCH="elemMatch",t.EXISTS="exists",t.SIZE="size",t.MOD="mod",t.GEO_NEAR="geoNear",t.GEO_WITHIN="geoWithin",t.GEO_INTERSECTS="geoIntersects"}(lt||(lt={}));var dt=function(t){function e(e,n,r){var o=t.call(this,e,n,r)||this;return o.operator=e,o._internalType=T,o}return ht(e,t),e.prototype.toJSON=function(){var t,e;switch(this.operator){case lt.IN:case lt.NIN:return(t={})["$"+this.operator]=this.operands,t;default:return(e={})["$"+this.operator]=this.operands[0],e}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(lt.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(lt.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(lt.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(lt.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(lt.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(lt.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(lt.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(lt.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof Z))throw new TypeError('"geometry" must be of type Point. Received type '.concat(typeof t.geometry));if(void 0!==t.maxDistance&&!z(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '.concat(typeof t.maxDistance));if(void 0!==t.minDistance&&!z(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '.concat(typeof t.minDistance));var n=new e(lt.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof ot||t.geometry instanceof X))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(lt.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof Z||t.geometry instanceof K||t.geometry instanceof X||t.geometry instanceof tt||t.geometry instanceof nt||t.geometry instanceof ot))throw new TypeError('"geometry" must be of type Point, LineString, Polygon, MultiPoint, MultiLineString or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(lt.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(ct);function pt(t){return t&&t instanceof dt&&t._internalType===T}function yt(t){return pt(t)}var gt={};for(var mt in lt)gt[mt]="$"+mt;for(var mt in st)gt[mt]="$"+mt;for(var mt in C)gt[mt]="$"+mt;function bt(t){return gt[t]||"$"+t}gt[lt.NEQ]="$ne",gt[C.REMOVE]="$unset",gt[C.SHIFT]="$pop",gt[C.UNSHIFT]="$push";var wt=function(){return wt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},wt.apply(this,arguments)},vt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},_t=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Ot(t){return Et(t,[t])}function Et(t,e){if(!W(t)){if(Y(t))return{$date:+t};if(G(t))return{$regex:t.source,$options:t.flags};if(H(t))return t.map(function(t){if(e.indexOf(t)>-1)throw new Error("Cannot convert circular structure to JSON");return Et(t,_t(_t([],vt(e),!1),[t],!1))});if(V(t)){var n=wt({},t);for(var r in n){if(e.indexOf(n[r])>-1)throw new Error("Cannot convert circular structure to JSON");n[r]=Et(n[r],_t(_t([],vt(e),!1),[n[r]],!1))}return n}return t}switch(t._internalType){case x:return t.toJSON();case j:case R:return t.parse();default:return t.toJSON?t.toJSON():t}}var St=function(){return St=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},St.apply(this,arguments)},Nt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},It=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Tt(t,e,n,r){var o=St({},t);for(var i in t)if(!/^\$/.test(i)){var s=t[i];if(s&&V(s)&&!e(s)){if(r.indexOf(s)>-1)throw new Error("Cannot convert circular structure to JSON");var a=Tt(s,e,It(It([],Nt(n),!1),[i],!1),It(It([],Nt(r),!1),[s],!1));o[i]=a;var u=!1;for(var c in a)/^\$/.test(c)?u=!0:(o["".concat(i,".").concat(c)]=a[c],delete o[i][c]);u||delete o[i]}}return o}function Bt(t){return Tt(t,Lt,[],[t])}function xt(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?H(t[r])?t[r].push(e[r]):V(t[r])?V(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is ".concat(k(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(k(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]}function Lt(t){return W(t)||Y(t)||G(t)}function $t(t){return Ot(t)}var At=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.prototype.encodeUpdate=function(t){return ut(t)?this.encodeUpdateCommand(t):"object"===k(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===N)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case C.PUSH:case C.PULL:case C.PULL_ALL:case C.POP:case C.SHIFT:case C.UNSHIFT:case C.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,o,i=bt(t.operator);return t.operator===C.REMOVE?((e={})[i]=((n={})[t.fieldName]="",n),e):((r={})[i]=((o={})[t.fieldName]=t.operands[0],o),r)},t.prototype.encodeArrayUpdateCommand=function(t){var e,n,r,o,i,s,a,u,c,f,l=bt(t.operator);switch(t.operator){case C.PUSH:var h=void 0;return h=H(t.operands)?{$each:t.operands.map($t)}:t.operands,(e={})[l]=((n={})[t.fieldName]=h,n),e;case C.UNSHIFT:return h={$each:t.operands.map($t),$position:0},(r={})[l]=((o={})[t.fieldName]=h,o),r;case C.POP:return(i={})[l]=((s={})[t.fieldName]=1,s),i;case C.SHIFT:return(a={})[l]=((u={})[t.fieldName]=-1,u),a;default:return(c={})[l]=((f={})[t.fieldName]=$t(t.operands),f),c}},t.prototype.encodeUpdateObject=function(t){var e=Bt(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(ut(r))e[n]=r._setFieldName(n),xt(e,this.encodeUpdateCommand(e[n]),n);else{e[n]=r=$t(r);var o=new at(C.SET,[r],n);xt(e,this.encodeUpdateCommand(o),n)}}return e},t}(),Ut={};function Pt(t){if(!ge.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return Ut[e]||(Ut[e]=new ge.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:ge.createRequest(t.config)}}})),Ut[e]}var jt=function(){return jt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},jt.apply(this,arguments)},Rt=function(){function t(t,e,n,r){void 0===r&&(r={});var o=this;this.watch=function(t){return Pt(o._db).watch(jt(jt({},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=ge.createRequest(this._db.config),this.projection=r}return t.prototype.create=function(t,e){e=e||it();var n=Array.isArray(t),r={collectionName:this._coll,data:n?t.map(function(t){return Ot(t)}):Ot(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||it(),!this.id)return Promise.resolve({code:"INVALID_PARAM",message:"docId不能为空"});if(!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n=!1,r=function(t){if("object"==typeof t)for(var e in t)t[e]instanceof at?n=!0:"object"==typeof t[e]&&r(t[e])};if(r(t),n)return Promise.resolve({code:"DATABASE_REQUEST_FAILED",message:"update operator complicit"});var o={collectionName:this._coll,queryType:a.DOC,data:Ot(t),multi:!1,merge:!1,upsert:!0};return this.id&&(o.query={_id:this.id}),this.request.send("database.updateDocument",o).then(function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})}).catch(function(t){e(t)}),e.promise},t.prototype.update=function(t,e){if(e=e||it(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={_id:this.id},r={collectionName:this._coll,data:At.encode(t),query:n,queryType:a.DOC,multi:!1,merge:!0,upsert:!1};return this.request.send("database.updateDocument",r).then(function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})}).catch(function(t){e(t)}),e.promise},t.prototype.remove=function(t){t=t||it();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:a.DOC,multi:!1};return this.request.send("database.deleteDocument",n).then(function(e){e.code?t(0,e):t(0,{deleted:e.data.deleted,requestId:e.requestId})}).catch(function(e){t(e)}),t.promise},t.prototype.get=function(t){t=t||it();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:a.DOC,multi:!1,projection:this.projection};return this.request.send("database.queryDocument",n).then(function(e){if(e.code)t(0,e);else{var n=M.formatResDocumentData(e.data.list);t(0,{data:n,requestId:e.requestId})}}).catch(function(e){t(e)}),t.promise},t.prototype.field=function(e){for(var n in e)e[n]?e[n]=1:e[n]=0;return new t(this._db,this._coll,this.id,e)},t}(),Dt=function(){function t(){}return t.encode=function(t){return(new qt).encodeQuery(t)},t}(),qt=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n;return Lt(t)?ft(t)?this.encodeLogicCommand(t):pt(t)?this.encodeQueryCommand(t):((n={})[e]=this.encodeQueryObject(t),n):V(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regex:t.source,$options:t.flags}},t.prototype.encodeLogicCommand=function(t){var e,n,r,o,i,s,a,u=this;switch(t.operator){case st.NOR:case st.AND:case st.OR:var c=bt(t.operator),f=t.operands.map(function(e){return u.encodeQuery(e,t.fieldName)});return(e={})[c]=f,e;case st.NOT:c=bt(t.operator);var l=t.operands[0];return G(l)?((n={})[t.fieldName]=((r={})[c]=this.encodeRegExp(l),r),n):(f=this.encodeQuery(l)[t.fieldName],(o={})[t.fieldName]=((i={})[c]=f,i),o);default:if(c=bt(t.operator),1===t.operands.length){var h=this.encodeQuery(t.operands[0]);return(s={})[c]=h,s}return f=t.operands.map(this.encodeQuery.bind(this)),(a={})[c]=f,a}},t.prototype.encodeQueryCommand=function(t){return yt(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,o,i,s,a,u,c;if(t.fieldName===N)throw new Error("Cannot encode a comparison command with unset field name");var f=bt(t.operator);switch(t.operator){case lt.EQ:case lt.NEQ:case lt.LT:case lt.LTE:case lt.GT:case lt.GTE:case lt.ELEM_MATCH:case lt.EXISTS:case lt.SIZE:case lt.MOD:return(e={})[t.fieldName]=((n={})[f]=$t(t.operands[0]),n),e;case lt.IN:case lt.NIN:case lt.ALL:return(r={})[t.fieldName]=((o={})[f]=$t(t.operands),o),r;case lt.GEO_NEAR:var l=t.operands[0];return(i={})[t.fieldName]={$nearSphere:{$geometry:l.geometry.toJSON(),$maxDistance:l.maxDistance,$minDistance:l.minDistance}},i;case lt.GEO_WITHIN:return l=t.operands[0],(s={})[t.fieldName]={$geoWithin:{$geometry:l.geometry.toJSON()}},s;case lt.GEO_INTERSECTS:return l=t.operands[0],(a={})[t.fieldName]={$geoIntersects:{$geometry:l.geometry.toJSON()}},a;default:return(u={})[t.fieldName]=((c={})[f]=$t(t.operands[0]),c),u}},t.prototype.encodeQueryObject=function(t){var e=Bt(t);for(var n in e){var r=e[n];if(ft(r)){e[n]=r._setFieldName(n);var o=this.encodeLogicCommand(e[n]);this.mergeConditionAfterEncode(e,o,n)}else yt(r)?(e[n]=r._setFieldName(n),o=this.encodeComparisonCommand(e[n]),this.mergeConditionAfterEncode(e,o,n)):Lt(r)&&(e[n]=$t(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?H(t[r])?t[r]=t[r].concat(e[r]):V(t[r])?V(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is ".concat(k(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(k(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),Ct=function(){return Ct=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ct.apply(this,arguments)},Ft=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){return Pt(i._db).watch(Ct(Ct({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify(i._fieldFilters||{}),limit:i._queryOptions.limit,orderBy:i._fieldOrders?i._fieldOrders.reduce(function(t,e){return t[e.field]=e.direction,t},{}):void 0}))},this._db=t,this._coll=e,this._fieldFilters=n,this._fieldOrders=r||[],this._queryOptions=o||{},this._request=ge.createRequest(this._db.config)}return t.prototype.get=function(t){t=t||it();var e=[];this._fieldOrders&&this._fieldOrders.forEach(function(t){e.push(t)});var n={collectionName:this._coll,queryType:a.WHERE};return this._fieldFilters&&(n.query=this._fieldFilters),e.length>0&&(n.order=e),this._queryOptions.offset&&(n.offset=this._queryOptions.offset),this._queryOptions.limit?n.limit=this._queryOptions.limit<1e3?this._queryOptions.limit:1e3:n.limit=100,this._queryOptions.projection&&(n.projection=this._queryOptions.projection),this._request.send("database.queryDocument",n).then(function(e){if(e.code)t(0,e);else{var n={data:M.formatResDocumentData(e.data.list),requestId:e.requestId};void 0!==e.total&&(n.total=e.total),void 0!==e.limit&&(n.limit=e.limit),void 0!==e.offset&&(n.offset=e.offset),t(0,n)}}).catch(function(e){t(e)}),t.promise},t.prototype.count=function(t){t=t||it();var e={collectionName:this._coll,queryType:a.WHERE};return this._fieldFilters&&(e.query=this._fieldFilters),this._request.send("database.countDocument",e).then(function(e){e.code?t(0,e):t(0,{requestId:e.requestId,total:e.data.total})}).catch(function(e){t(e)}),t.promise},t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(o.QueryParamTypeError);var n=Object.keys(e),r=n.some(function(t){return void 0!==e[t]});if(n.length&&!r)throw Error(o.QueryParamValueError);return new t(this._db,this._coll,Dt.encode(e),this._fieldOrders,this._queryOptions)},t.prototype.orderBy=function(e,n){J.isFieldPath(e),J.isFieldOrder(n);var r={field:e,direction:n},o=this._fieldOrders.concat(r);return new t(this._db,this._coll,this._fieldFilters,o,this._queryOptions)},t.prototype.limit=function(e){J.isInteger("limit",e);var n=Ct({},this._queryOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.skip=function(e){J.isInteger("offset",e);var n=Ct({},this._queryOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.update=function(t,e){if(e=e||it(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={collectionName:this._coll,query:this._fieldFilters,queryType:a.WHERE,multi:!0,merge:!0,upsert:!1,data:At.encode(t)};return this._request.send("database.updateDocument",n).then(function(t){t.code?e(0,t):e(0,{requestId:t.requestId,updated:t.data.updated,upsertId:t.data.upsert_id})}).catch(function(t){e(t)}),e.promise},t.prototype.field=function(e){for(var n in e)e[n]?"object"!=typeof e[n]&&(e[n]=1):e[n]=0;var r=Ct({},this._queryOptions);return r.projection=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,r)},t.prototype.remove=function(t){t=t||it(),Object.keys(this._queryOptions).length>0&&console.warn("`offset`, `limit` and `projection` are not supported in remove() operation"),this._fieldOrders.length>0&&console.warn("`orderBy` is not supported in remove() operation");var e={collectionName:this._coll,query:Dt.encode(this._fieldFilters),queryType:a.WHERE,multi:!0};return this._request.send("database.deleteDocument",e).then(function(e){e.code?t(0,e):t(0,{requestId:e.requestId,deleted:e.data.deleted})}).catch(function(e){t(e)}),t.promise},t}(),Mt=n(804),Jt=function(){function t(t,e){this._stages=[],t&&e&&(this._db=t,this._request=ge.createRequest(this._db.config),this._collectionName=e)}return t.prototype.end=function(){return t=this,e=void 0,r=function(){var t;return function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,function(e){switch(e.label){case 0:if(!this._collectionName||!this._db)throw new Error("Aggregation pipeline cannot send request");return[4,this._request.send("database.aggregate",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:JSON.parse(t.data.list).map(Mt.EJSON.parse)}]:[2,t]}})},new((n=void 0)||(n=Promise))(function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}u((r=r.apply(t,e||[])).next())});var t,e,n,r},t.prototype.unwrap=function(){return this._stages},t.prototype.done=function(){return this._stages.map(function(t){var e,n=t.stageKey,r=t.stageValue;return(e={})[n]=JSON.parse(r),e})},t.prototype._pipe=function(t,e){return this._stages.push({stageKey:"$".concat(t),stageValue:JSON.stringify(e)}),this},t.prototype.addFields=function(t){return this._pipe("addFields",t)},t.prototype.bucket=function(t){return this._pipe("bucket",t)},t.prototype.bucketAuto=function(t){return this._pipe("bucketAuto",t)},t.prototype.count=function(t){return this._pipe("count",t)},t.prototype.geoNear=function(t){return t.query&&(t.query=Dt.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new Z(t.near.longitude,t.near.latitude).toJSON()),this._pipe("geoNear",t)},t.prototype.group=function(t){return this._pipe("group",t)},t.prototype.limit=function(t){return this._pipe("limit",t)},t.prototype.match=function(t){return this._pipe("match",Dt.encode(t))},t.prototype.project=function(t){return this._pipe("project",t)},t.prototype.lookup=function(t){return this._pipe("lookup",t)},t.prototype.replaceRoot=function(t){return this._pipe("replaceRoot",t)},t.prototype.sample=function(t){return this._pipe("sample",t)},t.prototype.skip=function(t){return this._pipe("skip",t)},t.prototype.sort=function(t){return this._pipe("sort",t)},t.prototype.sortByCount=function(t){return this._pipe("sortByCount",t)},t.prototype.unwind=function(t){return this._pipe("unwind",t)},t}();const kt=Jt;var Vt=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,