@cloudbase/js-sdk 2.5.6-beta.1 → 2.5.7-beta.0

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.
@@ -14,4 +14,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
14
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
15
  PERFORMANCE OF THIS SOFTWARE.
16
16
  ***************************************************************************** */
17
- var b=function(t,e){return(b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function v(t,e){function n(){this.constructor=t}b(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var _=function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return v(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return"BSONError"},enumerable:!1,configurable:!0}),e}(Error),E=function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return v(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return"BSONTypeError"},enumerable:!1,configurable:!0}),e}(TypeError);function O(t){return t&&t.Math==Math&&t}function S(){return O("object"==typeof globalThis&&globalThis)||O("object"==typeof window&&window)||O("object"==typeof self&&self)||O("object"==typeof t&&t)||Function("return this")()}var N=function(t){var e,n="object"==typeof(e=S()).navigator&&"ReactNative"===e.navigator.product?"BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.":"BSON: No cryptographic implementation for random bytes present, falling back to a less secure implementation.";console.warn(n);for(var r=w.alloc(t),o=0;o<t;++o)r[o]=Math.floor(256*Math.random());return r},x=function(){if("undefined"!=typeof window){var e=window.crypto||window.msCrypto;if(e&&e.getRandomValues)return function(t){return e.getRandomValues(w.alloc(t))}}return void 0!==t&&t.crypto&&t.crypto.getRandomValues?function(e){return t.crypto.getRandomValues(w.alloc(e))}:N}();function I(t){return["[object ArrayBuffer]","[object SharedArrayBuffer]"].includes(Object.prototype.toString.call(t))}function A(t){return"[object Uint8Array]"===Object.prototype.toString.call(t)}function T(t){return"[object RegExp]"===Object.prototype.toString.call(t)}function B(t){return j(t)&&"[object Date]"===Object.prototype.toString.call(t)}function j(t){return"object"==typeof t&&null!==t}function P(t,e){var n=!1;return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];return n||(console.warn(e),n=!0),t.apply(this,r)}}function L(t){if(ArrayBuffer.isView(t))return w.from(t.buffer,t.byteOffset,t.byteLength);if(I(t))return w.from(t);throw new E("Must use either Buffer or TypedArray")}var U=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15})$/i,$=function(t){return"string"==typeof t&&U.test(t)},R=function(t){if(!$(t))throw new E('UUID string representations must be a 32 or 36 character hex string (dashes excluded/included). Format: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" or "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".');var e=t.replace(/-/g,"");return w.from(e,"hex")},M=function(t,e){return void 0===e&&(e=!0),e?t.toString("hex",0,4)+"-"+t.toString("hex",4,6)+"-"+t.toString("hex",6,8)+"-"+t.toString("hex",8,10)+"-"+t.toString("hex",10,16):t.toString("hex")},D=(Math.pow(2,63),Math.pow(2,63),Math.pow(2,53)),q=-Math.pow(2,53),C=function(){function t(e,n){if(!(this instanceof t))return new t(e,n);if(!(null==e||"string"==typeof e||ArrayBuffer.isView(e)||e instanceof ArrayBuffer||Array.isArray(e)))throw new E("Binary can only be constructed from string, Buffer, TypedArray, or Array<number>");this.sub_type=null!=n?n:t.BSON_BINARY_SUBTYPE_DEFAULT,null==e?(this.buffer=w.alloc(t.BUFFER_SIZE),this.position=0):("string"==typeof e?this.buffer=w.from(e,"binary"):Array.isArray(e)?this.buffer=w.from(e):this.buffer=L(e),this.position=this.buffer.byteLength)}return t.prototype.put=function(e){if("string"==typeof e&&1!==e.length)throw new E("only accepts single character String");if("number"!=typeof e&&1!==e.length)throw new E("only accepts single character Uint8Array or Array");var n;if((n="string"==typeof e?e.charCodeAt(0):"number"==typeof e?e:e[0])<0||n>255)throw new E("only accepts number in a valid unsigned byte range 0-255");if(this.buffer.length>this.position)this.buffer[this.position++]=n;else{var r=w.alloc(t.BUFFER_SIZE+this.buffer.length);this.buffer.copy(r,0,0,this.buffer.length),this.buffer=r,this.buffer[this.position++]=n}},t.prototype.write=function(t,e){if(e="number"==typeof e?e:this.position,this.buffer.length<e+t.length){var n=w.alloc(this.buffer.length+t.length);this.buffer.copy(n,0,0,this.buffer.length),this.buffer=n}ArrayBuffer.isView(t)?(this.buffer.set(L(t),e),this.position=e+t.byteLength>this.position?e+t.length:this.position):"string"==typeof t&&(this.buffer.write(t,e,t.length,"binary"),this.position=e+t.length>this.position?e+t.length:this.position)},t.prototype.read=function(t,e){return e=e&&e>0?e:this.position,this.buffer.slice(t,t+e)},t.prototype.value=function(t){return(t=!!t)&&this.buffer.length===this.position?this.buffer:t?this.buffer.slice(0,this.position):this.buffer.toString("binary",0,this.position)},t.prototype.length=function(){return this.position},t.prototype.toJSON=function(){return this.buffer.toString("base64")},t.prototype.toString=function(t){return this.buffer.toString(t)},t.prototype.toExtendedJSON=function(t){t=t||{};var e=this.buffer.toString("base64"),n=Number(this.sub_type).toString(16);return t.legacy?{$binary:e,$type:1===n.length?"0"+n:n}:{$binary:{base64:e,subType:1===n.length?"0"+n:n}}},t.prototype.toUUID=function(){if(this.sub_type===t.SUBTYPE_UUID)return new k(this.buffer.slice(0,this.position));throw new _('Binary sub_type "'.concat(this.sub_type,'" is not supported for converting to UUID. Only "').concat(t.SUBTYPE_UUID,'" is currently supported.'))},t.fromExtendedJSON=function(e,n){var r,o;if(n=n||{},"$binary"in e?n.legacy&&"string"==typeof e.$binary&&"$type"in e?(o=e.$type?parseInt(e.$type,16):0,r=w.from(e.$binary,"base64")):"string"!=typeof e.$binary&&(o=e.$binary.subType?parseInt(e.$binary.subType,16):0,r=w.from(e.$binary.base64,"base64")):"$uuid"in e&&(o=4,r=R(e.$uuid)),!r)throw new E("Unexpected Binary Extended JSON format ".concat(JSON.stringify(e)));return 4===o?new k(r):new t(r,o)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){var t=this.value(!0);return'new Binary(Buffer.from("'.concat(t.toString("hex"),'", "hex"), ').concat(this.sub_type,")")},t.BSON_BINARY_SUBTYPE_DEFAULT=0,t.BUFFER_SIZE=256,t.SUBTYPE_DEFAULT=0,t.SUBTYPE_FUNCTION=1,t.SUBTYPE_BYTE_ARRAY=2,t.SUBTYPE_UUID_OLD=3,t.SUBTYPE_UUID=4,t.SUBTYPE_MD5=5,t.SUBTYPE_ENCRYPTED=6,t.SUBTYPE_COLUMN=7,t.SUBTYPE_USER_DEFINED=128,t}();Object.defineProperty(C.prototype,"_bsontype",{value:"Binary"});var k=function(t){function e(n){var r,o,i=this;if(null==n)r=e.generate();else if(n instanceof e)r=w.from(n.buffer),o=n.__id;else if(ArrayBuffer.isView(n)&&16===n.byteLength)r=L(n);else{if("string"!=typeof n)throw new E("Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).");r=R(n)}return(i=t.call(this,r,4)||this).__id=o,i}return v(e,t),Object.defineProperty(e.prototype,"id",{get:function(){return this.buffer},set:function(t){this.buffer=t,e.cacheHexString&&(this.__id=M(t))},enumerable:!1,configurable:!0}),e.prototype.toHexString=function(t){if(void 0===t&&(t=!0),e.cacheHexString&&this.__id)return this.__id;var n=M(this.id,t);return e.cacheHexString&&(this.__id=n),n},e.prototype.toString=function(t){return t?this.id.toString(t):this.toHexString()},e.prototype.toJSON=function(){return this.toHexString()},e.prototype.equals=function(t){if(!t)return!1;if(t instanceof e)return t.id.equals(this.id);try{return new e(t).id.equals(this.id)}catch(t){return!1}},e.prototype.toBinary=function(){return new C(this.id,C.SUBTYPE_UUID)},e.generate=function(){var t=x(16);return t[6]=15&t[6]|64,t[8]=63&t[8]|128,w.from(t)},e.isValid=function(t){return!!t&&(t instanceof e||("string"==typeof t?$(t):!!A(t)&&(16===t.length&&(64==(240&t[6])&&128==(128&t[8])))))},e.createFromHexString=function(t){return new e(R(t))},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){return'new UUID("'.concat(this.toHexString(),'")')},e}(C),J=function(){function t(e,n){if(!(this instanceof t))return new t(e,n);this.code=e,this.scope=n}return t.prototype.toJSON=function(){return{code:this.code,scope:this.scope}},t.prototype.toExtendedJSON=function(){return this.scope?{$code:this.code,$scope:this.scope}:{$code:this.code}},t.fromExtendedJSON=function(e){return new t(e.$code,e.$scope)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){var t=this.toJSON();return'new Code("'.concat(String(t.code),'"').concat(t.scope?", ".concat(JSON.stringify(t.scope)):"",")")},t}();function F(t){return j(t)&&null!=t.$id&&"string"==typeof t.$ref&&(null==t.$db||"string"==typeof t.$db)}Object.defineProperty(J.prototype,"_bsontype",{value:"Code"});var V=function(){function t(e,n,r,o){if(!(this instanceof t))return new t(e,n,r,o);var i=e.split(".");2===i.length&&(r=i.shift(),e=i.shift()),this.collection=e,this.oid=n,this.db=r,this.fields=o||{}}return Object.defineProperty(t.prototype,"namespace",{get:function(){return this.collection},set:function(t){this.collection=t},enumerable:!1,configurable:!0}),t.prototype.toJSON=function(){var t=Object.assign({$ref:this.collection,$id:this.oid},this.fields);return null!=this.db&&(t.$db=this.db),t},t.prototype.toExtendedJSON=function(t){t=t||{};var e={$ref:this.collection,$id:this.oid};return t.legacy?e:(this.db&&(e.$db=this.db),e=Object.assign(e,this.fields))},t.fromExtendedJSON=function(e){var n=Object.assign({},e);return delete n.$ref,delete n.$id,delete n.$db,new t(e.$ref,e.$id,e.$db,n)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){var t=void 0===this.oid||void 0===this.oid.toString?this.oid:this.oid.toString();return'new DBRef("'.concat(this.namespace,'", new ObjectId("').concat(String(t),'")').concat(this.db?', "'.concat(this.db,'"'):"",")")},t}();Object.defineProperty(V.prototype,"_bsontype",{value:"DBRef"});var H=void 0;try{H=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch(t){}var G={},Z={},Y=function(){function t(e,n,r){if(void 0===e&&(e=0),!(this instanceof t))return new t(e,n,r);"bigint"==typeof e?Object.assign(this,t.fromBigInt(e,!!n)):"string"==typeof e?Object.assign(this,t.fromString(e,!!n)):(this.low=0|e,this.high=0|n,this.unsigned=!!r),Object.defineProperty(this,"__isLong__",{value:!0,configurable:!1,writable:!1,enumerable:!1})}return t.fromBits=function(e,n,r){return new t(e,n,r)},t.fromInt=function(e,n){var r,o,i;return n?(i=0<=(e>>>=0)&&e<256)&&(o=Z[e])?o:(r=t.fromBits(e,(0|e)<0?-1:0,!0),i&&(Z[e]=r),r):(i=-128<=(e|=0)&&e<128)&&(o=G[e])?o:(r=t.fromBits(e,e<0?-1:0,!1),i&&(G[e]=r),r)},t.fromNumber=function(e,n){if(isNaN(e))return n?t.UZERO:t.ZERO;if(n){if(e<0)return t.UZERO;if(e>=0x10000000000000000)return t.MAX_UNSIGNED_VALUE}else{if(e<=-0x8000000000000000)return t.MIN_VALUE;if(e+1>=0x8000000000000000)return t.MAX_VALUE}return e<0?t.fromNumber(-e,n).neg():t.fromBits(e%4294967296|0,e/4294967296|0,n)},t.fromBigInt=function(e,n){return t.fromString(e.toString(),n)},t.fromString=function(e,n,r){if(0===e.length)throw Error("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return t.ZERO;if("number"==typeof n?(r=n,n=!1):n=!!n,(r=r||10)<2||36<r)throw RangeError("radix");var o;if((o=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===o)return t.fromString(e.substring(1),n,r).neg();for(var i=t.fromNumber(Math.pow(r,8)),u=t.ZERO,s=0;s<e.length;s+=8){var a=Math.min(8,e.length-s),f=parseInt(e.substring(s,s+a),r);if(a<8){var c=t.fromNumber(Math.pow(r,a));u=u.mul(c).add(t.fromNumber(f))}else u=(u=u.mul(i)).add(t.fromNumber(f))}return u.unsigned=n,u},t.fromBytes=function(e,n,r){return r?t.fromBytesLE(e,n):t.fromBytesBE(e,n)},t.fromBytesLE=function(e,n){return new t(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,n)},t.fromBytesBE=function(e,n){return new t(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],n)},t.isLong=function(t){return j(t)&&!0===t.__isLong__},t.fromValue=function(e,n){return"number"==typeof e?t.fromNumber(e,n):"string"==typeof e?t.fromString(e,n):t.fromBits(e.low,e.high,"boolean"==typeof n?n:e.unsigned)},t.prototype.add=function(e){t.isLong(e)||(e=t.fromValue(e));var n=this.high>>>16,r=65535&this.high,o=this.low>>>16,i=65535&this.low,u=e.high>>>16,s=65535&e.high,a=e.low>>>16,f=0,c=0,h=0,p=0;return h+=(p+=i+(65535&e.low))>>>16,p&=65535,c+=(h+=o+a)>>>16,h&=65535,f+=(c+=r+s)>>>16,c&=65535,f+=n+u,f&=65535,t.fromBits(h<<16|p,f<<16|c,this.unsigned)},t.prototype.and=function(e){return t.isLong(e)||(e=t.fromValue(e)),t.fromBits(this.low&e.low,this.high&e.high,this.unsigned)},t.prototype.compare=function(e){if(t.isLong(e)||(e=t.fromValue(e)),this.eq(e))return 0;var n=this.isNegative(),r=e.isNegative();return n&&!r?-1:!n&&r?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},t.prototype.comp=function(t){return this.compare(t)},t.prototype.divide=function(e){if(t.isLong(e)||(e=t.fromValue(e)),e.isZero())throw Error("division by zero");if(H){if(!this.unsigned&&-2147483648===this.high&&-1===e.low&&-1===e.high)return this;var n=(this.unsigned?H.div_u:H.div_s)(this.low,this.high,e.low,e.high);return t.fromBits(n,H.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?t.UZERO:t.ZERO;var r,o,i;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return t.UZERO;if(e.gt(this.shru(1)))return t.UONE;i=t.UZERO}else{if(this.eq(t.MIN_VALUE))return e.eq(t.ONE)||e.eq(t.NEG_ONE)?t.MIN_VALUE:e.eq(t.MIN_VALUE)?t.ONE:(r=this.shr(1).div(e).shl(1)).eq(t.ZERO)?e.isNegative()?t.ONE:t.NEG_ONE:(o=this.sub(e.mul(r)),i=r.add(o.div(e)));if(e.eq(t.MIN_VALUE))return this.unsigned?t.UZERO:t.ZERO;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();i=t.ZERO}for(o=this;o.gte(e);){r=Math.max(1,Math.floor(o.toNumber()/e.toNumber()));for(var u=Math.ceil(Math.log(r)/Math.LN2),s=u<=48?1:Math.pow(2,u-48),a=t.fromNumber(r),f=a.mul(e);f.isNegative()||f.gt(o);)r-=s,f=(a=t.fromNumber(r,this.unsigned)).mul(e);a.isZero()&&(a=t.ONE),i=i.add(a),o=o.sub(f)}return i},t.prototype.div=function(t){return this.divide(t)},t.prototype.equals=function(e){return t.isLong(e)||(e=t.fromValue(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},t.prototype.eq=function(t){return this.equals(t)},t.prototype.getHighBits=function(){return this.high},t.prototype.getHighBitsUnsigned=function(){return this.high>>>0},t.prototype.getLowBits=function(){return this.low},t.prototype.getLowBitsUnsigned=function(){return this.low>>>0},t.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.eq(t.MIN_VALUE)?64:this.neg().getNumBitsAbs();var e,n=0!==this.high?this.high:this.low;for(e=31;e>0&&0==(n&1<<e);e--);return 0!==this.high?e+33:e+1},t.prototype.greaterThan=function(t){return this.comp(t)>0},t.prototype.gt=function(t){return this.greaterThan(t)},t.prototype.greaterThanOrEqual=function(t){return this.comp(t)>=0},t.prototype.gte=function(t){return this.greaterThanOrEqual(t)},t.prototype.ge=function(t){return this.greaterThanOrEqual(t)},t.prototype.isEven=function(){return 0==(1&this.low)},t.prototype.isNegative=function(){return!this.unsigned&&this.high<0},t.prototype.isOdd=function(){return 1==(1&this.low)},t.prototype.isPositive=function(){return this.unsigned||this.high>=0},t.prototype.isZero=function(){return 0===this.high&&0===this.low},t.prototype.lessThan=function(t){return this.comp(t)<0},t.prototype.lt=function(t){return this.lessThan(t)},t.prototype.lessThanOrEqual=function(t){return this.comp(t)<=0},t.prototype.lte=function(t){return this.lessThanOrEqual(t)},t.prototype.modulo=function(e){if(t.isLong(e)||(e=t.fromValue(e)),H){var n=(this.unsigned?H.rem_u:H.rem_s)(this.low,this.high,e.low,e.high);return t.fromBits(n,H.get_high(),this.unsigned)}return this.sub(this.div(e).mul(e))},t.prototype.mod=function(t){return this.modulo(t)},t.prototype.rem=function(t){return this.modulo(t)},t.prototype.multiply=function(e){if(this.isZero())return t.ZERO;if(t.isLong(e)||(e=t.fromValue(e)),H){var n=H.mul(this.low,this.high,e.low,e.high);return t.fromBits(n,H.get_high(),this.unsigned)}if(e.isZero())return t.ZERO;if(this.eq(t.MIN_VALUE))return e.isOdd()?t.MIN_VALUE:t.ZERO;if(e.eq(t.MIN_VALUE))return this.isOdd()?t.MIN_VALUE:t.ZERO;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(t.TWO_PWR_24)&&e.lt(t.TWO_PWR_24))return t.fromNumber(this.toNumber()*e.toNumber(),this.unsigned);var r=this.high>>>16,o=65535&this.high,i=this.low>>>16,u=65535&this.low,s=e.high>>>16,a=65535&e.high,f=e.low>>>16,c=65535&e.low,h=0,p=0,l=0,d=0;return l+=(d+=u*c)>>>16,d&=65535,p+=(l+=i*c)>>>16,l&=65535,p+=(l+=u*f)>>>16,l&=65535,h+=(p+=o*c)>>>16,p&=65535,h+=(p+=i*f)>>>16,p&=65535,h+=(p+=u*a)>>>16,p&=65535,h+=r*c+o*f+i*a+u*s,h&=65535,t.fromBits(l<<16|d,h<<16|p,this.unsigned)},t.prototype.mul=function(t){return this.multiply(t)},t.prototype.negate=function(){return!this.unsigned&&this.eq(t.MIN_VALUE)?t.MIN_VALUE:this.not().add(t.ONE)},t.prototype.neg=function(){return this.negate()},t.prototype.not=function(){return t.fromBits(~this.low,~this.high,this.unsigned)},t.prototype.notEquals=function(t){return!this.equals(t)},t.prototype.neq=function(t){return this.notEquals(t)},t.prototype.ne=function(t){return this.notEquals(t)},t.prototype.or=function(e){return t.isLong(e)||(e=t.fromValue(e)),t.fromBits(this.low|e.low,this.high|e.high,this.unsigned)},t.prototype.shiftLeft=function(e){return t.isLong(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?t.fromBits(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):t.fromBits(0,this.low<<e-32,this.unsigned)},t.prototype.shl=function(t){return this.shiftLeft(t)},t.prototype.shiftRight=function(e){return t.isLong(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?t.fromBits(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):t.fromBits(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},t.prototype.shr=function(t){return this.shiftRight(t)},t.prototype.shiftRightUnsigned=function(e){if(t.isLong(e)&&(e=e.toInt()),0===(e&=63))return this;var n=this.high;if(e<32){var r=this.low;return t.fromBits(r>>>e|n<<32-e,n>>>e,this.unsigned)}return 32===e?t.fromBits(n,0,this.unsigned):t.fromBits(n>>>e-32,0,this.unsigned)},t.prototype.shr_u=function(t){return this.shiftRightUnsigned(t)},t.prototype.shru=function(t){return this.shiftRightUnsigned(t)},t.prototype.subtract=function(e){return t.isLong(e)||(e=t.fromValue(e)),this.add(e.neg())},t.prototype.sub=function(t){return this.subtract(t)},t.prototype.toInt=function(){return this.unsigned?this.low>>>0:this.low},t.prototype.toNumber=function(){return this.unsigned?4294967296*(this.high>>>0)+(this.low>>>0):4294967296*this.high+(this.low>>>0)},t.prototype.toBigInt=function(){return BigInt(this.toString())},t.prototype.toBytes=function(t){return t?this.toBytesLE():this.toBytesBE()},t.prototype.toBytesLE=function(){var t=this.high,e=this.low;return[255&e,e>>>8&255,e>>>16&255,e>>>24,255&t,t>>>8&255,t>>>16&255,t>>>24]},t.prototype.toBytesBE=function(){var t=this.high,e=this.low;return[t>>>24,t>>>16&255,t>>>8&255,255&t,e>>>24,e>>>16&255,e>>>8&255,255&e]},t.prototype.toSigned=function(){return this.unsigned?t.fromBits(this.low,this.high,!1):this},t.prototype.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(t.MIN_VALUE)){var n=t.fromNumber(e),r=this.div(n),o=r.mul(n).sub(this);return r.toString(e)+o.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var i=t.fromNumber(Math.pow(e,6),this.unsigned),u=this,s="";;){var a=u.div(i),f=(u.sub(a.mul(i)).toInt()>>>0).toString(e);if((u=a).isZero())return f+s;for(;f.length<6;)f="0"+f;s=""+f+s}},t.prototype.toUnsigned=function(){return this.unsigned?this:t.fromBits(this.low,this.high,!0)},t.prototype.xor=function(e){return t.isLong(e)||(e=t.fromValue(e)),t.fromBits(this.low^e.low,this.high^e.high,this.unsigned)},t.prototype.eqz=function(){return this.isZero()},t.prototype.le=function(t){return this.lessThanOrEqual(t)},t.prototype.toExtendedJSON=function(t){return t&&t.relaxed?this.toNumber():{$numberLong:this.toString()}},t.fromExtendedJSON=function(e,n){var r=t.fromString(e.$numberLong);return n&&n.relaxed?r.toNumber():r},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return'new Long("'.concat(this.toString(),'"').concat(this.unsigned?", true":"",")")},t.TWO_PWR_24=t.fromInt(1<<24),t.MAX_UNSIGNED_VALUE=t.fromBits(-1,-1,!0),t.ZERO=t.fromInt(0),t.UZERO=t.fromInt(0,!0),t.ONE=t.fromInt(1),t.UONE=t.fromInt(1,!0),t.NEG_ONE=t.fromInt(-1),t.MAX_VALUE=t.fromBits(-1,2147483647,!1),t.MIN_VALUE=t.fromBits(0,-2147483648,!1),t}();Object.defineProperty(Y.prototype,"__isLong__",{value:!0}),Object.defineProperty(Y.prototype,"_bsontype",{value:"Long"});var W=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,Q=/^(\+|-)?(Infinity|inf)$/i,z=/^(\+|-)?NaN$/i,X=[124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),K=[248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),tt=[120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),et=/^([-+])?(\d+)?$/;function nt(t){return!isNaN(parseInt(t,10))}function rt(t){var e=Y.fromNumber(1e9),n=Y.fromNumber(0);if(!(t.parts[0]||t.parts[1]||t.parts[2]||t.parts[3]))return{quotient:t,rem:n};for(var r=0;r<=3;r++)n=(n=n.shiftLeft(32)).add(new Y(t.parts[r],0)),t.parts[r]=n.div(e).low,n=n.modulo(e);return{quotient:t,rem:n}}function ot(t,e){throw new E('"'.concat(t,'" is not a valid Decimal128 string - ').concat(e))}var it=function(){function t(e){if(!(this instanceof t))return new t(e);if("string"==typeof e)this.bytes=t.fromString(e).bytes;else{if(!A(e))throw new E("Decimal128 must take a Buffer or string");if(16!==e.byteLength)throw new E("Decimal128 must take a Buffer of 16 bytes");this.bytes=e}}return t.fromString=function(e){var n,r=!1,o=!1,i=!1,u=0,s=0,a=0,f=0,c=0,h=[0],p=0,l=0,d=0,y=0,g=0,m=0,b=new Y(0,0),v=new Y(0,0),_=0;if(e.length>=7e3)throw new E(e+" not a valid Decimal128 string");var O=e.match(W),S=e.match(Q),N=e.match(z);if(!O&&!S&&!N||0===e.length)throw new E(e+" not a valid Decimal128 string");if(O){var x=O[2],I=O[4],A=O[5],T=O[6];I&&void 0===T&&ot(e,"missing exponent power"),I&&void 0===x&&ot(e,"missing exponent base"),void 0===I&&(A||T)&&ot(e,"missing e before exponent")}if("+"!==e[_]&&"-"!==e[_]||(r="-"===e[_++]),!nt(e[_])&&"."!==e[_]){if("i"===e[_]||"I"===e[_])return new t(w.from(r?K:tt));if("N"===e[_])return new t(w.from(X))}for(;nt(e[_])||"."===e[_];)"."!==e[_]?(p<34&&("0"!==e[_]||i)&&(i||(c=s),i=!0,h[l++]=parseInt(e[_],10),p+=1),i&&(a+=1),o&&(f+=1),s+=1,_+=1):(o&&ot(e,"contains multiple periods"),o=!0,_+=1);if(o&&!s)throw new E(e+" not a valid Decimal128 string");if("e"===e[_]||"E"===e[_]){var B=e.substr(++_).match(et);if(!B||!B[2])return new t(w.from(X));g=parseInt(B[0],10),_+=B[0].length}if(e[_])return new t(w.from(X));if(d=0,p){if(y=p-1,1!==(u=a))for(;0===h[c+u-1];)u-=1}else d=0,y=0,h[0]=0,a=1,p=1,u=0;for(g<=f&&f-g>16384?g=-6176:g-=f;g>6111;){if((y+=1)-d>34){if(h.join("").match(/^0+$/)){g=6111;break}ot(e,"overflow")}g-=1}for(;g<-6176||p<a;){if(0===y&&u<p){g=-6176,u=0;break}if(p<a?a-=1:y-=1,g<6111)g+=1;else{if(h.join("").match(/^0+$/)){g=6111;break}ot(e,"overflow")}}if(y-d+1<u){var j=s;o&&(c+=1,j+=1),r&&(c+=1,j+=1);var P=parseInt(e[c+y+1],10),L=0;if(P>=5&&(L=1,5===P))for(L=h[y]%2==1?1:0,m=c+y+2;m<j;m++)if(parseInt(e[m],10)){L=1;break}if(L)for(var U=y;U>=0;U--)if(++h[U]>9&&(h[U]=0,0===U)){if(!(g<6111))return new t(w.from(r?K:tt));g+=1,h[U]=1}}if(b=Y.fromNumber(0),v=Y.fromNumber(0),0===u)b=Y.fromNumber(0),v=Y.fromNumber(0);else if(y-d<17){U=d;for(v=Y.fromNumber(h[U++]),b=new Y(0,0);U<=y;U++)v=(v=v.multiply(Y.fromNumber(10))).add(Y.fromNumber(h[U]))}else{U=d;for(b=Y.fromNumber(h[U++]);U<=y-17;U++)b=(b=b.multiply(Y.fromNumber(10))).add(Y.fromNumber(h[U]));for(v=Y.fromNumber(h[U++]);U<=y;U++)v=(v=v.multiply(Y.fromNumber(10))).add(Y.fromNumber(h[U]))}var $,R,M,D,q=function(t,e){if(!t&&!e)return{high:Y.fromNumber(0),low:Y.fromNumber(0)};var n=t.shiftRightUnsigned(32),r=new Y(t.getLowBits(),0),o=e.shiftRightUnsigned(32),i=new Y(e.getLowBits(),0),u=n.multiply(o),s=n.multiply(i),a=r.multiply(o),f=r.multiply(i);return u=u.add(s.shiftRightUnsigned(32)),s=new Y(s.getLowBits(),0).add(a).add(f.shiftRightUnsigned(32)),{high:u=u.add(s.shiftRightUnsigned(32)),low:f=s.shiftLeft(32).add(new Y(f.getLowBits(),0))}}(b,Y.fromString("100000000000000000"));q.low=q.low.add(v),$=q.low,R=v,M=$.high>>>0,D=R.high>>>0,(M<D||M===D&&$.low>>>0<R.low>>>0)&&(q.high=q.high.add(Y.fromNumber(1))),n=g+6176;var C={low:Y.fromNumber(0),high:Y.fromNumber(0)};q.high.shiftRightUnsigned(49).and(Y.fromNumber(1)).equals(Y.fromNumber(1))?(C.high=C.high.or(Y.fromNumber(3).shiftLeft(61)),C.high=C.high.or(Y.fromNumber(n).and(Y.fromNumber(16383).shiftLeft(47))),C.high=C.high.or(q.high.and(Y.fromNumber(0x7fffffffffff)))):(C.high=C.high.or(Y.fromNumber(16383&n).shiftLeft(49)),C.high=C.high.or(q.high.and(Y.fromNumber(562949953421311)))),C.low=q.low,r&&(C.high=C.high.or(Y.fromString("9223372036854775808")));var k=w.alloc(16);return _=0,k[_++]=255&C.low.low,k[_++]=C.low.low>>8&255,k[_++]=C.low.low>>16&255,k[_++]=C.low.low>>24&255,k[_++]=255&C.low.high,k[_++]=C.low.high>>8&255,k[_++]=C.low.high>>16&255,k[_++]=C.low.high>>24&255,k[_++]=255&C.high.low,k[_++]=C.high.low>>8&255,k[_++]=C.high.low>>16&255,k[_++]=C.high.low>>24&255,k[_++]=255&C.high.high,k[_++]=C.high.high>>8&255,k[_++]=C.high.high>>16&255,k[_++]=C.high.high>>24&255,new t(k)},t.prototype.toString=function(){for(var t,e=0,n=new Array(36),r=0;r<n.length;r++)n[r]=0;var o,i,u,s=0,a=!1,f={parts:[0,0,0,0]},c=[];s=0;var h=this.bytes,p=h[s++]|h[s++]<<8|h[s++]<<16|h[s++]<<24,l=h[s++]|h[s++]<<8|h[s++]<<16|h[s++]<<24,d=h[s++]|h[s++]<<8|h[s++]<<16|h[s++]<<24,y=h[s++]|h[s++]<<8|h[s++]<<16|h[s++]<<24;s=0,{low:new Y(p,l),high:new Y(d,y)}.high.lessThan(Y.ZERO)&&c.push("-");var g=y>>26&31;if(g>>3==3){if(30===g)return c.join("")+"Infinity";if(31===g)return"NaN";t=y>>15&16383,o=8+(y>>14&1)}else o=y>>14&7,t=y>>17&16383;var m=t-6176;if(f.parts[0]=(16383&y)+((15&o)<<14),f.parts[1]=d,f.parts[2]=l,f.parts[3]=p,0===f.parts[0]&&0===f.parts[1]&&0===f.parts[2]&&0===f.parts[3])a=!0;else for(u=3;u>=0;u--){var w=0,b=rt(f);if(f=b.quotient,w=b.rem.low)for(i=8;i>=0;i--)n[9*u+i]=w%10,w=Math.floor(w/10)}if(a)e=1,n[s]=0;else for(e=36;!n[s];)e-=1,s+=1;var v=e-1+m;if(v>=34||v<=-7||m>0){if(e>34)return c.push("".concat(0)),m>0?c.push("E+".concat(m)):m<0&&c.push("E".concat(m)),c.join("");c.push("".concat(n[s++])),(e-=1)&&c.push(".");for(r=0;r<e;r++)c.push("".concat(n[s++]));c.push("E"),v>0?c.push("+".concat(v)):c.push("".concat(v))}else if(m>=0)for(r=0;r<e;r++)c.push("".concat(n[s++]));else{var _=e+m;if(_>0)for(r=0;r<_;r++)c.push("".concat(n[s++]));else c.push("0");for(c.push(".");_++<0;)c.push("0");for(r=0;r<e-Math.max(_-1,0);r++)c.push("".concat(n[s++]))}return c.join("")},t.prototype.toJSON=function(){return{$numberDecimal:this.toString()}},t.prototype.toExtendedJSON=function(){return{$numberDecimal:this.toString()}},t.fromExtendedJSON=function(e){return t.fromString(e.$numberDecimal)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return'new Decimal128("'.concat(this.toString(),'")')},t}();Object.defineProperty(it.prototype,"_bsontype",{value:"Decimal128"});var ut=function(){function t(e){if(!(this instanceof t))return new t(e);e instanceof Number&&(e=e.valueOf()),this.value=+e}return t.prototype.valueOf=function(){return this.value},t.prototype.toJSON=function(){return this.value},t.prototype.toString=function(t){return this.value.toString(t)},t.prototype.toExtendedJSON=function(t){return t&&(t.legacy||t.relaxed&&isFinite(this.value))?this.value:Object.is(Math.sign(this.value),-0)?{$numberDouble:"-".concat(this.value.toFixed(1))}:(Number.isInteger(this.value)?(e=this.value.toFixed(1)).length>=13&&(e=this.value.toExponential(13).toUpperCase()):e=this.value.toString(),{$numberDouble:e});var e},t.fromExtendedJSON=function(e,n){var r=parseFloat(e.$numberDouble);return n&&n.relaxed?r:new t(r)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){var t=this.toExtendedJSON();return"new Double(".concat(t.$numberDouble,")")},t}();Object.defineProperty(ut.prototype,"_bsontype",{value:"Double"});var st=function(){function t(e){if(!(this instanceof t))return new t(e);e instanceof Number&&(e=e.valueOf()),this.value=0|+e}return t.prototype.valueOf=function(){return this.value},t.prototype.toString=function(t){return this.value.toString(t)},t.prototype.toJSON=function(){return this.value},t.prototype.toExtendedJSON=function(t){return t&&(t.relaxed||t.legacy)?this.value:{$numberInt:this.value.toString()}},t.fromExtendedJSON=function(e,n){return n&&n.relaxed?parseInt(e.$numberInt,10):new t(e.$numberInt)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return"new Int32(".concat(this.valueOf(),")")},t}();Object.defineProperty(st.prototype,"_bsontype",{value:"Int32"});var at=function(){function t(){if(!(this instanceof t))return new t}return t.prototype.toExtendedJSON=function(){return{$maxKey:1}},t.fromExtendedJSON=function(){return new t},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return"new MaxKey()"},t}();Object.defineProperty(at.prototype,"_bsontype",{value:"MaxKey"});var ft=function(){function t(){if(!(this instanceof t))return new t}return t.prototype.toExtendedJSON=function(){return{$minKey:1}},t.fromExtendedJSON=function(){return new t},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return"new MinKey()"},t}();Object.defineProperty(ft.prototype,"_bsontype",{value:"MinKey"});var ct=new RegExp("^[0-9a-fA-F]{24}$"),ht=null,pt=Symbol("id"),lt=function(){function t(e){if(!(this instanceof t))return new t(e);var n;if("object"==typeof e&&e&&"id"in e){if("string"!=typeof e.id&&!ArrayBuffer.isView(e.id))throw new E("Argument passed in must have an id that is of type string or Buffer");n="toHexString"in e&&"function"==typeof e.toHexString?w.from(e.toHexString(),"hex"):e.id}else n=e;if(null==n||"number"==typeof n)this[pt]=t.generate("number"==typeof n?n:void 0);else if(ArrayBuffer.isView(n)&&12===n.byteLength)this[pt]=n instanceof w?n:L(n);else{if("string"!=typeof n)throw new E("Argument passed in does not match the accepted types");if(12===n.length){var r=w.from(n);if(12!==r.byteLength)throw new E("Argument passed in must be a string of 12 bytes");this[pt]=r}else{if(24!==n.length||!ct.test(n))throw new E("Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer");this[pt]=w.from(n,"hex")}}t.cacheHexString&&(this.__id=this.id.toString("hex"))}return Object.defineProperty(t.prototype,"id",{get:function(){return this[pt]},set:function(e){this[pt]=e,t.cacheHexString&&(this.__id=e.toString("hex"))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"generationTime",{get:function(){return this.id.readInt32BE(0)},set:function(t){this.id.writeUInt32BE(t,0)},enumerable:!1,configurable:!0}),t.prototype.toHexString=function(){if(t.cacheHexString&&this.__id)return this.__id;var e=this.id.toString("hex");return t.cacheHexString&&!this.__id&&(this.__id=e),e},t.getInc=function(){return t.index=(t.index+1)%16777215},t.generate=function(e){"number"!=typeof e&&(e=Math.floor(Date.now()/1e3));var n=t.getInc(),r=w.alloc(12);return r.writeUInt32BE(e,0),null===ht&&(ht=x(5)),r[4]=ht[0],r[5]=ht[1],r[6]=ht[2],r[7]=ht[3],r[8]=ht[4],r[11]=255&n,r[10]=n>>8&255,r[9]=n>>16&255,r},t.prototype.toString=function(t){return t?this.id.toString(t):this.toHexString()},t.prototype.toJSON=function(){return this.toHexString()},t.prototype.equals=function(e){if(null==e)return!1;if(e instanceof t)return this[pt][11]===e[pt][11]&&this[pt].equals(e[pt]);if("string"==typeof e&&t.isValid(e)&&12===e.length&&A(this.id))return e===w.prototype.toString.call(this.id,"latin1");if("string"==typeof e&&t.isValid(e)&&24===e.length)return e.toLowerCase()===this.toHexString();if("string"==typeof e&&t.isValid(e)&&12===e.length)return w.from(e).equals(this.id);if("object"==typeof e&&"toHexString"in e&&"function"==typeof e.toHexString){var n=e.toHexString(),r=this.toHexString().toLowerCase();return"string"==typeof n&&n.toLowerCase()===r}return!1},t.prototype.getTimestamp=function(){var t=new Date,e=this.id.readUInt32BE(0);return t.setTime(1e3*Math.floor(e)),t},t.createPk=function(){return new t},t.createFromTime=function(e){var n=w.from([0,0,0,0,0,0,0,0,0,0,0,0]);return n.writeUInt32BE(e,0),new t(n)},t.createFromHexString=function(e){if(void 0===e||null!=e&&24!==e.length)throw new E("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");return new t(w.from(e,"hex"))},t.isValid=function(e){if(null==e)return!1;try{return new t(e),!0}catch(t){return!1}},t.prototype.toExtendedJSON=function(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}},t.fromExtendedJSON=function(e){return new t(e.$oid)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return'new ObjectId("'.concat(this.toHexString(),'")')},t.index=Math.floor(16777215*Math.random()),t}();Object.defineProperty(lt.prototype,"generate",{value:P((function(t){return lt.generate(t)}),"Please use the static `ObjectId.generate(time)` instead")}),Object.defineProperty(lt.prototype,"getInc",{value:P((function(){return lt.getInc()}),"Please use the static `ObjectId.getInc()` instead")}),Object.defineProperty(lt.prototype,"get_inc",{value:P((function(){return lt.getInc()}),"Please use the static `ObjectId.getInc()` instead")}),Object.defineProperty(lt,"get_inc",{value:P((function(){return lt.getInc()}),"Please use the static `ObjectId.getInc()` instead")}),Object.defineProperty(lt.prototype,"_bsontype",{value:"ObjectID"});var dt=function(){function t(e,n){if(!(this instanceof t))return new t(e,n);if(this.pattern=e,this.options=(null!=n?n:"").split("").sort().join(""),-1!==this.pattern.indexOf("\0"))throw new _("BSON Regex patterns cannot contain null bytes, found: ".concat(JSON.stringify(this.pattern)));if(-1!==this.options.indexOf("\0"))throw new _("BSON Regex options cannot contain null bytes, found: ".concat(JSON.stringify(this.options)));for(var r=0;r<this.options.length;r++)if("i"!==this.options[r]&&"m"!==this.options[r]&&"x"!==this.options[r]&&"l"!==this.options[r]&&"s"!==this.options[r]&&"u"!==this.options[r])throw new _("The regular expression option [".concat(this.options[r],"] is not supported"))}return t.parseOptions=function(t){return t?t.split("").sort().join(""):""},t.prototype.toExtendedJSON=function(t){return(t=t||{}).legacy?{$regex:this.pattern,$options:this.options}:{$regularExpression:{pattern:this.pattern,options:this.options}}},t.fromExtendedJSON=function(e){if("$regex"in e){if("string"==typeof e.$regex)return new t(e.$regex,t.parseOptions(e.$options));if("BSONRegExp"===e.$regex._bsontype)return e}if("$regularExpression"in e)return new t(e.$regularExpression.pattern,t.parseOptions(e.$regularExpression.options));throw new E("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(e)))},t}();Object.defineProperty(dt.prototype,"_bsontype",{value:"BSONRegExp"});var yt=function(){function t(e){if(!(this instanceof t))return new t(e);this.value=e}return t.prototype.valueOf=function(){return this.value},t.prototype.toString=function(){return this.value},t.prototype.inspect=function(){return'new BSONSymbol("'.concat(this.value,'")')},t.prototype.toJSON=function(){return this.value},t.prototype.toExtendedJSON=function(){return{$symbol:this.value}},t.fromExtendedJSON=function(e){return new t(e.$symbol)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t}();Object.defineProperty(yt.prototype,"_bsontype",{value:"Symbol"});var gt=function(t){function e(n,r){var o=this;return o instanceof e?(o=Y.isLong(n)?t.call(this,n.low,n.high,!0)||this:j(n)&&void 0!==n.t&&void 0!==n.i?t.call(this,n.i,n.t,!0)||this:t.call(this,n,r,!0)||this,Object.defineProperty(o,"_bsontype",{value:"Timestamp",writable:!1,configurable:!1,enumerable:!1}),o):new e(n,r)}return v(e,t),e.prototype.toJSON=function(){return{$timestamp:this.toString()}},e.fromInt=function(t){return new e(Y.fromInt(t,!0))},e.fromNumber=function(t){return new e(Y.fromNumber(t,!0))},e.fromBits=function(t,n){return new e(t,n)},e.fromString=function(t,n){return new e(Y.fromString(t,!0,n))},e.prototype.toExtendedJSON=function(){return{$timestamp:{t:this.high>>>0,i:this.low>>>0}}},e.fromExtendedJSON=function(t){return new e(t.$timestamp)},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){return"new Timestamp({ t: ".concat(this.getHighBits(),", i: ").concat(this.getLowBits()," })")},e.MAX_VALUE=Y.MAX_UNSIGNED_VALUE,e}(Y);function mt(t){return j(t)&&Reflect.has(t,"_bsontype")&&"string"==typeof t._bsontype}var wt={$oid:lt,$binary:C,$uuid:C,$symbol:yt,$numberInt:st,$numberDecimal:it,$numberDouble:ut,$numberLong:Y,$minKey:ft,$maxKey:at,$regex:dt,$regularExpression:dt,$timestamp:gt};function bt(t){var e=t.toISOString();return 0!==t.getUTCMilliseconds()?e:e.slice(0,-5)+"Z"}function vt(t,e){if(("object"==typeof t||"function"==typeof t)&&null!==t){var n=e.seenObjects.findIndex((function(e){return e.obj===t}));if(-1!==n){var r=e.seenObjects.map((function(t){return t.propertyName})),o=r.slice(0,n).map((function(t){return"".concat(t," -> ")})).join(""),i=r[n],u=" -> "+r.slice(n+1,r.length-1).map((function(t){return"".concat(t," -> ")})).join(""),s=r[r.length-1],a=" ".repeat(o.length+i.length/2),f="-".repeat(u.length+(i.length+s.length)/2-1);throw new E("Converting circular structure to EJSON:\n"+" ".concat(o).concat(i).concat(u).concat(s,"\n")+" ".concat(a,"\\").concat(f,"/"))}e.seenObjects[e.seenObjects.length-1].obj=t}if(Array.isArray(t))return function(t,e){return t.map((function(t,n){e.seenObjects.push({propertyName:"index ".concat(n),obj:null});try{return vt(t,e)}finally{e.seenObjects.pop()}}))}(t,e);if(void 0===t)return null;if(t instanceof Date||B(t)){var c=t.getTime(),h=c>-1&&c<2534023188e5;return e.legacy?e.relaxed&&h?{$date:t.getTime()}:{$date:bt(t)}:e.relaxed&&h?{$date:bt(t)}:{$date:{$numberLong:t.getTime().toString()}}}if(!("number"!=typeof t||e.relaxed&&isFinite(t))){if(Math.floor(t)===t){var p=t>=-0x8000000000000000&&t<=0x8000000000000000;if(t>=-2147483648&&t<=2147483647)return{$numberInt:t.toString()};if(p)return{$numberLong:t.toString()}}return{$numberDouble:t.toString()}}if(t instanceof RegExp||T(t)){var l=t.flags;if(void 0===l){var d=t.toString().match(/[gimuy]*$/);d&&(l=d[0])}return new dt(t.source,l).toExtendedJSON(e)}return null!=t&&"object"==typeof t?function(t,e){if(null==t||"object"!=typeof t)throw new _("not an object instance");var n=t._bsontype;if(void 0===n){var r={};for(var o in t){e.seenObjects.push({propertyName:o,obj:null});try{var i=vt(t[o],e);"__proto__"===o?Object.defineProperty(r,o,{value:i,writable:!0,enumerable:!0,configurable:!0}):r[o]=i}finally{e.seenObjects.pop()}}return r}if(mt(t)){var u=t;if("function"!=typeof u.toExtendedJSON){var s=Et[t._bsontype];if(!s)throw new E("Unrecognized or invalid _bsontype: "+t._bsontype);u=s(u)}return"Code"===n&&u.scope?u=new J(u.code,vt(u.scope,e)):"DBRef"===n&&u.oid&&(u=new V(vt(u.collection,e),vt(u.oid,e),vt(u.db,e),vt(u.fields,e))),u.toExtendedJSON(e)}throw new _("_bsontype must be a string, but was: "+typeof n)}(t,e):t}var _t,Et={Binary:function(t){return new C(t.value(),t.sub_type)},Code:function(t){return new J(t.code,t.scope)},DBRef:function(t){return new V(t.collection||t.namespace,t.oid,t.db,t.fields)},Decimal128:function(t){return new it(t.bytes)},Double:function(t){return new ut(t.value)},Int32:function(t){return new st(t.value)},Long:function(t){return Y.fromBits(null!=t.low?t.low:t.low_,null!=t.low?t.high:t.high_,null!=t.low?t.unsigned:t.unsigned_)},MaxKey:function(){return new at},MinKey:function(){return new ft},ObjectID:function(t){return new lt(t)},ObjectId:function(t){return new lt(t)},BSONRegExp:function(t){return new dt(t.pattern,t.options)},Symbol:function(t){return new yt(t.value)},Timestamp:function(t){return gt.fromBits(t.low,t.high)}};!function(t){function e(t,e){var n=Object.assign({},{relaxed:!0,legacy:!1},e);return"boolean"==typeof n.relaxed&&(n.strict=!n.relaxed),"boolean"==typeof n.strict&&(n.relaxed=!n.strict),JSON.parse(t,(function(t,e){if(-1!==t.indexOf("\0"))throw new _("BSON Document field names cannot contain null bytes, found: ".concat(JSON.stringify(t)));return function t(e,n){if(void 0===n&&(n={}),"number"==typeof e){if(n.relaxed||n.legacy)return e;if(Math.floor(e)===e){if(e>=-2147483648&&e<=2147483647)return new st(e);if(e>=-0x8000000000000000&&e<=0x8000000000000000)return Y.fromNumber(e)}return new ut(e)}if(null==e||"object"!=typeof e)return e;if(e.$undefined)return null;for(var r=Object.keys(e).filter((function(t){return t.startsWith("$")&&null!=e[t]})),o=0;o<r.length;o++){var i=wt[r[o]];if(i)return i.fromExtendedJSON(e,n)}if(null!=e.$date){var u=e.$date,s=new Date;return n.legacy?"number"==typeof u?s.setTime(u):"string"==typeof u&&s.setTime(Date.parse(u)):"string"==typeof u?s.setTime(Date.parse(u)):Y.isLong(u)?s.setTime(u.toNumber()):"number"==typeof u&&n.relaxed&&s.setTime(u),s}if(null!=e.$code){var a=Object.assign({},e);return e.$scope&&(a.$scope=t(e.$scope)),J.fromExtendedJSON(e)}if(F(e)||e.$dbPointer){var f=e.$ref?e:e.$dbPointer;if(f instanceof V)return f;var c=Object.keys(f).filter((function(t){return t.startsWith("$")})),h=!0;if(c.forEach((function(t){-1===["$ref","$id","$db"].indexOf(t)&&(h=!1)})),h)return V.fromExtendedJSON(f)}return e}(e,n)}))}function n(t,e,n,r){null!=n&&"object"==typeof n&&(r=n,n=0),null==e||"object"!=typeof e||Array.isArray(e)||(r=e,e=void 0,n=0);var o=vt(t,Object.assign({relaxed:!0,legacy:!1},r,{seenObjects:[{propertyName:"(root)",obj:null}]}));return JSON.stringify(o,e,n)}t.parse=e,t.stringify=n,t.serialize=function(t,e){return e=e||{},JSON.parse(n(t,e))},t.deserialize=function(t,n){return n=n||{},e(JSON.stringify(t),n)}}(_t||(_t={}));var Ot=S();Ot.Map?Ot.Map:function(){function t(t){void 0===t&&(t=[]),this._keys=[],this._values={};for(var e=0;e<t.length;e++)if(null!=t[e]){var n=t[e],r=n[0],o=n[1];this._keys.push(r),this._values[r]={v:o,i:this._keys.length-1}}}t.prototype.clear=function(){this._keys=[],this._values={}},t.prototype.delete=function(t){var e=this._values[t];return null!=e&&(delete this._values[t],this._keys.splice(e.i,1),!0)},t.prototype.entries=function(){var t=this,e=0;return{next:function(){var n=t._keys[e++];return{value:void 0!==n?[n,t._values[n].v]:void 0,done:void 0===n}}}},t.prototype.forEach=function(t,e){e=e||this;for(var n=0;n<this._keys.length;n++){var r=this._keys[n];t.call(e,this._values[r].v,r,e)}},t.prototype.get=function(t){return this._values[t]?this._values[t].v:void 0},t.prototype.has=function(t){return null!=this._values[t]},t.prototype.keys=function(){var t=this,e=0;return{next:function(){var n=t._keys[e++];return{value:void 0!==n?n:void 0,done:void 0===n}}}},t.prototype.set=function(t,e){return this._values[t]?(this._values[t].v=e,this):(this._keys.push(t),this._values[t]={v:e,i:this._keys.length-1},this)},t.prototype.values=function(){var t=this,e=0;return{next:function(){var n=t._keys[e++];return{value:void 0!==n?t._values[n].v:void 0,done:void 0===n}}}},Object.defineProperty(t.prototype,"size",{get:function(){return this._keys.length},enumerable:!1,configurable:!0})}();Y.fromNumber(D),Y.fromNumber(q);new Set(["$db","$ref","$id","$clusterTime"]);var St=new Uint8Array(8);new DataView(St.buffer,St.byteOffset,St.byteLength);w.alloc(17825792)}).call(this,n(2))},function(t,e,n){"use strict";var r=this&&this.__assign||function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0}),e.registerDatabase=void 0;var o=n(3);var i={name:"database",entity:{database:function(t){var e=this.platform,n=e.adapter,i=e.runtime;return o.Db.reqClass=this.request.constructor,o.Db.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},o.Db.runtime=i,this.wsClientClass&&(o.Db.wsClass=n.wsClass,o.Db.wsClientClass=this.wsClientClass),o.Db.ws||(o.Db.ws=null),new o.Db(r(r(r({},this.config),{_fromApp:this}),t))}}};try{cloudbase.registerComponent(i)}catch(t){}e.registerDatabase=function(t){try{t.registerComponent(i)}catch(t){console.warn(t)}}},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){"use strict";n.r(e),n.d(e,"Query",(function(){return Vt})),n.d(e,"CollectionReference",(function(){return Qt})),n.d(e,"DocumentReference",(function(){return Ct})),n.d(e,"Db",(function(){return me}));var r,o,i={};n.r(i),n.d(i,"Point",(function(){return K})),n.d(i,"LineString",(function(){return et})),n.d(i,"Polygon",(function(){return rt})),n.d(i,"MultiPoint",(function(){return it})),n.d(i,"MultiLineString",(function(){return st})),n.d(i,"MultiPolygon",(function(){return ft})),function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined"}(o||(o={}));var u,s="Number",a="Object",f="Array",c="GeoPoint",h="GeoLineString",p="GeoPolygon",l="GeoMultiPoint",d="GeoMultiLineString",y="GeoMultiPolygon",g="Date",m="ServerDate",w="BsonDate",b=["desc","asc"],v=["<","<=","==",">=",">"];!function(t){t.lt="<",t.gt=">",t.lte="<=",t.gte=">=",t.eq="=="}(u||(u={}));var _;(r={})[u.eq]="$eq",r[u.lt]="$lt",r[u.lte]="$lte",r[u.gt]="$gt",r[u.gte]="$gte";!function(t){t.WHERE="WHERE",t.DOC="DOC"}(_||(_={}));var E,O=(E=function(t,e){return(E=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}E(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),S=[],N={},x=function(t){function e(e,n){if(n!==N)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=S.length;n<r;n++)if(S[n].target===t)return S[n].instance;var o=new e(t,N);return S.push({target:t,instance:o}),o},e}((function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})})),I=x,A=I.for("UNSET_FIELD_NAME"),T=I.for("UPDATE_COMMAND"),B=I.for("QUERY_COMMAND"),j=I.for("LOGIC_COMMAND"),P=I.for("GEO_POINT"),L=I.for("SYMBOL_GEO_LINE_STRING"),U=I.for("SYMBOL_GEO_POLYGON"),$=I.for("SYMBOL_GEO_MULTI_POINT"),R=I.for("SYMBOL_GEO_MULTI_LINE_STRING"),M=I.for("SYMBOL_GEO_MULTI_POLYGON"),D=I.for("SERVER_DATE"),q=I.for("REGEXP"),C=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 D},enumerable:!0,configurable:!0}),t.prototype.parse=function(){return{$date:{offset:this.offset}}},t}();function k(t){return new C(t)}var J,F=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.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 u},V=function(){function t(){}return t.formatResDocumentData=function(e){return e.map((function(e){return t.formatField(e)}))},t.formatField=function(e){var n=Object.keys(e),r={};return Array.isArray(e)&&(r=[]),n.forEach((function(n){var o,i=e[n];switch(t.whichType(i)){case c:o=new K(i.coordinates[0],i.coordinates[1]);break;case h:o=new et(i.coordinates.map((function(t){return new K(t[0],t[1])})));break;case p:o=new rt(i.coordinates.map((function(t){return new et(t.map((function(t){var e=F(t,2),n=e[0],r=e[1];return new K(n,r)})))})));break;case l:o=new it(i.coordinates.map((function(t){return new K(t[0],t[1])})));break;case d:o=new st(i.coordinates.map((function(t){return new et(t.map((function(t){var e=F(t,2),n=e[0],r=e[1];return new K(n,r)})))})));break;case y:o=new ft(i.coordinates.map((function(t){return new rt(t.map((function(t){return new et(t.map((function(t){var e=F(t,2),n=e[0],r=e[1];return new K(n,r)})))})))})));break;case g:o=new Date(1e3*i.$timestamp);break;case a:case f:o=t.formatField(i);break;case m:o=new Date(i.$date);break;default:o=i}Array.isArray(r)?r.push(o):r[n]=o})),r},t.whichType=function(t){var e=Object.prototype.toString.call(t).slice(8,-1);if(e===g)return w;if(e===a){if(t instanceof K)return c;if(t instanceof Date)return g;if(t instanceof C)return m;t.$timestamp?e=g:t.$date?e=m:K.validate(t)?e=c:et.validate(t)?e=h:rt.validate(t)?e=p:it.validate(t)?e=l:st.validate(t)?e=d:ft.validate(t)&&(e=y)}return e},t.generateDocId=function(){for(var t="ABCDEFabcdef0123456789",e="",n=0;n<24;n++)e+=t.charAt(Math.floor(Math.random()*t.length));return e},t}(),H=function(){function t(){}return t.isGeopoint=function(t,e){if(V.whichType(e)!==s)throw new Error("Geo Point must be number type");var n=Math.abs(e);if("latitude"===t&&n>90)throw new Error("latitude should be a number ranges from -90 to 90");if("longitude"===t&&n>180)throw new Error("longitude should be a number ranges from -180 to 180");return!0},t.isInteger=function(t,e){if(!Number.isInteger(e))throw new Error(t+o.IntergerError);return!0},t.isFieldOrder=function(t){if(-1===b.indexOf(t))throw new Error(o.DirectionError);return!0},t.isFieldPath=function(t){if(!/^[a-zA-Z0-9-_\.]/.test(t))throw new Error;return!0},t.isOperator=function(t){if(-1===v.indexOf(t))throw new Error(o.OpStrError);return!0},t.isCollName=function(t){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(t))throw new Error(o.CollNameError);return!0},t.isDocID=function(t){if(!/^([a-fA-F0-9]){24}$/.test(t))throw new Error(o.DocIDError);return!0},t}(),G=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},Z=function(t){return"object"===G(t)},Y=function(t){return"number"===G(t)},W=function(t){return Array.isArray(t)},Q=function(t){return"date"===G(t)},z=function(t){return"regexp"===G(t)},X=function(t){return t&&t._internalType instanceof x},K=function(){function t(t,e){H.isGeopoint("longitude",t),H.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"["+this.longitude+","+this.latitude+"]"},t.validate=function(t){return"Point"===t.type&&W(t.coordinates)&&H.isGeopoint("longitude",t.coordinates[0])&&H.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return P},enumerable:!0,configurable:!0}),t}(),tt=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.")},et=function(){function t(t){if(!W(t))throw new TypeError('"points" must be of type Point[]. Received type '+typeof t);if(t.length<2)throw new Error('"points" must contain 2 points at least');t.forEach((function(t){if(!(t instanceof K))throw new TypeError('"points" must be of type Point[]. Received type '+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||!W(t.coordinates))return!1;try{for(var r=tt(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!Y(i[0])||!Y(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},t.isClosed=function(t){var e=t.points[0],n=t.points[t.points.length-1];if(e.latitude===n.latitude&&e.longitude===n.longitude)return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return L},enumerable:!0,configurable:!0}),t}(),nt=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.")},rt=function(){function t(t){if(!W(t))throw new TypeError('"lines" must be of type LineString[]. Received type '+typeof t);if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach((function(t){if(!(t instanceof et))throw new TypeError('"lines" must be of type LineString[]. Received type '+typeof t+"[]");if(!et.isClosed(t))throw new Error("LineString "+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||!W(t.coordinates))return!1;try{for(var i=nt(t.coordinates),u=i.next();!u.done;u=i.next()){var s=u.value;if(!this.isCloseLineString(s))return!1;try{for(var a=(r=void 0,nt(s)),f=a.next();!f.done;f=a.next()){var c=f.value;if(!Y(c[0])||!Y(c[1]))return!1}}catch(t){r={error:t}}finally{try{f&&!f.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{u&&!u.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 M},enumerable:!0,configurable:!0}),t}(),ot=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},it=function(){function t(t){if(!W(t))throw new TypeError('"points" must be of type Point[]. Received type '+typeof t);if(0===t.length)throw new Error('"points" must contain 1 point at least');t.forEach((function(t){if(!(t instanceof K))throw new TypeError('"points" must be of type Point[]. Received type '+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||!W(t.coordinates))return!1;try{for(var r=ot(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!Y(i[0])||!Y(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 $},enumerable:!0,configurable:!0}),t}(),ut=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.")},st=function(){function t(t){if(!W(t))throw new TypeError('"lines" must be of type LineString[]. Received type '+typeof t);if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach((function(t){if(!(t instanceof et))throw new TypeError('"lines" must be of type LineString[]. Received type '+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||!W(t.coordinates))return!1;try{for(var i=ut(t.coordinates),u=i.next();!u.done;u=i.next()){var s=u.value;try{for(var a=(r=void 0,ut(s)),f=a.next();!f.done;f=a.next()){var c=f.value;if(!Y(c[0])||!Y(c[1]))return!1}}catch(t){r={error:t}}finally{try{f&&!f.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{u&&!u.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:!0,configurable:!0}),t}(),at=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.")},ft=function(){function t(t){var e,n;if(!W(t))throw new TypeError('"polygons" must be of type Polygon[]. Received type '+typeof t);if(0===t.length)throw new Error("MultiPolygon must contain 1 polygon at least");try{for(var r=at(t),o=r.next();!o.done;o=r.next()){var i=o.value;if(!(i instanceof rt))throw new TypeError('"polygon" must be of type Polygon[]. Received type '+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,u;if("MultiPolygon"!==t.type||!W(t.coordinates))return!1;try{for(var s=at(t.coordinates),a=s.next();!a.done;a=s.next()){var f=a.value;try{for(var c=(r=void 0,at(f)),h=c.next();!h.done;h=c.next()){var p=h.value;try{for(var l=(i=void 0,at(p)),d=l.next();!d.done;d=l.next()){var y=d.value;if(!Y(y[0])||!Y(y[1]))return!1}}catch(t){i={error:t}}finally{try{d&&!d.done&&(u=l.return)&&u.call(l)}finally{if(i)throw i.error}}}}catch(t){r={error:t}}finally{try{h&&!h.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return U},enumerable:!0,configurable:!0}),t}(),ct=function(){var t;if(!Promise){(t=function(){}).promise={};var e=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(t.promise,"then",{get:e}),Object.defineProperty(t.promise,"catch",{get:e}),t}var n=new Promise((function(e,n){t=function(t,r){return t?n(t):e(r)}}));return t.promise=n,t};!function(t){t.SET="set",t.REMOVE="remove",t.INC="inc",t.MUL="mul",t.PUSH="push",t.PULL="pull",t.PULL_ALL="pullAll",t.POP="pop",t.SHIFT="shift",t.UNSHIFT="unshift",t.ADD_TO_SET="addToSet",t.BIT="bit",t.RENAME="rename",t.MAX="max",t.MIN="min"}(J||(J={}));var ht=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||A}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function pt(t){return t&&t instanceof ht&&t._internalType===T}var lt;!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(lt||(lt={}));var dt=function(){function t(t,e,n){if(this._internalType=j,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||A,this.fieldName!==A)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,o=e.length;r<o;r++){(yt(i=e[r])||bt(i))&&(e[r]=i._setFieldName(this.fieldName))}}else{var i;(yt(i=e)||bt(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(lt.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(lt.OR,r,this.fieldName)},t}();function yt(t){return t&&t instanceof dt&&t._internalType===j}var gt,mt=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)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){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"}(gt||(gt={}));var wt=function(t){function e(e,n,r){var o=t.call(this,e,n,r)||this;return o.operator=e,o._internalType=B,o}return mt(e,t),e.prototype.toJSON=function(){var t,e;switch(this.operator){case gt.IN:case gt.NIN:return(t={})["$"+this.operator]=this.operands,t;default:return(e={})["$"+this.operator]=this.operands[0],e}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(gt.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(gt.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(gt.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(gt.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(gt.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(gt.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(gt.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(gt.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof K))throw new TypeError('"geometry" must be of type Point. Received type '+typeof t.geometry);if(void 0!==t.maxDistance&&!Y(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '+typeof t.maxDistance);if(void 0!==t.minDistance&&!Y(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '+typeof t.minDistance);var n=new e(gt.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof ft||t.geometry instanceof rt))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '+typeof t.geometry);var n=new e(gt.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof K||t.geometry instanceof et||t.geometry instanceof rt||t.geometry instanceof it||t.geometry instanceof st||t.geometry instanceof ft))throw new TypeError('"geometry" must be of type Point, LineString, Polygon, MultiPoint, MultiLineString or MultiPolygon. Received type '+typeof t.geometry);var n=new e(gt.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(dt);function bt(t){return t&&t instanceof wt&&t._internalType===B}function vt(t){return bt(t)}var _t={};for(var Et in gt)_t[Et]="$"+Et;for(var Et in lt)_t[Et]="$"+Et;for(var Et in J)_t[Et]="$"+Et;function Ot(t){return _t[t]||"$"+t}_t[gt.NEQ]="$ne",_t[J.REMOVE]="$unset",_t[J.SHIFT]="$pop",_t[J.UNSHIFT]="$push";var St=function(){return(St=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},Nt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.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 u},xt=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(Nt(arguments[e]));return t};function It(t){return function t(e,n){if(!X(e)){if(Q(e))return{$date:+e};if(z(e))return{$regex:e.source,$options:e.flags};if(W(e))return e.map((function(e){if(n.indexOf(e)>-1)throw new Error("Cannot convert circular structure to JSON");return t(e,xt(n,[e]))}));if(Z(e)){var r=St({},e);for(var o in r){if(n.indexOf(r[o])>-1)throw new Error("Cannot convert circular structure to JSON");r[o]=t(r[o],xt(n,[r[o]]))}return r}return e}switch(e._internalType){case P:return e.toJSON();case D:case q:return e.parse();default:return e.toJSON?e.toJSON():e}}(t,[t])}var At=function(){return(At=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}).apply(this,arguments)},Tt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.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 u},Bt=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(Tt(arguments[e]));return t};function jt(t,e,n,r){var o=At({},t);for(var i in t)if(!/^\$/.test(i)){var u=t[i];if(u&&Z(u)&&!e(u)){if(r.indexOf(u)>-1)throw new Error("Cannot convert circular structure to JSON");var s=jt(u,e,Bt(n,[i]),Bt(r,[u]));o[i]=s;var a=!1;for(var f in s)/^\$/.test(f)?a=!0:(o[i+"."+f]=s[f],delete o[i][f]);a||delete o[i]}}return o}function Pt(t){return jt(t,Ut,[],[t])}function Lt(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?W(t[r])?t[r].push(e[r]):Z(t[r])?Z(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is "+G(e)+", can only overwrite",e,n),t[r]=e[r]):(console.warn("to-merge query is of type "+G(t)+", can only overwrite",t,e,n),t[r]=e[r]):t[r]=e[r]}function Ut(t){return X(t)||Q(t)||z(t)}function $t(t){return It(t)}var Rt=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.prototype.encodeUpdate=function(t){return pt(t)?this.encodeUpdateCommand(t):"object"===G(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===A)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case J.PUSH:case J.PULL:case J.PULL_ALL:case J.POP:case J.SHIFT:case J.UNSHIFT:case J.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,o,i=Ot(t.operator);switch(t.operator){case J.REMOVE:return(e={})[i]=((n={})[t.fieldName]="",n),e;default:return(r={})[i]=((o={})[t.fieldName]=t.operands[0],o),r}},t.prototype.encodeArrayUpdateCommand=function(t){var e,n,r,o,i,u,s,a,f,c,h=Ot(t.operator);switch(t.operator){case J.PUSH:var p=void 0;return p=W(t.operands)?{$each:t.operands.map($t)}:t.operands,(e={})[h]=((n={})[t.fieldName]=p,n),e;case J.UNSHIFT:p={$each:t.operands.map($t),$position:0};return(r={})[h]=((o={})[t.fieldName]=p,o),r;case J.POP:return(i={})[h]=((u={})[t.fieldName]=1,u),i;case J.SHIFT:return(s={})[h]=((a={})[t.fieldName]=-1,a),s;default:return(f={})[h]=((c={})[t.fieldName]=$t(t.operands),c),f}},t.prototype.encodeUpdateObject=function(t){var e=Pt(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(pt(r)){e[n]=r._setFieldName(n),Lt(e,this.encodeUpdateCommand(e[n]),n)}else{e[n]=r=$t(r);var o=new ht(J.SET,[r],n);Lt(e,this.encodeUpdateCommand(o),n)}}return e},t}(),Mt={};function Dt(t){if(!me.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return Mt[e]||(Mt[e]=new me.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:new me.reqClass(t.config)}}})),Mt[e]}var qt=function(){return(qt=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}).apply(this,arguments)},Ct=function(){function t(t,e,n,r){var o=this;void 0===r&&(r={}),this.watch=function(t){return Dt(o._db).watch(qt(qt({},t),{envId:o._db.config.env,collectionName:o._coll,query:JSON.stringify({_id:o.id})}))},this._db=t,this._coll=e,this.id=n,this.request=new me.reqClass(this._db.config),this.projection=r}return t.prototype.create=function(t,e){e=e||ct();var n={collectionName:this._coll,data:It(t)};return this.id&&(n._id=this.id),this.request.send("database.addDocument",n).then((function(t){t.code?e(0,t):e(0,{id:t.data._id,requestId:t.requestId})})).catch((function(t){e(t)})),e.promise},t.prototype.set=function(t,e){if(e=e||ct(),!this.id)return Promise.resolve({code:"INVALID_PARAM",message:"docId不能为空"});if(!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n=!1,r=function(t){if("object"==typeof t)for(var e in t)t[e]instanceof ht?n=!0:"object"==typeof t[e]&&r(t[e])};if(r(t),n)return Promise.resolve({code:"DATABASE_REQUEST_FAILED",message:"update operator complicit"});var o={collectionName:this._coll,queryType:_.DOC,data:It(t),multi:!1,merge:!1,upsert:!0};return this.id&&(o.query={_id:this.id}),this.request.send("database.updateDocument",o).then((function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})})).catch((function(t){e(t)})),e.promise},t.prototype.update=function(t,e){if(e=e||ct(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={_id:this.id},r={collectionName:this._coll,data:Rt.encode(t),query:n,queryType:_.DOC,multi:!1,merge:!0,upsert:!1};return this.request.send("database.updateDocument",r).then((function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})})).catch((function(t){e(t)})),e.promise},t.prototype.remove=function(t){t=t||ct();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:_.DOC,multi:!1};return this.request.send("database.deleteDocument",n).then((function(e){e.code?t(0,e):t(0,{deleted:e.data.deleted,requestId:e.requestId})})).catch((function(e){t(e)})),t.promise},t.prototype.get=function(t){t=t||ct();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:_.DOC,multi:!1,projection:this.projection};return this.request.send("database.queryDocument",n).then((function(e){if(e.code)t(0,e);else{var n=V.formatResDocumentData(e.data.list);t(0,{data:n,requestId:e.requestId,total:e.TotalCount,limit:e.Limit,offset:e.Offset})}})).catch((function(e){t(e)})),t.promise},t.prototype.field=function(e){for(var n in e)e[n]?e[n]=1:e[n]=0;return new t(this._db,this._coll,this.id,e)},t}(),kt=function(){function t(){}return t.encode=function(t){return(new Jt).encodeQuery(t)},t}(),Jt=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n;return Ut(t)?yt(t)?this.encodeLogicCommand(t):bt(t)?this.encodeQueryCommand(t):((n={})[e]=this.encodeQueryObject(t),n):Z(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regex:t.source,$options:t.flags}},t.prototype.encodeLogicCommand=function(t){var e,n,r,o,i,u,s,a=this;switch(t.operator){case lt.NOR:case lt.AND:case lt.OR:var f=Ot(t.operator),c=t.operands.map((function(e){return a.encodeQuery(e,t.fieldName)}));return(e={})[f]=c,e;case lt.NOT:f=Ot(t.operator);var h=t.operands[0];if(z(h))return(n={})[t.fieldName]=((r={})[f]=this.encodeRegExp(h),r),n;c=this.encodeQuery(h)[t.fieldName];return(o={})[t.fieldName]=((i={})[f]=c,i),o;default:f=Ot(t.operator);if(1===t.operands.length){var p=this.encodeQuery(t.operands[0]);return(u={})[f]=p,u}c=t.operands.map(this.encodeQuery.bind(this));return(s={})[f]=c,s}},t.prototype.encodeQueryCommand=function(t){return vt(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,o,i,u,s,a,f;if(t.fieldName===A)throw new Error("Cannot encode a comparison command with unset field name");var c=Ot(t.operator);switch(t.operator){case gt.EQ:case gt.NEQ:case gt.LT:case gt.LTE:case gt.GT:case gt.GTE:case gt.ELEM_MATCH:case gt.EXISTS:case gt.SIZE:case gt.MOD:return(e={})[t.fieldName]=((n={})[c]=$t(t.operands[0]),n),e;case gt.IN:case gt.NIN:case gt.ALL:return(r={})[t.fieldName]=((o={})[c]=$t(t.operands),o),r;case gt.GEO_NEAR:var h=t.operands[0];return(i={})[t.fieldName]={$nearSphere:{$geometry:h.geometry.toJSON(),$maxDistance:h.maxDistance,$minDistance:h.minDistance}},i;case gt.GEO_WITHIN:h=t.operands[0];return(u={})[t.fieldName]={$geoWithin:{$geometry:h.geometry.toJSON()}},u;case gt.GEO_INTERSECTS:h=t.operands[0];return(s={})[t.fieldName]={$geoIntersects:{$geometry:h.geometry.toJSON()}},s;default:return(a={})[t.fieldName]=((f={})[c]=$t(t.operands[0]),f),a}},t.prototype.encodeQueryObject=function(t){var e=Pt(t);for(var n in e){var r=e[n];if(yt(r)){e[n]=r._setFieldName(n);var o=this.encodeLogicCommand(e[n]);this.mergeConditionAfterEncode(e,o,n)}else if(vt(r)){e[n]=r._setFieldName(n);o=this.encodeComparisonCommand(e[n]);this.mergeConditionAfterEncode(e,o,n)}else Ut(r)&&(e[n]=$t(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?W(t[r])?t[r]=t[r].concat(e[r]):Z(t[r])?Z(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is "+G(e)+", can only overwrite",e,n),t[r]=e[r]):(console.warn("to-merge query is of type "+G(t)+", can only overwrite",t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),Ft=function(){return(Ft=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}).apply(this,arguments)},Vt=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){return Dt(i._db).watch(Ft(Ft({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify(i._fieldFilters||{}),limit:i._queryOptions.limit,orderBy:i._fieldOrders?i._fieldOrders.reduce((function(t,e){return t[e.field]=e.direction,t}),{}):void 0}))},this._db=t,this._coll=e,this._fieldFilters=n,this._fieldOrders=r||[],this._queryOptions=o||{},this._request=new me.reqClass(this._db.config)}return t.prototype.get=function(t){t=t||ct();var e=[];this._fieldOrders&&this._fieldOrders.forEach((function(t){e.push(t)}));var n={collectionName:this._coll,queryType:_.WHERE};return this._fieldFilters&&(n.query=this._fieldFilters),e.length>0&&(n.order=e),this._queryOptions.offset&&(n.offset=this._queryOptions.offset),this._queryOptions.limit?n.limit=this._queryOptions.limit<1e3?this._queryOptions.limit:1e3:n.limit=100,this._queryOptions.projection&&(n.projection=this._queryOptions.projection),this._request.send("database.queryDocument",n).then((function(e){if(e.code)t(0,e);else{var n={data:V.formatResDocumentData(e.data.list),requestId:e.requestId};e.TotalCount&&(n.total=e.TotalCount),e.Limit&&(n.limit=e.Limit),e.Offset&&(n.offset=e.Offset),t(0,n)}})).catch((function(e){t(e)})),t.promise},t.prototype.count=function(t){t=t||ct();var e={collectionName:this._coll,queryType:_.WHERE};return this._fieldFilters&&(e.query=this._fieldFilters),this._request.send("database.countDocument",e).then((function(e){e.code?t(0,e):t(0,{requestId:e.requestId,total:e.data.total})})).catch((function(e){t(e)})),t.promise},t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(o.QueryParamTypeError);var n=Object.keys(e),r=n.some((function(t){return void 0!==e[t]}));if(n.length&&!r)throw Error(o.QueryParamValueError);return new t(this._db,this._coll,kt.encode(e),this._fieldOrders,this._queryOptions)},t.prototype.orderBy=function(e,n){H.isFieldPath(e),H.isFieldOrder(n);var r={field:e,direction:n},o=this._fieldOrders.concat(r);return new t(this._db,this._coll,this._fieldFilters,o,this._queryOptions)},t.prototype.limit=function(e){H.isInteger("limit",e);var n=Ft({},this._queryOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.skip=function(e){H.isInteger("offset",e);var n=Ft({},this._queryOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.update=function(t,e){if(e=e||ct(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={collectionName:this._coll,query:this._fieldFilters,queryType:_.WHERE,multi:!0,merge:!0,upsert:!1,data:Rt.encode(t)};return this._request.send("database.updateDocument",n).then((function(t){t.code?e(0,t):e(0,{requestId:t.requestId,updated:t.data.updated,upsertId:t.data.upsert_id})})).catch((function(t){e(t)})),e.promise},t.prototype.field=function(e){for(var n in e)e[n]?"object"!=typeof e[n]&&(e[n]=1):e[n]=0;var r=Ft({},this._queryOptions);return r.projection=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,r)},t.prototype.remove=function(t){t=t||ct(),Object.keys(this._queryOptions).length>0&&console.warn("`offset`, `limit` and `projection` are not supported in remove() operation"),this._fieldOrders.length>0&&console.warn("`orderBy` is not supported in remove() operation");var e={collectionName:this._coll,query:kt.encode(this._fieldFilters),queryType:_.WHERE,multi:!0};return this._request.send("database.deleteDocument",e).then((function(e){e.code?t(0,e):t(0,{requestId:e.requestId,deleted:e.data.deleted})})).catch((function(e){t(e)})),t.promise},t}(),Ht=n(0),Gt=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function s(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,s)}a((r=r.apply(t,e||[])).next())}))},Zt=function(t,e){var n,r,o,i,u={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(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},Yt=function(){function t(t,e){this._stages=[],t&&e&&(this._db=t,this._request=new me.reqClass(this._db.config),this._collectionName=e)}return t.prototype.end=function(){return Gt(this,void 0,void 0,(function(){var t;return Zt(this,(function(e){switch(e.label){case 0:if(!this._collectionName||!this._db)throw new Error("Aggregation pipeline cannot send request");return[4,this._request.send("database.aggregate",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:JSON.parse(t.data.list).map(Ht.a.parse)}]:[2,t]}}))}))},t.prototype.unwrap=function(){return this._stages},t.prototype.done=function(){return this._stages.map((function(t){var e,n=t.stageKey,r=t.stageValue;return(e={})[n]=JSON.parse(r),e}))},t.prototype._pipe=function(t,e){return this._stages.push({stageKey:"$"+t,stageValue:JSON.stringify(e)}),this},t.prototype.addFields=function(t){return this._pipe("addFields",t)},t.prototype.bucket=function(t){return this._pipe("bucket",t)},t.prototype.bucketAuto=function(t){return this._pipe("bucketAuto",t)},t.prototype.count=function(t){return this._pipe("count",t)},t.prototype.geoNear=function(t){return t.query&&(t.query=kt.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new K(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",kt.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}(),Wt=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)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Qt=function(t){function e(e,n){return t.call(this,e,n)||this}return Wt(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!0,configurable:!0}),e.prototype.doc=function(t){if("string"!=typeof t&&"number"!=typeof t)throw new Error("docId必须为字符串或数字");return new Ct(this._db,this._coll,t)},e.prototype.add=function(t,e){return new Ct(this._db,this._coll,void 0).create(t,e)},e.prototype.aggregate=function(){return new Yt(this._db,this._coll)},e}(Vt),zt={eq:function(t){return new wt(gt.EQ,[t])},neq:function(t){return new wt(gt.NEQ,[t])},lt:function(t){return new wt(gt.LT,[t])},lte:function(t){return new wt(gt.LTE,[t])},gt:function(t){return new wt(gt.GT,[t])},gte:function(t){return new wt(gt.GTE,[t])},in:function(t){return new wt(gt.IN,t)},nin:function(t){return new wt(gt.NIN,t)},all:function(t){return new wt(gt.ALL,t)},elemMatch:function(t){return new wt(gt.ELEM_MATCH,[t])},exists:function(t){return new wt(gt.EXISTS,[t])},size:function(t){return new wt(gt.SIZE,[t])},mod:function(t){return new wt(gt.MOD,[t])},geoNear:function(t){return new wt(gt.GEO_NEAR,[t])},geoWithin:function(t){return new wt(gt.GEO_WITHIN,[t])},geoIntersects:function(t){return new wt(gt.GEO_INTERSECTS,[t])},and:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=W(arguments[0])?arguments[0]:Array.from(arguments);return new dt(lt.AND,n)},nor:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=W(arguments[0])?arguments[0]:Array.from(arguments);return new dt(lt.NOR,n)},or:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=W(arguments[0])?arguments[0]:Array.from(arguments);return new dt(lt.OR,n)},not:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=W(arguments[0])?arguments[0]:Array.from(arguments);return new dt(lt.NOT,n)},set:function(t){return new ht(J.SET,[t])},remove:function(){return new ht(J.REMOVE,[])},inc:function(t){return new ht(J.INC,[t])},mul:function(t){return new ht(J.MUL,[t])},push:function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(Z(e[0])&&e[0].hasOwnProperty("each")){var r=e[0];t={$each:r.each,$position:r.position,$sort:r.sort,$slice:r.slice}}else t=W(e[0])?e[0]:Array.from(e);return new ht(J.PUSH,t)},pull:function(t){return new ht(J.PULL,t)},pullAll:function(t){return new ht(J.PULL_ALL,t)},pop:function(){return new ht(J.POP,[])},shift:function(){return new ht(J.SHIFT,[])},unshift:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=W(arguments[0])?arguments[0]:Array.from(arguments);return new ht(J.UNSHIFT,n)},addToSet:function(t){return new ht(J.ADD_TO_SET,t)},rename:function(t){return new ht(J.RENAME,[t])},bit:function(t){return new ht(J.BIT,[t])},max:function(t){return new ht(J.MAX,[t])},min:function(t){return new ht(J.MIN,[t])},expr:function(t){return{$expr:t}},jsonSchema:function(t){return{$jsonSchema:t}},text:function(t){return"string"===G(t)?{$search:t.search}:{$search:t.search,$language:t.language,$caseSensitive:t.caseSensitive,$diacriticSensitive:t.diacriticSensitive}},aggregate:{pipeline:function(){return new Yt},abs:function(t){return new Xt("abs",t)},add:function(t){return new Xt("add",t)},ceil:function(t){return new Xt("ceil",t)},divide:function(t){return new Xt("divide",t)},exp:function(t){return new Xt("exp",t)},floor:function(t){return new Xt("floor",t)},ln:function(t){return new Xt("ln",t)},log:function(t){return new Xt("log",t)},log10:function(t){return new Xt("log10",t)},mod:function(t){return new Xt("mod",t)},multiply:function(t){return new Xt("multiply",t)},pow:function(t){return new Xt("pow",t)},sqrt:function(t){return new Xt("sqrt",t)},subtract:function(t){return new Xt("subtract",t)},trunc:function(t){return new Xt("trunc",t)},arrayElemAt:function(t){return new Xt("arrayElemAt",t)},arrayToObject:function(t){return new Xt("arrayToObject",t)},concatArrays:function(t){return new Xt("concatArrays",t)},filter:function(t){return new Xt("filter",t)},in:function(t){return new Xt("in",t)},indexOfArray:function(t){return new Xt("indexOfArray",t)},isArray:function(t){return new Xt("isArray",t)},map:function(t){return new Xt("map",t)},range:function(t){return new Xt("range",t)},reduce:function(t){return new Xt("reduce",t)},reverseArray:function(t){return new Xt("reverseArray",t)},size:function(t){return new Xt("size",t)},slice:function(t){return new Xt("slice",t)},zip:function(t){return new Xt("zip",t)},and:function(t){return new Xt("and",t)},not:function(t){return new Xt("not",t)},or:function(t){return new Xt("or",t)},cmp:function(t){return new Xt("cmp",t)},eq:function(t){return new Xt("eq",t)},gt:function(t){return new Xt("gt",t)},gte:function(t){return new Xt("gte",t)},lt:function(t){return new Xt("lt",t)},lte:function(t){return new Xt("lte",t)},neq:function(t){return new Xt("ne",t)},cond:function(t){return new Xt("cond",t)},ifNull:function(t){return new Xt("ifNull",t)},switch:function(t){return new Xt("switch",t)},dateFromParts:function(t){return new Xt("dateFromParts",t)},dateFromString:function(t){return new Xt("dateFromString",t)},dayOfMonth:function(t){return new Xt("dayOfMonth",t)},dayOfWeek:function(t){return new Xt("dayOfWeek",t)},dayOfYear:function(t){return new Xt("dayOfYear",t)},isoDayOfWeek:function(t){return new Xt("isoDayOfWeek",t)},isoWeek:function(t){return new Xt("isoWeek",t)},isoWeekYear:function(t){return new Xt("isoWeekYear",t)},millisecond:function(t){return new Xt("millisecond",t)},minute:function(t){return new Xt("minute",t)},month:function(t){return new Xt("month",t)},second:function(t){return new Xt("second",t)},hour:function(t){return new Xt("hour",t)},week:function(t){return new Xt("week",t)},year:function(t){return new Xt("year",t)},literal:function(t){return new Xt("literal",t)},mergeObjects:function(t){return new Xt("mergeObjects",t)},objectToArray:function(t){return new Xt("objectToArray",t)},allElementsTrue:function(t){return new Xt("allElementsTrue",t)},anyElementTrue:function(t){return new Xt("anyElementTrue",t)},setDifference:function(t){return new Xt("setDifference",t)},setEquals:function(t){return new Xt("setEquals",t)},setIntersection:function(t){return new Xt("setIntersection",t)},setIsSubset:function(t){return new Xt("setIsSubset",t)},setUnion:function(t){return new Xt("setUnion",t)},concat:function(t){return new Xt("concat",t)},dateToString:function(t){return new Xt("dateToString",t)},indexOfBytes:function(t){return new Xt("indexOfBytes",t)},indexOfCP:function(t){return new Xt("indexOfCP",t)},split:function(t){return new Xt("split",t)},strLenBytes:function(t){return new Xt("strLenBytes",t)},strLenCP:function(t){return new Xt("strLenCP",t)},strcasecmp:function(t){return new Xt("strcasecmp",t)},substr:function(t){return new Xt("substr",t)},substrBytes:function(t){return new Xt("substrBytes",t)},substrCP:function(t){return new Xt("substrCP",t)},toLower:function(t){return new Xt("toLower",t)},toUpper:function(t){return new Xt("toUpper",t)},meta:function(t){return new Xt("meta",t)},addToSet:function(t){return new Xt("addToSet",t)},avg:function(t){return new Xt("avg",t)},first:function(t){return new Xt("first",t)},last:function(t){return new Xt("last",t)},max:function(t){return new Xt("max",t)},min:function(t){return new Xt("min",t)},push:function(t){return new Xt("push",t)},stdDevPop:function(t){return new Xt("stdDevPop",t)},stdDevSamp:function(t){return new Xt("stdDevSamp",t)},sum:function(t){return new Xt("sum",t)},let:function(t){return new Xt("let",t)}},project:{slice:function(t){return new Kt("slice",t)},elemMatch:function(t){return new Kt("elemMatch",t)}}},Xt=function(t,e){this["$"+t]=e},Kt=function(t,e){this["$"+t]=e},te=function(){function t(t){var e=t.regexp,n=t.options;if(!e)throw new TypeError("regexp must be a string");this.$regex=e,this.$options=n}return t.prototype.parse=function(){return{$regex:this.$regex,$options:this.$options}},Object.defineProperty(t.prototype,"_internalType",{get:function(){return q},enumerable:!0,configurable:!0}),t}();function ee(t){return new te(t)}var ne={code:"INSERT_DOC_FAIL",message:"insert document failed"},re={code:"DATABASE_TRANSACTION_CONFLICT",message:"database transaction conflict"},oe=function(){return(oe=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},ie=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function s(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,s)}a((r=r.apply(t,e||[])).next())}))},ue=function(t,e){var n,r,o,i,u={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(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},se="database.updateDocInTransaction",ae=function(){function t(t,e,n){this._coll=e,this.id=n,this._transaction=t,this._request=this._transaction.getRequestMethod(),this._transactionId=this._transaction.getTransactionId()}return t.prototype.create=function(t){return ie(this,void 0,void 0,(function(){var e,n,r,o;return ue(this,(function(i){switch(i.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,data:Ht.a.stringify(It(t),{relaxed:!1})},this.id&&(e._id=this.id),[4,this._request.send("database.insertDocInTransaction",e)];case 1:if((n=i.sent()).code)throw n;if(r=Ht.a.parse(n.inserted),1==(o=Ht.a.parse(n.ok))&&1==r)return[2,oe(oe({},n),{ok:o,inserted:r})];throw new Error(ne.message)}}))}))},t.prototype.get=function(){return ie(this,void 0,void 0,(function(){var t,e;return ue(this,(function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.getInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,{data:"null"!==e.data?V.formatField(Ht.a.parse(e.data)):Ht.a.parse(e.data),requestId:e.requestId}]}}))}))},t.prototype.set=function(t){return ie(this,void 0,void 0,(function(){var e,n;return ue(this,(function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:Ht.a.stringify(It(t),{relaxed:!1}),upsert:!0},[4,this._request.send(se,e)];case 1:if((n=r.sent()).code)throw n;return[2,oe(oe({},n),{updated:Ht.a.parse(n.updated),upserted:n.upserted?JSON.parse(n.upserted):null})]}}))}))},t.prototype.update=function(t){return ie(this,void 0,void 0,(function(){var e,n;return ue(this,(function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:Ht.a.stringify(Rt.encode(t),{relaxed:!1})},[4,this._request.send(se,e)];case 1:if((n=r.sent()).code)throw n;return[2,oe(oe({},n),{updated:Ht.a.parse(n.updated)})]}}))}))},t.prototype.delete=function(){return ie(this,void 0,void 0,(function(){var t,e;return ue(this,(function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.deleteDocInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,oe(oe({},e),{deleted:Ht.a.parse(e.deleted)})]}}))}))},t}(),fe=function(t,e){this._coll=e,this._transaction=t},ce=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)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),he=function(t){function e(e,n){return t.call(this,e,n)||this}return ce(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!0,configurable:!0}),e.prototype.doc=function(t){if("string"!=typeof t&&"number"!=typeof t)throw new Error("docId必须为字符串或数字");return new ae(this._transaction,this._coll,t)},e.prototype.add=function(t){var e;return void 0!==t._id&&(e=t._id),new ae(this._transaction,this._coll,e).create(t)},e}(fe),pe=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function s(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,s)}a((r=r.apply(t,e||[])).next())}))},le=function(t,e){var n,r,o,i,u={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(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},de=function(){function t(t){this._db=t,this._request=new me.reqClass(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return t.prototype.init=function(){return pe(this,void 0,void 0,(function(){var t;return le(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 he(this,t)},t.prototype.getTransactionId=function(){return this._id},t.prototype.getRequestMethod=function(){return this._request},t.prototype.commit=function(){return pe(this,void 0,void 0,(function(){var t,e;return le(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 pe(this,void 0,void 0,(function(){var e,n;return le(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 ye(){return pe(this,void 0,void 0,(function(){var t;return le(this,(function(e){switch(e.label){case 0:return[4,(t=new de(this)).init()];case 1:return e.sent(),[2,t]}}))}))}function ge(t,e){return void 0===e&&(e=3),pe(this,void 0,void 0,(function(){var n,r,o,i,u=this;return le(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,10]),[4,(n=new de(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 pe(u,void 0,void 0,(function(){return le(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:return e.sent(),[3,4];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===re.code?[4,ge.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 me=function(){function t(t){this.config=t,this.Geo=i,this.serverDate=k,this.command=zt,this.RegExp=ee,this.startTransaction=ye,this.runTransaction=ge,this.logicCommand=dt,this.updateCommand=ht,this.queryCommand=wt}return t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new Qt(this,t)},t.prototype.createCollection=function(e){var n={collectionName:e};return new t.reqClass(this.config).send("database.addCollection",n)},t}()}])}));
17
+ var b=function(t,e){return(b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function v(t,e){function n(){this.constructor=t}b(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var _=function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return v(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return"BSONError"},enumerable:!1,configurable:!0}),e}(Error),E=function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return v(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return"BSONTypeError"},enumerable:!1,configurable:!0}),e}(TypeError);function O(t){return t&&t.Math==Math&&t}function S(){return O("object"==typeof globalThis&&globalThis)||O("object"==typeof window&&window)||O("object"==typeof self&&self)||O("object"==typeof t&&t)||Function("return this")()}var N=function(t){var e,n="object"==typeof(e=S()).navigator&&"ReactNative"===e.navigator.product?"BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.":"BSON: No cryptographic implementation for random bytes present, falling back to a less secure implementation.";console.warn(n);for(var r=w.alloc(t),o=0;o<t;++o)r[o]=Math.floor(256*Math.random());return r},x=function(){if("undefined"!=typeof window){var e=window.crypto||window.msCrypto;if(e&&e.getRandomValues)return function(t){return e.getRandomValues(w.alloc(t))}}return void 0!==t&&t.crypto&&t.crypto.getRandomValues?function(e){return t.crypto.getRandomValues(w.alloc(e))}:N}();function I(t){return["[object ArrayBuffer]","[object SharedArrayBuffer]"].includes(Object.prototype.toString.call(t))}function A(t){return"[object Uint8Array]"===Object.prototype.toString.call(t)}function T(t){return"[object RegExp]"===Object.prototype.toString.call(t)}function B(t){return j(t)&&"[object Date]"===Object.prototype.toString.call(t)}function j(t){return"object"==typeof t&&null!==t}function P(t,e){var n=!1;return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];return n||(console.warn(e),n=!0),t.apply(this,r)}}function L(t){if(ArrayBuffer.isView(t))return w.from(t.buffer,t.byteOffset,t.byteLength);if(I(t))return w.from(t);throw new E("Must use either Buffer or TypedArray")}var U=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15})$/i,$=function(t){return"string"==typeof t&&U.test(t)},R=function(t){if(!$(t))throw new E('UUID string representations must be a 32 or 36 character hex string (dashes excluded/included). Format: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" or "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".');var e=t.replace(/-/g,"");return w.from(e,"hex")},M=function(t,e){return void 0===e&&(e=!0),e?t.toString("hex",0,4)+"-"+t.toString("hex",4,6)+"-"+t.toString("hex",6,8)+"-"+t.toString("hex",8,10)+"-"+t.toString("hex",10,16):t.toString("hex")},D=(Math.pow(2,63),Math.pow(2,63),Math.pow(2,53)),q=-Math.pow(2,53),C=function(){function t(e,n){if(!(this instanceof t))return new t(e,n);if(!(null==e||"string"==typeof e||ArrayBuffer.isView(e)||e instanceof ArrayBuffer||Array.isArray(e)))throw new E("Binary can only be constructed from string, Buffer, TypedArray, or Array<number>");this.sub_type=null!=n?n:t.BSON_BINARY_SUBTYPE_DEFAULT,null==e?(this.buffer=w.alloc(t.BUFFER_SIZE),this.position=0):("string"==typeof e?this.buffer=w.from(e,"binary"):Array.isArray(e)?this.buffer=w.from(e):this.buffer=L(e),this.position=this.buffer.byteLength)}return t.prototype.put=function(e){if("string"==typeof e&&1!==e.length)throw new E("only accepts single character String");if("number"!=typeof e&&1!==e.length)throw new E("only accepts single character Uint8Array or Array");var n;if((n="string"==typeof e?e.charCodeAt(0):"number"==typeof e?e:e[0])<0||n>255)throw new E("only accepts number in a valid unsigned byte range 0-255");if(this.buffer.length>this.position)this.buffer[this.position++]=n;else{var r=w.alloc(t.BUFFER_SIZE+this.buffer.length);this.buffer.copy(r,0,0,this.buffer.length),this.buffer=r,this.buffer[this.position++]=n}},t.prototype.write=function(t,e){if(e="number"==typeof e?e:this.position,this.buffer.length<e+t.length){var n=w.alloc(this.buffer.length+t.length);this.buffer.copy(n,0,0,this.buffer.length),this.buffer=n}ArrayBuffer.isView(t)?(this.buffer.set(L(t),e),this.position=e+t.byteLength>this.position?e+t.length:this.position):"string"==typeof t&&(this.buffer.write(t,e,t.length,"binary"),this.position=e+t.length>this.position?e+t.length:this.position)},t.prototype.read=function(t,e){return e=e&&e>0?e:this.position,this.buffer.slice(t,t+e)},t.prototype.value=function(t){return(t=!!t)&&this.buffer.length===this.position?this.buffer:t?this.buffer.slice(0,this.position):this.buffer.toString("binary",0,this.position)},t.prototype.length=function(){return this.position},t.prototype.toJSON=function(){return this.buffer.toString("base64")},t.prototype.toString=function(t){return this.buffer.toString(t)},t.prototype.toExtendedJSON=function(t){t=t||{};var e=this.buffer.toString("base64"),n=Number(this.sub_type).toString(16);return t.legacy?{$binary:e,$type:1===n.length?"0"+n:n}:{$binary:{base64:e,subType:1===n.length?"0"+n:n}}},t.prototype.toUUID=function(){if(this.sub_type===t.SUBTYPE_UUID)return new k(this.buffer.slice(0,this.position));throw new _('Binary sub_type "'.concat(this.sub_type,'" is not supported for converting to UUID. Only "').concat(t.SUBTYPE_UUID,'" is currently supported.'))},t.fromExtendedJSON=function(e,n){var r,o;if(n=n||{},"$binary"in e?n.legacy&&"string"==typeof e.$binary&&"$type"in e?(o=e.$type?parseInt(e.$type,16):0,r=w.from(e.$binary,"base64")):"string"!=typeof e.$binary&&(o=e.$binary.subType?parseInt(e.$binary.subType,16):0,r=w.from(e.$binary.base64,"base64")):"$uuid"in e&&(o=4,r=R(e.$uuid)),!r)throw new E("Unexpected Binary Extended JSON format ".concat(JSON.stringify(e)));return 4===o?new k(r):new t(r,o)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){var t=this.value(!0);return'new Binary(Buffer.from("'.concat(t.toString("hex"),'", "hex"), ').concat(this.sub_type,")")},t.BSON_BINARY_SUBTYPE_DEFAULT=0,t.BUFFER_SIZE=256,t.SUBTYPE_DEFAULT=0,t.SUBTYPE_FUNCTION=1,t.SUBTYPE_BYTE_ARRAY=2,t.SUBTYPE_UUID_OLD=3,t.SUBTYPE_UUID=4,t.SUBTYPE_MD5=5,t.SUBTYPE_ENCRYPTED=6,t.SUBTYPE_COLUMN=7,t.SUBTYPE_USER_DEFINED=128,t}();Object.defineProperty(C.prototype,"_bsontype",{value:"Binary"});var k=function(t){function e(n){var r,o,i=this;if(null==n)r=e.generate();else if(n instanceof e)r=w.from(n.buffer),o=n.__id;else if(ArrayBuffer.isView(n)&&16===n.byteLength)r=L(n);else{if("string"!=typeof n)throw new E("Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).");r=R(n)}return(i=t.call(this,r,4)||this).__id=o,i}return v(e,t),Object.defineProperty(e.prototype,"id",{get:function(){return this.buffer},set:function(t){this.buffer=t,e.cacheHexString&&(this.__id=M(t))},enumerable:!1,configurable:!0}),e.prototype.toHexString=function(t){if(void 0===t&&(t=!0),e.cacheHexString&&this.__id)return this.__id;var n=M(this.id,t);return e.cacheHexString&&(this.__id=n),n},e.prototype.toString=function(t){return t?this.id.toString(t):this.toHexString()},e.prototype.toJSON=function(){return this.toHexString()},e.prototype.equals=function(t){if(!t)return!1;if(t instanceof e)return t.id.equals(this.id);try{return new e(t).id.equals(this.id)}catch(t){return!1}},e.prototype.toBinary=function(){return new C(this.id,C.SUBTYPE_UUID)},e.generate=function(){var t=x(16);return t[6]=15&t[6]|64,t[8]=63&t[8]|128,w.from(t)},e.isValid=function(t){return!!t&&(t instanceof e||("string"==typeof t?$(t):!!A(t)&&(16===t.length&&(64==(240&t[6])&&128==(128&t[8])))))},e.createFromHexString=function(t){return new e(R(t))},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){return'new UUID("'.concat(this.toHexString(),'")')},e}(C),J=function(){function t(e,n){if(!(this instanceof t))return new t(e,n);this.code=e,this.scope=n}return t.prototype.toJSON=function(){return{code:this.code,scope:this.scope}},t.prototype.toExtendedJSON=function(){return this.scope?{$code:this.code,$scope:this.scope}:{$code:this.code}},t.fromExtendedJSON=function(e){return new t(e.$code,e.$scope)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){var t=this.toJSON();return'new Code("'.concat(String(t.code),'"').concat(t.scope?", ".concat(JSON.stringify(t.scope)):"",")")},t}();function F(t){return j(t)&&null!=t.$id&&"string"==typeof t.$ref&&(null==t.$db||"string"==typeof t.$db)}Object.defineProperty(J.prototype,"_bsontype",{value:"Code"});var V=function(){function t(e,n,r,o){if(!(this instanceof t))return new t(e,n,r,o);var i=e.split(".");2===i.length&&(r=i.shift(),e=i.shift()),this.collection=e,this.oid=n,this.db=r,this.fields=o||{}}return Object.defineProperty(t.prototype,"namespace",{get:function(){return this.collection},set:function(t){this.collection=t},enumerable:!1,configurable:!0}),t.prototype.toJSON=function(){var t=Object.assign({$ref:this.collection,$id:this.oid},this.fields);return null!=this.db&&(t.$db=this.db),t},t.prototype.toExtendedJSON=function(t){t=t||{};var e={$ref:this.collection,$id:this.oid};return t.legacy?e:(this.db&&(e.$db=this.db),e=Object.assign(e,this.fields))},t.fromExtendedJSON=function(e){var n=Object.assign({},e);return delete n.$ref,delete n.$id,delete n.$db,new t(e.$ref,e.$id,e.$db,n)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){var t=void 0===this.oid||void 0===this.oid.toString?this.oid:this.oid.toString();return'new DBRef("'.concat(this.namespace,'", new ObjectId("').concat(String(t),'")').concat(this.db?', "'.concat(this.db,'"'):"",")")},t}();Object.defineProperty(V.prototype,"_bsontype",{value:"DBRef"});var H=void 0;try{H=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch(t){}var G={},Z={},Y=function(){function t(e,n,r){if(void 0===e&&(e=0),!(this instanceof t))return new t(e,n,r);"bigint"==typeof e?Object.assign(this,t.fromBigInt(e,!!n)):"string"==typeof e?Object.assign(this,t.fromString(e,!!n)):(this.low=0|e,this.high=0|n,this.unsigned=!!r),Object.defineProperty(this,"__isLong__",{value:!0,configurable:!1,writable:!1,enumerable:!1})}return t.fromBits=function(e,n,r){return new t(e,n,r)},t.fromInt=function(e,n){var r,o,i;return n?(i=0<=(e>>>=0)&&e<256)&&(o=Z[e])?o:(r=t.fromBits(e,(0|e)<0?-1:0,!0),i&&(Z[e]=r),r):(i=-128<=(e|=0)&&e<128)&&(o=G[e])?o:(r=t.fromBits(e,e<0?-1:0,!1),i&&(G[e]=r),r)},t.fromNumber=function(e,n){if(isNaN(e))return n?t.UZERO:t.ZERO;if(n){if(e<0)return t.UZERO;if(e>=0x10000000000000000)return t.MAX_UNSIGNED_VALUE}else{if(e<=-0x8000000000000000)return t.MIN_VALUE;if(e+1>=0x8000000000000000)return t.MAX_VALUE}return e<0?t.fromNumber(-e,n).neg():t.fromBits(e%4294967296|0,e/4294967296|0,n)},t.fromBigInt=function(e,n){return t.fromString(e.toString(),n)},t.fromString=function(e,n,r){if(0===e.length)throw Error("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return t.ZERO;if("number"==typeof n?(r=n,n=!1):n=!!n,(r=r||10)<2||36<r)throw RangeError("radix");var o;if((o=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===o)return t.fromString(e.substring(1),n,r).neg();for(var i=t.fromNumber(Math.pow(r,8)),u=t.ZERO,s=0;s<e.length;s+=8){var a=Math.min(8,e.length-s),f=parseInt(e.substring(s,s+a),r);if(a<8){var c=t.fromNumber(Math.pow(r,a));u=u.mul(c).add(t.fromNumber(f))}else u=(u=u.mul(i)).add(t.fromNumber(f))}return u.unsigned=n,u},t.fromBytes=function(e,n,r){return r?t.fromBytesLE(e,n):t.fromBytesBE(e,n)},t.fromBytesLE=function(e,n){return new t(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,n)},t.fromBytesBE=function(e,n){return new t(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],n)},t.isLong=function(t){return j(t)&&!0===t.__isLong__},t.fromValue=function(e,n){return"number"==typeof e?t.fromNumber(e,n):"string"==typeof e?t.fromString(e,n):t.fromBits(e.low,e.high,"boolean"==typeof n?n:e.unsigned)},t.prototype.add=function(e){t.isLong(e)||(e=t.fromValue(e));var n=this.high>>>16,r=65535&this.high,o=this.low>>>16,i=65535&this.low,u=e.high>>>16,s=65535&e.high,a=e.low>>>16,f=0,c=0,h=0,p=0;return h+=(p+=i+(65535&e.low))>>>16,p&=65535,c+=(h+=o+a)>>>16,h&=65535,f+=(c+=r+s)>>>16,c&=65535,f+=n+u,f&=65535,t.fromBits(h<<16|p,f<<16|c,this.unsigned)},t.prototype.and=function(e){return t.isLong(e)||(e=t.fromValue(e)),t.fromBits(this.low&e.low,this.high&e.high,this.unsigned)},t.prototype.compare=function(e){if(t.isLong(e)||(e=t.fromValue(e)),this.eq(e))return 0;var n=this.isNegative(),r=e.isNegative();return n&&!r?-1:!n&&r?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},t.prototype.comp=function(t){return this.compare(t)},t.prototype.divide=function(e){if(t.isLong(e)||(e=t.fromValue(e)),e.isZero())throw Error("division by zero");if(H){if(!this.unsigned&&-2147483648===this.high&&-1===e.low&&-1===e.high)return this;var n=(this.unsigned?H.div_u:H.div_s)(this.low,this.high,e.low,e.high);return t.fromBits(n,H.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?t.UZERO:t.ZERO;var r,o,i;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return t.UZERO;if(e.gt(this.shru(1)))return t.UONE;i=t.UZERO}else{if(this.eq(t.MIN_VALUE))return e.eq(t.ONE)||e.eq(t.NEG_ONE)?t.MIN_VALUE:e.eq(t.MIN_VALUE)?t.ONE:(r=this.shr(1).div(e).shl(1)).eq(t.ZERO)?e.isNegative()?t.ONE:t.NEG_ONE:(o=this.sub(e.mul(r)),i=r.add(o.div(e)));if(e.eq(t.MIN_VALUE))return this.unsigned?t.UZERO:t.ZERO;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();i=t.ZERO}for(o=this;o.gte(e);){r=Math.max(1,Math.floor(o.toNumber()/e.toNumber()));for(var u=Math.ceil(Math.log(r)/Math.LN2),s=u<=48?1:Math.pow(2,u-48),a=t.fromNumber(r),f=a.mul(e);f.isNegative()||f.gt(o);)r-=s,f=(a=t.fromNumber(r,this.unsigned)).mul(e);a.isZero()&&(a=t.ONE),i=i.add(a),o=o.sub(f)}return i},t.prototype.div=function(t){return this.divide(t)},t.prototype.equals=function(e){return t.isLong(e)||(e=t.fromValue(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},t.prototype.eq=function(t){return this.equals(t)},t.prototype.getHighBits=function(){return this.high},t.prototype.getHighBitsUnsigned=function(){return this.high>>>0},t.prototype.getLowBits=function(){return this.low},t.prototype.getLowBitsUnsigned=function(){return this.low>>>0},t.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.eq(t.MIN_VALUE)?64:this.neg().getNumBitsAbs();var e,n=0!==this.high?this.high:this.low;for(e=31;e>0&&0==(n&1<<e);e--);return 0!==this.high?e+33:e+1},t.prototype.greaterThan=function(t){return this.comp(t)>0},t.prototype.gt=function(t){return this.greaterThan(t)},t.prototype.greaterThanOrEqual=function(t){return this.comp(t)>=0},t.prototype.gte=function(t){return this.greaterThanOrEqual(t)},t.prototype.ge=function(t){return this.greaterThanOrEqual(t)},t.prototype.isEven=function(){return 0==(1&this.low)},t.prototype.isNegative=function(){return!this.unsigned&&this.high<0},t.prototype.isOdd=function(){return 1==(1&this.low)},t.prototype.isPositive=function(){return this.unsigned||this.high>=0},t.prototype.isZero=function(){return 0===this.high&&0===this.low},t.prototype.lessThan=function(t){return this.comp(t)<0},t.prototype.lt=function(t){return this.lessThan(t)},t.prototype.lessThanOrEqual=function(t){return this.comp(t)<=0},t.prototype.lte=function(t){return this.lessThanOrEqual(t)},t.prototype.modulo=function(e){if(t.isLong(e)||(e=t.fromValue(e)),H){var n=(this.unsigned?H.rem_u:H.rem_s)(this.low,this.high,e.low,e.high);return t.fromBits(n,H.get_high(),this.unsigned)}return this.sub(this.div(e).mul(e))},t.prototype.mod=function(t){return this.modulo(t)},t.prototype.rem=function(t){return this.modulo(t)},t.prototype.multiply=function(e){if(this.isZero())return t.ZERO;if(t.isLong(e)||(e=t.fromValue(e)),H){var n=H.mul(this.low,this.high,e.low,e.high);return t.fromBits(n,H.get_high(),this.unsigned)}if(e.isZero())return t.ZERO;if(this.eq(t.MIN_VALUE))return e.isOdd()?t.MIN_VALUE:t.ZERO;if(e.eq(t.MIN_VALUE))return this.isOdd()?t.MIN_VALUE:t.ZERO;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(t.TWO_PWR_24)&&e.lt(t.TWO_PWR_24))return t.fromNumber(this.toNumber()*e.toNumber(),this.unsigned);var r=this.high>>>16,o=65535&this.high,i=this.low>>>16,u=65535&this.low,s=e.high>>>16,a=65535&e.high,f=e.low>>>16,c=65535&e.low,h=0,p=0,l=0,d=0;return l+=(d+=u*c)>>>16,d&=65535,p+=(l+=i*c)>>>16,l&=65535,p+=(l+=u*f)>>>16,l&=65535,h+=(p+=o*c)>>>16,p&=65535,h+=(p+=i*f)>>>16,p&=65535,h+=(p+=u*a)>>>16,p&=65535,h+=r*c+o*f+i*a+u*s,h&=65535,t.fromBits(l<<16|d,h<<16|p,this.unsigned)},t.prototype.mul=function(t){return this.multiply(t)},t.prototype.negate=function(){return!this.unsigned&&this.eq(t.MIN_VALUE)?t.MIN_VALUE:this.not().add(t.ONE)},t.prototype.neg=function(){return this.negate()},t.prototype.not=function(){return t.fromBits(~this.low,~this.high,this.unsigned)},t.prototype.notEquals=function(t){return!this.equals(t)},t.prototype.neq=function(t){return this.notEquals(t)},t.prototype.ne=function(t){return this.notEquals(t)},t.prototype.or=function(e){return t.isLong(e)||(e=t.fromValue(e)),t.fromBits(this.low|e.low,this.high|e.high,this.unsigned)},t.prototype.shiftLeft=function(e){return t.isLong(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?t.fromBits(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):t.fromBits(0,this.low<<e-32,this.unsigned)},t.prototype.shl=function(t){return this.shiftLeft(t)},t.prototype.shiftRight=function(e){return t.isLong(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?t.fromBits(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):t.fromBits(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},t.prototype.shr=function(t){return this.shiftRight(t)},t.prototype.shiftRightUnsigned=function(e){if(t.isLong(e)&&(e=e.toInt()),0===(e&=63))return this;var n=this.high;if(e<32){var r=this.low;return t.fromBits(r>>>e|n<<32-e,n>>>e,this.unsigned)}return 32===e?t.fromBits(n,0,this.unsigned):t.fromBits(n>>>e-32,0,this.unsigned)},t.prototype.shr_u=function(t){return this.shiftRightUnsigned(t)},t.prototype.shru=function(t){return this.shiftRightUnsigned(t)},t.prototype.subtract=function(e){return t.isLong(e)||(e=t.fromValue(e)),this.add(e.neg())},t.prototype.sub=function(t){return this.subtract(t)},t.prototype.toInt=function(){return this.unsigned?this.low>>>0:this.low},t.prototype.toNumber=function(){return this.unsigned?4294967296*(this.high>>>0)+(this.low>>>0):4294967296*this.high+(this.low>>>0)},t.prototype.toBigInt=function(){return BigInt(this.toString())},t.prototype.toBytes=function(t){return t?this.toBytesLE():this.toBytesBE()},t.prototype.toBytesLE=function(){var t=this.high,e=this.low;return[255&e,e>>>8&255,e>>>16&255,e>>>24,255&t,t>>>8&255,t>>>16&255,t>>>24]},t.prototype.toBytesBE=function(){var t=this.high,e=this.low;return[t>>>24,t>>>16&255,t>>>8&255,255&t,e>>>24,e>>>16&255,e>>>8&255,255&e]},t.prototype.toSigned=function(){return this.unsigned?t.fromBits(this.low,this.high,!1):this},t.prototype.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(t.MIN_VALUE)){var n=t.fromNumber(e),r=this.div(n),o=r.mul(n).sub(this);return r.toString(e)+o.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var i=t.fromNumber(Math.pow(e,6),this.unsigned),u=this,s="";;){var a=u.div(i),f=(u.sub(a.mul(i)).toInt()>>>0).toString(e);if((u=a).isZero())return f+s;for(;f.length<6;)f="0"+f;s=""+f+s}},t.prototype.toUnsigned=function(){return this.unsigned?this:t.fromBits(this.low,this.high,!0)},t.prototype.xor=function(e){return t.isLong(e)||(e=t.fromValue(e)),t.fromBits(this.low^e.low,this.high^e.high,this.unsigned)},t.prototype.eqz=function(){return this.isZero()},t.prototype.le=function(t){return this.lessThanOrEqual(t)},t.prototype.toExtendedJSON=function(t){return t&&t.relaxed?this.toNumber():{$numberLong:this.toString()}},t.fromExtendedJSON=function(e,n){var r=t.fromString(e.$numberLong);return n&&n.relaxed?r.toNumber():r},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return'new Long("'.concat(this.toString(),'"').concat(this.unsigned?", true":"",")")},t.TWO_PWR_24=t.fromInt(1<<24),t.MAX_UNSIGNED_VALUE=t.fromBits(-1,-1,!0),t.ZERO=t.fromInt(0),t.UZERO=t.fromInt(0,!0),t.ONE=t.fromInt(1),t.UONE=t.fromInt(1,!0),t.NEG_ONE=t.fromInt(-1),t.MAX_VALUE=t.fromBits(-1,2147483647,!1),t.MIN_VALUE=t.fromBits(0,-2147483648,!1),t}();Object.defineProperty(Y.prototype,"__isLong__",{value:!0}),Object.defineProperty(Y.prototype,"_bsontype",{value:"Long"});var W=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,Q=/^(\+|-)?(Infinity|inf)$/i,z=/^(\+|-)?NaN$/i,X=[124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),K=[248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),tt=[120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),et=/^([-+])?(\d+)?$/;function nt(t){return!isNaN(parseInt(t,10))}function rt(t){var e=Y.fromNumber(1e9),n=Y.fromNumber(0);if(!(t.parts[0]||t.parts[1]||t.parts[2]||t.parts[3]))return{quotient:t,rem:n};for(var r=0;r<=3;r++)n=(n=n.shiftLeft(32)).add(new Y(t.parts[r],0)),t.parts[r]=n.div(e).low,n=n.modulo(e);return{quotient:t,rem:n}}function ot(t,e){throw new E('"'.concat(t,'" is not a valid Decimal128 string - ').concat(e))}var it=function(){function t(e){if(!(this instanceof t))return new t(e);if("string"==typeof e)this.bytes=t.fromString(e).bytes;else{if(!A(e))throw new E("Decimal128 must take a Buffer or string");if(16!==e.byteLength)throw new E("Decimal128 must take a Buffer of 16 bytes");this.bytes=e}}return t.fromString=function(e){var n,r=!1,o=!1,i=!1,u=0,s=0,a=0,f=0,c=0,h=[0],p=0,l=0,d=0,y=0,g=0,m=0,b=new Y(0,0),v=new Y(0,0),_=0;if(e.length>=7e3)throw new E(e+" not a valid Decimal128 string");var O=e.match(W),S=e.match(Q),N=e.match(z);if(!O&&!S&&!N||0===e.length)throw new E(e+" not a valid Decimal128 string");if(O){var x=O[2],I=O[4],A=O[5],T=O[6];I&&void 0===T&&ot(e,"missing exponent power"),I&&void 0===x&&ot(e,"missing exponent base"),void 0===I&&(A||T)&&ot(e,"missing e before exponent")}if("+"!==e[_]&&"-"!==e[_]||(r="-"===e[_++]),!nt(e[_])&&"."!==e[_]){if("i"===e[_]||"I"===e[_])return new t(w.from(r?K:tt));if("N"===e[_])return new t(w.from(X))}for(;nt(e[_])||"."===e[_];)"."!==e[_]?(p<34&&("0"!==e[_]||i)&&(i||(c=s),i=!0,h[l++]=parseInt(e[_],10),p+=1),i&&(a+=1),o&&(f+=1),s+=1,_+=1):(o&&ot(e,"contains multiple periods"),o=!0,_+=1);if(o&&!s)throw new E(e+" not a valid Decimal128 string");if("e"===e[_]||"E"===e[_]){var B=e.substr(++_).match(et);if(!B||!B[2])return new t(w.from(X));g=parseInt(B[0],10),_+=B[0].length}if(e[_])return new t(w.from(X));if(d=0,p){if(y=p-1,1!==(u=a))for(;0===h[c+u-1];)u-=1}else d=0,y=0,h[0]=0,a=1,p=1,u=0;for(g<=f&&f-g>16384?g=-6176:g-=f;g>6111;){if((y+=1)-d>34){if(h.join("").match(/^0+$/)){g=6111;break}ot(e,"overflow")}g-=1}for(;g<-6176||p<a;){if(0===y&&u<p){g=-6176,u=0;break}if(p<a?a-=1:y-=1,g<6111)g+=1;else{if(h.join("").match(/^0+$/)){g=6111;break}ot(e,"overflow")}}if(y-d+1<u){var j=s;o&&(c+=1,j+=1),r&&(c+=1,j+=1);var P=parseInt(e[c+y+1],10),L=0;if(P>=5&&(L=1,5===P))for(L=h[y]%2==1?1:0,m=c+y+2;m<j;m++)if(parseInt(e[m],10)){L=1;break}if(L)for(var U=y;U>=0;U--)if(++h[U]>9&&(h[U]=0,0===U)){if(!(g<6111))return new t(w.from(r?K:tt));g+=1,h[U]=1}}if(b=Y.fromNumber(0),v=Y.fromNumber(0),0===u)b=Y.fromNumber(0),v=Y.fromNumber(0);else if(y-d<17){U=d;for(v=Y.fromNumber(h[U++]),b=new Y(0,0);U<=y;U++)v=(v=v.multiply(Y.fromNumber(10))).add(Y.fromNumber(h[U]))}else{U=d;for(b=Y.fromNumber(h[U++]);U<=y-17;U++)b=(b=b.multiply(Y.fromNumber(10))).add(Y.fromNumber(h[U]));for(v=Y.fromNumber(h[U++]);U<=y;U++)v=(v=v.multiply(Y.fromNumber(10))).add(Y.fromNumber(h[U]))}var $,R,M,D,q=function(t,e){if(!t&&!e)return{high:Y.fromNumber(0),low:Y.fromNumber(0)};var n=t.shiftRightUnsigned(32),r=new Y(t.getLowBits(),0),o=e.shiftRightUnsigned(32),i=new Y(e.getLowBits(),0),u=n.multiply(o),s=n.multiply(i),a=r.multiply(o),f=r.multiply(i);return u=u.add(s.shiftRightUnsigned(32)),s=new Y(s.getLowBits(),0).add(a).add(f.shiftRightUnsigned(32)),{high:u=u.add(s.shiftRightUnsigned(32)),low:f=s.shiftLeft(32).add(new Y(f.getLowBits(),0))}}(b,Y.fromString("100000000000000000"));q.low=q.low.add(v),$=q.low,R=v,M=$.high>>>0,D=R.high>>>0,(M<D||M===D&&$.low>>>0<R.low>>>0)&&(q.high=q.high.add(Y.fromNumber(1))),n=g+6176;var C={low:Y.fromNumber(0),high:Y.fromNumber(0)};q.high.shiftRightUnsigned(49).and(Y.fromNumber(1)).equals(Y.fromNumber(1))?(C.high=C.high.or(Y.fromNumber(3).shiftLeft(61)),C.high=C.high.or(Y.fromNumber(n).and(Y.fromNumber(16383).shiftLeft(47))),C.high=C.high.or(q.high.and(Y.fromNumber(0x7fffffffffff)))):(C.high=C.high.or(Y.fromNumber(16383&n).shiftLeft(49)),C.high=C.high.or(q.high.and(Y.fromNumber(562949953421311)))),C.low=q.low,r&&(C.high=C.high.or(Y.fromString("9223372036854775808")));var k=w.alloc(16);return _=0,k[_++]=255&C.low.low,k[_++]=C.low.low>>8&255,k[_++]=C.low.low>>16&255,k[_++]=C.low.low>>24&255,k[_++]=255&C.low.high,k[_++]=C.low.high>>8&255,k[_++]=C.low.high>>16&255,k[_++]=C.low.high>>24&255,k[_++]=255&C.high.low,k[_++]=C.high.low>>8&255,k[_++]=C.high.low>>16&255,k[_++]=C.high.low>>24&255,k[_++]=255&C.high.high,k[_++]=C.high.high>>8&255,k[_++]=C.high.high>>16&255,k[_++]=C.high.high>>24&255,new t(k)},t.prototype.toString=function(){for(var t,e=0,n=new Array(36),r=0;r<n.length;r++)n[r]=0;var o,i,u,s=0,a=!1,f={parts:[0,0,0,0]},c=[];s=0;var h=this.bytes,p=h[s++]|h[s++]<<8|h[s++]<<16|h[s++]<<24,l=h[s++]|h[s++]<<8|h[s++]<<16|h[s++]<<24,d=h[s++]|h[s++]<<8|h[s++]<<16|h[s++]<<24,y=h[s++]|h[s++]<<8|h[s++]<<16|h[s++]<<24;s=0,{low:new Y(p,l),high:new Y(d,y)}.high.lessThan(Y.ZERO)&&c.push("-");var g=y>>26&31;if(g>>3==3){if(30===g)return c.join("")+"Infinity";if(31===g)return"NaN";t=y>>15&16383,o=8+(y>>14&1)}else o=y>>14&7,t=y>>17&16383;var m=t-6176;if(f.parts[0]=(16383&y)+((15&o)<<14),f.parts[1]=d,f.parts[2]=l,f.parts[3]=p,0===f.parts[0]&&0===f.parts[1]&&0===f.parts[2]&&0===f.parts[3])a=!0;else for(u=3;u>=0;u--){var w=0,b=rt(f);if(f=b.quotient,w=b.rem.low)for(i=8;i>=0;i--)n[9*u+i]=w%10,w=Math.floor(w/10)}if(a)e=1,n[s]=0;else for(e=36;!n[s];)e-=1,s+=1;var v=e-1+m;if(v>=34||v<=-7||m>0){if(e>34)return c.push("".concat(0)),m>0?c.push("E+".concat(m)):m<0&&c.push("E".concat(m)),c.join("");c.push("".concat(n[s++])),(e-=1)&&c.push(".");for(r=0;r<e;r++)c.push("".concat(n[s++]));c.push("E"),v>0?c.push("+".concat(v)):c.push("".concat(v))}else if(m>=0)for(r=0;r<e;r++)c.push("".concat(n[s++]));else{var _=e+m;if(_>0)for(r=0;r<_;r++)c.push("".concat(n[s++]));else c.push("0");for(c.push(".");_++<0;)c.push("0");for(r=0;r<e-Math.max(_-1,0);r++)c.push("".concat(n[s++]))}return c.join("")},t.prototype.toJSON=function(){return{$numberDecimal:this.toString()}},t.prototype.toExtendedJSON=function(){return{$numberDecimal:this.toString()}},t.fromExtendedJSON=function(e){return t.fromString(e.$numberDecimal)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return'new Decimal128("'.concat(this.toString(),'")')},t}();Object.defineProperty(it.prototype,"_bsontype",{value:"Decimal128"});var ut=function(){function t(e){if(!(this instanceof t))return new t(e);e instanceof Number&&(e=e.valueOf()),this.value=+e}return t.prototype.valueOf=function(){return this.value},t.prototype.toJSON=function(){return this.value},t.prototype.toString=function(t){return this.value.toString(t)},t.prototype.toExtendedJSON=function(t){return t&&(t.legacy||t.relaxed&&isFinite(this.value))?this.value:Object.is(Math.sign(this.value),-0)?{$numberDouble:"-".concat(this.value.toFixed(1))}:{$numberDouble:Number.isInteger(this.value)?this.value.toFixed(1):this.value.toString()}},t.fromExtendedJSON=function(e,n){var r=parseFloat(e.$numberDouble);return n&&n.relaxed?r:new t(r)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){var t=this.toExtendedJSON();return"new Double(".concat(t.$numberDouble,")")},t}();Object.defineProperty(ut.prototype,"_bsontype",{value:"Double"});var st=function(){function t(e){if(!(this instanceof t))return new t(e);e instanceof Number&&(e=e.valueOf()),this.value=0|+e}return t.prototype.valueOf=function(){return this.value},t.prototype.toString=function(t){return this.value.toString(t)},t.prototype.toJSON=function(){return this.value},t.prototype.toExtendedJSON=function(t){return t&&(t.relaxed||t.legacy)?this.value:{$numberInt:this.value.toString()}},t.fromExtendedJSON=function(e,n){return n&&n.relaxed?parseInt(e.$numberInt,10):new t(e.$numberInt)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return"new Int32(".concat(this.valueOf(),")")},t}();Object.defineProperty(st.prototype,"_bsontype",{value:"Int32"});var at=function(){function t(){if(!(this instanceof t))return new t}return t.prototype.toExtendedJSON=function(){return{$maxKey:1}},t.fromExtendedJSON=function(){return new t},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return"new MaxKey()"},t}();Object.defineProperty(at.prototype,"_bsontype",{value:"MaxKey"});var ft=function(){function t(){if(!(this instanceof t))return new t}return t.prototype.toExtendedJSON=function(){return{$minKey:1}},t.fromExtendedJSON=function(){return new t},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return"new MinKey()"},t}();Object.defineProperty(ft.prototype,"_bsontype",{value:"MinKey"});var ct=new RegExp("^[0-9a-fA-F]{24}$"),ht=null,pt=Symbol("id"),lt=function(){function t(e){if(!(this instanceof t))return new t(e);var n;if("object"==typeof e&&e&&"id"in e){if("string"!=typeof e.id&&!ArrayBuffer.isView(e.id))throw new E("Argument passed in must have an id that is of type string or Buffer");n="toHexString"in e&&"function"==typeof e.toHexString?w.from(e.toHexString(),"hex"):e.id}else n=e;if(null==n||"number"==typeof n)this[pt]=t.generate("number"==typeof n?n:void 0);else if(ArrayBuffer.isView(n)&&12===n.byteLength)this[pt]=n instanceof w?n:L(n);else{if("string"!=typeof n)throw new E("Argument passed in does not match the accepted types");if(12===n.length){var r=w.from(n);if(12!==r.byteLength)throw new E("Argument passed in must be a string of 12 bytes");this[pt]=r}else{if(24!==n.length||!ct.test(n))throw new E("Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer");this[pt]=w.from(n,"hex")}}t.cacheHexString&&(this.__id=this.id.toString("hex"))}return Object.defineProperty(t.prototype,"id",{get:function(){return this[pt]},set:function(e){this[pt]=e,t.cacheHexString&&(this.__id=e.toString("hex"))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"generationTime",{get:function(){return this.id.readInt32BE(0)},set:function(t){this.id.writeUInt32BE(t,0)},enumerable:!1,configurable:!0}),t.prototype.toHexString=function(){if(t.cacheHexString&&this.__id)return this.__id;var e=this.id.toString("hex");return t.cacheHexString&&!this.__id&&(this.__id=e),e},t.getInc=function(){return t.index=(t.index+1)%16777215},t.generate=function(e){"number"!=typeof e&&(e=Math.floor(Date.now()/1e3));var n=t.getInc(),r=w.alloc(12);return r.writeUInt32BE(e,0),null===ht&&(ht=x(5)),r[4]=ht[0],r[5]=ht[1],r[6]=ht[2],r[7]=ht[3],r[8]=ht[4],r[11]=255&n,r[10]=n>>8&255,r[9]=n>>16&255,r},t.prototype.toString=function(t){return t?this.id.toString(t):this.toHexString()},t.prototype.toJSON=function(){return this.toHexString()},t.prototype.equals=function(e){if(null==e)return!1;if(e instanceof t)return this[pt][11]===e[pt][11]&&this[pt].equals(e[pt]);if("string"==typeof e&&t.isValid(e)&&12===e.length&&A(this.id))return e===w.prototype.toString.call(this.id,"latin1");if("string"==typeof e&&t.isValid(e)&&24===e.length)return e.toLowerCase()===this.toHexString();if("string"==typeof e&&t.isValid(e)&&12===e.length)return w.from(e).equals(this.id);if("object"==typeof e&&"toHexString"in e&&"function"==typeof e.toHexString){var n=e.toHexString(),r=this.toHexString().toLowerCase();return"string"==typeof n&&n.toLowerCase()===r}return!1},t.prototype.getTimestamp=function(){var t=new Date,e=this.id.readUInt32BE(0);return t.setTime(1e3*Math.floor(e)),t},t.createPk=function(){return new t},t.createFromTime=function(e){var n=w.from([0,0,0,0,0,0,0,0,0,0,0,0]);return n.writeUInt32BE(e,0),new t(n)},t.createFromHexString=function(e){if(void 0===e||null!=e&&24!==e.length)throw new E("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");return new t(w.from(e,"hex"))},t.isValid=function(e){if(null==e)return!1;try{return new t(e),!0}catch(t){return!1}},t.prototype.toExtendedJSON=function(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}},t.fromExtendedJSON=function(e){return new t(e.$oid)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return'new ObjectId("'.concat(this.toHexString(),'")')},t.index=Math.floor(16777215*Math.random()),t}();Object.defineProperty(lt.prototype,"generate",{value:P((function(t){return lt.generate(t)}),"Please use the static `ObjectId.generate(time)` instead")}),Object.defineProperty(lt.prototype,"getInc",{value:P((function(){return lt.getInc()}),"Please use the static `ObjectId.getInc()` instead")}),Object.defineProperty(lt.prototype,"get_inc",{value:P((function(){return lt.getInc()}),"Please use the static `ObjectId.getInc()` instead")}),Object.defineProperty(lt,"get_inc",{value:P((function(){return lt.getInc()}),"Please use the static `ObjectId.getInc()` instead")}),Object.defineProperty(lt.prototype,"_bsontype",{value:"ObjectID"});var dt=function(){function t(e,n){if(!(this instanceof t))return new t(e,n);if(this.pattern=e,this.options=(null!=n?n:"").split("").sort().join(""),-1!==this.pattern.indexOf("\0"))throw new _("BSON Regex patterns cannot contain null bytes, found: ".concat(JSON.stringify(this.pattern)));if(-1!==this.options.indexOf("\0"))throw new _("BSON Regex options cannot contain null bytes, found: ".concat(JSON.stringify(this.options)));for(var r=0;r<this.options.length;r++)if("i"!==this.options[r]&&"m"!==this.options[r]&&"x"!==this.options[r]&&"l"!==this.options[r]&&"s"!==this.options[r]&&"u"!==this.options[r])throw new _("The regular expression option [".concat(this.options[r],"] is not supported"))}return t.parseOptions=function(t){return t?t.split("").sort().join(""):""},t.prototype.toExtendedJSON=function(t){return(t=t||{}).legacy?{$regex:this.pattern,$options:this.options}:{$regularExpression:{pattern:this.pattern,options:this.options}}},t.fromExtendedJSON=function(e){if("$regex"in e){if("string"==typeof e.$regex)return new t(e.$regex,t.parseOptions(e.$options));if("BSONRegExp"===e.$regex._bsontype)return e}if("$regularExpression"in e)return new t(e.$regularExpression.pattern,t.parseOptions(e.$regularExpression.options));throw new E("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(e)))},t}();Object.defineProperty(dt.prototype,"_bsontype",{value:"BSONRegExp"});var yt=function(){function t(e){if(!(this instanceof t))return new t(e);this.value=e}return t.prototype.valueOf=function(){return this.value},t.prototype.toString=function(){return this.value},t.prototype.inspect=function(){return'new BSONSymbol("'.concat(this.value,'")')},t.prototype.toJSON=function(){return this.value},t.prototype.toExtendedJSON=function(){return{$symbol:this.value}},t.fromExtendedJSON=function(e){return new t(e.$symbol)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t}();Object.defineProperty(yt.prototype,"_bsontype",{value:"Symbol"});var gt=function(t){function e(n,r){var o=this;return o instanceof e?(o=Y.isLong(n)?t.call(this,n.low,n.high,!0)||this:j(n)&&void 0!==n.t&&void 0!==n.i?t.call(this,n.i,n.t,!0)||this:t.call(this,n,r,!0)||this,Object.defineProperty(o,"_bsontype",{value:"Timestamp",writable:!1,configurable:!1,enumerable:!1}),o):new e(n,r)}return v(e,t),e.prototype.toJSON=function(){return{$timestamp:this.toString()}},e.fromInt=function(t){return new e(Y.fromInt(t,!0))},e.fromNumber=function(t){return new e(Y.fromNumber(t,!0))},e.fromBits=function(t,n){return new e(t,n)},e.fromString=function(t,n){return new e(Y.fromString(t,!0,n))},e.prototype.toExtendedJSON=function(){return{$timestamp:{t:this.high>>>0,i:this.low>>>0}}},e.fromExtendedJSON=function(t){return new e(t.$timestamp)},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){return"new Timestamp({ t: ".concat(this.getHighBits(),", i: ").concat(this.getLowBits()," })")},e.MAX_VALUE=Y.MAX_UNSIGNED_VALUE,e}(Y);function mt(t){return j(t)&&Reflect.has(t,"_bsontype")&&"string"==typeof t._bsontype}var wt={$oid:lt,$binary:C,$uuid:C,$symbol:yt,$numberInt:st,$numberDecimal:it,$numberDouble:ut,$numberLong:Y,$minKey:ft,$maxKey:at,$regex:dt,$regularExpression:dt,$timestamp:gt};function bt(t){var e=t.toISOString();return 0!==t.getUTCMilliseconds()?e:e.slice(0,-5)+"Z"}function vt(t,e){if(("object"==typeof t||"function"==typeof t)&&null!==t){var n=e.seenObjects.findIndex((function(e){return e.obj===t}));if(-1!==n){var r=e.seenObjects.map((function(t){return t.propertyName})),o=r.slice(0,n).map((function(t){return"".concat(t," -> ")})).join(""),i=r[n],u=" -> "+r.slice(n+1,r.length-1).map((function(t){return"".concat(t," -> ")})).join(""),s=r[r.length-1],a=" ".repeat(o.length+i.length/2),f="-".repeat(u.length+(i.length+s.length)/2-1);throw new E("Converting circular structure to EJSON:\n"+" ".concat(o).concat(i).concat(u).concat(s,"\n")+" ".concat(a,"\\").concat(f,"/"))}e.seenObjects[e.seenObjects.length-1].obj=t}if(Array.isArray(t))return function(t,e){return t.map((function(t,n){e.seenObjects.push({propertyName:"index ".concat(n),obj:null});try{return vt(t,e)}finally{e.seenObjects.pop()}}))}(t,e);if(void 0===t)return null;if(t instanceof Date||B(t)){var c=t.getTime(),h=c>-1&&c<2534023188e5;return e.legacy?e.relaxed&&h?{$date:t.getTime()}:{$date:bt(t)}:e.relaxed&&h?{$date:bt(t)}:{$date:{$numberLong:t.getTime().toString()}}}if(!("number"!=typeof t||e.relaxed&&isFinite(t))){if(Math.floor(t)===t){var p=t>=-0x8000000000000000&&t<=0x8000000000000000;if(t>=-2147483648&&t<=2147483647)return{$numberInt:t.toString()};if(p)return{$numberLong:t.toString()}}return{$numberDouble:t.toString()}}if(t instanceof RegExp||T(t)){var l=t.flags;if(void 0===l){var d=t.toString().match(/[gimuy]*$/);d&&(l=d[0])}return new dt(t.source,l).toExtendedJSON(e)}return null!=t&&"object"==typeof t?function(t,e){if(null==t||"object"!=typeof t)throw new _("not an object instance");var n=t._bsontype;if(void 0===n){var r={};for(var o in t){e.seenObjects.push({propertyName:o,obj:null});try{var i=vt(t[o],e);"__proto__"===o?Object.defineProperty(r,o,{value:i,writable:!0,enumerable:!0,configurable:!0}):r[o]=i}finally{e.seenObjects.pop()}}return r}if(mt(t)){var u=t;if("function"!=typeof u.toExtendedJSON){var s=Et[t._bsontype];if(!s)throw new E("Unrecognized or invalid _bsontype: "+t._bsontype);u=s(u)}return"Code"===n&&u.scope?u=new J(u.code,vt(u.scope,e)):"DBRef"===n&&u.oid&&(u=new V(vt(u.collection,e),vt(u.oid,e),vt(u.db,e),vt(u.fields,e))),u.toExtendedJSON(e)}throw new _("_bsontype must be a string, but was: "+typeof n)}(t,e):t}var _t,Et={Binary:function(t){return new C(t.value(),t.sub_type)},Code:function(t){return new J(t.code,t.scope)},DBRef:function(t){return new V(t.collection||t.namespace,t.oid,t.db,t.fields)},Decimal128:function(t){return new it(t.bytes)},Double:function(t){return new ut(t.value)},Int32:function(t){return new st(t.value)},Long:function(t){return Y.fromBits(null!=t.low?t.low:t.low_,null!=t.low?t.high:t.high_,null!=t.low?t.unsigned:t.unsigned_)},MaxKey:function(){return new at},MinKey:function(){return new ft},ObjectID:function(t){return new lt(t)},ObjectId:function(t){return new lt(t)},BSONRegExp:function(t){return new dt(t.pattern,t.options)},Symbol:function(t){return new yt(t.value)},Timestamp:function(t){return gt.fromBits(t.low,t.high)}};!function(t){function e(t,e){var n=Object.assign({},{relaxed:!0,legacy:!1},e);return"boolean"==typeof n.relaxed&&(n.strict=!n.relaxed),"boolean"==typeof n.strict&&(n.relaxed=!n.strict),JSON.parse(t,(function(t,e){if(-1!==t.indexOf("\0"))throw new _("BSON Document field names cannot contain null bytes, found: ".concat(JSON.stringify(t)));return function t(e,n){if(void 0===n&&(n={}),"number"==typeof e){if(n.relaxed||n.legacy)return e;if(Math.floor(e)===e){if(e>=-2147483648&&e<=2147483647)return new st(e);if(e>=-0x8000000000000000&&e<=0x8000000000000000)return Y.fromNumber(e)}return new ut(e)}if(null==e||"object"!=typeof e)return e;if(e.$undefined)return null;for(var r=Object.keys(e).filter((function(t){return t.startsWith("$")&&null!=e[t]})),o=0;o<r.length;o++){var i=wt[r[o]];if(i)return i.fromExtendedJSON(e,n)}if(null!=e.$date){var u=e.$date,s=new Date;return n.legacy?"number"==typeof u?s.setTime(u):"string"==typeof u&&s.setTime(Date.parse(u)):"string"==typeof u?s.setTime(Date.parse(u)):Y.isLong(u)?s.setTime(u.toNumber()):"number"==typeof u&&n.relaxed&&s.setTime(u),s}if(null!=e.$code){var a=Object.assign({},e);return e.$scope&&(a.$scope=t(e.$scope)),J.fromExtendedJSON(e)}if(F(e)||e.$dbPointer){var f=e.$ref?e:e.$dbPointer;if(f instanceof V)return f;var c=Object.keys(f).filter((function(t){return t.startsWith("$")})),h=!0;if(c.forEach((function(t){-1===["$ref","$id","$db"].indexOf(t)&&(h=!1)})),h)return V.fromExtendedJSON(f)}return e}(e,n)}))}function n(t,e,n,r){null!=n&&"object"==typeof n&&(r=n,n=0),null==e||"object"!=typeof e||Array.isArray(e)||(r=e,e=void 0,n=0);var o=vt(t,Object.assign({relaxed:!0,legacy:!1},r,{seenObjects:[{propertyName:"(root)",obj:null}]}));return JSON.stringify(o,e,n)}t.parse=e,t.stringify=n,t.serialize=function(t,e){return e=e||{},JSON.parse(n(t,e))},t.deserialize=function(t,n){return n=n||{},e(JSON.stringify(t),n)}}(_t||(_t={}));var Ot=S();Ot.Map?Ot.Map:function(){function t(t){void 0===t&&(t=[]),this._keys=[],this._values={};for(var e=0;e<t.length;e++)if(null!=t[e]){var n=t[e],r=n[0],o=n[1];this._keys.push(r),this._values[r]={v:o,i:this._keys.length-1}}}t.prototype.clear=function(){this._keys=[],this._values={}},t.prototype.delete=function(t){var e=this._values[t];return null!=e&&(delete this._values[t],this._keys.splice(e.i,1),!0)},t.prototype.entries=function(){var t=this,e=0;return{next:function(){var n=t._keys[e++];return{value:void 0!==n?[n,t._values[n].v]:void 0,done:void 0===n}}}},t.prototype.forEach=function(t,e){e=e||this;for(var n=0;n<this._keys.length;n++){var r=this._keys[n];t.call(e,this._values[r].v,r,e)}},t.prototype.get=function(t){return this._values[t]?this._values[t].v:void 0},t.prototype.has=function(t){return null!=this._values[t]},t.prototype.keys=function(){var t=this,e=0;return{next:function(){var n=t._keys[e++];return{value:void 0!==n?n:void 0,done:void 0===n}}}},t.prototype.set=function(t,e){return this._values[t]?(this._values[t].v=e,this):(this._keys.push(t),this._values[t]={v:e,i:this._keys.length-1},this)},t.prototype.values=function(){var t=this,e=0;return{next:function(){var n=t._keys[e++];return{value:void 0!==n?t._values[n].v:void 0,done:void 0===n}}}},Object.defineProperty(t.prototype,"size",{get:function(){return this._keys.length},enumerable:!1,configurable:!0})}();Y.fromNumber(D),Y.fromNumber(q);new Set(["$db","$ref","$id","$clusterTime"]);var St=new Uint8Array(8);new DataView(St.buffer,St.byteOffset,St.byteLength);w.alloc(17825792)}).call(this,n(2))},function(t,e,n){"use strict";var r=this&&this.__assign||function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0}),e.registerDatabase=void 0;var o=n(3);var i={name:"database",entity:{database:function(t){var e=this.platform,n=e.adapter,i=e.runtime;return o.Db.reqClass=this.request.constructor,o.Db.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},o.Db.runtime=i,this.wsClientClass&&(o.Db.wsClass=n.wsClass,o.Db.wsClientClass=this.wsClientClass),o.Db.ws||(o.Db.ws=null),new o.Db(r(r(r({},this.config),{_fromApp:this}),t))}}};try{cloudbase.registerComponent(i)}catch(t){}e.registerDatabase=function(t){try{t.registerComponent(i)}catch(t){console.warn(t)}}},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){"use strict";n.r(e),n.d(e,"Query",(function(){return Vt})),n.d(e,"CollectionReference",(function(){return Qt})),n.d(e,"DocumentReference",(function(){return Ct})),n.d(e,"Db",(function(){return me}));var r,o,i={};n.r(i),n.d(i,"Point",(function(){return K})),n.d(i,"LineString",(function(){return et})),n.d(i,"Polygon",(function(){return rt})),n.d(i,"MultiPoint",(function(){return it})),n.d(i,"MultiLineString",(function(){return st})),n.d(i,"MultiPolygon",(function(){return ft})),function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined"}(o||(o={}));var u,s="Number",a="Object",f="Array",c="GeoPoint",h="GeoLineString",p="GeoPolygon",l="GeoMultiPoint",d="GeoMultiLineString",y="GeoMultiPolygon",g="Date",m="ServerDate",w="BsonDate",b=["desc","asc"],v=["<","<=","==",">=",">"];!function(t){t.lt="<",t.gt=">",t.lte="<=",t.gte=">=",t.eq="=="}(u||(u={}));var _;(r={})[u.eq]="$eq",r[u.lt]="$lt",r[u.lte]="$lte",r[u.gt]="$gt",r[u.gte]="$gte";!function(t){t.WHERE="WHERE",t.DOC="DOC"}(_||(_={}));var E,O=(E=function(t,e){return(E=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}E(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),S=[],N={},x=function(t){function e(e,n){if(n!==N)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=S.length;n<r;n++)if(S[n].target===t)return S[n].instance;var o=new e(t,N);return S.push({target:t,instance:o}),o},e}((function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})})),I=x,A=I.for("UNSET_FIELD_NAME"),T=I.for("UPDATE_COMMAND"),B=I.for("QUERY_COMMAND"),j=I.for("LOGIC_COMMAND"),P=I.for("GEO_POINT"),L=I.for("SYMBOL_GEO_LINE_STRING"),U=I.for("SYMBOL_GEO_POLYGON"),$=I.for("SYMBOL_GEO_MULTI_POINT"),R=I.for("SYMBOL_GEO_MULTI_LINE_STRING"),M=I.for("SYMBOL_GEO_MULTI_POLYGON"),D=I.for("SERVER_DATE"),q=I.for("REGEXP"),C=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 D},enumerable:!0,configurable:!0}),t.prototype.parse=function(){return{$date:{offset:this.offset}}},t}();function k(t){return new C(t)}var J,F=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.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 u},V=function(){function t(){}return t.formatResDocumentData=function(e){return e.map((function(e){return t.formatField(e)}))},t.formatField=function(e){var n=Object.keys(e),r={};return Array.isArray(e)&&(r=[]),n.forEach((function(n){var o,i=e[n];switch(t.whichType(i)){case c:o=new K(i.coordinates[0],i.coordinates[1]);break;case h:o=new et(i.coordinates.map((function(t){return new K(t[0],t[1])})));break;case p:o=new rt(i.coordinates.map((function(t){return new et(t.map((function(t){var e=F(t,2),n=e[0],r=e[1];return new K(n,r)})))})));break;case l:o=new it(i.coordinates.map((function(t){return new K(t[0],t[1])})));break;case d:o=new st(i.coordinates.map((function(t){return new et(t.map((function(t){var e=F(t,2),n=e[0],r=e[1];return new K(n,r)})))})));break;case y:o=new ft(i.coordinates.map((function(t){return new rt(t.map((function(t){return new et(t.map((function(t){var e=F(t,2),n=e[0],r=e[1];return new K(n,r)})))})))})));break;case g:o=new Date(1e3*i.$timestamp);break;case a:case f:o=t.formatField(i);break;case m:o=new Date(i.$date);break;default:o=i}Array.isArray(r)?r.push(o):r[n]=o})),r},t.whichType=function(t){var e=Object.prototype.toString.call(t).slice(8,-1);if(e===g)return w;if(e===a){if(t instanceof K)return c;if(t instanceof Date)return g;if(t instanceof C)return m;t.$timestamp?e=g:t.$date?e=m:K.validate(t)?e=c:et.validate(t)?e=h:rt.validate(t)?e=p:it.validate(t)?e=l:st.validate(t)?e=d:ft.validate(t)&&(e=y)}return e},t.generateDocId=function(){for(var t="ABCDEFabcdef0123456789",e="",n=0;n<24;n++)e+=t.charAt(Math.floor(Math.random()*t.length));return e},t}(),H=function(){function t(){}return t.isGeopoint=function(t,e){if(V.whichType(e)!==s)throw new Error("Geo Point must be number type");var n=Math.abs(e);if("latitude"===t&&n>90)throw new Error("latitude should be a number ranges from -90 to 90");if("longitude"===t&&n>180)throw new Error("longitude should be a number ranges from -180 to 180");return!0},t.isInteger=function(t,e){if(!Number.isInteger(e))throw new Error(t+o.IntergerError);return!0},t.isFieldOrder=function(t){if(-1===b.indexOf(t))throw new Error(o.DirectionError);return!0},t.isFieldPath=function(t){if(!/^[a-zA-Z0-9-_\.]/.test(t))throw new Error;return!0},t.isOperator=function(t){if(-1===v.indexOf(t))throw new Error(o.OpStrError);return!0},t.isCollName=function(t){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(t))throw new Error(o.CollNameError);return!0},t.isDocID=function(t){if(!/^([a-fA-F0-9]){24}$/.test(t))throw new Error(o.DocIDError);return!0},t}(),G=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},Z=function(t){return"object"===G(t)},Y=function(t){return"number"===G(t)},W=function(t){return Array.isArray(t)},Q=function(t){return"date"===G(t)},z=function(t){return"regexp"===G(t)},X=function(t){return t&&t._internalType instanceof x},K=function(){function t(t,e){H.isGeopoint("longitude",t),H.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"["+this.longitude+","+this.latitude+"]"},t.validate=function(t){return"Point"===t.type&&W(t.coordinates)&&H.isGeopoint("longitude",t.coordinates[0])&&H.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return P},enumerable:!0,configurable:!0}),t}(),tt=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.")},et=function(){function t(t){if(!W(t))throw new TypeError('"points" must be of type Point[]. Received type '+typeof t);if(t.length<2)throw new Error('"points" must contain 2 points at least');t.forEach((function(t){if(!(t instanceof K))throw new TypeError('"points" must be of type Point[]. Received type '+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||!W(t.coordinates))return!1;try{for(var r=tt(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!Y(i[0])||!Y(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},t.isClosed=function(t){var e=t.points[0],n=t.points[t.points.length-1];if(e.latitude===n.latitude&&e.longitude===n.longitude)return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return L},enumerable:!0,configurable:!0}),t}(),nt=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.")},rt=function(){function t(t){if(!W(t))throw new TypeError('"lines" must be of type LineString[]. Received type '+typeof t);if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach((function(t){if(!(t instanceof et))throw new TypeError('"lines" must be of type LineString[]. Received type '+typeof t+"[]");if(!et.isClosed(t))throw new Error("LineString "+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||!W(t.coordinates))return!1;try{for(var i=nt(t.coordinates),u=i.next();!u.done;u=i.next()){var s=u.value;if(!this.isCloseLineString(s))return!1;try{for(var a=(r=void 0,nt(s)),f=a.next();!f.done;f=a.next()){var c=f.value;if(!Y(c[0])||!Y(c[1]))return!1}}catch(t){r={error:t}}finally{try{f&&!f.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{u&&!u.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 M},enumerable:!0,configurable:!0}),t}(),ot=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},it=function(){function t(t){if(!W(t))throw new TypeError('"points" must be of type Point[]. Received type '+typeof t);if(0===t.length)throw new Error('"points" must contain 1 point at least');t.forEach((function(t){if(!(t instanceof K))throw new TypeError('"points" must be of type Point[]. Received type '+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||!W(t.coordinates))return!1;try{for(var r=ot(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!Y(i[0])||!Y(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 $},enumerable:!0,configurable:!0}),t}(),ut=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.")},st=function(){function t(t){if(!W(t))throw new TypeError('"lines" must be of type LineString[]. Received type '+typeof t);if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach((function(t){if(!(t instanceof et))throw new TypeError('"lines" must be of type LineString[]. Received type '+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||!W(t.coordinates))return!1;try{for(var i=ut(t.coordinates),u=i.next();!u.done;u=i.next()){var s=u.value;try{for(var a=(r=void 0,ut(s)),f=a.next();!f.done;f=a.next()){var c=f.value;if(!Y(c[0])||!Y(c[1]))return!1}}catch(t){r={error:t}}finally{try{f&&!f.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{u&&!u.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:!0,configurable:!0}),t}(),at=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.")},ft=function(){function t(t){var e,n;if(!W(t))throw new TypeError('"polygons" must be of type Polygon[]. Received type '+typeof t);if(0===t.length)throw new Error("MultiPolygon must contain 1 polygon at least");try{for(var r=at(t),o=r.next();!o.done;o=r.next()){var i=o.value;if(!(i instanceof rt))throw new TypeError('"polygon" must be of type Polygon[]. Received type '+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,u;if("MultiPolygon"!==t.type||!W(t.coordinates))return!1;try{for(var s=at(t.coordinates),a=s.next();!a.done;a=s.next()){var f=a.value;try{for(var c=(r=void 0,at(f)),h=c.next();!h.done;h=c.next()){var p=h.value;try{for(var l=(i=void 0,at(p)),d=l.next();!d.done;d=l.next()){var y=d.value;if(!Y(y[0])||!Y(y[1]))return!1}}catch(t){i={error:t}}finally{try{d&&!d.done&&(u=l.return)&&u.call(l)}finally{if(i)throw i.error}}}}catch(t){r={error:t}}finally{try{h&&!h.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return U},enumerable:!0,configurable:!0}),t}(),ct=function(){var t;if(!Promise){(t=function(){}).promise={};var e=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(t.promise,"then",{get:e}),Object.defineProperty(t.promise,"catch",{get:e}),t}var n=new Promise((function(e,n){t=function(t,r){return t?n(t):e(r)}}));return t.promise=n,t};!function(t){t.SET="set",t.REMOVE="remove",t.INC="inc",t.MUL="mul",t.PUSH="push",t.PULL="pull",t.PULL_ALL="pullAll",t.POP="pop",t.SHIFT="shift",t.UNSHIFT="unshift",t.ADD_TO_SET="addToSet",t.BIT="bit",t.RENAME="rename",t.MAX="max",t.MIN="min"}(J||(J={}));var ht=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||A}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function pt(t){return t&&t instanceof ht&&t._internalType===T}var lt;!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(lt||(lt={}));var dt=function(){function t(t,e,n){if(this._internalType=j,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||A,this.fieldName!==A)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,o=e.length;r<o;r++){(yt(i=e[r])||bt(i))&&(e[r]=i._setFieldName(this.fieldName))}}else{var i;(yt(i=e)||bt(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(lt.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(lt.OR,r,this.fieldName)},t}();function yt(t){return t&&t instanceof dt&&t._internalType===j}var gt,mt=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)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){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"}(gt||(gt={}));var wt=function(t){function e(e,n,r){var o=t.call(this,e,n,r)||this;return o.operator=e,o._internalType=B,o}return mt(e,t),e.prototype.toJSON=function(){var t,e;switch(this.operator){case gt.IN:case gt.NIN:return(t={})["$"+this.operator]=this.operands,t;default:return(e={})["$"+this.operator]=this.operands[0],e}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(gt.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(gt.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(gt.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(gt.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(gt.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(gt.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(gt.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(gt.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof K))throw new TypeError('"geometry" must be of type Point. Received type '+typeof t.geometry);if(void 0!==t.maxDistance&&!Y(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '+typeof t.maxDistance);if(void 0!==t.minDistance&&!Y(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '+typeof t.minDistance);var n=new e(gt.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof ft||t.geometry instanceof rt))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '+typeof t.geometry);var n=new e(gt.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof K||t.geometry instanceof et||t.geometry instanceof rt||t.geometry instanceof it||t.geometry instanceof st||t.geometry instanceof ft))throw new TypeError('"geometry" must be of type Point, LineString, Polygon, MultiPoint, MultiLineString or MultiPolygon. Received type '+typeof t.geometry);var n=new e(gt.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(dt);function bt(t){return t&&t instanceof wt&&t._internalType===B}function vt(t){return bt(t)}var _t={};for(var Et in gt)_t[Et]="$"+Et;for(var Et in lt)_t[Et]="$"+Et;for(var Et in J)_t[Et]="$"+Et;function Ot(t){return _t[t]||"$"+t}_t[gt.NEQ]="$ne",_t[J.REMOVE]="$unset",_t[J.SHIFT]="$pop",_t[J.UNSHIFT]="$push";var St=function(){return(St=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},Nt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.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 u},xt=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(Nt(arguments[e]));return t};function It(t){return function t(e,n){if(!X(e)){if(Q(e))return{$date:+e};if(z(e))return{$regex:e.source,$options:e.flags};if(W(e))return e.map((function(e){if(n.indexOf(e)>-1)throw new Error("Cannot convert circular structure to JSON");return t(e,xt(n,[e]))}));if(Z(e)){var r=St({},e);for(var o in r){if(n.indexOf(r[o])>-1)throw new Error("Cannot convert circular structure to JSON");r[o]=t(r[o],xt(n,[r[o]]))}return r}return e}switch(e._internalType){case P:return e.toJSON();case D:case q:return e.parse();default:return e.toJSON?e.toJSON():e}}(t,[t])}var At=function(){return(At=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}).apply(this,arguments)},Tt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.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 u},Bt=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(Tt(arguments[e]));return t};function jt(t,e,n,r){var o=At({},t);for(var i in t)if(!/^\$/.test(i)){var u=t[i];if(u&&Z(u)&&!e(u)){if(r.indexOf(u)>-1)throw new Error("Cannot convert circular structure to JSON");var s=jt(u,e,Bt(n,[i]),Bt(r,[u]));o[i]=s;var a=!1;for(var f in s)/^\$/.test(f)?a=!0:(o[i+"."+f]=s[f],delete o[i][f]);a||delete o[i]}}return o}function Pt(t){return jt(t,Ut,[],[t])}function Lt(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?W(t[r])?t[r].push(e[r]):Z(t[r])?Z(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is "+G(e)+", can only overwrite",e,n),t[r]=e[r]):(console.warn("to-merge query is of type "+G(t)+", can only overwrite",t,e,n),t[r]=e[r]):t[r]=e[r]}function Ut(t){return X(t)||Q(t)||z(t)}function $t(t){return It(t)}var Rt=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.prototype.encodeUpdate=function(t){return pt(t)?this.encodeUpdateCommand(t):"object"===G(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===A)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case J.PUSH:case J.PULL:case J.PULL_ALL:case J.POP:case J.SHIFT:case J.UNSHIFT:case J.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,o,i=Ot(t.operator);switch(t.operator){case J.REMOVE:return(e={})[i]=((n={})[t.fieldName]="",n),e;default:return(r={})[i]=((o={})[t.fieldName]=t.operands[0],o),r}},t.prototype.encodeArrayUpdateCommand=function(t){var e,n,r,o,i,u,s,a,f,c,h=Ot(t.operator);switch(t.operator){case J.PUSH:var p=void 0;return p=W(t.operands)?{$each:t.operands.map($t)}:t.operands,(e={})[h]=((n={})[t.fieldName]=p,n),e;case J.UNSHIFT:p={$each:t.operands.map($t),$position:0};return(r={})[h]=((o={})[t.fieldName]=p,o),r;case J.POP:return(i={})[h]=((u={})[t.fieldName]=1,u),i;case J.SHIFT:return(s={})[h]=((a={})[t.fieldName]=-1,a),s;default:return(f={})[h]=((c={})[t.fieldName]=$t(t.operands),c),f}},t.prototype.encodeUpdateObject=function(t){var e=Pt(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(pt(r)){e[n]=r._setFieldName(n),Lt(e,this.encodeUpdateCommand(e[n]),n)}else{e[n]=r=$t(r);var o=new ht(J.SET,[r],n);Lt(e,this.encodeUpdateCommand(o),n)}}return e},t}(),Mt={};function Dt(t){if(!me.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return Mt[e]||(Mt[e]=new me.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:new me.reqClass(t.config)}}})),Mt[e]}var qt=function(){return(qt=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}).apply(this,arguments)},Ct=function(){function t(t,e,n,r){var o=this;void 0===r&&(r={}),this.watch=function(t){return Dt(o._db).watch(qt(qt({},t),{envId:o._db.config.env,collectionName:o._coll,query:JSON.stringify({_id:o.id})}))},this._db=t,this._coll=e,this.id=n,this.request=new me.reqClass(this._db.config),this.projection=r}return t.prototype.create=function(t,e){e=e||ct();var n={collectionName:this._coll,data:It(t)};return this.id&&(n._id=this.id),this.request.send("database.addDocument",n).then((function(t){t.code?e(0,t):e(0,{id:t.data._id,requestId:t.requestId})})).catch((function(t){e(t)})),e.promise},t.prototype.set=function(t,e){if(e=e||ct(),!this.id)return Promise.resolve({code:"INVALID_PARAM",message:"docId不能为空"});if(!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n=!1,r=function(t){if("object"==typeof t)for(var e in t)t[e]instanceof ht?n=!0:"object"==typeof t[e]&&r(t[e])};if(r(t),n)return Promise.resolve({code:"DATABASE_REQUEST_FAILED",message:"update operator complicit"});var o={collectionName:this._coll,queryType:_.DOC,data:It(t),multi:!1,merge:!1,upsert:!0};return this.id&&(o.query={_id:this.id}),this.request.send("database.updateDocument",o).then((function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})})).catch((function(t){e(t)})),e.promise},t.prototype.update=function(t,e){if(e=e||ct(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={_id:this.id},r={collectionName:this._coll,data:Rt.encode(t),query:n,queryType:_.DOC,multi:!1,merge:!0,upsert:!1};return this.request.send("database.updateDocument",r).then((function(t){t.code?e(0,t):e(0,{updated:t.data.updated,upsertedId:t.data.upserted_id,requestId:t.requestId})})).catch((function(t){e(t)})),e.promise},t.prototype.remove=function(t){t=t||ct();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:_.DOC,multi:!1};return this.request.send("database.deleteDocument",n).then((function(e){e.code?t(0,e):t(0,{deleted:e.data.deleted,requestId:e.requestId})})).catch((function(e){t(e)})),t.promise},t.prototype.get=function(t){t=t||ct();var e={_id:this.id},n={collectionName:this._coll,query:e,queryType:_.DOC,multi:!1,projection:this.projection};return this.request.send("database.queryDocument",n).then((function(e){if(e.code)t(0,e);else{var n=V.formatResDocumentData(e.data.list);t(0,{data:n,requestId:e.requestId,total:e.TotalCount,limit:e.Limit,offset:e.Offset})}})).catch((function(e){t(e)})),t.promise},t.prototype.field=function(e){for(var n in e)e[n]?e[n]=1:e[n]=0;return new t(this._db,this._coll,this.id,e)},t}(),kt=function(){function t(){}return t.encode=function(t){return(new Jt).encodeQuery(t)},t}(),Jt=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n;return Ut(t)?yt(t)?this.encodeLogicCommand(t):bt(t)?this.encodeQueryCommand(t):((n={})[e]=this.encodeQueryObject(t),n):Z(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regex:t.source,$options:t.flags}},t.prototype.encodeLogicCommand=function(t){var e,n,r,o,i,u,s,a=this;switch(t.operator){case lt.NOR:case lt.AND:case lt.OR:var f=Ot(t.operator),c=t.operands.map((function(e){return a.encodeQuery(e,t.fieldName)}));return(e={})[f]=c,e;case lt.NOT:f=Ot(t.operator);var h=t.operands[0];if(z(h))return(n={})[t.fieldName]=((r={})[f]=this.encodeRegExp(h),r),n;c=this.encodeQuery(h)[t.fieldName];return(o={})[t.fieldName]=((i={})[f]=c,i),o;default:f=Ot(t.operator);if(1===t.operands.length){var p=this.encodeQuery(t.operands[0]);return(u={})[f]=p,u}c=t.operands.map(this.encodeQuery.bind(this));return(s={})[f]=c,s}},t.prototype.encodeQueryCommand=function(t){return vt(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,o,i,u,s,a,f;if(t.fieldName===A)throw new Error("Cannot encode a comparison command with unset field name");var c=Ot(t.operator);switch(t.operator){case gt.EQ:case gt.NEQ:case gt.LT:case gt.LTE:case gt.GT:case gt.GTE:case gt.ELEM_MATCH:case gt.EXISTS:case gt.SIZE:case gt.MOD:return(e={})[t.fieldName]=((n={})[c]=$t(t.operands[0]),n),e;case gt.IN:case gt.NIN:case gt.ALL:return(r={})[t.fieldName]=((o={})[c]=$t(t.operands),o),r;case gt.GEO_NEAR:var h=t.operands[0];return(i={})[t.fieldName]={$nearSphere:{$geometry:h.geometry.toJSON(),$maxDistance:h.maxDistance,$minDistance:h.minDistance}},i;case gt.GEO_WITHIN:h=t.operands[0];return(u={})[t.fieldName]={$geoWithin:{$geometry:h.geometry.toJSON()}},u;case gt.GEO_INTERSECTS:h=t.operands[0];return(s={})[t.fieldName]={$geoIntersects:{$geometry:h.geometry.toJSON()}},s;default:return(a={})[t.fieldName]=((f={})[c]=$t(t.operands[0]),f),a}},t.prototype.encodeQueryObject=function(t){var e=Pt(t);for(var n in e){var r=e[n];if(yt(r)){e[n]=r._setFieldName(n);var o=this.encodeLogicCommand(e[n]);this.mergeConditionAfterEncode(e,o,n)}else if(vt(r)){e[n]=r._setFieldName(n);o=this.encodeComparisonCommand(e[n]);this.mergeConditionAfterEncode(e,o,n)}else Ut(r)&&(e[n]=$t(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?W(t[r])?t[r]=t[r].concat(e[r]):Z(t[r])?Z(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is "+G(e)+", can only overwrite",e,n),t[r]=e[r]):(console.warn("to-merge query is of type "+G(t)+", can only overwrite",t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),Ft=function(){return(Ft=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}).apply(this,arguments)},Vt=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){return Dt(i._db).watch(Ft(Ft({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify(i._fieldFilters||{}),limit:i._queryOptions.limit,orderBy:i._fieldOrders?i._fieldOrders.reduce((function(t,e){return t[e.field]=e.direction,t}),{}):void 0}))},this._db=t,this._coll=e,this._fieldFilters=n,this._fieldOrders=r||[],this._queryOptions=o||{},this._request=new me.reqClass(this._db.config)}return t.prototype.get=function(t){t=t||ct();var e=[];this._fieldOrders&&this._fieldOrders.forEach((function(t){e.push(t)}));var n={collectionName:this._coll,queryType:_.WHERE};return this._fieldFilters&&(n.query=this._fieldFilters),e.length>0&&(n.order=e),this._queryOptions.offset&&(n.offset=this._queryOptions.offset),this._queryOptions.limit?n.limit=this._queryOptions.limit<1e3?this._queryOptions.limit:1e3:n.limit=100,this._queryOptions.projection&&(n.projection=this._queryOptions.projection),this._request.send("database.queryDocument",n).then((function(e){if(e.code)t(0,e);else{var n={data:V.formatResDocumentData(e.data.list),requestId:e.requestId};e.TotalCount&&(n.total=e.TotalCount),e.Limit&&(n.limit=e.Limit),e.Offset&&(n.offset=e.Offset),t(0,n)}})).catch((function(e){t(e)})),t.promise},t.prototype.count=function(t){t=t||ct();var e={collectionName:this._coll,queryType:_.WHERE};return this._fieldFilters&&(e.query=this._fieldFilters),this._request.send("database.countDocument",e).then((function(e){e.code?t(0,e):t(0,{requestId:e.requestId,total:e.data.total})})).catch((function(e){t(e)})),t.promise},t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(o.QueryParamTypeError);var n=Object.keys(e),r=n.some((function(t){return void 0!==e[t]}));if(n.length&&!r)throw Error(o.QueryParamValueError);return new t(this._db,this._coll,kt.encode(e),this._fieldOrders,this._queryOptions)},t.prototype.orderBy=function(e,n){H.isFieldPath(e),H.isFieldOrder(n);var r={field:e,direction:n},o=this._fieldOrders.concat(r);return new t(this._db,this._coll,this._fieldFilters,o,this._queryOptions)},t.prototype.limit=function(e){H.isInteger("limit",e);var n=Ft({},this._queryOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.skip=function(e){H.isInteger("offset",e);var n=Ft({},this._queryOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},t.prototype.update=function(t,e){if(e=e||ct(),!t||"object"!=typeof t)return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(t.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={collectionName:this._coll,query:this._fieldFilters,queryType:_.WHERE,multi:!0,merge:!0,upsert:!1,data:Rt.encode(t)};return this._request.send("database.updateDocument",n).then((function(t){t.code?e(0,t):e(0,{requestId:t.requestId,updated:t.data.updated,upsertId:t.data.upsert_id})})).catch((function(t){e(t)})),e.promise},t.prototype.field=function(e){for(var n in e)e[n]?"object"!=typeof e[n]&&(e[n]=1):e[n]=0;var r=Ft({},this._queryOptions);return r.projection=e,new t(this._db,this._coll,this._fieldFilters,this._fieldOrders,r)},t.prototype.remove=function(t){t=t||ct(),Object.keys(this._queryOptions).length>0&&console.warn("`offset`, `limit` and `projection` are not supported in remove() operation"),this._fieldOrders.length>0&&console.warn("`orderBy` is not supported in remove() operation");var e={collectionName:this._coll,query:kt.encode(this._fieldFilters),queryType:_.WHERE,multi:!0};return this._request.send("database.deleteDocument",e).then((function(e){e.code?t(0,e):t(0,{requestId:e.requestId,deleted:e.data.deleted})})).catch((function(e){t(e)})),t.promise},t}(),Ht=n(0),Gt=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function s(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,s)}a((r=r.apply(t,e||[])).next())}))},Zt=function(t,e){var n,r,o,i,u={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(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},Yt=function(){function t(t,e){this._stages=[],t&&e&&(this._db=t,this._request=new me.reqClass(this._db.config),this._collectionName=e)}return t.prototype.end=function(){return Gt(this,void 0,void 0,(function(){var t;return Zt(this,(function(e){switch(e.label){case 0:if(!this._collectionName||!this._db)throw new Error("Aggregation pipeline cannot send request");return[4,this._request.send("database.aggregate",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:JSON.parse(t.data.list).map(Ht.a.parse)}]:[2,t]}}))}))},t.prototype.unwrap=function(){return this._stages},t.prototype.done=function(){return this._stages.map((function(t){var e,n=t.stageKey,r=t.stageValue;return(e={})[n]=JSON.parse(r),e}))},t.prototype._pipe=function(t,e){return this._stages.push({stageKey:"$"+t,stageValue:JSON.stringify(e)}),this},t.prototype.addFields=function(t){return this._pipe("addFields",t)},t.prototype.bucket=function(t){return this._pipe("bucket",t)},t.prototype.bucketAuto=function(t){return this._pipe("bucketAuto",t)},t.prototype.count=function(t){return this._pipe("count",t)},t.prototype.geoNear=function(t){return t.query&&(t.query=kt.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new K(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",kt.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}(),Wt=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)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Qt=function(t){function e(e,n){return t.call(this,e,n)||this}return Wt(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!0,configurable:!0}),e.prototype.doc=function(t){if("string"!=typeof t&&"number"!=typeof t)throw new Error("docId必须为字符串或数字");return new Ct(this._db,this._coll,t)},e.prototype.add=function(t,e){return new Ct(this._db,this._coll,void 0).create(t,e)},e.prototype.aggregate=function(){return new Yt(this._db,this._coll)},e}(Vt),zt={eq:function(t){return new wt(gt.EQ,[t])},neq:function(t){return new wt(gt.NEQ,[t])},lt:function(t){return new wt(gt.LT,[t])},lte:function(t){return new wt(gt.LTE,[t])},gt:function(t){return new wt(gt.GT,[t])},gte:function(t){return new wt(gt.GTE,[t])},in:function(t){return new wt(gt.IN,t)},nin:function(t){return new wt(gt.NIN,t)},all:function(t){return new wt(gt.ALL,t)},elemMatch:function(t){return new wt(gt.ELEM_MATCH,[t])},exists:function(t){return new wt(gt.EXISTS,[t])},size:function(t){return new wt(gt.SIZE,[t])},mod:function(t){return new wt(gt.MOD,[t])},geoNear:function(t){return new wt(gt.GEO_NEAR,[t])},geoWithin:function(t){return new wt(gt.GEO_WITHIN,[t])},geoIntersects:function(t){return new wt(gt.GEO_INTERSECTS,[t])},and:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=W(arguments[0])?arguments[0]:Array.from(arguments);return new dt(lt.AND,n)},nor:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=W(arguments[0])?arguments[0]:Array.from(arguments);return new dt(lt.NOR,n)},or:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=W(arguments[0])?arguments[0]:Array.from(arguments);return new dt(lt.OR,n)},not:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=W(arguments[0])?arguments[0]:Array.from(arguments);return new dt(lt.NOT,n)},set:function(t){return new ht(J.SET,[t])},remove:function(){return new ht(J.REMOVE,[])},inc:function(t){return new ht(J.INC,[t])},mul:function(t){return new ht(J.MUL,[t])},push:function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(Z(e[0])&&e[0].hasOwnProperty("each")){var r=e[0];t={$each:r.each,$position:r.position,$sort:r.sort,$slice:r.slice}}else t=W(e[0])?e[0]:Array.from(e);return new ht(J.PUSH,t)},pull:function(t){return new ht(J.PULL,t)},pullAll:function(t){return new ht(J.PULL_ALL,t)},pop:function(){return new ht(J.POP,[])},shift:function(){return new ht(J.SHIFT,[])},unshift:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=W(arguments[0])?arguments[0]:Array.from(arguments);return new ht(J.UNSHIFT,n)},addToSet:function(t){return new ht(J.ADD_TO_SET,t)},rename:function(t){return new ht(J.RENAME,[t])},bit:function(t){return new ht(J.BIT,[t])},max:function(t){return new ht(J.MAX,[t])},min:function(t){return new ht(J.MIN,[t])},expr:function(t){return{$expr:t}},jsonSchema:function(t){return{$jsonSchema:t}},text:function(t){return"string"===G(t)?{$search:t.search}:{$search:t.search,$language:t.language,$caseSensitive:t.caseSensitive,$diacriticSensitive:t.diacriticSensitive}},aggregate:{pipeline:function(){return new Yt},abs:function(t){return new Xt("abs",t)},add:function(t){return new Xt("add",t)},ceil:function(t){return new Xt("ceil",t)},divide:function(t){return new Xt("divide",t)},exp:function(t){return new Xt("exp",t)},floor:function(t){return new Xt("floor",t)},ln:function(t){return new Xt("ln",t)},log:function(t){return new Xt("log",t)},log10:function(t){return new Xt("log10",t)},mod:function(t){return new Xt("mod",t)},multiply:function(t){return new Xt("multiply",t)},pow:function(t){return new Xt("pow",t)},sqrt:function(t){return new Xt("sqrt",t)},subtract:function(t){return new Xt("subtract",t)},trunc:function(t){return new Xt("trunc",t)},arrayElemAt:function(t){return new Xt("arrayElemAt",t)},arrayToObject:function(t){return new Xt("arrayToObject",t)},concatArrays:function(t){return new Xt("concatArrays",t)},filter:function(t){return new Xt("filter",t)},in:function(t){return new Xt("in",t)},indexOfArray:function(t){return new Xt("indexOfArray",t)},isArray:function(t){return new Xt("isArray",t)},map:function(t){return new Xt("map",t)},range:function(t){return new Xt("range",t)},reduce:function(t){return new Xt("reduce",t)},reverseArray:function(t){return new Xt("reverseArray",t)},size:function(t){return new Xt("size",t)},slice:function(t){return new Xt("slice",t)},zip:function(t){return new Xt("zip",t)},and:function(t){return new Xt("and",t)},not:function(t){return new Xt("not",t)},or:function(t){return new Xt("or",t)},cmp:function(t){return new Xt("cmp",t)},eq:function(t){return new Xt("eq",t)},gt:function(t){return new Xt("gt",t)},gte:function(t){return new Xt("gte",t)},lt:function(t){return new Xt("lt",t)},lte:function(t){return new Xt("lte",t)},neq:function(t){return new Xt("ne",t)},cond:function(t){return new Xt("cond",t)},ifNull:function(t){return new Xt("ifNull",t)},switch:function(t){return new Xt("switch",t)},dateFromParts:function(t){return new Xt("dateFromParts",t)},dateFromString:function(t){return new Xt("dateFromString",t)},dayOfMonth:function(t){return new Xt("dayOfMonth",t)},dayOfWeek:function(t){return new Xt("dayOfWeek",t)},dayOfYear:function(t){return new Xt("dayOfYear",t)},isoDayOfWeek:function(t){return new Xt("isoDayOfWeek",t)},isoWeek:function(t){return new Xt("isoWeek",t)},isoWeekYear:function(t){return new Xt("isoWeekYear",t)},millisecond:function(t){return new Xt("millisecond",t)},minute:function(t){return new Xt("minute",t)},month:function(t){return new Xt("month",t)},second:function(t){return new Xt("second",t)},hour:function(t){return new Xt("hour",t)},week:function(t){return new Xt("week",t)},year:function(t){return new Xt("year",t)},literal:function(t){return new Xt("literal",t)},mergeObjects:function(t){return new Xt("mergeObjects",t)},objectToArray:function(t){return new Xt("objectToArray",t)},allElementsTrue:function(t){return new Xt("allElementsTrue",t)},anyElementTrue:function(t){return new Xt("anyElementTrue",t)},setDifference:function(t){return new Xt("setDifference",t)},setEquals:function(t){return new Xt("setEquals",t)},setIntersection:function(t){return new Xt("setIntersection",t)},setIsSubset:function(t){return new Xt("setIsSubset",t)},setUnion:function(t){return new Xt("setUnion",t)},concat:function(t){return new Xt("concat",t)},dateToString:function(t){return new Xt("dateToString",t)},indexOfBytes:function(t){return new Xt("indexOfBytes",t)},indexOfCP:function(t){return new Xt("indexOfCP",t)},split:function(t){return new Xt("split",t)},strLenBytes:function(t){return new Xt("strLenBytes",t)},strLenCP:function(t){return new Xt("strLenCP",t)},strcasecmp:function(t){return new Xt("strcasecmp",t)},substr:function(t){return new Xt("substr",t)},substrBytes:function(t){return new Xt("substrBytes",t)},substrCP:function(t){return new Xt("substrCP",t)},toLower:function(t){return new Xt("toLower",t)},toUpper:function(t){return new Xt("toUpper",t)},meta:function(t){return new Xt("meta",t)},addToSet:function(t){return new Xt("addToSet",t)},avg:function(t){return new Xt("avg",t)},first:function(t){return new Xt("first",t)},last:function(t){return new Xt("last",t)},max:function(t){return new Xt("max",t)},min:function(t){return new Xt("min",t)},push:function(t){return new Xt("push",t)},stdDevPop:function(t){return new Xt("stdDevPop",t)},stdDevSamp:function(t){return new Xt("stdDevSamp",t)},sum:function(t){return new Xt("sum",t)},let:function(t){return new Xt("let",t)}},project:{slice:function(t){return new Kt("slice",t)},elemMatch:function(t){return new Kt("elemMatch",t)}}},Xt=function(t,e){this["$"+t]=e},Kt=function(t,e){this["$"+t]=e},te=function(){function t(t){var e=t.regexp,n=t.options;if(!e)throw new TypeError("regexp must be a string");this.$regex=e,this.$options=n}return t.prototype.parse=function(){return{$regex:this.$regex,$options:this.$options}},Object.defineProperty(t.prototype,"_internalType",{get:function(){return q},enumerable:!0,configurable:!0}),t}();function ee(t){return new te(t)}var ne={code:"INSERT_DOC_FAIL",message:"insert document failed"},re={code:"DATABASE_TRANSACTION_CONFLICT",message:"database transaction conflict"},oe=function(){return(oe=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},ie=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function s(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,s)}a((r=r.apply(t,e||[])).next())}))},ue=function(t,e){var n,r,o,i,u={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(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},se="database.updateDocInTransaction",ae=function(){function t(t,e,n){this._coll=e,this.id=n,this._transaction=t,this._request=this._transaction.getRequestMethod(),this._transactionId=this._transaction.getTransactionId()}return t.prototype.create=function(t){return ie(this,void 0,void 0,(function(){var e,n,r,o;return ue(this,(function(i){switch(i.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,data:Ht.a.stringify(It(t),{relaxed:!1})},this.id&&(e._id=this.id),[4,this._request.send("database.insertDocInTransaction",e)];case 1:if((n=i.sent()).code)throw n;if(r=Ht.a.parse(n.inserted),1==(o=Ht.a.parse(n.ok))&&1==r)return[2,oe(oe({},n),{ok:o,inserted:r})];throw new Error(ne.message)}}))}))},t.prototype.get=function(){return ie(this,void 0,void 0,(function(){var t,e;return ue(this,(function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.getInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,{data:"null"!==e.data?V.formatField(Ht.a.parse(e.data)):Ht.a.parse(e.data),requestId:e.requestId}]}}))}))},t.prototype.set=function(t){return ie(this,void 0,void 0,(function(){var e,n;return ue(this,(function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:Ht.a.stringify(It(t),{relaxed:!1}),upsert:!0},[4,this._request.send(se,e)];case 1:if((n=r.sent()).code)throw n;return[2,oe(oe({},n),{updated:Ht.a.parse(n.updated),upserted:n.upserted?JSON.parse(n.upserted):null})]}}))}))},t.prototype.update=function(t){return ie(this,void 0,void 0,(function(){var e,n;return ue(this,(function(r){switch(r.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:Ht.a.stringify(Rt.encode(t),{relaxed:!1})},[4,this._request.send(se,e)];case 1:if((n=r.sent()).code)throw n;return[2,oe(oe({},n),{updated:Ht.a.parse(n.updated)})]}}))}))},t.prototype.delete=function(){return ie(this,void 0,void 0,(function(){var t,e;return ue(this,(function(n){switch(n.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send("database.deleteDocInTransaction",t)];case 1:if((e=n.sent()).code)throw e;return[2,oe(oe({},e),{deleted:Ht.a.parse(e.deleted)})]}}))}))},t}(),fe=function(t,e){this._coll=e,this._transaction=t},ce=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)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),he=function(t){function e(e,n){return t.call(this,e,n)||this}return ce(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!0,configurable:!0}),e.prototype.doc=function(t){if("string"!=typeof t&&"number"!=typeof t)throw new Error("docId必须为字符串或数字");return new ae(this._transaction,this._coll,t)},e.prototype.add=function(t){var e;return void 0!==t._id&&(e=t._id),new ae(this._transaction,this._coll,e).create(t)},e}(fe),pe=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function s(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,s)}a((r=r.apply(t,e||[])).next())}))},le=function(t,e){var n,r,o,i,u={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(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},de=function(){function t(t){this._db=t,this._request=new me.reqClass(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return t.prototype.init=function(){return pe(this,void 0,void 0,(function(){var t;return le(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 he(this,t)},t.prototype.getTransactionId=function(){return this._id},t.prototype.getRequestMethod=function(){return this._request},t.prototype.commit=function(){return pe(this,void 0,void 0,(function(){var t,e;return le(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 pe(this,void 0,void 0,(function(){var e,n;return le(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 ye(){return pe(this,void 0,void 0,(function(){var t;return le(this,(function(e){switch(e.label){case 0:return[4,(t=new de(this)).init()];case 1:return e.sent(),[2,t]}}))}))}function ge(t,e){return void 0===e&&(e=3),pe(this,void 0,void 0,(function(){var n,r,o,i,u=this;return le(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,10]),[4,(n=new de(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 pe(u,void 0,void 0,(function(){return le(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:return e.sent(),[3,4];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===re.code?[4,ge.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 me=function(){function t(t){this.config=t,this.Geo=i,this.serverDate=k,this.command=zt,this.RegExp=ee,this.startTransaction=ye,this.runTransaction=ge,this.logicCommand=dt,this.updateCommand=ht,this.queryCommand=wt}return t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new Qt(this,t)},t.prototype.createCollection=function(e){var n={collectionName:e};return new t.reqClass(this.config).send("database.addCollection",n)},t}()}])}));