undici-types 6.21.0 → 7.8.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/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
  */
@@ -68,6 +84,8 @@ interface WebidlUtil {
68
84
  */
69
85
  Stringify (V: any): string
70
86
 
87
+ MakeTypeAssertion <I>(I: I): (arg: any) => arg is I
88
+
71
89
  /**
72
90
  * Mark a value as uncloneable for Node.js.
73
91
  * This is only effective in some newer Node.js versions.
@@ -156,7 +174,7 @@ interface WebidlConverters {
156
174
  ): NodeJS.TypedArray | ArrayBufferLike | DataView
157
175
 
158
176
  ['sequence<ByteString>']: SequenceConverter<string>
159
-
177
+
160
178
  ['sequence<sequence<ByteString>>']: SequenceConverter<string[]>
161
179
 
162
180
  ['record<ByteString, ByteString>']: RecordConverter<string, string>
@@ -164,16 +182,35 @@ interface WebidlConverters {
164
182
  [Key: string]: (...args: any[]) => unknown
165
183
  }
166
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
+
167
201
  export interface Webidl {
168
202
  errors: WebidlErrors
169
203
  util: WebidlUtil
170
204
  converters: WebidlConverters
205
+ is: WebidlIs
171
206
 
172
207
  /**
173
208
  * @description Performs a brand-check on {@param V} to ensure it is a
174
209
  * {@param cls} object.
175
210
  */
176
- 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]
177
214
 
178
215
  /**
179
216
  * @see https://webidl.spec.whatwg.org/#es-sequence
@@ -196,10 +233,11 @@ export interface Webidl {
196
233
  * Similar to {@link Webidl.brandCheck} but allows skipping the check if third party
197
234
  * interfaces are allowed.
198
235
  */
199
- interfaceConverter <Interface>(cls: Interface): (
236
+ interfaceConverter <Interface>(typeCheck: IsAssertion<Interface>, name: string): (
200
237
  V: unknown,
201
- opts?: { strict: boolean }
202
- ) => asserts V is typeof cls
238
+ prefix: string,
239
+ argument: string
240
+ ) => asserts V is Interface
203
241
 
204
242
  // TODO(@KhafraDev): a type could likely be implemented that can infer the return type
205
243
  // from the converters given?
package/websocket.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
 
3
3
  import type { Blob } from 'buffer'
4
+ import type { ReadableStream, WritableStream } from 'stream/web'
4
5
  import type { MessagePort } from 'worker_threads'
5
6
  import {
6
7
  EventInit,
@@ -22,7 +23,7 @@ interface WebSocketEventMap {
22
23
 
23
24
  interface WebSocket extends EventTarget {
24
25
  binaryType: BinaryType
25
-
26
+
26
27
  readonly bufferedAmount: number
27
28
  readonly extensions: string
28
29
 
@@ -148,3 +149,36 @@ interface WebSocketInit {
148
149
  dispatcher?: Dispatcher,
149
150
  headers?: HeadersInit
150
151
  }
152
+
153
+ interface WebSocketStreamOptions {
154
+ protocols?: string | string[]
155
+ signal?: AbortSignal
156
+ }
157
+
158
+ interface WebSocketCloseInfo {
159
+ closeCode: number
160
+ reason: string
161
+ }
162
+
163
+ interface WebSocketStream {
164
+ closed: Promise<WebSocketCloseInfo>
165
+ opened: Promise<{
166
+ extensions: string
167
+ protocol: string
168
+ readable: ReadableStream
169
+ writable: WritableStream
170
+ }>
171
+ url: string
172
+ }
173
+
174
+ export declare const WebSocketStream: {
175
+ prototype: WebSocketStream
176
+ new (url: string | URL, options?: WebSocketStreamOptions): WebSocketStream
177
+ }
178
+
179
+ interface WebSocketError extends Event, WebSocketCloseInfo {}
180
+
181
+ export declare const WebSocketError: {
182
+ prototype: WebSocketError
183
+ new (type: string, init?: WebSocketCloseInfo): WebSocketError
184
+ }
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
- }