@types/node 16.18.79 → 16.18.81

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 v16.18/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/v16.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Thu, 01 Feb 2024 17:35:23 GMT
11
+ * Last updated: Thu, 15 Feb 2024 10:07:24 GMT
12
12
  * Dependencies: none
13
13
 
14
14
  # Credits
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/node",
3
- "version": "16.18.79",
3
+ "version": "16.18.81",
4
4
  "description": "TypeScript definitions for node",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
6
6
  "license": "MIT",
@@ -222,6 +222,6 @@
222
222
  },
223
223
  "scripts": {},
224
224
  "dependencies": {},
225
- "typesPublisherContentHash": "052d62dae6ffb01bc2ee31005dcedbade3b7287f6e0ea97a6302c5d2fd41aec9",
225
+ "typesPublisherContentHash": "ae03b227c3d602f42dd30296514410e0f03c04128303e667d569752dad86921f",
226
226
  "typeScriptVersion": "4.6"
227
227
  }
@@ -5,7 +5,7 @@
5
5
  * ```js
6
6
  * import url from 'url';
7
7
  * ```
8
- * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/url.js)
8
+ * @see [source](https://github.com/nodejs/node/blob/v16.20.2/lib/url.js)
9
9
  */
10
10
  declare module "url" {
11
11
  import { Blob } from "node:buffer";
@@ -104,18 +104,18 @@ declare module "url" {
104
104
  */
105
105
  function format(urlObject: URL, options?: URLFormatOptions): string;
106
106
  /**
107
- * The `url.format()` method returns a formatted URL string derived from`urlObject`.
107
+ * The `url.format()` method returns a formatted URL string derived from `urlObject`.
108
108
  *
109
109
  * ```js
110
- * const url = require('url');
110
+ * const url = require('node:url');
111
111
  * url.format({
112
112
  * protocol: 'https',
113
113
  * hostname: 'example.com',
114
114
  * pathname: '/some/path',
115
115
  * query: {
116
116
  * page: 1,
117
- * format: 'json'
118
- * }
117
+ * format: 'json',
118
+ * },
119
119
  * });
120
120
  *
121
121
  * // => 'https://example.com/some/path?page=1&format=json'
@@ -130,33 +130,33 @@ declare module "url" {
130
130
  * * Otherwise, if `urlObject.protocol` is not `undefined` and is not a string, an `Error` is thrown.
131
131
  * * For all string values of `urlObject.protocol` that _do not end_ with an ASCII
132
132
  * colon (`:`) character, the literal string `:` will be appended to `result`.
133
- * * If either of the following conditions is true, then the literal string `//`will be appended to `result`:
133
+ * * If either of the following conditions is true, then the literal string `//` will be appended to `result`:
134
134
  * * `urlObject.slashes` property is true;
135
- * * `urlObject.protocol` begins with `http`, `https`, `ftp`, `gopher`, or`file`;
136
- * * If the value of the `urlObject.auth` property is truthy, and either`urlObject.host` or `urlObject.hostname` are not `undefined`, the value of`urlObject.auth` will be coerced into a string
137
- * and appended to `result`followed by the literal string `@`.
135
+ * * `urlObject.protocol` begins with `http`, `https`, `ftp`, `gopher`, or `file`;
136
+ * * If the value of the `urlObject.auth` property is truthy, and either `urlObject.host` or `urlObject.hostname` are not `undefined`, the value of `urlObject.auth` will be coerced into a string
137
+ * and appended to `result` followed by the literal string `@`.
138
138
  * * If the `urlObject.host` property is `undefined` then:
139
139
  * * If the `urlObject.hostname` is a string, it is appended to `result`.
140
140
  * * Otherwise, if `urlObject.hostname` is not `undefined` and is not a string,
141
141
  * an `Error` is thrown.
142
- * * If the `urlObject.port` property value is truthy, and `urlObject.hostname`is not `undefined`:
142
+ * * If the `urlObject.port` property value is truthy, and `urlObject.hostname` is not `undefined`:
143
143
  * * The literal string `:` is appended to `result`, and
144
- * * The value of `urlObject.port` is coerced to a string and appended to`result`.
145
- * * Otherwise, if the `urlObject.host` property value is truthy, the value of`urlObject.host` is coerced to a string and appended to `result`.
144
+ * * The value of `urlObject.port` is coerced to a string and appended to `result`.
145
+ * * Otherwise, if the `urlObject.host` property value is truthy, the value of `urlObject.host` is coerced to a string and appended to `result`.
146
146
  * * If the `urlObject.pathname` property is a string that is not an empty string:
147
- * * If the `urlObject.pathname`_does not start_ with an ASCII forward slash
147
+ * * If the `urlObject.pathname` _does not start_ with an ASCII forward slash
148
148
  * (`/`), then the literal string `'/'` is appended to `result`.
149
149
  * * The value of `urlObject.pathname` is appended to `result`.
150
150
  * * Otherwise, if `urlObject.pathname` is not `undefined` and is not a string, an `Error` is thrown.
151
- * * If the `urlObject.search` property is `undefined` and if the `urlObject.query`property is an `Object`, the literal string `?` is appended to `result`followed by the output of calling the
152
- * `querystring` module's `stringify()`method passing the value of `urlObject.query`.
151
+ * * If the `urlObject.search` property is `undefined` and if the `urlObject.query`property is an `Object`, the literal string `?` is appended to `result` followed by the output of calling the
152
+ * `querystring` module's `stringify()` method passing the value of `urlObject.query`.
153
153
  * * Otherwise, if `urlObject.search` is a string:
154
- * * If the value of `urlObject.search`_does not start_ with the ASCII question
154
+ * * If the value of `urlObject.search` _does not start_ with the ASCII question
155
155
  * mark (`?`) character, the literal string `?` is appended to `result`.
156
156
  * * The value of `urlObject.search` is appended to `result`.
157
157
  * * Otherwise, if `urlObject.search` is not `undefined` and is not a string, an `Error` is thrown.
158
158
  * * If the `urlObject.hash` property is a string:
159
- * * If the value of `urlObject.hash`_does not start_ with the ASCII hash (`#`)
159
+ * * If the value of `urlObject.hash` _does not start_ with the ASCII hash (`#`)
160
160
  * character, the literal string `#` is appended to `result`.
161
161
  * * The value of `urlObject.hash` is appended to `result`.
162
162
  * * Otherwise, if the `urlObject.hash` property is not `undefined` and is not a
@@ -172,7 +172,7 @@ declare module "url" {
172
172
  * manner similar to that of a Web browser resolving an anchor tag HREF.
173
173
  *
174
174
  * ```js
175
- * const url = require('url');
175
+ * const url = require('node:url');
176
176
  * url.resolve('/one/two/three', 'four'); // '/one/two/four'
177
177
  * url.resolve('http://example.com/', '/one'); // 'http://example.com/one'
178
178
  * url.resolve('http://example.com/one', '/two'); // 'http://example.com/two'
@@ -210,7 +210,7 @@ declare module "url" {
210
210
  * This feature is only available if the `node` executable was compiled with `ICU` enabled. If not, the domain names are passed through unchanged.
211
211
  *
212
212
  * ```js
213
- * import url from 'url';
213
+ * import url from 'node:url';
214
214
  *
215
215
  * console.log(url.domainToASCII('español.com'));
216
216
  * // Prints xn--espaol-zwa.com
@@ -231,7 +231,7 @@ declare module "url" {
231
231
  * This feature is only available if the `node` executable was compiled with `ICU` enabled. If not, the domain names are passed through unchanged.
232
232
  *
233
233
  * ```js
234
- * import url from 'url';
234
+ * import url from 'node:url';
235
235
  *
236
236
  * console.log(url.domainToUnicode('xn--espaol-zwa.com'));
237
237
  * // Prints español.com
@@ -248,7 +248,7 @@ declare module "url" {
248
248
  * well as ensuring a cross-platform valid absolute path string.
249
249
  *
250
250
  * ```js
251
- * import { fileURLToPath } from 'url';
251
+ * import { fileURLToPath } from 'node:url';
252
252
  *
253
253
  * const __filename = fileURLToPath(import.meta.url);
254
254
  *
@@ -274,7 +274,7 @@ declare module "url" {
274
274
  * control characters are correctly encoded when converting into a File URL.
275
275
  *
276
276
  * ```js
277
- * import { pathToFileURL } from 'url';
277
+ * import { pathToFileURL } from 'node:url';
278
278
  *
279
279
  * new URL('/foo#1', 'file:'); // Incorrect: file:///foo#1
280
280
  * pathToFileURL('/foo#1'); // Correct: file:///foo%231 (POSIX)
@@ -292,7 +292,7 @@ declare module "url" {
292
292
  * expected by the `http.request()` and `https.request()` APIs.
293
293
  *
294
294
  * ```js
295
- * import { urlToHttpOptions } from 'url';
295
+ * import { urlToHttpOptions } from 'node:url';
296
296
  * const myURL = new URL('https://a:b@測試?abc#foo');
297
297
  *
298
298
  * console.log(urlToHttpOptions(myURL));
@@ -315,9 +315,26 @@ declare module "url" {
315
315
  */
316
316
  function urlToHttpOptions(url: URL): ClientRequestArgs;
317
317
  interface URLFormatOptions {
318
+ /**
319
+ * `true` if the serialized URL string should include the username and password, `false` otherwise.
320
+ * @default true
321
+ */
318
322
  auth?: boolean | undefined;
323
+ /**
324
+ * `true` if the serialized URL string should include the fragment, `false` otherwise.
325
+ * @default true
326
+ */
319
327
  fragment?: boolean | undefined;
328
+ /**
329
+ * `true` if the serialized URL string should include the search query, `false` otherwise.
330
+ * @default true
331
+ */
320
332
  search?: boolean | undefined;
333
+ /**
334
+ * `true` if Unicode characters appearing in the host component of the URL string should be encoded directly as opposed to
335
+ * being Punycode encoded.
336
+ * @default false
337
+ */
321
338
  unicode?: boolean | undefined;
322
339
  }
323
340
  /**
@@ -340,7 +357,7 @@ declare module "url" {
340
357
  * const {
341
358
  * Blob,
342
359
  * resolveObjectURL,
343
- * } = require('buffer');
360
+ * } = require('node:buffer');
344
361
  *
345
362
  * const blob = new Blob(['hello']);
346
363
  * const id = URL.createObjectURL(blob);
@@ -366,8 +383,8 @@ declare module "url" {
366
383
  * @experimental
367
384
  * @param id A `'blob:nodedata:...` URL string returned by a prior call to `URL.createObjectURL()`.
368
385
  */
369
- static revokeObjectURL(objectUrl: string): void;
370
- constructor(input: string, base?: string | URL);
386
+ static revokeObjectURL(id: string): void;
387
+ constructor(input: string | { toString: () => string }, base?: string | URL);
371
388
  /**
372
389
  * Gets and sets the fragment portion of the URL.
373
390
  *
@@ -496,14 +513,14 @@ declare module "url" {
496
513
  * // Prints https://example.org/abcdef?123
497
514
  * ```
498
515
  *
499
- * Invalid URL characters included in the value assigned to the `pathname`property are `percent-encoded`. The selection of which characters
516
+ * Invalid URL characters included in the value assigned to the `pathname` property are `percent-encoded`. The selection of which characters
500
517
  * to percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
501
518
  */
502
519
  pathname: string;
503
520
  /**
504
521
  * Gets and sets the port portion of the URL.
505
522
  *
506
- * The port value may be a number or a string containing a number in the range`0` to `65535` (inclusive). Setting the value to the default port of the`URL` objects given `protocol` will
523
+ * The port value may be a number or a string containing a number in the range `0` to `65535` (inclusive). Setting the value to the default port of the `URL` objects given `protocol` will
507
524
  * result in the `port` value becoming
508
525
  * the empty string (`''`).
509
526
  *
@@ -643,7 +660,7 @@ declare module "url" {
643
660
  * // Prints https://123:xyz@example.com/
644
661
  * ```
645
662
  *
646
- * Any invalid URL characters appearing in the value assigned the `username`property will be `percent-encoded`. The selection of which
663
+ * Any invalid URL characters appearing in the value assigned the `username` property will be `percent-encoded`. The selection of which
647
664
  * characters to percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
648
665
  */
649
666
  username: string;
@@ -671,7 +688,7 @@ declare module "url" {
671
688
  toJSON(): string;
672
689
  }
673
690
  /**
674
- * The `URLSearchParams` API provides read and write access to the query of a`URL`. The `URLSearchParams` class can also be used standalone with one of the
691
+ * The `URLSearchParams` API provides read and write access to the query of a `URL`. The `URLSearchParams` class can also be used standalone with one of the
675
692
  * four following constructors.
676
693
  * The `URLSearchParams` class is also available on the global object.
677
694
  *
@@ -755,7 +772,7 @@ declare module "url" {
755
772
  * @param thisArg To be used as `this` value for when `fn` is called
756
773
  */
757
774
  forEach<TThis = this>(
758
- callback: (this: TThis, value: string, name: string, searchParams: URLSearchParams) => void,
775
+ fn: (this: TThis, value: string, name: string, searchParams: URLSearchParams) => void,
759
776
  thisArg?: TThis,
760
777
  ): void;
761
778
  /**
@@ -1,10 +1,10 @@
1
1
  /**
2
- * The `v8` module exposes APIs that are specific to the version of [V8](https://developers.google.com/v8/) built into the Node.js binary. It can be accessed using:
2
+ * The `node:v8` module exposes APIs that are specific to the version of [V8](https://developers.google.com/v8/) built into the Node.js binary. It can be accessed using:
3
3
  *
4
4
  * ```js
5
- * const v8 = require('v8');
5
+ * const v8 = require('node:v8');
6
6
  * ```
7
- * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/v8.js)
7
+ * @see [source](https://github.com/nodejs/node/blob/v16.20.2/lib/v8.js)
8
8
  */
9
9
  declare module "v8" {
10
10
  import { Readable } from "node:stream";
@@ -29,6 +29,9 @@ declare module "v8" {
29
29
  does_zap_garbage: DoesZapCodeSpaceFlag;
30
30
  number_of_native_contexts: number;
31
31
  number_of_detached_contexts: number;
32
+ total_global_handles_size: number;
33
+ used_global_handles_size: number;
34
+ external_memory: number;
32
35
  }
33
36
  interface HeapCodeStatistics {
34
37
  code_and_metadata_size: number;
@@ -68,6 +71,15 @@ declare module "v8" {
68
71
  * of contexts that were detached and not yet garbage collected. This number
69
72
  * being non-zero indicates a potential memory leak.
70
73
  *
74
+ * `total_global_handles_size` The value of total\_global\_handles\_size is the
75
+ * total memory size of V8 global handles.
76
+ *
77
+ * `used_global_handles_size` The value of used\_global\_handles\_size is the
78
+ * used memory size of V8 global handles.
79
+ *
80
+ * `external_memory` The value of external\_memory is the memory size of array
81
+ * buffers and external strings.
82
+ *
71
83
  * ```js
72
84
  * {
73
85
  * total_heap_size: 7326976,
@@ -80,7 +92,10 @@ declare module "v8" {
80
92
  * peak_malloced_memory: 1127496,
81
93
  * does_zap_garbage: 0,
82
94
  * number_of_native_contexts: 1,
83
- * number_of_detached_contexts: 0
95
+ * number_of_detached_contexts: 0,
96
+ * total_global_handles_size: 8192,
97
+ * used_global_handles_size: 3296,
98
+ * external_memory: 318824
84
99
  * }
85
100
  * ```
86
101
  * @since v1.0.0
@@ -90,7 +105,7 @@ declare module "v8" {
90
105
  * Returns statistics about the V8 heap spaces, i.e. the segments which make up
91
106
  * the V8 heap. Neither the ordering of heap spaces, nor the availability of a
92
107
  * heap space can be guaranteed as the statistics are provided via the
93
- * V8[`GetHeapSpaceStatistics`](https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#ac673576f24fdc7a33378f8f57e1d13a4) function and may change from one V8 version to the
108
+ * V8 [`GetHeapSpaceStatistics`](https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#ac673576f24fdc7a33378f8f57e1d13a4) function and may change from one V8 version to the
94
109
  * next.
95
110
  *
96
111
  * The value returned is an array of objects containing the following properties:
@@ -149,7 +164,7 @@ declare module "v8" {
149
164
  *
150
165
  * ```js
151
166
  * // Print GC events to stdout for one minute.
152
- * const v8 = require('v8');
167
+ * const v8 = require('node:v8');
153
168
  * v8.setFlagsFromString('--trace_gc');
154
169
  * setTimeout(() => { v8.setFlagsFromString('--notrace_gc'); }, 60e3);
155
170
  * ```
@@ -163,9 +178,16 @@ declare module "v8" {
163
178
  * Chrome DevTools. The JSON schema is undocumented and specific to the
164
179
  * V8 engine. Therefore, the schema may change from one version of V8 to the next.
165
180
  *
181
+ * Creating a heap snapshot requires memory about twice the size of the heap at
182
+ * the time the snapshot is created. This results in the risk of OOM killers
183
+ * terminating the process.
184
+ *
185
+ * Generating a snapshot is a synchronous operation which blocks the event loop
186
+ * for a duration depending on the heap size.
187
+ *
166
188
  * ```js
167
189
  * // Print heap snapshot to the console
168
- * const v8 = require('v8');
190
+ * const v8 = require('node:v8');
169
191
  * const stream = v8.getHeapSnapshot();
170
192
  * stream.pipe(process.stdout);
171
193
  * ```
@@ -182,13 +204,20 @@ declare module "v8" {
182
204
  * A heap snapshot is specific to a single V8 isolate. When using `worker threads`, a heap snapshot generated from the main thread will
183
205
  * not contain any information about the workers, and vice versa.
184
206
  *
207
+ * Creating a heap snapshot requires memory about twice the size of the heap at
208
+ * the time the snapshot is created. This results in the risk of OOM killers
209
+ * terminating the process.
210
+ *
211
+ * Generating a snapshot is a synchronous operation which blocks the event loop
212
+ * for a duration depending on the heap size.
213
+ *
185
214
  * ```js
186
- * const { writeHeapSnapshot } = require('v8');
215
+ * const { writeHeapSnapshot } = require('node:v8');
187
216
  * const {
188
217
  * Worker,
189
218
  * isMainThread,
190
- * parentPort
191
- * } = require('worker_threads');
219
+ * parentPort,
220
+ * } = require('node:worker_threads');
192
221
  *
193
222
  * if (isMainThread) {
194
223
  * const worker = new Worker(__filename);
@@ -219,13 +248,16 @@ declare module "v8" {
219
248
  */
220
249
  function writeHeapSnapshot(filename?: string): string;
221
250
  /**
222
- * Returns an object with the following properties:
251
+ * Get statistics about code and its metadata in the heap, see
252
+ * V8 [`GetHeapCodeAndMetadataStatistics`](https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#a6079122af17612ef54ef3348ce170866) API. Returns an object with the
253
+ * following properties:
223
254
  *
224
255
  * ```js
225
256
  * {
226
257
  * code_and_metadata_size: 212208,
227
258
  * bytecode_and_metadata_size: 161368,
228
- * external_script_source_size: 1410794
259
+ * external_script_source_size: 1410794,
260
+ * cpu_profiler_metadata_size: 0,
229
261
  * }
230
262
  * ```
231
263
  * @since v12.8.0
@@ -275,7 +307,7 @@ declare module "v8" {
275
307
  */
276
308
  writeDouble(value: number): void;
277
309
  /**
278
- * Write raw bytes into the serializers internal buffer. The deserializer
310
+ * Write raw bytes into the serializer's internal buffer. The deserializer
279
311
  * will require a way to compute the length of the buffer.
280
312
  * For use inside of a custom `serializer._writeHostObject()`.
281
313
  */
@@ -331,7 +363,7 @@ declare module "v8" {
331
363
  */
332
364
  readDouble(): number;
333
365
  /**
334
- * Read raw bytes from the deserializers internal buffer. The `length` parameter
366
+ * Read raw bytes from the deserializer's internal buffer. The `length` parameter
335
367
  * must correspond to the length of the buffer that was passed to `serializer.writeRawBytes()`.
336
368
  * For use inside of a custom `deserializer._readHostObject()`.
337
369
  */
@@ -344,6 +376,10 @@ declare module "v8" {
344
376
  class DefaultDeserializer extends Deserializer {}
345
377
  /**
346
378
  * Uses a `DefaultSerializer` to serialize `value` into a buffer.
379
+ *
380
+ * `ERR_BUFFER_TOO_LARGE` will be thrown when trying to
381
+ * serialize a huge object which requires buffer
382
+ * larger than `buffer.constants.MAX_LENGTH`.
347
383
  * @since v8.0.0
348
384
  */
349
385
  function serialize(value: any): Buffer;
@@ -362,20 +398,27 @@ declare module "v8" {
362
398
  *
363
399
  * When the process is about to exit, one last coverage will still be written to
364
400
  * disk unless {@link stopCoverage} is invoked before the process exits.
365
- * @since v15.1.0, v12.22.0
401
+ * @since v15.1.0, v14.18.0, v12.22.0
366
402
  */
367
403
  function takeCoverage(): void;
368
404
  /**
369
405
  * The `v8.stopCoverage()` method allows the user to stop the coverage collection
370
406
  * started by `NODE_V8_COVERAGE`, so that V8 can release the execution count
371
407
  * records and optimize code. This can be used in conjunction with {@link takeCoverage} if the user wants to collect the coverage on demand.
372
- * @since v15.1.0, v12.22.0
408
+ * @since v15.1.0, v14.18.0, v12.22.0
373
409
  */
374
410
  function stopCoverage(): void;
411
+ /**
412
+ * The API is a no-op if `--heapsnapshot-near-heap-limit` is already set from the command line or the API is called more than once.
413
+ * `limit` must be a positive integer. See [`--heapsnapshot-near-heap-limit`](https://nodejs.org/docs/latest-v16.x/api/cli.html#--heapsnapshot-near-heap-limitmax_count) for more information.
414
+ * @experimental
415
+ * @since v16.18.0
416
+ */
417
+ function setHeapSnapshotNearHeapLimit(limit: number): void;
375
418
  /**
376
419
  * Called when a promise is constructed. This does not mean that corresponding before/after events will occur, only that the possibility exists. This will
377
420
  * happen if a promise is created without ever getting a continuation.
378
- * @since v17.1.0, v16.14.0
421
+ * @since v16.14.0
379
422
  * @param promise The promise being created.
380
423
  * @param parent The promise continued from, if applicable.
381
424
  */
@@ -387,14 +430,14 @@ declare module "v8" {
387
430
  *
388
431
  * The before callback will be called 0 to N times. The before callback will typically be called 0 times if no continuation was ever made for the promise.
389
432
  * The before callback may be called many times in the case where many continuations have been made from the same promise.
390
- * @since v17.1.0, v16.14.0
433
+ * @since v16.14.0
391
434
  */
392
435
  interface Before {
393
436
  (promise: Promise<unknown>): void;
394
437
  }
395
438
  /**
396
439
  * Called immediately after a promise continuation executes. This may be after a `then()`, `catch()`, or `finally()` handler or before an await after another await.
397
- * @since v17.1.0, v16.14.0
440
+ * @since v16.14.0
398
441
  */
399
442
  interface After {
400
443
  (promise: Promise<unknown>): void;
@@ -402,7 +445,7 @@ declare module "v8" {
402
445
  /**
403
446
  * Called when the promise receives a resolution or rejection value. This may occur synchronously in the case of {@link Promise.resolve()} or
404
447
  * {@link Promise.reject()}.
405
- * @since v17.1.0, v16.14.0
448
+ * @since v16.14.0
406
449
  */
407
450
  interface Settled {
408
451
  (promise: Promise<unknown>): void;
@@ -413,7 +456,7 @@ declare module "v8" {
413
456
  *
414
457
  * Because promises are asynchronous resources whose lifecycle is tracked via the promise hooks mechanism, the `init()`, `before()`, `after()`, and
415
458
  * `settled()` callbacks must not be async functions as they create more promises which would produce an infinite loop.
416
- * @since v17.1.0, v16.14.0
459
+ * @since v16.14.0
417
460
  */
418
461
  interface HookCallbacks {
419
462
  init?: Init;
@@ -424,28 +467,28 @@ declare module "v8" {
424
467
  interface PromiseHooks {
425
468
  /**
426
469
  * The `init` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
427
- * @since v17.1.0, v16.14.0
470
+ * @since v16.14.0
428
471
  * @param init The {@link Init | `init` callback} to call when a promise is created.
429
472
  * @return Call to stop the hook.
430
473
  */
431
474
  onInit: (init: Init) => Function;
432
475
  /**
433
476
  * The `settled` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
434
- * @since v17.1.0, v16.14.0
477
+ * @since v16.14.0
435
478
  * @param settled The {@link Settled | `settled` callback} to call when a promise is created.
436
479
  * @return Call to stop the hook.
437
480
  */
438
481
  onSettled: (settled: Settled) => Function;
439
482
  /**
440
483
  * The `before` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
441
- * @since v17.1.0, v16.14.0
484
+ * @since v16.14.0
442
485
  * @param before The {@link Before | `before` callback} to call before a promise continuation executes.
443
486
  * @return Call to stop the hook.
444
487
  */
445
488
  onBefore: (before: Before) => Function;
446
489
  /**
447
490
  * The `after` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
448
- * @since v17.1.0, v16.14.0
491
+ * @since v16.14.0
449
492
  * @param after The {@link After | `after` callback} to call after a promise continuation executes.
450
493
  * @return Call to stop the hook.
451
494
  */
@@ -455,7 +498,7 @@ declare module "v8" {
455
498
  * The callbacks `init()`/`before()`/`after()`/`settled()` are called for the respective events during a promise's lifetime.
456
499
  * All callbacks are optional. For example, if only promise creation needs to be tracked, then only the init callback needs to be passed.
457
500
  * The hook callbacks must be plain functions. Providing async functions will throw as it would produce an infinite microtask loop.
458
- * @since v17.1.0, v16.14.0
501
+ * @since v16.14.0
459
502
  * @param callbacks The {@link HookCallbacks | Hook Callbacks} to register
460
503
  * @return Used for disabling hooks
461
504
  */
@@ -463,9 +506,120 @@ declare module "v8" {
463
506
  }
464
507
  /**
465
508
  * The `promiseHooks` interface can be used to track promise lifecycle events.
466
- * @since v17.1.0, v16.14.0
509
+ * @since v16.14.0
467
510
  */
468
511
  const promiseHooks: PromiseHooks;
512
+ type StartupSnapshotCallbackFn = (args: any) => any;
513
+ interface StartupSnapshot {
514
+ /**
515
+ * Add a callback that will be called when the Node.js instance is about to get serialized into a snapshot and exit.
516
+ * This can be used to release resources that should not or cannot be serialized or to convert user data into a form more suitable for serialization.
517
+ * @since v16.17.0
518
+ */
519
+ addSerializeCallback(callback: StartupSnapshotCallbackFn, data?: any): void;
520
+ /**
521
+ * Add a callback that will be called when the Node.js instance is deserialized from a snapshot.
522
+ * The `callback` and the `data` (if provided) will be serialized into the snapshot, they can be used to re-initialize the state of the application or
523
+ * to re-acquire resources that the application needs when the application is restarted from the snapshot.
524
+ * @since v16.17.0
525
+ */
526
+ addDeserializeCallback(callback: StartupSnapshotCallbackFn, data?: any): void;
527
+ /**
528
+ * This sets the entry point of the Node.js application when it is deserialized from a snapshot. This can be called only once in the snapshot building script.
529
+ * If called, the deserialized application no longer needs an additional entry point script to start up and will simply invoke the callback along with the deserialized
530
+ * data (if provided), otherwise an entry point script still needs to be provided to the deserialized application.
531
+ * @since v16.17.0
532
+ */
533
+ setDeserializeMainFunction(callback: StartupSnapshotCallbackFn, data?: any): void;
534
+ /**
535
+ * Returns true if the Node.js instance is run to build a snapshot.
536
+ * @since v16.17.0
537
+ */
538
+ isBuildingSnapshot(): boolean;
539
+ }
540
+ /**
541
+ * The `v8.startupSnapshot` interface can be used to add serialization and deserialization hooks for custom startup snapshots.
542
+ *
543
+ * ```bash
544
+ * $ node --snapshot-blob snapshot.blob --build-snapshot entry.js
545
+ * # This launches a process with the snapshot
546
+ * $ node --snapshot-blob snapshot.blob
547
+ * ```
548
+ *
549
+ * In the example above, `entry.js` can use methods from the `v8.startupSnapshot` interface to specify how to save information for custom objects
550
+ * in the snapshot during serialization
551
+ * and how the information can be used to synchronize these objects during deserialization of the snapshot.
552
+ * For example, if the `entry.js` contains the following script:
553
+ *
554
+ * ```js
555
+ * 'use strict';
556
+ *
557
+ * const fs = require('node:fs');
558
+ * const zlib = require('node:zlib');
559
+ * const path = require('node:path');
560
+ * const assert = require('node:assert');
561
+ *
562
+ * const v8 = require('node:v8');
563
+ *
564
+ * class BookShelf {
565
+ * storage = new Map();
566
+ *
567
+ * // Reading a series of files from directory and store them into storage.
568
+ * constructor(directory, books) {
569
+ * for (const book of books) {
570
+ * this.storage.set(book, fs.readFileSync(path.join(directory, book)));
571
+ * }
572
+ * }
573
+ *
574
+ * static compressAll(shelf) {
575
+ * for (const [ book, content ] of shelf.storage) {
576
+ * shelf.storage.set(book, zlib.gzipSync(content));
577
+ * }
578
+ * }
579
+ *
580
+ * static decompressAll(shelf) {
581
+ * for (const [ book, content ] of shelf.storage) {
582
+ * shelf.storage.set(book, zlib.gunzipSync(content));
583
+ * }
584
+ * }
585
+ * }
586
+ *
587
+ * // __dirname here is where the snapshot script is placed
588
+ * // during snapshot building time.
589
+ * const shelf = new BookShelf(__dirname, [
590
+ * 'book1.en_US.txt',
591
+ * 'book1.es_ES.txt',
592
+ * 'book2.zh_CN.txt',
593
+ * ]);
594
+ *
595
+ * assert(v8.startupSnapshot.isBuildingSnapshot());
596
+ * // On snapshot serialization, compress the books to reduce size.
597
+ * v8.startupSnapshot.addSerializeCallback(BookShelf.compressAll, shelf);
598
+ * // On snapshot deserialization, decompress the books.
599
+ * v8.startupSnapshot.addDeserializeCallback(BookShelf.decompressAll, shelf);
600
+ * v8.startupSnapshot.setDeserializeMainFunction((shelf) => {
601
+ * // process.env and process.argv are refreshed during snapshot
602
+ * // deserialization.
603
+ * const lang = process.env.BOOK_LANG || 'en_US';
604
+ * const book = process.argv[1];
605
+ * const name = `${book}.${lang}.txt`;
606
+ * console.log(shelf.storage.get(name));
607
+ * }, shelf);
608
+ * ```
609
+ *
610
+ * The resulted binary will get print the data deserialized from the snapshot during start up, using the refreshed `process.env` and `process.argv` of the launched process:
611
+ *
612
+ * ```bash
613
+ * $ BOOK_LANG=es_ES node --snapshot-blob snapshot.blob book1
614
+ * # Prints content of book1.es_ES.txt deserialized from the snapshot.
615
+ * ```
616
+ *
617
+ * Currently the application deserialized from a user-land snapshot cannot be snapshotted again, so these APIs are only available to applications that are not deserialized from a user-land snapshot.
618
+ *
619
+ * @experimental
620
+ * @since v16.17.0
621
+ */
622
+ const startupSnapshot: StartupSnapshot;
469
623
  }
470
624
  declare module "node:v8" {
471
625
  export * from "v8";
node v16.18/url.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * ```js
6
6
  * import url from 'url';
7
7
  * ```
8
- * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/url.js)
8
+ * @see [source](https://github.com/nodejs/node/blob/v16.20.2/lib/url.js)
9
9
  */
10
10
  declare module "url" {
11
11
  import { Blob } from "node:buffer";
@@ -104,18 +104,18 @@ declare module "url" {
104
104
  */
105
105
  function format(urlObject: URL, options?: URLFormatOptions): string;
106
106
  /**
107
- * The `url.format()` method returns a formatted URL string derived from`urlObject`.
107
+ * The `url.format()` method returns a formatted URL string derived from `urlObject`.
108
108
  *
109
109
  * ```js
110
- * const url = require('url');
110
+ * const url = require('node:url');
111
111
  * url.format({
112
112
  * protocol: 'https',
113
113
  * hostname: 'example.com',
114
114
  * pathname: '/some/path',
115
115
  * query: {
116
116
  * page: 1,
117
- * format: 'json'
118
- * }
117
+ * format: 'json',
118
+ * },
119
119
  * });
120
120
  *
121
121
  * // => 'https://example.com/some/path?page=1&#x26;format=json'
@@ -130,33 +130,33 @@ declare module "url" {
130
130
  * * Otherwise, if `urlObject.protocol` is not `undefined` and is not a string, an `Error` is thrown.
131
131
  * * For all string values of `urlObject.protocol` that _do not end_ with an ASCII
132
132
  * colon (`:`) character, the literal string `:` will be appended to `result`.
133
- * * If either of the following conditions is true, then the literal string `//`will be appended to `result`:
133
+ * * If either of the following conditions is true, then the literal string `//` will be appended to `result`:
134
134
  * * `urlObject.slashes` property is true;
135
- * * `urlObject.protocol` begins with `http`, `https`, `ftp`, `gopher`, or`file`;
136
- * * If the value of the `urlObject.auth` property is truthy, and either`urlObject.host` or `urlObject.hostname` are not `undefined`, the value of`urlObject.auth` will be coerced into a string
137
- * and appended to `result`followed by the literal string `@`.
135
+ * * `urlObject.protocol` begins with `http`, `https`, `ftp`, `gopher`, or `file`;
136
+ * * If the value of the `urlObject.auth` property is truthy, and either `urlObject.host` or `urlObject.hostname` are not `undefined`, the value of `urlObject.auth` will be coerced into a string
137
+ * and appended to `result` followed by the literal string `@`.
138
138
  * * If the `urlObject.host` property is `undefined` then:
139
139
  * * If the `urlObject.hostname` is a string, it is appended to `result`.
140
140
  * * Otherwise, if `urlObject.hostname` is not `undefined` and is not a string,
141
141
  * an `Error` is thrown.
142
- * * If the `urlObject.port` property value is truthy, and `urlObject.hostname`is not `undefined`:
142
+ * * If the `urlObject.port` property value is truthy, and `urlObject.hostname` is not `undefined`:
143
143
  * * The literal string `:` is appended to `result`, and
144
- * * The value of `urlObject.port` is coerced to a string and appended to`result`.
145
- * * Otherwise, if the `urlObject.host` property value is truthy, the value of`urlObject.host` is coerced to a string and appended to `result`.
144
+ * * The value of `urlObject.port` is coerced to a string and appended to `result`.
145
+ * * Otherwise, if the `urlObject.host` property value is truthy, the value of `urlObject.host` is coerced to a string and appended to `result`.
146
146
  * * If the `urlObject.pathname` property is a string that is not an empty string:
147
- * * If the `urlObject.pathname`_does not start_ with an ASCII forward slash
147
+ * * If the `urlObject.pathname` _does not start_ with an ASCII forward slash
148
148
  * (`/`), then the literal string `'/'` is appended to `result`.
149
149
  * * The value of `urlObject.pathname` is appended to `result`.
150
150
  * * Otherwise, if `urlObject.pathname` is not `undefined` and is not a string, an `Error` is thrown.
151
- * * If the `urlObject.search` property is `undefined` and if the `urlObject.query`property is an `Object`, the literal string `?` is appended to `result`followed by the output of calling the
152
- * `querystring` module's `stringify()`method passing the value of `urlObject.query`.
151
+ * * If the `urlObject.search` property is `undefined` and if the `urlObject.query`property is an `Object`, the literal string `?` is appended to `result` followed by the output of calling the
152
+ * `querystring` module's `stringify()` method passing the value of `urlObject.query`.
153
153
  * * Otherwise, if `urlObject.search` is a string:
154
- * * If the value of `urlObject.search`_does not start_ with the ASCII question
154
+ * * If the value of `urlObject.search` _does not start_ with the ASCII question
155
155
  * mark (`?`) character, the literal string `?` is appended to `result`.
156
156
  * * The value of `urlObject.search` is appended to `result`.
157
157
  * * Otherwise, if `urlObject.search` is not `undefined` and is not a string, an `Error` is thrown.
158
158
  * * If the `urlObject.hash` property is a string:
159
- * * If the value of `urlObject.hash`_does not start_ with the ASCII hash (`#`)
159
+ * * If the value of `urlObject.hash` _does not start_ with the ASCII hash (`#`)
160
160
  * character, the literal string `#` is appended to `result`.
161
161
  * * The value of `urlObject.hash` is appended to `result`.
162
162
  * * Otherwise, if the `urlObject.hash` property is not `undefined` and is not a
@@ -172,7 +172,7 @@ declare module "url" {
172
172
  * manner similar to that of a Web browser resolving an anchor tag HREF.
173
173
  *
174
174
  * ```js
175
- * const url = require('url');
175
+ * const url = require('node:url');
176
176
  * url.resolve('/one/two/three', 'four'); // '/one/two/four'
177
177
  * url.resolve('http://example.com/', '/one'); // 'http://example.com/one'
178
178
  * url.resolve('http://example.com/one', '/two'); // 'http://example.com/two'
@@ -210,7 +210,7 @@ declare module "url" {
210
210
  * This feature is only available if the `node` executable was compiled with `ICU` enabled. If not, the domain names are passed through unchanged.
211
211
  *
212
212
  * ```js
213
- * import url from 'url';
213
+ * import url from 'node:url';
214
214
  *
215
215
  * console.log(url.domainToASCII('español.com'));
216
216
  * // Prints xn--espaol-zwa.com
@@ -231,7 +231,7 @@ declare module "url" {
231
231
  * This feature is only available if the `node` executable was compiled with `ICU` enabled. If not, the domain names are passed through unchanged.
232
232
  *
233
233
  * ```js
234
- * import url from 'url';
234
+ * import url from 'node:url';
235
235
  *
236
236
  * console.log(url.domainToUnicode('xn--espaol-zwa.com'));
237
237
  * // Prints español.com
@@ -248,7 +248,7 @@ declare module "url" {
248
248
  * well as ensuring a cross-platform valid absolute path string.
249
249
  *
250
250
  * ```js
251
- * import { fileURLToPath } from 'url';
251
+ * import { fileURLToPath } from 'node:url';
252
252
  *
253
253
  * const __filename = fileURLToPath(import.meta.url);
254
254
  *
@@ -274,7 +274,7 @@ declare module "url" {
274
274
  * control characters are correctly encoded when converting into a File URL.
275
275
  *
276
276
  * ```js
277
- * import { pathToFileURL } from 'url';
277
+ * import { pathToFileURL } from 'node:url';
278
278
  *
279
279
  * new URL('/foo#1', 'file:'); // Incorrect: file:///foo#1
280
280
  * pathToFileURL('/foo#1'); // Correct: file:///foo%231 (POSIX)
@@ -292,7 +292,7 @@ declare module "url" {
292
292
  * expected by the `http.request()` and `https.request()` APIs.
293
293
  *
294
294
  * ```js
295
- * import { urlToHttpOptions } from 'url';
295
+ * import { urlToHttpOptions } from 'node:url';
296
296
  * const myURL = new URL('https://a:b@測試?abc#foo');
297
297
  *
298
298
  * console.log(urlToHttpOptions(myURL));
@@ -315,9 +315,26 @@ declare module "url" {
315
315
  */
316
316
  function urlToHttpOptions(url: URL): ClientRequestArgs;
317
317
  interface URLFormatOptions {
318
+ /**
319
+ * `true` if the serialized URL string should include the username and password, `false` otherwise.
320
+ * @default true
321
+ */
318
322
  auth?: boolean | undefined;
323
+ /**
324
+ * `true` if the serialized URL string should include the fragment, `false` otherwise.
325
+ * @default true
326
+ */
319
327
  fragment?: boolean | undefined;
328
+ /**
329
+ * `true` if the serialized URL string should include the search query, `false` otherwise.
330
+ * @default true
331
+ */
320
332
  search?: boolean | undefined;
333
+ /**
334
+ * `true` if Unicode characters appearing in the host component of the URL string should be encoded directly as opposed to
335
+ * being Punycode encoded.
336
+ * @default false
337
+ */
321
338
  unicode?: boolean | undefined;
322
339
  }
323
340
  /**
@@ -340,7 +357,7 @@ declare module "url" {
340
357
  * const {
341
358
  * Blob,
342
359
  * resolveObjectURL,
343
- * } = require('buffer');
360
+ * } = require('node:buffer');
344
361
  *
345
362
  * const blob = new Blob(['hello']);
346
363
  * const id = URL.createObjectURL(blob);
@@ -366,8 +383,8 @@ declare module "url" {
366
383
  * @experimental
367
384
  * @param id A `'blob:nodedata:...` URL string returned by a prior call to `URL.createObjectURL()`.
368
385
  */
369
- static revokeObjectURL(objectUrl: string): void;
370
- constructor(input: string, base?: string | URL);
386
+ static revokeObjectURL(id: string): void;
387
+ constructor(input: string | { toString: () => string }, base?: string | URL);
371
388
  /**
372
389
  * Gets and sets the fragment portion of the URL.
373
390
  *
@@ -496,14 +513,14 @@ declare module "url" {
496
513
  * // Prints https://example.org/abcdef?123
497
514
  * ```
498
515
  *
499
- * Invalid URL characters included in the value assigned to the `pathname`property are `percent-encoded`. The selection of which characters
516
+ * Invalid URL characters included in the value assigned to the `pathname` property are `percent-encoded`. The selection of which characters
500
517
  * to percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
501
518
  */
502
519
  pathname: string;
503
520
  /**
504
521
  * Gets and sets the port portion of the URL.
505
522
  *
506
- * The port value may be a number or a string containing a number in the range`0` to `65535` (inclusive). Setting the value to the default port of the`URL` objects given `protocol` will
523
+ * The port value may be a number or a string containing a number in the range `0` to `65535` (inclusive). Setting the value to the default port of the `URL` objects given `protocol` will
507
524
  * result in the `port` value becoming
508
525
  * the empty string (`''`).
509
526
  *
@@ -643,7 +660,7 @@ declare module "url" {
643
660
  * // Prints https://123:xyz@example.com/
644
661
  * ```
645
662
  *
646
- * Any invalid URL characters appearing in the value assigned the `username`property will be `percent-encoded`. The selection of which
663
+ * Any invalid URL characters appearing in the value assigned the `username` property will be `percent-encoded`. The selection of which
647
664
  * characters to percent-encode may vary somewhat from what the {@link parse} and {@link format} methods would produce.
648
665
  */
649
666
  username: string;
@@ -671,7 +688,7 @@ declare module "url" {
671
688
  toJSON(): string;
672
689
  }
673
690
  /**
674
- * The `URLSearchParams` API provides read and write access to the query of a`URL`. The `URLSearchParams` class can also be used standalone with one of the
691
+ * The `URLSearchParams` API provides read and write access to the query of a `URL`. The `URLSearchParams` class can also be used standalone with one of the
675
692
  * four following constructors.
676
693
  * The `URLSearchParams` class is also available on the global object.
677
694
  *
@@ -755,7 +772,7 @@ declare module "url" {
755
772
  * @param thisArg To be used as `this` value for when `fn` is called
756
773
  */
757
774
  forEach<TThis = this>(
758
- callback: (this: TThis, value: string, name: string, searchParams: URLSearchParams) => void,
775
+ fn: (this: TThis, value: string, name: string, searchParams: URLSearchParams) => void,
759
776
  thisArg?: TThis,
760
777
  ): void;
761
778
  /**
node v16.18/v8.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * The `v8` module exposes APIs that are specific to the version of [V8](https://developers.google.com/v8/) built into the Node.js binary. It can be accessed using:
2
+ * The `node:v8` module exposes APIs that are specific to the version of [V8](https://developers.google.com/v8/) built into the Node.js binary. It can be accessed using:
3
3
  *
4
4
  * ```js
5
- * const v8 = require('v8');
5
+ * const v8 = require('node:v8');
6
6
  * ```
7
- * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/v8.js)
7
+ * @see [source](https://github.com/nodejs/node/blob/v16.20.2/lib/v8.js)
8
8
  */
9
9
  declare module "v8" {
10
10
  import { Readable } from "node:stream";
@@ -29,6 +29,9 @@ declare module "v8" {
29
29
  does_zap_garbage: DoesZapCodeSpaceFlag;
30
30
  number_of_native_contexts: number;
31
31
  number_of_detached_contexts: number;
32
+ total_global_handles_size: number;
33
+ used_global_handles_size: number;
34
+ external_memory: number;
32
35
  }
33
36
  interface HeapCodeStatistics {
34
37
  code_and_metadata_size: number;
@@ -68,6 +71,15 @@ declare module "v8" {
68
71
  * of contexts that were detached and not yet garbage collected. This number
69
72
  * being non-zero indicates a potential memory leak.
70
73
  *
74
+ * `total_global_handles_size` The value of total\_global\_handles\_size is the
75
+ * total memory size of V8 global handles.
76
+ *
77
+ * `used_global_handles_size` The value of used\_global\_handles\_size is the
78
+ * used memory size of V8 global handles.
79
+ *
80
+ * `external_memory` The value of external\_memory is the memory size of array
81
+ * buffers and external strings.
82
+ *
71
83
  * ```js
72
84
  * {
73
85
  * total_heap_size: 7326976,
@@ -80,7 +92,10 @@ declare module "v8" {
80
92
  * peak_malloced_memory: 1127496,
81
93
  * does_zap_garbage: 0,
82
94
  * number_of_native_contexts: 1,
83
- * number_of_detached_contexts: 0
95
+ * number_of_detached_contexts: 0,
96
+ * total_global_handles_size: 8192,
97
+ * used_global_handles_size: 3296,
98
+ * external_memory: 318824
84
99
  * }
85
100
  * ```
86
101
  * @since v1.0.0
@@ -90,7 +105,7 @@ declare module "v8" {
90
105
  * Returns statistics about the V8 heap spaces, i.e. the segments which make up
91
106
  * the V8 heap. Neither the ordering of heap spaces, nor the availability of a
92
107
  * heap space can be guaranteed as the statistics are provided via the
93
- * V8[`GetHeapSpaceStatistics`](https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#ac673576f24fdc7a33378f8f57e1d13a4) function and may change from one V8 version to the
108
+ * V8 [`GetHeapSpaceStatistics`](https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#ac673576f24fdc7a33378f8f57e1d13a4) function and may change from one V8 version to the
94
109
  * next.
95
110
  *
96
111
  * The value returned is an array of objects containing the following properties:
@@ -149,7 +164,7 @@ declare module "v8" {
149
164
  *
150
165
  * ```js
151
166
  * // Print GC events to stdout for one minute.
152
- * const v8 = require('v8');
167
+ * const v8 = require('node:v8');
153
168
  * v8.setFlagsFromString('--trace_gc');
154
169
  * setTimeout(() => { v8.setFlagsFromString('--notrace_gc'); }, 60e3);
155
170
  * ```
@@ -163,9 +178,16 @@ declare module "v8" {
163
178
  * Chrome DevTools. The JSON schema is undocumented and specific to the
164
179
  * V8 engine. Therefore, the schema may change from one version of V8 to the next.
165
180
  *
181
+ * Creating a heap snapshot requires memory about twice the size of the heap at
182
+ * the time the snapshot is created. This results in the risk of OOM killers
183
+ * terminating the process.
184
+ *
185
+ * Generating a snapshot is a synchronous operation which blocks the event loop
186
+ * for a duration depending on the heap size.
187
+ *
166
188
  * ```js
167
189
  * // Print heap snapshot to the console
168
- * const v8 = require('v8');
190
+ * const v8 = require('node:v8');
169
191
  * const stream = v8.getHeapSnapshot();
170
192
  * stream.pipe(process.stdout);
171
193
  * ```
@@ -182,13 +204,20 @@ declare module "v8" {
182
204
  * A heap snapshot is specific to a single V8 isolate. When using `worker threads`, a heap snapshot generated from the main thread will
183
205
  * not contain any information about the workers, and vice versa.
184
206
  *
207
+ * Creating a heap snapshot requires memory about twice the size of the heap at
208
+ * the time the snapshot is created. This results in the risk of OOM killers
209
+ * terminating the process.
210
+ *
211
+ * Generating a snapshot is a synchronous operation which blocks the event loop
212
+ * for a duration depending on the heap size.
213
+ *
185
214
  * ```js
186
- * const { writeHeapSnapshot } = require('v8');
215
+ * const { writeHeapSnapshot } = require('node:v8');
187
216
  * const {
188
217
  * Worker,
189
218
  * isMainThread,
190
- * parentPort
191
- * } = require('worker_threads');
219
+ * parentPort,
220
+ * } = require('node:worker_threads');
192
221
  *
193
222
  * if (isMainThread) {
194
223
  * const worker = new Worker(__filename);
@@ -219,13 +248,16 @@ declare module "v8" {
219
248
  */
220
249
  function writeHeapSnapshot(filename?: string): string;
221
250
  /**
222
- * Returns an object with the following properties:
251
+ * Get statistics about code and its metadata in the heap, see
252
+ * V8 [`GetHeapCodeAndMetadataStatistics`](https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#a6079122af17612ef54ef3348ce170866) API. Returns an object with the
253
+ * following properties:
223
254
  *
224
255
  * ```js
225
256
  * {
226
257
  * code_and_metadata_size: 212208,
227
258
  * bytecode_and_metadata_size: 161368,
228
- * external_script_source_size: 1410794
259
+ * external_script_source_size: 1410794,
260
+ * cpu_profiler_metadata_size: 0,
229
261
  * }
230
262
  * ```
231
263
  * @since v12.8.0
@@ -275,7 +307,7 @@ declare module "v8" {
275
307
  */
276
308
  writeDouble(value: number): void;
277
309
  /**
278
- * Write raw bytes into the serializers internal buffer. The deserializer
310
+ * Write raw bytes into the serializer's internal buffer. The deserializer
279
311
  * will require a way to compute the length of the buffer.
280
312
  * For use inside of a custom `serializer._writeHostObject()`.
281
313
  */
@@ -331,7 +363,7 @@ declare module "v8" {
331
363
  */
332
364
  readDouble(): number;
333
365
  /**
334
- * Read raw bytes from the deserializers internal buffer. The `length` parameter
366
+ * Read raw bytes from the deserializer's internal buffer. The `length` parameter
335
367
  * must correspond to the length of the buffer that was passed to `serializer.writeRawBytes()`.
336
368
  * For use inside of a custom `deserializer._readHostObject()`.
337
369
  */
@@ -344,6 +376,10 @@ declare module "v8" {
344
376
  class DefaultDeserializer extends Deserializer {}
345
377
  /**
346
378
  * Uses a `DefaultSerializer` to serialize `value` into a buffer.
379
+ *
380
+ * `ERR_BUFFER_TOO_LARGE` will be thrown when trying to
381
+ * serialize a huge object which requires buffer
382
+ * larger than `buffer.constants.MAX_LENGTH`.
347
383
  * @since v8.0.0
348
384
  */
349
385
  function serialize(value: any): Buffer;
@@ -362,20 +398,27 @@ declare module "v8" {
362
398
  *
363
399
  * When the process is about to exit, one last coverage will still be written to
364
400
  * disk unless {@link stopCoverage} is invoked before the process exits.
365
- * @since v15.1.0, v12.22.0
401
+ * @since v15.1.0, v14.18.0, v12.22.0
366
402
  */
367
403
  function takeCoverage(): void;
368
404
  /**
369
405
  * The `v8.stopCoverage()` method allows the user to stop the coverage collection
370
406
  * started by `NODE_V8_COVERAGE`, so that V8 can release the execution count
371
407
  * records and optimize code. This can be used in conjunction with {@link takeCoverage} if the user wants to collect the coverage on demand.
372
- * @since v15.1.0, v12.22.0
408
+ * @since v15.1.0, v14.18.0, v12.22.0
373
409
  */
374
410
  function stopCoverage(): void;
411
+ /**
412
+ * The API is a no-op if `--heapsnapshot-near-heap-limit` is already set from the command line or the API is called more than once.
413
+ * `limit` must be a positive integer. See [`--heapsnapshot-near-heap-limit`](https://nodejs.org/docs/latest-v16.x/api/cli.html#--heapsnapshot-near-heap-limitmax_count) for more information.
414
+ * @experimental
415
+ * @since v16.18.0
416
+ */
417
+ function setHeapSnapshotNearHeapLimit(limit: number): void;
375
418
  /**
376
419
  * Called when a promise is constructed. This does not mean that corresponding before/after events will occur, only that the possibility exists. This will
377
420
  * happen if a promise is created without ever getting a continuation.
378
- * @since v17.1.0, v16.14.0
421
+ * @since v16.14.0
379
422
  * @param promise The promise being created.
380
423
  * @param parent The promise continued from, if applicable.
381
424
  */
@@ -387,14 +430,14 @@ declare module "v8" {
387
430
  *
388
431
  * The before callback will be called 0 to N times. The before callback will typically be called 0 times if no continuation was ever made for the promise.
389
432
  * The before callback may be called many times in the case where many continuations have been made from the same promise.
390
- * @since v17.1.0, v16.14.0
433
+ * @since v16.14.0
391
434
  */
392
435
  interface Before {
393
436
  (promise: Promise<unknown>): void;
394
437
  }
395
438
  /**
396
439
  * Called immediately after a promise continuation executes. This may be after a `then()`, `catch()`, or `finally()` handler or before an await after another await.
397
- * @since v17.1.0, v16.14.0
440
+ * @since v16.14.0
398
441
  */
399
442
  interface After {
400
443
  (promise: Promise<unknown>): void;
@@ -402,7 +445,7 @@ declare module "v8" {
402
445
  /**
403
446
  * Called when the promise receives a resolution or rejection value. This may occur synchronously in the case of {@link Promise.resolve()} or
404
447
  * {@link Promise.reject()}.
405
- * @since v17.1.0, v16.14.0
448
+ * @since v16.14.0
406
449
  */
407
450
  interface Settled {
408
451
  (promise: Promise<unknown>): void;
@@ -413,7 +456,7 @@ declare module "v8" {
413
456
  *
414
457
  * Because promises are asynchronous resources whose lifecycle is tracked via the promise hooks mechanism, the `init()`, `before()`, `after()`, and
415
458
  * `settled()` callbacks must not be async functions as they create more promises which would produce an infinite loop.
416
- * @since v17.1.0, v16.14.0
459
+ * @since v16.14.0
417
460
  */
418
461
  interface HookCallbacks {
419
462
  init?: Init;
@@ -424,28 +467,28 @@ declare module "v8" {
424
467
  interface PromiseHooks {
425
468
  /**
426
469
  * The `init` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
427
- * @since v17.1.0, v16.14.0
470
+ * @since v16.14.0
428
471
  * @param init The {@link Init | `init` callback} to call when a promise is created.
429
472
  * @return Call to stop the hook.
430
473
  */
431
474
  onInit: (init: Init) => Function;
432
475
  /**
433
476
  * The `settled` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
434
- * @since v17.1.0, v16.14.0
477
+ * @since v16.14.0
435
478
  * @param settled The {@link Settled | `settled` callback} to call when a promise is created.
436
479
  * @return Call to stop the hook.
437
480
  */
438
481
  onSettled: (settled: Settled) => Function;
439
482
  /**
440
483
  * The `before` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
441
- * @since v17.1.0, v16.14.0
484
+ * @since v16.14.0
442
485
  * @param before The {@link Before | `before` callback} to call before a promise continuation executes.
443
486
  * @return Call to stop the hook.
444
487
  */
445
488
  onBefore: (before: Before) => Function;
446
489
  /**
447
490
  * The `after` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
448
- * @since v17.1.0, v16.14.0
491
+ * @since v16.14.0
449
492
  * @param after The {@link After | `after` callback} to call after a promise continuation executes.
450
493
  * @return Call to stop the hook.
451
494
  */
@@ -455,7 +498,7 @@ declare module "v8" {
455
498
  * The callbacks `init()`/`before()`/`after()`/`settled()` are called for the respective events during a promise's lifetime.
456
499
  * All callbacks are optional. For example, if only promise creation needs to be tracked, then only the init callback needs to be passed.
457
500
  * The hook callbacks must be plain functions. Providing async functions will throw as it would produce an infinite microtask loop.
458
- * @since v17.1.0, v16.14.0
501
+ * @since v16.14.0
459
502
  * @param callbacks The {@link HookCallbacks | Hook Callbacks} to register
460
503
  * @return Used for disabling hooks
461
504
  */
@@ -463,9 +506,120 @@ declare module "v8" {
463
506
  }
464
507
  /**
465
508
  * The `promiseHooks` interface can be used to track promise lifecycle events.
466
- * @since v17.1.0, v16.14.0
509
+ * @since v16.14.0
467
510
  */
468
511
  const promiseHooks: PromiseHooks;
512
+ type StartupSnapshotCallbackFn = (args: any) => any;
513
+ interface StartupSnapshot {
514
+ /**
515
+ * Add a callback that will be called when the Node.js instance is about to get serialized into a snapshot and exit.
516
+ * This can be used to release resources that should not or cannot be serialized or to convert user data into a form more suitable for serialization.
517
+ * @since v16.17.0
518
+ */
519
+ addSerializeCallback(callback: StartupSnapshotCallbackFn, data?: any): void;
520
+ /**
521
+ * Add a callback that will be called when the Node.js instance is deserialized from a snapshot.
522
+ * The `callback` and the `data` (if provided) will be serialized into the snapshot, they can be used to re-initialize the state of the application or
523
+ * to re-acquire resources that the application needs when the application is restarted from the snapshot.
524
+ * @since v16.17.0
525
+ */
526
+ addDeserializeCallback(callback: StartupSnapshotCallbackFn, data?: any): void;
527
+ /**
528
+ * This sets the entry point of the Node.js application when it is deserialized from a snapshot. This can be called only once in the snapshot building script.
529
+ * If called, the deserialized application no longer needs an additional entry point script to start up and will simply invoke the callback along with the deserialized
530
+ * data (if provided), otherwise an entry point script still needs to be provided to the deserialized application.
531
+ * @since v16.17.0
532
+ */
533
+ setDeserializeMainFunction(callback: StartupSnapshotCallbackFn, data?: any): void;
534
+ /**
535
+ * Returns true if the Node.js instance is run to build a snapshot.
536
+ * @since v16.17.0
537
+ */
538
+ isBuildingSnapshot(): boolean;
539
+ }
540
+ /**
541
+ * The `v8.startupSnapshot` interface can be used to add serialization and deserialization hooks for custom startup snapshots.
542
+ *
543
+ * ```bash
544
+ * $ node --snapshot-blob snapshot.blob --build-snapshot entry.js
545
+ * # This launches a process with the snapshot
546
+ * $ node --snapshot-blob snapshot.blob
547
+ * ```
548
+ *
549
+ * In the example above, `entry.js` can use methods from the `v8.startupSnapshot` interface to specify how to save information for custom objects
550
+ * in the snapshot during serialization
551
+ * and how the information can be used to synchronize these objects during deserialization of the snapshot.
552
+ * For example, if the `entry.js` contains the following script:
553
+ *
554
+ * ```js
555
+ * 'use strict';
556
+ *
557
+ * const fs = require('node:fs');
558
+ * const zlib = require('node:zlib');
559
+ * const path = require('node:path');
560
+ * const assert = require('node:assert');
561
+ *
562
+ * const v8 = require('node:v8');
563
+ *
564
+ * class BookShelf {
565
+ * storage = new Map();
566
+ *
567
+ * // Reading a series of files from directory and store them into storage.
568
+ * constructor(directory, books) {
569
+ * for (const book of books) {
570
+ * this.storage.set(book, fs.readFileSync(path.join(directory, book)));
571
+ * }
572
+ * }
573
+ *
574
+ * static compressAll(shelf) {
575
+ * for (const [ book, content ] of shelf.storage) {
576
+ * shelf.storage.set(book, zlib.gzipSync(content));
577
+ * }
578
+ * }
579
+ *
580
+ * static decompressAll(shelf) {
581
+ * for (const [ book, content ] of shelf.storage) {
582
+ * shelf.storage.set(book, zlib.gunzipSync(content));
583
+ * }
584
+ * }
585
+ * }
586
+ *
587
+ * // __dirname here is where the snapshot script is placed
588
+ * // during snapshot building time.
589
+ * const shelf = new BookShelf(__dirname, [
590
+ * 'book1.en_US.txt',
591
+ * 'book1.es_ES.txt',
592
+ * 'book2.zh_CN.txt',
593
+ * ]);
594
+ *
595
+ * assert(v8.startupSnapshot.isBuildingSnapshot());
596
+ * // On snapshot serialization, compress the books to reduce size.
597
+ * v8.startupSnapshot.addSerializeCallback(BookShelf.compressAll, shelf);
598
+ * // On snapshot deserialization, decompress the books.
599
+ * v8.startupSnapshot.addDeserializeCallback(BookShelf.decompressAll, shelf);
600
+ * v8.startupSnapshot.setDeserializeMainFunction((shelf) => {
601
+ * // process.env and process.argv are refreshed during snapshot
602
+ * // deserialization.
603
+ * const lang = process.env.BOOK_LANG || 'en_US';
604
+ * const book = process.argv[1];
605
+ * const name = `${book}.${lang}.txt`;
606
+ * console.log(shelf.storage.get(name));
607
+ * }, shelf);
608
+ * ```
609
+ *
610
+ * The resulted binary will get print the data deserialized from the snapshot during start up, using the refreshed `process.env` and `process.argv` of the launched process:
611
+ *
612
+ * ```bash
613
+ * $ BOOK_LANG=es_ES node --snapshot-blob snapshot.blob book1
614
+ * # Prints content of book1.es_ES.txt deserialized from the snapshot.
615
+ * ```
616
+ *
617
+ * Currently the application deserialized from a user-land snapshot cannot be snapshotted again, so these APIs are only available to applications that are not deserialized from a user-land snapshot.
618
+ *
619
+ * @experimental
620
+ * @since v16.17.0
621
+ */
622
+ const startupSnapshot: StartupSnapshot;
469
623
  }
470
624
  declare module "node:v8" {
471
625
  export * from "v8";