(function(v,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(v=typeof globalThis<"u"?globalThis:v||self,p(v["ff-request"]={}))})(this,function(v){"use strict";var ye=Object.defineProperty;var be=(v,p,P)=>p in v?ye(v,p,{enumerable:!0,configurable:!0,writable:!0,value:P}):v[p]=P;var A=(v,p,P)=>(be(v,typeof p!="symbol"?p+"":p,P),P),ue=(v,p,P)=>{if(!p.has(v))throw TypeError("Cannot "+P)};var u=(v,p,P)=>(ue(v,p,"read from private field"),P?P.call(v):p.get(v)),C=(v,p,P)=>{if(p.has(v))throw TypeError("Cannot add the same private member more than once");p instanceof WeakSet?p.add(v):p.set(v,P)},I=(v,p,P,Y)=>(ue(v,p,"write to private field"),Y?Y.call(v,P):p.set(v,P),P);var G,B,q,D,Q,W,L,X,Z,H,K,k,j,M;function p(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function P(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),r=0;r>>0,d=new Uint8Array(c);o!==h;){for(var S=n[o],O=0,y=c-1;(S!==0||O>>0,d[y]=S%g>>>0,S=S/g>>>0;if(S!==0)throw new Error("Non-zero carry");f=O,o++}for(var a=c-f;a!==c&&d[a]===0;)a++;for(var b=R.repeat(s);a>>0,c=new Uint8Array(h);n[s];){var d=e[n.charCodeAt(s)];if(d===255)return;for(var S=0,O=h-1;(d!==0||S>>0,c[O]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");o=S,s++}for(var y=h-o;y!==h&&c[y]===0;)y++;for(var a=new Uint8Array(f+(h-y)),b=f;y!==h;)a[b++]=c[y++];return a}function z(n){var s=x(n);if(s)return s;throw new Error("Non-base"+g+" character")}return{encode:F,decodeUnsafe:x,decode:z}}var Y=P;const ce=p(Y);var ne={};(function(t){(function(e){e([],function(){var r=-1,i=-2,l=-3,w=-4,g=-5,R=function(s,f){f=f||{};var o=f.verbose||!1;o&&console.log("Normalize the JSON Object"),s=typeof s=="string"?this.JSON.parse(s):s,o&&console.log("Creating a empty dictionary");var h={strings:[],integers:[],floats:[]};o&&console.log("Creating the AST");var c=function y(a){o&&console.log("Calling recursiveAstBuilder with "+this.JSON.stringify(a));var b=typeof a;if(a===null)return{type:"null",index:l};if(typeof a>"u")return{type:"undefined",index:g};if(a instanceof Array){var N=["@"];for(var T in a)a.hasOwnProperty(T)&&N.push(y(a[T]));return N}if(b==="object"){var N=["$"];for(var $ in a)a.hasOwnProperty($)&&(N.push(y($)),N.push(y(a[$])));return N}if(a==="")return{type:"empty",index:w};if(b==="string"){var _=n.call(h.strings,a);return _==-1&&(h.strings.push(J(a)),_=h.strings.length-1),{type:"strings",index:_}}if(b==="number"&&a%1===0){var _=n.call(h.integers,a);return _==-1&&(h.integers.push(x(a)),_=h.integers.length-1),{type:"integers",index:_}}if(b==="number"){var _=n.call(h.floats,a);return _==-1&&(h.floats.push(a),_=h.floats.length-1),{type:"floats",index:_}}if(b==="boolean")return{type:"boolean",index:a?r:i};throw new Error("Unexpected argument of type "+typeof a)}(s),d=h.strings.length,S=h.integers.length;h.floats.length,o&&console.log("Parsing the dictionary");var O=h.strings.join("|");return O+="^"+h.integers.join("|"),O+="^"+h.floats.join("|"),o&&console.log("Parsing the structure"),O+="^"+function y(a){if(o&&console.log("Calling a recursiveParser with "+this.JSON.stringify(a)),a instanceof Array){var b=a.shift();for(var N in a)a.hasOwnProperty(N)&&(b+=y(a[N])+"|");return(b[b.length-1]==="|"?b.slice(0,-1):b)+"]"}var T=a.type,$=a.index;if(T==="strings")return x($);if(T==="integers")return x(d+$);if(T==="floats")return x(d+S+$);if(T==="boolean")return a.index;if(T==="null")return l;if(T==="undefined")return g;if(T==="empty")return w;throw new TypeError("The item is alien!")}(c),o&&console.log("Ending parser"),f.debug?{dictionary:h,ast:c,packed:O}:O},V=function(s,f){f=f||{};var o=s.split("^");f.verbose&&console.log("Building dictionary");var h=[],c=o[0];if(c!==""){c=c.split("|"),f.verbose&&console.log("Parse the strings dictionary");for(var d=0,S=c.length;du(this,Q).call(this,r),ownKeys:()=>Object.keys(u(this,D).getPrototypeOf()||{}),getPrototypeOf:()=>u(this,B)?this:this.data,getOwnPropertyDescriptor:()=>({configurable:!0,enumerable:!0,writable:!0,value:u(this,D).getPrototypeOf()})});C(this,Q,e=>e==="$echoMsg"?u(this,L):e==="msg"?u(this,W):e==="then"||e==="resp"?(I(this,q,!0),I(this,B,e==="resp"),u(this,X)):e==="catch"?u(this,Z):e==="IS_ECHO_MSG"?u(this,q):Reflect.get(this,e));C(this,W,(e=i=>i,r=!1)=>(u(this,L).call(this),I(this,B,r),Promise.resolve(e==null?void 0:e(u(this,D).getPrototypeOf()))));C(this,L,()=>{u(this,q)&&(I(this,q,!1),le.onMsg(this.code,this.message))});C(this,X,e=>[0,1].includes(this.code)?Promise.resolve(e==null?void 0:e(u(this,D).getPrototypeOf())):Promise.reject(u(this,G)));C(this,Z,e=>Promise.resolve(e(u(this,G))));return this.code=e,this.message=r,this.data=i,this.url=l,this.res=w,I(this,G,new Proxy(this,u(this,D)))}}G=new WeakMap,B=new WeakMap,q=new WeakMap,D=new WeakMap,Q=new WeakMap,W=new WeakMap,L=new WeakMap,X=new WeakMap,Z=new WeakMap;const te=(t,e,r,i="/",l="")=>new ee(t,e,r,i,l);var ie=["utf8","utf-8","unicode-1-1-utf-8"];function ge(t){if(ie.indexOf(t)<0&&typeof t<"u"&&t!=null)throw new RangeError("Invalid encoding type. Only utf-8 is supported");this.encoding="utf-8",this.encode=function(e){if(typeof e!="string")throw new TypeError("passed argument must be of tye string");var r=unescape(encodeURIComponent(e)),i=new Uint8Array(r.length);const l=r.split("");for(let w=0;w"u")return"";var i=typeof r<"u"&&i in r?r.stream:!1;if(typeof i!="boolean")throw new TypeError("stream option must be boolean");if(ArrayBuffer.isView(e)){var l=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),w=new Array(l.length);for(let g=0;g{let e=5381;for(let r=0;r>>0).toString(16)},we=(t,e)=>t.replace(new RegExp(`^${e}+|${e}+$`,"g"),""),fe=t=>ve.encode(t||""),he=t=>pe.decode(new DataView(t),{});Promise.withResolvers||(Promise.withResolvers=function(){let t,e;return{promise:new Promise((i,l)=>{t=i,e=l}),resolve:t,reject:e}});class re{constructor(e,r,i=({})=>Promise.reject({code:-1,msg:"请初始化HTTP请求方法主体"})){C(this,H,void 0);C(this,K,void 0);C(this,k,void 0);C(this,j,{"#":new Map,$:new Map});C(this,M,new Map);A(this,"request",({url:e="/",method:r="GET",...i},l=!1)=>{var x,z;const w=r.toUpperCase(),g=ae(JSON.stringify([e,w,i])),R=(x=e==null?void 0:e.includes)!=null&&x.call(e,"/_/")?"#":"$",{promise:V,resolve:J,reject:F}=Promise.withResolvers();return u(this,j)[R].has(g)?(console.log("缓存命中",e),J(u(this,j)[R].get(g))):(u(this,M).has(g)?u(this,M).get(g).push([J,F]):u(this,M).set(g,[[J,F]]),(z=u(this,M).get(g))!=null&&z.some(n=>n)&&u(this,H).call(this,{url:e,method:w,...i}).then(n=>{if(![0,1].includes(n.code))throw te(n.code,n.msg,n.data,e,n==null?void 0:n.res);return[n.code,n.msg,n.data,e,n==null?void 0:n.res]}).then(n=>((R=="#"||l&&w==="GET")&&u(this,j)[R].set(g,n),n)).then(n=>{var s;return(s=u(this,M).get(g))==null?void 0:s.forEach((f,o,h)=>{f&&f[0](n),delete h[o]})}).catch(n=>{var s;u(this,j)[R].delete(g),(s=u(this,M).get(g))==null||s.forEach((f,o,h)=>{f&&f[1](n instanceof ee?n:te(-1,n,null,e)),delete h[o]})}).finally(()=>u(this,M).delete(g))),new Proxy(V,{get:(n,s)=>(...f)=>n.then(o=>te(...o)[s](...f)).catch(o=>{if(!o instanceof ee)throw o;return typeof o[s]=="function"?o[s](...f):o[s]})})});A(this,"get",(e,r={})=>this.request({url:e,method:"GET",params:r}));A(this,"post",(e,r={},i={})=>this.request({url:e,method:"POST",data:r,params:i}));A(this,"put",(e,r={},i={})=>this.request({url:e,method:"PUT",data:r,params:i}));A(this,"del",(e,r={},i={})=>this.request({url:e,method:"DELETE",data:r,params:i}));A(this,"download",(e,r)=>{});A(this,"cache",(e,r={})=>this.request({url:e,method:"GET",params:r},!0));A(this,"list",(e,r={})=>this.get(`/api/${e}/${this.encode(r)}`));A(this,"getAppInfo",()=>{});A(this,"refreshCache",(e=!1)=>{e&&u(this,j)["#"].clear(),u(this,j).$.clear()});A(this,"decode",(e="",r={})=>{if(e===void 0||e===""||e===null)return r;try{const i=u(this,K).decode(e).buffer;return se.unpack(he(i))}catch{return console.warn("core.decode",e),r}});A(this,"encode",(e={})=>{const r=JSON.stringify(e,(i,l)=>l===void 0?null:l);return u(this,K).encode(fe(se.pack(r)))});I(this,k,e),I(this,H,i),I(this,K,ce(r))}}H=new WeakMap,K=new WeakMap,k=new WeakMap,j=new WeakMap,M=new WeakMap;const le=re;re.onUnhandledRejection=t=>{var e,r,i,l,w,g;t!=null&&t.IS_ECHO_MSG?((e=t==null?void 0:t.$echoMsg)==null||e.call(t),(r=t==null?void 0:t.preventDefault)==null||r.call(t)):(i=t.reason)!=null&&i.IS_ECHO_MSG&&((w=(l=t.reason)==null?void 0:l.$echoMsg)==null||w.call(l),(g=t==null?void 0:t.preventDefault)==null||g.call(t))},re.onMsg=(t,e)=>[0,1].includes(t)?console.log(e):console.warn(e),v.default=le,v.signature=ae,v.str2uint8array=fe,v.trim=we,v.uint8array2str=he,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});