Skip to content

Commit

Permalink
fix: origin as optional parameter on Client and Pool types definitions (
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopedrocampos authored Jul 25, 2021
1 parent 0f8e9b5 commit 6061920
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions test/types/client.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ expectAssignable<Client>(new Client(new URL('http://localhost'), {}))
// request
expectAssignable<Promise<Dispatcher.ResponseData>>(client.request({ origin: '', path: '', method: '' }))
expectAssignable<Promise<Dispatcher.ResponseData>>(client.request({ origin: new URL('http://localhost:3000'), path: '', method: '' }))
expectAssignable<Promise<Dispatcher.ResponseData>>(client.request({ path: '/', method: 'GET' }))
expectAssignable<void>(client.request({ origin: '', path: '', method: '' }, (err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.ResponseData>(data)
Expand Down Expand Up @@ -93,6 +94,7 @@ expectAssignable<Client>(new Client(new URL('http://localhost'), {}))
}))

// dispatch
expectAssignable<void>(client.dispatch({ path: '', method: '' }, {}))
expectAssignable<void>(client.dispatch({ origin: '', path: '', method: '' }, {}))
expectAssignable<void>(client.dispatch({ origin: '', path: '', method: '', headers: [] }, {}))
expectAssignable<void>(client.dispatch({ origin: '', path: '', method: '', headers: {} }, {}))
Expand Down
2 changes: 2 additions & 0 deletions test/types/pool.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ expectAssignable<Pool>(new Pool('', { connections: 1 }))
expectAssignable<boolean>(pool.destroyed)

// request
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ path: '', method: '' }))
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: '', path: '', method: '' }))
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: new URL('http://localhost'), path: '', method: '' }))
expectAssignable<void>(pool.request({ origin: '', path: '', method: '' }, (err, data) => {
Expand Down Expand Up @@ -86,6 +87,7 @@ expectAssignable<Pool>(new Pool('', { connections: 1 }))
}))

// dispatch
expectAssignable<void>(pool.dispatch({ path: '', method: '' }, {}))
expectAssignable<void>(pool.dispatch({ origin: '', path: '', method: '' }, {}))
expectAssignable<void>(pool.dispatch({ origin: new URL('http://localhost'), path: '', method: '' }, {}))

Expand Down
15 changes: 14 additions & 1 deletion types/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { URL } from 'url'
import { TlsOptions } from 'tls'
import Dispatcher from './dispatcher'
import Dispatcher, { DispatchOptions, RequestOptions } from './dispatcher'

export = Client

Expand All @@ -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<Dispatcher.ResponseData>;
request(options: Client.ClientRequestOptions, callback: (err: Error | null, data: Dispatcher.ResponseData) => void): void;
}

declare namespace Client {
Expand Down Expand Up @@ -45,4 +50,12 @@ declare namespace Client {
timeout?: number | null;
servername?: string | null;
}

export interface ClientDispatchOptions extends Partial<DispatchOptions> {
origin?: string | URL;
}

export interface ClientRequestOptions extends Partial<RequestOptions> {
origin?: string | URL;
}
}
15 changes: 14 additions & 1 deletion types/pool.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Client from './client'
import Dispatcher from './dispatcher'
import Dispatcher, { DispatchOptions, RequestOptions } from './dispatcher'
import { URL } from 'url'

export = Pool
Expand All @@ -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<Dispatcher.ResponseData>;
request(options: Pool.PoolRequestOptions, callback: (err: Error | null, data: Dispatcher.ResponseData) => void): void;
}

declare namespace Pool {
Expand All @@ -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<DispatchOptions> {
origin?: string | URL;
}

export interface PoolRequestOptions extends Partial<RequestOptions> {
origin?: string | URL;
}
}

0 comments on commit 6061920

Please sign in to comment.