undici-types 7.4.0 → 7.5.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/index.d.ts +4 -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/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import Agent from './agent'
|
|
|
12
12
|
import MockClient from './mock-client'
|
|
13
13
|
import MockPool from './mock-pool'
|
|
14
14
|
import MockAgent from './mock-agent'
|
|
15
|
+
import { MockCallHistory, MockCallHistoryLog } from './mock-call-history'
|
|
15
16
|
import mockErrors from './mock-errors'
|
|
16
17
|
import ProxyAgent from './proxy-agent'
|
|
17
18
|
import EnvHttpProxyAgent from './env-http-proxy-agent'
|
|
@@ -31,7 +32,7 @@ export * from './content-type'
|
|
|
31
32
|
export * from './cache'
|
|
32
33
|
export { Interceptable } from './mock-interceptor'
|
|
33
34
|
|
|
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 }
|
|
35
|
+
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 }
|
|
35
36
|
export default Undici
|
|
36
37
|
|
|
37
38
|
declare namespace Undici {
|
|
@@ -55,6 +56,8 @@ declare namespace Undici {
|
|
|
55
56
|
const MockClient: typeof import('./mock-client').default
|
|
56
57
|
const MockPool: typeof import('./mock-pool').default
|
|
57
58
|
const MockAgent: typeof import('./mock-agent').default
|
|
59
|
+
const MockCallHistory: typeof import('./mock-call-history').MockCallHistory
|
|
60
|
+
const MockCallHistoryLog: typeof import('./mock-call-history').MockCallHistoryLog
|
|
58
61
|
const mockErrors: typeof import('./mock-errors').default
|
|
59
62
|
const fetch: typeof import('./fetch').fetch
|
|
60
63
|
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 }
|