Skip to content

Commit 9f06060

Browse files
committed
Upgrade dependencies
1 parent 36cf6a8 commit 9f06060

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+203
-180
lines changed

.github/workflows/main.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ jobs:
1818
- macos-latest
1919
- windows-latest
2020
steps:
21-
- uses: actions/checkout@v2
22-
- uses: actions/setup-node@v2
21+
- uses: actions/checkout@v3
22+
- uses: actions/setup-node@v3
2323
with:
2424
node-version: ${{ matrix.node-version }}
2525
- run: npm install
2626
- run: npm test
27-
# - uses: codecov/codecov-action@v2
27+
# - uses: codecov/codecov-action@v3
2828
# if: matrix.os == 'ubuntu-latest' && matrix.node-version == 16
2929
# with:
3030
# fail_ci_if_error: true

benchmark/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import fetch from 'node-fetch';
66
import request from 'request';
77
import got from '../source/index.js';
88
import Request from '../source/core/index.js';
9-
import Options, {OptionsInit} from '../source/core/options.js';
9+
import Options, {type OptionsInit} from '../source/core/options.js';
1010

1111
// Configuration
1212
const httpsAgent = new https.Agent({

benchmark/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {AddressInfo} from 'node:net';
1+
import type {AddressInfo} from 'node:net';
22
import https from 'node:https';
33
// @ts-expect-error No types
44
import createCert from 'create-cert';

package.json

+6-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"@sindresorhus/is": "^5.2.0",
4949
"@szmarczak/http-timer": "^5.0.1",
5050
"@types/cacheable-request": "^6.0.2",
51-
"@types/responselike": "^1.0.0",
5251
"cacheable-lookup": "^6.0.4",
5352
"cacheable-request": "^7.0.2",
5453
"decompress-response": "^6.0.0",
@@ -57,15 +56,15 @@
5756
"http2-wrapper": "^2.1.10",
5857
"lowercase-keys": "^3.0.0",
5958
"p-cancelable": "^3.0.0",
60-
"responselike": "^2.0.0"
59+
"responselike": "^3.0.0"
6160
},
6261
"devDependencies": {
6362
"@hapi/bourne": "^3.0.0",
6463
"@sindresorhus/tsconfig": "^2.0.0",
6564
"@sinonjs/fake-timers": "^9.1.1",
66-
"@types/benchmark": "^2.1.1",
65+
"@types/benchmark": "^2.1.2",
6766
"@types/express": "^4.17.13",
68-
"@types/node": "^18.0.1",
67+
"@types/node": "^18.7.13",
6968
"@types/pem": "^1.9.6",
7069
"@types/pify": "^5.0.1",
7170
"@types/readable-stream": "^2.3.13",
@@ -80,7 +79,7 @@
8079
"body-parser": "^1.19.2",
8180
"create-cert": "^1.0.6",
8281
"create-test-server": "^3.0.1",
83-
"del-cli": "^4.0.1",
82+
"del-cli": "^5.0.0",
8483
"delay": "^5.0.0",
8584
"express": "^4.17.3",
8685
"form-data": "^4.0.0",
@@ -101,8 +100,8 @@
101100
"to-readable-stream": "^3.0.0",
102101
"tough-cookie": "4.0.0",
103102
"ts-node": "^10.8.2",
104-
"typescript": "^4.7.4",
105-
"xo": "^0.50.0"
103+
"typescript": "~4.8.2",
104+
"xo": "^0.52.2"
106105
},
107106
"sideEffects": false,
108107
"ava": {

source/as-promise/index.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ import {EventEmitter} from 'node:events';
22
import is from '@sindresorhus/is';
33
import PCancelable from 'p-cancelable';
44
import {
5-
RequestError,
65
HTTPError,
76
RetryError,
7+
type RequestError,
88
} from '../core/errors.js';
99
import Request from '../core/index.js';
10-
import {parseBody, isResponseOk} from '../core/response.js';
10+
import {parseBody, isResponseOk, type Response} from '../core/response.js';
1111
import proxyEvents from '../core/utils/proxy-events.js';
1212
import type Options from '../core/options.js';
13-
import type {Response} from '../core/response.js';
14-
import {CancelError} from './types.js';
15-
import type {CancelableRequest} from './types.js';
13+
import {CancelError, type CancelableRequest} from './types.js';
1614

1715
const proxiedRequestEvents = [
1816
'request',

source/as-promise/types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {Buffer} from 'node:buffer';
2-
import PCancelable from 'p-cancelable';
2+
import type PCancelable from 'p-cancelable';
33
import {RequestError} from '../core/errors.js';
44
import type Request from '../core/index.js';
55
import type {RequestEvents} from '../core/index.js';
@@ -25,6 +25,8 @@ export class CancelError extends RequestError {
2525
}
2626
}
2727

28+
// TODO: Make this a `type`.
29+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- TS cannot handle this being a `type` for some reason.
2830
export interface CancelableRequest<T extends Response | Response['body'] = Response['body']> extends PCancelable<T>, RequestEvents<CancelableRequest<T>> {
2931
/**
3032
A shortcut method that gives a Promise returning a JSON object.

source/core/index.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import process from 'node:process';
22
import {Buffer} from 'node:buffer';
3-
import {Duplex, Readable} from 'node:stream';
3+
import {Duplex, type Readable} from 'node:stream';
44
import {URL, URLSearchParams} from 'node:url';
55
import http, {ServerResponse} from 'node:http';
66
import type {ClientRequest, RequestOptions} from 'node:http';
@@ -20,8 +20,14 @@ import timedOut, {TimeoutError as TimedOutTimeoutError} from './timed-out.js';
2020
import urlToOptions from './utils/url-to-options.js';
2121
import WeakableMap from './utils/weakable-map.js';
2222
import calculateRetryDelay from './calculate-retry-delay.js';
23-
import Options, {OptionsError, OptionsInit} from './options.js';
24-
import {isResponseOk, Response} from './response.js';
23+
import Options, {
24+
type PromiseCookieJar,
25+
type NativeRequestOptions,
26+
type RetryOptions,
27+
type OptionsError,
28+
type OptionsInit,
29+
} from './options.js';
30+
import {isResponseOk, type PlainResponse, type Response} from './response.js';
2531
import isClientRequest from './utils/is-client-request.js';
2632
import isUnixSocketURL from './utils/is-unix-socket-url.js';
2733
import {
@@ -34,16 +40,14 @@ import {
3440
CacheError,
3541
AbortError,
3642
} from './errors.js';
37-
import type {PlainResponse} from './response.js';
38-
import type {PromiseCookieJar, NativeRequestOptions, RetryOptions} from './options.js';
3943

4044
type Error = NodeJS.ErrnoException;
4145

42-
export interface Progress {
46+
export type Progress = {
4347
percent: number;
4448
transferred: number;
4549
total?: number;
46-
}
50+
};
4751

4852
const supportsBrotli = is.string(process.versions.brotli);
4953

@@ -114,11 +118,11 @@ export type GotEventFunction<T> =
114118
*/
115119
& ((name: 'retry', listener: (retryCount: number, error: RequestError) => void) => T);
116120

117-
export interface RequestEvents<T> {
121+
export type RequestEvents<T> = {
118122
on: GotEventFunction<T>;
119123
once: GotEventFunction<T>;
120124
off: GotEventFunction<T>;
121-
}
125+
};
122126

123127
export type CacheableRequestFunction = (
124128
options: string | URL | NativeRequestOptions,

source/core/options.ts

+27-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import process from 'node:process';
2-
import {Buffer} from 'node:buffer';
2+
import type {Buffer} from 'node:buffer';
33
import {promisify, inspect} from 'node:util';
44
import {URL, URLSearchParams} from 'node:url';
55
import {checkServerIdentity} from 'node:tls';
@@ -21,7 +21,7 @@ import type {InspectOptions} from 'node:util';
2121
import is, {assert} from '@sindresorhus/is';
2222
import lowercaseKeys from 'lowercase-keys';
2323
import CacheableLookup from 'cacheable-lookup';
24-
import http2wrapper, {ClientHttp2Session} from 'http2-wrapper';
24+
import http2wrapper, {type ClientHttp2Session} from 'http2-wrapper';
2525
import {isFormData} from 'form-data-encoder';
2626
import type {FormDataLike} from 'form-data-encoder';
2727
import type CacheableRequest from 'cacheable-request';
@@ -47,25 +47,25 @@ type AcceptableResponse = IncomingMessageWithTimings | ResponseLike;
4747
type AcceptableRequestResult = Promisable<AcceptableResponse | ClientRequest> | undefined;
4848
export type RequestFunction = (url: URL, options: NativeRequestOptions, callback?: (response: AcceptableResponse) => void) => AcceptableRequestResult;
4949

50-
export interface Agents {
50+
export type Agents = {
5151
http?: HttpAgent | false;
5252
https?: HttpsAgent | false;
5353
http2?: unknown | false;
54-
}
54+
};
5555

5656
export type Headers = Record<string, string | string[] | undefined>;
5757

58-
export interface ToughCookieJar {
58+
export type ToughCookieJar = {
5959
getCookieString: ((currentUrl: string, options: Record<string, unknown>, cb: (error: Error | null, cookies: string) => void) => void) // eslint-disable-line @typescript-eslint/ban-types
6060
& ((url: string, callback: (error: Error | null, cookieHeader: string) => void) => void); // eslint-disable-line @typescript-eslint/ban-types
6161
setCookie: ((cookieOrString: unknown, currentUrl: string, options: Record<string, unknown>, cb: (error: Error | null, cookie: unknown) => void) => void) // eslint-disable-line @typescript-eslint/ban-types
6262
& ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void); // eslint-disable-line @typescript-eslint/ban-types
63-
}
63+
};
6464

65-
export interface PromiseCookieJar {
65+
export type PromiseCookieJar = {
6666
getCookieString: (url: string) => Promise<string>;
6767
setCookie: (rawCookie: string, url: string) => Promise<unknown>;
68-
}
68+
};
6969

7070
export type InitHook = (init: OptionsInit, self: Options) => void;
7171
export type BeforeRequestHook = (options: Options) => Promisable<void | Response | ResponseLike>;
@@ -77,7 +77,7 @@ export type AfterResponseHook<ResponseType = unknown> = (response: Response<Resp
7777
/**
7878
All available hooks of Got.
7979
*/
80-
export interface Hooks {
80+
export type Hooks = {
8181
/**
8282
Called with the plain request options, right before their normalization.
8383
@@ -350,7 +350,7 @@ export interface Hooks {
350350
```
351351
*/
352352
afterResponse: AfterResponseHook[];
353-
}
353+
};
354354

355355
export type ParseJsonFunction = (text: string) => unknown;
356356
export type StringifyJsonFunction = (object: unknown) => string;
@@ -376,13 +376,13 @@ export type Method =
376376
| 'options'
377377
| 'trace';
378378

379-
export interface RetryObject {
379+
export type RetryObject = {
380380
attemptCount: number;
381381
retryOptions: RetryOptions;
382382
error: RequestError;
383383
computedValue: number;
384384
retryAfter?: number;
385-
}
385+
};
386386

387387
export type RetryFunction = (retryObject: RetryObject) => Promisable<number>;
388388

@@ -408,7 +408,7 @@ __Note:__ Got does not retry on `POST` by default.
408408
__Note:__ If `maxRetryAfter` is set to `undefined`, it will use `options.timeout`.
409409
__Note:__ 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.
410410
*/
411-
export interface RetryOptions {
411+
export type RetryOptions = {
412412
limit: number;
413413
methods: Method[];
414414
statusCodes: number[];
@@ -417,17 +417,17 @@ export interface RetryOptions {
417417
backoffLimit: number;
418418
noise: number;
419419
maxRetryAfter?: number;
420-
}
420+
};
421421

422422
export type CreateConnectionFunction = (options: NativeRequestOptions, oncreate: (error: NodeJS.ErrnoException, socket: Socket) => void) => Socket;
423423
export type CheckServerIdentityFunction = (hostname: string, certificate: DetailedPeerCertificate) => NodeJS.ErrnoException | void;
424424

425-
export interface CacheOptions {
425+
export type CacheOptions = {
426426
shared?: boolean;
427427
cacheHeuristic?: number;
428428
immutableMinTimeToLive?: number;
429429
ignoreCargoCult?: boolean;
430-
}
430+
};
431431

432432
type PfxObject = {
433433
buffer: string | Buffer;
@@ -436,7 +436,7 @@ type PfxObject = {
436436

437437
type PfxType = string | Buffer | Array<string | Buffer | PfxObject> | undefined;
438438

439-
export interface HttpsOptions {
439+
export type HttpsOptions = {
440440
alpnProtocols?: string[];
441441

442442
// From `http.RequestOptions` and `tls.CommonConnectionOptions`
@@ -497,24 +497,24 @@ export interface HttpsOptions {
497497
dhparam?: SecureContextOptions['dhparam'];
498498
ecdhCurve?: SecureContextOptions['ecdhCurve'];
499499
certificateRevocationLists?: SecureContextOptions['crl'];
500-
}
500+
};
501501

502-
export interface PaginateData<BodyType, ElementType> {
502+
export type PaginateData<BodyType, ElementType> = {
503503
response: Response<BodyType>;
504504
currentItems: ElementType[];
505505
allItems: ElementType[];
506-
}
506+
};
507507

508-
export interface FilterData<ElementType> {
508+
export type FilterData<ElementType> = {
509509
item: ElementType;
510510
currentItems: ElementType[];
511511
allItems: ElementType[];
512-
}
512+
};
513513

514514
/**
515515
All options accepted by `got.paginate()`.
516516
*/
517-
export interface PaginationOptions<ElementType, BodyType> {
517+
export type PaginationOptions<ElementType, BodyType> = {
518518
/**
519519
A function that transform [`Response`](#response) into an array of items.
520520
This is where you should do the parsing.
@@ -619,7 +619,7 @@ export interface PaginationOptions<ElementType, BodyType> {
619619
@default false
620620
*/
621621
stackAllItems?: boolean;
622-
}
622+
};
623623

624624
export type SearchParameters = Record<string, string | number | boolean | null | undefined>; // eslint-disable-line @typescript-eslint/ban-types
625625

@@ -1142,6 +1142,7 @@ export default class Options {
11421142
throw new TypeError(`Unexpected agent option: ${key}`);
11431143
}
11441144

1145+
// @ts-expect-error - No idea why `value[key]` doesn't work here.
11451146
assert.any([is.object, is.undefined], value[key]);
11461147
}
11471148

@@ -1210,6 +1211,7 @@ export default class Options {
12101211
throw new Error(`Unexpected timeout option: ${key}`);
12111212
}
12121213

1214+
// @ts-expect-error - No idea why `value[key]` doesn't work here.
12131215
assert.any([is.number, is.undefined], value[key]);
12141216
}
12151217

@@ -1732,8 +1734,7 @@ export default class Options {
17321734
}
17331735

17341736
const typedKnownHookEvent = knownHookEvent as keyof Hooks;
1735-
const typedValue = value as Hooks;
1736-
const hooks = typedValue[typedKnownHookEvent];
1737+
const hooks = value[typedKnownHookEvent];
17371738

17381739
assert.any([is.array, is.undefined], hooks);
17391740

source/core/response.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {RequestError} from './errors.js';
55
import type {ParseJsonFunction, ResponseType} from './options.js';
66
import type Request from './index.js';
77

8-
export interface PlainResponse extends IncomingMessageWithTimings {
8+
export type PlainResponse = {
99
/**
1010
The original request URL.
1111
*/
@@ -98,10 +98,10 @@ export interface PlainResponse extends IncomingMessageWithTimings {
9898
__Note__: Got throws automatically when `response.ok` is `false` and `throwHttpErrors` is `true`.
9999
*/
100100
ok: boolean;
101-
}
101+
} & IncomingMessageWithTimings;
102102

103103
// For Promise support
104-
export interface Response<T = unknown> extends PlainResponse {
104+
export type Response<T = unknown> = {
105105
/**
106106
The result of the request.
107107
*/
@@ -111,7 +111,7 @@ export interface Response<T = unknown> extends PlainResponse {
111111
The raw result of the request.
112112
*/
113113
rawBody: Buffer;
114-
}
114+
} & PlainResponse;
115115

116116
export const isResponseOk = (response: PlainResponse): boolean => {
117117
const {statusCode} = response;

0 commit comments

Comments
 (0)