Comparing version 0.2.4 to 0.2.5
@@ -1,1 +0,1 @@ | ||
import{merge as e}from"ts-deepmerge";export{merge}from"ts-deepmerge";function t(e,t){let r=new globalThis.AbortController;function n(e){r.abort(e),o()}let s=[];for(let t of e){if((null==t?void 0:t.aborted)===!0){n(t.reason);break}if((null==t?void 0:t.addEventListener)!=null){let e=()=>{n(t.reason)};s.push(()=>{(null==t?void 0:t.removeEventListener)!=null&&t.removeEventListener("abort",e)}),t.addEventListener("abort",e)}}function o(){s.forEach(e=>{e()}),null==t||t()}let i=r.signal;return i.clear=o,i}function r(e,t,r){let n=t?r(t):"";n&&(n=e+(e.includes("?")?"&"+n:"?"+n));let[s,o]=n.split("?");if(o){let e=o.split("&");return`${s}?${e.sort().join("&")}`}return n||e}function n(e){return new Promise(t=>{setTimeout(()=>{t("ok")},e)})}function s(e,t=!0,r=null){if(null==e)return"";let n=[],o=t?encodeURIComponent:e=>e;for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let a=e[i],l=r?`${r}[${o(i)}]`:o(i);if("object"==typeof a){let e=s(a,t,l);""!==e&&n.push(e)}else Array.isArray(a)?a.forEach((e,t)=>{let r=`${l}[${t}]`;n.push(`${o(r)}=${o(e)}`)}):n.push(`${o(l)}=${o(a)}`)}return n.join("&")}function o(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function i(e,t){return t?(e.endsWith("/")?e:e+"/")+(t.startsWith("/")?t.slice(1):t):e}class a extends Error{constructor(e,t,r){super(e),this.name="XiorError",this.request=t,this.config=t,this.response=r}}class l extends a{constructor(e,t,r){super(e),this.name="XiorTimeoutError",this.request=t,this.config=t,this.response=r}}function u(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name}function c(e,t,r,n,s,o,i){try{var a=e[o](i),l=a.value}catch(e){r(e);return}a.done?t(l):Promise.resolve(l).then(n,s)}function p(){return(p=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 h="application/x-www-form-urlencoded",d="application/json";function f(e="GET"){return["HEAD","GET","DELETE","OPTIONS"].includes(e)}function m(e){return v.apply(this,arguments)}function v(){var t;return t=function*(t){let r=t.encode||t.paramsSerializer||s,n=!1!==t.encodeURI,o=t.method?t.method.toUpperCase():"GET",i=t.url||"",a=i,l=t.data,u=l,c=!1,m=(null==t?void 0:t.headers)||{};if(l&&!(l instanceof FormData)){let s="";if(null==t?void 0:t.headers){let e=Object.keys(t.headers).find(e=>"content-type"===e.toLowerCase());e&&(s=t.headers[e])}if(s||(s=f(o)?h:d,m["Content-Type"]=s),s===h&&("object"==typeof l||t.params)){c=!0;let s=r(e(l||{},t.params||{}),n);s&&(i+=i.includes("?")?`&${s}`:`?${s}`)}else s===d&&(u=JSON.stringify(l))}return!c&&t.params&&Object.keys(t.params).length>0&&(i+=i.includes("?")?`&${r(t.params,n)}`:`?${r(t.params,n)}`),p({},t,{data:l,_data:u,url:a,_url:i,method:o,headers:m,encode:r,paramsSerializer:r})},(v=function(){var e=this,r=arguments;return new Promise(function(n,s){var o=t.apply(e,r);function i(e){c(o,n,s,i,a,"next",e)}function a(e){c(o,n,s,i,a,"throw",e)}i(void 0)})}).apply(this,arguments)}function y(e,t,r,n,s,o,i){try{var a=e[o](i),l=a.value}catch(e){r(e);return}a.done?t(l):Promise.resolve(l).then(n,s)}function g(e){return function(){var t=this,r=arguments;return new Promise(function(n,s){var o=e.apply(t,r);function i(e){y(o,n,s,i,a,"next",e)}function a(e){y(o,n,s,i,a,"throw",e)}i(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 b="undefined"!=typeof AbortController;class O{static create(e){return new O(e)}get interceptors(){return{request:{use:(e,t)=>(this.requestInterceptors.push(e),e),eject:e=>{this.requestInterceptors=this.requestInterceptors.filter(t=>t!==e)},clear:()=>{this.requestInterceptors=[this.requestInterceptors[0]]}},response:{use:(e,t)=>(this.responseInterceptors.push({fn:e,onRejected:t}),e),eject:e=>{this.responseInterceptors=this.responseInterceptors.filter(t=>t.fn!==e)},clear:()=>{this.responseInterceptors=[]}}}}get plugins(){return{use:e=>(this._plugins.push(e),e),eject:e=>{this._plugins=this._plugins.filter(t=>t!==e)},clear:()=>{this._plugins=[]}}}request(t){var r=this;return g(function*(){let n=e({},r.config||{},r.defaults||{},"string"==typeof t?{url:t}:t||{},{headers:{},params:{}});for(let e of r.requestInterceptors)n=yield e(n);let s=r.handlerFetch.bind(r);return r._plugins.forEach(e=>{s=e(s)}),s(n)})()}handlerFetch(e){var r=this;return g(function*(){var n,s;let u,c;let{url:p,method:h,headers:d,timeout:m,signal:v,data:y,_data:g}=e,O=function(e,t){if(null==e)return{};var r,n,s={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(s[r]=e[r]);return s}(e,["url","method","headers","timeout","signal","data","_data"]),j=[];if(m&&b){let t=new AbortController;c=setTimeout(()=>{t.abort(new l(`timeout of ${m}ms exceeded`,e))},m),j.push(t.signal)}v&&j.push(v),u=j[0],j.length>1&&(u=t(j,()=>{clearTimeout(c)}));let T=e._url||p||"";e.baseURL&&!o(T)&&(T=i(e.baseURL,T));let I=yield fetch(T,E({body:f(e.method)?void 0:g},O,{signal:u,method:h,headers:d}));c&&clearTimeout(c),null==u||null==(n=u.clear)||n.call(u);let w={response:I,config:e,status:I.status,statusText:I.statusText,headers:I.headers};if(!I.ok){let t;try{(t=yield I.text())&&(t=JSON.parse(t))}catch(e){}let n=new a(I.status?`Request failed with status code ${I.status}`:"Network error",e,E({data:t},w));for(let e of r.responseInterceptors)if(e.onRejected){let t=yield e.onRejected(n);if(null==t?void 0:null==(s=t.response)?void 0:s.ok)return t}throw n}if("HEAD"===e.method)return E({data:void 0,request:e},w);let{responseType:P}=e;if(!P||"json"===P||"text"===P){let t;try{(t=yield I.text())&&"text"!==P&&(t=JSON.parse(t))}catch(e){}let n={data:t,request:e,response:I};for(let e of r.responseInterceptors)n=yield e.fn(n);return E({data:n.data,request:e},w)}return E({data:void 0,request:e},w)})()}createGetHandler(e){return(t,r)=>this.request(r?E({},r,{method:e,url:t}):{method:e,url:t})}createPostHandler(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.createGetHandler("GET")(e,t)}head(e,t){return this.createGetHandler("HEAD")(e,t)}post(e,t,r){return this.createPostHandler("POST")(e,t,r)}put(e,t,r){return this.createPostHandler("PUT")(e,t,r)}patch(e,t,r){return this.createPostHandler("PATCH")(e,t,r)}delete(e,t){return this.createGetHandler("DELETE")(e,t)}options(e,t){return this.createGetHandler("OPTIONS")(e,t)}constructor(e){this.requestInterceptors=[m],this.responseInterceptors=[],this._plugins=[],this.config=e,this.defaults={params:{},headers:{}}}}O.VERSION="0.2.4";let j=Object.assign(O.create(),{create:O.create,VERSION:O.VERSION});export{a as XiorError,l as XiorTimeoutError,t as anySignal,r as buildSortedURL,j as default,n as delay,s as encodeParams,o as isAbsoluteURL,u as isXiorError,i as joinPath,O as xior}; | ||
import{merge as e}from"ts-deepmerge";export{merge}from"ts-deepmerge";function t(e,t){let r=new globalThis.AbortController;function n(e){r.abort(e),o()}let s=[];for(let t of e){if((null==t?void 0:t.aborted)===!0){n(t.reason);break}if((null==t?void 0:t.addEventListener)!=null){let e=()=>{n(t.reason)};s.push(()=>{(null==t?void 0:t.removeEventListener)!=null&&t.removeEventListener("abort",e)}),t.addEventListener("abort",e)}}function o(){s.forEach(e=>{e()}),null==t||t()}let i=r.signal;return i.clear=o,i}function r(e,t,r){let n=t?r(t):"";n&&(n=e+(e.includes("?")?"&"+n:"?"+n));let[s,o]=n.split("?");if(o){let e=o.split("&");return`${s}?${e.sort().join("&")}`}return n||e}function n(e){return new Promise(t=>{setTimeout(()=>{t("ok")},e)})}function s(e,t=!0,r=null){if(null==e)return"";let n=[],o=t?encodeURIComponent:e=>e;for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let a=e[i],l=r?`${r}[${o(i)}]`:o(i);if("object"==typeof a){let e=s(a,t,l);""!==e&&n.push(e)}else Array.isArray(a)?a.forEach((e,t)=>{let r=`${l}[${t}]`;n.push(`${o(r)}=${o(e)}`)}):n.push(`${o(l)}=${o(a)}`)}return n.join("&")}function o(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function i(e,t){return t?(e.endsWith("/")?e:e+"/")+(t.startsWith("/")?t.slice(1):t):e}class a extends Error{constructor(e,t,r){super(e),this.name="XiorError",this.request=t,this.config=t,this.response=r}}class l extends a{constructor(e,t,r){super(e),this.name="XiorTimeoutError",this.request=t,this.config=t,this.response=r}}function u(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name}function c(e,t,r,n,s,o,i){try{var a=e[o](i),l=a.value}catch(e){r(e);return}a.done?t(l):Promise.resolve(l).then(n,s)}function p(){return(p=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 h="application/x-www-form-urlencoded",d="application/json";function f(e="GET"){return["HEAD","GET","DELETE","OPTIONS"].includes(e)}function m(e){return v.apply(this,arguments)}function v(){var t;return t=function*(t){let r=t.encode||t.paramsSerializer||s,n=!1!==t.encodeURI,o=t.method?t.method.toUpperCase():"GET",i=t.url||"",a=i,l=t.data,u=l,c=!1,m=(null==t?void 0:t.headers)||{};if(l&&!(l instanceof FormData)){let s="";if(null==t?void 0:t.headers){let e=Object.keys(t.headers).find(e=>"content-type"===e.toLowerCase());e&&(s=t.headers[e])}if(s||(s=f(o)?h:d,m["Content-Type"]=s),s===h&&("object"==typeof l||t.params)){c=!0;let s=r(e(l||{},t.params||{}),n);s&&(i+=i.includes("?")?`&${s}`:`?${s}`)}else s===d&&(u=JSON.stringify(l))}return!c&&t.params&&Object.keys(t.params).length>0&&(i+=i.includes("?")?`&${r(t.params,n)}`:`?${r(t.params,n)}`),p({},t,{data:l,_data:u,url:a,_url:i,method:o,headers:m,encode:r,paramsSerializer:r})},(v=function(){var e=this,r=arguments;return new Promise(function(n,s){var o=t.apply(e,r);function i(e){c(o,n,s,i,a,"next",e)}function a(e){c(o,n,s,i,a,"throw",e)}i(void 0)})}).apply(this,arguments)}function y(e,t,r,n,s,o,i){try{var a=e[o](i),l=a.value}catch(e){r(e);return}a.done?t(l):Promise.resolve(l).then(n,s)}function g(e){return function(){var t=this,r=arguments;return new Promise(function(n,s){var o=e.apply(t,r);function i(e){y(o,n,s,i,a,"next",e)}function a(e){y(o,n,s,i,a,"throw",e)}i(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 b="undefined"!=typeof AbortController;class O{static create(e){return new O(e)}get interceptors(){return{request:{use:(e,t)=>(this.requestInterceptors.push(e),e),eject:e=>{this.requestInterceptors=this.requestInterceptors.filter(t=>t!==e)},clear:()=>{this.requestInterceptors=[this.requestInterceptors[0]]}},response:{use:(e,t)=>(this.responseInterceptors.push({fn:e,onRejected:t}),e),eject:e=>{this.responseInterceptors=this.responseInterceptors.filter(t=>t.fn!==e)},clear:()=>{this.responseInterceptors=[]}}}}get plugins(){return{use:e=>(this._plugins.push(e),e),eject:e=>{this._plugins=this._plugins.filter(t=>t!==e)},clear:()=>{this._plugins=[]}}}request(t){var r=this;return g(function*(){let n=e({},r.config||{},r.defaults||{},"string"==typeof t?{url:t}:t||{},{headers:{},params:{}});for(let e of r.requestInterceptors)n=yield e(n);let s=r.handlerFetch.bind(r);return r._plugins.forEach(e=>{s=e(s)}),s(n)})()}handlerFetch(e){var r=this;return g(function*(){var n,s;let u,c;if(r._plugins.length>0)for(let t of r.requestInterceptors.slice(1))e=yield t(e);let{url:p,method:h,headers:d,timeout:m,signal:v,data:y,_data:g}=e,O=function(e,t){if(null==e)return{};var r,n,s={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(s[r]=e[r]);return s}(e,["url","method","headers","timeout","signal","data","_data"]),j=[];if(m&&b){let t=new AbortController;c=setTimeout(()=>{t.abort(new l(`timeout of ${m}ms exceeded`,e))},m),j.push(t.signal)}v&&j.push(v),u=j[0],j.length>1&&(u=t(j,()=>{clearTimeout(c)}));let I=e._url||p||"";e.baseURL&&!o(I)&&(I=i(e.baseURL,I));let T=yield fetch(I,E({body:f(e.method)?void 0:g},O,{signal:u,method:h,headers:d}));c&&clearTimeout(c),null==u||null==(n=u.clear)||n.call(u);let w={response:T,config:e,status:T.status,statusText:T.statusText,headers:T.headers};if(!T.ok){let t;try{(t=yield T.text())&&(t=JSON.parse(t))}catch(e){}let n=new a(T.status?`Request failed with status code ${T.status}`:"Network error",e,E({data:t},w));for(let e of r.responseInterceptors)if(e.onRejected){let t=yield e.onRejected(n);if(null==t?void 0:null==(s=t.response)?void 0:s.ok)return t}throw n}if("HEAD"===e.method)return E({data:void 0,request:e},w);let{responseType:q}=e;if(!q||"json"===q||"text"===q){let t;try{(t=yield T.text())&&"text"!==q&&(t=JSON.parse(t))}catch(e){}let n={data:t,request:e,response:T};for(let e of r.responseInterceptors)n=yield e.fn(n);return E({data:n.data,request:e},w)}return E({data:void 0,request:e},w)})()}createGetHandler(e){return(t,r)=>this.request(r?E({},r,{method:e,url:t}):{method:e,url:t})}createPostHandler(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.createGetHandler("GET")(e,t)}head(e,t){return this.createGetHandler("HEAD")(e,t)}post(e,t,r){return this.createPostHandler("POST")(e,t,r)}put(e,t,r){return this.createPostHandler("PUT")(e,t,r)}patch(e,t,r){return this.createPostHandler("PATCH")(e,t,r)}delete(e,t){return this.createGetHandler("DELETE")(e,t)}options(e,t){return this.createGetHandler("OPTIONS")(e,t)}constructor(e){this.requestInterceptors=[m],this.responseInterceptors=[],this._plugins=[],this.config=e,this.defaults={params:{},headers:{}}}}O.VERSION="0.2.5";let j=Object.assign(O.create(),{create:O.create,VERSION:O.VERSION});export{a as XiorError,l as XiorTimeoutError,t as anySignal,r as buildSortedURL,j as default,n as delay,s as encodeParams,o as isAbsoluteURL,u as isXiorError,i as joinPath,O as xior}; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.xior=t():e.xior=t()}(this,(()=>(()=>{"use strict";var e={699:(e,t)=>{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),s()}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 s(){o.forEach((e=>{e()})),null==t||t()}const i=r.signal;return i.clear=s,i}},509:function(e,t,r){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 s=r(895);o(r(895),t),o(r(340),t),o(r(976),t);const i=Object.assign(s.xior.create(),{create:s.xior.create,VERSION:s.xior.VERSION});t.default=i},393:function(e,t,r){var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function a(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.likeGET=void 0;const o=r(976),s="application/x-www-form-urlencoded",i="application/json";function a(e="GET"){return["HEAD","GET","DELETE","OPTIONS"].includes(e)}t.likeGET=a,t.default=function(e){return n(this,void 0,void 0,(function*(){const t=e.encode||e.paramsSerializer||o.encodeParams,r=!1!==e.encodeURI,n=e.method?e.method.toUpperCase():"GET";let c=e.url||"";const u=c,l=e.data;let d=l,f=!1;const p=(null==e?void 0:e.headers)||{};if(l&&!(l instanceof FormData)){let u="";if(null==e?void 0:e.headers){const t=Object.keys(e.headers).find((e=>"content-type"===e.toLowerCase()));t&&(u=e.headers[t])}if(u||(u=a(n)?s:i,p["Content-Type"]=u),u!==s||"object"!=typeof l&&!e.params)u===i&&(d=JSON.stringify(l));else{f=!0;const n=t((0,o.merge)(l||{},e.params||{}),r);n&&(c+=c.includes("?")?`&${n}`:`?${n}`)}}return!f&&e.params&&Object.keys(e.params).length>0&&(c+=c.includes("?")?`&${t(e.params,r)}`:`?${t(e.params,r)}`),Object.assign(Object.assign({},e),{data:l,_data:d,url:u,_url:c,method:n,headers:p,encode:t,paramsSerializer:t})}))}},729:(e,t,r)=>{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)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){let n=t?r(t):"";n&&(n=e+(e.includes("?")?"&"+n:"?"+n));const[o,s]=n.split("?");return s?`${o}?${s.split("&").sort().join("&")}`:n||e}},99:function(e,t,r){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)=>{Object.defineProperty(t,"__esModule",{value:!0})},976:function(e,t,r){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.encodeParams=void 0,o(r(699),t),o(r(729),t),o(r(99),t),t.encodeParams=function e(t,r=!0,n=null){if(null==t)return"";const o=[],s=r?encodeURIComponent:e=>e;for(const i in t)if(Object.prototype.hasOwnProperty.call(t,i)){const a=t[i],c=n?`${n}[${s(i)}]`:s(i);if("object"==typeof a){const t=e(a,r,c);""!==t&&o.push(t)}else Array.isArray(a)?a.forEach(((e,t)=>{const r=`${c}[${t}]`;o.push(`${s(r)}=${s(e)}`)})):o.push(`${s(c)}=${s(a)}`)}return o.join("&")},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.startsWith("/")?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){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.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&n(t,e,r);return o(t,e),t},i=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function a(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}c((n=n.apply(e,t||[])).next())}))},a=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};Object.defineProperty(t,"__esModule",{value:!0}),t.xior=void 0;const c=s(r(393)),u=r(976),l="undefined"!=typeof AbortController;class d{static create(e){return new d(e)}constructor(e){this.requestInterceptors=[c.default],this.responseInterceptors=[],this._plugins=[],this.config=e,this.defaults={params:{},headers:{}}}get interceptors(){return{request:{use:(e,t)=>(this.requestInterceptors.push(e),e),eject:e=>{this.requestInterceptors=this.requestInterceptors.filter((t=>t!==e))},clear:()=>{this.requestInterceptors=[this.requestInterceptors[0]]}},response:{use:(e,t)=>(this.responseInterceptors.push({fn:e,onRejected:t}),e),eject:e=>{this.responseInterceptors=this.responseInterceptors.filter((t=>t.fn!==e))},clear:()=>{this.responseInterceptors=[]}}}}get plugins(){return{use:e=>(this._plugins.push(e),e),eject:e=>{this._plugins=this._plugins.filter((t=>t!==e))},clear:()=>{this._plugins=[]}}}request(e){return i(this,void 0,void 0,(function*(){let t=(0,u.merge)({},this.config||{},this.defaults||{},"string"==typeof e?{url:e}:e||{},{headers:{},params:{}});for(const e of this.requestInterceptors)t=yield e(t);let r=this.handlerFetch.bind(this);return this._plugins.forEach((e=>{r=e(r)})),r(t)}))}handlerFetch(e){var t,r;return i(this,void 0,void 0,(function*(){const{url:n,method:o,headers:s,timeout:i,signal:d,data:f,_data:p}=e,h=a(e,["url","method","headers","timeout","signal","data","_data"]);let b;const y=[];let m;if(i&&l){const t=new AbortController;m=setTimeout((()=>{t.abort(new u.XiorTimeoutError(`timeout of ${i}ms exceeded`,e))}),i),y.push(t.signal)}d&&y.push(d),b=y[0],y.length>1&&(b=(0,u.anySignal)(y,(()=>{clearTimeout(m)})));let g=e._url||n||"";e.baseURL&&!(0,u.isAbsoluteURL)(g)&&(g=(0,u.joinPath)(e.baseURL,g));const O=yield fetch(g,Object.assign(Object.assign({body:(0,c.likeGET)(e.method)?void 0:p},h),{signal:b,method:o,headers:s}));m&&clearTimeout(m),null===(t=null==b?void 0:b.clear)||void 0===t||t.call(b);const v={response:O,config:e,status:O.status,statusText:O.statusText,headers:O.headers};if(!O.ok){let t;try{t=yield O.text(),t&&(t=JSON.parse(t))}catch(e){}const n=new u.XiorError(O.status?`Request failed with status code ${O.status}`:"Network error",e,Object.assign({data:t},v));for(const e of this.responseInterceptors)if(e.onRejected){const t=yield e.onRejected(n);if(null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.ok)return t}throw n}if("HEAD"===e.method)return Object.assign({data:void 0,request:e},v);const{responseType:j}=e;if(!j||"json"===j||"text"===j){let t;try{t=yield O.text(),t&&"text"!==j&&(t=JSON.parse(t))}catch(e){}let r={data:t,request:e,response:O};for(const e of this.responseInterceptors)r=yield e.fn(r);return Object.assign({data:r.data,request:e},v)}return Object.assign({data:void 0,request:e},v)}))}createGetHandler(e){return(t,r)=>this.request(r?Object.assign(Object.assign({},r),{method:e,url:t}):{method:e,url:t})}createPostHandler(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.createGetHandler("GET")(e,t)}head(e,t){return this.createGetHandler("HEAD")(e,t)}post(e,t,r){return this.createPostHandler("POST")(e,t,r)}put(e,t,r){return this.createPostHandler("PUT")(e,t,r)}patch(e,t,r){return this.createPostHandler("PATCH")(e,t,r)}delete(e,t){return this.createGetHandler("DELETE")(e,t)}options(e,t){return this.createGetHandler("OPTIONS")(e,t)}}t.xior=d,d.VERSION="0.2.4"},602:(e,t)=>{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}}},t={},r=function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}(509);return r.default})())); | ||
!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,(()=>(()=>{"use strict";var e={699:(e,t)=>{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),s()}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 s(){o.forEach((e=>{e()})),null==t||t()}const i=r.signal;return i.clear=s,i}},509:function(e,t,r){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 s=r(895);o(r(895),t),o(r(340),t),o(r(976),t);const i=Object.assign(s.xior.create(),{create:s.xior.create,VERSION:s.xior.VERSION});t.default=i},393:function(e,t,r){var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function a(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.likeGET=void 0;const o=r(976),s="application/x-www-form-urlencoded",i="application/json";function a(e="GET"){return["HEAD","GET","DELETE","OPTIONS"].includes(e)}t.likeGET=a,t.default=function(e){return n(this,void 0,void 0,(function*(){const t=e.encode||e.paramsSerializer||o.encodeParams,r=!1!==e.encodeURI,n=e.method?e.method.toUpperCase():"GET";let c=e.url||"";const u=c,l=e.data;let d=l,f=!1;const p=(null==e?void 0:e.headers)||{};if(l&&!(l instanceof FormData)){let u="";if(null==e?void 0:e.headers){const t=Object.keys(e.headers).find((e=>"content-type"===e.toLowerCase()));t&&(u=e.headers[t])}if(u||(u=a(n)?s:i,p["Content-Type"]=u),u!==s||"object"!=typeof l&&!e.params)u===i&&(d=JSON.stringify(l));else{f=!0;const n=t((0,o.merge)(l||{},e.params||{}),r);n&&(c+=c.includes("?")?`&${n}`:`?${n}`)}}return!f&&e.params&&Object.keys(e.params).length>0&&(c+=c.includes("?")?`&${t(e.params,r)}`:`?${t(e.params,r)}`),Object.assign(Object.assign({},e),{data:l,_data:d,url:u,_url:c,method:n,headers:p,encode:t,paramsSerializer:t})}))}},729:(e,t,r)=>{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)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){let n=t?r(t):"";n&&(n=e+(e.includes("?")?"&"+n:"?"+n));const[o,s]=n.split("?");return s?`${o}?${s.split("&").sort().join("&")}`:n||e}},99:function(e,t,r){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)=>{Object.defineProperty(t,"__esModule",{value:!0})},976:function(e,t,r){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.encodeParams=void 0,o(r(699),t),o(r(729),t),o(r(99),t),t.encodeParams=function e(t,r=!0,n=null){if(null==t)return"";const o=[],s=r?encodeURIComponent:e=>e;for(const i in t)if(Object.prototype.hasOwnProperty.call(t,i)){const a=t[i],c=n?`${n}[${s(i)}]`:s(i);if("object"==typeof a){const t=e(a,r,c);""!==t&&o.push(t)}else Array.isArray(a)?a.forEach(((e,t)=>{const r=`${c}[${t}]`;o.push(`${s(r)}=${s(e)}`)})):o.push(`${s(c)}=${s(a)}`)}return o.join("&")},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.startsWith("/")?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){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.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&n(t,e,r);return o(t,e),t},i=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function a(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}c((n=n.apply(e,t||[])).next())}))},a=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};Object.defineProperty(t,"__esModule",{value:!0}),t.xior=void 0;const c=s(r(393)),u=r(976),l="undefined"!=typeof AbortController;class d{static create(e){return new d(e)}constructor(e){this.requestInterceptors=[c.default],this.responseInterceptors=[],this._plugins=[],this.config=e,this.defaults={params:{},headers:{}}}get interceptors(){return{request:{use:(e,t)=>(this.requestInterceptors.push(e),e),eject:e=>{this.requestInterceptors=this.requestInterceptors.filter((t=>t!==e))},clear:()=>{this.requestInterceptors=[this.requestInterceptors[0]]}},response:{use:(e,t)=>(this.responseInterceptors.push({fn:e,onRejected:t}),e),eject:e=>{this.responseInterceptors=this.responseInterceptors.filter((t=>t.fn!==e))},clear:()=>{this.responseInterceptors=[]}}}}get plugins(){return{use:e=>(this._plugins.push(e),e),eject:e=>{this._plugins=this._plugins.filter((t=>t!==e))},clear:()=>{this._plugins=[]}}}request(e){return i(this,void 0,void 0,(function*(){let t=(0,u.merge)({},this.config||{},this.defaults||{},"string"==typeof e?{url:e}:e||{},{headers:{},params:{}});for(const e of this.requestInterceptors)t=yield e(t);let r=this.handlerFetch.bind(this);return this._plugins.forEach((e=>{r=e(r)})),r(t)}))}handlerFetch(e){var t,r;return i(this,void 0,void 0,(function*(){if(this._plugins.length>0)for(const t of this.requestInterceptors.slice(1))e=yield t(e);const{url:n,method:o,headers:s,timeout:i,signal:d,data:f,_data:p}=e,h=a(e,["url","method","headers","timeout","signal","data","_data"]);let b;const y=[];let g;if(i&&l){const t=new AbortController;g=setTimeout((()=>{t.abort(new u.XiorTimeoutError(`timeout of ${i}ms exceeded`,e))}),i),y.push(t.signal)}d&&y.push(d),b=y[0],y.length>1&&(b=(0,u.anySignal)(y,(()=>{clearTimeout(g)})));let m=e._url||n||"";e.baseURL&&!(0,u.isAbsoluteURL)(m)&&(m=(0,u.joinPath)(e.baseURL,m));const O=yield fetch(m,Object.assign(Object.assign({body:(0,c.likeGET)(e.method)?void 0:p},h),{signal:b,method:o,headers:s}));g&&clearTimeout(g),null===(t=null==b?void 0:b.clear)||void 0===t||t.call(b);const v={response:O,config:e,status:O.status,statusText:O.statusText,headers:O.headers};if(!O.ok){let t;try{t=yield O.text(),t&&(t=JSON.parse(t))}catch(e){}const n=new u.XiorError(O.status?`Request failed with status code ${O.status}`:"Network error",e,Object.assign({data:t},v));for(const e of this.responseInterceptors)if(e.onRejected){const t=yield e.onRejected(n);if(null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.ok)return t}throw n}if("HEAD"===e.method)return Object.assign({data:void 0,request:e},v);const{responseType:j}=e;if(!j||"json"===j||"text"===j){let t;try{t=yield O.text(),t&&"text"!==j&&(t=JSON.parse(t))}catch(e){}let r={data:t,request:e,response:O};for(const e of this.responseInterceptors)r=yield e.fn(r);return Object.assign({data:r.data,request:e},v)}return Object.assign({data:void 0,request:e},v)}))}createGetHandler(e){return(t,r)=>this.request(r?Object.assign(Object.assign({},r),{method:e,url:t}):{method:e,url:t})}createPostHandler(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.createGetHandler("GET")(e,t)}head(e,t){return this.createGetHandler("HEAD")(e,t)}post(e,t,r){return this.createPostHandler("POST")(e,t,r)}put(e,t,r){return this.createPostHandler("PUT")(e,t,r)}patch(e,t,r){return this.createPostHandler("PATCH")(e,t,r)}delete(e,t){return this.createGetHandler("DELETE")(e,t)}options(e,t){return this.createGetHandler("OPTIONS")(e,t)}}t.xior=d,d.VERSION="0.2.5"},602:(e,t)=>{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}}},t={},r=function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}(509);return r.default})())); |
@@ -64,4 +64,4 @@ [Go back](./README.md) | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/plugins/mock.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/plugins/mock.umd.js"></script> | ||
@@ -83,4 +83,4 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.2/plugins/mock.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/plugins/mock.umd.js"></script> | ||
@@ -87,0 +87,0 @@ <!-- Usage --> |
{ | ||
"name": "xior", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "A lite request lib based on fetch with plugins support, and axios similar API", | ||
@@ -5,0 +5,0 @@ "repository": "suhaotian/xior", |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.xiorErrorRetry=t():e.xiorErrorRetry=t()}(this,(()=>(()=>{"use strict";var e={629:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,n){let r=t?n(t):"";r&&(r=e+(e.includes("?")?"&"+r:"?"+r));const[o,i]=r.split("?");return i?`${o}?${i.split("&").sort().join("&")}`:r||e}},351:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{f(r.next(e))}catch(e){i(e)}}function c(e){try{f(r.throw(e))}catch(e){i(e)}}function f(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}f((r=r.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const o=n(99);t.default=function(e={}){const{retryTimes:t,retryInterval:n,enableRetry:i,onRetry:u}=e||{retryTimes:2,retryInterval:3e3};return function(e){return c=>r(this,void 0,void 0,(function*(){const{retryTimes:f=t,retryInterval:s=n,enableRetry:d=i,onRetry:l=u}=c;let a=!1,y=0;return function t(){return r(this,void 0,void 0,(function*(){try{return yield e(c)}catch(e){const n="GET"===c.method||c.isGet,r=typeof d,i="undefined"===r?n:"function"===r?d(c,e):Boolean(d);if(a=f===y,a||!i)throw e;const u="function"==typeof s?s(y):s;return u&&u>0&&y>0&&(yield(0,o.delay)(u)),y++,l&&l(c,e,y),t()}}))}()}))}}},99:function(e,t,n){var r=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=r(n(629));t.buildSortedURL=o.default,t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t("ok")}),e)}))}}},t={},n=function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}(351);return n.default})())); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.xiorErrorRetry=t():e.xiorErrorRetry=t()}(this,(()=>(()=>{"use strict";var e={629:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,n){let r=t?n(t):"";r&&(r=e+(e.includes("?")?"&"+r:"?"+r));const[o,i]=r.split("?");return i?`${o}?${i.split("&").sort().join("&")}`:r||e}},351:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{f(r.next(e))}catch(e){i(e)}}function c(e){try{f(r.throw(e))}catch(e){i(e)}}function f(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}f((r=r.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const o=n(99);t.default=function(e={}){const{retryTimes:t,retryInterval:n,enableRetry:i,onRetry:u}=Object.assign({retryTimes:2,retryInterval:3e3},e||{});return function(e){return c=>r(this,void 0,void 0,(function*(){const{retryTimes:f=t,retryInterval:s=n,enableRetry:d=i,onRetry:l=u}=c;let a=!1,y=0;return function t(){return r(this,void 0,void 0,(function*(){try{return yield e(c)}catch(e){const n="GET"===c.method||c.isGet,r=typeof d,i="undefined"===r?n:"function"===r?d(c,e):Boolean(d);if(a=f===y,a||!i)throw e;const u="function"==typeof s?s(y):s;return u&&u>0&&y>0&&(yield(0,o.delay)(u)),y++,l&&l(c,e,y),t()}}))}()}))}}},99:function(e,t,n){var r=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=r(n(629));t.buildSortedURL=o.default,t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t("ok")}),e)}))}}},t={},n=function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}(351);return n.default})())); |
@@ -1,1 +0,1 @@ | ||
function t(t,e,n,r,i,o,u){try{var f=t[o](u),c=f.value}catch(t){n(t);return}f.done?e(c):Promise.resolve(c).then(r,i)}function e(e){return function(){var n=this,r=arguments;return new Promise(function(i,o){var u=e.apply(n,r);function f(e){t(u,i,o,f,c,"next",e)}function c(e){t(u,i,o,f,c,"throw",e)}f(void 0)})}}function n(t={}){let{retryTimes:n,retryInterval:r,enableRetry:i,onRetry:o}=t||{retryTimes:2,retryInterval:3e3};return function(t){return e(function*(u){let{retryTimes:f=n,retryInterval:c=r,enableRetry:l=i,onRetry:y=o}=u,a=0;function s(){return h.apply(this,arguments)}function h(){return(h=e(function*(){try{return yield t(u)}catch(i){let t="GET"===u.method||u.isGet,e=typeof l,n="undefined"===e?t:"function"===e?l(u,i):!!l;if(f===a||!n)throw i;let r="function"==typeof c?c(a):c;return r&&r>0&&a>0&&(yield new Promise(t=>{setTimeout(()=>{t("ok")},r)})),a++,y&&y(u,i,a),s()}})).apply(this,arguments)}return s()})}}export{n as default}; | ||
function t(t,r,n,e,o,i,u){try{var c=t[i](u),f=c.value}catch(t){n(t);return}c.done?r(f):Promise.resolve(f).then(e,o)}function r(r){return function(){var n=this,e=arguments;return new Promise(function(o,i){var u=r.apply(n,e);function c(r){t(u,o,i,c,f,"next",r)}function f(r){t(u,o,i,c,f,"throw",r)}c(void 0)})}}function n(){return(n=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 e(t={}){let{retryTimes:e,retryInterval:o,enableRetry:i,onRetry:u}=n({},{retryTimes:2,retryInterval:3e3},t||{});return function(t){return r(function*(n){let{retryTimes:c=e,retryInterval:f=o,enableRetry:a=i,onRetry:l=u}=n,y=0;function s(){return p.apply(this,arguments)}function p(){return(p=r(function*(){try{return yield t(n)}catch(i){let t="GET"===n.method||n.isGet,r=typeof a,e="undefined"===r?t:"function"===r?a(n,i):!!a;if(c===y||!e)throw i;let o="function"==typeof f?f(y):f;return o&&o>0&&y>0&&(yield new Promise(t=>{setTimeout(()=>{t("ok")},o)})),y++,l&&l(n,i,y),s()}})).apply(this,arguments)}return s()})}}export{e as default}; |
@@ -119,3 +119,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.2.2/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/dist/xior.umd.js"></script> | ||
@@ -135,3 +135,3 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/dist/xior.umd.js"></script> | ||
@@ -447,5 +447,5 @@ <!-- Usage --> | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/plugins/error-retry.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/plugins/error-retry.umd.js"></script> | ||
@@ -463,6 +463,6 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://unpkg.com/xior@0.2.2/plugins/error-retry.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/plugins/error-retry.umd.js"></script> | ||
@@ -550,5 +550,5 @@ <!-- Usage --> | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/plugins/throttle.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/plugins/throttle.umd.js"></script> | ||
@@ -566,6 +566,6 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://unpkg.com/xior@0.2.2/plugins/throttle.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/plugins/throttle.umd.js"></script> | ||
@@ -618,5 +618,5 @@ <!-- Usage --> | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/plugins/dedupe.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/plugins/dedupe.umd.js"></script> | ||
@@ -634,6 +634,6 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://unpkg.com/xior@0.2.2/plugins/dedupe.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/plugins/dedupe.umd.js"></script> | ||
@@ -696,5 +696,5 @@ <!-- Usage --> | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/plugins/error-cache.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/plugins/error-cache.umd.js"></script> | ||
@@ -712,6 +712,6 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://unpkg.com/xior@0.2.2/plugins/error-cache.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/plugins/error-cache.umd.js"></script> | ||
@@ -851,5 +851,5 @@ <!-- Usage --> | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/plugins/progress.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/plugins/progress.umd.js"></script> | ||
@@ -867,6 +867,6 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://unpkg.com/xior@0.2.2/plugins/progress.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/plugins/progress.umd.js"></script> | ||
@@ -978,5 +978,5 @@ <!-- Usage --> | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.2/plugins/mock.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/xior@0.2.5/plugins/mock.umd.js"></script> | ||
@@ -994,6 +994,6 @@ <!-- Usage --> | ||
```html | ||
<script src="https://unpkg.com/xior@0.2.2/dist/xior.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/dist/xior.umd.js"></script> | ||
<!-- Load plugin --> | ||
<script src="https://unpkg.com/xior@0.2.2/plugins/mock.umd.js"></script> | ||
<script src="https://unpkg.com/xior@0.2.5/plugins/mock.umd.js"></script> | ||
@@ -1000,0 +1000,0 @@ <!-- Usage --> |
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
285976
1905