mirror of
https://github.com/godotengine/issue-stats.git
synced 2026-01-01 01:48:12 +03:00
9 lines
7.1 KiB
JavaScript
9 lines
7.1 KiB
JavaScript
/**
|
|
* Minified by jsDelivr using Terser v3.14.1.
|
|
* Original file: /npm/ky@0.21.0/umd.js
|
|
*
|
|
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
|
*/
|
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).ky=e()}(this,function(){"use strict";const t={},e=t=>"undefined"!=typeof self&&self&&t in self?self:"undefined"!=typeof window&&window&&t in window?window:"undefined"!=typeof global&&global&&t in global?global:"undefined"!=typeof globalThis&&globalThis?globalThis:void 0,s=["Headers","Request","Response","ReadableStream","fetch","AbortController","FormData"];for(const o of s)Object.defineProperty(t,o,{get(){const t=e(o),s=t&&t[o];return"function"==typeof s?s.bind(t):s}});const o=t=>null!==t&&"object"==typeof t,r="function"==typeof t.AbortController,n="function"==typeof t.ReadableStream,i="function"==typeof t.FormData,a=(e,s)=>{const o=new t.Headers(e),r=s instanceof t.Headers,n=new t.Headers(s);for(const[t,e]of n)r&&"undefined"===e||void 0===e?o.delete(t):o.set(t,e);return o},h=(...t)=>{let e={},s={};for(const r of t){if(Array.isArray(r))Array.isArray(e)||(e=[]),e=[...e,...r];else if(o(r)){for(let[t,s]of Object.entries(r))o(s)&&Reflect.has(e,t)&&(s=h(e[t],s)),e={...e,[t]:s};o(r.headers)&&(s=a(s,r.headers))}e.headers=s}return e},u=["get","post","put","patch","head","delete"],p={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},f=[413,429,503],c=Symbol("stop");class d extends Error{constructor(t){super(t.statusText||String(0===t.status||t.status?t.status:"Unknown response error")),this.name="HTTPError",this.response=t}}class l extends Error{constructor(t){super("Request timed out"),this.name="TimeoutError",this.request=t}}const y=t=>new Promise(e=>setTimeout(e,t)),m=(e,s,o)=>new Promise((r,n)=>{const i=setTimeout(()=>{o&&o.abort(),n(new l(e))},s);t.fetch(e).then(r).catch(n).then(()=>{clearTimeout(i)})}),_=t=>u.includes(t)?t.toUpperCase():t,w={limit:2,methods:["get","put","head","delete","options","trace"],statusCodes:[408,413,429,500,502,503,504],afterStatusCodes:f},b=(t={})=>{if("number"==typeof t)return{...w,limit:t};if(t.methods&&!Array.isArray(t.methods))throw new Error("retry.methods must be an array");if(t.statusCodes&&!Array.isArray(t.statusCodes))throw new Error("retry.statusCodes must be an array");return{...w,...t,afterStatusCodes:f}},g=2147483647;class R{constructor(e,s={}){if(this._retryCount=0,this._input=e,this._options={credentials:this._input.credentials||"same-origin",...s,headers:a(this._input.headers,s.headers),hooks:h({beforeRequest:[],beforeRetry:[],afterResponse:[]},s.hooks),method:_(s.method||this._input.method),prefixUrl:String(s.prefixUrl||""),retry:b(s.retry),throwHttpErrors:!1!==s.throwHttpErrors,timeout:void 0===s.timeout?1e4:s.timeout},"string"!=typeof this._input&&!(this._input instanceof URL||this._input instanceof t.Request))throw new TypeError("`input` must be a string, URL, or Request");if(this._options.prefixUrl&&"string"==typeof this._input){if(this._input.startsWith("/"))throw new Error("`input` must not begin with a slash when using `prefixUrl`");this._options.prefixUrl.endsWith("/")||(this._options.prefixUrl+="/"),this._input=this._options.prefixUrl+this._input}if(r&&(this.abortController=new t.AbortController,this._options.signal&&this._options.signal.addEventListener("abort",()=>{this.abortController.abort()}),this._options.signal=this.abortController.signal),this.request=new t.Request(this._input,this._options),this._options.searchParams){const e=new URL(this.request.url);e.search=new URLSearchParams(this._options.searchParams),!(i&&this._options.body instanceof t.FormData||this._options.body instanceof URLSearchParams)||this._options.headers&&this._options.headers["content-type"]||this.request.headers.delete("content-type"),this.request=new t.Request(new t.Request(e,this.request),this._options)}void 0!==this._options.json&&(this._options.body=JSON.stringify(this._options.json),this.request.headers.set("content-type","application/json"),this.request=new t.Request(this.request,{body:this._options.body}));const o=async()=>{if(this._options.timeout>g)throw new RangeError(`The \`timeout\` option cannot be greater than ${g}`);await y(1);let e=await this._fetch();for(const s of this._options.hooks.afterResponse){const o=await s(this.request,this._options,e.clone());o instanceof t.Response&&(e=o)}if(!e.ok&&this._options.throwHttpErrors)throw new d(e);if(this._options.onDownloadProgress){if("function"!=typeof this._options.onDownloadProgress)throw new TypeError("The `onDownloadProgress` option must be a function");if(!n)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return this._stream(e.clone(),this._options.onDownloadProgress)}return e},u=this._options.retry.methods.includes(this.request.method.toLowerCase())?this._retry(o):o();for(const[t,e]of Object.entries(p))u[t]=(async()=>{this.request.headers.set("accept",this.request.headers.get("accept")||e);const s=(await u).clone();return"json"===t&&204===s.status?"":s[t]()});return u}_calculateRetryDelay(t){if(this._retryCount++,this._retryCount<this._options.retry.limit&&!(t instanceof l)){if(t instanceof d){if(!this._options.retry.statusCodes.includes(t.response.status))return 0;const e=t.response.headers.get("Retry-After");if(e&&this._options.retry.afterStatusCodes.includes(t.response.status)){let t=Number(e);return Number.isNaN(t)?t=Date.parse(e)-Date.now():t*=1e3,void 0!==this._options.retry.maxRetryAfter&&t>this._options.retry.maxRetryAfter?0:t}if(413===t.response.status)return 0}return.3*2**(this._retryCount-1)*1e3}return 0}async _retry(t){try{return await t()}catch(e){const s=Math.min(this._calculateRetryDelay(e),g);if(0!==s&&this._retryCount>0){await y(s);for(const t of this._options.hooks.beforeRetry){if(await t({request:this.request,options:this._options,error:e,response:e.response.clone(),retryCount:this._retryCount})===c)return}return this._retry(t)}if(this._options.throwHttpErrors)throw e}}async _fetch(){for(const t of this._options.hooks.beforeRequest){const e=await t(this.request,this._options);if(e instanceof Request){this.request=e;break}if(e instanceof Response)return e}return!1===this._options.timeout?t.fetch(this.request.clone()):m(this.request.clone(),this._options.timeout,this.abortController)}_stream(e,s){const o=Number(e.headers.get("content-length"))||0;let r=0;return new t.Response(new t.ReadableStream({start(t){const n=e.body.getReader();s&&s({percent:0,transferredBytes:0,totalBytes:o},new Uint8Array),async function e(){const{done:i,value:a}=await n.read();i?t.close():(s&&(r+=a.byteLength,s({percent:0===o?0:r/o,transferredBytes:r,totalBytes:o},a)),t.enqueue(a),e())}()}}))}}const q=(...t)=>{for(const e of t)if((!o(e)||Array.isArray(e))&&void 0!==e)throw new TypeError("The `options` argument must be an object");return h({},...t)},C=t=>{const e=(e,s)=>new R(e,q(t,s));for(const s of u)e[s]=((e,o)=>new R(e,q(t,o,{method:s})));return e.HTTPError=d,e.TimeoutError=l,e.create=(t=>C(q(t))),e.extend=(e=>C(q(t,e))),e.stop=c,e};return C()});
|
|
//# sourceMappingURL=/sm/6d13e45656994bb662018695e24cc4e461ffca349766163d679967708e99ff74.map
|