Comparing version 0.28.5 to 0.28.6
@@ -1,14 +0,13 @@ | ||
import { HTTPMethod } from '../types/options.js'; | ||
export declare const supportsAbortController: boolean; | ||
export declare const supportsStreams: boolean; | ||
export declare const supportsFormData: boolean; | ||
export declare const requestMethods: readonly HTTPMethod[]; | ||
export declare const requestMethods: readonly ["get", "post", "put", "patch", "head", "delete"]; | ||
export declare const responseTypes: { | ||
json: string; | ||
text: string; | ||
formData: string; | ||
arrayBuffer: string; | ||
blob: string; | ||
readonly json: "application/json"; | ||
readonly text: "text/*"; | ||
readonly formData: "multipart/form-data"; | ||
readonly arrayBuffer: "*/*"; | ||
readonly blob: "*/*"; | ||
}; | ||
export declare const maxSafeTimeout = 2147483647; | ||
export declare const stop: unique symbol; |
@@ -5,2 +5,4 @@ export const supportsAbortController = typeof globalThis.AbortController === 'function'; | ||
export const requestMethods = ['get', 'post', 'put', 'patch', 'head', 'delete']; | ||
const validate = () => undefined; | ||
validate(); | ||
export const responseTypes = { | ||
@@ -7,0 +9,0 @@ json: 'application/json', |
@@ -11,3 +11,3 @@ import type { Input, InternalOptions, Options } from '../types/options.js'; | ||
static create(input: Input, options: Options): ResponsePromise; | ||
protected _calculateRetryDelay(error: Error): number; | ||
protected _calculateRetryDelay(error: unknown): number; | ||
protected _decorateResponse(response: Response): Response; | ||
@@ -14,0 +14,0 @@ protected _retry<T extends (...args: any) => Promise<any>>(fn: T): Promise<ReturnType<T> | void>; |
@@ -109,5 +109,4 @@ import { HTTPError } from '../errors/HTTPError.js'; | ||
const isRetriableMethod = ky._options.retry.methods.includes(ky.request.method.toLowerCase()); | ||
const result = isRetriableMethod ? ky._retry(fn) : fn(); | ||
const result = (isRetriableMethod ? ky._retry(fn) : fn()); | ||
for (const [type, mimeType] of Object.entries(responseTypes)) { | ||
// @ts-expect-error not sure how to properly type this! | ||
result[type] = async () => { | ||
@@ -125,3 +124,2 @@ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
} | ||
// @ts-expect-error not sure how to properly type this! | ||
return response[type](); | ||
@@ -180,3 +178,2 @@ }; | ||
for (const hook of this._options.hooks.beforeRetry) { | ||
// @ts-expect-error TODO missing response? | ||
// eslint-disable-next-line no-await-in-loop | ||
@@ -186,3 +183,3 @@ const hookResult = await hook({ | ||
options: this._options, | ||
error, | ||
error: error, | ||
retryCount: this._retryCount | ||
@@ -189,0 +186,0 @@ }); |
@@ -9,3 +9,2 @@ /*! MIT License © Sindre Sorhus */ | ||
for (const method of requestMethods) { | ||
// @ts-expect-error not sure how to properly type this! | ||
// eslint-disable-next-line @typescript-eslint/promise-function-async | ||
@@ -12,0 +11,0 @@ ky[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method })); |
@@ -6,3 +6,2 @@ import { stop } from '../core/constants.js'; | ||
request: Request; | ||
response: Response; | ||
options: NormalizedOptions; | ||
@@ -9,0 +8,0 @@ error: Error; |
@@ -6,2 +6,19 @@ import { stop } from '../core/constants.js'; | ||
/** | ||
Fetch the given `url`. | ||
@param url - `Request` object, `URL` object, or URL string. | ||
@returns A promise with `Body` method added. | ||
@example | ||
``` | ||
import ky from 'ky'; | ||
const json = await ky('https://example.com', {json: {foo: true}}).json(); | ||
console.log(json); | ||
//=> `{data: '🦄'}` | ||
``` | ||
*/ | ||
(url: Input, options?: Options): ResponsePromise; | ||
/** | ||
Fetch the given `url` using the option `{method: 'get'}`. | ||
@@ -94,19 +111,2 @@ | ||
readonly stop: typeof stop; | ||
/** | ||
Fetch the given `url`. | ||
@param url - `Request` object, `URL` object, or URL string. | ||
@returns A promise with `Body` method added. | ||
@example | ||
``` | ||
import ky from 'ky'; | ||
const json = await ky('https://example.com', {json: {foo: true}}).json(); | ||
console.log(json); | ||
//=> `{data: '🦄'}` | ||
``` | ||
*/ | ||
(url: Input, options?: Options): ResponsePromise; | ||
} |
@@ -157,2 +157,4 @@ import type { LiteralUnion, Required } from './common.js'; | ||
Note: If `false`, error responses are considered successful and the request will not be retried. | ||
@default true | ||
@@ -159,0 +161,0 @@ */ |
{ | ||
"name": "ky", | ||
"version": "0.28.5", | ||
"version": "0.28.6", | ||
"description": "Tiny and elegant HTTP client based on the browser Fetch API", | ||
@@ -54,2 +54,3 @@ "license": "MIT", | ||
"@sindresorhus/tsconfig": "^1.0.2", | ||
"@type-challenges/utils": "^0.1.1", | ||
"@types/body-parser": "^1.19.0", | ||
@@ -73,3 +74,3 @@ "@types/busboy": "^0.2.3", | ||
"ts-node": "^10.0.0", | ||
"typescript": "^4.3.2", | ||
"typescript": "^4.4.3", | ||
"xo": "^0.39.0" | ||
@@ -76,0 +77,0 @@ }, |
@@ -242,3 +242,3 @@ <div align="center"> | ||
You can prevent Ky from retrying the request by throwing an error. Ky will not handle it in any way and the error will be propagated to the request initiator. The rest of the `beforeRetry` hooks will not be called in this case. Alternatively, you can return the [`ky.stop`](#ky.stop) symbol to do the same thing but without propagating an error (this has some limitations, see `ky.stop` docs for details). | ||
You can prevent Ky from retrying the request by throwing an error. Ky will not handle it in any way and the error will be propagated to the request initiator. The rest of the `beforeRetry` hooks will not be called in this case. Alternatively, you can return the [`ky.stop`](#kystop) symbol to do the same thing but without propagating an error (this has some limitations, see `ky.stop` docs for details). | ||
@@ -307,2 +307,4 @@ ```js | ||
Note: If `false`, error responses are considered successful and the request will not be retried. | ||
##### onDownloadProgress | ||
@@ -542,7 +544,7 @@ | ||
Upload the [`index.js`](index.js) file in this repo somewhere, for example, to your website server, or use a CDN version. Then import the file. | ||
Make sure your code is running as a JavaScript module (ESM), for example by using a `<script type="module">` tag in your HTML document. Then Ky can be imported directly by that module without a bundler or other tools. | ||
```html | ||
<script type="module"> | ||
import ky from 'https://cdn.jsdelivr.net/npm/ky@latest/index.js'; | ||
import ky from 'https://unpkg.com/ky/distribution/index.js'; | ||
@@ -549,0 +551,0 @@ const json = await ky('https://jsonplaceholder.typicode.com/todos/1').json(); |
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
82479
51
881
592
22