undici-types 6.20.0 → 7.0.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/pool-stats.d.ts CHANGED
@@ -1,19 +1,19 @@
1
- import Pool from "./pool"
1
+ import Pool from './pool'
2
2
 
3
3
  export default PoolStats
4
4
 
5
5
  declare class PoolStats {
6
- constructor(pool: Pool);
6
+ constructor (pool: Pool)
7
7
  /** Number of open socket connections in this pool. */
8
- connected: number;
8
+ connected: number
9
9
  /** Number of open socket connections in this pool that do not have an active request. */
10
- free: number;
10
+ free: number
11
11
  /** Number of pending requests across all clients in this pool. */
12
- pending: number;
12
+ pending: number
13
13
  /** Number of queued requests across all clients in this pool. */
14
- queued: number;
14
+ queued: number
15
15
  /** Number of currently active requests across all clients in this pool. */
16
- running: number;
16
+ running: number
17
17
  /** Number of active, pending, or queued requests across all clients in this pool. */
18
- size: number;
18
+ size: number
19
19
  }
package/pool.d.ts CHANGED
@@ -1,39 +1,39 @@
1
1
  import Client from './client'
2
2
  import TPoolStats from './pool-stats'
3
3
  import { URL } from 'url'
4
- import Dispatcher from "./dispatcher";
4
+ import Dispatcher from './dispatcher'
5
5
 
6
6
  export default Pool
7
7
 
8
- type PoolConnectOptions = Omit<Dispatcher.ConnectOptions, "origin">;
8
+ type PoolConnectOptions = Omit<Dispatcher.ConnectOptions, 'origin'>
9
9
 
10
10
  declare class Pool extends Dispatcher {
11
- constructor(url: string | URL, options?: Pool.Options)
11
+ constructor (url: string | URL, options?: Pool.Options)
12
12
  /** `true` after `pool.close()` has been called. */
13
- closed: boolean;
13
+ closed: boolean
14
14
  /** `true` after `pool.destroyed()` has been called or `pool.close()` has been called and the pool shutdown has completed. */
15
- destroyed: boolean;
15
+ destroyed: boolean
16
16
  /** Aggregate stats for a Pool. */
17
- readonly stats: TPoolStats;
17
+ readonly stats: TPoolStats
18
18
 
19
19
  // Override dispatcher APIs.
20
- override connect(
20
+ override connect (
21
21
  options: PoolConnectOptions
22
- ): Promise<Dispatcher.ConnectData>;
23
- override connect(
22
+ ): Promise<Dispatcher.ConnectData>
23
+ override connect (
24
24
  options: PoolConnectOptions,
25
25
  callback: (err: Error | null, data: Dispatcher.ConnectData) => void
26
- ): void;
26
+ ): void
27
27
  }
28
28
 
29
29
  declare namespace Pool {
30
- export type PoolStats = TPoolStats;
30
+ export type PoolStats = TPoolStats
31
31
  export interface Options extends Client.Options {
32
32
  /** Default: `(origin, opts) => new Client(origin, opts)`. */
33
33
  factory?(origin: URL, opts: object): Dispatcher;
34
34
  /** The max number of clients to create. `null` if no limit. Default `null`. */
35
35
  connections?: number | null;
36
36
 
37
- interceptors?: { Pool?: readonly Dispatcher.DispatchInterceptor[] } & Client.Options["interceptors"]
37
+ interceptors?: { Pool?: readonly Dispatcher.DispatchInterceptor[] } & Client.Options['interceptors']
38
38
  }
39
39
  }
package/proxy-agent.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import Agent from './agent'
2
- import buildConnector from './connector';
2
+ import buildConnector from './connector'
3
3
  import Dispatcher from './dispatcher'
4
4
  import { IncomingHttpHeaders } from './header'
5
5
 
6
6
  export default ProxyAgent
7
7
 
8
8
  declare class ProxyAgent extends Dispatcher {
9
- constructor(options: ProxyAgent.Options | string)
9
+ constructor (options: ProxyAgent.Options | string)
10
10
 
11
- dispatch(options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean;
12
- close(): Promise<void>;
11
+ dispatch (options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean
12
+ close (): Promise<void>
13
13
  }
14
14
 
15
15
  declare namespace ProxyAgent {
package/readable.d.ts CHANGED
@@ -1,40 +1,47 @@
1
- import { Readable } from "stream";
1
+ import { Readable } from 'stream'
2
2
  import { Blob } from 'buffer'
3
3
 
4
4
  export default BodyReadable
5
5
 
6
6
  declare class BodyReadable extends Readable {
7
- constructor(
8
- resume?: (this: Readable, size: number) => void | null,
9
- abort?: () => void | null,
10
- contentType?: string
11
- )
7
+ constructor (opts: {
8
+ resume: (this: Readable, size: number) => void | null;
9
+ abort: () => void | null;
10
+ contentType?: string;
11
+ contentLength?: number;
12
+ highWaterMark?: number;
13
+ })
12
14
 
13
15
  /** Consumes and returns the body as a string
14
16
  * https://fetch.spec.whatwg.org/#dom-body-text
15
17
  */
16
- text(): Promise<string>
18
+ text (): Promise<string>
17
19
 
18
20
  /** Consumes and returns the body as a JavaScript Object
19
21
  * https://fetch.spec.whatwg.org/#dom-body-json
20
22
  */
21
- json(): Promise<unknown>
23
+ json (): Promise<unknown>
22
24
 
23
25
  /** Consumes and returns the body as a Blob
24
26
  * https://fetch.spec.whatwg.org/#dom-body-blob
25
27
  */
26
- blob(): Promise<Blob>
28
+ blob (): Promise<Blob>
29
+
30
+ /** Consumes and returns the body as an Uint8Array
31
+ * https://fetch.spec.whatwg.org/#dom-body-bytes
32
+ */
33
+ bytes (): Promise<Uint8Array>
27
34
 
28
35
  /** Consumes and returns the body as an ArrayBuffer
29
36
  * https://fetch.spec.whatwg.org/#dom-body-arraybuffer
30
37
  */
31
- arrayBuffer(): Promise<ArrayBuffer>
38
+ arrayBuffer (): Promise<ArrayBuffer>
32
39
 
33
40
  /** Not implemented
34
41
  *
35
42
  * https://fetch.spec.whatwg.org/#dom-body-formdata
36
43
  */
37
- formData(): Promise<never>
44
+ formData (): Promise<never>
38
45
 
39
46
  /** Returns true if the body is not null and the body has been consumed
40
47
  *
@@ -44,7 +51,7 @@ declare class BodyReadable extends Readable {
44
51
  */
45
52
  readonly bodyUsed: boolean
46
53
 
47
- /**
54
+ /**
48
55
  * If body is null, it should return null as the body
49
56
  *
50
57
  * If body is not null, should return the body as a ReadableStream
@@ -54,7 +61,8 @@ declare class BodyReadable extends Readable {
54
61
  readonly body: never | undefined
55
62
 
56
63
  /** Dumps the response body by reading `limit` number of bytes.
57
- * @param opts.limit Number of bytes to read (optional) - Default: 262144
64
+ * @param opts.limit Number of bytes to read (optional) - Default: 131072
65
+ * @param opts.signal AbortSignal to cancel the operation (optional)
58
66
  */
59
- dump(opts?: { limit: number }): Promise<void>
67
+ dump (opts?: { limit: number; signal?: AbortSignal }): Promise<void>
60
68
  }
package/retry-agent.d.ts CHANGED
@@ -4,5 +4,5 @@ import RetryHandler from './retry-handler'
4
4
  export default RetryAgent
5
5
 
6
6
  declare class RetryAgent extends Dispatcher {
7
- constructor(dispatcher: Dispatcher, options?: RetryHandler.RetryOptions)
7
+ constructor (dispatcher: Dispatcher, options?: RetryHandler.RetryOptions)
8
8
  }
@@ -1,18 +1,18 @@
1
- import Dispatcher from "./dispatcher";
1
+ import Dispatcher from './dispatcher'
2
2
 
3
- export default RetryHandler;
3
+ export default RetryHandler
4
4
 
5
- declare class RetryHandler implements Dispatcher.DispatchHandlers {
6
- constructor(
5
+ declare class RetryHandler implements Dispatcher.DispatchHandler {
6
+ constructor (
7
7
  options: Dispatcher.DispatchOptions & {
8
8
  retryOptions?: RetryHandler.RetryOptions;
9
9
  },
10
10
  retryHandlers: RetryHandler.RetryHandlers
11
- );
11
+ )
12
12
  }
13
13
 
14
14
  declare namespace RetryHandler {
15
- export type RetryState = { counter: number; };
15
+ export type RetryState = { counter: number; }
16
16
 
17
17
  export type RetryContext = {
18
18
  state: RetryState;
@@ -21,7 +21,7 @@ declare namespace RetryHandler {
21
21
  };
22
22
  }
23
23
 
24
- export type OnRetryCallback = (result?: Error | null) => void;
24
+ export type OnRetryCallback = (result?: Error | null) => void
25
25
 
26
26
  export type RetryCallback = (
27
27
  err: Error,
@@ -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
  /**
@@ -110,7 +110,7 @@ declare namespace RetryHandler {
110
110
  }
111
111
 
112
112
  export interface RetryHandlers {
113
- dispatch: Dispatcher["dispatch"];
114
- handler: Dispatcher.DispatchHandlers;
113
+ dispatch: Dispatcher['dispatch'];
114
+ handler: Dispatcher.DispatchHandler;
115
115
  }
116
116
  }
package/util.d.ts CHANGED
@@ -3,7 +3,7 @@ export namespace util {
3
3
  * Retrieves a header name and returns its lowercase value.
4
4
  * @param value Header name
5
5
  */
6
- export function headerNameToString(value: string | Buffer): string;
6
+ export function headerNameToString (value: string | Buffer): string
7
7
 
8
8
  /**
9
9
  * Receives a header object and returns the parsed value.
@@ -11,8 +11,8 @@ export namespace util {
11
11
  * @param obj Object to specify a proxy object. Used to assign parsed values.
12
12
  * @returns If `obj` is specified, it is equivalent to `obj`.
13
13
  */
14
- export function parseHeaders(
14
+ export function parseHeaders (
15
15
  headers: (Buffer | string | (Buffer | string)[])[],
16
16
  obj?: Record<string, string | string[]>
17
- ): Record<string, string | string[]>;
17
+ ): Record<string, string | string[]>
18
18
  }
package/utility.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ type AutocompletePrimitiveBaseType<T> =
2
+ T extends string ? string :
3
+ T extends number ? number :
4
+ T extends boolean ? boolean :
5
+ never
6
+
7
+ export type Autocomplete<T> = T | (AutocompletePrimitiveBaseType<T> & Record<never, never>)
package/webidl.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  // These types are not exported, and are only used internally
2
+ import * as undici from './index'
2
3
 
3
4
  /**
4
5
  * Take in an unknown value and return one that is of type T
@@ -34,11 +35,24 @@ interface WebidlErrors {
34
35
  }): TypeError
35
36
  }
36
37
 
38
+ interface WebIDLTypes {
39
+ UNDEFINED: 1,
40
+ BOOLEAN: 2,
41
+ STRING: 3,
42
+ SYMBOL: 4,
43
+ NUMBER: 5,
44
+ BIGINT: 6,
45
+ NULL: 7
46
+ OBJECT: 8
47
+ }
48
+
37
49
  interface WebidlUtil {
38
50
  /**
39
51
  * @see https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values
40
52
  */
41
- Type (object: unknown):
53
+ Type (object: unknown): WebIDLTypes[keyof WebIDLTypes]
54
+
55
+ TypeValueToString (o: unknown):
42
56
  | 'Undefined'
43
57
  | 'Boolean'
44
58
  | 'String'
@@ -48,6 +62,8 @@ interface WebidlUtil {
48
62
  | 'Null'
49
63
  | 'Object'
50
64
 
65
+ Types: WebIDLTypes
66
+
51
67
  /**
52
68
  * @see https://webidl.spec.whatwg.org/#abstract-opdef-converttoint
53
69
  */
@@ -67,6 +83,14 @@ interface WebidlUtil {
67
83
  * Stringifies {@param V}
68
84
  */
69
85
  Stringify (V: any): string
86
+
87
+ MakeTypeAssertion <I>(I: I): (arg: any) => arg is I
88
+
89
+ /**
90
+ * Mark a value as uncloneable for Node.js.
91
+ * This is only effective in some newer Node.js versions.
92
+ */
93
+ markAsUncloneable (V: any): void
70
94
  }
71
95
 
72
96
  interface WebidlConverters {
@@ -150,7 +174,7 @@ interface WebidlConverters {
150
174
  ): NodeJS.TypedArray | ArrayBufferLike | DataView
151
175
 
152
176
  ['sequence<ByteString>']: SequenceConverter<string>
153
-
177
+
154
178
  ['sequence<sequence<ByteString>>']: SequenceConverter<string[]>
155
179
 
156
180
  ['record<ByteString, ByteString>']: RecordConverter<string, string>
@@ -158,16 +182,35 @@ interface WebidlConverters {
158
182
  [Key: string]: (...args: any[]) => unknown
159
183
  }
160
184
 
185
+ type IsAssertion<T> = (arg: any) => arg is T
186
+
187
+ interface WebidlIs {
188
+ Request: IsAssertion<undici.Request>
189
+ Response: IsAssertion<undici.Response>
190
+ ReadableStream: IsAssertion<ReadableStream>
191
+ Blob: IsAssertion<Blob>
192
+ URLSearchParams: IsAssertion<URLSearchParams>
193
+ File: IsAssertion<File>
194
+ FormData: IsAssertion<undici.FormData>
195
+ URL: IsAssertion<URL>
196
+ WebSocketError: IsAssertion<undici.WebSocketError>
197
+ AbortSignal: IsAssertion<AbortSignal>
198
+ MessagePort: IsAssertion<MessagePort>
199
+ }
200
+
161
201
  export interface Webidl {
162
202
  errors: WebidlErrors
163
203
  util: WebidlUtil
164
204
  converters: WebidlConverters
205
+ is: WebidlIs
165
206
 
166
207
  /**
167
208
  * @description Performs a brand-check on {@param V} to ensure it is a
168
209
  * {@param cls} object.
169
210
  */
170
- brandCheck <Interface>(V: unknown, cls: Interface, opts?: { strict?: boolean }): asserts V is Interface
211
+ brandCheck <Interface extends new () => unknown>(V: unknown, cls: Interface): asserts V is Interface
212
+
213
+ brandCheckMultiple <Interfaces extends (new () => unknown)[]> (list: Interfaces): (V: any) => asserts V is Interfaces[number]
171
214
 
172
215
  /**
173
216
  * @see https://webidl.spec.whatwg.org/#es-sequence
@@ -190,10 +233,11 @@ export interface Webidl {
190
233
  * Similar to {@link Webidl.brandCheck} but allows skipping the check if third party
191
234
  * interfaces are allowed.
192
235
  */
193
- interfaceConverter <Interface>(cls: Interface): (
236
+ interfaceConverter <Interface>(typeCheck: IsAssertion<Interface>, name: string): (
194
237
  V: unknown,
195
- opts?: { strict: boolean }
196
- ) => asserts V is typeof cls
238
+ prefix: string,
239
+ argument: string
240
+ ) => asserts V is Interface
197
241
 
198
242
  // TODO(@KhafraDev): a type could likely be implemented that can infer the return type
199
243
  // from the converters given?
package/websocket.d.ts CHANGED
@@ -22,7 +22,7 @@ interface WebSocketEventMap {
22
22
 
23
23
  interface WebSocket extends EventTarget {
24
24
  binaryType: BinaryType
25
-
25
+
26
26
  readonly bufferedAmount: number
27
27
  readonly extensions: string
28
28
 
@@ -148,3 +148,36 @@ interface WebSocketInit {
148
148
  dispatcher?: Dispatcher,
149
149
  headers?: HeadersInit
150
150
  }
151
+
152
+ interface WebSocketStreamOptions {
153
+ protocols?: string | string[]
154
+ signal?: AbortSignal
155
+ }
156
+
157
+ interface WebSocketCloseInfo {
158
+ closeCode: number
159
+ reason: string
160
+ }
161
+
162
+ interface WebSocketStream {
163
+ closed: Promise<WebSocketCloseInfo>
164
+ opened: Promise<{
165
+ extensions: string
166
+ protocol: string
167
+ readable: ReadableStream
168
+ writable: WritableStream
169
+ }>
170
+ url: string
171
+ }
172
+
173
+ export declare const WebSocketStream: {
174
+ prototype: WebSocketStream
175
+ new (url: string | URL, options?: WebSocketStreamOptions): WebSocketStream
176
+ }
177
+
178
+ interface WebSocketError extends Event, WebSocketCloseInfo {}
179
+
180
+ export declare const WebSocketError: {
181
+ prototype: WebSocketError
182
+ new (type: string, init?: WebSocketCloseInfo): WebSocketError
183
+ }
package/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
- }
package/filereader.d.ts DELETED
@@ -1,54 +0,0 @@
1
- /// <reference types="node" />
2
-
3
- import { Blob } from 'buffer'
4
- import { DOMException, EventInit } 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
- }