diff --git a/test/types/client.test-d.ts b/test/types/client.test-d.ts index 2a6b3ce300f..66baf8a20da 100644 --- a/test/types/client.test-d.ts +++ b/test/types/client.test-d.ts @@ -21,6 +21,7 @@ expectAssignable(new Client(new URL('http://localhost'), {})) // request expectAssignable>(client.request({ origin: '', path: '', method: '' })) expectAssignable>(client.request({ origin: new URL('http://localhost:3000'), path: '', method: '' })) + expectAssignable>(client.request({ path: '/', method: 'GET' })) expectAssignable(client.request({ origin: '', path: '', method: '' }, (err, data) => { expectAssignable(err) expectAssignable(data) @@ -93,6 +94,7 @@ expectAssignable(new Client(new URL('http://localhost'), {})) })) // dispatch + expectAssignable(client.dispatch({ path: '', method: '' }, {})) expectAssignable(client.dispatch({ origin: '', path: '', method: '' }, {})) expectAssignable(client.dispatch({ origin: '', path: '', method: '', headers: [] }, {})) expectAssignable(client.dispatch({ origin: '', path: '', method: '', headers: {} }, {})) diff --git a/test/types/pool.test-d.ts b/test/types/pool.test-d.ts index 00174a3369c..79302815d3d 100644 --- a/test/types/pool.test-d.ts +++ b/test/types/pool.test-d.ts @@ -18,6 +18,7 @@ expectAssignable(new Pool('', { connections: 1 })) expectAssignable(pool.destroyed) // request + expectAssignable>(pool.request({ path: '', method: '' })) expectAssignable>(pool.request({ origin: '', path: '', method: '' })) expectAssignable>(pool.request({ origin: new URL('http://localhost'), path: '', method: '' })) expectAssignable(pool.request({ origin: '', path: '', method: '' }, (err, data) => { @@ -86,6 +87,7 @@ expectAssignable(new Pool('', { connections: 1 })) })) // dispatch + expectAssignable(pool.dispatch({ path: '', method: '' }, {})) expectAssignable(pool.dispatch({ origin: '', path: '', method: '' }, {})) expectAssignable(pool.dispatch({ origin: new URL('http://localhost'), path: '', method: '' }, {})) diff --git a/types/client.d.ts b/types/client.d.ts index e15474bf768..8328a415965 100644 --- a/types/client.d.ts +++ b/types/client.d.ts @@ -1,6 +1,6 @@ import { URL } from 'url' import { TlsOptions } from 'tls' -import Dispatcher from './dispatcher' +import Dispatcher, { DispatchOptions, RequestOptions } from './dispatcher' export = Client @@ -13,6 +13,11 @@ declare class Client extends Dispatcher { closed: boolean; /** `true` after `client.destroyed()` has been called or `client.close()` has been called and the client shutdown has completed. */ destroyed: boolean; + /** Dispatches a request. This API is expected to evolve through semver-major versions and is less stable than the preceding higher level APIs. It is primarily intended for library developers who implement higher level APIs on top of this. */ + dispatch(options: Client.ClientDispatchOptions, handler: Dispatcher.DispatchHandlers): void; + /** Performs an HTTP request. */ + request(options: Client.ClientRequestOptions): Promise; + request(options: Client.ClientRequestOptions, callback: (err: Error | null, data: Dispatcher.ResponseData) => void): void; } declare namespace Client { @@ -45,4 +50,12 @@ declare namespace Client { timeout?: number | null; servername?: string | null; } + + export interface ClientDispatchOptions extends Partial { + origin?: string | URL; + } + + export interface ClientRequestOptions extends Partial { + origin?: string | URL; + } } diff --git a/types/pool.d.ts b/types/pool.d.ts index bdce07bc669..70a05c71d47 100644 --- a/types/pool.d.ts +++ b/types/pool.d.ts @@ -1,5 +1,5 @@ import Client from './client' -import Dispatcher from './dispatcher' +import Dispatcher, { DispatchOptions, RequestOptions } from './dispatcher' import { URL } from 'url' export = Pool @@ -10,6 +10,11 @@ declare class Pool extends Dispatcher { closed: boolean; /** `true` after `pool.destroyed()` has been called or `pool.close()` has been called and the pool shutdown has completed. */ destroyed: boolean; + /** Dispatches a request. This API is expected to evolve through semver-major versions and is less stable than the preceding higher level APIs. It is primarily intended for library developers who implement higher level APIs on top of this. */ + dispatch(options: Pool.PoolDispatchOptions, handler: Dispatcher.DispatchHandlers): void; + /** Performs an HTTP request. */ + request(options: Pool.PoolRequestOptions): Promise; + request(options: Pool.PoolRequestOptions, callback: (err: Error | null, data: Dispatcher.ResponseData) => void): void; } declare namespace Pool { @@ -19,4 +24,12 @@ declare namespace Pool { /** The max number of clients to create. `null` if no limit. Default `null`. */ connections?: number | null; } + + export interface PoolDispatchOptions extends Partial { + origin?: string | URL; + } + + export interface PoolRequestOptions extends Partial { + origin?: string | URL; + } }