"use strict";const i=require("./dispatchRequest.js"),u=require("./InterceptorManager.js"),l=require("./mergeConfig.js"),d=require("./defaults.js"),n=require("../utils.js"),o=require("../utils/clone.js");class h{constructor(e={}){n.isPlainObject(e)||(e={},console.warn("设置全局参数必须接收一个Object")),this.config=o.clone({...d.defaults,...e}),this.interceptors={request:new u.InterceptorManager,response:new u.InterceptorManager}}setConfig(e){this.config=e(this.config)}middleware(e){e=l.mergeConfig(this.config,e);const t=[i.dispatchRequest,void 0];let s=Promise.resolve(e);for(this.interceptors.request.forEach(r=>{t.unshift(r.fulfilled,r.rejected)}),this.interceptors.response.forEach(r=>{t.push(r.fulfilled,r.rejected)});t.length;)s=s.then(t.shift(),t.shift());return s}request(e={}){return this.middleware(e)}get(e,t={}){return this.middleware({url:e,method:"GET",...t})}post(e,t,s={}){return this.middleware({url:e,data:t,method:"POST",...s})}put(e,t,s={}){return this.middleware({url:e,data:t,method:"PUT",...s})}delete(e,t,s={}){return this.middleware({url:e,data:t,method:"DELETE",...s})}connect(e,t,s={}){return this.middleware({url:e,data:t,method:"CONNECT",...s})}head(e,t,s={}){return this.middleware({url:e,data:t,method:"HEAD",...s})}options(e,t,s={}){return this.middleware({url:e,data:t,method:"OPTIONS",...s})}trace(e,t,s={}){return this.middleware({url:e,data:t,method:"TRACE",...s})}upload(e,t={}){return t.url=e,t.method="UPLOAD",this.middleware(t)}download(e,t={}){return t.url=e,t.method="DOWNLOAD",this.middleware(t)}}exports.Request=h;
