From 577ad90eee254d8ad58dc899a3c41ed715995cd0 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Sun, 13 Nov 2022 15:20:31 +0200 Subject: [PATCH] Refine internal TS export/imports to be more robust --- .gitignore | 1 + index.d.ts | 46 +++++++++++++------------- package.json | 3 +- test/imports/undici-import.ts | 5 +++ test/types/dispatcher.events.test-d.ts | 8 ++--- test/types/errors.test-d.ts | 4 +-- test/types/formdata.test-d.ts | 4 +-- test/types/interceptor.test-d.ts | 4 +-- test/types/readable.test-d.ts | 2 +- types/agent.d.ts | 9 +++-- types/api.d.ts | 2 +- types/balanced-pool.d.ts | 7 ++-- types/client.d.ts | 10 +++--- types/connector.d.ts | 6 ++-- types/diagnostics-channel.d.ts | 8 ++--- types/dispatcher.d.ts | 46 +++++++++++++------------- types/errors.d.ts | 6 ++-- types/fetch.d.ts | 2 +- types/global-dispatcher.d.ts | 2 +- types/interceptors.d.ts | 4 +-- types/mock-agent.d.ts | 6 ++-- types/mock-client.d.ts | 8 ++--- types/mock-errors.d.ts | 6 ++-- types/mock-interceptor.d.ts | 2 +- types/mock-pool.d.ts | 8 ++--- types/pool-stats.d.ts | 4 +-- types/pool.d.ts | 11 +++--- types/proxy-agent.d.ts | 6 ++-- types/readable.d.ts | 2 +- 29 files changed, 118 insertions(+), 114 deletions(-) create mode 100644 test/imports/undici-import.ts diff --git a/.gitignore b/.gitignore index 82971a7087e..acd1b69eca2 100644 --- a/.gitignore +++ b/.gitignore @@ -78,3 +78,4 @@ fuzz-results-*.json # Bundle output undici-fetch.js +/test/imports/undici-import.js diff --git a/index.d.ts b/index.d.ts index 1aaf14d38b2..d663178d410 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,19 +1,19 @@ -import Dispatcher = require('./types/dispatcher') +import Dispatcher from'./types/dispatcher' import { setGlobalDispatcher, getGlobalDispatcher } from './types/global-dispatcher' import { setGlobalOrigin, getGlobalOrigin } from './types/global-origin' -import Pool = require('./types/pool') +import Pool from'./types/pool' import { RedirectHandler, DecoratorHandler } from './types/handlers' -import BalancedPool = require('./types/balanced-pool') -import Client = require('./types/client') -import buildConnector = require('./types/connector') -import errors = require('./types/errors') -import Agent = require('./types/agent') -import MockClient = require('./types/mock-client') -import MockPool = require('./types/mock-pool') -import MockAgent = require('./types/mock-agent') -import mockErrors = require('./types/mock-errors') -import ProxyAgent = require('./types/proxy-agent') +import BalancedPool from './types/balanced-pool' +import Client from'./types/client' +import buildConnector from'./types/connector' +import errors from'./types/errors' +import Agent from'./types/agent' +import MockClient from'./types/mock-client' +import MockPool from'./types/mock-pool' +import MockAgent from'./types/mock-agent' +import mockErrors from'./types/mock-errors' +import ProxyAgent from'./types/proxy-agent' import { request, pipeline, stream, connect, upgrade } from './types/api' export * from './types/fetch' @@ -27,16 +27,16 @@ export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, export default Undici declare namespace Undici { - var Dispatcher: typeof import('./types/dispatcher') - var Pool: typeof import('./types/pool'); + var Dispatcher: typeof import('./types/dispatcher').default + var Pool: typeof import('./types/pool').default; var RedirectHandler: typeof import ('./types/handlers').RedirectHandler var DecoratorHandler: typeof import ('./types/handlers').DecoratorHandler var createRedirectInterceptor: typeof import ('./types/interceptors').createRedirectInterceptor - var BalancedPool: typeof import('./types/balanced-pool'); - var Client: typeof import('./types/client'); - var buildConnector: typeof import('./types/connector'); - var errors: typeof import('./types/errors'); - var Agent: typeof import('./types/agent'); + var BalancedPool: typeof import('./types/balanced-pool').default; + var Client: typeof import('./types/client').default; + var buildConnector: typeof import('./types/connector').default; + var errors: typeof import('./types/errors').default; + var Agent: typeof import('./types/agent').default; var setGlobalDispatcher: typeof import('./types/global-dispatcher').setGlobalDispatcher; var getGlobalDispatcher: typeof import('./types/global-dispatcher').getGlobalDispatcher; var request: typeof import('./types/api').request; @@ -44,9 +44,9 @@ declare namespace Undici { var pipeline: typeof import('./types/api').pipeline; var connect: typeof import('./types/api').connect; var upgrade: typeof import('./types/api').upgrade; - var MockClient: typeof import('./types/mock-client'); - var MockPool: typeof import('./types/mock-pool'); - var MockAgent: typeof import('./types/mock-agent'); - var mockErrors: typeof import('./types/mock-errors'); + var MockClient: typeof import('./types/mock-client').default; + var MockPool: typeof import('./types/mock-pool').default; + var MockAgent: typeof import('./types/mock-agent').default; + var mockErrors: typeof import('./types/mock-errors').default; var fetch: typeof import('./types/fetch').fetch; } diff --git a/package.json b/package.json index b2708018e58..a02ae1090b0 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "test:jest": "node scripts/verifyVersion.js 14 || jest", "test:tap": "tap test/*.js test/diagnostics-channel/*.js", "test:tdd": "tap test/*.js test/diagnostics-channel/*.js -w", - "test:typescript": "tsd", + "test:typescript": "tsd && tsc test/imports/undici-import.ts", "test:wpt": "node scripts/verifyVersion 18 || (node test/wpt/start-fetch.mjs && node test/wpt/start-FileAPI.mjs && node test/wpt/start-mimesniff.mjs && node test/wpt/start-xhr.mjs)", "coverage": "nyc --reporter=text --reporter=html npm run test", "coverage:ci": "nyc --reporter=lcov npm run test", @@ -95,6 +95,7 @@ "table": "^6.8.0", "tap": "^16.1.0", "tsd": "^0.24.1", + "typescript": "^4.8.4", "wait-on": "^6.0.0" }, "engines": { diff --git a/test/imports/undici-import.ts b/test/imports/undici-import.ts new file mode 100644 index 00000000000..fb7344e49b8 --- /dev/null +++ b/test/imports/undici-import.ts @@ -0,0 +1,5 @@ +import { request } from '../../' + +async function exampleCode() { + await request('http://localhost:3000/foo') +} diff --git a/test/types/dispatcher.events.test-d.ts b/test/types/dispatcher.events.test-d.ts index 1c58add84f2..71057e7a182 100644 --- a/test/types/dispatcher.events.test-d.ts +++ b/test/types/dispatcher.events.test-d.ts @@ -1,12 +1,12 @@ import { Dispatcher } from '../..' import {expectAssignable} from "tsd"; import {URL} from "url"; -import {UndiciError} from "../../types/errors"; +import Errors from "../../types/errors"; interface EventHandler { connect(origin: URL, targets: readonly Dispatcher[]): void - disconnect(origin: URL, targets: readonly Dispatcher[], error: UndiciError): void - connectionError(origin: URL, targets: readonly Dispatcher[], error: UndiciError): void + disconnect(origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError): void + connectionError(origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError): void drain(origin: URL): void } @@ -36,7 +36,7 @@ interface EventHandler { const origin = new URL('') const targets = new Array() - const error = new UndiciError() + const error = new Errors.UndiciError() expectAssignable(dispatcher.emit('connect', origin, targets)) expectAssignable(dispatcher.emit('disconnect', origin, targets, error)) expectAssignable(dispatcher.emit('connectionError', origin, targets, error)) diff --git a/test/types/errors.test-d.ts b/test/types/errors.test-d.ts index 76994687ca8..53b544dfcd1 100644 --- a/test/types/errors.test-d.ts +++ b/test/types/errors.test-d.ts @@ -1,6 +1,6 @@ import { expectAssignable } from 'tsd' import { errors } from '../..' -import { SocketInfo } from '../../types/client' +import Client from '../../types/client' expectAssignable(new errors.UndiciError()) @@ -53,7 +53,7 @@ expectAssignable(new errors.SocketError()) expectAssignable(new errors.SocketError()) expectAssignable<'SocketError'>(new errors.SocketError().name) expectAssignable<'UND_ERR_SOCKET'>(new errors.SocketError().code) -expectAssignable(new errors.SocketError().socket) +expectAssignable(new errors.SocketError().socket) expectAssignable(new errors.NotSupportedError()) expectAssignable(new errors.NotSupportedError()) diff --git a/test/types/formdata.test-d.ts b/test/types/formdata.test-d.ts index f5c4f8a5063..79058c4eff3 100644 --- a/test/types/formdata.test-d.ts +++ b/test/types/formdata.test-d.ts @@ -2,9 +2,9 @@ import { Blob } from 'buffer' import { Readable } from 'stream' import { expectAssignable, expectType } from 'tsd' import { File, FormData, SpecIterableIterator } from '../..' -import { DispatchOptions } from '../../types/dispatcher' +import Dispatcher from '../../types/dispatcher' -declare const dispatcherOptions: DispatchOptions +declare const dispatcherOptions: Dispatcher.DispatchOptions declare const blob: Blob const formData = new FormData() diff --git a/test/types/interceptor.test-d.ts b/test/types/interceptor.test-d.ts index ea69405548d..ba242bfcadb 100644 --- a/test/types/interceptor.test-d.ts +++ b/test/types/interceptor.test-d.ts @@ -1,5 +1,5 @@ import {expectAssignable} from "tsd"; import Undici from "../.."; -import Dispatcher, {DispatchInterceptor} from "../../types/dispatcher"; +import Dispatcher from "../../types/dispatcher"; -expectAssignable(Undici.createRedirectInterceptor({ maxRedirections: 3 })) +expectAssignable(Undici.createRedirectInterceptor({ maxRedirections: 3 })) diff --git a/test/types/readable.test-d.ts b/test/types/readable.test-d.ts index 8511de56e3d..671f6f3c6ef 100644 --- a/test/types/readable.test-d.ts +++ b/test/types/readable.test-d.ts @@ -1,5 +1,5 @@ import { expectAssignable } from 'tsd' -import BodyReadable = require('../../types/readable') +import BodyReadable from '../../types/readable' import { Blob } from 'buffer' expectAssignable(new BodyReadable()) diff --git a/types/agent.d.ts b/types/agent.d.ts index c09260b2913..08137358058 100644 --- a/types/agent.d.ts +++ b/types/agent.d.ts @@ -1,9 +1,8 @@ import { URL } from 'url' -import Dispatcher = require('./dispatcher') -import Pool = require('./pool') -import {DispatchInterceptor} from "./dispatcher"; +import Pool from './pool' +import Dispatcher from "./dispatcher"; -export = Agent +export default Agent declare class Agent extends Dispatcher{ constructor(opts?: Agent.Options) @@ -22,7 +21,7 @@ declare namespace Agent { /** Integer. Default: `0` */ maxRedirections?: number; - interceptors?: { Agent?: readonly DispatchInterceptor[] } & Pool.Options["interceptors"] + interceptors?: { Agent?: readonly Dispatcher.DispatchInterceptor[] } & Pool.Options["interceptors"] } export interface DispatchOptions extends Dispatcher.DispatchOptions { diff --git a/types/api.d.ts b/types/api.d.ts index 4bc3183e84e..400341dddc0 100644 --- a/types/api.d.ts +++ b/types/api.d.ts @@ -1,6 +1,6 @@ import { URL, UrlObject } from 'url' import { Duplex } from 'stream' -import Dispatcher = require('./dispatcher') +import Dispatcher from './dispatcher' export { request, diff --git a/types/balanced-pool.d.ts b/types/balanced-pool.d.ts index 5a765e15e10..b5de726eeca 100644 --- a/types/balanced-pool.d.ts +++ b/types/balanced-pool.d.ts @@ -1,9 +1,8 @@ -import Client = require('./client') -import Pool = require('./pool') -import Dispatcher = require('./dispatcher') +import Pool from './pool' +import Dispatcher from './dispatcher' import { URL } from 'url' -export = BalancedPool +export default BalancedPool declare class BalancedPool extends Dispatcher { constructor(url: string | URL | string[], options?: Pool.Options); diff --git a/types/client.d.ts b/types/client.d.ts index d87f08f1a08..3a954ac83a1 100644 --- a/types/client.d.ts +++ b/types/client.d.ts @@ -1,10 +1,10 @@ import { URL } from 'url' import { TlsOptions } from 'tls' -import Dispatcher = require('./dispatcher') -import {DispatchInterceptor} from './dispatcher' -import buildConnector, {connector} from "./connector"; +import Dispatcher from './dispatcher' +import DispatchInterceptor from './dispatcher' +import buildConnector from "./connector"; -export = Client +export default Client /** A basic HTTP/1.1 client, mapped on top a single TCP/TLS connection. Pipelining is disabled by default. */ declare class Client extends Dispatcher { @@ -28,7 +28,7 @@ declare namespace Client { /** The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Default: `1`. */ pipelining?: number | null; /** **/ - connect?: buildConnector.BuildOptions | connector | null; + connect?: buildConnector.BuildOptions | buildConnector.connector | null; /** The maximum length of request headers in bytes. Default: `16384` (16KiB). */ maxHeaderSize?: number | null; /** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Default: `30e3` milliseconds (30s). */ diff --git a/types/connector.d.ts b/types/connector.d.ts index 9a47f87e599..8a425d2972c 100644 --- a/types/connector.d.ts +++ b/types/connector.d.ts @@ -1,7 +1,7 @@ -import {TLSSocket, ConnectionOptions} from 'tls' -import {IpcNetConnectOpts, Socket, TcpNetConnectOpts} from 'net' +import { TLSSocket, ConnectionOptions } from 'tls' +import { IpcNetConnectOpts, Socket, TcpNetConnectOpts } from 'net' -export = buildConnector +export default buildConnector declare function buildConnector (options?: buildConnector.BuildOptions): buildConnector.connector declare namespace buildConnector { diff --git a/types/diagnostics-channel.d.ts b/types/diagnostics-channel.d.ts index 6c754491b89..85d44823978 100644 --- a/types/diagnostics-channel.d.ts +++ b/types/diagnostics-channel.d.ts @@ -1,13 +1,13 @@ import { Socket } from "net"; import { URL } from "url"; -import { connector } from "./connector"; -import { HttpMethod } from "./dispatcher"; +import Connector from "./connector"; +import Dispatcher from "./dispatcher"; declare namespace DiagnosticsChannel { interface Request { origin?: string | URL; completed: boolean; - method?: HttpMethod; + method?: Dispatcher.HttpMethod; path: string; headers: string; addHeader(key: string, value: string): Request; @@ -25,7 +25,7 @@ declare namespace DiagnosticsChannel { port: URL["port"]; servername: string | null; } - type Connector = connector; + type Connector = Connector.connector; export interface RequestCreateMessage { request: Request; } diff --git a/types/dispatcher.d.ts b/types/dispatcher.d.ts index cbd558a932f..adc95b9a0f3 100644 --- a/types/dispatcher.d.ts +++ b/types/dispatcher.d.ts @@ -3,13 +3,13 @@ import { Duplex, Readable, Writable } from 'stream' import { EventEmitter } from 'events' import { IncomingHttpHeaders } from 'http' import { Blob } from 'buffer' -import type BodyReadable from './readable' +import BodyReadable from './readable' import { FormData } from './formdata' -import { UndiciError } from './errors' +import Errors from './errors' type AbortSignal = unknown; -export = Dispatcher; +export default Dispatcher /** Dispatcher is the core API used to dispatch requests. */ declare class Dispatcher extends EventEmitter { @@ -39,56 +39,56 @@ declare class Dispatcher extends EventEmitter { destroy(err: Error | null, callback: () => void): void; on(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this; - on(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; - on(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; + on(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; + on(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; on(eventName: 'drain', callback: (origin: URL) => void): this; once(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this; - once(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; - once(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; + once(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; + once(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; once(eventName: 'drain', callback: (origin: URL) => void): this; off(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this; - off(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; - off(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; + off(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; + off(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; off(eventName: 'drain', callback: (origin: URL) => void): this; addListener(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this; - addListener(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; - addListener(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; + addListener(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; + addListener(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; addListener(eventName: 'drain', callback: (origin: URL) => void): this; removeListener(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this; - removeListener(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; - removeListener(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; + removeListener(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; + removeListener(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; removeListener(eventName: 'drain', callback: (origin: URL) => void): this; prependListener(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this; - prependListener(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; - prependListener(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; + prependListener(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; + prependListener(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; prependListener(eventName: 'drain', callback: (origin: URL) => void): this; prependOnceListener(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this; - prependOnceListener(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; - prependOnceListener(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void): this; + prependOnceListener(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; + prependOnceListener(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this; prependOnceListener(eventName: 'drain', callback: (origin: URL) => void): this; listeners(eventName: 'connect'): ((origin: URL, targets: readonly Dispatcher[]) => void)[] - listeners(eventName: 'disconnect'): ((origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void)[]; - listeners(eventName: 'connectionError'): ((origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void)[]; + listeners(eventName: 'disconnect'): ((origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[]; + listeners(eventName: 'connectionError'): ((origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[]; listeners(eventName: 'drain'): ((origin: URL) => void)[]; rawListeners(eventName: 'connect'): ((origin: URL, targets: readonly Dispatcher[]) => void)[] - rawListeners(eventName: 'disconnect'): ((origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void)[]; - rawListeners(eventName: 'connectionError'): ((origin: URL, targets: readonly Dispatcher[], error: UndiciError) => void)[]; + rawListeners(eventName: 'disconnect'): ((origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[]; + rawListeners(eventName: 'connectionError'): ((origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[]; rawListeners(eventName: 'drain'): ((origin: URL) => void)[]; emit(eventName: 'connect', origin: URL, targets: readonly Dispatcher[]): boolean; - emit(eventName: 'disconnect', origin: URL, targets: readonly Dispatcher[], error: UndiciError): boolean; - emit(eventName: 'connectionError', origin: URL, targets: readonly Dispatcher[], error: UndiciError): boolean; + emit(eventName: 'disconnect', origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError): boolean; + emit(eventName: 'connectionError', origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError): boolean; emit(eventName: 'drain', origin: URL): boolean; } diff --git a/types/errors.d.ts b/types/errors.d.ts index 492e31eb228..c4ef4b6f633 100644 --- a/types/errors.d.ts +++ b/types/errors.d.ts @@ -1,7 +1,7 @@ import {IncomingHttpHeaders} from "http"; +import Client from './client' -export = Errors -import { SocketInfo } from './client' +export default Errors declare namespace Errors { export class UndiciError extends Error { } @@ -79,7 +79,7 @@ declare namespace Errors { export class SocketError extends UndiciError { name: 'SocketError'; code: 'UND_ERR_SOCKET'; - socket: SocketInfo | null + socket: Client.SocketInfo | null } /** Encountered unsupported functionality. */ diff --git a/types/fetch.d.ts b/types/fetch.d.ts index d38e0d61242..58bd4d2a769 100644 --- a/types/fetch.d.ts +++ b/types/fetch.d.ts @@ -7,7 +7,7 @@ import { URL, URLSearchParams } from 'url' import { ReadableStream } from 'stream/web' import { FormData } from './formdata' -import Dispatcher = require('./dispatcher') +import Dispatcher from './dispatcher' export type RequestInfo = string | URL | Request diff --git a/types/global-dispatcher.d.ts b/types/global-dispatcher.d.ts index 56abd53d6cf..728f95ce23c 100644 --- a/types/global-dispatcher.d.ts +++ b/types/global-dispatcher.d.ts @@ -1,4 +1,4 @@ -import Dispatcher = require("./dispatcher"); +import Dispatcher from "./dispatcher"; export { getGlobalDispatcher, diff --git a/types/interceptors.d.ts b/types/interceptors.d.ts index a920ea982e8..047ac175d50 100644 --- a/types/interceptors.d.ts +++ b/types/interceptors.d.ts @@ -1,5 +1,5 @@ -import {DispatchInterceptor} from "./dispatcher"; +import Dispatcher from "./dispatcher"; type RedirectInterceptorOpts = { maxRedirections?: number } -export declare function createRedirectInterceptor (opts: RedirectInterceptorOpts): DispatchInterceptor +export declare function createRedirectInterceptor (opts: RedirectInterceptorOpts): Dispatcher.DispatchInterceptor diff --git a/types/mock-agent.d.ts b/types/mock-agent.d.ts index 825d2aeff6d..98cd645b29b 100644 --- a/types/mock-agent.d.ts +++ b/types/mock-agent.d.ts @@ -1,9 +1,9 @@ -import Agent = require('./agent') -import Dispatcher = require('./dispatcher') +import Agent from './agent' +import Dispatcher from './dispatcher' import { Interceptable, MockInterceptor } from './mock-interceptor' import MockDispatch = MockInterceptor.MockDispatch; -export = MockAgent +export default MockAgent interface PendingInterceptor extends MockDispatch { origin: string; diff --git a/types/mock-client.d.ts b/types/mock-client.d.ts index 9e751f42f35..51d008cc11c 100644 --- a/types/mock-client.d.ts +++ b/types/mock-client.d.ts @@ -1,9 +1,9 @@ -import Client = require('./client') -import Dispatcher = require('./dispatcher') -import MockAgent = require('./mock-agent') +import Client from './client' +import Dispatcher from './dispatcher' +import MockAgent from './mock-agent' import { MockInterceptor, Interceptable } from './mock-interceptor' -export = MockClient +export default MockClient /** MockClient extends the Client API and allows one to mock requests. */ declare class MockClient extends Client implements Interceptable { diff --git a/types/mock-errors.d.ts b/types/mock-errors.d.ts index 31e7ba23c7f..3d9e727d70a 100644 --- a/types/mock-errors.d.ts +++ b/types/mock-errors.d.ts @@ -1,10 +1,10 @@ -import { UndiciError } from './errors' +import Errors from './errors' -export = MockErrors +export default MockErrors declare namespace MockErrors { /** The request does not match any registered mock dispatches. */ - export class MockNotMatchedError extends UndiciError { + export class MockNotMatchedError extends Errors.UndiciError { constructor(message?: string); name: 'MockNotMatchedError'; code: 'UND_MOCK_ERR_MOCK_NOT_MATCHED'; diff --git a/types/mock-interceptor.d.ts b/types/mock-interceptor.d.ts index 87eedcd4060..9dc423c0600 100644 --- a/types/mock-interceptor.d.ts +++ b/types/mock-interceptor.d.ts @@ -1,5 +1,5 @@ import { IncomingHttpHeaders } from 'http' -import Dispatcher = require('./dispatcher'); +import Dispatcher from './dispatcher'; import { BodyInit, Headers } from './fetch' export { diff --git a/types/mock-pool.d.ts b/types/mock-pool.d.ts index d0c90515268..39e709aaf69 100644 --- a/types/mock-pool.d.ts +++ b/types/mock-pool.d.ts @@ -1,9 +1,9 @@ -import Pool = require('./pool') -import MockAgent = require('./mock-agent') +import Pool from './pool' +import MockAgent from './mock-agent' import { Interceptable, MockInterceptor } from './mock-interceptor' -import Dispatcher = require('./dispatcher') +import Dispatcher from './dispatcher' -export = MockPool +export default MockPool /** MockPool extends the Pool API and allows one to mock requests. */ declare class MockPool extends Pool implements Interceptable { diff --git a/types/pool-stats.d.ts b/types/pool-stats.d.ts index 807e68f1b81..8b6d2bff4ad 100644 --- a/types/pool-stats.d.ts +++ b/types/pool-stats.d.ts @@ -1,6 +1,6 @@ -import Pool = require("./pool") +import Pool from "./pool" -export = PoolStats +export default PoolStats declare class PoolStats { constructor(pool: Pool); diff --git a/types/pool.d.ts b/types/pool.d.ts index 0ef0bc39884..7747d48261b 100644 --- a/types/pool.d.ts +++ b/types/pool.d.ts @@ -1,10 +1,9 @@ -import Client = require('./client') -import Dispatcher = require('./dispatcher') -import TPoolStats = require('./pool-stats') +import Client from './client' +import TPoolStats from './pool-stats' import { URL } from 'url' -import {DispatchInterceptor} from "./dispatcher"; +import Dispatcher from "./dispatcher"; -export = Pool +export default Pool declare class Pool extends Dispatcher { constructor(url: string | URL, options?: Pool.Options) @@ -24,6 +23,6 @@ declare namespace Pool { /** The max number of clients to create. `null` if no limit. Default `null`. */ connections?: number | null; - interceptors?: { Pool?: readonly DispatchInterceptor[] } & Client.Options["interceptors"] + interceptors?: { Pool?: readonly Dispatcher.DispatchInterceptor[] } & Client.Options["interceptors"] } } diff --git a/types/proxy-agent.d.ts b/types/proxy-agent.d.ts index 118165d00d0..5e3718e9f34 100644 --- a/types/proxy-agent.d.ts +++ b/types/proxy-agent.d.ts @@ -1,8 +1,8 @@ import { TlsOptions } from 'tls' -import Agent = require('./agent') -import Dispatcher = require('./dispatcher') +import Agent from './agent' +import Dispatcher from './dispatcher' -export = ProxyAgent +export default ProxyAgent declare class ProxyAgent extends Dispatcher { constructor(options: ProxyAgent.Options | string) diff --git a/types/readable.d.ts b/types/readable.d.ts index 0d82ba86776..032b53b01f9 100644 --- a/types/readable.d.ts +++ b/types/readable.d.ts @@ -1,7 +1,7 @@ import { Readable } from "stream"; import { Blob } from 'buffer' -export = BodyReadable +export default BodyReadable declare class BodyReadable extends Readable { constructor(