@types/node 16.4.1 → 16.4.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.
node/trace_events.d.ts CHANGED
@@ -1,3 +1,80 @@
1
+ /**
2
+ * The `trace_events` module provides a mechanism to centralize tracing information
3
+ * generated by V8, Node.js core, and userspace code.
4
+ *
5
+ * Tracing can be enabled with the `--trace-event-categories` command-line flag
6
+ * or by using the `trace_events` module. The `--trace-event-categories` flag
7
+ * accepts a list of comma-separated category names.
8
+ *
9
+ * The available categories are:
10
+ *
11
+ * * `node`: An empty placeholder.
12
+ * * `node.async_hooks`: Enables capture of detailed `async_hooks` trace data.
13
+ * The `async_hooks` events have a unique `asyncId` and a special `triggerId` `triggerAsyncId` property.
14
+ * * `node.bootstrap`: Enables capture of Node.js bootstrap milestones.
15
+ * * `node.console`: Enables capture of `console.time()` and `console.count()`output.
16
+ * * `node.dns.native`: Enables capture of trace data for DNS queries.
17
+ * * `node.environment`: Enables capture of Node.js Environment milestones.
18
+ * * `node.fs.sync`: Enables capture of trace data for file system sync methods.
19
+ * * `node.perf`: Enables capture of `Performance API` measurements.
20
+ * * `node.perf.usertiming`: Enables capture of only Performance API User Timing
21
+ * measures and marks.
22
+ * * `node.perf.timerify`: Enables capture of only Performance API timerify
23
+ * measurements.
24
+ * * `node.promises.rejections`: Enables capture of trace data tracking the number
25
+ * of unhandled Promise rejections and handled-after-rejections.
26
+ * * `node.vm.script`: Enables capture of trace data for the `vm` module's`runInNewContext()`, `runInContext()`, and `runInThisContext()` methods.
27
+ * * `v8`: The `V8` events are GC, compiling, and execution related.
28
+ *
29
+ * By default the `node`, `node.async_hooks`, and `v8` categories are enabled.
30
+ *
31
+ * ```bash
32
+ * node --trace-event-categories v8,node,node.async_hooks server.js
33
+ * ```
34
+ *
35
+ * Prior versions of Node.js required the use of the `--trace-events-enabled`flag to enable trace events. This requirement has been removed. However, the`--trace-events-enabled` flag _may_ still be
36
+ * used and will enable the`node`, `node.async_hooks`, and `v8` trace event categories by default.
37
+ *
38
+ * ```bash
39
+ * node --trace-events-enabled
40
+ *
41
+ * # is equivalent to
42
+ *
43
+ * node --trace-event-categories v8,node,node.async_hooks
44
+ * ```
45
+ *
46
+ * Alternatively, trace events may be enabled using the `trace_events` module:
47
+ *
48
+ * ```js
49
+ * const trace_events = require('trace_events');
50
+ * const tracing = trace_events.createTracing({ categories: ['node.perf'] });
51
+ * tracing.enable(); // Enable trace event capture for the 'node.perf' category
52
+ *
53
+ * // do work
54
+ *
55
+ * tracing.disable(); // Disable trace event capture for the 'node.perf' category
56
+ * ```
57
+ *
58
+ * Running Node.js with tracing enabled will produce log files that can be opened
59
+ * in the [`chrome://tracing`](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool)tab of Chrome.
60
+ *
61
+ * The logging file is by default called `node_trace.${rotation}.log`, where`${rotation}` is an incrementing log-rotation id. The filepath pattern can
62
+ * be specified with `--trace-event-file-pattern` that accepts a template
63
+ * string that supports `${rotation}` and `${pid}`:
64
+ *
65
+ * ```bash
66
+ * node --trace-event-categories v8 --trace-event-file-pattern '${pid}-${rotation}.log' server.js
67
+ * ```
68
+ *
69
+ * The tracing system uses the same time source
70
+ * as the one used by `process.hrtime()`.
71
+ * However the trace-event timestamps are expressed in microseconds,
72
+ * unlike `process.hrtime()` which returns nanoseconds.
73
+ *
74
+ * The features from this module are not available in `Worker` threads.
75
+ * @experimental
76
+ * @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/trace_events.js)
77
+ */
1
78
  declare module 'trace_events' {
2
79
  /**
3
80
  * The `Tracing` object is used to enable or disable tracing for sets of
@@ -15,7 +92,6 @@ declare module 'trace_events' {
15
92
  * `Tracing` object.
16
93
  */
17
94
  readonly categories: string;
18
-
19
95
  /**
20
96
  * Disables this `Tracing` object.
21
97
  *
@@ -24,19 +100,16 @@ declare module 'trace_events' {
24
100
  * will be disabled.
25
101
  */
26
102
  disable(): void;
27
-
28
103
  /**
29
104
  * Enables this `Tracing` object for the set of categories covered by
30
105
  * the `Tracing` object.
31
106
  */
32
107
  enable(): void;
33
-
34
108
  /**
35
109
  * `true` only if the `Tracing` object has been enabled.
36
110
  */
37
111
  readonly enabled: boolean;
38
112
  }
39
-
40
113
  interface CreateTracingOptions {
41
114
  /**
42
115
  * An array of trace category names. Values included in the array are
@@ -45,21 +118,44 @@ declare module 'trace_events' {
45
118
  */
46
119
  categories: string[];
47
120
  }
48
-
49
121
  /**
50
- * Creates and returns a Tracing object for the given set of categories.
122
+ * Creates and returns a `Tracing` object for the given set of `categories`.
123
+ *
124
+ * ```js
125
+ * const trace_events = require('trace_events');
126
+ * const categories = ['node.perf', 'node.async_hooks'];
127
+ * const tracing = trace_events.createTracing({ categories });
128
+ * tracing.enable();
129
+ * // do stuff
130
+ * tracing.disable();
131
+ * ```
132
+ * @since v10.0.0
133
+ * @return .
51
134
  */
52
135
  function createTracing(options: CreateTracingOptions): Tracing;
53
-
54
136
  /**
55
137
  * Returns a comma-separated list of all currently-enabled trace event
56
- * categories. The current set of enabled trace event categories is
57
- * determined by the union of all currently-enabled `Tracing` objects and
58
- * any categories enabled using the `--trace-event-categories` flag.
138
+ * categories. The current set of enabled trace event categories is determined
139
+ * by the _union_ of all currently-enabled `Tracing` objects and any categories
140
+ * enabled using the `--trace-event-categories` flag.
141
+ *
142
+ * Given the file `test.js` below, the command`node --trace-event-categories node.perf test.js` will print`'node.async_hooks,node.perf'` to the console.
143
+ *
144
+ * ```js
145
+ * const trace_events = require('trace_events');
146
+ * const t1 = trace_events.createTracing({ categories: ['node.async_hooks'] });
147
+ * const t2 = trace_events.createTracing({ categories: ['node.perf'] });
148
+ * const t3 = trace_events.createTracing({ categories: ['v8'] });
149
+ *
150
+ * t1.enable();
151
+ * t2.enable();
152
+ *
153
+ * console.log(trace_events.getEnabledCategories());
154
+ * ```
155
+ * @since v10.0.0
59
156
  */
60
157
  function getEnabledCategories(): string | undefined;
61
158
  }
62
-
63
159
  declare module 'node:trace_events' {
64
160
  export * from 'trace_events';
65
161
  }
node/tty.d.ts CHANGED
@@ -1,11 +1,70 @@
1
+ /**
2
+ * The `tty` module provides the `tty.ReadStream` and `tty.WriteStream` classes.
3
+ * In most cases, it will not be necessary or possible to use this module directly.
4
+ * However, it can be accessed using:
5
+ *
6
+ * ```js
7
+ * const tty = require('tty');
8
+ * ```
9
+ *
10
+ * When Node.js detects that it is being run with a text terminal ("TTY")
11
+ * attached, `process.stdin` will, by default, be initialized as an instance of`tty.ReadStream` and both `process.stdout` and `process.stderr` will, by
12
+ * default, be instances of `tty.WriteStream`. The preferred method of determining
13
+ * whether Node.js is being run within a TTY context is to check that the value of
14
+ * the `process.stdout.isTTY` property is `true`:
15
+ *
16
+ * ```console
17
+ * $ node -p -e "Boolean(process.stdout.isTTY)"
18
+ * true
19
+ * $ node -p -e "Boolean(process.stdout.isTTY)" | cat
20
+ * false
21
+ * ```
22
+ *
23
+ * In most cases, there should be little to no reason for an application to
24
+ * manually create instances of the `tty.ReadStream` and `tty.WriteStream`classes.
25
+ * @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/tty.js)
26
+ */
1
27
  declare module 'tty' {
2
28
  import * as net from 'node:net';
3
-
29
+ /**
30
+ * The `tty.isatty()` method returns `true` if the given `fd` is associated with
31
+ * a TTY and `false` if it is not, including whenever `fd` is not a non-negative
32
+ * integer.
33
+ * @since v0.5.8
34
+ * @param fd A numeric file descriptor
35
+ */
4
36
  function isatty(fd: number): boolean;
37
+ /**
38
+ * * Extends: `<net.Socket>`
39
+ *
40
+ * Represents the readable side of a TTY. In normal circumstances `process.stdin` will be the only `tty.ReadStream` instance in a Node.js
41
+ * process and there should be no reason to create additional instances.
42
+ * @since v0.5.8
43
+ */
5
44
  class ReadStream extends net.Socket {
6
45
  constructor(fd: number, options?: net.SocketConstructorOpts);
46
+ /**
47
+ * A `boolean` that is `true` if the TTY is currently configured to operate as a
48
+ * raw device. Defaults to `false`.
49
+ * @since v0.7.7
50
+ */
7
51
  isRaw: boolean;
52
+ /**
53
+ * Allows configuration of `tty.ReadStream` so that it operates as a raw device.
54
+ *
55
+ * When in raw mode, input is always available character-by-character, not
56
+ * including modifiers. Additionally, all special processing of characters by the
57
+ * terminal is disabled, including echoing input characters.Ctrl+C will no longer cause a `SIGINT` when in this mode.
58
+ * @since v0.7.7
59
+ * @param mode If `true`, configures the `tty.ReadStream` to operate as a raw device. If `false`, configures the `tty.ReadStream` to operate in its default mode. The `readStream.isRaw`
60
+ * property will be set to the resulting mode.
61
+ * @return The read stream instance.
62
+ */
8
63
  setRawMode(mode: boolean): this;
64
+ /**
65
+ * A `boolean` that is always `true` for `tty.ReadStream` instances.
66
+ * @since v0.5.8
67
+ */
9
68
  isTTY: boolean;
10
69
  }
11
70
  /**
@@ -14,57 +73,138 @@ declare module 'tty' {
14
73
  * 1 - to the right from cursor
15
74
  */
16
75
  type Direction = -1 | 0 | 1;
76
+ /**
77
+ * * Extends: `<net.Socket>`
78
+ *
79
+ * Represents the writable side of a TTY. In normal circumstances,`process.stdout` and `process.stderr` will be the only`tty.WriteStream` instances created for a Node.js process and there
80
+ * should be no reason to create additional instances.
81
+ * @since v0.5.8
82
+ */
17
83
  class WriteStream extends net.Socket {
18
84
  constructor(fd: number);
19
85
  addListener(event: string, listener: (...args: any[]) => void): this;
20
- addListener(event: "resize", listener: () => void): this;
21
-
86
+ addListener(event: 'resize', listener: () => void): this;
22
87
  emit(event: string | symbol, ...args: any[]): boolean;
23
- emit(event: "resize"): boolean;
24
-
88
+ emit(event: 'resize'): boolean;
25
89
  on(event: string, listener: (...args: any[]) => void): this;
26
- on(event: "resize", listener: () => void): this;
27
-
90
+ on(event: 'resize', listener: () => void): this;
28
91
  once(event: string, listener: (...args: any[]) => void): this;
29
- once(event: "resize", listener: () => void): this;
30
-
92
+ once(event: 'resize', listener: () => void): this;
31
93
  prependListener(event: string, listener: (...args: any[]) => void): this;
32
- prependListener(event: "resize", listener: () => void): this;
33
-
94
+ prependListener(event: 'resize', listener: () => void): this;
34
95
  prependOnceListener(event: string, listener: (...args: any[]) => void): this;
35
- prependOnceListener(event: "resize", listener: () => void): this;
36
-
96
+ prependOnceListener(event: 'resize', listener: () => void): this;
37
97
  /**
38
- * Clears the current line of this WriteStream in a direction identified by `dir`.
98
+ * `writeStream.clearLine()` clears the current line of this `WriteStream` in a
99
+ * direction identified by `dir`.
100
+ * @since v0.7.7
101
+ * @param callback Invoked once the operation completes.
102
+ * @return `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
39
103
  */
40
104
  clearLine(dir: Direction, callback?: () => void): boolean;
41
105
  /**
42
- * Clears this `WriteStream` from the current cursor down.
106
+ * `writeStream.clearScreenDown()` clears this `WriteStream` from the current
107
+ * cursor down.
108
+ * @since v0.7.7
109
+ * @param callback Invoked once the operation completes.
110
+ * @return `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
43
111
  */
44
112
  clearScreenDown(callback?: () => void): boolean;
45
113
  /**
46
- * Moves this WriteStream's cursor to the specified position.
114
+ * `writeStream.cursorTo()` moves this `WriteStream`'s cursor to the specified
115
+ * position.
116
+ * @since v0.7.7
117
+ * @param callback Invoked once the operation completes.
118
+ * @return `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
47
119
  */
48
120
  cursorTo(x: number, y?: number, callback?: () => void): boolean;
49
121
  cursorTo(x: number, callback: () => void): boolean;
50
122
  /**
51
- * Moves this WriteStream's cursor relative to its current position.
123
+ * `writeStream.moveCursor()` moves this `WriteStream`'s cursor _relative_ to its
124
+ * current position.
125
+ * @since v0.7.7
126
+ * @param callback Invoked once the operation completes.
127
+ * @return `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
52
128
  */
53
129
  moveCursor(dx: number, dy: number, callback?: () => void): boolean;
54
130
  /**
55
- * @default `process.env`
131
+ * Returns:
132
+ *
133
+ * * `1` for 2,
134
+ * * `4` for 16,
135
+ * * `8` for 256,
136
+ * * `24` for 16,777,216
137
+ *
138
+ * colors supported.
139
+ *
140
+ * Use this to determine what colors the terminal supports. Due to the nature of
141
+ * colors in terminals it is possible to either have false positives or false
142
+ * negatives. It depends on process information and the environment variables that
143
+ * may lie about what terminal is used.
144
+ * It is possible to pass in an `env` object to simulate the usage of a specific
145
+ * terminal. This can be useful to check how specific environment settings behave.
146
+ *
147
+ * To enforce a specific color support, use one of the below environment settings.
148
+ *
149
+ * * 2 colors: `FORCE_COLOR = 0` (Disables colors)
150
+ * * 16 colors: `FORCE_COLOR = 1`
151
+ * * 256 colors: `FORCE_COLOR = 2`
152
+ * * 16,777,216 colors: `FORCE_COLOR = 3`
153
+ *
154
+ * Disabling color support is also possible by using the `NO_COLOR` and`NODE_DISABLE_COLORS` environment variables.
155
+ * @since v9.9.0
156
+ * @param env An object containing the environment variables to check. This enables simulating the usage of a specific terminal.
157
+ */
158
+ getColorDepth(env?: object): number;
159
+ /**
160
+ * Returns `true` if the `writeStream` supports at least as many colors as provided
161
+ * in `count`. Minimum support is 2 (black and white).
162
+ *
163
+ * This has the same false positives and negatives as described in `writeStream.getColorDepth()`.
164
+ *
165
+ * ```js
166
+ * process.stdout.hasColors();
167
+ * // Returns true or false depending on if `stdout` supports at least 16 colors.
168
+ * process.stdout.hasColors(256);
169
+ * // Returns true or false depending on if `stdout` supports at least 256 colors.
170
+ * process.stdout.hasColors({ TMUX: '1' });
171
+ * // Returns true.
172
+ * process.stdout.hasColors(2 ** 24, { TMUX: '1' });
173
+ * // Returns false (the environment setting pretends to support 2 ** 8 colors).
174
+ * ```
175
+ * @since v11.13.0, v10.16.0
176
+ * @param count The number of colors that are requested (minimum 2).
177
+ * @param env An object containing the environment variables to check. This enables simulating the usage of a specific terminal.
178
+ */
179
+ hasColors(count?: number): boolean;
180
+ hasColors(env?: object): boolean;
181
+ hasColors(count: number, env?: object): boolean;
182
+ /**
183
+ * `writeStream.getWindowSize()` returns the size of the `TTY` corresponding to this `WriteStream`. The array is of the type`[numColumns, numRows]` where `numColumns` and `numRows` represent
184
+ * the number
185
+ * of columns and rows in the corresponding `TTY`.
186
+ * @since v0.7.7
56
187
  */
57
- getColorDepth(env?: {}): number;
58
- hasColors(depth?: number): boolean;
59
- hasColors(env?: {}): boolean;
60
- hasColors(depth: number, env?: {}): boolean;
61
188
  getWindowSize(): [number, number];
189
+ /**
190
+ * A `number` specifying the number of columns the TTY currently has. This property
191
+ * is updated whenever the `'resize'` event is emitted.
192
+ * @since v0.7.7
193
+ */
62
194
  columns: number;
195
+ /**
196
+ * A `number` specifying the number of rows the TTY currently has. This property
197
+ * is updated whenever the `'resize'` event is emitted.
198
+ * @since v0.7.7
199
+ */
63
200
  rows: number;
201
+ /**
202
+ * A `boolean` that is always `true`.
203
+ * @since v0.5.8
204
+ */
64
205
  isTTY: boolean;
65
206
  }
66
207
  }
67
-
68
208
  declare module 'node:tty' {
69
209
  export * from 'tty';
70
210
  }