Comparing version 0.1.2 to 0.1.3
@@ -25,2 +25,7 @@ export { merge } from 'ts-deepmerge'; | ||
withCredentials?: boolean; | ||
/** | ||
* some API is get data, but the method is not 'GET', | ||
* add `isGet: true`, can let the plugins know this is also a `GET` API | ||
*/ | ||
isGet?: boolean; | ||
} | ||
@@ -27,0 +32,0 @@ type XiorInterceptorRequestConfig<T = any> = XiorRequestConfig & { |
@@ -25,2 +25,7 @@ export { merge } from 'ts-deepmerge'; | ||
withCredentials?: boolean; | ||
/** | ||
* some API is get data, but the method is not 'GET', | ||
* add `isGet: true`, can let the plugins know this is also a `GET` API | ||
*/ | ||
isGet?: boolean; | ||
} | ||
@@ -27,0 +32,0 @@ type XiorInterceptorRequestConfig<T = any> = XiorRequestConfig & { |
{ | ||
"name": "xior", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A lite request lib based on **fetch** with plugins support, and axios similar API", | ||
@@ -5,0 +5,0 @@ "repository": "suhaotian/xior", |
@@ -32,2 +32,7 @@ type ICacheLike<T> = { | ||
withCredentials?: boolean; | ||
/** | ||
* some API is get data, but the method is not 'GET', | ||
* add `isGet: true`, can let the plugins know this is also a `GET` API | ||
*/ | ||
isGet?: boolean; | ||
} | ||
@@ -34,0 +39,0 @@ type XiorInterceptorRequestConfig<T = any> = XiorRequestConfig & { |
@@ -32,2 +32,7 @@ type ICacheLike<T> = { | ||
withCredentials?: boolean; | ||
/** | ||
* some API is get data, but the method is not 'GET', | ||
* add `isGet: true`, can let the plugins know this is also a `GET` API | ||
*/ | ||
isGet?: boolean; | ||
} | ||
@@ -34,0 +39,0 @@ type XiorInterceptorRequestConfig<T = any> = XiorRequestConfig & { |
@@ -1,1 +0,1 @@ | ||
import{lru as t}from"tiny-lru";function e(t,e,n,r,i,u,o){try{var c=t[u](o),l=c.value}catch(t){n(t);return}c.done?e(l):Promise.resolve(l).then(r,i)}function n(t){return function(){var n=this,r=arguments;return new Promise(function(i,u){var o=t.apply(n,r);function c(t){e(o,i,u,c,l,"next",t)}function l(t){e(o,i,u,c,l,"throw",t)}c(void 0)})}}function r(e={}){let{enableCache:r,defaultCache:i=t(100,3e5)}=e;return function(t){return n(function*(e){let{enableCache:u=r,forceUpdate:o,defaultCache:c=i,_url:l,encode:f,data:a}=e,d="GET"===e.method,h=typeof u;if("undefined"===h?d:"function"===h?u(e):!!u){let r=function(t,e,n){let r=e?n(e):"";r&&(r=t.includes("?")?t+"&"+r:t+"?"+r);let[i,u]=r.split("?");if(u){let t=u.split("&");return`${i}?${t.sort().join("&")}`}return r||t}(l,a,f),i=c.get(r);return!i||o?(i=n(function*(){try{return yield t(e)}catch(t){throw"delete"in c?c.delete(r):c.del(r),t}})(),c.set(r,i),i):i.then(t=>(t.fromCache=!0,t))}return t(e)})}}export{r as default}; | ||
import{lru as t}from"tiny-lru";function e(t,e,n,r,i,u,o){try{var c=t[u](o),l=c.value}catch(t){n(t);return}c.done?e(l):Promise.resolve(l).then(r,i)}function n(t){return function(){var n=this,r=arguments;return new Promise(function(i,u){var o=t.apply(n,r);function c(t){e(o,i,u,c,l,"next",t)}function l(t){e(o,i,u,c,l,"throw",t)}c(void 0)})}}function r(e={}){let{enableCache:r,defaultCache:i=t(100,3e5)}=e;return function(t){return n(function*(e){let{enableCache:u=r,forceUpdate:o,defaultCache:c=i,_url:l,encode:f,data:a}=e,d="GET"===e.method||e.isGet,h=typeof u;if("undefined"===h?d:"function"===h?u(e):!!u){let r=function(t,e,n){let r=e?n(e):"";r&&(r=t.includes("?")?t+"&"+r:t+"?"+r);let[i,u]=r.split("?");if(u){let t=u.split("&");return`${i}?${t.sort().join("&")}`}return r||t}(l,a,f),i=c.get(r);return!i||o?(i=n(function*(){try{return yield t(e)}catch(t){throw"delete"in c?c.delete(r):c.del(r),t}})(),c.set(r,i),i):i.then(t=>(t.fromCache=!0,t))}return t(e)})}}export{r as default}; |
@@ -23,2 +23,7 @@ interface XiorRequestConfig<T = any> extends Omit<RequestInit, 'body'> { | ||
withCredentials?: boolean; | ||
/** | ||
* some API is get data, but the method is not 'GET', | ||
* add `isGet: true`, can let the plugins know this is also a `GET` API | ||
*/ | ||
isGet?: boolean; | ||
} | ||
@@ -25,0 +30,0 @@ type XiorInterceptorRequestConfig<T = any> = XiorRequestConfig & { |
@@ -23,2 +23,7 @@ interface XiorRequestConfig<T = any> extends Omit<RequestInit, 'body'> { | ||
withCredentials?: boolean; | ||
/** | ||
* some API is get data, but the method is not 'GET', | ||
* add `isGet: true`, can let the plugins know this is also a `GET` API | ||
*/ | ||
isGet?: boolean; | ||
} | ||
@@ -25,0 +30,0 @@ type XiorInterceptorRequestConfig<T = any> = XiorRequestConfig & { |
@@ -1,1 +0,1 @@ | ||
import"ts-deepmerge";class t extends Error{constructor(t,e,r){super(t),this.request=e,this.config=e,this.response=r}}class e extends t{}function r(t,e,r,n,i,o,u){try{var s=t[o](u),c=s.value}catch(t){r(t);return}s.done?e(c):Promise.resolve(c).then(n,i)}function n(t){return function(){var e=this,n=arguments;return new Promise(function(i,o){var u=t.apply(e,n);function s(t){r(u,i,o,s,c,"next",t)}function c(t){r(u,i,o,s,c,"throw",t)}s(void 0)})}}function i(r={}){let{retryTimes:i,retryInterval:o,enableRetry:u}=r||{retryTimes:2,retryInterval:3e3};return function(r){return n(function*(s){let{retryTimes:c=i,retryInterval:f=o,enableRetry:a=u}=s,l=0;function y(){return h.apply(this,arguments)}function h(){return(h=n(function*(){try{return yield r(s)}catch(r){if(r instanceof t||r instanceof e){let t="GET"===s.method,e=typeof a,n="undefined"===e?t:"function"===e?a(s,r):!!a;if(c===l||!n)throw r;return f&&f>0&&l>0&&(yield new Promise(t=>{setTimeout(()=>{t("ok")},f)})),l++,y()}throw r}})).apply(this,arguments)}return y()})}}export{i as default}; | ||
import"ts-deepmerge";class t extends Error{constructor(t,e,r){super(t),this.request=e,this.config=e,this.response=r}}class e extends t{}function r(t,e,r,n,i,o,u){try{var s=t[o](u),c=s.value}catch(t){r(t);return}s.done?e(c):Promise.resolve(c).then(n,i)}function n(t){return function(){var e=this,n=arguments;return new Promise(function(i,o){var u=t.apply(e,n);function s(t){r(u,i,o,s,c,"next",t)}function c(t){r(u,i,o,s,c,"throw",t)}s(void 0)})}}function i(r={}){let{retryTimes:i,retryInterval:o,enableRetry:u}=r||{retryTimes:2,retryInterval:3e3};return function(r){return n(function*(s){let{retryTimes:c=i,retryInterval:f=o,enableRetry:a=u}=s,l=0;function y(){return h.apply(this,arguments)}function h(){return(h=n(function*(){try{return yield r(s)}catch(r){if(r instanceof t||r instanceof e){let t="GET"===s.method||s.isGet,e=typeof a,n="undefined"===e?t:"function"===e?a(s,r):!!a;if(c===l||!n)throw r;return f&&f>0&&l>0&&(yield new Promise(t=>{setTimeout(()=>{t("ok")},f)})),l++,y()}throw r}})).apply(this,arguments)}return y()})}}export{i as default}; |
@@ -23,2 +23,7 @@ interface XiorRequestConfig<T = any> extends Omit<RequestInit, 'body'> { | ||
withCredentials?: boolean; | ||
/** | ||
* some API is get data, but the method is not 'GET', | ||
* add `isGet: true`, can let the plugins know this is also a `GET` API | ||
*/ | ||
isGet?: boolean; | ||
} | ||
@@ -25,0 +30,0 @@ type XiorInterceptorRequestConfig<T = any> = XiorRequestConfig & { |
@@ -23,2 +23,7 @@ interface XiorRequestConfig<T = any> extends Omit<RequestInit, 'body'> { | ||
withCredentials?: boolean; | ||
/** | ||
* some API is get data, but the method is not 'GET', | ||
* add `isGet: true`, can let the plugins know this is also a `GET` API | ||
*/ | ||
isGet?: boolean; | ||
} | ||
@@ -25,0 +30,0 @@ type XiorInterceptorRequestConfig<T = any> = XiorRequestConfig & { |
@@ -32,2 +32,7 @@ type ICacheLike<T> = { | ||
withCredentials?: boolean; | ||
/** | ||
* some API is get data, but the method is not 'GET', | ||
* add `isGet: true`, can let the plugins know this is also a `GET` API | ||
*/ | ||
isGet?: boolean; | ||
} | ||
@@ -34,0 +39,0 @@ type XiorInterceptorRequestConfig<T = any> = XiorRequestConfig & { |
@@ -32,2 +32,7 @@ type ICacheLike<T> = { | ||
withCredentials?: boolean; | ||
/** | ||
* some API is get data, but the method is not 'GET', | ||
* add `isGet: true`, can let the plugins know this is also a `GET` API | ||
*/ | ||
isGet?: boolean; | ||
} | ||
@@ -34,0 +39,0 @@ type XiorInterceptorRequestConfig<T = any> = XiorRequestConfig & { |
@@ -1,1 +0,1 @@ | ||
import{lru as t}from"tiny-lru";function e(t,e,n,r,i,o,u){try{var l=t[o](u),a=l.value}catch(t){n(t);return}l.done?e(a):Promise.resolve(a).then(r,i)}function n(t){return function(){var n=this,r=arguments;return new Promise(function(i,o){var u=t.apply(n,r);function l(t){e(u,i,o,l,a,"next",t)}function a(t){e(u,i,o,l,a,"throw",t)}l(void 0)})}}function r(e={}){let{enableThrottle:r,threshold:i=1e3,throttleCache:o=t(10)}=e;return function(t){let e=(e,r)=>{let i=n(function*(){try{let n=yield t(r);return o.set(e,{timestamp:Date.now(),value:Promise.resolve(n)}),n}catch(t){throw"delete"in o?o.delete(e):o.del(e),t}})();return o.set(e,{timestamp:Date.now(),value:i}),i};return n(function*(n){let{_url:u,encode:l,threshold:a=i,enableThrottle:f=r,data:s}=n,c="GET"===n.method,m=typeof f;if("undefined"===m?c:"function"===m?f(n):!!f){let t=function(t,e,n){let r=e?n(e):"";r&&(r=t.includes("?")?t+"&"+r:t+"?"+r);let[i,o]=r.split("?");if(o){let t=o.split("&");return`${i}?${t.sort().join("&")}`}return r||t}(u,s,l),r=Date.now(),i=o.get(t)||{timestamp:r};if(r-i.timestamp<=a){let t=i.value;if(t)return t}return e(t,n)}return t(n)})}}export{r as default}; | ||
import{lru as t}from"tiny-lru";function e(t,e,n,r,i,o,u){try{var l=t[o](u),a=l.value}catch(t){n(t);return}l.done?e(a):Promise.resolve(a).then(r,i)}function n(t){return function(){var n=this,r=arguments;return new Promise(function(i,o){var u=t.apply(n,r);function l(t){e(u,i,o,l,a,"next",t)}function a(t){e(u,i,o,l,a,"throw",t)}l(void 0)})}}function r(e={}){let{enableThrottle:r,threshold:i=1e3,throttleCache:o=t(10)}=e;return function(t){let e=(e,r)=>{let i=n(function*(){try{let n=yield t(r);return o.set(e,{timestamp:Date.now(),value:Promise.resolve(n)}),n}catch(t){throw"delete"in o?o.delete(e):o.del(e),t}})();return o.set(e,{timestamp:Date.now(),value:i}),i};return n(function*(n){let{_url:u,encode:l,threshold:a=i,enableThrottle:f=r,data:s}=n,c="GET"===n.method||n.isGet,m=typeof f;if("undefined"===m?c:"function"===m?f(n):!!f){let t=function(t,e,n){let r=e?n(e):"";r&&(r=t.includes("?")?t+"&"+r:t+"?"+r);let[i,o]=r.split("?");if(o){let t=o.split("&");return`${i}?${t.sort().join("&")}`}return r||t}(u,s,l),r=Date.now(),i=o.get(t)||{timestamp:r};if(r-i.timestamp<=a){let t=i.value;if(t)return t}return e(t,n)}return t(n)})}}export{r as default}; |
@@ -317,7 +317,7 @@ [![Build](https://github.com/suhaotian/xior/actions/workflows/check.yml/badge.svg)](https://github.com/suhaotian/xior/actions/workflows/check.yml) | ||
| Param | Type | Default value | Description | | ||
| ------------- | ---------------------------------------------------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------- | | ||
| retryTimes | number | 2 | Set the retry times for failed request | | ||
| retryInterval | number | 3000 | After first time retry, the next retries interval time, default interval is 3 seconds | | ||
| enableRetry | boolean \| ((config: Xiorconfig, error: XiorRequestConfig) => boolean) | (config, error) => config.method === 'GET' | Default only retry if `GET` request error and `retryTimes > 0` | | ||
| Param | Type | Default value | Description | | ||
| ------------- | ---------------------------------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------------- | | ||
| retryTimes | number | 2 | Set the retry times for failed request | | ||
| retryInterval | number | 3000 | After first time retry, the next retries interval time, default interval is 3 seconds | | ||
| enableRetry | boolean \| ((config: Xiorconfig, error: XiorRequestConfig) => boolean) | (config, error) => config.method === 'GET' \|\| config.isGet | Default only retry if `GET` request error and `retryTimes > 0` | | ||
@@ -373,7 +373,7 @@ Basic usage: | ||
| Param | Type | Default value | Description | | ||
| -------------- | -------------------------------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------ | | ||
| threshold | number | 1000 | The number of milliseconds to throttle request invocations to | | ||
| enableThrottle | boolean \| ((config: Xiorconfig) => boolean) | (config) => config.method === 'GET' | Default only enabled in `GET` request | | ||
| throttleCache | CacheLike | lru(10) | CacheLike instance that will be used for storing throttled requests, use `tiny-lru` module | | ||
| Param | Type | Default value | Description | | ||
| -------------- | -------------------------------------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------------ | | ||
| threshold | number | 1000 | The number of milliseconds to throttle request invocations to | | ||
| enableThrottle | boolean \| ((config: Xiorconfig) => boolean) | (config) => config.method === 'GET' \|\| config.isGet | Default only enabled in `GET` request | | ||
| throttleCache | CacheLike | lru(10) | CacheLike instance that will be used for storing throttled requests, use `tiny-lru` module | | ||
@@ -406,2 +406,14 @@ Basic usage: | ||
}); // response from cache | ||
// make post method as get method use `{isGet: true}`, | ||
// useful when some API is get data but the method is `post` | ||
http.post('/get', null, { | ||
isGet: true, | ||
}); // make real http request | ||
http.post('/get', null, { | ||
isGet: true, | ||
}); // response from cache | ||
http.post('/get', null, { | ||
isGet: true, | ||
}); // response from cache | ||
``` | ||
@@ -426,6 +438,6 @@ | ||
| Param | Type | Default value | Description | | ||
| ------------ | -------------------------------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | | ||
| enableCache | boolean \| ((config: Xiorconfig) => boolean) | (config) => config.method === 'GET' | Default only enabled in `GET` request | | ||
| defaultCache | CacheLike | lru(100, 1000\*60\*5) | will used for storing requests by default, except you define a custom Cache with your request config, use `tiny-lru` module | | ||
| Param | Type | Default value | Description | | ||
| ------------ | -------------------------------------------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | | ||
| enableCache | boolean \| ((config: Xiorconfig) => boolean) | (config) => config.method === 'GET' \|\| config.isGet | Default only enabled in `GET` request | | ||
| defaultCache | CacheLike | lru(100, 1000\*60\*5) | will used for storing requests by default, except you define a custom Cache with your request config, use `tiny-lru` module | | ||
@@ -1189,2 +1201,3 @@ Basic usage: | ||
- [axios-extensions](https://github.com/kuitos/axios-extensions) | ||
- [axios-mock-adapter](https://github.com/ctimmerm/axios-mock-adapter) | ||
- [ts-deepmerge](https://github.com/voodoocreation/ts-deepmerge) | ||
@@ -1191,0 +1204,0 @@ - [tiny-lru](https://github.com/avoidwork/tiny-lru) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
134622
1027
1202