Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 30, 2022
1 parent 36cf6a8 commit 9f06060
Show file tree
Hide file tree
Showing 51 changed files with 203 additions and 180 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
# - uses: codecov/codecov-action@v2
# - uses: codecov/codecov-action@v3
# if: matrix.os == 'ubuntu-latest' && matrix.node-version == 16
# with:
# fail_ci_if_error: true
2 changes: 1 addition & 1 deletion benchmark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fetch from 'node-fetch';
import request from 'request';
import got from '../source/index.js';
import Request from '../source/core/index.js';
import Options, {OptionsInit} from '../source/core/options.js';
import Options, {type OptionsInit} from '../source/core/options.js';

// Configuration
const httpsAgent = new https.Agent({
Expand Down
2 changes: 1 addition & 1 deletion benchmark/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AddressInfo} from 'node:net';
import type {AddressInfo} from 'node:net';
import https from 'node:https';
// @ts-expect-error No types
import createCert from 'create-cert';
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"@sindresorhus/is": "^5.2.0",
"@szmarczak/http-timer": "^5.0.1",
"@types/cacheable-request": "^6.0.2",
"@types/responselike": "^1.0.0",
"cacheable-lookup": "^6.0.4",
"cacheable-request": "^7.0.2",
"decompress-response": "^6.0.0",
Expand All @@ -57,15 +56,15 @@
"http2-wrapper": "^2.1.10",
"lowercase-keys": "^3.0.0",
"p-cancelable": "^3.0.0",
"responselike": "^2.0.0"
"responselike": "^3.0.0"
},
"devDependencies": {
"@hapi/bourne": "^3.0.0",
"@sindresorhus/tsconfig": "^2.0.0",
"@sinonjs/fake-timers": "^9.1.1",
"@types/benchmark": "^2.1.1",
"@types/benchmark": "^2.1.2",
"@types/express": "^4.17.13",
"@types/node": "^18.0.1",
"@types/node": "^18.7.13",
"@types/pem": "^1.9.6",
"@types/pify": "^5.0.1",
"@types/readable-stream": "^2.3.13",
Expand All @@ -80,7 +79,7 @@
"body-parser": "^1.19.2",
"create-cert": "^1.0.6",
"create-test-server": "^3.0.1",
"del-cli": "^4.0.1",
"del-cli": "^5.0.0",
"delay": "^5.0.0",
"express": "^4.17.3",
"form-data": "^4.0.0",
Expand All @@ -101,8 +100,8 @@
"to-readable-stream": "^3.0.0",
"tough-cookie": "4.0.0",
"ts-node": "^10.8.2",
"typescript": "^4.7.4",
"xo": "^0.50.0"
"typescript": "~4.8.2",
"xo": "^0.52.2"
},
"sideEffects": false,
"ava": {
Expand Down
8 changes: 3 additions & 5 deletions source/as-promise/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import {EventEmitter} from 'node:events';
import is from '@sindresorhus/is';
import PCancelable from 'p-cancelable';
import {
RequestError,
HTTPError,
RetryError,
type RequestError,
} from '../core/errors.js';
import Request from '../core/index.js';
import {parseBody, isResponseOk} from '../core/response.js';
import {parseBody, isResponseOk, type Response} from '../core/response.js';
import proxyEvents from '../core/utils/proxy-events.js';
import type Options from '../core/options.js';
import type {Response} from '../core/response.js';
import {CancelError} from './types.js';
import type {CancelableRequest} from './types.js';
import {CancelError, type CancelableRequest} from './types.js';

const proxiedRequestEvents = [
'request',
Expand Down
4 changes: 3 additions & 1 deletion source/as-promise/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {Buffer} from 'node:buffer';
import PCancelable from 'p-cancelable';
import type PCancelable from 'p-cancelable';
import {RequestError} from '../core/errors.js';
import type Request from '../core/index.js';
import type {RequestEvents} from '../core/index.js';
Expand All @@ -25,6 +25,8 @@ export class CancelError extends RequestError {
}
}

// TODO: Make this a `type`.
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- TS cannot handle this being a `type` for some reason.
export interface CancelableRequest<T extends Response | Response['body'] = Response['body']> extends PCancelable<T>, RequestEvents<CancelableRequest<T>> {
/**
A shortcut method that gives a Promise returning a JSON object.
Expand Down
22 changes: 13 additions & 9 deletions source/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import process from 'node:process';
import {Buffer} from 'node:buffer';
import {Duplex, Readable} from 'node:stream';
import {Duplex, type Readable} from 'node:stream';
import {URL, URLSearchParams} from 'node:url';
import http, {ServerResponse} from 'node:http';
import type {ClientRequest, RequestOptions} from 'node:http';
Expand All @@ -20,8 +20,14 @@ import timedOut, {TimeoutError as TimedOutTimeoutError} from './timed-out.js';
import urlToOptions from './utils/url-to-options.js';
import WeakableMap from './utils/weakable-map.js';
import calculateRetryDelay from './calculate-retry-delay.js';
import Options, {OptionsError, OptionsInit} from './options.js';
import {isResponseOk, Response} from './response.js';
import Options, {
type PromiseCookieJar,
type NativeRequestOptions,
type RetryOptions,
type OptionsError,
type OptionsInit,
} from './options.js';
import {isResponseOk, type PlainResponse, type Response} from './response.js';
import isClientRequest from './utils/is-client-request.js';
import isUnixSocketURL from './utils/is-unix-socket-url.js';
import {
Expand All @@ -34,16 +40,14 @@ import {
CacheError,
AbortError,
} from './errors.js';
import type {PlainResponse} from './response.js';
import type {PromiseCookieJar, NativeRequestOptions, RetryOptions} from './options.js';

type Error = NodeJS.ErrnoException;

export interface Progress {
export type Progress = {
percent: number;
transferred: number;
total?: number;
}
};

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

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

export interface RequestEvents<T> {
export type RequestEvents<T> = {
on: GotEventFunction<T>;
once: GotEventFunction<T>;
off: GotEventFunction<T>;
}
};

export type CacheableRequestFunction = (
options: string | URL | NativeRequestOptions,
Expand Down
53 changes: 27 additions & 26 deletions source/core/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import process from 'node:process';
import {Buffer} from 'node:buffer';
import type {Buffer} from 'node:buffer';
import {promisify, inspect} from 'node:util';
import {URL, URLSearchParams} from 'node:url';
import {checkServerIdentity} from 'node:tls';
Expand All @@ -21,7 +21,7 @@ import type {InspectOptions} from 'node:util';
import is, {assert} from '@sindresorhus/is';
import lowercaseKeys from 'lowercase-keys';
import CacheableLookup from 'cacheable-lookup';
import http2wrapper, {ClientHttp2Session} from 'http2-wrapper';
import http2wrapper, {type ClientHttp2Session} from 'http2-wrapper';
import {isFormData} from 'form-data-encoder';
import type {FormDataLike} from 'form-data-encoder';
import type CacheableRequest from 'cacheable-request';
Expand All @@ -47,25 +47,25 @@ type AcceptableResponse = IncomingMessageWithTimings | ResponseLike;
type AcceptableRequestResult = Promisable<AcceptableResponse | ClientRequest> | undefined;
export type RequestFunction = (url: URL, options: NativeRequestOptions, callback?: (response: AcceptableResponse) => void) => AcceptableRequestResult;

export interface Agents {
export type Agents = {
http?: HttpAgent | false;
https?: HttpsAgent | false;
http2?: unknown | false;
}
};

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

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

export interface PromiseCookieJar {
export type PromiseCookieJar = {
getCookieString: (url: string) => Promise<string>;
setCookie: (rawCookie: string, url: string) => Promise<unknown>;
}
};

export type InitHook = (init: OptionsInit, self: Options) => void;
export type BeforeRequestHook = (options: Options) => Promisable<void | Response | ResponseLike>;
Expand All @@ -77,7 +77,7 @@ export type AfterResponseHook<ResponseType = unknown> = (response: Response<Resp
/**
All available hooks of Got.
*/
export interface Hooks {
export type Hooks = {
/**
Called with the plain request options, right before their normalization.
Expand Down Expand Up @@ -350,7 +350,7 @@ export interface Hooks {
```
*/
afterResponse: AfterResponseHook[];
}
};

export type ParseJsonFunction = (text: string) => unknown;
export type StringifyJsonFunction = (object: unknown) => string;
Expand All @@ -376,13 +376,13 @@ export type Method =
| 'options'
| 'trace';

export interface RetryObject {
export type RetryObject = {
attemptCount: number;
retryOptions: RetryOptions;
error: RequestError;
computedValue: number;
retryAfter?: number;
}
};

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

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

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

export interface CacheOptions {
export type CacheOptions = {
shared?: boolean;
cacheHeuristic?: number;
immutableMinTimeToLive?: number;
ignoreCargoCult?: boolean;
}
};

type PfxObject = {
buffer: string | Buffer;
Expand All @@ -436,7 +436,7 @@ type PfxObject = {

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

export interface HttpsOptions {
export type HttpsOptions = {
alpnProtocols?: string[];

// From `http.RequestOptions` and `tls.CommonConnectionOptions`
Expand Down Expand Up @@ -497,24 +497,24 @@ export interface HttpsOptions {
dhparam?: SecureContextOptions['dhparam'];
ecdhCurve?: SecureContextOptions['ecdhCurve'];
certificateRevocationLists?: SecureContextOptions['crl'];
}
};

export interface PaginateData<BodyType, ElementType> {
export type PaginateData<BodyType, ElementType> = {
response: Response<BodyType>;
currentItems: ElementType[];
allItems: ElementType[];
}
};

export interface FilterData<ElementType> {
export type FilterData<ElementType> = {
item: ElementType;
currentItems: ElementType[];
allItems: ElementType[];
}
};

/**
All options accepted by `got.paginate()`.
*/
export interface PaginationOptions<ElementType, BodyType> {
export type PaginationOptions<ElementType, BodyType> = {
/**
A function that transform [`Response`](#response) into an array of items.
This is where you should do the parsing.
Expand Down Expand Up @@ -619,7 +619,7 @@ export interface PaginationOptions<ElementType, BodyType> {
@default false
*/
stackAllItems?: boolean;
}
};

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

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

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

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

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

Expand Down Expand Up @@ -1732,8 +1734,7 @@ export default class Options {
}

const typedKnownHookEvent = knownHookEvent as keyof Hooks;
const typedValue = value as Hooks;
const hooks = typedValue[typedKnownHookEvent];
const hooks = value[typedKnownHookEvent];

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

Expand Down
8 changes: 4 additions & 4 deletions source/core/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {RequestError} from './errors.js';
import type {ParseJsonFunction, ResponseType} from './options.js';
import type Request from './index.js';

export interface PlainResponse extends IncomingMessageWithTimings {
export type PlainResponse = {
/**
The original request URL.
*/
Expand Down Expand Up @@ -98,10 +98,10 @@ export interface PlainResponse extends IncomingMessageWithTimings {
__Note__: Got throws automatically when `response.ok` is `false` and `throwHttpErrors` is `true`.
*/
ok: boolean;
}
} & IncomingMessageWithTimings;

// For Promise support
export interface Response<T = unknown> extends PlainResponse {
export type Response<T = unknown> = {
/**
The result of the request.
*/
Expand All @@ -111,7 +111,7 @@ export interface Response<T = unknown> extends PlainResponse {
The raw result of the request.
*/
rawBody: Buffer;
}
} & PlainResponse;

export const isResponseOk = (response: PlainResponse): boolean => {
const {statusCode} = response;
Expand Down
Loading

0 comments on commit 9f06060

Please sign in to comment.