undici 7.10.0 → 7.12.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/README.md +159 -0
- package/docs/docs/api/CacheStore.md +3 -3
- package/docs/docs/api/Debug.md +13 -13
- package/docs/docs/api/DiagnosticsChannel.md +32 -4
- package/docs/docs/api/Dispatcher.md +22 -3
- package/docs/docs/api/GlobalInstallation.md +91 -0
- package/docs/docs/api/MockClient.md +4 -0
- package/docs/docs/api/MockPool.md +6 -0
- package/docs/docs/api/ProxyAgent.md +2 -0
- package/docs/docs/api/RetryAgent.md +6 -1
- package/docs/docs/api/RetryHandler.md +1 -0
- package/docs/docs/api/WebSocket.md +27 -0
- package/index.js +18 -1
- package/lib/api/api-stream.js +1 -1
- package/lib/api/readable.js +1 -3
- package/lib/cache/memory-cache-store.js +3 -3
- package/lib/cache/sqlite-cache-store.js +1 -1
- package/lib/core/connect.js +21 -51
- package/lib/core/diagnostics.js +6 -4
- package/lib/core/request.js +12 -1
- package/lib/core/tree.js +1 -1
- package/lib/core/util.js +0 -45
- package/lib/dispatcher/client-h1.js +9 -18
- package/lib/dispatcher/proxy-agent.js +2 -1
- package/lib/handler/cache-handler.js +4 -1
- package/lib/handler/redirect-handler.js +2 -2
- package/lib/handler/retry-handler.js +110 -56
- package/lib/interceptor/cache.js +2 -2
- package/lib/interceptor/redirect.js +1 -1
- package/lib/mock/mock-client.js +4 -0
- package/lib/mock/mock-pool.js +4 -0
- package/lib/util/cache.js +12 -2
- package/lib/util/promise.js +28 -0
- package/lib/util/timers.js +11 -9
- package/lib/web/cache/cache.js +11 -9
- package/lib/web/cache/cachestorage.js +1 -1
- package/lib/web/cookies/index.js +1 -1
- package/lib/web/eventsource/eventsource.js +3 -6
- package/lib/web/eventsource/util.js +1 -1
- package/lib/web/fetch/body.js +36 -24
- package/lib/web/fetch/formdata-parser.js +4 -4
- package/lib/web/fetch/formdata.js +1 -1
- package/lib/web/fetch/headers.js +1 -1
- package/lib/web/fetch/index.js +228 -226
- package/lib/web/fetch/request.js +16 -8
- package/lib/web/fetch/response.js +6 -4
- package/lib/web/fetch/util.js +23 -25
- package/lib/web/{fetch/webidl.js → webidl/index.js} +57 -9
- package/lib/web/websocket/connection.js +4 -12
- package/lib/web/websocket/events.js +1 -1
- package/lib/web/websocket/frame.js +2 -1
- package/lib/web/websocket/receiver.js +2 -12
- package/lib/web/websocket/stream/websocketerror.js +1 -1
- package/lib/web/websocket/stream/websocketstream.js +8 -5
- package/lib/web/websocket/websocket.js +61 -5
- package/package.json +5 -5
- package/types/diagnostics-channel.d.ts +9 -0
- package/types/dispatcher.d.ts +3 -2
- package/types/env-http-proxy-agent.d.ts +2 -1
- package/types/eventsource.d.ts +3 -3
- package/types/fetch.d.ts +1 -0
- package/types/handlers.d.ts +1 -1
- package/types/mock-client.d.ts +2 -0
- package/types/mock-interceptor.d.ts +2 -0
- package/types/mock-pool.d.ts +2 -0
- package/types/retry-handler.d.ts +9 -0
- package/types/webidl.d.ts +29 -15
- package/types/websocket.d.ts +3 -1
- package/lib/web/fetch/dispatcher-weakref.js +0 -46
package/types/handlers.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Dispatcher from './dispatcher'
|
|
|
2
2
|
|
|
3
3
|
export declare class RedirectHandler implements Dispatcher.DispatchHandler {
|
|
4
4
|
constructor (
|
|
5
|
-
dispatch: Dispatcher,
|
|
5
|
+
dispatch: Dispatcher.Dispatch,
|
|
6
6
|
maxRedirections: number,
|
|
7
7
|
opts: Dispatcher.DispatchOptions,
|
|
8
8
|
handler: Dispatcher.DispatchHandler,
|
package/types/mock-client.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ declare class MockClient extends Client implements Interceptable {
|
|
|
14
14
|
dispatch (options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandler): boolean
|
|
15
15
|
/** Closes the mock client and gracefully waits for enqueued requests to complete. */
|
|
16
16
|
close (): Promise<void>
|
|
17
|
+
/** Clean up all the prepared mocks. */
|
|
18
|
+
cleanMocks (): void
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
declare namespace MockClient {
|
|
@@ -84,6 +84,8 @@ declare namespace MockInterceptor {
|
|
|
84
84
|
interface Interceptable extends Dispatcher {
|
|
85
85
|
/** Intercepts any matching requests that use the same origin as this mock client. */
|
|
86
86
|
intercept(options: MockInterceptor.Options): MockInterceptor;
|
|
87
|
+
/** Clean up all the prepared mocks. */
|
|
88
|
+
cleanMocks (): void
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
export {
|
package/types/mock-pool.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ declare class MockPool extends Pool implements Interceptable {
|
|
|
14
14
|
dispatch (options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandler): boolean
|
|
15
15
|
/** Closes the mock pool and gracefully waits for enqueued requests to complete. */
|
|
16
16
|
close (): Promise<void>
|
|
17
|
+
/** Clean up all the prepared mocks. */
|
|
18
|
+
cleanMocks (): void
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
declare namespace MockPool {
|
package/types/retry-handler.d.ts
CHANGED
|
@@ -35,6 +35,15 @@ declare namespace RetryHandler {
|
|
|
35
35
|
) => void
|
|
36
36
|
|
|
37
37
|
export interface RetryOptions {
|
|
38
|
+
/**
|
|
39
|
+
* If true, the retry handler will throw an error if the request fails,
|
|
40
|
+
* this will prevent the folling handlers from being called, and will destroy the socket.
|
|
41
|
+
*
|
|
42
|
+
* @type {boolean}
|
|
43
|
+
* @memberof RetryOptions
|
|
44
|
+
* @default true
|
|
45
|
+
*/
|
|
46
|
+
throwOnError?: boolean;
|
|
38
47
|
/**
|
|
39
48
|
* Callback to be invoked on every retry iteration.
|
|
40
49
|
* It receives the error, current state of the retry object and the options object
|
package/types/webidl.d.ts
CHANGED
|
@@ -16,9 +16,12 @@ interface ConvertToIntOpts {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
interface WebidlErrors {
|
|
19
|
+
/**
|
|
20
|
+
* @description Instantiate an error
|
|
21
|
+
*/
|
|
19
22
|
exception (opts: { header: string, message: string }): TypeError
|
|
20
23
|
/**
|
|
21
|
-
* @description
|
|
24
|
+
* @description Instantiate an error when conversion from one type to another has failed
|
|
22
25
|
*/
|
|
23
26
|
conversionFailed (opts: {
|
|
24
27
|
prefix: string
|
|
@@ -75,7 +78,7 @@ interface WebidlUtil {
|
|
|
75
78
|
): number
|
|
76
79
|
|
|
77
80
|
/**
|
|
78
|
-
* @see https://webidl.spec.whatwg.org/#abstract-opdef-
|
|
81
|
+
* @see https://webidl.spec.whatwg.org/#abstract-opdef-integerpart
|
|
79
82
|
*/
|
|
80
83
|
IntegerPart (N: number): number
|
|
81
84
|
|
|
@@ -179,23 +182,34 @@ interface WebidlConverters {
|
|
|
179
182
|
|
|
180
183
|
['record<ByteString, ByteString>']: RecordConverter<string, string>
|
|
181
184
|
|
|
185
|
+
/**
|
|
186
|
+
* @see https://fetch.spec.whatwg.org/#requestinfo
|
|
187
|
+
*/
|
|
188
|
+
RequestInfo (V: unknown): undici.Request | string
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @see https://fetch.spec.whatwg.org/#requestinit
|
|
192
|
+
*/
|
|
193
|
+
RequestInit (V: unknown): undici.RequestInit
|
|
194
|
+
|
|
182
195
|
[Key: string]: (...args: any[]) => unknown
|
|
183
196
|
}
|
|
184
197
|
|
|
185
|
-
type
|
|
198
|
+
type WebidlIsFunction<T> = (arg: any) => arg is T
|
|
186
199
|
|
|
187
200
|
interface WebidlIs {
|
|
188
|
-
Request:
|
|
189
|
-
Response:
|
|
190
|
-
ReadableStream:
|
|
191
|
-
Blob:
|
|
192
|
-
URLSearchParams:
|
|
193
|
-
File:
|
|
194
|
-
FormData:
|
|
195
|
-
URL:
|
|
196
|
-
WebSocketError:
|
|
197
|
-
AbortSignal:
|
|
198
|
-
MessagePort:
|
|
201
|
+
Request: WebidlIsFunction<undici.Request>
|
|
202
|
+
Response: WebidlIsFunction<undici.Response>
|
|
203
|
+
ReadableStream: WebidlIsFunction<ReadableStream>
|
|
204
|
+
Blob: WebidlIsFunction<Blob>
|
|
205
|
+
URLSearchParams: WebidlIsFunction<URLSearchParams>
|
|
206
|
+
File: WebidlIsFunction<File>
|
|
207
|
+
FormData: WebidlIsFunction<undici.FormData>
|
|
208
|
+
URL: WebidlIsFunction<URL>
|
|
209
|
+
WebSocketError: WebidlIsFunction<undici.WebSocketError>
|
|
210
|
+
AbortSignal: WebidlIsFunction<AbortSignal>
|
|
211
|
+
MessagePort: WebidlIsFunction<MessagePort>
|
|
212
|
+
USVString: WebidlIsFunction<string>
|
|
199
213
|
}
|
|
200
214
|
|
|
201
215
|
export interface Webidl {
|
|
@@ -233,7 +247,7 @@ export interface Webidl {
|
|
|
233
247
|
* Similar to {@link Webidl.brandCheck} but allows skipping the check if third party
|
|
234
248
|
* interfaces are allowed.
|
|
235
249
|
*/
|
|
236
|
-
interfaceConverter <Interface>(typeCheck:
|
|
250
|
+
interfaceConverter <Interface>(typeCheck: WebidlIsFunction<Interface>, name: string): (
|
|
237
251
|
V: unknown,
|
|
238
252
|
prefix: string,
|
|
239
253
|
argument: string
|
package/types/websocket.d.ts
CHANGED
|
@@ -136,7 +136,7 @@ interface ErrorEvent extends Event {
|
|
|
136
136
|
readonly filename: string
|
|
137
137
|
readonly lineno: number
|
|
138
138
|
readonly colno: number
|
|
139
|
-
readonly error:
|
|
139
|
+
readonly error: Error
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
export declare const ErrorEvent: {
|
|
@@ -182,3 +182,5 @@ export declare const WebSocketError: {
|
|
|
182
182
|
prototype: WebSocketError
|
|
183
183
|
new (type: string, init?: WebSocketCloseInfo): WebSocketError
|
|
184
184
|
}
|
|
185
|
+
|
|
186
|
+
export declare const ping: (ws: WebSocket, body?: Buffer) => void
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { kConnected, kSize } = require('../../core/symbols')
|
|
4
|
-
|
|
5
|
-
class CompatWeakRef {
|
|
6
|
-
constructor (value) {
|
|
7
|
-
this.value = value
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
deref () {
|
|
11
|
-
return this.value[kConnected] === 0 && this.value[kSize] === 0
|
|
12
|
-
? undefined
|
|
13
|
-
: this.value
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class CompatFinalizer {
|
|
18
|
-
constructor (finalizer) {
|
|
19
|
-
this.finalizer = finalizer
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
register (dispatcher, key) {
|
|
23
|
-
if (dispatcher.on) {
|
|
24
|
-
dispatcher.on('disconnect', () => {
|
|
25
|
-
if (dispatcher[kConnected] === 0 && dispatcher[kSize] === 0) {
|
|
26
|
-
this.finalizer(key)
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
unregister (key) {}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
module.exports = function () {
|
|
36
|
-
// FIXME: remove workaround when the Node bug is backported to v18
|
|
37
|
-
// https://github.com/nodejs/node/issues/49344#issuecomment-1741776308
|
|
38
|
-
if (process.env.NODE_V8_COVERAGE && process.version.startsWith('v18')) {
|
|
39
|
-
process._rawDebug('Using compatibility WeakRef and FinalizationRegistry')
|
|
40
|
-
return {
|
|
41
|
-
WeakRef: CompatWeakRef,
|
|
42
|
-
FinalizationRegistry: CompatFinalizer
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return { WeakRef, FinalizationRegistry }
|
|
46
|
-
}
|