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.
@@ -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
- rawHeaders: Buffer[]
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
- rawHeaders: Buffer[]
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
- * @default Infinity
74
- */
78
+ * @default Infinity
79
+ */
75
80
  maxSize?: number
76
81
 
77
82
  /**
78
- * @default Infinity
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
  }
@@ -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.DispatchHandlers): boolean
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
- export interface DispatchHandlers {
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.DispatchHandlers): boolean
9
+ dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean
10
10
  }
11
11
 
12
12
  declare namespace EnvHttpProxyAgent {
@@ -1,15 +1,15 @@
1
1
  import Dispatcher from './dispatcher'
2
2
 
3
- export declare class RedirectHandler implements Dispatcher.DispatchHandlers {
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.DispatchHandlers,
8
+ handler: Dispatcher.DispatchHandler,
9
9
  redirectionLimitReached: boolean
10
10
  )
11
11
  }
12
12
 
13
- export declare class DecoratorHandler implements Dispatcher.DispatchHandlers {
14
- constructor (handler: Dispatcher.DispatchHandlers)
13
+ export declare class DecoratorHandler implements Dispatcher.DispatchHandler {
14
+ constructor (handler: Dispatcher.DispatchHandler)
15
15
  }
@@ -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.DispatchHandlers): boolean
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. */
@@ -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.DispatchHandlers): boolean
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
  }
@@ -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.DispatchHandlers): boolean
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
  }
@@ -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.DispatchHandlers): boolean
11
+ dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean
12
12
  close (): Promise<void>
13
13
  }
14
14
 
@@ -2,7 +2,7 @@ import Dispatcher from './dispatcher'
2
2
 
3
3
  export default RetryHandler
4
4
 
5
- declare class RetryHandler implements Dispatcher.DispatchHandlers {
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
- ) => number | null
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.DispatchHandlers;
114
+ handler: Dispatcher.DispatchHandler;
115
115
  }
116
116
  }