undici-types 5.24.0-test.2 → 5.24.0-test.5

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/types/fetch.d.ts DELETED
@@ -1,209 +0,0 @@
1
- // based on https://github.com/Ethan-Arrowood/undici-fetch/blob/249269714db874351589d2d364a0645d5160ae71/index.d.ts (MIT license)
2
- // and https://github.com/node-fetch/node-fetch/blob/914ce6be5ec67a8bab63d68510aabf07cb818b6d/index.d.ts (MIT license)
3
- /// <reference types="node" />
4
-
5
- import { Blob } from 'buffer'
6
- import { URL, URLSearchParams } from 'url'
7
- import { ReadableStream } from 'stream/web'
8
- import { FormData } from './formdata'
9
-
10
- import Dispatcher from './dispatcher'
11
-
12
- export type RequestInfo = string | URL | Request
13
-
14
- export declare function fetch (
15
- input: RequestInfo,
16
- init?: RequestInit
17
- ): Promise<Response>
18
-
19
- export type BodyInit =
20
- | ArrayBuffer
21
- | AsyncIterable<Uint8Array>
22
- | Blob
23
- | FormData
24
- | Iterable<Uint8Array>
25
- | NodeJS.ArrayBufferView
26
- | URLSearchParams
27
- | null
28
- | string
29
-
30
- export interface BodyMixin {
31
- readonly body: ReadableStream | null
32
- readonly bodyUsed: boolean
33
-
34
- readonly arrayBuffer: () => Promise<ArrayBuffer>
35
- readonly blob: () => Promise<Blob>
36
- readonly formData: () => Promise<FormData>
37
- readonly json: () => Promise<unknown>
38
- readonly text: () => Promise<string>
39
- }
40
-
41
- export interface SpecIterator<T, TReturn = any, TNext = undefined> {
42
- next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
43
- }
44
-
45
- export interface SpecIterableIterator<T> extends SpecIterator<T> {
46
- [Symbol.iterator](): SpecIterableIterator<T>;
47
- }
48
-
49
- export interface SpecIterable<T> {
50
- [Symbol.iterator](): SpecIterator<T>;
51
- }
52
-
53
- export type HeadersInit = string[][] | Record<string, string | ReadonlyArray<string>> | Headers
54
-
55
- export declare class Headers implements SpecIterable<[string, string]> {
56
- constructor (init?: HeadersInit)
57
- readonly append: (name: string, value: string) => void
58
- readonly delete: (name: string) => void
59
- readonly get: (name: string) => string | null
60
- readonly has: (name: string) => boolean
61
- readonly set: (name: string, value: string) => void
62
- readonly getSetCookie: () => string[]
63
- readonly forEach: (
64
- callbackfn: (value: string, key: string, iterable: Headers) => void,
65
- thisArg?: unknown
66
- ) => void
67
-
68
- readonly keys: () => SpecIterableIterator<string>
69
- readonly values: () => SpecIterableIterator<string>
70
- readonly entries: () => SpecIterableIterator<[string, string]>
71
- readonly [Symbol.iterator]: () => SpecIterator<[string, string]>
72
- }
73
-
74
- export type RequestCache =
75
- | 'default'
76
- | 'force-cache'
77
- | 'no-cache'
78
- | 'no-store'
79
- | 'only-if-cached'
80
- | 'reload'
81
-
82
- export type RequestCredentials = 'omit' | 'include' | 'same-origin'
83
-
84
- type RequestDestination =
85
- | ''
86
- | 'audio'
87
- | 'audioworklet'
88
- | 'document'
89
- | 'embed'
90
- | 'font'
91
- | 'image'
92
- | 'manifest'
93
- | 'object'
94
- | 'paintworklet'
95
- | 'report'
96
- | 'script'
97
- | 'sharedworker'
98
- | 'style'
99
- | 'track'
100
- | 'video'
101
- | 'worker'
102
- | 'xslt'
103
-
104
- export interface RequestInit {
105
- method?: string
106
- keepalive?: boolean
107
- headers?: HeadersInit
108
- body?: BodyInit
109
- redirect?: RequestRedirect
110
- integrity?: string
111
- signal?: AbortSignal
112
- credentials?: RequestCredentials
113
- mode?: RequestMode
114
- referrer?: string
115
- referrerPolicy?: ReferrerPolicy
116
- window?: null
117
- dispatcher?: Dispatcher
118
- duplex?: RequestDuplex
119
- }
120
-
121
- export type ReferrerPolicy =
122
- | ''
123
- | 'no-referrer'
124
- | 'no-referrer-when-downgrade'
125
- | 'origin'
126
- | 'origin-when-cross-origin'
127
- | 'same-origin'
128
- | 'strict-origin'
129
- | 'strict-origin-when-cross-origin'
130
- | 'unsafe-url';
131
-
132
- export type RequestMode = 'cors' | 'navigate' | 'no-cors' | 'same-origin'
133
-
134
- export type RequestRedirect = 'error' | 'follow' | 'manual'
135
-
136
- export type RequestDuplex = 'half'
137
-
138
- export declare class Request implements BodyMixin {
139
- constructor (input: RequestInfo, init?: RequestInit)
140
-
141
- readonly cache: RequestCache
142
- readonly credentials: RequestCredentials
143
- readonly destination: RequestDestination
144
- readonly headers: Headers
145
- readonly integrity: string
146
- readonly method: string
147
- readonly mode: RequestMode
148
- readonly redirect: RequestRedirect
149
- readonly referrerPolicy: string
150
- readonly url: string
151
-
152
- readonly keepalive: boolean
153
- readonly signal: AbortSignal
154
- readonly duplex: RequestDuplex
155
-
156
- readonly body: ReadableStream | null
157
- readonly bodyUsed: boolean
158
-
159
- readonly arrayBuffer: () => Promise<ArrayBuffer>
160
- readonly blob: () => Promise<Blob>
161
- readonly formData: () => Promise<FormData>
162
- readonly json: () => Promise<unknown>
163
- readonly text: () => Promise<string>
164
-
165
- readonly clone: () => Request
166
- }
167
-
168
- export interface ResponseInit {
169
- readonly status?: number
170
- readonly statusText?: string
171
- readonly headers?: HeadersInit
172
- }
173
-
174
- export type ResponseType =
175
- | 'basic'
176
- | 'cors'
177
- | 'default'
178
- | 'error'
179
- | 'opaque'
180
- | 'opaqueredirect'
181
-
182
- export type ResponseRedirectStatus = 301 | 302 | 303 | 307 | 308
183
-
184
- export declare class Response implements BodyMixin {
185
- constructor (body?: BodyInit, init?: ResponseInit)
186
-
187
- readonly headers: Headers
188
- readonly ok: boolean
189
- readonly status: number
190
- readonly statusText: string
191
- readonly type: ResponseType
192
- readonly url: string
193
- readonly redirected: boolean
194
-
195
- readonly body: ReadableStream | null
196
- readonly bodyUsed: boolean
197
-
198
- readonly arrayBuffer: () => Promise<ArrayBuffer>
199
- readonly blob: () => Promise<Blob>
200
- readonly formData: () => Promise<FormData>
201
- readonly json: () => Promise<unknown>
202
- readonly text: () => Promise<string>
203
-
204
- readonly clone: () => Response
205
-
206
- static error (): Response
207
- static json(data: any, init?: ResponseInit): Response
208
- static redirect (url: string | URL, status: ResponseRedirectStatus): Response
209
- }
package/types/file.d.ts DELETED
@@ -1,39 +0,0 @@
1
- // Based on https://github.com/octet-stream/form-data/blob/2d0f0dc371517444ce1f22cdde13f51995d0953a/lib/File.ts (MIT)
2
- /// <reference types="node" />
3
-
4
- import { Blob } from 'buffer'
5
-
6
- export interface BlobPropertyBag {
7
- type?: string
8
- endings?: 'native' | 'transparent'
9
- }
10
-
11
- export interface FilePropertyBag extends BlobPropertyBag {
12
- /**
13
- * The last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.
14
- */
15
- lastModified?: number
16
- }
17
-
18
- export declare class File extends Blob {
19
- /**
20
- * Creates a new File instance.
21
- *
22
- * @param fileBits An `Array` strings, or [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), [`ArrayBufferView`](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView), [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) objects, or a mix of any of such objects, that will be put inside the [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File).
23
- * @param fileName The name of the file.
24
- * @param options An options object containing optional attributes for the file.
25
- */
26
- constructor(fileBits: ReadonlyArray<string | NodeJS.ArrayBufferView | Blob>, fileName: string, options?: FilePropertyBag)
27
-
28
- /**
29
- * Name of the file referenced by the File object.
30
- */
31
- readonly name: string
32
-
33
- /**
34
- * The last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.
35
- */
36
- readonly lastModified: number
37
-
38
- readonly [Symbol.toStringTag]: string
39
- }
@@ -1,54 +0,0 @@
1
- /// <reference types="node" />
2
-
3
- import { Blob } from 'buffer'
4
- import { DOMException, Event, EventInit, EventTarget } from './patch'
5
-
6
- export declare class FileReader {
7
- __proto__: EventTarget & FileReader
8
-
9
- constructor ()
10
-
11
- readAsArrayBuffer (blob: Blob): void
12
- readAsBinaryString (blob: Blob): void
13
- readAsText (blob: Blob, encoding?: string): void
14
- readAsDataURL (blob: Blob): void
15
-
16
- abort (): void
17
-
18
- static readonly EMPTY = 0
19
- static readonly LOADING = 1
20
- static readonly DONE = 2
21
-
22
- readonly EMPTY = 0
23
- readonly LOADING = 1
24
- readonly DONE = 2
25
-
26
- readonly readyState: number
27
-
28
- readonly result: string | ArrayBuffer | null
29
-
30
- readonly error: DOMException | null
31
-
32
- onloadstart: null | ((this: FileReader, event: ProgressEvent) => void)
33
- onprogress: null | ((this: FileReader, event: ProgressEvent) => void)
34
- onload: null | ((this: FileReader, event: ProgressEvent) => void)
35
- onabort: null | ((this: FileReader, event: ProgressEvent) => void)
36
- onerror: null | ((this: FileReader, event: ProgressEvent) => void)
37
- onloadend: null | ((this: FileReader, event: ProgressEvent) => void)
38
- }
39
-
40
- export interface ProgressEventInit extends EventInit {
41
- lengthComputable?: boolean
42
- loaded?: number
43
- total?: number
44
- }
45
-
46
- export declare class ProgressEvent {
47
- __proto__: Event & ProgressEvent
48
-
49
- constructor (type: string, eventInitDict?: ProgressEventInit)
50
-
51
- readonly lengthComputable: boolean
52
- readonly loaded: number
53
- readonly total: number
54
- }
@@ -1,108 +0,0 @@
1
- // Based on https://github.com/octet-stream/form-data/blob/2d0f0dc371517444ce1f22cdde13f51995d0953a/lib/FormData.ts (MIT)
2
- /// <reference types="node" />
3
-
4
- import { File } from './file'
5
- import { SpecIterator, SpecIterableIterator } from './fetch'
6
-
7
- /**
8
- * A `string` or `File` that represents a single value from a set of `FormData` key-value pairs.
9
- */
10
- declare type FormDataEntryValue = string | File
11
-
12
- /**
13
- * Provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using fetch().
14
- */
15
- export declare class FormData {
16
- /**
17
- * Appends a new value onto an existing key inside a FormData object,
18
- * or adds the key if it does not already exist.
19
- *
20
- * The difference between `set()` and `append()` is that if the specified key already exists, `set()` will overwrite all existing values with the new one, whereas `append()` will append the new value onto the end of the existing set of values.
21
- *
22
- * @param name The name of the field whose data is contained in `value`.
23
- * @param value The field's value. This can be [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
24
- or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). If none of these are specified the value is converted to a string.
25
- * @param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
26
- */
27
- append(name: string, value: unknown, fileName?: string): void
28
-
29
- /**
30
- * Set a new value for an existing key inside FormData,
31
- * or add the new field if it does not already exist.
32
- *
33
- * @param name The name of the field whose data is contained in `value`.
34
- * @param value The field's value. This can be [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
35
- or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). If none of these are specified the value is converted to a string.
36
- * @param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
37
- *
38
- */
39
- set(name: string, value: unknown, fileName?: string): void
40
-
41
- /**
42
- * Returns the first value associated with a given key from within a `FormData` object.
43
- * If you expect multiple values and want all of them, use the `getAll()` method instead.
44
- *
45
- * @param {string} name A name of the value you want to retrieve.
46
- *
47
- * @returns A `FormDataEntryValue` containing the value. If the key doesn't exist, the method returns null.
48
- */
49
- get(name: string): FormDataEntryValue | null
50
-
51
- /**
52
- * Returns all the values associated with a given key from within a `FormData` object.
53
- *
54
- * @param {string} name A name of the value you want to retrieve.
55
- *
56
- * @returns An array of `FormDataEntryValue` whose key matches the value passed in the `name` parameter. If the key doesn't exist, the method returns an empty list.
57
- */
58
- getAll(name: string): FormDataEntryValue[]
59
-
60
- /**
61
- * Returns a boolean stating whether a `FormData` object contains a certain key.
62
- *
63
- * @param name A string representing the name of the key you want to test for.
64
- *
65
- * @return A boolean value.
66
- */
67
- has(name: string): boolean
68
-
69
- /**
70
- * Deletes a key and its value(s) from a `FormData` object.
71
- *
72
- * @param name The name of the key you want to delete.
73
- */
74
- delete(name: string): void
75
-
76
- /**
77
- * Executes given callback function for each field of the FormData instance
78
- */
79
- forEach: (
80
- callbackfn: (value: FormDataEntryValue, key: string, iterable: FormData) => void,
81
- thisArg?: unknown
82
- ) => void
83
-
84
- /**
85
- * Returns an [`iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) allowing to go through all keys contained in this `FormData` object.
86
- * Each key is a `string`.
87
- */
88
- keys: () => SpecIterableIterator<string>
89
-
90
- /**
91
- * Returns an [`iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) allowing to go through all values contained in this object `FormData` object.
92
- * Each value is a [`FormDataValue`](https://developer.mozilla.org/en-US/docs/Web/API/FormDataEntryValue).
93
- */
94
- values: () => SpecIterableIterator<FormDataEntryValue>
95
-
96
- /**
97
- * Returns an [`iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) allowing to go through the `FormData` key/value pairs.
98
- * The key of each pair is a string; the value is a [`FormDataValue`](https://developer.mozilla.org/en-US/docs/Web/API/FormDataEntryValue).
99
- */
100
- entries: () => SpecIterableIterator<[string, FormDataEntryValue]>
101
-
102
- /**
103
- * An alias for FormData#entries()
104
- */
105
- [Symbol.iterator]: () => SpecIterableIterator<[string, FormDataEntryValue]>
106
-
107
- readonly [Symbol.toStringTag]: string
108
- }
@@ -1,9 +0,0 @@
1
- import Dispatcher from "./dispatcher";
2
-
3
- export {
4
- getGlobalDispatcher,
5
- setGlobalDispatcher
6
- }
7
-
8
- declare function setGlobalDispatcher<DispatcherImplementation extends Dispatcher>(dispatcher: DispatcherImplementation): void;
9
- declare function getGlobalDispatcher(): Dispatcher;
@@ -1,7 +0,0 @@
1
- export {
2
- setGlobalOrigin,
3
- getGlobalOrigin
4
- }
5
-
6
- declare function setGlobalOrigin(origin: string | URL | undefined): void;
7
- declare function getGlobalOrigin(): URL | undefined;
@@ -1,9 +0,0 @@
1
- import Dispatcher from "./dispatcher";
2
-
3
- export declare class RedirectHandler implements Dispatcher.DispatchHandlers{
4
- constructor (dispatch: Dispatcher, maxRedirections: number, opts: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandlers)
5
- }
6
-
7
- export declare class DecoratorHandler implements Dispatcher.DispatchHandlers{
8
- constructor (handler: Dispatcher.DispatchHandlers)
9
- }
package/types/header.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * The header type declaration of `undici`.
3
- */
4
- export type IncomingHttpHeaders = Record<string, string | string[] | undefined>;
@@ -1,5 +0,0 @@
1
- import Dispatcher from "./dispatcher";
2
-
3
- type RedirectInterceptorOpts = { maxRedirections?: number }
4
-
5
- export declare function createRedirectInterceptor (opts: RedirectInterceptorOpts): Dispatcher.DispatchInterceptor
@@ -1,50 +0,0 @@
1
- import Agent from './agent'
2
- import Dispatcher from './dispatcher'
3
- import { Interceptable, MockInterceptor } from './mock-interceptor'
4
- import MockDispatch = MockInterceptor.MockDispatch;
5
-
6
- export default MockAgent
7
-
8
- interface PendingInterceptor extends MockDispatch {
9
- origin: string;
10
- }
11
-
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
- declare class MockAgent<TMockAgentOptions extends MockAgent.Options = MockAgent.Options> extends Dispatcher {
14
- constructor(options?: MockAgent.Options)
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;
19
- /** Dispatches a mocked request. */
20
- dispatch(options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean;
21
- /** Closes the mock agent and waits for registered mock pools and clients to also close before resolving. */
22
- close(): Promise<void>;
23
- /** Disables mocking in MockAgent. */
24
- deactivate(): void;
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;
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;
32
- /** Causes all requests to throw when requests are not matched in a MockAgent intercept. */
33
- disableNetConnect(): void;
34
- pendingInterceptors(): PendingInterceptor[];
35
- assertNoPendingInterceptors(options?: {
36
- pendingInterceptorsFormatter?: PendingInterceptorsFormatter;
37
- }): void;
38
- }
39
-
40
- interface PendingInterceptorsFormatter {
41
- format(pendingInterceptors: readonly PendingInterceptor[]): string;
42
- }
43
-
44
- declare namespace MockAgent {
45
- /** MockAgent options. */
46
- export interface Options extends Agent.Options {
47
- /** A custom agent to be encapsulated by the MockAgent. */
48
- agent?: Agent;
49
- }
50
- }
@@ -1,25 +0,0 @@
1
- import Client from './client'
2
- import Dispatcher from './dispatcher'
3
- import MockAgent from './mock-agent'
4
- import { MockInterceptor, Interceptable } from './mock-interceptor'
5
-
6
- export default MockClient
7
-
8
- /** MockClient extends the Client API and allows one to mock requests. */
9
- declare class MockClient extends Client implements Interceptable {
10
- constructor(origin: string, options: MockClient.Options);
11
- /** Intercepts any matching requests that use the same origin as this mock client. */
12
- intercept(options: MockInterceptor.Options): MockInterceptor;
13
- /** Dispatches a mocked request. */
14
- dispatch(options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandlers): boolean;
15
- /** Closes the mock client and gracefully waits for enqueued requests to complete. */
16
- close(): Promise<void>;
17
- }
18
-
19
- declare namespace MockClient {
20
- /** MockClient options. */
21
- export interface Options extends Client.Options {
22
- /** The agent to associate this MockClient with. */
23
- agent: MockAgent;
24
- }
25
- }
@@ -1,12 +0,0 @@
1
- import Errors from './errors'
2
-
3
- export default MockErrors
4
-
5
- declare namespace MockErrors {
6
- /** The request does not match any registered mock dispatches. */
7
- export class MockNotMatchedError extends Errors.UndiciError {
8
- constructor(message?: string);
9
- name: 'MockNotMatchedError';
10
- code: 'UND_MOCK_ERR_MOCK_NOT_MATCHED';
11
- }
12
- }
@@ -1,93 +0,0 @@
1
- import { IncomingHttpHeaders } from './header'
2
- import Dispatcher from './dispatcher';
3
- import { BodyInit, Headers } from './fetch'
4
-
5
- export {
6
- Interceptable,
7
- MockInterceptor,
8
- MockScope
9
- }
10
-
11
- /** The scope associated with a mock dispatch. */
12
- declare class MockScope<TData extends object = object> {
13
- constructor(mockDispatch: MockInterceptor.MockDispatch<TData>);
14
- /** Delay a reply by a set amount of time in ms. */
15
- delay(waitInMs: number): MockScope<TData>;
16
- /** Persist the defined mock data for the associated reply. It will return the defined mock data indefinitely. */
17
- persist(): MockScope<TData>;
18
- /** Define a reply for a set amount of matching requests. */
19
- times(repeatTimes: number): MockScope<TData>;
20
- }
21
-
22
- /** The interceptor for a Mock. */
23
- declare class MockInterceptor {
24
- constructor(options: MockInterceptor.Options, mockDispatches: MockInterceptor.MockDispatch[]);
25
- /** Mock an undici request with the defined reply. */
26
- reply<TData extends object = object>(replyOptionsCallback: MockInterceptor.MockReplyOptionsCallback<TData>): MockScope<TData>;
27
- reply<TData extends object = object>(
28
- statusCode: number,
29
- data?: TData | Buffer | string | MockInterceptor.MockResponseDataHandler<TData>,
30
- responseOptions?: MockInterceptor.MockResponseOptions
31
- ): MockScope<TData>;
32
- /** Mock an undici request by throwing the defined reply error. */
33
- replyWithError<TError extends Error = Error>(error: TError): MockScope;
34
- /** Set default reply headers on the interceptor for subsequent mocked replies. */
35
- defaultReplyHeaders(headers: IncomingHttpHeaders): MockInterceptor;
36
- /** Set default reply trailers on the interceptor for subsequent mocked replies. */
37
- defaultReplyTrailers(trailers: Record<string, string>): MockInterceptor;
38
- /** Set automatically calculated content-length header on subsequent mocked replies. */
39
- replyContentLength(): MockInterceptor;
40
- }
41
-
42
- declare namespace MockInterceptor {
43
- /** MockInterceptor options. */
44
- export interface Options {
45
- /** Path to intercept on. */
46
- path: string | RegExp | ((path: string) => boolean);
47
- /** Method to intercept on. Defaults to GET. */
48
- method?: string | RegExp | ((method: string) => boolean);
49
- /** Body to intercept on. */
50
- body?: string | RegExp | ((body: string) => boolean);
51
- /** Headers to intercept on. */
52
- headers?: Record<string, string | RegExp | ((body: string) => boolean)> | ((headers: Record<string, string>) => boolean);
53
- /** Query params to intercept on */
54
- query?: Record<string, any>;
55
- }
56
- export interface MockDispatch<TData extends object = object, TError extends Error = Error> extends Options {
57
- times: number | null;
58
- persist: boolean;
59
- consumed: boolean;
60
- data: MockDispatchData<TData, TError>;
61
- }
62
- export interface MockDispatchData<TData extends object = object, TError extends Error = Error> extends MockResponseOptions {
63
- error: TError | null;
64
- statusCode?: number;
65
- data?: TData | string;
66
- }
67
- export interface MockResponseOptions {
68
- headers?: IncomingHttpHeaders;
69
- trailers?: Record<string, string>;
70
- }
71
-
72
- export interface MockResponseCallbackOptions {
73
- path: string;
74
- origin: string;
75
- method: string;
76
- body?: BodyInit | Dispatcher.DispatchOptions['body'];
77
- headers: Headers | Record<string, string>;
78
- maxRedirections: number;
79
- }
80
-
81
- export type MockResponseDataHandler<TData extends object = object> = (
82
- opts: MockResponseCallbackOptions
83
- ) => TData | Buffer | string;
84
-
85
- export type MockReplyOptionsCallback<TData extends object = object> = (
86
- opts: MockResponseCallbackOptions
87
- ) => { statusCode: number, data?: TData | Buffer | string, responseOptions?: MockResponseOptions }
88
- }
89
-
90
- interface Interceptable extends Dispatcher {
91
- /** Intercepts any matching requests that use the same origin as this mock client. */
92
- intercept(options: MockInterceptor.Options): MockInterceptor;
93
- }
@@ -1,25 +0,0 @@
1
- import Pool from './pool'
2
- import MockAgent from './mock-agent'
3
- import { Interceptable, MockInterceptor } from './mock-interceptor'
4
- import Dispatcher from './dispatcher'
5
-
6
- export default MockPool
7
-
8
- /** MockPool extends the Pool API and allows one to mock requests. */
9
- declare class MockPool extends Pool implements Interceptable {
10
- constructor(origin: string, options: MockPool.Options);
11
- /** Intercepts any matching requests that use the same origin as this mock pool. */
12
- intercept(options: MockInterceptor.Options): MockInterceptor;
13
- /** Dispatches a mocked request. */
14
- dispatch(options: Dispatcher.DispatchOptions, handlers: Dispatcher.DispatchHandlers): boolean;
15
- /** Closes the mock pool and gracefully waits for enqueued requests to complete. */
16
- close(): Promise<void>;
17
- }
18
-
19
- declare namespace MockPool {
20
- /** MockPool options. */
21
- export interface Options extends Pool.Options {
22
- /** The agent to associate this MockPool with. */
23
- agent: MockAgent;
24
- }
25
- }