applets-request-mode-list
Advanced tools
Comparing version
@@ -43,2 +43,2 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).apiHttp={})}(this,(function(t){"use strict"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */function B(t){if(null===t||"[object Object]"!==function(t){return Object.prototype.toString.call(t)}(t))return!1;var e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}function Q(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(0===t.length)return Object.create(null);var r=Object.create(null);function n(t,e){B(r[e])&&B(t)?r[e]=Q(r[e],t):B(t)?r[e]=Q({},t):Array.isArray(t)?r[e]=Q(t):r[e]=t}return r=Array.isArray(t[0])?[]:Object.create(null),t.forEach((function(t){Z(t,n)})),r}function Z(t,e){if(null!=t){var r=t;"object"!=typeof t&&(r=[t]),Array.isArray(r)?r.forEach((function(r,n){e.call(null,r,n,t)})):Object.keys(r).forEach((function(t){e.call(null,r[t],t,r)}))}}function et(){if("undefined"!=typeof wx||"undefined"!=typeof my)return function(){if("undefined"!=typeof wx)return wx;if("undefined"!=typeof my)return my;if("undefined"!=typeof swan)return swan;if("undefined"!=typeof tt)return tt;throw new TypeError("Unrecognized Platform")}().request;throw new TypeError("Unrecognized Platform")}function rt(t){function e(t){if("string"!=typeof t)return t;try{return JSON.parse(t)}catch(e){return t}}function r(t){var e=Q({},t);return e.headers=t.header,delete e.header,delete e.Adapter,e}return new Promise((function(n,o){var i=t.Adapter,a=function(t){return"undefined"!=typeof wx?function(t){var e={url:t.url||"",method:t.method,data:t.data,header:t.headers,dataType:"json",timeout:t.timeout},r=t.dataType||"json";return e.dataType=r,t.responseType&&"json"!==t.responseType&&(e.dataType="其他"),e}(t):"undefined"!=typeof my?function(t){var e={url:t.url||"",method:t.method,data:t.data,headers:t.headers,dataType:"json",timeout:t.timeout},r=t.dataType||"json";return e.dataType=r,t.responseType&&"json"!==t.responseType&&(e.dataType="其他"),e}(t):t}(t),u=r(t);if(!i)throw new TypeError("Adapter is undefined or null");var s=new i(u),c=et()($($({},a),{success:function(t){s.resolve(function(t){return null==t?{headers:{},status:200,data:{},response:t}:{headers:t.header,status:t.statusCode,data:e(t.data),response:t}}(t),n)},fail:function(t){var e=function(t,e){return t&&(t.errMsg||"").toString().toLowerCase().includes("timeout")?{msg:"Timeout of "+(e||"")+" ms exceeded",type:"TIMEOUT"}:{msg:"Network Error",type:"NETWORK_ERROR"}}(t,a.timeout),r={errMsg:e.msg,status:e.type,extra:t};s.reject(r,o)},complete:function(){c=null}}));s.subscribeCancelEvent((function(t){o(t),c.abort(),c=null})),"function"==typeof t.getRequestTask&&t.getRequestTask(rt)}))}function nt(t){return rt(t)}function ot(t){if(null===t||"[object Object]"!==function(t){return Object.prototype.toString.call(t)}(t))return!1;var e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}function it(t,e){if(null!=t){var r=t;"object"!=typeof t&&(r=[t]),Array.isArray(r)?r.forEach((function(r,n){e.call(null,r,n,t)})):Object.keys(r).forEach((function(t){e.call(null,r[t],t,r)}))}}function at(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(0===t.length)return Object.create(null);var r=Object.create(null);function n(t,e){ot(r[e])&&ot(t)?r[e]=at(r[e],t):ot(t)?r[e]=at({},t):Array.isArray(t)?r[e]=at(t):r[e]=t}return r=Array.isArray(t[0])?[]:Object.create(null),t.forEach((function(t){it(t,n)})),r}Y.defaults.adapter=nt;var ut=function(){function t(t,e){this.hadRetry=0,this.retryTimes=2,this.interval=2e3,this.baseURL="",this.url="",this.fnName="",this.method="GET";var r=t.retryTimes,n=t.interval;this.baseURL=t.baseURL,this.url=t.url,this.fnName=t.fnName,this.method=t.method||this.method,this.retryTimes=this.getValidNumber(this.retryTimes,r),this.interval=this.getValidNumber(this.interval,n),this.appletsRequest=e}return t.prototype.getValidNumber=function(t,e){return e||0===e?e:t},t.prototype.http=function(t){var r=this;return new Promise((function(n,o){r.request(e(e({},t||{}),{url:r.url,method:r.method}),n,o)}))},t.prototype.request=function(t,e,r){var n=this;Promise.resolve(t).then((function(t){return n.appletsRequest(t)})).then((function(t){n.hadRetry=0,e(t)})).catch((function(o){if(n.isRetryError(o)&&n.hadRetry<n.retryTimes){n.hadRetry+=1;var i=at(t,o.options||{});n.request(i,e,r)}else n.isIntervalRetryError(o)&&n.hadRetry<n.retryTimes?setTimeout((function(){n.hadRetry+=1,n.request(t,e,r)}),n.interval):r(n.isRetryError(o)?o.originalErr:o)}))},t.prototype.isRetryError=function(t){return!!t&&"RETRY_ERROR"===t.errCode},t.prototype.isIntervalRetryError=function(t){return!!t&&("NETWORK_ERROR"===t.status||"TIMEOUT"===t.status)},t}(),st=function(){function t(t,r){var n;this.apiList=Object.create(null),this.apis=Object.create(null),this.baseURL=t.baseURL,this.appletsRequest=Y.create(e(e({},at(((n=R()).adapter=nt,n),r||{})),{baseURL:this.baseURL})),this.createApiItem(t.apiList)}return t.prototype.createApiItem=function(t){if(o=t,Array.isArray(o)){var r=Object.create(null);t.forEach((function(t){t.fnName&&(r[t.fnName]=t)}));var n=t.map((function(t){return t.fnName}));return this.apiList=e(e({},this.apiList),r),void this.generateApiFn(n)}var o;if(ot(t)){this.apiList=e(e({},this.apiList),t);n=Object.keys(t);this.generateApiFn(n)}},t.prototype.generateApiFn=function(t){var r=this;t.forEach((function(t){var n=r.apiList[t],o={baseURL:r.baseURL,fnName:t,method:n.method,url:n.apiUrl,interval:n.interval,retryTimes:n.retryTimes};if("function"==typeof r.apis[t])throw new Error(t+" already exists in apiList");r.apis[t]=function(t){var i=new ut(o,r.appletsRequest),a=e(e({},t||{}),{apiConfig:n});return i.http(a)},r.apis[t]=function(t,e){if("string"==typeof e)return t;for(var r in e)t[r]=e[r];return t}(r.apis[t],o)}))},t.prototype.addApiList=function(t){this.createApiItem(t)},t.prototype.createRetryError=function(t,e){return{errCode:"RETRY_ERROR",originalErr:t,options:e}},t.prototype.addRequestInterceptor=function(t,e){this.appletsRequest.interceptors.request.use(t,e)},t.prototype.addResponseInterceptor=function(t,e){this.appletsRequest.interceptors.response.use(t,e)},t.prototype.createCancelToken=function(){return new this.appletsRequest.CancelToken},t.prototype.transformConfig=function(t){this.appletsRequest.defaults.transformConfig=t},t}();t.default=st,Object.defineProperty(t,"__esModule",{value:!0})}));//# sourceMappingURL=applets-request-mode-list.min.js.map | ||
***************************************************************************** */function B(t){if(null===t||"[object Object]"!==function(t){return Object.prototype.toString.call(t)}(t))return!1;var e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}function Q(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(0===t.length)return Object.create(null);var r=Object.create(null);function n(t,e){B(r[e])&&B(t)?r[e]=Q(r[e],t):B(t)?r[e]=Q({},t):Array.isArray(t)?r[e]=Q(t):r[e]=t}return r=Array.isArray(t[0])?[]:Object.create(null),t.forEach((function(t){Z(t,n)})),r}function Z(t,e){if(null!=t){var r=t;"object"!=typeof t&&(r=[t]),Array.isArray(r)?r.forEach((function(r,n){e.call(null,r,n,t)})):Object.keys(r).forEach((function(t){e.call(null,r[t],t,r)}))}}function et(){if("undefined"!=typeof wx||"undefined"!=typeof my)return function(){if("undefined"!=typeof wx)return wx;if("undefined"!=typeof my)return my;if("undefined"!=typeof swan)return swan;if("undefined"!=typeof tt)return tt;throw new TypeError("Unrecognized Platform")}().request;throw new TypeError("Unrecognized Platform")}function rt(t){function e(t){if("string"!=typeof t)return t;try{return JSON.parse(t)}catch(e){return t}}function r(t){var e=Q({},t);return e.headers=t.headers,delete e.header,delete e.Adapter,e}return new Promise((function(n,o){var i=t.Adapter,a=function(t){return"undefined"!=typeof wx?function(t){var e={url:t.url||"",method:t.method,data:t.data,header:t.headers,dataType:"json",timeout:t.timeout},r=t.dataType||"json";return e.dataType=r,t.responseType&&"json"!==t.responseType&&(e.dataType="其他"),e}(t):"undefined"!=typeof my?function(t){var e={url:t.url||"",method:t.method,data:t.data,headers:t.headers,dataType:"json",timeout:t.timeout},r=t.dataType||"json";return e.dataType=r,t.responseType&&"json"!==t.responseType&&(e.dataType="其他"),e}(t):t}(t),u=r(t);if(!i)throw new TypeError("Adapter is undefined or null");var s=new i(u),c=et()($($({},a),{success:function(t){s.resolve(function(t){return null==t?{headers:{},status:200,data:{},response:t}:{headers:t.header,status:t.statusCode,data:e(t.data),response:t}}(t),n)},fail:function(t){var e=function(t,e){return t&&(t.errMsg||"").toString().toLowerCase().includes("timeout")?{msg:"Timeout of "+(e||"")+" ms exceeded",type:"TIMEOUT"}:{msg:"Network Error",type:"NETWORK_ERROR"}}(t,a.timeout),r={errMsg:e.msg,status:e.type,extra:t};s.reject(r,o)},complete:function(){c=null}}));s.subscribeCancelEvent((function(t){o(t),c.abort(),c=null})),"function"==typeof t.getRequestTask&&t.getRequestTask(rt)}))}function nt(t){return rt(t)}function ot(t){if(null===t||"[object Object]"!==function(t){return Object.prototype.toString.call(t)}(t))return!1;var e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}function it(t,e){if(null!=t){var r=t;"object"!=typeof t&&(r=[t]),Array.isArray(r)?r.forEach((function(r,n){e.call(null,r,n,t)})):Object.keys(r).forEach((function(t){e.call(null,r[t],t,r)}))}}function at(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(0===t.length)return Object.create(null);var r=Object.create(null);function n(t,e){ot(r[e])&&ot(t)?r[e]=at(r[e],t):ot(t)?r[e]=at({},t):Array.isArray(t)?r[e]=at(t):r[e]=t}return r=Array.isArray(t[0])?[]:Object.create(null),t.forEach((function(t){it(t,n)})),r}Y.defaults.adapter=nt;var ut=function(){function t(t,e){this.hadRetry=0,this.retryTimes=2,this.interval=2e3,this.baseURL="",this.url="",this.fnName="",this.method="GET";var r=t.retryTimes,n=t.interval;this.baseURL=t.baseURL,this.url=t.url,this.fnName=t.fnName,this.method=t.method||this.method,this.retryTimes=this.getValidNumber(this.retryTimes,r),this.interval=this.getValidNumber(this.interval,n),this.appletsRequest=e}return t.prototype.getValidNumber=function(t,e){return e||0===e?e:t},t.prototype.http=function(t){var r=this;return new Promise((function(n,o){r.request(e(e({},t||{}),{url:r.url,method:r.method}),n,o)}))},t.prototype.request=function(t,e,r){var n=this;Promise.resolve(t).then((function(t){return n.appletsRequest(t)})).then((function(t){n.hadRetry=0,e(t)})).catch((function(o){if(n.isRetryError(o)&&n.hadRetry<n.retryTimes){n.hadRetry+=1;var i=at(t,o.options||{});n.request(i,e,r)}else n.isIntervalRetryError(o)&&n.hadRetry<n.retryTimes?setTimeout((function(){n.hadRetry+=1,n.request(t,e,r)}),n.interval):r(n.isRetryError(o)?o.originalErr:o)}))},t.prototype.isRetryError=function(t){return!!t&&"RETRY_ERROR"===t.errCode},t.prototype.isIntervalRetryError=function(t){return!!t&&("NETWORK_ERROR"===t.status||"TIMEOUT"===t.status)},t}(),st=function(){function t(t,r){var n;this.apiList=Object.create(null),this.apis=Object.create(null),this.baseURL=t.baseURL,this.appletsRequest=Y.create(e(e({},at(((n=R()).adapter=nt,n),r||{})),{baseURL:this.baseURL})),this.createApiItem(t.apiList)}return t.prototype.createApiItem=function(t){if(o=t,Array.isArray(o)){var r=Object.create(null);t.forEach((function(t){t.fnName&&(r[t.fnName]=t)}));var n=t.map((function(t){return t.fnName}));return this.apiList=e(e({},this.apiList),r),void this.generateApiFn(n)}var o;if(ot(t)){this.apiList=e(e({},this.apiList),t);n=Object.keys(t);this.generateApiFn(n)}},t.prototype.generateApiFn=function(t){var r=this;t.forEach((function(t){var n=r.apiList[t],o={baseURL:r.baseURL,fnName:t,method:n.method,url:n.apiUrl,interval:n.interval,retryTimes:n.retryTimes};if("function"==typeof r.apis[t])throw new Error(t+" already exists in apiList");r.apis[t]=function(t){var i=new ut(o,r.appletsRequest),a=e(e({},t||{}),{apiConfig:n});return i.http(a)},r.apis[t]=function(t,e){if("string"==typeof e)return t;for(var r in e)t[r]=e[r];return t}(r.apis[t],o)}))},t.prototype.addApiList=function(t){this.createApiItem(t)},t.prototype.createRetryError=function(t,e){return{errCode:"RETRY_ERROR",originalErr:t,options:e}},t.prototype.addRequestInterceptor=function(t,e){this.appletsRequest.interceptors.request.use(t,e)},t.prototype.addResponseInterceptor=function(t,e){this.appletsRequest.interceptors.response.use(t,e)},t.prototype.createCancelToken=function(){return new this.appletsRequest.CancelToken},t.prototype.transformConfig=function(t){this.appletsRequest.defaults.transformConfig=t},t}();t.default=st,Object.defineProperty(t,"__esModule",{value:!0})}));//# sourceMappingURL=applets-request-mode-list.min.js.map |
{ | ||
"name": "applets-request-mode-list", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "mini program axios request wechat weapp alipay", | ||
@@ -76,3 +76,3 @@ "main": "dist/applets-request-mode-list.min.js", | ||
"dependencies": { | ||
"applets-request-all": "^1.0.3" | ||
"applets-request-all": "^1.0.4" | ||
}, | ||
@@ -79,0 +79,0 @@ "peerDependencies": { |
@@ -141,12 +141,10 @@ # applets-request-mode-list | ||
### Methods And Properties | ||
## Methods And Properties | ||
#### `constructor(config, [appletsRequestConfig])` | ||
### `constructor(config, [appletsRequestConfig])` | ||
构造函数 | ||
##### options | ||
#### `config` | ||
###### `config` | ||
Type: `Object` Required | ||
@@ -157,3 +155,3 @@ | ||
###### `appletsRequestConfig` | ||
#### `appletsRequestConfig` | ||
@@ -164,3 +162,3 @@ Type: `Object<IAppletsRequestConfig>` Optional | ||
###### `constructor` Example | ||
#### `constructor` Example | ||
@@ -167,0 +165,0 @@ ```javascript |
Sorry, the diff of this file is not supported yet
175275
-0.01%372
-0.53%Updated