undici 7.0.0-alpha.5 → 7.0.0-alpha.7
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 +19 -34
- package/docs/docs/api/CacheStore.md +13 -1
- package/docs/docs/api/Dispatcher.md +6 -8
- package/docs/docs/api/RedirectHandler.md +1 -1
- package/docs/docs/api/RetryHandler.md +2 -2
- package/index.js +9 -0
- package/lib/cache/memory-cache-store.js +6 -12
- package/lib/cache/sqlite-cache-store.js +457 -0
- package/lib/core/util.js +5 -0
- package/lib/dispatcher/client-h1.js +11 -0
- package/lib/dispatcher/client-h2.js +20 -6
- package/lib/dispatcher/dispatcher-base.js +2 -1
- package/lib/dispatcher/dispatcher.js +4 -0
- package/lib/handler/cache-handler.js +51 -157
- package/lib/handler/cache-revalidation-handler.js +33 -71
- package/lib/handler/redirect-handler.js +32 -25
- package/lib/handler/retry-handler.js +9 -15
- package/lib/handler/unwrap-handler.js +96 -0
- package/lib/handler/wrap-handler.js +98 -0
- package/lib/interceptor/cache.js +43 -34
- package/lib/interceptor/dns.js +8 -2
- package/lib/util/cache.js +75 -10
- package/lib/util/timers.js +1 -19
- package/package.json +1 -1
- package/types/agent.d.ts +1 -1
- package/types/cache-interceptor.d.ts +44 -6
- package/types/dispatcher.d.ts +28 -3
- package/types/env-http-proxy-agent.d.ts +1 -1
- package/types/handlers.d.ts +4 -4
- package/types/mock-agent.d.ts +1 -1
- package/types/mock-client.d.ts +1 -1
- package/types/mock-pool.d.ts +1 -1
- package/types/proxy-agent.d.ts +1 -1
- package/types/retry-handler.d.ts +3 -3
|
@@ -5,6 +5,10 @@ export default CacheHandler
|
|
|
5
5
|
declare namespace CacheHandler {
|
|
6
6
|
export type CacheMethods = 'GET' | 'HEAD' | 'OPTIONS' | 'TRACE'
|
|
7
7
|
|
|
8
|
+
export interface CacheHandlerOptions {
|
|
9
|
+
store: CacheStore
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export interface CacheOptions {
|
|
9
13
|
store?: CacheStore
|
|
10
14
|
|
|
@@ -28,7 +32,7 @@ declare namespace CacheHandler {
|
|
|
28
32
|
export interface CacheValue {
|
|
29
33
|
statusCode: number
|
|
30
34
|
statusMessage: string
|
|
31
|
-
|
|
35
|
+
headers: Record<string, string | string[]>
|
|
32
36
|
vary?: Record<string, string | string[]>
|
|
33
37
|
etag?: string
|
|
34
38
|
cachedAt: number
|
|
@@ -45,7 +49,8 @@ declare namespace CacheHandler {
|
|
|
45
49
|
type GetResult = {
|
|
46
50
|
statusCode: number
|
|
47
51
|
statusMessage: string
|
|
48
|
-
|
|
52
|
+
headers: Record<string, string | string[]>
|
|
53
|
+
etag?: string
|
|
49
54
|
body: null | Readable | Iterable<Buffer> | AsyncIterable<Buffer> | Buffer | Iterable<string> | AsyncIterable<string> | string
|
|
50
55
|
cachedAt: number
|
|
51
56
|
staleAt: number
|
|
@@ -70,13 +75,13 @@ declare namespace CacheHandler {
|
|
|
70
75
|
maxCount?: number
|
|
71
76
|
|
|
72
77
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
* @default Infinity
|
|
79
|
+
*/
|
|
75
80
|
maxSize?: number
|
|
76
81
|
|
|
77
82
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
* @default Infinity
|
|
84
|
+
*/
|
|
80
85
|
maxEntrySize?: number
|
|
81
86
|
|
|
82
87
|
errorCallback?: (err: Error) => void
|
|
@@ -91,4 +96,37 @@ declare namespace CacheHandler {
|
|
|
91
96
|
|
|
92
97
|
delete (key: CacheKey): void | Promise<void>
|
|
93
98
|
}
|
|
99
|
+
|
|
100
|
+
export interface SqliteCacheStoreOpts {
|
|
101
|
+
/**
|
|
102
|
+
* Location of the database
|
|
103
|
+
* @default ':memory:'
|
|
104
|
+
*/
|
|
105
|
+
location?: string
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @default Infinity
|
|
109
|
+
*/
|
|
110
|
+
maxCount?: number
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @default Infinity
|
|
114
|
+
*/
|
|
115
|
+
maxEntrySize?: number
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export class SqliteCacheStore implements CacheStore {
|
|
119
|
+
constructor (opts?: SqliteCacheStoreOpts)
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Closes the connection to the database
|
|
123
|
+
*/
|
|
124
|
+
close (): void
|
|
125
|
+
|
|
126
|
+
get (key: CacheKey): GetResult | Promise<GetResult | undefined> | undefined
|
|
127
|
+
|
|
128
|
+
createWriteStream (key: CacheKey, value: CacheValue): Writable | undefined
|
|
129
|
+
|
|
130
|
+
delete (key: CacheKey): void | Promise<void>
|
|
131
|
+
}
|
|
94
132
|
}
|
package/types/dispatcher.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export default Dispatcher
|
|
|
15
15
|
/** Dispatcher is the core API used to dispatch requests. */
|
|
16
16
|
declare class Dispatcher extends EventEmitter {
|
|
17
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. */
|
|
18
|
-
dispatch (options: Dispatcher.DispatchOptions, handler: Dispatcher.
|
|
18
|
+
dispatch (options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean
|
|
19
19
|
/** Starts two-way communications with the requested resource. */
|
|
20
20
|
connect<TOpaque = null>(options: Dispatcher.ConnectOptions<TOpaque>): Promise<Dispatcher.ConnectData<TOpaque>>
|
|
21
21
|
connect<TOpaque = null>(options: Dispatcher.ConnectOptions<TOpaque>, callback: (err: Error | null, data: Dispatcher.ConnectData<TOpaque>) => void): void
|
|
@@ -103,7 +103,7 @@ declare namespace Dispatcher {
|
|
|
103
103
|
/** Default: `null` */
|
|
104
104
|
body?: string | Buffer | Uint8Array | Readable | null | FormData;
|
|
105
105
|
/** Default: `null` */
|
|
106
|
-
headers?: IncomingHttpHeaders | string[] | Iterable<[string, string | string[] | undefined]> | null;
|
|
106
|
+
headers?: Record<string, string | string[]> | IncomingHttpHeaders | string[] | Iterable<[string, string | string[] | undefined]> | null;
|
|
107
107
|
/** Query string params to be embedded in the request URL. Default: `null` */
|
|
108
108
|
query?: Record<string, any>;
|
|
109
109
|
/** Whether the requests can be safely retried or not. If `false` the request won't be sent until all preceding requests in the pipeline have completed. Default: `true` if `method` is `HEAD` or `GET`. */
|
|
@@ -213,22 +213,47 @@ declare namespace Dispatcher {
|
|
|
213
213
|
context: object;
|
|
214
214
|
}
|
|
215
215
|
export type StreamFactory<TOpaque = null> = (data: StreamFactoryData<TOpaque>) => Writable
|
|
216
|
-
|
|
216
|
+
|
|
217
|
+
export interface DispatchController {
|
|
218
|
+
get aborted () : boolean
|
|
219
|
+
get paused () : boolean
|
|
220
|
+
get reason () : Error | null
|
|
221
|
+
abort (reason: Error): void
|
|
222
|
+
pause(): void
|
|
223
|
+
resume(): void
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export interface DispatchHandler {
|
|
227
|
+
onRequestStart?(controller: DispatchController, context: any): void;
|
|
228
|
+
onRequestUpgrade?(controller: DispatchController, statusCode: number, headers: IncomingHttpHeaders, socket: Duplex): void;
|
|
229
|
+
onResponseStart?(controller: DispatchController, statusCode: number, statusMessage: string | null, headers: IncomingHttpHeaders): void;
|
|
230
|
+
onResponseData?(controller: DispatchController, chunk: Buffer): void;
|
|
231
|
+
onResponseEnd?(controller: DispatchController, trailers: IncomingHttpHeaders): void;
|
|
232
|
+
onResponseError?(controller: DispatchController, error: Error): void;
|
|
233
|
+
|
|
217
234
|
/** 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. */
|
|
235
|
+
/** @deprecated */
|
|
218
236
|
onConnect?(abort: (err?: Error) => void): void;
|
|
219
237
|
/** Invoked when an error has occurred. */
|
|
238
|
+
/** @deprecated */
|
|
220
239
|
onError?(err: Error): void;
|
|
221
240
|
/** Invoked when request is upgraded either due to a `Upgrade` header or `CONNECT` method. */
|
|
241
|
+
/** @deprecated */
|
|
222
242
|
onUpgrade?(statusCode: number, headers: Buffer[] | string[] | null, socket: Duplex): void;
|
|
223
243
|
/** Invoked when response is received, before headers have been read. **/
|
|
244
|
+
/** @deprecated */
|
|
224
245
|
onResponseStarted?(): void;
|
|
225
246
|
/** Invoked when statusCode and headers have been received. May be invoked multiple times due to 1xx informational headers. */
|
|
247
|
+
/** @deprecated */
|
|
226
248
|
onHeaders?(statusCode: number, headers: Buffer[], resume: () => void, statusText: string): boolean;
|
|
227
249
|
/** Invoked when response payload data is received. */
|
|
250
|
+
/** @deprecated */
|
|
228
251
|
onData?(chunk: Buffer): boolean;
|
|
229
252
|
/** Invoked when response payload and trailers have been received and the request has completed. */
|
|
253
|
+
/** @deprecated */
|
|
230
254
|
onComplete?(trailers: string[] | null): void;
|
|
231
255
|
/** Invoked when a body chunk is sent to the server. May be invoked multiple times for chunked requests */
|
|
256
|
+
/** @deprecated */
|
|
232
257
|
onBodySent?(chunkSize: number, totalBytesSent: number): void;
|
|
233
258
|
}
|
|
234
259
|
export type PipelineHandler<TOpaque = null> = (data: PipelineHandlerData<TOpaque>) => Readable
|
|
@@ -6,7 +6,7 @@ export default EnvHttpProxyAgent
|
|
|
6
6
|
declare class EnvHttpProxyAgent extends Dispatcher {
|
|
7
7
|
constructor (opts?: EnvHttpProxyAgent.Options)
|
|
8
8
|
|
|
9
|
-
dispatch (options: Agent.DispatchOptions, handler: Dispatcher.
|
|
9
|
+
dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
declare namespace EnvHttpProxyAgent {
|
package/types/handlers.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import Dispatcher from './dispatcher'
|
|
2
2
|
|
|
3
|
-
export declare class RedirectHandler implements Dispatcher.
|
|
3
|
+
export declare class RedirectHandler implements Dispatcher.DispatchHandler {
|
|
4
4
|
constructor (
|
|
5
5
|
dispatch: Dispatcher,
|
|
6
6
|
maxRedirections: number,
|
|
7
7
|
opts: Dispatcher.DispatchOptions,
|
|
8
|
-
handler: Dispatcher.
|
|
8
|
+
handler: Dispatcher.DispatchHandler,
|
|
9
9
|
redirectionLimitReached: boolean
|
|
10
10
|
)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export declare class DecoratorHandler implements Dispatcher.
|
|
14
|
-
constructor (handler: Dispatcher.
|
|
13
|
+
export declare class DecoratorHandler implements Dispatcher.DispatchHandler {
|
|
14
|
+
constructor (handler: Dispatcher.DispatchHandler)
|
|
15
15
|
}
|
package/types/mock-agent.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare class MockAgent<TMockAgentOptions extends MockAgent.Options = MockAgent.
|
|
|
17
17
|
get<TInterceptable extends Interceptable>(origin: RegExp): TInterceptable
|
|
18
18
|
get<TInterceptable extends Interceptable>(origin: ((origin: string) => boolean)): TInterceptable
|
|
19
19
|
/** Dispatches a mocked request. */
|
|
20
|
-
dispatch (options: Agent.DispatchOptions, handler: Dispatcher.
|
|
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
22
|
close (): Promise<void>
|
|
23
23
|
/** Disables mocking in MockAgent. */
|
package/types/mock-client.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ declare class MockClient extends Client implements Interceptable {
|
|
|
11
11
|
/** Intercepts any matching requests that use the same origin as this mock client. */
|
|
12
12
|
intercept (options: MockInterceptor.Options): MockInterceptor
|
|
13
13
|
/** Dispatches a mocked request. */
|
|
14
|
-
dispatch (options: Dispatcher.DispatchOptions, handlers: Dispatcher.
|
|
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
17
|
}
|
package/types/mock-pool.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ declare class MockPool extends Pool implements Interceptable {
|
|
|
11
11
|
/** Intercepts any matching requests that use the same origin as this mock pool. */
|
|
12
12
|
intercept (options: MockInterceptor.Options): MockInterceptor
|
|
13
13
|
/** Dispatches a mocked request. */
|
|
14
|
-
dispatch (options: Dispatcher.DispatchOptions, handlers: Dispatcher.
|
|
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
17
|
}
|
package/types/proxy-agent.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export default ProxyAgent
|
|
|
8
8
|
declare class ProxyAgent extends Dispatcher {
|
|
9
9
|
constructor (options: ProxyAgent.Options | string)
|
|
10
10
|
|
|
11
|
-
dispatch (options: Agent.DispatchOptions, handler: Dispatcher.
|
|
11
|
+
dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean
|
|
12
12
|
close (): Promise<void>
|
|
13
13
|
}
|
|
14
14
|
|
package/types/retry-handler.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Dispatcher from './dispatcher'
|
|
|
2
2
|
|
|
3
3
|
export default RetryHandler
|
|
4
4
|
|
|
5
|
-
declare class RetryHandler implements Dispatcher.
|
|
5
|
+
declare class RetryHandler implements Dispatcher.DispatchHandler {
|
|
6
6
|
constructor (
|
|
7
7
|
options: Dispatcher.DispatchOptions & {
|
|
8
8
|
retryOptions?: RetryHandler.RetryOptions;
|
|
@@ -32,7 +32,7 @@ declare namespace RetryHandler {
|
|
|
32
32
|
};
|
|
33
33
|
},
|
|
34
34
|
callback: OnRetryCallback
|
|
35
|
-
) =>
|
|
35
|
+
) => void
|
|
36
36
|
|
|
37
37
|
export interface RetryOptions {
|
|
38
38
|
/**
|
|
@@ -111,6 +111,6 @@ declare namespace RetryHandler {
|
|
|
111
111
|
|
|
112
112
|
export interface RetryHandlers {
|
|
113
113
|
dispatch: Dispatcher['dispatch'];
|
|
114
|
-
handler: Dispatcher.
|
|
114
|
+
handler: Dispatcher.DispatchHandler;
|
|
115
115
|
}
|
|
116
116
|
}
|