mcpbrowser 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/.mcpregistry_github_token +1 -0
  2. package/.mcpregistry_registry_token +1 -0
  3. package/README.md +50 -52
  4. package/extension/.vscodeignore +6 -0
  5. package/extension/LICENSE +21 -0
  6. package/extension/README.md +61 -0
  7. package/extension/icon.png +0 -0
  8. package/extension/icon.svg +35 -0
  9. package/extension/mcpbrowser-0.1.1.vsix +0 -0
  10. package/extension/mcpbrowser-0.1.2.vsix +0 -0
  11. package/extension/mcpbrowser-0.1.3.vsix +0 -0
  12. package/extension/mcpbrowser-0.1.4.vsix +0 -0
  13. package/extension/mcpbrowser-config-0.1.0.vsix +0 -0
  14. package/extension/node_modules/.package-lock.json +32 -0
  15. package/extension/node_modules/@types/node/LICENSE +21 -0
  16. package/extension/node_modules/@types/node/README.md +15 -0
  17. package/extension/node_modules/@types/node/assert/strict.d.ts +8 -0
  18. package/extension/node_modules/@types/node/assert.d.ts +1062 -0
  19. package/extension/node_modules/@types/node/async_hooks.d.ts +605 -0
  20. package/extension/node_modules/@types/node/buffer.buffer.d.ts +471 -0
  21. package/extension/node_modules/@types/node/buffer.d.ts +1936 -0
  22. package/extension/node_modules/@types/node/child_process.d.ts +1475 -0
  23. package/extension/node_modules/@types/node/cluster.d.ts +577 -0
  24. package/extension/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
  25. package/extension/node_modules/@types/node/compatibility/index.d.ts +9 -0
  26. package/extension/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
  27. package/extension/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
  28. package/extension/node_modules/@types/node/console.d.ts +452 -0
  29. package/extension/node_modules/@types/node/constants.d.ts +21 -0
  30. package/extension/node_modules/@types/node/crypto.d.ts +4590 -0
  31. package/extension/node_modules/@types/node/dgram.d.ts +597 -0
  32. package/extension/node_modules/@types/node/diagnostics_channel.d.ts +578 -0
  33. package/extension/node_modules/@types/node/dns/promises.d.ts +479 -0
  34. package/extension/node_modules/@types/node/dns.d.ts +871 -0
  35. package/extension/node_modules/@types/node/domain.d.ts +170 -0
  36. package/extension/node_modules/@types/node/events.d.ts +977 -0
  37. package/extension/node_modules/@types/node/fs/promises.d.ts +1270 -0
  38. package/extension/node_modules/@types/node/fs.d.ts +4375 -0
  39. package/extension/node_modules/@types/node/globals.d.ts +172 -0
  40. package/extension/node_modules/@types/node/globals.typedarray.d.ts +38 -0
  41. package/extension/node_modules/@types/node/http.d.ts +2049 -0
  42. package/extension/node_modules/@types/node/http2.d.ts +2631 -0
  43. package/extension/node_modules/@types/node/https.d.ts +578 -0
  44. package/extension/node_modules/@types/node/index.d.ts +93 -0
  45. package/extension/node_modules/@types/node/inspector.generated.d.ts +3966 -0
  46. package/extension/node_modules/@types/node/module.d.ts +539 -0
  47. package/extension/node_modules/@types/node/net.d.ts +1012 -0
  48. package/extension/node_modules/@types/node/os.d.ts +506 -0
  49. package/extension/node_modules/@types/node/package.json +140 -0
  50. package/extension/node_modules/@types/node/path.d.ts +200 -0
  51. package/extension/node_modules/@types/node/perf_hooks.d.ts +961 -0
  52. package/extension/node_modules/@types/node/process.d.ts +1957 -0
  53. package/extension/node_modules/@types/node/punycode.d.ts +117 -0
  54. package/extension/node_modules/@types/node/querystring.d.ts +152 -0
  55. package/extension/node_modules/@types/node/readline/promises.d.ts +162 -0
  56. package/extension/node_modules/@types/node/readline.d.ts +589 -0
  57. package/extension/node_modules/@types/node/repl.d.ts +430 -0
  58. package/extension/node_modules/@types/node/sea.d.ts +153 -0
  59. package/extension/node_modules/@types/node/stream/consumers.d.ts +38 -0
  60. package/extension/node_modules/@types/node/stream/promises.d.ts +90 -0
  61. package/extension/node_modules/@types/node/stream/web.d.ts +533 -0
  62. package/extension/node_modules/@types/node/stream.d.ts +1675 -0
  63. package/extension/node_modules/@types/node/string_decoder.d.ts +67 -0
  64. package/extension/node_modules/@types/node/test.d.ts +1787 -0
  65. package/extension/node_modules/@types/node/timers/promises.d.ts +108 -0
  66. package/extension/node_modules/@types/node/timers.d.ts +286 -0
  67. package/extension/node_modules/@types/node/tls.d.ts +1255 -0
  68. package/extension/node_modules/@types/node/trace_events.d.ts +197 -0
  69. package/extension/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +468 -0
  70. package/extension/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +34 -0
  71. package/extension/node_modules/@types/node/ts5.6/index.d.ts +93 -0
  72. package/extension/node_modules/@types/node/tty.d.ts +208 -0
  73. package/extension/node_modules/@types/node/url.d.ts +964 -0
  74. package/extension/node_modules/@types/node/util.d.ts +2331 -0
  75. package/extension/node_modules/@types/node/v8.d.ts +809 -0
  76. package/extension/node_modules/@types/node/vm.d.ts +1001 -0
  77. package/extension/node_modules/@types/node/wasi.d.ts +181 -0
  78. package/extension/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
  79. package/extension/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
  80. package/extension/node_modules/@types/node/web-globals/events.d.ts +97 -0
  81. package/extension/node_modules/@types/node/web-globals/fetch.d.ts +46 -0
  82. package/extension/node_modules/@types/node/worker_threads.d.ts +715 -0
  83. package/extension/node_modules/@types/node/zlib.d.ts +540 -0
  84. package/extension/node_modules/@types/vscode/LICENSE +21 -0
  85. package/extension/node_modules/@types/vscode/README.md +15 -0
  86. package/extension/node_modules/@types/vscode/index.d.ts +21153 -0
  87. package/extension/node_modules/@types/vscode/package.json +26 -0
  88. package/extension/node_modules/undici-types/LICENSE +21 -0
  89. package/extension/node_modules/undici-types/README.md +6 -0
  90. package/extension/node_modules/undici-types/agent.d.ts +31 -0
  91. package/extension/node_modules/undici-types/api.d.ts +43 -0
  92. package/extension/node_modules/undici-types/balanced-pool.d.ts +29 -0
  93. package/extension/node_modules/undici-types/cache.d.ts +36 -0
  94. package/extension/node_modules/undici-types/client.d.ts +108 -0
  95. package/extension/node_modules/undici-types/connector.d.ts +34 -0
  96. package/extension/node_modules/undici-types/content-type.d.ts +21 -0
  97. package/extension/node_modules/undici-types/cookies.d.ts +28 -0
  98. package/extension/node_modules/undici-types/diagnostics-channel.d.ts +66 -0
  99. package/extension/node_modules/undici-types/dispatcher.d.ts +256 -0
  100. package/extension/node_modules/undici-types/env-http-proxy-agent.d.ts +21 -0
  101. package/extension/node_modules/undici-types/errors.d.ts +149 -0
  102. package/extension/node_modules/undici-types/eventsource.d.ts +61 -0
  103. package/extension/node_modules/undici-types/fetch.d.ts +209 -0
  104. package/extension/node_modules/undici-types/file.d.ts +39 -0
  105. package/extension/node_modules/undici-types/filereader.d.ts +54 -0
  106. package/extension/node_modules/undici-types/formdata.d.ts +108 -0
  107. package/extension/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  108. package/extension/node_modules/undici-types/global-origin.d.ts +7 -0
  109. package/extension/node_modules/undici-types/handlers.d.ts +15 -0
  110. package/extension/node_modules/undici-types/header.d.ts +4 -0
  111. package/extension/node_modules/undici-types/index.d.ts +71 -0
  112. package/extension/node_modules/undici-types/interceptors.d.ts +17 -0
  113. package/extension/node_modules/undici-types/mock-agent.d.ts +50 -0
  114. package/extension/node_modules/undici-types/mock-client.d.ts +25 -0
  115. package/extension/node_modules/undici-types/mock-errors.d.ts +12 -0
  116. package/extension/node_modules/undici-types/mock-interceptor.d.ts +93 -0
  117. package/extension/node_modules/undici-types/mock-pool.d.ts +25 -0
  118. package/extension/node_modules/undici-types/package.json +55 -0
  119. package/extension/node_modules/undici-types/patch.d.ts +33 -0
  120. package/extension/node_modules/undici-types/pool-stats.d.ts +19 -0
  121. package/extension/node_modules/undici-types/pool.d.ts +39 -0
  122. package/extension/node_modules/undici-types/proxy-agent.d.ts +28 -0
  123. package/extension/node_modules/undici-types/readable.d.ts +65 -0
  124. package/extension/node_modules/undici-types/retry-agent.d.ts +8 -0
  125. package/extension/node_modules/undici-types/retry-handler.d.ts +116 -0
  126. package/extension/node_modules/undici-types/util.d.ts +18 -0
  127. package/extension/node_modules/undici-types/webidl.d.ts +228 -0
  128. package/extension/node_modules/undici-types/websocket.d.ts +150 -0
  129. package/extension/package-lock.json +44 -0
  130. package/extension/package.json +55 -0
  131. package/extension/src/extension.js +257 -0
  132. package/package.json +1 -1
  133. package/server.json +3 -3
  134. package/src/mcp-browser.js +1 -1
@@ -0,0 +1,809 @@
1
+ /**
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
+ *
4
+ * ```js
5
+ * import v8 from 'node:v8';
6
+ * ```
7
+ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/v8.js)
8
+ */
9
+ declare module "v8" {
10
+ import { NonSharedBuffer } from "node:buffer";
11
+ import { Readable } from "node:stream";
12
+ interface HeapSpaceInfo {
13
+ space_name: string;
14
+ space_size: number;
15
+ space_used_size: number;
16
+ space_available_size: number;
17
+ physical_space_size: number;
18
+ }
19
+ // ** Signifies if the --zap_code_space option is enabled or not. 1 == enabled, 0 == disabled. */
20
+ type DoesZapCodeSpaceFlag = 0 | 1;
21
+ interface HeapInfo {
22
+ total_heap_size: number;
23
+ total_heap_size_executable: number;
24
+ total_physical_size: number;
25
+ total_available_size: number;
26
+ used_heap_size: number;
27
+ heap_size_limit: number;
28
+ malloced_memory: number;
29
+ peak_malloced_memory: number;
30
+ does_zap_garbage: DoesZapCodeSpaceFlag;
31
+ number_of_native_contexts: number;
32
+ number_of_detached_contexts: number;
33
+ total_global_handles_size: number;
34
+ used_global_handles_size: number;
35
+ external_memory: number;
36
+ }
37
+ interface HeapCodeStatistics {
38
+ code_and_metadata_size: number;
39
+ bytecode_and_metadata_size: number;
40
+ external_script_source_size: number;
41
+ }
42
+ interface HeapSnapshotOptions {
43
+ /**
44
+ * If true, expose internals in the heap snapshot.
45
+ * @default false
46
+ */
47
+ exposeInternals?: boolean | undefined;
48
+ /**
49
+ * If true, expose numeric values in artificial fields.
50
+ * @default false
51
+ */
52
+ exposeNumericValues?: boolean | undefined;
53
+ }
54
+ /**
55
+ * Returns an integer representing a version tag derived from the V8 version,
56
+ * command-line flags, and detected CPU features. This is useful for determining
57
+ * whether a `vm.Script` `cachedData` buffer is compatible with this instance
58
+ * of V8.
59
+ *
60
+ * ```js
61
+ * console.log(v8.cachedDataVersionTag()); // 3947234607
62
+ * // The value returned by v8.cachedDataVersionTag() is derived from the V8
63
+ * // version, command-line flags, and detected CPU features. Test that the value
64
+ * // does indeed update when flags are toggled.
65
+ * v8.setFlagsFromString('--allow_natives_syntax');
66
+ * console.log(v8.cachedDataVersionTag()); // 183726201
67
+ * ```
68
+ * @since v8.0.0
69
+ */
70
+ function cachedDataVersionTag(): number;
71
+ /**
72
+ * Returns an object with the following properties:
73
+ *
74
+ * `does_zap_garbage` is a 0/1 boolean, which signifies whether the `--zap_code_space` option is enabled or not. This makes V8 overwrite heap
75
+ * garbage with a bit pattern. The RSS footprint (resident set size) gets bigger
76
+ * because it continuously touches all heap pages and that makes them less likely
77
+ * to get swapped out by the operating system.
78
+ *
79
+ * `number_of_native_contexts` The value of native\_context is the number of the
80
+ * top-level contexts currently active. Increase of this number over time indicates
81
+ * a memory leak.
82
+ *
83
+ * `number_of_detached_contexts` The value of detached\_context is the number
84
+ * of contexts that were detached and not yet garbage collected. This number
85
+ * being non-zero indicates a potential memory leak.
86
+ *
87
+ * `total_global_handles_size` The value of total\_global\_handles\_size is the
88
+ * total memory size of V8 global handles.
89
+ *
90
+ * `used_global_handles_size` The value of used\_global\_handles\_size is the
91
+ * used memory size of V8 global handles.
92
+ *
93
+ * `external_memory` The value of external\_memory is the memory size of array
94
+ * buffers and external strings.
95
+ *
96
+ * ```js
97
+ * {
98
+ * total_heap_size: 7326976,
99
+ * total_heap_size_executable: 4194304,
100
+ * total_physical_size: 7326976,
101
+ * total_available_size: 1152656,
102
+ * used_heap_size: 3476208,
103
+ * heap_size_limit: 1535115264,
104
+ * malloced_memory: 16384,
105
+ * peak_malloced_memory: 1127496,
106
+ * does_zap_garbage: 0,
107
+ * number_of_native_contexts: 1,
108
+ * number_of_detached_contexts: 0,
109
+ * total_global_handles_size: 8192,
110
+ * used_global_handles_size: 3296,
111
+ * external_memory: 318824
112
+ * }
113
+ * ```
114
+ * @since v1.0.0
115
+ */
116
+ function getHeapStatistics(): HeapInfo;
117
+ /**
118
+ * Returns statistics about the V8 heap spaces, i.e. the segments which make up
119
+ * the V8 heap. Neither the ordering of heap spaces, nor the availability of a
120
+ * heap space can be guaranteed as the statistics are provided via the
121
+ * 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
122
+ * next.
123
+ *
124
+ * The value returned is an array of objects containing the following properties:
125
+ *
126
+ * ```json
127
+ * [
128
+ * {
129
+ * "space_name": "new_space",
130
+ * "space_size": 2063872,
131
+ * "space_used_size": 951112,
132
+ * "space_available_size": 80824,
133
+ * "physical_space_size": 2063872
134
+ * },
135
+ * {
136
+ * "space_name": "old_space",
137
+ * "space_size": 3090560,
138
+ * "space_used_size": 2493792,
139
+ * "space_available_size": 0,
140
+ * "physical_space_size": 3090560
141
+ * },
142
+ * {
143
+ * "space_name": "code_space",
144
+ * "space_size": 1260160,
145
+ * "space_used_size": 644256,
146
+ * "space_available_size": 960,
147
+ * "physical_space_size": 1260160
148
+ * },
149
+ * {
150
+ * "space_name": "map_space",
151
+ * "space_size": 1094160,
152
+ * "space_used_size": 201608,
153
+ * "space_available_size": 0,
154
+ * "physical_space_size": 1094160
155
+ * },
156
+ * {
157
+ * "space_name": "large_object_space",
158
+ * "space_size": 0,
159
+ * "space_used_size": 0,
160
+ * "space_available_size": 1490980608,
161
+ * "physical_space_size": 0
162
+ * }
163
+ * ]
164
+ * ```
165
+ * @since v6.0.0
166
+ */
167
+ function getHeapSpaceStatistics(): HeapSpaceInfo[];
168
+ /**
169
+ * The `v8.setFlagsFromString()` method can be used to programmatically set
170
+ * V8 command-line flags. This method should be used with care. Changing settings
171
+ * after the VM has started may result in unpredictable behavior, including
172
+ * crashes and data loss; or it may simply do nothing.
173
+ *
174
+ * The V8 options available for a version of Node.js may be determined by running `node --v8-options`.
175
+ *
176
+ * Usage:
177
+ *
178
+ * ```js
179
+ * // Print GC events to stdout for one minute.
180
+ * import v8 from 'node:v8';
181
+ * v8.setFlagsFromString('--trace_gc');
182
+ * setTimeout(() => { v8.setFlagsFromString('--notrace_gc'); }, 60e3);
183
+ * ```
184
+ * @since v1.0.0
185
+ */
186
+ function setFlagsFromString(flags: string): void;
187
+ /**
188
+ * This is similar to the [`queryObjects()` console API](https://developer.chrome.com/docs/devtools/console/utilities#queryObjects-function)
189
+ * provided by the Chromium DevTools console. It can be used to search for objects that have the matching constructor on its prototype chain
190
+ * in the heap after a full garbage collection, which can be useful for memory leak regression tests. To avoid surprising results, users should
191
+ * avoid using this API on constructors whose implementation they don't control, or on constructors that can be invoked by other parties in the
192
+ * application.
193
+ *
194
+ * To avoid accidental leaks, this API does not return raw references to the objects found. By default, it returns the count of the objects
195
+ * found. If `options.format` is `'summary'`, it returns an array containing brief string representations for each object. The visibility provided
196
+ * in this API is similar to what the heap snapshot provides, while users can save the cost of serialization and parsing and directly filter the
197
+ * target objects during the search.
198
+ *
199
+ * Only objects created in the current execution context are included in the results.
200
+ *
201
+ * ```js
202
+ * import { queryObjects } from 'node:v8';
203
+ * class A { foo = 'bar'; }
204
+ * console.log(queryObjects(A)); // 0
205
+ * const a = new A();
206
+ * console.log(queryObjects(A)); // 1
207
+ * // [ "A { foo: 'bar' }" ]
208
+ * console.log(queryObjects(A, { format: 'summary' }));
209
+ *
210
+ * class B extends A { bar = 'qux'; }
211
+ * const b = new B();
212
+ * console.log(queryObjects(B)); // 1
213
+ * // [ "B { foo: 'bar', bar: 'qux' }" ]
214
+ * console.log(queryObjects(B, { format: 'summary' }));
215
+ *
216
+ * // Note that, when there are child classes inheriting from a constructor,
217
+ * // the constructor also shows up in the prototype chain of the child
218
+ * // classes's prototoype, so the child classes's prototoype would also be
219
+ * // included in the result.
220
+ * console.log(queryObjects(A)); // 3
221
+ * // [ "B { foo: 'bar', bar: 'qux' }", 'A {}', "A { foo: 'bar' }" ]
222
+ * console.log(queryObjects(A, { format: 'summary' }));
223
+ * ```
224
+ * @param ctor The constructor that can be used to search on the prototype chain in order to filter target objects in the heap.
225
+ * @since v20.13.0
226
+ * @experimental
227
+ */
228
+ function queryObjects(ctor: Function): number | string[];
229
+ function queryObjects(ctor: Function, options: { format: "count" }): number;
230
+ function queryObjects(ctor: Function, options: { format: "summary" }): string[];
231
+ /**
232
+ * Generates a snapshot of the current V8 heap and returns a Readable
233
+ * Stream that may be used to read the JSON serialized representation.
234
+ * This JSON stream format is intended to be used with tools such as
235
+ * Chrome DevTools. The JSON schema is undocumented and specific to the
236
+ * V8 engine. Therefore, the schema may change from one version of V8 to the next.
237
+ *
238
+ * Creating a heap snapshot requires memory about twice the size of the heap at
239
+ * the time the snapshot is created. This results in the risk of OOM killers
240
+ * terminating the process.
241
+ *
242
+ * Generating a snapshot is a synchronous operation which blocks the event loop
243
+ * for a duration depending on the heap size.
244
+ *
245
+ * ```js
246
+ * // Print heap snapshot to the console
247
+ * import v8 from 'node:v8';
248
+ * const stream = v8.getHeapSnapshot();
249
+ * stream.pipe(process.stdout);
250
+ * ```
251
+ * @since v11.13.0
252
+ * @return A Readable containing the V8 heap snapshot.
253
+ */
254
+ function getHeapSnapshot(options?: HeapSnapshotOptions): Readable;
255
+ /**
256
+ * Generates a snapshot of the current V8 heap and writes it to a JSON
257
+ * file. This file is intended to be used with tools such as Chrome
258
+ * DevTools. The JSON schema is undocumented and specific to the V8
259
+ * engine, and may change from one version of V8 to the next.
260
+ *
261
+ * A heap snapshot is specific to a single V8 isolate. When using `worker threads`, a heap snapshot generated from the main thread will
262
+ * not contain any information about the workers, and vice versa.
263
+ *
264
+ * Creating a heap snapshot requires memory about twice the size of the heap at
265
+ * the time the snapshot is created. This results in the risk of OOM killers
266
+ * terminating the process.
267
+ *
268
+ * Generating a snapshot is a synchronous operation which blocks the event loop
269
+ * for a duration depending on the heap size.
270
+ *
271
+ * ```js
272
+ * import { writeHeapSnapshot } from 'node:v8';
273
+ * import {
274
+ * Worker,
275
+ * isMainThread,
276
+ * parentPort,
277
+ * } from 'node:worker_threads';
278
+ *
279
+ * if (isMainThread) {
280
+ * const worker = new Worker(__filename);
281
+ *
282
+ * worker.once('message', (filename) => {
283
+ * console.log(`worker heapdump: ${filename}`);
284
+ * // Now get a heapdump for the main thread.
285
+ * console.log(`main thread heapdump: ${writeHeapSnapshot()}`);
286
+ * });
287
+ *
288
+ * // Tell the worker to create a heapdump.
289
+ * worker.postMessage('heapdump');
290
+ * } else {
291
+ * parentPort.once('message', (message) => {
292
+ * if (message === 'heapdump') {
293
+ * // Generate a heapdump for the worker
294
+ * // and return the filename to the parent.
295
+ * parentPort.postMessage(writeHeapSnapshot());
296
+ * }
297
+ * });
298
+ * }
299
+ * ```
300
+ * @since v11.13.0
301
+ * @param filename The file path where the V8 heap snapshot is to be saved. If not specified, a file name with the pattern `'Heap-${yyyymmdd}-${hhmmss}-${pid}-${thread_id}.heapsnapshot'` will be
302
+ * generated, where `{pid}` will be the PID of the Node.js process, `{thread_id}` will be `0` when `writeHeapSnapshot()` is called from the main Node.js thread or the id of a
303
+ * worker thread.
304
+ * @return The filename where the snapshot was saved.
305
+ */
306
+ function writeHeapSnapshot(filename?: string, options?: HeapSnapshotOptions): string;
307
+ /**
308
+ * Get statistics about code and its metadata in the heap, see
309
+ * V8 [`GetHeapCodeAndMetadataStatistics`](https://v8docs.nodesource.com/node-13.2/d5/dda/classv8_1_1_isolate.html#a6079122af17612ef54ef3348ce170866) API. Returns an object with the
310
+ * following properties:
311
+ *
312
+ * ```js
313
+ * {
314
+ * code_and_metadata_size: 212208,
315
+ * bytecode_and_metadata_size: 161368,
316
+ * external_script_source_size: 1410794,
317
+ * cpu_profiler_metadata_size: 0,
318
+ * }
319
+ * ```
320
+ * @since v12.8.0
321
+ */
322
+ function getHeapCodeStatistics(): HeapCodeStatistics;
323
+ /**
324
+ * @since v8.0.0
325
+ */
326
+ class Serializer {
327
+ /**
328
+ * Writes out a header, which includes the serialization format version.
329
+ */
330
+ writeHeader(): void;
331
+ /**
332
+ * Serializes a JavaScript value and adds the serialized representation to the
333
+ * internal buffer.
334
+ *
335
+ * This throws an error if `value` cannot be serialized.
336
+ */
337
+ writeValue(val: any): boolean;
338
+ /**
339
+ * Returns the stored internal buffer. This serializer should not be used once
340
+ * the buffer is released. Calling this method results in undefined behavior
341
+ * if a previous write has failed.
342
+ */
343
+ releaseBuffer(): NonSharedBuffer;
344
+ /**
345
+ * Marks an `ArrayBuffer` as having its contents transferred out of band.
346
+ * Pass the corresponding `ArrayBuffer` in the deserializing context to `deserializer.transferArrayBuffer()`.
347
+ * @param id A 32-bit unsigned integer.
348
+ * @param arrayBuffer An `ArrayBuffer` instance.
349
+ */
350
+ transferArrayBuffer(id: number, arrayBuffer: ArrayBuffer): void;
351
+ /**
352
+ * Write a raw 32-bit unsigned integer.
353
+ * For use inside of a custom `serializer._writeHostObject()`.
354
+ */
355
+ writeUint32(value: number): void;
356
+ /**
357
+ * Write a raw 64-bit unsigned integer, split into high and low 32-bit parts.
358
+ * For use inside of a custom `serializer._writeHostObject()`.
359
+ */
360
+ writeUint64(hi: number, lo: number): void;
361
+ /**
362
+ * Write a JS `number` value.
363
+ * For use inside of a custom `serializer._writeHostObject()`.
364
+ */
365
+ writeDouble(value: number): void;
366
+ /**
367
+ * Write raw bytes into the serializer's internal buffer. The deserializer
368
+ * will require a way to compute the length of the buffer.
369
+ * For use inside of a custom `serializer._writeHostObject()`.
370
+ */
371
+ writeRawBytes(buffer: NodeJS.ArrayBufferView): void;
372
+ }
373
+ /**
374
+ * A subclass of `Serializer` that serializes `TypedArray`(in particular `Buffer`) and `DataView` objects as host objects, and only
375
+ * stores the part of their underlying `ArrayBuffer`s that they are referring to.
376
+ * @since v8.0.0
377
+ */
378
+ class DefaultSerializer extends Serializer {}
379
+ /**
380
+ * @since v8.0.0
381
+ */
382
+ class Deserializer {
383
+ constructor(data: NodeJS.TypedArray);
384
+ /**
385
+ * Reads and validates a header (including the format version).
386
+ * May, for example, reject an invalid or unsupported wire format. In that case,
387
+ * an `Error` is thrown.
388
+ */
389
+ readHeader(): boolean;
390
+ /**
391
+ * Deserializes a JavaScript value from the buffer and returns it.
392
+ */
393
+ readValue(): any;
394
+ /**
395
+ * Marks an `ArrayBuffer` as having its contents transferred out of band.
396
+ * Pass the corresponding `ArrayBuffer` in the serializing context to `serializer.transferArrayBuffer()` (or return the `id` from `serializer._getSharedArrayBufferId()` in the case of
397
+ * `SharedArrayBuffer`s).
398
+ * @param id A 32-bit unsigned integer.
399
+ * @param arrayBuffer An `ArrayBuffer` instance.
400
+ */
401
+ transferArrayBuffer(id: number, arrayBuffer: ArrayBuffer): void;
402
+ /**
403
+ * Reads the underlying wire format version. Likely mostly to be useful to
404
+ * legacy code reading old wire format versions. May not be called before `.readHeader()`.
405
+ */
406
+ getWireFormatVersion(): number;
407
+ /**
408
+ * Read a raw 32-bit unsigned integer and return it.
409
+ * For use inside of a custom `deserializer._readHostObject()`.
410
+ */
411
+ readUint32(): number;
412
+ /**
413
+ * Read a raw 64-bit unsigned integer and return it as an array `[hi, lo]` with two 32-bit unsigned integer entries.
414
+ * For use inside of a custom `deserializer._readHostObject()`.
415
+ */
416
+ readUint64(): [number, number];
417
+ /**
418
+ * Read a JS `number` value.
419
+ * For use inside of a custom `deserializer._readHostObject()`.
420
+ */
421
+ readDouble(): number;
422
+ /**
423
+ * Read raw bytes from the deserializer's internal buffer. The `length` parameter
424
+ * must correspond to the length of the buffer that was passed to `serializer.writeRawBytes()`.
425
+ * For use inside of a custom `deserializer._readHostObject()`.
426
+ */
427
+ readRawBytes(length: number): Buffer;
428
+ }
429
+ /**
430
+ * A subclass of `Deserializer` corresponding to the format written by `DefaultSerializer`.
431
+ * @since v8.0.0
432
+ */
433
+ class DefaultDeserializer extends Deserializer {}
434
+ /**
435
+ * Uses a `DefaultSerializer` to serialize `value` into a buffer.
436
+ *
437
+ * `ERR_BUFFER_TOO_LARGE` will be thrown when trying to
438
+ * serialize a huge object which requires buffer
439
+ * larger than `buffer.constants.MAX_LENGTH`.
440
+ * @since v8.0.0
441
+ */
442
+ function serialize(value: any): NonSharedBuffer;
443
+ /**
444
+ * Uses a `DefaultDeserializer` with default options to read a JS value
445
+ * from a buffer.
446
+ * @since v8.0.0
447
+ * @param buffer A buffer returned by {@link serialize}.
448
+ */
449
+ function deserialize(buffer: NodeJS.ArrayBufferView): any;
450
+ /**
451
+ * The `v8.takeCoverage()` method allows the user to write the coverage started by `NODE_V8_COVERAGE` to disk on demand. This method can be invoked multiple
452
+ * times during the lifetime of the process. Each time the execution counter will
453
+ * be reset and a new coverage report will be written to the directory specified
454
+ * by `NODE_V8_COVERAGE`.
455
+ *
456
+ * When the process is about to exit, one last coverage will still be written to
457
+ * disk unless {@link stopCoverage} is invoked before the process exits.
458
+ * @since v15.1.0, v14.18.0, v12.22.0
459
+ */
460
+ function takeCoverage(): void;
461
+ /**
462
+ * The `v8.stopCoverage()` method allows the user to stop the coverage collection
463
+ * started by `NODE_V8_COVERAGE`, so that V8 can release the execution count
464
+ * records and optimize code. This can be used in conjunction with {@link takeCoverage} if the user wants to collect the coverage on demand.
465
+ * @since v15.1.0, v14.18.0, v12.22.0
466
+ */
467
+ function stopCoverage(): void;
468
+ /**
469
+ * 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.
470
+ * `limit` must be a positive integer. See [`--heapsnapshot-near-heap-limit`](https://nodejs.org/docs/latest-v20.x/api/cli.html#--heapsnapshot-near-heap-limitmax_count) for more information.
471
+ * @experimental
472
+ * @since v18.10.0, v16.18.0
473
+ */
474
+ function setHeapSnapshotNearHeapLimit(limit: number): void;
475
+ /**
476
+ * This API collects GC data in current thread.
477
+ * @since v19.6.0, v18.15.0
478
+ */
479
+ class GCProfiler {
480
+ /**
481
+ * Start collecting GC data.
482
+ * @since v19.6.0, v18.15.0
483
+ */
484
+ start(): void;
485
+ /**
486
+ * Stop collecting GC data and return an object. The content of object
487
+ * is as follows.
488
+ *
489
+ * ```json
490
+ * {
491
+ * "version": 1,
492
+ * "startTime": 1674059033862,
493
+ * "statistics": [
494
+ * {
495
+ * "gcType": "Scavenge",
496
+ * "beforeGC": {
497
+ * "heapStatistics": {
498
+ * "totalHeapSize": 5005312,
499
+ * "totalHeapSizeExecutable": 524288,
500
+ * "totalPhysicalSize": 5226496,
501
+ * "totalAvailableSize": 4341325216,
502
+ * "totalGlobalHandlesSize": 8192,
503
+ * "usedGlobalHandlesSize": 2112,
504
+ * "usedHeapSize": 4883840,
505
+ * "heapSizeLimit": 4345298944,
506
+ * "mallocedMemory": 254128,
507
+ * "externalMemory": 225138,
508
+ * "peakMallocedMemory": 181760
509
+ * },
510
+ * "heapSpaceStatistics": [
511
+ * {
512
+ * "spaceName": "read_only_space",
513
+ * "spaceSize": 0,
514
+ * "spaceUsedSize": 0,
515
+ * "spaceAvailableSize": 0,
516
+ * "physicalSpaceSize": 0
517
+ * }
518
+ * ]
519
+ * },
520
+ * "cost": 1574.14,
521
+ * "afterGC": {
522
+ * "heapStatistics": {
523
+ * "totalHeapSize": 6053888,
524
+ * "totalHeapSizeExecutable": 524288,
525
+ * "totalPhysicalSize": 5500928,
526
+ * "totalAvailableSize": 4341101384,
527
+ * "totalGlobalHandlesSize": 8192,
528
+ * "usedGlobalHandlesSize": 2112,
529
+ * "usedHeapSize": 4059096,
530
+ * "heapSizeLimit": 4345298944,
531
+ * "mallocedMemory": 254128,
532
+ * "externalMemory": 225138,
533
+ * "peakMallocedMemory": 181760
534
+ * },
535
+ * "heapSpaceStatistics": [
536
+ * {
537
+ * "spaceName": "read_only_space",
538
+ * "spaceSize": 0,
539
+ * "spaceUsedSize": 0,
540
+ * "spaceAvailableSize": 0,
541
+ * "physicalSpaceSize": 0
542
+ * }
543
+ * ]
544
+ * }
545
+ * }
546
+ * ],
547
+ * "endTime": 1674059036865
548
+ * }
549
+ * ```
550
+ *
551
+ * Here's an example.
552
+ *
553
+ * ```js
554
+ * import { GCProfiler } from 'node:v8';
555
+ * const profiler = new GCProfiler();
556
+ * profiler.start();
557
+ * setTimeout(() => {
558
+ * console.log(profiler.stop());
559
+ * }, 1000);
560
+ * ```
561
+ * @since v19.6.0, v18.15.0
562
+ */
563
+ stop(): GCProfilerResult;
564
+ }
565
+ interface GCProfilerResult {
566
+ version: number;
567
+ startTime: number;
568
+ endTime: number;
569
+ statistics: Array<{
570
+ gcType: string;
571
+ cost: number;
572
+ beforeGC: {
573
+ heapStatistics: HeapStatistics;
574
+ heapSpaceStatistics: HeapSpaceStatistics[];
575
+ };
576
+ afterGC: {
577
+ heapStatistics: HeapStatistics;
578
+ heapSpaceStatistics: HeapSpaceStatistics[];
579
+ };
580
+ }>;
581
+ }
582
+ interface HeapStatistics {
583
+ totalHeapSize: number;
584
+ totalHeapSizeExecutable: number;
585
+ totalPhysicalSize: number;
586
+ totalAvailableSize: number;
587
+ totalGlobalHandlesSize: number;
588
+ usedGlobalHandlesSize: number;
589
+ usedHeapSize: number;
590
+ heapSizeLimit: number;
591
+ mallocedMemory: number;
592
+ externalMemory: number;
593
+ peakMallocedMemory: number;
594
+ }
595
+ interface HeapSpaceStatistics {
596
+ spaceName: string;
597
+ spaceSize: number;
598
+ spaceUsedSize: number;
599
+ spaceAvailableSize: number;
600
+ physicalSpaceSize: number;
601
+ }
602
+ /**
603
+ * Called when a promise is constructed. This does not mean that corresponding before/after events will occur, only that the possibility exists. This will
604
+ * happen if a promise is created without ever getting a continuation.
605
+ * @since v17.1.0, v16.14.0
606
+ * @param promise The promise being created.
607
+ * @param parent The promise continued from, if applicable.
608
+ */
609
+ interface Init {
610
+ (promise: Promise<unknown>, parent: Promise<unknown>): void;
611
+ }
612
+ /**
613
+ * Called before a promise continuation executes. This can be in the form of `then()`, `catch()`, or `finally()` handlers or an await resuming.
614
+ *
615
+ * 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.
616
+ * The before callback may be called many times in the case where many continuations have been made from the same promise.
617
+ * @since v17.1.0, v16.14.0
618
+ */
619
+ interface Before {
620
+ (promise: Promise<unknown>): void;
621
+ }
622
+ /**
623
+ * Called immediately after a promise continuation executes. This may be after a `then()`, `catch()`, or `finally()` handler or before an await after another await.
624
+ * @since v17.1.0, v16.14.0
625
+ */
626
+ interface After {
627
+ (promise: Promise<unknown>): void;
628
+ }
629
+ /**
630
+ * Called when the promise receives a resolution or rejection value. This may occur synchronously in the case of {@link Promise.resolve()} or
631
+ * {@link Promise.reject()}.
632
+ * @since v17.1.0, v16.14.0
633
+ */
634
+ interface Settled {
635
+ (promise: Promise<unknown>): void;
636
+ }
637
+ /**
638
+ * Key events in the lifetime of a promise have been categorized into four areas: creation of a promise, before/after a continuation handler is called or
639
+ * around an await, and when the promise resolves or rejects.
640
+ *
641
+ * Because promises are asynchronous resources whose lifecycle is tracked via the promise hooks mechanism, the `init()`, `before()`, `after()`, and
642
+ * `settled()` callbacks must not be async functions as they create more promises which would produce an infinite loop.
643
+ * @since v17.1.0, v16.14.0
644
+ */
645
+ interface HookCallbacks {
646
+ init?: Init;
647
+ before?: Before;
648
+ after?: After;
649
+ settled?: Settled;
650
+ }
651
+ interface PromiseHooks {
652
+ /**
653
+ * The `init` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
654
+ * @since v17.1.0, v16.14.0
655
+ * @param init The {@link Init | `init` callback} to call when a promise is created.
656
+ * @return Call to stop the hook.
657
+ */
658
+ onInit: (init: Init) => Function;
659
+ /**
660
+ * The `settled` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
661
+ * @since v17.1.0, v16.14.0
662
+ * @param settled The {@link Settled | `settled` callback} to call when a promise is created.
663
+ * @return Call to stop the hook.
664
+ */
665
+ onSettled: (settled: Settled) => Function;
666
+ /**
667
+ * The `before` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
668
+ * @since v17.1.0, v16.14.0
669
+ * @param before The {@link Before | `before` callback} to call before a promise continuation executes.
670
+ * @return Call to stop the hook.
671
+ */
672
+ onBefore: (before: Before) => Function;
673
+ /**
674
+ * The `after` hook must be a plain function. Providing an async function will throw as it would produce an infinite microtask loop.
675
+ * @since v17.1.0, v16.14.0
676
+ * @param after The {@link After | `after` callback} to call after a promise continuation executes.
677
+ * @return Call to stop the hook.
678
+ */
679
+ onAfter: (after: After) => Function;
680
+ /**
681
+ * Registers functions to be called for different lifetime events of each promise.
682
+ * The callbacks `init()`/`before()`/`after()`/`settled()` are called for the respective events during a promise's lifetime.
683
+ * All callbacks are optional. For example, if only promise creation needs to be tracked, then only the init callback needs to be passed.
684
+ * The hook callbacks must be plain functions. Providing async functions will throw as it would produce an infinite microtask loop.
685
+ * @since v17.1.0, v16.14.0
686
+ * @param callbacks The {@link HookCallbacks | Hook Callbacks} to register
687
+ * @return Used for disabling hooks
688
+ */
689
+ createHook: (callbacks: HookCallbacks) => Function;
690
+ }
691
+ /**
692
+ * The `promiseHooks` interface can be used to track promise lifecycle events.
693
+ * @since v17.1.0, v16.14.0
694
+ */
695
+ const promiseHooks: PromiseHooks;
696
+ type StartupSnapshotCallbackFn = (args: any) => any;
697
+ interface StartupSnapshot {
698
+ /**
699
+ * Add a callback that will be called when the Node.js instance is about to get serialized into a snapshot and exit.
700
+ * 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.
701
+ * @since v18.6.0, v16.17.0
702
+ */
703
+ addSerializeCallback(callback: StartupSnapshotCallbackFn, data?: any): void;
704
+ /**
705
+ * Add a callback that will be called when the Node.js instance is deserialized from a snapshot.
706
+ * 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
707
+ * to re-acquire resources that the application needs when the application is restarted from the snapshot.
708
+ * @since v18.6.0, v16.17.0
709
+ */
710
+ addDeserializeCallback(callback: StartupSnapshotCallbackFn, data?: any): void;
711
+ /**
712
+ * 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.
713
+ * 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
714
+ * data (if provided), otherwise an entry point script still needs to be provided to the deserialized application.
715
+ * @since v18.6.0, v16.17.0
716
+ */
717
+ setDeserializeMainFunction(callback: StartupSnapshotCallbackFn, data?: any): void;
718
+ /**
719
+ * Returns true if the Node.js instance is run to build a snapshot.
720
+ * @since v18.6.0, v16.17.0
721
+ */
722
+ isBuildingSnapshot(): boolean;
723
+ }
724
+ /**
725
+ * The `v8.startupSnapshot` interface can be used to add serialization and deserialization hooks for custom startup snapshots.
726
+ *
727
+ * ```bash
728
+ * $ node --snapshot-blob snapshot.blob --build-snapshot entry.js
729
+ * # This launches a process with the snapshot
730
+ * $ node --snapshot-blob snapshot.blob
731
+ * ```
732
+ *
733
+ * In the example above, `entry.js` can use methods from the `v8.startupSnapshot` interface to specify how to save information for custom objects
734
+ * in the snapshot during serialization and how the information can be used to synchronize these objects during deserialization of the snapshot.
735
+ * For example, if the `entry.js` contains the following script:
736
+ *
737
+ * ```js
738
+ * 'use strict';
739
+ *
740
+ * import fs from 'node:fs';
741
+ * import zlib from 'node:zlib';
742
+ * import path from 'node:path';
743
+ * import assert from 'node:assert';
744
+ *
745
+ * import v8 from 'node:v8';
746
+ *
747
+ * class BookShelf {
748
+ * storage = new Map();
749
+ *
750
+ * // Reading a series of files from directory and store them into storage.
751
+ * constructor(directory, books) {
752
+ * for (const book of books) {
753
+ * this.storage.set(book, fs.readFileSync(path.join(directory, book)));
754
+ * }
755
+ * }
756
+ *
757
+ * static compressAll(shelf) {
758
+ * for (const [ book, content ] of shelf.storage) {
759
+ * shelf.storage.set(book, zlib.gzipSync(content));
760
+ * }
761
+ * }
762
+ *
763
+ * static decompressAll(shelf) {
764
+ * for (const [ book, content ] of shelf.storage) {
765
+ * shelf.storage.set(book, zlib.gunzipSync(content));
766
+ * }
767
+ * }
768
+ * }
769
+ *
770
+ * // __dirname here is where the snapshot script is placed
771
+ * // during snapshot building time.
772
+ * const shelf = new BookShelf(__dirname, [
773
+ * 'book1.en_US.txt',
774
+ * 'book1.es_ES.txt',
775
+ * 'book2.zh_CN.txt',
776
+ * ]);
777
+ *
778
+ * assert(v8.startupSnapshot.isBuildingSnapshot());
779
+ * // On snapshot serialization, compress the books to reduce size.
780
+ * v8.startupSnapshot.addSerializeCallback(BookShelf.compressAll, shelf);
781
+ * // On snapshot deserialization, decompress the books.
782
+ * v8.startupSnapshot.addDeserializeCallback(BookShelf.decompressAll, shelf);
783
+ * v8.startupSnapshot.setDeserializeMainFunction((shelf) => {
784
+ * // process.env and process.argv are refreshed during snapshot
785
+ * // deserialization.
786
+ * const lang = process.env.BOOK_LANG || 'en_US';
787
+ * const book = process.argv[1];
788
+ * const name = `${book}.${lang}.txt`;
789
+ * console.log(shelf.storage.get(name));
790
+ * }, shelf);
791
+ * ```
792
+ *
793
+ * 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:
794
+ *
795
+ * ```bash
796
+ * $ BOOK_LANG=es_ES node --snapshot-blob snapshot.blob book1
797
+ * # Prints content of book1.es_ES.txt deserialized from the snapshot.
798
+ * ```
799
+ *
800
+ * 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.
801
+ *
802
+ * @experimental
803
+ * @since v18.6.0, v16.17.0
804
+ */
805
+ const startupSnapshot: StartupSnapshot;
806
+ }
807
+ declare module "node:v8" {
808
+ export * from "v8";
809
+ }