@types/node 20.11.30 → 20.12.1
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/README.md +1 -1
- node/cluster.d.ts +165 -19
- node/dom-events.d.ts +2 -0
- node/fs/promises.d.ts +6 -0
- node/package.json +2 -2
- node/process.d.ts +15 -0
node/README.md
CHANGED
|
@@ -8,7 +8,7 @@ This package contains type definitions for node (https://nodejs.org/).
|
|
|
8
8
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node.
|
|
9
9
|
|
|
10
10
|
### Additional Details
|
|
11
|
-
* Last updated:
|
|
11
|
+
* Last updated: Sat, 30 Mar 2024 05:07:46 GMT
|
|
12
12
|
* Dependencies: [undici-types](https://npmjs.com/package/undici-types)
|
|
13
13
|
|
|
14
14
|
# Credits
|
node/cluster.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Clusters of Node.js processes can be used to run multiple instances of Node.js
|
|
3
|
-
* that can distribute workloads among their application threads. When process
|
|
4
|
-
*
|
|
5
|
-
* allows running multiple application threads within a single Node.js instance.
|
|
3
|
+
* that can distribute workloads among their application threads. When process isolation
|
|
4
|
+
* is not needed, use the [`worker_threads`](https://nodejs.org/docs/latest-v20.x/api/worker_threads.html)
|
|
5
|
+
* module instead, which allows running multiple application threads within a single Node.js instance.
|
|
6
6
|
*
|
|
7
7
|
* The cluster module allows easy creation of child processes that all share
|
|
8
8
|
* server ports.
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
* ```
|
|
51
51
|
*
|
|
52
52
|
* On Windows, it is not yet possible to set up a named pipe server in a worker.
|
|
53
|
-
* @see [source](https://github.com/nodejs/node/blob/v20.
|
|
53
|
+
* @see [source](https://github.com/nodejs/node/blob/v20.11.1/lib/cluster.js)
|
|
54
54
|
*/
|
|
55
55
|
declare module "cluster" {
|
|
56
56
|
import * as child from "node:child_process";
|
|
@@ -58,22 +58,74 @@ declare module "cluster" {
|
|
|
58
58
|
import * as net from "node:net";
|
|
59
59
|
type SerializationType = "json" | "advanced";
|
|
60
60
|
export interface ClusterSettings {
|
|
61
|
-
|
|
61
|
+
/**
|
|
62
|
+
* List of string arguments passed to the Node.js executable.
|
|
63
|
+
* @default process.execArgv
|
|
64
|
+
*/
|
|
65
|
+
execArgv?: string[] | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* File path to worker file.
|
|
68
|
+
* @default process.argv[1]
|
|
69
|
+
*/
|
|
62
70
|
exec?: string | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* String arguments passed to worker.
|
|
73
|
+
* @default process.argv.slice(2)
|
|
74
|
+
*/
|
|
63
75
|
args?: string[] | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Whether or not to send output to parent's stdio.
|
|
78
|
+
* @default false
|
|
79
|
+
*/
|
|
64
80
|
silent?: boolean | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Configures the stdio of forked processes. Because the cluster module relies on IPC to function, this configuration must
|
|
83
|
+
* contain an `'ipc'` entry. When this option is provided, it overrides `silent`. See [`child_prcess.spawn()`](https://nodejs.org/docs/latest-v20.x/api/child_process.html#child_processspawncommand-args-options)'s
|
|
84
|
+
* [`stdio`](https://nodejs.org/docs/latest-v20.x/api/child_process.html#optionsstdio).
|
|
85
|
+
*/
|
|
65
86
|
stdio?: any[] | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Sets the user identity of the process. (See [`setuid(2)`](https://man7.org/linux/man-pages/man2/setuid.2.html).)
|
|
89
|
+
*/
|
|
66
90
|
uid?: number | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Sets the group identity of the process. (See [`setgid(2)`](https://man7.org/linux/man-pages/man2/setgid.2.html).)
|
|
93
|
+
*/
|
|
67
94
|
gid?: number | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Sets inspector port of worker. This can be a number, or a function that takes no arguments and returns a number.
|
|
97
|
+
* By default each worker gets its own port, incremented from the primary's `process.debugPort`.
|
|
98
|
+
*/
|
|
68
99
|
inspectPort?: number | (() => number) | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Specify the kind of serialization used for sending messages between processes. Possible values are `'json'` and `'advanced'`.
|
|
102
|
+
* See [Advanced serialization for `child_process`](https://nodejs.org/docs/latest-v20.x/api/child_process.html#advanced-serialization) for more details.
|
|
103
|
+
* @default false
|
|
104
|
+
*/
|
|
69
105
|
serialization?: SerializationType | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Current working directory of the worker process.
|
|
108
|
+
* @default undefined (inherits from parent process)
|
|
109
|
+
*/
|
|
70
110
|
cwd?: string | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Hide the forked processes console window that would normally be created on Windows systems.
|
|
113
|
+
* @default false
|
|
114
|
+
*/
|
|
71
115
|
windowsHide?: boolean | undefined;
|
|
72
116
|
}
|
|
73
117
|
export interface Address {
|
|
74
118
|
address: string;
|
|
75
119
|
port: number;
|
|
76
|
-
|
|
120
|
+
/**
|
|
121
|
+
* The `addressType` is one of:
|
|
122
|
+
*
|
|
123
|
+
* * `4` (TCPv4)
|
|
124
|
+
* * `6` (TCPv6)
|
|
125
|
+
* * `-1` (Unix domain socket)
|
|
126
|
+
* * `'udp4'` or `'udp6'` (UDPv4 or UDPv6)
|
|
127
|
+
*/
|
|
128
|
+
addressType: 4 | 6 | -1 | "udp4" | "udp6";
|
|
77
129
|
}
|
|
78
130
|
/**
|
|
79
131
|
* A `Worker` object contains all public information and method about a worker.
|
|
@@ -83,17 +135,17 @@ declare module "cluster" {
|
|
|
83
135
|
*/
|
|
84
136
|
export class Worker extends EventEmitter {
|
|
85
137
|
/**
|
|
86
|
-
* Each new worker is given its own unique id, this id is stored in the`id`.
|
|
138
|
+
* Each new worker is given its own unique id, this id is stored in the `id`.
|
|
87
139
|
*
|
|
88
|
-
* While a worker is alive, this is the key that indexes it in`cluster.workers`.
|
|
140
|
+
* While a worker is alive, this is the key that indexes it in `cluster.workers`.
|
|
89
141
|
* @since v0.8.0
|
|
90
142
|
*/
|
|
91
143
|
id: number;
|
|
92
144
|
/**
|
|
93
|
-
* All workers are created using `child_process.fork()
|
|
94
|
-
* from this function is stored as `.process`. In a worker, the global `process`is stored.
|
|
145
|
+
* All workers are created using [`child_process.fork()`](https://nodejs.org/docs/latest-v20.x/api/child_process.html#child_processforkmodulepath-args-options), the returned object
|
|
146
|
+
* from this function is stored as `.process`. In a worker, the global `process` is stored.
|
|
95
147
|
*
|
|
96
|
-
* See:
|
|
148
|
+
* See: [Child Process module](https://nodejs.org/docs/latest-v20.x/api/child_process.html#child_processforkmodulepath-args-options).
|
|
97
149
|
*
|
|
98
150
|
* Workers will call `process.exit(0)` if the `'disconnect'` event occurs
|
|
99
151
|
* on `process` and `.exitedAfterDisconnect` is not `true`. This protects against
|
|
@@ -104,9 +156,9 @@ declare module "cluster" {
|
|
|
104
156
|
/**
|
|
105
157
|
* Send a message to a worker or primary, optionally with a handle.
|
|
106
158
|
*
|
|
107
|
-
* In the primary, this sends a message to a specific worker. It is identical to `ChildProcess.send()
|
|
159
|
+
* In the primary, this sends a message to a specific worker. It is identical to [`ChildProcess.send()`](https://nodejs.org/docs/latest-v20.x/api/child_process.html#subprocesssendmessage-sendhandle-options-callback).
|
|
108
160
|
*
|
|
109
|
-
* In a worker, this sends a message to the primary. It is identical to`process.send()`.
|
|
161
|
+
* In a worker, this sends a message to the primary. It is identical to `process.send()`.
|
|
110
162
|
*
|
|
111
163
|
* This example will echo back all messages from the primary:
|
|
112
164
|
*
|
|
@@ -122,7 +174,7 @@ declare module "cluster" {
|
|
|
122
174
|
* }
|
|
123
175
|
* ```
|
|
124
176
|
* @since v0.7.0
|
|
125
|
-
* @param options The `options` argument, if present, is an object used to parameterize the sending of certain types of handles.
|
|
177
|
+
* @param options The `options` argument, if present, is an object used to parameterize the sending of certain types of handles.
|
|
126
178
|
*/
|
|
127
179
|
send(message: child.Serializable, callback?: (error: Error | null) => void): boolean;
|
|
128
180
|
send(
|
|
@@ -138,7 +190,7 @@ declare module "cluster" {
|
|
|
138
190
|
): boolean;
|
|
139
191
|
/**
|
|
140
192
|
* This function will kill the worker. In the primary worker, it does this by
|
|
141
|
-
* disconnecting the `worker.process`, and once disconnected, killing with`signal`. In the worker, it does it by killing the process with `signal`.
|
|
193
|
+
* disconnecting the `worker.process`, and once disconnected, killing with `signal`. In the worker, it does it by killing the process with `signal`.
|
|
142
194
|
*
|
|
143
195
|
* The `kill()` function kills the worker process without waiting for a graceful
|
|
144
196
|
* disconnect, it has the same behavior as `worker.process.kill()`.
|
|
@@ -146,7 +198,7 @@ declare module "cluster" {
|
|
|
146
198
|
* This method is aliased as `worker.destroy()` for backwards compatibility.
|
|
147
199
|
*
|
|
148
200
|
* In a worker, `process.kill()` exists, but it is not this function;
|
|
149
|
-
* it is `kill()
|
|
201
|
+
* it is [`kill()`](https://nodejs.org/docs/latest-v20.x/api/process.html#processkillpid-signal).
|
|
150
202
|
* @since v0.9.12
|
|
151
203
|
* @param [signal='SIGTERM'] Name of the kill signal to send to the worker process.
|
|
152
204
|
*/
|
|
@@ -156,7 +208,7 @@ declare module "cluster" {
|
|
|
156
208
|
* In a worker, this function will close all servers, wait for the `'close'` event
|
|
157
209
|
* on those servers, and then disconnect the IPC channel.
|
|
158
210
|
*
|
|
159
|
-
* In the primary, an internal message is sent to the worker causing it to call`.disconnect()` on itself.
|
|
211
|
+
* In the primary, an internal message is sent to the worker causing it to call `.disconnect()` on itself.
|
|
160
212
|
*
|
|
161
213
|
* Causes `.exitedAfterDisconnect` to be set.
|
|
162
214
|
*
|
|
@@ -336,20 +388,114 @@ declare module "cluster" {
|
|
|
336
388
|
}
|
|
337
389
|
export interface Cluster extends EventEmitter {
|
|
338
390
|
disconnect(callback?: () => void): void;
|
|
391
|
+
/**
|
|
392
|
+
* Spawn a new worker process.
|
|
393
|
+
*
|
|
394
|
+
* This can only be called from the primary process.
|
|
395
|
+
* @param env Key/value pairs to add to worker process environment.
|
|
396
|
+
* @since v0.6.0
|
|
397
|
+
*/
|
|
339
398
|
fork(env?: any): Worker;
|
|
340
399
|
/** @deprecated since v16.0.0 - use isPrimary. */
|
|
341
400
|
readonly isMaster: boolean;
|
|
401
|
+
/**
|
|
402
|
+
* True if the process is a primary. This is determined by the `process.env.NODE_UNIQUE_ID`. If `process.env.NODE_UNIQUE_ID`
|
|
403
|
+
* is undefined, then `isPrimary` is `true`.
|
|
404
|
+
* @since v16.0.0
|
|
405
|
+
*/
|
|
342
406
|
readonly isPrimary: boolean;
|
|
407
|
+
/**
|
|
408
|
+
* True if the process is not a primary (it is the negation of `cluster.isPrimary`).
|
|
409
|
+
* @since v0.6.0
|
|
410
|
+
*/
|
|
343
411
|
readonly isWorker: boolean;
|
|
412
|
+
/**
|
|
413
|
+
* The scheduling policy, either `cluster.SCHED_RR` for round-robin or `cluster.SCHED_NONE` to leave it to the operating system. This is a
|
|
414
|
+
* global setting and effectively frozen once either the first worker is spawned, or [`.setupPrimary()`](https://nodejs.org/docs/latest-v20.x/api/cluster.html#clustersetupprimarysettings)
|
|
415
|
+
* is called, whichever comes first.
|
|
416
|
+
*
|
|
417
|
+
* `SCHED_RR` is the default on all operating systems except Windows. Windows will change to `SCHED_RR` once libuv is able to effectively distribute
|
|
418
|
+
* IOCP handles without incurring a large performance hit.
|
|
419
|
+
*
|
|
420
|
+
* `cluster.schedulingPolicy` can also be set through the `NODE_CLUSTER_SCHED_POLICY` environment variable. Valid values are `'rr'` and `'none'`.
|
|
421
|
+
* @since v0.11.2
|
|
422
|
+
*/
|
|
344
423
|
schedulingPolicy: number;
|
|
424
|
+
/**
|
|
425
|
+
* After calling [`.setupPrimary()`](https://nodejs.org/docs/latest-v20.x/api/cluster.html#clustersetupprimarysettings)
|
|
426
|
+
* (or [`.fork()`](https://nodejs.org/docs/latest-v20.x/api/cluster.html#clusterforkenv)) this settings object will contain
|
|
427
|
+
* the settings, including the default values.
|
|
428
|
+
*
|
|
429
|
+
* This object is not intended to be changed or set manually.
|
|
430
|
+
* @since v0.7.1
|
|
431
|
+
*/
|
|
345
432
|
readonly settings: ClusterSettings;
|
|
346
|
-
/** @deprecated since v16.0.0 - use setupPrimary. */
|
|
433
|
+
/** @deprecated since v16.0.0 - use [`.setupPrimary()`](https://nodejs.org/docs/latest-v20.x/api/cluster.html#clustersetupprimarysettings) instead. */
|
|
347
434
|
setupMaster(settings?: ClusterSettings): void;
|
|
348
435
|
/**
|
|
349
|
-
* `setupPrimary` is used to change the default 'fork' behavior. Once called, the settings will be present in cluster.settings
|
|
436
|
+
* `setupPrimary` is used to change the default 'fork' behavior. Once called, the settings will be present in `cluster.settings`.
|
|
437
|
+
*
|
|
438
|
+
* Any settings changes only affect future calls to [`.fork()`](https://nodejs.org/docs/latest-v20.x/api/cluster.html#clusterforkenv)
|
|
439
|
+
* and have no effect on workers that are already running.
|
|
440
|
+
*
|
|
441
|
+
* The only attribute of a worker that cannot be set via `.setupPrimary()` is the `env` passed to
|
|
442
|
+
* [`.fork()`](https://nodejs.org/docs/latest-v20.x/api/cluster.html#clusterforkenv).
|
|
443
|
+
*
|
|
444
|
+
* The defaults above apply to the first call only; the defaults for later calls are the current values at the time of
|
|
445
|
+
* `cluster.setupPrimary()` is called.
|
|
446
|
+
*
|
|
447
|
+
* ```js
|
|
448
|
+
* import cluster from 'node:cluster';
|
|
449
|
+
*
|
|
450
|
+
* cluster.setupPrimary({
|
|
451
|
+
* exec: 'worker.js',
|
|
452
|
+
* args: ['--use', 'https'],
|
|
453
|
+
* silent: true,
|
|
454
|
+
* });
|
|
455
|
+
* cluster.fork(); // https worker
|
|
456
|
+
* cluster.setupPrimary({
|
|
457
|
+
* exec: 'worker.js',
|
|
458
|
+
* args: ['--use', 'http'],
|
|
459
|
+
* });
|
|
460
|
+
* cluster.fork(); // http worker
|
|
461
|
+
* ```
|
|
462
|
+
*
|
|
463
|
+
* This can only be called from the primary process.
|
|
464
|
+
* @since v16.0.0
|
|
350
465
|
*/
|
|
351
466
|
setupPrimary(settings?: ClusterSettings): void;
|
|
467
|
+
/**
|
|
468
|
+
* A reference to the current worker object. Not available in the primary process.
|
|
469
|
+
*
|
|
470
|
+
* ```js
|
|
471
|
+
* import cluster from 'node:cluster';
|
|
472
|
+
*
|
|
473
|
+
* if (cluster.isPrimary) {
|
|
474
|
+
* console.log('I am primary');
|
|
475
|
+
* cluster.fork();
|
|
476
|
+
* cluster.fork();
|
|
477
|
+
* } else if (cluster.isWorker) {
|
|
478
|
+
* console.log(`I am worker #${cluster.worker.id}`);
|
|
479
|
+
* }
|
|
480
|
+
* ```
|
|
481
|
+
* @since v0.7.0
|
|
482
|
+
*/
|
|
352
483
|
readonly worker?: Worker | undefined;
|
|
484
|
+
/**
|
|
485
|
+
* A hash that stores the active worker objects, keyed by `id` field. This makes it easy to loop through all the workers. It is only available in the primary process.
|
|
486
|
+
*
|
|
487
|
+
* A worker is removed from `cluster.workers` after the worker has disconnected _and_ exited. The order between these two events cannot be determined in advance. However, it
|
|
488
|
+
* is guaranteed that the removal from the `cluster.workers` list happens before the last `'disconnect'` or `'exit'` event is emitted.
|
|
489
|
+
*
|
|
490
|
+
* ```js
|
|
491
|
+
* import cluster from 'node:cluster';
|
|
492
|
+
*
|
|
493
|
+
* for (const worker of Object.values(cluster.workers)) {
|
|
494
|
+
* worker.send('big announcement to all workers');
|
|
495
|
+
* }
|
|
496
|
+
* ```
|
|
497
|
+
* @since v0.7.0
|
|
498
|
+
*/
|
|
353
499
|
readonly workers?: NodeJS.Dict<Worker> | undefined;
|
|
354
500
|
readonly SCHED_NONE: number;
|
|
355
501
|
readonly SCHED_RR: number;
|
node/dom-events.d.ts
CHANGED
|
@@ -89,6 +89,8 @@ interface AddEventListenerOptions extends EventListenerOptions {
|
|
|
89
89
|
once?: boolean;
|
|
90
90
|
/** When `true`, serves as a hint that the listener will not call the `Event` object's `preventDefault()` method. Default: false. */
|
|
91
91
|
passive?: boolean;
|
|
92
|
+
/** The listener will be removed when the given AbortSignal object's `abort()` method is called. */
|
|
93
|
+
signal?: AbortSignal;
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
interface EventListener {
|
node/fs/promises.d.ts
CHANGED
|
@@ -1008,6 +1008,12 @@ declare module "fs/promises" {
|
|
|
1008
1008
|
| (ObjectEncodingOptions & {
|
|
1009
1009
|
mode?: Mode | undefined;
|
|
1010
1010
|
flag?: OpenMode | undefined;
|
|
1011
|
+
/**
|
|
1012
|
+
* If all data is successfully written to the file, and `flush`
|
|
1013
|
+
* is `true`, `filehandle.sync()` is used to flush the data.
|
|
1014
|
+
* @default false
|
|
1015
|
+
*/
|
|
1016
|
+
flush?: boolean | undefined;
|
|
1011
1017
|
} & Abortable)
|
|
1012
1018
|
| BufferEncoding
|
|
1013
1019
|
| null,
|
node/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/node",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.12.1",
|
|
4
4
|
"description": "TypeScript definitions for node",
|
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
|
|
6
6
|
"license": "MIT",
|
|
@@ -212,6 +212,6 @@
|
|
|
212
212
|
"dependencies": {
|
|
213
213
|
"undici-types": "~5.26.4"
|
|
214
214
|
},
|
|
215
|
-
"typesPublisherContentHash": "
|
|
215
|
+
"typesPublisherContentHash": "36951b30e57ad53cbd8833203ba2cba0fc7b0abdc851f9292af12a58cd72a4c1",
|
|
216
216
|
"typeScriptVersion": "4.7"
|
|
217
217
|
}
|
node/process.d.ts
CHANGED
|
@@ -1044,6 +1044,21 @@ declare module "process" {
|
|
|
1044
1044
|
* @param [signal='SIGTERM'] The signal to send, either as a string or number.
|
|
1045
1045
|
*/
|
|
1046
1046
|
kill(pid: number, signal?: string | number): true;
|
|
1047
|
+
/**
|
|
1048
|
+
* Loads the environment configuration from a `.env` file into `process.env`. If
|
|
1049
|
+
* the file is not found, error will be thrown.
|
|
1050
|
+
*
|
|
1051
|
+
* To load a specific .env file by specifying its path, use the following code:
|
|
1052
|
+
*
|
|
1053
|
+
* ```js
|
|
1054
|
+
* import { loadEnvFile } from 'node:process';
|
|
1055
|
+
*
|
|
1056
|
+
* loadEnvFile('./development.env')
|
|
1057
|
+
* ```
|
|
1058
|
+
* @since v20.12.0
|
|
1059
|
+
* @param path The path to the .env file
|
|
1060
|
+
*/
|
|
1061
|
+
loadEnvFile(path?: string | URL | Buffer): void;
|
|
1047
1062
|
/**
|
|
1048
1063
|
* The `process.pid` property returns the PID of the process.
|
|
1049
1064
|
*
|