🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

ky

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ky - npm Package Compare versions

Comparing version
1.1.0
to
1.1.1
+1
distribution/utils/options.d.ts
export declare const findUnknownOptions: (request: Request, options: Record<string, unknown>) => Record<string, unknown>;
import { kyOptionKeys } from '../core/constants.js';
export const findUnknownOptions = (request, options) => {
const unknownOptions = {};
for (const key in options) {
if (!(key in kyOptionKeys) && !(key in request)) {
unknownOptions[key] = options[key];
}
}
return unknownOptions;
};
//# sourceMappingURL=options.js.map
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../source/utils/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAElD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CACjC,OAAgB,EAChB,OAAgC,EACN,EAAE;IAC5B,MAAM,cAAc,GAA4B,EAAE,CAAC;IAEnD,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;QAC1B,IAAI,CAAC,CAAC,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,OAAO,CAAC,EAAE;YAChD,cAAc,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;SACnC;KACD;IAED,OAAO,cAAc,CAAC;AACvB,CAAC,CAAC","sourcesContent":["import {kyOptionKeys} from '../core/constants.js';\n\nexport const findUnknownOptions = (\n\trequest: Request,\n\toptions: Record<string, unknown>,\n): Record<string, unknown> => {\n\tconst unknownOptions: Record<string, unknown> = {};\n\n\tfor (const key in options) {\n\t\tif (!(key in kyOptionKeys) && !(key in request)) {\n\t\t\tunknownOptions[key] = options[key];\n\t\t}\n\t}\n\n\treturn unknownOptions;\n};\n"]}
+2
-0

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

import { type KyOptionsRegistry } from '../types/options.js';
export declare const supportsRequestStreams: boolean;

@@ -15,1 +16,2 @@ export declare const supportsAbortController: boolean;

export declare const stop: unique symbol;
export declare const kyOptionKeys: KyOptionsRegistry;

@@ -35,2 +35,14 @@ export const supportsRequestStreams = (() => {

export const stop = Symbol('stop');
export const kyOptionKeys = {
json: true,
parseJson: true,
searchParams: true,
prefixUrl: true,
retry: true,
timeout: true,
hooks: true,
throwHttpErrors: true,
onDownloadProgress: true,
fetch: true,
};
//# sourceMappingURL=constants.js.map
+1
-1

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

{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../source/core/constants.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAG,EAAE;IAC3C,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,MAAM,sBAAsB,GAAG,OAAO,UAAU,CAAC,cAAc,KAAK,UAAU,CAAC;IAC/E,MAAM,eAAe,GAAG,OAAO,UAAU,CAAC,OAAO,KAAK,UAAU,CAAC;IAEjE,IAAI,sBAAsB,IAAI,eAAe,EAAE;QAC9C,cAAc,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,uBAAuB,EAAE;YAChE,IAAI,EAAE,IAAI,UAAU,CAAC,cAAc,EAAE;YACrC,MAAM,EAAE,MAAM;YACd,yCAAyC;YACzC,IAAI,MAAM;gBACT,cAAc,GAAG,IAAI,CAAC;gBACtB,OAAO,MAAM,CAAC;YACf,CAAC;SACD,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;KAC/B;IAED,OAAO,cAAc,IAAI,CAAC,cAAc,CAAC;AAC1C,CAAC,CAAC,EAAE,CAAC;AAEL,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,UAAU,CAAC,eAAe,KAAK,UAAU,CAAC;AACxF,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,UAAU,CAAC,cAAc,KAAK,UAAU,CAAC;AACvF,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,UAAU,CAAC,QAAQ,KAAK,UAAU,CAAC;AAE1E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC;AAEzF,MAAM,QAAQ,GAAG,GAA0B,EAAE,CAAC,SAAyB,CAAC;AACxE,QAAQ,EAEJ,CAAC;AAEL,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,qBAAqB;IAC/B,WAAW,EAAE,KAAK;IAClB,IAAI,EAAE,KAAK;CACF,CAAC;AAEX,oDAAoD;AACpD,MAAM,CAAC,MAAM,cAAc,GAAG,UAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC","sourcesContent":["import type {Expect, Equal} from '@type-challenges/utils';\nimport {type HttpMethod} from '../types/options.js';\n\nexport const supportsRequestStreams = (() => {\n\tlet duplexAccessed = false;\n\tlet hasContentType = false;\n\tconst supportsReadableStream = typeof globalThis.ReadableStream === 'function';\n\tconst supportsRequest = typeof globalThis.Request === 'function';\n\n\tif (supportsReadableStream && supportsRequest) {\n\t\thasContentType = new globalThis.Request('https://empty.invalid', {\n\t\t\tbody: new globalThis.ReadableStream(),\n\t\t\tmethod: 'POST',\n\t\t\t// @ts-expect-error - Types are outdated.\n\t\t\tget duplex() {\n\t\t\t\tduplexAccessed = true;\n\t\t\t\treturn 'half';\n\t\t\t},\n\t\t}).headers.has('Content-Type');\n\t}\n\n\treturn duplexAccessed && !hasContentType;\n})();\n\nexport const supportsAbortController = typeof globalThis.AbortController === 'function';\nexport const supportsResponseStreams = typeof globalThis.ReadableStream === 'function';\nexport const supportsFormData = typeof globalThis.FormData === 'function';\n\nexport const requestMethods = ['get', 'post', 'put', 'patch', 'head', 'delete'] as const;\n\nconst validate = <T extends Array<true>>() => undefined as unknown as T;\nvalidate<[\n\tExpect<Equal<typeof requestMethods[number], HttpMethod>>,\n]>();\n\nexport const responseTypes = {\n\tjson: 'application/json',\n\ttext: 'text/*',\n\tformData: 'multipart/form-data',\n\tarrayBuffer: '*/*',\n\tblob: '*/*',\n} as const;\n\n// The maximum value of a 32bit int (see issue #117)\nexport const maxSafeTimeout = 2_147_483_647;\n\nexport const stop = Symbol('stop');\n"]}
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../source/core/constants.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAG,EAAE;IAC3C,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,MAAM,sBAAsB,GAAG,OAAO,UAAU,CAAC,cAAc,KAAK,UAAU,CAAC;IAC/E,MAAM,eAAe,GAAG,OAAO,UAAU,CAAC,OAAO,KAAK,UAAU,CAAC;IAEjE,IAAI,sBAAsB,IAAI,eAAe,EAAE;QAC9C,cAAc,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,uBAAuB,EAAE;YAChE,IAAI,EAAE,IAAI,UAAU,CAAC,cAAc,EAAE;YACrC,MAAM,EAAE,MAAM;YACd,yCAAyC;YACzC,IAAI,MAAM;gBACT,cAAc,GAAG,IAAI,CAAC;gBACtB,OAAO,MAAM,CAAC;YACf,CAAC;SACD,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;KAC/B;IAED,OAAO,cAAc,IAAI,CAAC,cAAc,CAAC;AAC1C,CAAC,CAAC,EAAE,CAAC;AAEL,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,UAAU,CAAC,eAAe,KAAK,UAAU,CAAC;AACxF,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,UAAU,CAAC,cAAc,KAAK,UAAU,CAAC;AACvF,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,UAAU,CAAC,QAAQ,KAAK,UAAU,CAAC;AAE1E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC;AAEzF,MAAM,QAAQ,GAAG,GAA0B,EAAE,CAAC,SAAyB,CAAC;AACxE,QAAQ,EAEJ,CAAC;AAEL,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,qBAAqB;IAC/B,WAAW,EAAE,KAAK;IAClB,IAAI,EAAE,KAAK;CACF,CAAC;AAEX,oDAAoD;AACpD,MAAM,CAAC,MAAM,cAAc,GAAG,UAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAEnC,MAAM,CAAC,MAAM,YAAY,GAAsB;IAC9C,IAAI,EAAE,IAAI;IACV,SAAS,EAAE,IAAI;IACf,YAAY,EAAE,IAAI;IAClB,SAAS,EAAE,IAAI;IACf,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,IAAI;IACX,eAAe,EAAE,IAAI;IACrB,kBAAkB,EAAE,IAAI;IACxB,KAAK,EAAE,IAAI;CACX,CAAC","sourcesContent":["import type {Expect, Equal} from '@type-challenges/utils';\nimport {type HttpMethod, type KyOptionsRegistry} from '../types/options.js';\n\nexport const supportsRequestStreams = (() => {\n\tlet duplexAccessed = false;\n\tlet hasContentType = false;\n\tconst supportsReadableStream = typeof globalThis.ReadableStream === 'function';\n\tconst supportsRequest = typeof globalThis.Request === 'function';\n\n\tif (supportsReadableStream && supportsRequest) {\n\t\thasContentType = new globalThis.Request('https://empty.invalid', {\n\t\t\tbody: new globalThis.ReadableStream(),\n\t\t\tmethod: 'POST',\n\t\t\t// @ts-expect-error - Types are outdated.\n\t\t\tget duplex() {\n\t\t\t\tduplexAccessed = true;\n\t\t\t\treturn 'half';\n\t\t\t},\n\t\t}).headers.has('Content-Type');\n\t}\n\n\treturn duplexAccessed && !hasContentType;\n})();\n\nexport const supportsAbortController = typeof globalThis.AbortController === 'function';\nexport const supportsResponseStreams = typeof globalThis.ReadableStream === 'function';\nexport const supportsFormData = typeof globalThis.FormData === 'function';\n\nexport const requestMethods = ['get', 'post', 'put', 'patch', 'head', 'delete'] as const;\n\nconst validate = <T extends Array<true>>() => undefined as unknown as T;\nvalidate<[\n\tExpect<Equal<typeof requestMethods[number], HttpMethod>>,\n]>();\n\nexport const responseTypes = {\n\tjson: 'application/json',\n\ttext: 'text/*',\n\tformData: 'multipart/form-data',\n\tarrayBuffer: '*/*',\n\tblob: '*/*',\n} as const;\n\n// The maximum value of a 32bit int (see issue #117)\nexport const maxSafeTimeout = 2_147_483_647;\n\nexport const stop = Symbol('stop');\n\nexport const kyOptionKeys: KyOptionsRegistry = {\n\tjson: true,\n\tparseJson: true,\n\tsearchParams: true,\n\tprefixUrl: true,\n\tretry: true,\n\ttimeout: true,\n\thooks: true,\n\tthrowHttpErrors: true,\n\tonDownloadProgress: true,\n\tfetch: true,\n};\n"]}

@@ -7,2 +7,3 @@ import { HTTPError } from '../errors/HTTPError.js';

import delay from '../utils/delay.js';
import { findUnknownOptions } from '../utils/options.js';
import { maxSafeTimeout, responseTypes, stop, supportsAbortController, supportsFormData, supportsResponseStreams, supportsRequestStreams, } from './constants.js';

@@ -249,6 +250,7 @@ export class Ky {

}
const nonRequestOptions = findUnknownOptions(this.request, this._options);
if (this._options.timeout === false) {
return this._options.fetch(this.request.clone());
return this._options.fetch(this.request.clone(), nonRequestOptions);
}
return timeout(this.request.clone(), this.abortController, this._options);
return timeout(this.request.clone(), nonRequestOptions, this.abortController, this._options);
}

@@ -255,0 +257,0 @@ /* istanbul ignore next */

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

{"version":3,"file":"Ky.js","sourceRoot":"","sources":["../../source/core/Ky.ts"],"names":[],"mappings":"AAA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,CACD,CAAC;IACH,CAAC;CACD","sourcesContent":["import {HTTPError} from '../errors/HTTPError.js';\nimport {TimeoutError} from '../errors/TimeoutError.js';\nimport type {Hooks} from '../types/hooks.js';\nimport type {Input, InternalOptions, NormalizedOptions, Options, SearchParamsInit} from '../types/options.js';\nimport {type ResponsePromise} from '../types/ResponsePromise.js';\nimport {deepMerge, mergeHeaders} from '../utils/merge.js';\nimport {normalizeRequestMethod, normalizeRetryOptions} from '../utils/normalize.js';\nimport timeout, {type TimeoutOptions} from '../utils/timeout.js';\nimport delay from '../utils/delay.js';\nimport {type ObjectEntries} from '../utils/types.js';\nimport {\n\tmaxSafeTimeout,\n\tresponseTypes,\n\tstop,\n\tsupportsAbortController,\n\tsupportsFormData,\n\tsupportsResponseStreams,\n\tsupportsRequestStreams,\n} from './constants.js';\n\nexport class Ky {\n\tstatic create(input: Input, options: Options): ResponsePromise {\n\t\tconst ky = new Ky(input, options);\n\n\t\tconst fn = async (): Promise<Response> => {\n\t\t\tif (typeof ky._options.timeout === 'number' && ky._options.timeout > maxSafeTimeout) {\n\t\t\t\tthrow new RangeError(`The \\`timeout\\` option cannot be greater than ${maxSafeTimeout}`);\n\t\t\t}\n\n\t\t\t// Delay the fetch so that body method shortcuts can set the Accept header\n\t\t\tawait Promise.resolve();\n\t\t\tlet response = await ky._fetch();\n\n\t\t\tfor (const hook of ky._options.hooks.afterResponse) {\n\t\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\t\tconst modifiedResponse = await hook(\n\t\t\t\t\tky.request,\n\t\t\t\t\tky._options as NormalizedOptions,\n\t\t\t\t\tky._decorateResponse(response.clone()),\n\t\t\t\t);\n\n\t\t\t\tif (modifiedResponse instanceof globalThis.Response) {\n\t\t\t\t\tresponse = modifiedResponse;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tky._decorateResponse(response);\n\n\t\t\tif (!response.ok && ky._options.throwHttpErrors) {\n\t\t\t\tlet error = new HTTPError(response, ky.request, (ky._options as unknown) as NormalizedOptions);\n\n\t\t\t\tfor (const hook of ky._options.hooks.beforeError) {\n\t\t\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\t\t\terror = await hook(error);\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\t// If `onDownloadProgress` is passed, it uses the stream API internally\n\t\t\t/* istanbul ignore next */\n\t\t\tif (ky._options.onDownloadProgress) {\n\t\t\t\tif (typeof ky._options.onDownloadProgress !== 'function') {\n\t\t\t\t\tthrow new TypeError('The `onDownloadProgress` option must be a function');\n\t\t\t\t}\n\n\t\t\t\tif (!supportsResponseStreams) {\n\t\t\t\t\tthrow new Error('Streams are not supported in your environment. `ReadableStream` is missing.');\n\t\t\t\t}\n\n\t\t\t\treturn ky._stream(response.clone(), ky._options.onDownloadProgress);\n\t\t\t}\n\n\t\t\treturn response;\n\t\t};\n\n\t\tconst isRetriableMethod = ky._options.retry.methods.includes(ky.request.method.toLowerCase());\n\t\tconst result = (isRetriableMethod ? ky._retry(fn) : fn()) as ResponsePromise;\n\n\t\tfor (const [type, mimeType] of Object.entries(responseTypes) as ObjectEntries<typeof responseTypes>) {\n\t\t\tresult[type] = async () => {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\t\tky.request.headers.set('accept', ky.request.headers.get('accept') || mimeType);\n\n\t\t\t\tconst awaitedResult = await result;\n\t\t\t\tconst response = awaitedResult.clone();\n\n\t\t\t\tif (type === 'json') {\n\t\t\t\t\tif (response.status === 204) {\n\t\t\t\t\t\treturn '';\n\t\t\t\t\t}\n\n\t\t\t\t\tconst arrayBuffer = await response.clone().arrayBuffer();\n\t\t\t\t\tconst responseSize = arrayBuffer.byteLength;\n\t\t\t\t\tif (responseSize === 0) {\n\t\t\t\t\t\treturn '';\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.parseJson) {\n\t\t\t\t\t\treturn options.parseJson(await response.text());\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn response[type]();\n\t\t\t};\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tpublic request: Request;\n\tprotected abortController?: AbortController;\n\tprotected _retryCount = 0;\n\tprotected _input: Input;\n\tprotected _options: InternalOptions;\n\n\t// eslint-disable-next-line complexity\n\tconstructor(input: Input, options: Options = {}) {\n\t\tthis._input = input;\n\t\tthis._options = {\n\t\t\t// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208\n\t\t\tcredentials: (this._input as Request).credentials || 'same-origin',\n\t\t\t...options,\n\t\t\theaders: mergeHeaders((this._input as Request).headers, options.headers),\n\t\t\thooks: deepMerge<Required<Hooks>>(\n\t\t\t\t{\n\t\t\t\t\tbeforeRequest: [],\n\t\t\t\t\tbeforeRetry: [],\n\t\t\t\t\tbeforeError: [],\n\t\t\t\t\tafterResponse: [],\n\t\t\t\t},\n\t\t\t\toptions.hooks,\n\t\t\t),\n\t\t\tmethod: normalizeRequestMethod(options.method ?? (this._input as Request).method),\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\tprefixUrl: String(options.prefixUrl || ''),\n\t\t\tretry: normalizeRetryOptions(options.retry),\n\t\t\tthrowHttpErrors: options.throwHttpErrors !== false,\n\t\t\ttimeout: options.timeout ?? 10_000,\n\t\t\tfetch: options.fetch ?? globalThis.fetch.bind(globalThis),\n\t\t};\n\n\t\tif (typeof this._input !== 'string' && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {\n\t\t\tthrow new TypeError('`input` must be a string, URL, or Request');\n\t\t}\n\n\t\tif (this._options.prefixUrl && typeof this._input === 'string') {\n\t\t\tif (this._input.startsWith('/')) {\n\t\t\t\tthrow new Error('`input` must not begin with a slash when using `prefixUrl`');\n\t\t\t}\n\n\t\t\tif (!this._options.prefixUrl.endsWith('/')) {\n\t\t\t\tthis._options.prefixUrl += '/';\n\t\t\t}\n\n\t\t\tthis._input = this._options.prefixUrl + this._input;\n\t\t}\n\n\t\tif (supportsAbortController) {\n\t\t\tthis.abortController = new globalThis.AbortController();\n\t\t\tif (this._options.signal) {\n\t\t\t\tconst originalSignal = this._options.signal;\n\n\t\t\t\tthis._options.signal.addEventListener('abort', () => {\n\t\t\t\t\tthis.abortController!.abort(originalSignal.reason);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tthis._options.signal = this.abortController.signal;\n\t\t}\n\n\t\tif (supportsRequestStreams) {\n\t\t\t// @ts-expect-error - Types are outdated.\n\t\t\tthis._options.duplex = 'half';\n\t\t}\n\n\t\tthis.request = new globalThis.Request(this._input as RequestInfo, this._options as RequestInit);\n\n\t\tif (this._options.searchParams) {\n\t\t\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\t\t\tconst textSearchParams = typeof this._options.searchParams === 'string'\n\t\t\t\t? this._options.searchParams.replace(/^\\?/, '')\n\t\t\t\t: new URLSearchParams(this._options.searchParams as unknown as SearchParamsInit).toString();\n\t\t\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\t\t\tconst searchParams = '?' + textSearchParams;\n\t\t\tconst url = this.request.url.replace(/(?:\\?.*?)?(?=#|$)/, searchParams);\n\n\t\t\t// To provide correct form boundary, Content-Type header should be deleted each time when new Request instantiated from another one\n\t\t\tif (\n\t\t\t\t((supportsFormData && this._options.body instanceof globalThis.FormData)\n\t\t\t\t\t|| this._options.body instanceof URLSearchParams) && !(this._options.headers && (this._options.headers as Record<string, string>)['content-type'])\n\t\t\t) {\n\t\t\t\tthis.request.headers.delete('content-type');\n\t\t\t}\n\n\t\t\t// The spread of `this.request` is required as otherwise it misses the `duplex` option for some reason and throws.\n\t\t\tthis.request = new globalThis.Request(new globalThis.Request(url, {...this.request}), this._options as RequestInit);\n\t\t}\n\n\t\tif (this._options.json !== undefined) {\n\t\t\tthis._options.body = JSON.stringify(this._options.json);\n\t\t\tthis.request.headers.set('content-type', this._options.headers.get('content-type') ?? 'application/json');\n\t\t\tthis.request = new globalThis.Request(this.request, {body: this._options.body});\n\t\t}\n\t}\n\n\tprotected _calculateRetryDelay(error: unknown) {\n\t\tthis._retryCount++;\n\n\t\tif (this._retryCount < this._options.retry.limit && !(error instanceof TimeoutError)) {\n\t\t\tif (error instanceof HTTPError) {\n\t\t\t\tif (!this._options.retry.statusCodes.includes(error.response.status)) {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\n\t\t\t\tconst retryAfter = error.response.headers.get('Retry-After');\n\t\t\t\tif (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {\n\t\t\t\t\tlet after = Number(retryAfter);\n\t\t\t\t\tif (Number.isNaN(after)) {\n\t\t\t\t\t\tafter = Date.parse(retryAfter) - Date.now();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tafter *= 1000;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this._options.retry.maxRetryAfter !== undefined && after > this._options.retry.maxRetryAfter) {\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn after;\n\t\t\t\t}\n\n\t\t\t\tif (error.response.status === 413) {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst retryDelay = this._options.retry.delay(this._retryCount);\n\t\t\treturn Math.min(this._options.retry.backoffLimit, retryDelay);\n\t\t}\n\n\t\treturn 0;\n\t}\n\n\tprotected _decorateResponse(response: Response): Response {\n\t\tif (this._options.parseJson) {\n\t\t\tresponse.json = async () => this._options.parseJson!(await response.text());\n\t\t}\n\n\t\treturn response;\n\t}\n\n\tprotected async _retry<T extends (...args: any) => Promise<any>>(fn: T): Promise<ReturnType<T> | void> {\n\t\ttry {\n\t\t\treturn await fn();\n\t\t} catch (error) {\n\t\t\tconst ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);\n\t\t\tif (ms !== 0 && this._retryCount > 0) {\n\t\t\t\tawait delay(ms, {signal: this._options.signal});\n\n\t\t\t\tfor (const hook of this._options.hooks.beforeRetry) {\n\t\t\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\t\t\tconst hookResult = await hook({\n\t\t\t\t\t\trequest: this.request,\n\t\t\t\t\t\toptions: (this._options as unknown) as NormalizedOptions,\n\t\t\t\t\t\terror: error as Error,\n\t\t\t\t\t\tretryCount: this._retryCount,\n\t\t\t\t\t});\n\n\t\t\t\t\t// If `stop` is returned from the hook, the retry process is stopped\n\t\t\t\t\tif (hookResult === stop) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn this._retry(fn);\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprotected async _fetch(): Promise<Response> {\n\t\tfor (const hook of this._options.hooks.beforeRequest) {\n\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\tconst result = await hook(this.request, (this._options as unknown) as NormalizedOptions);\n\n\t\t\tif (result instanceof Request) {\n\t\t\t\tthis.request = result;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (result instanceof Response) {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t}\n\n\t\tif (this._options.timeout === false) {\n\t\t\treturn this._options.fetch(this.request.clone());\n\t\t}\n\n\t\treturn timeout(this.request.clone(), this.abortController, this._options as TimeoutOptions);\n\t}\n\n\t/* istanbul ignore next */\n\tprotected _stream(response: Response, onDownloadProgress: Options['onDownloadProgress']) {\n\t\tconst totalBytes = Number(response.headers.get('content-length')) || 0;\n\t\tlet transferredBytes = 0;\n\n\t\tif (response.status === 204) {\n\t\t\tif (onDownloadProgress) {\n\t\t\t\tonDownloadProgress({percent: 1, totalBytes, transferredBytes}, new Uint8Array());\n\t\t\t}\n\n\t\t\treturn new globalThis.Response(\n\t\t\t\tnull,\n\t\t\t\t{\n\t\t\t\t\tstatus: response.status,\n\t\t\t\t\tstatusText: response.statusText,\n\t\t\t\t\theaders: response.headers,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\treturn new globalThis.Response(\n\t\t\tnew globalThis.ReadableStream({\n\t\t\t\tasync start(controller) {\n\t\t\t\t\tconst reader = response.body!.getReader();\n\n\t\t\t\t\tif (onDownloadProgress) {\n\t\t\t\t\t\tonDownloadProgress({percent: 0, transferredBytes: 0, totalBytes}, new Uint8Array());\n\t\t\t\t\t}\n\n\t\t\t\t\tasync function read() {\n\t\t\t\t\t\tconst {done, value} = await reader.read();\n\t\t\t\t\t\tif (done) {\n\t\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (onDownloadProgress) {\n\t\t\t\t\t\t\ttransferredBytes += value.byteLength;\n\t\t\t\t\t\t\tconst percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;\n\t\t\t\t\t\t\tonDownloadProgress({percent, transferredBytes, totalBytes}, value);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tcontroller.enqueue(value);\n\t\t\t\t\t\tawait read();\n\t\t\t\t\t}\n\n\t\t\t\t\tawait read();\n\t\t\t\t},\n\t\t\t}),\n\t\t\t{\n\t\t\t\tstatus: response.status,\n\t\t\t\tstatusText: response.statusText,\n\t\t\t\theaders: response.headers,\n\t\t\t},\n\t\t);\n\t}\n}\n"]}
{"version":3,"file":"Ky.js","sourceRoot":"","sources":["../../source/core/Ky.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAIvD,OAAO,EAAC,SAAS,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAC,sBAAsB,EAAE,qBAAqB,EAAC,MAAM,uBAAuB,CAAC;AACpF,OAAO,OAA8B,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,MAAM,mBAAmB,CAAC;AAEtC,OAAO,EAAC,kBAAkB,EAAC,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACN,cAAc,EACd,aAAa,EACb,IAAI,EACJ,uBAAuB,EACvB,gBAAgB,EAChB,uBAAuB,E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M,MAAM,GAAG,QAAQ,CAAC,IAAK,CAAC,SAAS,EAAE,CAAC;gBAE1C,IAAI,kBAAkB,EAAE;oBACvB,kBAAkB,CAAC,EAAC,OAAO,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,UAAU,EAAC,EAAE,IAAI,UAAU,EAAE,CAAC,CAAC;iBACpF;gBAED,KAAK,UAAU,IAAI;oBAClB,MAAM,EAAC,IAAI,EAAE,KAAK,EAAC,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;oBAC1C,IAAI,IAAI,EAAE;wBACT,UAAU,CAAC,KAAK,EAAE,CAAC;wBACnB,OAAO;qBACP;oBAED,IAAI,kBAAkB,EAAE;wBACvB,gBAAgB,IAAI,KAAK,CAAC,UAAU,CAAC;wBACrC,MAAM,OAAO,GAAG,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB,GAAG,UAAU,CAAC;wBACrE,kBAAkB,CAAC,EAAC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAC,EAAE,KAAK,CAAC,CAAC;qBACnE;oBAED,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;oBAC1B,MAAM,IAAI,EAAE,CAAC;gBACd,CAAC;gBAED,MAAM,IAAI,EAAE,CAAC;YACd,CAAC;SACD,CAAC,EACF;YACC,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,OAAO,EAAE,QAAQ,CAAC,OAAO;SACzB,CACD,CAAC;IACH,CAAC;CACD","sourcesContent":["import {HTTPError} from '../errors/HTTPError.js';\nimport {TimeoutError} from '../errors/TimeoutError.js';\nimport type {Hooks} from '../types/hooks.js';\nimport type {Input, InternalOptions, NormalizedOptions, Options, SearchParamsInit} from '../types/options.js';\nimport {type ResponsePromise} from '../types/ResponsePromise.js';\nimport {deepMerge, mergeHeaders} from '../utils/merge.js';\nimport {normalizeRequestMethod, normalizeRetryOptions} from '../utils/normalize.js';\nimport timeout, {type TimeoutOptions} from '../utils/timeout.js';\nimport delay from '../utils/delay.js';\nimport {type ObjectEntries} from '../utils/types.js';\nimport {findUnknownOptions} from '../utils/options.js';\nimport {\n\tmaxSafeTimeout,\n\tresponseTypes,\n\tstop,\n\tsupportsAbortController,\n\tsupportsFormData,\n\tsupportsResponseStreams,\n\tsupportsRequestStreams,\n} from './constants.js';\n\nexport class Ky {\n\tstatic create(input: Input, options: Options): ResponsePromise {\n\t\tconst ky = new Ky(input, options);\n\n\t\tconst fn = async (): Promise<Response> => {\n\t\t\tif (typeof ky._options.timeout === 'number' && ky._options.timeout > maxSafeTimeout) {\n\t\t\t\tthrow new RangeError(`The \\`timeout\\` option cannot be greater than ${maxSafeTimeout}`);\n\t\t\t}\n\n\t\t\t// Delay the fetch so that body method shortcuts can set the Accept header\n\t\t\tawait Promise.resolve();\n\t\t\tlet response = await ky._fetch();\n\n\t\t\tfor (const hook of ky._options.hooks.afterResponse) {\n\t\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\t\tconst modifiedResponse = await hook(\n\t\t\t\t\tky.request,\n\t\t\t\t\tky._options as NormalizedOptions,\n\t\t\t\t\tky._decorateResponse(response.clone()),\n\t\t\t\t);\n\n\t\t\t\tif (modifiedResponse instanceof globalThis.Response) {\n\t\t\t\t\tresponse = modifiedResponse;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tky._decorateResponse(response);\n\n\t\t\tif (!response.ok && ky._options.throwHttpErrors) {\n\t\t\t\tlet error = new HTTPError(response, ky.request, (ky._options as unknown) as NormalizedOptions);\n\n\t\t\t\tfor (const hook of ky._options.hooks.beforeError) {\n\t\t\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\t\t\terror = await hook(error);\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\t// If `onDownloadProgress` is passed, it uses the stream API internally\n\t\t\t/* istanbul ignore next */\n\t\t\tif (ky._options.onDownloadProgress) {\n\t\t\t\tif (typeof ky._options.onDownloadProgress !== 'function') {\n\t\t\t\t\tthrow new TypeError('The `onDownloadProgress` option must be a function');\n\t\t\t\t}\n\n\t\t\t\tif (!supportsResponseStreams) {\n\t\t\t\t\tthrow new Error('Streams are not supported in your environment. `ReadableStream` is missing.');\n\t\t\t\t}\n\n\t\t\t\treturn ky._stream(response.clone(), ky._options.onDownloadProgress);\n\t\t\t}\n\n\t\t\treturn response;\n\t\t};\n\n\t\tconst isRetriableMethod = ky._options.retry.methods.includes(ky.request.method.toLowerCase());\n\t\tconst result = (isRetriableMethod ? ky._retry(fn) : fn()) as ResponsePromise;\n\n\t\tfor (const [type, mimeType] of Object.entries(responseTypes) as ObjectEntries<typeof responseTypes>) {\n\t\t\tresult[type] = async () => {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\t\tky.request.headers.set('accept', ky.request.headers.get('accept') || mimeType);\n\n\t\t\t\tconst awaitedResult = await result;\n\t\t\t\tconst response = awaitedResult.clone();\n\n\t\t\t\tif (type === 'json') {\n\t\t\t\t\tif (response.status === 204) {\n\t\t\t\t\t\treturn '';\n\t\t\t\t\t}\n\n\t\t\t\t\tconst arrayBuffer = await response.clone().arrayBuffer();\n\t\t\t\t\tconst responseSize = arrayBuffer.byteLength;\n\t\t\t\t\tif (responseSize === 0) {\n\t\t\t\t\t\treturn '';\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.parseJson) {\n\t\t\t\t\t\treturn options.parseJson(await response.text());\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn response[type]();\n\t\t\t};\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tpublic request: Request;\n\tprotected abortController?: AbortController;\n\tprotected _retryCount = 0;\n\tprotected _input: Input;\n\tprotected _options: InternalOptions;\n\n\t// eslint-disable-next-line complexity\n\tconstructor(input: Input, options: Options = {}) {\n\t\tthis._input = input;\n\t\tthis._options = {\n\t\t\t// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208\n\t\t\tcredentials: (this._input as Request).credentials || 'same-origin',\n\t\t\t...options,\n\t\t\theaders: mergeHeaders((this._input as Request).headers, options.headers),\n\t\t\thooks: deepMerge<Required<Hooks>>(\n\t\t\t\t{\n\t\t\t\t\tbeforeRequest: [],\n\t\t\t\t\tbeforeRetry: [],\n\t\t\t\t\tbeforeError: [],\n\t\t\t\t\tafterResponse: [],\n\t\t\t\t},\n\t\t\t\toptions.hooks,\n\t\t\t),\n\t\t\tmethod: normalizeRequestMethod(options.method ?? (this._input as Request).method),\n\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\tprefixUrl: String(options.prefixUrl || ''),\n\t\t\tretry: normalizeRetryOptions(options.retry),\n\t\t\tthrowHttpErrors: options.throwHttpErrors !== false,\n\t\t\ttimeout: options.timeout ?? 10_000,\n\t\t\tfetch: options.fetch ?? globalThis.fetch.bind(globalThis),\n\t\t};\n\n\t\tif (typeof this._input !== 'string' && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {\n\t\t\tthrow new TypeError('`input` must be a string, URL, or Request');\n\t\t}\n\n\t\tif (this._options.prefixUrl && typeof this._input === 'string') {\n\t\t\tif (this._input.startsWith('/')) {\n\t\t\t\tthrow new Error('`input` must not begin with a slash when using `prefixUrl`');\n\t\t\t}\n\n\t\t\tif (!this._options.prefixUrl.endsWith('/')) {\n\t\t\t\tthis._options.prefixUrl += '/';\n\t\t\t}\n\n\t\t\tthis._input = this._options.prefixUrl + this._input;\n\t\t}\n\n\t\tif (supportsAbortController) {\n\t\t\tthis.abortController = new globalThis.AbortController();\n\t\t\tif (this._options.signal) {\n\t\t\t\tconst originalSignal = this._options.signal;\n\n\t\t\t\tthis._options.signal.addEventListener('abort', () => {\n\t\t\t\t\tthis.abortController!.abort(originalSignal.reason);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tthis._options.signal = this.abortController.signal;\n\t\t}\n\n\t\tif (supportsRequestStreams) {\n\t\t\t// @ts-expect-error - Types are outdated.\n\t\t\tthis._options.duplex = 'half';\n\t\t}\n\n\t\tthis.request = new globalThis.Request(this._input as RequestInfo, this._options as RequestInit);\n\n\t\tif (this._options.searchParams) {\n\t\t\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\t\t\tconst textSearchParams = typeof this._options.searchParams === 'string'\n\t\t\t\t? this._options.searchParams.replace(/^\\?/, '')\n\t\t\t\t: new URLSearchParams(this._options.searchParams as unknown as SearchParamsInit).toString();\n\t\t\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\t\t\tconst searchParams = '?' + textSearchParams;\n\t\t\tconst url = this.request.url.replace(/(?:\\?.*?)?(?=#|$)/, searchParams);\n\n\t\t\t// To provide correct form boundary, Content-Type header should be deleted each time when new Request instantiated from another one\n\t\t\tif (\n\t\t\t\t((supportsFormData && this._options.body instanceof globalThis.FormData)\n\t\t\t\t\t|| this._options.body instanceof URLSearchParams) && !(this._options.headers && (this._options.headers as Record<string, string>)['content-type'])\n\t\t\t) {\n\t\t\t\tthis.request.headers.delete('content-type');\n\t\t\t}\n\n\t\t\t// The spread of `this.request` is required as otherwise it misses the `duplex` option for some reason and throws.\n\t\t\tthis.request = new globalThis.Request(new globalThis.Request(url, {...this.request}), this._options as RequestInit);\n\t\t}\n\n\t\tif (this._options.json !== undefined) {\n\t\t\tthis._options.body = JSON.stringify(this._options.json);\n\t\t\tthis.request.headers.set('content-type', this._options.headers.get('content-type') ?? 'application/json');\n\t\t\tthis.request = new globalThis.Request(this.request, {body: this._options.body});\n\t\t}\n\t}\n\n\tprotected _calculateRetryDelay(error: unknown) {\n\t\tthis._retryCount++;\n\n\t\tif (this._retryCount < this._options.retry.limit && !(error instanceof TimeoutError)) {\n\t\t\tif (error instanceof HTTPError) {\n\t\t\t\tif (!this._options.retry.statusCodes.includes(error.response.status)) {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\n\t\t\t\tconst retryAfter = error.response.headers.get('Retry-After');\n\t\t\t\tif (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {\n\t\t\t\t\tlet after = Number(retryAfter);\n\t\t\t\t\tif (Number.isNaN(after)) {\n\t\t\t\t\t\tafter = Date.parse(retryAfter) - Date.now();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tafter *= 1000;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this._options.retry.maxRetryAfter !== undefined && after > this._options.retry.maxRetryAfter) {\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn after;\n\t\t\t\t}\n\n\t\t\t\tif (error.response.status === 413) {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst retryDelay = this._options.retry.delay(this._retryCount);\n\t\t\treturn Math.min(this._options.retry.backoffLimit, retryDelay);\n\t\t}\n\n\t\treturn 0;\n\t}\n\n\tprotected _decorateResponse(response: Response): Response {\n\t\tif (this._options.parseJson) {\n\t\t\tresponse.json = async () => this._options.parseJson!(await response.text());\n\t\t}\n\n\t\treturn response;\n\t}\n\n\tprotected async _retry<T extends (...args: any) => Promise<any>>(fn: T): Promise<ReturnType<T> | void> {\n\t\ttry {\n\t\t\treturn await fn();\n\t\t} catch (error) {\n\t\t\tconst ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);\n\t\t\tif (ms !== 0 && this._retryCount > 0) {\n\t\t\t\tawait delay(ms, {signal: this._options.signal});\n\n\t\t\t\tfor (const hook of this._options.hooks.beforeRetry) {\n\t\t\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\t\t\tconst hookResult = await hook({\n\t\t\t\t\t\trequest: this.request,\n\t\t\t\t\t\toptions: (this._options as unknown) as NormalizedOptions,\n\t\t\t\t\t\terror: error as Error,\n\t\t\t\t\t\tretryCount: this._retryCount,\n\t\t\t\t\t});\n\n\t\t\t\t\t// If `stop` is returned from the hook, the retry process is stopped\n\t\t\t\t\tif (hookResult === stop) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn this._retry(fn);\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprotected async _fetch(): Promise<Response> {\n\t\tfor (const hook of this._options.hooks.beforeRequest) {\n\t\t\t// eslint-disable-next-line no-await-in-loop\n\t\t\tconst result = await hook(this.request, (this._options as unknown) as NormalizedOptions);\n\n\t\t\tif (result instanceof Request) {\n\t\t\t\tthis.request = result;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (result instanceof Response) {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t}\n\n\t\tconst nonRequestOptions = findUnknownOptions(this.request, this._options);\n\n\t\tif (this._options.timeout === false) {\n\t\t\treturn this._options.fetch(this.request.clone(), nonRequestOptions);\n\t\t}\n\n\t\treturn timeout(this.request.clone(), nonRequestOptions, this.abortController, this._options as TimeoutOptions);\n\t}\n\n\t/* istanbul ignore next */\n\tprotected _stream(response: Response, onDownloadProgress: Options['onDownloadProgress']) {\n\t\tconst totalBytes = Number(response.headers.get('content-length')) || 0;\n\t\tlet transferredBytes = 0;\n\n\t\tif (response.status === 204) {\n\t\t\tif (onDownloadProgress) {\n\t\t\t\tonDownloadProgress({percent: 1, totalBytes, transferredBytes}, new Uint8Array());\n\t\t\t}\n\n\t\t\treturn new globalThis.Response(\n\t\t\t\tnull,\n\t\t\t\t{\n\t\t\t\t\tstatus: response.status,\n\t\t\t\t\tstatusText: response.statusText,\n\t\t\t\t\theaders: response.headers,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\treturn new globalThis.Response(\n\t\t\tnew globalThis.ReadableStream({\n\t\t\t\tasync start(controller) {\n\t\t\t\t\tconst reader = response.body!.getReader();\n\n\t\t\t\t\tif (onDownloadProgress) {\n\t\t\t\t\t\tonDownloadProgress({percent: 0, transferredBytes: 0, totalBytes}, new Uint8Array());\n\t\t\t\t\t}\n\n\t\t\t\t\tasync function read() {\n\t\t\t\t\t\tconst {done, value} = await reader.read();\n\t\t\t\t\t\tif (done) {\n\t\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (onDownloadProgress) {\n\t\t\t\t\t\t\ttransferredBytes += value.byteLength;\n\t\t\t\t\t\t\tconst percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;\n\t\t\t\t\t\t\tonDownloadProgress({percent, transferredBytes, totalBytes}, value);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tcontroller.enqueue(value);\n\t\t\t\t\t\tawait read();\n\t\t\t\t\t}\n\n\t\t\t\t\tawait read();\n\t\t\t\t},\n\t\t\t}),\n\t\t\t{\n\t\t\t\tstatus: response.status,\n\t\t\t\tstatusText: response.statusText,\n\t\t\t\theaders: response.headers,\n\t\t\t},\n\t\t);\n\t}\n}\n"]}

@@ -18,48 +18,6 @@ import type { LiteralUnion, Required } from './common.js';

/**
Options are the same as `window.fetch`, with some exceptions.
Custom Ky options
*/
export interface Options extends Omit<RequestInit, 'headers'> {
export type KyOptions = {
/**
HTTP method used to make the request.
Internally, the standard methods (`GET`, `POST`, `PUT`, `PATCH`, `HEAD` and `DELETE`) are uppercased in order to avoid server errors due to case sensitivity.
*/
method?: LiteralUnion<HttpMethod, string>;
/**
HTTP headers used to make the request.
You can pass a `Headers` instance or a plain object.
You can remove a header with `.extend()` by passing the header with an `undefined` value.
@example
```
import ky from 'ky';
const url = 'https://sindresorhus.com';
const original = ky.create({
headers: {
rainbow: 'rainbow',
unicorn: 'unicorn'
}
});
const extended = original.extend({
headers: {
rainbow: undefined
}
});
const response = await extended(url).json();
console.log('rainbow' in response);
//=> false
console.log('unicorn' in response);
//=> true
```
*/
headers?: KyHeadersInit;
/**
Shortcut for sending JSON. Use this instead of the `body` option.

@@ -204,2 +162,57 @@

fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
};
/**
Each key from KyOptions is present and set to `true`.
This type is used for identifying and working with the known keys in KyOptions.
*/
export type KyOptionsRegistry = {
[K in keyof KyOptions]-?: true;
};
/**
Options are the same as `window.fetch`, except for the KyOptions
*/
export interface Options extends KyOptions, Omit<RequestInit, 'headers'> {
/**
HTTP method used to make the request.
Internally, the standard methods (`GET`, `POST`, `PUT`, `PATCH`, `HEAD` and `DELETE`) are uppercased in order to avoid server errors due to case sensitivity.
*/
method?: LiteralUnion<HttpMethod, string>;
/**
HTTP headers used to make the request.
You can pass a `Headers` instance or a plain object.
You can remove a header with `.extend()` by passing the header with an `undefined` value.
@example
```
import ky from 'ky';
const url = 'https://sindresorhus.com';
const original = ky.create({
headers: {
rainbow: 'rainbow',
unicorn: 'unicorn'
}
});
const extended = original.extend({
headers: {
rainbow: undefined
}
});
const response = await extended(url).json();
console.log('rainbow' in response);
//=> false
console.log('unicorn' in response);
//=> true
```
*/
headers?: KyHeadersInit;
}

@@ -206,0 +219,0 @@ export type InternalOptions = Required<Omit<Options, 'hooks' | 'retry'>, 'credentials' | 'fetch' | 'prefixUrl' | 'timeout'> & {

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

{"version":3,"file":"options.js","sourceRoot":"","sources":["../../source/types/options.ts"],"names":[],"mappings":"","sourcesContent":["import type {LiteralUnion, Required} from './common.js';\nimport type {Hooks} from './hooks.js';\nimport type {RetryOptions} from './retry.js';\n\n// eslint-disable-next-line unicorn/prevent-abbreviations\nexport type SearchParamsInit = string | string[][] | Record<string, string> | URLSearchParams | undefined;\n\n// eslint-disable-next-line unicorn/prevent-abbreviations\nexport type SearchParamsOption = SearchParamsInit | Record<string, string | number | boolean> | Array<Array<string | number | boolean>>;\n\nexport type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete';\n\nexport type Input = string | URL | Request;\n\nexport type DownloadProgress = {\n\tpercent: number;\n\ttransferredBytes: number;\n\n\t/**\n\tNote: If it's not possible to retrieve the body size, it will be `0`.\n\t*/\n\ttotalBytes: number;\n};\n\nexport type KyHeadersInit = HeadersInit | Record<string, string | undefined>;\n\n/**\nOptions are the same as `window.fetch`, with some exceptions.\n*/\nexport interface Options extends Omit<RequestInit, 'headers'> { // eslint-disable-line @typescript-eslint/consistent-type-definitions -- This must stay an interface so that it can be extended outside of Ky for use in `ky.create`.\n\t/**\n\tHTTP method used to make the request.\n\n\tInternally, the standard methods (`GET`, `POST`, `PUT`, `PATCH`, `HEAD` and `DELETE`) are uppercased in order to avoid server errors due to case sensitivity.\n\t*/\n\tmethod?: LiteralUnion<HttpMethod, string>;\n\n\t/**\n\tHTTP headers used to make the request.\n\n\tYou can pass a `Headers` instance or a plain object.\n\n\tYou can remove a header with `.extend()` by passing the header with an `undefined` value.\n\n\t@example\n\t```\n\timport ky from 'ky';\n\n\tconst url = 'https://sindresorhus.com';\n\n\tconst original = ky.create({\n\t\theaders: {\n\t\t\trainbow: 'rainbow',\n\t\t\tunicorn: 'unicorn'\n\t\t}\n\t});\n\n\tconst extended = original.extend({\n\t\theaders: {\n\t\t\trainbow: undefined\n\t\t}\n\t});\n\n\tconst response = await extended(url).json();\n\n\tconsole.log('rainbow' in response);\n\t//=> false\n\n\tconsole.log('unicorn' in response);\n\t//=> true\n\t```\n\t*/\n\theaders?: KyHeadersInit;\n\n\t/**\n\tShortcut for sending JSON. Use this instead of the `body` option.\n\n\tAccepts any plain object or value, which will be `JSON.stringify()`'d and sent in the body with the correct header set.\n\t*/\n\tjson?: unknown;\n\n\t/**\n\tUser-defined JSON-parsing function.\n\n\tUse-cases:\n\t1. Parse JSON via the [`bourne` package](https://github.com/hapijs/bourne) to protect from prototype pollution.\n\t2. Parse JSON with [`reviver` option of `JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).\n\n\t@default JSON.parse()\n\n\t@example\n\t```\n\timport ky from 'ky';\n\timport bourne from '@hapijs/bourne';\n\n\tconst json = await ky('https://example.com', {\n\t\tparseJson: text => bourne(text)\n\t}).json();\n\t```\n\t*/\n\tparseJson?: (text: string) => unknown;\n\n\t/**\n\tSearch parameters to include in the request URL. Setting this will override all existing search parameters in the input URL.\n\n\tAccepts any value supported by [`URLSearchParams()`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams).\n\t*/\n\tsearchParams?: SearchParamsOption;\n\n\t/**\n\tA prefix to prepend to the `input` URL when making the request. It can be any valid URL, either relative or absolute. A trailing slash `/` is optional and will be added automatically, if needed, when it is joined with `input`. Only takes effect when `input` is a string. The `input` argument cannot start with a slash `/` when using this option.\n\n\tUseful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.\n\n\tNotes:\n\t - After `prefixUrl` and `input` are joined, the result is resolved against the [base URL](https://developer.mozilla.org/en-US/docs/Web/API/Node/baseURI) of the page (if any).\n\t - Leading slashes in `input` are disallowed when using this option to enforce consistency and avoid confusion about how the `input` URL is handled, given that `input` will not follow the normal URL resolution rules when `prefixUrl` is being used, which changes the meaning of a leading slash.\n\n\t@example\n\t```\n\timport ky from 'ky';\n\n\t// On https://example.com\n\n\tconst response = await ky('unicorn', {prefixUrl: '/api'});\n\t//=> 'https://example.com/api/unicorn'\n\n\tconst response = await ky('unicorn', {prefixUrl: 'https://cats.com'});\n\t//=> 'https://cats.com/unicorn'\n\t```\n\t*/\n\tprefixUrl?: URL | string;\n\n\t/**\n\tAn object representing `limit`, `methods`, `statusCodes` and `maxRetryAfter` fields for maximum retry count, allowed methods, allowed status codes and maximum [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time.\n\n\tIf `retry` is a number, it will be used as `limit` and other defaults will remain in place.\n\n\tIf `maxRetryAfter` is set to `undefined`, it will use `options.timeout`. If [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than `maxRetryAfter`, it will cancel the request.\n\n\tBy default, delays between retries are calculated with the function `0.3 * (2 ** (attemptCount - 1)) * 1000`, where `attemptCount` is the attempt number (starts from 1), however this can be changed by passing a `delay` function.\n\n\tRetries are not triggered following a timeout.\n\n\t@example\n\t```\n\timport ky from 'ky';\n\n\tconst json = await ky('https://example.com', {\n\t\tretry: {\n\t\t\tlimit: 10,\n\t\t\tmethods: ['get'],\n\t\t\tstatusCodes: [413]\n\t\t}\n\t}).json();\n\t```\n\t*/\n\tretry?: RetryOptions | number;\n\n\t/**\n\tTimeout in milliseconds for getting a response, including any retries. Can not be greater than 2147483647.\n\tIf set to `false`, there will be no timeout.\n\n\t@default 10000\n\t*/\n\ttimeout?: number | false;\n\n\t/**\n\tHooks allow modifications during the request lifecycle. Hook functions may be async and are run serially.\n\t*/\n\thooks?: Hooks;\n\n\t/**\n\tThrow an `HTTPError` when, after following redirects, the response has a non-2xx status code. To also throw for redirects instead of following them, set the [`redirect`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters) option to `'manual'`.\n\n\tSetting this to `false` may be useful if you are checking for resource availability and are expecting error responses.\n\n\tNote: If `false`, error responses are considered successful and the request will not be retried.\n\n\t@default true\n\t*/\n\tthrowHttpErrors?: boolean;\n\n\t/**\n\tDownload progress event handler.\n\n\t@param chunk - Note: It's empty for the first call.\n\n\t@example\n\t```\n\timport ky from 'ky';\n\n\tconst response = await ky('https://example.com', {\n\t\tonDownloadProgress: (progress, chunk) => {\n\t\t\t// Example output:\n\t\t\t// `0% - 0 of 1271 bytes`\n\t\t\t// `100% - 1271 of 1271 bytes`\n\t\t\tconsole.log(`${progress.percent * 100}% - ${progress.transferredBytes} of ${progress.totalBytes} bytes`);\n\t\t}\n\t});\n\t```\n\t*/\n\tonDownloadProgress?: (progress: DownloadProgress, chunk: Uint8Array) => void;\n\n\t/**\n\tUser-defined `fetch` function.\n\tHas to be fully compatible with the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) standard.\n\n\tUse-cases:\n\t1. Use custom `fetch` implementations like [`isomorphic-unfetch`](https://www.npmjs.com/package/isomorphic-unfetch).\n\t2. Use the `fetch` wrapper function provided by some frameworks that use server-side rendering (SSR).\n\n\t@default fetch\n\n\t@example\n\t```\n\timport ky from 'ky';\n\timport fetch from 'isomorphic-unfetch';\n\n\tconst json = await ky('https://example.com', {fetch}).json();\n\t```\n\t*/\n\tfetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;\n}\n\nexport type InternalOptions = Required<\nOmit<Options, 'hooks' | 'retry'>,\n'credentials' | 'fetch' | 'prefixUrl' | 'timeout'\n> & {\n\theaders: Required<Headers>;\n\thooks: Required<Hooks>;\n\tretry: Required<RetryOptions>;\n\tprefixUrl: string;\n};\n\n/**\nNormalized options passed to the `fetch` call and the `beforeRequest` hooks.\n*/\nexport interface NormalizedOptions extends RequestInit { // eslint-disable-line @typescript-eslint/consistent-type-definitions -- This must stay an interface so that it can be extended outside of Ky for use in `ky.create`.\n\t// Extended from `RequestInit`, but ensured to be set (not optional).\n\tmethod: RequestInit['method'];\n\tcredentials: RequestInit['credentials'];\n\n\t// Extended from custom `KyOptions`, but ensured to be set (not optional).\n\tretry: RetryOptions;\n\tprefixUrl: string;\n\tonDownloadProgress: Options['onDownloadProgress'];\n}\n\nexport type {RetryOptions} from './retry.js';\n"]}
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../source/types/options.ts"],"names":[],"mappings":"","sourcesContent":["import type {LiteralUnion, Required} from './common.js';\nimport type {Hooks} from './hooks.js';\nimport type {RetryOptions} from './retry.js';\n\n// eslint-disable-next-line unicorn/prevent-abbreviations\nexport type SearchParamsInit = string | string[][] | Record<string, string> | URLSearchParams | undefined;\n\n// eslint-disable-next-line unicorn/prevent-abbreviations\nexport type SearchParamsOption = SearchParamsInit | Record<string, string | number | boolean> | Array<Array<string | number | boolean>>;\n\nexport type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete';\n\nexport type Input = string | URL | Request;\n\nexport type DownloadProgress = {\n\tpercent: number;\n\ttransferredBytes: number;\n\n\t/**\n\tNote: If it's not possible to retrieve the body size, it will be `0`.\n\t*/\n\ttotalBytes: number;\n};\n\nexport type KyHeadersInit = HeadersInit | Record<string, string | undefined>;\n\n/**\nCustom Ky options\n*/\n\nexport type KyOptions = {\n\t/**\n\tShortcut for sending JSON. Use this instead of the `body` option.\n\n\tAccepts any plain object or value, which will be `JSON.stringify()`'d and sent in the body with the correct header set.\n\t*/\n\tjson?: unknown;\n\n\t/**\n\tUser-defined JSON-parsing function.\n\n\tUse-cases:\n\t1. Parse JSON via the [`bourne` package](https://github.com/hapijs/bourne) to protect from prototype pollution.\n\t2. Parse JSON with [`reviver` option of `JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).\n\n\t@default JSON.parse()\n\n\t@example\n\t```\n\timport ky from 'ky';\n\timport bourne from '@hapijs/bourne';\n\n\tconst json = await ky('https://example.com', {\n\t\tparseJson: text => bourne(text)\n\t}).json();\n\t```\n\t*/\n\tparseJson?: (text: string) => unknown;\n\n\t/**\n\tSearch parameters to include in the request URL. Setting this will override all existing search parameters in the input URL.\n\n\tAccepts any value supported by [`URLSearchParams()`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams).\n\t*/\n\tsearchParams?: SearchParamsOption;\n\n\t/**\n\tA prefix to prepend to the `input` URL when making the request. It can be any valid URL, either relative or absolute. A trailing slash `/` is optional and will be added automatically, if needed, when it is joined with `input`. Only takes effect when `input` is a string. The `input` argument cannot start with a slash `/` when using this option.\n\n\tUseful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.\n\n\tNotes:\n\t - After `prefixUrl` and `input` are joined, the result is resolved against the [base URL](https://developer.mozilla.org/en-US/docs/Web/API/Node/baseURI) of the page (if any).\n\t - Leading slashes in `input` are disallowed when using this option to enforce consistency and avoid confusion about how the `input` URL is handled, given that `input` will not follow the normal URL resolution rules when `prefixUrl` is being used, which changes the meaning of a leading slash.\n\n\t@example\n\t```\n\timport ky from 'ky';\n\n\t// On https://example.com\n\n\tconst response = await ky('unicorn', {prefixUrl: '/api'});\n\t//=> 'https://example.com/api/unicorn'\n\n\tconst response = await ky('unicorn', {prefixUrl: 'https://cats.com'});\n\t//=> 'https://cats.com/unicorn'\n\t```\n\t*/\n\tprefixUrl?: URL | string;\n\n\t/**\n\tAn object representing `limit`, `methods`, `statusCodes` and `maxRetryAfter` fields for maximum retry count, allowed methods, allowed status codes and maximum [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time.\n\n\tIf `retry` is a number, it will be used as `limit` and other defaults will remain in place.\n\n\tIf `maxRetryAfter` is set to `undefined`, it will use `options.timeout`. If [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than `maxRetryAfter`, it will cancel the request.\n\n\tBy default, delays between retries are calculated with the function `0.3 * (2 ** (attemptCount - 1)) * 1000`, where `attemptCount` is the attempt number (starts from 1), however this can be changed by passing a `delay` function.\n\n\tRetries are not triggered following a timeout.\n\n\t@example\n\t```\n\timport ky from 'ky';\n\n\tconst json = await ky('https://example.com', {\n\t\tretry: {\n\t\t\tlimit: 10,\n\t\t\tmethods: ['get'],\n\t\t\tstatusCodes: [413]\n\t\t}\n\t}).json();\n\t```\n\t*/\n\tretry?: RetryOptions | number;\n\n\t/**\n\tTimeout in milliseconds for getting a response, including any retries. Can not be greater than 2147483647.\n\tIf set to `false`, there will be no timeout.\n\n\t@default 10000\n\t*/\n\ttimeout?: number | false;\n\n\t/**\n\tHooks allow modifications during the request lifecycle. Hook functions may be async and are run serially.\n\t*/\n\thooks?: Hooks;\n\n\t/**\n\tThrow an `HTTPError` when, after following redirects, the response has a non-2xx status code. To also throw for redirects instead of following them, set the [`redirect`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters) option to `'manual'`.\n\n\tSetting this to `false` may be useful if you are checking for resource availability and are expecting error responses.\n\n\tNote: If `false`, error responses are considered successful and the request will not be retried.\n\n\t@default true\n\t*/\n\tthrowHttpErrors?: boolean;\n\n\t/**\n\tDownload progress event handler.\n\n\t@param chunk - Note: It's empty for the first call.\n\n\t@example\n\t```\n\timport ky from 'ky';\n\n\tconst response = await ky('https://example.com', {\n\t\tonDownloadProgress: (progress, chunk) => {\n\t\t\t// Example output:\n\t\t\t// `0% - 0 of 1271 bytes`\n\t\t\t// `100% - 1271 of 1271 bytes`\n\t\t\tconsole.log(`${progress.percent * 100}% - ${progress.transferredBytes} of ${progress.totalBytes} bytes`);\n\t\t}\n\t});\n\t```\n\t*/\n\tonDownloadProgress?: (progress: DownloadProgress, chunk: Uint8Array) => void;\n\n\t/**\n\tUser-defined `fetch` function.\n\tHas to be fully compatible with the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) standard.\n\n\tUse-cases:\n\t1. Use custom `fetch` implementations like [`isomorphic-unfetch`](https://www.npmjs.com/package/isomorphic-unfetch).\n\t2. Use the `fetch` wrapper function provided by some frameworks that use server-side rendering (SSR).\n\n\t@default fetch\n\n\t@example\n\t```\n\timport ky from 'ky';\n\timport fetch from 'isomorphic-unfetch';\n\n\tconst json = await ky('https://example.com', {fetch}).json();\n\t```\n\t*/\n\tfetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;\n};\n\n/**\nEach key from KyOptions is present and set to `true`.\n\nThis type is used for identifying and working with the known keys in KyOptions.\n*/\nexport type KyOptionsRegistry = {[K in keyof KyOptions]-?: true};\n\n/**\nOptions are the same as `window.fetch`, except for the KyOptions\n*/\nexport interface Options extends KyOptions, Omit<RequestInit, 'headers'> { // eslint-disable-line @typescript-eslint/consistent-type-definitions -- This must stay an interface so that it can be extended outside of Ky for use in `ky.create`.\n\t/**\n\tHTTP method used to make the request.\n\n\tInternally, the standard methods (`GET`, `POST`, `PUT`, `PATCH`, `HEAD` and `DELETE`) are uppercased in order to avoid server errors due to case sensitivity.\n\t*/\n\tmethod?: LiteralUnion<HttpMethod, string>;\n\n\t/**\n\tHTTP headers used to make the request.\n\n\tYou can pass a `Headers` instance or a plain object.\n\n\tYou can remove a header with `.extend()` by passing the header with an `undefined` value.\n\n\t@example\n\t```\n\timport ky from 'ky';\n\n\tconst url = 'https://sindresorhus.com';\n\n\tconst original = ky.create({\n\t\theaders: {\n\t\t\trainbow: 'rainbow',\n\t\t\tunicorn: 'unicorn'\n\t\t}\n\t});\n\n\tconst extended = original.extend({\n\t\theaders: {\n\t\t\trainbow: undefined\n\t\t}\n\t});\n\n\tconst response = await extended(url).json();\n\n\tconsole.log('rainbow' in response);\n\t//=> false\n\n\tconsole.log('unicorn' in response);\n\t//=> true\n\t```\n\t*/\n\theaders?: KyHeadersInit;\n}\n\nexport type InternalOptions = Required<\nOmit<Options, 'hooks' | 'retry'>,\n'credentials' | 'fetch' | 'prefixUrl' | 'timeout'\n> & {\n\theaders: Required<Headers>;\n\thooks: Required<Hooks>;\n\tretry: Required<RetryOptions>;\n\tprefixUrl: string;\n};\n\n/**\nNormalized options passed to the `fetch` call and the `beforeRequest` hooks.\n*/\nexport interface NormalizedOptions extends RequestInit { // eslint-disable-line @typescript-eslint/consistent-type-definitions -- This must stay an interface so that it can be extended outside of Ky for use in `ky.create`.\n\t// Extended from `RequestInit`, but ensured to be set (not optional).\n\tmethod: RequestInit['method'];\n\tcredentials: RequestInit['credentials'];\n\n\t// Extended from custom `KyOptions`, but ensured to be set (not optional).\n\tretry: RetryOptions;\n\tprefixUrl: string;\n\tonDownloadProgress: Options['onDownloadProgress'];\n}\n\nexport type {RetryOptions} from './retry.js';\n"]}

@@ -5,2 +5,2 @@ export type TimeoutOptions = {

};
export default function timeout(request: Request, abortController: AbortController | undefined, options: TimeoutOptions): Promise<Response>;
export default function timeout(request: Request, init: RequestInit, abortController: AbortController | undefined, options: TimeoutOptions): Promise<Response>;
import { TimeoutError } from '../errors/TimeoutError.js';
// `Promise.race()` workaround (#91)
export default async function timeout(request, abortController, options) {
export default async function timeout(request, init, abortController, options) {
return new Promise((resolve, reject) => {

@@ -12,3 +12,3 @@ const timeoutId = setTimeout(() => {

void options
.fetch(request)
.fetch(request, init)
.then(resolve)

@@ -15,0 +15,0 @@ .catch(reject)

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

{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../source/utils/timeout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAOvD,oCAAoC;AACpC,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,OAAO,CACpC,OAAgB,EAChB,eAA4C,EAC5C,OAAuB;IAEvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YACjC,IAAI,eAAe,EAAE;gBACpB,eAAe,CAAC,KAAK,EAAE,CAAC;aACxB;YAED,MAAM,CAAC,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;QACnC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpB,KAAK,OAAO;aACV,KAAK,CAAC,OAAO,CAAC;aACd,IAAI,CAAC,OAAO,CAAC;aACb,KAAK,CAAC,MAAM,CAAC;aACb,IAAI,CAAC,GAAG,EAAE;YACV,YAAY,CAAC,SAAS,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {TimeoutError} from '../errors/TimeoutError.js';\n\nexport type TimeoutOptions = {\n\ttimeout: number;\n\tfetch: typeof fetch;\n};\n\n// `Promise.race()` workaround (#91)\nexport default async function timeout(\n\trequest: Request,\n\tabortController: AbortController | undefined,\n\toptions: TimeoutOptions,\n): Promise<Response> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst timeoutId = setTimeout(() => {\n\t\t\tif (abortController) {\n\t\t\t\tabortController.abort();\n\t\t\t}\n\n\t\t\treject(new TimeoutError(request));\n\t\t}, options.timeout);\n\n\t\tvoid options\n\t\t\t.fetch(request)\n\t\t\t.then(resolve)\n\t\t\t.catch(reject)\n\t\t\t.then(() => {\n\t\t\t\tclearTimeout(timeoutId);\n\t\t\t});\n\t});\n}\n"]}
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../source/utils/timeout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAOvD,oCAAoC;AACpC,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,OAAO,CACpC,OAAgB,EAChB,IAAiB,EACjB,eAA4C,EAC5C,OAAuB;IAEvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YACjC,IAAI,eAAe,EAAE;gBACpB,eAAe,CAAC,KAAK,EAAE,CAAC;aACxB;YAED,MAAM,CAAC,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;QACnC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpB,KAAK,OAAO;aACV,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC;aACpB,IAAI,CAAC,OAAO,CAAC;aACb,KAAK,CAAC,MAAM,CAAC;aACb,IAAI,CAAC,GAAG,EAAE;YACV,YAAY,CAAC,SAAS,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {TimeoutError} from '../errors/TimeoutError.js';\n\nexport type TimeoutOptions = {\n\ttimeout: number;\n\tfetch: typeof fetch;\n};\n\n// `Promise.race()` workaround (#91)\nexport default async function timeout(\n\trequest: Request,\n\tinit: RequestInit,\n\tabortController: AbortController | undefined,\n\toptions: TimeoutOptions,\n): Promise<Response> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst timeoutId = setTimeout(() => {\n\t\t\tif (abortController) {\n\t\t\t\tabortController.abort();\n\t\t\t}\n\n\t\t\treject(new TimeoutError(request));\n\t\t}, options.timeout);\n\n\t\tvoid options\n\t\t\t.fetch(request, init)\n\t\t\t.then(resolve)\n\t\t\t.catch(reject)\n\t\t\t.then(() => {\n\t\t\t\tclearTimeout(timeoutId);\n\t\t\t});\n\t});\n}\n"]}
{
"name": "ky",
"version": "1.1.0",
"version": "1.1.1",
"description": "Tiny and elegant HTTP client based on the browser Fetch API",

@@ -5,0 +5,0 @@ "license": "MIT",