@vegajs/http-client-adapter
Version:
A flexible, type-safe HTTP client adapter for TypeScript and JavaScript. Supports custom adapters and includes an out-of-the-box Axios adapter for easy HTTP request handling.
1 lines • 1.49 kB
JavaScript
var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,o={};((e,r)=>{for(var s in r)t(e,s,{get:r[s],enumerable:!0})})(o,{InterceptorManager:()=>c}),module.exports=(e=o,((e,o,c,p)=>{if(o&&"object"===typeof o||"function"===typeof o)for(let i of s(o))n.call(e,i)||i===c||t(e,i,{get:()=>o[i],enumerable:!(p=r(o,i))||p.enumerable});return e})(t({},"__esModule",{value:!0}),e));class c{constructor(){this.requestInterceptors=[],this.responseInterceptors=[],this.nextId=0}useRequest(e){const t=this.nextId++;return this.requestInterceptors.push({fulfilled:e,id:t}),t}useResponse(e){const t=this.nextId++;return this.responseInterceptors.push({fulfilled:e,id:t}),t}ejectRequest(e){const t=this.requestInterceptors.findIndex((t=>t?.id===e));-1!==t&&(this.requestInterceptors[t]=null)}ejectResponse(e){const t=this.responseInterceptors.findIndex((t=>t?.id===e));-1!==t&&(this.responseInterceptors[t]=null)}clearRequestInterceptors(){this.requestInterceptors=[]}clearResponseInterceptors(){this.responseInterceptors=[]}async executeRequestInterceptors(e){let t=e;for(const s of this.requestInterceptors)if(null!==s)try{t=await s.fulfilled(t)}catch(r){throw console.error("Error in request interceptor:",r),r}return t}async executeResponseInterceptors(e){let t=e;for(const s of this.responseInterceptors)if(null!==s)try{t=await s.fulfilled(t)}catch(r){throw console.error("Error in response interceptor:",r),r}return t}}
;