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