"use strict";var o=Object.defineProperty;var l=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable;var d=(u,e,t)=>e in u?o(u,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):u[e]=t,s=(u,e)=>{for(var t in e||(e={}))h.call(e,t)&&d(u,t,e[t]);if(l)for(var t of l(e))a.call(e,t)&&d(u,t,e[t]);return u};var c=require("./dispatchRequest.js"),n=require("./InterceptorManager.js"),_=require("./mergeConfig.js"),m=require("./defaults.js"),w=require("../utils.js"),q=require("../utils/clone.js");class f{constructor(e={}){w.isPlainObject(e)||(e={},console.warn("\u8BBE\u7F6E\u5168\u5C40\u53C2\u6570\u5FC5\u987B\u63A5\u6536\u4E00\u4E2AObject")),this.config=q.clone(s(s({},m.defaults),e)),this.interceptors={request:new n.InterceptorManager,response:new n.InterceptorManager}}setConfig(e){this.config=e(this.config)}middleware(e){e=_.mergeConfig(this.config,e);const t=[c.dispatchRequest,void 0];let r=Promise.resolve(e);for(this.interceptors.request.forEach(i=>{t.unshift(i.fulfilled,i.rejected)}),this.interceptors.response.forEach(i=>{t.push(i.fulfilled,i.rejected)});t.length;)r=r.then(t.shift(),t.shift());return r}request(e={}){return this.middleware(e)}get(e,t={}){return this.middleware(s({url:e,method:"GET"},t))}post(e,t,r={}){return this.middleware(s({url:e,data:t,method:"POST"},r))}put(e,t,r={}){return this.middleware(s({url:e,data:t,method:"PUT"},r))}delete(e,t,r={}){return this.middleware(s({url:e,data:t,method:"DELETE"},r))}connect(e,t,r={}){return this.middleware(s({url:e,data:t,method:"CONNECT"},r))}head(e,t,r={}){return this.middleware(s({url:e,data:t,method:"HEAD"},r))}options(e,t,r={}){return this.middleware(s({url:e,data:t,method:"OPTIONS"},r))}trace(e,t,r={}){return this.middleware(s({url:e,data:t,method:"TRACE"},r))}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=f;
