Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConnectOptions should include 'origin' field #2532

Merged
merged 2 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions test/types/agent.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ expectAssignable<Agent>(new Agent({ factory: () => new Dispatcher() }))
}))

// connect
expectAssignable<Promise<Dispatcher.ConnectData>>(agent.connect({ path: '' }))
expectAssignable<void>(agent.connect({ path: '' }, (err, data) => {
expectAssignable<Promise<Dispatcher.ConnectData>>(agent.connect({ origin: '', path: '' }))
expectAssignable<Promise<Dispatcher.ConnectData>>(agent.connect({ origin: new URL('http://localhost'), path: '' }))
expectAssignable<void>(agent.connect({ origin: '', path: '' }, (err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.ConnectData>(data)
}))
expectAssignable<void>(agent.connect({ origin: new URL('http://localhost'), path: '' }, (err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.ConnectData>(data)
}))
Expand Down
9 changes: 7 additions & 2 deletions test/types/dispatcher.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ expectAssignable<Dispatcher>(new Dispatcher())
expectAssignable<boolean>(dispatcher.dispatch({ origin: new URL('http://localhost'), path: '', method: 'GET' }, {}))

// connect
expectAssignable<Promise<Dispatcher.ConnectData>>(dispatcher.connect({ path: '', maxRedirections: 0 }))
expectAssignable<void>(dispatcher.connect({ path: '' }, (err, data) => {
expectAssignable<Promise<Dispatcher.ConnectData>>(dispatcher.connect({ origin: '', path: '', maxRedirections: 0 }))
expectAssignable<Promise<Dispatcher.ConnectData>>(dispatcher.connect({ origin: new URL('http://localhost'), path: '', maxRedirections: 0 }))
expectAssignable<void>(dispatcher.connect({ origin: '', path: '' }, (err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.ConnectData>(data)
}))
expectAssignable<void>(dispatcher.connect({ origin: new URL('http://localhost'), path: '' }, (err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.ConnectData>(data)
}))
Expand Down
11 changes: 11 additions & 0 deletions types/balanced-pool.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { URL } from 'url'

export default BalancedPool

type BalancedPoolConnectOptions = Omit<Dispatcher.ConnectOptions, "origin">;

declare class BalancedPool extends Dispatcher {
constructor(url: string | string[] | URL | URL[], options?: Pool.Options);

Expand All @@ -15,4 +17,13 @@ declare class BalancedPool 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;

// Override dispatcher APIs.
override connect(
options: BalancedPoolConnectOptions
): Promise<Dispatcher.ConnectData>;
override connect(
options: BalancedPoolConnectOptions,
callback: (err: Error | null, data: Dispatcher.ConnectData) => void
): void;
}
11 changes: 11 additions & 0 deletions types/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { TlsOptions } from 'tls'
import Dispatcher from './dispatcher'
import buildConnector from "./connector";

type ClientConnectOptions = Omit<Dispatcher.ConnectOptions, "origin">;

/**
* A basic HTTP/1.1 client, mapped on top a single TCP/TLS connection. Pipelining is disabled by default.
*/
Expand All @@ -14,6 +16,15 @@ export 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;

// Override dispatcher APIs.
override connect(
options: ClientConnectOptions
): Promise<Dispatcher.ConnectData>;
override connect(
options: ClientConnectOptions,
callback: (err: Error | null, data: Dispatcher.ConnectData) => void
): void;
}

export declare namespace Client {
Expand Down
1 change: 1 addition & 0 deletions types/dispatcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ declare namespace Dispatcher {
expectContinue?: boolean;
}
export interface ConnectOptions {
origin: string | URL;
path: string;
/** Default: `null` */
headers?: IncomingHttpHeaders | string[] | null;
Expand Down
11 changes: 11 additions & 0 deletions types/pool.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Dispatcher from "./dispatcher";

export default Pool

type PoolConnectOptions = Omit<Dispatcher.ConnectOptions, "origin">;

declare class Pool extends Dispatcher {
constructor(url: string | URL, options?: Pool.Options)
/** `true` after `pool.close()` has been called. */
Expand All @@ -13,6 +15,15 @@ declare class Pool extends Dispatcher {
destroyed: boolean;
/** Aggregate stats for a Pool. */
readonly stats: TPoolStats;

// Override dispatcher APIs.
override connect(
options: PoolConnectOptions
): Promise<Dispatcher.ConnectData>;
override connect(
options: PoolConnectOptions,
callback: (err: Error | null, data: Dispatcher.ConnectData) => void
): void;
}

declare namespace Pool {
Expand Down