undici 6.19.8 → 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 +5 -8
  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 +4 -6
  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 +7 -24
  59. package/lib/web/fetch/response.js +9 -22
  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
@@ -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.DispatchHandlers): 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,6 @@ 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
49
  }
50
50
  }
@@ -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.DispatchHandlers): 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 {
@@ -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
+ }
@@ -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.DispatchHandlers): 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/types/patch.d.ts CHANGED
@@ -2,48 +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
- export type EventTarget = typeof globalThis extends { EventTarget: infer T }
10
- ? T
11
- : {
12
- addEventListener(
13
- type: string,
14
- listener: any,
15
- options?: any,
16
- ): void
17
- dispatchEvent(event: Event): boolean
18
- removeEventListener(
19
- type: string,
20
- listener: any,
21
- options?: any | boolean,
22
- ): void
23
- }
24
-
25
- export type Event = typeof globalThis extends { Event: infer T }
26
- ? T
27
- : {
28
- readonly bubbles: boolean
29
- cancelBubble: () => void
30
- readonly cancelable: boolean
31
- readonly composed: boolean
32
- composedPath(): [EventTarget?]
33
- readonly currentTarget: EventTarget | null
34
- readonly defaultPrevented: boolean
35
- readonly eventPhase: 0 | 2
36
- readonly isTrusted: boolean
37
- preventDefault(): void
38
- returnValue: boolean
39
- readonly srcElement: EventTarget | null
40
- stopImmediatePropagation(): void
41
- stopPropagation(): void
42
- readonly target: EventTarget | null
43
- readonly timeStamp: number
44
- readonly type: string
45
- }
46
-
47
5
  export interface EventInit {
48
6
  bubbles?: boolean
49
7
  cancelable?: boolean
@@ -1,19 +1,19 @@
1
- import Pool from "./pool"
1
+ import Pool from './pool'
2
2
 
3
3
  export default PoolStats
4
4
 
5
5
  declare class PoolStats {
6
- constructor(pool: Pool);
6
+ constructor (pool: Pool)
7
7
  /** Number of open socket connections in this pool. */
8
- connected: number;
8
+ connected: number
9
9
  /** Number of open socket connections in this pool that do not have an active request. */
10
- free: number;
10
+ free: number
11
11
  /** Number of pending requests across all clients in this pool. */
12
- pending: number;
12
+ pending: number
13
13
  /** Number of queued requests across all clients in this pool. */
14
- queued: number;
14
+ queued: number
15
15
  /** Number of currently active requests across all clients in this pool. */
16
- running: number;
16
+ running: number
17
17
  /** Number of active, pending, or queued requests across all clients in this pool. */
18
- size: number;
18
+ size: number
19
19
  }
package/types/pool.d.ts CHANGED
@@ -1,39 +1,39 @@
1
1
  import Client from './client'
2
2
  import TPoolStats from './pool-stats'
3
3
  import { URL } from 'url'
4
- import Dispatcher from "./dispatcher";
4
+ import Dispatcher from './dispatcher'
5
5
 
6
6
  export default Pool
7
7
 
8
- type PoolConnectOptions = Omit<Dispatcher.ConnectOptions, "origin">;
8
+ type PoolConnectOptions = Omit<Dispatcher.ConnectOptions, 'origin'>
9
9
 
10
10
  declare class Pool extends Dispatcher {
11
- constructor(url: string | URL, options?: Pool.Options)
11
+ constructor (url: string | URL, options?: Pool.Options)
12
12
  /** `true` after `pool.close()` has been called. */
13
- closed: boolean;
13
+ closed: boolean
14
14
  /** `true` after `pool.destroyed()` has been called or `pool.close()` has been called and the pool shutdown has completed. */
15
- destroyed: boolean;
15
+ destroyed: boolean
16
16
  /** Aggregate stats for a Pool. */
17
- readonly stats: TPoolStats;
17
+ readonly stats: TPoolStats
18
18
 
19
19
  // Override dispatcher APIs.
20
- override connect(
20
+ override connect (
21
21
  options: PoolConnectOptions
22
- ): Promise<Dispatcher.ConnectData>;
23
- override connect(
22
+ ): Promise<Dispatcher.ConnectData>
23
+ override connect (
24
24
  options: PoolConnectOptions,
25
25
  callback: (err: Error | null, data: Dispatcher.ConnectData) => void
26
- ): void;
26
+ ): void
27
27
  }
28
28
 
29
29
  declare namespace Pool {
30
- export type PoolStats = TPoolStats;
30
+ export type PoolStats = TPoolStats
31
31
  export interface Options extends Client.Options {
32
32
  /** Default: `(origin, opts) => new Client(origin, opts)`. */
33
33
  factory?(origin: URL, opts: object): Dispatcher;
34
34
  /** The max number of clients to create. `null` if no limit. Default `null`. */
35
35
  connections?: number | null;
36
36
 
37
- interceptors?: { Pool?: readonly Dispatcher.DispatchInterceptor[] } & Client.Options["interceptors"]
37
+ interceptors?: { Pool?: readonly Dispatcher.DispatchInterceptor[] } & Client.Options['interceptors']
38
38
  }
39
39
  }
@@ -1,15 +1,15 @@
1
1
  import Agent from './agent'
2
- import buildConnector from './connector';
2
+ import buildConnector from './connector'
3
3
  import Dispatcher from './dispatcher'
4
4
  import { IncomingHttpHeaders } from './header'
5
5
 
6
6
  export default ProxyAgent
7
7
 
8
8
  declare class ProxyAgent extends Dispatcher {
9
- constructor(options: ProxyAgent.Options | string)
9
+ constructor (options: ProxyAgent.Options | string)
10
10
 
11
- dispatch(options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean;
12
- close(): Promise<void>;
11
+ dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean
12
+ close (): Promise<void>
13
13
  }
14
14
 
15
15
  declare namespace ProxyAgent {
@@ -1,10 +1,10 @@
1
- import { Readable } from "stream";
1
+ import { Readable } from 'stream'
2
2
  import { Blob } from 'buffer'
3
3
 
4
4
  export default BodyReadable
5
5
 
6
6
  declare class BodyReadable extends Readable {
7
- constructor(
7
+ constructor (
8
8
  resume?: (this: Readable, size: number) => void | null,
9
9
  abort?: () => void | null,
10
10
  contentType?: string
@@ -13,28 +13,33 @@ declare class BodyReadable extends Readable {
13
13
  /** Consumes and returns the body as a string
14
14
  * https://fetch.spec.whatwg.org/#dom-body-text
15
15
  */
16
- text(): Promise<string>
16
+ text (): Promise<string>
17
17
 
18
18
  /** Consumes and returns the body as a JavaScript Object
19
19
  * https://fetch.spec.whatwg.org/#dom-body-json
20
20
  */
21
- json(): Promise<unknown>
21
+ json (): Promise<unknown>
22
22
 
23
23
  /** Consumes and returns the body as a Blob
24
24
  * https://fetch.spec.whatwg.org/#dom-body-blob
25
25
  */
26
- blob(): Promise<Blob>
26
+ blob (): Promise<Blob>
27
+
28
+ /** Consumes and returns the body as an Uint8Array
29
+ * https://fetch.spec.whatwg.org/#dom-body-bytes
30
+ */
31
+ bytes (): Promise<Uint8Array>
27
32
 
28
33
  /** Consumes and returns the body as an ArrayBuffer
29
34
  * https://fetch.spec.whatwg.org/#dom-body-arraybuffer
30
35
  */
31
- arrayBuffer(): Promise<ArrayBuffer>
36
+ arrayBuffer (): Promise<ArrayBuffer>
32
37
 
33
38
  /** Not implemented
34
39
  *
35
40
  * https://fetch.spec.whatwg.org/#dom-body-formdata
36
41
  */
37
- formData(): Promise<never>
42
+ formData (): Promise<never>
38
43
 
39
44
  /** Returns true if the body is not null and the body has been consumed
40
45
  *
@@ -44,7 +49,7 @@ declare class BodyReadable extends Readable {
44
49
  */
45
50
  readonly bodyUsed: boolean
46
51
 
47
- /**
52
+ /**
48
53
  * If body is null, it should return null as the body
49
54
  *
50
55
  * If body is not null, should return the body as a ReadableStream
@@ -56,5 +61,5 @@ declare class BodyReadable extends Readable {
56
61
  /** Dumps the response body by reading `limit` number of bytes.
57
62
  * @param opts.limit Number of bytes to read (optional) - Default: 262144
58
63
  */
59
- dump(opts?: { limit: number }): Promise<void>
64
+ dump (opts?: { limit: number }): Promise<void>
60
65
  }
@@ -4,5 +4,5 @@ import RetryHandler from './retry-handler'
4
4
  export default RetryAgent
5
5
 
6
6
  declare class RetryAgent extends Dispatcher {
7
- constructor(dispatcher: Dispatcher, options?: RetryHandler.RetryOptions)
7
+ constructor (dispatcher: Dispatcher, options?: RetryHandler.RetryOptions)
8
8
  }
@@ -1,18 +1,18 @@
1
- import Dispatcher from "./dispatcher";
1
+ import Dispatcher from './dispatcher'
2
2
 
3
- export default RetryHandler;
3
+ export default RetryHandler
4
4
 
5
5
  declare class RetryHandler implements Dispatcher.DispatchHandlers {
6
- constructor(
6
+ constructor (
7
7
  options: Dispatcher.DispatchOptions & {
8
8
  retryOptions?: RetryHandler.RetryOptions;
9
9
  },
10
10
  retryHandlers: RetryHandler.RetryHandlers
11
- );
11
+ )
12
12
  }
13
13
 
14
14
  declare namespace RetryHandler {
15
- export type RetryState = { counter: number; };
15
+ export type RetryState = { counter: number; }
16
16
 
17
17
  export type RetryContext = {
18
18
  state: RetryState;
@@ -21,7 +21,7 @@ declare namespace RetryHandler {
21
21
  };
22
22
  }
23
23
 
24
- export type OnRetryCallback = (result?: Error | null) => void;
24
+ export type OnRetryCallback = (result?: Error | null) => void
25
25
 
26
26
  export type RetryCallback = (
27
27
  err: Error,
@@ -32,7 +32,7 @@ declare namespace RetryHandler {
32
32
  };
33
33
  },
34
34
  callback: OnRetryCallback
35
- ) => number | null;
35
+ ) => number | null
36
36
 
37
37
  export interface RetryOptions {
38
38
  /**
@@ -110,7 +110,7 @@ declare namespace RetryHandler {
110
110
  }
111
111
 
112
112
  export interface RetryHandlers {
113
- dispatch: Dispatcher["dispatch"];
113
+ dispatch: Dispatcher['dispatch'];
114
114
  handler: Dispatcher.DispatchHandlers;
115
115
  }
116
116
  }
package/types/util.d.ts CHANGED
@@ -3,7 +3,7 @@ export namespace util {
3
3
  * Retrieves a header name and returns its lowercase value.
4
4
  * @param value Header name
5
5
  */
6
- export function headerNameToString(value: string | Buffer): string;
6
+ export function headerNameToString (value: string | Buffer): string
7
7
 
8
8
  /**
9
9
  * Receives a header object and returns the parsed value.
@@ -11,8 +11,8 @@ export namespace util {
11
11
  * @param obj Object to specify a proxy object. Used to assign parsed values.
12
12
  * @returns If `obj` is specified, it is equivalent to `obj`.
13
13
  */
14
- export function parseHeaders(
14
+ export function parseHeaders (
15
15
  headers: (Buffer | string | (Buffer | string)[])[],
16
16
  obj?: Record<string, string | string[]>
17
- ): Record<string, string | string[]>;
17
+ ): Record<string, string | string[]>
18
18
  }
@@ -0,0 +1,7 @@
1
+ type AutocompletePrimitiveBaseType<T> =
2
+ T extends string ? string :
3
+ T extends number ? number :
4
+ T extends boolean ? boolean :
5
+ never
6
+
7
+ export type Autocomplete<T> = T | (AutocompletePrimitiveBaseType<T> & Record<never, never>)
package/types/webidl.d.ts CHANGED
@@ -34,11 +34,24 @@ interface WebidlErrors {
34
34
  }): TypeError
35
35
  }
36
36
 
37
+ interface WebIDLTypes {
38
+ UNDEFINED: 1,
39
+ BOOLEAN: 2,
40
+ STRING: 3,
41
+ SYMBOL: 4,
42
+ NUMBER: 5,
43
+ BIGINT: 6,
44
+ NULL: 7
45
+ OBJECT: 8
46
+ }
47
+
37
48
  interface WebidlUtil {
38
49
  /**
39
50
  * @see https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values
40
51
  */
41
- Type (object: unknown):
52
+ Type (object: unknown): WebIDLTypes
53
+
54
+ TypeValueToString (o: unknown):
42
55
  | 'Undefined'
43
56
  | 'Boolean'
44
57
  | 'String'
@@ -48,6 +61,8 @@ interface WebidlUtil {
48
61
  | 'Null'
49
62
  | 'Object'
50
63
 
64
+ Types: WebIDLTypes
65
+
51
66
  /**
52
67
  * @see https://webidl.spec.whatwg.org/#abstract-opdef-converttoint
53
68
  */
@@ -150,7 +165,7 @@ interface WebidlConverters {
150
165
  ): NodeJS.TypedArray | ArrayBufferLike | DataView
151
166
 
152
167
  ['sequence<ByteString>']: SequenceConverter<string>
153
-
168
+
154
169
  ['sequence<sequence<ByteString>>']: SequenceConverter<string[]>
155
170
 
156
171
  ['record<ByteString, ByteString>']: RecordConverter<string, string>
@@ -167,7 +182,9 @@ export interface Webidl {
167
182
  * @description Performs a brand-check on {@param V} to ensure it is a
168
183
  * {@param cls} object.
169
184
  */
170
- brandCheck <Interface>(V: unknown, cls: Interface, opts?: { strict?: boolean }): asserts V is Interface
185
+ brandCheck <Interface extends new () => unknown>(V: unknown, cls: Interface): asserts V is Interface
186
+
187
+ brandCheckMultiple <Interfaces extends (new () => unknown)[]> (V: unknown, list: Interfaces): asserts V is Interfaces[number]
171
188
 
172
189
  /**
173
190
  * @see https://webidl.spec.whatwg.org/#es-sequence
@@ -192,7 +209,8 @@ export interface Webidl {
192
209
  */
193
210
  interfaceConverter <Interface>(cls: Interface): (
194
211
  V: unknown,
195
- opts?: { strict: boolean }
212
+ prefix: string,
213
+ argument: string
196
214
  ) => asserts V is typeof cls
197
215
 
198
216
  // TODO(@KhafraDev): a type could likely be implemented that can infer the return type
@@ -3,8 +3,6 @@
3
3
  import type { Blob } from 'buffer'
4
4
  import type { MessagePort } from 'worker_threads'
5
5
  import {
6
- EventTarget,
7
- Event,
8
6
  EventInit,
9
7
  EventListenerOptions,
10
8
  AddEventListenerOptions,
@@ -24,7 +22,7 @@ interface WebSocketEventMap {
24
22
 
25
23
  interface WebSocket extends EventTarget {
26
24
  binaryType: BinaryType
27
-
25
+
28
26
  readonly bufferedAmount: number
29
27
  readonly extensions: string
30
28
 
@@ -1,60 +0,0 @@
1
- # Interface: DispatchInterceptor
2
-
3
- Extends: `Function`
4
-
5
- A function that can be applied to the `Dispatcher.Dispatch` function before it is invoked with a dispatch request.
6
-
7
- This allows one to write logic to intercept both the outgoing request, and the incoming response.
8
-
9
- ### Parameter: `Dispatcher.Dispatch`
10
-
11
- The base dispatch function you are decorating.
12
-
13
- ### ReturnType: `Dispatcher.Dispatch`
14
-
15
- A dispatch function that has been altered to provide additional logic
16
-
17
- ### Basic Example
18
-
19
- Here is an example of an interceptor being used to provide a JWT bearer token
20
-
21
- ```js
22
- 'use strict'
23
-
24
- const insertHeaderInterceptor = dispatch => {
25
- return function InterceptedDispatch(opts, handler){
26
- opts.headers.push('Authorization', 'Bearer [Some token]')
27
- return dispatch(opts, handler)
28
- }
29
- }
30
-
31
- const client = new Client('https://localhost:3000', {
32
- interceptors: { Client: [insertHeaderInterceptor] }
33
- })
34
-
35
- ```
36
-
37
- ### Basic Example 2
38
-
39
- Here is a contrived example of an interceptor stripping the headers from a response.
40
-
41
- ```js
42
- 'use strict'
43
-
44
- const clearHeadersInterceptor = dispatch => {
45
- const { DecoratorHandler } = require('undici')
46
- class ResultInterceptor extends DecoratorHandler {
47
- onHeaders (statusCode, headers, resume) {
48
- return super.onHeaders(statusCode, [], resume)
49
- }
50
- }
51
- return function InterceptedDispatch(opts, handler){
52
- return dispatch(opts, new ResultInterceptor(handler))
53
- }
54
- }
55
-
56
- const client = new Client('https://localhost:3000', {
57
- interceptors: { Client: [clearHeadersInterceptor] }
58
- })
59
-
60
- ```
@@ -1,21 +0,0 @@
1
- 'use strict'
2
-
3
- const RedirectHandler = require('../handler/redirect-handler')
4
-
5
- function createRedirectInterceptor ({ maxRedirections: defaultMaxRedirections }) {
6
- return (dispatch) => {
7
- return function Intercept (opts, handler) {
8
- const { maxRedirections = defaultMaxRedirections } = opts
9
-
10
- if (!maxRedirections) {
11
- return dispatch(opts, handler)
12
- }
13
-
14
- const redirectHandler = new RedirectHandler(dispatch, maxRedirections, opts, handler)
15
- opts = { ...opts, maxRedirections: 0 } // Stop sub dispatcher from also redirecting.
16
- return dispatch(opts, redirectHandler)
17
- }
18
- }
19
- }
20
-
21
- module.exports = createRedirectInterceptor