Comparing version 0.5.1 to 0.5.2
@@ -1,1 +0,1 @@ | ||
import{merge as t,trimUndefined as e,encodeParams as r,XiorTimeoutError as n,anySignal as i,isAbsoluteURL as s,joinPath as a,XiorError as o}from"xior/utils";export*from"xior/utils";function u(t,e,r,n,i,s,a){try{var o=t[s](a),u=o.value}catch(t){r(t);return}o.done?e(u):Promise.resolve(u).then(n,i)}function l(){return(l=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}let c="application/",h=`${c}x-www-form-urlencoded`,f=`${c}json`;function p(){var n;return n=function*(n){let i=n.paramsSerializer||r,s=!1!==n.encodeURI,a=n.method?n.method.toUpperCase():"GET",o=n.url||"",u=o,c=n.data,p=c,d=(null==n?void 0:n.headers)||{},y=n.params||{},m=function(t="GET"){return["HEAD","GET","OPTIONS"].includes(t)}(a);if(c&&!(c instanceof FormData)){let r="";if(null==n?void 0:n.headers){let t=Object.keys(n.headers).find(t=>"content-type"===t.toLowerCase());t&&(r=n.headers[t],n.headers["Content-Type"]=r,"Content-Type"!==t&&delete n.headers[t])}r||(r=m?h:f,d["Content-Type"]=r),m&&n.params&&(y=t({},c||{},y)),r===f?p=JSON.stringify(e(c)):!m&&r===h&&c&&"object"==typeof c&&(p=i(c))}if(Object.keys(y).length>0){let t=i(y,s);o+=o.includes("?")?`&${t}`:`?${t}`}return l({},n,{_data:p,_url:o,data:c,url:u,method:a,headers:d,isGet:m})},(p=function(){var t=this,e=arguments;return new Promise(function(r,i){var s=n.apply(t,e);function a(t){u(s,r,i,a,o,"next",t)}function o(t){u(s,r,i,a,o,"throw",t)}a(void 0)})}).apply(this,arguments)}function d(t,e,r,n,i,s,a){try{var o=t[s](a),u=o.value}catch(t){r(t);return}o.done?e(u):Promise.resolve(u).then(n,i)}function y(t){return function(){var e=this,r=arguments;return new Promise(function(n,i){var s=t.apply(e,r);function a(t){d(s,n,i,a,o,"next",t)}function o(t){d(s,n,i,a,o,"throw",t)}a(void 0)})}}function m(){return(m=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}let v=void 0,E=typeof AbortController!=`${v}`;function P(){return(P=y(function*(t,e){let r;if(!e||!t.ok||["text","json"].includes(e)){if((r=yield t.text())&&"text"!==e)try{r=JSON.parse(r)}catch(t){}}else if("blob"===e)return t.blob();else if("arraybuffer"===e)return t.arrayBuffer();return r})).apply(this,arguments)}class b{static create(t){return new b(t)}get interceptors(){return{request:{use:(t,e,r)=>(this.REQI.push(t),t),eject:t=>{this.REQI=this.REQI.filter(e=>e!==t)},clear:()=>{this.REQI=[]}},response:{use:(t,e)=>(this.RESI.push({fn:t,onRejected:e}),t),eject:t=>{this.RESI=this.RESI.filter(e=>e.fn!==t)},clear:()=>{this.RESI=[]}}}}get plugins(){return{use:t=>(this.P.push(t),t),eject:t=>{this.P=this.P.filter(e=>e!==t)},clear:()=>{this.P=[]}}}request(e){var n=this;return y(function*(){let i=t({},n.config||{},n.defaults||{},"string"==typeof e?{url:e}:e||{},{headers:{},params:{}});for(let t of(i.withCredentials&&!i.credentials&&(i.credentials="include"),i.paramsSerializer||(i.paramsSerializer=r),n.REQI))i=yield t(i);let s=n.fetch.bind(n);return n.P.forEach(t=>{s=t(s,n)}),s(i)})()}fetch(t){var e=this;return y(function*(){let r;let u=yield function(t){return p.apply(this,arguments)}(t),{url:l,method:c,headers:h,timeout:f,signal:d,data:b,_data:g,_url:O,isGet:R}=u,I=function(t,e){if(null==t)return{};var r,n,i={},s=Object.keys(t);for(n=0;n<s.length;n++)e.indexOf(r=s[n])>=0||(i[r]=t[r]);return i}(u,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);t._url=O;let T=[],w=v;if(f&&E){let e=new AbortController;w=setTimeout(()=>{e.abort(new n(`timeout of ${f}ms exceeded`,t))},f),T.push(e.signal)}d&&T.push(d),r=T[0],T.length>1&&(r=i(T,()=>{clearTimeout(w)}));let S=O||l||"";t.baseURL&&!s(S)&&(S=a(t.baseURL,S));let j=0,x=fetch(S,m({body:R?v:g},I,{signal:r,method:c,headers:h})).then(y(function*(e){let{responseType:r}=t,n={data:yield function(t,e){return P.apply(this,arguments)}(e,r),response:e,config:t,request:t,status:e.status,statusText:e.statusText,headers:e.headers};return e.ok?n:Promise.reject(new o(e.status?`Request failed with status code ${e.status}`:"Network error",t,n))})).finally(()=>{var t;w&&clearTimeout(w),null==r||null==(t=r.clear)||t.call(r)}),G=[];for(e.RESI.forEach(function(t){G.push(t.fn,t.onRejected)});G.length>j;)x=x.then(G[j++],G[j++]);return x})()}cG(t){return(e,r)=>this.request(r?m({},r,{method:t,url:e}):{method:t,url:e})}cP(t){return(e,r,n)=>this.request(n?m({},n,{method:t,url:e,data:r}):{method:t,url:e,data:r})}get(t,e){return this.cG("GET")(t,e)}head(t,e){return this.cG("HEAD")(t,e)}post(t,e,r){return this.cP("POST")(t,e,r)}put(t,e,r){return this.cP("PUT")(t,e,r)}patch(t,e,r){return this.cP("PATCH")(t,e,r)}delete(t,e){return this.cG("DELETE")(t,e)}options(t,e){return this.cG("OPTIONS")(t,e)}constructor(t){this.REQI=[],this.RESI=[],this.P=[],this.config=t,this.defaults={params:{},headers:{}}}}b.VERSION="0.5.1";let g=Object.assign(b.create(),{create:b.create,VERSION:b.VERSION});export{b as Xior,g as default}; | ||
import{merge as e,encodeParams as t,XiorTimeoutError as r,anySignal as n,isAbsoluteURL as i,joinPath as s,XiorError as a}from"xior/utils";export*from"xior/utils";import{trimUndefined as o}from"../utils/index.mjs";function u(e,t,r,n,i,s,a){try{var o=e[s](a),u=o.value}catch(e){r(e);return}o.done?t(u):Promise.resolve(u).then(n,i)}function l(){return(l=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 c="application/",h=`${c}x-www-form-urlencoded`,f=`${c}json`,d="Content-Type",p=d.toLowerCase();function y(){var r;return r=function*(r){let n=r.paramsSerializer||t,i=!1!==r.encodeURI,s=r.method?r.method.toUpperCase():"GET",a=r.url||"",u=a,c=r.data,y=c,m=(null==r?void 0:r.headers)||{},v=r.params||{},E=function(e="GET"){return["HEAD","GET","OPTIONS"].includes(e)}(s);if(c&&!(c instanceof FormData)){let t="";if(null==r?void 0:r.headers){let e=Object.keys(r.headers).find(e=>e.toLowerCase()===p);e&&(t=r.headers[e],r.headers[d]=t,e!==d&&delete r.headers[e])}t||(t=E?h:f,m[d]=t),"object"!=typeof c||(E&&r.params&&(v=e({},c||{},v)),t===f?y=JSON.stringify(o(c)):E||t!==h||(y=n(c)))}if(Object.keys(v).length>0){let e=n(v,i);a+=a.includes("?")?`&${e}`:`?${e}`}return l({},r,{_data:y,_url:a,data:c,url:u,method:s,headers:m,isGet:E})},(y=function(){var e=this,t=arguments;return new Promise(function(n,i){var s=r.apply(e,t);function a(e){u(s,n,i,a,o,"next",e)}function o(e){u(s,n,i,a,o,"throw",e)}a(void 0)})}).apply(this,arguments)}function m(e,t,r,n,i,s,a){try{var o=e[s](a),u=o.value}catch(e){r(e);return}o.done?t(u):Promise.resolve(u).then(n,i)}function v(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var s=e.apply(t,r);function a(e){m(s,n,i,a,o,"next",e)}function o(e){m(s,n,i,a,o,"throw",e)}a(void 0)})}}function E(){return(E=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 P=void 0,b=typeof AbortController!=`${P}`;function g(){return(g=v(function*(e,t){let r;if(!t||!e.ok||["text","json"].includes(t)){if((r=yield e.text())&&"text"!==t)try{r=JSON.parse(r)}catch(e){}}else if("blob"===t)return e.blob();else if("arraybuffer"===t)return e.arrayBuffer();return r})).apply(this,arguments)}class O{static create(e){return new O(e)}get interceptors(){return{request:{use:(e,t,r)=>(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 v(function*(){let i=e({},n.config||{},n.defaults||{},"string"==typeof r?{url:r}:r||{},{headers:{},params:{}});for(let e of(i.withCredentials&&!i.credentials&&(i.credentials="include"),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 v(function*(){let o;let u=yield function(e){return y.apply(this,arguments)}(e),{url:l,method:c,headers:h,timeout:f,signal:d,data:p,_data:m,_url:O,isGet:R}=u,w=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}(u,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);e._url=O;let I=[],j=P;if(f&&b){let t=new AbortController;j=setTimeout(()=>{t.abort(new r(`timeout of ${f}ms exceeded`,e))},f),I.push(t.signal)}d&&I.push(d),o=I[0],I.length>1&&(o=n(I,()=>{clearTimeout(j)}));let S=O||l||"";e.baseURL&&!i(S)&&(S=s(e.baseURL,S));let x=0,T=fetch(S,E({body:R?P:m},w,{signal:o,method:c,headers:h})).then(v(function*(t){let{responseType:r}=e,n={data:yield function(e,t){return g.apply(this,arguments)}(t,r),response:t,config:e,request:e,status:t.status,statusText:t.statusText,headers:t.headers};return t.ok?n:Promise.reject(new a(t.status?`Request failed with status code ${t.status}`:"Network error",e,n))})).finally(()=>{var e;j&&clearTimeout(j),null==o||null==(e=o.clear)||e.call(o)}),G=[];for(t.RESI.forEach(function(e){G.push(e.fn,e.onRejected)});G.length>x;)T=T.then(G[x++],G[x++]);return T})()}cG(e){return(t,r)=>this.request(r?E({},r,{method:e,url:t}):{method:e,url:t})}cP(e){return(t,r,n)=>this.request(n?E({},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:{}}}}O.VERSION="0.5.2";let R=Object.assign(O.create(),{create:O.create,VERSION:O.VERSION});export{O as Xior,R as default}; |
@@ -79,3 +79,3 @@ import { XiorError } from 'xior/utils'; | ||
request: { | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: null | ((error: any) => any), options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void; | ||
@@ -85,3 +85,3 @@ clear: () => void; | ||
response: { | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: null | ((error: XiorError) => any)) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void; | ||
@@ -88,0 +88,0 @@ clear: () => void; |
@@ -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={699:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.anySignal=void 0,t.anySignal=function(e,t){const r=new globalThis.AbortController;function n(e){r.abort(e),i()}const o=[];for(const t of e){if(!0===(null==t?void 0:t.aborted)){n(t.reason);break}if(null!=(null==t?void 0:t.addEventListener)){const 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()}const s=r.signal;return s.clear=i,s}},509:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0});const i=r(895);o(r(895),t),o(r(340),t),o(r(121),t);const s=Object.assign(i.Xior.create(),{create:i.Xior.create,VERSION:i.Xior.VERSION});t.default=s},393: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{a(n.next(e))}catch(e){i(e)}}function u(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,u)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.likeGET=void 0;const o=r(121),i=r(976),s="application/",u=`${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 n(this,void 0,void 0,(function*(){const t=e.paramsSerializer||o.encodeParams,r=!1!==e.encodeURI,n=e.method?e.method.toUpperCase():"GET";let s=e.url||"";const l=s,d=e.data;let f=d;const h=(null==e?void 0:e.headers)||{};let p=e.params||{};const y=c(n);if(d&&!(d 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=y?u:a,h["Content-Type"]=r),y&&e.params&&(p=(0,o.merge)({},d||{},p)),r===a?f=JSON.stringify((0,i.trimUndefined)(d)):!y&&r===u&&d&&"object"==typeof d&&(f=t(d))}if(Object.keys(p).length>0){const e=t(p,r);s+=s.includes("?")?`&${e}`:`?${e}`}return Object.assign(Object.assign({},e),{_data:f,_url:s,data:d,url:l,method:n,headers:h,isGet:y})}))}},729:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.merge=void 0;const n=r(602);Object.defineProperty(t,"merge",{enumerable:!0,get:function(){return n.merge}})},629:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){let n=t?r(t):"";n&&(n=e+(e.includes("?")?"&":"?")+n);const[o,i]=n.split("?");return i?`${o}?${i.split("&").sort().join("&")}`:n||e}},99:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.delay=t.buildSortedURL=void 0;const o=n(r(629));t.buildSortedURL=o.default,t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t("ok")}),e)}))}},340:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},976:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.isXiorError=t.XiorTimeoutError=t.XiorError=t.joinPath=t.isAbsoluteURL=t.trimUndefined=t.encodeParams=void 0,o(r(699),t),o(r(729),t),o(r(99),t);const i=void 0;t.encodeParams=function e(t,r=!0,n=null){if(t===i||null===t)return"";const o=[],s=r?encodeURIComponent:e=>e;for(const u in t)if(Object.prototype.hasOwnProperty.call(t,u)){const a=t[u];if(a!==i){const t=n?`${n}[${s(u)}]`:s(u);if("object"==typeof a){const n=e(a,r,t);""!==n&&o.push(n)}else Array.isArray(a)?a.forEach(((e,r)=>{const n=`${t}[${r}]`;o.push(`${s(n)}=${s(e)}`)})):o.push(`${s(t)}=${s(a)}`)}}return o.join("&")},t.trimUndefined=function e(t){return Array.isArray(t)?t.map(e):(t&&"object"==typeof t&&Object.keys(t).forEach((r=>{const n=t[r];if(n!==i)return e(n);delete t[r]})),t)},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},t.joinPath=function(e,t){return t?(e.endsWith("/")?e:e+"/")+("/"===t[0]?t.slice(1):t):e};class s extends Error{constructor(e,t,r){super(e),this.name="XiorError",this.request=t,this.config=t,this.response=r}}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.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name}},895: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{a(n.next(e))}catch(e){i(e)}}function u(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,u)}a((n=n.apply(e,t||[])).next())}))},o=this&&this.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Xior=void 0;const s=r(121),u=i(r(393)),a=void 0,c="undefined"!=typeof AbortController;class l{static create(e){return new l(e)}constructor(e){this.REQI=[],this.RESI=[],this.P=[],this.config=e,this.defaults={params:{},headers:{}}}get interceptors(){return{request:{use:(e,t,r)=>(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 n(this,void 0,void 0,(function*(){let t=(0,s.merge)({},this.config||{},this.defaults||{},"string"==typeof e?{url:e}:e||{},{headers:{},params:{}});t.withCredentials&&!t.credentials&&(t.credentials="include"),t.paramsSerializer||(t.paramsSerializer=s.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){return n(this,void 0,void 0,(function*(){const t=yield(0,u.default)(e),{url:r,method:i,headers:l,timeout:d,signal:f,data:h,_data:p,_url:y,isGet:b}=t,m=o(t,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);let v;e._url=y;const g=[];let j=a;if(d&&c){const t=new AbortController;j=setTimeout((()=>{t.abort(new s.XiorTimeoutError(`timeout of ${d}ms exceeded`,e))}),d),g.push(t.signal)}f&&g.push(f),v=g[0],g.length>1&&(v=(0,s.anySignal)(g,(()=>{clearTimeout(j)})));let O=y||r||"";e.baseURL&&!(0,s.isAbsoluteURL)(O)&&(O=(0,s.joinPath)(e.baseURL,O));let E=0,_=fetch(O,Object.assign(Object.assign({body:b?a:p},m),{signal:v,method:i,headers:l})).then((t=>n(this,void 0,void 0,(function*(){const{responseType:r}=e,o=yield function(e,t){return n(this,void 0,void 0,(function*(){let r;if(t&&e.ok&&!["text","json"].includes(t)){if("blob"===t)return e.blob();if("arraybuffer"===t)return e.arrayBuffer()}else if(r=yield e.text(),r&&"text"!==t)try{r=JSON.parse(r)}catch(e){}return r}))}(t,r),i={data:o,response:t,config:e,request:e,status:t.status,statusText:t.statusText,headers:t.headers};if(!t.ok){const r=new s.XiorError(t.status?`Request failed with status code ${t.status}`:"Network error",e,i);return Promise.reject(r)}return i})))).finally((()=>{var e;j&&clearTimeout(j),null===(e=null==v?void 0:v.clear)||void 0===e||e.call(v)}));const P=[];for(this.RESI.forEach((function(e){P.push(e.fn,e.onRejected)}));P.length>E;)_=_.then(P[E++],P[E++]);return _}))}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,n)=>this.request(n?Object.assign(Object.assign({},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)}}t.Xior=l,l.VERSION="0.5.1"},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);const o=void 0;class i 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=i,t.XiorTimeoutError=class extends i{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(t===o||null===t)return"";let i=[],s=r?encodeURIComponent:e=>e;for(let u in t)if(Object.prototype.hasOwnProperty.call(t,u)){let a=t[u];if(a!==o){let t=n?`${n}[${s(u)}]`:s(u);if("object"==typeof a){let n=e(a,r,t);""!==n&&i.push(n)}else Array.isArray(a)?a.forEach(((e,r)=>{let n=`${t}[${r}]`;i.push(`${s(n)}=${s(e)}`)})):i.push(`${s(t)}=${s(a)}`)}}return i.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.trimUndefined=function e(t){return Array.isArray(t)?t.map(e):(t&&"object"==typeof t&&Object.keys(t).forEach((r=>{let n=t[r];if(n!==o)return e(n);delete t[r]})),t)}}},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}(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={699:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.anySignal=void 0,t.anySignal=function(e,t){const r=new globalThis.AbortController;function n(e){r.abort(e),i()}const o=[];for(const t of e){if(!0===(null==t?void 0:t.aborted)){n(t.reason);break}if(null!=(null==t?void 0:t.addEventListener)){const 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()}const s=r.signal;return s.clear=i,s}},509:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0});const i=r(895);o(r(895),t),o(r(340),t),o(r(121),t);const s=Object.assign(i.Xior.create(),{create:i.Xior.create,VERSION:i.Xior.VERSION});t.default=s},393: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{a(n.next(e))}catch(e){i(e)}}function u(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,u)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.likeGET=void 0;const o=r(121),i=r(976),s="application/",u=`${s}x-www-form-urlencoded`,a=`${s}json`,c="Content-Type",l=c.toLowerCase();function d(e="GET"){return["HEAD","GET","OPTIONS"].includes(e)}t.likeGET=d,t.default=function(e){return n(this,void 0,void 0,(function*(){const t=e.paramsSerializer||o.encodeParams,r=!1!==e.encodeURI,n=e.method?e.method.toUpperCase():"GET";let s=e.url||"";const f=s,h=e.data;let p=h;const b=(null==e?void 0:e.headers)||{};let m=e.params||{};const y=d(n);if(h&&!(h instanceof FormData)){let r="";if(null==e?void 0:e.headers){const t=Object.keys(e.headers).find((e=>e.toLowerCase()===l));t&&(r=e.headers[t],e.headers[c]=r,t!==c&&delete e.headers[t])}r||(r=y?u:a,b[c]=r),"object"==typeof h&&(y&&e.params&&(m=(0,o.merge)({},h||{},m)),r===a?p=JSON.stringify((0,i.trimUndefined)(h)):y||r!==u||(p=t(h)))}if(Object.keys(m).length>0){const e=t(m,r);s+=s.includes("?")?`&${e}`:`?${e}`}return Object.assign(Object.assign({},e),{_data:p,_url:s,data:h,url:f,method:n,headers:b,isGet:y})}))}},729:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.merge=void 0;const n=r(602);Object.defineProperty(t,"merge",{enumerable:!0,get:function(){return n.merge}})},629:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){let n=t?r(t):"";n&&(n=e+(e.includes("?")?"&":"?")+n);const[o,i]=n.split("?");return i?`${o}?${i.split("&").sort().join("&")}`:n||e}},99:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.delay=t.buildSortedURL=void 0;const o=n(r(629));t.buildSortedURL=o.default,t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t("ok")}),e)}))}},340:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},976:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.isXiorError=t.XiorTimeoutError=t.XiorError=t.joinPath=t.isAbsoluteURL=t.trimUndefined=t.encodeParams=void 0,o(r(699),t),o(r(729),t),o(r(99),t);const i=void 0;t.encodeParams=function e(t,r=!0,n=null,o){if(t===i||null===t)return"";const u=[],a=r?encodeURIComponent:e=>e,c=Array.isArray(t);for(const l in t)if(Object.prototype.hasOwnProperty.call(t,l)){let d=t[l];if(d!==i){const t=s(n,l,c,null==o?void 0:o.arrayFormat,null==o?void 0:o.allowDots);if(d instanceof Date&&(d=(null==o?void 0:o.serializeDate)?null==o?void 0:o.serializeDate(d):d.toISOString()),"object"==typeof d){const n=e(d,r,t,o);""!==n&&u.push(n)}else u.push(`${a(t)}=${a(d)}`)}}return u.join("&")};const s=(e,t,r,n,o)=>e?`${e}${(e=>{if(o&&!r)return`.${e}`;if(r){if("brackets"===n)return"[]";if("repeat"===n)return""}return`[${e}]`})(t)}`:t;t.trimUndefined=function e(t){return Array.isArray(t)?t.map(e):(t&&"object"==typeof t&&Object.keys(t).forEach((r=>{const n=t[r];if(n!==i)return e(n);delete t[r]})),t)},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},t.joinPath=function(e,t){return t?(e.endsWith("/")?e:e+"/")+("/"===t[0]?t.slice(1):t):e};class u extends Error{constructor(e,t,r){super(e),this.name="XiorError",this.request=t,this.config=t,this.response=r}}t.XiorError=u,t.XiorTimeoutError=class extends u{constructor(e,t,r){super(e),this.name="XiorTimeoutError",this.request=t,this.config=t,this.response=r}},t.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name}},895: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{a(n.next(e))}catch(e){i(e)}}function u(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,u)}a((n=n.apply(e,t||[])).next())}))},o=this&&this.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Xior=void 0;const s=r(121),u=i(r(393)),a=void 0,c="undefined"!=typeof AbortController;class l{static create(e){return new l(e)}constructor(e){this.REQI=[],this.RESI=[],this.P=[],this.config=e,this.defaults={params:{},headers:{}}}get interceptors(){return{request:{use:(e,t,r)=>(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 n(this,void 0,void 0,(function*(){let t=(0,s.merge)({},this.config||{},this.defaults||{},"string"==typeof e?{url:e}:e||{},{headers:{},params:{}});t.withCredentials&&!t.credentials&&(t.credentials="include"),t.paramsSerializer||(t.paramsSerializer=s.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){return n(this,void 0,void 0,(function*(){const t=yield(0,u.default)(e),{url:r,method:i,headers:l,timeout:d,signal:f,data:h,_data:p,_url:b,isGet:m}=t,y=o(t,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);let v;e._url=b;const g=[];let O=a;if(d&&c){const t=new AbortController;O=setTimeout((()=>{t.abort(new s.XiorTimeoutError(`timeout of ${d}ms exceeded`,e))}),d),g.push(t.signal)}f&&g.push(f),v=g[0],g.length>1&&(v=(0,s.anySignal)(g,(()=>{clearTimeout(O)})));let j=b||r||"";e.baseURL&&!(0,s.isAbsoluteURL)(j)&&(j=(0,s.joinPath)(e.baseURL,j));let E=0,_=fetch(j,Object.assign(Object.assign({body:m?a:p},y),{signal:v,method:i,headers:l})).then((t=>n(this,void 0,void 0,(function*(){const{responseType:r}=e,o=yield function(e,t){return n(this,void 0,void 0,(function*(){let r;if(t&&e.ok&&!["text","json"].includes(t)){if("blob"===t)return e.blob();if("arraybuffer"===t)return e.arrayBuffer()}else if(r=yield e.text(),r&&"text"!==t)try{r=JSON.parse(r)}catch(e){}return r}))}(t,r),i={data:o,response:t,config:e,request:e,status:t.status,statusText:t.statusText,headers:t.headers};if(!t.ok){const r=new s.XiorError(t.status?`Request failed with status code ${t.status}`:"Network error",e,i);return Promise.reject(r)}return i})))).finally((()=>{var e;O&&clearTimeout(O),null===(e=null==v?void 0:v.clear)||void 0===e||e.call(v)}));const P=[];for(this.RESI.forEach((function(e){P.push(e.fn,e.onRejected)}));P.length>E;)_=_.then(P[E++],P[E++]);return _}))}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,n)=>this.request(n?Object.assign(Object.assign({},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)}}t.Xior=l,l.VERSION="0.5.2"},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);const o=void 0,i=(e,t,r,n,o)=>e?`${e}${(e=>{if(o&&!r)return`.${e}`;if(r){if("brackets"===n)return"[]";if("repeat"===n)return""}return`[${e}]`})(t)}`:t;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 n.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 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,s){if(t===o||null===t)return"";let u=[],a=r?encodeURIComponent:e=>e,c=Array.isArray(t);for(let l in t)if(Object.prototype.hasOwnProperty.call(t,l)){let d=t[l];if(d!==o){let t=i(n,l,c,null==s?void 0:s.arrayFormat,null==s?void 0:s.allowDots);if(d instanceof Date&&(d=(null==s?void 0:s.serializeDate)?null==s?void 0:s.serializeDate(d):d.toISOString()),"object"==typeof d){let n=e(d,r,t,s);""!==n&&u.push(n)}else u.push(`${a(t)}=${a(d)}`)}}return u.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.trimUndefined=function e(t){return Array.isArray(t)?t.map(e):(t&&"object"==typeof t&&Object.keys(t).forEach((r=>{let n=t[r];if(n!==o)return e(n);delete t[r]})),t)}}},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}(509).default;var e,t})); |
{ | ||
"name": "xior", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "A lite request lib based on fetch with plugin support and similar API to axios.", | ||
@@ -5,0 +5,0 @@ "repository": "suhaotian/xior", |
/*! 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(884),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,c="GET"===s.method||s.isGet,h=typeof o;let f;if("function"===h&&(f=o(s)),void 0===f&&(f="undefined"===h?c: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)}))}}},884:(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);const s=void 0;class n 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=n,e.XiorTimeoutError=class extends n{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(e===s||null===e)return"";let n=[],o=r?encodeURIComponent:t=>t;for(let l in e)if(Object.prototype.hasOwnProperty.call(e,l)){let u=e[l];if(u!==s){let e=i?`${i}[${o(l)}]`:o(l);if("object"==typeof u){let i=t(u,r,e);""!==i&&n.push(i)}else Array.isArray(u)?u.forEach(((t,r)=>{let i=`${e}[${r}]`;n.push(`${o(i)}=${o(t)}`)})):n.push(`${o(e)}=${o(u)}`)}}return n.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.trimUndefined=function t(e){return Array.isArray(e)?e.map(t):(e&&"object"==typeof e&&Object.keys(e).forEach((r=>{let i=e[r];if(i!==s)return t(i);delete e[r]})),e)}}},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{a(i.next(t))}catch(t){n(t)}}function l(t){try{a(i.throw(t))}catch(t){n(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,l)}a((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:a=r,paramsSerializer:u}=s,c="GET"===s.method||s.isGet,h=typeof o;let f;if("function"===h&&(f=o(s)),void 0===f&&(f="undefined"===h?c:Boolean(o)),f){const e=a,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},u);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);const s=void 0,n=(t,e,r,i,s)=>t?`${t}${(t=>{if(s&&!r)return`.${t}`;if(r){if("brackets"===i)return"[]";if("repeat"===i)return""}return`[${t}]`})(e)}`:e;class o 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=o,e.XiorTimeoutError=class extends o{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,o){if(e===s||null===e)return"";let l=[],a=r?encodeURIComponent:t=>t,u=Array.isArray(e);for(let c in e)if(Object.prototype.hasOwnProperty.call(e,c)){let h=e[c];if(h!==s){let e=n(i,c,u,null==o?void 0:o.arrayFormat,null==o?void 0:o.allowDots);if(h instanceof Date&&(h=(null==o?void 0:o.serializeDate)?null==o?void 0:o.serializeDate(h):h.toISOString()),"object"==typeof h){let i=t(h,r,e,o);""!==i&&l.push(i)}else l.push(`${a(e)}=${a(h)}`)}}return l.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.trimUndefined=function t(e){return Array.isArray(e)?e.map(t):(e&&"object"==typeof e&&Object.keys(e).forEach((r=>{let i=e[r];if(i!==s)return t(i);delete e[r]})),e)}}},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})); |
/** | ||
* tiny-lru | ||
* | ||
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com> | ||
* @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com> | ||
* @license BSD-3-Clause | ||
* @version 11.2.6 | ||
* @version 11.2.5 | ||
*/ |
@@ -29,3 +29,3 @@ import { XiorError } from 'xior/utils'; | ||
request: { | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: null | ((error: any) => any), options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void; | ||
@@ -35,3 +35,3 @@ clear: () => void; | ||
response: { | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: null | ((error: XiorError) => any)) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void; | ||
@@ -38,0 +38,0 @@ clear: () => void; |
@@ -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 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}; | ||
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:a,defaultCache:c=e(i.cacheItems||100,i.cacheTime||3e5)}=i;return function(e){return o(function*(i){let u;let{enableCache:l=a,forceUpdate:f,defaultCache:h=c,paramsSerializer:d}=i,m="GET"===i.method||i.isGet,s=typeof l;if("function"===s&&(u=l(i)),void 0===u&&(u="undefined"===s?m:!!l),u){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);const n=void 0;class i 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=i,t.XiorTimeoutError=class extends i{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(t===n||null===t)return"";let i=[],s=r?encodeURIComponent:e=>e;for(let u in t)if(Object.prototype.hasOwnProperty.call(t,u)){let l=t[u];if(l!==n){let t=o?`${o}[${s(u)}]`:s(u);if("object"==typeof l){let o=e(l,r,t);""!==o&&i.push(o)}else Array.isArray(l)?l.forEach(((e,r)=>{let o=`${t}[${r}]`;i.push(`${s(o)}=${s(e)}`)})):i.push(`${s(t)}=${s(l)}`)}}return i.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.trimUndefined=function e(t){return Array.isArray(t)?t.map(e):(t&&"object"==typeof t&&Object.keys(t).forEach((r=>{let o=t[r];if(o!==n)return e(o);delete t[r]})),t)}}},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 n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{l(n.next(e))}catch(e){i(e)}}function u(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,u)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.inflight=void 0;const o=r(121);t.inflight=new Map,t.default=function(e={}){const{enableDedupe:r,onDedupe:i}=e;return function(e){return s=>n(this,void 0,void 0,(function*(){var n,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 y=(0,o.buildSortedURL)(s.url&&(0,o.isAbsoluteURL)(s.url)?s.url:(0,o.joinPath)(s.baseURL||"",s.url||""),{a:s.data,b:s.params},l);if(t.inflight.has(y))return c&&c(s),new Promise(((e,r)=>{var n;null===(n=t.inflight.get(y))||void 0===n||n.push([e,r])}));t.inflight.set(y,[]);try{const r=yield e(s);return null===(n=t.inflight.get(y))||void 0===n||n.forEach((([e])=>e(r))),t.inflight.delete(y),r}catch(e){throw null===(u=t.inflight.get(y))||void 0===u||u.forEach((([,t])=>t(e))),t.inflight.delete(y),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,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);const o=void 0,i=(e,t,r,n,o)=>e?`${e}${(e=>{if(o&&!r)return`.${e}`;if(r){if("brackets"===n)return"[]";if("repeat"===n)return""}return`[${e}]`})(t)}`:t;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 n.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 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,s){if(t===o||null===t)return"";let u=[],l=r?encodeURIComponent:e=>e,a=Array.isArray(t);for(let c in t)if(Object.prototype.hasOwnProperty.call(t,c)){let f=t[c];if(f!==o){let t=i(n,c,a,null==s?void 0:s.arrayFormat,null==s?void 0:s.allowDots);if(f instanceof Date&&(f=(null==s?void 0:s.serializeDate)?null==s?void 0:s.serializeDate(f):f.toISOString()),"object"==typeof f){let n=e(f,r,t,s);""!==n&&u.push(n)}else u.push(`${l(t)}=${l(f)}`)}}return u.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.trimUndefined=function e(t){return Array.isArray(t)?t.map(e):(t&&"object"==typeof t&&Object.keys(t).forEach((r=>{let n=t[r];if(n!==o)return e(n);delete t[r]})),t)}}},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}(91).default;var e,t})); |
@@ -20,3 +20,3 @@ import { XiorError } from 'xior/utils'; | ||
request: { | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: null | ((error: any) => any), options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void; | ||
@@ -26,3 +26,3 @@ clear: () => void; | ||
response: { | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: null | ((error: XiorError) => any)) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void; | ||
@@ -29,0 +29,0 @@ clear: () => void; |
@@ -1,1 +0,1 @@ | ||
import{buildSortedURL as e,isAbsoluteURL as t,joinPath as n}from"xior/utils";function r(e,t,n,r,u,o,i){try{var l=e[o](i),a=l.value}catch(e){n(e);return}l.done?t(a):Promise.resolve(a).then(r,u)}let u=new Map;function o(o={}){let{enableDedupe:i,onDedupe:l}=o;return function(o){var a;return a=function*(r){var a,f;let c;let{paramsSerializer:d,enableDedupe:s=i,onDedupe:h=l}=r,p="GET"===r.method||r.isGet,v=typeof s;if("function"===v&&(c=s(r)),void 0===c&&(c="undefined"===v?p:!!s),!c)return o(r);let m=e(r.url&&t(r.url)?r.url:n(r.baseURL||"",r.url||""),{a:r.data,b:r.params},d);if(u.has(m))return h&&h(r),new Promise((e,t)=>{var n;null==(n=u.get(m))||n.push([e,t])});u.set(m,[]);try{let e=yield o(r);return null==(a=u.get(m))||a.forEach(([t])=>t(e)),u.delete(m),e}catch(e){throw null==(f=u.get(m))||f.forEach(([,t])=>t(e)),u.delete(m),e}},function(){var e=this,t=arguments;return new Promise(function(n,u){var o=a.apply(e,t);function i(e){r(o,n,u,i,l,"next",e)}function l(e){r(o,n,u,i,l,"throw",e)}i(void 0)})}}}export{o as default,u as inflight}; | ||
import{buildSortedURL as e,isAbsoluteURL as t,joinPath as n}from"xior/utils";function r(e,t,n,r,u,o,i){try{var l=e[o](i),a=l.value}catch(e){n(e);return}l.done?t(a):Promise.resolve(a).then(r,u)}let u=new Map;function o(i={}){let{enableDedupe:l,onDedupe:a}=i;return function(o){var i;return i=function*(r){var i,f;let c;let{paramsSerializer:d,enableDedupe:s=l,onDedupe:h=a}=r,p="GET"===r.method||r.isGet,v=typeof s;if("function"===v&&(c=s(r)),void 0===c&&(c="undefined"===v?p:!!s),!c)return o(r);let m=e(r.url&&t(r.url)?r.url:n(r.baseURL||"",r.url||""),{a:r.data,b:r.params},d);if(u.has(m))return h&&h(r),new Promise((e,t)=>{var n;null==(n=u.get(m))||n.push([e,t])});u.set(m,[]);try{let e=yield o(r);return null==(i=u.get(m))||i.forEach(([t])=>t(e)),u.delete(m),e}catch(e){throw null==(f=u.get(m))||f.forEach(([,t])=>t(e)),u.delete(m),e}},function(){var e=this,t=arguments;return new Promise(function(n,u){var o=i.apply(e,t);function l(e){r(o,n,u,l,a,"next",e)}function a(e){r(o,n,u,l,a,"throw",e)}l(void 0)})}}}export{o as default,u as inflight}; |
/*! 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{a(i.next(e))}catch(e){n(e)}}function l(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,l)}a((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const s=r(884),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:a=t,defaultCache:u=r,useCacheFirst:c=o,onCacheRequest:h=l,paramsSerializer:f}=s,d="GET"===s.method||s.isGet,p=typeof a;let m;if("function"===p&&(m=a(s)),void 0===m&&(m="undefined"===p?d:Boolean(a)),!m)return e(s);const v=u,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}}))}}},884:(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);const s=void 0;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 i.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 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(t===s||null===t)return"";let n=[],o=r?encodeURIComponent:e=>e;for(let l in t)if(Object.prototype.hasOwnProperty.call(t,l)){let a=t[l];if(a!==s){let t=i?`${i}[${o(l)}]`:o(l);if("object"==typeof a){let i=e(a,r,t);""!==i&&n.push(i)}else Array.isArray(a)?a.forEach(((e,r)=>{let i=`${t}[${r}]`;n.push(`${o(i)}=${o(e)}`)})):n.push(`${o(t)}=${o(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.trimUndefined=function e(t){return Array.isArray(t)?t.map(e):(t&&"object"==typeof t&&Object.keys(t).forEach((r=>{let i=t[r];if(i!==s)return e(i);delete t[r]})),t)}}},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})); | ||
!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{a(i.next(e))}catch(e){n(e)}}function l(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,l)}a((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:a=t,defaultCache:u=r,useCacheFirst:c=o,onCacheRequest:h=l,paramsSerializer:f}=s,d="GET"===s.method||s.isGet,p=typeof a;let m;if("function"===p&&(m=a(s)),void 0===m&&(m="undefined"===p?d:Boolean(a)),!m)return e(s);const v=u,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);const s=void 0,n=(e,t,r,i,s)=>e?`${e}${(e=>{if(s&&!r)return`.${e}`;if(r){if("brackets"===i)return"[]";if("repeat"===i)return""}return`[${e}]`})(t)}`:t;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 i.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 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,o){if(t===s||null===t)return"";let l=[],a=r?encodeURIComponent:e=>e,u=Array.isArray(t);for(let c in t)if(Object.prototype.hasOwnProperty.call(t,c)){let h=t[c];if(h!==s){let t=n(i,c,u,null==o?void 0:o.arrayFormat,null==o?void 0:o.allowDots);if(h instanceof Date&&(h=(null==o?void 0:o.serializeDate)?null==o?void 0:o.serializeDate(h):h.toISOString()),"object"==typeof h){let i=e(h,r,t,o);""!==i&&l.push(i)}else l.push(`${a(t)}=${a(h)}`)}}return l.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.trimUndefined=function e(t){return Array.isArray(t)?t.map(e):(t&&"object"==typeof t&&Object.keys(t).forEach((r=>{let i=t[r];if(i!==s)return e(i);delete t[r]})),t)}}},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})); |
/** | ||
* tiny-lru | ||
* | ||
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com> | ||
* @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com> | ||
* @license BSD-3-Clause | ||
* @version 11.2.6 | ||
* @version 11.2.5 | ||
*/ |
@@ -29,3 +29,3 @@ import { XiorError } from 'xior/utils'; | ||
request: { | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: null | ((error: any) => any), options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void; | ||
@@ -35,3 +35,3 @@ clear: () => void; | ||
response: { | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: null | ((error: XiorError) => any)) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void; | ||
@@ -38,0 +38,0 @@ clear: () => void; |
@@ -1,1 +0,1 @@ | ||
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}; | ||
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:c,defaultCache:a=e(n.cacheItems||100),useCacheFirst:u,onCacheRequest:s}=n;return function(e){return l(function*(n){let o;let{enableCache:d=c,defaultCache:h=a,useCacheFirst:f=u,onCacheRequest:m=s,paramsSerializer:v}=n,T="GET"===n.method||n.isGet,g=typeof d;if("function"===g&&(o=d(n)),void 0===o&&(o="undefined"===g?T:!!d),!o)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(){return o(this,arguments,void 0,(function*(t=!1){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);const n=void 0;class i 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=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.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(r===n||null===r)return"";let i=[],s=t?encodeURIComponent:e=>e;for(let u in r)if(Object.prototype.hasOwnProperty.call(r,u)){let c=r[u];if(c!==n){let r=o?`${o}[${s(u)}]`:s(u);if("object"==typeof c){let o=e(c,t,r);""!==o&&i.push(o)}else Array.isArray(c)?c.forEach(((e,t)=>{let o=`${r}[${t}]`;i.push(`${s(o)}=${s(e)}`)})):i.push(`${s(r)}=${s(c)}`)}}return i.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.trimUndefined=function e(r){return Array.isArray(r)?r.map(e):(r&&"object"==typeof r&&Object.keys(r).forEach((t=>{let o=r[t];if(o!==n)return e(o);delete r[t]})),r)}}},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{l(o.next(e))}catch(e){i(e)}}function u(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var r;e.done?n(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(s,u)}l((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 l=>o(this,void 0,void 0,(function*(){const{retryTimes:a=r,retryInterval:c=t,enableRetry:f=i,onRetry:d=s}=l;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)l=yield e(l);try{return yield e(l)}catch(e){const t="GET"===l.method||Boolean(l.isGet),o=typeof f;let i;if("function"===o&&(i=f(l,e)),void 0===i&&(i="undefined"===o?t:Boolean(f)),y=a===p,y||!i)throw e;const s="function"==typeof c?c(p,l,e):c;return s&&s>0&&p>0&&(yield(0,n.delay)(s)),p++,d&&d(l,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);const n=void 0,i=(e,r,t,o,n)=>e?`${e}${(e=>{if(n&&!t)return`.${e}`;if(t){if("brackets"===o)return"[]";if("repeat"===o)return""}return`[${e}]`})(r)}`:r;class s 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=s,r.XiorTimeoutError=class extends s{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,s){if(r===n||null===r)return"";let u=[],l=t?encodeURIComponent:e=>e,a=Array.isArray(r);for(let c in r)if(Object.prototype.hasOwnProperty.call(r,c)){let f=r[c];if(f!==n){let r=i(o,c,a,null==s?void 0:s.arrayFormat,null==s?void 0:s.allowDots);if(f instanceof Date&&(f=(null==s?void 0:s.serializeDate)?null==s?void 0:s.serializeDate(f):f.toISOString()),"object"==typeof f){let o=e(f,t,r,s);""!==o&&u.push(o)}else u.push(`${l(r)}=${l(f)}`)}}return u.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.trimUndefined=function e(r){return Array.isArray(r)?r.map(e):(r&&"object"==typeof r&&Object.keys(r).forEach((t=>{let o=r[t];if(o!==n)return e(o);delete r[t]})),r)}}},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})); |
@@ -20,3 +20,3 @@ import { XiorError } from 'xior/utils'; | ||
request: { | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: null | ((error: any) => any), options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void; | ||
@@ -26,3 +26,3 @@ clear: () => void; | ||
response: { | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: null | ((error: XiorError) => any)) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void; | ||
@@ -29,0 +29,0 @@ clear: () => void; |
@@ -1,1 +0,1 @@ | ||
import{delay as t}from"xior/utils";function r(t,r,n,e,o,i,u){try{var f=t[i](u),l=f.value}catch(t){n(t);return}f.done?r(l):Promise.resolve(l).then(e,o)}function n(t){return function(){var n=this,e=arguments;return new Promise(function(o,i){var u=t.apply(n,e);function f(t){r(u,o,i,f,l,"next",t)}function l(t){r(u,o,i,f,l,"throw",t)}f(void 0)})}}function e(){return(e=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])}return t}).apply(this,arguments)}function o(r={}){let{retryTimes:o,retryInterval:i,enableRetry:u,onRetry:f}=e({},{retryTimes:2,retryInterval:3e3},r||{});return function(r,e){return n(function*(l){let{retryTimes:c=o,retryInterval:a=i,enableRetry:y=u,onRetry:p=f}=l,s=0;function v(){return h.apply(this,arguments)}function h(){return(h=n(function*(n=!1){if(n&&(null==e?void 0:e.REQI))for(let t of e.REQI)l=yield t(l);try{return yield r(l)}catch(i){let r;let n="GET"===l.method||!!l.isGet,e=typeof y;if("function"===e&&(r=y(l,i)),void 0===r&&(r="undefined"===e?n:!!y),c===s||!r)throw i;let o="function"==typeof a?a(s,l,i):a;return o&&o>0&&s>0&&(yield t(o)),s++,p&&p(l,i,s),v(!0)}})).apply(this,arguments)}return v()})}}export{o as default}; | ||
import{delay as t}from"xior/utils";function r(t,r,n,e,o,i,u){try{var f=t[i](u),l=f.value}catch(t){n(t);return}f.done?r(l):Promise.resolve(l).then(e,o)}function n(t){return function(){var n=this,e=arguments;return new Promise(function(o,i){var u=t.apply(n,e);function f(t){r(u,o,i,f,l,"next",t)}function l(t){r(u,o,i,f,l,"throw",t)}f(void 0)})}}function e(){return(e=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])}return t}).apply(this,arguments)}function o(r={}){let{retryTimes:i,retryInterval:u,enableRetry:f,onRetry:l}=e({},{retryTimes:2,retryInterval:3e3},r||{});return function(r,e){return n(function*(o){let{retryTimes:c=i,retryInterval:a=u,enableRetry:y=f,onRetry:p=l}=o,s=0;function v(){return h.apply(this,arguments)}function h(){return(h=n(function*(n=!1){if(n&&(null==e?void 0:e.REQI))for(let t of e.REQI)o=yield t(o);try{return yield r(o)}catch(u){let r;let n="GET"===o.method||!!o.isGet,e=typeof y;if("function"===e&&(r=y(o,u)),void 0===r&&(r="undefined"===e?n:!!y),c===s||!r)throw u;let i="function"==typeof a?a(s,o,u):a;return i&&i>0&&s>0&&(yield t(i)),s++,p&&p(o,u,s),v(!0)}})).apply(this,arguments)}return v()})}}export{o 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.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);const o=void 0;class i 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=i,t.XiorTimeoutError=class extends i{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(t===o||null===t)return"";let i=[],s=r?encodeURIComponent:e=>e;for(let a in t)if(Object.prototype.hasOwnProperty.call(t,a)){let d=t[a];if(d!==o){let t=n?`${n}[${s(a)}]`:s(a);if("object"==typeof d){let n=e(d,r,t);""!==n&&i.push(n)}else Array.isArray(d)?d.forEach(((e,r)=>{let n=`${t}[${r}]`;i.push(`${s(n)}=${s(e)}`)})):i.push(`${s(t)}=${s(d)}`)}}return i.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.trimUndefined=function e(t){return Array.isArray(t)?t.map(e):(t&&"object"==typeof t&&Object.keys(t).forEach((r=>{let n=t[r];if(n!==o)return e(n);delete t[r]})),t)}}},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{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}l((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 l(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 d(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 u(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,l,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 l=n.find((e=>e.aborted));if(l)return null==a||a(),Promise.reject(l.reason);if(2===f.length)return e(t);if("function"!=typeof f[2]){const e=f.slice(2),r=u({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=u({data:c[1],status:c[0],statusText:"ok",headers:d(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:u({data:e[1],status:e[0],statusText:"ok",headers:d(e[2]),request:t,config:t},t)}}if("passthrough"===(null===(l=this.options)||void 0===l?void 0:l.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,l,d;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===(d=null===(l=this.instance)||void 0===l?void 0:l.config)||void 0===d?void 0:d.data},r||{}):{},t=void 0===t?/.*/:t;const u=(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:u,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:()=>u((e=>Promise.reject(new o.XiorError("Request aborted",e)))),abortRequestOnce:()=>c((e=>Promise.reject(new o.XiorError("Request aborted",e,{})))),networkError:()=>u((e=>Promise.reject(new o.XiorError("Network Error",e,{})))),networkErrorOnce:()=>c((e=>Promise.reject(new o.XiorError("Network Error",e,{})))),timeout:()=>u((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:d}=e,u=null==r?void 0:r.toLowerCase();return null===(t=this.handlers[u])||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=d&&t[0].startsWith(d),r=(0,o.buildSortedURL)(e?(0,o.joinPath)(d,n):(0,o.joinPath)("/",n),{b:s,c:a,a:i},o.encodeParams),u=(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===u||r.startsWith(u)||l([[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)(d||"",n)))&&((0,o.buildSortedURL)(u,{b:s,c:a,a:i},o.encodeParams)===(0,o.buildSortedURL)(u,{b:t[1].params||{},c:t[1].data||{},a:c},o.encodeParams)||l([[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);const o=void 0,i=(e,t,r,n,o)=>e?`${e}${(e=>{if(o&&!r)return`.${e}`;if(r){if("brackets"===n)return"[]";if("repeat"===n)return""}return`[${e}]`})(t)}`:t;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 n.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 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,s){if(t===o||null===t)return"";let a=[],l=r?encodeURIComponent:e=>e,d=Array.isArray(t);for(let u in t)if(Object.prototype.hasOwnProperty.call(t,u)){let c=t[u];if(c!==o){let t=i(n,u,d,null==s?void 0:s.arrayFormat,null==s?void 0:s.allowDots);if(c instanceof Date&&(c=(null==s?void 0:s.serializeDate)?null==s?void 0:s.serializeDate(c):c.toISOString()),"object"==typeof c){let n=e(c,r,t,s);""!==n&&a.push(n)}else a.push(`${l(t)}=${l(c)}`)}}return a.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.trimUndefined=function e(t){return Array.isArray(t)?t.map(e):(t&&"object"==typeof t&&Object.keys(t).forEach((r=>{let n=t[r];if(n!==o)return e(n);delete t[r]})),t)}}},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})); |
@@ -20,3 +20,3 @@ import { XiorError } from 'xior/utils'; | ||
request: { | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: null | ((error: any) => any), options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void; | ||
@@ -26,3 +26,3 @@ clear: () => void; | ||
response: { | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: null | ((error: XiorError) => any)) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void; | ||
@@ -29,0 +29,0 @@ clear: () => void; |
@@ -20,3 +20,3 @@ import { XiorError } from 'xior/utils'; | ||
request: { | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: null | ((error: any) => any), options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void; | ||
@@ -26,3 +26,3 @@ clear: () => void; | ||
response: { | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: null | ((error: XiorError) => any)) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void; | ||
@@ -29,0 +29,0 @@ clear: () => void; |
@@ -1,1 +0,1 @@ | ||
function e(e,r,t,n,l,o,a){try{var u=e[o](a),i=u.value}catch(e){t(e);return}u.done?r(i):Promise.resolve(i).then(n,l)}function r(r={}){let{progressDuration:t=5e3}=r;return function(r){var n;return n=function*(e){let n;let{progressDuration:l=t,onUploadProgress:o,onDownloadProgress:a}=e;if(o||a){let e=0,r=0,t=1e3/(l/300);n=setInterval(()=>{if(r>=99)return clearInterval(n);e+=Math.random()*t,r=Math.floor(e/1e3*100);let l={total:1e3,loaded:e,progress:r};l.progress>=99&&(l.progress=99,l.loaded=990),null==o||o(l),null==a||a(l)},300)}try{let t=yield r(e);if(o||a){let e={total:1e3,loaded:1e3,progress:100};null==o||o(e),null==a||a(e)}return t}catch(e){throw e}finally{n&&clearInterval(n)}},function(){var r=this,t=arguments;return new Promise(function(l,o){var a=n.apply(r,t);function u(r){e(a,l,o,u,i,"next",r)}function i(r){e(a,l,o,u,i,"throw",r)}u(void 0)})}}}export{r as default}; | ||
function e(e,r,t,n,l,o,a){try{var u=e[o](a),i=u.value}catch(e){t(e);return}u.done?r(i):Promise.resolve(i).then(n,l)}function r(t={}){let{progressDuration:n=5e3}=t;return function(r){var t;return t=function*(e){let t;let{progressDuration:l=n,onUploadProgress:o,onDownloadProgress:a}=e;if(o||a){let e=0,r=0,n=1e3/(l/300);t=setInterval(()=>{if(r>=99)return clearInterval(t);e+=Math.random()*n,r=Math.floor(e/1e3*100);let l={total:1e3,loaded:e,progress:r};l.progress>=99&&(l.progress=99,l.loaded=990),null==o||o(l),null==a||a(l)},300)}try{let t=yield r(e);if(o||a){let e={total:1e3,loaded:1e3,progress:100};null==o||o(e),null==a||a(e)}return t}catch(e){throw e}finally{t&&clearInterval(t)}},function(){var r=this,n=arguments;return new Promise(function(l,o){var a=t.apply(r,n);function u(r){e(a,l,o,u,i,"next",r)}function i(r){e(a,l,o,u,i,"throw",r)}u(void 0)})}}}export{r as default}; |
/*! 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 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(884),n=r(121);e.default=function(t={}){const{enableThrottle:e,threshold:r=1e3,throttleCache:o=(0,s.lru)(t.throttleItems||100),onThrottle:l}=t,u=o;return function(t){const s=(e,r)=>{const s=(()=>i(this,void 0,void 0,(function*(){try{const i=yield t(r);return u.set(e,{timestamp:Date.now(),value:Promise.resolve(i)}),i}catch(t){throw"delete"in u?u.delete(e):u.del(e),t}})))();return u.set(e,{timestamp:Date.now(),value:s}),s};return o=>i(this,void 0,void 0,(function*(){const{paramsSerializer:i,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},i),e=Date.now(),r=u.get(t)||{timestamp:e},l=r.value;return l&&e-r.timestamp<=a?(null==c||c(o),l):s(t,o)}return t(o)}))}}},884:(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);const s=void 0;class n 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=n,e.XiorTimeoutError=class extends n{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(e===s||null===e)return"";let n=[],o=r?encodeURIComponent:t=>t;for(let l in e)if(Object.prototype.hasOwnProperty.call(e,l)){let u=e[l];if(u!==s){let e=i?`${i}[${o(l)}]`:o(l);if("object"==typeof u){let i=t(u,r,e);""!==i&&n.push(i)}else Array.isArray(u)?u.forEach(((t,r)=>{let i=`${e}[${r}]`;n.push(`${o(i)}=${o(t)}`)})):n.push(`${o(e)}=${o(u)}`)}}return n.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.trimUndefined=function t(e){return Array.isArray(e)?e.map(t):(e&&"object"==typeof e&&Object.keys(e).forEach((r=>{let i=e[r];if(i!==s)return t(i);delete e[r]})),e)}}},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}(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 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{enableThrottle:e,threshold:r=1e3,throttleCache:o=(0,s.lru)(t.throttleItems||100),onThrottle:l}=t,u=o;return function(t){const s=(e,r)=>{const s=(()=>i(this,void 0,void 0,(function*(){try{const i=yield t(r);return u.set(e,{timestamp:Date.now(),value:Promise.resolve(i)}),i}catch(t){throw"delete"in u?u.delete(e):u.del(e),t}})))();return u.set(e,{timestamp:Date.now(),value:s}),s};return o=>i(this,void 0,void 0,(function*(){const{paramsSerializer:i,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},i),e=Date.now(),r=u.get(t)||{timestamp:e},l=r.value;return l&&e-r.timestamp<=a?(null==c||c(o),l):s(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,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);const s=void 0,n=(t,e,r,i,s)=>t?`${t}${(t=>{if(s&&!r)return`.${t}`;if(r){if("brackets"===i)return"[]";if("repeat"===i)return""}return`[${t}]`})(e)}`:e;class o 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=o,e.XiorTimeoutError=class extends o{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,o){if(e===s||null===e)return"";let l=[],u=r?encodeURIComponent:t=>t,a=Array.isArray(e);for(let h in e)if(Object.prototype.hasOwnProperty.call(e,h)){let c=e[h];if(c!==s){let e=n(i,h,a,null==o?void 0:o.arrayFormat,null==o?void 0:o.allowDots);if(c instanceof Date&&(c=(null==o?void 0:o.serializeDate)?null==o?void 0:o.serializeDate(c):c.toISOString()),"object"==typeof c){let i=t(c,r,e,o);""!==i&&l.push(i)}else l.push(`${u(e)}=${u(c)}`)}}return l.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.trimUndefined=function t(e){return Array.isArray(e)?e.map(t):(e&&"object"==typeof e&&Object.keys(e).forEach((r=>{let i=e[r];if(i!==s)return t(i);delete e[r]})),e)}}},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}(272).default;var t,e})); |
/** | ||
* tiny-lru | ||
* | ||
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com> | ||
* @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com> | ||
* @license BSD-3-Clause | ||
* @version 11.2.6 | ||
* @version 11.2.5 | ||
*/ |
@@ -29,3 +29,3 @@ import { XiorError } from 'xior/utils'; | ||
request: { | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: null | ((error: any) => any), options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig; | ||
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void; | ||
@@ -35,3 +35,3 @@ clear: () => void; | ||
response: { | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: null | ((error: XiorError) => any)) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig; | ||
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void; | ||
@@ -38,0 +38,0 @@ clear: () => void; |
@@ -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,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}; | ||
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:i,threshold:a=1e3,throttleCache:s=t(o.throttleItems||100),onThrottle:m}=o;return function(t){let o=(e,r)=>{let n=l(function*(){try{let n=yield t(r);return s.set(e,{timestamp:Date.now(),value:Promise.resolve(n)}),n}catch(t){throw"delete"in s?s.delete(e):s.del(e),t}})();return s.set(e,{timestamp:Date.now(),value:n}),n};return l(function*(l){let u;let{paramsSerializer:f,threshold:c=a,enableThrottle:d=i,onThrottle:h=m}=l,p="GET"===l.method||l.isGet,v=typeof d;if("function"===v&&(u=d(l)),void 0===u&&(u="undefined"===v?p:!!d),u){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=s.get(t)||{timestamp:u},a=i.value;return a&&u-i.timestamp<=c?(null==h||h(l),a):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.trimUndefined=r.encodeParams=void 0,n(t(699),r),n(t(729),r),n(t(99),r);const i=void 0;r.encodeParams=function e(r,t=!0,o=null){if(r===i||null===r)return"";const n=[],s=t?encodeURIComponent:e=>e;for(const u in r)if(Object.prototype.hasOwnProperty.call(r,u)){const c=r[u];if(c!==i){const r=o?`${o}[${s(u)}]`:s(u);if("object"==typeof c){const o=e(c,t,r);""!==o&&n.push(o)}else Array.isArray(c)?c.forEach(((e,t)=>{const o=`${r}[${t}]`;n.push(`${s(o)}=${s(e)}`)})):n.push(`${s(r)}=${s(c)}`)}}return n.join("&")},r.trimUndefined=function e(r){return Array.isArray(r)?r.map(e):(r&&"object"==typeof r&&Object.keys(r).forEach((t=>{const o=r[t];if(o!==i)return e(o);delete r[t]})),r)},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 s extends Error{constructor(e,r,t){super(e),this.name="XiorError",this.request=r,this.config=r,this.response=t}}r.XiorError=s,r.XiorTimeoutError=class extends s{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.trimUndefined=r.encodeParams=void 0,n(t(699),r),n(t(729),r),n(t(99),r);const i=void 0;r.encodeParams=function e(r,t=!0,o=null,n){if(r===i||null===r)return"";const u=[],c=t?encodeURIComponent:e=>e,a=Array.isArray(r);for(const l in r)if(Object.prototype.hasOwnProperty.call(r,l)){let d=r[l];if(d!==i){const r=s(o,l,a,null==n?void 0:n.arrayFormat,null==n?void 0:n.allowDots);if(d instanceof Date&&(d=(null==n?void 0:n.serializeDate)?null==n?void 0:n.serializeDate(d):d.toISOString()),"object"==typeof d){const o=e(d,t,r,n);""!==o&&u.push(o)}else u.push(`${c(r)}=${c(d)}`)}}return u.join("&")};const s=(e,r,t,o,n)=>e?`${e}${(e=>{if(n&&!t)return`.${e}`;if(t){if("brackets"===o)return"[]";if("repeat"===o)return""}return`[${e}]`})(r)}`:r;r.trimUndefined=function e(r){return Array.isArray(r)?r.map(e):(r&&"object"==typeof r&&Object.keys(r).forEach((t=>{const o=r[t];if(o!==i)return e(o);delete r[t]})),r)},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 u extends Error{constructor(e,r,t){super(e),this.name="XiorError",this.request=r,this.config=r,this.response=t}}r.XiorError=u,r.XiorTimeoutError=class extends u{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})())); |
@@ -102,3 +102,3 @@ [![Build](https://github.com/suhaotian/xior/actions/workflows/check.yml/badge.svg)](https://github.com/suhaotian/xior/actions/workflows/check.yml) | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.2/dist/xior.umd.js"></script> | ||
@@ -118,3 +118,3 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.5.2/dist/xior.umd.js"></script> | ||
@@ -272,3 +272,3 @@ <!-- Usage --> | ||
// One more inteceptor for request | ||
// One more interceptors for request | ||
http.interceptors.request.use((config) => { | ||
@@ -567,5 +567,5 @@ return config; | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.2/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.1/plugins/error-retry.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.2/plugins/error-retry.umd.js"></script> | ||
@@ -583,6 +583,6 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.5.2/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://unpkg.com/xior@0.5.1/plugins/error-retry.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.5.2/plugins/error-retry.umd.js"></script> | ||
@@ -680,5 +680,5 @@ <!-- Usage --> | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.2/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.1/plugins/throttle.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.2/plugins/throttle.umd.js"></script> | ||
@@ -696,6 +696,6 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.5.2/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://unpkg.com/xior@0.5.1/plugins/throttle.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.5.2/plugins/throttle.umd.js"></script> | ||
@@ -755,5 +755,5 @@ <!-- Usage --> | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.2/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.1/plugins/dedupe.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.2/plugins/dedupe.umd.js"></script> | ||
@@ -771,6 +771,6 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.5.2/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://unpkg.com/xior@0.5.1/plugins/dedupe.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.5.2/plugins/dedupe.umd.js"></script> | ||
@@ -837,5 +837,5 @@ <!-- Usage --> | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.2/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.1/plugins/error-cache.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.2/plugins/error-cache.umd.js"></script> | ||
@@ -853,6 +853,6 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.5.2/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://unpkg.com/xior@0.5.1/plugins/error-cache.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.5.2/plugins/error-cache.umd.js"></script> | ||
@@ -1002,5 +1002,5 @@ <!-- Usage --> | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.2/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.1/plugins/progress.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.2/plugins/progress.umd.js"></script> | ||
@@ -1018,6 +1018,6 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.5.2/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://unpkg.com/xior@0.5.1/plugins/progress.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.5.2/plugins/progress.umd.js"></script> | ||
@@ -1129,5 +1129,5 @@ <!-- Usage --> | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.2/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.1/plugins/mock.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.5.2/plugins/mock.umd.js"></script> | ||
@@ -1145,6 +1145,6 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.5.1/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.5.2/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://unpkg.com/xior@0.5.1/plugins/mock.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.5.2/plugins/mock.umd.js"></script> | ||
@@ -1151,0 +1151,0 @@ <!-- Usage --> |
@@ -67,3 +67,7 @@ export { merge } from 'ts-deepmerge'; | ||
declare function encodeParams<T = any>(params: T, encodeURI?: boolean, parentKey?: string | null): string; | ||
declare function encodeParams<T = any>(params: T, encodeURI?: boolean, parentKey?: string | null, options?: { | ||
allowDots?: boolean; | ||
serializeDate?: (value: Date) => string; | ||
arrayFormat?: 'indices' | 'repeat' | 'brackets'; | ||
}): string; | ||
declare function trimUndefined(obj: any): any; | ||
@@ -70,0 +74,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)})}let o=void 0;function n(e,r=!0,t=null){if(e===o||null===e)return"";let i=[],s=r?encodeURIComponent:e=>e;for(let l in e)if(Object.prototype.hasOwnProperty.call(e,l)){let u=e[l];if(u!==o){let e=t?`${t}[${s(l)}]`:s(l);if("object"==typeof u){let t=n(u,r,e);""!==t&&i.push(t)}else Array.isArray(u)?u.forEach((r,t)=>{let o=`${e}[${t}]`;i.push(`${s(o)}=${s(r)}`)}):i.push(`${s(e)}=${s(u)}`)}}return i.join("&")}function i(e){return Array.isArray(e)?e.map(i):(e&&"object"==typeof e&&Object.keys(e).forEach(r=>{let t=e[r];if(t!==o)return i(t);delete e[r]}),e)}function s(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function l(e,r){return r?(e.endsWith("/")?e:e+"/")+("/"===r[0]?r.slice(1):r):e}class u extends Error{constructor(e,r,t){super(e),this.name="XiorError",this.request=r,this.config=r,this.response=t}}class a extends u{constructor(e,r,t){super(e),this.name="XiorTimeoutError",this.request=r,this.config=r,this.response=t}}function c(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name}export{u as XiorError,a as XiorTimeoutError,e as anySignal,r as buildSortedURL,t as delay,n as encodeParams,s as isAbsoluteURL,c as isXiorError,l as joinPath,i as trimUndefined}; | ||
export{merge}from"ts-deepmerge";function e(e,r){let t=new globalThis.AbortController;function n(e){t.abort(e),i()}let o=[];for(let r of e){if((null==r?void 0:r.aborted)===!0){n(r.reason);break}if((null==r?void 0:r.addEventListener)!=null){let e=()=>{n(r.reason)};o.push(()=>{(null==r?void 0:r.removeEventListener)!=null&&r.removeEventListener("abort",e)}),r.addEventListener("abort",e)}}function i(){o.forEach(e=>{e()}),null==r||r()}let l=t.signal;return l.clear=i,l}function r(e,r,t){let n=r?t(r):"";n&&(n=e+(e.includes("?")?"&":"?")+n);let[o,i]=n.split("?");if(i){let e=i.split("&");return`${o}?${e.sort().join("&")}`}return n||e}function t(e){return new Promise(r=>{setTimeout(()=>{r("ok")},e)})}let n=void 0;function o(e,r=!0,t=null,l){if(e===n||null===e)return"";let s=[],u=r?encodeURIComponent:e=>e,a=Array.isArray(e);for(let f in e)if(Object.prototype.hasOwnProperty.call(e,f)){let c=e[f];if(c!==n){let e=i(t,f,a,null==l?void 0:l.arrayFormat,null==l?void 0:l.allowDots);if(c instanceof Date&&(c=(null==l?void 0:l.serializeDate)?null==l?void 0:l.serializeDate(c):c.toISOString()),"object"==typeof c){let t=o(c,r,e,l);""!==t&&s.push(t)}else s.push(`${u(e)}=${u(c)}`)}}return s.join("&")}let i=(e,r,t,n,o)=>e?`${e}${(e=>{if(o&&!t)return`.${e}`;if(t){if("brackets"===n)return"[]";if("repeat"===n)return""}return`[${e}]`})(r)}`:r;function l(e){return Array.isArray(e)?e.map(l):(e&&"object"==typeof e&&Object.keys(e).forEach(r=>{let t=e[r];if(t!==n)return l(t);delete e[r]}),e)}function s(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function u(e,r){return r?(e.endsWith("/")?e:e+"/")+("/"===r[0]?r.slice(1):r):e}class a extends Error{constructor(e,r,t){super(e),this.name="XiorError",this.request=r,this.config=r,this.response=t}}class f extends a{constructor(e,r,t){super(e),this.name="XiorTimeoutError",this.request=r,this.config=r,this.response=t}}function c(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name}export{a as XiorError,f as XiorTimeoutError,e as anySignal,r as buildSortedURL,t as delay,o as encodeParams,s as isAbsoluteURL,c as isXiorError,u as joinPath,l as trimUndefined}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
254975
1532