@done-coding/request-ofetch 0.0.1-alpha.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/index.mjs +1389 -0
- package/lib/index.cjs +1 -0
- package/package.json +34 -20
- package/types/index.d.ts +0 -0
- package/types/main.d.ts +0 -0
- package/types/types.d.ts +0 -0
- package/es/index.js +0 -1958
- package/lib/index.js +0 -1
package/lib/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Ie=Object.defineProperty,Pe=(t,e,n)=>e in t?Ie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,T=(t,e,n)=>(Pe(t,typeof e!="symbol"?e+"":e,n),n),y=(t=>(t.REQUEST_ERROR="REQUEST_ERROR",t.NO_RESPONSE="NO_RESPONSE",t.NO_RESPONSE_TIMEOUT="NO_RESPONSE_TIMEOUT",t.NO_RESPONSE_OFFLINE="NO_RESPONSE_OFFLINE",t.DISPATCH_RESPONSE="DISPATCH_RESPONSE",t.DEAL_ERROR="DEAL_ERROR",t.NO_BUSINESS_CODE="NO_BUSINESS_CODE",t.NO_NETWORK_CODE="NO_NETWORK_CODE",t.ABORT="ABORT",t))(y||{});class v extends Error{constructor({message:e,code:n,isBusinessError:r}){super(e),T(this,"code"),T(this,"isBusinessError"),T(this,"message"),this.message=e,this.code=n,this.isBusinessError=r,this.name="DC Request ERROR"}}class N extends v{constructor({message:e,code:n,cause:r}){super({message:e,code:n,isBusinessError:!1}),T(this,"cause"),this.cause=r}}class st extends v{constructor({message:e,code:n}){super({message:e,code:n,isBusinessError:!0})}}var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Bt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var je=200,ut="__lodash_hash_undefined__",De=1/0,Kt=9007199254740991,Fe="[object Arguments]",xe="[object Function]",Le="[object GeneratorFunction]",Ue="[object Symbol]",Be=/[\\^$.*+?()[\]{}|]/g,Ke=/^\[object .+?Constructor\]$/,Me=/^(?:0|[1-9]\d*)$/,Ge=typeof G=="object"&&G&&G.Object===Object&&G,He=typeof self=="object"&&self&&self.Object===Object&&self,ct=Ge||He||Function("return this")();function qe(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)}function We(t,e){var n=t?t.length:0;return!!n&&ze(t,e,0)>-1}function Qe(t,e,n){for(var r=-1,o=t?t.length:0;++r<o;)if(n(e,t[r]))return!0;return!1}function Mt(t,e){for(var n=-1,r=t?t.length:0,o=Array(r);++n<r;)o[n]=e(t[n],n,t);return o}function ft(t,e){for(var n=-1,r=e.length,o=t.length;++n<r;)t[o+n]=e[n];return t}function Ye(t,e,n,r){for(var o=t.length,i=n+(r?1:-1);r?i--:++i<o;)if(e(t[i],i,t))return i;return-1}function ze(t,e,n){if(e!==e)return Ye(t,Je,n);for(var r=n-1,o=t.length;++r<o;)if(t[r]===e)return r;return-1}function Je(t){return t!==t}function Ve(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}function Xe(t){return function(e){return t(e)}}function Ze(t,e){return t.has(e)}function ke(t,e){return t==null?void 0:t[e]}function tn(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch{}return e}function Gt(t,e){return function(n){return t(e(n))}}var en=Array.prototype,nn=Function.prototype,W=Object.prototype,nt=ct["__core-js_shared__"],Ct=function(){var t=/[^.]+$/.exec(nt&&nt.keys&&nt.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),Ht=nn.toString,A=W.hasOwnProperty,lt=W.toString,rn=RegExp("^"+Ht.call(A).replace(Be,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),wt=ct.Symbol,on=Gt(Object.getPrototypeOf,Object),an=W.propertyIsEnumerable,sn=en.splice,Tt=wt?wt.isConcatSpreadable:void 0,it=Object.getOwnPropertySymbols,$t=Math.max,un=Wt(ct,"Map"),L=Wt(Object,"create");function S(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function cn(){this.__data__=L?L(null):{}}function fn(t){return this.has(t)&&delete this.__data__[t]}function ln(t){var e=this.__data__;if(L){var n=e[t];return n===ut?void 0:n}return A.call(e,t)?e[t]:void 0}function hn(t){var e=this.__data__;return L?e[t]!==void 0:A.call(e,t)}function _n(t,e){var n=this.__data__;return n[t]=L&&e===void 0?ut:e,this}S.prototype.clear=cn;S.prototype.delete=fn;S.prototype.get=ln;S.prototype.has=hn;S.prototype.set=_n;function I(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function pn(){this.__data__=[]}function dn(t){var e=this.__data__,n=Q(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():sn.call(e,n,1),!0}function gn(t){var e=this.__data__,n=Q(e,t);return n<0?void 0:e[n][1]}function yn(t){return Q(this.__data__,t)>-1}function En(t,e){var n=this.__data__,r=Q(n,t);return r<0?n.push([t,e]):n[r][1]=e,this}I.prototype.clear=pn;I.prototype.delete=dn;I.prototype.get=gn;I.prototype.has=yn;I.prototype.set=En;function P(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function Rn(){this.__data__={hash:new S,map:new(un||I),string:new S}}function On(t){return Y(this,t).delete(t)}function bn(t){return Y(this,t).get(t)}function vn(t){return Y(this,t).has(t)}function Sn(t,e){return Y(this,t).set(t,e),this}P.prototype.clear=Rn;P.prototype.delete=On;P.prototype.get=bn;P.prototype.has=vn;P.prototype.set=Sn;function H(t){var e=-1,n=t?t.length:0;for(this.__data__=new P;++e<n;)this.add(t[e])}function mn(t){return this.__data__.set(t,ut),this}function Cn(t){return this.__data__.has(t)}H.prototype.add=H.prototype.push=mn;H.prototype.has=Cn;function wn(t,e){var n=ht(t)||Qt(t)?Ve(t.length,String):[],r=n.length,o=!!r;for(var i in t)(e||A.call(t,i))&&!(o&&(i=="length"||Un(i,r)))&&n.push(i);return n}function Q(t,e){for(var n=t.length;n--;)if(Wn(t[n][0],e))return n;return-1}function Tn(t,e,n,r){var o=-1,i=We,a=!0,s=t.length,c=[],h=e.length;if(!s)return c;n&&(e=Mt(e,Xe(n))),r?(i=Qe,a=!1):e.length>=je&&(i=Ze,a=!1,e=new H(e));t:for(;++o<s;){var u=t[o],f=n?n(u):u;if(u=r||u!==0?u:0,a&&f===f){for(var l=h;l--;)if(e[l]===f)continue t;c.push(u)}else i(e,f,r)||c.push(u)}return c}function qt(t,e,n,r,o){var i=-1,a=t.length;for(n||(n=Ln),o||(o=[]);++i<a;){var s=t[i];e>0&&n(s)?e>1?qt(s,e-1,n,r,o):ft(o,s):r||(o[o.length]=s)}return o}function $n(t,e,n){var r=e(t);return ht(t)?r:ft(r,n(t))}function Nn(t){if(!_t(t)||Kn(t))return!1;var e=zt(t)||tn(t)?rn:Ke;return e.test(qn(t))}function An(t){if(!_t(t))return Gn(t);var e=Mn(t),n=[];for(var r in t)r=="constructor"&&(e||!A.call(t,r))||n.push(r);return n}function In(t,e){return t=Object(t),Pn(t,e,function(n,r){return r in t})}function Pn(t,e,n){for(var r=-1,o=e.length,i={};++r<o;){var a=e[r],s=t[a];n(s,a)&&(i[a]=s)}return i}function jn(t,e){return e=$t(e===void 0?t.length-1:e,0),function(){for(var n=arguments,r=-1,o=$t(n.length-e,0),i=Array(o);++r<o;)i[r]=n[e+r];r=-1;for(var a=Array(e+1);++r<e;)a[r]=n[r];return a[e]=i,qe(t,this,a)}}function Dn(t){return $n(t,Jn,xn)}function Y(t,e){var n=t.__data__;return Bn(e)?n[typeof e=="string"?"string":"hash"]:n.map}function Wt(t,e){var n=ke(t,e);return Nn(n)?n:void 0}var Fn=it?Gt(it,Object):Vt,xn=it?function(t){for(var e=[];t;)ft(e,Fn(t)),t=on(t);return e}:Vt;function Ln(t){return ht(t)||Qt(t)||!!(Tt&&t&&t[Tt])}function Un(t,e){return e=e??Kt,!!e&&(typeof t=="number"||Me.test(t))&&t>-1&&t%1==0&&t<e}function Bn(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function Kn(t){return!!Ct&&Ct in t}function Mn(t){var e=t&&t.constructor,n=typeof e=="function"&&e.prototype||W;return t===n}function Gn(t){var e=[];if(t!=null)for(var n in Object(t))e.push(n);return e}function Hn(t){if(typeof t=="string"||zn(t))return t;var e=t+"";return e=="0"&&1/t==-De?"-0":e}function qn(t){if(t!=null){try{return Ht.call(t)}catch{}try{return t+""}catch{}}return""}function Wn(t,e){return t===e||t!==t&&e!==e}function Qt(t){return Qn(t)&&A.call(t,"callee")&&(!an.call(t,"callee")||lt.call(t)==Fe)}var ht=Array.isArray;function Yt(t){return t!=null&&Yn(t.length)&&!zt(t)}function Qn(t){return Jt(t)&&Yt(t)}function zt(t){var e=_t(t)?lt.call(t):"";return e==xe||e==Le}function Yn(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=Kt}function _t(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function Jt(t){return!!t&&typeof t=="object"}function zn(t){return typeof t=="symbol"||Jt(t)&<.call(t)==Ue}function Jn(t){return Yt(t)?wn(t,!0):An(t)}var Vn=jn(function(t,e){return t==null?{}:(e=Mt(qt(e,1),Hn),In(t,Tn(Dn(t),e)))});function Vt(){return[]}var Xn=Vn;const Zn=Bt(Xn);var E=(t=>(t.LOG="log",t.WARN="warn",t.ERROR="error",t))(E||{}),_=(t=>(t.BEFORE="1 发起请求前阶段",t.BEFORE_ERROR="1.1 发起请求前阶段出错",t.BEFORE_ERROR_ORIGIN="1.1.1 发起请求前阶段-原始错误",t.BEFORE_ERROR_PACK="1.1.2 发起请求前阶段-包装后错误",t.NETWORK="2 网络阶段",t.NETWORK_SUCCESS="2.1 网络成功阶段",t.NETWORK_SUCCESS_BUSINESS_SUCCESS="2.1.1 网路成功且业务成功",t.NETWORK_SUCCESS_BUSINESS_FAIL="2.1.2 网络成功但业务失败",t.NETWORK_SUCCESS_DISPATCH_ERROR="2.1.3 网络成功但分发业务结果出错",t.NETWORK_ERROR="2.2 网络出错阶段",t.NETWORK_ERROR_ORIGIN="2.2.1 网络出错阶段-原始错误",t.NETWORK_ERROR_PACK="2.2.2 网络出错阶段-包装后错误",t.DEAL_ERROR="3 处理错误阶段",t.DEAL_ERROR_ERROR="3.1 处理错误阶段出错",t.DEAL_ERROR_RESULT="3.2 处理错误结果",t.DEAL_ERROR_RESULT_RELOAD="3.2.1 处理错误结果-重新请求",t.DEAL_ERROR_RESULT_CONTINUE="3.2.2 处理错误结果-正常抛错",t))(_||{});const p=({stage:t,data:e},n="log")=>{console[n](t,e instanceof v?Zn({...e},"cause"):e)},$=t=>t instanceof Error?t.message:"未知错误",Xt=(t,{getBusinessCode:e,getBusinessMsg:n,getBusinessData:r,businessSuccessCodeList:o=[200],isSuccessBusinessCode:i},a)=>{a&&p({stage:_.NETWORK_SUCCESS,data:t},E.LOG);try{const s=e(t),c=n(t);if(i?i(s):o.includes(s)){const h={code:s,data:r(t),message:c};return a&&p({stage:_.NETWORK_SUCCESS_BUSINESS_SUCCESS,data:h},E.LOG),h}else{if(s===void 0)throw new Error("业务code未定义");const h=new st({code:s,message:c??"未知错误"});return a&&p({stage:_.NETWORK_SUCCESS_BUSINESS_FAIL,data:h},E.ERROR),Promise.reject(h)}}catch(s){a&&p({stage:_.NETWORK_SUCCESS_DISPATCH_ERROR,data:s},E.ERROR);const c=new N({code:y.DISPATCH_RESPONSE,message:$(s)??"分发响应结果执行出错",cause:s});return Promise.reject(c)}},kn=t=>new Promise((e,n)=>{t({success:r=>e(r),fail:r=>n(r)})});var Zt=9007199254740991,tr="[object Arguments]",er="[object Function]",nr="[object GeneratorFunction]",rr=/^(?:0|[1-9]\d*)$/;function or(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)}function ir(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}function ar(t,e){return function(n){return t(e(n))}}var z=Object.prototype,K=z.hasOwnProperty,kt=z.toString,te=z.propertyIsEnumerable,sr=ar(Object.keys,Object),Nt=Math.max,ur=!te.call({valueOf:1},"valueOf");function cr(t,e){var n=gr(t)||dr(t)?ir(t.length,String):[],r=n.length,o=!!r;for(var i in t)(e||K.call(t,i))&&!(o&&(i=="length"||ne(i,r)))&&n.push(i);return n}function ee(t,e,n){var r=t[e];(!(K.call(t,e)&&oe(r,n))||n===void 0&&!(e in t))&&(t[e]=n)}function fr(t){if(!re(t))return sr(t);var e=[];for(var n in Object(t))K.call(t,n)&&n!="constructor"&&e.push(n);return e}function lr(t,e){return e=Nt(e===void 0?t.length-1:e,0),function(){for(var n=arguments,r=-1,o=Nt(n.length-e,0),i=Array(o);++r<o;)i[r]=n[e+r];r=-1;for(var a=Array(e+1);++r<e;)a[r]=n[r];return a[e]=i,or(t,this,a)}}function hr(t,e,n,r){n||(n={});for(var o=-1,i=e.length;++o<i;){var a=e[o],s=r?r(n[a],t[a],a,n,t):void 0;ee(n,a,s===void 0?t[a]:s)}return n}function _r(t){return lr(function(e,n){var r=-1,o=n.length,i=o>1?n[o-1]:void 0,a=o>2?n[2]:void 0;for(i=t.length>3&&typeof i=="function"?(o--,i):void 0,a&&pr(n[0],n[1],a)&&(i=o<3?void 0:i,o=1),e=Object(e);++r<o;){var s=n[r];s&&t(e,s,r,i)}return e})}function ne(t,e){return e=e??Zt,!!e&&(typeof t=="number"||rr.test(t))&&t>-1&&t%1==0&&t<e}function pr(t,e,n){if(!ie(n))return!1;var r=typeof e;return(r=="number"?J(n)&&ne(e,n.length):r=="string"&&e in n)?oe(n[e],t):!1}function re(t){var e=t&&t.constructor,n=typeof e=="function"&&e.prototype||z;return t===n}function oe(t,e){return t===e||t!==t&&e!==e}function dr(t){return yr(t)&&K.call(t,"callee")&&(!te.call(t,"callee")||kt.call(t)==tr)}var gr=Array.isArray;function J(t){return t!=null&&Rr(t.length)&&!Er(t)}function yr(t){return Or(t)&&J(t)}function Er(t){var e=ie(t)?kt.call(t):"";return e==er||e==nr}function Rr(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=Zt}function ie(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function Or(t){return!!t&&typeof t=="object"}var br=_r(function(t,e){if(ur||re(e)||J(e)){hr(e,vr(e),t);return}for(var n in e)K.call(e,n)&&ee(t,n,e[n])});function vr(t){return J(t)?cr(t):fr(t)}var Sr=br;const mr=Bt(Sr),ae=(t,e)=>{try{return t()}catch(n){return e&&p({stage:_.DEAL_ERROR_ERROR,data:n},E.ERROR),{canShowErrorToast:!0,newError:new N({code:y.DEAL_ERROR,message:$(n)??"处理RequestFailResult错误时出错",cause:n}),reload:!1}}};class se{constructor(e){T(this,"options"),T(this,"request",async(n,r=!1)=>{var o;r&&p({stage:_.BEFORE,data:n});const{uiConfig:i={},...a}=n,s=mr({},this.uiConfig,i),c={uiConfig:s},h={...a,BASE_PATH:this.basePath,TIMEOUT:this.timeout,debug:r};try{return await this.issue(h,c)}catch(u){const f=await ae(()=>{var l;return r&&p({stage:_.DEAL_ERROR,data:u}),((l=this.beforeError)==null?void 0:l.call(this,u,{apiConfig:n,extendConfig:c}))||{canShowErrorToast:!0,newError:u}},r);if(f.reload)return r&&p({stage:_.DEAL_ERROR_RESULT_RELOAD}),this.request(n);{const{newError:l,canShowErrorToast:M=!0}=f;M&&(s.errorToast??!0)&&((o=this.showToast)==null||o.call(this,l.message));let d;return l instanceof v?d=l:l.isBusinessError?d=new st(l):d=new N(l),r&&p({stage:_.DEAL_ERROR_RESULT_CONTINUE,data:d}),Promise.reject(d)}}}),this.options=e}get basePath(){return this.options.basePath}get timeout(){return this.options.timeout}get uiConfig(){return this.options.uiConfig||{}}get issue(){return this.options.issue}get beforeError(){return this.options.beforeError}get showToast(){return this.options.showToast}}const Cr=t=>new se(t);var R=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ue(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var wr=200,pt="__lodash_hash_undefined__",Tr=1/0,ce=9007199254740991,$r="[object Arguments]",Nr="[object Function]",Ar="[object GeneratorFunction]",Ir="[object Symbol]",Pr=/[\\^$.*+?()[\]{}|]/g,jr=/^\[object .+?Constructor\]$/,Dr=/^(?:0|[1-9]\d*)$/,Fr=typeof R=="object"&&R&&R.Object===Object&&R,xr=typeof self=="object"&&self&&self.Object===Object&&self,dt=Fr||xr||Function("return this")();function Lr(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)}function Ur(t,e){var n=t?t.length:0;return!!n&&Mr(t,e,0)>-1}function Br(t,e,n){for(var r=-1,o=t?t.length:0;++r<o;)if(n(e,t[r]))return!0;return!1}function fe(t,e){for(var n=-1,r=t?t.length:0,o=Array(r);++n<r;)o[n]=e(t[n],n,t);return o}function gt(t,e){for(var n=-1,r=e.length,o=t.length;++n<r;)t[o+n]=e[n];return t}function Kr(t,e,n,r){for(var o=t.length,i=n+(r?1:-1);r?i--:++i<o;)if(e(t[i],i,t))return i;return-1}function Mr(t,e,n){if(e!==e)return Kr(t,Gr,n);for(var r=n-1,o=t.length;++r<o;)if(t[r]===e)return r;return-1}function Gr(t){return t!==t}function Hr(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}function qr(t){return function(e){return t(e)}}function Wr(t,e){return t.has(e)}function Qr(t,e){return t==null?void 0:t[e]}function Yr(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch{}return e}function le(t,e){return function(n){return t(e(n))}}var zr=Array.prototype,Jr=Function.prototype,V=Object.prototype,rt=dt["__core-js_shared__"],At=function(){var t=/[^.]+$/.exec(rt&&rt.keys&&rt.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),he=Jr.toString,j=V.hasOwnProperty,yt=V.toString,Vr=RegExp("^"+he.call(j).replace(Pr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),It=dt.Symbol,Xr=le(Object.getPrototypeOf,Object),Zr=V.propertyIsEnumerable,kr=zr.splice,Pt=It?It.isConcatSpreadable:void 0,at=Object.getOwnPropertySymbols,jt=Math.max,to=pe(dt,"Map"),U=pe(Object,"create");function m(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function eo(){this.__data__=U?U(null):{}}function no(t){return this.has(t)&&delete this.__data__[t]}function ro(t){var e=this.__data__;if(U){var n=e[t];return n===pt?void 0:n}return j.call(e,t)?e[t]:void 0}function oo(t){var e=this.__data__;return U?e[t]!==void 0:j.call(e,t)}function io(t,e){var n=this.__data__;return n[t]=U&&e===void 0?pt:e,this}m.prototype.clear=eo;m.prototype.delete=no;m.prototype.get=ro;m.prototype.has=oo;m.prototype.set=io;function D(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function ao(){this.__data__=[]}function so(t){var e=this.__data__,n=X(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():kr.call(e,n,1),!0}function uo(t){var e=this.__data__,n=X(e,t);return n<0?void 0:e[n][1]}function co(t){return X(this.__data__,t)>-1}function fo(t,e){var n=this.__data__,r=X(n,t);return r<0?n.push([t,e]):n[r][1]=e,this}D.prototype.clear=ao;D.prototype.delete=so;D.prototype.get=uo;D.prototype.has=co;D.prototype.set=fo;function F(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function lo(){this.__data__={hash:new m,map:new(to||D),string:new m}}function ho(t){return Z(this,t).delete(t)}function _o(t){return Z(this,t).get(t)}function po(t){return Z(this,t).has(t)}function go(t,e){return Z(this,t).set(t,e),this}F.prototype.clear=lo;F.prototype.delete=ho;F.prototype.get=_o;F.prototype.has=po;F.prototype.set=go;function q(t){var e=-1,n=t?t.length:0;for(this.__data__=new F;++e<n;)this.add(t[e])}function yo(t){return this.__data__.set(t,pt),this}function Eo(t){return this.__data__.has(t)}q.prototype.add=q.prototype.push=yo;q.prototype.has=Eo;function Ro(t,e){var n=Et(t)||de(t)?Hr(t.length,String):[],r=n.length,o=!!r;for(var i in t)(e||j.call(t,i))&&!(o&&(i=="length"||Io(i,r)))&&n.push(i);return n}function X(t,e){for(var n=t.length;n--;)if(Uo(t[n][0],e))return n;return-1}function Oo(t,e,n,r){var o=-1,i=Ur,a=!0,s=t.length,c=[],h=e.length;if(!s)return c;n&&(e=fe(e,qr(n))),r?(i=Br,a=!1):e.length>=wr&&(i=Wr,a=!1,e=new q(e));t:for(;++o<s;){var u=t[o],f=n?n(u):u;if(u=r||u!==0?u:0,a&&f===f){for(var l=h;l--;)if(e[l]===f)continue t;c.push(u)}else i(e,f,r)||c.push(u)}return c}function _e(t,e,n,r,o){var i=-1,a=t.length;for(n||(n=Ao),o||(o=[]);++i<a;){var s=t[i];e>0&&n(s)?e>1?_e(s,e-1,n,r,o):gt(o,s):r||(o[o.length]=s)}return o}function bo(t,e,n){var r=e(t);return Et(t)?r:gt(r,n(t))}function vo(t){if(!Rt(t)||jo(t))return!1;var e=ye(t)||Yr(t)?Vr:jr;return e.test(Lo(t))}function So(t){if(!Rt(t))return Fo(t);var e=Do(t),n=[];for(var r in t)r=="constructor"&&(e||!j.call(t,r))||n.push(r);return n}function mo(t,e){return t=Object(t),Co(t,e,function(n,r){return r in t})}function Co(t,e,n){for(var r=-1,o=e.length,i={};++r<o;){var a=e[r],s=t[a];n(s,a)&&(i[a]=s)}return i}function wo(t,e){return e=jt(e===void 0?t.length-1:e,0),function(){for(var n=arguments,r=-1,o=jt(n.length-e,0),i=Array(o);++r<o;)i[r]=n[e+r];r=-1;for(var a=Array(e+1);++r<e;)a[r]=n[r];return a[e]=i,Lr(t,this,a)}}function To(t){return bo(t,Go,No)}function Z(t,e){var n=t.__data__;return Po(e)?n[typeof e=="string"?"string":"hash"]:n.map}function pe(t,e){var n=Qr(t,e);return vo(n)?n:void 0}var $o=at?le(at,Object):Re,No=at?function(t){for(var e=[];t;)gt(e,$o(t)),t=Xr(t);return e}:Re;function Ao(t){return Et(t)||de(t)||!!(Pt&&t&&t[Pt])}function Io(t,e){return e=e??ce,!!e&&(typeof t=="number"||Dr.test(t))&&t>-1&&t%1==0&&t<e}function Po(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function jo(t){return!!At&&At in t}function Do(t){var e=t&&t.constructor,n=typeof e=="function"&&e.prototype||V;return t===n}function Fo(t){var e=[];if(t!=null)for(var n in Object(t))e.push(n);return e}function xo(t){if(typeof t=="string"||Mo(t))return t;var e=t+"";return e=="0"&&1/t==-Tr?"-0":e}function Lo(t){if(t!=null){try{return he.call(t)}catch{}try{return t+""}catch{}}return""}function Uo(t,e){return t===e||t!==t&&e!==e}function de(t){return Bo(t)&&j.call(t,"callee")&&(!Zr.call(t,"callee")||yt.call(t)==$r)}var Et=Array.isArray;function ge(t){return t!=null&&Ko(t.length)&&!ye(t)}function Bo(t){return Ee(t)&&ge(t)}function ye(t){var e=Rt(t)?yt.call(t):"";return e==Nr||e==Ar}function Ko(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=ce}function Rt(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function Ee(t){return!!t&&typeof t=="object"}function Mo(t){return typeof t=="symbol"||Ee(t)&&yt.call(t)==Ir}function Go(t){return ge(t)?Ro(t,!0):So(t)}var Ho=wo(function(t,e){return t==null?{}:(e=fe(_e(e,1),xo),mo(t,Oo(To(t),e)))});function Re(){return[]}var qo=Ho;const Dt=ue(qo);var Wo="Expected a function",Oe="__lodash_hash_undefined__",be=1/0,Qo="[object Function]",Yo="[object GeneratorFunction]",zo="[object Symbol]",Jo=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Vo=/^\w*$/,Xo=/^\./,Zo=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ko=/[\\^$.*+?()[\]{}|]/g,ti=/\\(\\)?/g,ei=/^\[object .+?Constructor\]$/,ni=typeof R=="object"&&R&&R.Object===Object&&R,ri=typeof self=="object"&&self&&self.Object===Object&&self,Ot=ni||ri||Function("return this")();function oi(t,e){return t==null?void 0:t[e]}function ii(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch{}return e}var ai=Array.prototype,si=Function.prototype,ve=Object.prototype,ot=Ot["__core-js_shared__"],Ft=function(){var t=/[^.]+$/.exec(ot&&ot.keys&&ot.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),Se=si.toString,bt=ve.hasOwnProperty,me=ve.toString,ui=RegExp("^"+Se.call(bt).replace(ko,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),xt=Ot.Symbol,ci=ai.splice,fi=Ce(Ot,"Map"),B=Ce(Object,"create"),Lt=xt?xt.prototype:void 0,Ut=Lt?Lt.toString:void 0;function C(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function li(){this.__data__=B?B(null):{}}function hi(t){return this.has(t)&&delete this.__data__[t]}function _i(t){var e=this.__data__;if(B){var n=e[t];return n===Oe?void 0:n}return bt.call(e,t)?e[t]:void 0}function pi(t){var e=this.__data__;return B?e[t]!==void 0:bt.call(e,t)}function di(t,e){var n=this.__data__;return n[t]=B&&e===void 0?Oe:e,this}C.prototype.clear=li;C.prototype.delete=hi;C.prototype.get=_i;C.prototype.has=pi;C.prototype.set=di;function x(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function gi(){this.__data__=[]}function yi(t){var e=this.__data__,n=k(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():ci.call(e,n,1),!0}function Ei(t){var e=this.__data__,n=k(e,t);return n<0?void 0:e[n][1]}function Ri(t){return k(this.__data__,t)>-1}function Oi(t,e){var n=this.__data__,r=k(n,t);return r<0?n.push([t,e]):n[r][1]=e,this}x.prototype.clear=gi;x.prototype.delete=yi;x.prototype.get=Ei;x.prototype.has=Ri;x.prototype.set=Oi;function w(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function bi(){this.__data__={hash:new C,map:new(fi||x),string:new C}}function vi(t){return tt(this,t).delete(t)}function Si(t){return tt(this,t).get(t)}function mi(t){return tt(this,t).has(t)}function Ci(t,e){return tt(this,t).set(t,e),this}w.prototype.clear=bi;w.prototype.delete=vi;w.prototype.get=Si;w.prototype.has=mi;w.prototype.set=Ci;function k(t,e){for(var n=t.length;n--;)if(xi(t[n][0],e))return n;return-1}function wi(t,e){e=Ai(e,t)?[e]:Ni(e);for(var n=0,r=e.length;t!=null&&n<r;)t=t[Di(e[n++])];return n&&n==r?t:void 0}function Ti(t){if(!Te(t)||Pi(t))return!1;var e=Li(t)||ii(t)?ui:ei;return e.test(Fi(t))}function $i(t){if(typeof t=="string")return t;if(St(t))return Ut?Ut.call(t):"";var e=t+"";return e=="0"&&1/t==-be?"-0":e}function Ni(t){return we(t)?t:ji(t)}function tt(t,e){var n=t.__data__;return Ii(e)?n[typeof e=="string"?"string":"hash"]:n.map}function Ce(t,e){var n=oi(t,e);return Ti(n)?n:void 0}function Ai(t,e){if(we(t))return!1;var n=typeof t;return n=="number"||n=="symbol"||n=="boolean"||t==null||St(t)?!0:Vo.test(t)||!Jo.test(t)||e!=null&&t in Object(e)}function Ii(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function Pi(t){return!!Ft&&Ft in t}var ji=vt(function(t){t=Bi(t);var e=[];return Xo.test(t)&&e.push(""),t.replace(Zo,function(n,r,o,i){e.push(o?i.replace(ti,"$1"):r||n)}),e});function Di(t){if(typeof t=="string"||St(t))return t;var e=t+"";return e=="0"&&1/t==-be?"-0":e}function Fi(t){if(t!=null){try{return Se.call(t)}catch{}try{return t+""}catch{}}return""}function vt(t,e){if(typeof t!="function"||e&&typeof e!="function")throw new TypeError(Wo);var n=function(){var r=arguments,o=e?e.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var a=t.apply(this,r);return n.cache=i.set(o,a),a};return n.cache=new(vt.Cache||w),n}vt.Cache=w;function xi(t,e){return t===e||t!==t&&e!==e}var we=Array.isArray;function Li(t){var e=Te(t)?me.call(t):"";return e==Qo||e==Yo}function Te(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function Ui(t){return!!t&&typeof t=="object"}function St(t){return typeof t=="symbol"||Ui(t)&&me.call(t)==zo}function Bi(t){return t==null?"":$i(t)}function Ki(t,e,n){var r=t==null?void 0:wi(t,e);return r===void 0?n:r}var Mi=Ki;const Gi=ue(Mi),Hi=({basePath:t,timeout:e,beforeRequest:n=c=>c,networkSuccessCodeList:r,isSuccessNetworkCode:o=c=>Array.isArray(r)?r.includes(c):c>=200&&c<300,Fetch:i,instanceCreateConfig:a={},...s})=>{const c=i.create({baseURL:t,timeout:e,...a,onRequest:async u=>{const{options:f,request:l}=u,d=await n({...f,url:l});u.request=d.url,u.options=Dt(d,"url")},onResponseError:async u=>{if(u instanceof v)return Promise.reject(u);const f=new N({code:y.REQUEST_ERROR,message:$(u)??"发起请求出错",cause:u});return Promise.reject(f)},onResponse:async u=>{const{response:f}=u,l=f.status;if(!o(l))throw u}}),{request:h}=Cr({...s,basePath:t,timeout:e,issue:({TIMEOUT:u,DEBUG:f,url:l,...M})=>{const d={timeout:u,...Dt(M,["BASE_PATH"])},$e=Date.now();return c(l,d).then(g=>Xt(g,s,f)).catch(g=>{if(g instanceof v)return f&&p({stage:_.NETWORK_ERROR_ORIGIN,data:g},E.ERROR),Promise.reject(g);const{response:et,request:Ne}=g;let O,b;const Ae=Date.now()-$e;(g.message||"").toLowerCase().includes("timeout")||["FetchError","AbortError"].includes(g.name)&&Ae>(d.timeout||u)?(O=y.NO_RESPONSE_TIMEOUT,b="请求超时"):Gi(globalThis,"navigator.onLine")===!1?(O=y.NO_RESPONSE_OFFLINE,b="网络未连接"):et?(O=et.status,b=et.statusText):Ne?(O=y.NO_RESPONSE,b=$(g)??"未响应"):(O=y.REQUEST_ERROR,b=$(g)??"发起请求出错");const mt=new N({code:O,message:b,cause:g});return f&&p({stage:_.NETWORK_ERROR_PACK,data:mt},E.ERROR),Promise.reject(mt)})}});return h};exports.DebugLevelEnum=E;exports.DebugStageEnum=_;exports.InnerErrorCode=y;exports.Request=se;exports.RequestFailResultBase=v;exports.RequestFailResultBusiness=st;exports.RequestFailResultNetwork=N;exports.callback2Promise=kn;exports.catchBeforeError=ae;exports.createDebugInfo=p;exports.createRequest=Hi;exports.dispatchBusinessResult=Xt;exports.resolveErrorMsg=$;
|
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/request-ofetch",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "请求ofetch配置 支持nuxt",
|
|
5
|
-
"main": "lib/index.
|
|
6
|
-
"module": "es/index.
|
|
5
|
+
"main": "lib/index.cjs",
|
|
6
|
+
"module": "es/index.mjs",
|
|
7
7
|
"types": "types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./es/index.mjs",
|
|
11
|
+
"require": "./lib/index.cjs",
|
|
12
|
+
"types": "./types/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
8
15
|
"publishConfig": {
|
|
9
16
|
"access": "public"
|
|
10
17
|
},
|
|
@@ -13,22 +20,34 @@
|
|
|
13
20
|
"es",
|
|
14
21
|
"types"
|
|
15
22
|
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"serve": "vite",
|
|
25
|
+
"clean": "rimraf es lib types",
|
|
26
|
+
"dev": "vite build --watch",
|
|
27
|
+
"predev": "pnpm run clean",
|
|
28
|
+
"build": "vite build",
|
|
29
|
+
"prebuild": "pnpm run clean",
|
|
30
|
+
"prepack": "pnpm build",
|
|
31
|
+
"test": "vitest",
|
|
32
|
+
"coverage": "vitest run --coverage"
|
|
33
|
+
},
|
|
16
34
|
"repository": {
|
|
17
35
|
"type": "git",
|
|
18
|
-
"url": "
|
|
36
|
+
"url": "git@gitee.com:justsosu/done-coding-request.git",
|
|
19
37
|
"directory": "packages/ofetch"
|
|
20
38
|
},
|
|
21
39
|
"author": "JustSoSu",
|
|
22
|
-
"license": "
|
|
40
|
+
"license": "MIT",
|
|
23
41
|
"devDependencies": {
|
|
24
42
|
"@types/jsdom": "^21.1.6",
|
|
25
|
-
"@types/lodash": "^4.
|
|
43
|
+
"@types/lodash.get": "^4.4.9",
|
|
44
|
+
"@types/lodash.omit": "^4.5.9",
|
|
26
45
|
"@types/qs": "^6.9.9",
|
|
27
46
|
"@vitest/coverage-istanbul": "^1.1.1",
|
|
28
47
|
"csstype": "^3.1.2",
|
|
29
48
|
"jsdom": "^23.0.1",
|
|
30
|
-
"lodash": "^4.17.21",
|
|
31
49
|
"msw": "^2.2.8",
|
|
50
|
+
"ofetch": "^1.3.4",
|
|
32
51
|
"rimraf": "^5.0.1",
|
|
33
52
|
"typescript": "^5.2.2",
|
|
34
53
|
"vite": "^5.0.10",
|
|
@@ -37,17 +56,12 @@
|
|
|
37
56
|
},
|
|
38
57
|
"sideEffects": [],
|
|
39
58
|
"dependencies": {
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
59
|
+
"@done-coding/request-base": "^1.0.0",
|
|
60
|
+
"lodash.get": "^4.4.2",
|
|
61
|
+
"lodash.omit": "^4.5.0"
|
|
43
62
|
},
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"prebuild": "pnpm run clean",
|
|
50
|
-
"test": "vitest",
|
|
51
|
-
"coverage": "vitest run --coverage"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"ofetch": "^1.3.4"
|
|
65
|
+
},
|
|
66
|
+
"gitHead": "c7964ac36e3943edba6bf308ed358019d92face3"
|
|
67
|
+
}
|
package/types/index.d.ts
CHANGED
|
File without changes
|
package/types/main.d.ts
CHANGED
|
File without changes
|
package/types/types.d.ts
CHANGED
|
File without changes
|