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