@types/node 16.11.39 → 18.11.2

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.
Files changed (111) hide show
  1. {node v16.11 → node}/LICENSE +0 -0
  2. node v16.11/README.md → node/README.md +4 -4
  3. {node v16.11 → node}/assert/strict.d.ts +0 -0
  4. node v16.11/assert.d.ts → node/assert.d.ts +7 -8
  5. node v16.11/async_hooks.d.ts → node/async_hooks.d.ts +8 -4
  6. node/buffer.d.ts +2258 -0
  7. node v16.11/child_process.d.ts → node/child_process.d.ts +6 -3
  8. node v16.11/cluster.d.ts → node/cluster.d.ts +14 -18
  9. node v16.11/console.d.ts → node/console.d.ts +1 -1
  10. {node v16.11 → node}/constants.d.ts +0 -0
  11. node v16.11/crypto.d.ts → node/crypto.d.ts +679 -53
  12. node v16.11/dgram.d.ts → node/dgram.d.ts +3 -3
  13. node v16.11/diagnostics_channel.d.ts → node/diagnostics_channel.d.ts +2 -1
  14. node v16.11/dns/promises.d.ts → node/dns/promises.d.ts +10 -8
  15. node v16.11/dns.d.ts → node/dns.d.ts +16 -11
  16. node/dom-events.d.ts +126 -0
  17. node v16.11/domain.d.ts → node/domain.d.ts +3 -2
  18. node v16.11/events.d.ts → node/events.d.ts +65 -10
  19. node v16.11/fs/promises.d.ts → node/fs/promises.d.ts +86 -39
  20. node v16.11/fs.d.ts → node/fs.d.ts +149 -67
  21. node/globals.d.ts +300 -0
  22. {node v16.11 → node}/globals.global.d.ts +0 -0
  23. node v16.11/http.d.ts → node/http.d.ts +305 -77
  24. node v16.11/http2.d.ts → node/http2.d.ts +38 -5
  25. node v16.11/https.d.ts → node/https.d.ts +209 -59
  26. node v16.11/index.d.ts → node/index.d.ts +6 -3
  27. node v16.11/inspector.d.ts → node/inspector.d.ts +11 -15
  28. {node v16.11 → node}/module.d.ts +0 -0
  29. node v16.11/net.d.ts → node/net.d.ts +94 -21
  30. node v16.11/os.d.ts → node/os.d.ts +15 -4
  31. node v16.11/package.json → node/package.json +15 -8
  32. node v16.11/path.d.ts → node/path.d.ts +34 -23
  33. node v16.11/perf_hooks.d.ts → node/perf_hooks.d.ts +76 -8
  34. node v16.11/process.d.ts → node/process.d.ts +17 -16
  35. node v16.11/punycode.d.ts → node/punycode.d.ts +1 -1
  36. node v16.11/querystring.d.ts → node/querystring.d.ts +4 -4
  37. node/readline/promises.d.ts +143 -0
  38. node v16.11/readline.d.ts → node/readline.d.ts +140 -30
  39. node v16.11/repl.d.ts → node/repl.d.ts +2 -2
  40. node v16.11/stream/consumers.d.ts → node/stream/consumers.d.ts +2 -14
  41. {node v16.11 → node}/stream/promises.d.ts +0 -0
  42. node v16.11/stream/web.d.ts → node/stream/web.d.ts +3 -65
  43. node v16.11/stream.d.ts → node/stream.d.ts +97 -19
  44. node v16.11/string_decoder.d.ts → node/string_decoder.d.ts +1 -1
  45. node/test.d.ts +314 -0
  46. {node v16.11 → node}/timers/promises.d.ts +0 -0
  47. node v16.11/timers.d.ts → node/timers.d.ts +1 -1
  48. node v16.11/tls.d.ts → node/tls.d.ts +32 -23
  49. node v16.11/trace_events.d.ts → node/trace_events.d.ts +11 -1
  50. node/ts4.8/assert/strict.d.ts +8 -0
  51. node/ts4.8/assert.d.ts +911 -0
  52. node/ts4.8/async_hooks.d.ts +501 -0
  53. node v16.11/buffer.d.ts → node/ts4.8/buffer.d.ts +46 -19
  54. node/ts4.8/child_process.d.ts +1369 -0
  55. node/ts4.8/cluster.d.ts +410 -0
  56. node/ts4.8/console.d.ts +412 -0
  57. node/ts4.8/constants.d.ts +18 -0
  58. node/ts4.8/crypto.d.ts +3964 -0
  59. node/ts4.8/dgram.d.ts +545 -0
  60. node/ts4.8/diagnostics_channel.d.ts +153 -0
  61. node/ts4.8/dns/promises.d.ts +370 -0
  62. node/ts4.8/dns.d.ts +659 -0
  63. node/ts4.8/dom-events.d.ts +126 -0
  64. node/ts4.8/domain.d.ts +170 -0
  65. node/ts4.8/events.d.ts +678 -0
  66. node/ts4.8/fs/promises.d.ts +1138 -0
  67. node/ts4.8/fs.d.ts +3872 -0
  68. node v16.11/globals.d.ts → node/ts4.8/globals.d.ts +14 -4
  69. node/ts4.8/globals.global.d.ts +1 -0
  70. node/ts4.8/http.d.ts +1607 -0
  71. node/ts4.8/http2.d.ts +2134 -0
  72. node/ts4.8/https.d.ts +541 -0
  73. node/ts4.8/index.d.ts +88 -0
  74. node/ts4.8/inspector.d.ts +2741 -0
  75. node/ts4.8/module.d.ts +114 -0
  76. node/ts4.8/net.d.ts +869 -0
  77. node/ts4.8/os.d.ts +466 -0
  78. node/ts4.8/path.d.ts +191 -0
  79. node/ts4.8/perf_hooks.d.ts +625 -0
  80. node/ts4.8/process.d.ts +1482 -0
  81. node/ts4.8/punycode.d.ts +117 -0
  82. node/ts4.8/querystring.d.ts +131 -0
  83. node/ts4.8/readline/promises.d.ts +143 -0
  84. node/ts4.8/readline.d.ts +653 -0
  85. node/ts4.8/repl.d.ts +424 -0
  86. node/ts4.8/stream/consumers.d.ts +12 -0
  87. node/ts4.8/stream/promises.d.ts +42 -0
  88. node/ts4.8/stream/web.d.ts +330 -0
  89. node/ts4.8/stream.d.ts +1340 -0
  90. node/ts4.8/string_decoder.d.ts +67 -0
  91. node/ts4.8/test.d.ts +314 -0
  92. node/ts4.8/timers/promises.d.ts +68 -0
  93. node/ts4.8/timers.d.ts +94 -0
  94. node/ts4.8/tls.d.ts +1028 -0
  95. node/ts4.8/trace_events.d.ts +171 -0
  96. node v16.11/tty.d.ts → node/ts4.8/tty.d.ts +4 -2
  97. node v16.11/url.d.ts → node/ts4.8/url.d.ts +85 -39
  98. node v16.11/util.d.ts → node/ts4.8/util.d.ts +268 -12
  99. node v16.11/v8.d.ts → node/ts4.8/v8.d.ts +21 -3
  100. node v16.11/vm.d.ts → node/ts4.8/vm.d.ts +6 -4
  101. node v16.11/wasi.d.ts → node/ts4.8/wasi.d.ts +1 -1
  102. node v16.11/worker_threads.d.ts → node/ts4.8/worker_threads.d.ts +50 -10
  103. node v16.11/zlib.d.ts → node/ts4.8/zlib.d.ts +1 -1
  104. node/tty.d.ts +206 -0
  105. node/url.d.ts +897 -0
  106. node/util.d.ts +1850 -0
  107. node/v8.d.ts +396 -0
  108. node/vm.d.ts +509 -0
  109. node/wasi.d.ts +158 -0
  110. node/worker_threads.d.ts +689 -0
  111. node/zlib.d.ts +517 -0
@@ -23,7 +23,7 @@
23
23
  * server.bind(41234);
24
24
  * // Prints: server listening 0.0.0.0:41234
25
25
  * ```
26
- * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/dgram.js)
26
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/dgram.js)
27
27
  */
28
28
  declare module 'dgram' {
29
29
  import { AddressInfo } from 'node:net';
@@ -260,7 +260,7 @@ declare module 'dgram' {
260
260
  *
261
261
  * The `address` argument is a string. If the value of `address` is a host name,
262
262
  * DNS will be used to resolve the address of the host. If `address` is not
263
- * provided or otherwise falsy, `'127.0.0.1'` (for `udp4` sockets) or `'::1'`(for `udp6` sockets) will be used by default.
263
+ * provided or otherwise nullish, `'127.0.0.1'` (for `udp4` sockets) or `'::1'`(for `udp6` sockets) will be used by default.
264
264
  *
265
265
  * If the socket has not been previously bound with a call to `bind`, the socket
266
266
  * is assigned a random port number and is bound to the "all interfaces" address
@@ -451,7 +451,7 @@ declare module 'dgram' {
451
451
  * TTL. If the TTL is decremented to 0 by a router, it will not be forwarded.
452
452
  * Changing TTL values is typically done for network probes or when multicasting.
453
453
  *
454
- * The `ttl` argument may be between between 1 and 255\. The default on most systems
454
+ * The `ttl` argument may be between 1 and 255\. The default on most systems
455
455
  * is 64.
456
456
  *
457
457
  * This method throws `EBADF` if called on an unbound socket.
@@ -20,7 +20,7 @@
20
20
  * should generally include the module name to avoid collisions with data from
21
21
  * other modules.
22
22
  * @experimental
23
- * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/diagnostics_channel.js)
23
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/diagnostics_channel.js)
24
24
  */
25
25
  declare module 'diagnostics_channel' {
26
26
  /**
@@ -143,6 +143,7 @@ declare module 'diagnostics_channel' {
143
143
  * ```
144
144
  * @since v15.1.0, v14.17.0
145
145
  * @param onMessage The previous subscribed handler to remove
146
+ * @return `true` if the handler was found, `false` otherwise.
146
147
  */
147
148
  unsubscribe(onMessage: ChannelListener): void;
148
149
  }
@@ -189,7 +189,7 @@ declare module 'dns/promises' {
189
189
  * Uses the DNS protocol to resolve `CAA` records for the `hostname`. On success,
190
190
  * the `Promise` is resolved with an array of objects containing available
191
191
  * certification authority authorization records available for the `hostname`(e.g. `[{critical: 0, iodef: 'mailto:pki@example.com'},{critical: 128, issue: 'pki.example.com'}]`).
192
- * @since v15.0.0
192
+ * @since v15.0.0, v14.17.0
193
193
  */
194
194
  function resolveCaa(hostname: string): Promise<CaaRecord[]>;
195
195
  /**
@@ -332,14 +332,16 @@ declare module 'dns/promises' {
332
332
  */
333
333
  function setServers(servers: ReadonlyArray<string>): void;
334
334
  /**
335
- * Set the default value of `verbatim` in {@link lookup}. The value could be:
336
- * - `ipv4first`: sets default `verbatim` `false`.
337
- * - `verbatim`: sets default `verbatim` `true`.
335
+ * Set the default value of `verbatim` in `dns.lookup()` and `dnsPromises.lookup()`. The value could be:
338
336
  *
339
- * The default is `ipv4first` and {@link setDefaultResultOrder} have higher priority than `--dns-result-order`.
340
- * When using worker threads, {@link setDefaultResultOrder} from the main thread won't affect the default dns orders in workers.
341
- * @since v14.18.0
342
- * @param order must be 'ipv4first' or 'verbatim'.
337
+ * * `ipv4first`: sets default `verbatim` `false`.
338
+ * * `verbatim`: sets default `verbatim` `true`.
339
+ *
340
+ * The default is `ipv4first` and `dnsPromises.setDefaultResultOrder()` have
341
+ * higher priority than `--dns-result-order`. When using `worker threads`,`dnsPromises.setDefaultResultOrder()` from the main thread won't affect the
342
+ * default dns orders in workers.
343
+ * @since v16.4.0, v14.18.0
344
+ * @param order must be `'ipv4first'` or `'verbatim'`.
343
345
  */
344
346
  function setDefaultResultOrder(order: 'ipv4first' | 'verbatim'): void;
345
347
  class Resolver {
@@ -42,7 +42,7 @@
42
42
  * ```
43
43
  *
44
44
  * See the `Implementation considerations section` for more information.
45
- * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/dns.js)
45
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/dns.js)
46
46
  */
47
47
  declare module 'dns' {
48
48
  import * as dnsPromises from 'node:dns/promises';
@@ -58,6 +58,9 @@ declare module 'dns' {
58
58
  family?: number | undefined;
59
59
  hints?: number | undefined;
60
60
  all?: boolean | undefined;
61
+ /**
62
+ * @default true
63
+ */
61
64
  verbatim?: boolean | undefined;
62
65
  }
63
66
  export interface LookupOneOptions extends LookupOptions {
@@ -314,7 +317,7 @@ declare module 'dns' {
314
317
  * Uses the DNS protocol to resolve `CAA` records for the `hostname`. The`addresses` argument passed to the `callback` function
315
318
  * will contain an array of certification authority authorization records
316
319
  * available for the `hostname` (e.g. `[{critical: 0, iodef: 'mailto:pki@example.com'}, {critical: 128, issue: 'pki.example.com'}]`).
317
- * @since v15.0.0
320
+ * @since v15.0.0, v14.17.0
318
321
  */
319
322
  export function resolveCaa(hostname: string, callback: (err: NodeJS.ErrnoException | null, records: CaaRecord[]) => void): void;
320
323
  export namespace resolveCaa {
@@ -527,14 +530,16 @@ declare module 'dns' {
527
530
  */
528
531
  export function getServers(): string[];
529
532
  /**
530
- * Set the default value of `verbatim` in {@link lookup}. The value could be:
531
- * - `ipv4first`: sets default `verbatim` `false`.
532
- * - `verbatim`: sets default `verbatim` `true`.
533
- *
534
- * The default is `ipv4first` and {@link setDefaultResultOrder} have higher priority than `--dns-result-order`.
535
- * When using worker threads, {@link setDefaultResultOrder} from the main thread won't affect the default dns orders in workers.
536
- * @since v14.18.0
537
- * @param order must be 'ipv4first' or 'verbatim'.
533
+ * Set the default value of `verbatim` in {@link lookup} and `dnsPromises.lookup()`. The value could be:
534
+ *
535
+ * * `ipv4first`: sets default `verbatim` `false`.
536
+ * * `verbatim`: sets default `verbatim` `true`.
537
+ *
538
+ * The default is `ipv4first` and {@link setDefaultResultOrder} have higher
539
+ * priority than `--dns-result-order`. When using `worker threads`,{@link setDefaultResultOrder} from the main thread won't affect the default
540
+ * dns orders in workers.
541
+ * @since v16.4.0, v14.18.0
542
+ * @param order must be `'ipv4first'` or `'verbatim'`.
538
543
  */
539
544
  export function setDefaultResultOrder(order: 'ipv4first' | 'verbatim'): void;
540
545
  // Error codes
@@ -640,7 +645,7 @@ declare module 'dns' {
640
645
  * The resolver will use the v4 local address when making requests to IPv4 DNS
641
646
  * servers, and the v6 local address when making requests to IPv6 DNS servers.
642
647
  * The `rrtype` of resolution requests has no impact on the local address used.
643
- * @since v15.1.0
648
+ * @since v15.1.0, v14.17.0
644
649
  * @param [ipv4='0.0.0.0'] A string representation of an IPv4 address.
645
650
  * @param [ipv6='::0'] A string representation of an IPv6 address.
646
651
  */
node/dom-events.d.ts ADDED
@@ -0,0 +1,126 @@
1
+ export {}; // Don't export anything!
2
+
3
+ //// DOM-like Events
4
+ // NB: The Event / EventTarget / EventListener implementations below were copied
5
+ // from lib.dom.d.ts, then edited to reflect Node's documentation at
6
+ // https://nodejs.org/api/events.html#class-eventtarget.
7
+ // Please read that link to understand important implementation differences.
8
+
9
+ // This conditional type will be the existing global Event in a browser, or
10
+ // the copy below in a Node environment.
11
+ type __Event = typeof globalThis extends { onmessage: any, Event: any }
12
+ ? {}
13
+ : {
14
+ /** This is not used in Node.js and is provided purely for completeness. */
15
+ readonly bubbles: boolean;
16
+ /** Alias for event.stopPropagation(). This is not used in Node.js and is provided purely for completeness. */
17
+ cancelBubble: () => void;
18
+ /** True if the event was created with the cancelable option */
19
+ readonly cancelable: boolean;
20
+ /** This is not used in Node.js and is provided purely for completeness. */
21
+ readonly composed: boolean;
22
+ /** Returns an array containing the current EventTarget as the only entry or empty if the event is not being dispatched. This is not used in Node.js and is provided purely for completeness. */
23
+ composedPath(): [EventTarget?]
24
+ /** Alias for event.target. */
25
+ readonly currentTarget: EventTarget | null;
26
+ /** Is true if cancelable is true and event.preventDefault() has been called. */
27
+ readonly defaultPrevented: boolean;
28
+ /** This is not used in Node.js and is provided purely for completeness. */
29
+ readonly eventPhase: 0 | 2;
30
+ /** The `AbortSignal` "abort" event is emitted with `isTrusted` set to `true`. The value is `false` in all other cases. */
31
+ readonly isTrusted: boolean;
32
+ /** Sets the `defaultPrevented` property to `true` if `cancelable` is `true`. */
33
+ preventDefault(): void;
34
+ /** This is not used in Node.js and is provided purely for completeness. */
35
+ returnValue: boolean;
36
+ /** Alias for event.target. */
37
+ readonly srcElement: EventTarget | null;
38
+ /** Stops the invocation of event listeners after the current one completes. */
39
+ stopImmediatePropagation(): void;
40
+ /** This is not used in Node.js and is provided purely for completeness. */
41
+ stopPropagation(): void;
42
+ /** The `EventTarget` dispatching the event */
43
+ readonly target: EventTarget | null;
44
+ /** The millisecond timestamp when the Event object was created. */
45
+ readonly timeStamp: number;
46
+ /** Returns the type of event, e.g. "click", "hashchange", or "submit". */
47
+ readonly type: string;
48
+ };
49
+
50
+ // See comment above explaining conditional type
51
+ type __EventTarget = typeof globalThis extends { onmessage: any, EventTarget: any }
52
+ ? {}
53
+ : {
54
+ /**
55
+ * Adds a new handler for the `type` event. Any given `listener` is added only once per `type` and per `capture` option value.
56
+ *
57
+ * If the `once` option is true, the `listener` is removed after the next time a `type` event is dispatched.
58
+ *
59
+ * The `capture` option is not used by Node.js in any functional way other than tracking registered event listeners per the `EventTarget` specification.
60
+ * Specifically, the `capture` option is used as part of the key when registering a `listener`.
61
+ * Any individual `listener` may be added once with `capture = false`, and once with `capture = true`.
62
+ */
63
+ addEventListener(
64
+ type: string,
65
+ listener: EventListener | EventListenerObject,
66
+ options?: AddEventListenerOptions | boolean,
67
+ ): void;
68
+ /** Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. */
69
+ dispatchEvent(event: Event): boolean;
70
+ /** Removes the event listener in target's event listener list with the same type, callback, and options. */
71
+ removeEventListener(
72
+ type: string,
73
+ listener: EventListener | EventListenerObject,
74
+ options?: EventListenerOptions | boolean,
75
+ ): void;
76
+ };
77
+
78
+ interface EventInit {
79
+ bubbles?: boolean;
80
+ cancelable?: boolean;
81
+ composed?: boolean;
82
+ }
83
+
84
+ interface EventListenerOptions {
85
+ /** Not directly used by Node.js. Added for API completeness. Default: `false`. */
86
+ capture?: boolean;
87
+ }
88
+
89
+ interface AddEventListenerOptions extends EventListenerOptions {
90
+ /** When `true`, the listener is automatically removed when it is first invoked. Default: `false`. */
91
+ once?: boolean;
92
+ /** When `true`, serves as a hint that the listener will not call the `Event` object's `preventDefault()` method. Default: false. */
93
+ passive?: boolean;
94
+ }
95
+
96
+ interface EventListener {
97
+ (evt: Event): void;
98
+ }
99
+
100
+ interface EventListenerObject {
101
+ handleEvent(object: Event): void;
102
+ }
103
+
104
+ import {} from 'events'; // Make this an ambient declaration
105
+ declare global {
106
+ /** An event which takes place in the DOM. */
107
+ interface Event extends __Event {}
108
+ var Event: typeof globalThis extends { onmessage: any, Event: infer T }
109
+ ? T
110
+ : {
111
+ prototype: __Event;
112
+ new (type: string, eventInitDict?: EventInit): __Event;
113
+ };
114
+
115
+ /**
116
+ * EventTarget is a DOM interface implemented by objects that can
117
+ * receive events and may have listeners for them.
118
+ */
119
+ interface EventTarget extends __EventTarget {}
120
+ var EventTarget: typeof globalThis extends { onmessage: any, EventTarget: infer T }
121
+ ? T
122
+ : {
123
+ prototype: __EventTarget;
124
+ new (): __EventTarget;
125
+ };
126
+ }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * **This module is pending deprecation.** Once a replacement API has been
3
- * finalized, this module will be fully deprecated. Most developers should**not** have cause to use this module. Users who absolutely must have
3
+ * finalized, this module will be fully deprecated. Most developers should
4
+ * **not** have cause to use this module. Users who absolutely must have
4
5
  * the functionality that domains provide may rely on it for the time being
5
6
  * but should expect to have to migrate to a different solution
6
7
  * in the future.
@@ -11,7 +12,7 @@
11
12
  * will be notified, rather than losing the context of the error in the`process.on('uncaughtException')` handler, or causing the program to
12
13
  * exit immediately with an error code.
13
14
  * @deprecated Since v1.4.2 - Deprecated
14
- * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/domain.js)
15
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/domain.js)
15
16
  */
16
17
  declare module 'domain' {
17
18
  import EventEmitter = require('node:events');
@@ -32,19 +32,56 @@
32
32
  * });
33
33
  * myEmitter.emit('event');
34
34
  * ```
35
- * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/events.js)
35
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/events.js)
36
36
  */
37
37
  declare module 'events' {
38
+ // NOTE: This class is in the docs but is **not actually exported** by Node.
39
+ // If https://github.com/nodejs/node/issues/39903 gets resolved and Node
40
+ // actually starts exporting the class, uncomment below.
41
+
42
+ // import { EventListener, EventListenerObject } from '__dom-events';
43
+ // /** The NodeEventTarget is a Node.js-specific extension to EventTarget that emulates a subset of the EventEmitter API. */
44
+ // interface NodeEventTarget extends EventTarget {
45
+ // /**
46
+ // * Node.js-specific extension to the `EventTarget` class that emulates the equivalent `EventEmitter` API.
47
+ // * The only difference between `addListener()` and `addEventListener()` is that addListener() will return a reference to the EventTarget.
48
+ // */
49
+ // addListener(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this;
50
+ // /** Node.js-specific extension to the `EventTarget` class that returns an array of event `type` names for which event listeners are registered. */
51
+ // eventNames(): string[];
52
+ // /** Node.js-specific extension to the `EventTarget` class that returns the number of event listeners registered for the `type`. */
53
+ // listenerCount(type: string): number;
54
+ // /** Node.js-specific alias for `eventTarget.removeListener()`. */
55
+ // off(type: string, listener: EventListener | EventListenerObject): this;
56
+ // /** Node.js-specific alias for `eventTarget.addListener()`. */
57
+ // on(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this;
58
+ // /** Node.js-specific extension to the `EventTarget` class that adds a `once` listener for the given event `type`. This is equivalent to calling `on` with the `once` option set to `true`. */
59
+ // once(type: string, listener: EventListener | EventListenerObject): this;
60
+ // /**
61
+ // * Node.js-specific extension to the `EventTarget` class.
62
+ // * If `type` is specified, removes all registered listeners for `type`,
63
+ // * otherwise removes all registered listeners.
64
+ // */
65
+ // removeAllListeners(type: string): this;
66
+ // /**
67
+ // * Node.js-specific extension to the `EventTarget` class that removes the listener for the given `type`.
68
+ // * The only difference between `removeListener()` and `removeEventListener()` is that `removeListener()` will return a reference to the `EventTarget`.
69
+ // */
70
+ // removeListener(type: string, listener: EventListener | EventListenerObject): this;
71
+ // }
72
+
38
73
  interface EventEmitterOptions {
39
74
  /**
40
75
  * Enables automatic capturing of promise rejection.
41
76
  */
42
77
  captureRejections?: boolean | undefined;
43
78
  }
44
- interface NodeEventTarget {
79
+ // Any EventTarget with a Node-style `once` function
80
+ interface _NodeEventTarget {
45
81
  once(eventName: string | symbol, listener: (...args: any[]) => void): this;
46
82
  }
47
- interface DOMEventTarget {
83
+ // Any EventTarget with a DOM-style `addEventListener`
84
+ interface _DOMEventTarget {
48
85
  addEventListener(
49
86
  eventName: string,
50
87
  listener: (...args: any[]) => void,
@@ -154,8 +191,8 @@ declare module 'events' {
154
191
  * ```
155
192
  * @since v11.13.0, v10.16.0
156
193
  */
157
- static once(emitter: NodeEventTarget, eventName: string | symbol, options?: StaticEventEmitterOptions): Promise<any[]>;
158
- static once(emitter: DOMEventTarget, eventName: string, options?: StaticEventEmitterOptions): Promise<any[]>;
194
+ static once(emitter: _NodeEventTarget, eventName: string | symbol, options?: StaticEventEmitterOptions): Promise<any[]>;
195
+ static once(emitter: _DOMEventTarget, eventName: string, options?: StaticEventEmitterOptions): Promise<any[]>;
159
196
  /**
160
197
  * ```js
161
198
  * const { on, EventEmitter } = require('events');
@@ -257,9 +294,27 @@ declare module 'events' {
257
294
  * getEventListeners(et, 'foo'); // [listener]
258
295
  * }
259
296
  * ```
260
- * @since v15.2.0
297
+ * @since v15.2.0, v14.17.0
261
298
  */
262
- static getEventListeners(emitter: DOMEventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
299
+ static getEventListeners(emitter: _DOMEventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
300
+ /**
301
+ * ```js
302
+ * const {
303
+ * setMaxListeners,
304
+ * EventEmitter
305
+ * } = require('events');
306
+ *
307
+ * const target = new EventTarget();
308
+ * const emitter = new EventEmitter();
309
+ *
310
+ * setMaxListeners(5, target, emitter);
311
+ * ```
312
+ * @since v15.4.0
313
+ * @param n A non-negative number. The maximum number of listeners per `EventTarget` event.
314
+ * @param eventsTargets Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, `n` is set as the default max for all newly created {EventTarget} and {EventEmitter}
315
+ * objects.
316
+ */
317
+ static setMaxListeners(n?: number, ...eventTargets: Array<_DOMEventTarget | NodeJS.EventEmitter>): void;
263
318
  /**
264
319
  * This symbol shall be used to install a listener for only monitoring `'error'`
265
320
  * events. Listeners installed using this symbol are called before the regular
@@ -375,8 +430,8 @@ declare module 'events' {
375
430
  * called multiple times to remove each instance.
376
431
  *
377
432
  * Once an event is emitted, all listeners attached to it at the
378
- * time of emitting are called in order. This implies that any`removeListener()` or `removeAllListeners()` calls _after_ emitting and_before_ the last listener finishes execution will
379
- * not remove them from`emit()` in progress. Subsequent events behave as expected.
433
+ * time of emitting are called in order. This implies that any`removeListener()` or `removeAllListeners()` calls _after_ emitting and _before_ the last listener finishes execution
434
+ * will not remove them from`emit()` in progress. Subsequent events behave as expected.
380
435
  *
381
436
  * ```js
382
437
  * const myEmitter = new MyEmitter();
@@ -578,7 +633,7 @@ declare module 'events' {
578
633
  */
579
634
  prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
580
635
  /**
581
- * Adds a **one-time**`listener` function for the event named `eventName` to the_beginning_ of the listeners array. The next time `eventName` is triggered, this
636
+ * Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. The next time `eventName` is triggered, this
582
637
  * listener is removed, and then invoked.
583
638
  *
584
639
  * ```js
@@ -11,29 +11,34 @@
11
11
  declare module 'fs/promises' {
12
12
  import { Abortable } from 'node:events';
13
13
  import { Stream } from 'node:stream';
14
+ import { ReadableStream } from 'node:stream/web';
14
15
  import {
15
- Stats,
16
16
  BigIntStats,
17
- StatOptions,
18
- WriteVResult,
19
- ReadVResult,
20
- PathLike,
21
- RmDirOptions,
22
- RmOptions,
23
- MakeDirectoryOptions,
24
- Dirent,
25
- OpenDirOptions,
17
+ BufferEncodingOption,
18
+ constants as fsConstants,
19
+ CopyOptions,
26
20
  Dir,
21
+ Dirent,
22
+ MakeDirectoryOptions,
23
+ Mode,
27
24
  ObjectEncodingOptions,
28
- BufferEncodingOption,
25
+ OpenDirOptions,
29
26
  OpenMode,
30
- Mode,
31
- WatchOptions,
32
- WatchEventType,
33
- CopyOptions,
27
+ PathLike,
34
28
  ReadStream,
29
+ ReadVResult,
30
+ RmDirOptions,
31
+ RmOptions,
32
+ StatOptions,
33
+ Stats,
34
+ TimeLike,
35
+ WatchEventType,
36
+ WatchOptions,
35
37
  WriteStream,
38
+ WriteVResult,
36
39
  } from 'node:fs';
40
+ import { Interface as ReadlineInterface } from 'node:readline';
41
+
37
42
  interface FileChangeInfo<T extends string | Buffer> {
38
43
  eventType: WatchEventType;
39
44
  filename: T;
@@ -42,11 +47,11 @@ declare module 'fs/promises' {
42
47
  mode?: Mode | undefined;
43
48
  flag?: OpenMode | undefined;
44
49
  }
45
- interface FileReadResult<T extends ArrayBufferView> {
50
+ interface FileReadResult<T extends NodeJS.ArrayBufferView> {
46
51
  bytesRead: number;
47
52
  buffer: T;
48
53
  }
49
- interface FileReadOptions<T extends ArrayBufferView = Buffer> {
54
+ interface FileReadOptions<T extends NodeJS.ArrayBufferView = Buffer> {
50
55
  /**
51
56
  * @default `Buffer.alloc(0xffff)`
52
57
  */
@@ -163,9 +168,9 @@ declare module 'fs/promises' {
163
168
  /**
164
169
  * `options` may also include a `start` option to allow writing data at some
165
170
  * position past the beginning of the file, allowed values are in the
166
- * \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. Modifying a file rather than replacing
167
- * it may require the `flags` `open` option to be set to `r+` rather than the
168
- * default `r`. The `encoding` can be any one of those accepted by `Buffer`.
171
+ * \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. Modifying a file rather than
172
+ * replacing it may require the `flags` `open` option to be set to `r+` rather than
173
+ * the default `r`. The `encoding` can be any one of those accepted by `Buffer`.
169
174
  *
170
175
  * If `autoClose` is set to true (default behavior) on `'error'` or `'finish'`the file descriptor will be closed automatically. If `autoClose` is false,
171
176
  * then the file descriptor won't be closed, even if there's an error.
@@ -207,8 +212,31 @@ declare module 'fs/promises' {
207
212
  * integer, the current file position will remain unchanged.
208
213
  * @return Fulfills upon success with an object with two properties:
209
214
  */
210
- read<T extends ArrayBufferView>(buffer: T, offset?: number | null, length?: number | null, position?: number | null): Promise<FileReadResult<T>>;
211
- read<T extends ArrayBufferView = Buffer>(options?: FileReadOptions<T>): Promise<FileReadResult<T>>;
215
+ read<T extends NodeJS.ArrayBufferView>(buffer: T, offset?: number | null, length?: number | null, position?: number | null): Promise<FileReadResult<T>>;
216
+ read<T extends NodeJS.ArrayBufferView = Buffer>(options?: FileReadOptions<T>): Promise<FileReadResult<T>>;
217
+ /**
218
+ * Returns a `ReadableStream` that may be used to read the files data.
219
+ *
220
+ * An error will be thrown if this method is called more than once or is called after the `FileHandle` is closed
221
+ * or closing.
222
+ *
223
+ * ```js
224
+ * import { open } from 'node:fs/promises';
225
+ *
226
+ * const file = await open('./some/file/to/read');
227
+ *
228
+ * for await (const chunk of file.readableWebStream())
229
+ * console.log(chunk);
230
+ *
231
+ * await file.close();
232
+ * ```
233
+ *
234
+ * While the `ReadableStream` will read the file to completion, it will not close the `FileHandle` automatically. User code must still call the `fileHandle.close()` method.
235
+ *
236
+ * @since v17.0.0
237
+ * @experimental
238
+ */
239
+ readableWebStream(): ReadableStream;
212
240
  /**
213
241
  * Asynchronously reads the entire contents of a file.
214
242
  *
@@ -257,6 +285,23 @@ declare module 'fs/promises' {
257
285
  | BufferEncoding
258
286
  | null
259
287
  ): Promise<string | Buffer>;
288
+ /**
289
+ * Convenience method to create a `readline` interface and stream over the file. For example:
290
+ *
291
+ * ```js
292
+ * import { open } from 'node:fs/promises';
293
+ *
294
+ * const file = await open('./some/file/to/read');
295
+ *
296
+ * for await (const line of file.readLines()) {
297
+ * console.log(line);
298
+ * }
299
+ * ```
300
+ *
301
+ * @since v18.11.0
302
+ * @param options See `filehandle.createReadStream()` for the options.
303
+ */
304
+ readLines(options?: CreateReadStreamOptions): ReadlineInterface;
260
305
  /**
261
306
  * @since v10.0.0
262
307
  * @return Fulfills with an {fs.Stats} for the file.
@@ -305,13 +350,12 @@ declare module 'fs/promises' {
305
350
  * Change the file system timestamps of the object referenced by the `FileHandle` then resolves the promise with no arguments upon success.
306
351
  * @since v10.0.0
307
352
  */
308
- utimes(atime: string | number | Date, mtime: string | number | Date): Promise<void>;
353
+ utimes(atime: TimeLike, mtime: TimeLike): Promise<void>;
309
354
  /**
310
355
  * Asynchronously writes data to a file, replacing the file if it already exists.`data` can be a string, a buffer, an
311
356
  * [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface) or
312
- * [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object, or an
313
- * object with an own `toString` function
314
- * property. The promise is resolved with no arguments upon success.
357
+ * [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
358
+ * The promise is resolved with no arguments upon success.
315
359
  *
316
360
  * If `options` is a string, then it specifies the `encoding`.
317
361
  *
@@ -329,20 +373,18 @@ declare module 'fs/promises' {
329
373
  /**
330
374
  * Write `buffer` to the file.
331
375
  *
332
- * If `buffer` is a plain object, it must have an own (not inherited) `toString`function property.
333
- *
334
376
  * The promise is resolved with an object containing two properties:
335
377
  *
336
378
  * It is unsafe to use `filehandle.write()` multiple times on the same file
337
379
  * without waiting for the promise to be resolved (or rejected). For this
338
- * scenario, use `fs.createWriteStream()`.
380
+ * scenario, use `filehandle.createWriteStream()`.
339
381
  *
340
382
  * On Linux, positional writes do not work when the file is opened in append mode.
341
383
  * The kernel ignores the position argument and always appends the data to
342
384
  * the end of the file.
343
385
  * @since v10.0.0
344
386
  * @param [offset=0] The start position from within `buffer` where the data to write begins.
345
- * @param [length=buffer.byteLength] The number of bytes from `buffer` to write.
387
+ * @param [length=buffer.byteLength - offset] The number of bytes from `buffer` to write.
346
388
  * @param position The offset from the beginning of the file where the data from `buffer` should be written. If `position` is not a `number`, the data will be written at the current position.
347
389
  * See the POSIX pwrite(2) documentation for more detail.
348
390
  */
@@ -405,12 +447,15 @@ declare module 'fs/promises' {
405
447
  */
406
448
  close(): Promise<void>;
407
449
  }
450
+
451
+ const constants: typeof fsConstants;
452
+
408
453
  /**
409
454
  * Tests a user's permissions for the file or directory specified by `path`.
410
455
  * The `mode` argument is an optional integer that specifies the accessibility
411
- * checks to be performed. Check `File access constants` for possible values
412
- * of `mode`. It is possible to create a mask consisting of the bitwise OR of
413
- * two or more values (e.g. `fs.constants.W_OK | fs.constants.R_OK`).
456
+ * checks to be performed. `mode` should be either the value `fs.constants.F_OK`or a mask consisting of the bitwise OR of any of `fs.constants.R_OK`,`fs.constants.W_OK`, and `fs.constants.X_OK`
457
+ * (e.g.`fs.constants.W_OK | fs.constants.R_OK`). Check `File access constants` for
458
+ * possible values of `mode`.
414
459
  *
415
460
  * If the accessibility check is successful, the promise is resolved with no
416
461
  * value. If any of the accessibility checks fail, the promise is rejected
@@ -741,7 +786,7 @@ declare module 'fs/promises' {
741
786
  * @since v14.5.0, v12.19.0
742
787
  * @return Fulfills with `undefined` upon success.
743
788
  */
744
- function lutimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
789
+ function lutimes(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
745
790
  /**
746
791
  * Changes the ownership of a file.
747
792
  * @since v10.0.0
@@ -759,7 +804,7 @@ declare module 'fs/promises' {
759
804
  * @since v10.0.0
760
805
  * @return Fulfills with `undefined` upon success.
761
806
  */
762
- function utimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
807
+ function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
763
808
  /**
764
809
  * Determines the actual location of `path` using the same semantics as the`fs.realpath.native()` function.
765
810
  *
@@ -830,7 +875,9 @@ declare module 'fs/promises' {
830
875
  */
831
876
  function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
832
877
  /**
833
- * Asynchronously writes data to a file, replacing the file if it already exists.`data` can be a string, a `Buffer`, or, an object with an own (not inherited)`toString` function property.
878
+ * Asynchronously writes data to a file, replacing the file if it already exists.`data` can be a string, a buffer, an
879
+ * [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface) or
880
+ * [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
834
881
  *
835
882
  * The `encoding` option is ignored if `data` is a buffer.
836
883
  *
@@ -845,7 +892,7 @@ declare module 'fs/promises' {
845
892
  *
846
893
  * Similarly to `fsPromises.readFile` \- `fsPromises.writeFile` is a convenience
847
894
  * method that performs multiple `write` calls internally to write the buffer
848
- * passed to it. For performance sensitive code consider using `fs.createWriteStream()`.
895
+ * passed to it. For performance sensitive code consider using `fs.createWriteStream()` or `filehandle.createWriteStream()`.
849
896
  *
850
897
  * It is possible to use an `AbortSignal` to cancel an `fsPromises.writeFile()`.
851
898
  * Cancelation is "best effort", and some amount of data is likely still
@@ -1043,7 +1090,7 @@ declare module 'fs/promises' {
1043
1090
  * disappears in the directory.
1044
1091
  *
1045
1092
  * All the `caveats` for `fs.watch()` also apply to `fsPromises.watch()`.
1046
- * @since v15.9.0
1093
+ * @since v15.9.0, v14.18.0
1047
1094
  * @return of objects with the properties:
1048
1095
  */
1049
1096
  function watch(
@@ -1084,7 +1131,7 @@ declare module 'fs/promises' {
1084
1131
  * @param dest destination path to copy to.
1085
1132
  * @return Fulfills with `undefined` upon success.
1086
1133
  */
1087
- function cp(source: string, destination: string, opts?: CopyOptions): Promise<void>;
1134
+ function cp(source: string | URL, destination: string | URL, opts?: CopyOptions): Promise<void>;
1088
1135
  }
1089
1136
  declare module 'node:fs/promises' {
1090
1137
  export * from 'fs/promises';