undici 6.19.7 → 7.0.0-alpha.1

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.
Files changed (115) hide show
  1. package/README.md +5 -9
  2. package/docs/docs/api/Agent.md +0 -3
  3. package/docs/docs/api/Client.md +0 -2
  4. package/docs/docs/api/Dispatcher.md +204 -6
  5. package/docs/docs/api/EnvHttpProxyAgent.md +0 -1
  6. package/docs/docs/api/Fetch.md +1 -0
  7. package/docs/docs/api/Pool.md +0 -1
  8. package/docs/docs/api/RetryHandler.md +1 -1
  9. package/index.js +0 -4
  10. package/lib/api/api-connect.js +3 -1
  11. package/lib/api/api-pipeline.js +3 -4
  12. package/lib/api/api-request.js +29 -46
  13. package/lib/api/api-stream.js +36 -49
  14. package/lib/api/api-upgrade.js +5 -3
  15. package/lib/api/readable.js +71 -27
  16. package/lib/core/connect.js +39 -24
  17. package/lib/core/errors.js +17 -4
  18. package/lib/core/request.js +7 -5
  19. package/lib/core/symbols.js +0 -1
  20. package/lib/core/tree.js +6 -0
  21. package/lib/core/util.js +1 -11
  22. package/lib/dispatcher/agent.js +3 -17
  23. package/lib/dispatcher/balanced-pool.js +27 -11
  24. package/lib/dispatcher/client-h1.js +44 -39
  25. package/lib/dispatcher/client.js +3 -27
  26. package/lib/dispatcher/dispatcher-base.js +2 -34
  27. package/lib/dispatcher/dispatcher.js +3 -24
  28. package/lib/dispatcher/pool.js +3 -6
  29. package/lib/dispatcher/proxy-agent.js +3 -6
  30. package/lib/handler/decorator-handler.js +24 -0
  31. package/lib/handler/redirect-handler.js +9 -0
  32. package/lib/handler/retry-handler.js +22 -3
  33. package/lib/interceptor/dump.js +2 -2
  34. package/lib/interceptor/redirect.js +11 -14
  35. package/lib/interceptor/response-error.js +89 -0
  36. package/lib/llhttp/constants.d.ts +97 -0
  37. package/lib/llhttp/constants.js +412 -192
  38. package/lib/llhttp/constants.js.map +1 -0
  39. package/lib/llhttp/llhttp-wasm.js +11 -1
  40. package/lib/llhttp/llhttp_simd-wasm.js +11 -1
  41. package/lib/llhttp/utils.d.ts +2 -0
  42. package/lib/llhttp/utils.js +9 -9
  43. package/lib/llhttp/utils.js.map +1 -0
  44. package/lib/mock/mock-client.js +2 -2
  45. package/lib/mock/mock-pool.js +2 -2
  46. package/lib/mock/mock-symbols.js +1 -0
  47. package/lib/util/timers.js +324 -44
  48. package/lib/web/cookies/index.js +15 -13
  49. package/lib/web/cookies/parse.js +2 -2
  50. package/lib/web/eventsource/eventsource-stream.js +9 -8
  51. package/lib/web/eventsource/eventsource.js +10 -6
  52. package/lib/web/fetch/body.js +31 -11
  53. package/lib/web/fetch/data-url.js +1 -1
  54. package/lib/web/fetch/formdata-parser.js +1 -2
  55. package/lib/web/fetch/formdata.js +28 -37
  56. package/lib/web/fetch/headers.js +1 -1
  57. package/lib/web/fetch/index.js +7 -8
  58. package/lib/web/fetch/request.js +11 -28
  59. package/lib/web/fetch/response.js +13 -41
  60. package/lib/web/fetch/symbols.js +0 -1
  61. package/lib/web/fetch/util.js +3 -12
  62. package/lib/web/fetch/webidl.js +73 -62
  63. package/lib/web/websocket/connection.js +26 -174
  64. package/lib/web/websocket/constants.js +1 -1
  65. package/lib/web/websocket/frame.js +45 -3
  66. package/lib/web/websocket/receiver.js +28 -26
  67. package/lib/web/websocket/sender.js +18 -13
  68. package/lib/web/websocket/util.js +20 -74
  69. package/lib/web/websocket/websocket.js +294 -70
  70. package/package.json +16 -29
  71. package/scripts/strip-comments.js +3 -1
  72. package/types/agent.d.ts +7 -7
  73. package/types/api.d.ts +24 -24
  74. package/types/balanced-pool.d.ts +11 -11
  75. package/types/client.d.ts +11 -12
  76. package/types/diagnostics-channel.d.ts +10 -10
  77. package/types/dispatcher.d.ts +96 -97
  78. package/types/env-http-proxy-agent.d.ts +2 -2
  79. package/types/errors.d.ts +53 -47
  80. package/types/eventsource.d.ts +0 -2
  81. package/types/fetch.d.ts +8 -8
  82. package/types/formdata.d.ts +7 -7
  83. package/types/global-dispatcher.d.ts +4 -4
  84. package/types/global-origin.d.ts +5 -5
  85. package/types/handlers.d.ts +4 -4
  86. package/types/header.d.ts +157 -1
  87. package/types/index.d.ts +42 -46
  88. package/types/interceptors.d.ts +10 -8
  89. package/types/mock-agent.d.ts +18 -18
  90. package/types/mock-client.d.ts +4 -4
  91. package/types/mock-errors.d.ts +3 -3
  92. package/types/mock-interceptor.d.ts +19 -19
  93. package/types/mock-pool.d.ts +4 -4
  94. package/types/patch.d.ts +0 -42
  95. package/types/pool-stats.d.ts +8 -8
  96. package/types/pool.d.ts +12 -12
  97. package/types/proxy-agent.d.ts +4 -4
  98. package/types/readable.d.ts +14 -9
  99. package/types/retry-agent.d.ts +1 -1
  100. package/types/retry-handler.d.ts +8 -8
  101. package/types/util.d.ts +3 -3
  102. package/types/utility.d.ts +7 -0
  103. package/types/webidl.d.ts +22 -4
  104. package/types/websocket.d.ts +1 -3
  105. package/docs/docs/api/DispatchInterceptor.md +0 -60
  106. package/lib/interceptor/redirect-interceptor.js +0 -21
  107. package/lib/web/fetch/file.js +0 -126
  108. package/lib/web/fileapi/encoding.js +0 -290
  109. package/lib/web/fileapi/filereader.js +0 -344
  110. package/lib/web/fileapi/progressevent.js +0 -78
  111. package/lib/web/fileapi/symbols.js +0 -10
  112. package/lib/web/fileapi/util.js +0 -391
  113. package/lib/web/websocket/symbols.js +0 -12
  114. package/types/file.d.ts +0 -39
  115. package/types/filereader.d.ts +0 -54
package/types/agent.d.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  import { URL } from 'url'
2
2
  import Pool from './pool'
3
- import Dispatcher from "./dispatcher";
3
+ import Dispatcher from './dispatcher'
4
4
 
5
5
  export default Agent
6
6
 
7
- declare class Agent extends Dispatcher{
8
- constructor(opts?: Agent.Options)
7
+ declare class Agent extends Dispatcher {
8
+ constructor (opts?: Agent.Options)
9
9
  /** `true` after `dispatcher.close()` has been called. */
10
- closed: boolean;
10
+ closed: boolean
11
11
  /** `true` after `dispatcher.destroyed()` has been called or `dispatcher.close()` has been called and the dispatcher shutdown has completed. */
12
- destroyed: boolean;
12
+ destroyed: boolean
13
13
  /** Dispatches a request. */
14
- dispatch(options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean;
14
+ dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean
15
15
  }
16
16
 
17
17
  declare namespace Agent {
@@ -21,7 +21,7 @@ declare namespace Agent {
21
21
  /** Integer. Default: `0` */
22
22
  maxRedirections?: number;
23
23
 
24
- interceptors?: { Agent?: readonly Dispatcher.DispatchInterceptor[] } & Pool.Options["interceptors"]
24
+ interceptors?: { Agent?: readonly Dispatcher.DispatchInterceptor[] } & Pool.Options['interceptors']
25
25
  }
26
26
 
27
27
  export interface DispatchOptions extends Dispatcher.DispatchOptions {
package/types/api.d.ts CHANGED
@@ -2,42 +2,42 @@ import { URL, UrlObject } from 'url'
2
2
  import { Duplex } from 'stream'
3
3
  import Dispatcher from './dispatcher'
4
4
 
5
- export {
6
- request,
7
- stream,
8
- pipeline,
9
- connect,
10
- upgrade,
11
- }
12
-
13
5
  /** Performs an HTTP request. */
14
- declare function request(
6
+ declare function request<TOpaque = null> (
15
7
  url: string | URL | UrlObject,
16
- options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions, 'origin' | 'path' | 'method'> & Partial<Pick<Dispatcher.RequestOptions, 'method'>>,
17
- ): Promise<Dispatcher.ResponseData>;
8
+ options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions<TOpaque>, 'origin' | 'path' | 'method'> & Partial<Pick<Dispatcher.RequestOptions, 'method'>>,
9
+ ): Promise<Dispatcher.ResponseData<TOpaque>>
18
10
 
19
11
  /** A faster version of `request`. */
20
- declare function stream(
12
+ declare function stream<TOpaque = null> (
21
13
  url: string | URL | UrlObject,
22
- options: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions, 'origin' | 'path'>,
23
- factory: Dispatcher.StreamFactory
24
- ): Promise<Dispatcher.StreamData>;
14
+ options: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions<TOpaque>, 'origin' | 'path'>,
15
+ factory: Dispatcher.StreamFactory<TOpaque>
16
+ ): Promise<Dispatcher.StreamData<TOpaque>>
25
17
 
26
18
  /** For easy use with `stream.pipeline`. */
27
- declare function pipeline(
19
+ declare function pipeline<TOpaque = null> (
28
20
  url: string | URL | UrlObject,
29
- options: { dispatcher?: Dispatcher } & Omit<Dispatcher.PipelineOptions, 'origin' | 'path'>,
30
- handler: Dispatcher.PipelineHandler
31
- ): Duplex;
21
+ options: { dispatcher?: Dispatcher } & Omit<Dispatcher.PipelineOptions<TOpaque>, 'origin' | 'path'>,
22
+ handler: Dispatcher.PipelineHandler<TOpaque>
23
+ ): Duplex
32
24
 
33
25
  /** Starts two-way communications with the requested resource. */
34
- declare function connect(
26
+ declare function connect<TOpaque = null> (
35
27
  url: string | URL | UrlObject,
36
- options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.ConnectOptions, 'origin' | 'path'>
37
- ): Promise<Dispatcher.ConnectData>;
28
+ options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.ConnectOptions<TOpaque>, 'origin' | 'path'>
29
+ ): Promise<Dispatcher.ConnectData<TOpaque>>
38
30
 
39
31
  /** Upgrade to a different protocol. */
40
- declare function upgrade(
32
+ declare function upgrade (
41
33
  url: string | URL | UrlObject,
42
34
  options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.UpgradeOptions, 'origin' | 'path'>
43
- ): Promise<Dispatcher.UpgradeData>;
35
+ ): Promise<Dispatcher.UpgradeData>
36
+
37
+ export {
38
+ request,
39
+ stream,
40
+ pipeline,
41
+ connect,
42
+ upgrade
43
+ }
@@ -4,26 +4,26 @@ import { URL } from 'url'
4
4
 
5
5
  export default BalancedPool
6
6
 
7
- type BalancedPoolConnectOptions = Omit<Dispatcher.ConnectOptions, "origin">;
7
+ type BalancedPoolConnectOptions = Omit<Dispatcher.ConnectOptions, 'origin'>
8
8
 
9
9
  declare class BalancedPool extends Dispatcher {
10
- constructor(url: string | string[] | URL | URL[], options?: Pool.Options);
10
+ constructor (url: string | string[] | URL | URL[], options?: Pool.Options)
11
11
 
12
- addUpstream(upstream: string | URL): BalancedPool;
13
- removeUpstream(upstream: string | URL): BalancedPool;
14
- upstreams: Array<string>;
12
+ addUpstream (upstream: string | URL): BalancedPool
13
+ removeUpstream (upstream: string | URL): BalancedPool
14
+ upstreams: Array<string>
15
15
 
16
16
  /** `true` after `pool.close()` has been called. */
17
- closed: boolean;
17
+ closed: boolean
18
18
  /** `true` after `pool.destroyed()` has been called or `pool.close()` has been called and the pool shutdown has completed. */
19
- destroyed: boolean;
19
+ destroyed: boolean
20
20
 
21
21
  // Override dispatcher APIs.
22
- override connect(
22
+ override connect (
23
23
  options: BalancedPoolConnectOptions
24
- ): Promise<Dispatcher.ConnectData>;
25
- override connect(
24
+ ): Promise<Dispatcher.ConnectData>
25
+ override connect (
26
26
  options: BalancedPoolConnectOptions,
27
27
  callback: (err: Error | null, data: Dispatcher.ConnectData) => void
28
- ): void;
28
+ ): void
29
29
  }
package/types/client.d.ts CHANGED
@@ -1,30 +1,29 @@
1
1
  import { URL } from 'url'
2
- import { TlsOptions } from 'tls'
3
2
  import Dispatcher from './dispatcher'
4
- import buildConnector from "./connector";
3
+ import buildConnector from './connector'
5
4
 
6
- type ClientConnectOptions = Omit<Dispatcher.ConnectOptions, "origin">;
5
+ type ClientConnectOptions = Omit<Dispatcher.ConnectOptions, 'origin'>
7
6
 
8
7
  /**
9
8
  * A basic HTTP/1.1 client, mapped on top a single TCP/TLS connection. Pipelining is disabled by default.
10
9
  */
11
10
  export class Client extends Dispatcher {
12
- constructor(url: string | URL, options?: Client.Options);
11
+ constructor (url: string | URL, options?: Client.Options)
13
12
  /** Property to get and set the pipelining factor. */
14
- pipelining: number;
13
+ pipelining: number
15
14
  /** `true` after `client.close()` has been called. */
16
- closed: boolean;
15
+ closed: boolean
17
16
  /** `true` after `client.destroyed()` has been called or `client.close()` has been called and the client shutdown has completed. */
18
- destroyed: boolean;
17
+ destroyed: boolean
19
18
 
20
19
  // Override dispatcher APIs.
21
- override connect(
20
+ override connect (
22
21
  options: ClientConnectOptions
23
- ): Promise<Dispatcher.ConnectData>;
24
- override connect(
22
+ ): Promise<Dispatcher.ConnectData>
23
+ override connect (
25
24
  options: ClientConnectOptions,
26
25
  callback: (err: Error | null, data: Dispatcher.ConnectData) => void
27
- ): void;
26
+ ): void
28
27
  }
29
28
 
30
29
  export declare namespace Client {
@@ -105,4 +104,4 @@ export declare namespace Client {
105
104
  }
106
105
  }
107
106
 
108
- export default Client;
107
+ export default Client
@@ -1,7 +1,7 @@
1
- import { Socket } from "net";
2
- import { URL } from "url";
3
- import Connector from "./connector";
4
- import Dispatcher from "./dispatcher";
1
+ import { Socket } from 'net'
2
+ import { URL } from 'url'
3
+ import buildConnector from './connector'
4
+ import Dispatcher from './dispatcher'
5
5
 
6
6
  declare namespace DiagnosticsChannel {
7
7
  interface Request {
@@ -16,15 +16,15 @@ declare namespace DiagnosticsChannel {
16
16
  statusText: string;
17
17
  headers: Array<Buffer>;
18
18
  }
19
- type Error = unknown;
19
+ type Error = unknown
20
20
  interface ConnectParams {
21
- host: URL["host"];
22
- hostname: URL["hostname"];
23
- protocol: URL["protocol"];
24
- port: URL["port"];
21
+ host: URL['host'];
22
+ hostname: URL['hostname'];
23
+ protocol: URL['protocol'];
24
+ port: URL['port'];
25
25
  servername: string | null;
26
26
  }
27
- type Connector = Connector.connector;
27
+ type Connector = buildConnector.connector
28
28
  export interface RequestCreateMessage {
29
29
  request: Request;
30
30
  }
@@ -6,98 +6,96 @@ import { IncomingHttpHeaders } from './header'
6
6
  import BodyReadable from './readable'
7
7
  import { FormData } from './formdata'
8
8
  import Errors from './errors'
9
+ import { Autocomplete } from './utility'
9
10
 
10
- type AbortSignal = unknown;
11
+ type AbortSignal = unknown
11
12
 
12
13
  export default Dispatcher
13
14
 
14
15
  /** Dispatcher is the core API used to dispatch requests. */
15
16
  declare class Dispatcher extends EventEmitter {
16
17
  /** 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. */
17
- dispatch(options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean;
18
+ dispatch (options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean
18
19
  /** Starts two-way communications with the requested resource. */
19
- connect(options: Dispatcher.ConnectOptions): Promise<Dispatcher.ConnectData>;
20
- connect(options: Dispatcher.ConnectOptions, callback: (err: Error | null, data: Dispatcher.ConnectData) => void): void;
20
+ connect<TOpaque = null>(options: Dispatcher.ConnectOptions<TOpaque>): Promise<Dispatcher.ConnectData<TOpaque>>
21
+ connect<TOpaque = null>(options: Dispatcher.ConnectOptions<TOpaque>, callback: (err: Error | null, data: Dispatcher.ConnectData<TOpaque>) => void): void
21
22
  /** Compose a chain of dispatchers */
22
- compose(dispatchers: Dispatcher.DispatcherComposeInterceptor[]): Dispatcher.ComposedDispatcher;
23
- compose(...dispatchers: Dispatcher.DispatcherComposeInterceptor[]): Dispatcher.ComposedDispatcher;
23
+ compose (dispatchers: Dispatcher.DispatcherComposeInterceptor[]): Dispatcher.ComposedDispatcher
24
+ compose (...dispatchers: Dispatcher.DispatcherComposeInterceptor[]): Dispatcher.ComposedDispatcher
24
25
  /** Performs an HTTP request. */
25
- request(options: Dispatcher.RequestOptions): Promise<Dispatcher.ResponseData>;
26
- request(options: Dispatcher.RequestOptions, callback: (err: Error | null, data: Dispatcher.ResponseData) => void): void;
26
+ request<TOpaque = null>(options: Dispatcher.RequestOptions<TOpaque>): Promise<Dispatcher.ResponseData<TOpaque>>
27
+ request<TOpaque = null>(options: Dispatcher.RequestOptions<TOpaque>, callback: (err: Error | null, data: Dispatcher.ResponseData<TOpaque>) => void): void
27
28
  /** For easy use with `stream.pipeline`. */
28
- pipeline(options: Dispatcher.PipelineOptions, handler: Dispatcher.PipelineHandler): Duplex;
29
+ pipeline<TOpaque = null>(options: Dispatcher.PipelineOptions<TOpaque>, handler: Dispatcher.PipelineHandler<TOpaque>): Duplex
29
30
  /** A faster version of `Dispatcher.request`. */
30
- stream(options: Dispatcher.RequestOptions, factory: Dispatcher.StreamFactory): Promise<Dispatcher.StreamData>;
31
- stream(options: Dispatcher.RequestOptions, factory: Dispatcher.StreamFactory, callback: (err: Error | null, data: Dispatcher.StreamData) => void): void;
31
+ stream<TOpaque = null>(options: Dispatcher.RequestOptions<TOpaque>, factory: Dispatcher.StreamFactory<TOpaque>): Promise<Dispatcher.StreamData<TOpaque>>
32
+ stream<TOpaque = null>(options: Dispatcher.RequestOptions<TOpaque>, factory: Dispatcher.StreamFactory<TOpaque>, callback: (err: Error | null, data: Dispatcher.StreamData<TOpaque>) => void): void
32
33
  /** Upgrade to a different protocol. */
33
- upgrade(options: Dispatcher.UpgradeOptions): Promise<Dispatcher.UpgradeData>;
34
- upgrade(options: Dispatcher.UpgradeOptions, callback: (err: Error | null, data: Dispatcher.UpgradeData) => void): void;
34
+ upgrade (options: Dispatcher.UpgradeOptions): Promise<Dispatcher.UpgradeData>
35
+ upgrade (options: Dispatcher.UpgradeOptions, callback: (err: Error | null, data: Dispatcher.UpgradeData) => void): void
35
36
  /** Closes the client and gracefully waits for enqueued requests to complete before invoking the callback (or returning a promise if no callback is provided). */
36
- close(): Promise<void>;
37
- close(callback: () => void): void;
37
+ close (): Promise<void>
38
+ close (callback: () => void): void
38
39
  /** Destroy the client abruptly with the given err. All the pending and running requests will be asynchronously aborted and error. Waits until socket is closed before invoking the callback (or returning a promise if no callback is provided). Since this operation is asynchronously dispatched there might still be some progress on dispatched requests. */
39
- destroy(): Promise<void>;
40
- destroy(err: Error | null): Promise<void>;
41
- destroy(callback: () => void): void;
42
- destroy(err: Error | null, callback: () => void): void;
43
-
44
- on(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this;
45
- on(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
46
- on(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
47
- on(eventName: 'drain', callback: (origin: URL) => void): this;
48
-
49
-
50
- once(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this;
51
- once(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
52
- once(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
53
- once(eventName: 'drain', callback: (origin: URL) => void): this;
54
-
55
-
56
- off(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this;
57
- off(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
58
- off(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
59
- off(eventName: 'drain', callback: (origin: URL) => void): this;
60
-
61
-
62
- addListener(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this;
63
- addListener(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
64
- addListener(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
65
- addListener(eventName: 'drain', callback: (origin: URL) => void): this;
66
-
67
- removeListener(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this;
68
- removeListener(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
69
- removeListener(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
70
- removeListener(eventName: 'drain', callback: (origin: URL) => void): this;
71
-
72
- prependListener(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this;
73
- prependListener(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
74
- prependListener(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
75
- prependListener(eventName: 'drain', callback: (origin: URL) => void): this;
76
-
77
- prependOnceListener(eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this;
78
- prependOnceListener(eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
79
- prependOnceListener(eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
80
- prependOnceListener(eventName: 'drain', callback: (origin: URL) => void): this;
81
-
82
- listeners(eventName: 'connect'): ((origin: URL, targets: readonly Dispatcher[]) => void)[]
83
- listeners(eventName: 'disconnect'): ((origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
84
- listeners(eventName: 'connectionError'): ((origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
85
- listeners(eventName: 'drain'): ((origin: URL) => void)[];
86
-
87
- rawListeners(eventName: 'connect'): ((origin: URL, targets: readonly Dispatcher[]) => void)[]
88
- rawListeners(eventName: 'disconnect'): ((origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
89
- rawListeners(eventName: 'connectionError'): ((origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
90
- rawListeners(eventName: 'drain'): ((origin: URL) => void)[];
91
-
92
- emit(eventName: 'connect', origin: URL, targets: readonly Dispatcher[]): boolean;
93
- emit(eventName: 'disconnect', origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError): boolean;
94
- emit(eventName: 'connectionError', origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError): boolean;
95
- emit(eventName: 'drain', origin: URL): boolean;
40
+ destroy (): Promise<void>
41
+ destroy (err: Error | null): Promise<void>
42
+ destroy (callback: () => void): void
43
+ destroy (err: Error | null, callback: () => void): void
44
+
45
+ on (eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this
46
+ on (eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
47
+ on (eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
48
+ on (eventName: 'drain', callback: (origin: URL) => void): this
49
+
50
+ once (eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this
51
+ once (eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
52
+ once (eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
53
+ once (eventName: 'drain', callback: (origin: URL) => void): this
54
+
55
+ off (eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this
56
+ off (eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
57
+ off (eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
58
+ off (eventName: 'drain', callback: (origin: URL) => void): this
59
+
60
+ addListener (eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this
61
+ addListener (eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
62
+ addListener (eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
63
+ addListener (eventName: 'drain', callback: (origin: URL) => void): this
64
+
65
+ removeListener (eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this
66
+ removeListener (eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
67
+ removeListener (eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
68
+ removeListener (eventName: 'drain', callback: (origin: URL) => void): this
69
+
70
+ prependListener (eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this
71
+ prependListener (eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
72
+ prependListener (eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
73
+ prependListener (eventName: 'drain', callback: (origin: URL) => void): this
74
+
75
+ prependOnceListener (eventName: 'connect', callback: (origin: URL, targets: readonly Dispatcher[]) => void): this
76
+ prependOnceListener (eventName: 'disconnect', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
77
+ prependOnceListener (eventName: 'connectionError', callback: (origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this
78
+ prependOnceListener (eventName: 'drain', callback: (origin: URL) => void): this
79
+
80
+ listeners (eventName: 'connect'): ((origin: URL, targets: readonly Dispatcher[]) => void)[]
81
+ listeners (eventName: 'disconnect'): ((origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[]
82
+ listeners (eventName: 'connectionError'): ((origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[]
83
+ listeners (eventName: 'drain'): ((origin: URL) => void)[]
84
+
85
+ rawListeners (eventName: 'connect'): ((origin: URL, targets: readonly Dispatcher[]) => void)[]
86
+ rawListeners (eventName: 'disconnect'): ((origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[]
87
+ rawListeners (eventName: 'connectionError'): ((origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[]
88
+ rawListeners (eventName: 'drain'): ((origin: URL) => void)[]
89
+
90
+ emit (eventName: 'connect', origin: URL, targets: readonly Dispatcher[]): boolean
91
+ emit (eventName: 'disconnect', origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError): boolean
92
+ emit (eventName: 'connectionError', origin: URL, targets: readonly Dispatcher[], error: Errors.UndiciError): boolean
93
+ emit (eventName: 'drain', origin: URL): boolean
96
94
  }
97
95
 
98
96
  declare namespace Dispatcher {
99
97
  export interface ComposedDispatcher extends Dispatcher {}
100
- export type DispatcherComposeInterceptor = (dispatch: Dispatcher['dispatch']) => Dispatcher['dispatch'];
98
+ export type DispatcherComposeInterceptor = (dispatch: Dispatcher['dispatch']) => Dispatcher['dispatch']
101
99
  export interface DispatchOptions {
102
100
  origin?: string | URL;
103
101
  path: string;
@@ -122,10 +120,10 @@ declare namespace Dispatcher {
122
120
  reset?: boolean;
123
121
  /** Whether Undici should throw an error upon receiving a 4xx or 5xx response from the server. Defaults to false */
124
122
  throwOnError?: boolean;
125
- /** For H2, it appends the expect: 100-continue header, and halts the request body until a 100-continue is received from the remote server*/
123
+ /** For H2, it appends the expect: 100-continue header, and halts the request body until a 100-continue is received from the remote server */
126
124
  expectContinue?: boolean;
127
125
  }
128
- export interface ConnectOptions {
126
+ export interface ConnectOptions<TOpaque = null> {
129
127
  origin: string | URL;
130
128
  path: string;
131
129
  /** Default: `null` */
@@ -133,17 +131,17 @@ declare namespace Dispatcher {
133
131
  /** Default: `null` */
134
132
  signal?: AbortSignal | EventEmitter | null;
135
133
  /** This argument parameter is passed through to `ConnectData` */
136
- opaque?: unknown;
134
+ opaque?: TOpaque;
137
135
  /** Default: 0 */
138
136
  maxRedirections?: number;
139
137
  /** Default: false */
140
138
  redirectionLimitReached?: boolean;
141
139
  /** Default: `null` */
142
- responseHeader?: 'raw' | null;
140
+ responseHeaders?: 'raw' | null;
143
141
  }
144
- export interface RequestOptions extends DispatchOptions {
142
+ export interface RequestOptions<TOpaque = null> extends DispatchOptions {
145
143
  /** Default: `null` */
146
- opaque?: unknown;
144
+ opaque?: TOpaque;
147
145
  /** Default: `null` */
148
146
  signal?: AbortSignal | EventEmitter | null;
149
147
  /** Default: 0 */
@@ -153,11 +151,11 @@ declare namespace Dispatcher {
153
151
  /** Default: `null` */
154
152
  onInfo?: (info: { statusCode: number, headers: Record<string, string | string[]> }) => void;
155
153
  /** Default: `null` */
156
- responseHeader?: 'raw' | null;
154
+ responseHeaders?: 'raw' | null;
157
155
  /** Default: `64 KiB` */
158
156
  highWaterMark?: number;
159
157
  }
160
- export interface PipelineOptions extends RequestOptions {
158
+ export interface PipelineOptions<TOpaque = null> extends RequestOptions<TOpaque> {
161
159
  /** `true` if the `handler` will return an object stream. Default: `false` */
162
160
  objectMode?: boolean;
163
161
  }
@@ -176,45 +174,45 @@ declare namespace Dispatcher {
176
174
  /** Default: false */
177
175
  redirectionLimitReached?: boolean;
178
176
  /** Default: `null` */
179
- responseHeader?: 'raw' | null;
177
+ responseHeaders?: 'raw' | null;
180
178
  }
181
- export interface ConnectData {
179
+ export interface ConnectData<TOpaque = null> {
182
180
  statusCode: number;
183
181
  headers: IncomingHttpHeaders;
184
182
  socket: Duplex;
185
- opaque: unknown;
183
+ opaque: TOpaque;
186
184
  }
187
- export interface ResponseData {
185
+ export interface ResponseData<TOpaque = null> {
188
186
  statusCode: number;
189
187
  headers: IncomingHttpHeaders;
190
188
  body: BodyReadable & BodyMixin;
191
189
  trailers: Record<string, string>;
192
- opaque: unknown;
190
+ opaque: TOpaque;
193
191
  context: object;
194
192
  }
195
- export interface PipelineHandlerData {
193
+ export interface PipelineHandlerData<TOpaque = null> {
196
194
  statusCode: number;
197
195
  headers: IncomingHttpHeaders;
198
- opaque: unknown;
196
+ opaque: TOpaque;
199
197
  body: BodyReadable;
200
198
  context: object;
201
199
  }
202
- export interface StreamData {
203
- opaque: unknown;
200
+ export interface StreamData<TOpaque = null> {
201
+ opaque: TOpaque;
204
202
  trailers: Record<string, string>;
205
203
  }
206
- export interface UpgradeData {
204
+ export interface UpgradeData<TOpaque = null> {
207
205
  headers: IncomingHttpHeaders;
208
206
  socket: Duplex;
209
- opaque: unknown;
207
+ opaque: TOpaque;
210
208
  }
211
- export interface StreamFactoryData {
209
+ export interface StreamFactoryData<TOpaque = null> {
212
210
  statusCode: number;
213
211
  headers: IncomingHttpHeaders;
214
- opaque: unknown;
212
+ opaque: TOpaque;
215
213
  context: object;
216
214
  }
217
- export type StreamFactory = (data: StreamFactoryData) => Writable;
215
+ export type StreamFactory<TOpaque = null> = (data: StreamFactoryData<TOpaque>) => Writable
218
216
  export interface DispatchHandlers {
219
217
  /** Invoked before request is dispatched on socket. May be invoked multiple times when a request is retried when the request at the head of the pipeline fails. */
220
218
  onConnect?(abort: (err?: Error) => void): void;
@@ -233,8 +231,8 @@ declare namespace Dispatcher {
233
231
  /** Invoked when a body chunk is sent to the server. May be invoked multiple times for chunked requests */
234
232
  onBodySent?(chunkSize: number, totalBytesSent: number): void;
235
233
  }
236
- export type PipelineHandler = (data: PipelineHandlerData) => Readable;
237
- export type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
234
+ export type PipelineHandler<TOpaque = null> = (data: PipelineHandlerData<TOpaque>) => Readable
235
+ export type HttpMethod = Autocomplete<'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH'>
238
236
 
239
237
  /**
240
238
  * @link https://fetch.spec.whatwg.org/#body-mixin
@@ -244,6 +242,7 @@ declare namespace Dispatcher {
244
242
  readonly bodyUsed: boolean;
245
243
  arrayBuffer(): Promise<ArrayBuffer>;
246
244
  blob(): Promise<Blob>;
245
+ bytes(): Promise<Uint8Array>;
247
246
  formData(): Promise<never>;
248
247
  json(): Promise<unknown>;
249
248
  text(): Promise<string>;
@@ -4,9 +4,9 @@ import Dispatcher from './dispatcher'
4
4
  export default EnvHttpProxyAgent
5
5
 
6
6
  declare class EnvHttpProxyAgent extends Dispatcher {
7
- constructor(opts?: EnvHttpProxyAgent.Options)
7
+ constructor (opts?: EnvHttpProxyAgent.Options)
8
8
 
9
- dispatch(options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean;
9
+ dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean
10
10
  }
11
11
 
12
12
  declare namespace EnvHttpProxyAgent {