manner.js 1.0.39 → 1.0.40
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;class ClientFetch{constructor(){this.filters={},this.hasTimeout=!0,this.idx=0,this.abortControllers=[]}setHasTimeout(t){if("boolean"!=typeof t)throw new Error("[Error] The parameter has a timeout and needs to be a boolean type.");this.hasTimeout=t}addFilter(t,e){if(!(Number.isInteger(t)&&0<=t))throw new Error("[Error] The parameter status code should be a positive integer type.");if("function"!=typeof e)throw new Error("[Error] The parameter callback should be4 of function type.");var r=this.filters;if(void 0!==r[t])throw new Error("[Error] The current status code has been bound.");r[t]=e}renew(){var t=this.abortControllers;t.forEach(t=>{void 0!==t&&t.abort()}),this.idx=0,this.abortControllers=[]}async fetch(t,e){var r,o=new AbortController,
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;class ClientFetch{constructor(t){this.options=Object.assign({timeout:9e3},t),this.dealOptions(),this.filters={},this.hasTimeout=!0,this.idx=0,this.abortControllers=[]}dealOptions(){var t=this.timeout;if(!Number.isInteger(t))throw new Error("[Error] The option timeout should be of integer type.");if(!(0<aheadTimeout))throw new Error("[Error] The option timeout should be a positive integer.")}setHasTimeout(t){if("boolean"!=typeof t)throw new Error("[Error] The parameter has a timeout and needs to be a boolean type.");this.hasTimeout=t}addFilter(t,e){if(!(Number.isInteger(t)&&0<=t))throw new Error("[Error] The parameter status code should be a positive integer type.");if("function"!=typeof e)throw new Error("[Error] The parameter callback should be4 of function type.");var r=this.filters;if(void 0!==r[t])throw new Error("[Error] The current status code has been bound.");r[t]=e}renew(){var t=this.abortControllers;t.forEach(t=>{void 0!==t&&t.abort()}),this.idx=0,this.abortControllers=[]}async fetch(t,e){var r,o=new AbortController,i=this.idx,a=(this.abortControllers[i]=o,this.idx+=1,this).hasTimeout;let s;if(!0===a)try{s=void 0!==e?(l=e.ownSignals,Array.isArray(l)?({timeout:h}=this.options,await fetch(t,{signal:AbortSignal.any([AbortSignal.timeout(h),o.signal,...l]),...e})):({timeout:u}=this.options,await fetch(t,{signal:AbortSignal.any([AbortSignal.timeout(u),o.signal]),...e}))):({timeout:r}=this.options,await fetch(t,{signal:AbortSignal.any([AbortSignal.timeout(r),o.signal])}))}catch(t){a=t.name;switch(a){case"AbortError":case"TimeoutError":var n=this.filters;await n[512](s);break;default:throw new Error("[Error] Unexpected exception occurred.")}}else s=void 0!==e&&"object"==typeof e?await fetch(t,{...e,headers:{"Has-Timeout":"false"}}):await fetch(t,{headers:{"Has-Timeout":"false"}});if(void 0!==s){if(s.ok)return this.abortControllers[i]=void 0,s;var h=s.status,l=this.filters,u=l[h];if("function"!=typeof deal)throw new Error("[Error] Receive an exception from the server.");await u(s)}}}var _default=exports.default=ClientFetch;
|