Skip to content

Commit deb3835

Browse files
committed
feat(TS): add types
1 parent a8dd12e commit deb3835

6 files changed

Lines changed: 11 additions & 7 deletions

File tree

test/types/agent.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { URL } from 'url'
55

66
expectAssignable<Agent>(new Agent())
77
expectAssignable<Agent>(new Agent({}))
8-
expectAssignable<Agent>(new Agent({ maxRedirections: 1 }))
8+
expectAssignable<Agent>(new Agent({ maxRedirections: 1, reset: true }))
99
expectAssignable<Agent>(new Agent({ factory: () => new Dispatcher() }))
1010

1111
{
@@ -93,7 +93,7 @@ expectAssignable<Agent>(new Agent({ factory: () => new Dispatcher() }))
9393
}))
9494

9595
// dispatch
96-
expectAssignable<boolean>(agent.dispatch({ origin: '', path: '', method: 'GET' }, {}))
96+
expectAssignable<boolean>(agent.dispatch({ reset: true, origin: '', path: '', method: 'GET' }, {}))
9797
expectAssignable<boolean>(agent.dispatch({ origin: '', path: '', method: 'GET', maxRedirections: 1 }, {}))
9898

9999
// close

test/types/api.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Dispatcher, request, stream, pipeline, connect, upgrade } from '../..'
55
// request
66
expectAssignable<Promise<Dispatcher.ResponseData>>(request(''))
77
expectAssignable<Promise<Dispatcher.ResponseData>>(request('', { }))
8-
expectAssignable<Promise<Dispatcher.ResponseData>>(request('', { method: 'GET' }))
8+
expectAssignable<Promise<Dispatcher.ResponseData>>(request('', { method: 'GET', reset: true }))
99

1010
// stream
1111
expectAssignable<Promise<Dispatcher.StreamData>>(stream('', { method: 'GET' }, data => {

test/types/balanced-pool.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ expectAssignable<BalancedPool>(new BalancedPool('', {}))
88
expectAssignable<BalancedPool>(new BalancedPool(new URL('http://localhost'), {}))
99
expectAssignable<BalancedPool>(new BalancedPool('', { factory: () => new Dispatcher() }))
1010
expectAssignable<BalancedPool>(new BalancedPool('', { factory: (origin, opts) => new Client(origin, opts) }))
11-
expectAssignable<BalancedPool>(new BalancedPool('', { connections: 1 }))
11+
expectAssignable<BalancedPool>(new BalancedPool('', { connections: 1, reset: true }))
1212
expectAssignable<BalancedPool>(new BalancedPool(['http://localhost:4242', 'http://www.nodejs.org']))
1313

1414
{
@@ -27,7 +27,7 @@ expectAssignable<BalancedPool>(new BalancedPool(['http://localhost:4242', 'http:
2727
// request
2828
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: '', path: '', method: 'GET' }))
2929
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: new URL('http://localhost'), path: '', method: 'GET' }))
30-
expectAssignable<void>(pool.request({ origin: '', path: '', method: 'GET' }, (err, data) => {
30+
expectAssignable<void>(pool.request({ reset: false, origin: '', path: '', method: 'GET' }, (err, data) => {
3131
expectAssignable<Error | null>(err)
3232
expectAssignable<Dispatcher.ResponseData>(data)
3333
}))

test/types/pool.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ expectAssignable<Pool>(new Pool('', {}))
88
expectAssignable<Pool>(new Pool(new URL('http://localhost'), {}))
99
expectAssignable<Pool>(new Pool('', { factory: () => new Dispatcher() }))
1010
expectAssignable<Pool>(new Pool('', { factory: (origin, opts) => new Client(origin, opts) }))
11-
expectAssignable<Pool>(new Pool('', { connections: 1 }))
11+
expectAssignable<Pool>(new Pool('', { connections: 1, reset: true }))
1212

1313
{
1414
const pool = new Pool('', {})
@@ -21,7 +21,7 @@ expectAssignable<Pool>(new Pool('', { connections: 1 }))
2121
// request
2222
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: '', path: '', method: 'GET' }))
2323
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: new URL('http://localhost'), path: '', method: 'GET' }))
24-
expectAssignable<void>(pool.request({ origin: '', path: '', method: 'GET' }, (err, data) => {
24+
expectAssignable<void>(pool.request({ reset: false, origin: '', path: '', method: 'GET' }, (err, data) => {
2525
expectAssignable<Error | null>(err)
2626
expectAssignable<Dispatcher.ResponseData>(data)
2727
}))

types/client.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ declare namespace Client {
2727
keepAliveTimeoutThreshold?: number | null;
2828
/** 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`. */
2929
pipelining?: number | null;
30+
/** Indicate wether or not send `connection` header with keep-alive value for long-living connections */
31+
reset?: boolean;
3032
/** **/
3133
connect?: buildConnector.BuildOptions | buildConnector.connector | null;
3234
/** The maximum length of request headers in bytes. Default: `16384` (16KiB). */

types/dispatcher.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ declare namespace Dispatcher {
9797
origin?: string | URL;
9898
path: string;
9999
method: HttpMethod;
100+
/** Indicate wether or not send `connection` header with keep-alive value for long-living connections */
101+
reset?: boolean;
100102
/** Default: `null` */
101103
body?: string | Buffer | Uint8Array | Readable | null | FormData;
102104
/** Default: `null` */

0 commit comments

Comments
 (0)