diff --git a/dist/ff-request.js b/dist/ff-request.js index d670860..11638e7 100644 --- a/dist/ff-request.js +++ b/dist/ff-request.js @@ -20,7 +20,7 @@ var oe = {}; o = o || {}; var d = o.verbose || !1; d && console.log("Normalize the JSON Object"), h = typeof h == "string" ? this.JSON.parse(h) : h, d && console.log("Creating a empty dictionary"); - var f = { + var u = { strings: [], integers: [], floats: [] @@ -57,22 +57,22 @@ var oe = {}; index: c }; if (w === "string") { - var O = T.call(f.strings, a); - return O == -1 && (f.strings.push(G(a)), O = f.strings.length - 1), { + var O = T.call(u.strings, a); + return O == -1 && (u.strings.push(G(a)), O = u.strings.length - 1), { type: "strings", index: O }; } if (w === "number" && a % 1 === 0) { - var O = T.call(f.integers, a); - return O == -1 && (f.integers.push(F(a)), O = f.integers.length - 1), { + var O = T.call(u.integers, a); + return O == -1 && (u.integers.push(F(a)), O = u.integers.length - 1), { type: "integers", index: O }; } if (w === "number") { - var O = T.call(f.floats, a); - return O == -1 && (f.floats.push(a), O = f.floats.length - 1), { + var O = T.call(u.floats, a); + return O == -1 && (u.floats.push(a), O = u.floats.length - 1), { type: "floats", index: O }; @@ -83,10 +83,10 @@ var oe = {}; index: a ? t : n }; throw new Error("Unexpected argument of type " + typeof a); - }(h), b = f.strings.length, I = f.integers.length; - f.floats.length, d && console.log("Parsing the dictionary"); - var N = f.strings.join("|"); - return N += "^" + f.integers.join("|"), N += "^" + f.floats.join("|"), d && console.log("Parsing the structure"), N += "^" + function P(a) { + }(h), b = u.strings.length, I = u.integers.length; + u.floats.length, d && console.log("Parsing the dictionary"); + var N = u.strings.join("|"); + return N += "^" + u.integers.join("|"), N += "^" + u.floats.join("|"), d && console.log("Parsing the structure"), N += "^" + function P(a) { if (d && console.log("Calling a recursiveParser with " + this.JSON.stringify(a)), a instanceof Array) { var w = a.shift(); for (var x in a) @@ -110,7 +110,7 @@ var oe = {}; return c; throw new TypeError("The item is alien!"); }(g), d && console.log("Ending parser"), o.debug ? { - dictionary: f, + dictionary: u, ast: g, packed: N } : N; @@ -118,26 +118,26 @@ var oe = {}; o = o || {}; var d = h.split("^"); o.verbose && console.log("Building dictionary"); - var f = [], g = d[0]; + var u = [], g = d[0]; if (g !== "") { g = g.split("|"), o.verbose && console.log("Parse the strings dictionary"); for (var b = 0, I = g.length; b < I; b++) - f.push(z(g[b])); + u.push(z(g[b])); } if (g = d[1], g !== "") { g = g.split("|"), o.verbose && console.log("Parse the integers dictionary"); for (var b = 0, I = g.length; b < I; b++) - f.push(u(g[b])); + u.push(f(g[b])); } if (g = d[2], g !== "") { g = g.split("|"), o.verbose && console.log("Parse the floats dictionary"); for (var b = 0, I = g.length; b < I; b++) - f.push(parseFloat(g[b])); + u.push(parseFloat(g[b])); } g = null, o.verbose && console.log("Tokenizing the structure"); for (var N = "", P = [], a = d[3].length, b = 0; b < a; b++) { var w = d[3].charAt(b); - w === "|" || w === "$" || w === "@" || w === "]" ? (N && (P.push(u(N)), N = ""), w !== "|" && P.push(w)) : N += w; + w === "|" || w === "$" || w === "@" || w === "]" ? (N && (P.push(f(N)), N = ""), w !== "|" && P.push(w)) : N += w; } var x = P.length, y = 0; return o.verbose && console.log("Starting recursive parser"), function $() { @@ -167,7 +167,7 @@ var oe = {}; p.push(""); break; default: - p.push(f[_]); + p.push(u[_]); } } return o.verbose && console.log("Parsed " + this.JSON.stringify(p)), p; @@ -177,7 +177,7 @@ var oe = {}; var S = P[y]; if (S === "]") return p; - S === c ? S = "" : S = f[S]; + S === c ? S = "" : S = u[S]; var _ = P[++y]; if (_ === "@" || _ === "$") p[S] = $(); @@ -199,7 +199,7 @@ var oe = {}; p[S] = ""; break; default: - p[S] = f[_]; + p[S] = u[_]; } } return o.verbose && console.log("Parsed " + this.JSON.stringify(p)), p; @@ -228,10 +228,10 @@ var oe = {}; }); }, F = function(h) { return Number.prototype.toString.call(h, 36).toUpperCase(); - }, u = function(h) { + }, f = function(h) { return parseInt(h, 36); }, T = Array.prototype.indexOf || function(h, o) { - for (var d = o || 0, f = this.length; d < f; d++) + for (var d = o || 0, u = this.length; d < u; d++) if (this[d] === h) return d; return -1; @@ -277,7 +277,7 @@ class ee { E(this, Y, (e) => e === "$echoMsg" ? i(this, J) : e === "msg" ? i(this, Q) : e === "then" || e === "resp" ? (A(this, D, !0), A(this, B, e === "resp"), i(this, W)) : e === "catch" ? i(this, X) : e === "IS_ECHO_MSG" ? i(this, D) : Reflect.get(this, e)); E(this, Q, (e = (n) => n, t = !1) => (i(this, J).call(this), A(this, B, t), Promise.resolve(e == null ? void 0 : e(i(this, U).getPrototypeOf())))); E(this, J, () => { - i(this, D) && (A(this, D, !1), Te.onMsg(this.code, this.message)); + i(this, D) && (A(this, D, !1), Pe.onMsg(this.code, this.message)); }); E(this, W, (e) => [0, 1].includes(this.code) ? Promise.resolve(e == null ? void 0 : e(i(this, U).getPrototypeOf())) : Promise.reject(i(this, j))); E(this, X, (e) => Promise.resolve(e(i(this, j)))); @@ -291,7 +291,7 @@ var ie = [ "utf-8", "unicode-1-1-utf-8" ]; -function ue(r) { +function fe(r) { if (ie.indexOf(r) < 0 && typeof r < "u" && r != null) throw new RangeError("Invalid encoding type. Only utf-8 is supported"); this.encoding = "utf-8", this.encode = function(e) { @@ -304,7 +304,7 @@ function ue(r) { return n; }; } -function fe(r) { +function ue(r) { if (ie.indexOf(r) < 0 && typeof r < "u" && r != null) throw new RangeError("Invalid encoding type. Only utf-8 is supported"); this.encoding = "utf-8", this.decode = function(e, t) { @@ -323,20 +323,20 @@ function fe(r) { }; } var ae = { - TextEncoder: ue, - TextDecoder: fe + TextEncoder: fe, + TextDecoder: ue }; const de = new ae.TextEncoder("utf8"), ge = new ae.TextDecoder("utf8"), pe = (r) => { let e = 5381; for (let t = 0; t < r.length; t++) e = e * 33 ^ r.charCodeAt(t); return (e >>> 0).toString(16); -}, xe = (r, e) => r.replace(new RegExp(`^${e}+|${e}+$`, "g"), ""), ve = (r) => de.encode(r || ""), Se = (r) => ge.decode(new DataView(r), {}), we = 62, V = 30, se = 31, ye = 63; -class be { +}, ve = (r, e) => r.replace(new RegExp(`^${e}+|${e}+$`, "g"), ""), we = (r) => de.encode(r || ""), Se = (r) => ge.decode(new DataView(r), {}), ye = 62, V = 30, se = 31, be = 63; +class Ee { constructor(e) { v(this, "encodeTable", []); v(this, "decodeMap", new Uint8Array(256).fill(255)); - if (e.length !== we) + if (e.length !== ye) throw new Error("Encoding alphabet must be 62 characters long"); if (e.includes(` `) || e.includes("\r")) @@ -349,19 +349,19 @@ class be { encode(e) { if (!e || e.length === 0) return []; - const t = new Ee(this).encodeV2(e); + const t = new Oe(this).encodeV2(e); return String.fromCharCode(...t); } // 解码方法 decode(e) { if (!e || e.length === 0) return new Uint8Array(); - const t = new Oe(this).decode(e); + const t = new Te(this).decode(e); return new TextDecoder().decode(t); } } var K; -class Ee { +class Oe { constructor(e) { E(this, K, null); A(this, K, e); @@ -370,10 +370,10 @@ class Ee { let e = this.pos & 7, t = this.pos >> 3; e === 0 && (t -= 1, e = 8); let n = this.src[t] >> 8 - e; - return e < 6 && t > 0 && (n |= this.src[t - 1] << e), n & ye; + return e < 6 && t > 0 && (n |= this.src[t - 1] << e), n & be; } encodeV2(e) { - this.src = ve(e), this.pos = this.src.length * 8; + this.src = we(e), this.pos = this.src.length * 8; const t = []; for (; this.pos > 0; ) { let n = 6, s = this.get6bits(); @@ -384,7 +384,7 @@ class Ee { } K = new WeakMap(); var H; -class Oe { +class Te { constructor(e) { E(this, H, null); A(this, H, e); @@ -423,25 +423,26 @@ class te { E(this, R, /* @__PURE__ */ new Map()); v(this, "request", ({ url: e = "/", method: t = "GET", ...n }, s = !1) => { var F; + e = ve(e, "/"); const c = t.toUpperCase(), l = pe(JSON.stringify([e, c, n])), C = (F = e == null ? void 0 : e.includes) != null && F.call(e, "/_/") ? "#" : "$", { promise: M, resolve: G, reject: z } = Promise.withResolvers(); - return i(this, m)[C].has(l) ? (console.log("cache", e), G(i(this, m)[C].get(l))) : i(this, R).has(l) ? i(this, R).get(l).push([G, z]) : (i(this, R).set(l, [[G, z]]), i(this, L).call(this, { url: e, method: c, ...n }).then((u) => { - if (![0, 1].includes(u.code)) - throw k(u.code, u.msg, u.data, e, u == null ? void 0 : u.res); - return [u.code, u.msg, u.data, e, u == null ? void 0 : u.res]; - }).then((u) => ((C == "#" || c == "GET") && i(this, m)[C].set(l, u), C != "#" && c == "GET" && !s && setTimeout(() => { + return i(this, m)[C].has(l) ? (console.log("cache", e), G(i(this, m)[C].get(l))) : i(this, R).has(l) ? i(this, R).get(l).push([G, z]) : (i(this, R).set(l, [[G, z]]), i(this, L).call(this, { url: e, method: c, ...n }).then((f) => { + if (![0, 1].includes(f.code)) + throw k(f.code, f.msg, f.data, e, f == null ? void 0 : f.res); + return [f.code, f.msg, f.data, e, f == null ? void 0 : f.res]; + }).then((f) => ((C == "#" || c == "GET") && i(this, m)[C].set(l, f), C != "#" && c == "GET" && !s && setTimeout(() => { i(this, m)[C].delete(l); - }, 300), u)).then((u) => { + }, 300), f)).then((f) => { var T; return (T = i(this, R).get(l)) == null ? void 0 : T.forEach((h, o, d) => { - h && h[0](u), delete d[o]; + h && h[0](f), delete d[o]; }); - }).catch((u) => { + }).catch((f) => { var T; i(this, m)[C].delete(l), (T = i(this, R).get(l)) == null || T.forEach((h, o, d) => { - h && h[1](u instanceof ee ? u : k(-1, u, null, e)), delete d[o]; + h && h[1](f instanceof ee ? f : k(-1, f, null, e)), delete d[o]; }); }).finally(() => i(this, R).delete(l))), new Proxy(M, { - get: (u, T) => (...h) => u.then((o) => k(...o)[T](...h)).catch((o) => { + get: (f, T) => (...h) => f.then((o) => k(...o)[T](...h)).catch((o) => { if (!o instanceof ee) throw o; return typeof o[T] == "function" ? o[T](...h) : o[T]; @@ -475,20 +476,20 @@ class te { const t = JSON.stringify(e, (n, s) => s === void 0 ? null : s); return i(this, q).encode(ne.pack(t)); }); - A(this, Z, e), A(this, L, n), A(this, q, new be(t)); + A(this, Z, e), A(this, L, n), A(this, q, new Ee(t)); } } L = new WeakMap(), q = new WeakMap(), Z = new WeakMap(), m = new WeakMap(), R = new WeakMap(); -const Te = te; +const Pe = te; te.onUnhandledRejection = (r) => { var e, t, n, s, c, l; r != null && r.IS_ECHO_MSG ? ((e = r == null ? void 0 : r.$echoMsg) == null || e.call(r), (t = r == null ? void 0 : r.preventDefault) == null || t.call(r)) : (n = r.reason) != null && n.IS_ECHO_MSG && ((c = (s = r.reason) == null ? void 0 : s.$echoMsg) == null || c.call(s), (l = r == null ? void 0 : r.preventDefault) == null || l.call(r)); }; te.onMsg = (r, e) => [0, 1].includes(r) ? console.log(e) : console.warn(e); export { - Te as default, + Pe as default, pe as signature, - ve as str2uint8array, - xe as trim, + we as str2uint8array, + ve as trim, Se as uint8array2str }; diff --git a/dist/ff-request.umd.cjs b/dist/ff-request.umd.cjs index 4ed28c6..9d6457a 100644 --- a/dist/ff-request.umd.cjs +++ b/dist/ff-request.umd.cjs @@ -1,2 +1,2 @@ -(function(c,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(c=typeof globalThis<"u"?globalThis:c||self,d(c["ff-request"]={}))})(this,function(c){"use strict";var Se=Object.defineProperty;var xe=(c,d,b)=>d in c?Se(c,d,{enumerable:!0,configurable:!0,writable:!0,value:b}):c[d]=b;var w=(c,d,b)=>(xe(c,typeof d!="symbol"?d+"":d,b),b),he=(c,d,b)=>{if(!d.has(c))throw TypeError("Cannot "+b)};var o=(c,d,b)=>(he(c,d,"read from private field"),b?b.call(c):d.get(c)),P=(c,d,b)=>{if(d.has(c))throw TypeError("Cannot add the same private member more than once");d instanceof WeakSet?d.add(c):d.set(c,b)},N=(c,d,b,H)=>(he(c,d,"write to private field"),H?H.call(c,b):d.set(c,b),b);var G,J,D,j,X,Z,L,k,ee,z,V,Y,K,te,$,I;function d(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var b={};(function(r){(function(e){e([],function(){var t=-1,n=-2,s=-3,l=-4,u=-5,M=function(f,i){i=i||{};var p=i.verbose||!1;p&&console.log("Normalize the JSON Object"),f=typeof f=="string"?this.JSON.parse(f):f,p&&console.log("Creating a empty dictionary");var g={strings:[],integers:[],floats:[]};p&&console.log("Creating the AST");var v=function _(a){p&&console.log("Calling recursiveAstBuilder with "+this.JSON.stringify(a));var E=typeof a;if(a===null)return{type:"null",index:s};if(typeof a>"u")return{type:"undefined",index:u};if(a instanceof Array){var C=["@"];for(var T in a)a.hasOwnProperty(T)&&C.push(_(a[T]));return C}if(E==="object"){var C=["$"];for(var F in a)a.hasOwnProperty(F)&&(C.push(_(F)),C.push(_(a[F])));return C}if(a==="")return{type:"empty",index:l};if(E==="string"){var S=x.call(g.strings,a);return S==-1&&(g.strings.push(Q(a)),S=g.strings.length-1),{type:"strings",index:S}}if(E==="number"&&a%1===0){var S=x.call(g.integers,a);return S==-1&&(g.integers.push(B(a)),S=g.integers.length-1),{type:"integers",index:S}}if(E==="number"){var S=x.call(g.floats,a);return S==-1&&(g.floats.push(a),S=g.floats.length-1),{type:"floats",index:S}}if(E==="boolean")return{type:"boolean",index:a?t:n};throw new Error("Unexpected argument of type "+typeof a)}(f),O=g.strings.length,q=g.integers.length;g.floats.length,p&&console.log("Parsing the dictionary");var U=g.strings.join("|");return U+="^"+g.integers.join("|"),U+="^"+g.floats.join("|"),p&&console.log("Parsing the structure"),U+="^"+function _(a){if(p&&console.log("Calling a recursiveParser with "+this.JSON.stringify(a)),a instanceof Array){var E=a.shift();for(var C in a)a.hasOwnProperty(C)&&(E+=_(a[C])+"|");return(E[E.length-1]==="|"?E.slice(0,-1):E)+"]"}var T=a.type,F=a.index;if(T==="strings")return B(F);if(T==="integers")return B(O+F);if(T==="floats")return B(O+q+F);if(T==="boolean")return a.index;if(T==="null")return s;if(T==="undefined")return u;if(T==="empty")return l;throw new TypeError("The item is alien!")}(v),p&&console.log("Ending parser"),i.debug?{dictionary:g,ast:v,packed:U}:U},R=function(f,i){i=i||{};var p=f.split("^");i.verbose&&console.log("Building dictionary");var g=[],v=p[0];if(v!==""){v=v.split("|"),i.verbose&&console.log("Parse the strings dictionary");for(var O=0,q=v.length;Oo(this,X).call(this,t),ownKeys:()=>Object.keys(o(this,j).getPrototypeOf()||{}),getPrototypeOf:()=>o(this,J)?this:this.data,getOwnPropertyDescriptor:()=>({configurable:!0,enumerable:!0,writable:!0,value:o(this,j).getPrototypeOf()})});P(this,X,e=>e==="$echoMsg"?o(this,L):e==="msg"?o(this,Z):e==="then"||e==="resp"?(N(this,D,!0),N(this,J,e==="resp"),o(this,k)):e==="catch"?o(this,ee):e==="IS_ECHO_MSG"?o(this,D):Reflect.get(this,e));P(this,Z,(e=n=>n,t=!1)=>(o(this,L).call(this),N(this,J,t),Promise.resolve(e==null?void 0:e(o(this,j).getPrototypeOf()))));P(this,L,()=>{o(this,D)&&(N(this,D,!1),fe.onMsg(this.code,this.message))});P(this,k,e=>[0,1].includes(this.code)?Promise.resolve(e==null?void 0:e(o(this,j).getPrototypeOf())):Promise.reject(o(this,G)));P(this,ee,e=>Promise.resolve(e(o(this,G))));return this.code=e,this.message=t,this.data=n,this.url=s,this.res=l,N(this,G,new Proxy(this,o(this,j)))}}G=new WeakMap,J=new WeakMap,D=new WeakMap,j=new WeakMap,X=new WeakMap,Z=new WeakMap,L=new WeakMap,k=new WeakMap,ee=new WeakMap;const se=(r,e,t,n="/",s="")=>new ne(r,e,t,n,s);var oe=["utf8","utf-8","unicode-1-1-utf-8"];function de(r){if(oe.indexOf(r)<0&&typeof r<"u"&&r!=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 t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);const s=t.split("");for(let l=0;l"u")return"";var n=typeof t<"u"&&n in t?t.stream:!1;if(typeof n!="boolean")throw new TypeError("stream option must be boolean");if(ArrayBuffer.isView(e)){var s=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),l=new Array(s.length);for(let u=0;u{let e=5381;for(let t=0;t>>0).toString(16)},ye=(r,e)=>r.replace(new RegExp(`^${e}+|${e}+$`,"g"),""),le=r=>pe.encode(r||""),we=r=>ve.decode(new DataView(r),{}),be=62,W=30,ue=31,Ee=63;class Te{constructor(e){w(this,"encodeTable",[]);w(this,"decodeMap",new Uint8Array(256).fill(255));if(e.length!==be)throw new Error("Encoding alphabet must be 62 characters long");if(e.includes(` -`)||e.includes("\r"))throw new Error("Encoding alphabet contains newline character");this.encodeTable=e.split(""),this.decodeMap=new Uint8Array(256).fill(255);for(let t=0;t>3;e===0&&(t-=1,e=8);let n=this.src[t]>>8-e;return e<6&&t>0&&(n|=this.src[t-1]<0;){let n=6,s=this.get6bits();(s&W)===W&&((this.pos>6||s>ue)&&(n=5),s&=ue),t.push(o(this,z).encodeTable[s].charCodeAt(0)),this.pos-=n}return t}}z=new WeakMap;class Pe{constructor(e){P(this,V,null);N(this,V,e)}decode(e){const t=new Uint8Array(Math.ceil(e.length*6/8)+1);let n=t.length,s=0,l=0;for(let u=0;u=8&&(n--,t[n]=l&255,s%=8,l>>=8)}return s>0&&(n--,t[n]=l&255),t.slice(n)}}V=new WeakMap,Promise.withResolvers||(Promise.withResolvers=function(){let r,e;return{promise:new Promise((n,s)=>{r=n,e=s}),resolve:r,reject:e}});class ie{constructor(e,t,n=({})=>Promise.reject({code:-1,msg:"请初始化HTTP请求方法主体"})){P(this,Y,void 0);P(this,K,void 0);P(this,te,void 0);P(this,$,{"#":new Map,$:new Map});P(this,I,new Map);w(this,"request",({url:e="/",method:t="GET",...n},s=!1)=>{var B;const l=t.toUpperCase(),u=ce(JSON.stringify([e,l,n])),M=(B=e==null?void 0:e.includes)!=null&&B.call(e,"/_/")?"#":"$",{promise:R,resolve:Q,reject:re}=Promise.withResolvers();return o(this,$)[M].has(u)?(console.log("cache",e),Q(o(this,$)[M].get(u))):o(this,I).has(u)?o(this,I).get(u).push([Q,re]):(o(this,I).set(u,[[Q,re]]),o(this,Y).call(this,{url:e,method:l,...n}).then(h=>{if(![0,1].includes(h.code))throw se(h.code,h.msg,h.data,e,h==null?void 0:h.res);return[h.code,h.msg,h.data,e,h==null?void 0:h.res]}).then(h=>((M=="#"||l=="GET")&&o(this,$)[M].set(u,h),M!="#"&&l=="GET"&&!s&&setTimeout(()=>{o(this,$)[M].delete(u)},300),h)).then(h=>{var x;return(x=o(this,I).get(u))==null?void 0:x.forEach((f,i,p)=>{f&&f[0](h),delete p[i]})}).catch(h=>{var x;o(this,$)[M].delete(u),(x=o(this,I).get(u))==null||x.forEach((f,i,p)=>{f&&f[1](h instanceof ne?h:se(-1,h,null,e)),delete p[i]})}).finally(()=>o(this,I).delete(u))),new Proxy(R,{get:(h,x)=>(...f)=>h.then(i=>se(...i)[x](...f)).catch(i=>{if(!i instanceof ne)throw i;return typeof i[x]=="function"?i[x](...f):i[x]})})});w(this,"get",(e,t={})=>this.request({url:e,method:"GET",params:t}));w(this,"post",(e,t={},n={})=>this.request({url:e,method:"POST",data:t,params:n}));w(this,"put",(e,t={},n={})=>this.request({url:e,method:"PUT",data:t,params:n}));w(this,"del",(e,t={},n={})=>this.request({url:e,method:"DELETE",data:t,params:n}));w(this,"download",(e,t)=>{});w(this,"cache",(e,t={})=>this.request({url:e,method:"GET",params:t},!0));w(this,"list",(e,t={})=>this.get(`/api/${e}/${this.encode(t)}`));w(this,"getAppInfo",()=>{});w(this,"refreshCache",(e=!1)=>{e&&o(this,$)["#"].clear(),o(this,$).$.clear()});w(this,"decode",(e="",t={})=>{if(e===void 0||e===""||e===null)return t;try{const n=o(this,K).decode(e);return H.unpack(n)}catch{return console.warn("core.decode",e),t}});w(this,"encode",(e={})=>{const t=JSON.stringify(e,(n,s)=>s===void 0?null:s);return o(this,K).encode(H.pack(t))});N(this,te,e),N(this,Y,n),N(this,K,new Te(t))}}Y=new WeakMap,K=new WeakMap,te=new WeakMap,$=new WeakMap,I=new WeakMap;const fe=ie;ie.onUnhandledRejection=r=>{var e,t,n,s,l,u;r!=null&&r.IS_ECHO_MSG?((e=r==null?void 0:r.$echoMsg)==null||e.call(r),(t=r==null?void 0:r.preventDefault)==null||t.call(r)):(n=r.reason)!=null&&n.IS_ECHO_MSG&&((l=(s=r.reason)==null?void 0:s.$echoMsg)==null||l.call(s),(u=r==null?void 0:r.preventDefault)==null||u.call(r))},ie.onMsg=(r,e)=>[0,1].includes(r)?console.log(e):console.warn(e),c.default=fe,c.signature=ce,c.str2uint8array=le,c.trim=ye,c.uint8array2str=we,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); +(function(c,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(c=typeof globalThis<"u"?globalThis:c||self,d(c["ff-request"]={}))})(this,function(c){"use strict";var Se=Object.defineProperty;var xe=(c,d,b)=>d in c?Se(c,d,{enumerable:!0,configurable:!0,writable:!0,value:b}):c[d]=b;var w=(c,d,b)=>(xe(c,typeof d!="symbol"?d+"":d,b),b),de=(c,d,b)=>{if(!d.has(c))throw TypeError("Cannot "+b)};var o=(c,d,b)=>(de(c,d,"read from private field"),b?b.call(c):d.get(c)),P=(c,d,b)=>{if(d.has(c))throw TypeError("Cannot add the same private member more than once");d instanceof WeakSet?d.add(c):d.set(c,b)},N=(c,d,b,H)=>(de(c,d,"write to private field"),H?H.call(c,b):d.set(c,b),b);var G,J,D,j,X,Z,L,k,ee,z,V,Y,K,te,$,I;function d(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var b={};(function(r){(function(e){e([],function(){var t=-1,n=-2,s=-3,l=-4,u=-5,M=function(f,i){i=i||{};var p=i.verbose||!1;p&&console.log("Normalize the JSON Object"),f=typeof f=="string"?this.JSON.parse(f):f,p&&console.log("Creating a empty dictionary");var g={strings:[],integers:[],floats:[]};p&&console.log("Creating the AST");var v=function _(a){p&&console.log("Calling recursiveAstBuilder with "+this.JSON.stringify(a));var E=typeof a;if(a===null)return{type:"null",index:s};if(typeof a>"u")return{type:"undefined",index:u};if(a instanceof Array){var C=["@"];for(var T in a)a.hasOwnProperty(T)&&C.push(_(a[T]));return C}if(E==="object"){var C=["$"];for(var F in a)a.hasOwnProperty(F)&&(C.push(_(F)),C.push(_(a[F])));return C}if(a==="")return{type:"empty",index:l};if(E==="string"){var S=x.call(g.strings,a);return S==-1&&(g.strings.push(Q(a)),S=g.strings.length-1),{type:"strings",index:S}}if(E==="number"&&a%1===0){var S=x.call(g.integers,a);return S==-1&&(g.integers.push(B(a)),S=g.integers.length-1),{type:"integers",index:S}}if(E==="number"){var S=x.call(g.floats,a);return S==-1&&(g.floats.push(a),S=g.floats.length-1),{type:"floats",index:S}}if(E==="boolean")return{type:"boolean",index:a?t:n};throw new Error("Unexpected argument of type "+typeof a)}(f),O=g.strings.length,q=g.integers.length;g.floats.length,p&&console.log("Parsing the dictionary");var U=g.strings.join("|");return U+="^"+g.integers.join("|"),U+="^"+g.floats.join("|"),p&&console.log("Parsing the structure"),U+="^"+function _(a){if(p&&console.log("Calling a recursiveParser with "+this.JSON.stringify(a)),a instanceof Array){var E=a.shift();for(var C in a)a.hasOwnProperty(C)&&(E+=_(a[C])+"|");return(E[E.length-1]==="|"?E.slice(0,-1):E)+"]"}var T=a.type,F=a.index;if(T==="strings")return B(F);if(T==="integers")return B(O+F);if(T==="floats")return B(O+q+F);if(T==="boolean")return a.index;if(T==="null")return s;if(T==="undefined")return u;if(T==="empty")return l;throw new TypeError("The item is alien!")}(v),p&&console.log("Ending parser"),i.debug?{dictionary:g,ast:v,packed:U}:U},R=function(f,i){i=i||{};var p=f.split("^");i.verbose&&console.log("Building dictionary");var g=[],v=p[0];if(v!==""){v=v.split("|"),i.verbose&&console.log("Parse the strings dictionary");for(var O=0,q=v.length;Oo(this,X).call(this,t),ownKeys:()=>Object.keys(o(this,j).getPrototypeOf()||{}),getPrototypeOf:()=>o(this,J)?this:this.data,getOwnPropertyDescriptor:()=>({configurable:!0,enumerable:!0,writable:!0,value:o(this,j).getPrototypeOf()})});P(this,X,e=>e==="$echoMsg"?o(this,L):e==="msg"?o(this,Z):e==="then"||e==="resp"?(N(this,D,!0),N(this,J,e==="resp"),o(this,k)):e==="catch"?o(this,ee):e==="IS_ECHO_MSG"?o(this,D):Reflect.get(this,e));P(this,Z,(e=n=>n,t=!1)=>(o(this,L).call(this),N(this,J,t),Promise.resolve(e==null?void 0:e(o(this,j).getPrototypeOf()))));P(this,L,()=>{o(this,D)&&(N(this,D,!1),he.onMsg(this.code,this.message))});P(this,k,e=>[0,1].includes(this.code)?Promise.resolve(e==null?void 0:e(o(this,j).getPrototypeOf())):Promise.reject(o(this,G)));P(this,ee,e=>Promise.resolve(e(o(this,G))));return this.code=e,this.message=t,this.data=n,this.url=s,this.res=l,N(this,G,new Proxy(this,o(this,j)))}}G=new WeakMap,J=new WeakMap,D=new WeakMap,j=new WeakMap,X=new WeakMap,Z=new WeakMap,L=new WeakMap,k=new WeakMap,ee=new WeakMap;const se=(r,e,t,n="/",s="")=>new ne(r,e,t,n,s);var oe=["utf8","utf-8","unicode-1-1-utf-8"];function ge(r){if(oe.indexOf(r)<0&&typeof r<"u"&&r!=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 t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);const s=t.split("");for(let l=0;l"u")return"";var n=typeof t<"u"&&n in t?t.stream:!1;if(typeof n!="boolean")throw new TypeError("stream option must be boolean");if(ArrayBuffer.isView(e)){var s=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),l=new Array(s.length);for(let u=0;u{let e=5381;for(let t=0;t>>0).toString(16)},le=(r,e)=>r.replace(new RegExp(`^${e}+|${e}+$`,"g"),""),ue=r=>ve.encode(r||""),we=r=>ye.decode(new DataView(r),{}),be=62,W=30,fe=31,Ee=63;class Te{constructor(e){w(this,"encodeTable",[]);w(this,"decodeMap",new Uint8Array(256).fill(255));if(e.length!==be)throw new Error("Encoding alphabet must be 62 characters long");if(e.includes(` +`)||e.includes("\r"))throw new Error("Encoding alphabet contains newline character");this.encodeTable=e.split(""),this.decodeMap=new Uint8Array(256).fill(255);for(let t=0;t>3;e===0&&(t-=1,e=8);let n=this.src[t]>>8-e;return e<6&&t>0&&(n|=this.src[t-1]<0;){let n=6,s=this.get6bits();(s&W)===W&&((this.pos>6||s>fe)&&(n=5),s&=fe),t.push(o(this,z).encodeTable[s].charCodeAt(0)),this.pos-=n}return t}}z=new WeakMap;class Pe{constructor(e){P(this,V,null);N(this,V,e)}decode(e){const t=new Uint8Array(Math.ceil(e.length*6/8)+1);let n=t.length,s=0,l=0;for(let u=0;u=8&&(n--,t[n]=l&255,s%=8,l>>=8)}return s>0&&(n--,t[n]=l&255),t.slice(n)}}V=new WeakMap,Promise.withResolvers||(Promise.withResolvers=function(){let r,e;return{promise:new Promise((n,s)=>{r=n,e=s}),resolve:r,reject:e}});class ie{constructor(e,t,n=({})=>Promise.reject({code:-1,msg:"请初始化HTTP请求方法主体"})){P(this,Y,void 0);P(this,K,void 0);P(this,te,void 0);P(this,$,{"#":new Map,$:new Map});P(this,I,new Map);w(this,"request",({url:e="/",method:t="GET",...n},s=!1)=>{var B;e=le(e,"/");const l=t.toUpperCase(),u=ce(JSON.stringify([e,l,n])),M=(B=e==null?void 0:e.includes)!=null&&B.call(e,"/_/")?"#":"$",{promise:R,resolve:Q,reject:re}=Promise.withResolvers();return o(this,$)[M].has(u)?(console.log("cache",e),Q(o(this,$)[M].get(u))):o(this,I).has(u)?o(this,I).get(u).push([Q,re]):(o(this,I).set(u,[[Q,re]]),o(this,Y).call(this,{url:e,method:l,...n}).then(h=>{if(![0,1].includes(h.code))throw se(h.code,h.msg,h.data,e,h==null?void 0:h.res);return[h.code,h.msg,h.data,e,h==null?void 0:h.res]}).then(h=>((M=="#"||l=="GET")&&o(this,$)[M].set(u,h),M!="#"&&l=="GET"&&!s&&setTimeout(()=>{o(this,$)[M].delete(u)},300),h)).then(h=>{var x;return(x=o(this,I).get(u))==null?void 0:x.forEach((f,i,p)=>{f&&f[0](h),delete p[i]})}).catch(h=>{var x;o(this,$)[M].delete(u),(x=o(this,I).get(u))==null||x.forEach((f,i,p)=>{f&&f[1](h instanceof ne?h:se(-1,h,null,e)),delete p[i]})}).finally(()=>o(this,I).delete(u))),new Proxy(R,{get:(h,x)=>(...f)=>h.then(i=>se(...i)[x](...f)).catch(i=>{if(!i instanceof ne)throw i;return typeof i[x]=="function"?i[x](...f):i[x]})})});w(this,"get",(e,t={})=>this.request({url:e,method:"GET",params:t}));w(this,"post",(e,t={},n={})=>this.request({url:e,method:"POST",data:t,params:n}));w(this,"put",(e,t={},n={})=>this.request({url:e,method:"PUT",data:t,params:n}));w(this,"del",(e,t={},n={})=>this.request({url:e,method:"DELETE",data:t,params:n}));w(this,"download",(e,t)=>{});w(this,"cache",(e,t={})=>this.request({url:e,method:"GET",params:t},!0));w(this,"list",(e,t={})=>this.get(`/api/${e}/${this.encode(t)}`));w(this,"getAppInfo",()=>{});w(this,"refreshCache",(e=!1)=>{e&&o(this,$)["#"].clear(),o(this,$).$.clear()});w(this,"decode",(e="",t={})=>{if(e===void 0||e===""||e===null)return t;try{const n=o(this,K).decode(e);return H.unpack(n)}catch{return console.warn("core.decode",e),t}});w(this,"encode",(e={})=>{const t=JSON.stringify(e,(n,s)=>s===void 0?null:s);return o(this,K).encode(H.pack(t))});N(this,te,e),N(this,Y,n),N(this,K,new Te(t))}}Y=new WeakMap,K=new WeakMap,te=new WeakMap,$=new WeakMap,I=new WeakMap;const he=ie;ie.onUnhandledRejection=r=>{var e,t,n,s,l,u;r!=null&&r.IS_ECHO_MSG?((e=r==null?void 0:r.$echoMsg)==null||e.call(r),(t=r==null?void 0:r.preventDefault)==null||t.call(r)):(n=r.reason)!=null&&n.IS_ECHO_MSG&&((l=(s=r.reason)==null?void 0:s.$echoMsg)==null||l.call(s),(u=r==null?void 0:r.preventDefault)==null||u.call(r))},ie.onMsg=(r,e)=>[0,1].includes(r)?console.log(e):console.warn(e),c.default=he,c.signature=ce,c.str2uint8array=ue,c.trim=le,c.uint8array2str=we,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); diff --git a/package.json b/package.json index b984784..6f72b58 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ff-request", "private": true, - "version": "0.9.15", + "version": "0.9.16", "type": "module", "files": [ "dist"