@types/node 24.7.2 → 24.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- node/README.md +1 -1
- node/cluster.d.ts +1 -1
- node/crypto.d.ts +356 -25
- node/diagnostics_channel.d.ts +0 -2
- node/http2.d.ts +144 -26
- node/package.json +2 -2
- node/sea.d.ts +9 -0
- node/stream.d.ts +9 -1
- node/util.d.ts +1 -1
- node/v8.d.ts +16 -0
- node/vm.d.ts +128 -38
- node/wasi.d.ts +1 -1
- node/worker_threads.d.ts +39 -1
node/vm.d.ts
CHANGED
|
@@ -676,14 +676,12 @@ declare module "vm" {
|
|
|
676
676
|
* flag enabled.
|
|
677
677
|
*
|
|
678
678
|
* The `vm.Module` class provides a low-level interface for using
|
|
679
|
-
* ECMAScript modules in VM contexts. It is the counterpart of the `vm.Script`
|
|
680
|
-
* defined in the ECMAScript
|
|
679
|
+
* ECMAScript modules in VM contexts. It is the counterpart of the `vm.Script`
|
|
680
|
+
* class that closely mirrors [Module Record](https://tc39.es/ecma262/#sec-abstract-module-records)s as defined in the ECMAScript
|
|
681
681
|
* specification.
|
|
682
682
|
*
|
|
683
683
|
* Unlike `vm.Script` however, every `vm.Module` object is bound to a context from
|
|
684
|
-
* its creation.
|
|
685
|
-
* in contrast with the synchronous nature of `vm.Script` objects. The use of
|
|
686
|
-
* 'async' functions can help with manipulating `vm.Module` objects.
|
|
684
|
+
* its creation.
|
|
687
685
|
*
|
|
688
686
|
* Using a `vm.Module` object requires three distinct steps: creation/parsing,
|
|
689
687
|
* linking, and evaluation. These three steps are illustrated in the following
|
|
@@ -711,7 +709,7 @@ declare module "vm" {
|
|
|
711
709
|
* // Here, we attempt to obtain the default export from the module "foo", and
|
|
712
710
|
* // put it into local binding "secret".
|
|
713
711
|
*
|
|
714
|
-
* const
|
|
712
|
+
* const rootModule = new vm.SourceTextModule(`
|
|
715
713
|
* import s from 'foo';
|
|
716
714
|
* s;
|
|
717
715
|
* print(s);
|
|
@@ -721,39 +719,48 @@ declare module "vm" {
|
|
|
721
719
|
* //
|
|
722
720
|
* // "Link" the imported dependencies of this Module to it.
|
|
723
721
|
* //
|
|
724
|
-
* //
|
|
725
|
-
* //
|
|
726
|
-
* // the imported module. The callback is expected to return a Module that
|
|
727
|
-
* // corresponds to the provided specifier, with certain requirements documented
|
|
728
|
-
* // in `module.link()`.
|
|
729
|
-
* //
|
|
730
|
-
* // If linking has not started for the returned Module, the same linker
|
|
731
|
-
* // callback will be called on the returned Module.
|
|
722
|
+
* // Obtain the requested dependencies of a SourceTextModule by
|
|
723
|
+
* // `sourceTextModule.moduleRequests` and resolve them.
|
|
732
724
|
* //
|
|
733
725
|
* // Even top-level Modules without dependencies must be explicitly linked. The
|
|
734
|
-
* //
|
|
735
|
-
* //
|
|
736
|
-
* // The link() method returns a Promise that will be resolved when all the
|
|
737
|
-
* // Promises returned by the linker resolve.
|
|
726
|
+
* // array passed to `sourceTextModule.linkRequests(modules)` can be
|
|
727
|
+
* // empty, however.
|
|
738
728
|
* //
|
|
739
|
-
* // Note: This is a contrived example in that the
|
|
740
|
-
* // "foo" module every time it is called. In a full-fledged
|
|
741
|
-
* // cache would probably be used to avoid duplicated modules.
|
|
729
|
+
* // Note: This is a contrived example in that the resolveAndLinkDependencies
|
|
730
|
+
* // creates a new "foo" module every time it is called. In a full-fledged
|
|
731
|
+
* // module system, a cache would probably be used to avoid duplicated modules.
|
|
732
|
+
*
|
|
733
|
+
* const moduleMap = new Map([
|
|
734
|
+
* ['root', rootModule],
|
|
735
|
+
* ]);
|
|
742
736
|
*
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
*
|
|
746
|
-
*
|
|
747
|
-
*
|
|
748
|
-
*
|
|
749
|
-
* `, { context: referencingModule.context });
|
|
737
|
+
* function resolveAndLinkDependencies(module) {
|
|
738
|
+
* const requestedModules = module.moduleRequests.map((request) => {
|
|
739
|
+
* // In a full-fledged module system, the resolveAndLinkDependencies would
|
|
740
|
+
* // resolve the module with the module cache key `[specifier, attributes]`.
|
|
741
|
+
* // In this example, we just use the specifier as the key.
|
|
742
|
+
* const specifier = request.specifier;
|
|
750
743
|
*
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
744
|
+
* let requestedModule = moduleMap.get(specifier);
|
|
745
|
+
* if (requestedModule === undefined) {
|
|
746
|
+
* requestedModule = new vm.SourceTextModule(`
|
|
747
|
+
* // The "secret" variable refers to the global variable we added to
|
|
748
|
+
* // "contextifiedObject" when creating the context.
|
|
749
|
+
* export default secret;
|
|
750
|
+
* `, { context: referencingModule.context });
|
|
751
|
+
* moduleMap.set(specifier, linkedModule);
|
|
752
|
+
* // Resolve the dependencies of the new module as well.
|
|
753
|
+
* resolveAndLinkDependencies(requestedModule);
|
|
754
|
+
* }
|
|
755
|
+
*
|
|
756
|
+
* return requestedModule;
|
|
757
|
+
* });
|
|
758
|
+
*
|
|
759
|
+
* module.linkRequests(requestedModules);
|
|
755
760
|
* }
|
|
756
|
-
*
|
|
761
|
+
*
|
|
762
|
+
* resolveAndLinkDependencies(rootModule);
|
|
763
|
+
* rootModule.instantiate();
|
|
757
764
|
*
|
|
758
765
|
* // Step 3
|
|
759
766
|
* //
|
|
@@ -761,7 +768,7 @@ declare module "vm" {
|
|
|
761
768
|
* // resolve after the module has finished evaluating.
|
|
762
769
|
*
|
|
763
770
|
* // Prints 42.
|
|
764
|
-
* await
|
|
771
|
+
* await rootModule.evaluate();
|
|
765
772
|
* ```
|
|
766
773
|
* @since v13.0.0, v12.16.0
|
|
767
774
|
* @experimental
|
|
@@ -831,6 +838,10 @@ declare module "vm" {
|
|
|
831
838
|
* Link module dependencies. This method must be called before evaluation, and
|
|
832
839
|
* can only be called once per module.
|
|
833
840
|
*
|
|
841
|
+
* Use `sourceTextModule.linkRequests(modules)` and
|
|
842
|
+
* `sourceTextModule.instantiate()` to link modules either synchronously or
|
|
843
|
+
* asynchronously.
|
|
844
|
+
*
|
|
834
845
|
* The function is expected to return a `Module` object or a `Promise` that
|
|
835
846
|
* eventually resolves to a `Module` object. The returned `Module` must satisfy the
|
|
836
847
|
* following two invariants:
|
|
@@ -911,6 +922,39 @@ declare module "vm" {
|
|
|
911
922
|
class SourceTextModule extends Module {
|
|
912
923
|
/**
|
|
913
924
|
* Creates a new `SourceTextModule` instance.
|
|
925
|
+
*
|
|
926
|
+
* Properties assigned to the `import.meta` object that are objects may
|
|
927
|
+
* allow the module to access information outside the specified `context`. Use
|
|
928
|
+
* `vm.runInContext()` to create objects in a specific context.
|
|
929
|
+
*
|
|
930
|
+
* ```js
|
|
931
|
+
* import vm from 'node:vm';
|
|
932
|
+
*
|
|
933
|
+
* const contextifiedObject = vm.createContext({ secret: 42 });
|
|
934
|
+
*
|
|
935
|
+
* const module = new vm.SourceTextModule(
|
|
936
|
+
* 'Object.getPrototypeOf(import.meta.prop).secret = secret;',
|
|
937
|
+
* {
|
|
938
|
+
* initializeImportMeta(meta) {
|
|
939
|
+
* // Note: this object is created in the top context. As such,
|
|
940
|
+
* // Object.getPrototypeOf(import.meta.prop) points to the
|
|
941
|
+
* // Object.prototype in the top context rather than that in
|
|
942
|
+
* // the contextified object.
|
|
943
|
+
* meta.prop = {};
|
|
944
|
+
* },
|
|
945
|
+
* });
|
|
946
|
+
* // The module has an empty `moduleRequests` array.
|
|
947
|
+
* module.linkRequests([]);
|
|
948
|
+
* module.instantiate();
|
|
949
|
+
* await module.evaluate();
|
|
950
|
+
*
|
|
951
|
+
* // Now, Object.prototype.secret will be equal to 42.
|
|
952
|
+
* //
|
|
953
|
+
* // To fix this problem, replace
|
|
954
|
+
* // meta.prop = {};
|
|
955
|
+
* // above with
|
|
956
|
+
* // meta.prop = vm.runInContext('{}', contextifiedObject);
|
|
957
|
+
* ```
|
|
914
958
|
* @param code JavaScript Module code to parse
|
|
915
959
|
*/
|
|
916
960
|
constructor(code: string, options?: SourceTextModuleOptions);
|
|
@@ -918,6 +962,55 @@ declare module "vm" {
|
|
|
918
962
|
* @deprecated Use `sourceTextModule.moduleRequests` instead.
|
|
919
963
|
*/
|
|
920
964
|
readonly dependencySpecifiers: readonly string[];
|
|
965
|
+
/**
|
|
966
|
+
* Instantiate the module with the linked requested modules.
|
|
967
|
+
*
|
|
968
|
+
* This resolves the imported bindings of the module, including re-exported
|
|
969
|
+
* binding names. When there are any bindings that cannot be resolved,
|
|
970
|
+
* an error would be thrown synchronously.
|
|
971
|
+
*
|
|
972
|
+
* If the requested modules include cyclic dependencies, the
|
|
973
|
+
* `sourceTextModule.linkRequests(modules)` method must be called on all
|
|
974
|
+
* modules in the cycle before calling this method.
|
|
975
|
+
* @since v24.8.0
|
|
976
|
+
*/
|
|
977
|
+
instantiate(): void;
|
|
978
|
+
/**
|
|
979
|
+
* Link module dependencies. This method must be called before evaluation, and
|
|
980
|
+
* can only be called once per module.
|
|
981
|
+
*
|
|
982
|
+
* The order of the module instances in the `modules` array should correspond to the order of
|
|
983
|
+
* `sourceTextModule.moduleRequests` being resolved. If two module requests have the same
|
|
984
|
+
* specifier and import attributes, they must be resolved with the same module instance or an
|
|
985
|
+
* `ERR_MODULE_LINK_MISMATCH` would be thrown. For example, when linking requests for this
|
|
986
|
+
* module:
|
|
987
|
+
*
|
|
988
|
+
* ```js
|
|
989
|
+
* import foo from 'foo';
|
|
990
|
+
* import source Foo from 'foo';
|
|
991
|
+
* ```
|
|
992
|
+
*
|
|
993
|
+
* The `modules` array must contain two references to the same instance, because the two
|
|
994
|
+
* module requests are identical but in two phases.
|
|
995
|
+
*
|
|
996
|
+
* If the module has no dependencies, the `modules` array can be empty.
|
|
997
|
+
*
|
|
998
|
+
* Users can use `sourceTextModule.moduleRequests` to implement the host-defined
|
|
999
|
+
* [HostLoadImportedModule](https://tc39.es/ecma262/#sec-HostLoadImportedModule) abstract operation in the ECMAScript specification,
|
|
1000
|
+
* and using `sourceTextModule.linkRequests()` to invoke specification defined
|
|
1001
|
+
* [FinishLoadingImportedModule](https://tc39.es/ecma262/#sec-FinishLoadingImportedModule), on the module with all dependencies in a batch.
|
|
1002
|
+
*
|
|
1003
|
+
* It's up to the creator of the `SourceTextModule` to determine if the resolution
|
|
1004
|
+
* of the dependencies is synchronous or asynchronous.
|
|
1005
|
+
*
|
|
1006
|
+
* After each module in the `modules` array is linked, call
|
|
1007
|
+
* `sourceTextModule.instantiate()`.
|
|
1008
|
+
* @since v24.8.0
|
|
1009
|
+
* @param modules Array of `vm.Module` objects that this module depends on.
|
|
1010
|
+
* The order of the modules in the array is the order of
|
|
1011
|
+
* `sourceTextModule.moduleRequests`.
|
|
1012
|
+
*/
|
|
1013
|
+
linkRequests(modules: readonly Module[]): void;
|
|
921
1014
|
/**
|
|
922
1015
|
* The requested import dependencies of this module. The returned array is frozen
|
|
923
1016
|
* to disallow any changes to it.
|
|
@@ -1013,9 +1106,7 @@ declare module "vm" {
|
|
|
1013
1106
|
options?: SyntheticModuleOptions,
|
|
1014
1107
|
);
|
|
1015
1108
|
/**
|
|
1016
|
-
* This method
|
|
1017
|
-
* it is called before the module is linked, an `ERR_VM_MODULE_STATUS` error
|
|
1018
|
-
* will be thrown.
|
|
1109
|
+
* This method sets the module export binding slots with the given value.
|
|
1019
1110
|
*
|
|
1020
1111
|
* ```js
|
|
1021
1112
|
* import vm from 'node:vm';
|
|
@@ -1024,7 +1115,6 @@ declare module "vm" {
|
|
|
1024
1115
|
* m.setExport('x', 1);
|
|
1025
1116
|
* });
|
|
1026
1117
|
*
|
|
1027
|
-
* await m.link(() => {});
|
|
1028
1118
|
* await m.evaluate();
|
|
1029
1119
|
*
|
|
1030
1120
|
* assert.strictEqual(m.namespace.x, 1);
|
node/wasi.d.ts
CHANGED
node/worker_threads.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ declare module "worker_threads" {
|
|
|
62
62
|
import { Readable, Writable } from "node:stream";
|
|
63
63
|
import { ReadableStream, TransformStream, WritableStream } from "node:stream/web";
|
|
64
64
|
import { URL } from "node:url";
|
|
65
|
-
import { HeapInfo } from "node:v8";
|
|
65
|
+
import { CPUProfileHandle, HeapInfo } from "node:v8";
|
|
66
66
|
import { MessageEvent } from "undici-types";
|
|
67
67
|
const isInternalThread: boolean;
|
|
68
68
|
const isMainThread: boolean;
|
|
@@ -469,6 +469,44 @@ declare module "worker_threads" {
|
|
|
469
469
|
* @since v24.0.0
|
|
470
470
|
*/
|
|
471
471
|
getHeapStatistics(): Promise<HeapInfo>;
|
|
472
|
+
/**
|
|
473
|
+
* Starting a CPU profile then return a Promise that fulfills with an error
|
|
474
|
+
* or an `CPUProfileHandle` object. This API supports `await using` syntax.
|
|
475
|
+
*
|
|
476
|
+
* ```js
|
|
477
|
+
* const { Worker } = require('node:worker_threads');
|
|
478
|
+
*
|
|
479
|
+
* const worker = new Worker(`
|
|
480
|
+
* const { parentPort } = require('worker_threads');
|
|
481
|
+
* parentPort.on('message', () => {});
|
|
482
|
+
* `, { eval: true });
|
|
483
|
+
*
|
|
484
|
+
* worker.on('online', async () => {
|
|
485
|
+
* const handle = await worker.startCpuProfile();
|
|
486
|
+
* const profile = await handle.stop();
|
|
487
|
+
* console.log(profile);
|
|
488
|
+
* worker.terminate();
|
|
489
|
+
* });
|
|
490
|
+
* ```
|
|
491
|
+
*
|
|
492
|
+
* `await using` example.
|
|
493
|
+
*
|
|
494
|
+
* ```js
|
|
495
|
+
* const { Worker } = require('node::worker_threads');
|
|
496
|
+
*
|
|
497
|
+
* const w = new Worker(`
|
|
498
|
+
* const { parentPort } = require('worker_threads');
|
|
499
|
+
* parentPort.on('message', () => {});
|
|
500
|
+
* `, { eval: true });
|
|
501
|
+
*
|
|
502
|
+
* w.on('online', async () => {
|
|
503
|
+
* // Stop profile automatically when return and profile will be discarded
|
|
504
|
+
* await using handle = await w.startCpuProfile();
|
|
505
|
+
* });
|
|
506
|
+
* ```
|
|
507
|
+
* @since v24.8.0
|
|
508
|
+
*/
|
|
509
|
+
startCpuProfile(): Promise<CPUProfileHandle>;
|
|
472
510
|
/**
|
|
473
511
|
* Calls `worker.terminate()` when the dispose scope is exited.
|
|
474
512
|
*
|