undici-types 7.4.0 → 7.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +1 -1
- package/dispatcher.d.ts +5 -3
- package/h2c-client.d.ts +75 -0
- package/index.d.ts +6 -1
- package/mock-agent.d.ts +12 -0
- package/mock-call-history.d.ts +111 -0
- package/package.json +1 -1
package/client.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ export declare namespace Client {
|
|
|
70
70
|
/** TODO */
|
|
71
71
|
maxRedirections?: number;
|
|
72
72
|
/** TODO */
|
|
73
|
-
connect?: buildConnector.BuildOptions | buildConnector.connector;
|
|
73
|
+
connect?: Partial<buildConnector.BuildOptions> | buildConnector.connector;
|
|
74
74
|
/** TODO */
|
|
75
75
|
maxRequestsPerClient?: number;
|
|
76
76
|
/** TODO */
|
package/dispatcher.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ type AbortSignal = unknown
|
|
|
12
12
|
|
|
13
13
|
export default Dispatcher
|
|
14
14
|
|
|
15
|
+
export type UndiciHeaders = Record<string, string | string[]> | IncomingHttpHeaders | string[] | Iterable<[string, string | string[] | undefined]> | null
|
|
16
|
+
|
|
15
17
|
/** Dispatcher is the core API used to dispatch requests. */
|
|
16
18
|
declare class Dispatcher extends EventEmitter {
|
|
17
19
|
/** 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. */
|
|
@@ -103,7 +105,7 @@ declare namespace Dispatcher {
|
|
|
103
105
|
/** Default: `null` */
|
|
104
106
|
body?: string | Buffer | Uint8Array | Readable | null | FormData;
|
|
105
107
|
/** Default: `null` */
|
|
106
|
-
headers?:
|
|
108
|
+
headers?: UndiciHeaders;
|
|
107
109
|
/** Query string params to be embedded in the request URL. Default: `null` */
|
|
108
110
|
query?: Record<string, any>;
|
|
109
111
|
/** Whether the requests can be safely retried or not. If `false` the request won't be sent until all preceding requests in the pipeline have completed. Default: `true` if `method` is `HEAD` or `GET`. */
|
|
@@ -127,7 +129,7 @@ declare namespace Dispatcher {
|
|
|
127
129
|
origin: string | URL;
|
|
128
130
|
path: string;
|
|
129
131
|
/** Default: `null` */
|
|
130
|
-
headers?:
|
|
132
|
+
headers?: UndiciHeaders;
|
|
131
133
|
/** Default: `null` */
|
|
132
134
|
signal?: AbortSignal | EventEmitter | null;
|
|
133
135
|
/** This argument parameter is passed through to `ConnectData` */
|
|
@@ -164,7 +166,7 @@ declare namespace Dispatcher {
|
|
|
164
166
|
/** Default: `'GET'` */
|
|
165
167
|
method?: string;
|
|
166
168
|
/** Default: `null` */
|
|
167
|
-
headers?:
|
|
169
|
+
headers?: UndiciHeaders;
|
|
168
170
|
/** A string of comma separated protocols, in descending preference order. Default: `'Websocket'` */
|
|
169
171
|
protocol?: string;
|
|
170
172
|
/** Default: `null` */
|
package/h2c-client.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { URL } from 'url'
|
|
2
|
+
import Dispatcher from './dispatcher'
|
|
3
|
+
import buildConnector from './connector'
|
|
4
|
+
|
|
5
|
+
type H2ClientOptions = Omit<Dispatcher.ConnectOptions, 'origin'>
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A basic H2C client, mapped on top a single TCP connection. Pipelining is disabled by default.
|
|
9
|
+
*/
|
|
10
|
+
export class H2CClient extends Dispatcher {
|
|
11
|
+
constructor (url: string | URL, options?: H2CClient.Options)
|
|
12
|
+
/** Property to get and set the pipelining factor. */
|
|
13
|
+
pipelining: number
|
|
14
|
+
/** `true` after `client.close()` has been called. */
|
|
15
|
+
closed: boolean
|
|
16
|
+
/** `true` after `client.destroyed()` has been called or `client.close()` has been called and the client shutdown has completed. */
|
|
17
|
+
destroyed: boolean
|
|
18
|
+
|
|
19
|
+
// Override dispatcher APIs.
|
|
20
|
+
override connect (
|
|
21
|
+
options: H2ClientOptions
|
|
22
|
+
): Promise<Dispatcher.ConnectData>
|
|
23
|
+
override connect (
|
|
24
|
+
options: H2ClientOptions,
|
|
25
|
+
callback: (err: Error | null, data: Dispatcher.ConnectData) => void
|
|
26
|
+
): void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export declare namespace H2CClient {
|
|
30
|
+
export interface Options {
|
|
31
|
+
/** The maximum length of request headers in bytes. Default: Node.js' `--max-http-header-size` or `16384` (16KiB). */
|
|
32
|
+
maxHeaderSize?: number;
|
|
33
|
+
/** The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers (Node 14 and above only). Default: `300e3` milliseconds (300s). */
|
|
34
|
+
headersTimeout?: number;
|
|
35
|
+
/** TODO */
|
|
36
|
+
connectTimeout?: number;
|
|
37
|
+
/** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Default: `300e3` milliseconds (300s). */
|
|
38
|
+
bodyTimeout?: number;
|
|
39
|
+
/** the timeout, in milliseconds, after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. Default: `4e3` milliseconds (4s). */
|
|
40
|
+
keepAliveTimeout?: number;
|
|
41
|
+
/** the maximum allowed `idleTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Default: `600e3` milliseconds (10min). */
|
|
42
|
+
keepAliveMaxTimeout?: number;
|
|
43
|
+
/** A number of milliseconds subtracted from server *keep-alive* hints when overriding `idleTimeout` to account for timing inaccuracies caused by e.g. transport latency. Default: `1e3` milliseconds (1s). */
|
|
44
|
+
keepAliveTimeoutThreshold?: number;
|
|
45
|
+
/** TODO */
|
|
46
|
+
socketPath?: string;
|
|
47
|
+
/** 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`. */
|
|
48
|
+
pipelining?: number;
|
|
49
|
+
/** If `true`, an error is thrown when the request content-length header doesn't match the length of the request body. Default: `true`. */
|
|
50
|
+
strictContentLength?: boolean;
|
|
51
|
+
/** TODO */
|
|
52
|
+
maxCachedSessions?: number;
|
|
53
|
+
/** TODO */
|
|
54
|
+
maxRedirections?: number;
|
|
55
|
+
/** TODO */
|
|
56
|
+
connect?: Omit<Partial<buildConnector.BuildOptions>, 'allowH2'> | buildConnector.connector;
|
|
57
|
+
/** TODO */
|
|
58
|
+
maxRequestsPerClient?: number;
|
|
59
|
+
/** TODO */
|
|
60
|
+
localAddress?: string;
|
|
61
|
+
/** Max response body size in bytes, -1 is disabled */
|
|
62
|
+
maxResponseSize?: number;
|
|
63
|
+
/** Enables a family autodetection algorithm that loosely implements section 5 of RFC 8305. */
|
|
64
|
+
autoSelectFamily?: boolean;
|
|
65
|
+
/** The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. */
|
|
66
|
+
autoSelectFamilyAttemptTimeout?: number;
|
|
67
|
+
/**
|
|
68
|
+
* @description Dictates the maximum number of concurrent streams for a single H2 session. It can be overridden by a SETTINGS remote frame.
|
|
69
|
+
* @default 100
|
|
70
|
+
*/
|
|
71
|
+
maxConcurrentStreams?: number
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default H2CClient
|
package/index.d.ts
CHANGED
|
@@ -6,12 +6,14 @@ import { RedirectHandler, DecoratorHandler } from './handlers'
|
|
|
6
6
|
|
|
7
7
|
import BalancedPool from './balanced-pool'
|
|
8
8
|
import Client from './client'
|
|
9
|
+
import H2CClient from './h2c-client'
|
|
9
10
|
import buildConnector from './connector'
|
|
10
11
|
import errors from './errors'
|
|
11
12
|
import Agent from './agent'
|
|
12
13
|
import MockClient from './mock-client'
|
|
13
14
|
import MockPool from './mock-pool'
|
|
14
15
|
import MockAgent from './mock-agent'
|
|
16
|
+
import { MockCallHistory, MockCallHistoryLog } from './mock-call-history'
|
|
15
17
|
import mockErrors from './mock-errors'
|
|
16
18
|
import ProxyAgent from './proxy-agent'
|
|
17
19
|
import EnvHttpProxyAgent from './env-http-proxy-agent'
|
|
@@ -31,7 +33,7 @@ export * from './content-type'
|
|
|
31
33
|
export * from './cache'
|
|
32
34
|
export { Interceptable } from './mock-interceptor'
|
|
33
35
|
|
|
34
|
-
export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, request, stream, pipeline, connect, upgrade, setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, getGlobalOrigin, interceptors, MockClient, MockPool, MockAgent, mockErrors, ProxyAgent, EnvHttpProxyAgent, RedirectHandler, DecoratorHandler, RetryHandler, RetryAgent }
|
|
36
|
+
export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, request, stream, pipeline, connect, upgrade, setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, getGlobalOrigin, interceptors, MockClient, MockPool, MockAgent, MockCallHistory, MockCallHistoryLog, mockErrors, ProxyAgent, EnvHttpProxyAgent, RedirectHandler, DecoratorHandler, RetryHandler, RetryAgent, H2CClient }
|
|
35
37
|
export default Undici
|
|
36
38
|
|
|
37
39
|
declare namespace Undici {
|
|
@@ -42,6 +44,7 @@ declare namespace Undici {
|
|
|
42
44
|
const RetryHandler: typeof import ('./retry-handler').default
|
|
43
45
|
const BalancedPool: typeof import('./balanced-pool').default
|
|
44
46
|
const Client: typeof import('./client').default
|
|
47
|
+
const H2CClient: typeof import('./h2c-client').default
|
|
45
48
|
const buildConnector: typeof import('./connector').default
|
|
46
49
|
const errors: typeof import('./errors').default
|
|
47
50
|
const Agent: typeof import('./agent').default
|
|
@@ -55,6 +58,8 @@ declare namespace Undici {
|
|
|
55
58
|
const MockClient: typeof import('./mock-client').default
|
|
56
59
|
const MockPool: typeof import('./mock-pool').default
|
|
57
60
|
const MockAgent: typeof import('./mock-agent').default
|
|
61
|
+
const MockCallHistory: typeof import('./mock-call-history').MockCallHistory
|
|
62
|
+
const MockCallHistoryLog: typeof import('./mock-call-history').MockCallHistoryLog
|
|
58
63
|
const mockErrors: typeof import('./mock-errors').default
|
|
59
64
|
const fetch: typeof import('./fetch').fetch
|
|
60
65
|
const Headers: typeof import('./fetch').Headers
|
package/mock-agent.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import Agent from './agent'
|
|
|
2
2
|
import Dispatcher from './dispatcher'
|
|
3
3
|
import { Interceptable, MockInterceptor } from './mock-interceptor'
|
|
4
4
|
import MockDispatch = MockInterceptor.MockDispatch
|
|
5
|
+
import { MockCallHistory } from './mock-call-history'
|
|
5
6
|
|
|
6
7
|
export default MockAgent
|
|
7
8
|
|
|
@@ -31,6 +32,14 @@ declare class MockAgent<TMockAgentOptions extends MockAgent.Options = MockAgent.
|
|
|
31
32
|
enableNetConnect (host: ((host: string) => boolean)): void
|
|
32
33
|
/** Causes all requests to throw when requests are not matched in a MockAgent intercept. */
|
|
33
34
|
disableNetConnect (): void
|
|
35
|
+
/** get call history. returns the MockAgent call history or undefined if the option is not enabled. */
|
|
36
|
+
getCallHistory (): MockCallHistory | undefined
|
|
37
|
+
/** clear every call history. Any MockCallHistoryLog will be deleted on the MockCallHistory instance */
|
|
38
|
+
clearCallHistory (): void
|
|
39
|
+
/** Enable call history. Any subsequence calls will then be registered. */
|
|
40
|
+
enableCallHistory (): this
|
|
41
|
+
/** Disable call history. Any subsequence calls will then not be registered. */
|
|
42
|
+
disableCallHistory (): this
|
|
34
43
|
pendingInterceptors (): PendingInterceptor[]
|
|
35
44
|
assertNoPendingInterceptors (options?: {
|
|
36
45
|
pendingInterceptorsFormatter?: PendingInterceptorsFormatter;
|
|
@@ -49,5 +58,8 @@ declare namespace MockAgent {
|
|
|
49
58
|
|
|
50
59
|
/** Ignore trailing slashes in the path */
|
|
51
60
|
ignoreTrailingSlash?: boolean;
|
|
61
|
+
|
|
62
|
+
/** Enable call history. you can either call MockAgent.enableCallHistory(). default false */
|
|
63
|
+
enableCallHistory?: boolean
|
|
52
64
|
}
|
|
53
65
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import Dispatcher from './dispatcher'
|
|
2
|
+
|
|
3
|
+
declare namespace MockCallHistoryLog {
|
|
4
|
+
/** request's configuration properties */
|
|
5
|
+
export type MockCallHistoryLogProperties = 'protocol' | 'host' | 'port' | 'origin' | 'path' | 'hash' | 'fullUrl' | 'method' | 'searchParams' | 'body' | 'headers'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** a log reflecting request configuration */
|
|
9
|
+
declare class MockCallHistoryLog {
|
|
10
|
+
constructor (requestInit: Dispatcher.DispatchOptions)
|
|
11
|
+
/** protocol used. ie. 'https:' or 'http:' etc... */
|
|
12
|
+
protocol: string
|
|
13
|
+
/** request's host. */
|
|
14
|
+
host: string
|
|
15
|
+
/** request's port. */
|
|
16
|
+
port: string
|
|
17
|
+
/** request's origin. ie. https://localhost:3000. */
|
|
18
|
+
origin: string
|
|
19
|
+
/** path. never contains searchParams. */
|
|
20
|
+
path: string
|
|
21
|
+
/** request's hash. */
|
|
22
|
+
hash: string
|
|
23
|
+
/** the full url requested. */
|
|
24
|
+
fullUrl: string
|
|
25
|
+
/** request's method. */
|
|
26
|
+
method: string
|
|
27
|
+
/** search params. */
|
|
28
|
+
searchParams: Record<string, string>
|
|
29
|
+
/** request's body */
|
|
30
|
+
body: string | null | undefined
|
|
31
|
+
/** request's headers */
|
|
32
|
+
headers: Record<string, string | string[]> | null | undefined
|
|
33
|
+
|
|
34
|
+
/** returns an Map of property / value pair */
|
|
35
|
+
toMap (): Map<MockCallHistoryLog.MockCallHistoryLogProperties, string | Record<string, string | string[]> | null | undefined>
|
|
36
|
+
|
|
37
|
+
/** returns a string computed with all key value pair */
|
|
38
|
+
toString (): string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare namespace MockCallHistory {
|
|
42
|
+
export type FilterCallsOperator = 'AND' | 'OR'
|
|
43
|
+
|
|
44
|
+
/** modify the filtering behavior */
|
|
45
|
+
export interface FilterCallsOptions {
|
|
46
|
+
/** the operator to apply when filtering. 'OR' will adds any MockCallHistoryLog matching any criteria given. 'AND' will adds only MockCallHistoryLog matching every criteria given. (default 'OR') */
|
|
47
|
+
operator?: FilterCallsOperator | Lowercase<FilterCallsOperator>
|
|
48
|
+
}
|
|
49
|
+
/** a function to be executed for filtering MockCallHistoryLog */
|
|
50
|
+
export type FilterCallsFunctionCriteria = (log: MockCallHistoryLog) => boolean
|
|
51
|
+
|
|
52
|
+
/** parameter to filter MockCallHistoryLog */
|
|
53
|
+
export type FilterCallsParameter = string | RegExp | undefined | null
|
|
54
|
+
|
|
55
|
+
/** an object to execute multiple filtering at once */
|
|
56
|
+
export interface FilterCallsObjectCriteria extends Record<string, FilterCallsParameter> {
|
|
57
|
+
/** filter by request protocol. ie https: */
|
|
58
|
+
protocol?: FilterCallsParameter;
|
|
59
|
+
/** filter by request host. */
|
|
60
|
+
host?: FilterCallsParameter;
|
|
61
|
+
/** filter by request port. */
|
|
62
|
+
port?: FilterCallsParameter;
|
|
63
|
+
/** filter by request origin. */
|
|
64
|
+
origin?: FilterCallsParameter;
|
|
65
|
+
/** filter by request path. */
|
|
66
|
+
path?: FilterCallsParameter;
|
|
67
|
+
/** filter by request hash. */
|
|
68
|
+
hash?: FilterCallsParameter;
|
|
69
|
+
/** filter by request fullUrl. */
|
|
70
|
+
fullUrl?: FilterCallsParameter;
|
|
71
|
+
/** filter by request method. */
|
|
72
|
+
method?: FilterCallsParameter;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** a call history to track requests configuration */
|
|
77
|
+
declare class MockCallHistory {
|
|
78
|
+
constructor (name: string)
|
|
79
|
+
/** returns an array of MockCallHistoryLog. */
|
|
80
|
+
calls (): Array<MockCallHistoryLog>
|
|
81
|
+
/** returns the first MockCallHistoryLog */
|
|
82
|
+
firstCall (): MockCallHistoryLog | undefined
|
|
83
|
+
/** returns the last MockCallHistoryLog. */
|
|
84
|
+
lastCall (): MockCallHistoryLog | undefined
|
|
85
|
+
/** returns the nth MockCallHistoryLog. */
|
|
86
|
+
nthCall (position: number): MockCallHistoryLog | undefined
|
|
87
|
+
/** return all MockCallHistoryLog matching any of criteria given. if an object is used with multiple properties, you can change the operator to apply during filtering on options */
|
|
88
|
+
filterCalls (criteria: MockCallHistory.FilterCallsFunctionCriteria | MockCallHistory.FilterCallsObjectCriteria | RegExp, options?: MockCallHistory.FilterCallsOptions): Array<MockCallHistoryLog>
|
|
89
|
+
/** return all MockCallHistoryLog matching the given protocol. if a string is given, it is matched with includes */
|
|
90
|
+
filterCallsByProtocol (protocol: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
91
|
+
/** return all MockCallHistoryLog matching the given host. if a string is given, it is matched with includes */
|
|
92
|
+
filterCallsByHost (host: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
93
|
+
/** return all MockCallHistoryLog matching the given port. if a string is given, it is matched with includes */
|
|
94
|
+
filterCallsByPort (port: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
95
|
+
/** return all MockCallHistoryLog matching the given origin. if a string is given, it is matched with includes */
|
|
96
|
+
filterCallsByOrigin (origin: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
97
|
+
/** return all MockCallHistoryLog matching the given path. if a string is given, it is matched with includes */
|
|
98
|
+
filterCallsByPath (path: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
99
|
+
/** return all MockCallHistoryLog matching the given hash. if a string is given, it is matched with includes */
|
|
100
|
+
filterCallsByHash (hash: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
101
|
+
/** return all MockCallHistoryLog matching the given fullUrl. if a string is given, it is matched with includes */
|
|
102
|
+
filterCallsByFullUrl (fullUrl: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
103
|
+
/** return all MockCallHistoryLog matching the given method. if a string is given, it is matched with includes */
|
|
104
|
+
filterCallsByMethod (method: MockCallHistory.FilterCallsParameter): Array<MockCallHistoryLog>
|
|
105
|
+
/** clear all MockCallHistoryLog on this MockCallHistory. */
|
|
106
|
+
clear (): void
|
|
107
|
+
/** use it with for..of loop or spread operator */
|
|
108
|
+
[Symbol.iterator]: () => Generator<MockCallHistoryLog>
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { MockCallHistoryLog, MockCallHistory }
|