Object.defineProperty(exports,"__esModule",{value:!0});var e=require("xior/utils"),t=require("../utils/index.cjs");function r(e,t,r,n,i,s,a){try{var o=e[s](a),u=o.value}catch(e){r(e);return}o.done?t(u):Promise.resolve(u).then(n,i)}function n(){return(n=Object.assign||function(e){for(var t=1;te.toLowerCase()===o);e&&(o=e,n=r.headers[e])}(!n||h)&&(n=E||h?s:a,y[o]=n),"object"!=typeof d||(E&&r.params&&(m=e.merge({},d||{},m)),n===a?p=JSON.stringify(t.trimUndefined(d)):E||n!==s||(p=i(d)))}if(Object.keys(m).length>0){let e=i(m,u);l+=l.includes("?")?`&${e}`:`?${e}`}return n({},r,{_data:p,_url:l,data:d,url:f,method:c,headers:y,isGet:E})},(u=function(){var e=this,t=arguments;return new Promise(function(n,s){var a=i.apply(e,t);function o(e){r(a,n,s,o,u,"next",e)}function u(e){r(a,n,s,o,u,"throw",e)}o(void 0)})}).apply(this,arguments)}function c(e,t,r,n,i,s,a){try{var o=e[s](a),u=o.value}catch(e){r(e);return}o.done?t(u):Promise.resolve(u).then(n,i)}function l(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var s=e.apply(t,r);function a(e){c(s,n,i,a,o,"next",e)}function o(e){c(s,n,i,a,o,"throw",e)}a(void 0)})}}function f(){return(f=Object.assign||function(e){for(var t=1;t(this.REQI.push(e),e),eject:e=>{this.REQI=this.REQI.filter(t=>t!==e)},clear:()=>{this.REQI=[]}},response:{use:(e,t)=>(this.RESI.push({fn:e,onRejected:t}),e),eject:e=>{this.RESI=this.RESI.filter(t=>t.fn!==e)},clear:()=>{this.RESI=[]}}}}get plugins(){return{use:e=>(this.P.push(e),e),eject:e=>{this.P=this.P.filter(t=>t!==e)},clear:()=>{this.P=[]}}}request(t){var r=this;return l(function*(){let n=e.merge({},r.config||{},r.defaults||{},"string"==typeof t?{url:t}:t||{},{headers:{},params:{}});for(let t of(n.withCredentials&&!n.credentials&&(n.credentials="include"),n.paramsSerializer||(n.paramsSerializer=e.encodeParams),r.REQI))n=yield t(n);let i=r.fetch.bind(r);r.P.forEach(e=>{i=e(i,r)});let s=i(n);if(!n._RESIRun){let e=0,t=[];for(r.RESI.forEach(function(e){t.push(e.fn,e.onRejected)});t.length>e;)s=s.then(t[e++],t[e++])}return s})()}fetch(t){return l(function*(){let r;let n=yield function(e){return u.apply(this,arguments)}(t),{url:i,method:s,headers:a,timeout:o,signal:c,data:y,_data:m,_url:E,isGet:P}=n,b=function(e,t){if(null==e)return{};var r,n,i={},s=Object.keys(e);for(n=0;n=0||(i[r]=e[r]);return i}(n,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);t._url=E;let v=[],O=h;if(o&&d){let r=new AbortController;O=setTimeout(()=>{r.abort(new e.XiorTimeoutError(`timeout of ${o}ms exceeded`,t))},o),v.push(r.signal)}c&&v.push(c),r=v[0],v.length>1&&(r=e.anySignal(v,()=>{clearTimeout(O)}));let g=E||i;return t.baseURL&&!e.isAbsoluteURL(g)&&(g=e.joinPath(t.baseURL,g)),fetch(g,f({body:P?h:m},b,{signal:r,method:s,headers:a})).then(l(function*(r){let{responseType:n}=t,i={data:yield function(e,t){return p.apply(this,arguments)}(r,n),response:r,config:t,request:t,status:r.status,statusText:r.statusText,headers:r.headers};return r.ok?i:Promise.reject(new e.XiorError(r.status?`Request failed with status code ${r.status}`:"Network error",t,i))})).finally(()=>{var e;O&&clearTimeout(O),null==r||null==(e=r.clear)||e.call(r)})})()}cG(e){return(t,r)=>this.request(r?f({},r,{method:e,url:t}):{method:e,url:t})}cP(e){return(t,r,n)=>this.request(n?f({},n,{method:e,url:t,data:r}):{method:e,url:t,data:r})}get(e,t){return this.cG("GET")(e,t)}head(e,t){return this.cG("HEAD")(e,t)}post(e,t,r){return this.cP("POST")(e,t,r)}put(e,t,r){return this.cP("PUT")(e,t,r)}patch(e,t,r){return this.cP("PATCH")(e,t,r)}delete(e,t){return this.cG("DELETE")(e,t)}options(e,t){return this.cG("OPTIONS")(e,t)}constructor(e){this.REQI=[],this.RESI=[],this.P=[],this.config=e,this.defaults={params:{},headers:{}}}}y.VERSION="0.6.1";const m=Object.assign(y.create(),{create:y.create,VERSION:y.VERSION});exports.Xior=y,exports.default=m,Object.keys(e).forEach(function(t){"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});