@types/node 20.11.29 → 20.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. node/README.md +1 -1
  2. node/cluster.d.ts +165 -19
  3. node/package.json +2 -2
  4. node/process.d.ts +15 -0
  5. node/wasi.d.ts +12 -10
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: Mon, 18 Mar 2024 19:35:28 GMT
11
+ * Last updated: Sat, 30 Mar 2024 04:35:27 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
- * isolation is not needed, use the `worker_threads` module instead, which
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.2.0/lib/cluster.js)
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
- execArgv?: string[] | undefined; // default: process.execArgv
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
- addressType: number | "udp4" | "udp6"; // 4, 6, -1, "udp4", "udp6"
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()`, the returned object
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: `Child Process module`.
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. `options` supports the following properties:
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/node",
3
- "version": "20.11.29",
3
+ "version": "20.12.0",
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": "601e89c10ccbef86517c0e5c93b1ded9d6c14a61a4f2ddfde003e0eac55e8f2f",
215
+ "typesPublisherContentHash": "c3429c6538fb2d25096eb610dc4ca612cad0b8c7c007c7898c20ae20cb6b7ded",
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
  *
node/wasi.d.ts CHANGED
@@ -29,7 +29,7 @@
29
29
  * wasi.start(instance);
30
30
  * ```
31
31
  *
32
- * To run the above example, create a new WebAssembly text format file named`demo.wat`:
32
+ * To run the above example, create a new WebAssembly text format file named `demo.wat`:
33
33
  *
34
34
  * ```text
35
35
  * (module
@@ -67,7 +67,7 @@
67
67
  * wat2wasm demo.wat
68
68
  * ```
69
69
  * @experimental
70
- * @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/wasi.js)
70
+ * @see [source](https://github.com/nodejs/node/blob/v20.11.1/lib/wasi.js)
71
71
  */
72
72
  declare module "wasi" {
73
73
  interface WASIOptions {
@@ -75,11 +75,13 @@ declare module "wasi" {
75
75
  * An array of strings that the WebAssembly application will
76
76
  * see as command line arguments. The first argument is the virtual path to the
77
77
  * WASI command itself.
78
+ * @default []
78
79
  */
79
80
  args?: string[] | undefined;
80
81
  /**
81
82
  * An object similar to `process.env` that the WebAssembly
82
83
  * application will see as its environment.
84
+ * @default {}
83
85
  */
84
86
  env?: object | undefined;
85
87
  /**
@@ -91,7 +93,7 @@ declare module "wasi" {
91
93
  preopens?: NodeJS.Dict<string> | undefined;
92
94
  /**
93
95
  * By default, when WASI applications call `__wasi_proc_exit()`
94
- * `wasi.start()` will return with the exit code specified rather than terminatng the process.
96
+ * `wasi.start()` will return with the exit code specified rather than terminatng the process.
95
97
  * Setting this option to `false` will cause the Node.js process to exit with
96
98
  * the specified exit code instead.
97
99
  * @default true
@@ -114,10 +116,10 @@ declare module "wasi" {
114
116
  stderr?: number | undefined;
115
117
  /**
116
118
  * The version of WASI requested.
117
- * Currently the only supported versions are `'unstable'` and `'preview1'`.
118
- * @since v20.0.0
119
+ * Currently the only supported versions are `'unstable'` and `'preview1'`. This option is mandatory.
120
+ * @since v19.8.0
119
121
  */
120
- version: string;
122
+ version: "unstable" | "preview1";
121
123
  }
122
124
  /**
123
125
  * The `WASI` class provides the WASI system call API and additional convenience
@@ -145,10 +147,10 @@ declare module "wasi" {
145
147
  */
146
148
  getImportObject(): object;
147
149
  /**
148
- * Attempt to begin execution of `instance` as a WASI command by invoking its`_start()` export. If `instance` does not contain a `_start()` export, or if`instance` contains an `_initialize()`
150
+ * Attempt to begin execution of `instance` as a WASI command by invoking its `_start()` export. If `instance` does not contain a `_start()` export, or if `instance` contains an `_initialize()`
149
151
  * export, then an exception is thrown.
150
152
  *
151
- * `start()` requires that `instance` exports a [`WebAssembly.Memory`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) named`memory`. If
153
+ * `start()` requires that `instance` exports a [`WebAssembly.Memory`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) named `memory`. If
152
154
  * `instance` does not have a `memory` export an exception is thrown.
153
155
  *
154
156
  * If `start()` is called more than once, an exception is thrown.
@@ -156,9 +158,9 @@ declare module "wasi" {
156
158
  */
157
159
  start(instance: object): number; // TODO: avoid DOM dependency until WASM moved to own lib.
158
160
  /**
159
- * Attempt to initialize `instance` as a WASI reactor by invoking its`_initialize()` export, if it is present. If `instance` contains a `_start()`export, then an exception is thrown.
161
+ * Attempt to initialize `instance` as a WASI reactor by invoking its `_initialize()` export, if it is present. If `instance` contains a `_start()` export, then an exception is thrown.
160
162
  *
161
- * `initialize()` requires that `instance` exports a [`WebAssembly.Memory`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) named`memory`.
163
+ * `initialize()` requires that `instance` exports a [`WebAssembly.Memory`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) named `memory`.
162
164
  * If `instance` does not have a `memory` export an exception is thrown.
163
165
  *
164
166
  * If `initialize()` is called more than once, an exception is thrown.