@tacoreai/web-sdk 1.0.7 → 1.0.8

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.
Files changed (2) hide show
  1. package/dist/index.umd.js +55 -1
  2. package/package.json +1 -1
package/dist/index.umd.js CHANGED
@@ -1 +1,55 @@
1
- (function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e.TacoreAIWebSDK={}))})(this,function(e){"use strict";function t(){const{host:a,pathname:u}=window.location;if(["localhost","127.0.0.1","tacoreai.com","tacore.ai"].includes(a)){const o=u.match(/^\/app-run\/([^/]+)/);return`/app-run/${o==null?void 0:o[1]}`}return"/"}const n=Object.freeze(Object.defineProperty({__proto__:null,getRouterBasename:t},Symbol.toStringTag,{value:"Module"})),i=Object.freeze(Object.defineProperty({__proto__:null,testValue:1},Symbol.toStringTag,{value:"Module"}));e.databaseCore=i,e.utils=n,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
1
+ (function(Gr,si){typeof exports=="object"&&typeof module<"u"?si(exports):typeof define=="function"&&define.amd?define(["exports"],si):(Gr=typeof globalThis<"u"?globalThis:Gr||self,si(Gr.TacoreAIWebSDK={}))})(this,function(Gr){"use strict";function si(){const{host:r,pathname:e}=window.location;if(["localhost","127.0.0.1","tacoreai.com","tacore.ai"].includes(r)){const t=e.match(/^\/app-run\/([^/]+)/);return`/app-run/${t==null?void 0:t[1]}`}return"/"}const kh=Object.freeze(Object.defineProperty({__proto__:null,getRouterBasename:si},Symbol.toStringTag,{value:"Module"}));var bu="@cloudbase/js-sdk";function $h(r){bu=r}function Ji(){return bu}var wu="https:";function Wh(r){wu=r}function Hh(){return wu}var Ki="https://support.qq.com/products/148793",at={INVALID_PARAMS:"INVALID_PARAMS",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL"},Yi;(function(r){r.local="local",r.none="none",r.session="session"})(Yi||(Yi={}));var Ea=function(){function r(){}return r}(),Eu=function(){function r(){}return r}();function Qi(r,e,t){t===void 0&&(t={});var n=/\?/.test(e),o="";for(var i in t)o===""?!n&&(e+="?"):o+="&",o+=i+"="+encodeURIComponent(t[i]);return e+=o,/^http(s)?\:\/\//.test(e)?e:""+r+e}const Gh=Object.freeze(Object.defineProperty({__proto__:null,AbstractSDKRequest:Ea,AbstractStorage:Eu,get StorageType(){return Yi},formatUrl:Qi},Symbol.toStringTag,{value:"Module"}));function Su(r){return Object.prototype.toString.call(r)==="[object Array]"}function Iu(r){return typeof r=="string"}function Vh(r){return Object.prototype.toString.call(r)==="[object Object]"}function zh(r,e){return r instanceof e}function Ou(r){return Object.prototype.toString.call(r)==="[object FormData]"}function Jh(){return Math.random().toString(16).slice(2)}function Kh(){var r=new Date().getTime(),e=(performance==null?void 0:performance.now)&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=Math.random()*16;return r>0?(n=(r+n)%16|0,r=Math.floor(r/16)):(n=(e+n)%16|0,e=Math.floor(e/16)),(t==="x"?n:n&7|8).toString(16)})}function Tu(r,e,t){t===void 0&&(t={});var n=/\?/.test(e),o="";return Object.keys(t).forEach(function(i){o===""?!n&&(e+="?"):o+="&",o+="".concat(i,"=").concat(encodeURIComponent(t[i]))}),e+=o,/^http(s)?:\/\//.test(e)?e:"".concat(r).concat(e)}function Yh(r){r===void 0&&(r={});var e=[];return Object.keys(r).forEach(function(t){e.push("".concat(t,"=").concat(encodeURIComponent(r[t])))}),e.join("&")}function Au(r,e,t){if(t===void 0&&(t=null),r&&typeof r=="function")return r(e,t);if(e)throw e;return t}function An(r,e){console.warn("[".concat(Ji(),"][").concat(r,"]:").concat(e))}var Qh=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(n[i]=o[i])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),Ke=function(){return Ke=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Ke.apply(this,arguments)},Sa=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Ia=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Xh=function(r){Qh(e,r);function e(t){var n=r.call(this)||this,o=t.timeout,i=t.timeoutMsg,s=t.restrictedMethods;return n.timeout=o||0,n.timeoutMsg=i||"请求超时",n.restrictedMethods=s||["get","post","upload","download"],n}return e.prototype.get=function(t){return this.request(Ke(Ke({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(Ke(Ke({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(Ke(Ke({},t),{method:"put"}))},e.prototype.upload=function(t){var n=t.data,o=t.file,i=t.name,s=t.method,c=t.headers,l=c===void 0?{}:c,a={post:"post",put:"put"}[s==null?void 0:s.toLowerCase()]||"put",u=new FormData;return a==="post"?(Object.keys(n).forEach(function(f){u.append(f,n[f])}),u.append("key",i),u.append("file",o),this.request(Ke(Ke({},t),{data:u,method:a}),this.restrictedMethods.includes("upload"))):this.request(Ke(Ke({},t),{method:"put",headers:l,body:o}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return Sa(this,void 0,void 0,function(){var n,o,i,s;return Ia(this,function(c){switch(c.label){case 0:return c.trys.push([0,2,,3]),[4,this.get(Ke(Ke({},t),{headers:{},responseType:"blob"}))];case 1:return n=c.sent().data,o=window.URL.createObjectURL(new Blob([n])),i=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),s=document.createElement("a"),s.href=o,s.setAttribute("download",i),s.style.display="none",document.body.appendChild(s),s.click(),window.URL.revokeObjectURL(o),document.body.removeChild(s),[3,3];case 2:return c.sent(),[3,3];case 3:return[2,new Promise(function(l){l({statusCode:200,tempFilePath:t.url})})]}})})},e.prototype.fetch=function(t){var n;return Sa(this,void 0,void 0,function(){var o,i,s,c,l,a,u,f,d,y,m,v=this;return Ia(this,function(I){switch(I.label){case 0:return o=new AbortController,i=t.url,s=t.enableAbort,c=s===void 0?!1:s,l=t.stream,a=l===void 0?!1:l,u=t.signal,f=t.timeout,d=f??this.timeout,u&&(u.aborted&&o.abort(),u.addEventListener("abort",function(){return o.abort()})),y=null,c&&d&&(y=setTimeout(function(){console.warn(v.timeoutMsg),o.abort(new Error(v.timeoutMsg))},d)),[4,fetch(i,Ke(Ke({},t),{signal:o.signal})).then(function(S){return Sa(v,void 0,void 0,function(){var w,O,T;return Ia(this,function(N){switch(N.label){case 0:return clearTimeout(y),S.ok?(w=S,[3,3]):[3,1];case 1:return T=(O=Promise).reject,[4,S.json()];case 2:w=T.apply(O,[N.sent()]),N.label=3;case 3:return[2,w]}})})}).catch(function(S){return clearTimeout(y),Promise.reject(S)})];case 1:return m=I.sent(),[2,{data:a?m.body:!((n=m.headers.get("content-type"))===null||n===void 0)&&n.includes("application/json")?m.json():m.text(),statusCode:m.status,header:m.headers}]}})})},e.prototype.request=function(t,n){var o=this;n===void 0&&(n=!1);var i=String(t.method).toLowerCase()||"get";return new Promise(function(s){var c=t.url,l=t.headers,a=l===void 0?{}:l,u=t.data,f=t.responseType,d=t.withCredentials,y=t.body,m=t.onUploadProgress,v=Tu(Hh(),c,i==="get"?u:{}),I=new XMLHttpRequest;I.open(i,v),f&&(I.responseType=f),Object.keys(a).forEach(function(O){I.setRequestHeader(O,a[O])});var S;m&&I.upload.addEventListener("progress",m),I.onreadystatechange=function(){var O={};if(I.readyState===4){var T=I.getAllResponseHeaders(),N=T.trim().split(/[\r\n]+/),D={};N.forEach(function(B){var R=B.split(": "),x=R.shift().toLowerCase(),L=R.join(": ");D[x]=L}),O.header=D,O.statusCode=I.status;try{O.data=f==="blob"?I.response:JSON.parse(I.responseText)}catch{O.data=f==="blob"?I.response:I.responseText}clearTimeout(S),s(O)}},n&&o.timeout&&(S=setTimeout(function(){console.warn(o.timeoutMsg),I.abort()},o.timeout));var w;Ou(u)?w=u:a["content-type"]==="application/x-www-form-urlencoded"?w=Yh(u):y?w=y:w=u?JSON.stringify(u):void 0,d&&(I.withCredentials=!0),I.send(w)})},e}(Ea);function Zh(){var r={root:window,reqClass:Xh,wsClass:WebSocket,localStorage};return r}var Oa;(function(r){r.WEB="web",r.WX_MP="wx_mp"})(Oa||(Oa={}));function ep(r){for(var e=Su(r)?r:[r],t=0,n=e;t<n.length;t++){var o=n[t],i=o.isMatch,s=o.genAdapter,c=o.runtime;if(i())return{adapter:s(),runtime:c}}}function tp(){return{adapter:Zh(),runtime:Oa.WEB}}var rp=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(n[i]=o[i])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),Ta=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Aa=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Ra=function(r){rp(e,r);function e(t){var n=r.call(this)||this;return n.root=t,t.tcbCacheObject||(t.tcbCacheObject={}),n}return e.prototype.setItem=function(t,n){this.root.tcbCacheObject[t]=n},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(Eu);function np(r,e){switch(r){case"local":return e.localStorage?e.localStorage:(An(at.INVALID_PARAMS,"localStorage is not supported on current platform"),new Ra(e.root));case"none":return new Ra(e.root);default:return e.localStorage?e.localStorage:(An(at.INVALID_PARAMS,"localStorage is not supported on current platform"),new Ra(e.root))}}var ip=function(){function r(e){this.keys={};var t=e.persistence,n=e.platformInfo,o=n===void 0?{}:n,i=e.keys,s=i===void 0?{}:i;this.platformInfo=o,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||t,this.storage=np(this.persistenceTag,this.platformInfo.adapter),this.keys=s)}return Object.defineProperty(r.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),r.prototype.setStore=function(e,t,n){if(this.mode==="async"){An(at.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed");return}if(this.storage)try{var o={version:n||"localCachev1",content:t};this.storage.setItem(e,JSON.stringify(o))}catch(i){throw new Error(JSON.stringify({code:at.OPERATION_FAIL,msg:"[".concat(Ji(),"][").concat(at.OPERATION_FAIL,"]setStore failed"),info:i}))}},r.prototype.setStoreAsync=function(e,t,n){return Ta(this,void 0,void 0,function(){var o;return Aa(this,function(i){switch(i.label){case 0:if(!this.storage)return[2];i.label=1;case 1:return i.trys.push([1,3,,4]),o={version:n||"localCachev1",content:t},[4,this.storage.setItem(e,JSON.stringify(o))];case 2:return i.sent(),[3,4];case 3:return i.sent(),[2];case 4:return[2]}})})},r.prototype.getStore=function(e,t){var n;if(this.mode==="async"){An(at.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed");return}try{if(typeof process<"u"&&(!((n=process.env)===null||n===void 0)&&n.tcb_token))return process.env.tcb_token;if(!this.storage)return""}catch{return""}t=t||"localCachev1";var o=this.storage.getItem(e);if(!o)return"";if(o.indexOf(t)>=0){var i=JSON.parse(o);return i.content}return""},r.prototype.getStoreAsync=function(e,t){var n;return Ta(this,void 0,void 0,function(){var o,i;return Aa(this,function(s){switch(s.label){case 0:try{if(typeof process<"u"&&(!((n=process.env)===null||n===void 0)&&n.tcb_token))return[2,process.env.tcb_token];if(!this.storage)return[2,""]}catch{return[2,""]}return t=t||"localCachev1",[4,this.storage.getItem(e)];case 1:return o=s.sent(),o?o.indexOf(t)>=0?(i=JSON.parse(o),[2,i.content]):[2,""]:[2,""]}})})},r.prototype.removeStore=function(e){if(this.mode==="async"){An(at.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed");return}this.storage.removeItem(e)},r.prototype.removeStoreAsync=function(e){return Ta(this,void 0,void 0,function(){return Aa(this,function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}})})},r}(),op=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(n[i]=o[i])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),ap=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return r.concat(i||Array.prototype.slice.call(e))};function sp(r,e,t){t[r]=t[r]||[],t[r].push(e)}function up(r,e,t){if(t!=null&&t[r]){var n=t[r].indexOf(e);n!==-1&&t[r].splice(n,1)}}var Ru=function(){function r(e,t){this.data=t||null,this.name=e}return r}(),cp=function(r){op(e,r);function e(t,n){var o=r.call(this,"error",{error:t,data:n})||this;return o.error=t,o}return e}(Ru),lp=function(){function r(){this.listeners={}}return r.prototype.on=function(e,t){return sp(e,t,this.listeners),this},r.prototype.off=function(e,t){return up(e,t,this.listeners),this},r.prototype.fire=function(e,t){if(zh(e,cp))return console.error(e.error),this;var n=Iu(e)?new Ru(e,t||{}):e,o=n.name;if(this.listens(o)){n.target=this;for(var i=this.listeners[o]?ap([],this.listeners[o],!0):[],s=0,c=i;s<c.length;s++){var l=c[s];l.call(this,n)}}return this},r.prototype.listens=function(e){return this.listeners[e]&&this.listeners[e].length>0},r}();typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");function Xi(r){return r.mode,r.customInfo,r.title,r.messages,function(e,t,n){}}function Ca(r){this.message=r}Ca.prototype=new Error,Ca.prototype.name="InvalidCharacterError",typeof window<"u"&&window.atob&&window.atob.bind(window);function Cu(r){this.message=r}Cu.prototype=new Error,Cu.prototype.name="InvalidTokenError";/**
2
+ * @license
3
+ * web-streams-polyfill v4.1.0
4
+ * Copyright 2024 Mattias Buelens, Diwank Singh Tomer and other contributors.
5
+ * This code is released under the MIT license.
6
+ * SPDX-License-Identifier: MIT
7
+ */function ui(){}function Be(r){return typeof r=="object"&&r!==null||typeof r=="function"}const xu=ui;function fe(r,e){try{Object.defineProperty(r,"name",{value:e,configurable:!0})}catch{}}const xa=Promise,fp=Promise.resolve.bind(xa),dp=Promise.prototype.then,hp=Promise.reject.bind(xa),pp=fp;function Pe(r){return new xa(r)}function de(r){return Pe(e=>e(r))}function K(r){return hp(r)}function Jt(r,e,t){return dp.call(r,e,t)}function st(r,e,t){Jt(Jt(r,e,t),void 0,xu)}function Na(r,e){st(r,e)}function Pa(r,e){st(r,void 0,e)}function ur(r,e,t){return Jt(r,e,t)}function Rn(r){Jt(r,void 0,xu)}let Vr=r=>{if(typeof queueMicrotask=="function")Vr=queueMicrotask;else{const e=de(void 0);Vr=t=>Jt(e,t)}return Vr(r)};function zr(r,e,t){if(typeof r!="function")throw new TypeError("Argument is not a function");return Function.prototype.apply.call(r,e,t)}function cr(r,e,t){try{return de(zr(r,e,t))}catch(n){return K(n)}}class At{constructor(){this._cursor=0,this._size=0,this._front={_elements:[],_next:void 0},this._back=this._front,this._cursor=0,this._size=0}get length(){return this._size}push(e){const t=this._back;let n=t;t._elements.length===16383&&(n={_elements:[],_next:void 0}),t._elements.push(e),n!==t&&(this._back=n,t._next=n),++this._size}shift(){const e=this._front;let t=e;const n=this._cursor;let o=n+1;const i=e._elements,s=i[n];return o===16384&&(t=e._next,o=0),--this._size,this._cursor=o,e!==t&&(this._front=t),i[n]=void 0,s}forEach(e){let t=this._cursor,n=this._front,o=n._elements;for(;!(t===o.length&&n._next===void 0||t===o.length&&(n=n._next,o=n._elements,t=0,o.length===0));)e(o[t]),++t}peek(){const e=this._front,t=this._cursor;return e._elements[t]}}const Nu=Symbol("[[AbortSteps]]"),Pu=Symbol("[[ErrorSteps]]"),Da=Symbol("[[CancelSteps]]"),Fa=Symbol("[[PullSteps]]"),Ua=Symbol("[[ReleaseSteps]]");function Du(r,e){r._ownerReadableStream=e,e._reader=r,e._state==="readable"?La(r):e._state==="closed"?function(t){La(t),Uu(t)}(r):Fu(r,e._storedError)}function Ba(r,e){return Mt(r._ownerReadableStream,e)}function lr(r){const e=r._ownerReadableStream;e._state==="readable"?Ma(r,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")):function(t,n){Fu(t,n)}(r,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")),e._readableStreamController[Ua](),e._reader=void 0,r._ownerReadableStream=void 0}function Zi(r){return new TypeError("Cannot "+r+" a stream using a released reader")}function La(r){r._closedPromise=Pe((e,t)=>{r._closedPromise_resolve=e,r._closedPromise_reject=t})}function Fu(r,e){La(r),Ma(r,e)}function Ma(r,e){r._closedPromise_reject!==void 0&&(Rn(r._closedPromise),r._closedPromise_reject(e),r._closedPromise_resolve=void 0,r._closedPromise_reject=void 0)}function Uu(r){r._closedPromise_resolve!==void 0&&(r._closedPromise_resolve(void 0),r._closedPromise_resolve=void 0,r._closedPromise_reject=void 0)}const Bu=Number.isFinite||function(r){return typeof r=="number"&&isFinite(r)},yp=Math.trunc||function(r){return r<0?Math.ceil(r):Math.floor(r)};function fr(r,e){if(r!==void 0&&typeof(t=r)!="object"&&typeof t!="function")throw new TypeError(`${e} is not an object.`);var t}function Rt(r,e){if(typeof r!="function")throw new TypeError(`${e} is not a function.`)}function Lu(r,e){if(!function(t){return typeof t=="object"&&t!==null||typeof t=="function"}(r))throw new TypeError(`${e} is not an object.`)}function Jr(r,e,t){if(r===void 0)throw new TypeError(`Parameter ${e} is required in '${t}'.`)}function Mu(r,e,t){if(r===void 0)throw new TypeError(`${e} is required in '${t}'.`)}function qu(r){return Number(r)}function ju(r){return r===0?0:r}function qa(r,e){const t=Number.MAX_SAFE_INTEGER;let n=Number(r);if(n=ju(n),!Bu(n))throw new TypeError(`${e} is not a finite number`);if(n=function(o){return ju(yp(o))}(n),n<0||n>t)throw new TypeError(`${e} is outside the accepted range of 0 to ${t}, inclusive`);return Bu(n)&&n!==0?n:0}function ja(r,e){if(!Dr(r))throw new TypeError(`${e} is not a ReadableStream.`)}function Cn(r){return new Kr(r)}function ku(r,e){r._reader._readRequests.push(e)}function ka(r,e,t){const n=r._reader._readRequests.shift();t?n._closeSteps():n._chunkSteps(e)}function eo(r){return r._reader._readRequests.length}function $u(r){const e=r._reader;return e!==void 0&&!!Rr(e)}class Kr{constructor(e){if(Jr(e,1,"ReadableStreamDefaultReader"),ja(e,"First parameter"),Fr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");Du(this,e),this._readRequests=new At}get closed(){return Rr(this)?this._closedPromise:K(to("closed"))}cancel(e=void 0){return Rr(this)?this._ownerReadableStream===void 0?K(Zi("cancel")):Ba(this,e):K(to("cancel"))}read(){if(!Rr(this))return K(to("read"));if(this._ownerReadableStream===void 0)return K(Zi("read from"));let e,t;const n=Pe((o,i)=>{e=o,t=i});return ci(this,{_chunkSteps:o=>e({value:o,done:!1}),_closeSteps:()=>e({value:void 0,done:!0}),_errorSteps:o=>t(o)}),n}releaseLock(){if(!Rr(this))throw to("releaseLock");this._ownerReadableStream!==void 0&&function(e){lr(e);const t=new TypeError("Reader was released");Wu(e,t)}(this)}}function Rr(r){return!!Be(r)&&!!Object.prototype.hasOwnProperty.call(r,"_readRequests")&&r instanceof Kr}function ci(r,e){const t=r._ownerReadableStream;t._disturbed=!0,t._state==="closed"?e._closeSteps():t._state==="errored"?e._errorSteps(t._storedError):t._readableStreamController[Fa](e)}function Wu(r,e){const t=r._readRequests;r._readRequests=new At,t.forEach(n=>{n._errorSteps(e)})}function to(r){return new TypeError(`ReadableStreamDefaultReader.prototype.${r} can only be used on a ReadableStreamDefaultReader`)}var $a,Wa,Ha;function li(r){return r.slice()}function Hu(r,e,t,n,o){new Uint8Array(r).set(new Uint8Array(t,n,o),e)}Object.defineProperties(Kr.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),fe(Kr.prototype.cancel,"cancel"),fe(Kr.prototype.read,"read"),fe(Kr.prototype.releaseLock,"releaseLock"),typeof Symbol.toStringTag=="symbol"&&Object.defineProperty(Kr.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultReader",configurable:!0});let Yr=r=>(Yr=typeof r.transfer=="function"?e=>e.transfer():typeof structuredClone=="function"?e=>structuredClone(e,{transfer:[e]}):e=>e,Yr(r)),Qr=r=>(Qr=typeof r.detached=="boolean"?e=>e.detached:e=>e.byteLength===0,Qr(r));function Gu(r,e,t){if(r.slice)return r.slice(e,t);const n=t-e,o=new ArrayBuffer(n);return Hu(o,0,r,e,n),o}function fi(r,e){const t=r[e];if(t!=null){if(typeof t!="function")throw new TypeError(`${String(e)} is not a function`);return t}}function Vu(r){try{const e=r.done,t=r.value;return Jt(pp(t),n=>({done:e,value:n}))}catch(e){return K(e)}}const di=(Ha=($a=Symbol.asyncIterator)!==null&&$a!==void 0?$a:(Wa=Symbol.for)===null||Wa===void 0?void 0:Wa.call(Symbol,"Symbol.asyncIterator"))!==null&&Ha!==void 0?Ha:"@@asyncIterator";function zu(r,e="sync",t){if(t===void 0)if(e==="async"){if((t=fi(r,di))===void 0)return function(o){const i={next(){let s;try{s=Ju(o)}catch(c){return K(c)}return Vu(s)},return(s){let c;try{const l=fi(o.iterator,"return");if(l===void 0)return de({done:!0,value:s});c=zr(l,o.iterator,[s])}catch(l){return K(l)}return Be(c)?Vu(c):K(new TypeError("The iterator.return() method must return an object"))}};return{iterator:i,nextMethod:i.next,done:!1}}(zu(r,"sync",fi(r,Symbol.iterator)))}else t=fi(r,Symbol.iterator);if(t===void 0)throw new TypeError("The object is not iterable");const n=zr(t,r,[]);if(!Be(n))throw new TypeError("The iterator method must return an object");return{iterator:n,nextMethod:n.next,done:!1}}function Ju(r){const e=zr(r.nextMethod,r.iterator,[]);if(!Be(e))throw new TypeError("The iterator.next() method must return an object");return e}class Ku{constructor(e,t){this._ongoingPromise=void 0,this._isFinished=!1,this._reader=e,this._preventCancel=t}next(){const e=()=>this._nextSteps();return this._ongoingPromise=this._ongoingPromise?ur(this._ongoingPromise,e,e):e(),this._ongoingPromise}return(e){const t=()=>this._returnSteps(e);return this._ongoingPromise=this._ongoingPromise?ur(this._ongoingPromise,t,t):t(),this._ongoingPromise}_nextSteps(){if(this._isFinished)return Promise.resolve({value:void 0,done:!0});const e=this._reader;let t,n;const o=Pe((i,s)=>{t=i,n=s});return ci(e,{_chunkSteps:i=>{this._ongoingPromise=void 0,Vr(()=>t({value:i,done:!1}))},_closeSteps:()=>{this._ongoingPromise=void 0,this._isFinished=!0,lr(e),t({value:void 0,done:!0})},_errorSteps:i=>{this._ongoingPromise=void 0,this._isFinished=!0,lr(e),n(i)}}),o}_returnSteps(e){if(this._isFinished)return Promise.resolve({value:e,done:!0});this._isFinished=!0;const t=this._reader;if(!this._preventCancel){const n=Ba(t,e);return lr(t),ur(n,()=>({value:e,done:!0}))}return lr(t),de({value:e,done:!0})}}const Yu={next(){return Qu(this)?this._asyncIteratorImpl.next():K(Xu("next"))},return(r){return Qu(this)?this._asyncIteratorImpl.return(r):K(Xu("return"))},[di](){return this}};function Qu(r){if(!Be(r)||!Object.prototype.hasOwnProperty.call(r,"_asyncIteratorImpl"))return!1;try{return r._asyncIteratorImpl instanceof Ku}catch{return!1}}function Xu(r){return new TypeError(`ReadableStreamAsyncIterator.${r} can only be used on a ReadableSteamAsyncIterator`)}Object.defineProperty(Yu,di,{enumerable:!1});const Zu=Number.isNaN||function(r){return r!=r};function ec(r){const e=Gu(r.buffer,r.byteOffset,r.byteOffset+r.byteLength);return new Uint8Array(e)}function Ga(r){const e=r._queue.shift();return r._queueTotalSize-=e.size,r._queueTotalSize<0&&(r._queueTotalSize=0),e.value}function Va(r,e,t){if(typeof(n=t)!="number"||Zu(n)||n<0||t===1/0)throw new RangeError("Size must be a finite, non-NaN, non-negative number.");var n;r._queue.push({value:e,size:t}),r._queueTotalSize+=t}function Cr(r){r._queue=new At,r._queueTotalSize=0}function tc(r){return r===DataView}class xn{constructor(){throw new TypeError("Illegal constructor")}get view(){if(!za(this))throw Qa("view");return this._view}respond(e){if(!za(this))throw Qa("respond");if(Jr(e,1,"respond"),e=qa(e,"First parameter"),this._associatedReadableByteStreamController===void 0)throw new TypeError("This BYOB request has been invalidated");if(Qr(this._view.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be used as a response");ao(this._associatedReadableByteStreamController,e)}respondWithNewView(e){if(!za(this))throw Qa("respondWithNewView");if(Jr(e,1,"respondWithNewView"),!ArrayBuffer.isView(e))throw new TypeError("You can only respond with array buffer views");if(this._associatedReadableByteStreamController===void 0)throw new TypeError("This BYOB request has been invalidated");if(Qr(e.buffer))throw new TypeError("The given view's buffer has been detached and so cannot be used as a response");so(this._associatedReadableByteStreamController,e)}}Object.defineProperties(xn.prototype,{respond:{enumerable:!0},respondWithNewView:{enumerable:!0},view:{enumerable:!0}}),fe(xn.prototype.respond,"respond"),fe(xn.prototype.respondWithNewView,"respondWithNewView"),typeof Symbol.toStringTag=="symbol"&&Object.defineProperty(xn.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBRequest",configurable:!0});class xr{constructor(){throw new TypeError("Illegal constructor")}get byobRequest(){if(!Xr(this))throw pi("byobRequest");return Ya(this)}get desiredSize(){if(!Xr(this))throw pi("desiredSize");return dc(this)}close(){if(!Xr(this))throw pi("close");if(this._closeRequested)throw new TypeError("The stream has already been closed; do not close it again!");const e=this._controlledReadableByteStream._state;if(e!=="readable")throw new TypeError(`The stream (in ${e} state) is not in the readable state and cannot be closed`);hi(this)}enqueue(e){if(!Xr(this))throw pi("enqueue");if(Jr(e,1,"enqueue"),!ArrayBuffer.isView(e))throw new TypeError("chunk must be an array buffer view");if(e.byteLength===0)throw new TypeError("chunk must have non-zero byteLength");if(e.buffer.byteLength===0)throw new TypeError("chunk's buffer must have non-zero byteLength");if(this._closeRequested)throw new TypeError("stream is closed or draining");const t=this._controlledReadableByteStream._state;if(t!=="readable")throw new TypeError(`The stream (in ${t} state) is not in the readable state and cannot be enqueued to`);oo(this,e)}error(e=void 0){if(!Xr(this))throw pi("error");Ct(this,e)}[Da](e){rc(this),Cr(this);const t=this._cancelAlgorithm(e);return io(this),t}[Fa](e){const t=this._controlledReadableByteStream;if(this._queueTotalSize>0)return void fc(this,e);const n=this._autoAllocateChunkSize;if(n!==void 0){let o;try{o=new ArrayBuffer(n)}catch(s){return void e._errorSteps(s)}const i={buffer:o,bufferByteLength:n,byteOffset:0,byteLength:n,bytesFilled:0,minimumFill:1,elementSize:1,viewConstructor:Uint8Array,readerType:"default"};this._pendingPullIntos.push(i)}ku(t,e),Zr(this)}[Ua](){if(this._pendingPullIntos.length>0){const e=this._pendingPullIntos.peek();e.readerType="none",this._pendingPullIntos=new At,this._pendingPullIntos.push(e)}}}function Xr(r){return!!Be(r)&&!!Object.prototype.hasOwnProperty.call(r,"_controlledReadableByteStream")&&r instanceof xr}function za(r){return!!Be(r)&&!!Object.prototype.hasOwnProperty.call(r,"_associatedReadableByteStreamController")&&r instanceof xn}function Zr(r){if(function(t){const n=t._controlledReadableByteStream;return n._state!=="readable"||t._closeRequested||!t._started?!1:!!($u(n)&&eo(n)>0||Xa(n)&&mc(n)>0||dc(t)>0)}(r)){if(r._pulling)return void(r._pullAgain=!0);r._pulling=!0,st(r._pullAlgorithm(),()=>(r._pulling=!1,r._pullAgain&&(r._pullAgain=!1,Zr(r)),null),t=>(Ct(r,t),null))}}function rc(r){Ja(r),r._pendingPullIntos=new At}function nc(r,e){let t=!1;r._state==="closed"&&(t=!0);const n=ic(e);e.readerType==="default"?ka(r,n,t):function(o,i,s){const c=o._reader,l=c._readIntoRequests.shift();s?l._closeSteps(i):l._chunkSteps(i)}(r,n,t)}function ro(r,e){for(let t=0;t<e.length;++t)nc(r,e[t])}function ic(r){const e=r.bytesFilled,t=r.elementSize;return new r.viewConstructor(r.buffer,r.byteOffset,e/t)}function no(r,e,t,n){r._queue.push({buffer:e,byteOffset:t,byteLength:n}),r._queueTotalSize+=n}function oc(r,e,t,n){let o;try{o=Gu(e,t,t+n)}catch(i){throw Ct(r,i),i}no(r,o,0,n)}function ac(r,e){e.bytesFilled>0&&oc(r,e.buffer,e.byteOffset,e.bytesFilled),Nn(r)}function sc(r,e){const t=Math.min(r._queueTotalSize,e.byteLength-e.bytesFilled),n=e.bytesFilled+t;let o=t,i=!1;const s=n-n%e.elementSize;s>=e.minimumFill&&(o=s-e.bytesFilled,i=!0);const c=r._queue;for(;o>0;){const l=c.peek(),a=Math.min(o,l.byteLength),u=e.byteOffset+e.bytesFilled;Hu(e.buffer,u,l.buffer,l.byteOffset,a),l.byteLength===a?c.shift():(l.byteOffset+=a,l.byteLength-=a),r._queueTotalSize-=a,uc(r,a,e),o-=a}return i}function uc(r,e,t){t.bytesFilled+=e}function cc(r){r._queueTotalSize===0&&r._closeRequested?(io(r),wi(r._controlledReadableByteStream)):Zr(r)}function Ja(r){r._byobRequest!==null&&(r._byobRequest._associatedReadableByteStreamController=void 0,r._byobRequest._view=null,r._byobRequest=null)}function Ka(r){const e=[];for(;r._pendingPullIntos.length>0&&r._queueTotalSize!==0;){const t=r._pendingPullIntos.peek();sc(r,t)&&(Nn(r),e.push(t))}return e}function mp(r,e,t,n){const o=r._controlledReadableByteStream,i=e.constructor,s=function(d){return tc(d)?1:d.BYTES_PER_ELEMENT}(i),{byteOffset:c,byteLength:l}=e,a=t*s;let u;try{u=Yr(e.buffer)}catch(d){return void n._errorSteps(d)}const f={buffer:u,bufferByteLength:u.byteLength,byteOffset:c,byteLength:l,bytesFilled:0,minimumFill:a,elementSize:s,viewConstructor:i,readerType:"byob"};if(r._pendingPullIntos.length>0)return r._pendingPullIntos.push(f),void yc(o,n);if(o._state!=="closed"){if(r._queueTotalSize>0){if(sc(r,f)){const d=ic(f);return cc(r),void n._chunkSteps(d)}if(r._closeRequested){const d=new TypeError("Insufficient bytes to fill elements in the given buffer");return Ct(r,d),void n._errorSteps(d)}}r._pendingPullIntos.push(f),yc(o,n),Zr(r)}else{const d=new i(f.buffer,f.byteOffset,0);n._closeSteps(d)}}function lc(r,e){const t=r._pendingPullIntos.peek();Ja(r),r._controlledReadableByteStream._state==="closed"?function(n,o){o.readerType==="none"&&Nn(n);const i=n._controlledReadableByteStream;if(Xa(i)){const s=[];for(let c=0;c<mc(i);++c)s.push(Nn(n));ro(i,s)}}(r,t):function(n,o,i){if(uc(0,o,i),i.readerType==="none"){ac(n,i);const l=Ka(n);return void ro(n._controlledReadableByteStream,l)}if(i.bytesFilled<i.minimumFill)return;Nn(n);const s=i.bytesFilled%i.elementSize;if(s>0){const l=i.byteOffset+i.bytesFilled;oc(n,i.buffer,l-s,s)}i.bytesFilled-=s;const c=Ka(n);nc(n._controlledReadableByteStream,i),ro(n._controlledReadableByteStream,c)}(r,e,t),Zr(r)}function Nn(r){return r._pendingPullIntos.shift()}function io(r){r._pullAlgorithm=void 0,r._cancelAlgorithm=void 0}function hi(r){const e=r._controlledReadableByteStream;if(!r._closeRequested&&e._state==="readable")if(r._queueTotalSize>0)r._closeRequested=!0;else{if(r._pendingPullIntos.length>0){const t=r._pendingPullIntos.peek();if(t.bytesFilled%t.elementSize!=0){const n=new TypeError("Insufficient bytes to fill elements in the given buffer");throw Ct(r,n),n}}io(r),wi(e)}}function oo(r,e){const t=r._controlledReadableByteStream;if(r._closeRequested||t._state!=="readable")return;const{buffer:n,byteOffset:o,byteLength:i}=e;if(Qr(n))throw new TypeError("chunk's buffer is detached and so cannot be enqueued");const s=Yr(n);if(r._pendingPullIntos.length>0){const c=r._pendingPullIntos.peek();if(Qr(c.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be filled with an enqueued chunk");Ja(r),c.buffer=Yr(c.buffer),c.readerType==="none"&&ac(r,c)}if($u(t))(function(c){const l=c._controlledReadableByteStream._reader;for(;l._readRequests.length>0;){if(c._queueTotalSize===0)return;fc(c,l._readRequests.shift())}})(r),eo(t)===0?no(r,s,o,i):(r._pendingPullIntos.length>0&&Nn(r),ka(t,new Uint8Array(s,o,i),!1));else if(Xa(t)){no(r,s,o,i);const c=Ka(r);ro(r._controlledReadableByteStream,c)}else no(r,s,o,i);Zr(r)}function Ct(r,e){const t=r._controlledReadableByteStream;t._state==="readable"&&(rc(r),Cr(r),io(r),kc(t,e))}function fc(r,e){const t=r._queue.shift();r._queueTotalSize-=t.byteLength,cc(r);const n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);e._chunkSteps(n)}function Ya(r){if(r._byobRequest===null&&r._pendingPullIntos.length>0){const e=r._pendingPullIntos.peek(),t=new Uint8Array(e.buffer,e.byteOffset+e.bytesFilled,e.byteLength-e.bytesFilled),n=Object.create(xn.prototype);(function(o,i,s){o._associatedReadableByteStreamController=i,o._view=s})(n,r,t),r._byobRequest=n}return r._byobRequest}function dc(r){const e=r._controlledReadableByteStream._state;return e==="errored"?null:e==="closed"?0:r._strategyHWM-r._queueTotalSize}function ao(r,e){const t=r._pendingPullIntos.peek();if(r._controlledReadableByteStream._state==="closed"){if(e!==0)throw new TypeError("bytesWritten must be 0 when calling respond() on a closed stream")}else{if(e===0)throw new TypeError("bytesWritten must be greater than 0 when calling respond() on a readable stream");if(t.bytesFilled+e>t.byteLength)throw new RangeError("bytesWritten out of range")}t.buffer=Yr(t.buffer),lc(r,e)}function so(r,e){const t=r._pendingPullIntos.peek();if(r._controlledReadableByteStream._state==="closed"){if(e.byteLength!==0)throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream")}else if(e.byteLength===0)throw new TypeError("The view's length must be greater than 0 when calling respondWithNewView() on a readable stream");if(t.byteOffset+t.bytesFilled!==e.byteOffset)throw new RangeError("The region specified by view does not match byobRequest");if(t.bufferByteLength!==e.buffer.byteLength)throw new RangeError("The buffer of view has different capacity than byobRequest");if(t.bytesFilled+e.byteLength>t.byteLength)throw new RangeError("The region specified by view is larger than byobRequest");const n=e.byteLength;t.buffer=Yr(e.buffer),lc(r,n)}function hc(r,e,t,n,o,i,s){e._controlledReadableByteStream=r,e._pullAgain=!1,e._pulling=!1,e._byobRequest=null,e._queue=e._queueTotalSize=void 0,Cr(e),e._closeRequested=!1,e._started=!1,e._strategyHWM=i,e._pullAlgorithm=n,e._cancelAlgorithm=o,e._autoAllocateChunkSize=s,e._pendingPullIntos=new At,r._readableStreamController=e,st(de(t()),()=>(e._started=!0,Zr(e),null),c=>(Ct(e,c),null))}function Qa(r){return new TypeError(`ReadableStreamBYOBRequest.prototype.${r} can only be used on a ReadableStreamBYOBRequest`)}function pi(r){return new TypeError(`ReadableByteStreamController.prototype.${r} can only be used on a ReadableByteStreamController`)}function gp(r,e){if((r=`${r}`)!="byob")throw new TypeError(`${e} '${r}' is not a valid enumeration value for ReadableStreamReaderMode`);return r}function pc(r){return new en(r)}function yc(r,e){r._reader._readIntoRequests.push(e)}function mc(r){return r._reader._readIntoRequests.length}function Xa(r){const e=r._reader;return e!==void 0&&!!tn(e)}Object.defineProperties(xr.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},byobRequest:{enumerable:!0},desiredSize:{enumerable:!0}}),fe(xr.prototype.close,"close"),fe(xr.prototype.enqueue,"enqueue"),fe(xr.prototype.error,"error"),typeof Symbol.toStringTag=="symbol"&&Object.defineProperty(xr.prototype,Symbol.toStringTag,{value:"ReadableByteStreamController",configurable:!0});class en{constructor(e){if(Jr(e,1,"ReadableStreamBYOBReader"),ja(e,"First parameter"),Fr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");if(!Xr(e._readableStreamController))throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");Du(this,e),this._readIntoRequests=new At}get closed(){return tn(this)?this._closedPromise:K(uo("closed"))}cancel(e=void 0){return tn(this)?this._ownerReadableStream===void 0?K(Zi("cancel")):Ba(this,e):K(uo("cancel"))}read(e,t={}){if(!tn(this))return K(uo("read"));if(!ArrayBuffer.isView(e))return K(new TypeError("view must be an array buffer view"));if(e.byteLength===0)return K(new TypeError("view must have non-zero byteLength"));if(e.buffer.byteLength===0)return K(new TypeError("view's buffer must have non-zero byteLength"));if(Qr(e.buffer))return K(new TypeError("view's buffer has been detached"));let n;try{n=function(l,a){var u;return fr(l,a),{min:qa((u=l==null?void 0:l.min)!==null&&u!==void 0?u:1,`${a} has member 'min' that`)}}(t,"options")}catch(l){return K(l)}const o=n.min;if(o===0)return K(new TypeError("options.min must be greater than 0"));if(function(l){return tc(l.constructor)}(e)){if(o>e.byteLength)return K(new RangeError("options.min must be less than or equal to view's byteLength"))}else if(o>e.length)return K(new RangeError("options.min must be less than or equal to view's length"));if(this._ownerReadableStream===void 0)return K(Zi("read from"));let i,s;const c=Pe((l,a)=>{i=l,s=a});return gc(this,e,o,{_chunkSteps:l=>i({value:l,done:!1}),_closeSteps:l=>i({value:l,done:!0}),_errorSteps:l=>s(l)}),c}releaseLock(){if(!tn(this))throw uo("releaseLock");this._ownerReadableStream!==void 0&&function(e){lr(e);const t=new TypeError("Reader was released");vc(e,t)}(this)}}function tn(r){return!!Be(r)&&!!Object.prototype.hasOwnProperty.call(r,"_readIntoRequests")&&r instanceof en}function gc(r,e,t,n){const o=r._ownerReadableStream;o._disturbed=!0,o._state==="errored"?n._errorSteps(o._storedError):mp(o._readableStreamController,e,t,n)}function vc(r,e){const t=r._readIntoRequests;r._readIntoRequests=new At,t.forEach(n=>{n._errorSteps(e)})}function uo(r){return new TypeError(`ReadableStreamBYOBReader.prototype.${r} can only be used on a ReadableStreamBYOBReader`)}function yi(r,e){const{highWaterMark:t}=r;if(t===void 0)return e;if(Zu(t)||t<0)throw new RangeError("Invalid highWaterMark");return t}function co(r){const{size:e}=r;return e||(()=>1)}function lo(r,e){fr(r,e);const t=r==null?void 0:r.highWaterMark,n=r==null?void 0:r.size;return{highWaterMark:t===void 0?void 0:qu(t),size:n===void 0?void 0:vp(n,`${e} has member 'size' that`)}}function vp(r,e){return Rt(r,e),t=>qu(r(t))}function _p(r,e,t){return Rt(r,t),n=>cr(r,e,[n])}function bp(r,e,t){return Rt(r,t),()=>cr(r,e,[])}function wp(r,e,t){return Rt(r,t),n=>zr(r,e,[n])}function Ep(r,e,t){return Rt(r,t),(n,o)=>cr(r,e,[n,o])}function _c(r,e){if(!Pn(r))throw new TypeError(`${e} is not a WritableStream.`)}Object.defineProperties(en.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),fe(en.prototype.cancel,"cancel"),fe(en.prototype.read,"read"),fe(en.prototype.releaseLock,"releaseLock"),typeof Symbol.toStringTag=="symbol"&&Object.defineProperty(en.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBReader",configurable:!0});class rn{constructor(e={},t={}){e===void 0?e=null:Lu(e,"First parameter");const n=lo(t,"Second parameter"),o=function(s,c){fr(s,c);const l=s==null?void 0:s.abort,a=s==null?void 0:s.close,u=s==null?void 0:s.start,f=s==null?void 0:s.type,d=s==null?void 0:s.write;return{abort:l===void 0?void 0:_p(l,s,`${c} has member 'abort' that`),close:a===void 0?void 0:bp(a,s,`${c} has member 'close' that`),start:u===void 0?void 0:wp(u,s,`${c} has member 'start' that`),write:d===void 0?void 0:Ep(d,s,`${c} has member 'write' that`),type:f}}(e,"First parameter");if(wc(this),o.type!==void 0)throw new RangeError("Invalid type is specified");const i=co(n);(function(s,c,l,a){const u=Object.create(mi.prototype);let f,d,y,m;f=c.start!==void 0?()=>c.start(u):()=>{},d=c.write!==void 0?v=>c.write(v,u):()=>de(void 0),y=c.close!==void 0?()=>c.close():()=>de(void 0),m=c.abort!==void 0?v=>c.abort(v):()=>de(void 0),Rc(s,u,f,d,y,m,l,a)})(this,o,yi(n,1),i)}get locked(){if(!Pn(this))throw mo("locked");return Dn(this)}abort(e=void 0){return Pn(this)?Dn(this)?K(new TypeError("Cannot abort a stream that already has a writer")):fo(this,e):K(mo("abort"))}close(){return Pn(this)?Dn(this)?K(new TypeError("Cannot close a stream that already has a writer")):Kt(this)?K(new TypeError("Cannot close an already-closing stream")):Ec(this):K(mo("close"))}getWriter(){if(!Pn(this))throw mo("getWriter");return bc(this)}}function bc(r){return new Nr(r)}function wc(r){r._state="writable",r._storedError=void 0,r._writer=void 0,r._writableStreamController=void 0,r._writeRequests=new At,r._inFlightWriteRequest=void 0,r._closeRequest=void 0,r._inFlightCloseRequest=void 0,r._pendingAbortRequest=void 0,r._backpressure=!1}function Pn(r){return!!Be(r)&&!!Object.prototype.hasOwnProperty.call(r,"_writableStreamController")&&r instanceof rn}function Dn(r){return r._writer!==void 0}function fo(r,e){var t;if(r._state==="closed"||r._state==="errored")return de(void 0);r._writableStreamController._abortReason=e,(t=r._writableStreamController._abortController)===null||t===void 0||t.abort(e);const n=r._state;if(n==="closed"||n==="errored")return de(void 0);if(r._pendingAbortRequest!==void 0)return r._pendingAbortRequest._promise;let o=!1;n==="erroring"&&(o=!0,e=void 0);const i=Pe((s,c)=>{r._pendingAbortRequest={_promise:void 0,_resolve:s,_reject:c,_reason:e,_wasAlreadyErroring:o}});return r._pendingAbortRequest._promise=i,o||es(r,e),i}function Ec(r){const e=r._state;if(e==="closed"||e==="errored")return K(new TypeError(`The stream (in ${e} state) is not in the writable state and cannot be closed`));const t=Pe((i,s)=>{const c={_resolve:i,_reject:s};r._closeRequest=c}),n=r._writer;var o;return n!==void 0&&r._backpressure&&e==="writable"&&us(n),Va(o=r._writableStreamController,Ac,0),yo(o),t}function Za(r,e){r._state!=="writable"?ts(r):es(r,e)}function es(r,e){const t=r._writableStreamController;r._state="erroring",r._storedError=e;const n=r._writer;n!==void 0&&Ic(n,e),!function(o){return!(o._inFlightWriteRequest===void 0&&o._inFlightCloseRequest===void 0)}(r)&&t._started&&ts(r)}function ts(r){r._state="errored",r._writableStreamController[Pu]();const e=r._storedError;if(r._writeRequests.forEach(n=>{n._reject(e)}),r._writeRequests=new At,r._pendingAbortRequest===void 0)return void ho(r);const t=r._pendingAbortRequest;if(r._pendingAbortRequest=void 0,t._wasAlreadyErroring)return t._reject(e),void ho(r);st(r._writableStreamController[Nu](t._reason),()=>(t._resolve(),ho(r),null),n=>(t._reject(n),ho(r),null))}function Kt(r){return r._closeRequest!==void 0||r._inFlightCloseRequest!==void 0}function ho(r){r._closeRequest!==void 0&&(r._closeRequest._reject(r._storedError),r._closeRequest=void 0);const e=r._writer;e!==void 0&&as(e,r._storedError)}function rs(r,e){const t=r._writer;t!==void 0&&e!==r._backpressure&&(e?function(n){vo(n)}(t):us(t)),r._backpressure=e}Object.defineProperties(rn.prototype,{abort:{enumerable:!0},close:{enumerable:!0},getWriter:{enumerable:!0},locked:{enumerable:!0}}),fe(rn.prototype.abort,"abort"),fe(rn.prototype.close,"close"),fe(rn.prototype.getWriter,"getWriter"),typeof Symbol.toStringTag=="symbol"&&Object.defineProperty(rn.prototype,Symbol.toStringTag,{value:"WritableStream",configurable:!0});class Nr{constructor(e){if(Jr(e,1,"WritableStreamDefaultWriter"),_c(e,"First parameter"),Dn(e))throw new TypeError("This stream has already been locked for exclusive writing by another writer");this._ownerWritableStream=e,e._writer=this;const t=e._state;if(t==="writable")!Kt(e)&&e._backpressure?vo(this):Dc(this),go(this);else if(t==="erroring")ss(this,e._storedError),go(this);else if(t==="closed")Dc(this),go(n=this),Pc(n);else{const o=e._storedError;ss(this,o),Nc(this,o)}var n}get closed(){return nn(this)?this._closedPromise:K(on("closed"))}get desiredSize(){if(!nn(this))throw on("desiredSize");if(this._ownerWritableStream===void 0)throw vi("desiredSize");return function(e){const t=e._ownerWritableStream,n=t._state;return n==="errored"||n==="erroring"?null:n==="closed"?0:Cc(t._writableStreamController)}(this)}get ready(){return nn(this)?this._readyPromise:K(on("ready"))}abort(e=void 0){return nn(this)?this._ownerWritableStream===void 0?K(vi("abort")):function(t,n){return fo(t._ownerWritableStream,n)}(this,e):K(on("abort"))}close(){if(!nn(this))return K(on("close"));const e=this._ownerWritableStream;return e===void 0?K(vi("close")):Kt(e)?K(new TypeError("Cannot close an already-closing stream")):Sc(this)}releaseLock(){if(!nn(this))throw on("releaseLock");this._ownerWritableStream!==void 0&&Oc(this)}write(e=void 0){return nn(this)?this._ownerWritableStream===void 0?K(vi("write to")):Tc(this,e):K(on("write"))}}function nn(r){return!!Be(r)&&!!Object.prototype.hasOwnProperty.call(r,"_ownerWritableStream")&&r instanceof Nr}function Sc(r){return Ec(r._ownerWritableStream)}function Sp(r,e){r._closedPromiseState==="pending"?as(r,e):function(t,n){Nc(t,n)}(r,e)}function Ic(r,e){r._readyPromiseState==="pending"?Fc(r,e):function(t,n){ss(t,n)}(r,e)}function Oc(r){const e=r._ownerWritableStream,t=new TypeError("Writer was released and can no longer be used to monitor the stream's closedness");Ic(r,t),Sp(r,t),e._writer=void 0,r._ownerWritableStream=void 0}function Tc(r,e){const t=r._ownerWritableStream,n=t._writableStreamController,o=function(c,l){if(c._strategySizeAlgorithm===void 0)return 1;try{return c._strategySizeAlgorithm(l)}catch(a){return gi(c,a),1}}(n,e);if(t!==r._ownerWritableStream)return K(vi("write to"));const i=t._state;if(i==="errored")return K(t._storedError);if(Kt(t)||i==="closed")return K(new TypeError("The stream is closing or closed and cannot be written to"));if(i==="erroring")return K(t._storedError);const s=function(c){return Pe((l,a)=>{const u={_resolve:l,_reject:a};c._writeRequests.push(u)})}(t);return function(c,l,a){try{Va(c,l,a)}catch(f){return void gi(c,f)}const u=c._controlledWritableStream;!Kt(u)&&u._state==="writable"&&rs(u,is(c)),yo(c)}(n,e,o),s}Object.defineProperties(Nr.prototype,{abort:{enumerable:!0},close:{enumerable:!0},releaseLock:{enumerable:!0},write:{enumerable:!0},closed:{enumerable:!0},desiredSize:{enumerable:!0},ready:{enumerable:!0}}),fe(Nr.prototype.abort,"abort"),fe(Nr.prototype.close,"close"),fe(Nr.prototype.releaseLock,"releaseLock"),fe(Nr.prototype.write,"write"),typeof Symbol.toStringTag=="symbol"&&Object.defineProperty(Nr.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultWriter",configurable:!0});const Ac={};class mi{constructor(){throw new TypeError("Illegal constructor")}get abortReason(){if(!ns(this))throw os("abortReason");return this._abortReason}get signal(){if(!ns(this))throw os("signal");if(this._abortController===void 0)throw new TypeError("WritableStreamDefaultController.prototype.signal is not supported");return this._abortController.signal}error(e=void 0){if(!ns(this))throw os("error");this._controlledWritableStream._state==="writable"&&xc(this,e)}[Nu](e){const t=this._abortAlgorithm(e);return po(this),t}[Pu](){Cr(this)}}function ns(r){return!!Be(r)&&!!Object.prototype.hasOwnProperty.call(r,"_controlledWritableStream")&&r instanceof mi}function Rc(r,e,t,n,o,i,s,c){e._controlledWritableStream=r,r._writableStreamController=e,e._queue=void 0,e._queueTotalSize=void 0,Cr(e),e._abortReason=void 0,e._abortController=function(){if(typeof AbortController=="function")return new AbortController}(),e._started=!1,e._strategySizeAlgorithm=c,e._strategyHWM=s,e._writeAlgorithm=n,e._closeAlgorithm=o,e._abortAlgorithm=i;const l=is(e);rs(r,l),st(de(t()),()=>(e._started=!0,yo(e),null),a=>(e._started=!0,Za(r,a),null))}function po(r){r._writeAlgorithm=void 0,r._closeAlgorithm=void 0,r._abortAlgorithm=void 0,r._strategySizeAlgorithm=void 0}function Cc(r){return r._strategyHWM-r._queueTotalSize}function yo(r){const e=r._controlledWritableStream;if(!r._started||e._inFlightWriteRequest!==void 0)return;if(e._state==="erroring")return void ts(e);if(r._queue.length===0)return;const t=r._queue.peek().value;t===Ac?function(n){const o=n._controlledWritableStream;(function(s){s._inFlightCloseRequest=s._closeRequest,s._closeRequest=void 0})(o),Ga(n);const i=n._closeAlgorithm();po(n),st(i,()=>(function(s){s._inFlightCloseRequest._resolve(void 0),s._inFlightCloseRequest=void 0,s._state==="erroring"&&(s._storedError=void 0,s._pendingAbortRequest!==void 0&&(s._pendingAbortRequest._resolve(),s._pendingAbortRequest=void 0)),s._state="closed";const c=s._writer;c!==void 0&&Pc(c)}(o),null),s=>(function(c,l){c._inFlightCloseRequest._reject(l),c._inFlightCloseRequest=void 0,c._pendingAbortRequest!==void 0&&(c._pendingAbortRequest._reject(l),c._pendingAbortRequest=void 0),Za(c,l)}(o,s),null))}(r):function(n,o){const i=n._controlledWritableStream;(function(c){c._inFlightWriteRequest=c._writeRequests.shift()})(i);const s=n._writeAlgorithm(o);st(s,()=>{(function(l){l._inFlightWriteRequest._resolve(void 0),l._inFlightWriteRequest=void 0})(i);const c=i._state;if(Ga(n),!Kt(i)&&c==="writable"){const l=is(n);rs(i,l)}return yo(n),null},c=>(i._state==="writable"&&po(n),function(l,a){l._inFlightWriteRequest._reject(a),l._inFlightWriteRequest=void 0,Za(l,a)}(i,c),null))}(r,t)}function gi(r,e){r._controlledWritableStream._state==="writable"&&xc(r,e)}function is(r){return Cc(r)<=0}function xc(r,e){const t=r._controlledWritableStream;po(r),es(t,e)}function mo(r){return new TypeError(`WritableStream.prototype.${r} can only be used on a WritableStream`)}function os(r){return new TypeError(`WritableStreamDefaultController.prototype.${r} can only be used on a WritableStreamDefaultController`)}function on(r){return new TypeError(`WritableStreamDefaultWriter.prototype.${r} can only be used on a WritableStreamDefaultWriter`)}function vi(r){return new TypeError("Cannot "+r+" a stream using a released writer")}function go(r){r._closedPromise=Pe((e,t)=>{r._closedPromise_resolve=e,r._closedPromise_reject=t,r._closedPromiseState="pending"})}function Nc(r,e){go(r),as(r,e)}function as(r,e){r._closedPromise_reject!==void 0&&(Rn(r._closedPromise),r._closedPromise_reject(e),r._closedPromise_resolve=void 0,r._closedPromise_reject=void 0,r._closedPromiseState="rejected")}function Pc(r){r._closedPromise_resolve!==void 0&&(r._closedPromise_resolve(void 0),r._closedPromise_resolve=void 0,r._closedPromise_reject=void 0,r._closedPromiseState="resolved")}function vo(r){r._readyPromise=Pe((e,t)=>{r._readyPromise_resolve=e,r._readyPromise_reject=t}),r._readyPromiseState="pending"}function ss(r,e){vo(r),Fc(r,e)}function Dc(r){vo(r),us(r)}function Fc(r,e){r._readyPromise_reject!==void 0&&(Rn(r._readyPromise),r._readyPromise_reject(e),r._readyPromise_resolve=void 0,r._readyPromise_reject=void 0,r._readyPromiseState="rejected")}function us(r){r._readyPromise_resolve!==void 0&&(r._readyPromise_resolve(void 0),r._readyPromise_resolve=void 0,r._readyPromise_reject=void 0,r._readyPromiseState="fulfilled")}Object.defineProperties(mi.prototype,{abortReason:{enumerable:!0},signal:{enumerable:!0},error:{enumerable:!0}}),typeof Symbol.toStringTag=="symbol"&&Object.defineProperty(mi.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultController",configurable:!0});const Uc=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof global<"u"?global:void 0,Ip=function(){const r=Uc==null?void 0:Uc.DOMException;return function(e){if(typeof e!="function"&&typeof e!="object"||e.name!=="DOMException")return!1;try{return new e,!0}catch{return!1}}(r)?r:void 0}()||function(){const r=function(e,t){this.message=e||"",this.name=t||"Error",Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)};return fe(r,"DOMException"),r.prototype=Object.create(Error.prototype),Object.defineProperty(r.prototype,"constructor",{value:r,writable:!0,configurable:!0}),r}();function Bc(r,e,t,n,o,i){const s=Cn(r),c=bc(e);r._disturbed=!0;let l=!1,a=de(void 0);return Pe((u,f)=>{let d;if(i!==void 0){if(d=()=>{const N=i.reason!==void 0?i.reason:new Ip("Aborted","AbortError"),D=[];n||D.push(()=>e._state==="writable"?fo(e,N):de(void 0)),o||D.push(()=>r._state==="readable"?Mt(r,N):de(void 0)),w(()=>Promise.all(D.map(B=>B())),!0,N)},i.aborted)return void d();i.addEventListener("abort",d)}var y,m,v;if(S(r,s._closedPromise,N=>(n?O(!0,N):w(()=>fo(e,N),!0,N),null)),S(e,c._closedPromise,N=>(o?O(!0,N):w(()=>Mt(r,N),!0,N),null)),y=r,m=s._closedPromise,v=()=>(t?O():w(()=>function(N){const D=N._ownerWritableStream,B=D._state;return Kt(D)||B==="closed"?de(void 0):B==="errored"?K(D._storedError):Sc(N)}(c)),null),y._state==="closed"?v():Na(m,v),Kt(e)||e._state==="closed"){const N=new TypeError("the destination writable stream closed before all data could be piped to it");o?O(!0,N):w(()=>Mt(r,N),!0,N)}function I(){const N=a;return Jt(a,()=>N!==a?I():void 0)}function S(N,D,B){N._state==="errored"?B(N._storedError):Pa(D,B)}function w(N,D,B){function R(){return st(N(),()=>T(D,B),x=>T(!0,x)),null}l||(l=!0,e._state!=="writable"||Kt(e)?R():Na(I(),R))}function O(N,D){l||(l=!0,e._state!=="writable"||Kt(e)?T(N,D):Na(I(),()=>T(N,D)))}function T(N,D){return Oc(c),lr(s),i!==void 0&&i.removeEventListener("abort",d),N?f(D):u(void 0),null}Rn(Pe((N,D)=>{(function B(R){R?N():Jt(l?de(!0):Jt(c._readyPromise,()=>Pe((x,L)=>{ci(s,{_chunkSteps:F=>{a=Jt(Tc(c,F),void 0,ui),x(!1)},_closeSteps:()=>x(!0),_errorSteps:L})})),B,D)})(!1)}))})}class Pr{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!_o(this))throw wo("desiredSize");return cs(this)}close(){if(!_o(this))throw wo("close");if(!Un(this))throw new TypeError("The stream is not in a state that permits close");an(this)}enqueue(e=void 0){if(!_o(this))throw wo("enqueue");if(!Un(this))throw new TypeError("The stream is not in a state that permits enqueue");return Fn(this,e)}error(e=void 0){if(!_o(this))throw wo("error");Lt(this,e)}[Da](e){Cr(this);const t=this._cancelAlgorithm(e);return bo(this),t}[Fa](e){const t=this._controlledReadableStream;if(this._queue.length>0){const n=Ga(this);this._closeRequested&&this._queue.length===0?(bo(this),wi(t)):_i(this),e._chunkSteps(n)}else ku(t,e),_i(this)}[Ua](){}}function _o(r){return!!Be(r)&&!!Object.prototype.hasOwnProperty.call(r,"_controlledReadableStream")&&r instanceof Pr}function _i(r){if(Lc(r)){if(r._pulling)return void(r._pullAgain=!0);r._pulling=!0,st(r._pullAlgorithm(),()=>(r._pulling=!1,r._pullAgain&&(r._pullAgain=!1,_i(r)),null),e=>(Lt(r,e),null))}}function Lc(r){const e=r._controlledReadableStream;return!Un(r)||!r._started?!1:Fr(e)&&eo(e)>0?!0:cs(r)>0}function bo(r){r._pullAlgorithm=void 0,r._cancelAlgorithm=void 0,r._strategySizeAlgorithm=void 0}function an(r){if(!Un(r))return;const e=r._controlledReadableStream;r._closeRequested=!0,r._queue.length===0&&(bo(r),wi(e))}function Fn(r,e){if(!Un(r))return;const t=r._controlledReadableStream;if(Fr(t)&&eo(t)>0)ka(t,e,!1);else{let n;try{n=r._strategySizeAlgorithm(e)}catch(o){throw Lt(r,o),o}try{Va(r,e,n)}catch(o){throw Lt(r,o),o}}_i(r)}function Lt(r,e){const t=r._controlledReadableStream;t._state==="readable"&&(Cr(r),bo(r),kc(t,e))}function cs(r){const e=r._controlledReadableStream._state;return e==="errored"?null:e==="closed"?0:r._strategyHWM-r._queueTotalSize}function Un(r){const e=r._controlledReadableStream._state;return!r._closeRequested&&e==="readable"}function Mc(r,e,t,n,o,i,s){e._controlledReadableStream=r,e._queue=void 0,e._queueTotalSize=void 0,Cr(e),e._started=!1,e._closeRequested=!1,e._pullAgain=!1,e._pulling=!1,e._strategySizeAlgorithm=s,e._strategyHWM=i,e._pullAlgorithm=n,e._cancelAlgorithm=o,r._readableStreamController=e,st(de(t()),()=>(e._started=!0,_i(e),null),c=>(Lt(e,c),null))}function wo(r){return new TypeError(`ReadableStreamDefaultController.prototype.${r} can only be used on a ReadableStreamDefaultController`)}function Op(r,e){return Xr(r._readableStreamController)?function(t){let n,o,i,s,c,l=Cn(t),a=!1,u=!1,f=!1,d=!1,y=!1;const m=Pe(B=>{c=B});function v(B){Pa(B._closedPromise,R=>(B!==l||(Ct(i._readableStreamController,R),Ct(s._readableStreamController,R),d&&y||c(void 0)),null))}function I(){tn(l)&&(lr(l),l=Cn(t),v(l)),ci(l,{_chunkSteps:B=>{Vr(()=>{u=!1,f=!1;const R=B;let x=B;if(!d&&!y)try{x=ec(B)}catch(L){return Ct(i._readableStreamController,L),Ct(s._readableStreamController,L),void c(Mt(t,L))}d||oo(i._readableStreamController,R),y||oo(s._readableStreamController,x),a=!1,u?w():f&&O()})},_closeSteps:()=>{a=!1,d||hi(i._readableStreamController),y||hi(s._readableStreamController),i._readableStreamController._pendingPullIntos.length>0&&ao(i._readableStreamController,0),s._readableStreamController._pendingPullIntos.length>0&&ao(s._readableStreamController,0),d&&y||c(void 0)},_errorSteps:()=>{a=!1}})}function S(B,R){Rr(l)&&(lr(l),l=pc(t),v(l));const x=R?s:i,L=R?i:s;gc(l,B,1,{_chunkSteps:F=>{Vr(()=>{u=!1,f=!1;const j=R?y:d;if(R?d:y)j||so(x._readableStreamController,F);else{let V;try{V=ec(F)}catch(W){return Ct(x._readableStreamController,W),Ct(L._readableStreamController,W),void c(Mt(t,W))}j||so(x._readableStreamController,F),oo(L._readableStreamController,V)}a=!1,u?w():f&&O()})},_closeSteps:F=>{a=!1;const j=R?y:d,V=R?d:y;j||hi(x._readableStreamController),V||hi(L._readableStreamController),F!==void 0&&(j||so(x._readableStreamController,F),!V&&L._readableStreamController._pendingPullIntos.length>0&&ao(L._readableStreamController,0)),j&&V||c(void 0)},_errorSteps:()=>{a=!1}})}function w(){if(a)return u=!0,de(void 0);a=!0;const B=Ya(i._readableStreamController);return B===null?I():S(B._view,!1),de(void 0)}function O(){if(a)return f=!0,de(void 0);a=!0;const B=Ya(s._readableStreamController);return B===null?I():S(B._view,!0),de(void 0)}function T(B){if(d=!0,n=B,y){const R=li([n,o]),x=Mt(t,R);c(x)}return m}function N(B){if(y=!0,o=B,d){const R=li([n,o]),x=Mt(t,R);c(x)}return m}function D(){}return i=jc(D,w,T),s=jc(D,O,N),v(l),[i,s]}(r):function(t,n){const o=Cn(t);let i,s,c,l,a,u=!1,f=!1,d=!1,y=!1;const m=Pe(O=>{a=O});function v(){return u?(f=!0,de(void 0)):(u=!0,ci(o,{_chunkSteps:O=>{Vr(()=>{f=!1;const T=O,N=O;d||Fn(c._readableStreamController,T),y||Fn(l._readableStreamController,N),u=!1,f&&v()})},_closeSteps:()=>{u=!1,d||an(c._readableStreamController),y||an(l._readableStreamController),d&&y||a(void 0)},_errorSteps:()=>{u=!1}}),de(void 0))}function I(O){if(d=!0,i=O,y){const T=li([i,s]),N=Mt(t,T);a(N)}return m}function S(O){if(y=!0,s=O,d){const T=li([i,s]),N=Mt(t,T);a(N)}return m}function w(){}return c=bi(w,v,I),l=bi(w,v,S),Pa(o._closedPromise,O=>(Lt(c._readableStreamController,O),Lt(l._readableStreamController,O),d&&y||a(void 0),null)),[c,l]}(r)}function Tp(r){return Be(e=r)&&e.getReader!==void 0?function(t){let n;function o(){let s;try{s=t.read()}catch(c){return K(c)}return ur(s,c=>{if(!Be(c))throw new TypeError("The promise returned by the reader.read() method must fulfill with an object");if(c.done)an(n._readableStreamController);else{const l=c.value;Fn(n._readableStreamController,l)}})}function i(s){try{return de(t.cancel(s))}catch(c){return K(c)}}return n=bi(ui,o,i,0),n}(r.getReader()):function(t){let n;const o=zu(t,"async");function i(){let c;try{c=Ju(o)}catch(l){return K(l)}return ur(de(c),l=>{if(!Be(l))throw new TypeError("The promise returned by the iterator.next() method must fulfill with an object");if(l.done)an(n._readableStreamController);else{const a=l.value;Fn(n._readableStreamController,a)}})}function s(c){const l=o.iterator;let a;try{a=fi(l,"return")}catch(u){return K(u)}return a===void 0?de(void 0):ur(cr(a,l,[c]),u=>{if(!Be(u))throw new TypeError("The promise returned by the iterator.return() method must fulfill with an object")})}return n=bi(ui,i,s,0),n}(r);var e}function Ap(r,e,t){return Rt(r,t),n=>cr(r,e,[n])}function Rp(r,e,t){return Rt(r,t),n=>cr(r,e,[n])}function Cp(r,e,t){return Rt(r,t),n=>zr(r,e,[n])}function xp(r,e){if((r=`${r}`)!="bytes")throw new TypeError(`${e} '${r}' is not a valid enumeration value for ReadableStreamType`);return r}function qc(r,e){fr(r,e);const t=r==null?void 0:r.preventAbort,n=r==null?void 0:r.preventCancel,o=r==null?void 0:r.preventClose,i=r==null?void 0:r.signal;return i!==void 0&&function(s,c){if(!function(l){if(typeof l!="object"||l===null)return!1;try{return typeof l.aborted=="boolean"}catch{return!1}}(s))throw new TypeError(`${c} is not an AbortSignal.`)}(i,`${e} has member 'signal' that`),{preventAbort:!!t,preventCancel:!!n,preventClose:!!o,signal:i}}Object.defineProperties(Pr.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},desiredSize:{enumerable:!0}}),fe(Pr.prototype.close,"close"),fe(Pr.prototype.enqueue,"enqueue"),fe(Pr.prototype.error,"error"),typeof Symbol.toStringTag=="symbol"&&Object.defineProperty(Pr.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultController",configurable:!0});let ze=class{constructor(e={},t={}){e===void 0?e=null:Lu(e,"First parameter");const n=lo(t,"Second parameter"),o=function(i,s){fr(i,s);const c=i,l=c==null?void 0:c.autoAllocateChunkSize,a=c==null?void 0:c.cancel,u=c==null?void 0:c.pull,f=c==null?void 0:c.start,d=c==null?void 0:c.type;return{autoAllocateChunkSize:l===void 0?void 0:qa(l,`${s} has member 'autoAllocateChunkSize' that`),cancel:a===void 0?void 0:Ap(a,c,`${s} has member 'cancel' that`),pull:u===void 0?void 0:Rp(u,c,`${s} has member 'pull' that`),start:f===void 0?void 0:Cp(f,c,`${s} has member 'start' that`),type:d===void 0?void 0:xp(d,`${s} has member 'type' that`)}}(e,"First parameter");if(ls(this),o.type==="bytes"){if(n.size!==void 0)throw new RangeError("The strategy for a byte stream cannot have a size function");(function(i,s,c){const l=Object.create(xr.prototype);let a,u,f;a=s.start!==void 0?()=>s.start(l):()=>{},u=s.pull!==void 0?()=>s.pull(l):()=>de(void 0),f=s.cancel!==void 0?y=>s.cancel(y):()=>de(void 0);const d=s.autoAllocateChunkSize;if(d===0)throw new TypeError("autoAllocateChunkSize must be greater than 0");hc(i,l,a,u,f,c,d)})(this,o,yi(n,0))}else{const i=co(n);(function(s,c,l,a){const u=Object.create(Pr.prototype);let f,d,y;f=c.start!==void 0?()=>c.start(u):()=>{},d=c.pull!==void 0?()=>c.pull(u):()=>de(void 0),y=c.cancel!==void 0?m=>c.cancel(m):()=>de(void 0),Mc(s,u,f,d,y,l,a)})(this,o,yi(n,1),i)}}get locked(){if(!Dr(this))throw sn("locked");return Fr(this)}cancel(e=void 0){return Dr(this)?Fr(this)?K(new TypeError("Cannot cancel a stream that already has a reader")):Mt(this,e):K(sn("cancel"))}getReader(e=void 0){if(!Dr(this))throw sn("getReader");return function(t,n){fr(t,n);const o=t==null?void 0:t.mode;return{mode:o===void 0?void 0:gp(o,`${n} has member 'mode' that`)}}(e,"First parameter").mode===void 0?Cn(this):pc(this)}pipeThrough(e,t={}){if(!Dr(this))throw sn("pipeThrough");Jr(e,1,"pipeThrough");const n=function(i,s){fr(i,s);const c=i==null?void 0:i.readable;Mu(c,"readable","ReadableWritablePair"),ja(c,`${s} has member 'readable' that`);const l=i==null?void 0:i.writable;return Mu(l,"writable","ReadableWritablePair"),_c(l,`${s} has member 'writable' that`),{readable:c,writable:l}}(e,"First parameter"),o=qc(t,"Second parameter");if(Fr(this))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");if(Dn(n.writable))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");return Rn(Bc(this,n.writable,o.preventClose,o.preventAbort,o.preventCancel,o.signal)),n.readable}pipeTo(e,t={}){if(!Dr(this))return K(sn("pipeTo"));if(e===void 0)return K("Parameter 1 is required in 'pipeTo'.");if(!Pn(e))return K(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream"));let n;try{n=qc(t,"Second parameter")}catch(o){return K(o)}return Fr(this)?K(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream")):Dn(e)?K(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream")):Bc(this,e,n.preventClose,n.preventAbort,n.preventCancel,n.signal)}tee(){if(!Dr(this))throw sn("tee");return li(Op(this))}values(e=void 0){if(!Dr(this))throw sn("values");return function(t,n){const o=Cn(t),i=new Ku(o,n),s=Object.create(Yu);return s._asyncIteratorImpl=i,s}(this,function(t,n){return fr(t,n),{preventCancel:!!(t==null?void 0:t.preventCancel)}}(e,"First parameter").preventCancel)}[di](e){return this.values(e)}static from(e){return Tp(e)}};function bi(r,e,t,n=1,o=()=>1){const i=Object.create(ze.prototype);return ls(i),Mc(i,Object.create(Pr.prototype),r,e,t,n,o),i}function jc(r,e,t){const n=Object.create(ze.prototype);return ls(n),hc(n,Object.create(xr.prototype),r,e,t,0,void 0),n}function ls(r){r._state="readable",r._reader=void 0,r._storedError=void 0,r._disturbed=!1}function Dr(r){return!!Be(r)&&!!Object.prototype.hasOwnProperty.call(r,"_readableStreamController")&&r instanceof ze}function Fr(r){return r._reader!==void 0}function Mt(r,e){if(r._disturbed=!0,r._state==="closed")return de(void 0);if(r._state==="errored")return K(r._storedError);wi(r);const t=r._reader;if(t!==void 0&&tn(t)){const n=t._readIntoRequests;t._readIntoRequests=new At,n.forEach(o=>{o._closeSteps(void 0)})}return ur(r._readableStreamController[Da](e),ui)}function wi(r){r._state="closed";const e=r._reader;if(e!==void 0&&(Uu(e),Rr(e))){const t=e._readRequests;e._readRequests=new At,t.forEach(n=>{n._closeSteps()})}}function kc(r,e){r._state="errored",r._storedError=e;const t=r._reader;t!==void 0&&(Ma(t,e),Rr(t)?Wu(t,e):vc(t,e))}function sn(r){return new TypeError(`ReadableStream.prototype.${r} can only be used on a ReadableStream`)}Object.defineProperties(ze,{from:{enumerable:!0}}),Object.defineProperties(ze.prototype,{cancel:{enumerable:!0},getReader:{enumerable:!0},pipeThrough:{enumerable:!0},pipeTo:{enumerable:!0},tee:{enumerable:!0},values:{enumerable:!0},locked:{enumerable:!0}}),fe(ze.from,"from"),fe(ze.prototype.cancel,"cancel"),fe(ze.prototype.getReader,"getReader"),fe(ze.prototype.pipeThrough,"pipeThrough"),fe(ze.prototype.pipeTo,"pipeTo"),fe(ze.prototype.tee,"tee"),fe(ze.prototype.values,"values"),typeof Symbol.toStringTag=="symbol"&&Object.defineProperty(ze.prototype,Symbol.toStringTag,{value:"ReadableStream",configurable:!0}),Object.defineProperty(ze.prototype,di,{value:ze.prototype.values,writable:!0,configurable:!0}),fe(r=>r.byteLength,"size"),fe(()=>1,"size");function Np(r,e,t){return Rt(r,t),n=>cr(r,e,[n])}function Pp(r,e,t){return Rt(r,t),n=>zr(r,e,[n])}function Dp(r,e,t){return Rt(r,t),(n,o)=>cr(r,e,[n,o])}function Fp(r,e,t){return Rt(r,t),n=>cr(r,e,[n])}let Eo=class{constructor(e={},t={},n={}){e===void 0&&(e=null);const o=lo(t,"Second parameter"),i=lo(n,"Third parameter"),s=function(d,y){fr(d,y);const m=d==null?void 0:d.cancel,v=d==null?void 0:d.flush,I=d==null?void 0:d.readableType,S=d==null?void 0:d.start,w=d==null?void 0:d.transform,O=d==null?void 0:d.writableType;return{cancel:m===void 0?void 0:Fp(m,d,`${y} has member 'cancel' that`),flush:v===void 0?void 0:Np(v,d,`${y} has member 'flush' that`),readableType:I,start:S===void 0?void 0:Pp(S,d,`${y} has member 'start' that`),transform:w===void 0?void 0:Dp(w,d,`${y} has member 'transform' that`),writableType:O}}(e,"First parameter");if(s.readableType!==void 0)throw new RangeError("Invalid readableType specified");if(s.writableType!==void 0)throw new RangeError("Invalid writableType specified");const c=yi(i,0),l=co(i),a=yi(o,1),u=co(o);let f;(function(d,y,m,v,I,S){function w(){return y}function O(R){return function(x,L){const F=x._transformStreamController;return x._backpressure?ur(x._backpressureChangePromise,()=>{const j=x._writable;if(j._state==="erroring")throw j._storedError;return Gc(F,L)}):Gc(F,L)}(d,R)}function T(R){return function(x,L){const F=x._transformStreamController;if(F._finishPromise!==void 0)return F._finishPromise;const j=x._readable;F._finishPromise=Pe((W,oe)=>{F._finishPromise_resolve=W,F._finishPromise_reject=oe});const V=F._cancelAlgorithm(L);return Oo(F),st(V,()=>(j._state==="errored"?Bn(F,j._storedError):(Lt(j._readableStreamController,L),hs(F)),null),W=>(Lt(j._readableStreamController,W),Bn(F,W),null)),F._finishPromise}(d,R)}function N(){return function(R){const x=R._transformStreamController;if(x._finishPromise!==void 0)return x._finishPromise;const L=R._readable;x._finishPromise=Pe((j,V)=>{x._finishPromise_resolve=j,x._finishPromise_reject=V});const F=x._flushAlgorithm();return Oo(x),st(F,()=>(L._state==="errored"?Bn(x,L._storedError):(an(L._readableStreamController),hs(x)),null),j=>(Lt(L._readableStreamController,j),Bn(x,j),null)),x._finishPromise}(d)}function D(){return function(R){return So(R,!1),R._backpressureChangePromise}(d)}function B(R){return function(x,L){const F=x._transformStreamController;if(F._finishPromise!==void 0)return F._finishPromise;const j=x._writable;F._finishPromise=Pe((W,oe)=>{F._finishPromise_resolve=W,F._finishPromise_reject=oe});const V=F._cancelAlgorithm(L);return Oo(F),st(V,()=>(j._state==="errored"?Bn(F,j._storedError):(gi(j._writableStreamController,L),ds(x),hs(F)),null),W=>(gi(j._writableStreamController,W),ds(x),Bn(F,W),null)),F._finishPromise}(d,R)}d._writable=function(R,x,L,F,j=1,V=()=>1){const W=Object.create(rn.prototype);return wc(W),Rc(W,Object.create(mi.prototype),R,x,L,F,j,V),W}(w,O,N,T,m,v),d._readable=bi(w,D,B,I,S),d._backpressure=void 0,d._backpressureChangePromise=void 0,d._backpressureChangePromise_resolve=void 0,So(d,!0),d._transformStreamController=void 0})(this,Pe(d=>{f=d}),a,u,c,l),function(d,y){const m=Object.create(un.prototype);let v,I,S;v=y.transform!==void 0?w=>y.transform(w,m):w=>{try{return Hc(m,w),de(void 0)}catch(O){return K(O)}},I=y.flush!==void 0?()=>y.flush(m):()=>de(void 0),S=y.cancel!==void 0?w=>y.cancel(w):()=>de(void 0),function(w,O,T,N,D){O._controlledTransformStream=w,w._transformStreamController=O,O._transformAlgorithm=T,O._flushAlgorithm=N,O._cancelAlgorithm=D,O._finishPromise=void 0,O._finishPromise_resolve=void 0,O._finishPromise_reject=void 0}(d,m,v,I,S)}(this,s),s.start!==void 0?f(s.start(this._transformStreamController)):f(void 0)}get readable(){if(!$c(this))throw Vc("readable");return this._readable}get writable(){if(!$c(this))throw Vc("writable");return this._writable}};function $c(r){return!!Be(r)&&!!Object.prototype.hasOwnProperty.call(r,"_transformStreamController")&&r instanceof Eo}function Wc(r,e){Lt(r._readable._readableStreamController,e),fs(r,e)}function fs(r,e){Oo(r._transformStreamController),gi(r._writable._writableStreamController,e),ds(r)}function ds(r){r._backpressure&&So(r,!1)}function So(r,e){r._backpressureChangePromise!==void 0&&r._backpressureChangePromise_resolve(),r._backpressureChangePromise=Pe(t=>{r._backpressureChangePromise_resolve=t}),r._backpressure=e}Object.defineProperties(Eo.prototype,{readable:{enumerable:!0},writable:{enumerable:!0}}),typeof Symbol.toStringTag=="symbol"&&Object.defineProperty(Eo.prototype,Symbol.toStringTag,{value:"TransformStream",configurable:!0});class un{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!Io(this))throw To("desiredSize");return cs(this._controlledTransformStream._readable._readableStreamController)}enqueue(e=void 0){if(!Io(this))throw To("enqueue");Hc(this,e)}error(e=void 0){if(!Io(this))throw To("error");var t;t=e,Wc(this._controlledTransformStream,t)}terminate(){if(!Io(this))throw To("terminate");(function(e){const t=e._controlledTransformStream;an(t._readable._readableStreamController);const n=new TypeError("TransformStream terminated");fs(t,n)})(this)}}function Io(r){return!!Be(r)&&!!Object.prototype.hasOwnProperty.call(r,"_controlledTransformStream")&&r instanceof un}function Oo(r){r._transformAlgorithm=void 0,r._flushAlgorithm=void 0,r._cancelAlgorithm=void 0}function Hc(r,e){const t=r._controlledTransformStream,n=t._readable._readableStreamController;if(!Un(n))throw new TypeError("Readable side is not in a state that permits enqueue");try{Fn(n,e)}catch(i){throw fs(t,i),t._readable._storedError}(function(i){return!Lc(i)})(n)!==t._backpressure&&So(t,!0)}function Gc(r,e){return ur(r._transformAlgorithm(e),void 0,t=>{throw Wc(r._controlledTransformStream,t),t})}function To(r){return new TypeError(`TransformStreamDefaultController.prototype.${r} can only be used on a TransformStreamDefaultController`)}function hs(r){r._finishPromise_resolve!==void 0&&(r._finishPromise_resolve(),r._finishPromise_resolve=void 0,r._finishPromise_reject=void 0)}function Bn(r,e){r._finishPromise_reject!==void 0&&(Rn(r._finishPromise),r._finishPromise_reject(e),r._finishPromise_resolve=void 0,r._finishPromise_reject=void 0)}function Vc(r){return new TypeError(`TransformStream.prototype.${r} can only be used on a TransformStream`)}Object.defineProperties(un.prototype,{enqueue:{enumerable:!0},error:{enumerable:!0},terminate:{enumerable:!0},desiredSize:{enumerable:!0}}),fe(un.prototype.enqueue,"enqueue"),fe(un.prototype.error,"error"),fe(un.prototype.terminate,"terminate"),typeof Symbol.toStringTag=="symbol"&&Object.defineProperty(un.prototype,Symbol.toStringTag,{value:"TransformStreamDefaultController",configurable:!0});var Up=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)o.hasOwnProperty(i)&&(n[i]=o[i])},r(e,t)};return function(e,t){r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),Ao=function(){return Ao=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Ao.apply(this,arguments)},Bp=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Lp=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}};function Mp(){if(typeof wx>"u"||typeof Page>"u"||!wx.getSystemInfoSync||!wx.getStorageSync||!wx.setStorageSync||!wx.connectSocket||!wx.request)return!1;try{if(!wx.getSystemInfoSync()||wx.getSystemInfoSync().AppPlatform==="qq")return!1}catch{return!1}return!0}function qp(){return typeof App>"u"&&typeof getApp>"u"&&!wx.onAppHide&&!wx.offAppHide&&!wx.onAppShow&&!wx.offAppShow}var zc="Error when aborting requestTask",jp=function(r){Up(e,r);function e(t){t===void 0&&(t={});var n=r.call(this)||this,o=t.timeout,i=t.timeoutMsg,s=t.restrictedMethods;return n._timeout=o||0,n._timeoutMsg=i||"请求超时",n._restrictedMethods=s||["get","post","upload","download"],n}return e.prototype.post=function(t){var n=this;return new Promise(function(o,i){var s=t.url,c=t.data,l=t.headers,a=wx.request({url:Qi("https:",s),data:c,timeout:n._timeout,method:"POST",header:l,success:function(u){o(u)},fail:function(u){i(u)},complete:function(u){if(!(!u||!u.errMsg)&&!(!n._timeout||n._restrictedMethods.indexOf("post")===-1)){var f=u.errMsg;if(f==="request:fail timeout"){console.warn(n._timeoutMsg);try{a.abort()}catch{}}}}})})},e.prototype.upload=function(t){var n=this,o=this;return new Promise(function(i){return Bp(n,void 0,void 0,function(){var s,c,l,a,u,f;return Lp(this,function(d){return s=t.url,c=t.file,l=t.data,a=t.headers,u=t.onUploadProgress,f=wx.uploadFile({url:s,filePath:c,name:"file",formData:Ao({},l),header:a,timeout:this._timeout,success:function(y){var m={statusCode:y.statusCode,data:y.data||{}};y.statusCode===200&&l.success_action_status&&(m.statusCode=parseInt(l.success_action_status,10)),i(m)},fail:function(y){i(y)},complete:function(y){if(!(!y||!y.errMsg)&&!(!o._timeout||o._restrictedMethods.indexOf("upload")===-1)){var m=y.errMsg;if(m==="request:fail timeout"){console.warn(o._timeoutMsg);try{f.abort()}catch{}}}}}),u&&f.onProgressUpdate(function(y){u(y)}),[2]})})})},e.prototype.download=function(t){var n=this,o=this;return new Promise(function(i,s){var c=t.url,l=t.headers,a=wx.downloadFile({url:Qi("https:",c),header:l,timeout:n._timeout,success:function(u){u.statusCode===200&&u.tempFilePath?i({statusCode:200,tempFilePath:u.tempFilePath}):i(u)},fail:function(u){s(u)},complete:function(u){if(!(!u||!u.errMsg)&&!(!o._timeout||o._restrictedMethods.indexOf("download")===-1)){var f=u.errMsg;if(f==="request:fail timeout"){console.warn(o._timeoutMsg);try{a.abort()}catch{}}}}})})},e.prototype.fetch=function(t){var n=t.url,o=t.body,i=t.enableAbort,s=t.headers,c=t.method,l=t.stream,a=l===void 0?!1:l,u=t.signal,f=t.timeout,d=this,y=f??this._timeout,m=null,v=new ze({start:function(I){m=I},cancel:function(){m=null}});return new Promise(function(I,S){a&&I({data:v});var w=wx.request({url:Qi("https:",n),data:o,timeout:y,method:c.toUpperCase(),header:s,success:function(T){var N;(N=m)===null||N===void 0||N.close(),!a&&I(T)},fail:function(T){var N;if((N=m)===null||N===void 0||N.close(),S(T),a)throw T},complete:function(T){if(!(!T||!T.errMsg)&&!(!y||d._restrictedMethods.indexOf("post")===-1||!i)){var N=T.errMsg;if(N==="request:fail timeout"){console.warn(d._timeoutMsg);try{w.abort()}catch(D){console.warn(zc,D)}}}},enableChunked:a});if(w.onChunkReceived(function(T){var N;(N=m)===null||N===void 0||N.enqueue(new Uint8Array(T.data))}),u){var O=function(){try{w.abort()}catch(T){console.warn(zc,T)}};u.aborted?O():u.addEventListener("abort",function(){return O()})}})},e}(Ea),kp={setItem:function(r,e){wx.setStorageSync(r,e)},getItem:function(r){return wx.getStorageSync(r)},removeItem:function(r){wx.removeStorageSync(r)},clear:function(){wx.clearStorageSync()}},$p=function(){function r(e,t){t===void 0&&(t={});var n=wx.connectSocket(Ao({url:e},t)),o={set onopen(i){n.onOpen(i)},set onmessage(i){n.onMessage(i)},set onclose(i){n.onClose(i)},set onerror(i){n.onError(i)},send:function(i){return n.send({data:i})},close:function(i,s){return n.close({code:i,reason:s})},get readyState(){return n.readyState},CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3};return o}return r}();function Wp(){var r={root:{},reqClass:jp,wsClass:$p,localStorage:kp,primaryStorage:Yi.local,getAppSign:function(){var e=wx.getAccountInfoSync();return qp()?e&&e.plugin?e.plugin.appId:"":e&&e.miniProgram?e.miniProgram.appId:""}};return r}var dr={genAdapter:Wp,isMatch:Mp,runtime:"wx_mp"},Ro=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return r.concat(i||Array.prototype.slice.call(e))},Co=at,Jc={};function Hp(r,e){var t=e.name,n=e.namespace,o=e.entity,i=e.injectEvents,s=e.IIFE,c=s===void 0?!1:s;if(Jc[t]||n&&r[n])throw new Error(JSON.stringify({code:Co.INVALID_OPERATION,msg:"Duplicate component ".concat(t)}));if(c){if(!o||typeof o!="function")throw new Error(JSON.stringify({code:Co.INVALID_PARAMS,msg:"IIFE component's entity must be a function"}));o.call(r)}if(Jc[t]=e,n?r.prototype[n]=o:Kc(r.prototype,o),i){var l=i.bus,a=i.events;if(!l||!a||a.length===0)return;var u=r.prototype.fire||function(){};r.prototype.events||(r.prototype.events={});var f=r.prototype.events||{};f[t]?r.prototype.events[t].events=Ro(Ro([],r.prototype.events[t].events,!0),a,!0):r.prototype.events[t]={bus:l,events:a},r.prototype.fire=function(d,y){u(d,y);for(var m=Object.keys(this.events),v=0,I=m;v<I.length;v++){var S=I[v],w=this.events[S],O=w.bus,T=w.events;if(T.includes(d)){O.fire(d,y);break}}}}}function Kc(r,e){if(!(e instanceof Object))return e;switch(e.constructor){case Date:{var t=e;return new Date(t.getTime())}case Object:r===void 0&&(r={});break;case Array:r=[];break;default:return e}for(var n=Object.keys(e),o=0,i=n;o<i.length;o++){var s=i[o];Object.prototype.hasOwnProperty.call(e,s)&&(r[s]=Kc(r[s],e[s]))}return r}function Gp(r,e){var t=e.entity,n=e.target;if(Object.prototype.hasOwnProperty.call(r,n))throw new Error(JSON.stringify({code:Co.INVALID_OPERATION,msg:"target:".concat(n," is not exist")}));var o=r.prototype[n];if(typeof o!="function")throw new Error(JSON.stringify({code:Co.INVALID_OPERATION,msg:"target:".concat(n," is not a function which is the only type supports hook")}));r.prototype[n]=function(){for(var i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];return t.call.apply(t,Ro([this],i,!1)),o.call.apply(o,Ro([this],i,!1))}}var Ur={},Ln=function(){return Ln=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Ln.apply(this,arguments)},Vp="user_info",Yc=ip,ps={},ys={};function Qc(r){var e=r.env,t=r.platformInfo,n="".concat(Vp,"_").concat(e),o={userInfoKey:n};ps[e]=ps[e]||new Yc(Ln(Ln({},r),{keys:o,platformInfo:t})),ys[e]=ys[e]||new Yc(Ln(Ln({},r),{keys:o,platformInfo:t,persistence:"local"}))}function zp(r){return ps[r]}function Xc(r){return ys[r]}var xo=function(){return xo=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},xo.apply(this,arguments)},Jp=$h,Kp=Wh,Zc="",el="@cloudbase/js-sdk";function Yp(r){Zc=r}function ms(){return Zc}function Qp(r){el=r,Jp(r)}function Xp(){return el}var Zp="2020-01-10",tl=[],ey=["env","endPointKey","region"],rl="https:";function nl(r){return tl.find(function(e){return ey.filter(function(t){return r[t]!=null}).every(function(t){return e[t]===r[t]})})}function No(r){var e,t,n=nl(r);n?(r.baseUrl!=null&&(n.baseUrl=r.baseUrl),r.protocol!=null&&(n.protocol=r.protocol)):tl.push(xo(xo({},r),{protocol:(e=r.protocol)!==null&&e!==void 0?e:rl})),r.endPointKey==="CLOUD_API"&&Kp((t=r.protocol)!==null&&t!==void 0?t:rl)}function gs(r,e,t){return nl({env:r,endPointKey:e,region:t})}function ty(r,e){No({endPointKey:"GATEWAY",env:r,baseUrl:"//".concat(r,".api.tcloudbasegateway.com/v1"),protocol:e})}function ry(r,e,t){var n=e?"//".concat(r,".").concat(e,".tcb-api.tencentcloudapi.com/web"):"//".concat(r,".ap-shanghai.tcb-api.tencentcloudapi.com/web");No({env:r,region:e,baseUrl:n,protocol:t,endPointKey:"CLOUD_API"})}function il(r){var e=gs(r,"CLOUD_API"),t=e.protocol,n=e.baseUrl,o="".concat(t).concat(n);return o.match(/(http(s)?:)?\/\/([^/?#]*)/)[0]}var ol;(function(r){r.NULL="NULL",r.ANONYMOUS="ANONYMOUS",r.WECHAT="WECHAT",r.WECHAT_PUBLIC="WECHAT-PUBLIC",r.WECHAT_OPEN="WECHAT-OPEN",r.CUSTOM="CUSTOM",r.EMAIL="EMAIL",r.USERNAME="USERNAME",r.PHONE="PHONE"})(ol||(ol={}));var $e=function(){return $e=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},$e.apply(this,arguments)},hr=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},pr=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},ny=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(r);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(r,n[o])&&(t[n[o]]=r[n[o]]);return t},iy=at,oy=Jh,ay=Ou,al=Tu,sy=["auth.getJwt","auth.logout","auth.signInWithTicket","auth.signInAnonymously","auth.signIn","auth.fetchAccessTokenWithRefreshToken","auth.signUpWithEmailAndPassword","auth.activateEndUserMail","auth.sendPasswordResetEmail","auth.resetPasswordWithToken","auth.isUsernameRegistered"];function vs(r,e,t){var n=r[e];r[e]=function(o){var i={},s={};t.forEach(function(l){var a=l.call(r,o),u=a.data,f=a.headers;Object.assign(i,u),Object.assign(s,f)});var c=o.data;return c&&function(){if(ay(c)){Object.keys(i).forEach(function(l){c.append(l,i[l])});return}o.data=$e($e({},c),i)}(),o.headers=$e($e({},o.headers||{}),s),n.call(r,o)}}function _s(){var r=oy();return{data:{seqId:r},headers:{"X-SDK-Version":"@cloudbase/js-sdk/".concat(ms()),"x-seqid":r}}}var uy=function(){function r(e){this.throwWhenRequestFail=!1,this.config=e;var t={timeout:this.config.timeout,timeoutMsg:"[@cloudbase/js-sdk] 请求在".concat(this.config.timeout/1e3,"s内未完成,已中断"),restrictedMethods:["post","put"]};this.reqClass=new Ur.adapter.reqClass(t),this.throwWhenRequestFail=e.throw||!1,this.localCache=Xc(this.config.env),vs(this.reqClass,"post",[_s]),vs(this.reqClass,"upload",[_s]),vs(this.reqClass,"download",[_s])}return r.prototype.post=function(e){return hr(this,void 0,void 0,function(){var t;return pr(this,function(n){switch(n.label){case 0:return[4,this.reqClass.post(e)];case 1:return t=n.sent(),[2,t]}})})},r.prototype.upload=function(e){return hr(this,void 0,void 0,function(){var t;return pr(this,function(n){switch(n.label){case 0:return[4,this.reqClass.upload(e)];case 1:return t=n.sent(),[2,t]}})})},r.prototype.download=function(e){return hr(this,void 0,void 0,function(){var t;return pr(this,function(n){switch(n.label){case 0:return[4,this.reqClass.download(e)];case 1:return t=n.sent(),[2,t]}})})},r.prototype.getBaseEndPoint=function(){return il(this.config.env)},r.prototype.getOauthAccessTokenV2=function(e){return hr(this,void 0,void 0,function(){var t,n;return pr(this,function(o){switch(o.label){case 0:return[4,e.getAccessToken()];case 1:return t=o.sent(),[4,e.getCredentials()];case 2:return n=o.sent(),[2,{accessToken:t,accessTokenExpire:new Date(n.expires_at).getTime()}]}})})},r.prototype.request=function(e,t,n){var o,i;return hr(this,void 0,void 0,function(){var s,c,l,a,u,f,d,y,m,v,I,S,w,O,T,N,D,B,R,x;return pr(this,function(L){switch(L.label){case 0:if(s="x-tcb-trace_".concat(this.config.env),c="application/x-www-form-urlencoded",l=$e({action:e,dataVersion:Zp,env:this.config.env},t),sy.indexOf(e)!==-1)return[3,2];if(a=this.config._fromApp,!a.oauthInstance)throw new Error("you can't request without auth");return u=a.oauthInstance,f=u.oauth2client,d=l,[4,this.getOauthAccessTokenV2(f)];case 1:d.access_token=L.sent().accessToken,L.label=2;case 2:return e==="storage.uploadFile"?(y=new FormData,Object.keys(y).forEach(function(F){Object.prototype.hasOwnProperty.call(y,F)&&y[F]!==void 0&&y.append(F,l[F])}),c="multipart/form-data"):(c="application/json;charset=UTF-8",y={},Object.keys(l).forEach(function(F){l[F]!==void 0&&(y[F]=l[F])})),m={headers:{"content-type":c}},n!=null&&n.onUploadProgress&&(m.onUploadProgress=n.onUploadProgress),this.config.region&&(m.headers["X-TCB-Region"]=this.config.region),v=this.localCache.getStore(s),v&&(m.headers["X-TCB-Trace"]=v),I=(n==null?void 0:n.parse)!==void 0?n.parse:t.parse,S=(n==null?void 0:n.inQuery)!==void 0?n.inQuery:t.inQuery,w=(n==null?void 0:n.search)!==void 0?n.search:t.search,O=$e($e({},(n==null?void 0:n.defaultQuery)||{}),{env:this.config.env}),I&&(O.parse=!0),S&&(O=$e($e({},S),O)),T=gs(this.config.env,"CLOUD_API"),N=T.baseUrl,D=T.protocol,n.pathname?B=al(D,"".concat((o=il(this.config.env))===null||o===void 0?void 0:o.replace(/^https?:/,""),"/").concat(n.pathname),O):B=al(D,N,O),w&&(B+=w),[4,this.post($e({url:B,data:y},m))];case 3:if(R=L.sent(),x=(i=R.header)===null||i===void 0?void 0:i["x-tcb-trace"],x&&this.localCache.setStore(s,x),Number(R.status)!==200&&Number(R.statusCode)!==200||!R.data)throw new Error("network request error");return[2,R]}})})},r.prototype.fetch=function(e){var t,n,o,i,s,c,l,a;return hr(this,void 0,void 0,function(){var u,f,d,y,m,v,I,S,w=this;return pr(this,function(O){switch(O.label){case 0:u=e.token,f=e.headers,d=f===void 0?{}:f,y=ny(e,["token","headers"]),m=function(){return hr(w,void 0,void 0,function(){var T,N,D;return pr(this,function(B){switch(B.label){case 0:if(u!=null)return[2,u];if(T=this.config._fromApp,!T.oauthInstance)throw new Error("you can't request without auth");return N=T.oauthInstance,D=N.oauth2client,[4,this.getOauthAccessTokenV2(D)];case 1:return[2,B.sent().accessToken]}})})},v=function(){return hr(w,void 0,void 0,function(){var T,N,D,B,R;return pr(this,function(x){switch(x.label){case 0:return N=(T=this.reqClass).fetch,B={},R={"X-SDK-Version":"@cloudbase/js-sdk/".concat(ms())},D="Bearer ".concat,[4,m()];case 1:return[2,N.apply(T,[$e.apply(void 0,[(B.headers=$e.apply(void 0,[(R.Authorization=D.apply("Bearer ",[x.sent()]),R),d]),B),y])])]}})})},O.label=1;case 1:return O.trys.push([1,3,,6]),[4,v()];case 2:return I=O.sent(),[2,I];case 3:if(S=O.sent(),(S==null?void 0:S.code)!=="ACCESS_TOKEN_EXPIRED")return[3,5];if(typeof((i=(o=(n=(t=this.config)===null||t===void 0?void 0:t._fromApp)===null||n===void 0?void 0:n.oauthInstance)===null||o===void 0?void 0:o.authApi)===null||i===void 0?void 0:i.refreshTokenForce)!="function")throw S;return[4,(a=(l=(c=(s=this.config)===null||s===void 0?void 0:s._fromApp)===null||c===void 0?void 0:c.oauthInstance)===null||l===void 0?void 0:l.authApi)===null||a===void 0?void 0:a.refreshTokenForce()];case 4:return O.sent(),[2,v()];case 5:throw S;case 6:return[2]}})})},r.prototype.send=function(e,t,n){return t===void 0&&(t={}),n===void 0&&(n={}),hr(this,void 0,void 0,function(){var o;return pr(this,function(i){switch(i.label){case 0:return[4,this.request(e,t,$e($e({},n),{onUploadProgress:t.onUploadProgress}))];case 1:if(o=i.sent(),o.data.code&&this.throwWhenRequestFail)throw new Error(JSON.stringify({code:iy.OPERATION_FAIL,msg:"[".concat(o.data.code,"] ").concat(o.data.message)}));return[2,o.data]}})})},r}(),sl={};function cy(r){sl[r.env]=new uy($e($e({},r),{throw:!0}))}function ly(r){return sl[r]}var Po=function(){return Po=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Po.apply(this,arguments)},ul=function(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var c=r.length-1;c>=0;c--)(s=r[c])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i},Mn=function(r,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,e)},fy=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},dy=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},hy=ep,py=tp,Do=at,cl=Ki,ll=An,fl=Xi,yy={timeout:15e3,persistence:"local"},dl=1e3*60*10,hl=100,pl={},my=function(){function r(e){this.cloudbaseConfig=e||this.cloudbaseConfig,this.authInstance=null,this.oauthInstance=null,this.version=ms()}return Object.defineProperty(r.prototype,"config",{get:function(){return this.cloudbaseConfig},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"platform",{get:function(){return Ur},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"cache",{get:function(){return zp(this.cloudbaseConfig.env)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"localCache",{get:function(){return Xc(this.cloudbaseConfig.env)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"request",{get:function(){return ly(this.cloudbaseConfig.env)},enumerable:!1,configurable:!0}),r.prototype.init=function(e){var t;if(!e.env)throw new Error(JSON.stringify({code:Do.INVALID_PARAMS,msg:"env must not be specified"}));Ur.adapter||this.useDefaultAdapter();var n={timeout:e.timeout||5e3,timeoutMsg:"[".concat(Xp(),"][REQUEST TIMEOUT] request had been abort since didn't finished within").concat(e.timeout/1e3,"s")};this.requestClient=new Ur.adapter.reqClass(n),this.cloudbaseConfig=Po(Po({},yy),e),this.cloudbaseConfig.timeout=this.formatTimeout(this.cloudbaseConfig.timeout);var o=this.cloudbaseConfig,i=o.env,s=o.persistence,c=o.debug,l=o.timeout,a=o.oauthClient;Qc({env:i,persistence:s,debug:c,platformInfo:this.platform}),ry(i,e.region||""),ty(i);var u=new r(this.cloudbaseConfig);return cy({env:i,region:e.region||"",timeout:l,oauthClient:a,_fromApp:u}),u.requestClient=this.requestClient,(t=this===null||this===void 0?void 0:this.fire)===null||t===void 0||t.call(this,"cloudbase_init",u),u},r.prototype.updateConfig=function(e){var t=e.persistence,n=e.debug;this.cloudbaseConfig.persistence=t,this.cloudbaseConfig.debug=n,Qc({env:this.cloudbaseConfig.env,persistence:t,debug:n,platformInfo:this.platform})},r.prototype.registerExtension=function(e){pl[e.name]=e},r.prototype.invokeExtension=function(e,t){return fy(this,void 0,void 0,function(){var n;return dy(this,function(o){switch(o.label){case 0:if(n=pl[e],!n)throw new Error(JSON.stringify({code:Do.INVALID_PARAMS,msg:"extension:".concat(e," must be registered before invoke")}));return[4,n.invoke(t,this)];case 1:return[2,o.sent()]}})})},r.prototype.useAdapters=function(e){var t=hy(e)||{},n=t.adapter,o=t.runtime;n&&(Ur.adapter=n),o&&(Ur.runtime=o)},r.prototype.registerHook=function(e){Gp(r,e)},r.prototype.registerComponent=function(e){Hp(r,e)},r.prototype.registerVersion=function(e){Yp(e),this.version=e},r.prototype.registerSdkName=function(e){Qp(e)},r.prototype.registerEndPoint=function(e,t){No({baseUrl:e,protocol:t,env:this.config.env,endPointKey:"CLOUD_API"})},r.prototype.registerEndPointWithKey=function(e){No({env:this.config.env,endPointKey:e.key,baseUrl:e.url,protocol:e.protocol})},r.prototype.getEndPointWithKey=function(e){var t=gs(this.config.env,e);return{BASE_URL:t.baseUrl,PROTOCOL:t.protocol}},r.prototype.useDefaultAdapter=function(){var e=py(),t=e.adapter,n=e.runtime;Ur.adapter=t,Ur.runtime=n},r.prototype.formatTimeout=function(e){switch(!0){case e>dl:return ll(Do.INVALID_PARAMS,"timeout is greater than maximum value[10min]"),dl;case e<hl:return ll(Do.INVALID_PARAMS,"timeout is less than maximum value[100ms]"),hl;default:return e}},ul([fl({mode:"sync",title:"Cloudbase 初始化失败",messages:["请确认以下各项:"," 1 - 调用 cloudbase.init() 的语法或参数是否正确"," 2 - 如果是非浏览器环境,是否配置了安全应用来源(https://docs.cloudbase.net/api-reference/webv3/adapter#%E7%AC%AC-2-%E6%AD%A5%E9%85%8D%E7%BD%AE%E5%AE%89%E5%85%A8%E5%BA%94%E7%94%A8%E6%9D%A5%E6%BA%90)","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(cl)]}),Mn("design:type",Function),Mn("design:paramtypes",[Object]),Mn("design:returntype",r)],r.prototype,"init",null),ul([fl({title:"调用扩展能力失败",messages:["请确认以下各项:"," 1 - 调用 invokeExtension() 的语法或参数是否正确"," 2 - 被调用的扩展能力是否已经安装并通过 registerExtension() 注册","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(cl)]}),Mn("design:type",Function),Mn("design:paramtypes",[String,Object]),Mn("design:returntype",Promise)],r.prototype,"invokeExtension",null),r}(),bt=new my;bt.useAdapters(dr);var ie;(function(r){r.AUTH_SIGN_UP_URL="/auth/v1/signup",r.AUTH_TOKEN_URL="/auth/v1/token",r.AUTH_REVOKE_URL="/auth/v1/revoke",r.WEDA_USER_URL="/auth/v1/plugin/weda/userinfo",r.AUTH_RESET_PASSWORD="/auth/v1/reset",r.AUTH_GET_DEVICE_CODE="/auth/v1/device/code",r.CHECK_USERNAME="/auth/v1/checkUsername",r.CHECK_IF_USER_EXIST="/auth/v1/checkIfUserExist",r.GET_PROVIDER_TYPE="/auth/v1/mgr/provider/providerSubType",r.AUTH_SIGN_IN_URL="/auth/v1/signin",r.AUTH_SIGN_IN_ANONYMOUSLY_URL="/auth/v1/signin/anonymously",r.AUTH_SIGN_IN_WITH_PROVIDER_URL="/auth/v1/signin/with/provider",r.AUTH_SIGN_IN_WITH_WECHAT_URL="/auth/v1/signin/wechat/noauth",r.AUTH_SIGN_IN_CUSTOM="/auth/v1/signin/custom",r.PROVIDER_TOKEN_URL="/auth/v1/provider/token",r.PROVIDER_URI_URL="/auth/v1/provider/uri",r.USER_ME_URL="/auth/v1/user/me",r.AUTH_SIGNOUT_URL="/auth/v1/user/signout",r.USER_QUERY_URL="/auth/v1/user/query",r.USER_PRIFILE_URL="/auth/v1/user/profile",r.USER_BASIC_EDIT_URL="/auth/v1/user/basic/edit",r.USER_TRANS_BY_PROVIDER_URL="/auth/v1/user/trans/by/provider",r.PROVIDER_LIST="/auth/v1/user/provider",r.PROVIDER_BIND_URL="/auth/v1/user/provider/bind",r.PROVIDER_UNBIND_URL="/auth/v1/user/provider",r.CHECK_PWD_URL="/auth/v1/user/sudo",r.SUDO_URL="/auth/v1/user/sudo",r.BIND_CONTACT_URL="/auth/v1/user/contact",r.AUTH_SET_PASSWORD="/auth/v1/user/password",r.AUTHORIZE_DEVICE_URL="/auth/v1/user/device/authorize",r.AUTHORIZE_URL="/auth/v1/user/authorize",r.AUTHORIZE_INFO_URL="/auth/v1/user/authorize/info",r.AUTHORIZED_DEVICES_DELETE_URL="/auth/v1/user/authorized/devices/",r.AUTH_REVOKE_ALL_URL="/auth/v1/user/revoke/all",r.GET_USER_BEHAVIOR_LOG="/auth/v1/user/security/history",r.VERIFICATION_URL="/auth/v1/verification",r.VERIFY_URL="/auth/v1/verification/verify",r.CAPTCHA_DATA_URL="/auth/v1/captcha/data",r.VERIFY_CAPTCHA_DATA_URL="/auth/v1/captcha/data/verify",r.GET_CAPTCHA_URL="/auth/v1/captcha/init",r.GET_MINIPROGRAM_QRCODE="/auth/v1/qrcode/generate",r.GET_MINIPROGRAM_QRCODE_STATUS="/auth/v1/qrcode/get/status"})(ie||(ie={}));var qn;(function(r){r.AUTH_SIGN_IN_URL="/auth/v2/signin/username",r.AUTH_TOKEN_URL="/auth/v2/token",r.USER_ME_URL="/auth/v2/user/me",r.VERIFY_URL="/auth/v2/signin/verificationcode",r.AUTH_SIGN_IN_WITH_PROVIDER_URL="/auth/v2/signin/with/provider",r.AUTH_PUBLIC_KEY="/auth/v2/signin/publichkey",r.AUTH_RESET_PASSWORD="/auth/v2/signin/password/update"})(qn||(qn={}));var yl;(function(r){r.REGISTER="REGISTER",r.SIGN_IN="SIGN_IN",r.PASSWORD_RESET="PASSWORD_RESET",r.EMAIL_ADDRESS_CHANGE="EMAIL_ADDRESS_CHANGE",r.PHONE_NUMBER_CHANGE="PHONE_NUMBER_CHANGE"})(yl||(yl={}));var et;(function(r){r.UNREACHABLE="unreachable",r.LOCAL="local",r.CANCELLED="cancelled",r.UNKNOWN="unknown",r.UNAUTHENTICATED="unauthenticated",r.RESOURCE_EXHAUSTED="resource_exhausted",r.FAILED_PRECONDITION="failed_precondition",r.INVALID_ARGUMENT="invalid_argument",r.DEADLINE_EXCEEDED="deadline_exceeded",r.NOT_FOUND="not_found",r.ALREADY_EXISTS="already_exists",r.PERMISSION_DENIED="permission_denied",r.ABORTED="aborted",r.OUT_OF_RANGE="out_of_range",r.UNIMPLEMENTED="unimplemented",r.INTERNAL="internal",r.UNAVAILABLE="unavailable",r.DATA_LOSS="data_loss",r.INVALID_PASSWORD="invalid_password",r.PASSWORD_NOT_SET="password_not_set",r.INVALID_STATUS="invalid_status",r.USER_PENDING="user_pending",r.USER_BLOCKED="user_blocked",r.INVALID_VERIFICATION_CODE="invalid_verification_code",r.TWO_FACTOR_REQUIRED="two_factor_required",r.INVALID_TWO_FACTOR="invalid_two_factor",r.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",r.UNDER_REVIEW="under_review",r.INVALID_REQUEST="invalid_request",r.UNAUTHORIZED_CLIENT="unauthorized_client",r.ACCESS_DENIED="access_denied",r.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",r.INVALID_SCOPE="invalid_scope",r.INVALID_GRANT="invalid_grant",r.SERVER_ERROR="server_error",r.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",r.INTERACTION_REQUIRED="interaction_required",r.LOGIN_REQUIRED="login_required",r.ACCOUNT_SELECTION_REQUIRED="account_selection_required",r.CONSENT_REQUIRED="consent_required",r.INVALID_REQUEST_URI="invalid_request_uri",r.INVALID_REQUEST_OBJECT="invalid_request_object",r.REQUEST_NOT_SUPPORTED="request_not_supported",r.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",r.REGISTRATION_NOT_SUPPORTED="registration_not_supported",r.CAPTCHA_REQUIRED="captcha_required",r.CAPTCHA_INVALID="captcha_invalid"})(et||(et={}));var ml;(function(r){r.CLIENT_ID="client_id",r.CLIENT_SECRET="client_secret",r.RESPONSE_TYPE="response_type",r.SCOPE="scope",r.STATE="state",r.REDIRECT_URI="redirect_uri",r.ERROR="error",r.ERROR_DESCRIPTION="error_description",r.ERROR_URI="error_uri",r.GRANT_TYPE="grant_type",r.CODE="code",r.ACCESS_TOKEN="access_token",r.TOKEN_TYPE="token_type",r.EXPIRES_IN="expires_in",r.USERNAME="username",r.PASSWORD="password",r.REFRESH_TOKEN="refresh_token"})(ml||(ml={}));function gl(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,r=>{const e=Math.random()*16|0;return(r==="x"?e:e&3|8).toString(16)})}const bs=r=>{const e=n=>{for(const o in r)r.hasOwnProperty(o)&&(n[o]=bs(r[o]));return n},t=r==null?"NullOrUndefined":Object.prototype.toString.call(r).slice(8,-1);if(["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(t))return r.slice();switch(t){case"Object":return e(Object.create(Object.getPrototypeOf(r)));case"Array":return e([]);case"Date":return new Date(r.valueOf());case"RegExp":return new RegExp(r.source,(r.global?"g":"")+(r.ignoreCase?"i":"")+(r.multiline?"m":"")+(r.sticky?"y":"")+(r.unicode?"u":""));default:return r}},vl=r=>{const e=/^(?:http(s)?:\/\/[^\/]+)?(\/[^\?#]*)/,t=r.match(e);return t&&t[2]||""};class _l{constructor(e){this.clientId=(e==null?void 0:e.clientId)||"",globalThis.jsSdkFnPromiseMap=globalThis.jsSdkFnPromiseMap||new Map}async run(e,t){e=`${this.clientId}_${e}`;let n=globalThis.jsSdkFnPromiseMap.get(e);return n||(n=new Promise((o,i)=>{(async()=>{try{await this.runIdlePromise();const s=t();o(await s)}catch(s){i(s)}finally{globalThis.jsSdkFnPromiseMap.delete(e)}})()}),globalThis.jsSdkFnPromiseMap.set(e,n)),n}runIdlePromise(){return Promise.resolve()}}const Fo="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function gy(r){r=String(r);let e,t,n,o,i="",s=0;const c=r.length%3;for(;s<r.length;){if((t=r.charCodeAt(s++))>255||(n=r.charCodeAt(s++))>255||(o=r.charCodeAt(s++))>255)throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");e=t<<16|n<<8|o,i+=Fo.charAt(e>>18&63)+Fo.charAt(e>>12&63)+Fo.charAt(e>>6&63)+Fo.charAt(e&63)}return c?i.slice(0,c-3)+"===".substring(c):i}function vy(){if(typeof wx>"u"||typeof Page>"u"||!wx.getSystemInfoSync||!wx.getStorageSync||!wx.setStorageSync||!wx.connectSocket||!wx.request)return!1;try{if(!wx.getSystemInfoSync()||wx.getSystemInfoSync().AppPlatform==="qq")return!1}catch{return!1}return!0}const bl="x-request-id",wl="x-device-id",El="device_id",_y=async function(r,e){let t=null,n=null;try{const o=Object.assign({},e);o.method||(o.method="GET"),o.body&&typeof o.body!="string"&&(o.body=JSON.stringify(o.body));const s=await(await fetch(r,o)).json();s!=null&&s.error?(n=s,n.error_uri=new URL(r).pathname):t=s}catch(o){n={error:et.UNREACHABLE,error_description:o.message,error_uri:new URL(r).pathname}}if(n)throw n;return t};function by(){return gl()}class wy{constructor(e){this._env=(e==null?void 0:e.env)||""}async getItem(e){return window.localStorage.getItem(`${e}${this._env}`)}async removeItem(e){window.localStorage.removeItem(`${e}${this._env}`)}async setItem(e,t){window.localStorage.setItem(`${e}${this._env}`,t)}getItemSync(e){return window.localStorage.getItem(`${e}${this._env}`)}removeItemSync(e){window.localStorage.removeItem(`${e}${this._env}`)}setItemSync(e,t){window.localStorage.setItem(`${e}${this._env}`,t)}}const ws=new wy;function Sl(r){let e=!0;return r!=null&&r.expires_at&&(r!=null&&r.access_token)&&(e=r.expires_at<new Date),e}class Ey{constructor(e){this.credentials=null,this.singlePromise=null,this.tokenSectionName=e.tokenSectionName,this.storage=e.storage,this.clientId=e.clientId,this.singlePromise=new _l({clientId:this.clientId})}getStorageCredentialsSync(){let e=null;const t=this.storage.getItemSync(this.tokenSectionName);if(t!=null)try{e=JSON.parse(t),e!=null&&e.expires_at&&(e.expires_at=new Date(e.expires_at))}catch{this.storage.removeItem(this.tokenSectionName),e=null}return e}async setCredentials(e){if(e!=null&&e.expires_in){if(e!=null&&e.expires_at||(e.expires_at=new Date(Date.now()+(e.expires_in-30)*1e3)),this.storage){const t=JSON.stringify(e);await this.storage.setItem(this.tokenSectionName,t)}this.credentials=e}else this.storage&&await this.storage.removeItem(this.tokenSectionName),this.credentials=null}async getCredentials(){return this.singlePromise.run("getCredentials",async()=>(Sl(this.credentials)&&(this.credentials=await this.getStorageCredentials()),this.credentials))}async getStorageCredentials(){return this.singlePromise.run("_getStorageCredentials",async()=>{let e=null;const t=await this.storage.getItem(this.tokenSectionName);if(t!=null)try{e=JSON.parse(t),e!=null&&e.expires_at&&(e.expires_at=new Date(e.expires_at))}catch{await this.storage.removeItem(this.tokenSectionName),e=null}return e})}}class qt{constructor(e){this.singlePromise=null,e.clientSecret||(e.clientSecret=""),!e.clientId&&e.env&&(e.clientId=e.env),this.apiOrigin=e.apiOrigin,this.clientId=e.clientId,this.singlePromise=new _l({clientId:this.clientId}),this.retry=this.formatRetry(e.retry,qt.defaultRetry),e.baseRequest?this.baseRequest=e.baseRequest:this.baseRequest=_y,this.tokenInURL=e.tokenInURL,this.headers=e.headers,this.storage=e.storage||ws,this.localCredentials=new Ey({tokenSectionName:`credentials_${e.clientId}`,storage:this.storage,clientId:e.clientId}),this.clientSecret=e.clientSecret,e.clientId&&(this.basicAuth=`Basic ${gy(`${e.clientId}:${this.clientSecret}`)}`),this.wxCloud=e.wxCloud;try{vy()&&this.wxCloud===void 0&&e.env&&(wx.cloud.init({env:e.env}),this.wxCloud=wx.cloud)}catch{}this.refreshTokenFunc=e.refreshTokenFunc||this.defaultRefreshTokenFunc,this.anonymousSignInFunc=e.anonymousSignInFunc}setCredentials(e){return this.localCredentials.setCredentials(e)}async getAccessToken(){const e=await this.getCredentials();if(e!=null&&e.access_token)return Promise.resolve(e.access_token);const t={error:et.UNAUTHENTICATED};return Promise.reject(t)}async request(e,t){t||(t={});const n=this.formatRetry(t.retry,this.retry);if(t.headers=t.headers||{},this.headers&&(t.headers={...this.headers,...t.headers}),t.headers[bl]||(t.headers[bl]=by()),!t.headers[wl]){const s=await this.getDeviceId();t.headers[wl]=s}if(t!=null&&t.withBasicAuth&&this.basicAuth&&(t.headers.Authorization=this.basicAuth),t!=null&&t.withCredentials){const s=await this.getCredentials();s&&(this.tokenInURL?(e.indexOf("?")<0&&(e+="?"),e+=`access_token=${s.access_token}`):t.headers.Authorization=`${s.token_type} ${s.access_token}`)}else this.clientId&&e.indexOf("client_id")<0&&(e+=e.indexOf("?")<0?"?":"&",e+=`client_id=${this.clientId}`);e.startsWith("/")&&(e=this.apiOrigin+e);let o=null;const i=n+1;for(let s=0;s<i;s++){try{t.useWxCloud?o=await this.wxCloudCallFunction(e,t):o=await this.baseRequest(e,t);break}catch(c){if(t.withCredentials&&c&&c.error===et.UNAUTHENTICATED)return await this.setCredentials(null),Promise.reject(c);if(s===n||!c||c.error!=="unreachable")return Promise.reject(c)}await this.sleep(qt.retryInterval)}return o}async wxCloudCallFunction(e,t){var i;let n=null,o=null;try{let s="";try{s=await wx.getRendererUserAgent()}catch{}const{result:c}=await this.wxCloud.callFunction({name:"httpOverCallFunction",data:{url:e,method:t.method,headers:{origin:"https://servicewechat.com","User-Agent":s,...t.headers},body:t.body}});(i=c==null?void 0:c.body)!=null&&i.error_code?(o=c==null?void 0:c.body,o.error_uri=vl(e)):n=c==null?void 0:c.body}catch(s){o={error:et.UNREACHABLE,error_description:s.message,error_uri:vl(e)}}if(o)throw o;return n}async getCredentials(){let e=await this.localCredentials.getCredentials();return e?(Sl(e)&&(e&&e.scope==="anonymous"?this.anonymousSignInFunc?e=await this.anonymousSignInFunc(e)||await this.localCredentials.getCredentials():e=await this.anonymousSignIn(e):e=await this.refreshToken(e)),e):this.unAuthenticatedError("credentials not found")}getCredentialsSync(){return this.localCredentials.getStorageCredentialsSync()}getCredentialsAsync(){return this.getCredentials()}async getScope(){const e=await this.localCredentials.getCredentials();return e?e.scope:this.unAuthenticatedError("credentials not found")}async getGroups(){const e=await this.localCredentials.getCredentials();return e?e.groups:this.unAuthenticatedError("credentials not found")}async refreshToken(e){return this.singlePromise.run("_refreshToken",async()=>{if(!e||!e.refresh_token)return this.unAuthenticatedError("no refresh token found in credentials");try{const t=await this.refreshTokenFunc(e.refresh_token,e);return await this.localCredentials.setCredentials(t),t}catch(t){return t.error===et.INVALID_GRANT?(await this.localCredentials.setCredentials(null),this.unAuthenticatedError(t.error_description)):Promise.reject(t)}})}checkRetry(e){let t=null;if((typeof e!="number"||e<qt.minRetry||e>qt.maxRetry)&&(t={error:et.UNREACHABLE,error_description:"wrong options param: retry"}),t)throw t;return e}formatRetry(e,t){return typeof e>"u"?t:this.checkRetry(e)}async sleep(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}async anonymousSignIn(e){return this.singlePromise.run("_anonymous",async()=>{if(!e||e.scope!=="anonymous")return this.unAuthenticatedError("no anonymous in credentials");try{const t=await this.request(ie.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",withBasicAuth:!0,body:{}});return await this.localCredentials.setCredentials(t),t}catch(t){return t.error===et.INVALID_GRANT?(await this.localCredentials.setCredentials(null),this.unAuthenticatedError(t.error_description)):Promise.reject(t)}})}async defaultRefreshTokenFunc(e,t){if(e===void 0||e==="")return this.unAuthenticatedError("refresh token not found");let n=ie.AUTH_TOKEN_URL;return(t==null?void 0:t.version)==="v2"&&(n=qn.AUTH_TOKEN_URL),{...await this.request(n,{method:"POST",body:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"refresh_token",refresh_token:e}}),version:(t==null?void 0:t.version)||"v1"}}async getDeviceId(){if(this.deviceID)return this.deviceID;let e=await this.storage.getItem(El);return typeof e=="string"&&e.length>=16&&e.length<=48||(e=gl(),await this.storage.setItem(El,e)),this.deviceID=e,e}unAuthenticatedError(e){const t={error:et.UNAUTHENTICATED,error_description:e};return Promise.reject(t)}}qt.defaultRetry=2,qt.minRetry=0,qt.maxRetry=5,qt.retryInterval=1e3;function Es(){const{wx:r}=globalThis;if(typeof r>"u"||globalThis.Page===void 0||!r.getSystemInfoSync||!r.getStorageSync||!r.setStorageSync||!r.connectSocket||!r.request)return!1;try{if(!r.getSystemInfoSync()||r.getSystemInfoSync().AppPlatform==="qq")return!1}catch{return!1}return!0}let Ei=!1;function Il(){Ei=Ei||typeof window!==void 0&&window.__wxjs_environment==="miniprogram"}try{Es()||(Ei=Ei||!!navigator.userAgent.match(/miniprogram/i)||window.__wxjs_environment==="miniprogram",window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?Il():typeof document<"u"&&document.addEventListener("WeixinJSBridgeReady",Il,!1))}catch{}function Ol(){return Ei}class Si{constructor(e){if(this.params={},typeof e=="string")this.parse(e);else if(e&&typeof e=="object")for(const t in e)Object.prototype.hasOwnProperty.call(e,t)&&this.append(t,e[t])}parse(e){e.split("&").forEach(n=>{const[o,i]=n.split("=").map(decodeURIComponent);this.append(o,i)})}append(e,t){this.params[e]?this.params[e]=this.params[e].concat([t]):this.params[e]=[t]}get(e){return this.params[e]?this.params[e][0]:null}getAll(e){return this.params[e]||[]}delete(e){delete this.params[e]}has(e){return Object.prototype.hasOwnProperty.call(this.params,e)}set(e,t){this.params[e]=[t]}toString(){const e=[];for(const t in this.params)Object.prototype.hasOwnProperty.call(this.params,t)&&this.params[t].forEach(n=>{e.push(`${encodeURIComponent(t)}=${encodeURIComponent(n)}`)});return e.join("&")}}class Sy{constructor(e){e.openURIWithCallback||(e.openURIWithCallback=this.getDefaultOpenURIWithCallback()),e.storage||(e.storage=ws),this.config=e,this.tokenSectionName=`captcha_${e.clientId}`}async request(e,t){t||(t={}),t.method||(t.method="GET");const n=`${t.method}:${e}`;let o=e;t.withCaptcha&&(o=await this.appendCaptchaTokenToURL(e,n,!1));let i;try{i=await this.config.request(o,t)}catch(s){return s.error===et.CAPTCHA_REQUIRED||s.error===et.CAPTCHA_INVALID?(e=await this.appendCaptchaTokenToURL(e,n,s.error===et.CAPTCHA_INVALID),this.config.request(e,t)):Promise.reject(s)}return i}getDefaultOpenURIWithCallback(){if(!Es()&&!Ol()&&(window.location.search.indexOf("__captcha")>0&&(document.body.style.display="none"),document.getElementById("captcha_panel_wrap")===null)){const e=document.createElement("div");e.style.cssText="background-color: rgba(0, 0, 0, 0.7);position: fixed;left: 0px;right: 0px;top: 0px;bottom: 0px;padding: 9vw 0 0 0;display: none;z-index:100;",e.setAttribute("id","captcha_panel_wrap"),setTimeout(()=>{document.body.appendChild(e)},0)}return this.defaultOpenURIWithCallback}async defaultOpenURIWithCallback(e,t){const{width:n="355px",height:o="355px"}=t||{};if(e.match(/^(data:.*)$/))return Promise.reject({error:et.UNIMPLEMENTED,error_description:"need to impl captcha data"});const s=document.getElementById("captcha_panel_wrap"),c=document.createElement("iframe");return s.innerHTML="",c.setAttribute("src",e),c.setAttribute("id","review-panel-iframe"),c.style.cssText=`min-width:${n};display:block;height:${o};margin:0 auto;background-color: rgb(255, 255, 255);border: none;`,s.appendChild(c),s.style.display="block",new Promise((l,a)=>{c.onload=function(){try{const u=window.location,f=c.contentWindow.location;if(f.host+f.pathname===u.host+u.pathname){s.style.display="none";const d=new Si(f.search),y=d.get("captcha_token");return y?l({captcha_token:y,expires_in:Number(d.get("expires_in"))}):a({error:d.get("error"),error_description:d.get("error_description")})}s.style.display="block"}catch{s.style.display="block"}}})}async getCaptchaToken(e,t){if(!e){const i=await this.findCaptchaToken();if(i)return i}let n;if(!Es()&&!Ol()){const i=`${window.location.origin+window.location.pathname}?__captcha=on`;if(n=await this.config.request(ie.GET_CAPTCHA_URL,{method:"POST",body:{client_id:this.config.clientId,redirect_uri:i,state:t},withCredentials:!1}),n.captcha_token){const s={captcha_token:n.captcha_token,expires_in:n.expires_in};return this.saveCaptchaToken(s),n.captcha_token}}else{const i=await this.config.request(ie.CAPTCHA_DATA_URL,{method:"POST",body:{state:t,redirect_uri:""},withCredentials:!1});n={url:`${i.data}?state=${encodeURIComponent(t)}&token=${encodeURIComponent(i.token)}`}}const o=await this.config.openURIWithCallback(n.url);return this.saveCaptchaToken(o),o.captcha_token}async appendCaptchaTokenToURL(e,t,n){const o=await this.getCaptchaToken(n,t);return e.indexOf("?")>0?e+=`&captcha_token=${o}`:e+=`?captcha_token=${o}`,e}async saveCaptchaToken(e){e.expires_at=new Date(Date.now()+(e.expires_in-10)*1e3);const t=JSON.stringify(e);await this.config.storage.setItem(this.tokenSectionName,t)}async findCaptchaToken(){const e=await this.config.storage.getItem(this.tokenSectionName);if(e!=null)try{const t=JSON.parse(e);return t!=null&&t.expires_at&&(t.expires_at=new Date(t.expires_at)),t.expires_at<new Date?null:t.captcha_token}catch{return await this.config.storage.removeItem(this.tokenSectionName),null}return null}}function Ss(r){if(!globalThis.IS_MP_BUILD&&r)return require("../utils/encrypt")}let Iy=class wa{static parseParamsToSearch(e){return Object.keys(e).forEach(n=>{e[n]||delete e[n]}),new Si(e).toString()}constructor(e){let{request:t}=e,n=e.credentialsClient;if(!n){const o={apiOrigin:e.apiOrigin,clientId:e.clientId,storage:e.storage,env:e.env,baseRequest:e.baseRequest,anonymousSignInFunc:e.anonymousSignInFunc,wxCloud:e.wxCloud};n=new qt(o)}if(!t){const o=n.request.bind(n),i=new Sy({clientId:e.clientId,request:o,storage:e.storage,...e.captchaOptions});t=i.request.bind(i)}this.config={env:e.env,apiOrigin:e.apiOrigin,clientId:e.clientId,request:t,credentialsClient:n,storage:e.storage||ws}}getParamsByVersion(e,t){var i;const n=bs(e),o=((i={v2:qn}[n==null?void 0:n.version])==null?void 0:i[t])||ie[t];return n&&delete n.version,{params:n,url:o}}async signIn(e){const t=e.version||"v1",n=this.getParamsByVersion(e,"AUTH_SIGN_IN_URL");n.params.query&&delete n.params.query;const o=await this.getEncryptParams(n.params),i=await this.config.request(n.url,{method:"POST",body:o});return await this.config.credentialsClient.setCredentials({...i,version:t}),Promise.resolve(i)}async signInAnonymously(e={},t=!1){const n=await this.config.request(ie.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:e,useWxCloud:t});return await this.config.credentialsClient.setCredentials(n),Promise.resolve(n)}async signUp(e){const t=await this.config.request(ie.AUTH_SIGN_UP_URL,{method:"POST",body:e});return await this.config.credentialsClient.setCredentials(t),Promise.resolve(t)}async signOut(e){let t={};if(e){try{t=await this.config.request(ie.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:e})}catch(i){i.error!==et.UNAUTHENTICATED&&console.log("sign_out_error",i)}return await this.config.credentialsClient.setCredentials(),t}const n=await this.config.credentialsClient.getAccessToken(),o=await this.config.request(ie.AUTH_REVOKE_URL,{method:"POST",body:{token:n}});return await this.config.credentialsClient.setCredentials(),Promise.resolve(o)}async revokeAllDevices(){await this.config.request(ie.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})}async revokeDevice(e){await this.config.request(ie.AUTHORIZED_DEVICES_DELETE_URL+e.device_id,{method:"DELETE",withCredentials:!0})}async getVerification(e,t){let n=!1;return(e.target==="CUR_USER"||await this.hasLoginState())&&(n=!0),this.config.request(ie.VERIFICATION_URL,{method:"POST",body:e,withCaptcha:(t==null?void 0:t.withCaptcha)||!1,withCredentials:n})}async verify(e){const t=this.getParamsByVersion(e,"VERIFY_URL"),n=await this.config.request(t.url,{method:"POST",body:t.params});return(e==null?void 0:e.version)==="v2"&&await this.config.credentialsClient.setCredentials({...n,version:"v2"}),n}async genProviderRedirectUri(e){const{provider_redirect_uri:t,other_params:n={},...o}=e;t&&!o.redirect_uri&&(o.redirect_uri=t);let i=`${ie.PROVIDER_URI_URL}?${wa.parseParamsToSearch(o)}`;return Object.keys(n).forEach(s=>{const c=n[s];s==="sign_out_uri"&&!((c==null?void 0:c.length)>0)||(i+=`&other_params[${s}]=${encodeURIComponent(c)}`)}),this.config.request(i,{method:"GET"})}async grantProviderToken(e,t=!1){return this.config.request(ie.PROVIDER_TOKEN_URL,{method:"POST",body:e,useWxCloud:t})}async patchProviderToken(e){return this.config.request(ie.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})}async signInWithProvider(e,t=!1){const n=this.getParamsByVersion(e,"AUTH_SIGN_IN_WITH_PROVIDER_URL"),o=await this.config.request(n.url,{method:"POST",body:n.params,useWxCloud:t});return await this.config.credentialsClient.setCredentials({...o,version:(e==null?void 0:e.version)||"v1"}),Promise.resolve(o)}async signInCustom(e){const t=await this.config.request(ie.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:e});return await this.config.credentialsClient.setCredentials(t),Promise.resolve(t)}async signInWithWechat(e={}){const t=await this.config.request(ie.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:e});return await this.config.credentialsClient.setCredentials(t),Promise.resolve(t)}async bindWithProvider(e){return this.config.request(ie.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0})}async getUserProfile(e){return this.getUserInfo(e)}async getUserInfo(e={}){var o;const t=this.getParamsByVersion(e,"USER_ME_URL");if((o=t.params)!=null&&o.query){const i=new Si(t.params.query);t.url+=`?${i.toString()}`}const n=await this.config.request(t.url,{method:"GET",withCredentials:!0});return n.sub&&(n.uid=n.sub),n}async getWedaUserInfo(){return await this.config.request(ie.WEDA_USER_URL,{method:"GET",withCredentials:!0})}async deleteMe(e){const t=this.getParamsByVersion(e,"USER_ME_URL"),n=`${t.url}?${wa.parseParamsToSearch(t.params)}`;return this.config.request(n,{method:"DELETE",withCredentials:!0})}async hasLoginState(){try{return await this.config.credentialsClient.getAccessToken(),!0}catch{return!1}}hasLoginStateSync(){return this.config.credentialsClient.getCredentialsSync()}async getLoginState(){return this.config.credentialsClient.getCredentialsAsync()}async transByProvider(e){return this.config.request(ie.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:e,withCredentials:!0})}async grantToken(e){const t=this.getParamsByVersion(e,"AUTH_TOKEN_URL");return this.config.request(t.url,{method:"POST",body:t.params})}async getProviders(){return this.config.request(ie.PROVIDER_LIST,{method:"GET",withCredentials:!0})}async unbindProvider(e){return this.config.request(`${ie.PROVIDER_UNBIND_URL}/${e.provider_id}`,{method:"DELETE",withCredentials:!0})}async checkPassword(e){return this.config.request(`${ie.CHECK_PWD_URL}`,{method:"POST",withCredentials:!0,body:e})}async editContact(e){return this.config.request(`${ie.BIND_CONTACT_URL}`,{method:"PATCH",withCredentials:!0,body:e})}async setPassword(e){return this.config.request(`${ie.AUTH_SET_PASSWORD}`,{method:"PATCH",withCredentials:!0,body:e})}async updatePasswordByOld(e){const t=await this.sudo({password:e.old_password});return this.setPassword({sudo_token:t.sudo_token,new_password:e.new_password})}async sudo(e){return this.config.request(`${ie.SUDO_URL}`,{method:"POST",withCredentials:!0,body:e})}async sendVerificationCodeToCurrentUser(e){return e.target="CUR_USER",this.config.request(ie.VERIFICATION_URL,{method:"POST",body:e,withCredentials:!0,withCaptcha:!0})}async changeBoundProvider(e){return this.config.request(`${ie.PROVIDER_LIST}/${e.provider_id}/trans`,{method:"POST",body:{provider_trans_token:e.trans_token},withCredentials:!0})}async setUserProfile(e){return this.config.request(ie.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})}async updateUserBasicInfo(e){return this.config.request(ie.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:e})}async queryUserProfile(e){const t=new Si(e);return this.config.request(`${ie.USER_QUERY_URL}?${t.toString()}`,{method:"GET",withCredentials:!0})}setCustomSignFunc(e){this.getCustomSignTicketFn=e}async signInWithCustomTicket(){const e=this.getCustomSignTicketFn;if(!e)return Promise.reject({error:"failed_precondition",error_description:"please use setCustomSignFunc to set custom sign function"});const t=await e();return this.signInCustom({provider_id:"custom",ticket:t})}async resetPassword(e){return this.config.request(ie.AUTH_RESET_PASSWORD,{method:"POST",body:e})}async authorize(e){return this.config.request(ie.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:e})}async authorizeDevice(e){return this.config.request(ie.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:e})}async deviceAuthorize(e){return this.config.request(ie.AUTH_GET_DEVICE_CODE,{method:"POST",body:e,withCredentials:!0})}async authorizeInfo(e){const t=`${ie.AUTHORIZE_INFO_URL}?${wa.parseParamsToSearch(e)}`;let n=!0,o=!1;return await this.hasLoginState()&&(o=!0,n=!1),this.config.request(t,{method:"GET",withBasicAuth:n,withCredentials:o})}async checkUsername(e){return this.config.request(ie.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})}async checkIfUserExist(e){const t=new Si(e);return this.config.request(`${ie.CHECK_IF_USER_EXIST}?${t.toString()}`,{method:"GET"})}async loginScope(){return this.config.credentialsClient.getScope()}async loginGroups(){return this.config.credentialsClient.getGroups()}async refreshTokenForce(e){const t=await this.config.credentialsClient.getCredentials();return await this.config.credentialsClient.refreshToken({...t,version:(e==null?void 0:e.version)||"v1"})}async getCredentials(){return this.config.credentialsClient.getCredentials()}async getPublicKey(){return this.config.request(qn.AUTH_PUBLIC_KEY,{method:"POST",body:{}})}async getEncryptParams(e){const{isEncrypt:t}=e;delete e.isEncrypt;const n=bs(e),o=Ss(t);if(!o)return e;let i="",s="";try{const c=await this.getPublicKey();if(i=c.public_key,s=c.public_key_thumbprint,!i||!s)throw c}catch(c){throw c}return{params:o.getEncryptInfo({publicKey:i,payload:n}),public_key_thumbprint:s}}async getProviderSubType(){return this.config.request(ie.GET_PROVIDER_TYPE,{method:"POST",body:{provider_id:"weda"}})}async verifyCaptchaData({token:e,key:t}){return this.config.request(ie.VERIFY_CAPTCHA_DATA_URL,{method:"POST",body:{token:e,key:t},withCredentials:!1})}async createCaptchaData({state:e,redirect_uri:t=void 0}){return this.config.request(ie.CAPTCHA_DATA_URL,{method:"POST",body:{state:e,redirect_uri:t},withCredentials:!1})}async getMiniProgramCode(e){return this.config.request(ie.GET_MINIPROGRAM_QRCODE,{method:"POST",body:e})}async getMiniProgramQrCodeStatus(e){return this.config.request(ie.GET_MINIPROGRAM_QRCODE_STATUS,{method:"POST",body:e})}async getUserBehaviorLog(e){const t={LOGIN:"query[action]=USER_LOGIN",MODIFY:"ne_query[action]=USER_LOGIN"},n=`${ie.GET_USER_BEHAVIOR_LOG}?${t[e.type]}&limit=${e.limit}${e.page_token?`&page_token=${e.page_token}`:""}`;return this.config.request(n,{method:"GET",withCredentials:!0})}async modifyPassword(e){let t="",n="";const o=Ss(!0);if(!o)throw new Error("do not support encrypt, a encrypt util required.");try{const c=await this.getPublicKey();if(t=c.public_key,n=c.public_key_thumbprint,!t||!n)throw c}catch(c){throw c}const i=e.password?o.getEncryptInfo({publicKey:t,payload:e.password}):"",s=o.getEncryptInfo({publicKey:t,payload:e.new_password});return this.config.request(ie.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:{user_id:e.user_id,encrypt_password:i,encrypt_new_password:s,public_key_thumbprint:n}})}async modifyPasswordWithoutLogin(e){let t="",n="";const o=Ss(!0);if(!o)throw new Error("do not support encrypt, a encrypt util required.");try{const c=await this.getPublicKey();if(t=c.public_key,n=c.public_key_thumbprint,!t||!n)throw c}catch(c){throw c}const i=e.password?o.getEncryptInfo({publicKey:t,payload:e.password}):"",s=o.getEncryptInfo({publicKey:t,payload:e.new_password});return this.config.request(qn.AUTH_RESET_PASSWORD,{method:"POST",body:{username:e.username,password:i,new_password:s,public_key_thumbprint:n}})}};class Oy{constructor(e){const{apiOrigin:t,clientId:n,env:o,storage:i,request:s,baseRequest:c,anonymousSignInFunc:l,wxCloud:a}=e;this.oauth2client=new qt({apiOrigin:t,clientId:n,env:o,storage:i,baseRequest:c||s,anonymousSignInFunc:l,wxCloud:a}),this.authApi=new Iy({credentialsClient:this.oauth2client,...e,request:s?this.oauth2client.request.bind(this.oauth2client):void 0})}}var ut=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Is(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function Ty(r){if(Object.prototype.hasOwnProperty.call(r,"__esModule"))return r;var e=r.default;if(typeof e=="function"){var t=function n(){return this instanceof n?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};t.prototype=e.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(r).forEach(function(n){var o=Object.getOwnPropertyDescriptor(r,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return r[n]}})}),t}var re={},cn={},tt={},Tl;function Al(){if(Tl)return tt;Tl=1,Object.defineProperty(tt,"__esModule",{value:!0}),tt.COMMUNITY_SITE_URL=tt.IS_DEBUG_MODE=tt.getProtocol=tt.setProtocol=tt.getSdkName=tt.setSdkName=void 0;var r="@cloudbase/js-sdk";function e(s){r=s}tt.setSdkName=e;function t(){return r}tt.getSdkName=t;var n="https:";function o(s){n=s}tt.setProtocol=o;function i(){return n}return tt.getProtocol=i,tt.IS_DEBUG_MODE=!1,tt.COMMUNITY_SITE_URL="https://support.qq.com/products/148793",tt}var Ii={},Rl;function Ay(){return Rl||(Rl=1,Object.defineProperty(Ii,"__esModule",{value:!0}),Ii.ERRORS=void 0,Ii.ERRORS={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"}),Ii}var Cl;function Uo(){return Cl||(Cl=1,function(r){var e=cn&&cn.__createBinding||(Object.create?function(n,o,i,s){s===void 0&&(s=i);var c=Object.getOwnPropertyDescriptor(o,i);(!c||("get"in c?!o.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return o[i]}}),Object.defineProperty(n,s,c)}:function(n,o,i,s){s===void 0&&(s=i),n[s]=o[i]}),t=cn&&cn.__exportStar||function(n,o){for(var i in n)i!=="default"&&!Object.prototype.hasOwnProperty.call(o,i)&&e(o,n,i)};Object.defineProperty(r,"__esModule",{value:!0}),r.OATUH_LOGINTYPE=void 0,t(Al(),r),t(Ay(),r),r.OATUH_LOGINTYPE="constants"}(cn)),cn}var xl;function jn(){if(xl)return re;xl=1,Object.defineProperty(re,"__esModule",{value:!0}),re.transformPhone=re.sleep=re.printGroupLog=re.throwError=re.printInfo=re.printError=re.printWarn=re.execCallback=re.createPromiseCallback=re.removeParam=re.getHash=re.getQuery=re.toQueryString=re.formatUrl=re.generateRequestId=re.genSeqId=re.isFormData=re.isInstanceOf=re.isNull=re.isPalinObject=re.isUndefined=re.isString=re.isArray=void 0;var r=Uo();function e(R){return Object.prototype.toString.call(R)==="[object Array]"}re.isArray=e;function t(R){return typeof R=="string"}re.isString=t;function n(R){return typeof R>"u"}re.isUndefined=n;function o(R){return Object.prototype.toString.call(R)==="[object Object]"}re.isPalinObject=o;function i(R){return Object.prototype.toString.call(R)==="[object Null]"}re.isNull=i;function s(R,x){return R instanceof x}re.isInstanceOf=s;function c(R){return Object.prototype.toString.call(R)==="[object FormData]"}re.isFormData=c;function l(){return Math.random().toString(16).slice(2)}re.genSeqId=l;function a(){var R=new Date().getTime(),x=(performance==null?void 0:performance.now)&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(L){var F=Math.random()*16;return R>0?(F=(R+F)%16|0,R=Math.floor(R/16)):(F=(x+F)%16|0,x=Math.floor(x/16)),(L==="x"?F:F&7|8).toString(16)})}re.generateRequestId=a;function u(R,x,L){L===void 0&&(L={});var F=/\?/.test(x),j="";return Object.keys(L).forEach(function(V){j===""?!F&&(x+="?"):j+="&",j+="".concat(V,"=").concat(encodeURIComponent(L[V]))}),x+=j,/^http(s)?:\/\//.test(x)?x:"".concat(R).concat(x)}re.formatUrl=u;function f(R){R===void 0&&(R={});var x=[];return Object.keys(R).forEach(function(L){x.push("".concat(L,"=").concat(encodeURIComponent(R[L])))}),x.join("&")}re.toQueryString=f;function d(R,x){if(typeof window>"u")return!1;var L=x||window.location.search,F=new RegExp("(^|&)".concat(R,"=([^&]*)(&|$)")),j=L.substr(L.indexOf("?")+1).match(F);return j!=null?j[2]:""}re.getQuery=d;var y=function(R){if(typeof window>"u")return"";var x=window.location.hash.match(new RegExp("[#?&/]".concat(R,"=([^&#]*)")));return x?x[1]:""};re.getHash=y;function m(R,x){var L=x.split("?")[0],F,j=[],V=x.indexOf("?")!==-1?x.split("?")[1]:"";if(V!==""){j=V.split("&");for(var W=j.length-1;W>=0;W-=1)F=j[W].split("=")[0],F===R&&j.splice(W,1);L="".concat(L,"?").concat(j.join("&"))}return L}re.removeParam=m;function v(){var R;if(!Promise){R=function(){},R.promise={};var x=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(R.promise,"then",{get:x}),Object.defineProperty(R.promise,"catch",{get:x}),R}var L=new Promise(function(F,j){R=function(V,W){return V?j(V):F(W)}});return R.promise=L,R}re.createPromiseCallback=v;function I(R,x,L){if(L===void 0&&(L=null),R&&typeof R=="function")return R(x,L);if(x)throw x;return L}re.execCallback=I;function S(R,x){console.warn("[".concat((0,r.getSdkName)(),"][").concat(R,"]:").concat(x))}re.printWarn=S;function w(R,x){console.error({code:R,msg:"[".concat((0,r.getSdkName)(),"][").concat(R,"]:").concat(x)})}re.printError=w;function O(R,x){console.log("[".concat((0,r.getSdkName)(),"][").concat(R,"]:").concat(x))}re.printInfo=O;function T(R,x){throw new Error(JSON.stringify({code:R,msg:"[".concat((0,r.getSdkName)(),"][").concat(R,"]:").concat(x)}))}re.throwError=T;function N(R){var x=R.title,L=R.subtitle,F=L===void 0?"":L,j=R.content,V=j===void 0?[]:j,W=R.printTrace,oe=W===void 0?!1:W,se=R.collapsed,Z=se===void 0?!1:se;Z?console.groupCollapsed(x,F):console.group(x,F);for(var ee=0,Y=V;ee<Y.length;ee++){var G=Y[ee],Se=G.type,Fe=G.body;switch(Se){case"info":console.log(Fe);break;case"warn":console.warn(Fe);break;case"error":console.error(Fe);break}}oe&&console.trace("stack trace:"),console.groupEnd()}re.printGroupLog=N;var D=function(R){return R===void 0&&(R=0),new Promise(function(x){return setTimeout(x,R)})};re.sleep=D;function B(R){return"+86".concat(R)}return re.transformPhone=B,re}var kn=jn(),pe=Uo(),ln={},yr={},Nl;function Ry(){if(Nl)return yr;Nl=1;var r=yr&&yr.__awaiter||function(u,f,d,y){function m(v){return v instanceof d?v:new d(function(I){I(v)})}return new(d||(d=Promise))(function(v,I){function S(T){try{O(y.next(T))}catch(N){I(N)}}function w(T){try{O(y.throw(T))}catch(N){I(N)}}function O(T){T.done?v(T.value):m(T.value).then(S,w)}O((y=y.apply(u,f||[])).next())})},e=yr&&yr.__generator||function(u,f){var d={label:0,sent:function(){if(v[0]&1)throw v[1];return v[1]},trys:[],ops:[]},y,m,v,I;return I={next:S(0),throw:S(1),return:S(2)},typeof Symbol=="function"&&(I[Symbol.iterator]=function(){return this}),I;function S(O){return function(T){return w([O,T])}}function w(O){if(y)throw new TypeError("Generator is already executing.");for(;I&&(I=0,O[0]&&(d=0)),d;)try{if(y=1,m&&(v=O[0]&2?m.return:O[0]?m.throw||((v=m.return)&&v.call(m),0):m.next)&&!(v=v.call(m,O[1])).done)return v;switch(m=0,v&&(O=[O[0]&2,v.value]),O[0]){case 0:case 1:v=O;break;case 4:return d.label++,{value:O[1],done:!1};case 5:d.label++,m=O[1],O=[0];continue;case 7:O=d.ops.pop(),d.trys.pop();continue;default:if(v=d.trys,!(v=v.length>0&&v[v.length-1])&&(O[0]===6||O[0]===2)){d=0;continue}if(O[0]===3&&(!v||O[1]>v[0]&&O[1]<v[3])){d.label=O[1];break}if(O[0]===6&&d.label<v[1]){d.label=v[1],v=O;break}if(v&&d.label<v[2]){d.label=v[2],d.ops.push(O);break}v[2]&&d.ops.pop(),d.trys.pop();continue}O=f.call(u,d)}catch(T){O=[6,T],m=0}finally{y=v=0}if(O[0]&5)throw O[1];return{value:O[0]?O[1]:void 0,done:!0}}};Object.defineProperty(yr,"__esModule",{value:!0}),yr.catchErrorsDecorator=void 0;var t=jn(),n=Uo(),o=!1;typeof navigator<"u"&&navigator.userAgent&&(o=navigator.userAgent.indexOf("Firefox")!==-1);var i=o?/(\.js\/)?__decorate(\$\d+)?<@.*\d$/:/(\/\w+\.js\.)?__decorate(\$\d+)?\s*\(.*\)$/,s=/https?:\/\/.+:\d*\/.*\.js:\d+:\d+/;function c(u){var f=u.mode,d=f===void 0?"async":f,y=u.customInfo,m=y===void 0?{}:y,v=u.title,I=u.messages,S=I===void 0?[]:I;return function(w,O,T){if(n.IS_DEBUG_MODE){var N=m.className||w.constructor.name,D=m.methodName||O,B=T.value,R=l(new Error);d==="sync"?T.value=function(){for(var x=[],L=0;L<arguments.length;L++)x[L]=arguments[L];var F=a({err:new Error,className:N,methodName:D,sourceLink:R});try{return B.apply(this,x)}catch(ee){var j=ee,V=ee.message,W=ee.error,oe=ee.error_description,se={title:v||"".concat(N,".").concat(D," failed"),content:[{type:"error",body:ee}]};if(V&&/^\{.*\}$/.test(V)){var Z=JSON.parse(V);se.subtitle=V,Z.code&&(F?(F.code=Z.code,F.msg=Z.msg):(ee.code=Z.code,ee.message=Z.msg),j=F||ee,se.content=S.map(function(Y){return{type:"info",body:Y}}))}throw W&&oe&&(se.subtitle=oe,F?(F.code=W,F.msg=oe):(ee.code=W,ee.message=oe),j=F||ee,se.content=S.map(function(Y){return{type:"info",body:Y}})),(0,t.printGroupLog)(se),j}}:T.value=function(){for(var x=[],L=0;L<arguments.length;L++)x[L]=arguments[L];return r(this,void 0,void 0,function(){var F,j,V,W,oe,se,Z,ee;return e(this,function(Y){switch(Y.label){case 0:F=a({err:new Error,className:N,methodName:D,sourceLink:R}),Y.label=1;case 1:return Y.trys.push([1,3,,4]),[4,B.apply(this,x)];case 2:return[2,Y.sent()];case 3:throw j=Y.sent(),V=j,W=j.message,oe=j.error,se=j.error_description,Z={title:v||"".concat(N,".").concat(D," failed"),content:[{type:"error",body:j}]},W&&/^\{.*\}$/.test(W)&&(ee=JSON.parse(W),Z.subtitle=ee,ee.code&&(F?(F.code=ee.code,F.message=ee.msg):(j.code=ee.code,j.message=ee.msg),V=F||j,Z.content=S.map(function(G){return{type:"info",body:G}}))),oe&&se&&(Z.subtitle=se,F?(F.code=oe,F.msg=se):(j.code=oe,j.message=se),V=F||j,Z.content=S.map(function(G){return{type:"info",body:G}})),(0,t.printGroupLog)(Z),V;case 4:return[2]}})})}}}}yr.catchErrorsDecorator=c;function l(u){var f="",d=u.stack.split(`
8
+ `),y=d.findIndex(function(v){return i.test(v)});if(y!==-1){var m=s.exec(d[y+1]||"");f=m?m[0]:""}return f}function a(u){var f=u.err,d=u.className,y=u.methodName,m=u.sourceLink;if(!m)return null;var v=f.stack.split(`
9
+ `),I=o?/^catchErrorsDecorator\/<\/descriptor.value@.*\d$/:new RegExp("".concat(d,"\\.descriptor.value\\s*\\[as\\s").concat(y,"\\]\\s*\\(.*\\)$")),S=o?/^catchErrorsDecorator\/<\/descriptor.value/:new RegExp("".concat(d,"\\.descriptor.value\\s*\\[as\\s").concat(y,"\\]")),w=v.findIndex(function(N){return I.test(N)}),O;if(w!==-1){var T=v.filter(function(N,D){return D>w});T.unshift(v[w].replace(S,"".concat(d,".").concat(y)).replace(s,m)),O=new Error,O.stack="".concat(o?"@debugger":"Error",`
10
+ `).concat(T.join(`
11
+ `))}return O}return yr}var Pl;function Cy(){return Pl||(Pl=1,function(r){var e=ln&&ln.__createBinding||(Object.create?function(n,o,i,s){s===void 0&&(s=i);var c=Object.getOwnPropertyDescriptor(o,i);(!c||("get"in c?!o.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return o[i]}}),Object.defineProperty(n,s,c)}:function(n,o,i,s){s===void 0&&(s=i),n[s]=o[i]}),t=ln&&ln.__exportStar||function(n,o){for(var i in n)i!=="default"&&!Object.prototype.hasOwnProperty.call(o,i)&&e(o,n,i)};Object.defineProperty(r,"__esModule",{value:!0}),t(Ry(),r)}(ln)),ln}var _e=Cy(),Le={},Dl;function xy(){if(Dl)return Le;Dl=1;var r=Le&&Le.__extends||function(){var d=function(y,m){return d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(v,I){v.__proto__=I}||function(v,I){for(var S in I)Object.prototype.hasOwnProperty.call(I,S)&&(v[S]=I[S])},d(y,m)};return function(y,m){if(typeof m!="function"&&m!==null)throw new TypeError("Class extends value "+String(m)+" is not a constructor or null");d(y,m);function v(){this.constructor=y}y.prototype=m===null?Object.create(m):(v.prototype=m.prototype,new v)}}(),e=Le&&Le.__spreadArray||function(d,y,m){if(m||arguments.length===2)for(var v=0,I=y.length,S;v<I;v++)(S||!(v in y))&&(S||(S=Array.prototype.slice.call(y,0,v)),S[v]=y[v]);return d.concat(S||Array.prototype.slice.call(y))};Object.defineProperty(Le,"__esModule",{value:!0}),Le.removeEventListener=Le.activateEvent=Le.addEventListener=Le.CloudbaseEventEmitter=Le.IErrorEvent=Le.CloudbaseEvent=void 0;var t=jn();function n(d,y,m){m[d]=m[d]||[],m[d].push(y)}function o(d,y,m){if(m!=null&&m[d]){var v=m[d].indexOf(y);v!==-1&&m[d].splice(v,1)}}var i=function(){function d(y,m){this.data=m||null,this.name=y}return d}();Le.CloudbaseEvent=i;var s=function(d){r(y,d);function y(m,v){var I=d.call(this,"error",{error:m,data:v})||this;return I.error=m,I}return y}(i);Le.IErrorEvent=s;var c=function(){function d(){this.listeners={}}return d.prototype.on=function(y,m){return n(y,m,this.listeners),this},d.prototype.off=function(y,m){return o(y,m,this.listeners),this},d.prototype.fire=function(y,m){if((0,t.isInstanceOf)(y,s))return console.error(y.error),this;var v=(0,t.isString)(y)?new i(y,m||{}):y,I=v.name;if(this.listens(I)){v.target=this;for(var S=this.listeners[I]?e([],this.listeners[I],!0):[],w=0,O=S;w<O.length;w++){var T=O[w];T.call(this,v)}}return this},d.prototype.listens=function(y){return this.listeners[y]&&this.listeners[y].length>0},d}();Le.CloudbaseEventEmitter=c;var l=new c;function a(d,y){l.on(d,y)}Le.addEventListener=a;function u(d,y){y===void 0&&(y={}),l.fire(d,y)}Le.activateEvent=u;function f(d,y){l.off(d,y)}return Le.removeEventListener=f,Le}var Ny=xy(),jt={};const Fl=Ty(Gh);var Ul;function Py(){if(Ul)return jt;Ul=1;var r=jt&&jt.__extends||function(){var a=function(u,f){return a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,y){d.__proto__=y}||function(d,y){for(var m in y)Object.prototype.hasOwnProperty.call(y,m)&&(d[m]=y[m])},a(u,f)};return function(u,f){if(typeof f!="function"&&f!==null)throw new TypeError("Class extends value "+String(f)+" is not a constructor or null");a(u,f);function d(){this.constructor=u}u.prototype=f===null?Object.create(f):(d.prototype=f.prototype,new d)}}(),e=jt&&jt.__awaiter||function(a,u,f,d){function y(m){return m instanceof f?m:new f(function(v){v(m)})}return new(f||(f=Promise))(function(m,v){function I(O){try{w(d.next(O))}catch(T){v(T)}}function S(O){try{w(d.throw(O))}catch(T){v(T)}}function w(O){O.done?m(O.value):y(O.value).then(I,S)}w((d=d.apply(a,u||[])).next())})},t=jt&&jt.__generator||function(a,u){var f={label:0,sent:function(){if(m[0]&1)throw m[1];return m[1]},trys:[],ops:[]},d,y,m,v;return v={next:I(0),throw:I(1),return:I(2)},typeof Symbol=="function"&&(v[Symbol.iterator]=function(){return this}),v;function I(w){return function(O){return S([w,O])}}function S(w){if(d)throw new TypeError("Generator is already executing.");for(;v&&(v=0,w[0]&&(f=0)),f;)try{if(d=1,y&&(m=w[0]&2?y.return:w[0]?y.throw||((m=y.return)&&m.call(y),0):y.next)&&!(m=m.call(y,w[1])).done)return m;switch(y=0,m&&(w=[w[0]&2,m.value]),w[0]){case 0:case 1:m=w;break;case 4:return f.label++,{value:w[1],done:!1};case 5:f.label++,y=w[1],w=[0];continue;case 7:w=f.ops.pop(),f.trys.pop();continue;default:if(m=f.trys,!(m=m.length>0&&m[m.length-1])&&(w[0]===6||w[0]===2)){f=0;continue}if(w[0]===3&&(!m||w[1]>m[0]&&w[1]<m[3])){f.label=w[1];break}if(w[0]===6&&f.label<m[1]){f.label=m[1],m=w;break}if(m&&f.label<m[2]){f.label=m[2],f.ops.push(w);break}m[2]&&f.ops.pop(),f.trys.pop();continue}w=u.call(a,f)}catch(O){w=[6,O],y=0}finally{d=m=0}if(w[0]&5)throw w[1];return{value:w[0]?w[1]:void 0,done:!0}}};Object.defineProperty(jt,"__esModule",{value:!0}),jt.CloudbaseCache=void 0;var n=Fl,o=jn(),i=Uo(),s=function(a){r(u,a);function u(f){var d=a.call(this)||this;return d.root=f,f.tcbCacheObject||(f.tcbCacheObject={}),d}return u.prototype.setItem=function(f,d){this.root.tcbCacheObject[f]=d},u.prototype.getItem=function(f){return this.root.tcbCacheObject[f]},u.prototype.removeItem=function(f){delete this.root.tcbCacheObject[f]},u.prototype.clear=function(){delete this.root.tcbCacheObject},u}(n.AbstractStorage);function c(a,u){switch(a){case"local":return u.localStorage?u.localStorage:((0,o.printWarn)(i.ERRORS.INVALID_PARAMS,"localStorage is not supported on current platform"),new s(u.root));case"none":return new s(u.root);default:return u.localStorage?u.localStorage:((0,o.printWarn)(i.ERRORS.INVALID_PARAMS,"localStorage is not supported on current platform"),new s(u.root))}}var l=function(){function a(u){this.keys={};var f=u.persistence,d=u.platformInfo,y=d===void 0?{}:d,m=u.keys,v=m===void 0?{}:m;this.platformInfo=y,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||f,this.storage=c(this.persistenceTag,this.platformInfo.adapter),this.keys=v)}return Object.defineProperty(a.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),a.prototype.setStore=function(u,f,d){if(this.mode==="async"){(0,o.printWarn)(i.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed");return}if(this.storage)try{var y={version:d||"localCachev1",content:f};this.storage.setItem(u,JSON.stringify(y))}catch(m){throw new Error(JSON.stringify({code:i.ERRORS.OPERATION_FAIL,msg:"[".concat((0,i.getSdkName)(),"][").concat(i.ERRORS.OPERATION_FAIL,"]setStore failed"),info:m}))}},a.prototype.setStoreAsync=function(u,f,d){return e(this,void 0,void 0,function(){var y;return t(this,function(m){switch(m.label){case 0:if(!this.storage)return[2];m.label=1;case 1:return m.trys.push([1,3,,4]),y={version:d||"localCachev1",content:f},[4,this.storage.setItem(u,JSON.stringify(y))];case 2:return m.sent(),[3,4];case 3:return m.sent(),[2];case 4:return[2]}})})},a.prototype.getStore=function(u,f){var d;if(this.mode==="async"){(0,o.printWarn)(i.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed");return}try{if(typeof process<"u"&&(!((d=process.env)===null||d===void 0)&&d.tcb_token))return process.env.tcb_token;if(!this.storage)return""}catch{return""}f=f||"localCachev1";var y=this.storage.getItem(u);if(!y)return"";if(y.indexOf(f)>=0){var m=JSON.parse(y);return m.content}return""},a.prototype.getStoreAsync=function(u,f){var d;return e(this,void 0,void 0,function(){var y,m;return t(this,function(v){switch(v.label){case 0:try{if(typeof process<"u"&&(!((d=process.env)===null||d===void 0)&&d.tcb_token))return[2,process.env.tcb_token];if(!this.storage)return[2,""]}catch{return[2,""]}return f=f||"localCachev1",[4,this.storage.getItem(u)];case 1:return y=v.sent(),y?y.indexOf(f)>=0?(m=JSON.parse(y),[2,m.content]):[2,""]:[2,""]}})})},a.prototype.removeStore=function(u){if(this.mode==="async"){(0,o.printWarn)(i.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed");return}this.storage.removeItem(u)},a.prototype.removeStoreAsync=function(u){return e(this,void 0,void 0,function(){return t(this,function(f){switch(f.label){case 0:return[4,this.storage.removeItem(u)];case 1:return f.sent(),[2]}})})},a}();return jt.CloudbaseCache=l,jt}var Dy=Py(),mr={},rt={},Bl;function Fy(){if(Bl)return rt;Bl=1;var r=rt&&rt.__extends||function(){var a=function(u,f){return a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,y){d.__proto__=y}||function(d,y){for(var m in y)Object.prototype.hasOwnProperty.call(y,m)&&(d[m]=y[m])},a(u,f)};return function(u,f){if(typeof f!="function"&&f!==null)throw new TypeError("Class extends value "+String(f)+" is not a constructor or null");a(u,f);function d(){this.constructor=u}u.prototype=f===null?Object.create(f):(d.prototype=f.prototype,new d)}}(),e=rt&&rt.__assign||function(){return e=Object.assign||function(a){for(var u,f=1,d=arguments.length;f<d;f++){u=arguments[f];for(var y in u)Object.prototype.hasOwnProperty.call(u,y)&&(a[y]=u[y])}return a},e.apply(this,arguments)},t=rt&&rt.__awaiter||function(a,u,f,d){function y(m){return m instanceof f?m:new f(function(v){v(m)})}return new(f||(f=Promise))(function(m,v){function I(O){try{w(d.next(O))}catch(T){v(T)}}function S(O){try{w(d.throw(O))}catch(T){v(T)}}function w(O){O.done?m(O.value):y(O.value).then(I,S)}w((d=d.apply(a,u||[])).next())})},n=rt&&rt.__generator||function(a,u){var f={label:0,sent:function(){if(m[0]&1)throw m[1];return m[1]},trys:[],ops:[]},d,y,m,v;return v={next:I(0),throw:I(1),return:I(2)},typeof Symbol=="function"&&(v[Symbol.iterator]=function(){return this}),v;function I(w){return function(O){return S([w,O])}}function S(w){if(d)throw new TypeError("Generator is already executing.");for(;v&&(v=0,w[0]&&(f=0)),f;)try{if(d=1,y&&(m=w[0]&2?y.return:w[0]?y.throw||((m=y.return)&&m.call(y),0):y.next)&&!(m=m.call(y,w[1])).done)return m;switch(y=0,m&&(w=[w[0]&2,m.value]),w[0]){case 0:case 1:m=w;break;case 4:return f.label++,{value:w[1],done:!1};case 5:f.label++,y=w[1],w=[0];continue;case 7:w=f.ops.pop(),f.trys.pop();continue;default:if(m=f.trys,!(m=m.length>0&&m[m.length-1])&&(w[0]===6||w[0]===2)){f=0;continue}if(w[0]===3&&(!m||w[1]>m[0]&&w[1]<m[3])){f.label=w[1];break}if(w[0]===6&&f.label<m[1]){f.label=m[1],m=w;break}if(m&&f.label<m[2]){f.label=m[2],f.ops.push(w);break}m[2]&&f.ops.pop(),f.trys.pop();continue}w=u.call(a,f)}catch(O){w=[6,O],y=0}finally{d=m=0}if(w[0]&5)throw w[1];return{value:w[0]?w[1]:void 0,done:!0}}};Object.defineProperty(rt,"__esModule",{value:!0}),rt.WebRequest=rt.genAdapter=void 0;var o=Fl,i=jn(),s=Al(),c=function(a){r(u,a);function u(f){var d=a.call(this)||this,y=f.timeout,m=f.timeoutMsg,v=f.restrictedMethods;return d.timeout=y||0,d.timeoutMsg=m||"请求超时",d.restrictedMethods=v||["get","post","upload","download"],d}return u.prototype.get=function(f){return this.request(e(e({},f),{method:"get"}),this.restrictedMethods.includes("get"))},u.prototype.post=function(f){return this.request(e(e({},f),{method:"post"}),this.restrictedMethods.includes("post"))},u.prototype.put=function(f){return this.request(e(e({},f),{method:"put"}))},u.prototype.upload=function(f){var d=f.data,y=f.file,m=f.name,v=f.method,I=f.headers,S=I===void 0?{}:I,w={post:"post",put:"put"}[v==null?void 0:v.toLowerCase()]||"put",O=new FormData;return w==="post"?(Object.keys(d).forEach(function(T){O.append(T,d[T])}),O.append("key",m),O.append("file",y),this.request(e(e({},f),{data:O,method:w}),this.restrictedMethods.includes("upload"))):this.request(e(e({},f),{method:"put",headers:S,body:y}),this.restrictedMethods.includes("upload"))},u.prototype.download=function(f){return t(this,void 0,void 0,function(){var d,y,m,v;return n(this,function(I){switch(I.label){case 0:return I.trys.push([0,2,,3]),[4,this.get(e(e({},f),{headers:{},responseType:"blob"}))];case 1:return d=I.sent().data,y=window.URL.createObjectURL(new Blob([d])),m=decodeURIComponent(new URL(f.url).pathname.split("/").pop()||""),v=document.createElement("a"),v.href=y,v.setAttribute("download",m),v.style.display="none",document.body.appendChild(v),v.click(),window.URL.revokeObjectURL(y),document.body.removeChild(v),[3,3];case 2:return I.sent(),[3,3];case 3:return[2,new Promise(function(S){S({statusCode:200,tempFilePath:f.url})})]}})})},u.prototype.fetch=function(f){var d;return t(this,void 0,void 0,function(){var y,m,v,I,S,w,O,T,N,D,B,R=this;return n(this,function(x){switch(x.label){case 0:return y=new AbortController,m=f.url,v=f.enableAbort,I=v===void 0?!1:v,S=f.stream,w=S===void 0?!1:S,O=f.signal,T=f.timeout,N=T??this.timeout,O&&(O.aborted&&y.abort(),O.addEventListener("abort",function(){return y.abort()})),D=null,I&&N&&(D=setTimeout(function(){console.warn(R.timeoutMsg),y.abort(new Error(R.timeoutMsg))},N)),[4,fetch(m,e(e({},f),{signal:y.signal})).then(function(L){return t(R,void 0,void 0,function(){var F,j,V;return n(this,function(W){switch(W.label){case 0:return clearTimeout(D),L.ok?(F=L,[3,3]):[3,1];case 1:return V=(j=Promise).reject,[4,L.json()];case 2:F=V.apply(j,[W.sent()]),W.label=3;case 3:return[2,F]}})})}).catch(function(L){return clearTimeout(D),Promise.reject(L)})];case 1:return B=x.sent(),[2,{data:w?B.body:!((d=B.headers.get("content-type"))===null||d===void 0)&&d.includes("application/json")?B.json():B.text(),statusCode:B.status,header:B.headers}]}})})},u.prototype.request=function(f,d){var y=this;d===void 0&&(d=!1);var m=String(f.method).toLowerCase()||"get";return new Promise(function(v){var I=f.url,S=f.headers,w=S===void 0?{}:S,O=f.data,T=f.responseType,N=f.withCredentials,D=f.body,B=f.onUploadProgress,R=(0,i.formatUrl)((0,s.getProtocol)(),I,m==="get"?O:{}),x=new XMLHttpRequest;x.open(m,R),T&&(x.responseType=T),Object.keys(w).forEach(function(j){x.setRequestHeader(j,w[j])});var L;B&&x.upload.addEventListener("progress",B),x.onreadystatechange=function(){var j={};if(x.readyState===4){var V=x.getAllResponseHeaders(),W=V.trim().split(/[\r\n]+/),oe={};W.forEach(function(se){var Z=se.split(": "),ee=Z.shift().toLowerCase(),Y=Z.join(": ");oe[ee]=Y}),j.header=oe,j.statusCode=x.status;try{j.data=T==="blob"?x.response:JSON.parse(x.responseText)}catch{j.data=T==="blob"?x.response:x.responseText}clearTimeout(L),v(j)}},d&&y.timeout&&(L=setTimeout(function(){console.warn(y.timeoutMsg),x.abort()},y.timeout));var F;(0,i.isFormData)(O)?F=O:w["content-type"]==="application/x-www-form-urlencoded"?F=(0,i.toQueryString)(O):D?F=D:F=O?JSON.stringify(O):void 0,N&&(x.withCredentials=!0),x.send(F)})},u}(o.AbstractSDKRequest);rt.WebRequest=c;function l(){var a={root:window,reqClass:c,wsClass:WebSocket,localStorage};return a}return rt.genAdapter=l,rt}var Ll;function Uy(){return Ll||(Ll=1,function(r){var e=mr&&mr.__createBinding||(Object.create?function(a,u,f,d){d===void 0&&(d=f);var y=Object.getOwnPropertyDescriptor(u,f);(!y||("get"in y?!u.__esModule:y.writable||y.configurable))&&(y={enumerable:!0,get:function(){return u[f]}}),Object.defineProperty(a,d,y)}:function(a,u,f,d){d===void 0&&(d=f),a[d]=u[f]}),t=mr&&mr.__setModuleDefault||(Object.create?function(a,u){Object.defineProperty(a,"default",{enumerable:!0,value:u})}:function(a,u){a.default=u}),n=mr&&mr.__importStar||function(a){if(a&&a.__esModule)return a;var u={};if(a!=null)for(var f in a)f!=="default"&&Object.prototype.hasOwnProperty.call(a,f)&&e(u,a,f);return t(u,a),u};Object.defineProperty(r,"__esModule",{value:!0}),r.useDefaultAdapter=r.useAdapters=r.RUNTIME=void 0;var o=n(Fy()),i=jn(),s;(function(a){a.WEB="web",a.WX_MP="wx_mp"})(s=r.RUNTIME||(r.RUNTIME={}));function c(a){for(var u=(0,i.isArray)(a)?a:[a],f=0,d=u;f<d.length;f++){var y=d[f],m=y.isMatch,v=y.genAdapter,I=y.runtime;if(m())return{adapter:v(),runtime:I}}}r.useAdapters=c;function l(){return{adapter:o.genAdapter(),runtime:s.WEB}}r.useDefaultAdapter=l}(mr)),mr}var By=Uy(),Bo=function(){return Bo=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Bo.apply(this,arguments)},Lo=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Mo=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Ly=function(){function r(e){this.localStorage=(e==null?void 0:e.localStorage)||globalThis.localStorage}return r.prototype.getItem=function(e){return Lo(this,void 0,void 0,function(){return Mo(this,function(t){return[2,this.localStorage.getItem(e)]})})},r.prototype.removeItem=function(e){return Lo(this,void 0,void 0,function(){return Mo(this,function(t){return this.localStorage.removeItem(e),[2]})})},r.prototype.setItem=function(e,t){return Lo(this,void 0,void 0,function(){return Mo(this,function(n){return this.localStorage.setItem(e,t),[2]})})},r.prototype.getItemSync=function(e){return this.localStorage.getItem(e)},r.prototype.setItemSync=function(e,t){this.localStorage.setItem(e,t)},r.prototype.removeItemSync=function(e){this.localStorage.removeItem(e)},r}(),My=/^[^:]+:\/\/[^/]+(\/[^?#]+)/;function qy(r){return function(e,t){var n;return Lo(this,void 0,void 0,function(){var o;return Mo(this,function(i){return o=(n=t==null?void 0:t.headers)===null||n===void 0?void 0:n["x-request-id"],[2,new Promise(function(s,c){var l=Object.assign({},t);l.body&&typeof l.body!="string"&&(l.body=JSON.stringify(l.body));var a=wx.request({url:e,data:l.body,timeout:r._timeout,method:l.method||"GET",header:l.headers,success:function(u){var f,d;(u.code||!((f=u.data)===null||f===void 0)&&f.error_code)&&(u={error:u.code||u.data.error,error_description:u.data.error_description||u.message||u.code||u.data.error_code,request_id:u.requestId,error_code:(d=u.data)===null||d===void 0?void 0:d.error_code}),u.request_id||(u.request_id=u.request_id||o),u.error&&(u.error_uri=jy(e),c(u)),s(u.data||{})},fail:function(u){c({error:"unreachable",error_description:u.message})},complete:function(u){if(!(!u||!u.errMsg)&&!(!r._timeout||r._restrictedMethods.indexOf("request")===-1)){var f=u.errMsg;if(f==="request:fail timeout"){console.warn(r._timeoutMsg);try{a.abort()}catch{}}}}})})]})})}}function jy(r){return My.test(r)?RegExp.$1:r}var ky=function(r){if(!dr.isMatch()||r.storage&&r.baseRequest)return r;var e={};try{var t=dr.genAdapter(),n=t.localStorage,o=t.reqClass;if(n&&(e.storage=new Ly({localStorage:n})),o){var i=new o({timeout:1e4,restrictedMethods:["get","post","upload","download","request"]});e.request=qy(i)}return r.captchaOptions&&(e.baseRequest=e.request,e.request=void 0),Bo(Bo({},r),e)}catch(s){console.error("adapter generate fail:",s)}return r},Br=function(){return Br=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Br.apply(this,arguments)},be=function(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var c=r.length-1;c>=0;c--)(s=r[c])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i},H=function(r,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,e)},z=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},J=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},$y="auth",Os={LOGIN_STATE_CHANGED:"loginStateChanged"},Ts=new Ny.CloudbaseEventEmitter,Wy=function(){function r(e){var t=e.cache,n=e.oauthInstance;this.cache=t,this.oauthInstance=n,this.setUserInfo()}return r.prototype.checkLocalInfo=function(){return z(this,void 0,void 0,function(){return J(this,function(e){return this.uid=this.getLocalUserInfo("uid"),this.gender=this.getLocalUserInfo("gender"),this.picture=this.getLocalUserInfo("picture"),this.email=this.getLocalUserInfo("email"),this.emailVerified=this.getLocalUserInfo("email_verified"),this.phoneNumber=this.getLocalUserInfo("phone_number"),this.username=this.getLocalUserInfo("username"),this.name=this.getLocalUserInfo("name"),this.birthdate=this.getLocalUserInfo("birthdate"),this.zoneinfo=this.getLocalUserInfo("zoneinfo"),this.locale=this.getLocalUserInfo("locale"),this.sub=this.getLocalUserInfo("sub"),this.createdFrom=this.getLocalUserInfo("created_from"),this.providers=this.getLocalUserInfo("providers"),[2]})})},r.prototype.checkLocalInfoAsync=function(){return z(this,void 0,void 0,function(){var e,t,n,o;return J(this,function(i){switch(i.label){case 0:return e=this,[4,this.getLocalUserInfoAsync("uid")];case 1:return e.uid=i.sent(),t=this,[4,this.getLocalUserInfoAsync("gender")];case 2:return t.gender=i.sent(),this.picture=this.getLocalUserInfo("picture"),n=this,[4,this.getLocalUserInfoAsync("email")];case 3:return n.email=i.sent(),this.emailVerified=this.getLocalUserInfo("email_verified"),this.phoneNumber=this.getLocalUserInfo("phone_number"),o=this,[4,this.getLocalUserInfoAsync("username")];case 4:return o.username=i.sent(),this.name=this.getLocalUserInfo("name"),this.birthdate=this.getLocalUserInfo("birthdate"),this.zoneinfo=this.getLocalUserInfo("zoneinfo"),this.locale=this.getLocalUserInfo("locale"),this.sub=this.getLocalUserInfo("sub"),this.createdFrom=this.getLocalUserInfo("created_from"),this.providers=this.getLocalUserInfo("providers"),[2]}})})},r.prototype.update=function(e){return z(this,void 0,void 0,function(){var t;return J(this,function(n){switch(n.label){case 0:return[4,this.oauthInstance.authApi.setUserProfile(Br({},e))];case 1:return t=n.sent(),this.setLocalUserInfo(t),[2]}})})},r.prototype.updateUserBasicInfo=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){switch(t.label){case 0:return[4,this.oauthInstance.authApi.updateUserBasicInfo(Br({},e))];case 1:return t.sent(),this.setLocalUserInfo({username:e.username}),[2]}})})},r.prototype.updatePassword=function(e,t){return this.oauthInstance.authApi.updatePasswordByOld({old_password:t,new_password:e})},r.prototype.updateUsername=function(e){return typeof e!="string"&&kn.throwError(pe.ERRORS.INVALID_PARAMS,"username must be a string"),this.update({username:e})},r.prototype.refresh=function(e){return z(this,void 0,void 0,function(){var t;return J(this,function(n){switch(n.label){case 0:return[4,this.oauthInstance.authApi.getUserInfo(e)];case 1:return t=n.sent(),this.setLocalUserInfo(t),[2,t]}})})},r.prototype.getLocalUserInfo=function(e){var t=this.cache.keys.userInfoKey,n=this.cache.getStore(t);return n[e]},r.prototype.getLocalUserInfoAsync=function(e){return z(this,void 0,void 0,function(){var t,n;return J(this,function(o){switch(o.label){case 0:return t=this.cache.keys.userInfoKey,[4,this.cache.getStoreAsync(t)];case 1:return n=o.sent(),[2,n[e]]}})})},r.prototype.setUserInfo=function(){var e=this,t=this.cache.keys.userInfoKey,n=this.cache.getStore(t);["uid","email","name","gender","picture","email_verified","phone_number","birthdate","zoneinfo","locale","sub","created_from","providers","username"].forEach(function(o){e[o]=n[o]})},r.prototype.setLocalUserInfo=function(e){var t=this.cache.keys.userInfoKey;this.cache.setStore(t,e),this.setUserInfo()},be([_e.catchErrorsDecorator({title:"更新用户信息失败",messages:["请确认以下各项:"," 1 - 调用 User.update() 的语法或参数是否正确"," 2 - 用户信息中是否包含非法值","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"update",null),be([_e.catchErrorsDecorator({title:"更新密码失败",messages:["请确认以下各项:"," 1 - 调用 User.updatePassword() 的语法或参数是否正确"," 3 - 新密码中是否包含非法字符","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[String,String]),H("design:returntype",void 0)],r.prototype,"updatePassword",null),be([_e.catchErrorsDecorator({title:"更新用户名失败",messages:["请确认以下各项:"," 1 - 调用 User.updateUsername() 的语法或参数是否正确"," 2 - 当前环境是否开通了用户名密码登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[String]),H("design:returntype",void 0)],r.prototype,"updateUsername",null),be([_e.catchErrorsDecorator({title:"刷新本地用户信息失败",messages:["请确认以下各项:"," 1 - 调用 User.refresh() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"refresh",null),r}(),As=function(){function r(e){var t=e.envId,n=e.cache,o=e.oauthInstance;t||kn.throwError(pe.ERRORS.INVALID_PARAMS,"envId is not defined"),this.cache=n,this.oauthInstance=o,this.user=new Wy({cache:this.cache,oauthInstance:o})}return r.prototype.checkLocalState=function(){var e;this.oauthLoginState=(e=this.oauthInstance)===null||e===void 0?void 0:e.authApi.hasLoginStateSync(),this.user.checkLocalInfo()},r.prototype.checkLocalStateAsync=function(){var e;return z(this,void 0,void 0,function(){return J(this,function(t){switch(t.label){case 0:return[4,(e=this.oauthInstance)===null||e===void 0?void 0:e.authApi.getLoginState()];case 1:return t.sent(),[4,this.user.checkLocalInfoAsync()];case 2:return t.sent(),[2]}})})},r}(),Hy=function(){function r(e){this.config=e,this.cache=e.cache,this.oauthInstance=e.oauthInstance}return r.prototype.bindPhoneNumber=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.editContact(e)]})})},r.prototype.unbindProvider=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.unbindProvider(e)]})})},r.prototype.bindEmail=function(e){return this.oauthInstance.authApi.editContact(e)},r.prototype.verify=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.verify(e)]})})},r.prototype.getVerification=function(e,t){return z(this,void 0,void 0,function(){return J(this,function(n){return[2,this.oauthInstance.authApi.getVerification(e,t)]})})},Object.defineProperty(r.prototype,"currentUser",{get:function(){if(this.cache.mode==="async"){kn.printWarn(pe.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getCurrentUser insteed");return}var e=this.hasLoginState();return e&&e.user||null},enumerable:!1,configurable:!0}),r.prototype.getCurrentUser=function(){return z(this,void 0,void 0,function(){var e;return J(this,function(t){switch(t.label){case 0:return[4,this.getLoginState()];case 1:return e=t.sent(),e?[4,e.user.checkLocalInfoAsync()]:[3,3];case 2:return t.sent(),[2,e.user||null];case 3:return[2,null]}})})},r.prototype.signInAnonymously=function(e){return e===void 0&&(e={}),z(this,void 0,void 0,function(){return J(this,function(t){switch(t.label){case 0:return[4,this.oauthInstance.authApi.signInAnonymously(e)];case 1:return t.sent(),[2,this.createLoginState()]}})})},r.prototype.signInAnonymouslyInWx=function(e){var t=e===void 0?{}:e,n=t.useWxCloud;return z(this,void 0,void 0,function(){var o,i,s=this;return J(this,function(c){switch(c.label){case 0:if(!dr.isMatch())throw Error("wx api undefined");return o=wx.getAccountInfoSync().miniProgram,i=function(l){return z(s,void 0,void 0,function(){var a,u,f;return J(this,function(d){switch(d.label){case 0:a=void 0,u=void 0,d.label=1;case 1:return d.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_id:o==null?void 0:o.appId,provider_code:l,provider_params:{provider_code_type:"open_id",appid:o==null?void 0:o.appId}},n)];case 2:if(a=d.sent(),a!=null&&a.error_code||!a.provider_token)throw a;return[4,this.oauthInstance.authApi.signInAnonymously({provider_token:a.provider_token},n)];case 3:if(u=d.sent(),u!=null&&u.error_code)throw u;return[3,5];case 4:throw f=d.sent(),f;case 5:return[2]}})})},[4,new Promise(function(l,a){wx.login({success:function(u){return z(s,void 0,void 0,function(){var f;return J(this,function(d){switch(d.label){case 0:return d.trys.push([0,2,,3]),[4,i(u.code)];case 1:return d.sent(),l(!0),[3,3];case 2:return f=d.sent(),a(f),[3,3];case 3:return[2]}})})},fail:function(u){var f=new Error(u==null?void 0:u.errMsg);f.code=u==null?void 0:u.errno,a(f)}})})];case 1:return c.sent(),[2,this.createLoginState(void 0,{asyncRefreshUser:!0})]}})})},r.prototype.bindOpenId=function(){return z(this,void 0,void 0,function(){var e,t,n=this;return J(this,function(o){switch(o.label){case 0:if(!dr.isMatch())throw Error("wx api undefined");return e=wx.getAccountInfoSync().miniProgram,t=function(i){return z(n,void 0,void 0,function(){var s,c;return J(this,function(l){switch(l.label){case 0:s=void 0,l.label=1;case 1:return l.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_id:e==null?void 0:e.appId,provider_code:i,provider_params:{provider_code_type:"open_id",appid:e==null?void 0:e.appId}})];case 2:if(s=l.sent(),s!=null&&s.error_code||!s.provider_token)throw s;return[4,this.oauthInstance.authApi.bindWithProvider({provider_token:s.provider_token})];case 3:return l.sent(),[3,5];case 4:throw c=l.sent(),c;case 5:return[2]}})})},[4,new Promise(function(i,s){wx.login({success:function(c){return z(n,void 0,void 0,function(){var l;return J(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,t(c.code)];case 1:return a.sent(),i(!0),[3,3];case 2:return l=a.sent(),s(l),[3,3];case 3:return[2]}})})},fail:function(c){var l=new Error(c==null?void 0:c.errMsg);l.code=c==null?void 0:c.errno,s(l)}})})];case 1:return o.sent(),[2]}})})},r.prototype.signInWithOpenId=function(e){var t=e===void 0?{}:e,n=t.useWxCloud,o=n===void 0?!0:n;return z(this,void 0,void 0,function(){var i,s,c=this;return J(this,function(l){switch(l.label){case 0:if(!dr.isMatch())throw Error("wx api undefined");return i=wx.getAccountInfoSync().miniProgram,s=function(a){return z(c,void 0,void 0,function(){var u,f,d;return J(this,function(y){switch(y.label){case 0:u=void 0,f=void 0,y.label=1;case 1:return y.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_id:i==null?void 0:i.appId,provider_code:a,provider_params:{provider_code_type:"open_id",appid:i==null?void 0:i.appId}},o)];case 2:if(u=y.sent(),u!=null&&u.error_code||!u.provider_token)throw u;return[4,this.oauthInstance.authApi.signInWithProvider({provider_token:u.provider_token},o)];case 3:if(f=y.sent(),f!=null&&f.error_code)throw f;return[3,5];case 4:throw d=y.sent(),d;case 5:return[4,this.oauthInstance.oauth2client.setCredentials(f)];case 6:return y.sent(),[2]}})})},[4,new Promise(function(a,u){wx.login({success:function(f){return z(c,void 0,void 0,function(){var d;return J(this,function(y){switch(y.label){case 0:return y.trys.push([0,2,,3]),[4,s(f.code)];case 1:return y.sent(),a(!0),[3,3];case 2:return d=y.sent(),u(d),[3,3];case 3:return[2]}})})},fail:function(f){var d=new Error(f==null?void 0:f.errMsg);d.code=f==null?void 0:f.errno,u(d)}})})];case 1:return l.sent(),[2,this.createLoginState()]}})})},r.prototype.signInWithUnionId=function(){return z(this,void 0,void 0,function(){var e,t=this;return J(this,function(n){switch(n.label){case 0:if(!dr.isMatch())throw Error("wx api undefined");n.label=1;case 1:return n.trys.push([1,3,,4]),[4,new Promise(function(o,i){var s=wx.getAccountInfoSync().miniProgram;wx.login({success:function(c){return z(t,void 0,void 0,function(){var l,a,u,f,d;return J(this,function(y){switch(y.label){case 0:l=s==null?void 0:s.appId,y.label=1;case 1:return y.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_code:c.code,provider_id:l,provider_params:{provider_code_type:"union_id",appid:s==null?void 0:s.appId}})];case 2:return a=y.sent(),u=a.provider_token,u?[4,this.oauthInstance.authApi.signInWithProvider({provider_id:l,provider_token:u})]:(i(a),[2]);case 3:return f=y.sent(),f!=null&&f.error_code?(i(f),[2]):(o(!0),[3,5]);case 4:return d=y.sent(),i(d),[3,5];case 5:return[2]}})})},fail:function(c){var l=new Error(c==null?void 0:c.errMsg);l.code=c==null?void 0:c.errno,i(l)}})})];case 2:return n.sent(),[3,4];case 3:throw e=n.sent(),e;case 4:return[2,this.createLoginState()]}})})},r.prototype.signInWithPhoneAuth=function(e){var t=e.phoneCode,n=t===void 0?"":t;return z(this,void 0,void 0,function(){var o,i,s,c,l,a;return J(this,function(u){switch(u.label){case 0:if(!dr.isMatch())throw Error("wx api undefined");return o=wx.getAccountInfoSync().miniProgram,i={provider_params:{provider_code_type:"phone"},provider_id:o.appId},[4,wx.login()];case 1:s=u.sent().code,i.provider_code=s,u.label=2;case 2:return u.trys.push([2,6,,7]),[4,this.oauthInstance.authApi.grantProviderToken(i)];case 3:if(c=u.sent(),c.error_code)throw c;return[4,this.oauthInstance.authApi.patchProviderToken({provider_token:c.provider_token,provider_id:o.appId,provider_params:{code:n,provider_code_type:"phone"}})];case 4:if(c=u.sent(),c.error_code)throw c;return[4,this.oauthInstance.authApi.signInWithProvider({provider_token:c.provider_token})];case 5:if(l=u.sent(),l!=null&&l.error_code)throw l;return[3,7];case 6:throw a=u.sent(),a;case 7:return[2,this.createLoginState()]}})})},r.prototype.signInWithSms=function(e){var t=e.verificationInfo,n=t===void 0?{verification_id:"",is_user:!1}:t,o=e.verificationCode,i=o===void 0?"":o,s=e.phoneNum,c=s===void 0?"":s,l=e.bindInfo,a=l===void 0?void 0:l;return z(this,void 0,void 0,function(){return J(this,function(u){try{return[2,this.signInWithUsername({verificationInfo:n,verificationCode:i,bindInfo:a,username:c,loginType:"sms"})]}catch(f){throw f}return[2]})})},r.prototype.signInWithEmail=function(e){var t=e.verificationInfo,n=t===void 0?{verification_id:"",is_user:!1}:t,o=e.verificationCode,i=o===void 0?"":o,s=e.bindInfo,c=s===void 0?void 0:s,l=e.email,a=l===void 0?"":l;return z(this,void 0,void 0,function(){return J(this,function(u){try{return[2,this.signInWithUsername({verificationInfo:n,verificationCode:i,bindInfo:c,username:a,loginType:"email"})]}catch(f){throw f}return[2]})})},r.prototype.setCustomSignFunc=function(e){this.oauthInstance.authApi.setCustomSignFunc(e)},r.prototype.signInWithCustomTicket=function(){return z(this,void 0,void 0,function(){return J(this,function(e){switch(e.label){case 0:return[4,this.oauthInstance.authApi.signInWithCustomTicket()];case 1:return e.sent(),[2,this.createLoginState()]}})})},r.prototype.signIn=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){switch(t.label){case 0:return[4,this.oauthInstance.authApi.signIn(e)];case 1:return t.sent(),[2,this.createLoginState(e)]}})})},r.prototype.signUp=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){switch(t.label){case 0:return[4,this.oauthInstance.authApi.signUp(e)];case 1:return t.sent(),[2,this.createLoginState()]}})})},r.prototype.setPassword=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.setPassword(e)]})})},r.prototype.isUsernameRegistered=function(e){return z(this,void 0,void 0,function(){var t;return J(this,function(n){switch(n.label){case 0:return typeof e!="string"&&kn.throwError(pe.ERRORS.INVALID_PARAMS,"username must be a string"),[4,this.oauthInstance.authApi.checkIfUserExist({username:e})];case 1:return t=n.sent().exist,[2,t]}})})},r.prototype.signOut=function(e){return z(this,void 0,void 0,function(){var t,n;return J(this,function(o){switch(o.label){case 0:return t=this.cache.keys.userInfoKey,[4,this.oauthInstance.authApi.signOut(e)];case 1:return n=o.sent(),[4,this.cache.removeStoreAsync(t)];case 2:return o.sent(),Ts.fire(Os.LOGIN_STATE_CHANGED),[2,n]}})})},r.prototype.hasLoginState=function(){var e;if(this.cache.mode==="async"){kn.printWarn(pe.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getLoginState insteed");return}var t=(e=this.oauthInstance)===null||e===void 0?void 0:e.authApi.hasLoginStateSync();if(t){var n=new As({envId:this.config.env,cache:this.cache,oauthInstance:this.oauthInstance});return n}return null},r.prototype.getLoginState=function(){return z(this,void 0,void 0,function(){var e,t;return J(this,function(n){switch(n.label){case 0:e=null,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.oauthInstance.authApi.getLoginState()];case 2:return e=n.sent(),[3,4];case 3:return n.sent(),[2,null];case 4:return e?(t=new As({envId:this.config.env,cache:this.cache,oauthInstance:this.oauthInstance}),[2,t]):[2,null]}})})},r.prototype.getUserInfo=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.getUserInfo(e)]})})},r.prototype.getWedaUserInfo=function(){return z(this,void 0,void 0,function(){return J(this,function(e){return[2,this.oauthInstance.authApi.getWedaUserInfo()]})})},r.prototype.updateUserBasicInfo=function(e){return z(this,void 0,void 0,function(){var t;return J(this,function(n){switch(n.label){case 0:return[4,this.getLoginState()];case 1:return t=n.sent(),t?[4,t.user.updateUserBasicInfo(e)]:[3,3];case 2:n.sent(),n.label=3;case 3:return[2]}})})},r.prototype.getAuthHeader=function(){return console.error("Auth.getAuthHeader API 已废弃"),{}},r.prototype.bindWithProvider=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.bindWithProvider(e)]})})},r.prototype.queryUser=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.queryUserProfile(e)]})})},r.prototype.getAccessToken=function(){return z(this,void 0,void 0,function(){var e;return J(this,function(t){switch(t.label){case 0:return[4,this.oauthInstance.oauth2client.getAccessToken()];case 1:return e=t.sent(),[2,{accessToken:e,env:this.config.env}]}})})},r.prototype.grantProviderToken=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.grantProviderToken(e)]})})},r.prototype.patchProviderToken=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.patchProviderToken(e)]})})},r.prototype.signInWithProvider=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){switch(t.label){case 0:return[4,this.oauthInstance.authApi.signInWithProvider(e)];case 1:return t.sent(),[2,this.createLoginState(e)]}})})},r.prototype.signInWithWechat=function(e){return e===void 0&&(e={}),z(this,void 0,void 0,function(){return J(this,function(t){switch(t.label){case 0:return[4,this.oauthInstance.authApi.signInWithWechat(e)];case 1:return t.sent(),[2,this.createLoginState(e)]}})})},r.prototype.grantToken=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){switch(t.label){case 0:return[4,this.oauthInstance.authApi.grantToken(e)];case 1:return t.sent(),[2,this.createLoginState()]}})})},r.prototype.genProviderRedirectUri=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.genProviderRedirectUri(e)]})})},r.prototype.resetPassword=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.resetPassword(e)]})})},r.prototype.deviceAuthorize=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.deviceAuthorize(e)]})})},r.prototype.sudo=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.sudo(e)]})})},r.prototype.deleteMe=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.deleteMe(e)]})})},r.prototype.getProviders=function(){return z(this,void 0,void 0,function(){return J(this,function(e){return[2,this.oauthInstance.authApi.getProviders()]})})},r.prototype.loginScope=function(){return z(this,void 0,void 0,function(){return J(this,function(e){return[2,this.oauthInstance.authApi.loginScope()]})})},r.prototype.loginGroups=function(){return z(this,void 0,void 0,function(){return J(this,function(e){return[2,this.oauthInstance.authApi.loginGroups()]})})},r.prototype.onLoginStateChanged=function(e){return z(this,void 0,void 0,function(){var t,n=this;return J(this,function(o){switch(o.label){case 0:return Ts.on(Os.LOGIN_STATE_CHANGED,function(){return z(n,void 0,void 0,function(){var i;return J(this,function(s){switch(s.label){case 0:return[4,this.getLoginState()];case 1:return i=s.sent(),e.call(this,i),[2]}})})}),[4,this.getLoginState()];case 1:return t=o.sent(),e.call(this,t),[2]}})})},r.prototype.refreshTokenForce=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.refreshTokenForce(e)]})})},r.prototype.getCredentials=function(){return z(this,void 0,void 0,function(){return J(this,function(e){return[2,this.oauthInstance.authApi.getCredentials()]})})},r.prototype.setCredentials=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){switch(t.label){case 0:return[4,this.oauthInstance.oauth2client.setCredentials(e)];case 1:return t.sent(),[2]}})})},r.prototype.getProviderSubType=function(){return z(this,void 0,void 0,function(){return J(this,function(e){return[2,this.oauthInstance.authApi.getProviderSubType()]})})},r.prototype.createCaptchaData=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.createCaptchaData(e)]})})},r.prototype.verifyCaptchaData=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.verifyCaptchaData(e)]})})},r.prototype.getMiniProgramQrCode=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.getMiniProgramCode(e)]})})},r.prototype.getMiniProgramQrCodeStatus=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.getMiniProgramQrCodeStatus(e)]})})},r.prototype.modifyPassword=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.modifyPassword(e)]})})},r.prototype.modifyPasswordWithoutLogin=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.modifyPasswordWithoutLogin(e)]})})},r.prototype.getUserBehaviorLog=function(e){return z(this,void 0,void 0,function(){return J(this,function(t){return[2,this.oauthInstance.authApi.getUserBehaviorLog(e)]})})},r.prototype.toDefaultLoginPage=function(e){return e===void 0&&(e={}),z(this,void 0,void 0,function(){var t,n,o,i;return J(this,function(s){return t=e.config_version||"env",dr.isMatch()?wx.navigateTo({url:"/packages/$wd_system/pages/login/index"}):(n=e.redirect_uri||window.location.href,o=new URL(n),i="".concat(o.origin,"/__auth/?app_id=").concat(e.app_id||"","&env_id=").concat(this.config.env,"&client_id=").concat(this.config.clientId,"&config_version=").concat(t,"&redirect_uri=").concat(encodeURIComponent(n)),window.location.href=i),[2]})})},r.prototype.createLoginState=function(e,t){return z(this,void 0,void 0,function(){var n;return J(this,function(o){switch(o.label){case 0:return n=new As({envId:this.config.env,cache:this.cache,oauthInstance:this.oauthInstance}),[4,n.checkLocalStateAsync()];case 1:return o.sent(),t!=null&&t.asyncRefreshUser?(n.user.refresh(e),[3,4]):[3,2];case 2:return[4,n.user.refresh(e)];case 3:o.sent(),o.label=4;case 4:return Ts.fire(Os.LOGIN_STATE_CHANGED),[2,n]}})})},r.prototype.signInWithUsername=function(e){var t=e.verificationInfo,n=t===void 0?{verification_id:"",is_user:!1}:t,o=e.verificationCode,i=o===void 0?"":o,s=e.username,c=s===void 0?"":s,l=e.bindInfo,a=l===void 0?void 0:l,u=e.loginType,f=u===void 0?"":u;return z(this,void 0,void 0,function(){var d,y,m,v,I,S,w,O;return J(this,function(T){switch(T.label){case 0:return T.trys.push([0,8,,9]),[4,this.oauthInstance.authApi.verify({verification_id:n.verification_id,verification_code:i})];case 1:if(d=T.sent(),d!=null&&d.error_code)throw d;return y=d.verification_token,m="+86 ".concat(c),v={phone_number:m},f==="email"&&(m=c,v={email:m}),n.is_user?[4,this.oauthInstance.authApi.signIn({username:m,verification_token:y})]:[3,5];case 2:if(I=T.sent(),I!=null&&I.error_code)throw I;return a?[4,this.oauthInstance.authApi.bindWithProvider({provider_token:a==null?void 0:a.providerToken})]:[3,4];case 3:if(S=T.sent(),S!=null&&S.error_code)throw S;T.label=4;case 4:return[3,7];case 5:return[4,this.oauthInstance.authApi.signUp(Br(Br({},v),{verification_token:y,provider_token:a==null?void 0:a.providerId}))];case 6:if(w=T.sent(),w!=null&&w.error_code)throw w;T.label=7;case 7:return[2,this.createLoginState()];case 8:throw O=T.sent(),O;case 9:return[2]}})})},be([_e.catchErrorsDecorator({title:"绑定手机号失败",messages:["请确认以下各项:"," 1 - 调用 auth().bindPhoneNumber() 的语法或参数是否正确"," 2 - 当前环境是否开通了短信验证码登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"bindPhoneNumber",null),be([_e.catchErrorsDecorator({title:"解除三方绑定失败",messages:["请确认以下各项:"," 1 - 调用 auth().unbindProvider() 的语法或参数是否正确"," 2 - 当前账户是否已经与此登录方式解绑","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"unbindProvider",null),be([_e.catchErrorsDecorator({title:"绑定邮箱地址失败",messages:["请确认以下各项:"," 1 - 调用 auth().bindEmail() 的语法或参数是否正确"," 2 - 当前环境是否开通了邮箱密码登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",void 0)],r.prototype,"bindEmail",null),be([_e.catchErrorsDecorator({title:"验证码验证失败",messages:["请确认以下各项:"," 1 - 调用 auth().verify() 的语法或参数是否正确"," 2 - 当前环境是否开通了手机验证码/邮箱登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"verify",null),be([_e.catchErrorsDecorator({title:"获取验证码失败",messages:["请确认以下各项:"," 1 - 调用 auth().getVerification() 的语法或参数是否正确"," 2 - 当前环境是否开通了手机验证码/邮箱登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object,Object]),H("design:returntype",Promise)],r.prototype,"getVerification",null),be([_e.catchErrorsDecorator({title:"获取用户信息失败",messages:["请确认以下各项:"," 1 - 调用 auth().getCurrentUser() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[]),H("design:returntype",Promise)],r.prototype,"getCurrentUser",null),be([_e.catchErrorsDecorator({title:"匿名登录失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了匿名登录"," 2 - 调用 auth().signInAnonymously() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"signInAnonymously",null),be([_e.catchErrorsDecorator({title:"小程序匿名登录失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了匿名登录"," 2 - 调用 auth().signInAnonymouslyInWx() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"signInAnonymouslyInWx",null),be([_e.catchErrorsDecorator({title:"小程序绑定OpenID失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了小程序openId静默登录"," 2 - 调用 auth().bindOpenId() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[]),H("design:returntype",Promise)],r.prototype,"bindOpenId",null),be([_e.catchErrorsDecorator({title:"小程序openId静默登录失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了小程序openId静默登录"," 2 - 调用 auth().signInWithOpenId() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"signInWithOpenId",null),be([_e.catchErrorsDecorator({title:"小程序unionId静默登录失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了小程序unionId静默登录"," 2 - 调用 auth().signInWithUnionId() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[]),H("design:returntype",Promise)],r.prototype,"signInWithUnionId",null),be([_e.catchErrorsDecorator({title:"小程序手机号授权登录失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了小程序手机号授权登录"," 2 - 调用 auth().signInWithPhoneAuth() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"signInWithPhoneAuth",null),be([_e.catchErrorsDecorator({title:"短信验证码登陆",messages:["请确认以下各项:"," 1 - 当前环境是否开启了小程序短信验证码登陆"," 2 - 调用 auth().signInWithSms() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"signInWithSms",null),be([_e.catchErrorsDecorator({title:"邮箱验证码登陆",messages:["请确认以下各项:"," 1 - 当前环境是否开启了邮箱登陆"," 2 - 调用 auth().signInWithEmail() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"signInWithEmail",null),be([_e.catchErrorsDecorator({title:"自定义登录失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了自定义登录"," 2 - 调用 auth().signInWithCustomTicket() 的语法或参数是否正确"," 3 - ticket 是否归属于当前环境"," 4 - 创建 ticket 的自定义登录私钥是否过期","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[]),H("design:returntype",Promise)],r.prototype,"signInWithCustomTicket",null),be([_e.catchErrorsDecorator({title:"注册失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了指定登录方式"," 2 - 调用 auth().signUp() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"signUp",null),be([_e.catchErrorsDecorator({title:"获取用户是否被占用失败",messages:["请确认以下各项:"," 1 - 调用 auth().isUsernameRegistered() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[String]),H("design:returntype",Promise)],r.prototype,"isUsernameRegistered",null),be([_e.catchErrorsDecorator({title:"用户登出失败",messages:["请确认以下各项:"," 1 - 调用 auth().signOut() 的语法或参数是否正确"," 2 - 当前用户是否为匿名登录(匿名登录不支持signOut)","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"signOut",null),be([_e.catchErrorsDecorator({title:"获取本地登录态失败",messages:["请确认以下各项:"," 1 - 调用 auth().getLoginState() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[]),H("design:returntype",Promise)],r.prototype,"getLoginState",null),be([_e.catchErrorsDecorator({title:"获取用户信息失败",messages:["请确认以下各项:"," 1 - 是否已登录"," 2 - 调用 auth().getUserInfo() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"getUserInfo",null),be([_e.catchErrorsDecorator({title:"获取微搭插件用户信息失败",messages:["请确认以下各项:"," 1 - 是否已登录"," 2 - 调用 auth().getWedaUserInfo() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[]),H("design:returntype",Promise)],r.prototype,"getWedaUserInfo",null),be([_e.catchErrorsDecorator({title:"绑定第三方登录方式失败",messages:["请确认以下各项:"," 1 - 调用 auth().bindWithProvider() 的语法或参数是否正确"," 2 - 此账户是否已经绑定此第三方","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[Object]),H("design:returntype",Promise)],r.prototype,"bindWithProvider",null),be([_e.catchErrorsDecorator({title:"获取身份源类型",messages:["请确认以下各项:"," 1 - 调用 auth().getProviderSubType() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(pe.COMMUNITY_SITE_URL)]}),H("design:type",Function),H("design:paramtypes",[]),H("design:returntype",Promise)],r.prototype,"getProviderSubType",null),r}();function Gy(r,e){var t=r.region,n=t===void 0?"ap-shanghai":t,o=(e==null?void 0:e.platform)||By.useDefaultAdapter(),i=o.runtime,s=e||{},c=s.env,l=s.clientId,a=s.debug,u=s.cache,f=s.app,d=(e||{}).apiOrigin;d||(d="https://".concat(c,".").concat(n,".tcb-api.tencentcloudapi.com"));var y=new Oy(ky({env:c,clientId:l,apiOrigin:d,storage:r==null?void 0:r.storage,baseRequest:r==null?void 0:r.baseRequest,request:r==null?void 0:r.request,anonymousSignInFunc:r==null?void 0:r.anonymousSignInFunc,captchaOptions:r==null?void 0:r.captchaOptions,wxCloud:r==null?void 0:r.wxCloud})),m=new Hy({env:c,clientId:l,region:n,persistence:r.persistence,debug:a,cache:u||new Dy.CloudbaseCache({persistence:r.persistence,keys:{userInfoKey:"user_info_".concat(c)},platformInfo:o}),runtime:i||"web",_fromApp:f,oauthInstance:y});return{authInstance:m,oauthInstance:y}}var Ml={name:$y,namespace:"auth",entity:function(r){if(r===void 0&&(r={region:"",persistence:"local"}),this.authInstance)return kn.printWarn(pe.ERRORS.INVALID_OPERATION,"every cloudbase instance should has only one auth object"),this.authInstance;var e=this.platform.adapter,t=r.persistence||e.primaryStorage;t&&t!==this.config.persistence&&this.updateConfig({persistence:t});var n=Gy(Br(Br({wxCloud:this.config.wxCloud,storage:this.config.storage},r),{persistence:this.config.persistence}),{env:this.config.env,clientId:this.config.clientId,apiOrigin:this.request.getBaseEndPoint(),platform:this.platform,cache:this.cache,app:this,debug:this.config.debug}),o=n.authInstance,i=n.oauthInstance;return this.oauthInstance=i,this.authInstance=o,this.authInstance}};try{cloudbase.registerComponent(Ml)}catch{}function Vy(r){try{r.registerComponent(Ml)}catch(e){console.warn(e)}}var qo=function(){return qo=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},qo.apply(this,arguments)},ql=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},jl=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},kl=at,Rs="cloudrun",zy=function(){function r(){}return r.prototype.callContainer=function(e){return ql(this,void 0,void 0,function(){var t,n,o;return jl(this,function(i){switch(i.label){case 0:if(t=e.name,n=e.data,!t)throw new Error(JSON.stringify({code:kl.INVALID_PARAMS,msg:"[".concat(Rs,".callContainer] invalid name")}));try{o=n?JSON.stringify(n):""}catch{throw new Error(JSON.stringify({code:kl.INVALID_PARAMS,msg:"[".concat(Rs,".callContainer] invalid data")}))}return[4,$l.call(this,qo(qo({},e),{data:o}))];case 1:return[2,i.sent()]}})})},r}();function $l(r){return ql(this,void 0,void 0,function(){var e,t,n,o,i,s,c,l,a,u;return jl(this,function(f){switch(f.label){case 0:return e=r.name,t=r.data,n=r.path,o=n===void 0?"":n,i=r.method,s=r.header,c=s===void 0?{}:s,l="https://".concat(this.config.env,".api.tcloudbasegateway.com/v1/cloudrun/").concat(e),a=o.startsWith("/")?o:"/".concat(o),[4,this.request.fetch({method:i||"POST",headers:Object.assign({},{"Content-Type":"application/json; charset=utf-8"},c),body:t,url:"".concat(l).concat(a)})];case 1:return u=f.sent(),[4,u.data];case 2:return[2,f.sent()]}})})}var Jy=new zy,Wl={name:Rs,entity:{callContainer:Jy.callContainer}};try{cloudbase.registerComponent(Wl)}catch{}function Ky(r){try{r.registerComponent(Wl)}catch(e){console.warn(e)}}var jo=function(){return jo=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},jo.apply(this,arguments)},Yy=function(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var c=r.length-1;c>=0;c--)(s=r[c])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i},Cs=function(r,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,e)},Qy=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Xy=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Zy=Ji,xs=at,em=Ki,Oi=Au,tm=Xi,ko="functions",rm=function(){function r(){}return r.prototype.callFunction=function(e,t){var n,o;return Qy(this,void 0,void 0,function(){var i,s,c,l,a,u,f,d,y,m,v,I,S,D,w,O,T,N,D,B;return Xy(this,function(R){switch(R.label){case 0:if(i=e.name,s=e.data,c=e.query,l=e.parse,a=e.search,u=e.type,f=e.path,d=f===void 0?"":f,y=e.method,m=e.header,v=m===void 0?{}:m,!i)throw new Error(JSON.stringify({code:xs.INVALID_PARAMS,msg:"[".concat(ko,".callFunction] invalid function name")}));try{I=s?JSON.stringify(s):""}catch{throw new Error(JSON.stringify({code:xs.INVALID_PARAMS,msg:"[".concat(ko,".callFunction] invalid data")}))}return u!=="cloudrun"?[3,2]:(S=Kh(),[4,$l.call(this,{name:i,data:I,path:d,method:y,header:jo(jo({},v),{"X-Request-Id":S})})]);case 1:return D=R.sent(),[2,{result:D,requestId:S}];case 2:w="functions.invokeFunction",O={inQuery:c,parse:l,search:a,function_name:i,request_data:I},T=this.request,R.label=3;case 3:return R.trys.push([3,5,,6]),[4,T.send(w,O,{defaultQuery:!((n=s==null?void 0:s.params)===null||n===void 0)&&n.action?{action:(o=s==null?void 0:s.params)===null||o===void 0?void 0:o.action}:{}})];case 4:if(N=R.sent(),N.code)return[2,Oi(t,null,N)];if(D=N.data.response_data,l)return[2,Oi(t,null,{result:D,requestId:N.requestId})];try{return D=JSON.parse(N.data.response_data),[2,Oi(t,null,{result:D,requestId:N.requestId})]}catch{Oi(t,new Error("[".concat(Zy(),"][").concat(xs.INVALID_PARAMS,"][").concat(ko,".callFunction] response data must be json")))}return[3,6];case 5:return B=R.sent(),Oi(t,B),[3,6];case 6:return[2]}})})},Yy([tm({customInfo:{},title:"函数调用失败",messages:["请确认以下各项:"," 1 - 调用 callFunction() 的语法或参数是否正确"," 2 - 当前环境下是否存在此函数"," 3 - 函数安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(em)]}),Cs("design:type",Function),Cs("design:paramtypes",[Object,Function]),Cs("design:returntype",Promise)],r.prototype,"callFunction",null),r}(),nm=new rm,Hl={name:ko,entity:{callFunction:nm.callFunction}};try{cloudbase.registerComponent(Hl)}catch{}function im(r){try{r.registerComponent(Hl)}catch(e){console.warn(e)}}var Lr=function(){return Lr=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Lr.apply(this,arguments)},Ti=function(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var c=r.length-1;c>=0;c--)(s=r[c])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i},nt=function(r,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,e)},Ai=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Ri=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Yt;(function(r){r.put="put",r.post="post"})(Yt||(Yt={}));var om=Ji,gr=at,Ci=Ki,Gl=Su,xi=Iu,am=Vh,Qt=Au,Ni=Xi,Xt="storage",sm=function(){function r(){}return r.prototype.uploadFile=function(e,t){return Ai(this,void 0,void 0,function(){var n,o,i,s,c,l,a,u,f,d,y,m,v,I,S,w,O,T,N,D,B,R,x,L,F,j;return Ri(this,function(V){switch(V.label){case 0:if(n=e.cloudPath,o=e.filePath,i=e.onUploadProgress,s=e.method,c=s===void 0?"put":s,l=e.headers,a=l===void 0?{}:l,!xi(n)||!o)throw new Error(JSON.stringify({code:gr.INVALID_PARAMS,msg:"[".concat(Xt,".uploadFile] invalid params")}));return u={put:Yt.put,post:Yt.post}[c.toLocaleLowerCase()]||Yt.put,f="storage.getUploadMetadata",d=this.request,y={path:n,method:u},u===Yt.put&&(y.headers=a),[4,d.send(f,y)];case 1:return m=V.sent(),v=m.data,I=v.url,S=v.authorization,w=v.token,O=v.fileId,T=v.cosFileId,N=v.download_url,D=m.requestId,B={url:I,file:o,name:n,onUploadProgress:i},R=Lr(Lr({},B),{method:Yt.put,headers:Lr(Lr({},a),{authorization:S,"x-cos-meta-fileid":T,"x-cos-security-token":w})}),x=Lr(Lr({},B),{method:Yt.post,data:{key:n,signature:S,"x-cos-meta-fileid":T,success_action_status:"201","x-cos-security-token":w}}),L=(j={},j[Yt.put]={params:R,isSuccess:function(W){return W>=200&&W<300}},j[Yt.post]={params:x,isSuccess:function(W){return W===201}},j),[4,d.upload(L[u].params)];case 2:return F=V.sent(),L[u].isSuccess(F.statusCode)?[2,Qt(t,null,{fileID:O,download_url:N,requestId:D})]:[2,Qt(t,new Error("[".concat(om(),"][").concat(gr.OPERATION_FAIL,"][").concat(Xt,"]:").concat(F.data)))]}})})},r.prototype.getUploadMetadata=function(e,t){return Ai(this,void 0,void 0,function(){var n,o,i,s,c;return Ri(this,function(l){switch(l.label){case 0:if(n=e.cloudPath,!xi(n))throw new Error(JSON.stringify({code:gr.INVALID_PARAMS,msg:"[".concat(Xt,".getUploadMetadata] invalid cloudPath")}));o=this.request,i="storage.getUploadMetadata",l.label=1;case 1:return l.trys.push([1,3,,4]),[4,o.send(i,{path:n})];case 2:return s=l.sent(),[2,Qt(t,null,s)];case 3:return c=l.sent(),[2,Qt(t,c)];case 4:return[2]}})})},r.prototype.deleteFile=function(e,t){return Ai(this,void 0,void 0,function(){var n,o,i,s,c,l,a,u;return Ri(this,function(f){switch(f.label){case 0:if(n=e.fileList,!n||!Gl(n)||n.length===0)throw new Error(JSON.stringify({code:gr.INVALID_PARAMS,msg:"[".concat(Xt,".deleteFile] fileList must not be empty")}));for(o=0,i=n;o<i.length;o++)if(s=i[o],!s||!xi(s))throw new Error(JSON.stringify({code:gr.INVALID_PARAMS,msg:"[".concat(Xt,".deleteFile] fileID must be string")}));return c="storage.batchDeleteFile",l=this.request,[4,l.send(c,{fileid_list:n})];case 1:return a=f.sent(),a.code?[2,Qt(t,null,a)]:(u={fileList:a.data.delete_list,requestId:a.requestId},[2,Qt(t,null,u)])}})})},r.prototype.getTempFileURL=function(e,t){return Ai(this,void 0,void 0,function(){var n,o,i,s,c,l,a,u;return Ri(this,function(f){switch(f.label){case 0:if(n=e.fileList,!n||!Gl(n)||n.length===0)throw new Error(JSON.stringify({code:gr.INVALID_PARAMS,msg:"[".concat(Xt,".getTempFileURL] fileList must not be empty")}));for(o=[],i=0,s=n;i<s.length;i++)if(c=s[i],am(c)){if(!Object.prototype.hasOwnProperty.call(c,"fileID")||!Object.prototype.hasOwnProperty.call(c,"maxAge"))throw new Error(JSON.stringify({code:gr.INVALID_PARAMS,msg:"[".concat(Xt,".getTempFileURL] file info must include fileID and maxAge")}));o.push({fileid:c.fileID,max_age:c.maxAge})}else if(xi(c))o.push({fileid:c});else throw new Error(JSON.stringify({code:gr.INVALID_PARAMS,msg:"[".concat(Xt,".getTempFileURL] invalid fileList")}));return l="storage.batchGetDownloadUrl",a=this.request,[4,a.send(l,{file_list:o})];case 1:return u=f.sent(),u.code?[2,Qt(t,null,u)]:[2,Qt(t,null,{fileList:u.data.download_list,requestId:u.requestId})]}})})},r.prototype.downloadFile=function(e,t){return Ai(this,void 0,void 0,function(){var n,o,i,s,c,l;return Ri(this,function(a){switch(a.label){case 0:if(n=e.fileID,!xi(n))throw new Error(JSON.stringify({code:gr.INVALID_PARAMS,msg:"[".concat(Xt,".getTempFileURL] fileID must be string")}));return[4,this.getTempFileURL.call(this,{fileList:[{fileID:n,maxAge:600}]})];case 1:return o=a.sent(),i=o.fileList[0],i.code!=="SUCCESS"?[2,Qt(t,i)]:(s=this.request,c=encodeURI(i.download_url),[4,s.download({url:c})]);case 2:return l=a.sent(),[2,Qt(t,null,l)]}})})},Ti([Ni({customInfo:{},title:"上传文件失败",messages:["请确认以下各项:"," 1 - 调用 uploadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Ci)]}),nt("design:type",Function),nt("design:paramtypes",[Object,Function]),nt("design:returntype",Promise)],r.prototype,"uploadFile",null),Ti([Ni({customInfo:{},title:"获取上传元信息失败",messages:["请确认以下各项:"," 1 - 调用 getUploadMetadata() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Ci)]}),nt("design:type",Function),nt("design:paramtypes",[Object,Function]),nt("design:returntype",Promise)],r.prototype,"getUploadMetadata",null),Ti([Ni({customInfo:{},title:"删除文件失败",messages:["请确认以下各项:"," 1 - 调用 deleteFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Ci)]}),nt("design:type",Function),nt("design:paramtypes",[Object,Function]),nt("design:returntype",Promise)],r.prototype,"deleteFile",null),Ti([Ni({customInfo:{},title:"获取文件下载链接",messages:["请确认以下各项:"," 1 - 调用 getTempFileURL() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Ci)]}),nt("design:type",Function),nt("design:paramtypes",[Object,Function]),nt("design:returntype",Promise)],r.prototype,"getTempFileURL",null),Ti([Ni({customInfo:{},title:"下载文件失败",messages:["请确认以下各项:"," 1 - 调用 downloadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Ci)]}),nt("design:type",Function),nt("design:paramtypes",[Object,Function]),nt("design:returntype",Promise)],r.prototype,"downloadFile",null),r}(),Pi=new sm,Vl={name:Xt,entity:{uploadFile:Pi.uploadFile,deleteFile:Pi.deleteFile,getTempFileURL:Pi.getTempFileURL,downloadFile:Pi.downloadFile,getUploadMetadata:Pi.getUploadMetadata}};try{cloudbase.registerComponent(Vl)}catch{}function um(r){try{r.registerComponent(Vl)}catch(e){console.warn(e)}}var Ns,zl;function cm(){if(zl)return Ns;zl=1;var r="Expected a function",e="__lodash_hash_undefined__",t=9007199254740991,n="[object Function]",o="[object GeneratorFunction]",i="[object Symbol]",s=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,c=/^\w*$/,l=/^\./,a=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,u=/[\\^$.*+?()[\]{}|]/g,f=/\\(\\)?/g,d=/^\[object .+?Constructor\]$/,y=/^(?:0|[1-9]\d*)$/,m=typeof ut=="object"&&ut&&ut.Object===Object&&ut,v=typeof self=="object"&&self&&self.Object===Object&&self,I=m||v||Function("return this")();function S(g,A){return g==null?void 0:g[A]}function w(g){var A=!1;if(g!=null&&typeof g.toString!="function")try{A=!!(g+"")}catch{}return A}var O=Array.prototype,T=Function.prototype,N=Object.prototype,D=I["__core-js_shared__"],B=function(){var g=/[^.]+$/.exec(D&&D.keys&&D.keys.IE_PROTO||"");return g?"Symbol(src)_1."+g:""}(),R=T.toString,x=N.hasOwnProperty,L=N.toString,F=RegExp("^"+R.call(x).replace(u,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),j=I.Symbol,V=O.splice,W=le(I,"Map"),oe=le(Object,"create"),se=j?j.prototype:void 0,Z=se?se.toString:void 0;function ee(g){var A=-1,U=g?g.length:0;for(this.clear();++A<U;){var te=g[A];this.set(te[0],te[1])}}function Y(){this.__data__=oe?oe(null):{}}function G(g){return this.has(g)&&delete this.__data__[g]}function Se(g){var A=this.__data__;if(oe){var U=A[g];return U===e?void 0:U}return x.call(A,g)?A[g]:void 0}function Fe(g){var A=this.__data__;return oe?A[g]!==void 0:x.call(A,g)}function qe(g,A){var U=this.__data__;return U[g]=oe&&A===void 0?e:A,this}ee.prototype.clear=Y,ee.prototype.delete=G,ee.prototype.get=Se,ee.prototype.has=Fe,ee.prototype.set=qe;function Ze(g){var A=-1,U=g?g.length:0;for(this.clear();++A<U;){var te=g[A];this.set(te[0],te[1])}}function Ne(){this.__data__=[]}function ue(g){var A=this.__data__,U=p(A,g);if(U<0)return!1;var te=A.length-1;return U==te?A.pop():V.call(A,U,1),!0}function je(g){var A=this.__data__,U=p(A,g);return U<0?void 0:A[U][1]}function me(g){return p(this.__data__,g)>-1}function Re(g,A){var U=this.__data__,te=p(U,g);return te<0?U.push([g,A]):U[te][1]=A,this}Ze.prototype.clear=Ne,Ze.prototype.delete=ue,Ze.prototype.get=je,Ze.prototype.has=me,Ze.prototype.set=Re;function ge(g){var A=-1,U=g?g.length:0;for(this.clear();++A<U;){var te=g[A];this.set(te[0],te[1])}}function Ae(){this.__data__={hash:new ee,map:new(W||Ze),string:new ee}}function Ue(g){return ae(this,g).delete(g)}function Tt(g){return ae(this,g).get(g)}function ot(g){return ae(this,g).has(g)}function _(g,A){return ae(this,g).set(g,A),this}ge.prototype.clear=Ae,ge.prototype.delete=Ue,ge.prototype.get=Tt,ge.prototype.has=ot,ge.prototype.set=_;function h(g,A,U){var te=g[A];(!(x.call(g,A)&&ei(te,U))||U===void 0&&!(A in g))&&(g[A]=U)}function p(g,A){for(var U=g.length;U--;)if(ei(g[U][0],A))return U;return-1}function E(g){if(!Sr(g)||Vt(g))return!1;var A=ti(g)||w(g)?F:d;return A.test(Vi(g))}function C(g,A,U,te){if(!Sr(g))return g;A=Oe(A,g)?[A]:k(A);for(var Ee=-1,ke=A.length,Or=ke-1,Sn=g;Sn!=null&&++Ee<ke;){var ri=wr(A[Ee]),In=U;if(Ee!=Or){var sr=Sn[ri];In=void 0,In===void 0&&(In=Sr(sr)?sr:ce(A[Ee+1])?[]:{})}h(Sn,ri,In),Sn=Sn[ri]}return g}function q(g){if(typeof g=="string")return g;if(zt(g))return Z?Z.call(g):"";var A=g+"";return A=="0"&&1/g==-1/0?"-0":A}function k(g){return wn(g)?g:ar(g)}function ae(g,A){var U=g.__data__;return ve(A)?U[typeof A=="string"?"string":"hash"]:U.map}function le(g,A){var U=S(g,A);return E(U)?U:void 0}function ce(g,A){return A=A??t,!!A&&(typeof g=="number"||y.test(g))&&g>-1&&g%1==0&&g<A}function Oe(g,A){if(wn(g))return!1;var U=typeof g;return U=="number"||U=="symbol"||U=="boolean"||g==null||zt(g)?!0:c.test(g)||!s.test(g)||A!=null&&g in Object(A)}function ve(g){var A=typeof g;return A=="string"||A=="number"||A=="symbol"||A=="boolean"?g!=="__proto__":g===null}function Vt(g){return!!B&&B in g}var ar=Er(function(g){g=Ir(g);var A=[];return l.test(g)&&A.push(""),g.replace(a,function(U,te,Ee,ke){A.push(Ee?ke.replace(f,"$1"):te||U)}),A});function wr(g){if(typeof g=="string"||zt(g))return g;var A=g+"";return A=="0"&&1/g==-1/0?"-0":A}function Vi(g){if(g!=null){try{return R.call(g)}catch{}try{return g+""}catch{}}return""}function Er(g,A){if(typeof g!="function"||A&&typeof A!="function")throw new TypeError(r);var U=function(){var te=arguments,Ee=A?A.apply(this,te):te[0],ke=U.cache;if(ke.has(Ee))return ke.get(Ee);var Or=g.apply(this,te);return U.cache=ke.set(Ee,Or),Or};return U.cache=new(Er.Cache||ge),U}Er.Cache=ge;function ei(g,A){return g===A||g!==g&&A!==A}var wn=Array.isArray;function ti(g){var A=Sr(g)?L.call(g):"";return A==n||A==o}function Sr(g){var A=typeof g;return!!g&&(A=="object"||A=="function")}function zi(g){return!!g&&typeof g=="object"}function zt(g){return typeof g=="symbol"||zi(g)&&L.call(g)==i}function Ir(g){return g==null?"":q(g)}function En(g,A,U){return g==null?g:C(g,A,U)}return Ns=En,Ns}var lm=cm();const fm=Is(lm);var Ps,Jl;function dm(){if(Jl)return Ps;Jl=1;var r="Expected a function",e="__lodash_hash_undefined__",t="[object Function]",n="[object GeneratorFunction]",o="[object Symbol]",i=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,s=/^\w*$/,c=/^\./,l=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,a=/[\\^$.*+?()[\]{}|]/g,u=/\\(\\)?/g,f=/^\[object .+?Constructor\]$/,d=typeof ut=="object"&&ut&&ut.Object===Object&&ut,y=typeof self=="object"&&self&&self.Object===Object&&self,m=d||y||Function("return this")();function v(g,A){return g==null?void 0:g[A]}function I(g){var A=!1;if(g!=null&&typeof g.toString!="function")try{A=!!(g+"")}catch{}return A}var S=Array.prototype,w=Function.prototype,O=Object.prototype,T=m["__core-js_shared__"],N=function(){var g=/[^.]+$/.exec(T&&T.keys&&T.keys.IE_PROTO||"");return g?"Symbol(src)_1."+g:""}(),D=w.toString,B=O.hasOwnProperty,R=O.toString,x=RegExp("^"+D.call(B).replace(a,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),L=m.Symbol,F=S.splice,j=ae(m,"Map"),V=ae(Object,"create"),W=L?L.prototype:void 0,oe=W?W.toString:void 0;function se(g){var A=-1,U=g?g.length:0;for(this.clear();++A<U;){var te=g[A];this.set(te[0],te[1])}}function Z(){this.__data__=V?V(null):{}}function ee(g){return this.has(g)&&delete this.__data__[g]}function Y(g){var A=this.__data__;if(V){var U=A[g];return U===e?void 0:U}return B.call(A,g)?A[g]:void 0}function G(g){var A=this.__data__;return V?A[g]!==void 0:B.call(A,g)}function Se(g,A){var U=this.__data__;return U[g]=V&&A===void 0?e:A,this}se.prototype.clear=Z,se.prototype.delete=ee,se.prototype.get=Y,se.prototype.has=G,se.prototype.set=Se;function Fe(g){var A=-1,U=g?g.length:0;for(this.clear();++A<U;){var te=g[A];this.set(te[0],te[1])}}function qe(){this.__data__=[]}function Ze(g){var A=this.__data__,U=ot(A,g);if(U<0)return!1;var te=A.length-1;return U==te?A.pop():F.call(A,U,1),!0}function Ne(g){var A=this.__data__,U=ot(A,g);return U<0?void 0:A[U][1]}function ue(g){return ot(this.__data__,g)>-1}function je(g,A){var U=this.__data__,te=ot(U,g);return te<0?U.push([g,A]):U[te][1]=A,this}Fe.prototype.clear=qe,Fe.prototype.delete=Ze,Fe.prototype.get=Ne,Fe.prototype.has=ue,Fe.prototype.set=je;function me(g){var A=-1,U=g?g.length:0;for(this.clear();++A<U;){var te=g[A];this.set(te[0],te[1])}}function Re(){this.__data__={hash:new se,map:new(j||Fe),string:new se}}function ge(g){return k(this,g).delete(g)}function Ae(g){return k(this,g).get(g)}function Ue(g){return k(this,g).has(g)}function Tt(g,A){return k(this,g).set(g,A),this}me.prototype.clear=Re,me.prototype.delete=ge,me.prototype.get=Ae,me.prototype.has=Ue,me.prototype.set=Tt;function ot(g,A){for(var U=g.length;U--;)if(ei(g[U][0],A))return U;return-1}function _(g,A){A=le(A,g)?[A]:q(A);for(var U=0,te=A.length;g!=null&&U<te;)g=g[ar(A[U++])];return U&&U==te?g:void 0}function h(g){if(!Sr(g)||Oe(g))return!1;var A=ti(g)||I(g)?x:f;return A.test(wr(g))}function p(g,A,U){var te=-1,Ee=g.length;A<0&&(A=-A>Ee?0:Ee+A),U=U>Ee?Ee:U,U<0&&(U+=Ee),Ee=A>U?0:U-A>>>0,A>>>=0;for(var ke=Array(Ee);++te<Ee;)ke[te]=g[te+A];return ke}function E(g){if(typeof g=="string")return g;if(zt(g))return oe?oe.call(g):"";var A=g+"";return A=="0"&&1/g==-1/0?"-0":A}function C(g,A){A=le(A,g)?[A]:q(A),g=ve(g,A);var U=ar(Vi(A));return!(g!=null&&B.call(g,U))||delete g[U]}function q(g){return wn(g)?g:Vt(g)}function k(g,A){var U=g.__data__;return ce(A)?U[typeof A=="string"?"string":"hash"]:U.map}function ae(g,A){var U=v(g,A);return h(U)?U:void 0}function le(g,A){if(wn(g))return!1;var U=typeof g;return U=="number"||U=="symbol"||U=="boolean"||g==null||zt(g)?!0:s.test(g)||!i.test(g)||A!=null&&g in Object(A)}function ce(g){var A=typeof g;return A=="string"||A=="number"||A=="symbol"||A=="boolean"?g!=="__proto__":g===null}function Oe(g){return!!N&&N in g}function ve(g,A){return A.length==1?g:_(g,p(A,0,-1))}var Vt=Er(function(g){g=Ir(g);var A=[];return c.test(g)&&A.push(""),g.replace(l,function(U,te,Ee,ke){A.push(Ee?ke.replace(u,"$1"):te||U)}),A});function ar(g){if(typeof g=="string"||zt(g))return g;var A=g+"";return A=="0"&&1/g==-1/0?"-0":A}function wr(g){if(g!=null){try{return D.call(g)}catch{}try{return g+""}catch{}}return""}function Vi(g){var A=g?g.length:0;return A?g[A-1]:void 0}function Er(g,A){if(typeof g!="function"||A&&typeof A!="function")throw new TypeError(r);var U=function(){var te=arguments,Ee=A?A.apply(this,te):te[0],ke=U.cache;if(ke.has(Ee))return ke.get(Ee);var Or=g.apply(this,te);return U.cache=ke.set(Ee,Or),Or};return U.cache=new(Er.Cache||me),U}Er.Cache=me;function ei(g,A){return g===A||g!==g&&A!==A}var wn=Array.isArray;function ti(g){var A=Sr(g)?R.call(g):"";return A==t||A==n}function Sr(g){var A=typeof g;return!!g&&(A=="object"||A=="function")}function zi(g){return!!g&&typeof g=="object"}function zt(g){return typeof g=="symbol"||zi(g)&&R.call(g)==o}function Ir(g){return g==null?"":E(g)}function En(g,A){return g==null?!0:C(g,A)}return Ps=En,Ps}var hm=dm();const pm=Is(hm);var Di={exports:{}};Di.exports;var Kl;function ym(){return Kl||(Kl=1,function(r,e){var t=200,n="__lodash_hash_undefined__",o=9007199254740991,i="[object Arguments]",s="[object Array]",c="[object Boolean]",l="[object Date]",a="[object Error]",u="[object Function]",f="[object GeneratorFunction]",d="[object Map]",y="[object Number]",m="[object Object]",v="[object Promise]",I="[object RegExp]",S="[object Set]",w="[object String]",O="[object Symbol]",T="[object WeakMap]",N="[object ArrayBuffer]",D="[object DataView]",B="[object Float32Array]",R="[object Float64Array]",x="[object Int8Array]",L="[object Int16Array]",F="[object Int32Array]",j="[object Uint8Array]",V="[object Uint8ClampedArray]",W="[object Uint16Array]",oe="[object Uint32Array]",se=/[\\^$.*+?()[\]{}|]/g,Z=/\w*$/,ee=/^\[object .+?Constructor\]$/,Y=/^(?:0|[1-9]\d*)$/,G={};G[i]=G[s]=G[N]=G[D]=G[c]=G[l]=G[B]=G[R]=G[x]=G[L]=G[F]=G[d]=G[y]=G[m]=G[I]=G[S]=G[w]=G[O]=G[j]=G[V]=G[W]=G[oe]=!0,G[a]=G[u]=G[T]=!1;var Se=typeof ut=="object"&&ut&&ut.Object===Object&&ut,Fe=typeof self=="object"&&self&&self.Object===Object&&self,qe=Se||Fe||Function("return this")(),Ze=e&&!e.nodeType&&e,Ne=Ze&&!0&&r&&!r.nodeType&&r,ue=Ne&&Ne.exports===Ze;function je(b,P){return b.set(P[0],P[1]),b}function me(b,P){return b.add(P),b}function Re(b,P){for(var M=-1,Q=b?b.length:0;++M<Q&&P(b[M],M,b)!==!1;);return b}function ge(b,P){for(var M=-1,Q=P.length,Je=b.length;++M<Q;)b[Je+M]=P[M];return b}function Ae(b,P,M,Q){for(var Je=-1,vt=b?b.length:0;++Je<vt;)M=P(M,b[Je],Je,b);return M}function Ue(b,P){for(var M=-1,Q=Array(b);++M<b;)Q[M]=P(M);return Q}function Tt(b,P){return b==null?void 0:b[P]}function ot(b){var P=!1;if(b!=null&&typeof b.toString!="function")try{P=!!(b+"")}catch{}return P}function _(b){var P=-1,M=Array(b.size);return b.forEach(function(Q,Je){M[++P]=[Je,Q]}),M}function h(b,P){return function(M){return b(P(M))}}function p(b){var P=-1,M=Array(b.size);return b.forEach(function(Q){M[++P]=Q}),M}var E=Array.prototype,C=Function.prototype,q=Object.prototype,k=qe["__core-js_shared__"],ae=function(){var b=/[^.]+$/.exec(k&&k.keys&&k.keys.IE_PROTO||"");return b?"Symbol(src)_1."+b:""}(),le=C.toString,ce=q.hasOwnProperty,Oe=q.toString,ve=RegExp("^"+le.call(ce).replace(se,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Vt=ue?qe.Buffer:void 0,ar=qe.Symbol,wr=qe.Uint8Array,Vi=h(Object.getPrototypeOf,Object),Er=Object.create,ei=q.propertyIsEnumerable,wn=E.splice,ti=Object.getOwnPropertySymbols,Sr=Vt?Vt.isBuffer:void 0,zi=h(Object.keys,Object),zt=oi(qe,"DataView"),Ir=oi(qe,"Map"),En=oi(qe,"Promise"),g=oi(qe,"Set"),A=oi(qe,"WeakMap"),U=oi(Object,"create"),te=Tn(zt),Ee=Tn(Ir),ke=Tn(En),Or=Tn(g),Sn=Tn(A),ri=ar?ar.prototype:void 0,In=ri?ri.valueOf:void 0;function sr(b){var P=-1,M=b?b.length:0;for(this.clear();++P<M;){var Q=b[P];this.set(Q[0],Q[1])}}function Rv(){this.__data__=U?U(null):{}}function Cv(b){return this.has(b)&&delete this.__data__[b]}function xv(b){var P=this.__data__;if(U){var M=P[b];return M===n?void 0:M}return ce.call(P,b)?P[b]:void 0}function Nv(b){var P=this.__data__;return U?P[b]!==void 0:ce.call(P,b)}function Pv(b,P){var M=this.__data__;return M[b]=U&&P===void 0?n:P,this}sr.prototype.clear=Rv,sr.prototype.delete=Cv,sr.prototype.get=xv,sr.prototype.has=Nv,sr.prototype.set=Pv;function Tr(b){var P=-1,M=b?b.length:0;for(this.clear();++P<M;){var Q=b[P];this.set(Q[0],Q[1])}}function Dv(){this.__data__=[]}function Fv(b){var P=this.__data__,M=ga(P,b);if(M<0)return!1;var Q=P.length-1;return M==Q?P.pop():wn.call(P,M,1),!0}function Uv(b){var P=this.__data__,M=ga(P,b);return M<0?void 0:P[M][1]}function Bv(b){return ga(this.__data__,b)>-1}function Lv(b,P){var M=this.__data__,Q=ga(M,b);return Q<0?M.push([b,P]):M[Q][1]=P,this}Tr.prototype.clear=Dv,Tr.prototype.delete=Fv,Tr.prototype.get=Uv,Tr.prototype.has=Bv,Tr.prototype.set=Lv;function ni(b){var P=-1,M=b?b.length:0;for(this.clear();++P<M;){var Q=b[P];this.set(Q[0],Q[1])}}function Mv(){this.__data__={hash:new sr,map:new(Ir||Tr),string:new sr}}function qv(b){return va(this,b).delete(b)}function jv(b){return va(this,b).get(b)}function kv(b){return va(this,b).has(b)}function $v(b,P){return va(this,b).set(b,P),this}ni.prototype.clear=Mv,ni.prototype.delete=qv,ni.prototype.get=jv,ni.prototype.has=kv,ni.prototype.set=$v;function ii(b){this.__data__=new Tr(b)}function Wv(){this.__data__=new Tr}function Hv(b){return this.__data__.delete(b)}function Gv(b){return this.__data__.get(b)}function Vv(b){return this.__data__.has(b)}function zv(b,P){var M=this.__data__;if(M instanceof Tr){var Q=M.__data__;if(!Ir||Q.length<t-1)return Q.push([b,P]),this;M=this.__data__=new ni(Q)}return M.set(b,P),this}ii.prototype.clear=Wv,ii.prototype.delete=Hv,ii.prototype.get=Gv,ii.prototype.has=Vv,ii.prototype.set=zv;function Jv(b,P){var M=gu(b)||v_(b)?Ue(b.length,String):[],Q=M.length,Je=!!Q;for(var vt in b)ce.call(b,vt)&&!(Je&&(vt=="length"||p_(vt,Q)))&&M.push(vt);return M}function xh(b,P,M){var Q=b[P];(!(ce.call(b,P)&&Fh(Q,M))||M===void 0&&!(P in b))&&(b[P]=M)}function ga(b,P){for(var M=b.length;M--;)if(Fh(b[M][0],P))return M;return-1}function Kv(b,P){return b&&Nh(P,vu(P),b)}function yu(b,P,M,Q,Je,vt,Ar){var _t;if(Q&&(_t=vt?Q(b,Je,vt,Ar):Q(b)),_t!==void 0)return _t;if(!_a(b))return b;var Lh=gu(b);if(Lh){if(_t=f_(b),!P)return u_(b,_t)}else{var ai=On(b),Mh=ai==u||ai==f;if(b_(b))return t_(b,P);if(ai==m||ai==i||Mh&&!vt){if(ot(b))return vt?b:{};if(_t=d_(Mh?{}:b),!P)return c_(b,Kv(_t,b))}else{if(!G[ai])return vt?b:{};_t=h_(b,ai,yu,P)}}Ar||(Ar=new ii);var qh=Ar.get(b);if(qh)return qh;if(Ar.set(b,_t),!Lh)var jh=M?l_(b):vu(b);return Re(jh||b,function(_u,ba){jh&&(ba=_u,_u=b[ba]),xh(_t,ba,yu(_u,P,M,Q,ba,b,Ar))}),_t}function Yv(b){return _a(b)?Er(b):{}}function Qv(b,P,M){var Q=P(b);return gu(b)?Q:ge(Q,M(b))}function Xv(b){return Oe.call(b)}function Zv(b){if(!_a(b)||m_(b))return!1;var P=Bh(b)||ot(b)?ve:ee;return P.test(Tn(b))}function e_(b){if(!Dh(b))return zi(b);var P=[];for(var M in Object(b))ce.call(b,M)&&M!="constructor"&&P.push(M);return P}function t_(b,P){if(P)return b.slice();var M=new b.constructor(b.length);return b.copy(M),M}function mu(b){var P=new b.constructor(b.byteLength);return new wr(P).set(new wr(b)),P}function r_(b,P){var M=P?mu(b.buffer):b.buffer;return new b.constructor(M,b.byteOffset,b.byteLength)}function n_(b,P,M){var Q=P?M(_(b),!0):_(b);return Ae(Q,je,new b.constructor)}function i_(b){var P=new b.constructor(b.source,Z.exec(b));return P.lastIndex=b.lastIndex,P}function o_(b,P,M){var Q=P?M(p(b),!0):p(b);return Ae(Q,me,new b.constructor)}function a_(b){return In?Object(In.call(b)):{}}function s_(b,P){var M=P?mu(b.buffer):b.buffer;return new b.constructor(M,b.byteOffset,b.length)}function u_(b,P){var M=-1,Q=b.length;for(P||(P=Array(Q));++M<Q;)P[M]=b[M];return P}function Nh(b,P,M,Q){M||(M={});for(var Je=-1,vt=P.length;++Je<vt;){var Ar=P[Je],_t=void 0;xh(M,Ar,_t===void 0?b[Ar]:_t)}return M}function c_(b,P){return Nh(b,Ph(b),P)}function l_(b){return Qv(b,vu,Ph)}function va(b,P){var M=b.__data__;return y_(P)?M[typeof P=="string"?"string":"hash"]:M.map}function oi(b,P){var M=Tt(b,P);return Zv(M)?M:void 0}var Ph=ti?h(ti,Object):S_,On=Xv;(zt&&On(new zt(new ArrayBuffer(1)))!=D||Ir&&On(new Ir)!=d||En&&On(En.resolve())!=v||g&&On(new g)!=S||A&&On(new A)!=T)&&(On=function(b){var P=Oe.call(b),M=P==m?b.constructor:void 0,Q=M?Tn(M):void 0;if(Q)switch(Q){case te:return D;case Ee:return d;case ke:return v;case Or:return S;case Sn:return T}return P});function f_(b){var P=b.length,M=b.constructor(P);return P&&typeof b[0]=="string"&&ce.call(b,"index")&&(M.index=b.index,M.input=b.input),M}function d_(b){return typeof b.constructor=="function"&&!Dh(b)?Yv(Vi(b)):{}}function h_(b,P,M,Q){var Je=b.constructor;switch(P){case N:return mu(b);case c:case l:return new Je(+b);case D:return r_(b,Q);case B:case R:case x:case L:case F:case j:case V:case W:case oe:return s_(b,Q);case d:return n_(b,Q,M);case y:case w:return new Je(b);case I:return i_(b);case S:return o_(b,Q,M);case O:return a_(b)}}function p_(b,P){return P=P??o,!!P&&(typeof b=="number"||Y.test(b))&&b>-1&&b%1==0&&b<P}function y_(b){var P=typeof b;return P=="string"||P=="number"||P=="symbol"||P=="boolean"?b!=="__proto__":b===null}function m_(b){return!!ae&&ae in b}function Dh(b){var P=b&&b.constructor,M=typeof P=="function"&&P.prototype||q;return b===M}function Tn(b){if(b!=null){try{return le.call(b)}catch{}try{return b+""}catch{}}return""}function g_(b){return yu(b,!0,!0)}function Fh(b,P){return b===P||b!==b&&P!==P}function v_(b){return __(b)&&ce.call(b,"callee")&&(!ei.call(b,"callee")||Oe.call(b)==i)}var gu=Array.isArray;function Uh(b){return b!=null&&w_(b.length)&&!Bh(b)}function __(b){return E_(b)&&Uh(b)}var b_=Sr||I_;function Bh(b){var P=_a(b)?Oe.call(b):"";return P==u||P==f}function w_(b){return typeof b=="number"&&b>-1&&b%1==0&&b<=o}function _a(b){var P=typeof b;return!!b&&(P=="object"||P=="function")}function E_(b){return!!b&&typeof b=="object"}function vu(b){return Uh(b)?Jv(b):e_(b)}function S_(){return[]}function I_(){return!1}r.exports=g_}(Di,Di.exports)),Di.exports}var mm=ym();const gm=Is(mm);function $n(r){return r===void 0&&(r=""),"".concat(r?"".concat(r,"_"):"").concat(+new Date,"_").concat(Math.random())}var vm=function(){function r(e){this.close=e.close,this.onChange=e.onChange,this.onError=e.onError,e.debug&&Object.defineProperty(this,"virtualClient",{get:function(){return e.virtualClient}})}return r}(),Yl=function(){function r(e){var t=e.id,n=e.docChanges,o=e.docs,i=e.msgType,s=e.type,c,l;Object.defineProperties(this,{id:{get:function(){return t},enumerable:!0},docChanges:{get:function(){return c||(c=JSON.parse(JSON.stringify(n))),c},enumerable:!0},docs:{get:function(){return l||(l=JSON.parse(JSON.stringify(o))),l},enumerable:!0},msgType:{get:function(){return i},enumerable:!0},type:{get:function(){return s},enumerable:!0}})}return r}(),$o=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(n[i]=o[i])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),_m=function(r){$o(e,r);function e(t){var n=r.call(this,"Watch Error ".concat(JSON.stringify(t.msgData)," (requestid: ").concat(t.requestId,")"))||this;return n.isRealtimeErrorMessageError=!0,n.payload=t,n}return e}(Error),Ql=function(r){return r==null?void 0:r.isRealtimeErrorMessageError},bm=function(r){$o(e,r);function e(){var t=r!==null&&r.apply(this,arguments)||this;return t.type="timeout",t.payload=null,t.generic=!0,t}return e}(Error),wm=function(r){return r.type==="timeout"},Em=function(r){$o(e,r);function e(){var t=r!==null&&r.apply(this,arguments)||this;return t.type="cancelled",t.payload=null,t.generic=!0,t}return e}(Error),Sm=function(r){return r.type==="cancelled"},xt=function(r){$o(e,r);function e(t){var n=r.call(this,t.errMsg)||this;return n.errCode="UNKNOWN_ERROR",Object.defineProperties(n,{message:{get:function(){return"errCode: ".concat(this.errCode," ").concat(ct[this.errCode]||""," | errMsg: ").concat(this.errMsg)},set:function(o){this.errMsg=o}}}),n.errCode=t.errCode||"UNKNOWN_ERROR",n.errMsg=t.errMsg,n}return Object.defineProperty(e.prototype,"message",{get:function(){return"errCode: ".concat(this.errCode," | errMsg: ").concat(this.errMsg)},set:function(t){this.errMsg=t},enumerable:!1,configurable:!0}),e}(Error),ct={UNKNOWN_ERROR:"UNKNOWN_ERROR",SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG:"SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG",SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA:"SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA",SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR:"SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR",SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED:"SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED",SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL:"SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL",SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR:"SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR"},Ds=function(r){return r===void 0&&(r=0),new Promise(function(e){return setTimeout(e,r)})},wt=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},lt=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Xl=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return r.concat(i||Array.prototype.slice.call(e))},we;(function(r){r.LOGGINGIN="LOGGINGIN",r.INITING="INITING",r.REBUILDING="REBUILDING",r.ACTIVE="ACTIVE",r.ERRORED="ERRORED",r.CLOSING="CLOSING",r.CLOSED="CLOSED",r.PAUSED="PAUSED",r.RESUMING="RESUMING"})(we||(we={}));var Im=100,Wo=2,Om=2,Tm=10*1e3,Am=10*1e3,Rm=10*1e3,Cm=function(){function r(e){var t=this;this.watchStatus=we.INITING,this.wsLogin=function(n,o){return wt(t,void 0,void 0,function(){var i;return lt(this,function(s){switch(s.label){case 0:return this.watchStatus=we.LOGGINGIN,[4,this.login(n,o)];case 1:return i=s.sent(),this.envId||(this.envId=i.envId),[2,i]}})})},this.initWatch=function(n){return wt(t,void 0,void 0,function(){var o,i=this;return lt(this,function(s){switch(s.label){case 0:if(this.initWatchPromise!==null&&this.initWatchPromise!==void 0)return[2,this.initWatchPromise];this.initWatchPromise=new Promise(function(c,l){(function(){return wt(i,void 0,void 0,function(){var a,u,f,d,y,m,v,I,S,w,O;return lt(this,function(T){switch(T.label){case 0:return T.trys.push([0,3,,4]),this.watchStatus===we.PAUSED?(console.log("[realtime] initWatch cancelled on pause"),[2,c()]):[4,this.wsLogin(this.envId,n)];case 1:return a=T.sent().envId,this.watchStatus===we.PAUSED?(console.log("[realtime] initWatch cancelled on pause"),[2,c()]):(this.watchStatus=we.INITING,u={watchId:this.watchId,requestId:$n(),msgType:"INIT_WATCH",msgData:{envId:a,collName:this.collectionName,query:this.query,limit:this.limit,orderBy:this.orderBy}},[4,this.send({msg:u,waitResponse:!0,skipOnMessage:!0,timeout:Am})]);case 2:if(f=T.sent(),d=f.msgData,y=d.events,m=d.currEvent,this.sessionInfo={queryID:f.msgData.queryID,currentEventId:m-1,currentDocs:[]},y.length>0){for(v=0,I=y;v<I.length;v++)S=I[v],S.ID=m;this.handleServerEvents(f)}else this.sessionInfo.currentEventId=m,w=new Yl({id:m,docChanges:[],docs:[],type:"init"}),this.listener.onChange(w),this.scheduleSendACK();return this.onWatchStart(this,this.sessionInfo.queryID),this.watchStatus=we.ACTIVE,this.availableRetries.INIT_WATCH=Wo,c(),[3,4];case 3:return O=T.sent(),this.handleWatchEstablishmentError(O,{operationName:"INIT_WATCH",resolve:c,reject:l}),[3,4];case 4:return[2]}})})})()}),o=!1,s.label=1;case 1:return s.trys.push([1,,3,4]),[4,this.initWatchPromise];case 2:return s.sent(),o=!0,[3,4];case 3:return this.initWatchPromise=void 0,[7];case 4:return console.log("[realtime] initWatch ".concat(o?"success":"fail")),[2]}})})},this.rebuildWatch=function(n){return wt(t,void 0,void 0,function(){var o,i=this;return lt(this,function(s){switch(s.label){case 0:if(this.rebuildWatchPromise!==null&&this.rebuildWatchPromise!==void 0)return[2,this.rebuildWatchPromise];this.rebuildWatchPromise=new Promise(function(c,l){(function(){return wt(i,void 0,void 0,function(){var a,u,f,d;return lt(this,function(y){switch(y.label){case 0:return y.trys.push([0,3,,4]),this.watchStatus===we.PAUSED?(console.log("[realtime] rebuildWatch cancelled on pause"),[2,c()]):[4,this.wsLogin(this.envId,n)];case 1:if(a=y.sent().envId,!this.sessionInfo)throw new Error("can not rebuildWatch without a successful initWatch (lack of sessionInfo)");return this.watchStatus===we.PAUSED?(console.log("[realtime] rebuildWatch cancelled on pause"),[2,c()]):(this.watchStatus=we.REBUILDING,u={watchId:this.watchId,requestId:$n(),msgType:"REBUILD_WATCH",msgData:{envId:a,collName:this.collectionName,queryID:this.sessionInfo.queryID,eventID:this.sessionInfo.currentEventId}},[4,this.send({msg:u,waitResponse:!0,skipOnMessage:!1,timeout:Rm})]);case 2:return f=y.sent(),this.handleServerEvents(f),this.watchStatus=we.ACTIVE,this.availableRetries.REBUILD_WATCH=Wo,c(),[3,4];case 3:return d=y.sent(),this.handleWatchEstablishmentError(d,{operationName:"REBUILD_WATCH",resolve:c,reject:l}),[3,4];case 4:return[2]}})})})()}),o=!1,s.label=1;case 1:return s.trys.push([1,,3,4]),[4,this.rebuildWatchPromise];case 2:return s.sent(),o=!0,[3,4];case 3:return this.rebuildWatchPromise=void 0,[7];case 4:return console.log("[realtime] rebuildWatch ".concat(o?"success":"fail")),[2]}})})},this.handleWatchEstablishmentError=function(n,o){return wt(t,void 0,void 0,function(){var i,s,c,l=this;return lt(this,function(a){return i=o.operationName==="INIT_WATCH",s=function(){l.closeWithError(new xt({errCode:i?ct.SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL:ct.SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL,errMsg:n})),o.reject(n)},c=function(u){l.useRetryTicket(o.operationName)?i?(l.initWatchPromise=void 0,o.resolve(l.initWatch(u))):(l.rebuildWatchPromise=void 0,o.resolve(l.rebuildWatch(u))):s()},this.handleCommonError(n,{onSignError:function(){return c(!0)},onTimeoutError:function(){return c(!1)},onNotRetryableError:s,onCancelledError:o.reject,onUnknownError:function(){(function(){return wt(l,void 0,void 0,function(){var u,f=this;return lt(this,function(d){switch(d.label){case 0:return d.trys.push([0,8,,9]),u=function(){return wt(f,void 0,void 0,function(){return lt(this,function(y){switch(y.label){case 0:return this.pause(),[4,this.onceWSConnected()];case 1:return y.sent(),c(!0),[2]}})})},this.isWSConnected()?[3,2]:[4,u()];case 1:return d.sent(),[3,7];case 2:return[4,Ds(Im)];case 3:return d.sent(),this.watchStatus!==we.PAUSED?[3,4]:(o.reject(new Em("".concat(o.operationName," cancelled due to pause after unknownError"))),[3,7]);case 4:return this.isWSConnected()?[3,6]:[4,u()];case 5:return d.sent(),[3,7];case 6:c(!1),d.label=7;case 7:return[3,9];case 8:return d.sent(),c(!0),[3,9];case 9:return[2]}})})})()}}),[2]})})},this.closeWatch=function(){return wt(t,void 0,void 0,function(){var n,o,i;return lt(this,function(s){switch(s.label){case 0:if(n=this.sessionInfo?this.sessionInfo.queryID:"",this.watchStatus!==we.ACTIVE)return this.watchStatus=we.CLOSED,this.onWatchClose(this,n),[2];s.label=1;case 1:return s.trys.push([1,3,4,5]),this.watchStatus=we.CLOSING,o={watchId:this.watchId,requestId:$n(),msgType:"CLOSE_WATCH",msgData:null},[4,this.send({msg:o})];case 2:return s.sent(),this.sessionInfo=void 0,this.watchStatus=we.CLOSED,[3,5];case 3:return i=s.sent(),this.closeWithError(new xt({errCode:ct.SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL,errMsg:i})),[3,5];case 4:return this.onWatchClose(this,n),[7];case 5:return[2]}})})},this.scheduleSendACK=function(){t.clearACKSchedule(),t.ackTimeoutId=setTimeout(function(){t.waitExpectedTimeoutId?t.scheduleSendACK():t.sendACK()},Tm)},this.clearACKSchedule=function(){t.ackTimeoutId&&clearTimeout(t.ackTimeoutId)},this.sendACK=function(){return wt(t,void 0,void 0,function(){var n,o,i;return lt(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),this.watchStatus!==we.ACTIVE?(this.scheduleSendACK(),[2]):this.sessionInfo?(n={watchId:this.watchId,requestId:$n(),msgType:"CHECK_LAST",msgData:{queryID:this.sessionInfo.queryID,eventID:this.sessionInfo.currentEventId}},[4,this.send({msg:n})]):(console.warn("[realtime listener] can not send ack without a successful initWatch (lack of sessionInfo)"),[2]);case 1:return s.sent(),this.scheduleSendACK(),[3,3];case 2:if(o=s.sent(),Ql(o))switch(i=o.payload,i.msgData.code){case"CHECK_LOGIN_FAILED":case"SIGN_EXPIRED_ERROR":case"SIGN_INVALID_ERROR":case"SIGN_PARAM_INVALID":return this.rebuildWatch(),[2];case"QUERYID_INVALID_ERROR":case"SYS_ERR":case"INVALIID_ENV":case"COLLECTION_PERMISSION_DENIED":return this.closeWithError(new xt({errCode:ct.SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL,errMsg:i.msgData.code})),[2]}return this.availableRetries.CHECK_LAST&&this.availableRetries.CHECK_LAST>0?(this.availableRetries.CHECK_LAST-=1,this.scheduleSendACK()):this.closeWithError(new xt({errCode:ct.SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL,errMsg:o})),[3,3];case 3:return[2]}})})},this.handleCommonError=function(n,o){if(Ql(n)){var i=n.payload;switch(i.msgData.code){case"CHECK_LOGIN_FAILED":case"SIGN_EXPIRED_ERROR":case"SIGN_INVALID_ERROR":case"SIGN_PARAM_INVALID":{o.onSignError(n);return}case"QUERYID_INVALID_ERROR":case"SYS_ERR":case"INVALIID_ENV":case"COLLECTION_PERMISSION_DENIED":{o.onNotRetryableError(n);return}default:{o.onNotRetryableError(n);return}}}else if(wm(n)){o.onTimeoutError(n);return}else if(Sm(n)){o.onCancelledError(n);return}o.onUnknownError(n)},this.watchId="watchid_".concat(+new Date,"_").concat(Math.random()),this.envId=e.envId,this.collectionName=e.collectionName,this.query=e.query,this.limit=e.limit,this.orderBy=e.orderBy,this.send=e.send,this.login=e.login,this.isWSConnected=e.isWSConnected,this.onceWSConnected=e.onceWSConnected,this.getWaitExpectedTimeoutLength=e.getWaitExpectedTimeoutLength,this.onWatchStart=e.onWatchStart,this.onWatchClose=e.onWatchClose,this.debug=e.debug,this.availableRetries={INIT_WATCH:Wo,REBUILD_WATCH:Wo,CHECK_LAST:Om},this.listener=new vm({close:function(){t.closeWatch()},onChange:e.onChange,onError:e.onError,debug:this.debug,virtualClient:this}),this.initWatch()}return r.prototype.onMessage=function(e){var t=this;switch(this.watchStatus){case we.PAUSED:{if(e.msgType!=="ERROR")return;break}case we.LOGGINGIN:case we.INITING:case we.REBUILDING:{console.warn("[realtime listener] internal non-fatal error: unexpected message received while ".concat(this.watchStatus));return}case we.CLOSED:{console.warn("[realtime listener] internal non-fatal error: unexpected message received when the watch has closed");return}case we.ERRORED:{console.warn("[realtime listener] internal non-fatal error: unexpected message received when the watch has ended with error");return}}if(!this.sessionInfo){console.warn("[realtime listener] internal non-fatal error: sessionInfo not found while message is received.");return}switch(this.scheduleSendACK(),e.msgType){case"NEXT_EVENT":{console.warn("nextevent ".concat(e.msgData.currEvent," ignored"),e),this.handleServerEvents(e);break}case"CHECK_EVENT":{this.sessionInfo.currentEventId<e.msgData.currEvent&&(this.sessionInfo.expectEventId=e.msgData.currEvent,this.clearWaitExpectedEvent(),this.waitExpectedTimeoutId=setTimeout(function(){t.rebuildWatch()},this.getWaitExpectedTimeoutLength()),console.log("[realtime] waitExpectedTimeoutLength ".concat(this.getWaitExpectedTimeoutLength())));break}case"ERROR":{this.closeWithError(new xt({errCode:ct.SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG,errMsg:"".concat(e.msgData.code," - ").concat(e.msgData.message)}));break}default:{console.warn("[realtime listener] virtual client receive unexpected msg ".concat(e.msgType,": "),e);break}}},r.prototype.closeWithError=function(e){var t;this.watchStatus=we.ERRORED,this.clearACKSchedule(),this.listener.onError(e),this.onWatchClose(this,((t=this.sessionInfo)===null||t===void 0?void 0:t.queryID)||""),console.log("[realtime] client closed (".concat(this.collectionName," ").concat(this.query,") (watchId ").concat(this.watchId,")"))},r.prototype.pause=function(){this.watchStatus=we.PAUSED,console.log("[realtime] client paused (".concat(this.collectionName," ").concat(this.query,") (watchId ").concat(this.watchId,")"))},r.prototype.resume=function(){return wt(this,void 0,void 0,function(){var e;return lt(this,function(t){switch(t.label){case 0:this.watchStatus=we.RESUMING,console.log("[realtime] client resuming with ".concat(this.sessionInfo?"REBUILD_WATCH":"INIT_WATCH"," (").concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")")),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.sessionInfo?this.rebuildWatch():this.initWatch()];case 2:return t.sent(),console.log("[realtime] client successfully resumed (".concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")")),[3,4];case 3:return e=t.sent(),console.error("[realtime] client resume failed (".concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")"),e),[3,4];case 4:return[2]}})})},r.prototype.useRetryTicket=function(e){return this.availableRetries[e]&&this.availableRetries[e]>0?(this.availableRetries[e]-=1,console.log("[realtime] ".concat(e," use a retry ticket, now only ").concat(this.availableRetries[e]," retry left")),!0):!1},r.prototype.handleServerEvents=function(e){return wt(this,void 0,void 0,function(){var t;return lt(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.scheduleSendACK(),[4,this.handleServerEventsInternel(e)];case 1:return n.sent(),this.postHandleServerEventsValidityCheck(e),[3,3];case 2:throw t=n.sent(),console.error("[realtime listener] internal non-fatal error: handle server events failed with error: ",t),t;case 3:return[2]}})})},r.prototype.handleServerEventsInternel=function(e){return wt(this,void 0,void 0,function(){var t,n,o,i,s,c,l,a,u,f,d,y;return lt(this,function(m){switch(m.label){case 0:if(t=e.requestId,n=e.msgData.events,o=e.msgType,!n.length||!this.sessionInfo)return[2];i=this.sessionInfo;try{s=n.map(xm)}catch(v){return this.closeWithError(new xt({errCode:ct.SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA,errMsg:v})),[2]}c=Xl([],i.currentDocs,!0),l=!1,a=function(v,I){var S,w,O,T,N,D,R,R,B,B,R,x,x,L,F,j;return lt(this,function(V){switch(V.label){case 0:return S=s[v],i.currentEventId>=S.id?(!s[v-1]||S.id>s[v-1].id?console.warn("[realtime] duplicate event received, cur ".concat(i.currentEventId," but got ").concat(S.id)):console.error("[realtime listener] server non-fatal error: events out of order (the latter event's id is smaller than that of the former) (requestId ".concat(t,")")),[2,"continue"]):[3,1];case 1:if(i.currentEventId!==S.id-1)return[3,2];switch(S.dataType){case"update":{if(!S.doc)switch(S.queueType){case"update":case"dequeue":{if(w=c.find(function(W){return W._id===S.docId}),w){if(O=gm(w),S.updatedFields&&Object.keys(S.updatedFields).forEach(function(W){fm(O,W,S.updatedFields[W])}),S.removedFields)for(T=0,N=S.removedFields;T<N.length;T++)D=N[T],pm(O,D);S.doc=O}else console.error("[realtime listener] internal non-fatal server error: unexpected update dataType event where no doc is associated.");break}case"enqueue":throw R=new xt({errCode:ct.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="update" and queueType="enqueue" (requestId '.concat(e.requestId,")")}),u.closeWithError(R),R}break}case"replace":{if(!S.doc)throw R=new xt({errCode:ct.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="replace" (requestId '.concat(e.requestId,")")}),u.closeWithError(R),R;break}case"remove":{B=c.find(function(W){return W._id===S.docId}),B?S.doc=B:console.error("[realtime listener] internal non-fatal server error: unexpected remove event where no doc is associated.");break}case"limit":{if(!S.doc)switch(S.queueType){case"dequeue":{B=c.find(function(W){return W._id===S.docId}),B?S.doc=B:console.error("[realtime listener] internal non-fatal server error: unexpected limit dataType event where no doc is associated.");break}case"enqueue":throw R=new xt({errCode:ct.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="limit" and queueType="enqueue" (requestId '.concat(e.requestId,")")}),u.closeWithError(R),R}break}}switch(S.queueType){case"init":{l?c.push(S.doc):(l=!0,c=[S.doc]);break}case"enqueue":{c.push(S.doc);break}case"dequeue":{x=c.findIndex(function(W){return W._id===S.docId}),x>-1?c.splice(x,1):console.error("[realtime listener] internal non-fatal server error: unexpected dequeue event where no doc is associated.");break}case"update":{x=c.findIndex(function(W){return W._id===S.docId}),x>-1?c[x]=S.doc:console.error("[realtime listener] internal non-fatal server error: unexpected queueType update event where no doc is associated.");break}}return(v===I-1||s[v+1]&&s[v+1].id!==S.id)&&(L=Xl([],c,!0),F=s.slice(0,v+1).filter(function(W){return W.id===S.id}),u.sessionInfo.currentEventId=S.id,u.sessionInfo.currentDocs=c,j=new Yl({id:S.id,docChanges:F,docs:L,msgType:o}),u.listener.onChange(j)),[3,4];case 2:return console.warn("[realtime listener] event received is out of order, cur ".concat(u.sessionInfo.currentEventId," but got ").concat(S.id)),[4,u.rebuildWatch()];case 3:return V.sent(),[2,{value:void 0}];case 4:return[2]}})},u=this,f=0,d=s.length,m.label=1;case 1:return f<d?[5,a(f,d)]:[3,4];case 2:if(y=m.sent(),typeof y=="object")return[2,y.value];m.label=3;case 3:return f++,[3,1];case 4:return[2]}})})},r.prototype.postHandleServerEventsValidityCheck=function(e){if(!this.sessionInfo){console.error("[realtime listener] internal non-fatal error: sessionInfo lost after server event handling, this should never occur");return}if(this.sessionInfo.expectEventId&&this.sessionInfo.currentEventId>=this.sessionInfo.expectEventId&&this.clearWaitExpectedEvent(),this.sessionInfo.currentEventId<e.msgData.currEvent){console.warn("[realtime listener] internal non-fatal error: client eventId does not match with server event id after server event handling");return}},r.prototype.clearWaitExpectedEvent=function(){this.waitExpectedTimeoutId&&(clearTimeout(this.waitExpectedTimeoutId),this.waitExpectedTimeoutId=void 0)},r}();function xm(r){var e={id:r.ID,dataType:r.DataType,queueType:r.QueueType,docId:r.DocID,doc:r.Doc&&r.Doc!=="{}"?JSON.parse(r.Doc):void 0};return r.DataType==="update"&&(r.UpdatedFields&&(e.updatedFields=JSON.parse(r.UpdatedFields)),(r.removedFields||r.RemovedFields)&&(e.removedFields=JSON.parse(r.removedFields))),e}var Zl={1e3:{code:1e3,name:"Normal Closure",description:"Normal closure; the connection successfully completed whatever purpose for which it was created."},1001:{code:1001,name:"Going Away",description:"The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection."},1002:{code:1002,name:"Protocol Error",description:"The endpoint is terminating the connection due to a protocol error."},1003:{code:1003,name:"Unsupported Data",description:"The connection is being terminated because the endpoint received data of a type it cannot accept (for example, a text-only endpoint received binary data)."},1005:{code:1005,name:"No Status Received",description:"Indicates that no status code was provided even though one was expected."},1006:{code:1006,name:"Abnormal Closure",description:"Used to indicate that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected."},1007:{code:1007,name:"Invalid frame payload data",description:"The endpoint is terminating the connection because a message was received that contained inconsistent data (e.g., non-UTF-8 data within a text message)."},1008:{code:1008,name:"Policy Violation",description:"The endpoint is terminating the connection because it received a message that violates its policy. This is a generic status code, used when codes 1003 and 1009 are not suitable."},1009:{code:1009,name:"Message too big",description:"The endpoint is terminating the connection because a data frame was received that is too large."},1010:{code:1010,name:"Missing Extension",description:"The client is terminating the connection because it expected the server to negotiate one or more extension, but the server didn't."},1011:{code:1011,name:"Internal Error",description:"The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request."},1012:{code:1012,name:"Service Restart",description:"The server is terminating the connection because it is restarting."},1013:{code:1013,name:"Try Again Later",description:"The server is terminating the connection due to a temporary condition, e.g. it is overloaded and is casting off some of its clients."},1014:{code:1014,name:"Bad Gateway",description:"The server was acting as a gateway or proxy and received an invalid response from the upstream server. This is similar to 502 HTTP Status Code."},1015:{code:1015,name:"TLS Handshake",description:"Indicates that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified)."},3e3:{code:3e3,name:"Reconnect WebSocket",description:"The client is terminating the connection because it wants to reconnect"},3001:{code:3001,name:"No Realtime Listeners",description:"The client is terminating the connection because no more realtime listeners exist"},3002:{code:3002,name:"Heartbeat Ping Error",description:"The client is terminating the connection due to its failure in sending heartbeat messages"},3003:{code:3003,name:"Heartbeat Pong Timeout Error",description:"The client is terminating the connection because no heartbeat response is received from the server"},3050:{code:3050,name:"Server Close",description:"The client is terminating the connection because no heartbeat response is received from the server"}},Nt;(function(r){r[r.NormalClosure=1e3]="NormalClosure",r[r.GoingAway=1001]="GoingAway",r[r.ProtocolError=1002]="ProtocolError",r[r.UnsupportedData=1003]="UnsupportedData",r[r.NoStatusReceived=1005]="NoStatusReceived",r[r.AbnormalClosure=1006]="AbnormalClosure",r[r.InvalidFramePayloadData=1007]="InvalidFramePayloadData",r[r.PolicyViolation=1008]="PolicyViolation",r[r.MessageTooBig=1009]="MessageTooBig",r[r.MissingExtension=1010]="MissingExtension",r[r.InternalError=1011]="InternalError",r[r.ServiceRestart=1012]="ServiceRestart",r[r.TryAgainLater=1013]="TryAgainLater",r[r.BadGateway=1014]="BadGateway",r[r.TLSHandshake=1015]="TLSHandshake",r[r.ReconnectWebSocket=3e3]="ReconnectWebSocket",r[r.NoRealtimeListeners=3001]="NoRealtimeListeners",r[r.HeartbeatPingError=3002]="HeartbeatPingError",r[r.HeartbeatPongTimeoutError=3003]="HeartbeatPongTimeoutError",r[r.NoAuthentication=3050]="NoAuthentication"})(Nt||(Nt={}));var Fs=function(r,e){var t=Zl[r],n=t?"".concat(t.name,", code ").concat(r,", reason ").concat(e||t.description):"code ".concat(r);return new xt({errCode:ct.SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED,errMsg:n})},ef=null,tf="web";function Nm(){return ef}function Pm(r){ef=r}function rf(){return tf}function Dm(r){tf=r}var Ho=function(){return Ho=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Ho.apply(this,arguments)},kt=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},$t=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Us={OPEN:1},nf=3,Fm=5e3,Um=1e4,Bm=5,Lm=1e4,Mm=2,qm=2,jm=5e3,km=function(){function r(e){var t=this;this.virtualWSClient=new Set,this.queryIdClientMap=new Map,this.watchIdClientMap=new Map,this.pingFailed=0,this.pongMissed=0,this.logins=new Map,this.wsReadySubsribers=[],this.wsResponseWait=new Map,this.rttObserved=[],this.send=function(n){return kt(t,void 0,void 0,function(){var o=this;return $t(this,function(i){return[2,new Promise(function(s,c){(function(){return kt(o,void 0,void 0,function(){var l,a,u,f,d,y,m,v,I=this;return $t(this,function(S){switch(S.label){case 0:a=!1,u=!1,f=function(w){a=!0,l&&clearTimeout(l),s(w)},d=function(w){u=!0,l&&clearTimeout(l),c(w)},n.timeout&&(l=setTimeout(function(){(function(){return kt(I,void 0,void 0,function(){return $t(this,function(w){switch(w.label){case 0:return!a||!u?[4,Ds(0)]:[3,2];case 1:w.sent(),(!a||!u)&&d(new bm("wsclient.send timedout")),w.label=2;case 2:return[2]}})})})()},n.timeout)),S.label=1;case 1:return S.trys.push([1,8,,9]),this.wsInitPromise!==void 0||this.wsInitPromise!==null?[4,this.wsInitPromise]:[3,3];case 2:S.sent(),S.label=3;case 3:if(!this.ws)return d(new Error("invalid state: ws connection not exists, can not send message")),[2];if(this.ws.readyState!==Us.OPEN)return d(new Error("ws readyState invalid: ".concat(this.ws.readyState,", can not send message"))),[2];n.waitResponse&&(y={resolve:f,reject:d,skipOnMessage:n.skipOnMessage},this.wsResponseWait.set(n.msg.requestId,y)),S.label=4;case 4:return S.trys.push([4,6,,7]),[4,this.ws.send(JSON.stringify(n.msg))];case 5:return S.sent(),n.waitResponse||f(void 0),[3,7];case 6:return m=S.sent(),m&&(d(m),n.waitResponse&&this.wsResponseWait.delete(n.msg.requestId)),[3,7];case 7:return[3,9];case 8:return v=S.sent(),d(v),[3,9];case 9:return[2]}})})})()})]})})},this.closeAllClients=function(n){t.virtualWSClient.forEach(function(o){o.closeWithError(n)})},this.pauseClients=function(n){(n||t.virtualWSClient).forEach(function(o){o.pause()})},this.resumeClients=function(n){(n||t.virtualWSClient).forEach(function(o){o.resume()})},this.initWebSocketConnection=function(n,o){return o===void 0&&(o=t.maxReconnect),kt(t,void 0,void 0,function(){var i=this;return $t(this,function(s){switch(s.label){case 0:if(n&&this.reconnectState)return[2];if(n&&(this.reconnectState=!0),this.wsInitPromise!==void 0&&this.wsInitPromise!==null)return[2,this.wsInitPromise];n&&this.pauseClients(),this.close(Nt.ReconnectWebSocket),this.wsInitPromise=new Promise(function(c,l){(function(){return kt(i,void 0,void 0,function(){var a,u,f,d=this;return $t(this,function(y){switch(y.label){case 0:return y.trys.push([0,6,,11]),[4,this.getWsSign()];case 1:return a=y.sent(),[4,new Promise(function(m){var v=a.wsUrl||"wss://tcb-ws.tencentcloudapi.com",I=Nm();d.ws=I?new I(v):new WebSocket(v),m(void 0)})];case 2:return y.sent(),this.ws.connect?[4,this.ws.connect()]:[3,4];case 3:y.sent(),y.label=4;case 4:return[4,this.initWebSocketEvent()];case 5:return y.sent(),c(),n&&(this.resumeClients(),this.reconnectState=!1),[3,11];case 6:return u=y.sent(),console.error("[realtime] initWebSocketConnection connect fail",u),o>0?(f=!0,this.wsInitPromise=void 0,f?[4,Ds(this.reconnectInterval)]:[3,8]):[3,9];case 7:y.sent(),n&&(this.reconnectState=!1),y.label=8;case 8:return c(this.initWebSocketConnection(n,o-1)),[3,10];case 9:l(u),n&&this.closeAllClients(new xt({errCode:ct.SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL,errMsg:u})),y.label=10;case 10:return[3,11];case 11:return[2]}})})})()}),s.label=1;case 1:return s.trys.push([1,3,4,5]),[4,this.wsInitPromise];case 2:return s.sent(),this.wsReadySubsribers.forEach(function(c){var l=c.resolve;return l()}),[3,5];case 3:return s.sent(),this.wsReadySubsribers.forEach(function(c){var l=c.reject;return l()}),[3,5];case 4:return this.wsInitPromise=void 0,this.wsReadySubsribers=[],[7];case 5:return[2]}})})},this.initWebSocketEvent=function(){return new Promise(function(n,o){if(!t.ws)throw new Error("can not initWebSocketEvent, ws not exists");var i=!1;t.ws.onopen=function(s){console.warn("[realtime] ws event: open",s),i=!0,n()},t.ws.onerror=function(s){t.logins=new Map,i?(console.error("[realtime] ws event: error",s),t.clearHeartbeat(),t.virtualWSClient.forEach(function(c){return c.closeWithError(new xt({errCode:ct.SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR,errMsg:s}))})):(console.error("[realtime] ws open failed with ws event: error",s),o(s))},t.ws.onclose=function(s){switch(console.warn("[realtime] ws event: close",s),t.logins=new Map,t.clearHeartbeat(),s.code){case Nt.ReconnectWebSocket:break;case Nt.NoRealtimeListeners:break;case Nt.HeartbeatPingError:case Nt.HeartbeatPongTimeoutError:case Nt.NormalClosure:case Nt.AbnormalClosure:{t.maxReconnect>0?t.initWebSocketConnection(!0,t.maxReconnect):t.closeAllClients(Fs(s.code));break}case Nt.NoAuthentication:{t.closeAllClients(Fs(s.code,s.reason));break}default:t.maxReconnect>0?t.initWebSocketConnection(!0,t.maxReconnect):t.closeAllClients(Fs(s.code))}},t.ws.onmessage=function(s){var c=s.data;t.heartbeat();var l;try{l=JSON.parse(c)}catch(S){throw new Error("[realtime] onMessage parse res.data error: ".concat(S))}if(l.msgType==="ERROR"){var a=null;t.virtualWSClient.forEach(function(S){S.watchId===l.watchId&&(a=S)}),a&&a.listener.onError(l)}var u=t.wsResponseWait.get(l.requestId);if(u){try{l.msgType==="ERROR"?u.reject(new _m(l)):u.resolve(l)}catch(S){console.error("ws onMessage responseWaitSpec.resolve(msg) errored:",S)}finally{t.wsResponseWait.delete(l.requestId)}if(u.skipOnMessage)return}if(l.msgType==="PONG"){if(t.lastPingSendTS){var f=Date.now()-t.lastPingSendTS;if(f>Um){console.warn("[realtime] untrusted rtt observed: ".concat(f));return}t.rttObserved.length>=nf&&t.rttObserved.splice(0,t.rttObserved.length-nf+1),t.rttObserved.push(f)}return}var d=l.watchId&&t.watchIdClientMap.get(l.watchId);if(d)d.onMessage(l);else switch(console.error("[realtime] no realtime listener found responsible for watchId ".concat(l.watchId,": "),l),l.msgType){case"INIT_EVENT":case"NEXT_EVENT":case"CHECK_EVENT":{d=t.queryIdClientMap.get(l.msgData.queryID),d&&d.onMessage(l);break}default:for(var y=0,m=Array.from(t.watchIdClientMap.entries());y<m.length;y++){var v=m[y],I=v[1];I.onMessage(l);break}}},t.heartbeat()})},this.isWSConnected=function(){return!!(t.ws&&t.ws.readyState===Us.OPEN)},this.onceWSConnected=function(){return kt(t,void 0,void 0,function(){var n=this;return $t(this,function(o){return this.isWSConnected()?[2]:this.wsInitPromise!==null&&this.wsInitPromise!==void 0?[2,this.wsInitPromise]:[2,new Promise(function(i,s){n.wsReadySubsribers.push({resolve:i,reject:s})})]})})},this.webLogin=function(n,o){return kt(t,void 0,void 0,function(){var i,s,c,l,a,u,f,d,y=this;return $t(this,function(m){switch(m.label){case 0:if(!o){if(n){if(i=this.logins.get(n),i){if(i.loggedIn&&i.loginResult)return[2,i.loginResult];if(i.loggingInPromise!==null&&i.loggingInPromise!==void 0)return[2,i.loggingInPromise]}}else if(s=this.logins.get(""),(s==null?void 0:s.loggingInPromise)!==null&&(s==null?void 0:s.loggingInPromise)!==void 0)return[2,s.loggingInPromise]}c=new Promise(function(v,I){(function(){return kt(y,void 0,void 0,function(){var S,w,O,T,N;return $t(this,function(D){switch(D.label){case 0:return D.trys.push([0,3,,4]),[4,this.getWsSign()];case 1:return S=D.sent(),w={envId:S.envId||"",accessToken:"",referrer:"web",sdkVersion:"",dataVersion:""},O={watchId:void 0,requestId:$n(),msgType:"LOGIN",msgData:w,exMsgData:{runtime:rf(),signStr:S.signStr,secretVersion:S.secretVersion}},[4,this.send({msg:O,waitResponse:!0,skipOnMessage:!0,timeout:jm})];case 2:return T=D.sent(),T.msgData.code?I(new Error("".concat(T.msgData.code," ").concat(T.msgData.message))):v({envId:S.envId}),[3,4];case 3:return N=D.sent(),I(N),[3,4];case 4:return[2]}})})})()}),l=n&&this.logins.get(n),a=Date.now(),l?(l.loggedIn=!1,l.loggingInPromise=c,l.loginStartTS=a):(l={loggedIn:!1,loggingInPromise:c,loginStartTS:a},this.logins.set(n||"",l)),m.label=1;case 1:return m.trys.push([1,3,,4]),[4,c];case 2:if(u=m.sent(),f=n&&this.logins.get(n),f&&f===l&&f.loginStartTS===a)return l.loggedIn=!0,l.loggingInPromise=void 0,l.loginStartTS=void 0,l.loginResult=u,[2,u];if(f){if(f.loggedIn&&f.loginResult)return[2,f.loginResult];if(f.loggingInPromise!==null&&f.loggingInPromise!==void 0)return[2,f.loggingInPromise];throw new Error("ws unexpected login info")}else throw new Error("ws login info reset");case 3:throw d=m.sent(),l.loggedIn=!1,l.loggingInPromise=void 0,l.loginStartTS=void 0,l.loginResult=void 0,d;case 4:return[2]}})})},this.getWsSign=function(){return kt(t,void 0,void 0,function(){var n,o,i,s,c,l,a;return $t(this,function(u){switch(u.label){case 0:return this.wsSign&&this.wsSign.expiredTs>Date.now()?[2,this.wsSign]:(n=Date.now()+6e4,[4,this.context.appConfig.request.send("auth.wsWebSign",{runtime:rf()})]);case 1:if(o=u.sent(),o.code)throw new Error("[tcb-js-sdk] 获取实时数据推送登录票据失败: ".concat(o.code));if(o.data)return i=o.data,s=i.signStr,c=i.wsUrl,l=i.secretVersion,a=i.envId,[2,{signStr:s,wsUrl:c,secretVersion:l,envId:a,expiredTs:n}];throw new Error("[tcb-js-sdk] 获取实时数据推送登录票据失败")}})})},this.getWaitExpectedTimeoutLength=function(){return t.rttObserved.length?t.rttObserved.reduce(function(n,o){return n+o})/t.rttObserved.length*1.5:Fm},this.ping=function(){return kt(t,void 0,void 0,function(){var n;return $t(this,function(o){switch(o.label){case 0:return n={watchId:void 0,requestId:$n(),msgType:"PING",msgData:null},[4,this.send({msg:n})];case 1:return o.sent(),[2]}})})},this.onWatchStart=function(n,o){t.queryIdClientMap.set(o,n)},this.onWatchClose=function(n,o){o&&t.queryIdClientMap.delete(o),t.watchIdClientMap.delete(n.watchId),t.virtualWSClient.delete(n),t.virtualWSClient.size||t.close(Nt.NoRealtimeListeners)},this.maxReconnect=e.maxReconnect||Bm,this.reconnectInterval=e.reconnectInterval||Lm,this.context=e.context}return r.prototype.clearHeartbeat=function(){this.pingTimeoutId&&clearTimeout(this.pingTimeoutId),this.pongTimeoutId&&clearTimeout(this.pongTimeoutId)},r.prototype.close=function(e){this.clearHeartbeat(),this.ws&&(this.ws.close(e,Zl[e].name),this.ws=void 0)},r.prototype.watch=function(e){!this.ws&&(this.wsInitPromise===void 0||this.wsInitPromise===null)&&this.initWebSocketConnection(!1);var t=new Cm(Ho(Ho({},e),{send:this.send,login:this.webLogin,isWSConnected:this.isWSConnected,onceWSConnected:this.onceWSConnected,getWaitExpectedTimeoutLength:this.getWaitExpectedTimeoutLength,onWatchStart:this.onWatchStart,onWatchClose:this.onWatchClose,debug:!0}));return this.virtualWSClient.add(t),this.watchIdClientMap.set(t.watchId,t),t.listener},r.prototype.heartbeat=function(e){var t=this;this.clearHeartbeat(),this.pingTimeoutId=setTimeout(function(){(function(){return kt(t,void 0,void 0,function(){var n=this;return $t(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),!this.ws||this.ws.readyState!==Us.OPEN?[2]:(this.lastPingSendTS=Date.now(),[4,this.ping()]);case 1:return o.sent(),this.pingFailed=0,this.pongTimeoutId=setTimeout(function(){console.error("pong timed out"),n.pongMissed<qm?(n.pongMissed+=1,n.heartbeat(!0)):n.initWebSocketConnection(!0)},this.context.appConfig.realtimePongWaitTimeout),[3,3];case 2:return o.sent(),this.pingFailed<Mm?(this.pingFailed+=1,this.heartbeat()):this.close(Nt.HeartbeatPingError),[3,3];case 3:return[2]}})})})()},e?0:this.context.appConfig.realtimePingInterval)},r}(),of={target:"database",entity:function(){var r=this.platform,e=r.adapter,t=r.runtime;Pm(e.wsClass),Dm(t)}},af={name:"realtime",IIFE:!0,entity:function(){this.prototype.wsClientClass=km}};try{cloudbase.registerComponent(af),cloudbase.registerHook(of)}catch{}function $m(r){try{r.registerComponent(af),r.registerHook(of)}catch(e){console.warn(e)}}var Wm=function(r,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,e,t,n);else for(var c=r.length-1;c>=0;c--)(s=r[c])&&(i=(o<3?s(i):o>3?s(e,t,i):s(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i},Bs=function(r,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,e)},Hm=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Gm=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Vm=at,zm=Ki,Jm=Xi,sf="analytics",Km=["mall"];function Ym(r){if(Object.prototype.toString.call(r).slice(8,-1)!=="Object")return!1;var e=r.report_data,t=r.report_type;return!(Km.includes(t)===!1||Object.prototype.toString.call(e).slice(8,-1)!=="Object"||e.action_time!==void 0&&!Number.isInteger(e.action_time)||typeof e.action_type!="string")}var Qm=function(){function r(){}return r.prototype.analytics=function(e){return Hm(this,void 0,void 0,function(){var t,n,o,i,s;return Gm(this,function(c){if(!Ym(e))throw new Error(JSON.stringify({code:Vm.INVALID_PARAMS,msg:"[".concat(sf,".analytics] invalid report data")}));return t="analytics.report",n=e.report_data.action_time===void 0?Math.floor(Date.now()/1e3):e.report_data.action_time,o={analytics_scene:e.report_type,analytics_data:Object.assign({},e.report_data,{action_time:n})},i={requestData:o},s=this.request,s.send(t,i),[2]})})},Wm([Jm({customInfo:{},title:"上报调用失败",messages:["请确认以下各项:"," 1 - 调用 analytics() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(zm)]}),Bs("design:type",Function),Bs("design:paramtypes",[Object]),Bs("design:returntype",Promise)],r.prototype,"analytics",null),r}(),Xm=new Qm,uf={name:sf,entity:{analytics:Xm.analytics}};try{cloudbase.registerComponent(uf)}catch{}function Zm(r){try{r.registerComponent(uf)}catch(e){console.warn(e)}}var Ls=function(r,e){return Ls=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])},Ls(r,e)};function e0(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");Ls(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}var We=function(){return We=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++){t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},We.apply(this,arguments)};function Wn(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,[])).next())})}function Hn(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}var fn=function(r){e0(e,r);function e(t,n){var o=r.call(this,t)||this;return o.name="WxCloudSDKError",o.code=n==null?void 0:n.code,o.requestId=n==null?void 0:n.requestId,o.originError=n==null?void 0:n.originError,o}return e}(Error);function Ms(){return typeof window<"u"&&window||typeof globalThis<"u"&&globalThis}function t0(){try{var r=Ms();return r?typeof wx>"u"?Ms().location.href:r.__wxRoute:void 0}catch{}}function r0(){var r=Ms();if(r!=null&&r.navigator)return r.navigator.userAgent;if(typeof wx<"u"&&wx.getSystemInfo){var e;return wx.getSystemInfo({success:function(t){t&&(e=["brand","model","version","system","platform","SDKVersion","language"].map(function(n){return"".concat(n,": ").concat(t[n])}).join(", "))}}),e}}var n0="1.6.1",i0=function(r){var e=r.dataSourceName,t=r.methodName,n=r.params,o=r.realMethodName,i=r.callFunction,s=r.envType,c=s===void 0?"prod":s,l=r.mode;return Wn(void 0,void 0,void 0,function(){var a,u,f,d,y,m;return Hn(this,function(v){switch(v.label){case 0:a={data:{},requestId:""},v.label=1;case 1:return v.trys.push([1,3,,4]),[4,i({name:"lowcode-datasource",data:{dataSourceName:e,methodName:t,params:n,userAgent:r0(),referrer:t0(),"x-sdk-version":n0,envType:c,mode:l}})];case 2:if(u=v.sent(),f=((y=u==null?void 0:u.result)===null||y===void 0?void 0:y.requestId)||(u==null?void 0:u.requestId)||(u==null?void 0:u.requestID),u!=null&&u.result.code)throw new fn("【错误】".concat(u==null?void 0:u.result.message,`
12
+ 【操作】调用 models.`).concat(e?"".concat(e,"."):"").concat(o,`
13
+ 【错误码】`).concat(u==null?void 0:u.result.code,`
14
+ 【请求ID】`).concat(f||"N/A"),{code:u==null?void 0:u.result.code,requestId:f});return a.data=((m=u==null?void 0:u.result)===null||m===void 0?void 0:m.data)||{},a.requestId=f,[3,4];case 3:throw d=v.sent(),d.name==="WxCloudSDKError"?d:(console.log(d),new fn("【错误】".concat(d.message,`
15
+ 【操作】调用 models.`).concat(e?"".concat(e,"."):"").concat(o,`
16
+ 【请求ID】N/A`),{code:"UnknownError",originError:d}));case 4:return[2,a]}})})},cf=function(r){var e=r.sql,t=r.params,n=r.config,o=r.callFunction,i=r.unsafe,s=i===void 0?!1:i;return Wn(void 0,void 0,void 0,function(){return Hn(this,function(c){return[2,i0({realMethodName:"$runSQL",methodName:"callWedaApi",params:{action:"RunMysqlCommand",data:{sqlTemplate:e,config:n,parameter:s?"":Object.entries(t||{}).reduce(function(l,a){var u=a[0],f=a[1];if(f!==void 0){var d="OBJECT",y=typeof f;switch(y){case"boolean":{d="BOOLEAN";break}case"number":{d="NUMBER";break}case"string":{d="STRING";break}default:Array.isArray(f)?d="ARRAY":d="OBJECT"}l.push({key:u,type:d,value:d==="STRING"?f:JSON.stringify(f)})}return l},[])||[]}},callFunction:o,mode:"sdk"})]})})},o0=function(r){return{$runSQL:function(e,t,n){return Wn(this,void 0,void 0,function(){var o;return Hn(this,function(i){switch(i.label){case 0:return[4,cf({sql:e,params:t,config:We(We({},n),{preparedStatements:!0}),callFunction:r})];case 1:return o=i.sent(),[2,o]}})})},$runSQLRaw:function(e,t){return Wn(this,void 0,void 0,function(){var n;return Hn(this,function(o){switch(o.label){case 0:return[4,cf({sql:e,params:[],config:We(We({},t),{preparedStatements:!1}),callFunction:r})];case 1:return n=o.sent(),[2,n]}})})}}},lf={filter:{where:{}},select:{$master:!0}};function vr(r){return{getUrl:function(e){return"".concat(e,"/").concat(r)},method:"post"}}var a0={get:We(We({},vr("get")),{defaultParams:We({},lf)}),list:We(We({},vr("list")),{defaultParams:We({},lf)}),create:vr("create"),createMany:vr("createMany"),update:We(We({},vr("update")),{method:"put"}),updateMany:We(We({},vr("updateMany")),{method:"put"}),upsert:vr("upsert"),delete:vr("delete"),deleteMany:vr("deleteMany")},Go="Unknown error occurred",ff="NotSupported",s0=function(r,e,t,n){var o=o0(r);return new Proxy({},{get:function(i,s){if(typeof s=="string")return Object.prototype.hasOwnProperty.call(o,s)?o[s]:u0(t,s,e,n)}})},df=function(r,e,t,n,o){return new fn("【错误】".concat(r,`
17
+ 【操作】调用 models.`).concat(e,".").concat(t,`
18
+ 【错误码】`).concat(n,`
19
+ 【请求ID】`).concat(o),{code:n,requestId:o})},u0=function(r,e,t,n){var o=new Proxy({},{get:function(i,s){if(s!=="runSQLTemplate"){var c=a0[s];if(!c){var l=new Error("不支持的操作: ".concat(s));throw new fn(l.message||Go,{originError:l,code:ff,requestId:"N/A"})}return function(a){return a===void 0&&(a={}),Wn(void 0,void 0,void 0,function(){var u,f,d,y,m,v,I,S,w,O;return Hn(this,function(T){switch(T.label){case 0:u=c.getUrl,f=c.method,d=c.defaultParams,y=d===void 0?{}:d,m=Object.assign({},y,a),v=m.envType==="pre"?"pre":"prod",I=[r,v,u(e)].join("/"),T.label=1;case 1:return T.trys.push([1,3,,4]),[4,t({url:I,body:JSON.stringify(m),method:f})];case 2:if(S=T.sent(),S.code)throw df(S==null?void 0:S.message,e,s,S==null?void 0:S.code,S==null?void 0:S.requestId);return s==="get"&&Object.assign(S,{data:(O=S.data.record)!==null&&O!==void 0?O:S.data}),[2,S];case 3:throw w=T.sent(),new fn((w==null?void 0:w.message)||Go,{originError:w});case 4:return[2]}})})}}else{if(!(n!=null&&n.sqlBaseUrl)){var l=new Error("不支持的操作: ".concat(s));throw new fn(l.message||Go,{originError:l,code:ff,requestId:"N/A"})}return function(a){return Wn(void 0,void 0,void 0,function(){var u,f,d,y,m,v,I,S,w,O,T,N,D,B,R,x;return Hn(this,function(L){switch(L.label){case 0:u=a.params,f=a.templateName,d=a.envType,y=d==="pre"?"pre":"prod",m=[n.sqlBaseUrl,y,f,"run"].join("/"),v=Object.entries(u||{}).reduce(function(F,j){var V=j[0],W=j[1];if(W!==void 0){var oe="OBJECT",se=typeof W;switch(se){case"boolean":{oe="BOOLEAN";break}case"number":{oe="NUMBER";break}case"string":{oe="STRING";break}default:Array.isArray(W)?oe="ARRAY":oe="OBJECT"}F.push({key:V,type:oe,value:oe==="STRING"?W:JSON.stringify(W)})}return F},[]),L.label=1;case 1:return L.trys.push([1,3,,4]),[4,t({url:m,body:JSON.stringify({parameter:v}),method:"POST"})];case 2:if(I=L.sent(),!((w=I==null?void 0:I.Response)===null||w===void 0)&&w.Error)throw df((T=(O=I==null?void 0:I.Response)===null||O===void 0?void 0:O.Error)===null||T===void 0?void 0:T.Message,e,s,(D=(N=I==null?void 0:I.Response)===null||N===void 0?void 0:N.Error)===null||D===void 0?void 0:D.Code,(B=I==null?void 0:I.Response)===null||B===void 0?void 0:B.RequestId);return[2,We(We({},(R=I==null?void 0:I.Response)!==null&&R!==void 0?R:{}),{data:(x=I==null?void 0:I.Response)===null||x===void 0?void 0:x.Data})];case 3:throw S=L.sent(),new fn((S==null?void 0:S.message)||Go,{originError:S});case 4:return[2]}})})}}}});return o},Fi=function(){return Fi=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Fi.apply(this,arguments)},c0=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},l0=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},f0=lp,hf="models";function d0(r){var e=this,t=r.callFunction.bind(r),n=r.request.fetch.bind(r.request),o=function(f){return c0(e,void 0,void 0,function(){var d;return l0(this,function(y){switch(y.label){case 0:return[4,n(Fi(Fi({},f),{headers:Fi({"Content-Type":"application/json"},f.headers)}))];case 1:return d=y.sent(),[4,d.data];case 2:return[2,y.sent()]}})})},i=r.getEndPointWithKey("GATEWAY"),s=i.BASE_URL,c=i.PROTOCOL,l="".concat(c).concat(s,"/model"),a="".concat(c).concat(s,"/sql"),u=s0(t,o,l,{sqlBaseUrl:a});return u}var pf=new WeakMap;function h0(r){return new Proxy({},{get:function(e,t){var n=pf.get(r);return n||(n=d0(r),pf.set(r,n)),n[t]}})}var yf="cloudbase_init",mf=new f0;mf.on(yf,function(r){var e=r.data;Object.assign(e,{models:h0(e)})});var gf={name:hf,namespace:hf,entity:new Proxy({},{get:function(r,e){console.warn("【deprecated】Accessing Cloudbase.prototype.models.".concat(e,"."))}}),injectEvents:{bus:mf,events:[yf]}};try{cloudbase.registerComponent(gf)}catch{}function p0(r){try{r.registerComponent(gf)}catch(e){console.warn(e)}}/*! *****************************************************************************
20
+ Copyright (c) Microsoft Corporation.
21
+
22
+ Permission to use, copy, modify, and/or distribute this software for any
23
+ purpose with or without fee is hereby granted.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
26
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
27
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
28
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
29
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
30
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
31
+ PERFORMANCE OF THIS SOFTWARE.
32
+ ***************************************************************************** */var qs=function(r,e){return qs=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])},qs(r,e)};function vf(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");qs(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function Gn(r){if(!r)throw new TypeError("Assertion failed")}function y0(){}function m0(r){return typeof r=="object"&&r!==null||typeof r=="function"}function g0(r){if(typeof r!="function")return!1;var e=!1;try{new r({start:function(){e=!0}})}catch{}return e}function _f(r){return!(!m0(r)||typeof r.getReader!="function")}function v0(r){return!(!g0(r)||!_f(new r))}function bf(r){try{var e=r.getReader({mode:"byob"});return e.releaseLock(),!0}catch{return!1}}function _0(r){try{return new r({type:"bytes"}),!0}catch{return!1}}function b0(r){Gn(v0(r));var e=_0(r);return function(t,n){var o=n===void 0?{}:n,i=o.type;if(i=Ef(i),i==="bytes"&&!e&&(i=void 0),t.constructor===r&&(i!=="bytes"||bf(t)))return t;if(i==="bytes"){var s=wf(t,{type:i});return new r(s)}else{var s=wf(t);return new r(s)}}}function wf(r,e){var t=e===void 0?{}:e,n=t.type;Gn(_f(r)),Gn(r.locked===!1),n=Ef(n);var o;return n==="bytes"?o=new S0(r):o=new w0(r),o}function Ef(r){var e=String(r);if(e==="bytes")return e;if(r===void 0)return r;throw new RangeError("Invalid type is specified")}var Sf=function(){function r(e){this._underlyingReader=void 0,this._readerMode=void 0,this._readableStreamController=void 0,this._pendingRead=void 0,this._underlyingStream=e,this._attachDefaultReader()}return r.prototype.start=function(e){this._readableStreamController=e},r.prototype.cancel=function(e){return Gn(this._underlyingReader!==void 0),this._underlyingReader.cancel(e)},r.prototype._attachDefaultReader=function(){if(this._readerMode!=="default"){this._detachReader();var e=this._underlyingStream.getReader();this._readerMode="default",this._attachReader(e)}},r.prototype._attachReader=function(e){var t=this;Gn(this._underlyingReader===void 0),this._underlyingReader=e;var n=this._underlyingReader.closed;n&&n.then(function(){return t._finishPendingRead()}).then(function(){e===t._underlyingReader&&t._readableStreamController.close()},function(o){e===t._underlyingReader&&t._readableStreamController.error(o)}).catch(y0)},r.prototype._detachReader=function(){this._underlyingReader!==void 0&&(this._underlyingReader.releaseLock(),this._underlyingReader=void 0,this._readerMode=void 0)},r.prototype._pullWithDefaultReader=function(){var e=this;this._attachDefaultReader();var t=this._underlyingReader.read().then(function(n){var o=e._readableStreamController;n.done?e._tryClose():o.enqueue(n.value)});return this._setPendingRead(t),t},r.prototype._tryClose=function(){try{this._readableStreamController.close()}catch{}},r.prototype._setPendingRead=function(e){var t=this,n,o=function(){t._pendingRead===n&&(t._pendingRead=void 0)};this._pendingRead=n=e.then(o,o)},r.prototype._finishPendingRead=function(){var e=this;if(this._pendingRead){var t=function(){return e._finishPendingRead()};return this._pendingRead.then(t,t)}},r}(),w0=function(r){vf(e,r);function e(){return r!==null&&r.apply(this,arguments)||this}return e.prototype.pull=function(){return this._pullWithDefaultReader()},e}(Sf);function If(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function E0(r,e){var t=If(r),n=If(e);n.set(t,0)}var S0=function(r){vf(e,r);function e(t){var n=this,o=bf(t);return n=r.call(this,t)||this,n._supportsByob=o,n}return Object.defineProperty(e.prototype,"type",{get:function(){return"bytes"},enumerable:!1,configurable:!0}),e.prototype._attachByobReader=function(){if(this._readerMode!=="byob"){Gn(this._supportsByob),this._detachReader();var t=this._underlyingStream.getReader({mode:"byob"});this._readerMode="byob",this._attachReader(t)}},e.prototype.pull=function(){if(this._supportsByob){var t=this._readableStreamController.byobRequest;if(t)return this._pullWithByobRequest(t)}return this._pullWithDefaultReader()},e.prototype._pullWithByobRequest=function(t){var n=this;this._attachByobReader();var o=new Uint8Array(t.view.byteLength),i=this._underlyingReader.read(o).then(function(s){n._readableStreamController,s.done?(n._tryClose(),t.respond(0)):(E0(s.value,t.view),t.respond(s.value.byteLength))});return this._setPendingRead(i),i},e}(Sf);function I0(r){var e,t,n,o,i,s,c;return l(),{feed:a,reset:l};function l(){e=!0,t="",n=0,o=-1,i=void 0,s=void 0,c=""}function a(f){t=t?t+f:f,e&&O0(t)&&(t=t.slice(Of.length)),e=!1;for(var d=t.length,y=0,m=!1;y<d;){m&&(t[y]===`
33
+ `&&(y+=1),m=!1);for(var v=-1,I=o,S=void 0,w=n;v<0&&w<d;w++)S=t[w],S===":"&&I<0?I=w-y:S==="\r"?(m=!0,v=w-y):S===`
34
+ `&&(v=w-y);if(v<0){n=d-y,o=I;break}else n=0,o=-1;u(t,y,I,v),y+=v+1}y===d?t="":y>0&&(t=t.slice(y))}function u(f,d,y,m){if(m===0){c.length>0&&(r({type:"event",id:i,event:s||void 0,data:c.slice(0,-1)}),c="",i=void 0),s=void 0;return}var v=y<0,I=f.slice(d,d+(v?m:y)),S=0;v?S=m:f[d+y+1]===" "?S=y+2:S=y+1;var w=d+S,O=m-S,T=f.slice(w,w+O).toString();if(I==="data")c+=T?"".concat(T,`
35
+ `):`
36
+ `;else if(I==="event")s=T;else if(I==="id"&&!T.includes("\0"))i=T;else if(I==="retry"){var N=parseInt(T,10);Number.isNaN(N)||r({type:"reconnect-interval",value:N})}}}var Of=[239,187,191];function O0(r){return Of.every(function(e,t){return r.charCodeAt(t)===e})}var Vo={exports:{}},T0=Vo.exports,Tf;function A0(){return Tf||(Tf=1,function(r,e){(function(t,n){r.exports=n()})(T0,function(){var t=typeof ut<"u"?ut:self;if(typeof t.TextEncoder<"u"&&typeof t.TextDecoder<"u")return{TextEncoder:t.TextEncoder,TextDecoder:t.TextDecoder};var n=["utf8","utf-8","unicode-1-1-utf-8"],o=function(s){if(n.indexOf(s)<0&&typeof s<"u"&&s!==null)throw new RangeError("Invalid encoding type. Only utf-8 is supported");this.encoding="utf-8",this.encode=function(c){if(typeof c!="string")throw new TypeError("passed argument must be of type string");var l=unescape(encodeURIComponent(c)),a=new Uint8Array(l.length);return l.split("").forEach(function(u,f){a[f]=u.charCodeAt(0)}),a}},i=function(s,c){if(n.indexOf(s)<0&&typeof s<"u"&&s!==null)throw new RangeError("Invalid encoding type. Only utf-8 is supported");if(this.encoding="utf-8",this.ignoreBOM=!1,this.fatal=typeof c<"u"&&"fatal"in c?c.fatal:!1,typeof this.fatal!="boolean")throw new TypeError("fatal flag must be boolean");this.decode=function(l,a){if(typeof l>"u")return"";var u=typeof a<"u"&&"stream"in a?a.stream:!1;if(typeof u!="boolean")throw new TypeError("stream option must be boolean");if(ArrayBuffer.isView(l)){var f=new Uint8Array(l.buffer,l.byteOffset,l.byteLength),d=new Array(f.length);return f.forEach(function(y,m){d[m]=String.fromCharCode(y)}),decodeURIComponent(escape(d.join("")))}else throw new TypeError("passed argument must be an array buffer view")}};return{TextEncoder:o,TextDecoder:i}})}(Vo)),Vo.exports}var R0=A0(),Af=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Rf=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},C0=function(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof __values=="function"?__values(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(i){t[i]=r[i]&&function(s){return new Promise(function(c,l){s=r[i](s),o(c,l,s.done,s.value)})}}function o(i,s,c,l){Promise.resolve(l).then(function(a){i({value:a,done:c})},s)}},x0=ze,De=Eo,Cf=function(){var r;return new De({start:function(e){r=I0(function(t){t.type==="event"&&e.enqueue(t)})},transform:function(e){r.feed(e)}})},Et=b0(x0),js=function(){function r(e,t){e===void 0&&(e="utf-8"),t===void 0&&(t={});var n=this;this.transform=new De({transform:function(o,i){var s=n.handle.decode(new Uint8Array(o),{stream:!0});s&&i.enqueue(s)},flush:function(o){var i=n.handle.decode();i&&o.enqueue(i),o.terminate()}}),this.handle=new R0.TextDecoder(e,t)}return Object.defineProperty(r.prototype,"encoding",{get:function(){return this.handle.encoding},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"fatal",{get:function(){return this.handle.fatal},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"ignoreBOM",{get:function(){return this.handle.ignoreBOM},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"readable",{get:function(){return this.transform.readable},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"writable",{get:function(){return this.transform.writable},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,Symbol.toStringTag,{get:function(){return"TextDecoderStream"},enumerable:!1,configurable:!0}),r}();function Te(r){var e=r;return e[Symbol.asyncIterator]=function(){var t=r.getReader();return{next:function(){return Af(this,void 0,void 0,function(){var n,o,i;return Rf(this,function(s){switch(s.label){case 0:return[4,t.read()];case 1:return n=s.sent(),o=n.done,i=n.value,[2,o?{done:!0,value:void 0}:{done:!1,value:i}]}})})}}},e}function Wt(r){return Te(r.pipeThrough(new js).pipeThrough(Cf()).pipeThrough(new De({transform:function(e,t){try{var n=JSON.parse(e.data);t.enqueue(n)}catch(o){e.data!=="[DONE]"?console.warn("Error when transforming event source data to json",o,e):t.terminate()}}})))}function N0(r){return Te(Et(r).pipeThrough(new js))}function P0(r){var e,t,n,o;return Af(this,void 0,void 0,function(){var i,s,c,l,a,u,f;return Rf(this,function(d){switch(d.label){case 0:i=N0(r),s="",d.label=1;case 1:d.trys.push([1,6,7,12]),c=!0,l=C0(i),d.label=2;case 2:return[4,l.next()];case 3:if(a=d.sent(),e=a.done,!!e)return[3,5];o=a.value,c=!1;try{u=o,s+=u}finally{c=!0}d.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return f=d.sent(),t={error:f},[3,12];case 7:return d.trys.push([7,,10,11]),!c&&!e&&(n=l.return)?[4,n.call(l)]:[3,9];case 8:d.sent(),d.label=9;case 9:return[3,11];case 10:if(t)throw t.error;return[7];case 11:return[7];case 12:return[2,JSON.parse(s)]}})})}function xf(){var r,e,t=new Promise(function(n,o){r=n,e=o});return{promise:t,res:r,rej:e}}function Pt(r){var e;return r.role==="assistant"&&"tool_calls"in r&&((e=r.tool_calls)===null||e===void 0?void 0:e[0])!=null}function D0(r){return{type:"function",function:{description:r.description,name:r.name,parameters:r.parameters}}}var Mr=function(){return Mr=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Mr.apply(this,arguments)},Ht=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Gt=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Nf=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(r);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(r,n[o])&&(t[n[o]]=r[n[o]]);return t},F0=function(){function r(e,t){this.baseUrl=t;var n=arguments[2];typeof n=="string"?this.req=function(o){var i=o.headers,s=i===void 0?{}:i,c=Nf(o,["headers"]);return e(Mr(Mr({},c),{headers:Mr(Mr({},s),{Authorization:"Bearer ".concat(n)})}))}:this.req=e}return r.prototype.list=function(e,t){return this.req({method:"get",url:this.join("bots"),data:e,timeout:t==null?void 0:t.timeout})},r.prototype.create=function(e,t){var n=e.botInfo;return this.req({method:"post",url:this.join("bots"),data:n,timeout:t==null?void 0:t.timeout})},r.prototype.get=function(e,t){var n=e.botId;return this.req({method:"get",url:this.join("bots/".concat(n)),timeout:t==null?void 0:t.timeout})},r.prototype.update=function(e,t){var n=e.botId,o=e.botInfo;return this.req({method:"PATCH",url:this.join("bots/".concat(n)),data:o,timeout:t==null?void 0:t.timeout})},r.prototype.delete=function(e,t){var n=e.botId;return this.req({method:"delete",url:this.join("bots/".concat(n)),timeout:t==null?void 0:t.timeout})},r.prototype.getChatRecords=function(e,t){return this.req({method:"get",url:this.join("bots/".concat(e.botId,"/records")),data:e,timeout:t==null?void 0:t.timeout})},r.prototype.sendFeedback=function(e,t){var n=e.userFeedback;return this.req({method:"post",url:this.join("bots/".concat(n.botId,"/feedback")),data:n,timeout:t==null?void 0:t.timeout})},r.prototype.getFeedback=function(e,t){return this.req({method:"get",url:this.join("bots/".concat(e.botId,"/feedback")),data:e,timeout:t==null?void 0:t.timeout})},r.prototype.uploadFiles=function(e,t){return Ht(this,void 0,void 0,function(){return Gt(this,function(n){return[2,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/files")),data:e,timeout:t==null?void 0:t.timeout})]})})},r.prototype.createConversation=function(e,t){return Ht(this,void 0,void 0,function(){return Gt(this,function(n){return[2,this.req({method:"post",url:this.join("conversation"),data:e,timeout:t==null?void 0:t.timeout})]})})},r.prototype.getConversation=function(e,t){var n=e.pageSize,o=n===void 0?10:n,i=e.pageNumber,s=i===void 0?1:i,c=Nf(e,["pageSize","pageNumber"]);return Ht(this,void 0,void 0,function(){var l,a;return Gt(this,function(u){if(s<1)throw new Error("pageNumber must be greater than 0");return l=o*(s-1),a=o,[2,this.req({method:"get",url:this.join("conversation"),data:Mr(Mr({},c),{offset:l,limit:a}),timeout:t==null?void 0:t.timeout})]})})},r.prototype.deleteConversation=function(e,t){return Ht(this,void 0,void 0,function(){return Gt(this,function(n){return[2,this.req({method:"delete",url:this.join("conversation/".concat(e.conversationId)),data:e,timeout:t==null?void 0:t.timeout})]})})},r.prototype.speechToText=function(e,t){return Ht(this,void 0,void 0,function(){return Gt(this,function(n){return[2,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/speech-to-text")),data:e,timeout:t==null?void 0:t.timeout})]})})},r.prototype.textToSpeech=function(e,t){return Ht(this,void 0,void 0,function(){return Gt(this,function(n){return[2,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/text-to-speech")),data:e,timeout:t==null?void 0:t.timeout})]})})},r.prototype.getTextToSpeechResult=function(e,t){return Ht(this,void 0,void 0,function(){return Gt(this,function(n){return[2,this.req({method:"get",url:this.join("bots/".concat(e.botId,"/text-to-speech")),data:e,timeout:t==null?void 0:t.timeout})]})})},r.prototype.getRecommendQuestions=function(e,t){return Ht(this,void 0,void 0,function(){var n;return Gt(this,function(o){switch(o.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/recommend-questions")),data:e,stream:!0,timeout:t==null?void 0:t.timeout})];case 1:return n=o.sent(),[2,new zo(n)]}})})},r.prototype.generateBot=function(e,t){return Ht(this,void 0,void 0,function(){var n;return Gt(this,function(o){switch(o.label){case 0:return[4,this.req({method:"post",url:this.join("generate-bot"),data:e,stream:!0,timeout:t==null?void 0:t.timeout})];case 1:return n=o.sent(),[2,new zo(n)]}})})},r.prototype.getPreview=function(e,t){return Ht(this,void 0,void 0,function(){var n;return Gt(this,function(o){switch(o.label){case 0:return[4,this.req({method:"post",url:this.join("preview"),data:e,stream:!0,timeout:t==null?void 0:t.timeout})];case 1:return n=o.sent(),[2,new zo(n)]}})})},r.prototype.generateImage=function(e,t){return this.req({method:"post",url:this.join("generate-image"),data:e,timeout:t==null?void 0:t.timeout})},r.prototype.sendMessage=function(e,t){return Ht(this,void 0,void 0,function(){var n;return Gt(this,function(o){switch(o.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/send-message")),data:e,stream:!0,timeout:t==null?void 0:t.timeout})];case 1:return n=o.sent(),[2,new zo(n)]}})})},r.prototype.join=function(e){return"".concat(this.baseUrl,"/").concat(e)},r}(),zo=function(){function r(e){var t=Et(e);this._eventSourceStream=t.pipeThrough(new js).pipeThrough(Cf())}return Object.defineProperty(r.prototype,"teeedStream",{get:function(){var e=this._eventSourceStream.tee(),t=e[0],n=e[1];return this._eventSourceStream=n,t},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"eventSourceStream",{get:function(){return Te(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"dataStream",{get:function(){return Te(this.eventSourceStream.pipeThrough(new De({transform:function(e,t){try{var n=JSON.parse(e.data);t.enqueue(n)}catch(o){e.data!=="[DONE]"?console.warn("Error when transforming event source data to json",o,e):t.terminate()}}})))},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"textStream",{get:function(){return Te(this.dataStream.pipeThrough(new De({transform:function(e,t){var n;t.enqueue((n=e==null?void 0:e.content)!==null&&n!==void 0?n:"")}})))},enumerable:!1,configurable:!0}),r}(),Ye=function(){return Ye=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Ye.apply(this,arguments)},Pf=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Df=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}};function Ff(r){var e=r.messages,t=r.model,n=r.temperature,o=r.tool_choice,i=r.tools,s=r.top_p,c=function(){return o&&o!=="auto"&&console.warn("`tool_choice` is not 'auto'"),o};return Ye(Ye({},r),{messages:e,model:t,temperature:n,tool_choice:c(),tools:i,top_p:s})}var Uf=function(){function r(e,t,n){this.req=e,this.baseUrl=t,this.subUrl="zhipu/api/paas/v4/chat/completions",n!=null&&(this.subUrl=n)}return Object.defineProperty(r.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),r.prototype.doGenerate=function(e,t){return Pf(this,void 0,void 0,function(){var n,o;return Df(this,function(i){switch(i.label){case 0:return n=Ff(e),[4,this.req({url:this.url,data:Ye(Ye({},n),{stream:!1}),stream:!1,timeout:t==null?void 0:t.timeout})];case 1:return o=i.sent(),[2,Ye(Ye({},o),{rawResponse:o})]}})})},r.prototype.doStream=function(e,t){return Pf(this,void 0,void 0,function(){var n,o,i,s,c,l;return Df(this,function(a){switch(a.label){case 0:return n=Ff(e),o=null,[4,this.req({url:this.url,data:Ye(Ye({},n),{stream:!0}),stream:!0,timeout:t==null?void 0:t.timeout})];case 1:return i=a.sent(),s=Et(i),c=Wt(s),l=c.pipeThrough(new De({transform:function(u,f){var d=u.choices.map(function(m){var v=m.delta;return o==null&&(o=Pt(v)),o?Ye(Ye({},m),{finish_reason:"tool_calls",delta:v}):m}),y=Ye(Ye({},u),{choices:d});f.enqueue(Ye(Ye({},y),{rawResponse:u}))}})),[2,Te(l)]}})})},r}(),Jo=function(){return Jo=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Jo.apply(this,arguments)};function dn(r){var e=r.messages,t=r.model,n=r.temperature,o=r.tool_choice,i=r.tools,s=r.top_p,c=function(){if(i)return i.forEach(function(a){a.type!=="function"&&console.warn("`type` in tool is not 'function'",a)}),i},l=function(){return e.forEach(function(a){"tool_calls"in a&&a.tool_calls.filter(function(u){return u.type!=="function"}).forEach(function(u){return console.warn("`type` in tool_call is not 'function'",u,a)})}),e};return Jo(Jo({},r),{messages:l(),model:t,tools:c(),top_p:s,tool_choice:o,temperature:n})}function Ko(r){if(typeof r!="object"||r==null)return r;if(Array.isArray(r))return r.map(function(t){return Ko(t)});return Object.entries(r).reduce(function(t,n){var o=n[0],i=n[1],s=e(o);return t[s]=typeof i=="object"?Ko(i):i,t},{});function e(t){var n=t.replace(/[A-Z]/g,function(o){return"_".concat(o.toLowerCase())});return n.charAt(0)==="_"?n.slice(1):n}}var ft=function(){return ft=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},ft.apply(this,arguments)},Bf=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Lf=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Mf=function(){function r(e,t,n){this.req=e,this.baseUrl=t,this.subUrl="hunyuan-beta/openapi/v1/chat/completions",n!=null&&(this.subUrl=n)}return Object.defineProperty(r.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),r.prototype.doGenerate=function(e,t){return Bf(this,void 0,void 0,function(){var n;return Lf(this,function(o){switch(o.label){case 0:return[4,this.req({url:this.url,data:ft(ft({},dn(e)),{stream:!1}),stream:!1,timeout:t==null?void 0:t.timeout})];case 1:return n=o.sent(),[2,ft(ft({},n),{rawResponse:n})]}})})},r.prototype.doStream=function(e,t){return Bf(this,void 0,void 0,function(){var n,o,i,s,c;return Lf(this,function(l){switch(l.label){case 0:return n=null,[4,this.req({url:this.url,data:ft(ft({},dn(e)),{stream:!0}),stream:!0,timeout:t==null?void 0:t.timeout})];case 1:return o=l.sent(),i=Et(o),s=Wt(i),c=s.pipeThrough(new De({transform:function(a,u){var f=a.choices.map(function(y){var m=y.delta;return n==null&&(n=Pt(m)),n?ft(ft({},y),{finish_reason:"tool_calls",delta:m}):y}),d=ft(ft({},a),{choices:f});u.enqueue(ft(ft({},d),{rawResponse:a}))}})),[2,Te(c)]}})})},r}(),dt=function(){return dt=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},dt.apply(this,arguments)},qf=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},jf=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},kf=function(){function r(e,t,n){this.req=e,this.baseUrl=t,this.subUrl="hunyuan",n!=null&&(this.subUrl=n)}return Object.defineProperty(r.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),r.prototype.doGenerate=function(e,t){return qf(this,void 0,void 0,function(){var n,o;return jf(this,function(i){switch(i.label){case 0:return[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:dt(dt({},dn(e)),{stream:!1}),stream:!1,timeout:t==null?void 0:t.timeout})];case 1:return n=i.sent(),o=Ko(n.Response),[2,dt(dt({},o),{rawResponse:n})]}})})},r.prototype.doStream=function(e,t){return qf(this,void 0,void 0,function(){var n,o,i,s,c;return jf(this,function(l){switch(l.label){case 0:return n=null,[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:dt(dt({},e),{stream:!0}),stream:!0,timeout:t==null?void 0:t.timeout})];case 1:return o=l.sent(),i=Et(o),s=Wt(i),c=s.pipeThrough(new De({transform:function(a,u){var f=Ko(a),d=f.choices.map(function(m){var v=m.delta;return n==null&&(n=Pt(v)),n?dt(dt({},m),{finish_reason:"tool_calls",delta:v}):m}),y=dt(dt({},f),{choices:d});u.enqueue(dt(dt({},y),{rawResponse:a}))}})),[2,Te(c)]}})})},r}(),Qe=function(){return Qe=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Qe.apply(this,arguments)},$f=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Wf=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}};function Hf(r){var e=r.messages,t=r.model,n=r.temperature,o=r.tools,i=r.top_p;return Qe(Qe({},r),{messages:e,model:t,tools:o,top_p:i,temperature:n})}var Gf=function(){function r(e,t,n){this.req=e,this.baseUrl=t,this.subUrl="ark/api/v3/chat/completions",n!=null&&(this.subUrl=n)}return Object.defineProperty(r.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),r.prototype.doGenerate=function(e,t){return $f(this,void 0,void 0,function(){var n;return Wf(this,function(o){switch(o.label){case 0:return[4,this.req({url:this.url,data:Qe(Qe({},Hf(e)),{stream:!1}),stream:!1,timeout:t==null?void 0:t.timeout})];case 1:return n=o.sent(),[2,Qe(Qe({},n),{rawResponse:n})]}})})},r.prototype.doStream=function(e,t){return $f(this,void 0,void 0,function(){var n,o,i,s,c;return Wf(this,function(l){switch(l.label){case 0:return n=null,[4,this.req({url:this.url,data:Qe(Qe({},Hf(e)),{stream:!0}),stream:!0,timeout:t==null?void 0:t.timeout})];case 1:return o=l.sent(),i=Et(o),s=Wt(i),c=s.pipeThrough(new De({transform:function(a,u){var f=a.choices.map(function(y){var m=y.delta;return n==null&&(n=Pt(m)),n?Qe(Qe({},y),{finish_reason:"tool_calls",delta:m}):y}),d=Qe(Qe({},a),{choices:f});u.enqueue(Qe(Qe({},d),{rawResponse:a}))}})),[2,Te(c)]}})})},r}(),He=function(){return He=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},He.apply(this,arguments)},Vf=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},zf=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}};function Jf(r){var e=r.messages,t=r.model,n=r.temperature,o=r.tools,i=r.top_p;return He(He({},r),{messages:e,model:t,tools:o,top_p:i,temperature:n})}var Kf=function(){function r(e,t,n){this.req=e,this.baseUrl=t,this.subUrl="dashscope/compatible-mode/v1/chat/completions",n!=null&&(this.subUrl=n)}return Object.defineProperty(r.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),r.prototype.doGenerate=function(e,t){return Vf(this,void 0,void 0,function(){var n;return zf(this,function(o){switch(o.label){case 0:return[4,this.req({url:this.url,data:He(He({},Jf(e)),{stream:!1}),stream:!1,timeout:t==null?void 0:t.timeout})];case 1:return n=o.sent(),[2,He(He({},n),{rawResponse:n})]}})})},r.prototype.doStream=function(e,t){return Vf(this,void 0,void 0,function(){var n,o,i,s,c;return zf(this,function(l){switch(l.label){case 0:return n=null,[4,this.req({url:this.url,data:He(He({},Jf(e)),{stream:!0}),stream:!0,timeout:t==null?void 0:t.timeout})];case 1:return o=l.sent(),i=Et(o),s=Wt(i),c=s.pipeThrough(new De({transform:function(a,u){var f=a.choices.map(function(y){var m=Object.assign(y.delta,{role:"assistant"});return n==null&&(n=Pt(m)),n?He(He({},y),{finish_reason:"tool_calls",delta:m}):He(He({},y),{delta:m})}),d=He(He({},a),{choices:f});u.enqueue(He(He({},d),{rawResponse:a}))}})),[2,Te(c)]}})})},r}(),Ge=function(){return Ge=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Ge.apply(this,arguments)},Yf=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Qf=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}};function Xf(r){var e=r.messages,t=r.model,n=r.temperature,o=r.tools,i=r.top_p;return Ge(Ge({},r),{messages:e,model:t,tools:o,top_p:i,temperature:n})}var Zf=function(){function r(e,t,n){this.req=e,this.baseUrl=t,this.subUrl="01-ai/v1/chat/completions",n!=null&&(this.subUrl=n)}return Object.defineProperty(r.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),r.prototype.doGenerate=function(e,t){return Yf(this,void 0,void 0,function(){var n;return Qf(this,function(o){switch(o.label){case 0:return[4,this.req({url:this.url,data:Ge(Ge({},Xf(e)),{stream:!1}),stream:!1,timeout:t==null?void 0:t.timeout})];case 1:return n=o.sent(),[2,Ge(Ge({},n),{rawResponse:n})]}})})},r.prototype.doStream=function(e,t){return Yf(this,void 0,void 0,function(){var n,o,i,s,c;return Qf(this,function(l){switch(l.label){case 0:return n=null,[4,this.req({url:this.url,data:Ge(Ge({},Xf(e)),{stream:!0}),stream:!0,timeout:t==null?void 0:t.timeout})];case 1:return o=l.sent(),i=Et(o),s=Wt(i),c=s.pipeThrough(new De({transform:function(a,u){var f,d,y,m,v,I;if(!((y=(d=(f=a==null?void 0:a.choices)===null||f===void 0?void 0:f[0])===null||d===void 0?void 0:d.delta)===null||y===void 0)&&y.content||!((I=(v=(m=a==null?void 0:a.choices)===null||m===void 0?void 0:m[0])===null||v===void 0?void 0:v.delta)===null||I===void 0)&&I.tool_calls){var S=a.choices.map(function(O){var T=Object.assign(O.delta,{role:"assistant"});return n==null&&(n=Pt(T)),n?Ge(Ge({},O),{finish_reason:"tool_calls",delta:T}):Ge(Ge({},O),{delta:T})}),w=Ge(Ge({},a),{choices:S});u.enqueue(Ge(Ge({},w),{rawResponse:a}))}}})),[2,Te(c)]}})})},r}(),Xe=function(){return Xe=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Xe.apply(this,arguments)},ed=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},td=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}};function rd(r){var e=r.messages,t=r.model,n=r.temperature,o=r.tools,i=r.top_p;return Xe(Xe({},r),{messages:e,model:t,tools:o,top_p:i,temperature:n})}var nd=function(){function r(e,t,n){this.req=e,this.baseUrl=t,this.subUrl="moonshot/v1/chat/completions",n!=null&&(this.subUrl=n)}return Object.defineProperty(r.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),r.prototype.doGenerate=function(e,t){return ed(this,void 0,void 0,function(){var n;return td(this,function(o){switch(o.label){case 0:return[4,this.req({url:this.url,data:Xe(Xe({},rd(e)),{stream:!1}),stream:!1,timeout:t==null?void 0:t.timeout})];case 1:return n=o.sent(),[2,Xe(Xe({},n),{rawResponse:n})]}})})},r.prototype.doStream=function(e,t){return ed(this,void 0,void 0,function(){var n,o,i,s,c;return td(this,function(l){switch(l.label){case 0:return n=null,[4,this.req({url:this.url,data:Xe(Xe({},rd(e)),{stream:!0}),stream:!0,timeout:t==null?void 0:t.timeout})];case 1:return o=l.sent(),i=Et(o),s=Wt(i),c=s.pipeThrough(new De({transform:function(a,u){var f=a.choices.map(function(y){var m=y.delta;return n==null&&(n=Pt(m)),n?Xe(Xe({},y),{finish_reason:"tool_calls",delta:m}):y}),d=Xe(Xe({},a),{choices:f});u.enqueue(Xe(Xe({},d),{rawResponse:a}))}})),[2,Te(c)]}})})},r}(),ht=function(){return ht=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},ht.apply(this,arguments)},id=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},od=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},ad=function(){function r(e,t,n){this.req=e,this.baseUrl=t,this.subUrl="hunyuan-exp/chat/completions",n!=null&&(this.subUrl=n)}return Object.defineProperty(r.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),r.prototype.doGenerate=function(e){return id(this,void 0,void 0,function(){var t;return od(this,function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:ht(ht({},dn(e)),{stream:!1}),stream:!1})];case 1:return t=n.sent(),[2,ht(ht({},t),{rawResponse:t})]}})})},r.prototype.doStream=function(e){return id(this,void 0,void 0,function(){var t,n,o,i,s;return od(this,function(c){switch(c.label){case 0:return t=null,[4,this.req({url:this.url,data:ht(ht({},dn(e)),{stream:!0}),stream:!0})];case 1:return n=c.sent(),o=Et(n),i=Wt(o),s=i.pipeThrough(new De({transform:function(l,a){var u=l.choices.map(function(d){var y=d.delta;return t==null&&(t=Pt(y)),t?ht(ht({},d),{finish_reason:"tool_calls",delta:y}):d}),f=ht(ht({},l),{choices:u});a.enqueue(ht(ht({},f),{rawResponse:l}))}})),[2,Te(s)]}})})},r}(),pt=function(){return pt=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},pt.apply(this,arguments)},sd=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},ud=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},cd=function(){function r(e,t,n){this.req=e,this.baseUrl=t,this.subUrl="hunyuan-open/v1/chat/completions",n!=null&&(this.subUrl=n)}return Object.defineProperty(r.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),r.prototype.doGenerate=function(e,t){return sd(this,void 0,void 0,function(){var n;return ud(this,function(o){switch(o.label){case 0:return[4,this.req({url:this.url,data:pt(pt({},dn(e)),{stream:!1}),stream:!1,timeout:t==null?void 0:t.timeout})];case 1:return n=o.sent(),[2,pt(pt({},n),{rawResponse:n})]}})})},r.prototype.doStream=function(e,t){return sd(this,void 0,void 0,function(){var n,o,i,s,c;return ud(this,function(l){switch(l.label){case 0:return n=null,[4,this.req({url:this.url,data:pt(pt({},dn(e)),{stream:!0}),stream:!0,timeout:t==null?void 0:t.timeout})];case 1:return o=l.sent(),i=Et(o),s=Wt(i),c=s.pipeThrough(new De({transform:function(a,u){var f=a.choices.map(function(y){var m=y.delta;return n==null&&(n=Pt(m)),n?pt(pt({},y),{finish_reason:"tool_calls",delta:m}):y}),d=pt(pt({},a),{choices:f});u.enqueue(pt(pt({},d),{rawResponse:a}))}})),[2,Te(c)]}})})},r}(),yt=function(){return yt=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},yt.apply(this,arguments)},ld=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},fd=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},U0=function(){function r(e,t,n){this.req=e,this.baseUrl=t,this.subUrl="deepseek/chat/completions",n!=null&&(this.subUrl=n)}return Object.defineProperty(r.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),r.prototype.doGenerate=function(e,t){return ld(this,void 0,void 0,function(){var n;return fd(this,function(o){switch(o.label){case 0:return[4,this.req({url:this.url,data:yt(yt({},e),{stream:!1}),stream:!1,timeout:t==null?void 0:t.timeout})];case 1:return n=o.sent(),[2,yt(yt({},n),{rawResponse:n})]}})})},r.prototype.doStream=function(e,t){return ld(this,void 0,void 0,function(){var n,o,i,s,c;return fd(this,function(l){switch(l.label){case 0:return n=null,[4,this.req({url:this.url,data:yt(yt({},e),{stream:!0}),stream:!0,timeout:t==null?void 0:t.timeout})];case 1:return o=l.sent(),i=Et(o),s=Wt(i),c=s.pipeThrough(new De({transform:function(a,u){var f=a.choices.map(function(y){var m=y.delta;return n==null&&(n=Pt(m)),n?yt(yt({},y),{finish_reason:"tool_calls",delta:m}):y}),d=yt(yt({},a),{choices:f});u.enqueue(yt(yt({},d),{rawResponse:a}))}})),[2,Te(c)]}})})},r}(),mt=function(){return mt=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},mt.apply(this,arguments)},dd=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},hd=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},pd=function(){function r(e,t,n){n===void 0&&(n=""),this.req=e,this.baseUrl=t,this.subUrl=n}return Object.defineProperty(r.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),r.prototype.doGenerate=function(e){return dd(this,void 0,void 0,function(){var t;return hd(this,function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:mt(mt({},e),{stream:!1}),stream:!1})];case 1:return t=n.sent(),[2,mt(mt({},t),{rawResponse:t})]}})})},r.prototype.doStream=function(e){return dd(this,void 0,void 0,function(){var t,n,o,i,s;return hd(this,function(c){switch(c.label){case 0:return t=null,[4,this.req({url:this.url,data:mt(mt({},e),{stream:!0}),stream:!0})];case 1:return n=c.sent(),o=Et(n),i=Wt(o),s=i.pipeThrough(new De({transform:function(l,a){var u=l.choices.map(function(d){var y=d.delta;return t==null&&(t=Pt(y)),t?mt(mt({},d),{finish_reason:"tool_calls",delta:y}):d}),f=mt(mt({},l),{choices:u});a.enqueue(mt(mt({},f),{rawResponse:l}))}})),[2,Te(s)]}})})},r}(),Yo=function(){return Yo=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Yo.apply(this,arguments)},ks=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},$s=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},B0=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(r);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(r,n[o])&&(t[n[o]]=r[n[o]]);return t},L0=function(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof __values=="function"?__values(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(i){t[i]=r[i]&&function(s){return new Promise(function(c,l){s=r[i](s),o(c,l,s.done,s.value)})}}function o(i,s,c,l){Promise.resolve(l).then(function(a){i({value:a,done:c})},s)}},Zt=function(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return r.concat(i||Array.prototype.slice.call(e))};function yd(r){var e,t=r.onStepFinish,n=r.abortSignal,o=r.maxSteps,i=r.topP,s=r.toolChoice,c=B0(r,["onStepFinish","abortSignal","maxSteps","topP","toolChoice"]);if(o!=null&&o<1)throw new Error("`maxSteps` muse be greater than 0.");return[{onStepFinish:t,abortSignal:n,maxSteps:o},Yo(Yo({},c),{tools:(e=c.tools)===null||e===void 0?void 0:e.map(function(l){return"fn"in l?D0(l):l}),top_p:i??c.top_p,tool_choice:s??c.tool_choice})]}var md=function(){function r(e){this.model=e}return r.prototype.generateText=function(e,t){var n,o;return ks(this,void 0,void 0,function(){var i,s,c,l,a,u,f,d,y,m,v,I,S,w,O,T,N,D,B,R,x,L=this;return $s(this,function(F){switch(F.label){case 0:return i=[],s={completion_tokens:0,prompt_tokens:0,total_tokens:0},c=yd(e),l=c[0],a=l.onStepFinish,u=l.maxSteps,f=u===void 0?10:u,d=c[1],y=function(){return L.model.doGenerate(d,t)},[4,y()];case 1:m=F.sent(),v=1,m.rawResponse&&i.push(m.rawResponse),I=null,F.label=2;case 2:if(!(v<f&&(I=gd(m))!=null))return[3,9];S=bd(m.usage),Ui(s,S),F.label=3;case 3:return F.trys.push([3,7,,8]),[4,_d(I)];case 4:return w=F.sent(),O=m.choices[0],[4,a==null?void 0:a({finishReason:O.finish_reason,messages:d.messages.slice(),text:O.message.content,toolCall:I,toolResult:w,stepUsage:S,totalUsage:Object.assign({},s)})];case 5:return F.sent(),vd(d.messages,O.message,w),[4,y()];case 6:return m=F.sent(),m.rawResponse&&i.push(m.rawResponse),v+=1,[3,8];case 7:return T=F.sent(),[2,{text:"",messages:d.messages,usage:s,error:T,rawResponses:i}];case 8:return[3,2];case 9:return N=(n=m==null?void 0:m.choices)===null||n===void 0?void 0:n[0],D=N==null?void 0:N.message,B=(o=D==null?void 0:D.content)!==null&&o!==void 0?o:"",R=D?Zt(Zt([],d.messages,!0),[D],!1):d.messages,x=bd(m.usage),Ui(s,x),[4,a==null?void 0:a({finishReason:N.finish_reason,messages:R.slice(),text:B,toolCall:gd(m),toolResult:null,stepUsage:x,totalUsage:Object.assign({},s)})];case 10:return F.sent(),[2,{text:B,messages:R,usage:s,rawResponses:i}]}})})},r.prototype.streamText=function(e,t){var n;return ks(this,void 0,void 0,function(){var o,i,s,c,l,a,u,f,d,y,m,v,I,S,w,O,T,N,D,B,R,x,L,F,j,V,W,oe,se,Z,ee,Y,G,Se,Fe,qe,Ze=this;return $s(this,function(Ne){switch(Ne.label){case 0:return o={completion_tokens:0,prompt_tokens:0,total_tokens:0},i=yd(e),s=i[0],c=s.onStepFinish,l=s.maxSteps,a=l===void 0?10:l,u=i[1],f=function(){return Ze.model.doStream(u,t)},[4,f()];case 1:d=Ne.sent(),y=1,m=null,v=function(){var ue=d.tee(),je=ue[0],me=ue[1];return d=Te(je),M0(me)},Ne.label=2;case 2:return I=y<a,I?[4,v()]:[3,4];case 3:I=(m=Ne.sent())!=null,Ne.label=4;case 4:if(!I)return[3,11];S=m.message,w=m.usage,Ui(o,w),O=(n=S.tool_calls)===null||n===void 0?void 0:n[0],Ne.label=5;case 5:return Ne.trys.push([5,9,,10]),[4,_d(O)];case 6:return T=Ne.sent(),[4,c==null?void 0:c({finishReason:"tool_calls",messages:u.messages.slice(),text:S.content,toolCall:O,toolResult:T,stepUsage:w,totalUsage:Object.assign({},o)})];case 7:return Ne.sent(),vd(u.messages,S,T),[4,f()];case 8:return d=Ne.sent(),[3,10];case 9:return N=Ne.sent(),D=d.tee(),B=D[0],R=D[1],[2,{messages:Promise.resolve(u.messages),dataStream:Te(B),textStream:Te(R.pipeThrough(new De({transform:function(ue,je){var me,Re,ge,Ae=(ge=(Re=(me=ue==null?void 0:ue.choices)===null||me===void 0?void 0:me[0])===null||Re===void 0?void 0:Re.delta)===null||ge===void 0?void 0:ge.content;typeof Ae=="string"&&je.enqueue(Ae)}}))),usage:Promise.resolve(o),error:N}];case 10:return[3,2];case 11:return[4,v()];case 12:return m=Ne.sent(),m?(x=m.message,L=m.usage,Ui(o,L),F=Zt(Zt([],u.messages,!0),[x],!1),c({messages:F.slice(),finishReason:"tool_call",stepUsage:L,text:x.content,toolCall:x.tool_calls[0],totalUsage:Object.assign({},o)}),j=d.tee(),V=j[0],W=j[1],[2,{messages:Promise.resolve(Zt(Zt([],u.messages,!0),[x],!1)),dataStream:Te(V),textStream:Te(W.pipeThrough(new De({transform:function(ue,je){var me,Re,ge,Ae=(ge=(Re=(me=ue==null?void 0:ue.choices)===null||me===void 0?void 0:me[0])===null||Re===void 0?void 0:Re.delta)===null||ge===void 0?void 0:ge.content;typeof Ae=="string"&&je.enqueue(Ae)}}))),usage:Promise.resolve(o)}]):(oe=xf(),se=xf(),Z={role:"assistant",content:""},ee="",Y={completion_tokens:0,prompt_tokens:0,total_tokens:0},G=d.pipeThrough(new De({transform:function(ue,je){var me,Re,ge,Ae,Ue,Tt,ot,_,h=(ge=(Re=(me=ue==null?void 0:ue.choices)===null||me===void 0?void 0:me[0])===null||Re===void 0?void 0:Re.delta)===null||ge===void 0?void 0:ge.content;typeof h=="string"&&(Z.content+=h);var p=(Ue=(Ae=ue==null?void 0:ue.choices)===null||Ae===void 0?void 0:Ae[0])===null||Ue===void 0?void 0:Ue.finish_reason;p&&(ee=p),!((Tt=ue==null?void 0:ue.usage)===null||Tt===void 0)&&Tt.completion_tokens&&(Y.completion_tokens=ue.usage.completion_tokens),!((ot=ue==null?void 0:ue.usage)===null||ot===void 0)&&ot.prompt_tokens&&(Y.prompt_tokens=ue.usage.prompt_tokens),!((_=ue==null?void 0:ue.usage)===null||_===void 0)&&_.total_tokens&&(Y.total_tokens=ue.usage.total_tokens),je.enqueue(ue)},flush:function(){oe.res(Zt(Zt([],u.messages,!0),[Z],!1)),Ui(o,Y),se.res(Object.assign({},o)),c==null||c({messages:Zt(Zt([],u.messages,!0),[Z],!1),finishReason:ee,text:Z.content,stepUsage:Y,totalUsage:Object.assign({},o)})}})),Se=G.tee(),Fe=Se[0],qe=Se[1],[2,{messages:oe.promise,dataStream:Te(Fe),textStream:Te(qe.pipeThrough(new De({transform:function(ue,je){var me,Re,ge,Ae=(ge=(Re=(me=ue==null?void 0:ue.choices)===null||me===void 0?void 0:me[0])===null||Re===void 0?void 0:Re.delta)===null||ge===void 0?void 0:ge.content;typeof Ae=="string"&&je.enqueue(Ae)}}))),usage:se.promise}])}})})},r}();function gd(r){var e,t=(e=r==null?void 0:r.choices)===null||e===void 0?void 0:e[0];if(!t)return null;var n=t.finish_reason,o=t.message;return n!=="tool_calls"||!o||!Pt(o)?null:o.tool_calls[0]}function vd(r,e,t){r.push(e,{role:"tool",tool_call_id:e.tool_calls[0].id,content:JSON.stringify(t)})}function M0(r){var e,t,n,o,i,s,c,l,a,u;return ks(this,void 0,void 0,function(){var f,d,y,m,v,I,S,w,O,T,N,D,B;return $s(this,function(R){switch(R.label){case 0:f={completion_tokens:0,prompt_tokens:0,total_tokens:0},d=Te(r),y={id:"",function:{name:"",arguments:""},type:""},m={role:"assistant",content:"",tool_calls:[y]},R.label=1;case 1:R.trys.push([1,6,7,12]),v=!0,I=L0(d),R.label=2;case 2:return[4,I.next()];case 3:if(S=R.sent(),e=S.done,!!e)return[3,5];o=S.value,v=!1;try{if(w=o,O=w==null?void 0:w.choices[0],!O)return[2,null];if(T=O.finish_reason,N=O.delta,T!=="tool_calls")return[2,null];if(!N)return[3,4];if(N.content&&(m.content+=N.content),!("tool_calls"in N))return[3,4];D=(i=N==null?void 0:N.tool_calls)===null||i===void 0?void 0:i[0],D!=null&&D.id&&(y.id=D.id),D!=null&&D.type&&(y.type=D.type),!((s=D==null?void 0:D.function)===null||s===void 0)&&s.name&&(y.function.name=D.function.name),!((c=D==null?void 0:D.function)===null||c===void 0)&&c.arguments&&(y.function.arguments+=D.function.arguments),!((l=w==null?void 0:w.usage)===null||l===void 0)&&l.completion_tokens&&(f.completion_tokens=w.usage.completion_tokens),!((a=w==null?void 0:w.usage)===null||a===void 0)&&a.prompt_tokens&&(f.prompt_tokens=w.usage.prompt_tokens),!((u=w==null?void 0:w.usage)===null||u===void 0)&&u.total_tokens&&(f.total_tokens=w.usage.total_tokens)}finally{v=!0}R.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return B=R.sent(),t={error:B},[3,12];case 7:return R.trys.push([7,,10,11]),!v&&!e&&(n=I.return)?[4,n.call(I)]:[3,9];case 8:R.sent(),R.label=9;case 9:return[3,11];case 10:if(t)throw t.error;return[7];case 11:return[7];case 12:return[2,{message:m,usage:f}]}})})}var Qo=new Map;function _d(r){return Qo.get(r.function.name)(JSON.parse(r.function.arguments))}function bd(r){var e,t,n;return{completion_tokens:(e=r==null?void 0:r.completion_tokens)!==null&&e!==void 0?e:0,prompt_tokens:(t=r==null?void 0:r.prompt_tokens)!==null&&t!==void 0?t:0,total_tokens:(n=r==null?void 0:r.total_tokens)!==null&&n!==void 0?n:0}}function Ui(r,e){r.completion_tokens+=e.completion_tokens,r.prompt_tokens+=e.prompt_tokens,r.total_tokens+=e.total_tokens}var wd={hunyuan:kf,"hunyuan-beta":Mf,ark:Gf,dashscope:Kf,"01-ai":Zf,moonshot:nd,zhipu:Uf,"hunyuan-exp":ad,"hunyuan-open":cd,deepseek:U0};const q0=Object.freeze(Object.defineProperty({__proto__:null,ArkSimpleModel:Gf,DSSimpleModel:Kf,DefaultSimpleModel:pd,HunYuanBetaSimpleModel:Mf,HunYuanExpSimpleModel:ad,HunYuanOpenSimpleModel:cd,HunYuanSimpleModel:kf,MODELS:wd,MoonshotSimpleModel:nd,ReactModel:md,YiSimpleModel:Zf,ZhiPuSimpleModel:Uf,toolMap:Qo},Symbol.toStringTag,{value:"Module"}));var Vn=function(){return Vn=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Vn.apply(this,arguments)},Ws=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Hs=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Gs=wd,j0=function(){function r(e,t){var n=this;this.req=e,this.baseUrl=t,this.modelRequest=function(o){var i=o.url,s=o.data,c=o.headers,l=o.stream,a=o.timeout;return Ws(n,void 0,void 0,function(){var u,f,d,y;return Hs(this,function(m){switch(m.label){case 0:return u={"Content-Type":"application/json"},l&&Object.assign(u,{Accept:"text/event-stream"}),[4,this.req.fetch({method:"post",headers:Vn(Vn({},u),c),body:JSON.stringify(s),url:i,stream:l,timeout:a})];case 1:return f=m.sent(),d=f.data,y=f.header,[2,Vs(d,y)]}})})},this.botRequest=function(o){var i=o.method,s=o.url,c=o.data,l=c===void 0?{}:c,a=o.headers,u=o.stream,f=o.timeout;return Ws(n,void 0,void 0,function(){function d(w){return Object.entries(w).map(function(O){var T=O[0],N=O[1];return"".concat(T,"=").concat(N)}).join("&")}var y,m,v,I,S;return Hs(this,function(w){switch(w.label){case 0:return i!=="get"?[3,2]:(y=Vs,[4,this.req.fetch({url:"".concat(s,"?").concat(d(l)),method:i,headers:a,stream:u,timeout:f})]);case 1:return[2,y.apply(void 0,[w.sent().data])];case 2:return m={"Content-Type":"application/json"},u&&Object.assign(m,{Accept:"text/event-stream"}),[4,this.req.fetch({url:s,body:JSON.stringify(l),headers:Vn(Vn({},m),a),stream:u,method:i,timeout:f})];case 3:return v=w.sent(),I=v.data,S=v.header,[2,Vs(I,S)]}})})},this.aiBaseUrl="".concat(t,"/ai"),this.aiBotBaseUrl="".concat(t,"/aibot"),this.bot=new F0(this.botRequest,this.aiBotBaseUrl)}return r.prototype.createModel=function(e,t){var n,o=Gs[e];if(o)n=new o(this.modelRequest,this.aiBaseUrl);else{var i=typeof(t==null?void 0:t.defaultModelSubUrl)=="string"?t.defaultModelSubUrl:"/chat/completions";n=new pd(this.modelRequest,this.aiBaseUrl,"".concat(e).concat(i))}var s=new md(n);return s},r.prototype.registerModel=function(e,t){if(Gs[e]!=null){console.warn("AI model ".concat(e," already exists!"));return}Gs[e]=t},r.prototype.registerFunctionTool=function(e){Qo.has(e.name)&&console.warn("AI function tool ".concat(e.name," already exists and will be overwritten!")),Qo.set(e.name,e.fn)},r}(),Ed="请检查调用方式,或前往云开发 AI+ 首页查看文档:https://tcb.cloud.tencent.com/dev#/ai";function Vs(r,e){var t,n;return Ws(this,void 0,void 0,function(){var o,o;return Hs(this,function(i){switch(i.label){case 0:return typeof r=="object"&&r&&"then"in r?[4,r]:[3,2];case 1:if(o=i.sent(),typeof o=="object"&&o&&"code"in o&&o.code!=="NORMAL")throw new Error("AI+ 请求出错,错误码:".concat(o.code,",错误信息:").concat(o.message,`
37
+ `).concat(Ed,`
38
+ `).concat(JSON.stringify(o,null,2)));return[2,r];case 2:return!((n=(t=e==null?void 0:e.get)===null||t===void 0?void 0:t.call(e,"content-type"))===null||n===void 0)&&n.includes("application/json")?[4,P0(r)]:[3,4];case 3:if(o=i.sent(),typeof o=="object"&&o&&"code"in o&&o.code!=="NORMAL")throw new Error("AI+ 请求出错,错误码:".concat(o.code,",错误信息:").concat(o.message,`
39
+ `).concat(Ed,`
40
+ `).concat(JSON.stringify(o,null,2)));i.label=4;case 4:return[2,r]}})})}var Xo=function(){return Xo=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Xo.apply(this,arguments)},k0=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},$0=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(t=0)),t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},Sd=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(r);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(r,n[o])&&(t[n[o]]=r[n[o]]);return t},W0="ai";Sd(q0,["MODELS"]);var H0=function(r){var e=r.getAccessToken,t=r.req,n=function(o){return k0(void 0,void 0,void 0,function(){var i,s,c,l,a;return $0(this,function(u){switch(u.label){case 0:if(typeof t.fetch!="function")throw new Error("req.fetch is not a function");return i=o.token,s=o.headers,c=s===void 0?{}:s,l=Sd(o,["token","headers"]),i==null?[3,1]:(a=i,[3,3]);case 1:return[4,e()];case 2:a=u.sent().accessToken,u.label=3;case 3:return[2,t.fetch(Xo({headers:Xo({Authorization:"Bearer ".concat(a)},c)},l))]}})})};return{download:t.download,post:t.post,upload:t.upload,fetch:n}};function G0(r){var e=r.env,t=r.baseUrl,n=r.req,o=r.getAccessToken,i=r.handleReqInstance,s=function(){if(t!=null)return t;if(e==null)throw new Error("`env` is required when `baseUrl` is not provided!");return"https://".concat(e,".api.tcloudbasegateway.com/v1")},c=function(){if(i==null){if(o==null)throw new Error("`getAccessToken` is required when `handleReqInstance` is not provided!");return H0({req:n,getAccessToken:o})}return i({req:n})};return new j0(c(),s())}function V0(r){var e=this,t,n=this.request;if(n.fetch==null)throw new Error("cloudbase.request.fetch() unimplemented!");var o=function(){var s=e.getEndPointWithKey("GATEWAY"),c=s.BASE_URL,l=s.PROTOCOL;return"".concat(l).concat(c)},i=(t=r==null?void 0:r.baseUrl)!==null&&t!==void 0?t:o();return G0({req:n,baseUrl:i,handleReqInstance:function(s){var c=s.req;return c}})}var z0={name:W0,entity:{ai:V0}};function J0(r){try{r.registerComponent(z0)}catch(e){console.warn(e)}}var hn,_r;(function(r){r.DocIDError="文档ID不合法",r.CollNameError="集合名称不合法",r.OpStrError="操作符不合法",r.DirectionError="排序字符不合法",r.IntergerError="must be integer",r.QueryParamTypeError="查询参数必须为对象",r.QueryParamValueError="查询参数对象值不能均为undefined"})(_r||(_r={}));var Ie={Number:"Number",Object:"Object",Array:"Array",GeoPoint:"GeoPoint",GeoLineString:"GeoLineString",GeoPolygon:"GeoPolygon",GeoMultiPoint:"GeoMultiPoint",GeoMultiLineString:"GeoMultiLineString",GeoMultiPolygon:"GeoMultiPolygon",Timestamp:"Date",ServerDate:"ServerDate",BsonDate:"BsonDate"},K0=["desc","asc"],Y0=["<","<=","==",">=",">"],pn;(function(r){r.lt="<",r.gt=">",r.lte="<=",r.gte=">=",r.eq="=="})(pn||(pn={})),hn={},hn[pn.eq]="$eq",hn[pn.lt]="$lt",hn[pn.lte]="$lte",hn[pn.gt]="$gt",hn[pn.gte]="$gte";var er;(function(r){r.WHERE="WHERE",r.DOC="DOC"})(er||(er={}));var Q0=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)o.hasOwnProperty(i)&&(n[i]=o[i])},r(e,t)};return function(e,t){r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),Zo=[],Id={},X0=function(){function r(e){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:e}})}return r}(),St=function(r){Q0(e,r);function e(t,n){var o=this;if(n!==Id)throw new TypeError("InternalSymbol cannot be constructed with new operator");return o=r.call(this,t)||this,o}return e.for=function(t){for(var n=0,o=Zo.length;n<o;n++)if(Zo[n].target===t)return Zo[n].instance;var i=new e(t,Id);return Zo.push({target:t,instance:i}),i},e}(X0),Bi=St.for("UNSET_FIELD_NAME"),Od=St.for("UPDATE_COMMAND"),Td=St.for("QUERY_COMMAND"),Ad=St.for("LOGIC_COMMAND"),Rd=St.for("GEO_POINT"),Z0=St.for("SYMBOL_GEO_LINE_STRING"),eg=St.for("SYMBOL_GEO_POLYGON"),tg=St.for("SYMBOL_GEO_MULTI_POINT"),rg=St.for("SYMBOL_GEO_MULTI_LINE_STRING"),ng=St.for("SYMBOL_GEO_MULTI_POLYGON"),Cd=St.for("SERVER_DATE"),xd=St.for("REGEXP"),Nd=function(){function r(e){var t=(e===void 0?{}:e).offset,n=t===void 0?0:t;this.offset=n}return Object.defineProperty(r.prototype,"_internalType",{get:function(){return Cd},enumerable:!0,configurable:!0}),r.prototype.parse=function(){return{$date:{offset:this.offset}}},r}();function ig(r){return new Nd(r)}var zs=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(c){s={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(s)throw s.error}}return i},ea=function(){function r(){}return r.formatResDocumentData=function(e){return e.map(function(t){return r.formatField(t)})},r.formatField=function(e){var t=Object.keys(e),n={};return Array.isArray(e)&&(n=[]),t.forEach(function(o){var i=e[o],s=r.whichType(i),c;switch(s){case Ie.GeoPoint:c=new gt(i.coordinates[0],i.coordinates[1]);break;case Ie.GeoLineString:c=new rr(i.coordinates.map(function(l){return new gt(l[0],l[1])}));break;case Ie.GeoPolygon:c=new yn(i.coordinates.map(function(l){return new rr(l.map(function(a){var u=zs(a,2),f=u[0],d=u[1];return new gt(f,d)}))}));break;case Ie.GeoMultiPoint:c=new ta(i.coordinates.map(function(l){return new gt(l[0],l[1])}));break;case Ie.GeoMultiLineString:c=new ra(i.coordinates.map(function(l){return new rr(l.map(function(a){var u=zs(a,2),f=u[0],d=u[1];return new gt(f,d)}))}));break;case Ie.GeoMultiPolygon:c=new Li(i.coordinates.map(function(l){return new yn(l.map(function(a){return new rr(a.map(function(u){var f=zs(u,2),d=f[0],y=f[1];return new gt(d,y)}))}))}));break;case Ie.Timestamp:c=new Date(i.$timestamp*1e3);break;case Ie.Object:case Ie.Array:c=r.formatField(i);break;case Ie.ServerDate:c=new Date(i.$date);break;default:c=i}Array.isArray(n)?n.push(c):n[o]=c}),n},r.whichType=function(e){var t=Object.prototype.toString.call(e).slice(8,-1);if(t===Ie.Timestamp)return Ie.BsonDate;if(t===Ie.Object){if(e instanceof gt)return Ie.GeoPoint;if(e instanceof Date)return Ie.Timestamp;if(e instanceof Nd)return Ie.ServerDate;e.$timestamp?t=Ie.Timestamp:e.$date?t=Ie.ServerDate:gt.validate(e)?t=Ie.GeoPoint:rr.validate(e)?t=Ie.GeoLineString:yn.validate(e)?t=Ie.GeoPolygon:ta.validate(e)?t=Ie.GeoMultiPoint:ra.validate(e)?t=Ie.GeoMultiLineString:Li.validate(e)&&(t=Ie.GeoMultiPolygon)}return t},r.generateDocId=function(){for(var e="ABCDEFabcdef0123456789",t="",n=0;n<24;n++)t+=e.charAt(Math.floor(Math.random()*e.length));return t},r}(),qr=function(){function r(){}return r.isGeopoint=function(e,t){if(ea.whichType(t)!==Ie.Number)throw new Error("Geo Point must be number type");var n=Math.abs(t);if(e==="latitude"&&n>90)throw new Error("latitude should be a number ranges from -90 to 90");if(e==="longitude"&&n>180)throw new Error("longitude should be a number ranges from -180 to 180");return!0},r.isInteger=function(e,t){if(!Number.isInteger(t))throw new Error(e+_r.IntergerError);return!0},r.isFieldOrder=function(e){if(K0.indexOf(e)===-1)throw new Error(_r.DirectionError);return!0},r.isFieldPath=function(e){if(!/^[a-zA-Z0-9-_\.]/.test(e))throw new Error;return!0},r.isOperator=function(e){if(Y0.indexOf(e)===-1)throw new Error(_r.OpStrError);return!0},r.isCollName=function(e){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(e))throw new Error(_r.CollNameError);return!0},r.isDocID=function(e){if(!/^([a-fA-F0-9]){24}$/.test(e))throw new Error(_r.DocIDError);return!0},r}(),tr=function(r){return Object.prototype.toString.call(r).slice(8,-1).toLowerCase()},jr=function(r){return tr(r)==="object"},og=function(r){return tr(r)==="string"},Dt=function(r){return tr(r)==="number"},xe=function(r){return Array.isArray(r)},Pd=function(r){return tr(r)==="date"},Js=function(r){return tr(r)==="regexp"},Dd=function(r){return r&&r._internalType instanceof St},gt=function(){function r(e,t){qr.isGeopoint("longitude",e),qr.isGeopoint("latitude",t),this.longitude=e,this.latitude=t}return r.prototype.parse=function(e){var t;return t={},t[e]={type:"Point",coordinates:[this.longitude,this.latitude]},t},r.prototype.toJSON=function(){return{type:"Point",coordinates:[this.longitude,this.latitude]}},r.prototype.toReadableString=function(){return"["+this.longitude+","+this.latitude+"]"},r.validate=function(e){return e.type==="Point"&&xe(e.coordinates)&&qr.isGeopoint("longitude",e.coordinates[0])&&qr.isGeopoint("latitude",e.coordinates[1])},Object.defineProperty(r.prototype,"_internalType",{get:function(){return Rd},enumerable:!0,configurable:!0}),r}(),ag=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},rr=function(){function r(e){if(!xe(e))throw new TypeError('"points" must be of type Point[]. Received type '+typeof e);if(e.length<2)throw new Error('"points" must contain 2 points at least');e.forEach(function(t){if(!(t instanceof gt))throw new TypeError('"points" must be of type Point[]. Received type '+typeof t+"[]")}),this.points=e}return r.prototype.parse=function(e){var t;return t={},t[e]={type:"LineString",coordinates:this.points.map(function(n){return n.toJSON().coordinates})},t},r.prototype.toJSON=function(){return{type:"LineString",coordinates:this.points.map(function(e){return e.toJSON().coordinates})}},r.validate=function(e){var t,n;if(e.type!=="LineString"||!xe(e.coordinates))return!1;try{for(var o=ag(e.coordinates),i=o.next();!i.done;i=o.next()){var s=i.value;if(!Dt(s[0])||!Dt(s[1]))return!1}}catch(c){t={error:c}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}return!0},r.isClosed=function(e){var t=e.points[0],n=e.points[e.points.length-1];if(t.latitude===n.latitude&&t.longitude===n.longitude)return!0},Object.defineProperty(r.prototype,"_internalType",{get:function(){return Z0},enumerable:!0,configurable:!0}),r}(),Fd=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},yn=function(){function r(e){if(!xe(e))throw new TypeError('"lines" must be of type LineString[]. Received type '+typeof e);if(e.length===0)throw new Error("Polygon must contain 1 linestring at least");e.forEach(function(t){if(!(t instanceof rr))throw new TypeError('"lines" must be of type LineString[]. Received type '+typeof t+"[]");if(!rr.isClosed(t))throw new Error("LineString "+t.points.map(function(n){return n.toReadableString()})+" is not a closed cycle")}),this.lines=e}return r.prototype.parse=function(e){var t;return t={},t[e]={type:"Polygon",coordinates:this.lines.map(function(n){return n.points.map(function(o){return[o.longitude,o.latitude]})})},t},r.prototype.toJSON=function(){return{type:"Polygon",coordinates:this.lines.map(function(e){return e.points.map(function(t){return[t.longitude,t.latitude]})})}},r.validate=function(e){var t,n,o,i;if(e.type!=="Polygon"||!xe(e.coordinates))return!1;try{for(var s=Fd(e.coordinates),c=s.next();!c.done;c=s.next()){var l=c.value;if(!this.isCloseLineString(l))return!1;try{for(var a=(o=void 0,Fd(l)),u=a.next();!u.done;u=a.next()){var f=u.value;if(!Dt(f[0])||!Dt(f[1]))return!1}}catch(d){o={error:d}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}}}catch(d){t={error:d}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}return!0},r.isCloseLineString=function(e){var t=e[0],n=e[e.length-1];return!(t[0]!==n[0]||t[1]!==n[1])},Object.defineProperty(r.prototype,"_internalType",{get:function(){return ng},enumerable:!0,configurable:!0}),r}(),sg=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},ta=function(){function r(e){if(!xe(e))throw new TypeError('"points" must be of type Point[]. Received type '+typeof e);if(e.length===0)throw new Error('"points" must contain 1 point at least');e.forEach(function(t){if(!(t instanceof gt))throw new TypeError('"points" must be of type Point[]. Received type '+typeof t+"[]")}),this.points=e}return r.prototype.parse=function(e){var t;return t={},t[e]={type:"MultiPoint",coordinates:this.points.map(function(n){return n.toJSON().coordinates})},t},r.prototype.toJSON=function(){return{type:"MultiPoint",coordinates:this.points.map(function(e){return e.toJSON().coordinates})}},r.validate=function(e){var t,n;if(e.type!=="MultiPoint"||!xe(e.coordinates))return!1;try{for(var o=sg(e.coordinates),i=o.next();!i.done;i=o.next()){var s=i.value;if(!Dt(s[0])||!Dt(s[1]))return!1}}catch(c){t={error:c}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}return!0},Object.defineProperty(r.prototype,"_internalType",{get:function(){return tg},enumerable:!0,configurable:!0}),r}(),Ud=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},ra=function(){function r(e){if(!xe(e))throw new TypeError('"lines" must be of type LineString[]. Received type '+typeof e);if(e.length===0)throw new Error("Polygon must contain 1 linestring at least");e.forEach(function(t){if(!(t instanceof rr))throw new TypeError('"lines" must be of type LineString[]. Received type '+typeof t+"[]")}),this.lines=e}return r.prototype.parse=function(e){var t;return t={},t[e]={type:"MultiLineString",coordinates:this.lines.map(function(n){return n.points.map(function(o){return[o.longitude,o.latitude]})})},t},r.prototype.toJSON=function(){return{type:"MultiLineString",coordinates:this.lines.map(function(e){return e.points.map(function(t){return[t.longitude,t.latitude]})})}},r.validate=function(e){var t,n,o,i;if(e.type!=="MultiLineString"||!xe(e.coordinates))return!1;try{for(var s=Ud(e.coordinates),c=s.next();!c.done;c=s.next()){var l=c.value;try{for(var a=(o=void 0,Ud(l)),u=a.next();!u.done;u=a.next()){var f=u.value;if(!Dt(f[0])||!Dt(f[1]))return!1}}catch(d){o={error:d}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}}}catch(d){t={error:d}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}return!0},Object.defineProperty(r.prototype,"_internalType",{get:function(){return rg},enumerable:!0,configurable:!0}),r}(),na=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Li=function(){function r(e){var t,n;if(!xe(e))throw new TypeError('"polygons" must be of type Polygon[]. Received type '+typeof e);if(e.length===0)throw new Error("MultiPolygon must contain 1 polygon at least");try{for(var o=na(e),i=o.next();!i.done;i=o.next()){var s=i.value;if(!(s instanceof yn))throw new TypeError('"polygon" must be of type Polygon[]. Received type '+typeof s+"[]")}}catch(c){t={error:c}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}this.polygons=e}return r.prototype.parse=function(e){var t;return t={},t[e]={type:"MultiPolygon",coordinates:this.polygons.map(function(n){return n.lines.map(function(o){return o.points.map(function(i){return[i.longitude,i.latitude]})})})},t},r.prototype.toJSON=function(){return{type:"MultiPolygon",coordinates:this.polygons.map(function(e){return e.lines.map(function(t){return t.points.map(function(n){return[n.longitude,n.latitude]})})})}},r.validate=function(e){var t,n,o,i,s,c;if(e.type!=="MultiPolygon"||!xe(e.coordinates))return!1;try{for(var l=na(e.coordinates),a=l.next();!a.done;a=l.next()){var u=a.value;try{for(var f=(o=void 0,na(u)),d=f.next();!d.done;d=f.next()){var y=d.value;try{for(var m=(s=void 0,na(y)),v=m.next();!v.done;v=m.next()){var I=v.value;if(!Dt(I[0])||!Dt(I[1]))return!1}}catch(S){s={error:S}}finally{try{v&&!v.done&&(c=m.return)&&c.call(m)}finally{if(s)throw s.error}}}}catch(S){o={error:S}}finally{try{d&&!d.done&&(i=f.return)&&i.call(f)}finally{if(o)throw o.error}}}}catch(S){t={error:S}}finally{try{a&&!a.done&&(n=l.return)&&n.call(l)}finally{if(t)throw t.error}}return!0},Object.defineProperty(r.prototype,"_internalType",{get:function(){return eg},enumerable:!0,configurable:!0}),r}();const ug=Object.freeze(Object.defineProperty({__proto__:null,LineString:rr,MultiLineString:ra,MultiPoint:ta,MultiPolygon:Li,Point:gt,Polygon:yn},Symbol.toStringTag,{value:"Module"}));var br=function(){var r;if(!Promise){r=function(){},r.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(r.promise,"then",{get:e}),Object.defineProperty(r.promise,"catch",{get:e}),r}var t=new Promise(function(n,o){r=function(i,s){return i?o(i):n(s)}});return r.promise=t,r},he;(function(r){r.SET="set",r.REMOVE="remove",r.INC="inc",r.MUL="mul",r.PUSH="push",r.PULL="pull",r.PULL_ALL="pullAll",r.POP="pop",r.SHIFT="shift",r.UNSHIFT="unshift",r.ADD_TO_SET="addToSet",r.BIT="bit",r.RENAME="rename",r.MAX="max",r.MIN="min"})(he||(he={}));var Me=function(){function r(e,t,n){this._internalType=Od,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=e,this.operands=t,this.fieldName=n||Bi}return r.prototype._setFieldName=function(e){var t=new r(this.operator,this.operands,e);return t},r}();function Bd(r){return r&&r instanceof Me&&r._internalType===Od}var It;(function(r){r.AND="and",r.OR="or",r.NOT="not",r.NOR="nor"})(It||(It={}));var mn=function(){function r(e,t,n){if(this._internalType=Ad,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=e,this.operands=t,this.fieldName=n||Bi,this.fieldName!==Bi)if(Array.isArray(t)){t=t.slice(),this.operands=t;for(var o=0,i=t.length;o<i;o++){var s=t[o];(ia(s)||oa(s))&&(t[o]=s._setFieldName(this.fieldName))}}else{var s=t;(ia(s)||oa(s))&&(t=s._setFieldName(this.fieldName))}}return r.prototype._setFieldName=function(e){var t=this.operands.map(function(o){return o instanceof r?o._setFieldName(e):o}),n=new r(this.operator,t,e);return n},r.prototype.and=function(){var e=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return e.unshift(this),new r(It.AND,e,this.fieldName)},r.prototype.or=function(){var e=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return e.unshift(this),new r(It.OR,e,this.fieldName)},r}();function ia(r){return r&&r instanceof mn&&r._internalType===Ad}var cg=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)o.hasOwnProperty(i)&&(n[i]=o[i])},r(e,t)};return function(e,t){r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),ne;(function(r){r.EQ="eq",r.NEQ="neq",r.GT="gt",r.GTE="gte",r.LT="lt",r.LTE="lte",r.IN="in",r.NIN="nin",r.ALL="all",r.ELEM_MATCH="elemMatch",r.EXISTS="exists",r.SIZE="size",r.MOD="mod",r.GEO_NEAR="geoNear",r.GEO_WITHIN="geoWithin",r.GEO_INTERSECTS="geoIntersects"})(ne||(ne={}));var Ve=function(r){cg(e,r);function e(t,n,o){var i=r.call(this,t,n,o)||this;return i.operator=t,i._internalType=Td,i}return e.prototype.toJSON=function(){var t,n;switch(this.operator){case ne.IN:case ne.NIN:return t={},t["$"+this.operator]=this.operands,t;default:return n={},n["$"+this.operator]=this.operands[0],n}},e.prototype._setFieldName=function(t){var n=new e(this.operator,this.operands,t);return n},e.prototype.eq=function(t){var n=new e(ne.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(ne.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(ne.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(ne.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(ne.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(ne.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(ne.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(ne.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof gt))throw new TypeError('"geometry" must be of type Point. Received type '+typeof t.geometry);if(t.maxDistance!==void 0&&!Dt(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '+typeof t.maxDistance);if(t.minDistance!==void 0&&!Dt(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '+typeof t.minDistance);var n=new e(ne.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof Li)&&!(t.geometry instanceof yn))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '+typeof t.geometry);var n=new e(ne.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof gt)&&!(t.geometry instanceof rr)&&!(t.geometry instanceof yn)&&!(t.geometry instanceof ta)&&!(t.geometry instanceof ra)&&!(t.geometry instanceof Li))throw new TypeError('"geometry" must be of type Point, LineString, Polygon, MultiPoint, MultiLineString or MultiPolygon. Received type '+typeof t.geometry);var n=new e(ne.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(mn);function oa(r){return r&&r instanceof Ve&&r._internalType===Td}function Ld(r){return oa(r)}var kr={};for(var $r in ne)kr[$r]="$"+$r;for(var $r in It)kr[$r]="$"+$r;for(var $r in he)kr[$r]="$"+$r;kr[ne.NEQ]="$ne",kr[he.REMOVE]="$unset",kr[he.SHIFT]="$pop",kr[he.UNSHIFT]="$push";function zn(r){return kr[r]||"$"+r}var Ks=function(){return Ks=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Ks.apply(this,arguments)},lg=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(c){s={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(s)throw s.error}}return i},Md=function(){for(var r=[],e=0;e<arguments.length;e++)r=r.concat(lg(arguments[e]));return r};function Mi(r){return Ys(r,[r])}function Ys(r,e){if(Dd(r))switch(r._internalType){case Rd:return r.toJSON();case Cd:return r.parse();case xd:return r.parse();default:return r.toJSON?r.toJSON():r}else{if(Pd(r))return{$date:+r};if(Js(r))return{$regex:r.source,$options:r.flags};if(xe(r))return r.map(function(o){if(e.indexOf(o)>-1)throw new Error("Cannot convert circular structure to JSON");return Ys(o,Md(e,[o]))});if(jr(r)){var t=Ks({},r);for(var n in t){if(e.indexOf(t[n])>-1)throw new Error("Cannot convert circular structure to JSON");t[n]=Ys(t[n],Md(e,[t[n]]))}return t}else return r}}var Qs=function(){return Qs=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Qs.apply(this,arguments)},fg=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(c){s={error:c}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(s)throw s.error}}return i},qd=function(){for(var r=[],e=0;e<arguments.length;e++)r=r.concat(fg(arguments[e]));return r};function jd(r,e,t,n){var o=Qs({},r);for(var i in r)if(!/^\$/.test(i)){var s=r[i];if(s&&jr(s)&&!e(s)){if(n.indexOf(s)>-1)throw new Error("Cannot convert circular structure to JSON");var c=qd(t,[i]),l=qd(n,[s]),a=jd(s,e,c,l);o[i]=a;var u=!1;for(var f in a)/^\$/.test(f)?u=!0:(o[i+"."+f]=a[f],delete o[i][f]);u||delete o[i]}}return o}function kd(r){return jd(r,Xs,[],[r])}function $d(r,e,t){e[t]||delete r[t];for(var n in e)r[n]?xe(r[n])?r[n].push(e[n]):jr(r[n])?jr(e[n])?Object.assign(r[n],e[n]):(console.warn("unmergable condition, query is object but condition is "+tr(e)+", can only overwrite",e,t),r[n]=e[n]):(console.warn("to-merge query is of type "+tr(r)+", can only overwrite",r,e,t),r[n]=e[n]):r[n]=e[n]}function Xs(r){return Dd(r)||Pd(r)||Js(r)}function Wr(r){return Mi(r)}var Zs=function(){function r(){}return r.encode=function(e){var t=new r;return t.encodeUpdate(e)},r.prototype.encodeUpdate=function(e){return Bd(e)?this.encodeUpdateCommand(e):tr(e)==="object"?this.encodeUpdateObject(e):e},r.prototype.encodeUpdateCommand=function(e){if(e.fieldName===Bi)throw new Error("Cannot encode a comparison command with unset field name");switch(e.operator){case he.PUSH:case he.PULL:case he.PULL_ALL:case he.POP:case he.SHIFT:case he.UNSHIFT:case he.ADD_TO_SET:return this.encodeArrayUpdateCommand(e);default:return this.encodeFieldUpdateCommand(e)}},r.prototype.encodeFieldUpdateCommand=function(e){var t,n,o,i,s=zn(e.operator);switch(e.operator){case he.REMOVE:return t={},t[s]=(n={},n[e.fieldName]="",n),t;default:return o={},o[s]=(i={},i[e.fieldName]=e.operands[0],i),o}},r.prototype.encodeArrayUpdateCommand=function(e){var t,n,o,i,s,c,l,a,u,f,d=zn(e.operator);switch(e.operator){case he.PUSH:{var y=void 0;return xe(e.operands)?y={$each:e.operands.map(Wr)}:y=e.operands,t={},t[d]=(n={},n[e.fieldName]=y,n),t}case he.UNSHIFT:{var y={$each:e.operands.map(Wr),$position:0};return o={},o[d]=(i={},i[e.fieldName]=y,i),o}case he.POP:return s={},s[d]=(c={},c[e.fieldName]=1,c),s;case he.SHIFT:return l={},l[d]=(a={},a[e.fieldName]=-1,a),l;default:return u={},u[d]=(f={},f[e.fieldName]=Wr(e.operands),f),u}},r.prototype.encodeUpdateObject=function(e){var t=kd(e);for(var n in t)if(!/^\$/.test(n)){var o=t[n];if(Bd(o)){t[n]=o._setFieldName(n);var i=this.encodeUpdateCommand(t[n]);$d(t,i,n)}else{t[n]=o=Wr(o);var s=new Me(he.SET,[o],n),i=this.encodeUpdateCommand(s);$d(t,i,n)}}return t},r}(),eu={};function Wd(r){if(!it.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=r.config.env;return eu[e]||(eu[e]=new it.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:new it.reqClass(r.config)}}})),eu[e]}var aa=function(){return aa=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},aa.apply(this,arguments)},Hd=function(){function r(e,t,n,o){var i=this;o===void 0&&(o={}),this.watch=function(s){var c=Wd(i._db);return c.watch(aa(aa({},s),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify({_id:i.id})}))},this._db=e,this._coll=t,this.id=n,this.request=new it.reqClass(this._db.config),this.projection=o}return r.prototype.create=function(e,t){t=t||br();var n={collectionName:this._coll,data:Mi(e)};return this.id&&(n._id=this.id),this.request.send("database.addDocument",n).then(function(o){o.code?t(0,o):t(0,{id:o.data._id,requestId:o.requestId})}).catch(function(o){t(o)}),t.promise},r.prototype.set=function(e,t){if(t=t||br(),!this.id)return Promise.resolve({code:"INVALID_PARAM",message:"docId不能为空"});if(!e||typeof e!="object")return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(e.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n=!1,o=function(c){if(typeof c=="object")for(var l in c)c[l]instanceof Me?n=!0:typeof c[l]=="object"&&o(c[l])};if(o(e),n)return Promise.resolve({code:"DATABASE_REQUEST_FAILED",message:"update operator complicit"});var i=!1,s={collectionName:this._coll,queryType:er.DOC,data:Mi(e),multi:!1,merge:i,upsert:!0};return this.id&&(s.query={_id:this.id}),this.request.send("database.updateDocument",s).then(function(c){c.code?t(0,c):t(0,{updated:c.data.updated,upsertedId:c.data.upserted_id,requestId:c.requestId})}).catch(function(c){t(c)}),t.promise},r.prototype.update=function(e,t){if(t=t||br(),!e||typeof e!="object")return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(e.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={_id:this.id},o=!0,i={collectionName:this._coll,data:Zs.encode(e),query:n,queryType:er.DOC,multi:!1,merge:o,upsert:!1};return this.request.send("database.updateDocument",i).then(function(s){s.code?t(0,s):t(0,{updated:s.data.updated,upsertedId:s.data.upserted_id,requestId:s.requestId})}).catch(function(s){t(s)}),t.promise},r.prototype.remove=function(e){e=e||br();var t={_id:this.id},n={collectionName:this._coll,query:t,queryType:er.DOC,multi:!1};return this.request.send("database.deleteDocument",n).then(function(o){o.code?e(0,o):e(0,{deleted:o.data.deleted,requestId:o.requestId})}).catch(function(o){e(o)}),e.promise},r.prototype.get=function(e){e=e||br();var t={_id:this.id},n={collectionName:this._coll,query:t,queryType:er.DOC,multi:!1,projection:this.projection};return this.request.send("database.queryDocument",n).then(function(o){if(o.code)e(0,o);else{var i=ea.formatResDocumentData(o.data.list);e(0,{data:i,requestId:o.requestId})}}).catch(function(o){e(o)}),e.promise},r.prototype.field=function(e){for(var t in e)e[t]?e[t]=1:e[t]=0;return new r(this._db,this._coll,this.id,e)},r}(),sa=function(){function r(){}return r.encode=function(e){var t=new dg;return t.encodeQuery(e)},r}(),dg=function(){function r(){}return r.prototype.encodeQuery=function(e,t){var n;return Xs(e)?ia(e)?this.encodeLogicCommand(e):oa(e)?this.encodeQueryCommand(e):(n={},n[t]=this.encodeQueryObject(e),n):jr(e)?this.encodeQueryObject(e):e},r.prototype.encodeRegExp=function(e){return{$regex:e.source,$options:e.flags}},r.prototype.encodeLogicCommand=function(e){var t,n,o,i,s,c,l,a=this;switch(e.operator){case It.NOR:case It.AND:case It.OR:{var u=zn(e.operator),f=e.operands.map(function(m){return a.encodeQuery(m,e.fieldName)});return t={},t[u]=f,t}case It.NOT:{var u=zn(e.operator),d=e.operands[0];if(Js(d))return n={},n[e.fieldName]=(o={},o[u]=this.encodeRegExp(d),o),n;var f=this.encodeQuery(d)[e.fieldName];return i={},i[e.fieldName]=(s={},s[u]=f,s),i}default:{var u=zn(e.operator);if(e.operands.length===1){var y=this.encodeQuery(e.operands[0]);return c={},c[u]=y,c}else{var f=e.operands.map(this.encodeQuery.bind(this));return l={},l[u]=f,l}}}},r.prototype.encodeQueryCommand=function(e){return Ld(e)?this.encodeComparisonCommand(e):this.encodeComparisonCommand(e)},r.prototype.encodeComparisonCommand=function(e){var t,n,o,i,s,c,l,a,u;if(e.fieldName===Bi)throw new Error("Cannot encode a comparison command with unset field name");var f=zn(e.operator);switch(e.operator){case ne.EQ:case ne.NEQ:case ne.LT:case ne.LTE:case ne.GT:case ne.GTE:case ne.ELEM_MATCH:case ne.EXISTS:case ne.SIZE:case ne.MOD:return t={},t[e.fieldName]=(n={},n[f]=Wr(e.operands[0]),n),t;case ne.IN:case ne.NIN:case ne.ALL:return o={},o[e.fieldName]=(i={},i[f]=Wr(e.operands),i),o;case ne.GEO_NEAR:{var d=e.operands[0];return s={},s[e.fieldName]={$nearSphere:{$geometry:d.geometry.toJSON(),$maxDistance:d.maxDistance,$minDistance:d.minDistance}},s}case ne.GEO_WITHIN:{var d=e.operands[0];return c={},c[e.fieldName]={$geoWithin:{$geometry:d.geometry.toJSON()}},c}case ne.GEO_INTERSECTS:{var d=e.operands[0];return l={},l[e.fieldName]={$geoIntersects:{$geometry:d.geometry.toJSON()}},l}default:return a={},a[e.fieldName]=(u={},u[f]=Wr(e.operands[0]),u),a}},r.prototype.encodeQueryObject=function(e){var t=kd(e);for(var n in t){var o=t[n];if(ia(o)){t[n]=o._setFieldName(n);var i=this.encodeLogicCommand(t[n]);this.mergeConditionAfterEncode(t,i,n)}else if(Ld(o)){t[n]=o._setFieldName(n);var i=this.encodeComparisonCommand(t[n]);this.mergeConditionAfterEncode(t,i,n)}else Xs(o)&&(t[n]=Wr(o))}return t},r.prototype.mergeConditionAfterEncode=function(e,t,n){t[n]||delete e[n];for(var o in t)e[o]?xe(e[o])?e[o]=e[o].concat(t[o]):jr(e[o])?jr(t[o])?Object.assign(e,t):(console.warn("unmergable condition, query is object but condition is "+tr(t)+", can only overwrite",t,n),e[o]=t[o]):(console.warn("to-merge query is of type "+tr(e)+", can only overwrite",e,t,n),e[o]=t[o]):e[o]=t[o]},r}(),gn=function(){return gn=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},gn.apply(this,arguments)},hg=function(){function r(e,t,n,o,i){var s=this;this.watch=function(c){var l=Wd(s._db);return l.watch(gn(gn({},c),{envId:s._db.config.env,collectionName:s._coll,query:JSON.stringify(s._fieldFilters||{}),limit:s._queryOptions.limit,orderBy:s._fieldOrders?s._fieldOrders.reduce(function(a,u){return a[u.field]=u.direction,a},{}):void 0}))},this._db=e,this._coll=t,this._fieldFilters=n,this._fieldOrders=o||[],this._queryOptions=i||{},this._request=new it.reqClass(this._db.config)}return r.prototype.get=function(e){e=e||br();var t=[];this._fieldOrders&&this._fieldOrders.forEach(function(o){t.push(o)});var n={collectionName:this._coll,queryType:er.WHERE};return this._fieldFilters&&(n.query=this._fieldFilters),t.length>0&&(n.order=t),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(o){if(o.code)e(0,o);else{var i=ea.formatResDocumentData(o.data.list),s={data:i,requestId:o.requestId};o.total&&(s.total=o.total),o.limit&&(s.limit=o.limit),o.offset&&(s.offset=o.offset),e(0,s)}}).catch(function(o){e(o)}),e.promise},r.prototype.count=function(e){e=e||br();var t={collectionName:this._coll,queryType:er.WHERE};return this._fieldFilters&&(t.query=this._fieldFilters),this._request.send("database.countDocument",t).then(function(n){n.code?e(0,n):e(0,{requestId:n.requestId,total:n.data.total})}).catch(function(n){e(n)}),e.promise},r.prototype.where=function(e){if(Object.prototype.toString.call(e).slice(8,-1)!=="Object")throw Error(_r.QueryParamTypeError);var t=Object.keys(e),n=t.some(function(o){return e[o]!==void 0});if(t.length&&!n)throw Error(_r.QueryParamValueError);return new r(this._db,this._coll,sa.encode(e),this._fieldOrders,this._queryOptions)},r.prototype.orderBy=function(e,t){qr.isFieldPath(e),qr.isFieldOrder(t);var n={field:e,direction:t},o=this._fieldOrders.concat(n);return new r(this._db,this._coll,this._fieldFilters,o,this._queryOptions)},r.prototype.limit=function(e){qr.isInteger("limit",e);var t=gn({},this._queryOptions);return t.limit=e,new r(this._db,this._coll,this._fieldFilters,this._fieldOrders,t)},r.prototype.skip=function(e){qr.isInteger("offset",e);var t=gn({},this._queryOptions);return t.offset=e,new r(this._db,this._coll,this._fieldFilters,this._fieldOrders,t)},r.prototype.update=function(e,t){if(t=t||br(),!e||typeof e!="object")return Promise.resolve({code:"INVALID_PARAM",message:"参数必需是非空对象"});if(e.hasOwnProperty("_id"))return Promise.resolve({code:"INVALID_PARAM",message:"不能更新_id的值"});var n={collectionName:this._coll,query:this._fieldFilters,queryType:er.WHERE,multi:!0,merge:!0,upsert:!1,data:Zs.encode(e)};return this._request.send("database.updateDocument",n).then(function(o){o.code?t(0,o):t(0,{requestId:o.requestId,updated:o.data.updated,upsertId:o.data.upsert_id})}).catch(function(o){t(o)}),t.promise},r.prototype.field=function(e){for(var t in e)e[t]?typeof e[t]!="object"&&(e[t]=1):e[t]=0;var n=gn({},this._queryOptions);return n.projection=e,new r(this._db,this._coll,this._fieldFilters,this._fieldOrders,n)},r.prototype.remove=function(e){e=e||br(),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 t={collectionName:this._coll,query:sa.encode(this._fieldFilters),queryType:er.WHERE,multi:!0};return this._request.send("database.deleteDocument",t).then(function(n){n.code?e(0,n):e(0,{requestId:n.requestId,deleted:n.data.deleted})}).catch(function(n){e(n)}),e.promise},r}();function pg(r,e){return e={exports:{}},r(e,e.exports),e.exports}for(var yg=bg,mg=Eg,gg=Og,nr=[],Ft=[],vg=typeof Uint8Array<"u"?Uint8Array:Array,tu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Jn=0,_g=tu.length;Jn<_g;++Jn)nr[Jn]=tu[Jn],Ft[tu.charCodeAt(Jn)]=Jn;Ft[45]=62,Ft[95]=63;function Gd(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var n=t===e?0:4-t%4;return[t,n]}function bg(r){var e=Gd(r),t=e[0],n=e[1];return(t+n)*3/4-n}function wg(r,e,t){return(e+t)*3/4-t}function Eg(r){var e,t=Gd(r),n=t[0],o=t[1],i=new vg(wg(r,n,o)),s=0,c=o>0?n-4:n,l;for(l=0;l<c;l+=4)e=Ft[r.charCodeAt(l)]<<18|Ft[r.charCodeAt(l+1)]<<12|Ft[r.charCodeAt(l+2)]<<6|Ft[r.charCodeAt(l+3)],i[s++]=e>>16&255,i[s++]=e>>8&255,i[s++]=e&255;return o===2&&(e=Ft[r.charCodeAt(l)]<<2|Ft[r.charCodeAt(l+1)]>>4,i[s++]=e&255),o===1&&(e=Ft[r.charCodeAt(l)]<<10|Ft[r.charCodeAt(l+1)]<<4|Ft[r.charCodeAt(l+2)]>>2,i[s++]=e>>8&255,i[s++]=e&255),i}function Sg(r){return nr[r>>18&63]+nr[r>>12&63]+nr[r>>6&63]+nr[r&63]}function Ig(r,e,t){for(var n,o=[],i=e;i<t;i+=3)n=(r[i]<<16&16711680)+(r[i+1]<<8&65280)+(r[i+2]&255),o.push(Sg(n));return o.join("")}function Og(r){for(var e,t=r.length,n=t%3,o=[],i=16383,s=0,c=t-n;s<c;s+=i)o.push(Ig(r,s,s+i>c?c:s+i));return n===1?(e=r[t-1],o.push(nr[e>>2]+nr[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],o.push(nr[e>>10]+nr[e>>4&63]+nr[e<<2&63]+"=")),o.join("")}var ru={byteLength:yg,toByteArray:mg,fromByteArray:gg};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */var Tg=function(e,t,n,o,i){var s,c,l=i*8-o-1,a=(1<<l)-1,u=a>>1,f=-7,d=n?i-1:0,y=n?-1:1,m=e[t+d];for(d+=y,s=m&(1<<-f)-1,m>>=-f,f+=l;f>0;s=s*256+e[t+d],d+=y,f-=8);for(c=s&(1<<-f)-1,s>>=-f,f+=o;f>0;c=c*256+e[t+d],d+=y,f-=8);if(s===0)s=1-u;else{if(s===a)return c?NaN:(m?-1:1)*(1/0);c=c+Math.pow(2,o),s=s-u}return(m?-1:1)*c*Math.pow(2,s-o)},Ag=function(e,t,n,o,i,s){var c,l,a,u=s*8-i-1,f=(1<<u)-1,d=f>>1,y=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,m=o?0:s-1,v=o?1:-1,I=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(l=isNaN(t)?1:0,c=f):(c=Math.floor(Math.log(t)/Math.LN2),t*(a=Math.pow(2,-c))<1&&(c--,a*=2),c+d>=1?t+=y/a:t+=y*Math.pow(2,1-d),t*a>=2&&(c++,a/=2),c+d>=f?(l=0,c=f):c+d>=1?(l=(t*a-1)*Math.pow(2,i),c=c+d):(l=t*Math.pow(2,d-1)*Math.pow(2,i),c=0));i>=8;e[n+m]=l&255,m+=v,l/=256,i-=8);for(c=c<<i|l,u+=i;u>0;e[n+m]=c&255,m+=v,c/=256,u-=8);e[n+m-v]|=I*128},Kn={read:Tg,write:Ag},ua=pg(function(r,e){var t=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=s,e.SlowBuffer=S,e.INSPECT_MAX_BYTES=50;var n=2147483647;e.kMaxLength=n,s.TYPED_ARRAY_SUPPORT=o(),!s.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function o(){try{var _=new Uint8Array(1),h={foo:function(){return 42}};return Object.setPrototypeOf(h,Uint8Array.prototype),Object.setPrototypeOf(_,h),_.foo()===42}catch{return!1}}Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}});function i(_){if(_>n)throw new RangeError('The value "'+_+'" is invalid for option "size"');var h=new Uint8Array(_);return Object.setPrototypeOf(h,s.prototype),h}function s(_,h,p){if(typeof _=="number"){if(typeof h=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return u(_)}return c(_,h,p)}s.poolSize=8192;function c(_,h,p){if(typeof _=="string")return f(_,h);if(ArrayBuffer.isView(_))return y(_);if(_==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+babelHelpers.typeof(_));if(Ue(_,ArrayBuffer)||_&&Ue(_.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Ue(_,SharedArrayBuffer)||_&&Ue(_.buffer,SharedArrayBuffer)))return m(_,h,p);if(typeof _=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var E=_.valueOf&&_.valueOf();if(E!=null&&E!==_)return s.from(E,h,p);var C=v(_);if(C)return C;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof _[Symbol.toPrimitive]=="function")return s.from(_[Symbol.toPrimitive]("string"),h,p);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+babelHelpers.typeof(_))}s.from=function(_,h,p){return c(_,h,p)},Object.setPrototypeOf(s.prototype,Uint8Array.prototype),Object.setPrototypeOf(s,Uint8Array);function l(_){if(typeof _!="number")throw new TypeError('"size" argument must be of type number');if(_<0)throw new RangeError('The value "'+_+'" is invalid for option "size"')}function a(_,h,p){return l(_),_<=0?i(_):h!==void 0?typeof p=="string"?i(_).fill(h,p):i(_).fill(h):i(_)}s.alloc=function(_,h,p){return a(_,h,p)};function u(_){return l(_),i(_<0?0:I(_)|0)}s.allocUnsafe=function(_){return u(_)},s.allocUnsafeSlow=function(_){return u(_)};function f(_,h){if((typeof h!="string"||h==="")&&(h="utf8"),!s.isEncoding(h))throw new TypeError("Unknown encoding: "+h);var p=w(_,h)|0,E=i(p),C=E.write(_,h);return C!==p&&(E=E.slice(0,C)),E}function d(_){for(var h=_.length<0?0:I(_.length)|0,p=i(h),E=0;E<h;E+=1)p[E]=_[E]&255;return p}function y(_){if(Ue(_,Uint8Array)){var h=new Uint8Array(_);return m(h.buffer,h.byteOffset,h.byteLength)}return d(_)}function m(_,h,p){if(h<0||_.byteLength<h)throw new RangeError('"offset" is outside of buffer bounds');if(_.byteLength<h+(p||0))throw new RangeError('"length" is outside of buffer bounds');var E;return h===void 0&&p===void 0?E=new Uint8Array(_):p===void 0?E=new Uint8Array(_,h):E=new Uint8Array(_,h,p),Object.setPrototypeOf(E,s.prototype),E}function v(_){if(s.isBuffer(_)){var h=I(_.length)|0,p=i(h);return p.length===0||_.copy(p,0,0,h),p}if(_.length!==void 0)return typeof _.length!="number"||Tt(_.length)?i(0):d(_);if(_.type==="Buffer"&&Array.isArray(_.data))return d(_.data)}function I(_){if(_>=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return _|0}function S(_){return+_!=_&&(_=0),s.alloc(+_)}s.isBuffer=function(h){return h!=null&&h._isBuffer===!0&&h!==s.prototype},s.compare=function(h,p){if(Ue(h,Uint8Array)&&(h=s.from(h,h.offset,h.byteLength)),Ue(p,Uint8Array)&&(p=s.from(p,p.offset,p.byteLength)),!s.isBuffer(h)||!s.isBuffer(p))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(h===p)return 0;for(var E=h.length,C=p.length,q=0,k=Math.min(E,C);q<k;++q)if(h[q]!==p[q]){E=h[q],C=p[q];break}return E<C?-1:C<E?1:0},s.isEncoding=function(h){switch(String(h).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(h,p){if(!Array.isArray(h))throw new TypeError('"list" argument must be an Array of Buffers');if(h.length===0)return s.alloc(0);var E;if(p===void 0)for(p=0,E=0;E<h.length;++E)p+=h[E].length;var C=s.allocUnsafe(p),q=0;for(E=0;E<h.length;++E){var k=h[E];if(Ue(k,Uint8Array))q+k.length>C.length?s.from(k).copy(C,q):Uint8Array.prototype.set.call(C,k,q);else if(s.isBuffer(k))k.copy(C,q);else throw new TypeError('"list" argument must be an Array of Buffers');q+=k.length}return C};function w(_,h){if(s.isBuffer(_))return _.length;if(ArrayBuffer.isView(_)||Ue(_,ArrayBuffer))return _.byteLength;if(typeof _!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+babelHelpers.typeof(_));var p=_.length,E=arguments.length>2&&arguments[2]===!0;if(!E&&p===0)return 0;for(var C=!1;;)switch(h){case"ascii":case"latin1":case"binary":return p;case"utf8":case"utf-8":return je(_).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return p*2;case"hex":return p>>>1;case"base64":return ge(_).length;default:if(C)return E?-1:je(_).length;h=(""+h).toLowerCase(),C=!0}}s.byteLength=w;function O(_,h,p){var E=!1;if((h===void 0||h<0)&&(h=0),h>this.length||((p===void 0||p>this.length)&&(p=this.length),p<=0)||(p>>>=0,h>>>=0,p<=h))return"";for(_||(_="utf8");;)switch(_){case"hex":return ee(this,h,p);case"utf8":case"utf-8":return V(this,h,p);case"ascii":return se(this,h,p);case"latin1":case"binary":return Z(this,h,p);case"base64":return j(this,h,p);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Y(this,h,p);default:if(E)throw new TypeError("Unknown encoding: "+_);_=(_+"").toLowerCase(),E=!0}}s.prototype._isBuffer=!0;function T(_,h,p){var E=_[h];_[h]=_[p],_[p]=E}s.prototype.swap16=function(){var h=this.length;if(h%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var p=0;p<h;p+=2)T(this,p,p+1);return this},s.prototype.swap32=function(){var h=this.length;if(h%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var p=0;p<h;p+=4)T(this,p,p+3),T(this,p+1,p+2);return this},s.prototype.swap64=function(){var h=this.length;if(h%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var p=0;p<h;p+=8)T(this,p,p+7),T(this,p+1,p+6),T(this,p+2,p+5),T(this,p+3,p+4);return this},s.prototype.toString=function(){var h=this.length;return h===0?"":arguments.length===0?V(this,0,h):O.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(h){if(!s.isBuffer(h))throw new TypeError("Argument must be a Buffer");return this===h?!0:s.compare(this,h)===0},s.prototype.inspect=function(){var h="",p=e.INSPECT_MAX_BYTES;return h=this.toString("hex",0,p).replace(/(.{2})/g,"$1 ").trim(),this.length>p&&(h+=" ... "),"<Buffer "+h+">"},t&&(s.prototype[t]=s.prototype.inspect),s.prototype.compare=function(h,p,E,C,q){if(Ue(h,Uint8Array)&&(h=s.from(h,h.offset,h.byteLength)),!s.isBuffer(h))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+babelHelpers.typeof(h));if(p===void 0&&(p=0),E===void 0&&(E=h?h.length:0),C===void 0&&(C=0),q===void 0&&(q=this.length),p<0||E>h.length||C<0||q>this.length)throw new RangeError("out of range index");if(C>=q&&p>=E)return 0;if(C>=q)return-1;if(p>=E)return 1;if(p>>>=0,E>>>=0,C>>>=0,q>>>=0,this===h)return 0;for(var k=q-C,ae=E-p,le=Math.min(k,ae),ce=this.slice(C,q),Oe=h.slice(p,E),ve=0;ve<le;++ve)if(ce[ve]!==Oe[ve]){k=ce[ve],ae=Oe[ve];break}return k<ae?-1:ae<k?1:0};function N(_,h,p,E,C){if(_.length===0)return-1;if(typeof p=="string"?(E=p,p=0):p>2147483647?p=2147483647:p<-2147483648&&(p=-2147483648),p=+p,Tt(p)&&(p=C?0:_.length-1),p<0&&(p=_.length+p),p>=_.length){if(C)return-1;p=_.length-1}else if(p<0)if(C)p=0;else return-1;if(typeof h=="string"&&(h=s.from(h,E)),s.isBuffer(h))return h.length===0?-1:D(_,h,p,E,C);if(typeof h=="number")return h=h&255,typeof Uint8Array.prototype.indexOf=="function"?C?Uint8Array.prototype.indexOf.call(_,h,p):Uint8Array.prototype.lastIndexOf.call(_,h,p):D(_,[h],p,E,C);throw new TypeError("val must be string, number or Buffer")}function D(_,h,p,E,C){var q=1,k=_.length,ae=h.length;if(E!==void 0&&(E=String(E).toLowerCase(),E==="ucs2"||E==="ucs-2"||E==="utf16le"||E==="utf-16le")){if(_.length<2||h.length<2)return-1;q=2,k/=2,ae/=2,p/=2}function le(ar,wr){return q===1?ar[wr]:ar.readUInt16BE(wr*q)}var ce;if(C){var Oe=-1;for(ce=p;ce<k;ce++)if(le(_,ce)===le(h,Oe===-1?0:ce-Oe)){if(Oe===-1&&(Oe=ce),ce-Oe+1===ae)return Oe*q}else Oe!==-1&&(ce-=ce-Oe),Oe=-1}else for(p+ae>k&&(p=k-ae),ce=p;ce>=0;ce--){for(var ve=!0,Vt=0;Vt<ae;Vt++)if(le(_,ce+Vt)!==le(h,Vt)){ve=!1;break}if(ve)return ce}return-1}s.prototype.includes=function(h,p,E){return this.indexOf(h,p,E)!==-1},s.prototype.indexOf=function(h,p,E){return N(this,h,p,E,!0)},s.prototype.lastIndexOf=function(h,p,E){return N(this,h,p,E,!1)};function B(_,h,p,E){p=Number(p)||0;var C=_.length-p;E?(E=Number(E),E>C&&(E=C)):E=C;var q=h.length;E>q/2&&(E=q/2);for(var k=0;k<E;++k){var ae=parseInt(h.substr(k*2,2),16);if(Tt(ae))return k;_[p+k]=ae}return k}function R(_,h,p,E){return Ae(je(h,_.length-p),_,p,E)}function x(_,h,p,E){return Ae(me(h),_,p,E)}function L(_,h,p,E){return Ae(ge(h),_,p,E)}function F(_,h,p,E){return Ae(Re(h,_.length-p),_,p,E)}s.prototype.write=function(h,p,E,C){if(p===void 0)C="utf8",E=this.length,p=0;else if(E===void 0&&typeof p=="string")C=p,E=this.length,p=0;else if(isFinite(p))p=p>>>0,isFinite(E)?(E=E>>>0,C===void 0&&(C="utf8")):(C=E,E=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var q=this.length-p;if((E===void 0||E>q)&&(E=q),h.length>0&&(E<0||p<0)||p>this.length)throw new RangeError("Attempt to write outside buffer bounds");C||(C="utf8");for(var k=!1;;)switch(C){case"hex":return B(this,h,p,E);case"utf8":case"utf-8":return R(this,h,p,E);case"ascii":case"latin1":case"binary":return x(this,h,p,E);case"base64":return L(this,h,p,E);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return F(this,h,p,E);default:if(k)throw new TypeError("Unknown encoding: "+C);C=(""+C).toLowerCase(),k=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function j(_,h,p){return h===0&&p===_.length?ru.fromByteArray(_):ru.fromByteArray(_.slice(h,p))}function V(_,h,p){p=Math.min(_.length,p);for(var E=[],C=h;C<p;){var q=_[C],k=null,ae=q>239?4:q>223?3:q>191?2:1;if(C+ae<=p){var le,ce,Oe,ve;switch(ae){case 1:q<128&&(k=q);break;case 2:le=_[C+1],(le&192)===128&&(ve=(q&31)<<6|le&63,ve>127&&(k=ve));break;case 3:le=_[C+1],ce=_[C+2],(le&192)===128&&(ce&192)===128&&(ve=(q&15)<<12|(le&63)<<6|ce&63,ve>2047&&(ve<55296||ve>57343)&&(k=ve));break;case 4:le=_[C+1],ce=_[C+2],Oe=_[C+3],(le&192)===128&&(ce&192)===128&&(Oe&192)===128&&(ve=(q&15)<<18|(le&63)<<12|(ce&63)<<6|Oe&63,ve>65535&&ve<1114112&&(k=ve))}}k===null?(k=65533,ae=1):k>65535&&(k-=65536,E.push(k>>>10&1023|55296),k=56320|k&1023),E.push(k),C+=ae}return oe(E)}var W=4096;function oe(_){var h=_.length;if(h<=W)return String.fromCharCode.apply(String,_);for(var p="",E=0;E<h;)p+=String.fromCharCode.apply(String,_.slice(E,E+=W));return p}function se(_,h,p){var E="";p=Math.min(_.length,p);for(var C=h;C<p;++C)E+=String.fromCharCode(_[C]&127);return E}function Z(_,h,p){var E="";p=Math.min(_.length,p);for(var C=h;C<p;++C)E+=String.fromCharCode(_[C]);return E}function ee(_,h,p){var E=_.length;(!h||h<0)&&(h=0),(!p||p<0||p>E)&&(p=E);for(var C="",q=h;q<p;++q)C+=ot[_[q]];return C}function Y(_,h,p){for(var E=_.slice(h,p),C="",q=0;q<E.length-1;q+=2)C+=String.fromCharCode(E[q]+E[q+1]*256);return C}s.prototype.slice=function(h,p){var E=this.length;h=~~h,p=p===void 0?E:~~p,h<0?(h+=E,h<0&&(h=0)):h>E&&(h=E),p<0?(p+=E,p<0&&(p=0)):p>E&&(p=E),p<h&&(p=h);var C=this.subarray(h,p);return Object.setPrototypeOf(C,s.prototype),C};function G(_,h,p){if(_%1!==0||_<0)throw new RangeError("offset is not uint");if(_+h>p)throw new RangeError("Trying to access beyond buffer length")}s.prototype.readUintLE=s.prototype.readUIntLE=function(h,p,E){h=h>>>0,p=p>>>0,E||G(h,p,this.length);for(var C=this[h],q=1,k=0;++k<p&&(q*=256);)C+=this[h+k]*q;return C},s.prototype.readUintBE=s.prototype.readUIntBE=function(h,p,E){h=h>>>0,p=p>>>0,E||G(h,p,this.length);for(var C=this[h+--p],q=1;p>0&&(q*=256);)C+=this[h+--p]*q;return C},s.prototype.readUint8=s.prototype.readUInt8=function(h,p){return h=h>>>0,p||G(h,1,this.length),this[h]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(h,p){return h=h>>>0,p||G(h,2,this.length),this[h]|this[h+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(h,p){return h=h>>>0,p||G(h,2,this.length),this[h]<<8|this[h+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(h,p){return h=h>>>0,p||G(h,4,this.length),(this[h]|this[h+1]<<8|this[h+2]<<16)+this[h+3]*16777216},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(h,p){return h=h>>>0,p||G(h,4,this.length),this[h]*16777216+(this[h+1]<<16|this[h+2]<<8|this[h+3])},s.prototype.readIntLE=function(h,p,E){h=h>>>0,p=p>>>0,E||G(h,p,this.length);for(var C=this[h],q=1,k=0;++k<p&&(q*=256);)C+=this[h+k]*q;return q*=128,C>=q&&(C-=Math.pow(2,8*p)),C},s.prototype.readIntBE=function(h,p,E){h=h>>>0,p=p>>>0,E||G(h,p,this.length);for(var C=p,q=1,k=this[h+--C];C>0&&(q*=256);)k+=this[h+--C]*q;return q*=128,k>=q&&(k-=Math.pow(2,8*p)),k},s.prototype.readInt8=function(h,p){return h=h>>>0,p||G(h,1,this.length),this[h]&128?(255-this[h]+1)*-1:this[h]},s.prototype.readInt16LE=function(h,p){h=h>>>0,p||G(h,2,this.length);var E=this[h]|this[h+1]<<8;return E&32768?E|4294901760:E},s.prototype.readInt16BE=function(h,p){h=h>>>0,p||G(h,2,this.length);var E=this[h+1]|this[h]<<8;return E&32768?E|4294901760:E},s.prototype.readInt32LE=function(h,p){return h=h>>>0,p||G(h,4,this.length),this[h]|this[h+1]<<8|this[h+2]<<16|this[h+3]<<24},s.prototype.readInt32BE=function(h,p){return h=h>>>0,p||G(h,4,this.length),this[h]<<24|this[h+1]<<16|this[h+2]<<8|this[h+3]},s.prototype.readFloatLE=function(h,p){return h=h>>>0,p||G(h,4,this.length),Kn.read(this,h,!0,23,4)},s.prototype.readFloatBE=function(h,p){return h=h>>>0,p||G(h,4,this.length),Kn.read(this,h,!1,23,4)},s.prototype.readDoubleLE=function(h,p){return h=h>>>0,p||G(h,8,this.length),Kn.read(this,h,!0,52,8)},s.prototype.readDoubleBE=function(h,p){return h=h>>>0,p||G(h,8,this.length),Kn.read(this,h,!1,52,8)};function Se(_,h,p,E,C,q){if(!s.isBuffer(_))throw new TypeError('"buffer" argument must be a Buffer instance');if(h>C||h<q)throw new RangeError('"value" argument is out of bounds');if(p+E>_.length)throw new RangeError("Index out of range")}s.prototype.writeUintLE=s.prototype.writeUIntLE=function(h,p,E,C){if(h=+h,p=p>>>0,E=E>>>0,!C){var q=Math.pow(2,8*E)-1;Se(this,h,p,E,q,0)}var k=1,ae=0;for(this[p]=h&255;++ae<E&&(k*=256);)this[p+ae]=h/k&255;return p+E},s.prototype.writeUintBE=s.prototype.writeUIntBE=function(h,p,E,C){if(h=+h,p=p>>>0,E=E>>>0,!C){var q=Math.pow(2,8*E)-1;Se(this,h,p,E,q,0)}var k=E-1,ae=1;for(this[p+k]=h&255;--k>=0&&(ae*=256);)this[p+k]=h/ae&255;return p+E},s.prototype.writeUint8=s.prototype.writeUInt8=function(h,p,E){return h=+h,p=p>>>0,E||Se(this,h,p,1,255,0),this[p]=h&255,p+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(h,p,E){return h=+h,p=p>>>0,E||Se(this,h,p,2,65535,0),this[p]=h&255,this[p+1]=h>>>8,p+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(h,p,E){return h=+h,p=p>>>0,E||Se(this,h,p,2,65535,0),this[p]=h>>>8,this[p+1]=h&255,p+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(h,p,E){return h=+h,p=p>>>0,E||Se(this,h,p,4,4294967295,0),this[p+3]=h>>>24,this[p+2]=h>>>16,this[p+1]=h>>>8,this[p]=h&255,p+4},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(h,p,E){return h=+h,p=p>>>0,E||Se(this,h,p,4,4294967295,0),this[p]=h>>>24,this[p+1]=h>>>16,this[p+2]=h>>>8,this[p+3]=h&255,p+4},s.prototype.writeIntLE=function(h,p,E,C){if(h=+h,p=p>>>0,!C){var q=Math.pow(2,8*E-1);Se(this,h,p,E,q-1,-q)}var k=0,ae=1,le=0;for(this[p]=h&255;++k<E&&(ae*=256);)h<0&&le===0&&this[p+k-1]!==0&&(le=1),this[p+k]=(h/ae>>0)-le&255;return p+E},s.prototype.writeIntBE=function(h,p,E,C){if(h=+h,p=p>>>0,!C){var q=Math.pow(2,8*E-1);Se(this,h,p,E,q-1,-q)}var k=E-1,ae=1,le=0;for(this[p+k]=h&255;--k>=0&&(ae*=256);)h<0&&le===0&&this[p+k+1]!==0&&(le=1),this[p+k]=(h/ae>>0)-le&255;return p+E},s.prototype.writeInt8=function(h,p,E){return h=+h,p=p>>>0,E||Se(this,h,p,1,127,-128),h<0&&(h=255+h+1),this[p]=h&255,p+1},s.prototype.writeInt16LE=function(h,p,E){return h=+h,p=p>>>0,E||Se(this,h,p,2,32767,-32768),this[p]=h&255,this[p+1]=h>>>8,p+2},s.prototype.writeInt16BE=function(h,p,E){return h=+h,p=p>>>0,E||Se(this,h,p,2,32767,-32768),this[p]=h>>>8,this[p+1]=h&255,p+2},s.prototype.writeInt32LE=function(h,p,E){return h=+h,p=p>>>0,E||Se(this,h,p,4,2147483647,-2147483648),this[p]=h&255,this[p+1]=h>>>8,this[p+2]=h>>>16,this[p+3]=h>>>24,p+4},s.prototype.writeInt32BE=function(h,p,E){return h=+h,p=p>>>0,E||Se(this,h,p,4,2147483647,-2147483648),h<0&&(h=4294967295+h+1),this[p]=h>>>24,this[p+1]=h>>>16,this[p+2]=h>>>8,this[p+3]=h&255,p+4};function Fe(_,h,p,E,C,q){if(p+E>_.length)throw new RangeError("Index out of range");if(p<0)throw new RangeError("Index out of range")}function qe(_,h,p,E,C){return h=+h,p=p>>>0,C||Fe(_,h,p,4),Kn.write(_,h,p,E,23,4),p+4}s.prototype.writeFloatLE=function(h,p,E){return qe(this,h,p,!0,E)},s.prototype.writeFloatBE=function(h,p,E){return qe(this,h,p,!1,E)};function Ze(_,h,p,E,C){return h=+h,p=p>>>0,C||Fe(_,h,p,8),Kn.write(_,h,p,E,52,8),p+8}s.prototype.writeDoubleLE=function(h,p,E){return Ze(this,h,p,!0,E)},s.prototype.writeDoubleBE=function(h,p,E){return Ze(this,h,p,!1,E)},s.prototype.copy=function(h,p,E,C){if(!s.isBuffer(h))throw new TypeError("argument should be a Buffer");if(E||(E=0),!C&&C!==0&&(C=this.length),p>=h.length&&(p=h.length),p||(p=0),C>0&&C<E&&(C=E),C===E||h.length===0||this.length===0)return 0;if(p<0)throw new RangeError("targetStart out of bounds");if(E<0||E>=this.length)throw new RangeError("Index out of range");if(C<0)throw new RangeError("sourceEnd out of bounds");C>this.length&&(C=this.length),h.length-p<C-E&&(C=h.length-p+E);var q=C-E;return this===h&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(p,E,C):Uint8Array.prototype.set.call(h,this.subarray(E,C),p),q},s.prototype.fill=function(h,p,E,C){if(typeof h=="string"){if(typeof p=="string"?(C=p,p=0,E=this.length):typeof E=="string"&&(C=E,E=this.length),C!==void 0&&typeof C!="string")throw new TypeError("encoding must be a string");if(typeof C=="string"&&!s.isEncoding(C))throw new TypeError("Unknown encoding: "+C);if(h.length===1){var q=h.charCodeAt(0);(C==="utf8"&&q<128||C==="latin1")&&(h=q)}}else typeof h=="number"?h=h&255:typeof h=="boolean"&&(h=Number(h));if(p<0||this.length<p||this.length<E)throw new RangeError("Out of range index");if(E<=p)return this;p=p>>>0,E=E===void 0?this.length:E>>>0,h||(h=0);var k;if(typeof h=="number")for(k=p;k<E;++k)this[k]=h;else{var ae=s.isBuffer(h)?h:s.from(h,C),le=ae.length;if(le===0)throw new TypeError('The value "'+h+'" is invalid for argument "value"');for(k=0;k<E-p;++k)this[k+p]=ae[k%le]}return this};var Ne=/[^+/0-9A-Za-z-_]/g;function ue(_){if(_=_.split("=")[0],_=_.trim().replace(Ne,""),_.length<2)return"";for(;_.length%4!==0;)_=_+"=";return _}function je(_,h){h=h||1/0;for(var p,E=_.length,C=null,q=[],k=0;k<E;++k){if(p=_.charCodeAt(k),p>55295&&p<57344){if(!C){if(p>56319){(h-=3)>-1&&q.push(239,191,189);continue}else if(k+1===E){(h-=3)>-1&&q.push(239,191,189);continue}C=p;continue}if(p<56320){(h-=3)>-1&&q.push(239,191,189),C=p;continue}p=(C-55296<<10|p-56320)+65536}else C&&(h-=3)>-1&&q.push(239,191,189);if(C=null,p<128){if((h-=1)<0)break;q.push(p)}else if(p<2048){if((h-=2)<0)break;q.push(p>>6|192,p&63|128)}else if(p<65536){if((h-=3)<0)break;q.push(p>>12|224,p>>6&63|128,p&63|128)}else if(p<1114112){if((h-=4)<0)break;q.push(p>>18|240,p>>12&63|128,p>>6&63|128,p&63|128)}else throw new Error("Invalid code point")}return q}function me(_){for(var h=[],p=0;p<_.length;++p)h.push(_.charCodeAt(p)&255);return h}function Re(_,h){for(var p,E,C,q=[],k=0;k<_.length&&!((h-=2)<0);++k)p=_.charCodeAt(k),E=p>>8,C=p%256,q.push(C),q.push(E);return q}function ge(_){return ru.toByteArray(ue(_))}function Ae(_,h,p,E){for(var C=0;C<E&&!(C+p>=h.length||C>=_.length);++C)h[C+p]=_[C];return C}function Ue(_,h){return _ instanceof h||_!=null&&_.constructor!=null&&_.constructor.name!=null&&_.constructor.name===h.name}function Tt(_){return _!==_}var ot=function(){for(var _="0123456789abcdef",h=new Array(256),p=0;p<16;++p)for(var E=p*16,C=0;C<16;++C)h[E+C]=_[p]+_[C];return h}()}),ye=ua.Buffer;ua.SlowBuffer,ua.INSPECT_MAX_BYTES,ua.kMaxLength;/*! *****************************************************************************
41
+ Copyright (c) Microsoft Corporation.
42
+
43
+ Permission to use, copy, modify, and/or distribute this software for any
44
+ purpose with or without fee is hereby granted.
45
+
46
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
47
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
48
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
49
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
50
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
51
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
52
+ PERFORMANCE OF THIS SOFTWARE.
53
+ ***************************************************************************** */var nu=function(e,t){return nu=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)o.hasOwnProperty(i)&&(n[i]=o[i])},nu(e,t)};function ca(r,e){nu(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}var vn=function(r){ca(e,r);function e(t){var n=r.call(this,t)||this;return Object.setPrototypeOf(n,e.prototype),n}return Object.defineProperty(e.prototype,"name",{get:function(){return"BSONError"},enumerable:!1,configurable:!0}),e}(Error),Ce=function(r){ca(e,r);function e(t){var n=r.call(this,t)||this;return Object.setPrototypeOf(n,e.prototype),n}return Object.defineProperty(e.prototype,"name",{get:function(){return"BSONTypeError"},enumerable:!1,configurable:!0}),e}(TypeError);function la(r){return r&&r.Math==Math&&r}function Vd(){return la(typeof globalThis=="object"&&globalThis)||la(typeof window=="object"&&window)||la(typeof self=="object"&&self)||la(typeof global=="object"&&global)||Function("return this")()}function Rg(){var r=Vd();return typeof r.navigator=="object"&&r.navigator.product==="ReactNative"}var Cg=function(e){var t=Rg()?"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(t);for(var n=ye.alloc(e),o=0;o<e;++o)n[o]=Math.floor(Math.random()*256);return n},xg=function(){{if(typeof window<"u"){var r=window.crypto||window.msCrypto;if(r&&r.getRandomValues)return function(e){return r.getRandomValues(ye.alloc(e))}}return typeof global<"u"&&global.crypto&&global.crypto.getRandomValues?function(e){return global.crypto.getRandomValues(ye.alloc(e))}:Cg}},zd=xg();function Ng(r){return["[object ArrayBuffer]","[object SharedArrayBuffer]"].includes(Object.prototype.toString.call(r))}function iu(r){return Object.prototype.toString.call(r)==="[object Uint8Array]"}function Pg(r){return Object.prototype.toString.call(r)==="[object RegExp]"}function Dg(r){return qi(r)&&Object.prototype.toString.call(r)==="[object Date]"}function qi(r){return typeof r=="object"&&r!==null}function fa(r,e){var t=!1;function n(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];return t||(console.warn(e),t=!0),r.apply(this,o)}return n}function da(r){if(ArrayBuffer.isView(r))return ye.from(r.buffer,r.byteOffset,r.byteLength);if(Ng(r))return ye.from(r);throw new Ce("Must use either Buffer or TypedArray")}var Fg=/^(?:[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,Jd=function(r){return typeof r=="string"&&Fg.test(r)},ou=function(r){if(!Jd(r))throw new Ce('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=r.replace(/-/g,"");return ye.from(e,"hex")},Kd=function(r,e){return e===void 0&&(e=!0),e?r.toString("hex",0,4)+"-"+r.toString("hex",4,6)+"-"+r.toString("hex",6,8)+"-"+r.toString("hex",8,10)+"-"+r.toString("hex",10,16):r.toString("hex")},Ug=Math.pow(2,53),Bg=-Math.pow(2,53),Yd=4,_n=function(){function r(e,t){if(!(this instanceof r))return new r(e,t);if(e!=null&&typeof e!="string"&&!ArrayBuffer.isView(e)&&!(e instanceof ArrayBuffer)&&!Array.isArray(e))throw new Ce("Binary can only be constructed from string, Buffer, TypedArray, or Array<number>");this.sub_type=t??r.BSON_BINARY_SUBTYPE_DEFAULT,e==null?(this.buffer=ye.alloc(r.BUFFER_SIZE),this.position=0):(typeof e=="string"?this.buffer=ye.from(e,"binary"):Array.isArray(e)?this.buffer=ye.from(e):this.buffer=da(e),this.position=this.buffer.byteLength)}return r.prototype.put=function(e){if(typeof e=="string"&&e.length!==1)throw new Ce("only accepts single character String");if(typeof e!="number"&&e.length!==1)throw new Ce("only accepts single character Uint8Array or Array");var t;if(typeof e=="string"?t=e.charCodeAt(0):typeof e=="number"?t=e:t=e[0],t<0||t>255)throw new Ce("only accepts number in a valid unsigned byte range 0-255");if(this.buffer.length>this.position)this.buffer[this.position++]=t;else{var n=ye.alloc(r.BUFFER_SIZE+this.buffer.length);this.buffer.copy(n,0,0,this.buffer.length),this.buffer=n,this.buffer[this.position++]=t}},r.prototype.write=function(e,t){if(t=typeof t=="number"?t:this.position,this.buffer.length<t+e.length){var n=ye.alloc(this.buffer.length+e.length);this.buffer.copy(n,0,0,this.buffer.length),this.buffer=n}ArrayBuffer.isView(e)?(this.buffer.set(da(e),t),this.position=t+e.byteLength>this.position?t+e.length:this.position):typeof e=="string"&&(this.buffer.write(e,t,e.length,"binary"),this.position=t+e.length>this.position?t+e.length:this.position)},r.prototype.read=function(e,t){return t=t&&t>0?t:this.position,this.buffer.slice(e,e+t)},r.prototype.value=function(e){return e=!!e,e&&this.buffer.length===this.position?this.buffer:e?this.buffer.slice(0,this.position):this.buffer.toString("binary",0,this.position)},r.prototype.length=function(){return this.position},r.prototype.toJSON=function(){return this.buffer.toString("base64")},r.prototype.toString=function(e){return this.buffer.toString(e)},r.prototype.toExtendedJSON=function(e){e=e||{};var t=this.buffer.toString("base64"),n=Number(this.sub_type).toString(16);return e.legacy?{$binary:t,$type:n.length===1?"0"+n:n}:{$binary:{base64:t,subType:n.length===1?"0"+n:n}}},r.prototype.toUUID=function(){if(this.sub_type===r.SUBTYPE_UUID)return new Qd(this.buffer.slice(0,this.position));throw new vn('Binary sub_type "'.concat(this.sub_type,'" is not supported for converting to UUID. Only "').concat(r.SUBTYPE_UUID,'" is currently supported.'))},r.fromExtendedJSON=function(e,t){t=t||{};var n,o;if("$binary"in e?t.legacy&&typeof e.$binary=="string"&&"$type"in e?(o=e.$type?parseInt(e.$type,16):0,n=ye.from(e.$binary,"base64")):typeof e.$binary!="string"&&(o=e.$binary.subType?parseInt(e.$binary.subType,16):0,n=ye.from(e.$binary.base64,"base64")):"$uuid"in e&&(o=4,n=ou(e.$uuid)),!n)throw new Ce("Unexpected Binary Extended JSON format ".concat(JSON.stringify(e)));return o===Yd?new Qd(n):new r(n,o)},r.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},r.prototype.inspect=function(){var e=this.value(!0);return'new Binary(Buffer.from("'.concat(e.toString("hex"),'", "hex"), ').concat(this.sub_type,")")},r.BSON_BINARY_SUBTYPE_DEFAULT=0,r.BUFFER_SIZE=256,r.SUBTYPE_DEFAULT=0,r.SUBTYPE_FUNCTION=1,r.SUBTYPE_BYTE_ARRAY=2,r.SUBTYPE_UUID_OLD=3,r.SUBTYPE_UUID=4,r.SUBTYPE_MD5=5,r.SUBTYPE_ENCRYPTED=6,r.SUBTYPE_COLUMN=7,r.SUBTYPE_USER_DEFINED=128,r}();Object.defineProperty(_n.prototype,"_bsontype",{value:"Binary"});var au=16,Qd=function(r){ca(e,r);function e(t){var n=this,o,i;if(t==null)o=e.generate();else if(t instanceof e)o=ye.from(t.buffer),i=t.__id;else if(ArrayBuffer.isView(t)&&t.byteLength===au)o=da(t);else if(typeof t=="string")o=ou(t);else throw new Ce("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).");return n=r.call(this,o,Yd)||this,n.__id=i,n}return Object.defineProperty(e.prototype,"id",{get:function(){return this.buffer},set:function(t){this.buffer=t,e.cacheHexString&&(this.__id=Kd(t))},enumerable:!1,configurable:!0}),e.prototype.toHexString=function(t){if(t===void 0&&(t=!0),e.cacheHexString&&this.__id)return this.__id;var n=Kd(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{return!1}},e.prototype.toBinary=function(){return new _n(this.id,_n.SUBTYPE_UUID)},e.generate=function(){var t=zd(au);return t[6]=t[6]&15|64,t[8]=t[8]&63|128,ye.from(t)},e.isValid=function(t){return t?t instanceof e?!0:typeof t=="string"?Jd(t):iu(t)?t.length!==au?!1:(t[6]&240)===64&&(t[8]&128)===128:!1:!1},e.createFromHexString=function(t){var n=ou(t);return new e(n)},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){return'new UUID("'.concat(this.toHexString(),'")')},e}(_n),ha=function(){function r(e,t){if(!(this instanceof r))return new r(e,t);this.code=e,this.scope=t}return r.prototype.toJSON=function(){return{code:this.code,scope:this.scope}},r.prototype.toExtendedJSON=function(){return this.scope?{$code:this.code,$scope:this.scope}:{$code:this.code}},r.fromExtendedJSON=function(e){return new r(e.$code,e.$scope)},r.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},r.prototype.inspect=function(){var e=this.toJSON();return'new Code("'.concat(String(e.code),'"').concat(e.scope?", ".concat(JSON.stringify(e.scope)):"",")")},r}();Object.defineProperty(ha.prototype,"_bsontype",{value:"Code"});function Lg(r){return qi(r)&&r.$id!=null&&typeof r.$ref=="string"&&(r.$db==null||typeof r.$db=="string")}var ji=function(){function r(e,t,n,o){if(!(this instanceof r))return new r(e,t,n,o);var i=e.split(".");i.length===2&&(n=i.shift(),e=i.shift()),this.collection=e,this.oid=t,this.db=n,this.fields=o||{}}return Object.defineProperty(r.prototype,"namespace",{get:function(){return this.collection},set:function(e){this.collection=e},enumerable:!1,configurable:!0}),r.prototype.toJSON=function(){var e=Object.assign({$ref:this.collection,$id:this.oid},this.fields);return this.db!=null&&(e.$db=this.db),e},r.prototype.toExtendedJSON=function(e){e=e||{};var t={$ref:this.collection,$id:this.oid};return e.legacy||(this.db&&(t.$db=this.db),t=Object.assign(t,this.fields)),t},r.fromExtendedJSON=function(e){var t=Object.assign({},e);return delete t.$ref,delete t.$id,delete t.$db,new r(e.$ref,e.$id,e.$db,t)},r.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},r.prototype.inspect=function(){var e=this.oid===void 0||this.oid.toString===void 0?this.oid:this.oid.toString();return'new DBRef("'.concat(this.namespace,'", new ObjectId("').concat(String(e),'")').concat(this.db?', "'.concat(this.db,'"'):"",")")},r}();Object.defineProperty(ji.prototype,"_bsontype",{value:"DBRef"});var Ut=void 0;try{Ut=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{}var Xd=65536,Mg=1<<24,Yn=Xd*Xd,Zd=Yn*Yn,eh=Zd/2,th={},rh={},X=function(){function r(e,t,n){if(e===void 0&&(e=0),!(this instanceof r))return new r(e,t,n);typeof e=="bigint"?Object.assign(this,r.fromBigInt(e,!!t)):typeof e=="string"?Object.assign(this,r.fromString(e,!!t)):(this.low=e|0,this.high=t|0,this.unsigned=!!n),Object.defineProperty(this,"__isLong__",{value:!0,configurable:!1,writable:!1,enumerable:!1})}return r.fromBits=function(e,t,n){return new r(e,t,n)},r.fromInt=function(e,t){var n,o,i;return t?(e>>>=0,(i=0<=e&&e<256)&&(o=rh[e],o)?o:(n=r.fromBits(e,(e|0)<0?-1:0,!0),i&&(rh[e]=n),n)):(e|=0,(i=-128<=e&&e<128)&&(o=th[e],o)?o:(n=r.fromBits(e,e<0?-1:0,!1),i&&(th[e]=n),n))},r.fromNumber=function(e,t){if(isNaN(e))return t?r.UZERO:r.ZERO;if(t){if(e<0)return r.UZERO;if(e>=Zd)return r.MAX_UNSIGNED_VALUE}else{if(e<=-eh)return r.MIN_VALUE;if(e+1>=eh)return r.MAX_VALUE}return e<0?r.fromNumber(-e,t).neg():r.fromBits(e%Yn|0,e/Yn|0,t)},r.fromBigInt=function(e,t){return r.fromString(e.toString(),t)},r.fromString=function(e,t,n){if(e.length===0)throw Error("empty string");if(e==="NaN"||e==="Infinity"||e==="+Infinity"||e==="-Infinity")return r.ZERO;if(typeof t=="number"?(n=t,t=!1):t=!!t,n=n||10,n<2||36<n)throw RangeError("radix");var o;if((o=e.indexOf("-"))>0)throw Error("interior hyphen");if(o===0)return r.fromString(e.substring(1),t,n).neg();for(var i=r.fromNumber(Math.pow(n,8)),s=r.ZERO,c=0;c<e.length;c+=8){var l=Math.min(8,e.length-c),a=parseInt(e.substring(c,c+l),n);if(l<8){var u=r.fromNumber(Math.pow(n,l));s=s.mul(u).add(r.fromNumber(a))}else s=s.mul(i),s=s.add(r.fromNumber(a))}return s.unsigned=t,s},r.fromBytes=function(e,t,n){return n?r.fromBytesLE(e,t):r.fromBytesBE(e,t)},r.fromBytesLE=function(e,t){return new r(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)},r.fromBytesBE=function(e,t){return new r(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)},r.isLong=function(e){return qi(e)&&e.__isLong__===!0},r.fromValue=function(e,t){return typeof e=="number"?r.fromNumber(e,t):typeof e=="string"?r.fromString(e,t):r.fromBits(e.low,e.high,typeof t=="boolean"?t:e.unsigned)},r.prototype.add=function(e){r.isLong(e)||(e=r.fromValue(e));var t=this.high>>>16,n=this.high&65535,o=this.low>>>16,i=this.low&65535,s=e.high>>>16,c=e.high&65535,l=e.low>>>16,a=e.low&65535,u=0,f=0,d=0,y=0;return y+=i+a,d+=y>>>16,y&=65535,d+=o+l,f+=d>>>16,d&=65535,f+=n+c,u+=f>>>16,f&=65535,u+=t+s,u&=65535,r.fromBits(d<<16|y,u<<16|f,this.unsigned)},r.prototype.and=function(e){return r.isLong(e)||(e=r.fromValue(e)),r.fromBits(this.low&e.low,this.high&e.high,this.unsigned)},r.prototype.compare=function(e){if(r.isLong(e)||(e=r.fromValue(e)),this.eq(e))return 0;var t=this.isNegative(),n=e.isNegative();return t&&!n?-1:!t&&n?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},r.prototype.comp=function(e){return this.compare(e)},r.prototype.divide=function(e){if(r.isLong(e)||(e=r.fromValue(e)),e.isZero())throw Error("division by zero");if(Ut){if(!this.unsigned&&this.high===-2147483648&&e.low===-1&&e.high===-1)return this;var t=(this.unsigned?Ut.div_u:Ut.div_s)(this.low,this.high,e.low,e.high);return r.fromBits(t,Ut.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?r.UZERO:r.ZERO;var n,o,i;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return r.UZERO;if(e.gt(this.shru(1)))return r.UONE;i=r.UZERO}else{if(this.eq(r.MIN_VALUE)){if(e.eq(r.ONE)||e.eq(r.NEG_ONE))return r.MIN_VALUE;if(e.eq(r.MIN_VALUE))return r.ONE;var s=this.shr(1);return n=s.div(e).shl(1),n.eq(r.ZERO)?e.isNegative()?r.ONE:r.NEG_ONE:(o=this.sub(e.mul(n)),i=n.add(o.div(e)),i)}else if(e.eq(r.MIN_VALUE))return this.unsigned?r.UZERO:r.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=r.ZERO}for(o=this;o.gte(e);){n=Math.max(1,Math.floor(o.toNumber()/e.toNumber()));for(var c=Math.ceil(Math.log(n)/Math.LN2),l=c<=48?1:Math.pow(2,c-48),a=r.fromNumber(n),u=a.mul(e);u.isNegative()||u.gt(o);)n-=l,a=r.fromNumber(n,this.unsigned),u=a.mul(e);a.isZero()&&(a=r.ONE),i=i.add(a),o=o.sub(u)}return i},r.prototype.div=function(e){return this.divide(e)},r.prototype.equals=function(e){return r.isLong(e)||(e=r.fromValue(e)),this.unsigned!==e.unsigned&&this.high>>>31===1&&e.high>>>31===1?!1:this.high===e.high&&this.low===e.low},r.prototype.eq=function(e){return this.equals(e)},r.prototype.getHighBits=function(){return this.high},r.prototype.getHighBitsUnsigned=function(){return this.high>>>0},r.prototype.getLowBits=function(){return this.low},r.prototype.getLowBitsUnsigned=function(){return this.low>>>0},r.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.eq(r.MIN_VALUE)?64:this.neg().getNumBitsAbs();var e=this.high!==0?this.high:this.low,t;for(t=31;t>0&&(e&1<<t)===0;t--);return this.high!==0?t+33:t+1},r.prototype.greaterThan=function(e){return this.comp(e)>0},r.prototype.gt=function(e){return this.greaterThan(e)},r.prototype.greaterThanOrEqual=function(e){return this.comp(e)>=0},r.prototype.gte=function(e){return this.greaterThanOrEqual(e)},r.prototype.ge=function(e){return this.greaterThanOrEqual(e)},r.prototype.isEven=function(){return(this.low&1)===0},r.prototype.isNegative=function(){return!this.unsigned&&this.high<0},r.prototype.isOdd=function(){return(this.low&1)===1},r.prototype.isPositive=function(){return this.unsigned||this.high>=0},r.prototype.isZero=function(){return this.high===0&&this.low===0},r.prototype.lessThan=function(e){return this.comp(e)<0},r.prototype.lt=function(e){return this.lessThan(e)},r.prototype.lessThanOrEqual=function(e){return this.comp(e)<=0},r.prototype.lte=function(e){return this.lessThanOrEqual(e)},r.prototype.modulo=function(e){if(r.isLong(e)||(e=r.fromValue(e)),Ut){var t=(this.unsigned?Ut.rem_u:Ut.rem_s)(this.low,this.high,e.low,e.high);return r.fromBits(t,Ut.get_high(),this.unsigned)}return this.sub(this.div(e).mul(e))},r.prototype.mod=function(e){return this.modulo(e)},r.prototype.rem=function(e){return this.modulo(e)},r.prototype.multiply=function(e){if(this.isZero())return r.ZERO;if(r.isLong(e)||(e=r.fromValue(e)),Ut){var t=Ut.mul(this.low,this.high,e.low,e.high);return r.fromBits(t,Ut.get_high(),this.unsigned)}if(e.isZero())return r.ZERO;if(this.eq(r.MIN_VALUE))return e.isOdd()?r.MIN_VALUE:r.ZERO;if(e.eq(r.MIN_VALUE))return this.isOdd()?r.MIN_VALUE:r.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(r.TWO_PWR_24)&&e.lt(r.TWO_PWR_24))return r.fromNumber(this.toNumber()*e.toNumber(),this.unsigned);var n=this.high>>>16,o=this.high&65535,i=this.low>>>16,s=this.low&65535,c=e.high>>>16,l=e.high&65535,a=e.low>>>16,u=e.low&65535,f=0,d=0,y=0,m=0;return m+=s*u,y+=m>>>16,m&=65535,y+=i*u,d+=y>>>16,y&=65535,y+=s*a,d+=y>>>16,y&=65535,d+=o*u,f+=d>>>16,d&=65535,d+=i*a,f+=d>>>16,d&=65535,d+=s*l,f+=d>>>16,d&=65535,f+=n*u+o*a+i*l+s*c,f&=65535,r.fromBits(y<<16|m,f<<16|d,this.unsigned)},r.prototype.mul=function(e){return this.multiply(e)},r.prototype.negate=function(){return!this.unsigned&&this.eq(r.MIN_VALUE)?r.MIN_VALUE:this.not().add(r.ONE)},r.prototype.neg=function(){return this.negate()},r.prototype.not=function(){return r.fromBits(~this.low,~this.high,this.unsigned)},r.prototype.notEquals=function(e){return!this.equals(e)},r.prototype.neq=function(e){return this.notEquals(e)},r.prototype.ne=function(e){return this.notEquals(e)},r.prototype.or=function(e){return r.isLong(e)||(e=r.fromValue(e)),r.fromBits(this.low|e.low,this.high|e.high,this.unsigned)},r.prototype.shiftLeft=function(e){return r.isLong(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?r.fromBits(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):r.fromBits(0,this.low<<e-32,this.unsigned)},r.prototype.shl=function(e){return this.shiftLeft(e)},r.prototype.shiftRight=function(e){return r.isLong(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?r.fromBits(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):r.fromBits(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},r.prototype.shr=function(e){return this.shiftRight(e)},r.prototype.shiftRightUnsigned=function(e){if(r.isLong(e)&&(e=e.toInt()),e&=63,e===0)return this;var t=this.high;if(e<32){var n=this.low;return r.fromBits(n>>>e|t<<32-e,t>>>e,this.unsigned)}else return e===32?r.fromBits(t,0,this.unsigned):r.fromBits(t>>>e-32,0,this.unsigned)},r.prototype.shr_u=function(e){return this.shiftRightUnsigned(e)},r.prototype.shru=function(e){return this.shiftRightUnsigned(e)},r.prototype.subtract=function(e){return r.isLong(e)||(e=r.fromValue(e)),this.add(e.neg())},r.prototype.sub=function(e){return this.subtract(e)},r.prototype.toInt=function(){return this.unsigned?this.low>>>0:this.low},r.prototype.toNumber=function(){return this.unsigned?(this.high>>>0)*Yn+(this.low>>>0):this.high*Yn+(this.low>>>0)},r.prototype.toBigInt=function(){return BigInt(this.toString())},r.prototype.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},r.prototype.toBytesLE=function(){var e=this.high,t=this.low;return[t&255,t>>>8&255,t>>>16&255,t>>>24,e&255,e>>>8&255,e>>>16&255,e>>>24]},r.prototype.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,e&255,t>>>24,t>>>16&255,t>>>8&255,t&255]},r.prototype.toSigned=function(){return this.unsigned?r.fromBits(this.low,this.high,!1):this},r.prototype.toString=function(e){if(e=e||10,e<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative())if(this.eq(r.MIN_VALUE)){var t=r.fromNumber(e),n=this.div(t),o=n.mul(t).sub(this);return n.toString(e)+o.toInt().toString(e)}else return"-"+this.neg().toString(e);for(var i=r.fromNumber(Math.pow(e,6),this.unsigned),s=this,c="";;){var l=s.div(i),a=s.sub(l.mul(i)).toInt()>>>0,u=a.toString(e);if(s=l,s.isZero())return u+c;for(;u.length<6;)u="0"+u;c=""+u+c}},r.prototype.toUnsigned=function(){return this.unsigned?this:r.fromBits(this.low,this.high,!0)},r.prototype.xor=function(e){return r.isLong(e)||(e=r.fromValue(e)),r.fromBits(this.low^e.low,this.high^e.high,this.unsigned)},r.prototype.eqz=function(){return this.isZero()},r.prototype.le=function(e){return this.lessThanOrEqual(e)},r.prototype.toExtendedJSON=function(e){return e&&e.relaxed?this.toNumber():{$numberLong:this.toString()}},r.fromExtendedJSON=function(e,t){var n=r.fromString(e.$numberLong);return t&&t.relaxed?n.toNumber():n},r.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},r.prototype.inspect=function(){return'new Long("'.concat(this.toString(),'"').concat(this.unsigned?", true":"",")")},r.TWO_PWR_24=r.fromInt(Mg),r.MAX_UNSIGNED_VALUE=r.fromBits(-1,-1,!0),r.ZERO=r.fromInt(0),r.UZERO=r.fromInt(0,!0),r.ONE=r.fromInt(1),r.UONE=r.fromInt(1,!0),r.NEG_ONE=r.fromInt(-1),r.MAX_VALUE=r.fromBits(-1,2147483647,!1),r.MIN_VALUE=r.fromBits(0,-2147483648,!1),r}();Object.defineProperty(X.prototype,"__isLong__",{value:!0}),Object.defineProperty(X.prototype,"_bsontype",{value:"Long"});var qg=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,jg=/^(\+|-)?(Infinity|inf)$/i,kg=/^(\+|-)?NaN$/i,ki=6111,su=-6176,nh=6176,$g=34,uu=[124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),ih=[248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),oh=[120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),Wg=/^([-+])?(\d+)?$/,Hg=31,ah=16383,Gg=30,Vg=31;function sh(r){return!isNaN(parseInt(r,10))}function zg(r){var e=X.fromNumber(1e9),t=X.fromNumber(0);if(!r.parts[0]&&!r.parts[1]&&!r.parts[2]&&!r.parts[3])return{quotient:r,rem:t};for(var n=0;n<=3;n++)t=t.shiftLeft(32),t=t.add(new X(r.parts[n],0)),r.parts[n]=t.div(e).low,t=t.modulo(e);return{quotient:r,rem:t}}function Jg(r,e){if(!r&&!e)return{high:X.fromNumber(0),low:X.fromNumber(0)};var t=r.shiftRightUnsigned(32),n=new X(r.getLowBits(),0),o=e.shiftRightUnsigned(32),i=new X(e.getLowBits(),0),s=t.multiply(o),c=t.multiply(i),l=n.multiply(o),a=n.multiply(i);return s=s.add(c.shiftRightUnsigned(32)),c=new X(c.getLowBits(),0).add(l).add(a.shiftRightUnsigned(32)),s=s.add(c.shiftRightUnsigned(32)),a=c.shiftLeft(32).add(new X(a.getLowBits(),0)),{high:s,low:a}}function Kg(r,e){var t=r.high>>>0,n=e.high>>>0;if(t<n)return!0;if(t===n){var o=r.low>>>0,i=e.low>>>0;if(o<i)return!0}return!1}function Qn(r,e){throw new Ce('"'.concat(r,'" is not a valid Decimal128 string - ').concat(e))}var cu=function(){function r(e){if(!(this instanceof r))return new r(e);if(typeof e=="string")this.bytes=r.fromString(e).bytes;else if(iu(e)){if(e.byteLength!==16)throw new Ce("Decimal128 must take a Buffer of 16 bytes");this.bytes=e}else throw new Ce("Decimal128 must take a Buffer or string")}return r.fromString=function(e){var t=!1,n=!1,o=!1,i=0,s=0,c=0,l=0,a=0,u=[0],f=0,d=0,y=0,m=0,v=0,I=0,S=new X(0,0),w=new X(0,0),O=0,T=0;if(e.length>=7e3)throw new Ce(""+e+" not a valid Decimal128 string");var N=e.match(qg),D=e.match(jg),B=e.match(kg);if(!N&&!D&&!B||e.length===0)throw new Ce(""+e+" not a valid Decimal128 string");if(N){var R=N[2],x=N[4],L=N[5],F=N[6];x&&F===void 0&&Qn(e,"missing exponent power"),x&&R===void 0&&Qn(e,"missing exponent base"),x===void 0&&(L||F)&&Qn(e,"missing e before exponent")}if((e[T]==="+"||e[T]==="-")&&(t=e[T++]==="-"),!sh(e[T])&&e[T]!=="."){if(e[T]==="i"||e[T]==="I")return new r(ye.from(t?ih:oh));if(e[T]==="N")return new r(ye.from(uu))}for(;sh(e[T])||e[T]===".";){if(e[T]==="."){n&&Qn(e,"contains multiple periods"),n=!0,T=T+1;continue}f<34&&(e[T]!=="0"||o)&&(o||(a=s),o=!0,u[d++]=parseInt(e[T],10),f=f+1),o&&(c=c+1),n&&(l=l+1),s=s+1,T=T+1}if(n&&!s)throw new Ce(""+e+" not a valid Decimal128 string");if(e[T]==="e"||e[T]==="E"){var j=e.substr(++T).match(Wg);if(!j||!j[2])return new r(ye.from(uu));v=parseInt(j[0],10),T=T+j[0].length}if(e[T])return new r(ye.from(uu));if(y=0,!f)y=0,m=0,u[0]=0,c=1,f=1,i=0;else if(m=f-1,i=c,i!==1)for(;u[a+i-1]===0;)i=i-1;for(v<=l&&l-v>16384?v=su:v=v-l;v>ki;){if(m=m+1,m-y>$g){var V=u.join("");if(V.match(/^0+$/)){v=ki;break}Qn(e,"overflow")}v=v-1}for(;v<su||f<c;){if(m===0&&i<f){v=su,i=0;break}if(f<c?c=c-1:m=m-1,v<ki)v=v+1;else{var V=u.join("");if(V.match(/^0+$/)){v=ki;break}Qn(e,"overflow")}}if(m-y+1<i){var W=s;n&&(a=a+1,W=W+1),t&&(a=a+1,W=W+1);var oe=parseInt(e[a+m+1],10),se=0;if(oe>=5&&(se=1,oe===5)){for(se=u[m]%2===1?1:0,I=a+m+2;I<W;I++)if(parseInt(e[I],10)){se=1;break}}if(se){for(var Z=m;Z>=0;Z--)if(++u[Z]>9&&(u[Z]=0,Z===0))if(v<ki)v=v+1,u[Z]=1;else return new r(ye.from(t?ih:oh))}}if(S=X.fromNumber(0),w=X.fromNumber(0),i===0)S=X.fromNumber(0),w=X.fromNumber(0);else if(m-y<17){var Z=y;for(w=X.fromNumber(u[Z++]),S=new X(0,0);Z<=m;Z++)w=w.multiply(X.fromNumber(10)),w=w.add(X.fromNumber(u[Z]))}else{var Z=y;for(S=X.fromNumber(u[Z++]);Z<=m-17;Z++)S=S.multiply(X.fromNumber(10)),S=S.add(X.fromNumber(u[Z]));for(w=X.fromNumber(u[Z++]);Z<=m;Z++)w=w.multiply(X.fromNumber(10)),w=w.add(X.fromNumber(u[Z]))}var ee=Jg(S,X.fromString("100000000000000000"));ee.low=ee.low.add(w),Kg(ee.low,w)&&(ee.high=ee.high.add(X.fromNumber(1))),O=v+nh;var Y={low:X.fromNumber(0),high:X.fromNumber(0)};ee.high.shiftRightUnsigned(49).and(X.fromNumber(1)).equals(X.fromNumber(1))?(Y.high=Y.high.or(X.fromNumber(3).shiftLeft(61)),Y.high=Y.high.or(X.fromNumber(O).and(X.fromNumber(16383).shiftLeft(47))),Y.high=Y.high.or(ee.high.and(X.fromNumber(0x7fffffffffff)))):(Y.high=Y.high.or(X.fromNumber(O&16383).shiftLeft(49)),Y.high=Y.high.or(ee.high.and(X.fromNumber(562949953421311)))),Y.low=ee.low,t&&(Y.high=Y.high.or(X.fromString("9223372036854775808")));var G=ye.alloc(16);return T=0,G[T++]=Y.low.low&255,G[T++]=Y.low.low>>8&255,G[T++]=Y.low.low>>16&255,G[T++]=Y.low.low>>24&255,G[T++]=Y.low.high&255,G[T++]=Y.low.high>>8&255,G[T++]=Y.low.high>>16&255,G[T++]=Y.low.high>>24&255,G[T++]=Y.high.low&255,G[T++]=Y.high.low>>8&255,G[T++]=Y.high.low>>16&255,G[T++]=Y.high.low>>24&255,G[T++]=Y.high.high&255,G[T++]=Y.high.high>>8&255,G[T++]=Y.high.high>>16&255,G[T++]=Y.high.high>>24&255,new r(G)},r.prototype.toString=function(){for(var e,t=0,n=new Array(36),o=0;o<n.length;o++)n[o]=0;var i=0,s=!1,c,l={parts:[0,0,0,0]},a,u,f=[];i=0;var d=this.bytes,y=d[i++]|d[i++]<<8|d[i++]<<16|d[i++]<<24,m=d[i++]|d[i++]<<8|d[i++]<<16|d[i++]<<24,v=d[i++]|d[i++]<<8|d[i++]<<16|d[i++]<<24,I=d[i++]|d[i++]<<8|d[i++]<<16|d[i++]<<24;i=0;var S={low:new X(y,m),high:new X(v,I)};S.high.lessThan(X.ZERO)&&f.push("-");var w=I>>26&Hg;if(w>>3===3){if(w===Gg)return f.join("")+"Infinity";if(w===Vg)return"NaN";e=I>>15&ah,c=8+(I>>14&1)}else c=I>>14&7,e=I>>17&ah;var O=e-nh;if(l.parts[0]=(I&16383)+((c&15)<<14),l.parts[1]=v,l.parts[2]=m,l.parts[3]=y,l.parts[0]===0&&l.parts[1]===0&&l.parts[2]===0&&l.parts[3]===0)s=!0;else for(u=3;u>=0;u--){var T=0,N=zg(l);if(l=N.quotient,T=N.rem.low,!!T)for(a=8;a>=0;a--)n[u*9+a]=T%10,T=Math.floor(T/10)}if(s)t=1,n[i]=0;else for(t=36;!n[i];)t=t-1,i=i+1;var D=t-1+O;if(D>=34||D<=-7||O>0){if(t>34)return f.push("".concat(0)),O>0?f.push("E+".concat(O)):O<0&&f.push("E".concat(O)),f.join("");f.push("".concat(n[i++])),t=t-1,t&&f.push(".");for(var o=0;o<t;o++)f.push("".concat(n[i++]));f.push("E"),D>0?f.push("+".concat(D)):f.push("".concat(D))}else if(O>=0)for(var o=0;o<t;o++)f.push("".concat(n[i++]));else{var B=t+O;if(B>0)for(var o=0;o<B;o++)f.push("".concat(n[i++]));else f.push("0");for(f.push(".");B++<0;)f.push("0");for(var o=0;o<t-Math.max(B-1,0);o++)f.push("".concat(n[i++]))}return f.join("")},r.prototype.toJSON=function(){return{$numberDecimal:this.toString()}},r.prototype.toExtendedJSON=function(){return{$numberDecimal:this.toString()}},r.fromExtendedJSON=function(e){return r.fromString(e.$numberDecimal)},r.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},r.prototype.inspect=function(){return'new Decimal128("'.concat(this.toString(),'")')},r}();Object.defineProperty(cu.prototype,"_bsontype",{value:"Decimal128"});var pa=function(){function r(e){if(!(this instanceof r))return new r(e);e instanceof Number&&(e=e.valueOf()),this.value=+e}return r.prototype.valueOf=function(){return this.value},r.prototype.toJSON=function(){return this.value},r.prototype.toString=function(e){return this.value.toString(e)},r.prototype.toExtendedJSON=function(e){return e&&(e.legacy||e.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()}},r.fromExtendedJSON=function(e,t){var n=parseFloat(e.$numberDouble);return t&&t.relaxed?n:new r(n)},r.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},r.prototype.inspect=function(){var e=this.toExtendedJSON();return"new Double(".concat(e.$numberDouble,")")},r}();Object.defineProperty(pa.prototype,"_bsontype",{value:"Double"});var ya=function(){function r(e){if(!(this instanceof r))return new r(e);e instanceof Number&&(e=e.valueOf()),this.value=+e|0}return r.prototype.valueOf=function(){return this.value},r.prototype.toString=function(e){return this.value.toString(e)},r.prototype.toJSON=function(){return this.value},r.prototype.toExtendedJSON=function(e){return e&&(e.relaxed||e.legacy)?this.value:{$numberInt:this.value.toString()}},r.fromExtendedJSON=function(e,t){return t&&t.relaxed?parseInt(e.$numberInt,10):new r(e.$numberInt)},r.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},r.prototype.inspect=function(){return"new Int32(".concat(this.valueOf(),")")},r}();Object.defineProperty(ya.prototype,"_bsontype",{value:"Int32"});var lu=function(){function r(){if(!(this instanceof r))return new r}return r.prototype.toExtendedJSON=function(){return{$maxKey:1}},r.fromExtendedJSON=function(){return new r},r.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},r.prototype.inspect=function(){return"new MaxKey()"},r}();Object.defineProperty(lu.prototype,"_bsontype",{value:"MaxKey"});var fu=function(){function r(){if(!(this instanceof r))return new r}return r.prototype.toExtendedJSON=function(){return{$minKey:1}},r.fromExtendedJSON=function(){return new r},r.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},r.prototype.inspect=function(){return"new MinKey()"},r}();Object.defineProperty(fu.prototype,"_bsontype",{value:"MinKey"});var Yg=new RegExp("^[0-9a-fA-F]{24}$"),bn=null,ir=Symbol("id"),Bt=function(){function r(e){if(!(this instanceof r))return new r(e);var t;if(typeof e=="object"&&e&&"id"in e){if(typeof e.id!="string"&&!ArrayBuffer.isView(e.id))throw new Ce("Argument passed in must have an id that is of type string or Buffer");"toHexString"in e&&typeof e.toHexString=="function"?t=ye.from(e.toHexString(),"hex"):t=e.id}else t=e;if(t==null||typeof t=="number")this[ir]=r.generate(typeof t=="number"?t:void 0);else if(ArrayBuffer.isView(t)&&t.byteLength===12)this[ir]=t instanceof ye?t:da(t);else if(typeof t=="string")if(t.length===12){var n=ye.from(t);if(n.byteLength===12)this[ir]=n;else throw new Ce("Argument passed in must be a string of 12 bytes")}else if(t.length===24&&Yg.test(t))this[ir]=ye.from(t,"hex");else throw new Ce("Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer");else throw new Ce("Argument passed in does not match the accepted types");r.cacheHexString&&(this.__id=this.id.toString("hex"))}return Object.defineProperty(r.prototype,"id",{get:function(){return this[ir]},set:function(e){this[ir]=e,r.cacheHexString&&(this.__id=e.toString("hex"))},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"generationTime",{get:function(){return this.id.readInt32BE(0)},set:function(e){this.id.writeUInt32BE(e,0)},enumerable:!1,configurable:!0}),r.prototype.toHexString=function(){if(r.cacheHexString&&this.__id)return this.__id;var e=this.id.toString("hex");return r.cacheHexString&&!this.__id&&(this.__id=e),e},r.getInc=function(){return r.index=(r.index+1)%16777215},r.generate=function(e){typeof e!="number"&&(e=Math.floor(Date.now()/1e3));var t=r.getInc(),n=ye.alloc(12);return n.writeUInt32BE(e,0),bn===null&&(bn=zd(5)),n[4]=bn[0],n[5]=bn[1],n[6]=bn[2],n[7]=bn[3],n[8]=bn[4],n[11]=t&255,n[10]=t>>8&255,n[9]=t>>16&255,n},r.prototype.toString=function(e){return e?this.id.toString(e):this.toHexString()},r.prototype.toJSON=function(){return this.toHexString()},r.prototype.equals=function(e){if(e==null)return!1;if(e instanceof r)return this[ir][11]===e[ir][11]&&this[ir].equals(e[ir]);if(typeof e=="string"&&r.isValid(e)&&e.length===12&&iu(this.id))return e===ye.prototype.toString.call(this.id,"latin1");if(typeof e=="string"&&r.isValid(e)&&e.length===24)return e.toLowerCase()===this.toHexString();if(typeof e=="string"&&r.isValid(e)&&e.length===12)return ye.from(e).equals(this.id);if(typeof e=="object"&&"toHexString"in e&&typeof e.toHexString=="function"){var t=e.toHexString(),n=this.toHexString().toLowerCase();return typeof t=="string"&&t.toLowerCase()===n}return!1},r.prototype.getTimestamp=function(){var e=new Date,t=this.id.readUInt32BE(0);return e.setTime(Math.floor(t)*1e3),e},r.createPk=function(){return new r},r.createFromTime=function(e){var t=ye.from([0,0,0,0,0,0,0,0,0,0,0,0]);return t.writeUInt32BE(e,0),new r(t)},r.createFromHexString=function(e){if(typeof e>"u"||e!=null&&e.length!==24)throw new Ce("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");return new r(ye.from(e,"hex"))},r.isValid=function(e){if(e==null)return!1;try{return new r(e),!0}catch{return!1}},r.prototype.toExtendedJSON=function(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}},r.fromExtendedJSON=function(e){return new r(e.$oid)},r.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},r.prototype.inspect=function(){return'new ObjectId("'.concat(this.toHexString(),'")')},r.index=Math.floor(Math.random()*16777215),r}();Object.defineProperty(Bt.prototype,"generate",{value:fa(function(r){return Bt.generate(r)},"Please use the static `ObjectId.generate(time)` instead")}),Object.defineProperty(Bt.prototype,"getInc",{value:fa(function(){return Bt.getInc()},"Please use the static `ObjectId.getInc()` instead")}),Object.defineProperty(Bt.prototype,"get_inc",{value:fa(function(){return Bt.getInc()},"Please use the static `ObjectId.getInc()` instead")}),Object.defineProperty(Bt,"get_inc",{value:fa(function(){return Bt.getInc()},"Please use the static `ObjectId.getInc()` instead")}),Object.defineProperty(Bt.prototype,"_bsontype",{value:"ObjectID"});function Qg(r){return r.split("").sort().join("")}var $i=function(){function r(e,t){if(!(this instanceof r))return new r(e,t);if(this.pattern=e,this.options=Qg(t??""),this.pattern.indexOf("\0")!==-1)throw new vn("BSON Regex patterns cannot contain null bytes, found: ".concat(JSON.stringify(this.pattern)));if(this.options.indexOf("\0")!==-1)throw new vn("BSON Regex options cannot contain null bytes, found: ".concat(JSON.stringify(this.options)));for(var n=0;n<this.options.length;n++)if(!(this.options[n]==="i"||this.options[n]==="m"||this.options[n]==="x"||this.options[n]==="l"||this.options[n]==="s"||this.options[n]==="u"))throw new vn("The regular expression option [".concat(this.options[n],"] is not supported"))}return r.parseOptions=function(e){return e?e.split("").sort().join(""):""},r.prototype.toExtendedJSON=function(e){return e=e||{},e.legacy?{$regex:this.pattern,$options:this.options}:{$regularExpression:{pattern:this.pattern,options:this.options}}},r.fromExtendedJSON=function(e){if("$regex"in e)if(typeof e.$regex!="string"){if(e.$regex._bsontype==="BSONRegExp")return e}else return new r(e.$regex,r.parseOptions(e.$options));if("$regularExpression"in e)return new r(e.$regularExpression.pattern,r.parseOptions(e.$regularExpression.options));throw new Ce("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(e)))},r}();Object.defineProperty($i.prototype,"_bsontype",{value:"BSONRegExp"});var du=function(){function r(e){if(!(this instanceof r))return new r(e);this.value=e}return r.prototype.valueOf=function(){return this.value},r.prototype.toString=function(){return this.value},r.prototype.inspect=function(){return'new BSONSymbol("'.concat(this.value,'")')},r.prototype.toJSON=function(){return this.value},r.prototype.toExtendedJSON=function(){return{$symbol:this.value}},r.fromExtendedJSON=function(e){return new r(e.$symbol)},r.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},r}();Object.defineProperty(du.prototype,"_bsontype",{value:"Symbol"});var Xg=X,uh=function(r){ca(e,r);function e(t,n){var o=this;return o instanceof e?(X.isLong(t)?o=r.call(this,t.low,t.high,!0)||this:qi(t)&&typeof t.t<"u"&&typeof t.i<"u"?o=r.call(this,t.i,t.t,!0)||this:o=r.call(this,t,n,!0)||this,Object.defineProperty(o,"_bsontype",{value:"Timestamp",writable:!1,configurable:!1,enumerable:!1}),o):new e(t,n)}return e.prototype.toJSON=function(){return{$timestamp:this.toString()}},e.fromInt=function(t){return new e(X.fromInt(t,!0))},e.fromNumber=function(t){return new e(X.fromNumber(t,!0))},e.fromBits=function(t,n){return new e(t,n)},e.fromString=function(t,n){return new e(X.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=X.MAX_UNSIGNED_VALUE,e}(Xg);function Zg(r){return qi(r)&&Reflect.has(r,"_bsontype")&&typeof r._bsontype=="string"}var ch=2147483647,lh=-2147483648,fh=9223372036854776e3,dh=-9223372036854776e3,ev={$oid:Bt,$binary:_n,$uuid:_n,$symbol:du,$numberInt:ya,$numberDecimal:cu,$numberDouble:pa,$numberLong:X,$minKey:fu,$maxKey:lu,$regex:$i,$regularExpression:$i,$timestamp:uh};function hh(r,e){if(e===void 0&&(e={}),typeof r=="number"){if(e.relaxed||e.legacy)return r;if(Math.floor(r)===r){if(r>=lh&&r<=ch)return new ya(r);if(r>=dh&&r<=fh)return X.fromNumber(r)}return new pa(r)}if(r==null||typeof r!="object")return r;if(r.$undefined)return null;for(var t=Object.keys(r).filter(function(f){return f.startsWith("$")&&r[f]!=null}),n=0;n<t.length;n++){var o=ev[t[n]];if(o)return o.fromExtendedJSON(r,e)}if(r.$date!=null){var i=r.$date,s=new Date;return e.legacy?typeof i=="number"?s.setTime(i):typeof i=="string"&&s.setTime(Date.parse(i)):typeof i=="string"?s.setTime(Date.parse(i)):X.isLong(i)?s.setTime(i.toNumber()):typeof i=="number"&&e.relaxed&&s.setTime(i),s}if(r.$code!=null){var c=Object.assign({},r);return r.$scope&&(c.$scope=hh(r.$scope)),ha.fromExtendedJSON(r)}if(Lg(r)||r.$dbPointer){var l=r.$ref?r:r.$dbPointer;if(l instanceof ji)return l;var a=Object.keys(l).filter(function(f){return f.startsWith("$")}),u=!0;if(a.forEach(function(f){["$ref","$id","$db"].indexOf(f)===-1&&(u=!1)}),u)return ji.fromExtendedJSON(l)}return r}function tv(r,e){return r.map(function(t,n){e.seenObjects.push({propertyName:"index ".concat(n),obj:null});try{return Hr(t,e)}finally{e.seenObjects.pop()}})}function ph(r){var e=r.toISOString();return r.getUTCMilliseconds()!==0?e:e.slice(0,-5)+"Z"}function Hr(r,e){if((typeof r=="object"||typeof r=="function")&&r!==null){var t=e.seenObjects.findIndex(function(S){return S.obj===r});if(t!==-1){var n=e.seenObjects.map(function(S){return S.propertyName}),o=n.slice(0,t).map(function(S){return"".concat(S," -> ")}).join(""),i=n[t],s=" -> "+n.slice(t+1,n.length-1).map(function(S){return"".concat(S," -> ")}).join(""),c=n[n.length-1],l=" ".repeat(o.length+i.length/2),a="-".repeat(s.length+(i.length+c.length)/2-1);throw new Ce(`Converting circular structure to EJSON:
54
+ `+" ".concat(o).concat(i).concat(s).concat(c,`
55
+ `)+" ".concat(l,"\\").concat(a,"/"))}e.seenObjects[e.seenObjects.length-1].obj=r}if(Array.isArray(r))return tv(r,e);if(r===void 0)return null;if(r instanceof Date||Dg(r)){var u=r.getTime(),f=u>-1&&u<2534023188e5;return e.legacy?e.relaxed&&f?{$date:r.getTime()}:{$date:ph(r)}:e.relaxed&&f?{$date:ph(r)}:{$date:{$numberLong:r.getTime().toString()}}}if(typeof r=="number"&&(!e.relaxed||!isFinite(r))){if(Math.floor(r)===r){var d=r>=lh&&r<=ch,y=r>=dh&&r<=fh;if(d)return{$numberInt:r.toString()};if(y)return{$numberLong:r.toString()}}return{$numberDouble:r.toString()}}if(r instanceof RegExp||Pg(r)){var m=r.flags;if(m===void 0){var v=r.toString().match(/[gimuy]*$/);v&&(m=v[0])}var I=new $i(r.source,m);return I.toExtendedJSON(e)}return r!=null&&typeof r=="object"?nv(r,e):r}var rv={Binary:function(r){return new _n(r.value(),r.sub_type)},Code:function(r){return new ha(r.code,r.scope)},DBRef:function(r){return new ji(r.collection||r.namespace,r.oid,r.db,r.fields)},Decimal128:function(r){return new cu(r.bytes)},Double:function(r){return new pa(r.value)},Int32:function(r){return new ya(r.value)},Long:function(r){return X.fromBits(r.low!=null?r.low:r.low_,r.low!=null?r.high:r.high_,r.low!=null?r.unsigned:r.unsigned_)},MaxKey:function(){return new lu},MinKey:function(){return new fu},ObjectID:function(r){return new Bt(r)},ObjectId:function(r){return new Bt(r)},BSONRegExp:function(r){return new $i(r.pattern,r.options)},Symbol:function(r){return new du(r.value)},Timestamp:function(r){return uh.fromBits(r.low,r.high)}};function nv(r,e){if(r==null||typeof r!="object")throw new vn("not an object instance");var t=r._bsontype;if(typeof t>"u"){var n={};for(var o in r){e.seenObjects.push({propertyName:o,obj:null});try{var i=Hr(r[o],e);o==="__proto__"?Object.defineProperty(n,o,{value:i,writable:!0,enumerable:!0,configurable:!0}):n[o]=i}finally{e.seenObjects.pop()}}return n}else if(Zg(r)){var s=r;if(typeof s.toExtendedJSON!="function"){var c=rv[r._bsontype];if(!c)throw new Ce("Unrecognized or invalid _bsontype: "+r._bsontype);s=c(s)}return t==="Code"&&s.scope?s=new ha(s.code,Hr(s.scope,e)):t==="DBRef"&&s.oid&&(s=new ji(Hr(s.collection,e),Hr(s.oid,e),Hr(s.db,e),Hr(s.fields,e))),s.toExtendedJSON(e)}else throw new vn("_bsontype must be a string, but was: "+typeof t)}var Ot;(function(r){function e(i,s){var c=Object.assign({},{relaxed:!0,legacy:!1},s);return typeof c.relaxed=="boolean"&&(c.strict=!c.relaxed),typeof c.strict=="boolean"&&(c.relaxed=!c.strict),JSON.parse(i,function(l,a){if(l.indexOf("\0")!==-1)throw new vn("BSON Document field names cannot contain null bytes, found: ".concat(JSON.stringify(l)));return hh(a,c)})}r.parse=e;function t(i,s,c,l){c!=null&&typeof c=="object"&&(l=c,c=0),s!=null&&typeof s=="object"&&!Array.isArray(s)&&(l=s,s=void 0,c=0);var a=Object.assign({relaxed:!0,legacy:!1},l,{seenObjects:[{propertyName:"(root)",obj:null}]}),u=Hr(i,a);return JSON.stringify(u,s,c)}r.stringify=t;function n(i,s){return s=s||{},JSON.parse(t(i,s))}r.serialize=n;function o(i,s){return s=s||{},e(JSON.stringify(i),s)}r.deserialize=o})(Ot||(Ot={}));var yh=Vd();yh.Map?yh.Map:function(){function r(e){e===void 0&&(e=[]),this._keys=[],this._values={};for(var t=0;t<e.length;t++)if(e[t]!=null){var n=e[t],o=n[0],i=n[1];this._keys.push(o),this._values[o]={v:i,i:this._keys.length-1}}}return r.prototype.clear=function(){this._keys=[],this._values={}},r.prototype.delete=function(e){var t=this._values[e];return t==null?!1:(delete this._values[e],this._keys.splice(t.i,1),!0)},r.prototype.entries=function(){var e=this,t=0;return{next:function(){var n=e._keys[t++];return{value:n!==void 0?[n,e._values[n].v]:void 0,done:n===void 0}}}},r.prototype.forEach=function(e,t){t=t||this;for(var n=0;n<this._keys.length;n++){var o=this._keys[n];e.call(t,this._values[o].v,o,t)}},r.prototype.get=function(e){return this._values[e]?this._values[e].v:void 0},r.prototype.has=function(e){return this._values[e]!=null},r.prototype.keys=function(){var e=this,t=0;return{next:function(){var n=e._keys[t++];return{value:n!==void 0?n:void 0,done:n===void 0}}}},r.prototype.set=function(e,t){return this._values[e]?(this._values[e].v=t,this):(this._keys.push(e),this._values[e]={v:t,i:this._keys.length-1},this)},r.prototype.values=function(){var e=this,t=0;return{next:function(){var n=e._keys[t++];return{value:n!==void 0?e._values[n].v:void 0,done:n===void 0}}}},Object.defineProperty(r.prototype,"size",{get:function(){return this._keys.length},enumerable:!1,configurable:!0}),r}(),X.fromNumber(Ug),X.fromNumber(Bg);var hu=new Uint8Array(8);new DataView(hu.buffer,hu.byteOffset,hu.byteLength);var iv=1024*1024*17;ye.alloc(iv);var ov=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},av=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},mh=function(){function r(e,t){this._stages=[],e&&t&&(this._db=e,this._request=new it.reqClass(this._db.config),this._collectionName=t)}return r.prototype.end=function(){return ov(this,void 0,void 0,function(){var e;return av(this,function(t){switch(t.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 e=t.sent(),e&&e.data&&e.data.list?[2,{requestId:e.requestId,data:JSON.parse(e.data.list).map(Ot.parse)}]:[2,e]}})})},r.prototype.unwrap=function(){return this._stages},r.prototype.done=function(){return this._stages.map(function(e){var t,n=e.stageKey,o=e.stageValue;return t={},t[n]=JSON.parse(o),t})},r.prototype._pipe=function(e,t){return this._stages.push({stageKey:"$"+e,stageValue:JSON.stringify(t)}),this},r.prototype.addFields=function(e){return this._pipe("addFields",e)},r.prototype.bucket=function(e){return this._pipe("bucket",e)},r.prototype.bucketAuto=function(e){return this._pipe("bucketAuto",e)},r.prototype.count=function(e){return this._pipe("count",e)},r.prototype.geoNear=function(e){return e.query&&(e.query=sa.encode(e.query)),e.distanceMultiplier&&typeof e.distanceMultiplier=="number"&&(e.distanceMultiplier=e.distanceMultiplier),e.near&&(e.near=new gt(e.near.longitude,e.near.latitude).toJSON()),this._pipe("geoNear",e)},r.prototype.group=function(e){return this._pipe("group",e)},r.prototype.limit=function(e){return this._pipe("limit",e)},r.prototype.match=function(e){return this._pipe("match",sa.encode(e))},r.prototype.project=function(e){return this._pipe("project",e)},r.prototype.lookup=function(e){return this._pipe("lookup",e)},r.prototype.replaceRoot=function(e){return this._pipe("replaceRoot",e)},r.prototype.sample=function(e){return this._pipe("sample",e)},r.prototype.skip=function(e){return this._pipe("skip",e)},r.prototype.sort=function(e){return this._pipe("sort",e)},r.prototype.sortByCount=function(e){return this._pipe("sortByCount",e)},r.prototype.unwind=function(e){return this._pipe("unwind",e)},r}(),sv=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)o.hasOwnProperty(i)&&(n[i]=o[i])},r(e,t)};return function(e,t){r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),uv=function(r){sv(e,r);function e(t,n){return r.call(this,t,n)||this}return Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!0,configurable:!0}),e.prototype.doc=function(t){if(typeof t!="string"&&typeof t!="number")throw new Error("docId必须为字符串或数字");return new Hd(this._db,this._coll,t)},e.prototype.add=function(t,n){var o=new Hd(this._db,this._coll,void 0);return o.create(t,n)},e.prototype.aggregate=function(){return new mh(this._db,this._coll)},e}(hg),cv={eq:function(r){return new Ve(ne.EQ,[r])},neq:function(r){return new Ve(ne.NEQ,[r])},lt:function(r){return new Ve(ne.LT,[r])},lte:function(r){return new Ve(ne.LTE,[r])},gt:function(r){return new Ve(ne.GT,[r])},gte:function(r){return new Ve(ne.GTE,[r])},in:function(r){return new Ve(ne.IN,r)},nin:function(r){return new Ve(ne.NIN,r)},all:function(r){return new Ve(ne.ALL,r)},elemMatch:function(r){return new Ve(ne.ELEM_MATCH,[r])},exists:function(r){return new Ve(ne.EXISTS,[r])},size:function(r){return new Ve(ne.SIZE,[r])},mod:function(r){return new Ve(ne.MOD,[r])},geoNear:function(r){return new Ve(ne.GEO_NEAR,[r])},geoWithin:function(r){return new Ve(ne.GEO_WITHIN,[r])},geoIntersects:function(r){return new Ve(ne.GEO_INTERSECTS,[r])},and:function(){var r=xe(arguments[0])?arguments[0]:Array.from(arguments);return new mn(It.AND,r)},nor:function(){var r=xe(arguments[0])?arguments[0]:Array.from(arguments);return new mn(It.NOR,r)},or:function(){var r=xe(arguments[0])?arguments[0]:Array.from(arguments);return new mn(It.OR,r)},not:function(){var r=xe(arguments[0])?arguments[0]:Array.from(arguments);return new mn(It.NOT,r)},set:function(r){return new Me(he.SET,[r])},remove:function(){return new Me(he.REMOVE,[])},inc:function(r){return new Me(he.INC,[r])},mul:function(r){return new Me(he.MUL,[r])},push:function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];var t;if(jr(r[0])&&r[0].hasOwnProperty("each")){var n=r[0];t={$each:n.each,$position:n.position,$sort:n.sort,$slice:n.slice}}else xe(r[0])?t=r[0]:t=Array.from(r);return new Me(he.PUSH,t)},pull:function(r){return new Me(he.PULL,r)},pullAll:function(r){return new Me(he.PULL_ALL,r)},pop:function(){return new Me(he.POP,[])},shift:function(){return new Me(he.SHIFT,[])},unshift:function(){var r=xe(arguments[0])?arguments[0]:Array.from(arguments);return new Me(he.UNSHIFT,r)},addToSet:function(r){return new Me(he.ADD_TO_SET,r)},rename:function(r){return new Me(he.RENAME,[r])},bit:function(r){return new Me(he.BIT,[r])},max:function(r){return new Me(he.MAX,[r])},min:function(r){return new Me(he.MIN,[r])},expr:function(r){return{$expr:r}},jsonSchema:function(r){return{$jsonSchema:r}},text:function(r){return og(r)?{$search:r.search}:{$search:r.search,$language:r.language,$caseSensitive:r.caseSensitive,$diacriticSensitive:r.diacriticSensitive}},aggregate:{pipeline:function(){return new mh},abs:function(r){return new $("abs",r)},add:function(r){return new $("add",r)},ceil:function(r){return new $("ceil",r)},divide:function(r){return new $("divide",r)},exp:function(r){return new $("exp",r)},floor:function(r){return new $("floor",r)},ln:function(r){return new $("ln",r)},log:function(r){return new $("log",r)},log10:function(r){return new $("log10",r)},mod:function(r){return new $("mod",r)},multiply:function(r){return new $("multiply",r)},pow:function(r){return new $("pow",r)},sqrt:function(r){return new $("sqrt",r)},subtract:function(r){return new $("subtract",r)},trunc:function(r){return new $("trunc",r)},arrayElemAt:function(r){return new $("arrayElemAt",r)},arrayToObject:function(r){return new $("arrayToObject",r)},concatArrays:function(r){return new $("concatArrays",r)},filter:function(r){return new $("filter",r)},in:function(r){return new $("in",r)},indexOfArray:function(r){return new $("indexOfArray",r)},isArray:function(r){return new $("isArray",r)},map:function(r){return new $("map",r)},range:function(r){return new $("range",r)},reduce:function(r){return new $("reduce",r)},reverseArray:function(r){return new $("reverseArray",r)},size:function(r){return new $("size",r)},slice:function(r){return new $("slice",r)},zip:function(r){return new $("zip",r)},and:function(r){return new $("and",r)},not:function(r){return new $("not",r)},or:function(r){return new $("or",r)},cmp:function(r){return new $("cmp",r)},eq:function(r){return new $("eq",r)},gt:function(r){return new $("gt",r)},gte:function(r){return new $("gte",r)},lt:function(r){return new $("lt",r)},lte:function(r){return new $("lte",r)},neq:function(r){return new $("ne",r)},cond:function(r){return new $("cond",r)},ifNull:function(r){return new $("ifNull",r)},switch:function(r){return new $("switch",r)},dateFromParts:function(r){return new $("dateFromParts",r)},dateFromString:function(r){return new $("dateFromString",r)},dayOfMonth:function(r){return new $("dayOfMonth",r)},dayOfWeek:function(r){return new $("dayOfWeek",r)},dayOfYear:function(r){return new $("dayOfYear",r)},isoDayOfWeek:function(r){return new $("isoDayOfWeek",r)},isoWeek:function(r){return new $("isoWeek",r)},isoWeekYear:function(r){return new $("isoWeekYear",r)},millisecond:function(r){return new $("millisecond",r)},minute:function(r){return new $("minute",r)},month:function(r){return new $("month",r)},second:function(r){return new $("second",r)},hour:function(r){return new $("hour",r)},week:function(r){return new $("week",r)},year:function(r){return new $("year",r)},literal:function(r){return new $("literal",r)},mergeObjects:function(r){return new $("mergeObjects",r)},objectToArray:function(r){return new $("objectToArray",r)},allElementsTrue:function(r){return new $("allElementsTrue",r)},anyElementTrue:function(r){return new $("anyElementTrue",r)},setDifference:function(r){return new $("setDifference",r)},setEquals:function(r){return new $("setEquals",r)},setIntersection:function(r){return new $("setIntersection",r)},setIsSubset:function(r){return new $("setIsSubset",r)},setUnion:function(r){return new $("setUnion",r)},concat:function(r){return new $("concat",r)},dateToString:function(r){return new $("dateToString",r)},indexOfBytes:function(r){return new $("indexOfBytes",r)},indexOfCP:function(r){return new $("indexOfCP",r)},split:function(r){return new $("split",r)},strLenBytes:function(r){return new $("strLenBytes",r)},strLenCP:function(r){return new $("strLenCP",r)},strcasecmp:function(r){return new $("strcasecmp",r)},substr:function(r){return new $("substr",r)},substrBytes:function(r){return new $("substrBytes",r)},substrCP:function(r){return new $("substrCP",r)},toLower:function(r){return new $("toLower",r)},toUpper:function(r){return new $("toUpper",r)},meta:function(r){return new $("meta",r)},addToSet:function(r){return new $("addToSet",r)},avg:function(r){return new $("avg",r)},first:function(r){return new $("first",r)},last:function(r){return new $("last",r)},max:function(r){return new $("max",r)},min:function(r){return new $("min",r)},push:function(r){return new $("push",r)},stdDevPop:function(r){return new $("stdDevPop",r)},stdDevSamp:function(r){return new $("stdDevSamp",r)},sum:function(r){return new $("sum",r)},let:function(r){return new $("let",r)}},project:{slice:function(r){return new gh("slice",r)},elemMatch:function(r){return new gh("elemMatch",r)}}},$=function(){function r(e,t){this["$"+e]=t}return r}(),gh=function(){function r(e,t){this["$"+e]=t}return r}(),lv=function(){function r(e){var t=e.regexp,n=e.options;if(!t)throw new TypeError("regexp must be a string");this.$regex=t,this.$options=n}return r.prototype.parse=function(){return{$regex:this.$regex,$options:this.$options}},Object.defineProperty(r.prototype,"_internalType",{get:function(){return xd},enumerable:!0,configurable:!0}),r}();function fv(r){return new lv(r)}var vh={INSERT_DOC_FAIL:{message:"insert document failed"},DATABASE_TRANSACTION_CONFLICT:{code:"DATABASE_TRANSACTION_CONFLICT"}},or=function(){return or=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},or.apply(this,arguments)},Wi=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Hi=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},dv="database.getInTransaction",_h="database.updateDocInTransaction",hv="database.deleteDocInTransaction",pv="database.insertDocInTransaction",bh=function(){function r(e,t,n){this._coll=t,this.id=n,this._transaction=e,this._request=this._transaction.getRequestMethod(),this._transactionId=this._transaction.getTransactionId()}return r.prototype.create=function(e){return Wi(this,void 0,void 0,function(){var t,n,o,i;return Hi(this,function(s){switch(s.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,data:Ot.stringify(Mi(e),{relaxed:!1})},this.id&&(t._id=this.id),[4,this._request.send(pv,t)];case 1:if(n=s.sent(),n.code)throw n;if(o=Ot.parse(n.inserted),i=Ot.parse(n.ok),i==1&&o==1)return[2,or(or({},n),{ok:i,inserted:o})];throw new Error(vh.INSERT_DOC_FAIL.message)}})})},r.prototype.get=function(){return Wi(this,void 0,void 0,function(){var e,t;return Hi(this,function(n){switch(n.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send(dv,e)];case 1:if(t=n.sent(),t.code)throw t;return[2,{data:t.data!=="null"?ea.formatField(Ot.parse(t.data)):Ot.parse(t.data),requestId:t.requestId}]}})})},r.prototype.set=function(e){return Wi(this,void 0,void 0,function(){var t,n;return Hi(this,function(o){switch(o.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:Ot.stringify(Mi(e),{relaxed:!1}),upsert:!0},[4,this._request.send(_h,t)];case 1:if(n=o.sent(),n.code)throw n;return[2,or(or({},n),{updated:Ot.parse(n.updated),upserted:n.upserted?JSON.parse(n.upserted):null})]}})})},r.prototype.update=function(e){return Wi(this,void 0,void 0,function(){var t,n;return Hi(this,function(o){switch(o.label){case 0:return t={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}},data:Ot.stringify(Zs.encode(e),{relaxed:!1})},[4,this._request.send(_h,t)];case 1:if(n=o.sent(),n.code)throw n;return[2,or(or({},n),{updated:Ot.parse(n.updated)})]}})})},r.prototype.delete=function(){return Wi(this,void 0,void 0,function(){var e,t;return Hi(this,function(n){switch(n.label){case 0:return e={collectionName:this._coll,transactionId:this._transactionId,query:{_id:{$eq:this.id}}},[4,this._request.send(hv,e)];case 1:if(t=n.sent(),t.code)throw t;return[2,or(or({},t),{deleted:Ot.parse(t.deleted)})]}})})},r}(),yv=function(){function r(e,t){this._coll=t,this._transaction=e}return r}(),mv=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var i in o)o.hasOwnProperty(i)&&(n[i]=o[i])},r(e,t)};return function(e,t){r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),gv=function(r){mv(e,r);function e(t,n){return r.call(this,t,n)||this}return Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!0,configurable:!0}),e.prototype.doc=function(t){if(typeof t!="string"&&typeof t!="number")throw new Error("docId必须为字符串或数字");return new bh(this._transaction,this._coll,t)},e.prototype.add=function(t){var n;t._id!==void 0&&(n=t._id);var o=new bh(this._transaction,this._coll,n);return o.create(t)},e}(yv),Xn=function(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function c(u){try{a(n.next(u))}catch(f){s(f)}}function l(u){try{a(n.throw(u))}catch(f){s(f)}}function a(u){u.done?i(u.value):o(u.value).then(c,l)}a((n=n.apply(r,e||[])).next())})},Zn=function(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s;return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(u){return l([a,u])}}function l(a){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,o&&(i=a[0]&2?o.return:a[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;switch(o=0,i&&(a=[a[0]&2,i.value]),a[0]){case 0:case 1:i=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,o=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1],i=a;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(a);break}i[2]&&t.ops.pop(),t.trys.pop();continue}a=e.call(r,t)}catch(u){a=[6,u],o=0}finally{n=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},vv="database.startTransaction",_v="database.commitTransaction",bv="database.abortTransaction",wh=function(){function r(e){this._db=e,this._request=new it.reqClass(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return r.prototype.init=function(){return Xn(this,void 0,void 0,function(){var e;return Zn(this,function(t){switch(t.label){case 0:return[4,this._request.send(vv)];case 1:if(e=t.sent(),e.code)throw e;return this.inited=!0,this._id=e.transactionId,[2]}})})},r.prototype.collection=function(e){if(!e)throw new Error("Collection name is required");return new gv(this,e)},r.prototype.getTransactionId=function(){return this._id},r.prototype.getRequestMethod=function(){return this._request},r.prototype.commit=function(){return Xn(this,void 0,void 0,function(){var e,t;return Zn(this,function(n){switch(n.label){case 0:return e={transactionId:this._id},[4,this._request.send(_v,e)];case 1:if(t=n.sent(),t.code)throw t;return this.commited=!0,[2,t]}})})},r.prototype.rollback=function(e){return Xn(this,void 0,void 0,function(){var t,n;return Zn(this,function(o){switch(o.label){case 0:return t={transactionId:this._id},[4,this._request.send(bv,t)];case 1:if(n=o.sent(),n.code)throw n;return this.aborted=!0,this.abortReason=e,[2,n]}})})},r}();function wv(){return Xn(this,void 0,void 0,function(){var r;return Zn(this,function(e){switch(e.label){case 0:return r=new wh(this),[4,r.init()];case 1:return e.sent(),[2,r]}})})}function Eh(r,e){return e===void 0&&(e=3),Xn(this,void 0,void 0,function(){var t,n,o,i,s=this;return Zn(this,function(c){switch(c.label){case 0:return c.trys.push([0,4,,10]),t=new wh(this),[4,t.init()];case 1:return c.sent(),[4,r(t)];case 2:if(n=c.sent(),t.aborted===!0)throw t.abortReason;return[4,t.commit()];case 3:return c.sent(),[2,n];case 4:if(o=c.sent(),t.inited===!1)throw o;return i=function(l){return Xn(s,void 0,void 0,function(){return Zn(this,function(a){switch(a.label){case 0:if(!(!t.aborted&&!t.commited))return[3,5];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,t.rollback()];case 2:return a.sent(),[3,4];case 3:return a.sent(),[3,4];case 4:throw l;case 5:throw t.aborted===!0?t.abortReason:l}})})},e<=0?[4,i(o)]:[3,6];case 5:c.sent(),c.label=6;case 6:return o&&o.code===vh.DATABASE_TRANSACTION_CONFLICT.code?[4,Eh.bind(this)(r,--e)]:[3,8];case 7:return[2,c.sent()];case 8:return[4,i(o)];case 9:return c.sent(),[3,10];case 10:return[2]}})})}var it=function(){function r(e){this.config=e,this.Geo=ug,this.serverDate=ig,this.command=cv,this.RegExp=fv,this.startTransaction=wv,this.runTransaction=Eh,this.logicCommand=mn,this.updateCommand=Me,this.queryCommand=Ve}return r.prototype.collection=function(e){if(!e)throw new Error("Collection name is required");return new uv(this,e)},r.prototype.createCollection=function(e){var t=new r.reqClass(this.config),n={collectionName:e};return t.send("database.addCollection",n)},r}(),Gi=function(){return Gi=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},Gi.apply(this,arguments)},Ev="database";function Sv(r){var e=this.platform,t=e.adapter,n=e.runtime;return it.reqClass=this.request.constructor,it.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},it.runtime=n,this.wsClientClass&&(it.wsClass=t.wsClass,it.wsClientClass=this.wsClientClass),it.ws||(it.ws=null),new it(Gi(Gi(Gi({},this.config),{_fromApp:this}),r))}var Sh={name:Ev,entity:{database:Sv}};try{cloudbase.registerComponent(Sh)}catch{}function Iv(r){try{r.registerComponent(Sh)}catch(e){console.warn(e)}}var Ov={version:"2.17.3"}.version;bt.registerVersion(Ov);try{Vy(bt),im(bt),um(bt),Iv(bt),$m(bt),Zm(bt),p0(bt),J0(bt),Ky(bt)}catch{}try{window.cloudbase=bt}catch{}class Ih{constructor(e={}){this._db=null,this._collection=null,this._cloudBaseApp=null,this._cloudBaseAuth=null,this.config={env:e.env||"mobenai-weapp-dev-2e8qhi3a963364",persistence:e.persistence||"local",collectionName:e.collectionName||"platform-metadata",...e}}ensureInitialized(){this._cloudBaseApp||(this._cloudBaseApp=bt.init({env:this.config.env})),this._cloudBaseAuth||(this._cloudBaseAuth=this._cloudBaseApp.auth({persistence:this.config.persistence})),this._db||(this._db=this._cloudBaseApp.database(),this._collection=this._db.collection(this.config.collectionName))}get db(){return this.ensureInitialized(),this._db}get collection(){return this.ensureInitialized(),this._collection}get cloudBaseApp(){return this.ensureInitialized(),this._cloudBaseApp}get cloudBaseAuth(){return this.ensureInitialized(),this._cloudBaseAuth}getRawDB(){return this.ensureInitialized(),this._db}getRawCollection(){return this.ensureInitialized(),this._collection}isConnected(){return this._db!==null&&this._cloudBaseApp!==null}reset(){this._db=null,this._collection=null,this._cloudBaseApp=null,this._cloudBaseAuth=null}async getCurrentUserId(){var e;try{this.ensureInitialized();const t=await this._cloudBaseAuth.getLoginState();return((e=t==null?void 0:t.user)==null?void 0:e.uid)||null}catch(t){return console.error("Failed to get current user ID:",t),null}}async getAccessToken(){try{return this.ensureInitialized(),(await this._cloudBaseAuth.getAccessToken()).accessToken}catch(e){return console.error("Failed to get access token:",e),null}}updateConfig(e){this.config={...this.config,...e},(e.env||e.collectionName)&&this.reset()}getConfig(){return{...this.config}}}class Oh{constructor(){this.throttleTimeout=300}generateRequestKey(e,t){const n=JSON.stringify(t,Object.keys(t).sort());return`${e}:${n}`}async withThrottle(e,t,n){return await n()}clearPendingRequests(){console.log("All throttled requests cleared")}getPendingRequestCount(){return 0}setThrottleTimeout(e){e>0&&(this.throttleTimeout=e,console.log(`Throttle timeout updated to ${e}ms`))}clearRequestCache(e,t){console.log(`Request cache cleared for: ${e}`)}getCacheStatus(){return{throttledFunctionsCount:0,cachedResultsCount:0,throttleTimeout:this.throttleTimeout}}async forceExecute(e,t,n){return console.log(`Force executing request: ${e}`),await n()}}class Th{constructor(e){this.connection=e}validateWyIDFormat(e){return!e||typeof e!="string"?!1:/^[a-z_]+_\d+_[a-z0-9]+$|^[a-zA-Z0-9\-_]+$/.test(e)}async checkWyIDExists(e){try{return this.connection.ensureInitialized(),(await this.connection.collection.where({wyID:e,isDeleted:!1}).limit(1).get()).data.length>0}catch(t){throw console.error("Failed to check wyID existence:",t),new Error(`Failed to check wyID existence: ${t}`)}}async getExistingDocumentInfo(e){try{this.connection.ensureInitialized();const t=await this.connection.collection.where({wyID:e,isDeleted:!1}).field({wyID:!0,model:!0,createdAt:!0,createdBy:!0}).limit(1).get();return t.data.length>0?t.data[0]:null}catch(t){return console.error("Failed to get existing document info:",t),null}}async validateWyIDUniqueness(e){if(!this.validateWyIDFormat(e))throw new Error(`Invalid wyID format: ${e}. Expected format: prefix_timestamp_random or valid authUserId`);if(await this.checkWyIDExists(e)){const n=await this.getExistingDocumentInfo(e),o=n?` (existing: ${n.model}, created: ${n.createdAt})`:"";throw new Error(`DUPLICATE_WYID: Document with wyID '${e}' already exists${o}`)}}async validateBatchWyIDUniqueness(e){const t=e.filter((i,s)=>e.indexOf(i)!==s);if(t.length>0)throw new Error(`BATCH_DUPLICATE_WYID: Duplicate wyIDs in batch: ${t.join(", ")}`);for(const i of e){if(!i)throw new Error("VALIDATION_ERROR: Document wyID is required");if(!this.validateWyIDFormat(i))throw new Error(`VALIDATION_ERROR: Invalid wyID format: ${i}`)}const o=(await Promise.all(e.map(async i=>{const s=await this.checkWyIDExists(i);return{wyID:i,exists:s}}))).filter(i=>i.exists).map(i=>i.wyID);if(o.length>0)throw new Error(`BATCH_DUPLICATE_WYID: Documents with wyIDs already exist: ${o.join(", ")}`)}async getWyIDStats(){try{this.connection.ensureInitialized();const e=await this.connection.collection.field({wyID:!0,model:!0,isDeleted:!0}).get(),t={total:e.data.length,active:e.data.filter(n=>!n.isDeleted).length,deleted:e.data.filter(n=>n.isDeleted).length,byModel:{}};return e.data.forEach(n=>{t.byModel[n.model]||(t.byModel[n.model]={total:0,active:0,deleted:0}),t.byModel[n.model].total++,n.isDeleted?t.byModel[n.model].deleted++:t.byModel[n.model].active++}),t}catch(e){throw console.error("Failed to get wyID stats:",e),new Error(`Failed to get wyID stats: ${e}`)}}}class Ah{constructor(){}buildWhereCondition(e){const t={};return Object.keys(e).forEach(n=>{["limit","skip","orderBy"].includes(n)||(t[n]=e[n])}),t}buildBaseWhereCondition(e,t={}){return{model:e,isDeleted:!1,...this.buildWhereCondition(t)}}buildListQueryFields(e=[]){const t={wyID:!0,model:!0,createdAt:!0,updatedAt:!0,version:!0,organizationId:!0};return e.forEach(n=>{t[`data.${n}`]=!0}),t}buildDetailQueryFields(){return{wyID:!0,model:!0,data:!0,createdAt:!0,updatedAt:!0,createdBy:!0,updatedBy:!0,organizationId:!0,isDeleted:!0,version:!0}}applyFieldSelection(e,t){return t.fields?e.field(t.fields):t.includeData?e:e.field(this.buildListQueryFields())}applyPagination(e,t){let n=e;return t.limit&&(n=n.limit(t.limit)),t.skip&&(n=n.skip(t.skip)),n}applySorting(e,t){return t.orderBy?e.orderBy(t.orderBy.field,t.orderBy.direction):e}buildQuery(e,t,n={},o={}){const i=this.buildBaseWhereCondition(t,n);let s=e.where(i);return s=this.applyPagination(s,n),s=this.applySorting(s,n),s=this.applyFieldSelection(s,o),s}buildSearchQuery(e,t,n,o={}){let i=e.where({model:t,isDeleted:!1,searchText:new RegExp(n,"i")});return i=this.applyPagination(i,o),o.fields?i=i.field(o.fields):i=i.field({wyID:!0,model:!0,createdAt:!0,updatedAt:!0}),i}buildCountQuery(e,t,n={}){const o=this.buildBaseWhereCondition(t,n);return e.where(o)}buildBatchQuery(e,t,n,o,i={}){let s=e.where({model:n,wyID:t.command.in(o),isDeleted:!1});return s=this.applyFieldSelection(s,i),s}calculatePaginationInfo(e,t){const n=t.limit||20,o=t.skip||0,i=Math.floor(o/n)+1;return{total:e,page:i,pageSize:n,totalPages:Math.ceil(e/n),hasNext:o+n<e,hasPrev:o>0}}}class ma{static buildBaseDocument(e,t,n,o,i=null,s=null){const c=new Date().toISOString();return{wyID:e,model:t,data:n,createdBy:o,updatedBy:o,createdAt:c,updatedAt:c,isDeleted:!1,version:1,organizationId:i}}static buildUpdateDocument(e,t,n=null){const o=new Date().toISOString(),i={...e,updatedBy:t,updatedAt:o};return n&&n.db&&n.db.command&&(i.version=n.db.command.inc(1)),i}static buildSoftDeleteDocument(e,t=null){const n=new Date().toISOString(),o={isDeleted:!0,deletedAt:n,deletedBy:e,updatedBy:e,updatedAt:n};return t&&t.db&&t.db.command&&(o.version=t.db.command.inc(1)),o}static validateDocument(e){const t=[];return e.wyID||t.push("wyID is required"),e.model||t.push("model is required"),e.data||t.push("data is required"),e.createdBy||t.push("createdBy is required"),typeof e.data!="object"&&t.push("data must be an object"),typeof e.version!="number"&&t.push("version must be a number"),typeof e.isDeleted!="boolean"&&t.push("isDeleted must be a boolean"),t}static cleanDocument(e){const t={...e};return Object.keys(t).forEach(n=>{(t[n]===void 0||t[n]===null)&&delete t[n]}),t}static mergeUpdates(e,t){const n={...e};return Object.keys(t).forEach(o=>{if(o.includes(".")){const[i,s]=o.split(".");n[i]||(n[i]={}),n[i][s]=t[o]}else n[o]=t[o]}),n}static extractFieldValue(e,t){const n=t.split(".");let o=e;for(const i of n)if(o&&typeof o=="object")o=o[i];else return;return o}static buildListQueryFields(e=[]){const t={wyID:!0,model:!0,createdAt:!0,updatedAt:!0,organizationId:!0,isDeleted:!0};return e.forEach(n=>{t[`data.${n}`]=!0}),t}static buildDetailQueryFields(){return{wyID:!0,model:!0,data:!0,createdAt:!0,updatedAt:!0,createdBy:!0,updatedBy:!0,organizationId:!0,isDeleted:!0,version:!0}}}class pu{constructor(e,t,n,o={}){this.connection=e,this.validator=t,this.queryBuilder=n,this.config=o}getCurrentOrganizationId(){return this.config.getCurrentOrganizationId?this.config.getCurrentOrganizationId():null}getCurrentUserId(){return this.config.getCurrentUserId?this.config.getCurrentUserId():null}async create(e){try{if(this.connection.ensureInitialized(),!e.wyID)throw new Error("Document wyID is required");if(!e.model)throw new Error("Document model is required");await this.validator.validateWyIDUniqueness(e.wyID);let t=e;if(!e.createdAt||!e.updatedAt){const o=e.createdBy||this.getCurrentUserId(),i=e.organizationId||this.getCurrentOrganizationId();t=ma.buildBaseDocument(e.wyID,e.model,e.data,o,i,this.connection),t={...t,...e}}const n=await this.connection.collection.add(t);return console.log(`Document created successfully: ${t.model}/${t.wyID}`),t.wyID}catch(t){throw console.error("Failed to create document:",t),t.message.includes("DUPLICATE_WYID")?t:t.message.includes("wyID is required")||t.message.includes("model is required")||t.message.includes("Invalid wyID format")?new Error(`VALIDATION_ERROR: ${t.message}`):new Error(`DATABASE_ERROR: Failed to create document: ${t.message}`)}}async findById(e,t,n={}){try{this.connection.ensureInitialized();let o=this.connection.collection.where({model:e,wyID:t,isDeleted:!1});return o=this.queryBuilder.applyFieldSelection(o,n),(await o.get()).data[0]||null}catch(o){throw console.error("Failed to find document by ID:",o),new Error(`Failed to find document: ${o}`)}}async findList(e,t={},n={}){try{this.connection.ensureInitialized();const i=await this.queryBuilder.buildQuery(this.connection.collection,e,t,n).get(),s=await this.count(e,t),c=this.queryBuilder.calculatePaginationInfo(s,t);return{data:i.data,...c}}catch(o){throw console.error("Failed to find document list:",o),new Error(`Failed to find document list: ${o}`)}}async findByIds(e,t,n={}){try{return this.connection.ensureInitialized(),t.length===0?[]:(await this.queryBuilder.buildBatchQuery(this.connection.collection,this.connection.db,e,t,n).get()).data}catch(o){throw console.error("Failed to find documents by IDs:",o),new Error(`Failed to find documents by IDs: ${o}`)}}async update(e,t,n){try{this.connection.ensureInitialized();const o=this.getCurrentUserId(),i=ma.buildUpdateDocument(n,o,this.connection),s=await this.connection.collection.where({model:e,wyID:t,isDeleted:!1}).update(i);return console.log(`Document updated: ${t}, affected: ${s.updated}`),s.updated>0}catch(o){throw console.error("Failed to update document:",o),new Error(`Failed to update document: ${o}`)}}async softDelete(e,t,n){try{this.connection.ensureInitialized();const o=ma.buildSoftDeleteDocument(n,this.connection),i=await this.connection.collection.where({model:e,wyID:t,isDeleted:!1}).update(o);return console.log(`Document soft deleted: ${t}`),i.updated>0}catch(o){throw console.error("Failed to soft delete document:",o),new Error(`Failed to soft delete document: ${o}`)}}async hardDelete(e,t){try{this.connection.ensureInitialized();const n=await this.connection.collection.where({model:e,wyID:t}).remove();return console.log(`Document hard deleted: ${t}`),n.deleted>0}catch(n){throw console.error("Failed to hard delete document:",n),new Error(`Failed to hard delete document: ${n}`)}}async count(e,t={}){try{return this.connection.ensureInitialized(),(await this.queryBuilder.buildCountQuery(this.connection.collection,e,t).count()).total}catch(n){throw console.error("Failed to count documents:",n),new Error(`Failed to count documents: ${n}`)}}async batchUpdate(e,t){try{this.connection.ensureInitialized();let n=0;for(const{wyID:o,data:i}of t)await this.update(e,o,i)&&n++;return n}catch(n){throw console.error("Failed to batch update documents:",n),new Error(`Failed to batch update documents: ${n}`)}}}class Rh{constructor(e,t){this.crudOperations=e,this.validator=t}async batchCreate(e){try{if(!Array.isArray(e)||e.length===0)throw new Error("Documents array is required and cannot be empty");const t=e.map(i=>i.wyID).filter(Boolean);await this.validator.validateBatchWyIDUniqueness(t);const n=[],o=[];for(let i=0;i<e.length;i++)try{const s=await this.crudOperations.create(e[i]);n.push({index:i,wyID:s,success:!0})}catch(s){o.push({index:i,error:s.message,success:!1}),console.error(`Failed to create document at index ${i}:`,s)}return o.length>0&&console.warn(`Batch create completed with ${o.length} errors:`,o),console.log(`Batch create completed: ${n.length} successful, ${o.length} failed`),{successful:n,failed:o,totalProcessed:e.length,successCount:n.length,failureCount:o.length}}catch(t){throw console.error("Failed to batch create documents:",t),new Error(`Failed to batch create documents: ${t}`)}}async batchUpdate(e,t){try{if(!Array.isArray(t)||t.length===0)throw new Error("Updates array is required and cannot be empty");const n=[],o=[];for(let i=0;i<t.length;i++){const{wyID:s,data:c}=t[i];if(!s){o.push({index:i,wyID:null,error:"wyID is required",success:!1});continue}try{const l=await this.crudOperations.update(e,s,c);n.push({index:i,wyID:s,success:l,updated:l})}catch(l){o.push({index:i,wyID:s,error:l.message,success:!1}),console.error(`Failed to update document at index ${i} (wyID: ${s}):`,l)}}return o.length>0&&console.warn(`Batch update completed with ${o.length} errors:`,o),console.log(`Batch update completed: ${n.length} processed, ${o.length} failed`),{successful:n,failed:o,totalProcessed:t.length,successCount:n.filter(i=>i.updated).length,failureCount:o.length}}catch(n){throw console.error("Failed to batch update documents:",n),new Error(`Failed to batch update documents: ${n}`)}}async batchSoftDelete(e,t,n){try{if(!Array.isArray(t)||t.length===0)throw new Error("wyIDs array is required and cannot be empty");if(!n)throw new Error("userId is required for soft delete operations");const o=[],i=[];for(let s=0;s<t.length;s++){const c=t[s];if(!c){i.push({index:s,wyID:null,error:"wyID is required",success:!1});continue}try{const l=await this.crudOperations.softDelete(e,c,n);o.push({index:s,wyID:c,success:l,deleted:l})}catch(l){i.push({index:s,wyID:c,error:l.message,success:!1}),console.error(`Failed to soft delete document at index ${s} (wyID: ${c}):`,l)}}return i.length>0&&console.warn(`Batch soft delete completed with ${i.length} errors:`,i),console.log(`Batch soft delete completed: ${o.length} processed, ${i.length} failed`),{successful:o,failed:i,totalProcessed:t.length,successCount:o.filter(s=>s.deleted).length,failureCount:i.length}}catch(o){throw console.error("Failed to batch soft delete documents:",o),new Error(`Failed to batch soft delete documents: ${o}`)}}async batchHardDelete(e,t){try{if(!Array.isArray(t)||t.length===0)throw new Error("wyIDs array is required and cannot be empty");console.warn(`Performing batch hard delete for ${t.length} documents. This operation cannot be undone.`);const n=[],o=[];for(let i=0;i<t.length;i++){const s=t[i];if(!s){o.push({index:i,wyID:null,error:"wyID is required",success:!1});continue}try{const c=await this.crudOperations.hardDelete(e,s);n.push({index:i,wyID:s,success:c,deleted:c})}catch(c){o.push({index:i,wyID:s,error:c.message,success:!1}),console.error(`Failed to hard delete document at index ${i} (wyID: ${s}):`,c)}}return o.length>0&&console.warn(`Batch hard delete completed with ${o.length} errors:`,o),console.log(`Batch hard delete completed: ${n.length} processed, ${o.length} failed`),{successful:n,failed:o,totalProcessed:t.length,successCount:n.filter(i=>i.deleted).length,failureCount:o.length}}catch(n){throw console.error("Failed to batch hard delete documents:",n),new Error(`Failed to batch hard delete documents: ${n}`)}}async batchValidate(e){try{if(!Array.isArray(e)||e.length===0)throw new Error("Documents array is required and cannot be empty");const t=[],n=[],o=e.map(i=>i.wyID).filter(Boolean);try{await this.validator.validateBatchWyIDUniqueness(o)}catch(i){console.warn("Batch wyID validation failed:",i.message)}for(let i=0;i<e.length;i++){const s=e[i];try{if(!s.wyID)throw new Error("wyID is required");if(!s.model)throw new Error("model is required");if(!this.validator.validateWyIDFormat(s.wyID))throw new Error(`Invalid wyID format: ${s.wyID}`);t.push({index:i,wyID:s.wyID,valid:!0})}catch(c){n.push({index:i,wyID:s.wyID||null,error:c.message,valid:!1})}}return{valid:t,invalid:n,totalProcessed:e.length,validCount:t.length,invalidCount:n.length,isAllValid:n.length===0}}catch(t){throw console.error("Failed to batch validate documents:",t),new Error(`Failed to batch validate documents: ${t}`)}}}class Ch{constructor(e,t){this.connection=e,this.queryBuilder=t}async search(e,t,n={}){try{return this.connection.ensureInitialized(),(await this.queryBuilder.buildSearchQuery(this.connection.collection,e,t,n).get()).data}catch(o){throw console.error("Failed to search documents:",o),new Error(`Failed to search documents: ${o}`)}}async advancedSearch(e,t,n={}){try{this.connection.ensureInitialized();const o={model:e,isDeleted:!1};if(t.text&&(o.searchText=new RegExp(t.text,"i")),t.dateRange){const{startDate:u,endDate:f,field:d="createdAt"}=t.dateRange;u&&f?o[d]=this.connection.db.command.and([this.connection.db.command.gte(u),this.connection.db.command.lte(f)]):u?o[d]=this.connection.db.command.gte(u):f&&(o[d]=this.connection.db.command.lte(f))}t.organizationId&&(o.organizationId=t.organizationId),t.createdBy&&(o.createdBy=t.createdBy),t.customFields&&Object.keys(t.customFields).forEach(u=>{o[u]=t.customFields[u]});let i=this.connection.collection.where(o);i=this.queryBuilder.applyPagination(i,n),i=this.queryBuilder.applySorting(i,n),i=this.queryBuilder.applyFieldSelection(i,n);const s=await i.get(),l=await this.connection.collection.where(o).count(),a=this.queryBuilder.calculatePaginationInfo(l.total,n);return{data:s.data,...a}}catch(o){throw console.error("Failed to perform advanced search:",o),new Error(`Failed to perform advanced search: ${o}`)}}async getStatsByModel(){try{this.connection.ensureInitialized();const e=await this.connection.collection.field({model:!0,isDeleted:!0}).get(),t={};return e.data.forEach(n=>{t[n.model]||(t[n.model]={total:0,active:0,deleted:0}),t[n.model].total++,n.isDeleted?t[n.model].deleted++:t[n.model].active++}),t}catch(e){throw console.error("Failed to get stats by model:",e),new Error(`Failed to get stats by model: ${e}`)}}async getStatsByOrganization(){try{this.connection.ensureInitialized();const e=await this.connection.collection.field({organizationId:!0,model:!0,isDeleted:!0}).get(),t={};return e.data.forEach(n=>{const o=n.organizationId||"no-organization";t[o]||(t[o]={total:0,active:0,deleted:0,byModel:{}}),t[o].total++,n.isDeleted?t[o].deleted++:t[o].active++,t[o].byModel[n.model]||(t[o].byModel[n.model]={total:0,active:0,deleted:0}),t[o].byModel[n.model].total++,n.isDeleted?t[o].byModel[n.model].deleted++:t[o].byModel[n.model].active++}),t}catch(e){throw console.error("Failed to get stats by organization:",e),new Error(`Failed to get stats by organization: ${e}`)}}async getStatsByTimeRange(e,t,n="day"){try{this.connection.ensureInitialized();const o=await this.connection.collection.where({isDeleted:!1,createdAt:this.connection.db.command.and([this.connection.db.command.gte(e),this.connection.db.command.lte(t)])}).field({createdAt:!0,model:!0}).get(),i={};return o.data.forEach(s=>{const c=new Date(s.createdAt);let l;switch(n){case"hour":l=`${c.getFullYear()}-${String(c.getMonth()+1).padStart(2,"0")}-${String(c.getDate()).padStart(2,"0")} ${String(c.getHours()).padStart(2,"0")}:00`;break;case"day":l=`${c.getFullYear()}-${String(c.getMonth()+1).padStart(2,"0")}-${String(c.getDate()).padStart(2,"0")}`;break;case"month":l=`${c.getFullYear()}-${String(c.getMonth()+1).padStart(2,"0")}`;break;case"year":l=`${c.getFullYear()}`;break;default:l=`${c.getFullYear()}-${String(c.getMonth()+1).padStart(2,"0")}-${String(c.getDate()).padStart(2,"0")}`}i[l]||(i[l]={total:0,byModel:{}}),i[l].total++,i[l].byModel[s.model]||(i[l].byModel[s.model]=0),i[l].byModel[s.model]++}),i}catch(o){throw console.error("Failed to get stats by time range:",o),new Error(`Failed to get stats by time range: ${o}`)}}async getRecentActivity(e=50,t=null){try{this.connection.ensureInitialized();const n={isDeleted:!1};return t&&(n.model=t),(await this.connection.collection.where(n).orderBy("updatedAt","desc").limit(e).field({wyID:!0,model:!0,createdAt:!0,updatedAt:!0,createdBy:!0,updatedBy:!0,organizationId:!0}).get()).data}catch(n){throw console.error("Failed to get recent activity:",n),new Error(`Failed to get recent activity: ${n}`)}}async fullTextSearch(e,t={}){try{this.connection.ensureInitialized();const{models:n=[],limit:o=50,skip:i=0}=t,s={isDeleted:!1};n.length>0&&(s.model=this.connection.db.command.in(n));const c=new RegExp(e,"i");s.$or=[{searchText:c},{"data.title":c},{"data.name":c},{"data.description":c},{wyID:c}];let l=this.connection.collection.where(s);o&&(l=l.limit(o)),i&&(l=l.skip(i)),l=l.orderBy("updatedAt","desc"),l=l.field({wyID:!0,model:!0,createdAt:!0,updatedAt:!0,organizationId:!0,"data.title":!0,"data.name":!0,"data.description":!0});const a=await l.get(),f=await this.connection.collection.where(s).count();return{data:a.data,total:f.total,page:Math.floor(i/o)+1,pageSize:o,hasMore:i+o<f.total}}catch(n){throw console.error("Failed to perform full text search:",n),new Error(`Failed to perform full text search: ${n}`)}}}class Tv{constructor(e={}){this.config={cloudbaseConfig:{env:"mobenai-weapp-dev-2e8qhi3a963364",persistence:"local",collectionName:"platform-metadata",...e.cloudbaseConfig},getCurrentOrganizationId:e.getCurrentOrganizationId||(()=>null),getCurrentUserId:e.getCurrentUserId||(()=>null),...e},this.connection=new Ih(this.config.cloudbaseConfig),this.throttler=new Oh,this.queryBuilder=new Ah,this.validator=new Th(this.connection),this.crud=new pu(this.connection,this.validator,this.queryBuilder,this.config),this.batch=new Rh(this.crud,this.validator),this.search=new Ch(this.connection,this.queryBuilder)}updateConfig(e){this.config={...this.config,...e},e.cloudbaseConfig&&this.connection.updateConfig(e.cloudbaseConfig),this.crud=new pu(this.connection,this.validator,this.queryBuilder,this.config)}getConfig(){return{...this.config}}ensureInitialized(){return this.connection.ensureInitialized()}get db(){return this.connection.db}get collection(){return this.connection.collection}getRawDB(){return this.connection.getRawDB()}getRawCollection(){return this.connection.getRawCollection()}validateWyIDFormat(e){return this.validator.validateWyIDFormat(e)}async checkWyIDExists(e){return this.validator.checkWyIDExists(e)}async getExistingDocumentInfo(e){return this.validator.getExistingDocumentInfo(e)}async getWyIDStats(){return this.validator.getWyIDStats()}async create(e){return this.crud.create(e)}async findById(e,t,n={}){const o={model:e,wyID:t,options:n};return this.throttler.withThrottle("findById",o,async()=>this.crud.findById(e,t,n))}async findList(e,t={},n={}){const o={model:e,filter:t,options:n};return this.throttler.withThrottle("findList",o,async()=>this.crud.findList(e,t,n))}async findByIds(e,t,n={}){const o={model:e,wyIDs:t,options:n};return this.throttler.withThrottle("findByIds",o,async()=>this.crud.findByIds(e,t,n))}async update(e,t,n){return this.crud.update(e,t,n)}async softDelete(e,t,n){return this.crud.softDelete(e,t,n)}async hardDelete(e,t){return this.crud.hardDelete(e,t)}async count(e,t={}){const n={model:e,filter:t};return this.throttler.withThrottle("count",n,async()=>this.crud.count(e,t))}async batchCreate(e){return this.batch.batchCreate(e)}async batchUpdate(e,t){return this.batch.batchUpdate(e,t)}async batchSoftDelete(e,t,n){return this.batch.batchSoftDelete(e,t,n)}async batchHardDelete(e,t){return this.batch.batchHardDelete(e,t)}async batchValidate(e){return this.batch.batchValidate(e)}async search(e,t,n={}){const o={model:e,searchText:t,options:n};return this.throttler.withThrottle("search",o,async()=>this.search.search(e,t,n))}async advancedSearch(e,t,n={}){const o={model:e,searchCriteria:t,options:n};return this.throttler.withThrottle("advancedSearch",o,async()=>this.search.advancedSearch(e,t,n))}async fullTextSearch(e,t={}){const n={searchText:e,options:t};return this.throttler.withThrottle("fullTextSearch",n,async()=>this.search.fullTextSearch(e,t))}async getStatsByModel(){return this.search.getStatsByModel()}async getStatsByOrganization(){return this.search.getStatsByOrganization()}async getStatsByTimeRange(e,t,n="day"){return this.search.getStatsByTimeRange(e,t,n)}async getRecentActivity(e=50,t=null){return this.search.getRecentActivity(e,t)}buildWhereCondition(e){return this.queryBuilder.buildWhereCondition(e)}async runTransaction(e){throw console.warn("Transaction is temporarily disabled. Operations will be executed sequentially."),new Error("Transaction is not supported in browser environment. Please use sequential operations or migrate to server-side.")}async createInTransaction(e,t){throw console.warn("createInTransaction is temporarily disabled."),new Error("Transaction operations are not supported in browser environment.")}async updateInTransaction(e,t,n,o){throw console.warn("updateInTransaction is temporarily disabled."),new Error("Transaction operations are not supported in browser environment.")}async deleteInTransaction(e,t,n,o){throw console.warn("deleteInTransaction is temporarily disabled."),new Error("Transaction operations are not supported in browser environment.")}clearPendingRequests(){this.throttler.clearPendingRequests()}getPendingRequestCount(){return this.throttler.getPendingRequestCount()}setThrottleTimeout(e){this.throttler.setThrottleTimeout(e)}isConnected(){return this.connection.isConnected()}reset(){this.connection.reset(),this.throttler.clearPendingRequests()}getClientStatus(){return{isConnected:this.isConnected(),pendingRequests:this.getPendingRequestCount(),throttleTimeout:this.throttler.throttleTimeout,config:this.getConfig(),components:{connection:!!this.connection,throttler:!!this.throttler,validator:!!this.validator,crud:!!this.crud,batch:!!this.batch,search:!!this.search,queryBuilder:!!this.queryBuilder}}}}const Av=Object.freeze(Object.defineProperty({__proto__:null,BatchOperations:Rh,CRUDOperations:pu,DatabaseClient:Tv,DatabaseConnection:Ih,DocumentBuilder:ma,QueryBuilder:Ah,RequestThrottler:Oh,SearchOperations:Ch,WyIDValidator:Th},Symbol.toStringTag,{value:"Module"}));Gr.DatabaseCore=Av,Gr.utils=kh,Object.defineProperty(Gr,Symbol.toStringTag,{value:"Module"})});