xior
Version:
A lite http request lib based on fetch with plugins support and similar API to axios.
1 lines • 5.95 kB
JavaScript
!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,(function(){return function(){"use strict";var e={91: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{a(r.next(e))}catch(e){i(e)}}function s(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,s)}a((r=r.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.inflight=void 0,t.default=function(e={}){const{enableDedupe:n,onDedupe:u}=e;return function(e){return s=>r(this,void 0,void 0,(function*(){var r,a;const{paramsSerializer:l,enableDedupe:c=n,onDedupe:f=u}=s,d=s.method===o.GET||s.isGet,p=typeof c,h=p===o.f;let y=o.undefinedValue;if(h&&(y=c(s)),y===o.undefinedValue&&(y=h||p===`${o.undefinedValue}`?d:Boolean(c)),!y)return e(s);const v=(0,i.buildSortedURL)(s.url&&(0,i.isAbsoluteURL)(s.url)?s.url:(0,i.joinPath)(s.baseURL,s.url),{a:s.data,b:s.params},l);if(t.inflight.has(v))return f&&f(s),new Promise(((e,n)=>{var r;null===(r=t.inflight.get(v))||void 0===r||r.push([e,n])}));t.inflight.set(v,[]);try{const n=yield e(s);return null===(r=t.inflight.get(v))||void 0===r||r.forEach((([e])=>e(n))),t.inflight.delete(v),n}catch(e){throw null===(a=t.inflight.get(v))||void 0===a||a.forEach((([,t])=>t(e))),t.inflight.delete(v),e}}))}};const o=n(330),i=n(976);t.inflight=new Map},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.buildSortedURL=void 0,t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t(1)}),e)}))};const o=r(n(629));t.buildSortedURL=o.default},330:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.DELETE=t.PATCH=t.PUT=t.POST=t.OPTIONS=t.GET=t.HEAD=t.m=t.isArray=t.keys=t.op=t.nullValue=t.undefinedValue=t.O=t.h=t.status=t.addEventListener=t.qs=t.abort=t.json=t.text=t.p=t.f=t.o=void 0,t.o="object",t.f="function",t.p="prototype",t.text="text",t.json="json",t.abort="abort",t.qs="paramsSerializer",t.addEventListener="addEventListener",t.status="status",t.h="headers",t.O=Object,t.undefinedValue=void 0,t.nullValue=null,t.op=t.O[t.p],t.keys=t.O.keys,t.isArray=Array.isArray,t.m="method",t.HEAD="HEAD",t.GET="GET",t.OPTIONS="OPTIONS",t.POST="POST",t.PUT="PUT",t.PATCH="PATCH",t.DELETE="DELETE"},629:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,n){const r=t?n(t):"",o=e.includes("?")?"&":"?",i=r?`${e}${o}${r}`:e,[u,s]=i.split("?");if(!s)return i;return`${u}?${s.split("&").sort().join("&")}`}},699:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.anySignal=function(e,t){const n=new AbortController;function o(e){n.abort(e),u()}const i=[];for(const t of e){if(!0===(null==t?void 0:t.aborted)){o(t.reason);break}if(null==t?void 0:t[r.addEventListener]){const e=()=>{o(t.reason)};i.push((()=>{var n;null===(n=t.removeEventListener)||void 0===n||n.call(t,r.abort,e)})),t[r.addEventListener](r.abort,e)}}function u(){i.forEach((e=>e())),null==t||t()}const s=n.signal;return s.clear=u,s};const r=n(330)},729:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.merge=void 0;const r=n(330),o=r.O.getPrototypeOf,i=e=>{if(e!==r.nullValue&&typeof e===r.o){if(typeof o===r.f){const t=o(e);return t===r.op||t===r.nullValue}return r.op.toString.call(e)===`[${r.o} Object]`}return!1};t.merge=(...e)=>e.reduce(((e,n)=>{if((0,r.isArray)(n))throw new TypeError(`Arguments must be ${r.o}s, not arrays.`);return(0,r.keys)(n).forEach((o=>{["__proto__","constructor",r.p].includes(o)||((0,r.isArray)(e[o])&&(0,r.isArray)(n[o])?e[o]=Array.from(new Set(e[o].concat(n[o]))):i(e[o])&&i(n[o])?e[o]=(0,t.merge)(e[o],n[o]):e[o]=n[o])})),e}),{})},976:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.XiorTimeoutError=t.XiorError=void 0,t.encodeParams=function e(t,n=!0,r=i.nullValue,o){if(t===i.undefinedValue||t===i.nullValue)return"";const u=[],s=n?encodeURIComponent:e=>e,a=(0,i.isArray)(t),{arrayFormat:l,allowDots:c,serializeDate:f}=o||{},d=e=>{if(c&&!a)return`.${e}`;if(a){if("brackets"===l)return"[]";if("repeat"===l)return""}return`[${e}]`};for(const a in t)if(i.op.hasOwnProperty.call(t,a)){let l=t[a];if(l!==i.undefinedValue){const t=r?`${r}${d(a)}`:s(a);if(!isNaN(l)&&l instanceof Date&&(l=f?f(l):l.toISOString()),typeof l===i.o){const r=e(l,n,t,o);""!==r&&u.push(r)}else u.push(`${s(t)}=${s(l)}`)}}return u.join("&")},t.trimUndefined=function e(t){return(0,i.isArray)(t)?t.map(e):(t&&typeof t===i.o&&(0,i.keys)(t).forEach((n=>{const r=t[n];r===i.undefinedValue?delete t[n]:e(r)})),t)},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},t.joinPath=function(e,t){return e?t?(e.endsWith("/")?e:e+"/")+("/"===t[0]?t.slice(1):t):e:t||""},t.isXiorError=function(e){return(null==e?void 0:e.name)===u||(null==e?void 0:e.name)===s};const i=n(330);o(n(699),t),o(n(729),t),o(n(99),t);const u="XiorError",s="XiorTimeoutError";class a extends Error{constructor(e,t,n){super(e),this.name=u,this.request=t,this.config=t,this.response=n}}t.XiorError=a,t.XiorTimeoutError=class extends a{constructor(e,t,n){super(e,t,n),this.name=s}}}},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}(91);return n.default}()}));