@topvisor/ui
Version:
Topvisor UI-kit Vue
3 lines (2 loc) • 6.68 kB
JavaScript
define(["require","exports","../.chunks/field-Cvv0SRcJ.amd"],(function(m,f,O){"use strict";if(typeof J>"u")var J=window.Vue;const F=(t={})=>{var o;return t={...t},t.loadingEl??=(o=globalThis.document)==null?void 0:o.body,t.loadingShowSpinner??=!0,t.method??="POST",t.accept??="application/json",t},S=(t,o,r)=>({result:t,errors:o,response:r}),H=t=>t.startsWith("/system_2/common/"),N=(t=!1,o=window.location.href,r)=>{const{protocol:e,hostname:n,port:s}=new URL(o),i=n.split("."),u=!t||i.length<=2||/^[\d.]+$/.test(n)||n==="localhost"?n:i.slice(-2).join(".");return`${e}//${u}${s?`:${s}`:""}`},V=t=>Object.values(t).some(o=>o instanceof FileList||o instanceof File||o instanceof Blob||Array.isArray(o)&&o.some(r=>r instanceof File||r instanceof Blob)),G=(t,o,r)=>{const e={inLoading:!1,path:o,url:t.options.baseUrl+o,options:F(t.options.requestOptions),mockerOptions:void 0,params:{},getInLoading:()=>e.inLoading,setParams:n=>(e.params={...n},e),changeParams:n=>(Object.assign(e.params,n),e),setOptions:n=>(Object.assign(e.options,n),e),setMocker:n=>(e.mockerOptions=n,e),call:async n=>e.exec(n),callFetch:async(n,s)=>e.exec(s,n),callInNewWindow:async n=>{var d,h;const s=e.genData(n),i=t.genMiddlewareCtx(e,s);(h=(d=t.options).onPrepareData)==null||h.call(d,s,i);const{postInWindow:u}=await new Promise((g,y)=>m(["../.chunks/lazy-DSFLxvj4.amd"],g,y));u(e.url,s,"_blank")},callInSelfWindow:async n=>{var d,h;const s=e.genData(n),i=t.genMiddlewareCtx(e,s);(h=(d=t.options).onPrepareData)==null||h.call(d,s,i);const{postInWindow:u}=await new Promise((g,y)=>m(["../.chunks/lazy-DSFLxvj4.amd"],g,y));u(e.url,s,"_self")},genData:(n,s)=>{const i={...e.params};if(delete i.fetch_style,n){let u=[...n];r&&(u=u.filter(d=>r.includes(d))),i.fields=u}else r&&(i.fields=r);return s&&(i.fetch_style=s),i},async exec(n,s){var C,k,T,z,A,D,U,L,M,j,W,v,B,_,$;const i=t.options.Request,u=t.options.fetch,d=e.genData(n,s),h=t.genMiddlewareCtx(e,d);if((k=(C=t.options).onPrepareData)==null||k.call(C,d,h),e.mockerOptions){const{genMockResponse:c}=await new Promise((p,R)=>m(["../.chunks/index-BEI7XZmU.amd"],p,R));return await c(e.mockerOptions,n,d)}const g=V(d);if(g&&e.options.method!=="POST")throw new Error("Files can be sent only in POST requests");let y=e.url,q;if(g){if(e.options.method!=="POST")throw new Error("Files can be sent only in POST requests");const{formDataSerializer:c}=await new Promise((p,R)=>m(["../.chunks/lazy-DSFLxvj4.amd"],p,R));q=c(d)}else e.options.method!=="POST"?y+="?"+await t.options.querySerializer(d):q=t.options.bodySerializer(d);let I;if(this.options.checkFingerprint){const c=this.path+this.options.checkFingerprint;(T=t.abortControllers[c])==null||T.abort();const p=new AbortController;t.abortControllers[c]=p,I=p.signal}const Z={...t.options,method:e.options.method,body:q,signal:I};let x=new i(y,Z);x.headers.set("x-request-id",h.id),x.headers.set("accept",e.options.accept),g||x.headers.set("content-type","application/json");const w={...h,request:x};e.inLoading=!0,(A=(z=e.options).onLoading)==null||A.call(z,e.inLoading,w);let l;const E=await t.middlewareOnRequest(x,w);if(E instanceof Response?l=E:E instanceof i&&(x=E),!l)try{l=await u(x)}catch(c){l=await t.middlewareOnError(c,w)}finally{e.inLoading=!1,(U=(D=e.options).onLoading)==null||U.call(D,e.inLoading,w)}l=await t.middlewareOnResponse(l,w);let a,b,P;try{const c=(L=l.headers.get("content-type"))==null?void 0:L.includes("application/json");b=await l.text(),this.options.accept==="application/json"||c?a=JSON.parse(b):t.useExt?a=S(b,void 0,l):a=b}catch(c){if((c instanceof SyntaxError||c instanceof TypeError)&&(P=c,P.responseText=b),t.useExt&&P){let p=l.status,R=l.statusText;p===200&&(p=1e4,R="Error API response"),a=S(null,[{code:p,string:R}],l),t.options.useApiConsole&&console.error(c)}else throw c}return t.useExt&&(a.response=l,a&&((j=(M=e.options).onApiLoaded)==null||j.call(M,a,w)),a!=null&&a.errors&&(t.options.useApiConsole&&console.warn(new Error("API error"),{res:a}),(B=(v=e.options).onApiError)==null||B.call(v,a,{...w,formatError:P},(W=t.options.requestOptions)==null?void 0:W.onApiError)),a!=null&&a.messages&&(($=(_=e.options).onApiMessage)==null||$.call(_,a,w))),a}};return e};class K{options;useExt;middlewares=[];abortControllers={};constructor(o={},r){o.requestOptions=F(o.requestOptions),o.useApiConsole??=!0,o.fetch??=globalThis.fetch,o.Request??=globalThis.Request,o.querySerializer??=async e=>{const{querySerializer:n}=await new Promise((s,i)=>m(["../.chunks/lazy-DSFLxvj4.amd"],s,i));return n(e)},o.bodySerializer??=e=>typeof e=="string"?e:JSON.stringify(e),this.options=o,this.useExt=r}generateUUID(){return crypto!=null&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,o=>{const r=Math.random()*16|0;return(o==="x"?r:r&3|8).toString(16)})}use(o){this.middlewares.push(o)}gen(o,r){return G(this,o,r)}genAny(o,r){return this.gen(o,r)}genMiddlewareCtx(o,r){const e=this.generateUUID(),n=Object.freeze({baseUrl:this.options.baseUrl,querySerializer:this.options.querySerializer,bodySerializer:this.options.bodySerializer,Request:this.options.Request,fetch:this.options.fetch});return{useExt:this.useExt,requestOptions:o.options,data:r,middlewareData:{},options:n,schemaPath:o.path,id:e}}async middlewareOnRequest(o,r){var e;for(const n of this.middlewares){const s=await((e=n.onRequest)==null?void 0:e.call(n,{...r,request:o}));if(s)if(s instanceof Request)o=s;else{if(s instanceof Response)return s;throw new Error("onRequest: must return new Request() or Response() when modifying the request")}}return o}async middlewareOnError(o,r){var n;let e=o;for(const s of this.middlewares){const i=await((n=s.onError)==null?void 0:n.call(s,{...r,error:e}));if(i){if(i instanceof Response)return i;if(i instanceof Error){e=i;continue}throw new Error("onError: must return new Response() or instance of Error")}}throw e}async middlewareOnResponse(o,r){var e;for(const n of this.middlewares){const s=await((e=n.onResponse)==null?void 0:e.call(n,{...r,response:o}));if(s){if(!(s instanceof Response))throw new Error("onResponse: must return new Response() when modifying the response");o=s}}return o}}const Q=async(...t)=>{const{postInWindow:o}=await new Promise((r,e)=>m(["../.chunks/lazy-DSFLxvj4.amd"],r,e));return o(...t)},X=async(...t)=>{const{dataToForm:o}=await new Promise((r,e)=>m(["../.chunks/lazy-DSFLxvj4.amd"],r,e));return o(...t)},Y=(t={},o)=>new K(t,o);f.genFieldFilter=O.genFieldFilter,f.genFieldOrder=O.genFieldOrder,f.createClient=Y,f.dataToForm=X,f.genExtRes=S,f.getBaseDomainUrl=N,f.isPublicAPI=H,f.postInWindow=Q,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
//# sourceMappingURL=index.amd.js.map