undici-types 6.21.0 → 7.1.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/formdata.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // Based on https://github.com/octet-stream/form-data/blob/2d0f0dc371517444ce1f22cdde13f51995d0953a/lib/FormData.ts (MIT)
2
2
  /// <reference types="node" />
3
3
 
4
- import { File } from './file'
4
+ import { File } from 'buffer'
5
5
  import { SpecIterableIterator } from './fetch'
6
6
 
7
7
  /**
@@ -24,7 +24,7 @@ export declare class FormData {
24
24
  or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). If none of these are specified the value is converted to a string.
25
25
  * @param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
26
26
  */
27
- append(name: string, value: unknown, fileName?: string): void
27
+ append (name: string, value: unknown, fileName?: string): void
28
28
 
29
29
  /**
30
30
  * Set a new value for an existing key inside FormData,
@@ -36,7 +36,7 @@ export declare class FormData {
36
36
  * @param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
37
37
  *
38
38
  */
39
- set(name: string, value: unknown, fileName?: string): void
39
+ set (name: string, value: unknown, fileName?: string): void
40
40
 
41
41
  /**
42
42
  * Returns the first value associated with a given key from within a `FormData` object.
@@ -46,7 +46,7 @@ export declare class FormData {
46
46
  *
47
47
  * @returns A `FormDataEntryValue` containing the value. If the key doesn't exist, the method returns null.
48
48
  */
49
- get(name: string): FormDataEntryValue | null
49
+ get (name: string): FormDataEntryValue | null
50
50
 
51
51
  /**
52
52
  * Returns all the values associated with a given key from within a `FormData` object.
@@ -55,7 +55,7 @@ export declare class FormData {
55
55
  *
56
56
  * @returns An array of `FormDataEntryValue` whose key matches the value passed in the `name` parameter. If the key doesn't exist, the method returns an empty list.
57
57
  */
58
- getAll(name: string): FormDataEntryValue[]
58
+ getAll (name: string): FormDataEntryValue[]
59
59
 
60
60
  /**
61
61
  * Returns a boolean stating whether a `FormData` object contains a certain key.
@@ -64,14 +64,14 @@ export declare class FormData {
64
64
  *
65
65
  * @return A boolean value.
66
66
  */
67
- has(name: string): boolean
67
+ has (name: string): boolean
68
68
 
69
69
  /**
70
70
  * Deletes a key and its value(s) from a `FormData` object.
71
71
  *
72
72
  * @param name The name of the key you want to delete.
73
73
  */
74
- delete(name: string): void
74
+ delete (name: string): void
75
75
 
76
76
  /**
77
77
  * Executes given callback function for each field of the FormData instance
@@ -1,9 +1,9 @@
1
- import Dispatcher from "./dispatcher";
1
+ import Dispatcher from './dispatcher'
2
+
3
+ declare function setGlobalDispatcher<DispatcherImplementation extends Dispatcher> (dispatcher: DispatcherImplementation): void
4
+ declare function getGlobalDispatcher (): Dispatcher
2
5
 
3
6
  export {
4
7
  getGlobalDispatcher,
5
8
  setGlobalDispatcher
6
9
  }
7
-
8
- declare function setGlobalDispatcher<DispatcherImplementation extends Dispatcher>(dispatcher: DispatcherImplementation): void;
9
- declare function getGlobalDispatcher(): Dispatcher;
@@ -1,7 +1,7 @@
1
+ declare function setGlobalOrigin (origin: string | URL | undefined): void
2
+ declare function getGlobalOrigin (): URL | undefined
3
+
1
4
  export {
2
- setGlobalOrigin,
3
- getGlobalOrigin
5
+ setGlobalOrigin,
6
+ getGlobalOrigin
4
7
  }
5
-
6
- declare function setGlobalOrigin(origin: string | URL | undefined): void;
7
- declare function getGlobalOrigin(): URL | undefined;
package/handlers.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- import Dispatcher from "./dispatcher";
1
+ import Dispatcher from './dispatcher'
2
2
 
3
- export declare class RedirectHandler implements Dispatcher.DispatchHandlers {
4
- constructor(
3
+ export declare class RedirectHandler implements Dispatcher.DispatchHandler {
4
+ constructor (
5
5
  dispatch: Dispatcher,
6
6
  maxRedirections: number,
7
7
  opts: Dispatcher.DispatchOptions,
8
- handler: Dispatcher.DispatchHandlers,
8
+ handler: Dispatcher.DispatchHandler,
9
9
  redirectionLimitReached: boolean
10
- );
10
+ )
11
11
  }
12
12
 
13
- export declare class DecoratorHandler implements Dispatcher.DispatchHandlers {
14
- constructor(handler: Dispatcher.DispatchHandlers);
13
+ export declare class DecoratorHandler implements Dispatcher.DispatchHandler {
14
+ constructor (handler: Dispatcher.DispatchHandler)
15
15
  }
package/header.d.ts CHANGED
@@ -1,4 +1,160 @@
1
+ import { Autocomplete } from './utility'
2
+
1
3
  /**
2
4
  * The header type declaration of `undici`.
3
5
  */
4
- export type IncomingHttpHeaders = Record<string, string | string[] | undefined>;
6
+ export type IncomingHttpHeaders = Record<string, string | string[] | undefined>
7
+
8
+ type HeaderNames = Autocomplete<
9
+ | 'Accept'
10
+ | 'Accept-CH'
11
+ | 'Accept-Charset'
12
+ | 'Accept-Encoding'
13
+ | 'Accept-Language'
14
+ | 'Accept-Patch'
15
+ | 'Accept-Post'
16
+ | 'Accept-Ranges'
17
+ | 'Access-Control-Allow-Credentials'
18
+ | 'Access-Control-Allow-Headers'
19
+ | 'Access-Control-Allow-Methods'
20
+ | 'Access-Control-Allow-Origin'
21
+ | 'Access-Control-Expose-Headers'
22
+ | 'Access-Control-Max-Age'
23
+ | 'Access-Control-Request-Headers'
24
+ | 'Access-Control-Request-Method'
25
+ | 'Age'
26
+ | 'Allow'
27
+ | 'Alt-Svc'
28
+ | 'Alt-Used'
29
+ | 'Authorization'
30
+ | 'Cache-Control'
31
+ | 'Clear-Site-Data'
32
+ | 'Connection'
33
+ | 'Content-Disposition'
34
+ | 'Content-Encoding'
35
+ | 'Content-Language'
36
+ | 'Content-Length'
37
+ | 'Content-Location'
38
+ | 'Content-Range'
39
+ | 'Content-Security-Policy'
40
+ | 'Content-Security-Policy-Report-Only'
41
+ | 'Content-Type'
42
+ | 'Cookie'
43
+ | 'Cross-Origin-Embedder-Policy'
44
+ | 'Cross-Origin-Opener-Policy'
45
+ | 'Cross-Origin-Resource-Policy'
46
+ | 'Date'
47
+ | 'Device-Memory'
48
+ | 'ETag'
49
+ | 'Expect'
50
+ | 'Expect-CT'
51
+ | 'Expires'
52
+ | 'Forwarded'
53
+ | 'From'
54
+ | 'Host'
55
+ | 'If-Match'
56
+ | 'If-Modified-Since'
57
+ | 'If-None-Match'
58
+ | 'If-Range'
59
+ | 'If-Unmodified-Since'
60
+ | 'Keep-Alive'
61
+ | 'Last-Modified'
62
+ | 'Link'
63
+ | 'Location'
64
+ | 'Max-Forwards'
65
+ | 'Origin'
66
+ | 'Permissions-Policy'
67
+ | 'Priority'
68
+ | 'Proxy-Authenticate'
69
+ | 'Proxy-Authorization'
70
+ | 'Range'
71
+ | 'Referer'
72
+ | 'Referrer-Policy'
73
+ | 'Retry-After'
74
+ | 'Sec-Fetch-Dest'
75
+ | 'Sec-Fetch-Mode'
76
+ | 'Sec-Fetch-Site'
77
+ | 'Sec-Fetch-User'
78
+ | 'Sec-Purpose'
79
+ | 'Sec-WebSocket-Accept'
80
+ | 'Server'
81
+ | 'Server-Timing'
82
+ | 'Service-Worker-Navigation-Preload'
83
+ | 'Set-Cookie'
84
+ | 'SourceMap'
85
+ | 'Strict-Transport-Security'
86
+ | 'TE'
87
+ | 'Timing-Allow-Origin'
88
+ | 'Trailer'
89
+ | 'Transfer-Encoding'
90
+ | 'Upgrade'
91
+ | 'Upgrade-Insecure-Requests'
92
+ | 'User-Agent'
93
+ | 'Vary'
94
+ | 'Via'
95
+ | 'WWW-Authenticate'
96
+ | 'X-Content-Type-Options'
97
+ | 'X-Frame-Options'
98
+ >
99
+
100
+ type IANARegisteredMimeType = Autocomplete<
101
+ | 'audio/aac'
102
+ | 'video/x-msvideo'
103
+ | 'image/avif'
104
+ | 'video/av1'
105
+ | 'application/octet-stream'
106
+ | 'image/bmp'
107
+ | 'text/css'
108
+ | 'text/csv'
109
+ | 'application/vnd.ms-fontobject'
110
+ | 'application/epub+zip'
111
+ | 'image/gif'
112
+ | 'application/gzip'
113
+ | 'text/html'
114
+ | 'image/x-icon'
115
+ | 'text/calendar'
116
+ | 'image/jpeg'
117
+ | 'text/javascript'
118
+ | 'application/json'
119
+ | 'application/ld+json'
120
+ | 'audio/x-midi'
121
+ | 'audio/mpeg'
122
+ | 'video/mp4'
123
+ | 'video/mpeg'
124
+ | 'audio/ogg'
125
+ | 'video/ogg'
126
+ | 'application/ogg'
127
+ | 'audio/opus'
128
+ | 'font/otf'
129
+ | 'application/pdf'
130
+ | 'image/png'
131
+ | 'application/rtf'
132
+ | 'image/svg+xml'
133
+ | 'image/tiff'
134
+ | 'video/mp2t'
135
+ | 'font/ttf'
136
+ | 'text/plain'
137
+ | 'application/wasm'
138
+ | 'video/webm'
139
+ | 'audio/webm'
140
+ | 'image/webp'
141
+ | 'font/woff'
142
+ | 'font/woff2'
143
+ | 'application/xhtml+xml'
144
+ | 'application/xml'
145
+ | 'application/zip'
146
+ | 'video/3gpp'
147
+ | 'video/3gpp2'
148
+ | 'model/gltf+json'
149
+ | 'model/gltf-binary'
150
+ >
151
+
152
+ type KnownHeaderValues = {
153
+ 'content-type': IANARegisteredMimeType
154
+ }
155
+
156
+ export type HeaderRecord = {
157
+ [K in HeaderNames | Lowercase<HeaderNames>]?: Lowercase<K> extends keyof KnownHeaderValues
158
+ ? KnownHeaderValues[Lowercase<K>]
159
+ : string
160
+ }
package/index.d.ts CHANGED
@@ -1,22 +1,22 @@
1
- import Dispatcher from'./dispatcher'
1
+ import Dispatcher from './dispatcher'
2
2
  import { setGlobalDispatcher, getGlobalDispatcher } from './global-dispatcher'
3
3
  import { setGlobalOrigin, getGlobalOrigin } from './global-origin'
4
- import Pool from'./pool'
4
+ import Pool from './pool'
5
5
  import { RedirectHandler, DecoratorHandler } from './handlers'
6
6
 
7
7
  import BalancedPool from './balanced-pool'
8
- import Client from'./client'
9
- import buildConnector from'./connector'
10
- import errors from'./errors'
11
- import Agent from'./agent'
12
- import MockClient from'./mock-client'
13
- import MockPool from'./mock-pool'
14
- import MockAgent from'./mock-agent'
15
- import mockErrors from'./mock-errors'
16
- import ProxyAgent from'./proxy-agent'
8
+ import Client from './client'
9
+ import buildConnector from './connector'
10
+ import errors from './errors'
11
+ import Agent from './agent'
12
+ import MockClient from './mock-client'
13
+ import MockPool from './mock-pool'
14
+ import MockAgent from './mock-agent'
15
+ import mockErrors from './mock-errors'
16
+ import ProxyAgent from './proxy-agent'
17
17
  import EnvHttpProxyAgent from './env-http-proxy-agent'
18
- import RetryHandler from'./retry-handler'
19
- import RetryAgent from'./retry-agent'
18
+ import RetryHandler from './retry-handler'
19
+ import RetryAgent from './retry-agent'
20
20
  import { request, pipeline, stream, connect, upgrade } from './api'
21
21
  import interceptors from './interceptors'
22
22
 
@@ -24,8 +24,6 @@ export * from './util'
24
24
  export * from './cookies'
25
25
  export * from './eventsource'
26
26
  export * from './fetch'
27
- export * from './file'
28
- export * from './filereader'
29
27
  export * from './formdata'
30
28
  export * from './diagnostics-channel'
31
29
  export * from './websocket'
@@ -37,35 +35,35 @@ export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent,
37
35
  export default Undici
38
36
 
39
37
  declare namespace Undici {
40
- var Dispatcher: typeof import('./dispatcher').default
41
- var Pool: typeof import('./pool').default;
42
- var RedirectHandler: typeof import ('./handlers').RedirectHandler
43
- var DecoratorHandler: typeof import ('./handlers').DecoratorHandler
44
- var RetryHandler: typeof import ('./retry-handler').default
45
- var createRedirectInterceptor: typeof import ('./interceptors').default.createRedirectInterceptor
46
- var BalancedPool: typeof import('./balanced-pool').default;
47
- var Client: typeof import('./client').default;
48
- var buildConnector: typeof import('./connector').default;
49
- var errors: typeof import('./errors').default;
50
- var Agent: typeof import('./agent').default;
51
- var setGlobalDispatcher: typeof import('./global-dispatcher').setGlobalDispatcher;
52
- var getGlobalDispatcher: typeof import('./global-dispatcher').getGlobalDispatcher;
53
- var request: typeof import('./api').request;
54
- var stream: typeof import('./api').stream;
55
- var pipeline: typeof import('./api').pipeline;
56
- var connect: typeof import('./api').connect;
57
- var upgrade: typeof import('./api').upgrade;
58
- var MockClient: typeof import('./mock-client').default;
59
- var MockPool: typeof import('./mock-pool').default;
60
- var MockAgent: typeof import('./mock-agent').default;
61
- var mockErrors: typeof import('./mock-errors').default;
62
- var fetch: typeof import('./fetch').fetch;
63
- var Headers: typeof import('./fetch').Headers;
64
- var Response: typeof import('./fetch').Response;
65
- var Request: typeof import('./fetch').Request;
66
- var FormData: typeof import('./formdata').FormData;
67
- var File: typeof import('./file').File;
68
- var FileReader: typeof import('./filereader').FileReader;
69
- var caches: typeof import('./cache').caches;
70
- var interceptors: typeof import('./interceptors').default;
38
+ const Dispatcher: typeof import('./dispatcher').default
39
+ const Pool: typeof import('./pool').default
40
+ const RedirectHandler: typeof import ('./handlers').RedirectHandler
41
+ const DecoratorHandler: typeof import ('./handlers').DecoratorHandler
42
+ const RetryHandler: typeof import ('./retry-handler').default
43
+ const BalancedPool: typeof import('./balanced-pool').default
44
+ const Client: typeof import('./client').default
45
+ const buildConnector: typeof import('./connector').default
46
+ const errors: typeof import('./errors').default
47
+ const Agent: typeof import('./agent').default
48
+ const setGlobalDispatcher: typeof import('./global-dispatcher').setGlobalDispatcher
49
+ const getGlobalDispatcher: typeof import('./global-dispatcher').getGlobalDispatcher
50
+ const request: typeof import('./api').request
51
+ const stream: typeof import('./api').stream
52
+ const pipeline: typeof import('./api').pipeline
53
+ const connect: typeof import('./api').connect
54
+ const upgrade: typeof import('./api').upgrade
55
+ const MockClient: typeof import('./mock-client').default
56
+ const MockPool: typeof import('./mock-pool').default
57
+ const MockAgent: typeof import('./mock-agent').default
58
+ const mockErrors: typeof import('./mock-errors').default
59
+ const fetch: typeof import('./fetch').fetch
60
+ const Headers: typeof import('./fetch').Headers
61
+ const Response: typeof import('./fetch').Response
62
+ const Request: typeof import('./fetch').Request
63
+ const FormData: typeof import('./formdata').FormData
64
+ const caches: typeof import('./cache').caches
65
+ const interceptors: typeof import('./interceptors').default
66
+ const cacheStores: {
67
+ MemoryCacheStore: typeof import('./cache-interceptor').default.MemoryCacheStore
68
+ }
71
69
  }
package/interceptors.d.ts CHANGED
@@ -1,17 +1,34 @@
1
- import Dispatcher from "./dispatcher";
2
- import RetryHandler from "./retry-handler";
1
+ import CacheHandler from './cache-interceptor'
2
+ import Dispatcher from './dispatcher'
3
+ import RetryHandler from './retry-handler'
4
+ import { LookupOptions } from 'node:dns'
3
5
 
4
- export default Interceptors;
6
+ export default Interceptors
5
7
 
6
8
  declare namespace Interceptors {
7
9
  export type DumpInterceptorOpts = { maxSize?: number }
8
10
  export type RetryInterceptorOpts = RetryHandler.RetryOptions
9
11
  export type RedirectInterceptorOpts = { maxRedirections?: number }
12
+
10
13
  export type ResponseErrorInterceptorOpts = { throwOnError: boolean }
14
+ export type CacheInterceptorOpts = CacheHandler.CacheOptions
15
+
16
+ // DNS interceptor
17
+ export type DNSInterceptorRecord = { address: string, ttl: number, family: 4 | 6 }
18
+ export type DNSInterceptorOriginRecords = { 4: { ips: DNSInterceptorRecord[] } | null, 6: { ips: DNSInterceptorRecord[] } | null }
19
+ export type DNSInterceptorOpts = {
20
+ maxTTL?: number
21
+ maxItems?: number
22
+ lookup?: (hostname: string, options: LookupOptions, callback: (err: NodeJS.ErrnoException | null, addresses: DNSInterceptorRecord[]) => void) => void
23
+ pick?: (origin: URL, records: DNSInterceptorOriginRecords, affinity: 4 | 6) => DNSInterceptorRecord
24
+ dualStack?: boolean
25
+ affinity?: 4 | 6
26
+ }
11
27
 
12
- export function createRedirectInterceptor(opts: RedirectInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
13
- export function dump(opts?: DumpInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
14
- export function retry(opts?: RetryInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
15
- export function redirect(opts?: RedirectInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
16
- export function responseError(opts?: ResponseErrorInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
28
+ export function dump (opts?: DumpInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
29
+ export function retry (opts?: RetryInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
30
+ export function redirect (opts?: RedirectInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
31
+ export function responseError (opts?: ResponseErrorInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
32
+ export function dns (opts?: DNSInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
33
+ export function cache (opts?: CacheInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
17
34
  }
package/mock-agent.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import Agent from './agent'
2
2
  import Dispatcher from './dispatcher'
3
3
  import { Interceptable, MockInterceptor } from './mock-interceptor'
4
- import MockDispatch = MockInterceptor.MockDispatch;
4
+ import MockDispatch = MockInterceptor.MockDispatch
5
5
 
6
6
  export default MockAgent
7
7
 
@@ -11,30 +11,30 @@ interface PendingInterceptor extends MockDispatch {
11
11
 
12
12
  /** A mocked Agent class that implements the Agent API. It allows one to intercept HTTP requests made through undici and return mocked responses instead. */
13
13
  declare class MockAgent<TMockAgentOptions extends MockAgent.Options = MockAgent.Options> extends Dispatcher {
14
- constructor(options?: MockAgent.Options)
14
+ constructor (options?: TMockAgentOptions)
15
15
  /** Creates and retrieves mock Dispatcher instances which can then be used to intercept HTTP requests. If the number of connections on the mock agent is set to 1, a MockClient instance is returned. Otherwise a MockPool instance is returned. */
16
- get<TInterceptable extends Interceptable>(origin: string): TInterceptable;
17
- get<TInterceptable extends Interceptable>(origin: RegExp): TInterceptable;
18
- get<TInterceptable extends Interceptable>(origin: ((origin: string) => boolean)): TInterceptable;
16
+ get<TInterceptable extends Interceptable>(origin: string): TInterceptable
17
+ get<TInterceptable extends Interceptable>(origin: RegExp): TInterceptable
18
+ get<TInterceptable extends Interceptable>(origin: ((origin: string) => boolean)): TInterceptable
19
19
  /** Dispatches a mocked request. */
20
- dispatch(options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean;
20
+ dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean
21
21
  /** Closes the mock agent and waits for registered mock pools and clients to also close before resolving. */
22
- close(): Promise<void>;
22
+ close (): Promise<void>
23
23
  /** Disables mocking in MockAgent. */
24
- deactivate(): void;
24
+ deactivate (): void
25
25
  /** Enables mocking in a MockAgent instance. When instantiated, a MockAgent is automatically activated. Therefore, this method is only effective after `MockAgent.deactivate` has been called. */
26
- activate(): void;
26
+ activate (): void
27
27
  /** Define host matchers so only matching requests that aren't intercepted by the mock dispatchers will be attempted. */
28
- enableNetConnect(): void;
29
- enableNetConnect(host: string): void;
30
- enableNetConnect(host: RegExp): void;
31
- enableNetConnect(host: ((host: string) => boolean)): void;
28
+ enableNetConnect (): void
29
+ enableNetConnect (host: string): void
30
+ enableNetConnect (host: RegExp): void
31
+ enableNetConnect (host: ((host: string) => boolean)): void
32
32
  /** Causes all requests to throw when requests are not matched in a MockAgent intercept. */
33
- disableNetConnect(): void;
34
- pendingInterceptors(): PendingInterceptor[];
35
- assertNoPendingInterceptors(options?: {
33
+ disableNetConnect (): void
34
+ pendingInterceptors (): PendingInterceptor[]
35
+ assertNoPendingInterceptors (options?: {
36
36
  pendingInterceptorsFormatter?: PendingInterceptorsFormatter;
37
- }): void;
37
+ }): void
38
38
  }
39
39
 
40
40
  interface PendingInterceptorsFormatter {
@@ -45,6 +45,9 @@ declare namespace MockAgent {
45
45
  /** MockAgent options. */
46
46
  export interface Options extends Agent.Options {
47
47
  /** A custom agent to be encapsulated by the MockAgent. */
48
- agent?: Agent;
48
+ agent?: Dispatcher;
49
+
50
+ /** Ignore trailing slashes in the path */
51
+ ignoreTrailingSlash?: boolean;
49
52
  }
50
53
  }
package/mock-client.d.ts CHANGED
@@ -7,13 +7,13 @@ export default MockClient
7
7
 
8
8
  /** MockClient extends the Client API and allows one to mock requests. */
9
9
  declare class MockClient extends Client implements Interceptable {
10
- constructor(origin: string, options: MockClient.Options);
10
+ constructor (origin: string, options: MockClient.Options)
11
11
  /** Intercepts any matching requests that use the same origin as this mock client. */
12
- intercept(options: MockInterceptor.Options): MockInterceptor;
12
+ intercept (options: MockInterceptor.Options): MockInterceptor
13
13
  /** Dispatches a mocked request. */
14
- dispatch(options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandlers): boolean;
14
+ dispatch (options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandler): boolean
15
15
  /** Closes the mock client and gracefully waits for enqueued requests to complete. */
16
- close(): Promise<void>;
16
+ close (): Promise<void>
17
17
  }
18
18
 
19
19
  declare namespace MockClient {
package/mock-errors.d.ts CHANGED
@@ -5,8 +5,8 @@ export default MockErrors
5
5
  declare namespace MockErrors {
6
6
  /** The request does not match any registered mock dispatches. */
7
7
  export class MockNotMatchedError extends Errors.UndiciError {
8
- constructor(message?: string);
9
- name: 'MockNotMatchedError';
10
- code: 'UND_MOCK_ERR_MOCK_NOT_MATCHED';
8
+ constructor (message?: string)
9
+ name: 'MockNotMatchedError'
10
+ code: 'UND_MOCK_ERR_MOCK_NOT_MATCHED'
11
11
  }
12
12
  }
@@ -1,42 +1,36 @@
1
1
  import { IncomingHttpHeaders } from './header'
2
- import Dispatcher from './dispatcher';
2
+ import Dispatcher from './dispatcher'
3
3
  import { BodyInit, Headers } from './fetch'
4
4
 
5
- export {
6
- Interceptable,
7
- MockInterceptor,
8
- MockScope
9
- }
10
-
11
5
  /** The scope associated with a mock dispatch. */
12
6
  declare class MockScope<TData extends object = object> {
13
- constructor(mockDispatch: MockInterceptor.MockDispatch<TData>);
7
+ constructor (mockDispatch: MockInterceptor.MockDispatch<TData>)
14
8
  /** Delay a reply by a set amount of time in ms. */
15
- delay(waitInMs: number): MockScope<TData>;
9
+ delay (waitInMs: number): MockScope<TData>
16
10
  /** Persist the defined mock data for the associated reply. It will return the defined mock data indefinitely. */
17
- persist(): MockScope<TData>;
11
+ persist (): MockScope<TData>
18
12
  /** Define a reply for a set amount of matching requests. */
19
- times(repeatTimes: number): MockScope<TData>;
13
+ times (repeatTimes: number): MockScope<TData>
20
14
  }
21
15
 
22
16
  /** The interceptor for a Mock. */
23
17
  declare class MockInterceptor {
24
- constructor(options: MockInterceptor.Options, mockDispatches: MockInterceptor.MockDispatch[]);
18
+ constructor (options: MockInterceptor.Options, mockDispatches: MockInterceptor.MockDispatch[])
25
19
  /** Mock an undici request with the defined reply. */
26
- reply<TData extends object = object>(replyOptionsCallback: MockInterceptor.MockReplyOptionsCallback<TData>): MockScope<TData>;
20
+ reply<TData extends object = object>(replyOptionsCallback: MockInterceptor.MockReplyOptionsCallback<TData>): MockScope<TData>
27
21
  reply<TData extends object = object>(
28
22
  statusCode: number,
29
23
  data?: TData | Buffer | string | MockInterceptor.MockResponseDataHandler<TData>,
30
24
  responseOptions?: MockInterceptor.MockResponseOptions
31
- ): MockScope<TData>;
25
+ ): MockScope<TData>
32
26
  /** Mock an undici request by throwing the defined reply error. */
33
- replyWithError<TError extends Error = Error>(error: TError): MockScope;
27
+ replyWithError<TError extends Error = Error>(error: TError): MockScope
34
28
  /** Set default reply headers on the interceptor for subsequent mocked replies. */
35
- defaultReplyHeaders(headers: IncomingHttpHeaders): MockInterceptor;
29
+ defaultReplyHeaders (headers: IncomingHttpHeaders): MockInterceptor
36
30
  /** Set default reply trailers on the interceptor for subsequent mocked replies. */
37
- defaultReplyTrailers(trailers: Record<string, string>): MockInterceptor;
31
+ defaultReplyTrailers (trailers: Record<string, string>): MockInterceptor
38
32
  /** Set automatically calculated content-length header on subsequent mocked replies. */
39
- replyContentLength(): MockInterceptor;
33
+ replyContentLength (): MockInterceptor
40
34
  }
41
35
 
42
36
  declare namespace MockInterceptor {
@@ -80,7 +74,7 @@ declare namespace MockInterceptor {
80
74
 
81
75
  export type MockResponseDataHandler<TData extends object = object> = (
82
76
  opts: MockResponseCallbackOptions
83
- ) => TData | Buffer | string;
77
+ ) => TData | Buffer | string
84
78
 
85
79
  export type MockReplyOptionsCallback<TData extends object = object> = (
86
80
  opts: MockResponseCallbackOptions
@@ -91,3 +85,9 @@ interface Interceptable extends Dispatcher {
91
85
  /** Intercepts any matching requests that use the same origin as this mock client. */
92
86
  intercept(options: MockInterceptor.Options): MockInterceptor;
93
87
  }
88
+
89
+ export {
90
+ Interceptable,
91
+ MockInterceptor,
92
+ MockScope
93
+ }
package/mock-pool.d.ts CHANGED
@@ -7,13 +7,13 @@ export default MockPool
7
7
 
8
8
  /** MockPool extends the Pool API and allows one to mock requests. */
9
9
  declare class MockPool extends Pool implements Interceptable {
10
- constructor(origin: string, options: MockPool.Options);
10
+ constructor (origin: string, options: MockPool.Options)
11
11
  /** Intercepts any matching requests that use the same origin as this mock pool. */
12
- intercept(options: MockInterceptor.Options): MockInterceptor;
12
+ intercept (options: MockInterceptor.Options): MockInterceptor
13
13
  /** Dispatches a mocked request. */
14
- dispatch(options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandlers): boolean;
14
+ dispatch (options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandler): boolean
15
15
  /** Closes the mock pool and gracefully waits for enqueued requests to complete. */
16
- close(): Promise<void>;
16
+ close (): Promise<void>
17
17
  }
18
18
 
19
19
  declare namespace MockPool {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undici-types",
3
- "version": "6.21.0",
3
+ "version": "7.1.0",
4
4
  "description": "A stand-alone types package for Undici",
5
5
  "homepage": "https://undici.nodejs.org",
6
6
  "bugs": {
package/patch.d.ts CHANGED
@@ -2,10 +2,6 @@
2
2
 
3
3
  // See https://github.com/nodejs/undici/issues/1740
4
4
 
5
- export type DOMException = typeof globalThis extends { DOMException: infer T }
6
- ? T
7
- : any
8
-
9
5
  export interface EventInit {
10
6
  bubbles?: boolean
11
7
  cancelable?: boolean