Skip to content

Commit

Permalink
feat(TS): add types
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 committed Dec 26, 2022
1 parent a8dd12e commit deb3835
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions test/types/agent.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { URL } from 'url'

expectAssignable<Agent>(new Agent())
expectAssignable<Agent>(new Agent({}))
expectAssignable<Agent>(new Agent({ maxRedirections: 1 }))
expectAssignable<Agent>(new Agent({ maxRedirections: 1, reset: true }))
expectAssignable<Agent>(new Agent({ factory: () => new Dispatcher() }))

{
Expand Down Expand Up @@ -93,7 +93,7 @@ expectAssignable<Agent>(new Agent({ factory: () => new Dispatcher() }))
}))

// dispatch
expectAssignable<boolean>(agent.dispatch({ origin: '', path: '', method: 'GET' }, {}))
expectAssignable<boolean>(agent.dispatch({ reset: true, origin: '', path: '', method: 'GET' }, {}))
expectAssignable<boolean>(agent.dispatch({ origin: '', path: '', method: 'GET', maxRedirections: 1 }, {}))

// close
Expand Down
2 changes: 1 addition & 1 deletion test/types/api.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Dispatcher, request, stream, pipeline, connect, upgrade } from '../..'
// request
expectAssignable<Promise<Dispatcher.ResponseData>>(request(''))
expectAssignable<Promise<Dispatcher.ResponseData>>(request('', { }))
expectAssignable<Promise<Dispatcher.ResponseData>>(request('', { method: 'GET' }))
expectAssignable<Promise<Dispatcher.ResponseData>>(request('', { method: 'GET', reset: true }))

// stream
expectAssignable<Promise<Dispatcher.StreamData>>(stream('', { method: 'GET' }, data => {
Expand Down
4 changes: 2 additions & 2 deletions test/types/balanced-pool.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ expectAssignable<BalancedPool>(new BalancedPool('', {}))
expectAssignable<BalancedPool>(new BalancedPool(new URL('http://localhost'), {}))
expectAssignable<BalancedPool>(new BalancedPool('', { factory: () => new Dispatcher() }))
expectAssignable<BalancedPool>(new BalancedPool('', { factory: (origin, opts) => new Client(origin, opts) }))
expectAssignable<BalancedPool>(new BalancedPool('', { connections: 1 }))
expectAssignable<BalancedPool>(new BalancedPool('', { connections: 1, reset: true }))
expectAssignable<BalancedPool>(new BalancedPool(['http://localhost:4242', 'http://www.nodejs.org']))

{
Expand All @@ -27,7 +27,7 @@ expectAssignable<BalancedPool>(new BalancedPool(['http://localhost:4242', 'http:
// request
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: '', path: '', method: 'GET' }))
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: new URL('http://localhost'), path: '', method: 'GET' }))
expectAssignable<void>(pool.request({ origin: '', path: '', method: 'GET' }, (err, data) => {
expectAssignable<void>(pool.request({ reset: false, origin: '', path: '', method: 'GET' }, (err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.ResponseData>(data)
}))
Expand Down
4 changes: 2 additions & 2 deletions test/types/pool.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ expectAssignable<Pool>(new Pool('', {}))
expectAssignable<Pool>(new Pool(new URL('http://localhost'), {}))
expectAssignable<Pool>(new Pool('', { factory: () => new Dispatcher() }))
expectAssignable<Pool>(new Pool('', { factory: (origin, opts) => new Client(origin, opts) }))
expectAssignable<Pool>(new Pool('', { connections: 1 }))
expectAssignable<Pool>(new Pool('', { connections: 1, reset: true }))

{
const pool = new Pool('', {})
Expand All @@ -21,7 +21,7 @@ expectAssignable<Pool>(new Pool('', { connections: 1 }))
// request
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: '', path: '', method: 'GET' }))
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: new URL('http://localhost'), path: '', method: 'GET' }))
expectAssignable<void>(pool.request({ origin: '', path: '', method: 'GET' }, (err, data) => {
expectAssignable<void>(pool.request({ reset: false, origin: '', path: '', method: 'GET' }, (err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.ResponseData>(data)
}))
Expand Down
2 changes: 2 additions & 0 deletions types/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ declare namespace Client {
keepAliveTimeoutThreshold?: number | null;
/** 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;
/** Indicate wether or not send `connection` header with keep-alive value for long-living connections */
reset?: boolean;
/** **/
connect?: buildConnector.BuildOptions | buildConnector.connector | null;
/** The maximum length of request headers in bytes. Default: `16384` (16KiB). */
Expand Down
2 changes: 2 additions & 0 deletions types/dispatcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ declare namespace Dispatcher {
origin?: string | URL;
path: string;
method: HttpMethod;
/** Indicate wether or not send `connection` header with keep-alive value for long-living connections */
reset?: boolean;
/** Default: `null` */
body?: string | Buffer | Uint8Array | Readable | null | FormData;
/** Default: `null` */
Expand Down

0 comments on commit deb3835

Please sign in to comment.