undici 7.15.0 → 7.17.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.
Files changed (93) hide show
  1. package/README.md +48 -2
  2. package/docs/docs/api/Agent.md +1 -0
  3. package/docs/docs/api/Client.md +1 -0
  4. package/docs/docs/api/DiagnosticsChannel.md +57 -0
  5. package/docs/docs/api/Dispatcher.md +86 -0
  6. package/docs/docs/api/Errors.md +0 -1
  7. package/docs/docs/api/RoundRobinPool.md +145 -0
  8. package/docs/docs/api/WebSocket.md +21 -0
  9. package/docs/docs/best-practices/crawling.md +58 -0
  10. package/index-fetch.js +2 -2
  11. package/index.js +8 -9
  12. package/lib/api/api-request.js +22 -8
  13. package/lib/api/api-upgrade.js +2 -1
  14. package/lib/api/readable.js +7 -5
  15. package/lib/core/connect.js +4 -1
  16. package/lib/core/diagnostics.js +28 -1
  17. package/lib/core/errors.js +217 -13
  18. package/lib/core/request.js +5 -1
  19. package/lib/core/symbols.js +3 -0
  20. package/lib/core/util.js +61 -41
  21. package/lib/dispatcher/agent.js +19 -7
  22. package/lib/dispatcher/balanced-pool.js +10 -0
  23. package/lib/dispatcher/client-h1.js +18 -23
  24. package/lib/dispatcher/client-h2.js +166 -26
  25. package/lib/dispatcher/client.js +64 -59
  26. package/lib/dispatcher/dispatcher-base.js +20 -16
  27. package/lib/dispatcher/env-http-proxy-agent.js +12 -16
  28. package/lib/dispatcher/fixed-queue.js +15 -39
  29. package/lib/dispatcher/h2c-client.js +7 -78
  30. package/lib/dispatcher/pool-base.js +60 -43
  31. package/lib/dispatcher/pool.js +2 -2
  32. package/lib/dispatcher/proxy-agent.js +27 -11
  33. package/lib/dispatcher/round-robin-pool.js +137 -0
  34. package/lib/encoding/index.js +33 -0
  35. package/lib/global.js +19 -1
  36. package/lib/handler/cache-handler.js +84 -27
  37. package/lib/handler/deduplication-handler.js +216 -0
  38. package/lib/handler/retry-handler.js +0 -2
  39. package/lib/interceptor/cache.js +94 -15
  40. package/lib/interceptor/decompress.js +2 -1
  41. package/lib/interceptor/deduplicate.js +109 -0
  42. package/lib/interceptor/dns.js +55 -13
  43. package/lib/mock/mock-agent.js +4 -4
  44. package/lib/mock/mock-errors.js +10 -0
  45. package/lib/mock/mock-utils.js +13 -12
  46. package/lib/mock/snapshot-agent.js +11 -5
  47. package/lib/mock/snapshot-recorder.js +12 -4
  48. package/lib/mock/snapshot-utils.js +4 -4
  49. package/lib/util/cache.js +29 -1
  50. package/lib/util/date.js +534 -140
  51. package/lib/util/runtime-features.js +124 -0
  52. package/lib/web/cookies/index.js +1 -1
  53. package/lib/web/cookies/parse.js +1 -1
  54. package/lib/web/eventsource/eventsource-stream.js +2 -2
  55. package/lib/web/eventsource/eventsource.js +34 -29
  56. package/lib/web/eventsource/util.js +1 -9
  57. package/lib/web/fetch/body.js +45 -61
  58. package/lib/web/fetch/data-url.js +12 -160
  59. package/lib/web/fetch/formdata-parser.js +204 -127
  60. package/lib/web/fetch/index.js +21 -19
  61. package/lib/web/fetch/request.js +6 -0
  62. package/lib/web/fetch/response.js +4 -7
  63. package/lib/web/fetch/util.js +10 -79
  64. package/lib/web/infra/index.js +229 -0
  65. package/lib/web/subresource-integrity/subresource-integrity.js +6 -5
  66. package/lib/web/webidl/index.js +207 -44
  67. package/lib/web/websocket/connection.js +33 -22
  68. package/lib/web/websocket/events.js +1 -1
  69. package/lib/web/websocket/frame.js +9 -15
  70. package/lib/web/websocket/stream/websocketerror.js +22 -1
  71. package/lib/web/websocket/stream/websocketstream.js +17 -8
  72. package/lib/web/websocket/util.js +2 -1
  73. package/lib/web/websocket/websocket.js +32 -42
  74. package/package.json +9 -7
  75. package/types/agent.d.ts +2 -1
  76. package/types/api.d.ts +2 -2
  77. package/types/balanced-pool.d.ts +2 -1
  78. package/types/cache-interceptor.d.ts +1 -0
  79. package/types/client.d.ts +1 -1
  80. package/types/connector.d.ts +2 -2
  81. package/types/diagnostics-channel.d.ts +2 -2
  82. package/types/dispatcher.d.ts +12 -12
  83. package/types/errors.d.ts +5 -15
  84. package/types/fetch.d.ts +4 -4
  85. package/types/formdata.d.ts +1 -1
  86. package/types/h2c-client.d.ts +1 -1
  87. package/types/index.d.ts +9 -1
  88. package/types/interceptors.d.ts +36 -2
  89. package/types/pool.d.ts +1 -1
  90. package/types/readable.d.ts +2 -2
  91. package/types/round-robin-pool.d.ts +41 -0
  92. package/types/webidl.d.ts +82 -21
  93. package/types/websocket.d.ts +9 -9
@@ -0,0 +1,41 @@
1
+ import Client from './client'
2
+ import TPoolStats from './pool-stats'
3
+ import { URL } from 'node:url'
4
+ import Dispatcher from './dispatcher'
5
+
6
+ export default RoundRobinPool
7
+
8
+ type RoundRobinPoolConnectOptions = Omit<Dispatcher.ConnectOptions, 'origin'>
9
+
10
+ declare class RoundRobinPool extends Dispatcher {
11
+ constructor (url: string | URL, options?: RoundRobinPool.Options)
12
+ /** `true` after `pool.close()` has been called. */
13
+ closed: boolean
14
+ /** `true` after `pool.destroyed()` has been called or `pool.close()` has been called and the pool shutdown has completed. */
15
+ destroyed: boolean
16
+ /** Aggregate stats for a RoundRobinPool. */
17
+ readonly stats: TPoolStats
18
+
19
+ // Override dispatcher APIs.
20
+ override connect (
21
+ options: RoundRobinPoolConnectOptions
22
+ ): Promise<Dispatcher.ConnectData>
23
+ override connect (
24
+ options: RoundRobinPoolConnectOptions,
25
+ callback: (err: Error | null, data: Dispatcher.ConnectData) => void
26
+ ): void
27
+ }
28
+
29
+ declare namespace RoundRobinPool {
30
+ export type RoundRobinPoolStats = TPoolStats
31
+ export interface Options extends Client.Options {
32
+ /** Default: `(origin, opts) => new Client(origin, opts)`. */
33
+ factory?(origin: URL, opts: object): Dispatcher;
34
+ /** The max number of clients to create. `null` if no limit. Default `null`. */
35
+ connections?: number | null;
36
+ /** The amount of time before a client is removed from the pool and closed. `null` if no time limit. Default `null` */
37
+ clientTtl?: number | null;
38
+
39
+ interceptors?: { RoundRobinPool?: readonly Dispatcher.DispatchInterceptor[] } & Client.Options['interceptors']
40
+ }
41
+ }
package/types/webidl.d.ts CHANGED
@@ -10,11 +10,6 @@ type SequenceConverter<T> = (object: unknown, iterable?: IterableIterator<T>) =>
10
10
 
11
11
  type RecordConverter<K extends string, V> = (object: unknown) => Record<K, V>
12
12
 
13
- interface ConvertToIntOpts {
14
- clamp?: boolean
15
- enforceRange?: boolean
16
- }
17
-
18
13
  interface WebidlErrors {
19
14
  /**
20
15
  * @description Instantiate an error
@@ -74,7 +69,7 @@ interface WebidlUtil {
74
69
  V: unknown,
75
70
  bitLength: number,
76
71
  signedness: 'signed' | 'unsigned',
77
- opts?: ConvertToIntOpts
72
+ flags?: number
78
73
  ): number
79
74
 
80
75
  /**
@@ -94,15 +89,17 @@ interface WebidlUtil {
94
89
  * This is only effective in some newer Node.js versions.
95
90
  */
96
91
  markAsUncloneable (V: any): void
92
+
93
+ IsResizableArrayBuffer (V: ArrayBufferLike): boolean
94
+
95
+ HasFlag (flag: number, attributes: number): boolean
97
96
  }
98
97
 
99
98
  interface WebidlConverters {
100
99
  /**
101
100
  * @see https://webidl.spec.whatwg.org/#es-DOMString
102
101
  */
103
- DOMString (V: unknown, prefix: string, argument: string, opts?: {
104
- legacyNullToEmptyString: boolean
105
- }): string
102
+ DOMString (V: unknown, prefix: string, argument: string, flags?: number): string
106
103
 
107
104
  /**
108
105
  * @see https://webidl.spec.whatwg.org/#es-ByteString
@@ -142,39 +139,78 @@ interface WebidlConverters {
142
139
  /**
143
140
  * @see https://webidl.spec.whatwg.org/#es-unsigned-short
144
141
  */
145
- ['unsigned short'] (V: unknown, opts?: ConvertToIntOpts): number
142
+ ['unsigned short'] (V: unknown, flags?: number): number
146
143
 
147
144
  /**
148
145
  * @see https://webidl.spec.whatwg.org/#idl-ArrayBuffer
149
146
  */
150
- ArrayBuffer (V: unknown): ArrayBufferLike
151
- ArrayBuffer (V: unknown, opts: { allowShared: false }): ArrayBuffer
147
+ ArrayBuffer (
148
+ V: unknown,
149
+ prefix: string,
150
+ argument: string,
151
+ options?: { allowResizable: boolean }
152
+ ): ArrayBuffer
153
+
154
+ /**
155
+ * @see https://webidl.spec.whatwg.org/#idl-SharedArrayBuffer
156
+ */
157
+ SharedArrayBuffer (
158
+ V: unknown,
159
+ prefix: string,
160
+ argument: string,
161
+ options?: { allowResizable: boolean }
162
+ ): SharedArrayBuffer
152
163
 
153
164
  /**
154
165
  * @see https://webidl.spec.whatwg.org/#es-buffer-source-types
155
166
  */
156
167
  TypedArray (
157
168
  V: unknown,
158
- TypedArray: NodeJS.TypedArray | ArrayBufferLike
159
- ): NodeJS.TypedArray | ArrayBufferLike
160
- TypedArray (
169
+ T: new () => NodeJS.TypedArray,
170
+ prefix: string,
171
+ argument: string,
172
+ flags?: number
173
+ ): NodeJS.TypedArray
174
+
175
+ /**
176
+ * @see https://webidl.spec.whatwg.org/#es-buffer-source-types
177
+ */
178
+ DataView (
161
179
  V: unknown,
162
- TypedArray: NodeJS.TypedArray | ArrayBufferLike,
163
- opts?: { allowShared: false }
164
- ): NodeJS.TypedArray | ArrayBuffer
180
+ prefix: string,
181
+ argument: string,
182
+ flags?: number
183
+ ): DataView
165
184
 
166
185
  /**
167
186
  * @see https://webidl.spec.whatwg.org/#es-buffer-source-types
168
187
  */
169
- DataView (V: unknown, opts?: { allowShared: boolean }): DataView
188
+ ArrayBufferView (
189
+ V: unknown,
190
+ prefix: string,
191
+ argument: string,
192
+ flags?: number
193
+ ): NodeJS.ArrayBufferView
170
194
 
171
195
  /**
172
196
  * @see https://webidl.spec.whatwg.org/#BufferSource
173
197
  */
174
198
  BufferSource (
175
199
  V: unknown,
176
- opts?: { allowShared: boolean }
177
- ): NodeJS.TypedArray | ArrayBufferLike | DataView
200
+ prefix: string,
201
+ argument: string,
202
+ flags?: number
203
+ ): ArrayBuffer | NodeJS.ArrayBufferView
204
+
205
+ /**
206
+ * @see https://webidl.spec.whatwg.org/#AllowSharedBufferSource
207
+ */
208
+ AllowSharedBufferSource (
209
+ V: unknown,
210
+ prefix: string,
211
+ argument: string,
212
+ flags?: number
213
+ ): ArrayBuffer | SharedArrayBuffer | NodeJS.ArrayBufferView
178
214
 
179
215
  ['sequence<ByteString>']: SequenceConverter<string>
180
216
 
@@ -192,6 +228,13 @@ interface WebidlConverters {
192
228
  */
193
229
  RequestInit (V: unknown): undici.RequestInit
194
230
 
231
+ /**
232
+ * @see https://html.spec.whatwg.org/multipage/webappapis.html#eventhandlernonnull
233
+ */
234
+ EventHandlerNonNull (V: unknown): Function | null
235
+
236
+ WebSocketStreamWrite (V: unknown): ArrayBuffer | NodeJS.TypedArray | string
237
+
195
238
  [Key: string]: (...args: any[]) => unknown
196
239
  }
197
240
 
@@ -210,6 +253,10 @@ interface WebidlIs {
210
253
  AbortSignal: WebidlIsFunction<AbortSignal>
211
254
  MessagePort: WebidlIsFunction<MessagePort>
212
255
  USVString: WebidlIsFunction<string>
256
+ /**
257
+ * @see https://webidl.spec.whatwg.org/#BufferSource
258
+ */
259
+ BufferSource: WebidlIsFunction<ArrayBuffer | NodeJS.TypedArray>
213
260
  }
214
261
 
215
262
  export interface Webidl {
@@ -217,6 +264,7 @@ export interface Webidl {
217
264
  util: WebidlUtil
218
265
  converters: WebidlConverters
219
266
  is: WebidlIs
267
+ attributes: WebIDLExtendedAttributes
220
268
 
221
269
  /**
222
270
  * @description Performs a brand-check on {@param V} to ensure it is a
@@ -278,3 +326,16 @@ export interface Webidl {
278
326
 
279
327
  argumentLengthCheck (args: { length: number }, min: number, context: string): void
280
328
  }
329
+
330
+ interface WebIDLExtendedAttributes {
331
+ /** https://webidl.spec.whatwg.org/#Clamp */
332
+ Clamp: number
333
+ /** https://webidl.spec.whatwg.org/#EnforceRange */
334
+ EnforceRange: number
335
+ /** https://webidl.spec.whatwg.org/#AllowShared */
336
+ AllowShared: number
337
+ /** https://webidl.spec.whatwg.org/#AllowResizable */
338
+ AllowResizable: number
339
+ /** https://webidl.spec.whatwg.org/#LegacyNullToEmptyString */
340
+ LegacyNullToEmptyString: number
341
+ }
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
 
3
- import type { Blob } from 'buffer'
4
- import type { ReadableStream, WritableStream } from 'stream/web'
5
- import type { MessagePort } from 'worker_threads'
3
+ import type { Blob } from 'node:buffer'
4
+ import type { ReadableStream, WritableStream } from 'node:stream/web'
5
+ import type { MessagePort } from 'node:worker_threads'
6
6
  import {
7
7
  EventInit,
8
8
  EventListenerOptions,
@@ -96,16 +96,16 @@ interface MessageEventInit<T = any> extends EventInit {
96
96
  data?: T
97
97
  lastEventId?: string
98
98
  origin?: string
99
- ports?: (typeof MessagePort)[]
100
- source?: typeof MessagePort | null
99
+ ports?: MessagePort[]
100
+ source?: MessagePort | null
101
101
  }
102
102
 
103
103
  interface MessageEvent<T = any> extends Event {
104
104
  readonly data: T
105
105
  readonly lastEventId: string
106
106
  readonly origin: string
107
- readonly ports: ReadonlyArray<typeof MessagePort>
108
- readonly source: typeof MessagePort | null
107
+ readonly ports: readonly MessagePort[]
108
+ readonly source: MessagePort | null
109
109
  initMessageEvent(
110
110
  type: string,
111
111
  bubbles?: boolean,
@@ -113,8 +113,8 @@ interface MessageEvent<T = any> extends Event {
113
113
  data?: any,
114
114
  origin?: string,
115
115
  lastEventId?: string,
116
- source?: typeof MessagePort | null,
117
- ports?: (typeof MessagePort)[]
116
+ source?: MessagePort | null,
117
+ ports?: MessagePort[]
118
118
  ): void;
119
119
  }
120
120