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