@types/node 16.6.1 → 16.7.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.
node/events.d.ts CHANGED
@@ -32,7 +32,7 @@
32
32
  * });
33
33
  * myEmitter.emit('event');
34
34
  * ```
35
- * @see [source](https://github.com/nodejs/node/blob/v16.6.0/lib/events.js)
35
+ * @see [source](https://github.com/nodejs/node/blob/v16.7.0/lib/events.js)
36
36
  */
37
37
  declare module 'events' {
38
38
  interface EventEmitterOptions {
@@ -72,15 +72,194 @@ declare module 'events' {
72
72
  */
73
73
  class EventEmitter {
74
74
  constructor(options?: EventEmitterOptions);
75
+ /**
76
+ * Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
77
+ * event or that is rejected if the `EventEmitter` emits `'error'` while waiting.
78
+ * The `Promise` will resolve with an array of all the arguments emitted to the
79
+ * given event.
80
+ *
81
+ * This method is intentionally generic and works with the web platform[EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event
82
+ * semantics and does not listen to the `'error'` event.
83
+ *
84
+ * ```js
85
+ * const { once, EventEmitter } = require('events');
86
+ *
87
+ * async function run() {
88
+ * const ee = new EventEmitter();
89
+ *
90
+ * process.nextTick(() => {
91
+ * ee.emit('myevent', 42);
92
+ * });
93
+ *
94
+ * const [value] = await once(ee, 'myevent');
95
+ * console.log(value);
96
+ *
97
+ * const err = new Error('kaboom');
98
+ * process.nextTick(() => {
99
+ * ee.emit('error', err);
100
+ * });
101
+ *
102
+ * try {
103
+ * await once(ee, 'myevent');
104
+ * } catch (err) {
105
+ * console.log('error happened', err);
106
+ * }
107
+ * }
108
+ *
109
+ * run();
110
+ * ```
111
+ *
112
+ * The special handling of the `'error'` event is only used when `events.once()`is used to wait for another event. If `events.once()` is used to wait for the
113
+ * '`error'` event itself, then it is treated as any other kind of event without
114
+ * special handling:
115
+ *
116
+ * ```js
117
+ * const { EventEmitter, once } = require('events');
118
+ *
119
+ * const ee = new EventEmitter();
120
+ *
121
+ * once(ee, 'error')
122
+ * .then(([err]) => console.log('ok', err.message))
123
+ * .catch((err) => console.log('error', err.message));
124
+ *
125
+ * ee.emit('error', new Error('boom'));
126
+ *
127
+ * // Prints: ok boom
128
+ * ```
129
+ *
130
+ * An `AbortSignal` can be used to cancel waiting for the event:
131
+ *
132
+ * ```js
133
+ * const { EventEmitter, once } = require('events');
134
+ *
135
+ * const ee = new EventEmitter();
136
+ * const ac = new AbortController();
137
+ *
138
+ * async function foo(emitter, event, signal) {
139
+ * try {
140
+ * await once(emitter, event, { signal });
141
+ * console.log('event emitted!');
142
+ * } catch (error) {
143
+ * if (error.name === 'AbortError') {
144
+ * console.error('Waiting for the event was canceled!');
145
+ * } else {
146
+ * console.error('There was an error', error.message);
147
+ * }
148
+ * }
149
+ * }
150
+ *
151
+ * foo(ee, 'foo', ac.signal);
152
+ * ac.abort(); // Abort waiting for the event
153
+ * ee.emit('foo'); // Prints: Waiting for the event was canceled!
154
+ * ```
155
+ * @since v11.13.0, v10.16.0
156
+ */
75
157
  static once(emitter: NodeEventTarget, eventName: string | symbol, options?: StaticEventEmitterOptions): Promise<any[]>;
76
158
  static once(emitter: DOMEventTarget, eventName: string, options?: StaticEventEmitterOptions): Promise<any[]>;
159
+ /**
160
+ * ```js
161
+ * const { on, EventEmitter } = require('events');
162
+ *
163
+ * (async () => {
164
+ * const ee = new EventEmitter();
165
+ *
166
+ * // Emit later on
167
+ * process.nextTick(() => {
168
+ * ee.emit('foo', 'bar');
169
+ * ee.emit('foo', 42);
170
+ * });
171
+ *
172
+ * for await (const event of on(ee, 'foo')) {
173
+ * // The execution of this inner block is synchronous and it
174
+ * // processes one event at a time (even with await). Do not use
175
+ * // if concurrent execution is required.
176
+ * console.log(event); // prints ['bar'] [42]
177
+ * }
178
+ * // Unreachable here
179
+ * })();
180
+ * ```
181
+ *
182
+ * Returns an `AsyncIterator` that iterates `eventName` events. It will throw
183
+ * if the `EventEmitter` emits `'error'`. It removes all listeners when
184
+ * exiting the loop. The `value` returned by each iteration is an array
185
+ * composed of the emitted event arguments.
186
+ *
187
+ * An `AbortSignal` can be used to cancel waiting on events:
188
+ *
189
+ * ```js
190
+ * const { on, EventEmitter } = require('events');
191
+ * const ac = new AbortController();
192
+ *
193
+ * (async () => {
194
+ * const ee = new EventEmitter();
195
+ *
196
+ * // Emit later on
197
+ * process.nextTick(() => {
198
+ * ee.emit('foo', 'bar');
199
+ * ee.emit('foo', 42);
200
+ * });
201
+ *
202
+ * for await (const event of on(ee, 'foo', { signal: ac.signal })) {
203
+ * // The execution of this inner block is synchronous and it
204
+ * // processes one event at a time (even with await). Do not use
205
+ * // if concurrent execution is required.
206
+ * console.log(event); // prints ['bar'] [42]
207
+ * }
208
+ * // Unreachable here
209
+ * })();
210
+ *
211
+ * process.nextTick(() => ac.abort());
212
+ * ```
213
+ * @since v13.6.0, v12.16.0
214
+ * @param eventName The name of the event being listened for
215
+ * @return that iterates `eventName` events emitted by the `emitter`
216
+ */
77
217
  static on(emitter: NodeJS.EventEmitter, eventName: string, options?: StaticEventEmitterOptions): AsyncIterableIterator<any>;
78
- /** @deprecated since v4.0.0 */
218
+ /**
219
+ * A class method that returns the number of listeners for the given `eventName`registered on the given `emitter`.
220
+ *
221
+ * ```js
222
+ * const { EventEmitter, listenerCount } = require('events');
223
+ * const myEmitter = new EventEmitter();
224
+ * myEmitter.on('event', () => {});
225
+ * myEmitter.on('event', () => {});
226
+ * console.log(listenerCount(myEmitter, 'event'));
227
+ * // Prints: 2
228
+ * ```
229
+ * @since v0.9.12
230
+ * @deprecated Since v3.2.0 - Use `listenerCount` instead.
231
+ * @param emitter The emitter to query
232
+ * @param eventName The event name
233
+ */
79
234
  static listenerCount(emitter: NodeJS.EventEmitter, eventName: string | symbol): number;
80
235
  /**
81
- * Returns a list listener for a specific emitter event name.
236
+ * Returns a copy of the array of listeners for the event named `eventName`.
237
+ *
238
+ * For `EventEmitter`s this behaves exactly the same as calling `.listeners` on
239
+ * the emitter.
240
+ *
241
+ * For `EventTarget`s this is the only way to get the event listeners for the
242
+ * event target. This is useful for debugging and diagnostic purposes.
243
+ *
244
+ * ```js
245
+ * const { getEventListeners, EventEmitter } = require('events');
246
+ *
247
+ * {
248
+ * const ee = new EventEmitter();
249
+ * const listener = () => console.log('Events are fun');
250
+ * ee.on('foo', listener);
251
+ * getEventListeners(ee, 'foo'); // [listener]
252
+ * }
253
+ * {
254
+ * const et = new EventTarget();
255
+ * const listener = () => console.log('Events are fun');
256
+ * et.addEventListener('foo', listener);
257
+ * getEventListeners(et, 'foo'); // [listener]
258
+ * }
259
+ * ```
260
+ * @since v15.2.0
82
261
  */
83
- static getEventListener(emitter: DOMEventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
262
+ static getEventListeners(emitter: DOMEventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
84
263
  /**
85
264
  * This symbol shall be used to install a listener for only monitoring `'error'`
86
265
  * events. Listeners installed using this symbol are called before the regular
node/fs/promises.d.ts CHANGED
@@ -30,8 +30,9 @@ declare module 'fs/promises' {
30
30
  Mode,
31
31
  WatchOptions,
32
32
  WatchEventType,
33
+ CopyOptions,
33
34
  } from 'node:fs';
34
- interface FileChangeInfo<T extends (string | Buffer)> {
35
+ interface FileChangeInfo<T extends string | Buffer> {
35
36
  eventType: WatchEventType;
36
37
  filename: T;
37
38
  }
@@ -126,7 +127,7 @@ declare module 'fs/promises' {
126
127
  *
127
128
  * If `options` is a string, then it specifies the `encoding`.
128
129
  *
129
- * The `<FileHandle>` has to support reading.
130
+ * The `FileHandle` has to support reading.
130
131
  *
131
132
  * If one or more `filehandle.read()` calls are made on a file handle and then a`filehandle.readFile()` call is made, the data will be read from the current
132
133
  * position till the end of the file. It doesn't always read from the beginning
@@ -214,7 +215,7 @@ declare module 'fs/promises' {
214
215
  */
215
216
  truncate(len?: number): Promise<void>;
216
217
  /**
217
- * Change the file system timestamps of the object referenced by the `<FileHandle>` then resolves the promise with no arguments upon success.
218
+ * Change the file system timestamps of the object referenced by the `FileHandle` then resolves the promise with no arguments upon success.
218
219
  * @since v10.0.0
219
220
  */
220
221
  utimes(atime: string | number | Date, mtime: string | number | Date): Promise<void>;
@@ -224,7 +225,7 @@ declare module 'fs/promises' {
224
225
  *
225
226
  * If `options` is a string, then it specifies the `encoding`.
226
227
  *
227
- * The `<FileHandle>` has to support writing.
228
+ * The `FileHandle` has to support writing.
228
229
  *
229
230
  * It is unsafe to use `filehandle.writeFile()` multiple times on the same file
230
231
  * without waiting for the promise to be resolved (or rejected).
@@ -384,7 +385,7 @@ declare module 'fs/promises' {
384
385
  */
385
386
  function copyFile(src: PathLike, dest: PathLike, mode?: number): Promise<void>;
386
387
  /**
387
- * Opens a `<FileHandle>`.
388
+ * Opens a `FileHandle`.
388
389
  *
389
390
  * Refer to the POSIX [`open(2)`](http://man7.org/linux/man-pages/man2/open.2.html) documentation for more detail.
390
391
  *
@@ -471,9 +472,9 @@ declare module 'fs/promises' {
471
472
  * The optional `options` argument can be a string specifying an encoding, or an
472
473
  * object with an `encoding` property specifying the character encoding to use for
473
474
  * the filenames. If the `encoding` is set to `'buffer'`, the filenames returned
474
- * will be passed as `<Buffer>` objects.
475
+ * will be passed as `Buffer` objects.
475
476
  *
476
- * If `options.withFileTypes` is set to `true`, the resolved array will contain `<fs.Dirent>` objects.
477
+ * If `options.withFileTypes` is set to `true`, the resolved array will contain `fs.Dirent` objects.
477
478
  *
478
479
  * ```js
479
480
  * import { readdir } from 'fs/promises';
@@ -544,7 +545,7 @@ declare module 'fs/promises' {
544
545
  * The optional `options` argument can be a string specifying an encoding, or an
545
546
  * object with an `encoding` property specifying the character encoding to use for
546
547
  * the link path returned. If the `encoding` is set to `'buffer'`, the link path
547
- * returned will be passed as a `<Buffer>` object.
548
+ * returned will be passed as a `Buffer` object.
548
549
  * @since v10.0.0
549
550
  * @return Fulfills with the `linkString` upon success.
550
551
  */
@@ -677,7 +678,7 @@ declare module 'fs/promises' {
677
678
  * The optional `options` argument can be a string specifying an encoding, or an
678
679
  * object with an `encoding` property specifying the character encoding to use for
679
680
  * the path. If the `encoding` is set to `'buffer'`, the path returned will be
680
- * passed as a `<Buffer>` object.
681
+ * passed as a `Buffer` object.
681
682
  *
682
683
  * On Linux, when Node.js is linked against musl libc, the procfs file system must
683
684
  * be mounted on `/proc` in order for this function to work. Glibc does not have
@@ -739,13 +740,13 @@ declare module 'fs/promises' {
739
740
  */
740
741
  function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
741
742
  /**
742
- * 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.
743
+ * 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.
743
744
  *
744
745
  * The `encoding` option is ignored if `data` is a buffer.
745
746
  *
746
747
  * If `options` is a string, then it specifies the encoding.
747
748
  *
748
- * Any specified `<FileHandle>` has to support writing.
749
+ * Any specified `FileHandle` has to support writing.
749
750
  *
750
751
  * It is unsafe to use `fsPromises.writeFile()` multiple times on the same file
751
752
  * without waiting for the promise to be settled.
@@ -754,7 +755,7 @@ declare module 'fs/promises' {
754
755
  * method that performs multiple `write` calls internally to write the buffer
755
756
  * passed to it. For performance sensitive code consider using `fs.createWriteStream()`.
756
757
  *
757
- * It is possible to use an `<AbortSignal>` to cancel an `fsPromises.writeFile()`.
758
+ * It is possible to use an `AbortSignal` to cancel an `fsPromises.writeFile()`.
758
759
  * Cancelation is "best effort", and some amount of data is likely still
759
760
  * to be written.
760
761
  *
@@ -797,11 +798,11 @@ declare module 'fs/promises' {
797
798
  ): Promise<void>;
798
799
  /**
799
800
  * Asynchronously append data to a file, creating the file if it does not yet
800
- * exist. `data` can be a string or a `<Buffer>`.
801
+ * exist. `data` can be a string or a `Buffer`.
801
802
  *
802
803
  * If `options` is a string, then it specifies the `encoding`.
803
804
  *
804
- * The `path` may be specified as a `<FileHandle>` that has been opened
805
+ * The `path` may be specified as a `FileHandle` that has been opened
805
806
  * for appending (using `fsPromises.open()`).
806
807
  * @since v10.0.0
807
808
  * @param path filename or {FileHandle}
@@ -812,7 +813,7 @@ declare module 'fs/promises' {
812
813
  * Asynchronously reads the entire contents of a file.
813
814
  *
814
815
  * If no encoding is specified (using `options.encoding`), the data is returned
815
- * as a `<Buffer>` object. Otherwise, the data will be a string.
816
+ * as a `Buffer` object. Otherwise, the data will be a string.
816
817
  *
817
818
  * If `options` is a string, then it specifies the encoding.
818
819
  *
@@ -821,7 +822,7 @@ declare module 'fs/promises' {
821
822
  * with an error. On FreeBSD, a representation of the directory's contents will be
822
823
  * returned.
823
824
  *
824
- * It is possible to abort an ongoing `readFile` using an `<AbortSignal>`. If a
825
+ * It is possible to abort an ongoing `readFile` using an `AbortSignal`. If a
825
826
  * request is aborted the promise returned is rejected with an `AbortError`:
826
827
  *
827
828
  * ```js
@@ -845,7 +846,7 @@ declare module 'fs/promises' {
845
846
  * Aborting an ongoing request does not abort individual operating
846
847
  * system requests but rather the internal buffering `fs.readFile` performs.
847
848
  *
848
- * Any specified `<FileHandle>` has to support reading.
849
+ * Any specified `FileHandle` has to support reading.
849
850
  * @since v10.0.0
850
851
  * @param path filename or `FileHandle`
851
852
  * @return Fulfills with the contents of the file.
@@ -895,7 +896,7 @@ declare module 'fs/promises' {
895
896
  /**
896
897
  * Asynchronously open a directory for iterative scanning. See the POSIX[`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html) documentation for more detail.
897
898
  *
898
- * Creates an `<fs.Dir>`, which contains all further functions for reading from
899
+ * Creates an `fs.Dir`, which contains all further functions for reading from
899
900
  * and cleaning up the directory.
900
901
  *
901
902
  * The `encoding` option sets the encoding for the `path` while opening the
@@ -915,7 +916,7 @@ declare module 'fs/promises' {
915
916
  * }
916
917
  * ```
917
918
  *
918
- * When using the async iterator, the `<fs.Dir>` object will be automatically
919
+ * When using the async iterator, the `fs.Dir` object will be automatically
919
920
  * closed after the iterator exits.
920
921
  * @since v12.12.0
921
922
  * @return Fulfills with an {fs.Dir}.
@@ -977,6 +978,19 @@ declare module 'fs/promises' {
977
978
  * If `recursive` is not supplied, the default of `false` is used.
978
979
  */
979
980
  function watch(filename: PathLike, options: WatchOptions | string): AsyncIterable<FileChangeInfo<string>> | AsyncIterable<FileChangeInfo<Buffer>>;
981
+ /**
982
+ * Asynchronously copies the entire directory structure from `src` to `dest`,
983
+ * including subdirectories and files.
984
+ *
985
+ * When copying a directory to another directory, globs are not supported and
986
+ * behavior is similar to `cp dir1/ dir2/`.
987
+ * @since v16.7.0
988
+ * @experimental
989
+ * @param src source path to copy.
990
+ * @param dest destination path to copy to.
991
+ * @return Fulfills with `undefined` upon success.
992
+ */
993
+ function cp(source: string, destination: string, opts?: CopyOptions): Promise<void>;
980
994
  }
981
995
  declare module 'node:fs/promises' {
982
996
  export * from 'fs/promises';