Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xior

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xior - npm Package Compare versions

Comparing version 0.3.12 to 0.3.13

plugins/error-cache.umd.js.LICENSE.txt

2

dist/index.esm.js

@@ -1,1 +0,1 @@

import{merge as e,encodeParams as t,XiorTimeoutError as r,anySignal as n,isAbsoluteURL as i,joinPath as s,XiorError as o}from"xior/utils";export*from"xior/utils";function a(e,t,r,n,i,s,o){try{var a=e[s](o),u=a.value}catch(e){r(e);return}a.done?t(u):Promise.resolve(u).then(n,i)}function u(){return(u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}let l="application/",c=`${l}x-www-form-urlencoded`,h=`${l}json`;function f(){var r;return r=function*(r){let n=r.paramsSerializer||t,i=!1!==r.encodeURI,s=r.method?r.method.toUpperCase():"GET",o=r.url||"",a=o,l=r.data,f=l,d=(null==r?void 0:r.headers)||{},p=r.params||{},y=function(e="GET"){return["HEAD","GET","OPTIONS"].includes(e)}(s);if(l&&!(l instanceof FormData)){let t="";if(null==r?void 0:r.headers){let e=Object.keys(r.headers).find(e=>"content-type"===e.toLowerCase());e&&(t=r.headers[e],r.headers["Content-Type"]=t,"Content-Type"!==e&&delete r.headers[e])}t||(t=y?c:h,d["Content-Type"]=t),y&&r.params&&(p=e({},l||{},p)),t===h?f=JSON.stringify(l):!y&&t===c&&l&&"object"==typeof l&&(f=n(l))}if(Object.keys(p).length>0){let e=n(p,i);o+=o.includes("?")?`&${e}`:`?${e}`}return u({},r,{data:l,_data:f,url:a,_url:o,method:s,headers:d,isGet:y})},(f=function(){var e=this,t=arguments;return new Promise(function(n,i){var s=r.apply(e,t);function o(e){a(s,n,i,o,u,"next",e)}function u(e){a(s,n,i,o,u,"throw",e)}o(void 0)})}).apply(this,arguments)}function d(e,t,r,n,i,s,o){try{var a=e[s](o),u=a.value}catch(e){r(e);return}a.done?t(u):Promise.resolve(u).then(n,i)}function p(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var s=e.apply(t,r);function o(e){d(s,n,i,o,a,"next",e)}function a(e){d(s,n,i,o,a,"throw",e)}o(void 0)})}}function y(){return(y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}let v="undefined"!=typeof AbortController;class E{static create(e){return new E(e)}get interceptors(){return{request:{use:(e,t)=>(this.REQI.push(e),e),eject:e=>{this.REQI=this.REQI.filter(t=>t!==e)},clear:()=>{this.REQI=[]}},response:{use:(e,t)=>(this.RESI.push({fn:e,onRejected:t}),e),eject:e=>{this.RESI=this.RESI.filter(t=>t.fn!==e)},clear:()=>{this.RESI=[]}}}}get plugins(){return{use:e=>(this.P.push(e),e),eject:e=>{this.P=this.P.filter(t=>t!==e)},clear:()=>{this.P=[]}}}request(r){var n=this;return p(function*(){let i=e({},n.config||{},n.defaults||{},"string"==typeof r?{url:r}:r||{},{headers:{},params:{}});for(let e of(i.paramsSerializer||(i.paramsSerializer=t),n.REQI))i=yield e(i);let s=n.fetch.bind(n);return n.P.forEach(e=>{s=e(s,n)}),s(i)})()}fetch(e){var t=this;return p(function*(){var a,u;let l,c,h;let d=yield function(e){return f.apply(this,arguments)}(e),{url:p,method:E,headers:m,timeout:R,signal:O,data:g,_data:P,_url:I,isGet:S}=d,j=function(e,t){if(null==e)return{};var r,n,i={},s=Object.keys(e);for(n=0;n<s.length;n++)t.indexOf(r=s[n])>=0||(i[r]=e[r]);return i}(d,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);e._url=I;let w=[];if(R&&v){let t=new AbortController;h=setTimeout(()=>{t.abort(new r(`timeout of ${R}ms exceeded`,e))},R),w.push(t.signal)}O&&w.push(O),l=w[0],w.length>1&&(l=n(w,()=>{clearTimeout(h)}));let T=I||p||"";e.baseURL&&!i(T)&&(T=s(e.baseURL,T));try{c=yield fetch(T,y({body:S?void 0:P},j,{signal:l,method:E,headers:m}))}catch(e){for(let r of t.RESI)r.onRejected&&(yield r.onRejected(e));throw e}finally{h&&clearTimeout(h),null==l||null==(a=l.clear)||a.call(l)}let b={response:c,config:e,status:c.status,statusText:c.statusText,headers:c.headers};if(!c.ok){let r;try{(r=yield c.text())&&(r=JSON.parse(r))}catch(e){}let n=new o(c.status?`Request failed with status code ${c.status}`:"Network error",e,y({data:r},b));for(let e of t.RESI)if(e.onRejected){let t=yield e.onRejected(n);if(null==t?void 0:null==(u=t.response)?void 0:u.ok)return t}throw n}if("HEAD"===E)return y({data:void 0,request:e},b);let{responseType:x}=e;if(!x||["json","text"].includes(x)){let r;try{(r=yield c.text())&&"text"!==x&&(r=JSON.parse(r))}catch(e){}let n={data:r,config:e,request:e,response:c};for(let e of t.RESI)n=yield e.fn(n);return y({data:n.data,request:e},b)}return y({data:void 0,request:e},b)})()}cG(e){return(t,r)=>this.request(r?y({},r,{method:e,url:t}):{method:e,url:t})}cP(e){return(t,r,n)=>this.request(n?y({},n,{method:e,url:t,data:r}):{method:e,url:t,data:r})}get(e,t){return this.cG("GET")(e,t)}head(e,t){return this.cG("HEAD")(e,t)}post(e,t,r){return this.cP("POST")(e,t,r)}put(e,t,r){return this.cP("PUT")(e,t,r)}patch(e,t,r){return this.cP("PATCH")(e,t,r)}delete(e,t){return this.cG("DELETE")(e,t)}options(e,t){return this.cG("OPTIONS")(e,t)}constructor(e){this.REQI=[],this.RESI=[],this.P=[],this.config=e,this.defaults={params:{},headers:{}}}}E.VERSION="0.3.12";let m=Object.assign(E.create(),{create:E.create,VERSION:E.VERSION});export{m as default,E as xior};
import{merge as e,encodeParams as t,XiorTimeoutError as r,anySignal as n,isAbsoluteURL as i,joinPath as s,XiorError as o}from"xior/utils";export*from"xior/utils";function a(e,t,r,n,i,s,o){try{var a=e[s](o),u=a.value}catch(e){r(e);return}a.done?t(u):Promise.resolve(u).then(n,i)}function u(){return(u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}let l="application/",c=`${l}x-www-form-urlencoded`,h=`${l}json`;function f(){var r;return r=function*(r){let n=r.paramsSerializer||t,i=!1!==r.encodeURI,s=r.method?r.method.toUpperCase():"GET",o=r.url||"",a=o,l=r.data,f=l,d=(null==r?void 0:r.headers)||{},p=r.params||{},y=function(e="GET"){return["HEAD","GET","OPTIONS"].includes(e)}(s);if(l&&!(l instanceof FormData)){let t="";if(null==r?void 0:r.headers){let e=Object.keys(r.headers).find(e=>"content-type"===e.toLowerCase());e&&(t=r.headers[e],r.headers["Content-Type"]=t,"Content-Type"!==e&&delete r.headers[e])}t||(t=y?c:h,d["Content-Type"]=t),y&&r.params&&(p=e({},l||{},p)),t===h?f=JSON.stringify(l):!y&&t===c&&l&&"object"==typeof l&&(f=n(l))}if(Object.keys(p).length>0){let e=n(p,i);o+=o.includes("?")?`&${e}`:`?${e}`}return u({},r,{data:l,_data:f,url:a,_url:o,method:s,headers:d,isGet:y})},(f=function(){var e=this,t=arguments;return new Promise(function(n,i){var s=r.apply(e,t);function o(e){a(s,n,i,o,u,"next",e)}function u(e){a(s,n,i,o,u,"throw",e)}o(void 0)})}).apply(this,arguments)}function d(e,t,r,n,i,s,o){try{var a=e[s](o),u=a.value}catch(e){r(e);return}a.done?t(u):Promise.resolve(u).then(n,i)}function p(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var s=e.apply(t,r);function o(e){d(s,n,i,o,a,"next",e)}function a(e){d(s,n,i,o,a,"throw",e)}o(void 0)})}}function y(){return(y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}let v="undefined"!=typeof AbortController;class E{static create(e){return new E(e)}get interceptors(){return{request:{use:(e,t)=>(this.REQI.push(e),e),eject:e=>{this.REQI=this.REQI.filter(t=>t!==e)},clear:()=>{this.REQI=[]}},response:{use:(e,t)=>(this.RESI.push({fn:e,onRejected:t}),e),eject:e=>{this.RESI=this.RESI.filter(t=>t.fn!==e)},clear:()=>{this.RESI=[]}}}}get plugins(){return{use:e=>(this.P.push(e),e),eject:e=>{this.P=this.P.filter(t=>t!==e)},clear:()=>{this.P=[]}}}request(r){var n=this;return p(function*(){let i=e({},n.config||{},n.defaults||{},"string"==typeof r?{url:r}:r||{},{headers:{},params:{}});for(let e of(i.paramsSerializer||(i.paramsSerializer=t),n.REQI))i=yield e(i);let s=n.fetch.bind(n);return n.P.forEach(e=>{s=e(s,n)}),s(i)})()}fetch(e){var t=this;return p(function*(){var a,u;let l,c,h;let d=yield function(e){return f.apply(this,arguments)}(e),{url:p,method:E,headers:m,timeout:R,signal:O,data:g,_data:P,_url:I,isGet:S}=d,j=function(e,t){if(null==e)return{};var r,n,i={},s=Object.keys(e);for(n=0;n<s.length;n++)t.indexOf(r=s[n])>=0||(i[r]=e[r]);return i}(d,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);e._url=I;let w=[];if(R&&v){let t=new AbortController;h=setTimeout(()=>{t.abort(new r(`timeout of ${R}ms exceeded`,e))},R),w.push(t.signal)}O&&w.push(O),l=w[0],w.length>1&&(l=n(w,()=>{clearTimeout(h)}));let T=I||p||"";e.baseURL&&!i(T)&&(T=s(e.baseURL,T));try{c=yield fetch(T,y({body:S?void 0:P},j,{signal:l,method:E,headers:m}))}catch(e){for(let r of t.RESI)r.onRejected&&(yield r.onRejected(e));throw e}finally{h&&clearTimeout(h),null==l||null==(a=l.clear)||a.call(l)}let b={response:c,config:e,status:c.status,statusText:c.statusText,headers:c.headers};if(!c.ok){let r;try{(r=yield c.text())&&(r=JSON.parse(r))}catch(e){}let n=new o(c.status?`Request failed with status code ${c.status}`:"Network error",e,y({data:r},b));for(let e of t.RESI)if(e.onRejected){let t=yield e.onRejected(n);if(null==t?void 0:null==(u=t.response)?void 0:u.ok)return t}throw n}if("HEAD"===E)return y({data:void 0,request:e},b);let{responseType:x}=e;if(!x||["json","text"].includes(x)){let r;try{(r=yield c.text())&&"text"!==x&&(r=JSON.parse(r))}catch(e){}let n={data:r,config:e,request:e,response:c};for(let e of t.RESI)n=yield e.fn(n);return y({data:n.data,request:e},b)}return y({data:void 0,request:e},b)})()}cG(e){return(t,r)=>this.request(r?y({},r,{method:e,url:t}):{method:e,url:t})}cP(e){return(t,r,n)=>this.request(n?y({},n,{method:e,url:t,data:r}):{method:e,url:t,data:r})}get(e,t){return this.cG("GET")(e,t)}head(e,t){return this.cG("HEAD")(e,t)}post(e,t,r){return this.cP("POST")(e,t,r)}put(e,t,r){return this.cP("PUT")(e,t,r)}patch(e,t,r){return this.cP("PATCH")(e,t,r)}delete(e,t){return this.cG("DELETE")(e,t)}options(e,t){return this.cG("OPTIONS")(e,t)}constructor(e){this.REQI=[],this.RESI=[],this.P=[],this.config=e,this.defaults={params:{},headers:{}}}}E.VERSION="0.3.13";let m=Object.assign(E.create(),{create:E.create,VERSION:E.VERSION});export{m as default,E as xior};

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.xior=t():e.xior=t()}(this,(()=>{return e={509:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0});const s=r(895);n(r(895),t),n(r(340),t),n(r(121),t);const i=Object.assign(s.xior.create(),{create:s.xior.create,VERSION:s.xior.VERSION});t.default=i},393:function(e,t,r){"use strict";var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.likeGET=void 0;const n=r(121),s="application/",i=`${s}x-www-form-urlencoded`,a=`${s}json`;function c(e="GET"){return["HEAD","GET","OPTIONS"].includes(e)}t.likeGET=c,t.default=function(e){return o(this,void 0,void 0,(function*(){const t=e.paramsSerializer||n.encodeParams,r=!1!==e.encodeURI,o=e.method?e.method.toUpperCase():"GET";let s=e.url||"";const u=s,l=e.data;let d=l;const f=(null==e?void 0:e.headers)||{};let h=e.params||{};const p=c(o);if(l&&!(l instanceof FormData)){let r="";if(null==e?void 0:e.headers){const t=Object.keys(e.headers).find((e=>"content-type"===e.toLowerCase()));t&&(r=e.headers[t],e.headers["Content-Type"]=r,"Content-Type"!==t&&delete e.headers[t])}r||(r=p?i:a,f["Content-Type"]=r),p&&e.params&&(h=(0,n.merge)({},l||{},h)),r===a?d=JSON.stringify(l):!p&&r===i&&l&&"object"==typeof l&&(d=t(l))}if(Object.keys(h).length>0){const e=t(h,r);s+=s.includes("?")?`&${e}`:`?${e}`}return Object.assign(Object.assign({},e),{data:l,_data:d,url:u,_url:s,method:o,headers:f,isGet:p})}))}},340:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},895:function(e,t,r){"use strict";var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))},n=this&&this.__rest||function(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(r[o[n]]=e[o[n]])}return r},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.xior=void 0;const i=r(121),a=s(r(393)),c="undefined"!=typeof AbortController;class u{static create(e){return new u(e)}constructor(e){this.REQI=[],this.RESI=[],this.P=[],this.config=e,this.defaults={params:{},headers:{}}}get interceptors(){return{request:{use:(e,t)=>(this.REQI.push(e),e),eject:e=>{this.REQI=this.REQI.filter((t=>t!==e))},clear:()=>{this.REQI=[]}},response:{use:(e,t)=>(this.RESI.push({fn:e,onRejected:t}),e),eject:e=>{this.RESI=this.RESI.filter((t=>t.fn!==e))},clear:()=>{this.RESI=[]}}}}get plugins(){return{use:e=>(this.P.push(e),e),eject:e=>{this.P=this.P.filter((t=>t!==e))},clear:()=>{this.P=[]}}}request(e){return o(this,void 0,void 0,(function*(){let t=(0,i.merge)({},this.config||{},this.defaults||{},"string"==typeof e?{url:e}:e||{},{headers:{},params:{}});t.paramsSerializer||(t.paramsSerializer=i.encodeParams);for(const e of this.REQI)t=yield e(t);let r=this.fetch.bind(this);return this.P.forEach((e=>{r=e(r,this)})),r(t)}))}fetch(e){var t,r;return o(this,void 0,void 0,(function*(){const o=yield(0,a.default)(e),{url:s,method:u,headers:l,timeout:d,signal:f,data:h,_data:p,_url:y,isGet:m}=o,b=n(o,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);let g;e._url=y;const O=[];let j;if(d&&c){const t=new AbortController;j=setTimeout((()=>{t.abort(new i.XiorTimeoutError(`timeout of ${d}ms exceeded`,e))}),d),O.push(t.signal)}f&&O.push(f),g=O[0],O.length>1&&(g=(0,i.anySignal)(O,(()=>{clearTimeout(j)})));let v,E=y||s||"";e.baseURL&&!(0,i.isAbsoluteURL)(E)&&(E=(0,i.joinPath)(e.baseURL,E));try{v=yield fetch(E,Object.assign(Object.assign({body:m?void 0:p},b),{signal:g,method:u,headers:l}))}catch(e){for(const t of this.RESI)t.onRejected&&(yield t.onRejected(e));throw e}finally{j&&clearTimeout(j),null===(t=null==g?void 0:g.clear)||void 0===t||t.call(g)}const P={response:v,config:e,status:v.status,statusText:v.statusText,headers:v.headers};if(!v.ok){let t;try{t=yield v.text(),t&&(t=JSON.parse(t))}catch(e){}const o=new i.XiorError(v.status?`Request failed with status code ${v.status}`:"Network error",e,Object.assign({data:t},P));for(const e of this.RESI)if(e.onRejected){const t=yield e.onRejected(o);if(null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.ok)return t}throw o}if("HEAD"===u)return Object.assign({data:void 0,request:e},P);const{responseType:_}=e;if(!_||["json","text"].includes(_)){let t;try{t=yield v.text(),t&&"text"!==_&&(t=JSON.parse(t))}catch(e){}let r={data:t,config:e,request:e,response:v};for(const e of this.RESI)r=yield e.fn(r);return Object.assign({data:r.data,request:e},P)}return Object.assign({data:void 0,request:e},P)}))}cG(e){return(t,r)=>this.request(r?Object.assign(Object.assign({},r),{method:e,url:t}):{method:e,url:t})}cP(e){return(t,r,o)=>this.request(o?Object.assign(Object.assign({},o),{method:e,url:t,data:r}):{method:e,url:t,data:r})}get(e,t){return this.cG("GET")(e,t)}head(e,t){return this.cG("HEAD")(e,t)}post(e,t,r){return this.cP("POST")(e,t,r)}put(e,t,r){return this.cP("PUT")(e,t,r)}patch(e,t,r){return this.cP("PATCH")(e,t,r)}delete(e,t){return this.cG("DELETE")(e,t)}options(e,t){return this.cG("OPTIONS")(e,t)}}t.xior=u,u.VERSION="0.3.12"},602:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.merge=void 0;const r=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}return"[object Object]"===Object.prototype.toString.call(e)}return!1};t.merge=(...e)=>e.reduce(((e,o)=>{if(Array.isArray(o))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(o).forEach((n=>{["__proto__","constructor","prototype"].includes(n)||(Array.isArray(e[n])&&Array.isArray(o[n])?e[n]=t.merge.options.mergeArrays?t.merge.options.uniqueArrayItems?Array.from(new Set(e[n].concat(o[n]))):[...e[n],...o[n]]:o[n]:r(e[n])&&r(o[n])?e[n]=(0,t.merge)(e[n],o[n]):e[n]=void 0===o[n]?t.merge.options.allowUndefinedOverrides?o[n]:e[n]:o[n])})),e}),{});const o={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};t.merge.options=o,t.merge.withOptions=(e,...r)=>{t.merge.options=Object.assign(Object.assign({},o),e);const n=(0,t.merge)(...r);return t.merge.options=o,n}},121:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var o=r(602);class n extends Error{constructor(e,t,r){super(e),this.name="XiorError",this.request=t,this.config=t,this.response=r}}Object.defineProperty(t,"merge",{enumerable:!0,get:function(){return o.merge}}),t.XiorError=n,t.XiorTimeoutError=class extends n{constructor(e,t,r){super(e),this.name="XiorTimeoutError",this.request=t,this.config=t,this.response=r}},t.anySignal=function(e,t){let r=new globalThis.AbortController;function o(e){r.abort(e),s()}let n=[];for(let t of e){if(!0===(null==t?void 0:t.aborted)){o(t.reason);break}if(null!=(null==t?void 0:t.addEventListener)){let e=()=>{o(t.reason)};n.push((()=>{null!=(null==t?void 0:t.removeEventListener)&&t.removeEventListener("abort",e)})),t.addEventListener("abort",e)}}function s(){n.forEach((e=>{e()})),null==t||t()}let i=r.signal;return i.clear=s,i},t.buildSortedURL=function(e,t,r){let o=t?r(t):"";o&&(o=e+(e.includes("?")?"&":"?")+o);let[n,s]=o.split("?");return s?`${n}?${s.split("&").sort().join("&")}`:o||e},t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t("ok")}),e)}))},t.encodeParams=function e(t,r=!0,o=null){if(null==t)return"";let n=[],s=r?encodeURIComponent:e=>e;for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let a=t[i],c=o?`${o}[${s(i)}]`:s(i);if("object"==typeof a){let t=e(a,r,c);""!==t&&n.push(t)}else Array.isArray(a)?a.forEach(((e,t)=>{let r=`${c}[${t}]`;n.push(`${s(r)}=${s(e)}`)})):n.push(`${s(c)}=${s(a)}`)}return n.join("&")},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},t.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},t.joinPath=function(e,t){return t?(e.endsWith("/")?e:e+"/")+(t.startsWith("/")?t.slice(1):t):e}}},t={},function r(o){var n=t[o];if(void 0!==n)return n.exports;var s=t[o]={exports:{}};return e[o].call(s.exports,s,s.exports,r),s.exports}(509).default;var e,t}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.xior=t():e.xior=t()}(this,(()=>{return e={509:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0});const s=r(895);n(r(895),t),n(r(340),t),n(r(121),t);const i=Object.assign(s.xior.create(),{create:s.xior.create,VERSION:s.xior.VERSION});t.default=i},393:function(e,t,r){"use strict";var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.likeGET=void 0;const n=r(121),s="application/",i=`${s}x-www-form-urlencoded`,a=`${s}json`;function c(e="GET"){return["HEAD","GET","OPTIONS"].includes(e)}t.likeGET=c,t.default=function(e){return o(this,void 0,void 0,(function*(){const t=e.paramsSerializer||n.encodeParams,r=!1!==e.encodeURI,o=e.method?e.method.toUpperCase():"GET";let s=e.url||"";const u=s,l=e.data;let d=l;const f=(null==e?void 0:e.headers)||{};let h=e.params||{};const p=c(o);if(l&&!(l instanceof FormData)){let r="";if(null==e?void 0:e.headers){const t=Object.keys(e.headers).find((e=>"content-type"===e.toLowerCase()));t&&(r=e.headers[t],e.headers["Content-Type"]=r,"Content-Type"!==t&&delete e.headers[t])}r||(r=p?i:a,f["Content-Type"]=r),p&&e.params&&(h=(0,n.merge)({},l||{},h)),r===a?d=JSON.stringify(l):!p&&r===i&&l&&"object"==typeof l&&(d=t(l))}if(Object.keys(h).length>0){const e=t(h,r);s+=s.includes("?")?`&${e}`:`?${e}`}return Object.assign(Object.assign({},e),{data:l,_data:d,url:u,_url:s,method:o,headers:f,isGet:p})}))}},340:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},895:function(e,t,r){"use strict";var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))},n=this&&this.__rest||function(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(r[o[n]]=e[o[n]])}return r},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.xior=void 0;const i=r(121),a=s(r(393)),c="undefined"!=typeof AbortController;class u{static create(e){return new u(e)}constructor(e){this.REQI=[],this.RESI=[],this.P=[],this.config=e,this.defaults={params:{},headers:{}}}get interceptors(){return{request:{use:(e,t)=>(this.REQI.push(e),e),eject:e=>{this.REQI=this.REQI.filter((t=>t!==e))},clear:()=>{this.REQI=[]}},response:{use:(e,t)=>(this.RESI.push({fn:e,onRejected:t}),e),eject:e=>{this.RESI=this.RESI.filter((t=>t.fn!==e))},clear:()=>{this.RESI=[]}}}}get plugins(){return{use:e=>(this.P.push(e),e),eject:e=>{this.P=this.P.filter((t=>t!==e))},clear:()=>{this.P=[]}}}request(e){return o(this,void 0,void 0,(function*(){let t=(0,i.merge)({},this.config||{},this.defaults||{},"string"==typeof e?{url:e}:e||{},{headers:{},params:{}});t.paramsSerializer||(t.paramsSerializer=i.encodeParams);for(const e of this.REQI)t=yield e(t);let r=this.fetch.bind(this);return this.P.forEach((e=>{r=e(r,this)})),r(t)}))}fetch(e){var t,r;return o(this,void 0,void 0,(function*(){const o=yield(0,a.default)(e),{url:s,method:u,headers:l,timeout:d,signal:f,data:h,_data:p,_url:y,isGet:m}=o,b=n(o,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);let g;e._url=y;const O=[];let j;if(d&&c){const t=new AbortController;j=setTimeout((()=>{t.abort(new i.XiorTimeoutError(`timeout of ${d}ms exceeded`,e))}),d),O.push(t.signal)}f&&O.push(f),g=O[0],O.length>1&&(g=(0,i.anySignal)(O,(()=>{clearTimeout(j)})));let v,E=y||s||"";e.baseURL&&!(0,i.isAbsoluteURL)(E)&&(E=(0,i.joinPath)(e.baseURL,E));try{v=yield fetch(E,Object.assign(Object.assign({body:m?void 0:p},b),{signal:g,method:u,headers:l}))}catch(e){for(const t of this.RESI)t.onRejected&&(yield t.onRejected(e));throw e}finally{j&&clearTimeout(j),null===(t=null==g?void 0:g.clear)||void 0===t||t.call(g)}const P={response:v,config:e,status:v.status,statusText:v.statusText,headers:v.headers};if(!v.ok){let t;try{t=yield v.text(),t&&(t=JSON.parse(t))}catch(e){}const o=new i.XiorError(v.status?`Request failed with status code ${v.status}`:"Network error",e,Object.assign({data:t},P));for(const e of this.RESI)if(e.onRejected){const t=yield e.onRejected(o);if(null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.ok)return t}throw o}if("HEAD"===u)return Object.assign({data:void 0,request:e},P);const{responseType:_}=e;if(!_||["json","text"].includes(_)){let t;try{t=yield v.text(),t&&"text"!==_&&(t=JSON.parse(t))}catch(e){}let r={data:t,config:e,request:e,response:v};for(const e of this.RESI)r=yield e.fn(r);return Object.assign({data:r.data,request:e},P)}return Object.assign({data:void 0,request:e},P)}))}cG(e){return(t,r)=>this.request(r?Object.assign(Object.assign({},r),{method:e,url:t}):{method:e,url:t})}cP(e){return(t,r,o)=>this.request(o?Object.assign(Object.assign({},o),{method:e,url:t,data:r}):{method:e,url:t,data:r})}get(e,t){return this.cG("GET")(e,t)}head(e,t){return this.cG("HEAD")(e,t)}post(e,t,r){return this.cP("POST")(e,t,r)}put(e,t,r){return this.cP("PUT")(e,t,r)}patch(e,t,r){return this.cP("PATCH")(e,t,r)}delete(e,t){return this.cG("DELETE")(e,t)}options(e,t){return this.cG("OPTIONS")(e,t)}}t.xior=u,u.VERSION="0.3.13"},602:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.merge=void 0;const r=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}return"[object Object]"===Object.prototype.toString.call(e)}return!1};t.merge=(...e)=>e.reduce(((e,o)=>{if(Array.isArray(o))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(o).forEach((n=>{["__proto__","constructor","prototype"].includes(n)||(Array.isArray(e[n])&&Array.isArray(o[n])?e[n]=t.merge.options.mergeArrays?t.merge.options.uniqueArrayItems?Array.from(new Set(e[n].concat(o[n]))):[...e[n],...o[n]]:o[n]:r(e[n])&&r(o[n])?e[n]=(0,t.merge)(e[n],o[n]):e[n]=void 0===o[n]?t.merge.options.allowUndefinedOverrides?o[n]:e[n]:o[n])})),e}),{});const o={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};t.merge.options=o,t.merge.withOptions=(e,...r)=>{t.merge.options=Object.assign(Object.assign({},o),e);const n=(0,t.merge)(...r);return t.merge.options=o,n}},121:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var o=r(602);class n extends Error{constructor(e,t,r){super(e),this.name="XiorError",this.request=t,this.config=t,this.response=r}}Object.defineProperty(t,"merge",{enumerable:!0,get:function(){return o.merge}}),t.XiorError=n,t.XiorTimeoutError=class extends n{constructor(e,t,r){super(e),this.name="XiorTimeoutError",this.request=t,this.config=t,this.response=r}},t.anySignal=function(e,t){let r=new globalThis.AbortController;function o(e){r.abort(e),s()}let n=[];for(let t of e){if(!0===(null==t?void 0:t.aborted)){o(t.reason);break}if(null!=(null==t?void 0:t.addEventListener)){let e=()=>{o(t.reason)};n.push((()=>{null!=(null==t?void 0:t.removeEventListener)&&t.removeEventListener("abort",e)})),t.addEventListener("abort",e)}}function s(){n.forEach((e=>{e()})),null==t||t()}let i=r.signal;return i.clear=s,i},t.buildSortedURL=function(e,t,r){let o=t?r(t):"";o&&(o=e+(e.includes("?")?"&":"?")+o);let[n,s]=o.split("?");return s?`${n}?${s.split("&").sort().join("&")}`:o||e},t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t("ok")}),e)}))},t.encodeParams=function e(t,r=!0,o=null){if(null==t)return"";let n=[],s=r?encodeURIComponent:e=>e;for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let a=t[i],c=o?`${o}[${s(i)}]`:s(i);if("object"==typeof a){let t=e(a,r,c);""!==t&&n.push(t)}else Array.isArray(a)?a.forEach(((e,t)=>{let r=`${c}[${t}]`;n.push(`${s(r)}=${s(e)}`)})):n.push(`${s(c)}=${s(a)}`)}return n.join("&")},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},t.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},t.joinPath=function(e,t){return t?(e.endsWith("/")?e:e+"/")+("/"===t[0]?t.slice(1):t):e}}},t={},function r(o){var n=t[o];if(void 0!==n)return n.exports;var s=t[o]={exports:{}};return e[o].call(s.exports,s,s.exports,r),s.exports}(509).default;var e,t}));

@@ -64,4 +64,4 @@ [Go back](./README.md)

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/plugins/mock.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/mock.umd.js"></script>

@@ -83,4 +83,4 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.12/plugins/mock.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/plugins/mock.umd.js"></script>

@@ -87,0 +87,0 @@ <!-- Usage -->

{
"name": "xior",
"version": "0.3.12",
"description": "A lite request lib based on fetch with plugins support, and axios similar API",
"version": "0.3.13",
"description": "A lite request lib based on fetch with plugin support and similar API to axios.",
"repository": "suhaotian/xior",

@@ -6,0 +6,0 @@ "bugs": "https://github.com/suhaotian/xior/issues",

/*! For license information please see cache.umd.js.LICENSE.txt */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.xiorCache=e():t.xiorCache=e()}(this,(()=>{return t={523:function(t,e,r){"use strict";var i=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(s,n){function o(t){try{u(i.next(t))}catch(t){n(t)}}function l(t){try{u(i.throw(t))}catch(t){n(t)}}function u(t){var e;t.done?s(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,l)}u((i=i.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const s=r(455),n=r(121);e.default=function(t={}){const{enableCache:e,defaultCache:r=(0,s.lru)(100,3e5)}=t;return function(t){return s=>i(this,void 0,void 0,(function*(){const{enableCache:o=e,forceUpdate:l,defaultCache:u=r,paramsSerializer:a}=s,h="GET"===s.method||s.isGet,c=typeof o;let f;if("function"===c&&(f=o(s)),void 0===f&&(f="undefined"===c?h:Boolean(o)),f){const e=u,r=(0,n.buildSortedURL)(s.url&&(0,n.isAbsoluteURL)(s.url)?s.url:(0,n.joinPath)(s.baseURL||"",s.url||""),{a:s.data,b:s.params},a);let o=e.get(r);return!o||l?(o=(()=>i(this,void 0,void 0,(function*(){try{return yield t(s)}catch(t){throw"delete"in e?e.delete(r):e.del(r),t}})))(),e.set(r,o),o):o.then((t=>(t.fromCache=!0,t)))}return t(s)}))}}},455:(t,e)=>{"use strict";class r{constructor(t=0,e=0,r=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=r,this.size=0,this.ttl=e}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(t)){const e=this.items[t];delete this.items[t],this.size--,null!==e.prev&&(e.prev.next=e.next),null!==e.next&&(e.next.prev=e.prev),this.first===e&&(this.first=e.next),this.last===e&&(this.last=e.prev)}return this}entries(t=this.keys()){return t.map((t=>[t,this.get(t)]))}evict(t=!1){if(t||this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}expiresAt(t){let e;return this.has(t)&&(e=this.items[t].expiry),e}get(t){let e;if(this.has(t)){const r=this.items[t];this.ttl>0&&r.expiry<=Date.now()?this.delete(t):(e=r.value,this.set(t,e,!0))}return e}has(t){return t in this.items}keys(){const t=[];let e=this.first;for(;null!==e;)t.push(e.key),e=e.next;return t}set(t,e,r=!1,i=this.resetTtl){let s;if(r||this.has(t)){if(s=this.items[t],s.value=e,!1===r&&i&&(s.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==s){const t=this.last,e=s.next,r=s.prev;this.first===s&&(this.first=s.next),s.next=null,s.prev=this.last,t.next=s,null!==r&&(r.next=e),null!==e&&(e.prev=r)}}else this.max>0&&this.size===this.max&&this.evict(!0),s=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e},1==++this.size?this.first=s:this.last.next=s;return this.last=s,this}values(t=this.keys()){return t.map((t=>this.get(t)))}}e.LRU=r,e.lru=function(t=1e3,e=0,i=!1){if(isNaN(t)||t<0)throw new TypeError("Invalid max value");if(isNaN(e)||e<0)throw new TypeError("Invalid ttl value");if("boolean"!=typeof i)throw new TypeError("Invalid resetTtl value");return new r(t,e,i)}},602:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.merge=void 0;const r=t=>{if("object"==typeof t&&null!==t){if("function"==typeof Object.getPrototypeOf){const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}return"[object Object]"===Object.prototype.toString.call(t)}return!1};e.merge=(...t)=>t.reduce(((t,i)=>{if(Array.isArray(i))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(i).forEach((s=>{["__proto__","constructor","prototype"].includes(s)||(Array.isArray(t[s])&&Array.isArray(i[s])?t[s]=e.merge.options.mergeArrays?e.merge.options.uniqueArrayItems?Array.from(new Set(t[s].concat(i[s]))):[...t[s],...i[s]]:i[s]:r(t[s])&&r(i[s])?t[s]=(0,e.merge)(t[s],i[s]):t[s]=void 0===i[s]?e.merge.options.allowUndefinedOverrides?i[s]:t[s]:i[s])})),t}),{});const i={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};e.merge.options=i,e.merge.withOptions=(t,...r)=>{e.merge.options=Object.assign(Object.assign({},i),t);const s=(0,e.merge)(...r);return e.merge.options=i,s}},121:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});var i=r(602);class s extends Error{constructor(t,e,r){super(t),this.name="XiorError",this.request=e,this.config=e,this.response=r}}Object.defineProperty(e,"merge",{enumerable:!0,get:function(){return i.merge}}),e.XiorError=s,e.XiorTimeoutError=class extends s{constructor(t,e,r){super(t),this.name="XiorTimeoutError",this.request=e,this.config=e,this.response=r}},e.anySignal=function(t,e){let r=new globalThis.AbortController;function i(t){r.abort(t),n()}let s=[];for(let e of t){if(!0===(null==e?void 0:e.aborted)){i(e.reason);break}if(null!=(null==e?void 0:e.addEventListener)){let t=()=>{i(e.reason)};s.push((()=>{null!=(null==e?void 0:e.removeEventListener)&&e.removeEventListener("abort",t)})),e.addEventListener("abort",t)}}function n(){s.forEach((t=>{t()})),null==e||e()}let o=r.signal;return o.clear=n,o},e.buildSortedURL=function(t,e,r){let i=e?r(e):"";i&&(i=t+(t.includes("?")?"&":"?")+i);let[s,n]=i.split("?");return n?`${s}?${n.split("&").sort().join("&")}`:i||t},e.delay=function(t){return new Promise((e=>{setTimeout((()=>{e("ok")}),t)}))},e.encodeParams=function t(e,r=!0,i=null){if(null==e)return"";let s=[],n=r?encodeURIComponent:t=>t;for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o)){let l=e[o],u=i?`${i}[${n(o)}]`:n(o);if("object"==typeof l){let e=t(l,r,u);""!==e&&s.push(e)}else Array.isArray(l)?l.forEach(((t,e)=>{let r=`${u}[${e}]`;s.push(`${n(r)}=${n(t)}`)})):s.push(`${n(u)}=${n(l)}`)}return s.join("&")},e.isAbsoluteURL=function(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)},e.isXiorError=function(t){return"XiorError"===t.name||"XiorTimeoutError"===t.name},e.joinPath=function(t,e){return e?(t.endsWith("/")?t:t+"/")+(e.startsWith("/")?e.slice(1):e):t}}},e={},function r(i){var s=e[i];if(void 0!==s)return s.exports;var n=e[i]={exports:{}};return t[i].call(n.exports,n,n.exports,r),n.exports}(523).default;var t,e}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.xiorCache=e():t.xiorCache=e()}(this,(()=>{return t={523:function(t,e,r){"use strict";var i=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(s,n){function o(t){try{u(i.next(t))}catch(t){n(t)}}function l(t){try{u(i.throw(t))}catch(t){n(t)}}function u(t){var e;t.done?s(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,l)}u((i=i.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const s=r(455),n=r(121);e.default=function(t={}){const{enableCache:e,defaultCache:r=(0,s.lru)(t.cacheItems||100,t.cacheTime||3e5)}=t;return function(t){return s=>i(this,void 0,void 0,(function*(){const{enableCache:o=e,forceUpdate:l,defaultCache:u=r,paramsSerializer:a}=s,h="GET"===s.method||s.isGet,c=typeof o;let f;if("function"===c&&(f=o(s)),void 0===f&&(f="undefined"===c?h:Boolean(o)),f){const e=u,r=(0,n.buildSortedURL)(s.url&&(0,n.isAbsoluteURL)(s.url)?s.url:(0,n.joinPath)(s.baseURL||"",s.url||""),{a:s.data,b:s.params},a);let o=e.get(r);return!o||l?(o=(()=>i(this,void 0,void 0,(function*(){try{return yield t(s)}catch(t){throw"delete"in e?e.delete(r):e.del(r),t}})))(),e.set(r,o),o):o.then((t=>(t.fromCache=!0,t.cacheTime=Date.now(),t)))}return t(s)}))}}},455:(t,e)=>{"use strict";class r{constructor(t=0,e=0,r=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=r,this.size=0,this.ttl=e}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(t)){const e=this.items[t];delete this.items[t],this.size--,null!==e.prev&&(e.prev.next=e.next),null!==e.next&&(e.next.prev=e.prev),this.first===e&&(this.first=e.next),this.last===e&&(this.last=e.prev)}return this}entries(t=this.keys()){return t.map((t=>[t,this.get(t)]))}evict(t=!1){if(t||this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}expiresAt(t){let e;return this.has(t)&&(e=this.items[t].expiry),e}get(t){let e;if(this.has(t)){const r=this.items[t];this.ttl>0&&r.expiry<=Date.now()?this.delete(t):(e=r.value,this.set(t,e,!0))}return e}has(t){return t in this.items}keys(){const t=[];let e=this.first;for(;null!==e;)t.push(e.key),e=e.next;return t}set(t,e,r=!1,i=this.resetTtl){let s;if(r||this.has(t)){if(s=this.items[t],s.value=e,!1===r&&i&&(s.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==s){const t=this.last,e=s.next,r=s.prev;this.first===s&&(this.first=s.next),s.next=null,s.prev=this.last,t.next=s,null!==r&&(r.next=e),null!==e&&(e.prev=r)}}else this.max>0&&this.size===this.max&&this.evict(!0),s=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e},1==++this.size?this.first=s:this.last.next=s;return this.last=s,this}values(t=this.keys()){return t.map((t=>this.get(t)))}}e.LRU=r,e.lru=function(t=1e3,e=0,i=!1){if(isNaN(t)||t<0)throw new TypeError("Invalid max value");if(isNaN(e)||e<0)throw new TypeError("Invalid ttl value");if("boolean"!=typeof i)throw new TypeError("Invalid resetTtl value");return new r(t,e,i)}},602:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.merge=void 0;const r=t=>{if("object"==typeof t&&null!==t){if("function"==typeof Object.getPrototypeOf){const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}return"[object Object]"===Object.prototype.toString.call(t)}return!1};e.merge=(...t)=>t.reduce(((t,i)=>{if(Array.isArray(i))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(i).forEach((s=>{["__proto__","constructor","prototype"].includes(s)||(Array.isArray(t[s])&&Array.isArray(i[s])?t[s]=e.merge.options.mergeArrays?e.merge.options.uniqueArrayItems?Array.from(new Set(t[s].concat(i[s]))):[...t[s],...i[s]]:i[s]:r(t[s])&&r(i[s])?t[s]=(0,e.merge)(t[s],i[s]):t[s]=void 0===i[s]?e.merge.options.allowUndefinedOverrides?i[s]:t[s]:i[s])})),t}),{});const i={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};e.merge.options=i,e.merge.withOptions=(t,...r)=>{e.merge.options=Object.assign(Object.assign({},i),t);const s=(0,e.merge)(...r);return e.merge.options=i,s}},121:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});var i=r(602);class s extends Error{constructor(t,e,r){super(t),this.name="XiorError",this.request=e,this.config=e,this.response=r}}Object.defineProperty(e,"merge",{enumerable:!0,get:function(){return i.merge}}),e.XiorError=s,e.XiorTimeoutError=class extends s{constructor(t,e,r){super(t),this.name="XiorTimeoutError",this.request=e,this.config=e,this.response=r}},e.anySignal=function(t,e){let r=new globalThis.AbortController;function i(t){r.abort(t),n()}let s=[];for(let e of t){if(!0===(null==e?void 0:e.aborted)){i(e.reason);break}if(null!=(null==e?void 0:e.addEventListener)){let t=()=>{i(e.reason)};s.push((()=>{null!=(null==e?void 0:e.removeEventListener)&&e.removeEventListener("abort",t)})),e.addEventListener("abort",t)}}function n(){s.forEach((t=>{t()})),null==e||e()}let o=r.signal;return o.clear=n,o},e.buildSortedURL=function(t,e,r){let i=e?r(e):"";i&&(i=t+(t.includes("?")?"&":"?")+i);let[s,n]=i.split("?");return n?`${s}?${n.split("&").sort().join("&")}`:i||t},e.delay=function(t){return new Promise((e=>{setTimeout((()=>{e("ok")}),t)}))},e.encodeParams=function t(e,r=!0,i=null){if(null==e)return"";let s=[],n=r?encodeURIComponent:t=>t;for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o)){let l=e[o],u=i?`${i}[${n(o)}]`:n(o);if("object"==typeof l){let e=t(l,r,u);""!==e&&s.push(e)}else Array.isArray(l)?l.forEach(((t,e)=>{let r=`${u}[${e}]`;s.push(`${n(r)}=${n(t)}`)})):s.push(`${n(u)}=${n(l)}`)}return s.join("&")},e.isAbsoluteURL=function(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)},e.isXiorError=function(t){return"XiorError"===t.name||"XiorTimeoutError"===t.name},e.joinPath=function(t,e){return e?(t.endsWith("/")?t:t+"/")+("/"===e[0]?e.slice(1):e):t}}},e={},function r(i){var s=e[i];if(void 0!==s)return s.exports;var n=e[i]={exports:{}};return t[i].call(n.exports,n,n.exports,r),n.exports}(523).default;var t,e}));

@@ -178,6 +178,10 @@ import { XiorError } from 'xior/utils';

defaultCache?: ICacheLike<XiorPromise>;
/** max cache number in LRU, default is 100 */
cacheItems?: number;
/** cache time in ms, default is 5 minutes */
cacheTime?: number;
};
/** @ts-ignore */
declare module 'xior' {
interface XiorRequestConfig extends XiorCacheOptions {
interface XiorRequestConfig extends Omit<XiorCacheOptions, 'cacheItems' | 'cacheTime'> {
/** forceUpdate, default: false */

@@ -188,2 +192,3 @@ forceUpdate?: boolean;

fromCache?: boolean;
cacheTime?: number;
}

@@ -190,0 +195,0 @@ }

@@ -1,1 +0,1 @@

import{lru as e}from"tiny-lru";import{buildSortedURL as t,isAbsoluteURL as n,joinPath as r}from"xior/utils";function u(e,t,n,r,u,o,i){try{var a=e[o](i),l=a.value}catch(e){n(e);return}a.done?t(l):Promise.resolve(l).then(r,u)}function o(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function a(e){u(i,r,o,a,l,"next",e)}function l(e){u(i,r,o,a,l,"throw",e)}a(void 0)})}}function i(u={}){let{enableCache:i,defaultCache:a=e(100,3e5)}=u;return function(e){return o(function*(u){let l;let{enableCache:c=i,forceUpdate:f,defaultCache:d=a,paramsSerializer:h}=u,s="GET"===u.method||u.isGet,m=typeof c;if("function"===m&&(l=c(u)),void 0===l&&(l="undefined"===m?s:!!c),l){let i=t(u.url&&n(u.url)?u.url:r(u.baseURL||"",u.url||""),{a:u.data,b:u.params},h),a=d.get(i);return!a||f?(a=o(function*(){try{return yield e(u)}catch(e){throw"delete"in d?d.delete(i):d.del(i),e}})(),d.set(i,a),a):a.then(e=>(e.fromCache=!0,e))}return e(u)})}}export{i as default};
import{lru as e}from"tiny-lru";import{buildSortedURL as t,isAbsoluteURL as n,joinPath as r}from"xior/utils";function i(e,t,n,r,i,o,u){try{var a=e[o](u),c=a.value}catch(e){n(e);return}a.done?t(c):Promise.resolve(c).then(r,i)}function o(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var u=e.apply(t,n);function a(e){i(u,r,o,a,c,"next",e)}function c(e){i(u,r,o,a,c,"throw",e)}a(void 0)})}}function u(i={}){let{enableCache:u,defaultCache:a=e(i.cacheItems||100,i.cacheTime||3e5)}=i;return function(e){return o(function*(i){let c;let{enableCache:l=u,forceUpdate:f,defaultCache:h=a,paramsSerializer:d}=i,m="GET"===i.method||i.isGet,s=typeof l;if("function"===s&&(c=l(i)),void 0===c&&(c="undefined"===s?m:!!l),c){let u=t(i.url&&n(i.url)?i.url:r(i.baseURL||"",i.url||""),{a:i.data,b:i.params},d),a=h.get(u);return!a||f?(a=o(function*(){try{return yield e(i)}catch(e){throw"delete"in h?h.delete(u):h.del(u),e}})(),h.set(u,a),a):a.then(e=>(e.fromCache=!0,e.cacheTime=Date.now(),e))}return e(i)})}}export{u as default};

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.xiorDedupe=t():e.xiorDedupe=t()}(this,(()=>{return e={91:function(e,t,r){"use strict";var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,i){function s(e){try{l(o.next(e))}catch(e){i(e)}}function u(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,u)}l((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.inflight=void 0;const n=r(121);t.inflight=new Map,t.default=function(e={}){const{enableDedupe:r,onDedupe:i}=e;return function(e){return s=>o(this,void 0,void 0,(function*(){var o,u;const{paramsSerializer:l,enableDedupe:a=r,onDedupe:c=i}=s,f="GET"===s.method||s.isGet,d=typeof a;let p;if("function"===d&&(p=a(s)),void 0===p&&(p="undefined"===d?f:Boolean(a)),!p)return e(s);const h=(0,n.buildSortedURL)(s.url&&(0,n.isAbsoluteURL)(s.url)?s.url:(0,n.joinPath)(s.baseURL||"",s.url||""),{a:s.data,b:s.params},l);if(t.inflight.has(h))return c&&c(s),new Promise(((e,r)=>{var o;null===(o=t.inflight.get(h))||void 0===o||o.push([e,r])}));t.inflight.set(h,[]);try{const r=yield e(s);return null===(o=t.inflight.get(h))||void 0===o||o.forEach((([e])=>e(r))),t.inflight.delete(h),r}catch(e){throw null===(u=t.inflight.get(h))||void 0===u||u.forEach((([,t])=>t(e))),t.inflight.delete(h),e}}))}}},602:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.merge=void 0;const r=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}return"[object Object]"===Object.prototype.toString.call(e)}return!1};t.merge=(...e)=>e.reduce(((e,o)=>{if(Array.isArray(o))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(o).forEach((n=>{["__proto__","constructor","prototype"].includes(n)||(Array.isArray(e[n])&&Array.isArray(o[n])?e[n]=t.merge.options.mergeArrays?t.merge.options.uniqueArrayItems?Array.from(new Set(e[n].concat(o[n]))):[...e[n],...o[n]]:o[n]:r(e[n])&&r(o[n])?e[n]=(0,t.merge)(e[n],o[n]):e[n]=void 0===o[n]?t.merge.options.allowUndefinedOverrides?o[n]:e[n]:o[n])})),e}),{});const o={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};t.merge.options=o,t.merge.withOptions=(e,...r)=>{t.merge.options=Object.assign(Object.assign({},o),e);const n=(0,t.merge)(...r);return t.merge.options=o,n}},121:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var o=r(602);class n extends Error{constructor(e,t,r){super(e),this.name="XiorError",this.request=t,this.config=t,this.response=r}}Object.defineProperty(t,"merge",{enumerable:!0,get:function(){return o.merge}}),t.XiorError=n,t.XiorTimeoutError=class extends n{constructor(e,t,r){super(e),this.name="XiorTimeoutError",this.request=t,this.config=t,this.response=r}},t.anySignal=function(e,t){let r=new globalThis.AbortController;function o(e){r.abort(e),i()}let n=[];for(let t of e){if(!0===(null==t?void 0:t.aborted)){o(t.reason);break}if(null!=(null==t?void 0:t.addEventListener)){let e=()=>{o(t.reason)};n.push((()=>{null!=(null==t?void 0:t.removeEventListener)&&t.removeEventListener("abort",e)})),t.addEventListener("abort",e)}}function i(){n.forEach((e=>{e()})),null==t||t()}let s=r.signal;return s.clear=i,s},t.buildSortedURL=function(e,t,r){let o=t?r(t):"";o&&(o=e+(e.includes("?")?"&":"?")+o);let[n,i]=o.split("?");return i?`${n}?${i.split("&").sort().join("&")}`:o||e},t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t("ok")}),e)}))},t.encodeParams=function e(t,r=!0,o=null){if(null==t)return"";let n=[],i=r?encodeURIComponent:e=>e;for(let s in t)if(Object.prototype.hasOwnProperty.call(t,s)){let u=t[s],l=o?`${o}[${i(s)}]`:i(s);if("object"==typeof u){let t=e(u,r,l);""!==t&&n.push(t)}else Array.isArray(u)?u.forEach(((e,t)=>{let r=`${l}[${t}]`;n.push(`${i(r)}=${i(e)}`)})):n.push(`${i(l)}=${i(u)}`)}return n.join("&")},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},t.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},t.joinPath=function(e,t){return t?(e.endsWith("/")?e:e+"/")+(t.startsWith("/")?t.slice(1):t):e}}},t={},function r(o){var n=t[o];if(void 0!==n)return n.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,r),i.exports}(91).default;var e,t}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.xiorDedupe=t():e.xiorDedupe=t()}(this,(()=>{return e={91:function(e,t,r){"use strict";var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,i){function s(e){try{l(o.next(e))}catch(e){i(e)}}function u(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,u)}l((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.inflight=void 0;const n=r(121);t.inflight=new Map,t.default=function(e={}){const{enableDedupe:r,onDedupe:i}=e;return function(e){return s=>o(this,void 0,void 0,(function*(){var o,u;const{paramsSerializer:l,enableDedupe:a=r,onDedupe:c=i}=s,f="GET"===s.method||s.isGet,d=typeof a;let p;if("function"===d&&(p=a(s)),void 0===p&&(p="undefined"===d?f:Boolean(a)),!p)return e(s);const h=(0,n.buildSortedURL)(s.url&&(0,n.isAbsoluteURL)(s.url)?s.url:(0,n.joinPath)(s.baseURL||"",s.url||""),{a:s.data,b:s.params},l);if(t.inflight.has(h))return c&&c(s),new Promise(((e,r)=>{var o;null===(o=t.inflight.get(h))||void 0===o||o.push([e,r])}));t.inflight.set(h,[]);try{const r=yield e(s);return null===(o=t.inflight.get(h))||void 0===o||o.forEach((([e])=>e(r))),t.inflight.delete(h),r}catch(e){throw null===(u=t.inflight.get(h))||void 0===u||u.forEach((([,t])=>t(e))),t.inflight.delete(h),e}}))}}},602:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.merge=void 0;const r=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}return"[object Object]"===Object.prototype.toString.call(e)}return!1};t.merge=(...e)=>e.reduce(((e,o)=>{if(Array.isArray(o))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(o).forEach((n=>{["__proto__","constructor","prototype"].includes(n)||(Array.isArray(e[n])&&Array.isArray(o[n])?e[n]=t.merge.options.mergeArrays?t.merge.options.uniqueArrayItems?Array.from(new Set(e[n].concat(o[n]))):[...e[n],...o[n]]:o[n]:r(e[n])&&r(o[n])?e[n]=(0,t.merge)(e[n],o[n]):e[n]=void 0===o[n]?t.merge.options.allowUndefinedOverrides?o[n]:e[n]:o[n])})),e}),{});const o={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};t.merge.options=o,t.merge.withOptions=(e,...r)=>{t.merge.options=Object.assign(Object.assign({},o),e);const n=(0,t.merge)(...r);return t.merge.options=o,n}},121:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var o=r(602);class n extends Error{constructor(e,t,r){super(e),this.name="XiorError",this.request=t,this.config=t,this.response=r}}Object.defineProperty(t,"merge",{enumerable:!0,get:function(){return o.merge}}),t.XiorError=n,t.XiorTimeoutError=class extends n{constructor(e,t,r){super(e),this.name="XiorTimeoutError",this.request=t,this.config=t,this.response=r}},t.anySignal=function(e,t){let r=new globalThis.AbortController;function o(e){r.abort(e),i()}let n=[];for(let t of e){if(!0===(null==t?void 0:t.aborted)){o(t.reason);break}if(null!=(null==t?void 0:t.addEventListener)){let e=()=>{o(t.reason)};n.push((()=>{null!=(null==t?void 0:t.removeEventListener)&&t.removeEventListener("abort",e)})),t.addEventListener("abort",e)}}function i(){n.forEach((e=>{e()})),null==t||t()}let s=r.signal;return s.clear=i,s},t.buildSortedURL=function(e,t,r){let o=t?r(t):"";o&&(o=e+(e.includes("?")?"&":"?")+o);let[n,i]=o.split("?");return i?`${n}?${i.split("&").sort().join("&")}`:o||e},t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t("ok")}),e)}))},t.encodeParams=function e(t,r=!0,o=null){if(null==t)return"";let n=[],i=r?encodeURIComponent:e=>e;for(let s in t)if(Object.prototype.hasOwnProperty.call(t,s)){let u=t[s],l=o?`${o}[${i(s)}]`:i(s);if("object"==typeof u){let t=e(u,r,l);""!==t&&n.push(t)}else Array.isArray(u)?u.forEach(((e,t)=>{let r=`${l}[${t}]`;n.push(`${i(r)}=${i(e)}`)})):n.push(`${i(l)}=${i(u)}`)}return n.join("&")},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},t.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},t.joinPath=function(e,t){return t?(e.endsWith("/")?e:e+"/")+("/"===t[0]?t.slice(1):t):e}}},t={},function r(o){var n=t[o];if(void 0!==n)return n.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,r),i.exports}(91).default;var e,t}));

@@ -1,1 +0,2 @@

!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.xiorErrorCache=r():e.xiorErrorCache=r()}(this,(()=>{return e={431:function(e,r,t){"use strict";var o=this&&this.__awaiter||function(e,r,t,o){return new(t||(t=Promise))((function(n,i){function s(e){try{u(o.next(e))}catch(e){i(e)}}function c(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var r;e.done?n(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(s,c)}u((o=o.apply(e,r||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0});const n=t(121),i={},s={get:e=>i[e],set(e,r){i[e]=r}};r.default=function(e={}){const{enableCache:r,defaultCache:t=s,useCacheFirst:i,onCacheRequest:c}=e;return function(e){return s=>o(this,void 0,void 0,(function*(){const{enableCache:u=r,defaultCache:a=t,useCacheFirst:l=i,onCacheRequest:d=c,paramsSerializer:f}=s,h="GET"===s.method||s.isGet,p=typeof u;let m;if("function"===p&&(m=u(s)),void 0===m&&(m="undefined"===p?h:Boolean(u)),!m)return e(s);const y=a,v=(0,n.buildSortedURL)(s.url&&(0,n.isAbsoluteURL)(s.url)?s.url:(0,n.joinPath)(s.baseURL||"",s.url||""),{a:s.data,b:s.params},f);try{if(l){const r=y.get(v);if(y.set(v,{loading:!0,res:null==r?void 0:r.res,cacheTime:null==r?void 0:r.cacheTime}),null==r?void 0:r.res)return(null==r?void 0:r.loading)||(null==d||d(s),(()=>{o(this,void 0,void 0,(function*(){try{const r=yield e(s);y.set(v,{loading:!1,res:r,cacheTime:Date.now()})}catch(e){const r=y.get(v);l&&y.set(v,{loading:!1,res:null==r?void 0:r.res,cacheTime:null==r?void 0:r.cacheTime})}}))})()),r.res.fromCache=!0,r.res.cacheTime=null==r?void 0:r.cacheTime,null==r?void 0:r.res}const r=yield e(s);return y.set(v,{loading:!1,res:r,cacheTime:Date.now()}),r}catch(e){const r=y.get(v);if(l&&y.set(v,{loading:!1,res:null==r?void 0:r.res,cacheTime:null==r?void 0:r.cacheTime}),null==r?void 0:r.res)return r.res.fromCache=!0,r.res.error=e,r.res.cacheTime=null==r?void 0:r.cacheTime,r.res;throw e}}))}}},602:(e,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.merge=void 0;const t=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const r=Object.getPrototypeOf(e);return r===Object.prototype||null===r}return"[object Object]"===Object.prototype.toString.call(e)}return!1};r.merge=(...e)=>e.reduce(((e,o)=>{if(Array.isArray(o))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(o).forEach((n=>{["__proto__","constructor","prototype"].includes(n)||(Array.isArray(e[n])&&Array.isArray(o[n])?e[n]=r.merge.options.mergeArrays?r.merge.options.uniqueArrayItems?Array.from(new Set(e[n].concat(o[n]))):[...e[n],...o[n]]:o[n]:t(e[n])&&t(o[n])?e[n]=(0,r.merge)(e[n],o[n]):e[n]=void 0===o[n]?r.merge.options.allowUndefinedOverrides?o[n]:e[n]:o[n])})),e}),{});const o={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};r.merge.options=o,r.merge.withOptions=(e,...t)=>{r.merge.options=Object.assign(Object.assign({},o),e);const n=(0,r.merge)(...t);return r.merge.options=o,n}},121:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0});var o=t(602);class n extends Error{constructor(e,r,t){super(e),this.name="XiorError",this.request=r,this.config=r,this.response=t}}Object.defineProperty(r,"merge",{enumerable:!0,get:function(){return o.merge}}),r.XiorError=n,r.XiorTimeoutError=class extends n{constructor(e,r,t){super(e),this.name="XiorTimeoutError",this.request=r,this.config=r,this.response=t}},r.anySignal=function(e,r){let t=new globalThis.AbortController;function o(e){t.abort(e),i()}let n=[];for(let r of e){if(!0===(null==r?void 0:r.aborted)){o(r.reason);break}if(null!=(null==r?void 0:r.addEventListener)){let e=()=>{o(r.reason)};n.push((()=>{null!=(null==r?void 0:r.removeEventListener)&&r.removeEventListener("abort",e)})),r.addEventListener("abort",e)}}function i(){n.forEach((e=>{e()})),null==r||r()}let s=t.signal;return s.clear=i,s},r.buildSortedURL=function(e,r,t){let o=r?t(r):"";o&&(o=e+(e.includes("?")?"&":"?")+o);let[n,i]=o.split("?");return i?`${n}?${i.split("&").sort().join("&")}`:o||e},r.delay=function(e){return new Promise((r=>{setTimeout((()=>{r("ok")}),e)}))},r.encodeParams=function e(r,t=!0,o=null){if(null==r)return"";let n=[],i=t?encodeURIComponent:e=>e;for(let s in r)if(Object.prototype.hasOwnProperty.call(r,s)){let c=r[s],u=o?`${o}[${i(s)}]`:i(s);if("object"==typeof c){let r=e(c,t,u);""!==r&&n.push(r)}else Array.isArray(c)?c.forEach(((e,r)=>{let t=`${u}[${r}]`;n.push(`${i(t)}=${i(e)}`)})):n.push(`${i(u)}=${i(c)}`)}return n.join("&")},r.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},r.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},r.joinPath=function(e,r){return r?(e.endsWith("/")?e:e+"/")+(r.startsWith("/")?r.slice(1):r):e}}},r={},function t(o){var n=r[o];if(void 0!==n)return n.exports;var i=r[o]={exports:{}};return e[o].call(i.exports,i,i.exports,t),i.exports}(431).default;var e,r}));
/*! For license information please see error-cache.umd.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.xiorErrorCache=t():e.xiorErrorCache=t()}(this,(()=>{return e={431:function(e,t,r){"use strict";var i=this&&this.__awaiter||function(e,t,r,i){return new(r||(r=Promise))((function(s,n){function o(e){try{u(i.next(e))}catch(e){n(e)}}function l(e){try{u(i.throw(e))}catch(e){n(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,l)}u((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=r(455),n=r(121);t.default=function(e={}){const{enableCache:t,defaultCache:r=(0,s.lru)(e.cacheItems||100),useCacheFirst:o,onCacheRequest:l}=e;return function(e){return s=>i(this,void 0,void 0,(function*(){const{enableCache:u=t,defaultCache:a=r,useCacheFirst:c=o,onCacheRequest:h=l,paramsSerializer:f}=s,d="GET"===s.method||s.isGet,p=typeof u;let m;if("function"===p&&(m=u(s)),void 0===m&&(m="undefined"===p?d:Boolean(u)),!m)return e(s);const v=a,y=(0,n.buildSortedURL)(s.url&&(0,n.isAbsoluteURL)(s.url)?s.url:(0,n.joinPath)(s.baseURL||"",s.url||""),{a:s.data,b:s.params},f);try{if(c){const t=v.get(y);if(v.set(y,{loading:!0,res:null==t?void 0:t.res,cacheTime:null==t?void 0:t.cacheTime}),null==t?void 0:t.res)return(null==t?void 0:t.loading)||(null==h||h(s),(()=>{i(this,void 0,void 0,(function*(){try{const t=yield e(s);v.set(y,{loading:!1,res:t,cacheTime:Date.now()})}catch(e){const t=v.get(y);c&&v.set(y,{loading:!1,res:null==t?void 0:t.res,cacheTime:null==t?void 0:t.cacheTime})}}))})()),t.res.fromCache=!0,t.res.cacheTime=null==t?void 0:t.cacheTime,null==t?void 0:t.res}const t=yield e(s);return v.set(y,{loading:!1,res:t,cacheTime:Date.now()}),t}catch(e){const t=v.get(y);if(c&&v.set(y,{loading:!1,res:null==t?void 0:t.res,cacheTime:null==t?void 0:t.cacheTime}),null==t?void 0:t.res)return t.res.fromCache=!0,t.res.error=e,t.res.cacheTime=null==t?void 0:t.cacheTime,t.res;throw e}}))}}},455:(e,t)=>{"use strict";class r{constructor(e=0,t=0,r=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=e,this.resetTtl=r,this.size=0,this.ttl=t}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(e){if(this.has(e)){const t=this.items[e];delete this.items[e],this.size--,null!==t.prev&&(t.prev.next=t.next),null!==t.next&&(t.next.prev=t.prev),this.first===t&&(this.first=t.next),this.last===t&&(this.last=t.prev)}return this}entries(e=this.keys()){return e.map((e=>[e,this.get(e)]))}evict(e=!1){if(e||this.size>0){const e=this.first;delete this.items[e.key],0==--this.size?(this.first=null,this.last=null):(this.first=e.next,this.first.prev=null)}return this}expiresAt(e){let t;return this.has(e)&&(t=this.items[e].expiry),t}get(e){let t;if(this.has(e)){const r=this.items[e];this.ttl>0&&r.expiry<=Date.now()?this.delete(e):(t=r.value,this.set(e,t,!0))}return t}has(e){return e in this.items}keys(){const e=[];let t=this.first;for(;null!==t;)e.push(t.key),t=t.next;return e}set(e,t,r=!1,i=this.resetTtl){let s;if(r||this.has(e)){if(s=this.items[e],s.value=t,!1===r&&i&&(s.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==s){const e=this.last,t=s.next,r=s.prev;this.first===s&&(this.first=s.next),s.next=null,s.prev=this.last,e.next=s,null!==r&&(r.next=t),null!==t&&(t.prev=r)}}else this.max>0&&this.size===this.max&&this.evict(!0),s=this.items[e]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:e,prev:this.last,next:null,value:t},1==++this.size?this.first=s:this.last.next=s;return this.last=s,this}values(e=this.keys()){return e.map((e=>this.get(e)))}}t.LRU=r,t.lru=function(e=1e3,t=0,i=!1){if(isNaN(e)||e<0)throw new TypeError("Invalid max value");if(isNaN(t)||t<0)throw new TypeError("Invalid ttl value");if("boolean"!=typeof i)throw new TypeError("Invalid resetTtl value");return new r(e,t,i)}},602:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.merge=void 0;const r=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}return"[object Object]"===Object.prototype.toString.call(e)}return!1};t.merge=(...e)=>e.reduce(((e,i)=>{if(Array.isArray(i))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(i).forEach((s=>{["__proto__","constructor","prototype"].includes(s)||(Array.isArray(e[s])&&Array.isArray(i[s])?e[s]=t.merge.options.mergeArrays?t.merge.options.uniqueArrayItems?Array.from(new Set(e[s].concat(i[s]))):[...e[s],...i[s]]:i[s]:r(e[s])&&r(i[s])?e[s]=(0,t.merge)(e[s],i[s]):e[s]=void 0===i[s]?t.merge.options.allowUndefinedOverrides?i[s]:e[s]:i[s])})),e}),{});const i={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};t.merge.options=i,t.merge.withOptions=(e,...r)=>{t.merge.options=Object.assign(Object.assign({},i),e);const s=(0,t.merge)(...r);return t.merge.options=i,s}},121:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var i=r(602);class s extends Error{constructor(e,t,r){super(e),this.name="XiorError",this.request=t,this.config=t,this.response=r}}Object.defineProperty(t,"merge",{enumerable:!0,get:function(){return i.merge}}),t.XiorError=s,t.XiorTimeoutError=class extends s{constructor(e,t,r){super(e),this.name="XiorTimeoutError",this.request=t,this.config=t,this.response=r}},t.anySignal=function(e,t){let r=new globalThis.AbortController;function i(e){r.abort(e),n()}let s=[];for(let t of e){if(!0===(null==t?void 0:t.aborted)){i(t.reason);break}if(null!=(null==t?void 0:t.addEventListener)){let e=()=>{i(t.reason)};s.push((()=>{null!=(null==t?void 0:t.removeEventListener)&&t.removeEventListener("abort",e)})),t.addEventListener("abort",e)}}function n(){s.forEach((e=>{e()})),null==t||t()}let o=r.signal;return o.clear=n,o},t.buildSortedURL=function(e,t,r){let i=t?r(t):"";i&&(i=e+(e.includes("?")?"&":"?")+i);let[s,n]=i.split("?");return n?`${s}?${n.split("&").sort().join("&")}`:i||e},t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t("ok")}),e)}))},t.encodeParams=function e(t,r=!0,i=null){if(null==t)return"";let s=[],n=r?encodeURIComponent:e=>e;for(let o in t)if(Object.prototype.hasOwnProperty.call(t,o)){let l=t[o],u=i?`${i}[${n(o)}]`:n(o);if("object"==typeof l){let t=e(l,r,u);""!==t&&s.push(t)}else Array.isArray(l)?l.forEach(((e,t)=>{let r=`${u}[${t}]`;s.push(`${n(r)}=${n(e)}`)})):s.push(`${n(u)}=${n(l)}`)}return s.join("&")},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},t.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},t.joinPath=function(e,t){return t?(e.endsWith("/")?e:e+"/")+("/"===t[0]?t.slice(1):t):e}}},t={},function r(i){var s=t[i];if(void 0!==s)return s.exports;var n=t[i]={exports:{}};return e[i].call(n.exports,n,n.exports,r),n.exports}(431).default;var e,t}));

@@ -185,6 +185,8 @@ import { XiorError } from 'xior/utils';

onCacheRequest?: (config?: XiorRequestConfig) => void;
/** max cache numbers in LRU, default is 100 */
cacheItems?: number;
};
/** @ts-ignore */
declare module 'xior' {
interface XiorRequestConfig extends XiorErrorCacheOptions {
interface XiorRequestConfig extends Omit<XiorErrorCacheOptions, 'cacheItems'> {
}

@@ -191,0 +193,0 @@ interface XiorResponse {

@@ -1,1 +0,1 @@

import{buildSortedURL as e,isAbsoluteURL as t,joinPath as r}from"xior/utils";function n(e,t,r,n,i,l,o){try{var c=e[l](o),a=c.value}catch(e){r(e);return}c.done?t(a):Promise.resolve(a).then(n,i)}function i(e){return function(){var t=this,r=arguments;return new Promise(function(i,l){var o=e.apply(t,r);function c(e){n(o,i,l,c,a,"next",e)}function a(e){n(o,i,l,c,a,"throw",e)}c(void 0)})}}let l={},o={get:e=>l[e],set(e,t){l[e]=t}};function c(n={}){let{enableCache:l,defaultCache:c=o,useCacheFirst:a,onCacheRequest:u}=n;return function(n){return i(function*(o){let s;let{enableCache:d=l,defaultCache:h=c,useCacheFirst:f=a,onCacheRequest:m=u,paramsSerializer:v}=o,T="GET"===o.method||o.isGet,g=typeof d;if("function"===g&&(s=d(o)),void 0===s&&(s="undefined"===g?T:!!d),!s)return n(o);let y=e(o.url&&t(o.url)?o.url:r(o.baseURL||"",o.url||""),{a:o.data,b:o.params},v);try{if(f){let e=h.get(y);if(h.set(y,{loading:!0,res:null==e?void 0:e.res,cacheTime:null==e?void 0:e.cacheTime}),null==e?void 0:e.res)return(null==e?void 0:e.loading)||(null==m||m(o),i(function*(){try{let e=yield n(o);h.set(y,{loading:!1,res:e,cacheTime:Date.now()})}catch(t){let e=h.get(y);f&&h.set(y,{loading:!1,res:null==e?void 0:e.res,cacheTime:null==e?void 0:e.cacheTime})}})()),e.res.fromCache=!0,e.res.cacheTime=null==e?void 0:e.cacheTime,null==e?void 0:e.res}let e=yield n(o);return h.set(y,{loading:!1,res:e,cacheTime:Date.now()}),e}catch(t){let e=h.get(y);if(f&&h.set(y,{loading:!1,res:null==e?void 0:e.res,cacheTime:null==e?void 0:e.cacheTime}),null==e?void 0:e.res)return e.res.fromCache=!0,e.res.error=t,e.res.cacheTime=null==e?void 0:e.cacheTime,e.res;throw t}})}}export{c as default};
import{lru as e}from"tiny-lru";import{buildSortedURL as r,isAbsoluteURL as t,joinPath as i}from"xior/utils";function n(e,r,t,i,n,l,o){try{var c=e[l](o),a=c.value}catch(e){t(e);return}c.done?r(a):Promise.resolve(a).then(i,n)}function l(e){return function(){var r=this,t=arguments;return new Promise(function(i,l){var o=e.apply(r,t);function c(e){n(o,i,l,c,a,"next",e)}function a(e){n(o,i,l,c,a,"throw",e)}c(void 0)})}}function o(n={}){let{enableCache:o,defaultCache:c=e(n.cacheItems||100),useCacheFirst:a,onCacheRequest:u}=n;return function(e){return l(function*(n){let s;let{enableCache:d=o,defaultCache:h=c,useCacheFirst:f=a,onCacheRequest:m=u,paramsSerializer:v}=n,T="GET"===n.method||n.isGet,g=typeof d;if("function"===g&&(s=d(n)),void 0===s&&(s="undefined"===g?T:!!d),!s)return e(n);let y=r(n.url&&t(n.url)?n.url:i(n.baseURL||"",n.url||""),{a:n.data,b:n.params},v);try{if(f){let r=h.get(y);if(h.set(y,{loading:!0,res:null==r?void 0:r.res,cacheTime:null==r?void 0:r.cacheTime}),null==r?void 0:r.res)return(null==r?void 0:r.loading)||(null==m||m(n),l(function*(){try{let r=yield e(n);h.set(y,{loading:!1,res:r,cacheTime:Date.now()})}catch(r){let e=h.get(y);f&&h.set(y,{loading:!1,res:null==e?void 0:e.res,cacheTime:null==e?void 0:e.cacheTime})}})()),r.res.fromCache=!0,r.res.cacheTime=null==r?void 0:r.cacheTime,null==r?void 0:r.res}let r=yield e(n);return h.set(y,{loading:!1,res:r,cacheTime:Date.now()}),r}catch(r){let e=h.get(y);if(f&&h.set(y,{loading:!1,res:null==e?void 0:e.res,cacheTime:null==e?void 0:e.cacheTime}),null==e?void 0:e.res)return e.res.fromCache=!0,e.res.error=r,e.res.cacheTime=null==e?void 0:e.cacheTime,e.res;throw r}})}}export{o as default};

@@ -1,1 +0,1 @@

!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.xiorErrorRetry=r():e.xiorErrorRetry=r()}(this,(()=>{return e={351:function(e,r,t){"use strict";var o=this&&this.__awaiter||function(e,r,t,o){return new(t||(t=Promise))((function(n,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function u(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var r;e.done?n(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(s,u)}c((o=o.apply(e,r||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0});const n=t(121);r.default=function(e={}){const{retryTimes:r,retryInterval:t,enableRetry:i,onRetry:s}=Object.assign({retryTimes:2,retryInterval:3e3},e||{});return function(e,u){return c=>o(this,void 0,void 0,(function*(){const{retryTimes:l=r,retryInterval:a=t,enableRetry:f=i,onRetry:d=s}=c;let y=!1,p=0;return function r(t=!1){return o(this,void 0,void 0,(function*(){if(t&&(null==u?void 0:u.REQI))for(const e of u.REQI)c=yield e(c);try{return yield e(c)}catch(e){const t="GET"===c.method||Boolean(c.isGet),o=typeof f;let i;if("function"===o&&(i=f(c,e)),void 0===i&&(i="undefined"===o?t:Boolean(f)),y=l===p,y||!i)throw e;const s="function"==typeof a?a(p,c,e):a;return s&&s>0&&p>0&&(yield(0,n.delay)(s)),p++,d&&d(c,e,p),r(!0)}}))}()}))}}},602:(e,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.merge=void 0;const t=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const r=Object.getPrototypeOf(e);return r===Object.prototype||null===r}return"[object Object]"===Object.prototype.toString.call(e)}return!1};r.merge=(...e)=>e.reduce(((e,o)=>{if(Array.isArray(o))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(o).forEach((n=>{["__proto__","constructor","prototype"].includes(n)||(Array.isArray(e[n])&&Array.isArray(o[n])?e[n]=r.merge.options.mergeArrays?r.merge.options.uniqueArrayItems?Array.from(new Set(e[n].concat(o[n]))):[...e[n],...o[n]]:o[n]:t(e[n])&&t(o[n])?e[n]=(0,r.merge)(e[n],o[n]):e[n]=void 0===o[n]?r.merge.options.allowUndefinedOverrides?o[n]:e[n]:o[n])})),e}),{});const o={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};r.merge.options=o,r.merge.withOptions=(e,...t)=>{r.merge.options=Object.assign(Object.assign({},o),e);const n=(0,r.merge)(...t);return r.merge.options=o,n}},121:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0});var o=t(602);class n extends Error{constructor(e,r,t){super(e),this.name="XiorError",this.request=r,this.config=r,this.response=t}}Object.defineProperty(r,"merge",{enumerable:!0,get:function(){return o.merge}}),r.XiorError=n,r.XiorTimeoutError=class extends n{constructor(e,r,t){super(e),this.name="XiorTimeoutError",this.request=r,this.config=r,this.response=t}},r.anySignal=function(e,r){let t=new globalThis.AbortController;function o(e){t.abort(e),i()}let n=[];for(let r of e){if(!0===(null==r?void 0:r.aborted)){o(r.reason);break}if(null!=(null==r?void 0:r.addEventListener)){let e=()=>{o(r.reason)};n.push((()=>{null!=(null==r?void 0:r.removeEventListener)&&r.removeEventListener("abort",e)})),r.addEventListener("abort",e)}}function i(){n.forEach((e=>{e()})),null==r||r()}let s=t.signal;return s.clear=i,s},r.buildSortedURL=function(e,r,t){let o=r?t(r):"";o&&(o=e+(e.includes("?")?"&":"?")+o);let[n,i]=o.split("?");return i?`${n}?${i.split("&").sort().join("&")}`:o||e},r.delay=function(e){return new Promise((r=>{setTimeout((()=>{r("ok")}),e)}))},r.encodeParams=function e(r,t=!0,o=null){if(null==r)return"";let n=[],i=t?encodeURIComponent:e=>e;for(let s in r)if(Object.prototype.hasOwnProperty.call(r,s)){let u=r[s],c=o?`${o}[${i(s)}]`:i(s);if("object"==typeof u){let r=e(u,t,c);""!==r&&n.push(r)}else Array.isArray(u)?u.forEach(((e,r)=>{let t=`${c}[${r}]`;n.push(`${i(t)}=${i(e)}`)})):n.push(`${i(c)}=${i(u)}`)}return n.join("&")},r.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},r.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},r.joinPath=function(e,r){return r?(e.endsWith("/")?e:e+"/")+(r.startsWith("/")?r.slice(1):r):e}}},r={},function t(o){var n=r[o];if(void 0!==n)return n.exports;var i=r[o]={exports:{}};return e[o].call(i.exports,i,i.exports,t),i.exports}(351).default;var e,r}));
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.xiorErrorRetry=r():e.xiorErrorRetry=r()}(this,(()=>{return e={351:function(e,r,t){"use strict";var o=this&&this.__awaiter||function(e,r,t,o){return new(t||(t=Promise))((function(n,i){function s(e){try{c(o.next(e))}catch(e){i(e)}}function u(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var r;e.done?n(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(s,u)}c((o=o.apply(e,r||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0});const n=t(121);r.default=function(e={}){const{retryTimes:r,retryInterval:t,enableRetry:i,onRetry:s}=Object.assign({retryTimes:2,retryInterval:3e3},e||{});return function(e,u){return c=>o(this,void 0,void 0,(function*(){const{retryTimes:l=r,retryInterval:a=t,enableRetry:f=i,onRetry:d=s}=c;let y=!1,p=0;return function r(t=!1){return o(this,void 0,void 0,(function*(){if(t&&(null==u?void 0:u.REQI))for(const e of u.REQI)c=yield e(c);try{return yield e(c)}catch(e){const t="GET"===c.method||Boolean(c.isGet),o=typeof f;let i;if("function"===o&&(i=f(c,e)),void 0===i&&(i="undefined"===o?t:Boolean(f)),y=l===p,y||!i)throw e;const s="function"==typeof a?a(p,c,e):a;return s&&s>0&&p>0&&(yield(0,n.delay)(s)),p++,d&&d(c,e,p),r(!0)}}))}()}))}}},602:(e,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.merge=void 0;const t=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const r=Object.getPrototypeOf(e);return r===Object.prototype||null===r}return"[object Object]"===Object.prototype.toString.call(e)}return!1};r.merge=(...e)=>e.reduce(((e,o)=>{if(Array.isArray(o))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(o).forEach((n=>{["__proto__","constructor","prototype"].includes(n)||(Array.isArray(e[n])&&Array.isArray(o[n])?e[n]=r.merge.options.mergeArrays?r.merge.options.uniqueArrayItems?Array.from(new Set(e[n].concat(o[n]))):[...e[n],...o[n]]:o[n]:t(e[n])&&t(o[n])?e[n]=(0,r.merge)(e[n],o[n]):e[n]=void 0===o[n]?r.merge.options.allowUndefinedOverrides?o[n]:e[n]:o[n])})),e}),{});const o={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};r.merge.options=o,r.merge.withOptions=(e,...t)=>{r.merge.options=Object.assign(Object.assign({},o),e);const n=(0,r.merge)(...t);return r.merge.options=o,n}},121:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0});var o=t(602);class n extends Error{constructor(e,r,t){super(e),this.name="XiorError",this.request=r,this.config=r,this.response=t}}Object.defineProperty(r,"merge",{enumerable:!0,get:function(){return o.merge}}),r.XiorError=n,r.XiorTimeoutError=class extends n{constructor(e,r,t){super(e),this.name="XiorTimeoutError",this.request=r,this.config=r,this.response=t}},r.anySignal=function(e,r){let t=new globalThis.AbortController;function o(e){t.abort(e),i()}let n=[];for(let r of e){if(!0===(null==r?void 0:r.aborted)){o(r.reason);break}if(null!=(null==r?void 0:r.addEventListener)){let e=()=>{o(r.reason)};n.push((()=>{null!=(null==r?void 0:r.removeEventListener)&&r.removeEventListener("abort",e)})),r.addEventListener("abort",e)}}function i(){n.forEach((e=>{e()})),null==r||r()}let s=t.signal;return s.clear=i,s},r.buildSortedURL=function(e,r,t){let o=r?t(r):"";o&&(o=e+(e.includes("?")?"&":"?")+o);let[n,i]=o.split("?");return i?`${n}?${i.split("&").sort().join("&")}`:o||e},r.delay=function(e){return new Promise((r=>{setTimeout((()=>{r("ok")}),e)}))},r.encodeParams=function e(r,t=!0,o=null){if(null==r)return"";let n=[],i=t?encodeURIComponent:e=>e;for(let s in r)if(Object.prototype.hasOwnProperty.call(r,s)){let u=r[s],c=o?`${o}[${i(s)}]`:i(s);if("object"==typeof u){let r=e(u,t,c);""!==r&&n.push(r)}else Array.isArray(u)?u.forEach(((e,r)=>{let t=`${c}[${r}]`;n.push(`${i(t)}=${i(e)}`)})):n.push(`${i(c)}=${i(u)}`)}return n.join("&")},r.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},r.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},r.joinPath=function(e,r){return r?(e.endsWith("/")?e:e+"/")+("/"===r[0]?r.slice(1):r):e}}},r={},function t(o){var n=r[o];if(void 0!==n)return n.exports;var i=r[o]={exports:{}};return e[o].call(i.exports,i,i.exports,t),i.exports}(351).default;var e,r}));

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.xiorMock=t():e.xiorMock=t()}(this,(()=>{return e={437:function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{d(n.next(e))}catch(e){i(e)}}function a(e){try{d(n.throw(e))}catch(e){i(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.MockError=void 0;const o=r(121),i=r(732),s="undefined"!=typeof AbortController;class a extends Error{constructor(e,t){super(e),this.request=t,this.config=t}}function d(e){const t=e.filter((e=>{const[,t]=e;return"function"==typeof(null==t?void 0:t.asymmetricMatch)})),r=t.filter((e=>{const[t,r]=e;return r.asymmetricMatch(t)}));return r.length>0&&r.length===t.length}function u(e){e||(e={});const t={},r="undefined"==typeof Headers?{append(e,r){t[e]=r+""},get:e=>t[e]||null}:new Headers;return Object.keys(e).forEach((t=>{r.append(t,e[t])})),r}function l(e,t){if(e.status>=300)throw new o.XiorError(`Request failed with status code ${e.status}`,t,e);return e}t.MockError=a,t.default=class{constructor(e,t){this.handlers={},this.history={},this.options=t,this.instance=e,this.plugin=this._mockPlugin.bind(this),e.plugins.use(this.plugin)}_mockPlugin(e){return t=>n(this,void 0,void 0,(function*(){var r,n,i,d,c;const h=(null===(r=t.method)||void 0===r?void 0:r.toLowerCase())||"get";this.history[h]||(this.history[h]=[]),this.handlers[h]||(this.handlers[h]=[]),null===(n=this.history[h])||void 0===n||n.push(t);const f=this.findHandler(t);if(f){const r=f[6]||(null===(i=this.options)||void 0===i?void 0:i.delayResponse);6===f.length&&Object.keys(this.handlers).forEach((e=>{var t,r;let n=null===(t=this.handlers[e])||void 0===t?void 0:t.indexOf(f);n=void 0===n?-1:n,n>-1&&(null===(r=this.handlers[e])||void 0===r||r.splice(n,1))}));const n=[];let a;if(2!==f.length){let e,r;if(t.timeout&&s){const e=new AbortController;r=setTimeout((()=>{e.abort(new o.XiorTimeoutError(`timeout of ${t.timeout}ms exceeded`,t))}),t.timeout),n.push(e.signal)}t.signal&&n.push(t.signal),e=n[0],n.length>1&&(e=(0,o.anySignal)(n,(()=>{r&&clearTimeout(r)}))),a=()=>{var t;r&&clearTimeout(r),null===(t=null==e?void 0:e.clear)||void 0===t||t.call(e)}}r&&r>0&&(yield(0,o.delay)(r));const d=n.find((e=>e.aborted));if(d)return null==a||a(),Promise.reject(d.reason);if(2===f.length)return e(t);if("function"!=typeof f[2]){const e=f.slice(2),r=l({data:e[1],status:e[0],statusText:"ok",headers:e[2],request:t,config:t},t);return null==a||a(),r}const c=f[2](t);if("function"!=typeof(null==c?void 0:c.then)){const e=l({data:c[1],status:c[0],statusText:"ok",headers:u(c[2]),request:t,config:t},t);return null==a||a(),e}{const e=yield c;return null==a||a(),e.config&&e.status?e:l({data:e[1],status:e[0],statusText:"ok",headers:u(e[2]),request:t,config:t},t)}}if("passthrough"===(null===(d=this.options)||void 0===d?void 0:d.onNoMatch))return e(t);if("throwException"===(null===(c=this.options)||void 0===c?void 0:c.onNoMatch)){const e="Could not find mock for: \n"+JSON.stringify(t,["method","url"],2);throw new a(e,t)}{const e="Request failed with status code 404";throw new o.XiorError(e,t,{status:404,statusText:e,config:t})}}))}resetHandlers(){this.handlers={}}resetHistory(){this.history={}}reset(){this.resetHandlers(),this.resetHistory()}restore(){var e;this.reset(),null===(e=this.instance)||void 0===e||e.plugins.eject(this.plugin)}onGet(e,t){return this.createHandler("get").bind(this)(e,t)}onDelete(e,t){return this.createHandler("delete").bind(this)(e,t)}onHead(e,t){return this.createHandler("head").bind(this)(e,t)}onAny(e,t){return this.createHandler("any").bind(this)(e,t)}onPost(e,t,r){return this.createHandler("post").bind(this)(e,(0,o.merge)({},r||{},{data:t||{}}))}onPut(e,t,r){return this.createHandler("put").bind(this)(e,(0,o.merge)({},r||{},{data:t||{}}))}onPatch(e,t,r){return this.createHandler("patch").bind(this)(e,(0,o.merge)({},r||{},{data:t||{}}))}onOptions(e,t){return this.createHandler("options").bind(this)(e,t)}createHandler(e){return(t,r)=>{var n,i,s,a,d,u;r=r?(0,o.merge)({},{headers:null===(i=null===(n=this.instance)||void 0===n?void 0:n.config)||void 0===i?void 0:i.headers,params:null===(a=null===(s=this.instance)||void 0===s?void 0:s.config)||void 0===a?void 0:a.params,data:null===(u=null===(d=this.instance)||void 0===d?void 0:d.config)||void 0===u?void 0:u.data},r||{}):{},t=void 0===t?/.*/:t;const l=(n,o,i)=>{const s=[t,r,n,o,i];return this.addHandler(e,s),this},c=(n,o,i)=>{const s=[t,r,n,o,i,!0];return this.addHandler(e,s),this},h=(n,o,i,s)=>{const a=[t,r,o,i,s,!1,n];return this.addHandler(e,a),this};return{reply:l,replyOnce:c,withDelayInMs:function(e){return function(t,r,n){return h(e,t,r,n)}},passThrough:()=>{const n=[t,r];return this.addHandler(e,n),this},abortRequest:()=>l((e=>Promise.reject(new o.XiorError("Request aborted",e)))),abortRequestOnce:()=>c((e=>Promise.reject(new o.XiorError("Request aborted",e,{})))),networkError:()=>l((e=>Promise.reject(new o.XiorError("Network Error",e,{})))),networkErrorOnce:()=>c((e=>Promise.reject(new o.XiorError("Network Error",e,{})))),timeout:()=>l((e=>Promise.reject(new o.XiorTimeoutError("timeout of 0ms exceeded",e)))),timeoutOnce:()=>c((e=>Promise.reject(new o.XiorTimeoutError("timeout of 0ms exceeded",e))))}}}addHandler(e,t){var r,n,s;const a=[...t];if(a[3])try{a[3]=JSON.parse(JSON.stringify(a[3]))}catch(e){}if(a[4]){const e="undefined"==typeof Headers?(()=>{const e={};return{append(t,r){e[t]=r+""},get:t=>e[t]||null}})():new Headers;Object.keys(a[4]).forEach((t=>{e.append(t,a[4][t])})),a[4]=e}if("any"===e)i.VERBS.forEach((e=>{var t;this.handlers[e]||(this.handlers[e]=[]),null===(t=this.handlers[e])||void 0===t||t.push(a)}));else{this.handlers[e]||(this.handlers[e]=[]);let t=null===(r=this.handlers[e])||void 0===r?void 0:r.findIndex((e=>6!==e.length&&(0,o.buildSortedURL)(String(e[0]),e[1],o.encodeParams)===(0,o.buildSortedURL)(String(a[0]),a[1],o.encodeParams)));t=void 0===t?-1:t,t>-1&&a.length<6?null===(n=this.handlers[e])||void 0===n||n.splice(t,1,a):null===(s=this.handlers[e])||void 0===s||s.push(a)}}findHandler(e){var t;const{method:r,url:n,headers:i,params:s,data:a={},baseURL:u}=e,l=null==r?void 0:r.toLowerCase();return null===(t=this.handlers[l])||void 0===t?void 0:t.find((t=>{var r;const c=Object.assign({},t[1].headers||{});if((null===(r=e.headers)||void 0===r?void 0:r["Content-Type"])&&(Object.keys(c).find((e=>"content-type"===e.toLowerCase()))||(c["Content-Type"]=e.headers["Content-Type"])),"string"==typeof t[0]){const e=u&&t[0].startsWith(u),r=(0,o.buildSortedURL)(e?(0,o.joinPath)(u,n):(0,o.joinPath)("/",n),{b:s,c:a,a:i},o.encodeParams),l=(0,o.buildSortedURL)(e?t[0]:(0,o.joinPath)("/",t[0]),{b:t[1].params||{},c:t[1].data||{},a:c},o.encodeParams);return r===l||r.startsWith(l)||d([[s,t[1].params],[a,t[1].data],[i,c]])}if(t[0]instanceof RegExp)return(t[0].test(n)||t[0].test((0,o.joinPath)(u||"",n)))&&((0,o.buildSortedURL)(l,{b:s,c:a,a:i},o.encodeParams)===(0,o.buildSortedURL)(l,{b:t[1].params||{},c:t[1].data||{},a:c},o.encodeParams)||d([[s,t[1].params],[a,t[1].data],[i,c]]))}))}}},732:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.VERBS=void 0,t.VERBS=["get","post","head","delete","patch","put","options"]},602:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.merge=void 0;const r=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}return"[object Object]"===Object.prototype.toString.call(e)}return!1};t.merge=(...e)=>e.reduce(((e,n)=>{if(Array.isArray(n))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(n).forEach((o=>{["__proto__","constructor","prototype"].includes(o)||(Array.isArray(e[o])&&Array.isArray(n[o])?e[o]=t.merge.options.mergeArrays?t.merge.options.uniqueArrayItems?Array.from(new Set(e[o].concat(n[o]))):[...e[o],...n[o]]:n[o]:r(e[o])&&r(n[o])?e[o]=(0,t.merge)(e[o],n[o]):e[o]=void 0===n[o]?t.merge.options.allowUndefinedOverrides?n[o]:e[o]:n[o])})),e}),{});const n={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};t.merge.options=n,t.merge.withOptions=(e,...r)=>{t.merge.options=Object.assign(Object.assign({},n),e);const o=(0,t.merge)(...r);return t.merge.options=n,o}},121:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=r(602);class o extends Error{constructor(e,t,r){super(e),this.name="XiorError",this.request=t,this.config=t,this.response=r}}Object.defineProperty(t,"merge",{enumerable:!0,get:function(){return n.merge}}),t.XiorError=o,t.XiorTimeoutError=class extends o{constructor(e,t,r){super(e),this.name="XiorTimeoutError",this.request=t,this.config=t,this.response=r}},t.anySignal=function(e,t){let r=new globalThis.AbortController;function n(e){r.abort(e),i()}let o=[];for(let t of e){if(!0===(null==t?void 0:t.aborted)){n(t.reason);break}if(null!=(null==t?void 0:t.addEventListener)){let e=()=>{n(t.reason)};o.push((()=>{null!=(null==t?void 0:t.removeEventListener)&&t.removeEventListener("abort",e)})),t.addEventListener("abort",e)}}function i(){o.forEach((e=>{e()})),null==t||t()}let s=r.signal;return s.clear=i,s},t.buildSortedURL=function(e,t,r){let n=t?r(t):"";n&&(n=e+(e.includes("?")?"&":"?")+n);let[o,i]=n.split("?");return i?`${o}?${i.split("&").sort().join("&")}`:n||e},t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t("ok")}),e)}))},t.encodeParams=function e(t,r=!0,n=null){if(null==t)return"";let o=[],i=r?encodeURIComponent:e=>e;for(let s in t)if(Object.prototype.hasOwnProperty.call(t,s)){let a=t[s],d=n?`${n}[${i(s)}]`:i(s);if("object"==typeof a){let t=e(a,r,d);""!==t&&o.push(t)}else Array.isArray(a)?a.forEach(((e,t)=>{let r=`${d}[${t}]`;o.push(`${i(r)}=${i(e)}`)})):o.push(`${i(d)}=${i(a)}`)}return o.join("&")},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},t.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},t.joinPath=function(e,t){return t?(e.endsWith("/")?e:e+"/")+(t.startsWith("/")?t.slice(1):t):e}}},t={},function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}(437).default;var e,t}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.xiorMock=t():e.xiorMock=t()}(this,(()=>{return e={437:function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{d(n.next(e))}catch(e){i(e)}}function a(e){try{d(n.throw(e))}catch(e){i(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}d((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.MockError=void 0;const o=r(121),i=r(732),s="undefined"!=typeof AbortController;class a extends Error{constructor(e,t){super(e),this.request=t,this.config=t}}function d(e){const t=e.filter((e=>{const[,t]=e;return"function"==typeof(null==t?void 0:t.asymmetricMatch)})),r=t.filter((e=>{const[t,r]=e;return r.asymmetricMatch(t)}));return r.length>0&&r.length===t.length}function u(e){e||(e={});const t={},r="undefined"==typeof Headers?{append(e,r){t[e]=r+""},get:e=>t[e]||null}:new Headers;return Object.keys(e).forEach((t=>{r.append(t,e[t])})),r}function l(e,t){if(e.status>=300)throw new o.XiorError(`Request failed with status code ${e.status}`,t,e);return e}t.MockError=a,t.default=class{constructor(e,t){this.handlers={},this.history={},this.options=t,this.instance=e,this.plugin=this._mockPlugin.bind(this),e.plugins.use(this.plugin)}_mockPlugin(e){return t=>n(this,void 0,void 0,(function*(){var r,n,i,d,c;const h=(null===(r=t.method)||void 0===r?void 0:r.toLowerCase())||"get";this.history[h]||(this.history[h]=[]),this.handlers[h]||(this.handlers[h]=[]),null===(n=this.history[h])||void 0===n||n.push(t);const f=this.findHandler(t);if(f){const r=f[6]||(null===(i=this.options)||void 0===i?void 0:i.delayResponse);6===f.length&&Object.keys(this.handlers).forEach((e=>{var t,r;let n=null===(t=this.handlers[e])||void 0===t?void 0:t.indexOf(f);n=void 0===n?-1:n,n>-1&&(null===(r=this.handlers[e])||void 0===r||r.splice(n,1))}));const n=[];let a;if(2!==f.length){let e,r;if(t.timeout&&s){const e=new AbortController;r=setTimeout((()=>{e.abort(new o.XiorTimeoutError(`timeout of ${t.timeout}ms exceeded`,t))}),t.timeout),n.push(e.signal)}t.signal&&n.push(t.signal),e=n[0],n.length>1&&(e=(0,o.anySignal)(n,(()=>{r&&clearTimeout(r)}))),a=()=>{var t;r&&clearTimeout(r),null===(t=null==e?void 0:e.clear)||void 0===t||t.call(e)}}r&&r>0&&(yield(0,o.delay)(r));const d=n.find((e=>e.aborted));if(d)return null==a||a(),Promise.reject(d.reason);if(2===f.length)return e(t);if("function"!=typeof f[2]){const e=f.slice(2),r=l({data:e[1],status:e[0],statusText:"ok",headers:e[2],request:t,config:t},t);return null==a||a(),r}const c=f[2](t);if("function"!=typeof(null==c?void 0:c.then)){const e=l({data:c[1],status:c[0],statusText:"ok",headers:u(c[2]),request:t,config:t},t);return null==a||a(),e}{const e=yield c;return null==a||a(),e.config&&e.status?e:l({data:e[1],status:e[0],statusText:"ok",headers:u(e[2]),request:t,config:t},t)}}if("passthrough"===(null===(d=this.options)||void 0===d?void 0:d.onNoMatch))return e(t);if("throwException"===(null===(c=this.options)||void 0===c?void 0:c.onNoMatch)){const e="Could not find mock for: \n"+JSON.stringify(t,["method","url"],2);throw new a(e,t)}{const e="Request failed with status code 404";throw new o.XiorError(e,t,{status:404,statusText:e,config:t})}}))}resetHandlers(){this.handlers={}}resetHistory(){this.history={}}reset(){this.resetHandlers(),this.resetHistory()}restore(){var e;this.reset(),null===(e=this.instance)||void 0===e||e.plugins.eject(this.plugin)}onGet(e,t){return this.createHandler("get").bind(this)(e,t)}onDelete(e,t){return this.createHandler("delete").bind(this)(e,t)}onHead(e,t){return this.createHandler("head").bind(this)(e,t)}onAny(e,t){return this.createHandler("any").bind(this)(e,t)}onPost(e,t,r){return this.createHandler("post").bind(this)(e,(0,o.merge)({},r||{},{data:t||{}}))}onPut(e,t,r){return this.createHandler("put").bind(this)(e,(0,o.merge)({},r||{},{data:t||{}}))}onPatch(e,t,r){return this.createHandler("patch").bind(this)(e,(0,o.merge)({},r||{},{data:t||{}}))}onOptions(e,t){return this.createHandler("options").bind(this)(e,t)}createHandler(e){return(t,r)=>{var n,i,s,a,d,u;r=r?(0,o.merge)({},{headers:null===(i=null===(n=this.instance)||void 0===n?void 0:n.config)||void 0===i?void 0:i.headers,params:null===(a=null===(s=this.instance)||void 0===s?void 0:s.config)||void 0===a?void 0:a.params,data:null===(u=null===(d=this.instance)||void 0===d?void 0:d.config)||void 0===u?void 0:u.data},r||{}):{},t=void 0===t?/.*/:t;const l=(n,o,i)=>{const s=[t,r,n,o,i];return this.addHandler(e,s),this},c=(n,o,i)=>{const s=[t,r,n,o,i,!0];return this.addHandler(e,s),this},h=(n,o,i,s)=>{const a=[t,r,o,i,s,!1,n];return this.addHandler(e,a),this};return{reply:l,replyOnce:c,withDelayInMs:function(e){return function(t,r,n){return h(e,t,r,n)}},passThrough:()=>{const n=[t,r];return this.addHandler(e,n),this},abortRequest:()=>l((e=>Promise.reject(new o.XiorError("Request aborted",e)))),abortRequestOnce:()=>c((e=>Promise.reject(new o.XiorError("Request aborted",e,{})))),networkError:()=>l((e=>Promise.reject(new o.XiorError("Network Error",e,{})))),networkErrorOnce:()=>c((e=>Promise.reject(new o.XiorError("Network Error",e,{})))),timeout:()=>l((e=>Promise.reject(new o.XiorTimeoutError("timeout of 0ms exceeded",e)))),timeoutOnce:()=>c((e=>Promise.reject(new o.XiorTimeoutError("timeout of 0ms exceeded",e))))}}}addHandler(e,t){var r,n,s;const a=[...t];if(a[3])try{a[3]=JSON.parse(JSON.stringify(a[3]))}catch(e){}if(a[4]){const e="undefined"==typeof Headers?(()=>{const e={};return{append(t,r){e[t]=r+""},get:t=>e[t]||null}})():new Headers;Object.keys(a[4]).forEach((t=>{e.append(t,a[4][t])})),a[4]=e}if("any"===e)i.VERBS.forEach((e=>{var t;this.handlers[e]||(this.handlers[e]=[]),null===(t=this.handlers[e])||void 0===t||t.push(a)}));else{this.handlers[e]||(this.handlers[e]=[]);let t=null===(r=this.handlers[e])||void 0===r?void 0:r.findIndex((e=>6!==e.length&&(0,o.buildSortedURL)(String(e[0]),e[1],o.encodeParams)===(0,o.buildSortedURL)(String(a[0]),a[1],o.encodeParams)));t=void 0===t?-1:t,t>-1&&a.length<6?null===(n=this.handlers[e])||void 0===n||n.splice(t,1,a):null===(s=this.handlers[e])||void 0===s||s.push(a)}}findHandler(e){var t;const{method:r,url:n,headers:i,params:s,data:a={},baseURL:u}=e,l=null==r?void 0:r.toLowerCase();return null===(t=this.handlers[l])||void 0===t?void 0:t.find((t=>{var r;const c=Object.assign({},t[1].headers||{});if((null===(r=e.headers)||void 0===r?void 0:r["Content-Type"])&&(Object.keys(c).find((e=>"content-type"===e.toLowerCase()))||(c["Content-Type"]=e.headers["Content-Type"])),"string"==typeof t[0]){const e=u&&t[0].startsWith(u),r=(0,o.buildSortedURL)(e?(0,o.joinPath)(u,n):(0,o.joinPath)("/",n),{b:s,c:a,a:i},o.encodeParams),l=(0,o.buildSortedURL)(e?t[0]:(0,o.joinPath)("/",t[0]),{b:t[1].params||{},c:t[1].data||{},a:c},o.encodeParams);return r===l||r.startsWith(l)||d([[s,t[1].params],[a,t[1].data],[i,c]])}if(t[0]instanceof RegExp)return(t[0].test(n)||t[0].test((0,o.joinPath)(u||"",n)))&&((0,o.buildSortedURL)(l,{b:s,c:a,a:i},o.encodeParams)===(0,o.buildSortedURL)(l,{b:t[1].params||{},c:t[1].data||{},a:c},o.encodeParams)||d([[s,t[1].params],[a,t[1].data],[i,c]]))}))}}},732:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.VERBS=void 0,t.VERBS=["get","post","head","delete","patch","put","options"]},602:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.merge=void 0;const r=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}return"[object Object]"===Object.prototype.toString.call(e)}return!1};t.merge=(...e)=>e.reduce(((e,n)=>{if(Array.isArray(n))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(n).forEach((o=>{["__proto__","constructor","prototype"].includes(o)||(Array.isArray(e[o])&&Array.isArray(n[o])?e[o]=t.merge.options.mergeArrays?t.merge.options.uniqueArrayItems?Array.from(new Set(e[o].concat(n[o]))):[...e[o],...n[o]]:n[o]:r(e[o])&&r(n[o])?e[o]=(0,t.merge)(e[o],n[o]):e[o]=void 0===n[o]?t.merge.options.allowUndefinedOverrides?n[o]:e[o]:n[o])})),e}),{});const n={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};t.merge.options=n,t.merge.withOptions=(e,...r)=>{t.merge.options=Object.assign(Object.assign({},n),e);const o=(0,t.merge)(...r);return t.merge.options=n,o}},121:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=r(602);class o extends Error{constructor(e,t,r){super(e),this.name="XiorError",this.request=t,this.config=t,this.response=r}}Object.defineProperty(t,"merge",{enumerable:!0,get:function(){return n.merge}}),t.XiorError=o,t.XiorTimeoutError=class extends o{constructor(e,t,r){super(e),this.name="XiorTimeoutError",this.request=t,this.config=t,this.response=r}},t.anySignal=function(e,t){let r=new globalThis.AbortController;function n(e){r.abort(e),i()}let o=[];for(let t of e){if(!0===(null==t?void 0:t.aborted)){n(t.reason);break}if(null!=(null==t?void 0:t.addEventListener)){let e=()=>{n(t.reason)};o.push((()=>{null!=(null==t?void 0:t.removeEventListener)&&t.removeEventListener("abort",e)})),t.addEventListener("abort",e)}}function i(){o.forEach((e=>{e()})),null==t||t()}let s=r.signal;return s.clear=i,s},t.buildSortedURL=function(e,t,r){let n=t?r(t):"";n&&(n=e+(e.includes("?")?"&":"?")+n);let[o,i]=n.split("?");return i?`${o}?${i.split("&").sort().join("&")}`:n||e},t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t("ok")}),e)}))},t.encodeParams=function e(t,r=!0,n=null){if(null==t)return"";let o=[],i=r?encodeURIComponent:e=>e;for(let s in t)if(Object.prototype.hasOwnProperty.call(t,s)){let a=t[s],d=n?`${n}[${i(s)}]`:i(s);if("object"==typeof a){let t=e(a,r,d);""!==t&&o.push(t)}else Array.isArray(a)?a.forEach(((e,t)=>{let r=`${d}[${t}]`;o.push(`${i(r)}=${i(e)}`)})):o.push(`${i(d)}=${i(a)}`)}return o.join("&")},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},t.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},t.joinPath=function(e,t){return t?(e.endsWith("/")?e:e+"/")+("/"===t[0]?t.slice(1):t):e}}},t={},function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}(437).default;var e,t}));
/*! For license information please see throttle.umd.js.LICENSE.txt */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.xiorThrottle=e():t.xiorThrottle=e()}(this,(()=>{return t={272:function(t,e,r){"use strict";var s=this&&this.__awaiter||function(t,e,r,s){return new(r||(r=Promise))((function(i,n){function o(t){try{u(s.next(t))}catch(t){n(t)}}function l(t){try{u(s.throw(t))}catch(t){n(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,l)}u((s=s.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const i=r(455),n=r(121);e.default=function(t={}){const{enableThrottle:e,threshold:r=1e3,throttleCache:o=(0,i.lru)(10),onThrottle:l}=t,u=o;return function(t){const i=(e,r)=>{const i=(()=>s(this,void 0,void 0,(function*(){try{const s=yield t(r);return u.set(e,{timestamp:Date.now(),value:Promise.resolve(s)}),s}catch(t){throw"delete"in u?u.delete(e):u.del(e),t}})))();return u.set(e,{timestamp:Date.now(),value:i}),i};return o=>s(this,void 0,void 0,(function*(){const{paramsSerializer:s,threshold:a=r,enableThrottle:h=e,onThrottle:c=l}=o,f="GET"===o.method||o.isGet,p=typeof h;let d;if("function"===p&&(d=h(o)),void 0===d&&(d="undefined"===p?f:Boolean(h)),d){const t=(0,n.buildSortedURL)(o.url&&(0,n.isAbsoluteURL)(o.url)?o.url:(0,n.joinPath)(o.baseURL||"",o.url||""),{a:o.data,b:o.params},s),e=Date.now(),r=u.get(t)||{timestamp:e},l=r.value;return l&&e-r.timestamp<=a?(null==c||c(o),l):i(t,o)}return t(o)}))}}},455:(t,e)=>{"use strict";class r{constructor(t=0,e=0,r=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=r,this.size=0,this.ttl=e}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(t)){const e=this.items[t];delete this.items[t],this.size--,null!==e.prev&&(e.prev.next=e.next),null!==e.next&&(e.next.prev=e.prev),this.first===e&&(this.first=e.next),this.last===e&&(this.last=e.prev)}return this}entries(t=this.keys()){return t.map((t=>[t,this.get(t)]))}evict(t=!1){if(t||this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}expiresAt(t){let e;return this.has(t)&&(e=this.items[t].expiry),e}get(t){let e;if(this.has(t)){const r=this.items[t];this.ttl>0&&r.expiry<=Date.now()?this.delete(t):(e=r.value,this.set(t,e,!0))}return e}has(t){return t in this.items}keys(){const t=[];let e=this.first;for(;null!==e;)t.push(e.key),e=e.next;return t}set(t,e,r=!1,s=this.resetTtl){let i;if(r||this.has(t)){if(i=this.items[t],i.value=e,!1===r&&s&&(i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==i){const t=this.last,e=i.next,r=i.prev;this.first===i&&(this.first=i.next),i.next=null,i.prev=this.last,t.next=i,null!==r&&(r.next=e),null!==e&&(e.prev=r)}}else this.max>0&&this.size===this.max&&this.evict(!0),i=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e},1==++this.size?this.first=i:this.last.next=i;return this.last=i,this}values(t=this.keys()){return t.map((t=>this.get(t)))}}e.LRU=r,e.lru=function(t=1e3,e=0,s=!1){if(isNaN(t)||t<0)throw new TypeError("Invalid max value");if(isNaN(e)||e<0)throw new TypeError("Invalid ttl value");if("boolean"!=typeof s)throw new TypeError("Invalid resetTtl value");return new r(t,e,s)}},602:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.merge=void 0;const r=t=>{if("object"==typeof t&&null!==t){if("function"==typeof Object.getPrototypeOf){const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}return"[object Object]"===Object.prototype.toString.call(t)}return!1};e.merge=(...t)=>t.reduce(((t,s)=>{if(Array.isArray(s))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(s).forEach((i=>{["__proto__","constructor","prototype"].includes(i)||(Array.isArray(t[i])&&Array.isArray(s[i])?t[i]=e.merge.options.mergeArrays?e.merge.options.uniqueArrayItems?Array.from(new Set(t[i].concat(s[i]))):[...t[i],...s[i]]:s[i]:r(t[i])&&r(s[i])?t[i]=(0,e.merge)(t[i],s[i]):t[i]=void 0===s[i]?e.merge.options.allowUndefinedOverrides?s[i]:t[i]:s[i])})),t}),{});const s={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};e.merge.options=s,e.merge.withOptions=(t,...r)=>{e.merge.options=Object.assign(Object.assign({},s),t);const i=(0,e.merge)(...r);return e.merge.options=s,i}},121:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});var s=r(602);class i extends Error{constructor(t,e,r){super(t),this.name="XiorError",this.request=e,this.config=e,this.response=r}}Object.defineProperty(e,"merge",{enumerable:!0,get:function(){return s.merge}}),e.XiorError=i,e.XiorTimeoutError=class extends i{constructor(t,e,r){super(t),this.name="XiorTimeoutError",this.request=e,this.config=e,this.response=r}},e.anySignal=function(t,e){let r=new globalThis.AbortController;function s(t){r.abort(t),n()}let i=[];for(let e of t){if(!0===(null==e?void 0:e.aborted)){s(e.reason);break}if(null!=(null==e?void 0:e.addEventListener)){let t=()=>{s(e.reason)};i.push((()=>{null!=(null==e?void 0:e.removeEventListener)&&e.removeEventListener("abort",t)})),e.addEventListener("abort",t)}}function n(){i.forEach((t=>{t()})),null==e||e()}let o=r.signal;return o.clear=n,o},e.buildSortedURL=function(t,e,r){let s=e?r(e):"";s&&(s=t+(t.includes("?")?"&":"?")+s);let[i,n]=s.split("?");return n?`${i}?${n.split("&").sort().join("&")}`:s||t},e.delay=function(t){return new Promise((e=>{setTimeout((()=>{e("ok")}),t)}))},e.encodeParams=function t(e,r=!0,s=null){if(null==e)return"";let i=[],n=r?encodeURIComponent:t=>t;for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o)){let l=e[o],u=s?`${s}[${n(o)}]`:n(o);if("object"==typeof l){let e=t(l,r,u);""!==e&&i.push(e)}else Array.isArray(l)?l.forEach(((t,e)=>{let r=`${u}[${e}]`;i.push(`${n(r)}=${n(t)}`)})):i.push(`${n(u)}=${n(l)}`)}return i.join("&")},e.isAbsoluteURL=function(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)},e.isXiorError=function(t){return"XiorError"===t.name||"XiorTimeoutError"===t.name},e.joinPath=function(t,e){return e?(t.endsWith("/")?t:t+"/")+(e.startsWith("/")?e.slice(1):e):t}}},e={},function r(s){var i=e[s];if(void 0!==i)return i.exports;var n=e[s]={exports:{}};return t[s].call(n.exports,n,n.exports,r),n.exports}(272).default;var t,e}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.xiorThrottle=e():t.xiorThrottle=e()}(this,(()=>{return t={272:function(t,e,r){"use strict";var s=this&&this.__awaiter||function(t,e,r,s){return new(r||(r=Promise))((function(i,n){function o(t){try{u(s.next(t))}catch(t){n(t)}}function l(t){try{u(s.throw(t))}catch(t){n(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,l)}u((s=s.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const i=r(455),n=r(121);e.default=function(t={}){const{enableThrottle:e,threshold:r=1e3,throttleCache:o=(0,i.lru)(t.throttleItems||100),onThrottle:l}=t,u=o;return function(t){const i=(e,r)=>{const i=(()=>s(this,void 0,void 0,(function*(){try{const s=yield t(r);return u.set(e,{timestamp:Date.now(),value:Promise.resolve(s)}),s}catch(t){throw"delete"in u?u.delete(e):u.del(e),t}})))();return u.set(e,{timestamp:Date.now(),value:i}),i};return o=>s(this,void 0,void 0,(function*(){const{paramsSerializer:s,threshold:a=r,enableThrottle:h=e,onThrottle:c=l}=o,f="GET"===o.method||o.isGet,p=typeof h;let d;if("function"===p&&(d=h(o)),void 0===d&&(d="undefined"===p?f:Boolean(h)),d){const t=(0,n.buildSortedURL)(o.url&&(0,n.isAbsoluteURL)(o.url)?o.url:(0,n.joinPath)(o.baseURL||"",o.url||""),{a:o.data,b:o.params},s),e=Date.now(),r=u.get(t)||{timestamp:e},l=r.value;return l&&e-r.timestamp<=a?(null==c||c(o),l):i(t,o)}return t(o)}))}}},455:(t,e)=>{"use strict";class r{constructor(t=0,e=0,r=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=r,this.size=0,this.ttl=e}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(t)){const e=this.items[t];delete this.items[t],this.size--,null!==e.prev&&(e.prev.next=e.next),null!==e.next&&(e.next.prev=e.prev),this.first===e&&(this.first=e.next),this.last===e&&(this.last=e.prev)}return this}entries(t=this.keys()){return t.map((t=>[t,this.get(t)]))}evict(t=!1){if(t||this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}expiresAt(t){let e;return this.has(t)&&(e=this.items[t].expiry),e}get(t){let e;if(this.has(t)){const r=this.items[t];this.ttl>0&&r.expiry<=Date.now()?this.delete(t):(e=r.value,this.set(t,e,!0))}return e}has(t){return t in this.items}keys(){const t=[];let e=this.first;for(;null!==e;)t.push(e.key),e=e.next;return t}set(t,e,r=!1,s=this.resetTtl){let i;if(r||this.has(t)){if(i=this.items[t],i.value=e,!1===r&&s&&(i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==i){const t=this.last,e=i.next,r=i.prev;this.first===i&&(this.first=i.next),i.next=null,i.prev=this.last,t.next=i,null!==r&&(r.next=e),null!==e&&(e.prev=r)}}else this.max>0&&this.size===this.max&&this.evict(!0),i=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e},1==++this.size?this.first=i:this.last.next=i;return this.last=i,this}values(t=this.keys()){return t.map((t=>this.get(t)))}}e.LRU=r,e.lru=function(t=1e3,e=0,s=!1){if(isNaN(t)||t<0)throw new TypeError("Invalid max value");if(isNaN(e)||e<0)throw new TypeError("Invalid ttl value");if("boolean"!=typeof s)throw new TypeError("Invalid resetTtl value");return new r(t,e,s)}},602:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.merge=void 0;const r=t=>{if("object"==typeof t&&null!==t){if("function"==typeof Object.getPrototypeOf){const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}return"[object Object]"===Object.prototype.toString.call(t)}return!1};e.merge=(...t)=>t.reduce(((t,s)=>{if(Array.isArray(s))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(s).forEach((i=>{["__proto__","constructor","prototype"].includes(i)||(Array.isArray(t[i])&&Array.isArray(s[i])?t[i]=e.merge.options.mergeArrays?e.merge.options.uniqueArrayItems?Array.from(new Set(t[i].concat(s[i]))):[...t[i],...s[i]]:s[i]:r(t[i])&&r(s[i])?t[i]=(0,e.merge)(t[i],s[i]):t[i]=void 0===s[i]?e.merge.options.allowUndefinedOverrides?s[i]:t[i]:s[i])})),t}),{});const s={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};e.merge.options=s,e.merge.withOptions=(t,...r)=>{e.merge.options=Object.assign(Object.assign({},s),t);const i=(0,e.merge)(...r);return e.merge.options=s,i}},121:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});var s=r(602);class i extends Error{constructor(t,e,r){super(t),this.name="XiorError",this.request=e,this.config=e,this.response=r}}Object.defineProperty(e,"merge",{enumerable:!0,get:function(){return s.merge}}),e.XiorError=i,e.XiorTimeoutError=class extends i{constructor(t,e,r){super(t),this.name="XiorTimeoutError",this.request=e,this.config=e,this.response=r}},e.anySignal=function(t,e){let r=new globalThis.AbortController;function s(t){r.abort(t),n()}let i=[];for(let e of t){if(!0===(null==e?void 0:e.aborted)){s(e.reason);break}if(null!=(null==e?void 0:e.addEventListener)){let t=()=>{s(e.reason)};i.push((()=>{null!=(null==e?void 0:e.removeEventListener)&&e.removeEventListener("abort",t)})),e.addEventListener("abort",t)}}function n(){i.forEach((t=>{t()})),null==e||e()}let o=r.signal;return o.clear=n,o},e.buildSortedURL=function(t,e,r){let s=e?r(e):"";s&&(s=t+(t.includes("?")?"&":"?")+s);let[i,n]=s.split("?");return n?`${i}?${n.split("&").sort().join("&")}`:s||t},e.delay=function(t){return new Promise((e=>{setTimeout((()=>{e("ok")}),t)}))},e.encodeParams=function t(e,r=!0,s=null){if(null==e)return"";let i=[],n=r?encodeURIComponent:t=>t;for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o)){let l=e[o],u=s?`${s}[${n(o)}]`:n(o);if("object"==typeof l){let e=t(l,r,u);""!==e&&i.push(e)}else Array.isArray(l)?l.forEach(((t,e)=>{let r=`${u}[${e}]`;i.push(`${n(r)}=${n(t)}`)})):i.push(`${n(u)}=${n(l)}`)}return i.join("&")},e.isAbsoluteURL=function(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)},e.isXiorError=function(t){return"XiorError"===t.name||"XiorTimeoutError"===t.name},e.joinPath=function(t,e){return e?(t.endsWith("/")?t:t+"/")+("/"===e[0]?e.slice(1):e):t}}},e={},function r(s){var i=e[s];if(void 0!==i)return i.exports;var n=e[s]={exports:{}};return t[s].call(n.exports,n,n.exports,r),n.exports}(272).default;var t,e}));

@@ -185,6 +185,8 @@ import { XiorError } from 'xior/utils';

onThrottle?: (config: XiorRequestConfig) => void;
/** max throttle numbers in LRU, default is 100 */
throttleItems?: number;
};
/** @ts-ignore */
declare module 'xior' {
interface XiorRequestConfig extends Omit<XiorThrottleOptions, 'throttleCache'> {
interface XiorRequestConfig extends Omit<XiorThrottleOptions, 'throttleCache' | 'throttleItems'> {
}

@@ -191,0 +193,0 @@ }

@@ -1,1 +0,1 @@

import{lru as t}from"tiny-lru";import{buildSortedURL as e,isAbsoluteURL as r,joinPath as n}from"xior/utils";function o(t,e,r,n,o,u,i){try{var l=t[u](i),a=l.value}catch(t){r(t);return}l.done?e(a):Promise.resolve(a).then(n,o)}function u(t){return function(){var e=this,r=arguments;return new Promise(function(n,u){var i=t.apply(e,r);function l(t){o(i,n,u,l,a,"next",t)}function a(t){o(i,n,u,l,a,"throw",t)}l(void 0)})}}function i(o={}){let{enableThrottle:i,threshold:l=1e3,throttleCache:a=t(10),onThrottle:s}=o;return function(t){let o=(e,r)=>{let n=u(function*(){try{let n=yield t(r);return a.set(e,{timestamp:Date.now(),value:Promise.resolve(n)}),n}catch(t){throw"delete"in a?a.delete(e):a.del(e),t}})();return a.set(e,{timestamp:Date.now(),value:n}),n};return u(function*(u){let f;let{paramsSerializer:m,threshold:c=l,enableThrottle:d=i,onThrottle:h=s}=u,p="GET"===u.method||u.isGet,v=typeof d;if("function"===v&&(f=d(u)),void 0===f&&(f="undefined"===v?p:!!d),f){let t=e(u.url&&r(u.url)?u.url:n(u.baseURL||"",u.url||""),{a:u.data,b:u.params},m),i=Date.now(),l=a.get(t)||{timestamp:i},s=l.value;return s&&i-l.timestamp<=c?(null==h||h(u),s):o(t,u)}return t(u)})}}export{i as default};
import{lru as t}from"tiny-lru";import{buildSortedURL as e,isAbsoluteURL as r,joinPath as n}from"xior/utils";function o(t,e,r,n,o,l,u){try{var i=t[l](u),a=i.value}catch(t){r(t);return}i.done?e(a):Promise.resolve(a).then(n,o)}function l(t){return function(){var e=this,r=arguments;return new Promise(function(n,l){var u=t.apply(e,r);function i(t){o(u,n,l,i,a,"next",t)}function a(t){o(u,n,l,i,a,"throw",t)}i(void 0)})}}function u(o={}){let{enableThrottle:u,threshold:i=1e3,throttleCache:a=t(o.throttleItems||100),onThrottle:s}=o;return function(t){let o=(e,r)=>{let n=l(function*(){try{let n=yield t(r);return a.set(e,{timestamp:Date.now(),value:Promise.resolve(n)}),n}catch(t){throw"delete"in a?a.delete(e):a.del(e),t}})();return a.set(e,{timestamp:Date.now(),value:n}),n};return l(function*(l){let m;let{paramsSerializer:f,threshold:c=i,enableThrottle:d=u,onThrottle:h=s}=l,p="GET"===l.method||l.isGet,v=typeof d;if("function"===v&&(m=d(l)),void 0===m&&(m="undefined"===v?p:!!d),m){let t=e(l.url&&r(l.url)?l.url:n(l.baseURL||"",l.url||""),{a:l.data,b:l.params},f),u=Date.now(),i=a.get(t)||{timestamp:u},s=i.value;return s&&u-i.timestamp<=c?(null==h||h(l),s):o(t,l)}return t(l)})}}export{u as default};

@@ -1,1 +0,1 @@

!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.xiorUtils=r():e.xiorUtils=r()}(this,(()=>(()=>{"use strict";var e={699:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.anySignal=void 0,r.anySignal=function(e,r){const t=new globalThis.AbortController;function o(e){t.abort(e),i()}const n=[];for(const r of e){if(!0===(null==r?void 0:r.aborted)){o(r.reason);break}if(null!=(null==r?void 0:r.addEventListener)){const e=()=>{o(r.reason)};n.push((()=>{null!=(null==r?void 0:r.removeEventListener)&&r.removeEventListener("abort",e)})),r.addEventListener("abort",e)}}function i(){n.forEach((e=>{e()})),null==r||r()}const s=t.signal;return s.clear=i,s}},729:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.merge=void 0;const o=t(602);Object.defineProperty(r,"merge",{enumerable:!0,get:function(){return o.merge}})},629:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.default=function(e,r,t){let o=r?t(r):"";o&&(o=e+(e.includes("?")?"&":"?")+o);const[n,i]=o.split("?");return i?`${n}?${i.split("&").sort().join("&")}`:o||e}},99:function(e,r,t){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.delay=r.buildSortedURL=void 0;const n=o(t(629));r.buildSortedURL=n.default,r.delay=function(e){return new Promise((r=>{setTimeout((()=>{r("ok")}),e)}))}},976:function(e,r,t){var o=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var n=Object.getOwnPropertyDescriptor(r,t);n&&!("get"in n?!r.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,n)}:function(e,r,t,o){void 0===o&&(o=t),e[o]=r[t]}),n=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||o(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),r.isXiorError=r.XiorTimeoutError=r.XiorError=r.joinPath=r.isAbsoluteURL=r.encodeParams=void 0,n(t(699),r),n(t(729),r),n(t(99),r),r.encodeParams=function e(r,t=!0,o=null){if(null==r)return"";const n=[],i=t?encodeURIComponent:e=>e;for(const s in r)if(Object.prototype.hasOwnProperty.call(r,s)){const u=r[s],c=o?`${o}[${i(s)}]`:i(s);if("object"==typeof u){const r=e(u,t,c);""!==r&&n.push(r)}else Array.isArray(u)?u.forEach(((e,r)=>{const t=`${c}[${r}]`;n.push(`${i(t)}=${i(e)}`)})):n.push(`${i(c)}=${i(u)}`)}return n.join("&")},r.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},r.joinPath=function(e,r){return r?(e.endsWith("/")?e:e+"/")+(r.startsWith("/")?r.slice(1):r):e};class i extends Error{constructor(e,r,t){super(e),this.name="XiorError",this.request=r,this.config=r,this.response=t}}r.XiorError=i,r.XiorTimeoutError=class extends i{constructor(e,r,t){super(e),this.name="XiorTimeoutError",this.request=r,this.config=r,this.response=t}},r.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name}},602:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.merge=void 0;const t=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const r=Object.getPrototypeOf(e);return r===Object.prototype||null===r}return"[object Object]"===Object.prototype.toString.call(e)}return!1};r.merge=(...e)=>e.reduce(((e,o)=>{if(Array.isArray(o))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(o).forEach((n=>{["__proto__","constructor","prototype"].includes(n)||(Array.isArray(e[n])&&Array.isArray(o[n])?e[n]=r.merge.options.mergeArrays?r.merge.options.uniqueArrayItems?Array.from(new Set(e[n].concat(o[n]))):[...e[n],...o[n]]:o[n]:t(e[n])&&t(o[n])?e[n]=(0,r.merge)(e[n],o[n]):e[n]=void 0===o[n]?r.merge.options.allowUndefinedOverrides?o[n]:e[n]:o[n])})),e}),{});const o={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};r.merge.options=o,r.merge.withOptions=(e,...t)=>{r.merge.options=Object.assign(Object.assign({},o),e);const n=(0,r.merge)(...t);return r.merge.options=o,n}}},r={},t=function t(o){var n=r[o];if(void 0!==n)return n.exports;var i=r[o]={exports:{}};return e[o].call(i.exports,i,i.exports,t),i.exports}(976);return t.default})()));
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.xiorUtils=r():e.xiorUtils=r()}(this,(()=>(()=>{"use strict";var e={699:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.anySignal=void 0,r.anySignal=function(e,r){const t=new globalThis.AbortController;function o(e){t.abort(e),i()}const n=[];for(const r of e){if(!0===(null==r?void 0:r.aborted)){o(r.reason);break}if(null!=(null==r?void 0:r.addEventListener)){const e=()=>{o(r.reason)};n.push((()=>{null!=(null==r?void 0:r.removeEventListener)&&r.removeEventListener("abort",e)})),r.addEventListener("abort",e)}}function i(){n.forEach((e=>{e()})),null==r||r()}const s=t.signal;return s.clear=i,s}},729:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.merge=void 0;const o=t(602);Object.defineProperty(r,"merge",{enumerable:!0,get:function(){return o.merge}})},629:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.default=function(e,r,t){let o=r?t(r):"";o&&(o=e+(e.includes("?")?"&":"?")+o);const[n,i]=o.split("?");return i?`${n}?${i.split("&").sort().join("&")}`:o||e}},99:function(e,r,t){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.delay=r.buildSortedURL=void 0;const n=o(t(629));r.buildSortedURL=n.default,r.delay=function(e){return new Promise((r=>{setTimeout((()=>{r("ok")}),e)}))}},976:function(e,r,t){var o=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var n=Object.getOwnPropertyDescriptor(r,t);n&&!("get"in n?!r.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,n)}:function(e,r,t,o){void 0===o&&(o=t),e[o]=r[t]}),n=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||o(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),r.isXiorError=r.XiorTimeoutError=r.XiorError=r.joinPath=r.isAbsoluteURL=r.encodeParams=void 0,n(t(699),r),n(t(729),r),n(t(99),r),r.encodeParams=function e(r,t=!0,o=null){if(null==r)return"";const n=[],i=t?encodeURIComponent:e=>e;for(const s in r)if(Object.prototype.hasOwnProperty.call(r,s)){const u=r[s],c=o?`${o}[${i(s)}]`:i(s);if("object"==typeof u){const r=e(u,t,c);""!==r&&n.push(r)}else Array.isArray(u)?u.forEach(((e,r)=>{const t=`${c}[${r}]`;n.push(`${i(t)}=${i(e)}`)})):n.push(`${i(c)}=${i(u)}`)}return n.join("&")},r.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},r.joinPath=function(e,r){return r?(e.endsWith("/")?e:e+"/")+("/"===r[0]?r.slice(1):r):e};class i extends Error{constructor(e,r,t){super(e),this.name="XiorError",this.request=r,this.config=r,this.response=t}}r.XiorError=i,r.XiorTimeoutError=class extends i{constructor(e,r,t){super(e),this.name="XiorTimeoutError",this.request=r,this.config=r,this.response=t}},r.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name}},602:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.merge=void 0;const t=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const r=Object.getPrototypeOf(e);return r===Object.prototype||null===r}return"[object Object]"===Object.prototype.toString.call(e)}return!1};r.merge=(...e)=>e.reduce(((e,o)=>{if(Array.isArray(o))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(o).forEach((n=>{["__proto__","constructor","prototype"].includes(n)||(Array.isArray(e[n])&&Array.isArray(o[n])?e[n]=r.merge.options.mergeArrays?r.merge.options.uniqueArrayItems?Array.from(new Set(e[n].concat(o[n]))):[...e[n],...o[n]]:o[n]:t(e[n])&&t(o[n])?e[n]=(0,r.merge)(e[n],o[n]):e[n]=void 0===o[n]?r.merge.options.allowUndefinedOverrides?o[n]:e[n]:o[n])})),e}),{});const o={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};r.merge.options=o,r.merge.withOptions=(e,...t)=>{r.merge.options=Object.assign(Object.assign({},o),e);const n=(0,r.merge)(...t);return r.merge.options=o,n}}},r={},t=function t(o){var n=r[o];if(void 0!==n)return n.exports;var i=r[o]={exports:{}};return e[o].call(i.exports,i,i.exports,t),i.exports}(976);return t.default})()));

@@ -10,3 +10,3 @@ [![Build](https://github.com/suhaotian/xior/actions/workflows/check.yml/badge.svg)](https://github.com/suhaotian/xior/actions/workflows/check.yml)

A lite request lib based on **fetch** with plugins support.
A lite request lib based on **fetch** with plugin support and similar API to axios.

@@ -41,2 +41,4 @@ **Features:**

- [Encrypt and Decrypt Example](#encrypt-and-decrypt-example)
- [Automatically refreshing access token](#automatically-refreshing-access-token)
- [Tips: Make your SSR(Server-side Rendering) app more stable and faster](#tips-make-your-ssrserver-side-rendering-app-more-stable-and-faster)
- [Plugins](#plugins)

@@ -50,2 +52,3 @@ - [Error retry plugin](#error-retry-plugin)

- [Mock plugin](#mock-plugin)
- [Auth refresh token plugin](#auth-refresh-token-plugin)
- [Create your own custom plugin](#create-your-own-custom-plugin)

@@ -66,3 +69,3 @@ - [Helper functions](#helper-functions)

- [Get response headers](#get-response-headers-1)
- [Download file with `responseType: 'stream'` (In Node.JS)](#download-file-with-responsetype-stream-in-nodejs)
- [Download file with `responseType: 'stream' | 'blob'`](#download-file-with-responsetype-stream--blob)
- [Use stream](#use-stream)

@@ -125,3 +128,3 @@ - [Migrate from `fetch` to **xior**](#migrate-from-fetch-to-xior)

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>

@@ -141,3 +144,3 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>

@@ -277,3 +280,3 @@ <!-- Usage -->

Request inteceptors:
Request interceptors:

@@ -287,3 +290,3 @@ ```ts

http.inteceptors.request.use((config) => {
http.interceptors.request.use((config) => {
const token = localStorage.getItem('REQUEST_TOKEN');

@@ -300,3 +303,3 @@ if (!token) return config;

// One more inteceptor for request
http.inteceptors.request.use((config) => {
http.interceptors.request.use((config) => {
return config;

@@ -306,3 +309,3 @@ });

Response inteceptors:
Response interceptors:

@@ -314,3 +317,3 @@ ```ts

http.inteceptors.response.use(
http.interceptors.response.use(
(result) => {

@@ -425,2 +428,129 @@ const { data, request: config, response: originalResponse } = result;

### Automatically refreshing access token
We can use some plugins and interceptors to achieve this. The flow would be:
1. In response interceptors, check if status code is session expired, we set the new access token from API
2. Then throw error, the error will occur the error retry plugin to retry request with the new access token
> The error retry plugin will not retry with `POST` method request in default.
Example code:
```ts
import axios, { XiorError as AxiosError } from 'xior';
import errorRetryPlugin from 'xior/plugins/error-retry';
import dedupePlugin from 'xior/plugins/dedupe';
import throttlePlugin from 'xior/plugins/throttle';
const http = axios.create({
baseURL: 'http://localhost:3000',
});
http.plugins.use(errorRetryPlugin());
http.plugins.use(dedupePlugin()); // Prevent same `GET` requests from occurring simultaneously.
http.plugins.use(throttlePlugin()); // Throttle same `GET` request in 1000ms
const TOKEN_EXPIRED_STATUS = 403;
const TOKEN_STORAGE_KEY = 'AUTH_TOKEN';
http.interceptors.request.use((config) => {
// Get token from localStorage
const token = localStorage.getItem(TOKEN_STORAGE_KEY);
if (token) {
config.headers['Authorization'] = 'Bearer ' + token;
}
return config;
});
let refreshingToken = false;
const queue: (() => void)[] = [];
http.interceptors.response.use(
async (response) => {
return response;
},
async (error: AxiosError) => {
const token = localStorage.getItem(TOKEN_STORAGE_KEY);
if (error.response?.status === TOKEN_EXPIRED_STATUS && token) {
if (refreshingToken) {
await new Promise<void>((resolve, reject) => {
queue.push(resolve);
});
} else {
refreshingToken = true;
try {
const { data } = await http.post('/api/new_token', {
enableDedupe: true, // Use `enableDedupe: true` to enable dedupe request, if is GET method, can ignore
enableThrottle: true, // Use `enableThrottle: true` to enable throttle request, if is GET method, can ignore
});
// Save token
localStorage.setItem(TOKEN_STORAGE_KEY, data.token);
} catch (e) {
// refresh token wrong, remove the old token?
localStorage.removeItem(TOKEN_STORAGE_KEY);
throw e;
} finally {
refreshingToken = false;
queue.forEach((r) => r());
}
return Promise.reject(new Error('Token expired, new token refreshed, try again!'));
}
}
// If error, will retry on GET method
return Promise.reject(error);
}
);
```
Or You can use the plugin from community: [Auth refresh token plugin](#auth-refresh-token-plugin).
### Tips: Make your SSR(Server-side Rendering) app more stable and faster
How we do that? Use the xior's plugins:
1. If `GET` data error, at least have chance to retry;
2. If retry still error, return the cache data(if have) to prevent page crash or show error page;
3. Dedupe the `GET` requests
4. Throttle the `GET` requests
5. Return cache data first and run the fetching data task on the background
Example code:
```ts
import xior, { XiorError as AxiosError } from 'xior';
import errorRetryPlugin from 'xior/plugins/error-retry';
import dedupePlugin from 'xior/plugins/dedupe';
import throttlePlugin from 'xior/plugins/throttle';
import errorCachePlugin from 'xior/plugins/error-cache';
// Setup
const http = axios.create({
baseURL: 'http://localhost:3000',
});
http.plugins.use(errorRetryPlugin());
http.plugins.use(errorCachePlugin());
http.plugins.use(dedupePlugin()); // Prevent same GET requests from occurring simultaneously.
http.plugins.use(throttlePlugin()); // Throttle same `GET` request in 1000ms
// 1. If `GET` data error, at least have chance to retry;
// 2. If retry still error, return the cache data(if have) to prevent page crash or show error page;
const res = await http.get('/api/get-data'); // these will retry if have error
if (res.fromCache) {
console.log(`the data from cahce`, res.cacheTime);
}
// 3. Dedupe the same `GET` requests, this will only sent 1 real request
await Promise.all([
http.get('/api/get-data-2'),
http.get('/api/get-data-2'),
http.get('/api/get-data-2'),
]);
// 4. Throttle the `GET` requests,
// we want throttle some larget data request in 10s, default is 1s
http.get('/api/get-some-big-data', { threshold: 10e3 });
// 5. If have cache data, return the cache data first,
// and run the real request in background
http.get('/api/get-some-big-data', { threshold: 10e3, useCacheFirst: true });
```
## Plugins

@@ -437,2 +567,3 @@

- [Mock plugin](#Mock-plugin)
- [Auth token refreshing plugin]

@@ -544,5 +675,5 @@ Usage:

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/plugins/error-retry.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/error-retry.umd.js"></script>

@@ -560,6 +691,6 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://unpkg.com/xior@0.3.12/plugins/error-retry.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/plugins/error-retry.umd.js"></script>

@@ -590,2 +721,3 @@ <!-- Usage -->

onThrottle?: (config: XiorRequestConfig) => void;
throttleItems?: number;
}): XiorPlugin;

@@ -602,3 +734,4 @@ ```

| enableThrottle | boolean \| ((config: XiorRequestConfig) => boolean \| undefined) | (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 |
| throttleCache | CacheLike | lru(100) | CacheLike instance that will be used for storing throttled requests, use `tiny-lru` module |
| throttleItems | number | 100 | The max number of throttle items in the default LRU cache |

@@ -657,5 +790,5 @@ Basic usage:

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/plugins/throttle.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/throttle.umd.js"></script>

@@ -673,6 +806,6 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://unpkg.com/xior@0.3.12/plugins/throttle.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/plugins/throttle.umd.js"></script>

@@ -732,5 +865,5 @@ <!-- Usage -->

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/plugins/dedupe.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/dedupe.umd.js"></script>

@@ -748,6 +881,6 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://unpkg.com/xior@0.3.12/plugins/dedupe.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/plugins/dedupe.umd.js"></script>

@@ -781,4 +914,5 @@ <!-- Usage -->

| enableCache | boolean \| ((config: XiorRequestConfig) => boolean \| undefined) | (config) => config.method === 'GET' \|\| config.isGet | Default only enabled in `GET` request |
| defaultCache | CacheLike | lru(Inifinite, 0) | will used for storing requests by default, except you define a custom Cache with your request config, use `tiny-lru` module |
| defaultCache | CacheLike | lru(100, 0) | will used for storing requests by default, except you define a custom Cache with your request config, use `tiny-lru` module |
| useCacheFirst | boolean | false | If `useCacheFirst: true` and there's a cache, it will return the cached response first, then run fetching task on the background. This is useful when the response takes a long time, and the data is unnecessary in real-time. |
| cacheItems | number | 100 | The max number of error cache items in the default LRU cache |

@@ -814,5 +948,5 @@ Basic usage:

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/plugins/error-cache.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/error-cache.umd.js"></script>

@@ -830,6 +964,6 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://unpkg.com/xior@0.3.12/plugins/error-cache.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/plugins/error-cache.umd.js"></script>

@@ -858,2 +992,3 @@ <!-- Usage -->

defaultCache?: ICacheLike<XiorPromise>;
cacheItems?: number;
}): XiorPlugin;

@@ -868,2 +1003,4 @@ ```

| 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 |
| cacheItems | number | 100 | Custom the default LRU cache numbers |
| cacheTime | number | 1000 \* 60 \* 5 | Custom the default LRU cache time |

@@ -877,3 +1014,8 @@ Basic usage:

const http = xior.create();
http.plugins.use(cachePlugin());
http.plugins.use(
cachePlugin({
cacheItems: 100,
cacheTime: 1e3 * 60 * 5,
})
);

@@ -891,3 +1033,3 @@ http.get('/users'); // make real http request

// if `fromCache` is true, means data from cache!
console.log('data from cache!');
console.log('data from cache!', res.cacheTime);
}

@@ -911,2 +1053,4 @@ ```

enableCache: false,
cacheItems: 1000,
cacheTime: 1e3 * 60 * 10,
})

@@ -974,5 +1118,5 @@ );

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/plugins/progress.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/progress.umd.js"></script>

@@ -990,6 +1134,6 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://unpkg.com/xior@0.3.12/plugins/progress.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/plugins/progress.umd.js"></script>

@@ -1101,5 +1245,5 @@ <!-- Usage -->

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.12/plugins/mock.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/mock.umd.js"></script>

@@ -1117,6 +1261,6 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.12/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://unpkg.com/xior@0.3.12/plugins/mock.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/plugins/mock.umd.js"></script>

@@ -1131,2 +1275,41 @@ <!-- Usage -->

### Auth refresh token plugin
We will use `xior-auth-refresh` plugin from the community: https://github.com/Audiu/xior-auth-refresh
**Install:**
```sh
npm install xior-auth-refresh --save
# or
yarn add xior-auth-refresh
# or
pnpm add xior-auth-refresh
```
**Usage:**
```ts
import xior from 'xior';
import createAuthRefreshInterceptor from 'xior-auth-refresh';
// Function that will be called to refresh authorization
const refreshAuthLogic = (failedRequest) =>
xior.post('https://www.example.com/auth/token/refresh').then((tokenRefreshResponse) => {
localStorage.setItem('token', tokenRefreshResponse.data.token);
failedRequest.response.config.headers['Authorization'] =
'Bearer ' + tokenRefreshResponse.data.token;
return Promise.resolve();
});
// Instantiate the interceptor
createAuthRefreshInterceptor(xior, refreshAuthLogic);
// Make a call. If it returns a 401 error, the refreshAuthLogic will be run,
// and the request retried with the new token
xior.get('https://www.example.com/restricted/area').then(/* ... */).catch(/* ... */);
```
More: https://github.com/Audiu/xior-auth-refresh
### Create your own custom plugin

@@ -1190,5 +1373,18 @@

To handle such responses, use the `responseType: 'stream'` option in your request:
> Currently in `xior`, when `responseType` is set to `'stream', 'document', 'arraybuffer', 'blob', or 'original'`, Xior will return the original fetch response.
```ts
fetch('https://exmaple.com/some/api').then((response) => {
console.log(response);
});
// same with
xior.get('https://exmaple.com/some/api', { responseType: 'blob' }).then((res) => {
console.log(res.response); // res.data will be undefined
});
```
And to handle a stream response, use the `responseType: 'stream'` option in your request, then do something with the `response` as `fetch` does:
```ts
import xior from 'xior';

@@ -1434,3 +1630,3 @@

### Download file with `responseType: 'stream'` (In Node.JS)
### Download file with `responseType: 'stream' | 'blob'`

@@ -1441,4 +1637,5 @@ axios:

import axios from 'axios';
import fs from 'fs';
// GET request for remote image in node.js
// GET request for remote image in Node.js
axios({

@@ -1451,2 +1648,23 @@ method: 'get',

});
// For browser
axios({
method: 'get',
url: 'https://bit.ly/2mTM3nY',
responseType: 'blob',
}).then(function (response) {
// create file link in browser's memory
const href = URL.createObjectURL(response.data);
// create "a" HTML element with href to file & click
const link = document.createElement('a');
link.href = href;
link.setAttribute('download', 'file.pdf'); //or any other extension
document.body.appendChild(link);
link.click();
// clean up "a" element & remove ObjectURL
document.body.removeChild(link);
URL.revokeObjectURL(href);
});
```

@@ -1457,2 +1675,3 @@

```ts
// Node.js
import xior from 'xior';

@@ -1469,2 +1688,21 @@ const axios = xior.create();

});
// For browser
xior
.get('https://d2l.ai/d2l-en.pdf', {
headers: {
Accept: 'application/pdf',
},
responseType: 'blob',
})
.then((res) => res.response.blob())
.then((blob) => {
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = 'filename.pdf';
document.body.appendChild(a); // we need to append the element to the dom -> otherwise it will not work in firefox
a.click();
a.remove(); //afterwards we remove the element again
});
```

@@ -1471,0 +1709,0 @@

@@ -1,1 +0,1 @@

export{merge}from"ts-deepmerge";function e(e,r){let t=new globalThis.AbortController;function o(e){t.abort(e),i()}let n=[];for(let r of e){if((null==r?void 0:r.aborted)===!0){o(r.reason);break}if((null==r?void 0:r.addEventListener)!=null){let e=()=>{o(r.reason)};n.push(()=>{(null==r?void 0:r.removeEventListener)!=null&&r.removeEventListener("abort",e)}),r.addEventListener("abort",e)}}function i(){n.forEach(e=>{e()}),null==r||r()}let s=t.signal;return s.clear=i,s}function r(e,r,t){let o=r?t(r):"";o&&(o=e+(e.includes("?")?"&":"?")+o);let[n,i]=o.split("?");if(i){let e=i.split("&");return`${n}?${e.sort().join("&")}`}return o||e}function t(e){return new Promise(r=>{setTimeout(()=>{r("ok")},e)})}function o(e,r=!0,t=null){if(null==e)return"";let n=[],i=r?encodeURIComponent:e=>e;for(let s in e)if(Object.prototype.hasOwnProperty.call(e,s)){let l=e[s],u=t?`${t}[${i(s)}]`:i(s);if("object"==typeof l){let e=o(l,r,u);""!==e&&n.push(e)}else Array.isArray(l)?l.forEach((e,r)=>{let t=`${u}[${r}]`;n.push(`${i(t)}=${i(e)}`)}):n.push(`${i(u)}=${i(l)}`)}return n.join("&")}function n(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function i(e,r){return r?(e.endsWith("/")?e:e+"/")+(r.startsWith("/")?r.slice(1):r):e}class s extends Error{constructor(e,r,t){super(e),this.name="XiorError",this.request=r,this.config=r,this.response=t}}class l extends s{constructor(e,r,t){super(e),this.name="XiorTimeoutError",this.request=r,this.config=r,this.response=t}}function u(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name}export{s as XiorError,l as XiorTimeoutError,e as anySignal,r as buildSortedURL,t as delay,o as encodeParams,n as isAbsoluteURL,u as isXiorError,i as joinPath};
export{merge}from"ts-deepmerge";function e(e,r){let t=new globalThis.AbortController;function o(e){t.abort(e),i()}let n=[];for(let r of e){if((null==r?void 0:r.aborted)===!0){o(r.reason);break}if((null==r?void 0:r.addEventListener)!=null){let e=()=>{o(r.reason)};n.push(()=>{(null==r?void 0:r.removeEventListener)!=null&&r.removeEventListener("abort",e)}),r.addEventListener("abort",e)}}function i(){n.forEach(e=>{e()}),null==r||r()}let s=t.signal;return s.clear=i,s}function r(e,r,t){let o=r?t(r):"";o&&(o=e+(e.includes("?")?"&":"?")+o);let[n,i]=o.split("?");if(i){let e=i.split("&");return`${n}?${e.sort().join("&")}`}return o||e}function t(e){return new Promise(r=>{setTimeout(()=>{r("ok")},e)})}function o(e,r=!0,t=null){if(null==e)return"";let n=[],i=r?encodeURIComponent:e=>e;for(let s in e)if(Object.prototype.hasOwnProperty.call(e,s)){let l=e[s],u=t?`${t}[${i(s)}]`:i(s);if("object"==typeof l){let e=o(l,r,u);""!==e&&n.push(e)}else Array.isArray(l)?l.forEach((e,r)=>{let t=`${u}[${r}]`;n.push(`${i(t)}=${i(e)}`)}):n.push(`${i(u)}=${i(l)}`)}return n.join("&")}function n(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function i(e,r){return r?(e.endsWith("/")?e:e+"/")+("/"===r[0]?r.slice(1):r):e}class s extends Error{constructor(e,r,t){super(e),this.name="XiorError",this.request=r,this.config=r,this.response=t}}class l extends s{constructor(e,r,t){super(e),this.name="XiorTimeoutError",this.request=r,this.config=r,this.response=t}}function u(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name}export{s as XiorError,l as XiorTimeoutError,e as anySignal,r as buildSortedURL,t as delay,o as encodeParams,n as isAbsoluteURL,u as isXiorError,i as joinPath};

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc