@chainlink/external-adapter-framework 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/README.md +1 -1
  2. package/adapter/price.d.ts +1 -0
  3. package/adapter/price.js +13 -7
  4. package/adapter/price.js.map +1 -1
  5. package/generator-adapter/node_modules/.yarn-integrity +2 -2
  6. package/generator-adapter/node_modules/@types/node/README.md +1 -1
  7. package/generator-adapter/node_modules/@types/node/assert.d.ts +53 -0
  8. package/generator-adapter/node_modules/@types/node/buffer.buffer.d.ts +2 -1
  9. package/generator-adapter/node_modules/@types/node/dgram.d.ts +10 -7
  10. package/generator-adapter/node_modules/@types/node/events.d.ts +1 -1
  11. package/generator-adapter/node_modules/@types/node/fs.d.ts +45 -98
  12. package/generator-adapter/node_modules/@types/node/globals.d.ts +8 -63
  13. package/generator-adapter/node_modules/@types/node/http.d.ts +1 -0
  14. package/generator-adapter/node_modules/@types/node/module.d.ts +528 -235
  15. package/generator-adapter/node_modules/@types/node/net.d.ts +33 -5
  16. package/generator-adapter/node_modules/@types/node/package.json +2 -2
  17. package/generator-adapter/node_modules/@types/node/perf_hooks.d.ts +5 -0
  18. package/generator-adapter/node_modules/@types/node/process.d.ts +54 -4
  19. package/generator-adapter/node_modules/@types/node/sea.d.ts +1 -1
  20. package/generator-adapter/node_modules/@types/node/sqlite.d.ts +236 -10
  21. package/generator-adapter/node_modules/@types/node/test.d.ts +0 -5
  22. package/generator-adapter/node_modules/@types/node/util.d.ts +85 -17
  23. package/generator-adapter/package.json +1 -1
  24. package/metrics/index.d.ts +1 -0
  25. package/metrics/index.js +4 -0
  26. package/metrics/index.js.map +1 -1
  27. package/package.json +12 -12
  28. package/transports/websocket.d.ts +18 -0
  29. package/transports/websocket.js +9 -0
  30. package/transports/websocket.js.map +1 -1
@@ -1,11 +1,248 @@
1
1
  /**
2
2
  * @since v0.3.7
3
- * @experimental
4
3
  */
5
4
  declare module "module" {
6
5
  import { URL } from "node:url";
7
- import { MessagePort } from "node:worker_threads";
6
+ class Module {
7
+ constructor(id: string, parent?: Module);
8
+ }
9
+ interface Module extends NodeJS.Module {}
8
10
  namespace Module {
11
+ export { Module };
12
+ }
13
+ namespace Module {
14
+ /**
15
+ * A list of the names of all modules provided by Node.js. Can be used to verify
16
+ * if a module is maintained by a third party or not.
17
+ *
18
+ * Note: the list doesn't contain prefix-only modules like `node:test`.
19
+ * @since v9.3.0, v8.10.0, v6.13.0
20
+ */
21
+ const builtinModules: readonly string[];
22
+ /**
23
+ * @since v12.2.0
24
+ * @param path Filename to be used to construct the require
25
+ * function. Must be a file URL object, file URL string, or absolute path
26
+ * string.
27
+ */
28
+ function createRequire(path: string | URL): NodeJS.Require;
29
+ namespace constants {
30
+ /**
31
+ * The following constants are returned as the `status` field in the object returned by
32
+ * {@link enableCompileCache} to indicate the result of the attempt to enable the
33
+ * [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache).
34
+ * @since v22.8.0
35
+ */
36
+ namespace compileCacheStatus {
37
+ /**
38
+ * Node.js has enabled the compile cache successfully. The directory used to store the
39
+ * compile cache will be returned in the `directory` field in the
40
+ * returned object.
41
+ */
42
+ const ENABLED: number;
43
+ /**
44
+ * The compile cache has already been enabled before, either by a previous call to
45
+ * {@link enableCompileCache}, or by the `NODE_COMPILE_CACHE=dir`
46
+ * environment variable. The directory used to store the
47
+ * compile cache will be returned in the `directory` field in the
48
+ * returned object.
49
+ */
50
+ const ALREADY_ENABLED: number;
51
+ /**
52
+ * Node.js fails to enable the compile cache. This can be caused by the lack of
53
+ * permission to use the specified directory, or various kinds of file system errors.
54
+ * The detail of the failure will be returned in the `message` field in the
55
+ * returned object.
56
+ */
57
+ const FAILED: number;
58
+ /**
59
+ * Node.js cannot enable the compile cache because the environment variable
60
+ * `NODE_DISABLE_COMPILE_CACHE=1` has been set.
61
+ */
62
+ const DISABLED: number;
63
+ }
64
+ }
65
+ interface EnableCompileCacheResult {
66
+ /**
67
+ * One of the {@link constants.compileCacheStatus}
68
+ */
69
+ status: number;
70
+ /**
71
+ * If Node.js cannot enable the compile cache, this contains
72
+ * the error message. Only set if `status` is `module.constants.compileCacheStatus.FAILED`.
73
+ */
74
+ message?: string;
75
+ /**
76
+ * If the compile cache is enabled, this contains the directory
77
+ * where the compile cache is stored. Only set if `status` is
78
+ * `module.constants.compileCacheStatus.ENABLED` or
79
+ * `module.constants.compileCacheStatus.ALREADY_ENABLED`.
80
+ */
81
+ directory?: string;
82
+ }
83
+ /**
84
+ * Enable [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache)
85
+ * in the current Node.js instance.
86
+ *
87
+ * If `cacheDir` is not specified, Node.js will either use the directory specified by the
88
+ * `NODE_COMPILE_CACHE=dir` environment variable if it's set, or use
89
+ * `path.join(os.tmpdir(), 'node-compile-cache')` otherwise. For general use cases, it's
90
+ * recommended to call `module.enableCompileCache()` without specifying the `cacheDir`,
91
+ * so that the directory can be overridden by the `NODE_COMPILE_CACHE` environment
92
+ * variable when necessary.
93
+ *
94
+ * Since compile cache is supposed to be a quiet optimization that is not required for the
95
+ * application to be functional, this method is designed to not throw any exception when the
96
+ * compile cache cannot be enabled. Instead, it will return an object containing an error
97
+ * message in the `message` field to aid debugging.
98
+ * If compile cache is enabled successfully, the `directory` field in the returned object
99
+ * contains the path to the directory where the compile cache is stored. The `status`
100
+ * field in the returned object would be one of the `module.constants.compileCacheStatus`
101
+ * values to indicate the result of the attempt to enable the
102
+ * [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache).
103
+ *
104
+ * This method only affects the current Node.js instance. To enable it in child worker threads,
105
+ * either call this method in child worker threads too, or set the
106
+ * `process.env.NODE_COMPILE_CACHE` value to compile cache directory so the behavior can
107
+ * be inherited into the child workers. The directory can be obtained either from the
108
+ * `directory` field returned by this method, or with {@link getCompileCacheDir}.
109
+ * @since v22.8.0
110
+ * @param cacheDir Optional path to specify the directory where the compile cache
111
+ * will be stored/retrieved.
112
+ */
113
+ function enableCompileCache(cacheDir?: string): EnableCompileCacheResult;
114
+ /**
115
+ * Flush the [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache)
116
+ * accumulated from modules already loaded
117
+ * in the current Node.js instance to disk. This returns after all the flushing
118
+ * file system operations come to an end, no matter they succeed or not. If there
119
+ * are any errors, this will fail silently, since compile cache misses should not
120
+ * interfere with the actual operation of the application.
121
+ * @since v22.10.0
122
+ */
123
+ function flushCompileCache(): void;
124
+ /**
125
+ * @since v22.8.0
126
+ * @return Path to the [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache)
127
+ * directory if it is enabled, or `undefined` otherwise.
128
+ */
129
+ function getCompileCacheDir(): string | undefined;
130
+ /**
131
+ * @since v18.6.0, v16.17.0
132
+ */
133
+ function isBuiltin(moduleName: string): boolean;
134
+ interface RegisterOptions<Data> {
135
+ /**
136
+ * If you want to resolve `specifier` relative to a
137
+ * base URL, such as `import.meta.url`, you can pass that URL here. This
138
+ * property is ignored if the `parentURL` is supplied as the second argument.
139
+ * @default 'data:'
140
+ */
141
+ parentURL?: string | URL | undefined;
142
+ /**
143
+ * Any arbitrary, cloneable JavaScript value to pass into the
144
+ * {@link initialize} hook.
145
+ */
146
+ data?: Data | undefined;
147
+ /**
148
+ * [Transferable objects](https://nodejs.org/docs/latest-v22.x/api/worker_threads.html#portpostmessagevalue-transferlist)
149
+ * to be passed into the `initialize` hook.
150
+ */
151
+ transferList?: any[] | undefined;
152
+ }
153
+ /* eslint-disable @definitelytyped/no-unnecessary-generics */
154
+ /**
155
+ * Register a module that exports hooks that customize Node.js module
156
+ * resolution and loading behavior. See
157
+ * [Customization hooks](https://nodejs.org/docs/latest-v22.x/api/module.html#customization-hooks).
158
+ * @since v20.6.0, v18.19.0
159
+ * @param specifier Customization hooks to be registered; this should be
160
+ * the same string that would be passed to `import()`, except that if it is
161
+ * relative, it is resolved relative to `parentURL`.
162
+ * @param parentURL f you want to resolve `specifier` relative to a base
163
+ * URL, such as `import.meta.url`, you can pass that URL here.
164
+ */
165
+ function register<Data = any>(
166
+ specifier: string | URL,
167
+ parentURL?: string | URL,
168
+ options?: RegisterOptions<Data>,
169
+ ): void;
170
+ function register<Data = any>(specifier: string | URL, options?: RegisterOptions<Data>): void;
171
+ interface StripTypeScriptTypesOptions {
172
+ /**
173
+ * Possible values are:
174
+ * * `'strip'` Only strip type annotations without performing the transformation of TypeScript features.
175
+ * * `'transform'` Strip type annotations and transform TypeScript features to JavaScript.
176
+ * @default 'strip'
177
+ */
178
+ mode?: "strip" | "transform" | undefined;
179
+ /**
180
+ * Only when `mode` is `'transform'`, if `true`, a source map
181
+ * will be generated for the transformed code.
182
+ * @default false
183
+ */
184
+ sourceMap?: boolean | undefined;
185
+ /**
186
+ * Specifies the source url used in the source map.
187
+ */
188
+ sourceUrl?: string | undefined;
189
+ }
190
+ /**
191
+ * `module.stripTypeScriptTypes()` removes type annotations from TypeScript code. It
192
+ * can be used to strip type annotations from TypeScript code before running it
193
+ * with `vm.runInContext()` or `vm.compileFunction()`.
194
+ * By default, it will throw an error if the code contains TypeScript features
195
+ * that require transformation such as `Enums`,
196
+ * see [type-stripping](https://nodejs.org/docs/latest-v22.x/api/typescript.md#type-stripping) for more information.
197
+ * When mode is `'transform'`, it also transforms TypeScript features to JavaScript,
198
+ * see [transform TypeScript features](https://nodejs.org/docs/latest-v22.x/api/typescript.md#typescript-features) for more information.
199
+ * When mode is `'strip'`, source maps are not generated, because locations are preserved.
200
+ * If `sourceMap` is provided, when mode is `'strip'`, an error will be thrown.
201
+ *
202
+ * _WARNING_: The output of this function should not be considered stable across Node.js versions,
203
+ * due to changes in the TypeScript parser.
204
+ *
205
+ * ```js
206
+ * import { stripTypeScriptTypes } from 'node:module';
207
+ * const code = 'const a: number = 1;';
208
+ * const strippedCode = stripTypeScriptTypes(code);
209
+ * console.log(strippedCode);
210
+ * // Prints: const a = 1;
211
+ * ```
212
+ *
213
+ * If `sourceUrl` is provided, it will be used appended as a comment at the end of the output:
214
+ *
215
+ * ```js
216
+ * import { stripTypeScriptTypes } from 'node:module';
217
+ * const code = 'const a: number = 1;';
218
+ * const strippedCode = stripTypeScriptTypes(code, { mode: 'strip', sourceUrl: 'source.ts' });
219
+ * console.log(strippedCode);
220
+ * // Prints: const a = 1\n\n//# sourceURL=source.ts;
221
+ * ```
222
+ *
223
+ * When `mode` is `'transform'`, the code is transformed to JavaScript:
224
+ *
225
+ * ```js
226
+ * import { stripTypeScriptTypes } from 'node:module';
227
+ * const code = `
228
+ * namespace MathUtil {
229
+ * export const add = (a: number, b: number) => a + b;
230
+ * }`;
231
+ * const strippedCode = stripTypeScriptTypes(code, { mode: 'transform', sourceMap: true });
232
+ * console.log(strippedCode);
233
+ * // Prints:
234
+ * // var MathUtil;
235
+ * // (function(MathUtil) {
236
+ * // MathUtil.add = (a, b)=>a + b;
237
+ * // })(MathUtil || (MathUtil = {}));
238
+ * // # sourceMappingURL=data:application/json;base64, ...
239
+ * ```
240
+ * @since v22.13.0
241
+ * @param code The code to strip type annotations from.
242
+ * @returns The code with type annotations stripped.
243
+ */
244
+ function stripTypeScriptTypes(code: string, options?: StripTypeScriptTypesOptions): string;
245
+ /* eslint-enable @definitelytyped/no-unnecessary-generics */
9
246
  /**
10
247
  * The `module.syncBuiltinESMExports()` method updates all the live bindings for
11
248
  * builtin `ES Modules` to match the properties of the `CommonJS` exports. It
@@ -42,111 +279,27 @@ declare module "module" {
42
279
  * @since v12.12.0
43
280
  */
44
281
  function syncBuiltinESMExports(): void;
45
- /**
46
- * `path` is the resolved path for the file for which a corresponding source map
47
- * should be fetched.
48
- * @since v13.7.0, v12.17.0
49
- * @return Returns `module.SourceMap` if a source map is found, `undefined` otherwise.
50
- */
51
- function findSourceMap(path: string, error?: Error): SourceMap | undefined;
52
- interface SourceMapPayload {
53
- file: string;
54
- version: number;
55
- sources: string[];
56
- sourcesContent: string[];
57
- names: string[];
58
- mappings: string;
59
- sourceRoot: string;
60
- }
61
- interface SourceMapping {
62
- generatedLine: number;
63
- generatedColumn: number;
64
- originalSource: string;
65
- originalLine: number;
66
- originalColumn: number;
67
- }
68
- interface SourceOrigin {
69
- /**
70
- * The name of the range in the source map, if one was provided
71
- */
72
- name?: string;
73
- /**
74
- * The file name of the original source, as reported in the SourceMap
75
- */
76
- fileName: string;
77
- /**
78
- * The 1-indexed lineNumber of the corresponding call site in the original source
79
- */
80
- lineNumber: number;
81
- /**
82
- * The 1-indexed columnNumber of the corresponding call site in the original source
83
- */
84
- columnNumber: number;
85
- }
86
- /**
87
- * @since v13.7.0, v12.17.0
88
- */
89
- class SourceMap {
90
- /**
91
- * Getter for the payload used to construct the `SourceMap` instance.
92
- */
93
- readonly payload: SourceMapPayload;
94
- constructor(payload: SourceMapPayload);
95
- /**
96
- * Given a line offset and column offset in the generated source
97
- * file, returns an object representing the SourceMap range in the
98
- * original file if found, or an empty object if not.
99
- *
100
- * The object returned contains the following keys:
101
- *
102
- * The returned value represents the raw range as it appears in the
103
- * SourceMap, based on zero-indexed offsets, _not_ 1-indexed line and
104
- * column numbers as they appear in Error messages and CallSite
105
- * objects.
106
- *
107
- * To get the corresponding 1-indexed line and column numbers from a
108
- * lineNumber and columnNumber as they are reported by Error stacks
109
- * and CallSite objects, use `sourceMap.findOrigin(lineNumber, columnNumber)`
110
- * @param lineOffset The zero-indexed line number offset in the generated source
111
- * @param columnOffset The zero-indexed column number offset in the generated source
112
- */
113
- findEntry(lineOffset: number, columnOffset: number): SourceMapping;
114
- /**
115
- * Given a 1-indexed `lineNumber` and `columnNumber` from a call site in the generated source,
116
- * find the corresponding call site location in the original source.
117
- *
118
- * If the `lineNumber` and `columnNumber` provided are not found in any source map,
119
- * then an empty object is returned.
120
- * @param lineNumber The 1-indexed line number of the call site in the generated source
121
- * @param columnNumber The 1-indexed column number of the call site in the generated source
122
- */
123
- findOrigin(lineNumber: number, columnNumber: number): SourceOrigin | {};
124
- }
125
282
  interface ImportAttributes extends NodeJS.Dict<string> {
126
283
  type?: string | undefined;
127
284
  }
128
- type ModuleFormat = "builtin" | "commonjs" | "json" | "module" | "wasm";
285
+ type ModuleFormat =
286
+ | "builtin"
287
+ | "commonjs"
288
+ | "commonjs-typescript"
289
+ | "json"
290
+ | "module"
291
+ | "module-typescript"
292
+ | "wasm";
129
293
  type ModuleSource = string | ArrayBuffer | NodeJS.TypedArray;
130
- interface GlobalPreloadContext {
131
- port: MessagePort;
132
- }
133
294
  /**
134
- * @deprecated This hook will be removed in a future version.
135
- * Use `initialize` instead. When a loader has an `initialize` export, `globalPreload` will be ignored.
136
- *
137
- * Sometimes it might be necessary to run some code inside of the same global scope that the application runs in.
138
- * This hook allows the return of a string that is run as a sloppy-mode script on startup.
295
+ * The `initialize` hook provides a way to define a custom function that runs in
296
+ * the hooks thread when the hooks module is initialized. Initialization happens
297
+ * when the hooks module is registered via {@link register}.
139
298
  *
140
- * @param context Information to assist the preload code
141
- * @return Code to run before application startup
142
- */
143
- type GlobalPreloadHook = (context: GlobalPreloadContext) => string;
144
- /**
145
- * The `initialize` hook provides a way to define a custom function that runs in the hooks thread
146
- * when the hooks module is initialized. Initialization happens when the hooks module is registered via `register`.
147
- *
148
- * This hook can receive data from a `register` invocation, including ports and other transferrable objects.
149
- * The return value of `initialize` can be a `Promise`, in which case it will be awaited before the main application thread execution resumes.
299
+ * This hook can receive data from a {@link register} invocation, including
300
+ * ports and other transferable objects. The return value of `initialize` can be a
301
+ * `Promise`, in which case it will be awaited before the main application thread
302
+ * execution resumes.
150
303
  */
151
304
  type InitializeHook<Data = any> = (data: Data) => void | Promise<void>;
152
305
  interface ResolveHookContext {
@@ -183,20 +336,20 @@ declare module "module" {
183
336
  url: string;
184
337
  }
185
338
  /**
186
- * The `resolve` hook chain is responsible for resolving file URL for a given module specifier and parent URL, and optionally its format (such as `'module'`) as a hint to the `load` hook.
187
- * If a format is specified, the load hook is ultimately responsible for providing the final `format` value (and it is free to ignore the hint provided by `resolve`);
188
- * if `resolve` provides a format, a custom `load` hook is required even if only to pass the value to the Node.js default `load` hook.
189
- *
190
- * @param specifier The specified URL path of the module to be resolved
191
- * @param context
192
- * @param nextResolve The subsequent `resolve` hook in the chain, or the Node.js default `resolve` hook after the last user-supplied resolve hook
339
+ * The `resolve` hook chain is responsible for telling Node.js where to find and
340
+ * how to cache a given `import` statement or expression, or `require` call. It can
341
+ * optionally return a format (such as `'module'`) as a hint to the `load` hook. If
342
+ * a format is specified, the `load` hook is ultimately responsible for providing
343
+ * the final `format` value (and it is free to ignore the hint provided by
344
+ * `resolve`); if `resolve` provides a `format`, a custom `load` hook is required
345
+ * even if only to pass the value to the Node.js default `load` hook.
193
346
  */
194
347
  type ResolveHook = (
195
348
  specifier: string,
196
349
  context: ResolveHookContext,
197
350
  nextResolve: (
198
351
  specifier: string,
199
- context?: ResolveHookContext,
352
+ context?: Partial<ResolveHookContext>,
200
353
  ) => ResolveFnOutput | Promise<ResolveFnOutput>,
201
354
  ) => ResolveFnOutput | Promise<ResolveFnOutput>;
202
355
  interface LoadHookContext {
@@ -207,7 +360,7 @@ declare module "module" {
207
360
  /**
208
361
  * The format optionally supplied by the `resolve` hook chain
209
362
  */
210
- format: ModuleFormat;
363
+ format: ModuleFormat | null | undefined;
211
364
  /**
212
365
  * An object whose key-value pairs represent the assertions for the module to import
213
366
  */
@@ -223,143 +376,109 @@ declare module "module" {
223
376
  /**
224
377
  * The source for Node.js to evaluate
225
378
  */
226
- source?: ModuleSource;
379
+ source?: ModuleSource | undefined;
227
380
  }
228
381
  /**
229
- * The `load` hook provides a way to define a custom method of determining how a URL should be interpreted, retrieved, and parsed.
230
- * It is also in charge of validating the import assertion.
231
- *
232
- * @param url The URL/path of the module to be loaded
233
- * @param context Metadata about the module
234
- * @param nextLoad The subsequent `load` hook in the chain, or the Node.js default `load` hook after the last user-supplied `load` hook
382
+ * The `load` hook provides a way to define a custom method of determining how a
383
+ * URL should be interpreted, retrieved, and parsed. It is also in charge of
384
+ * validating the import attributes.
235
385
  */
236
386
  type LoadHook = (
237
387
  url: string,
238
388
  context: LoadHookContext,
239
- nextLoad: (url: string, context?: LoadHookContext) => LoadFnOutput | Promise<LoadFnOutput>,
389
+ nextLoad: (
390
+ url: string,
391
+ context?: Partial<LoadHookContext>,
392
+ ) => LoadFnOutput | Promise<LoadFnOutput>,
240
393
  ) => LoadFnOutput | Promise<LoadFnOutput>;
241
- namespace constants {
394
+ /**
395
+ * `path` is the resolved path for the file for which a corresponding source map
396
+ * should be fetched.
397
+ * @since v13.7.0, v12.17.0
398
+ * @return Returns `module.SourceMap` if a source map is found, `undefined` otherwise.
399
+ */
400
+ function findSourceMap(path: string): SourceMap | undefined;
401
+ interface SourceMapConstructorOptions {
242
402
  /**
243
- * The following constants are returned as the `status` field in the object returned by
244
- * {@link enableCompileCache} to indicate the result of the attempt to enable the
245
- * [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache).
246
- * @since v22.8.0
403
+ * @since v21.0.0, v20.5.0
247
404
  */
248
- namespace compileCacheStatus {
249
- /**
250
- * Node.js has enabled the compile cache successfully. The directory used to store the
251
- * compile cache will be returned in the `directory` field in the
252
- * returned object.
253
- */
254
- const ENABLED: number;
255
- /**
256
- * The compile cache has already been enabled before, either by a previous call to
257
- * {@link enableCompileCache}, or by the `NODE_COMPILE_CACHE=dir`
258
- * environment variable. The directory used to store the
259
- * compile cache will be returned in the `directory` field in the
260
- * returned object.
261
- */
262
- const ALREADY_ENABLED: number;
263
- /**
264
- * Node.js fails to enable the compile cache. This can be caused by the lack of
265
- * permission to use the specified directory, or various kinds of file system errors.
266
- * The detail of the failure will be returned in the `message` field in the
267
- * returned object.
268
- */
269
- const FAILED: number;
270
- /**
271
- * Node.js cannot enable the compile cache because the environment variable
272
- * `NODE_DISABLE_COMPILE_CACHE=1` has been set.
273
- */
274
- const DISABLED: number;
275
- }
405
+ lineLengths?: readonly number[] | undefined;
406
+ }
407
+ interface SourceMapPayload {
408
+ file: string;
409
+ version: number;
410
+ sources: string[];
411
+ sourcesContent: string[];
412
+ names: string[];
413
+ mappings: string;
414
+ sourceRoot: string;
415
+ }
416
+ interface SourceMapping {
417
+ generatedLine: number;
418
+ generatedColumn: number;
419
+ originalSource: string;
420
+ originalLine: number;
421
+ originalColumn: number;
422
+ }
423
+ interface SourceOrigin {
424
+ /**
425
+ * The name of the range in the source map, if one was provided
426
+ */
427
+ name: string | undefined;
428
+ /**
429
+ * The file name of the original source, as reported in the SourceMap
430
+ */
431
+ fileName: string;
432
+ /**
433
+ * The 1-indexed lineNumber of the corresponding call site in the original source
434
+ */
435
+ lineNumber: number;
436
+ /**
437
+ * The 1-indexed columnNumber of the corresponding call site in the original source
438
+ */
439
+ columnNumber: number;
276
440
  }
277
- }
278
- interface RegisterOptions<Data> {
279
- parentURL: string | URL;
280
- data?: Data | undefined;
281
- transferList?: any[] | undefined;
282
- }
283
- interface EnableCompileCacheResult {
284
- /**
285
- * One of the {@link constants.compileCacheStatus}
286
- */
287
- status: number;
288
- /**
289
- * If Node.js cannot enable the compile cache, this contains
290
- * the error message. Only set if `status` is `module.constants.compileCacheStatus.FAILED`.
291
- */
292
- message?: string;
293
- /**
294
- * If the compile cache is enabled, this contains the directory
295
- * where the compile cache is stored. Only set if `status` is
296
- * `module.constants.compileCacheStatus.ENABLED` or
297
- * `module.constants.compileCacheStatus.ALREADY_ENABLED`.
298
- */
299
- directory?: string;
300
- }
301
- interface Module extends NodeModule {}
302
- class Module {
303
- static runMain(): void;
304
- static wrap(code: string): string;
305
- static createRequire(path: string | URL): NodeRequire;
306
- static builtinModules: string[];
307
- static isBuiltin(moduleName: string): boolean;
308
- static Module: typeof Module;
309
- static register<Data = any>(
310
- specifier: string | URL,
311
- parentURL?: string | URL,
312
- options?: RegisterOptions<Data>,
313
- ): void;
314
- static register<Data = any>(specifier: string | URL, options?: RegisterOptions<Data>): void;
315
- /**
316
- * Enable [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache)
317
- * in the current Node.js instance.
318
- *
319
- * If `cacheDir` is not specified, Node.js will either use the directory specified by the
320
- * `NODE_COMPILE_CACHE=dir` environment variable if it's set, or use
321
- * `path.join(os.tmpdir(), 'node-compile-cache')` otherwise. For general use cases, it's
322
- * recommended to call `module.enableCompileCache()` without specifying the `cacheDir`,
323
- * so that the directory can be overridden by the `NODE_COMPILE_CACHE` environment
324
- * variable when necessary.
325
- *
326
- * Since compile cache is supposed to be a quiet optimization that is not required for the
327
- * application to be functional, this method is designed to not throw any exception when the
328
- * compile cache cannot be enabled. Instead, it will return an object containing an error
329
- * message in the `message` field to aid debugging.
330
- * If compile cache is enabled successfully, the `directory` field in the returned object
331
- * contains the path to the directory where the compile cache is stored. The `status`
332
- * field in the returned object would be one of the `module.constants.compileCacheStatus`
333
- * values to indicate the result of the attempt to enable the
334
- * [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache).
335
- *
336
- * This method only affects the current Node.js instance. To enable it in child worker threads,
337
- * either call this method in child worker threads too, or set the
338
- * `process.env.NODE_COMPILE_CACHE` value to compile cache directory so the behavior can
339
- * be inherited into the child workers. The directory can be obtained either from the
340
- * `directory` field returned by this method, or with {@link getCompileCacheDir}.
341
- * @since v22.8.0
342
- * @param cacheDir Optional path to specify the directory where the compile cache
343
- * will be stored/retrieved.
344
- */
345
- static enableCompileCache(cacheDir?: string): EnableCompileCacheResult;
346
- /**
347
- * @since v22.8.0
348
- * @return Path to the [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache)
349
- * directory if it is enabled, or `undefined` otherwise.
350
- */
351
- static getCompileCacheDir(): string | undefined;
352
441
  /**
353
- * Flush the [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache)
354
- * accumulated from modules already loaded
355
- * in the current Node.js instance to disk. This returns after all the flushing
356
- * file system operations come to an end, no matter they succeed or not. If there
357
- * are any errors, this will fail silently, since compile cache misses should not
358
- * interfere with the actual operation of the application.
359
- * @since v22.10.0
442
+ * @since v13.7.0, v12.17.0
360
443
  */
361
- static flushCompileCache(): void;
362
- constructor(id: string, parent?: Module);
444
+ class SourceMap {
445
+ constructor(payload: SourceMapPayload, options?: SourceMapConstructorOptions);
446
+ /**
447
+ * Getter for the payload used to construct the `SourceMap` instance.
448
+ */
449
+ readonly payload: SourceMapPayload;
450
+ /**
451
+ * Given a line offset and column offset in the generated source
452
+ * file, returns an object representing the SourceMap range in the
453
+ * original file if found, or an empty object if not.
454
+ *
455
+ * The object returned contains the following keys:
456
+ *
457
+ * The returned value represents the raw range as it appears in the
458
+ * SourceMap, based on zero-indexed offsets, _not_ 1-indexed line and
459
+ * column numbers as they appear in Error messages and CallSite
460
+ * objects.
461
+ *
462
+ * To get the corresponding 1-indexed line and column numbers from a
463
+ * lineNumber and columnNumber as they are reported by Error stacks
464
+ * and CallSite objects, use `sourceMap.findOrigin(lineNumber, columnNumber)`
465
+ * @param lineOffset The zero-indexed line number offset in the generated source
466
+ * @param columnOffset The zero-indexed column number offset in the generated source
467
+ */
468
+ findEntry(lineOffset: number, columnOffset: number): SourceMapping | {};
469
+ /**
470
+ * Given a 1-indexed `lineNumber` and `columnNumber` from a call site in the generated source,
471
+ * find the corresponding call site location in the original source.
472
+ *
473
+ * If the `lineNumber` and `columnNumber` provided are not found in any source map,
474
+ * then an empty object is returned.
475
+ * @param lineNumber The 1-indexed line number of the call site in the generated source
476
+ * @param columnNumber The 1-indexed column number of the call site in the generated source
477
+ */
478
+ findOrigin(lineNumber: number, columnNumber: number): SourceOrigin | {};
479
+ }
480
+ function runMain(main?: string): void;
481
+ function wrap(script: string): string;
363
482
  }
364
483
  global {
365
484
  interface ImportMeta {
@@ -393,6 +512,180 @@ declare module "module" {
393
512
  */
394
513
  resolve(specifier: string, parent?: string | URL | undefined): string;
395
514
  }
515
+ namespace NodeJS {
516
+ interface Module {
517
+ /**
518
+ * The module objects required for the first time by this one.
519
+ * @since v0.1.16
520
+ */
521
+ children: Module[];
522
+ /**
523
+ * The `module.exports` object is created by the `Module` system. Sometimes this is
524
+ * not acceptable; many want their module to be an instance of some class. To do
525
+ * this, assign the desired export object to `module.exports`.
526
+ * @since v0.1.16
527
+ */
528
+ exports: any;
529
+ /**
530
+ * The fully resolved filename of the module.
531
+ * @since v0.1.16
532
+ */
533
+ filename: string;
534
+ /**
535
+ * The identifier for the module. Typically this is the fully resolved
536
+ * filename.
537
+ * @since v0.1.16
538
+ */
539
+ id: string;
540
+ /**
541
+ * `true` if the module is running during the Node.js preload
542
+ * phase.
543
+ * @since v15.4.0, v14.17.0
544
+ */
545
+ isPreloading: boolean;
546
+ /**
547
+ * Whether or not the module is done loading, or is in the process of
548
+ * loading.
549
+ * @since v0.1.16
550
+ */
551
+ loaded: boolean;
552
+ /**
553
+ * The module that first required this one, or `null` if the current module is the
554
+ * entry point of the current process, or `undefined` if the module was loaded by
555
+ * something that is not a CommonJS module (e.g. REPL or `import`).
556
+ * @since v0.1.16
557
+ * @deprecated Please use `require.main` and `module.children` instead.
558
+ */
559
+ parent: Module | null | undefined;
560
+ /**
561
+ * The directory name of the module. This is usually the same as the
562
+ * `path.dirname()` of the `module.id`.
563
+ * @since v11.14.0
564
+ */
565
+ path: string;
566
+ /**
567
+ * The search paths for the module.
568
+ * @since v0.4.0
569
+ */
570
+ paths: string[];
571
+ /**
572
+ * The `module.require()` method provides a way to load a module as if
573
+ * `require()` was called from the original module.
574
+ * @since v0.5.1
575
+ */
576
+ require(id: string): any;
577
+ }
578
+ interface Require {
579
+ /**
580
+ * Used to import modules, `JSON`, and local files.
581
+ * @since v0.1.13
582
+ */
583
+ (id: string): any;
584
+ /**
585
+ * Modules are cached in this object when they are required. By deleting a key
586
+ * value from this object, the next `require` will reload the module.
587
+ * This does not apply to
588
+ * [native addons](https://nodejs.org/docs/latest-v22.x/api/addons.html),
589
+ * for which reloading will result in an error.
590
+ * @since v0.3.0
591
+ */
592
+ cache: Dict<Module>;
593
+ /**
594
+ * Instruct `require` on how to handle certain file extensions.
595
+ * @since v0.3.0
596
+ * @deprecated
597
+ */
598
+ extensions: RequireExtensions;
599
+ /**
600
+ * The `Module` object representing the entry script loaded when the Node.js
601
+ * process launched, or `undefined` if the entry point of the program is not a
602
+ * CommonJS module.
603
+ * @since v0.1.17
604
+ */
605
+ main: Module | undefined;
606
+ /**
607
+ * @since v0.3.0
608
+ */
609
+ resolve: RequireResolve;
610
+ }
611
+ /** @deprecated */
612
+ interface RequireExtensions extends Dict<(module: Module, filename: string) => any> {
613
+ ".js": (module: Module, filename: string) => any;
614
+ ".json": (module: Module, filename: string) => any;
615
+ ".node": (module: Module, filename: string) => any;
616
+ }
617
+ interface RequireResolveOptions {
618
+ /**
619
+ * Paths to resolve module location from. If present, these
620
+ * paths are used instead of the default resolution paths, with the exception
621
+ * of
622
+ * [GLOBAL\_FOLDERS](https://nodejs.org/docs/latest-v22.x/api/modules.html#loading-from-the-global-folders)
623
+ * like `$HOME/.node_modules`, which are
624
+ * always included. Each of these paths is used as a starting point for
625
+ * the module resolution algorithm, meaning that the `node_modules` hierarchy
626
+ * is checked from this location.
627
+ * @since v8.9.0
628
+ */
629
+ paths?: string[] | undefined;
630
+ }
631
+ interface RequireResolve {
632
+ /**
633
+ * Use the internal `require()` machinery to look up the location of a module,
634
+ * but rather than loading the module, just return the resolved filename.
635
+ *
636
+ * If the module can not be found, a `MODULE_NOT_FOUND` error is thrown.
637
+ * @since v0.3.0
638
+ * @param request The module path to resolve.
639
+ */
640
+ (request: string, options?: RequireResolveOptions): string;
641
+ /**
642
+ * Returns an array containing the paths searched during resolution of `request` or
643
+ * `null` if the `request` string references a core module, for example `http` or
644
+ * `fs`.
645
+ * @since v8.9.0
646
+ * @param request The module path whose lookup paths are being retrieved.
647
+ */
648
+ paths(request: string): string[] | null;
649
+ }
650
+ }
651
+ /**
652
+ * The directory name of the current module. This is the same as the
653
+ * `path.dirname()` of the `__filename`.
654
+ * @since v0.1.27
655
+ */
656
+ var __dirname: string;
657
+ /**
658
+ * The file name of the current module. This is the current module file's absolute
659
+ * path with symlinks resolved.
660
+ *
661
+ * For a main program this is not necessarily the same as the file name used in the
662
+ * command line.
663
+ * @since v0.0.1
664
+ */
665
+ var __filename: string;
666
+ /**
667
+ * The `exports` variable is available within a module's file-level scope, and is
668
+ * assigned the value of `module.exports` before the module is evaluated.
669
+ * @since v0.1.16
670
+ */
671
+ var exports: NodeJS.Module["exports"];
672
+ /**
673
+ * A reference to the current module.
674
+ * @since v0.1.16
675
+ */
676
+ var module: NodeJS.Module;
677
+ /**
678
+ * @since v0.1.13
679
+ */
680
+ var require: NodeJS.Require;
681
+ // Global-scope aliases for backwards compatibility with @types/node <13.0.x
682
+ // TODO: consider removing in a future major version update
683
+ /** @deprecated Use `NodeJS.Module` instead. */
684
+ interface NodeModule extends NodeJS.Module {}
685
+ /** @deprecated Use `NodeJS.Require` instead. */
686
+ interface NodeRequire extends NodeJS.Require {}
687
+ /** @deprecated Use `NodeJS.RequireResolve` instead. */
688
+ interface RequireResolve extends NodeJS.RequireResolve {}
396
689
  }
397
690
  export = Module;
398
691
  }