3 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			3 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
(function(u,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(u=typeof globalThis<"u"?globalThis:u||self,h(u["ff-request"]={}))})(this,function(u){"use strict";var Ae=Object.defineProperty;var Ce=(u,h,b)=>h in u?Ae(u,h,{enumerable:!0,configurable:!0,writable:!0,value:b}):u[h]=b;var w=(u,h,b)=>(Ce(u,typeof h!="symbol"?h+"":h,b),b),ve=(u,h,b)=>{if(!h.has(u))throw TypeError("Cannot "+b)};var i=(u,h,b)=>(ve(u,h,"read from private field"),b?b.call(u):h.get(u)),y=(u,h,b)=>{if(h.has(u))throw TypeError("Cannot add the same private member more than once");h instanceof WeakSet?h.add(u):h.set(u,b)},N=(u,h,b,V)=>(ve(u,h,"write to private field"),V?V.call(u,b):h.set(u,b),b);var z,k,K,D,ee,te,Y,re,ne,Q,W,q,B,se,$,F,H,ie,X;function h(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,o=-4,f=-5,j=function(g,l){l=l||{};var E=l.verbose||!1;E&&console.log("Normalize the JSON Object"),g=typeof g=="string"?this.JSON.parse(g):g,E&&console.log("Creating a empty dictionary");var d={strings:[],integers:[],floats:[]};E&&console.log("Creating the AST");var p=function x(c){E&&console.log("Calling recursiveAstBuilder with "+this.JSON.stringify(c));var T=typeof c;if(c===null)return{type:"null",index:s};if(typeof c>"u")return{type:"undefined",index:f};if(c instanceof Array){var _=["@"];for(var O in c)c.hasOwnProperty(O)&&_.push(x(c[O]));return _}if(T==="object"){var _=["$"];for(var I in c)c.hasOwnProperty(I)&&(_.push(x(I)),_.push(x(c[I])));return _}if(c==="")return{type:"empty",index:o};if(T==="string"){var P=J.call(d.strings,c);return P==-1&&(d.strings.push(C(c)),P=d.strings.length-1),{type:"strings",index:P}}if(T==="number"&&c%1===0){var P=J.call(d.integers,c);return P==-1&&(d.integers.push(M(c)),P=d.integers.length-1),{type:"integers",index:P}}if(T==="number"){var P=J.call(d.floats,c);return P==-1&&(d.floats.push(c),P=d.floats.length-1),{type:"floats",index:P}}if(T==="boolean")return{type:"boolean",index:c?t:n};throw new Error("Unexpected argument of type "+typeof c)}(g),S=d.strings.length,L=d.integers.length;d.floats.length,E&&console.log("Parsing the dictionary");var U=d.strings.join("|");return U+="^"+d.integers.join("|"),U+="^"+d.floats.join("|"),E&&console.log("Parsing the structure"),U+="^"+function x(c){if(E&&console.log("Calling a recursiveParser with "+this.JSON.stringify(c)),c instanceof Array){var T=c.shift();for(var _ in c)c.hasOwnProperty(_)&&(T+=x(c[_])+"|");return(T[T.length-1]==="|"?T.slice(0,-1):T)+"]"}var O=c.type,I=c.index;if(O==="strings")return M(I);if(O==="integers")return M(S+I);if(O==="floats")return M(S+L+I);if(O==="boolean")return c.index;if(O==="null")return s;if(O==="undefined")return f;if(O==="empty")return o;throw new TypeError("The item is alien!")}(p),E&&console.log("Ending parser"),l.debug?{dictionary:d,ast:p,packed:U}:U},a=function(g,l){l=l||{};var E=g.split("^");l.verbose&&console.log("Building dictionary");var d=[],p=E[0];if(p!==""){p=p.split("|"),l.verbose&&console.log("Parse the strings dictionary");for(var S=0,L=p.length;S<L;S++)d.push(R(p[S]))}if(p=E[1],p!==""){p=p.split("|"),l.verbose&&console.log("Parse the integers dictionary");for(var S=0,L=p.length;S<L;S++)d.push(G(p[S]))}if(p=E[2],p!==""){p=p.split("|"),l.verbose&&console.log("Parse the floats dictionary");for(var S=0,L=p.length;S<L;S++)d.push(parseFloat(p[S]))}p=null,l.verbose&&console.log("Tokenizing the structure");for(var U="",x=[],c=E[3].length,S=0;S<c;S++){var T=E[3].charAt(S);T==="|"||T==="$"||T==="@"||T==="]"?(U&&(x.push(G(U)),U=""),T!=="|"&&x.push(T)):U+=T}var _=x.length,O=0;return l.verbose&&console.log("Starting recursive parser"),function I(){var P=x[O++];if(l.verbose&&console.log("Reading collection type "+(P==="$"?"object":"Array")),P==="@"){for(var v=[];O<_;O++){var m=x[O];if(l.verbose&&console.log("Read "+m+" symbol"),m==="]")return v;if(m==="@"||m==="$")v.push(I());else switch(m){case t:v.push(!0);break;case n:v.push(!1);break;case s:v.push(null);break;case f:v.push(void 0);break;case o:v.push("");break;default:v.push(d[m])}}return l.verbose&&console.log("Parsed "+this.JSON.stringify(v)),v}if(P==="$"){for(var v={};O<_;O++){var A=x[O];if(A==="]")return v;A===o?A="":A=d[A];var m=x[++O];if(m==="@"||m==="$")v[A]=I();else switch(m){case t:v[A]=!0;break;case n:v[A]=!1;break;case s:v[A]=null;break;case f:v[A]=void 0;break;case o:v[A]="";break;default:v[A]=d[m]}}return l.verbose&&console.log("Parsed "+this.JSON.stringify(v)),v}throw new TypeError("Bad token "+P+" isn't a type")}()},C=function(g){return typeof g!="string"?g:g.replace(/[\+ \|\^\%]/g,function(l){return{" ":"+","+":"%2B","|":"%7C","^":"%5E","%":"%25"}[l]})},R=function(g){return typeof g!="string"?g:g.replace(/\+|%2B|%7C|%5E|%25/g,function(l){return{"+":" ","%2B":"+","%7C":"|","%5E":"^","%25":"%"}[l]})},M=function(g){return Number.prototype.toString.call(g,36).toUpperCase()},G=function(g){return parseInt(g,36)},J=Array.prototype.indexOf||function(g,l){for(var E=l||0,d=this.length;E<d;E++)if(this[E]===g)return E;return-1};return{JSON,pack:j,unpack:a}})})(function(e,t){var n=t();for(var s in n)r[s]=n[s]})})(b);const V=h(b);class oe{constructor(e,t,n,s,o){w(this,"code",0);w(this,"message","操作成功");w(this,"data",null);w(this,"url","");w(this,"res","");y(this,z,null);y(this,k,!0);y(this,K,!0);y(this,D,{get:(e,t)=>i(this,ee).call(this,t),ownKeys:()=>Object.keys(i(this,D).getPrototypeOf()||{}),getPrototypeOf:()=>i(this,k)?this:this.data,getOwnPropertyDescriptor:()=>({configurable:!0,enumerable:!0,writable:!0,value:i(this,D).getPrototypeOf()})});y(this,ee,e=>e==="$echoMsg"?i(this,Y):e==="msg"?i(this,te):e==="then"||e==="resp"?(N(this,K,!0),N(this,k,e==="resp"),i(this,re)):e==="catch"?i(this,ne):e==="IS_ECHO_MSG"?i(this,K):Reflect.get(this,e));y(this,te,(e=n=>n,t=!1)=>(i(this,Y).call(this),N(this,k,t),Promise.resolve(e==null?void 0:e(i(this,D).getPrototypeOf()))));y(this,Y,()=>{i(this,K)&&(N(this,K,!1),pe.onMsg(this.code,this.message))});y(this,re,e=>[0,1].includes(this.code)?Promise.resolve(e==null?void 0:e(i(this,D).getPrototypeOf())):Promise.reject(i(this,z)));y(this,ne,e=>Promise.resolve(e(i(this,z))));return this.code=e,this.message=t,this.data=n,this.url=s,this.res=o,N(this,z,new Proxy(this,i(this,D)))}}z=new WeakMap,k=new WeakMap,K=new WeakMap,D=new WeakMap,ee=new WeakMap,te=new WeakMap,Y=new WeakMap,re=new WeakMap,ne=new WeakMap;const ae=(r,e,t,n="/",s="")=>new oe(r,e,t,n,s);var le=["utf8","utf-8","unicode-1-1-utf-8"];function we(r){if(le.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 o=0;o<s.length;o++)n[o]=s[o].charCodeAt(0);return n}}function ye(r){if(le.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){if(typeof e>"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),o=new Array(s.length);for(let f=0;f<s.length;f++)o[f]=String.fromCharCode(s[f]);return decodeURIComponent(escape(o.join("")))}else throw new TypeError("passed argument must be an array buffer view")}}var ue={TextEncoder:we,TextDecoder:ye};const be=new ue.TextEncoder("utf8"),Ee=new ue.TextDecoder("utf8"),fe=r=>{let e=5381;for(let t=0;t<r.length;t++)e=e*33^r.charCodeAt(t);return(e>>>0).toString(16)},he=(r,e)=>r.replace(new RegExp(`^${e}+|${e}+$`,"g"),""),de=r=>be.encode(r||""),Te=r=>Ee.decode(new DataView(r),{}),Oe=62,Z=30,ge=31,Se=63;class Pe{constructor(e){w(this,"encodeTable",[]);w(this,"decodeMap",new Uint8Array(256).fill(255));if(e.length!==Oe)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<e.length;t++)this.decodeMap[e.charCodeAt(t)]=t}encode(e){if(!e||e.length===0)return[];const t=new xe(this).encodeV2(e);return String.fromCharCode(...t)}decode(e){if(!e||e.length===0)return new Uint8Array;const t=new _e(this).decode(e);return new TextDecoder().decode(t)}}class xe{constructor(e){y(this,Q,null);N(this,Q,e)}get6bits(){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&Se}encodeV2(e){this.src=de(e),this.pos=this.src.length*8;const t=[];for(;this.pos>0;){let n=6,s=this.get6bits();(s&Z)===Z&&((this.pos>6||s>ge)&&(n=5),s&=ge),t.push(i(this,Q).encodeTable[s].charCodeAt(0)),this.pos-=n}return t}}Q=new WeakMap;class _e{constructor(e){y(this,W,null);N(this,W,e)}decode(e){const t=new Uint8Array(Math.ceil(e.length*6/8)+1);let n=t.length,s=0,o=0;for(let f=0;f<e.length;f++){const j=e[f].charCodeAt(0),a=i(this,W).decodeMap[j];if(a===255)throw new Error(`CorruptInputError at index ${f}`);f===e.length-1?(o|=a<<s,s+=Math.ceil(Math.log2(a+1))):(a&Z)===Z?(o|=a<<s,s+=5):(o|=a<<s,s+=6),s>=8&&(n--,t[n]=o&255,s%=8,o>>=8)}return s>0&&(n--,t[n]=o&255),t.slice(n)}}W=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 ce{constructor(e,t,n){y(this,q,void 0);y(this,B,void 0);y(this,se,void 0);y(this,$,{"#":new Map,$:new Map});y(this,F,new Map);y(this,H,new Set);w(this,"init",(e,t,n)=>{e&&N(this,se,e),n&&N(this,q,n),t&&N(this,B,new Pe(t)),i(this,ie).call(this)});y(this,ie,()=>{!i(this,H).size||!i(this,q)||(i(this,H).forEach(e=>i(this,X).call(this,...e)),i(this,H).clear())});y(this,X,(e,t,n,s=!1)=>{if(!i(this,q))i(this,H).add([e,t,n,s]);else{const{url:o,method:f,...j}=n||{};i(this,q).call(this,{url:o,method:f,...j}).then(a=>{if(![0,1].includes(a.code))throw ae(a.code,a.msg,a.data,o,a==null?void 0:a.res);return[a.code,a.msg,a.data,o,a==null?void 0:a.res]}).then(a=>((t=="#"||f=="GET")&&i(this,$)[t].set(e,a),t!="#"&&f=="GET"&&!s&&setTimeout(()=>{i(this,$)[t].delete(e)},300),a)).then(a=>{var C;return(C=i(this,F).get(e))==null?void 0:C.forEach((R,M,G)=>{R&&R[0](a),delete G[M]})}).catch(a=>{var C;i(this,$)[t].delete(e),(C=i(this,F).get(e))==null||C.forEach((R,M,G)=>{R&&R[1](a instanceof oe?a:ae(-1,a,null,o)),delete G[M]})}).finally(()=>i(this,F).delete(e))}});w(this,"request",({url:e="/",method:t="GET",...n},s=!1)=>{var M;e=he(e,"/");const o=t.toUpperCase(),f=fe(JSON.stringify([e,o,n])),j=(M=e==null?void 0:e.includes)!=null&&M.call(e,"/_/")?"#":"$",{promise:a,resolve:C,reject:R}=Promise.withResolvers();return i(this,$)[j].has(f)?(console.log("cache",e),C(i(this,$)[j].get(f))):i(this,F).has(f)?i(this,F).get(f).push([C,R]):(i(this,F).set(f,[[C,R]]),i(this,X).call(this,f,j,{url:e,method:o,...n},s)),new Proxy(a,{get:(G,J)=>(...g)=>G.then(l=>ae(...l)[J](...g)).catch(l=>{if(!l instanceof oe)throw l;return typeof l[J]=="function"?l[J](...g):l[J]})})});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&&i(this,$)["#"].clear(),i(this,$).$.clear()});w(this,"decode",(e="",t={})=>{if(e===void 0||e===""||e===null)return t;try{if(!i(this,B))throw new Error("未初始化 appSecret,请先通过 init 设置 appSecret");const n=i(this,B).decode(e);return V.unpack(n)}catch{return console.warn("core.decode",e),t}});w(this,"encode",(e={})=>{if(!i(this,B))throw new Error("未初始化 appSecret,请先通过 init 设置 appSecret");const t=JSON.stringify(e,(n,s)=>s===void 0?null:s);return i(this,B).encode(V.pack(t))});this.init(e,t,n)}}q=new WeakMap,B=new WeakMap,se=new WeakMap,$=new WeakMap,F=new WeakMap,H=new WeakMap,ie=new WeakMap,X=new WeakMap;const pe=ce;ce.onUnhandledRejection=r=>{var e,t,n,s,o,f;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&&((o=(s=r.reason)==null?void 0:s.$echoMsg)==null||o.call(s),(f=r==null?void 0:r.preventDefault)==null||f.call(r))},ce.onMsg=(r,e)=>[0,1].includes(r)?console.log(e):console.warn(e),u.default=pe,u.signature=fe,u.str2uint8array=de,u.trim=he,u.uint8array2str=Te,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
 |