@aligent/cdk-prerender-proxy 0.2.4 → 0.2.5-beta

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 (150) hide show
  1. package/lib/handlers/cache-control.ts +7 -20
  2. package/lib/handlers/error-response.ts +8 -51
  3. package/lib/handlers/node_modules/.package-lock.json +32 -3
  4. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/index.d.ts +6 -0
  5. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/index.js +14 -0
  6. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/cache-control.d.ts +3 -0
  7. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/cache-control.js +24 -0
  8. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/error-response.d.ts +3 -0
  9. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/error-response.js +50 -0
  10. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/prerender-check.d.ts +3 -0
  11. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/prerender-check.js +28 -0
  12. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/prerender.d.ts +3 -0
  13. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/prerender.js +49 -0
  14. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/redirect.d.ts +3 -0
  15. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/redirect.js +33 -0
  16. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/package.json +27 -0
  17. package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/tsconfig.json +3 -0
  18. package/lib/handlers/node_modules/@middy/core/LICENSE +21 -0
  19. package/lib/handlers/node_modules/@middy/core/README.md +65 -0
  20. package/lib/handlers/node_modules/@middy/core/index.cjs +207 -0
  21. package/lib/handlers/node_modules/@middy/core/index.d.ts +91 -0
  22. package/lib/handlers/node_modules/@middy/core/index.js +199 -0
  23. package/lib/handlers/node_modules/@middy/core/package.json +65 -0
  24. package/lib/handlers/node_modules/@types/node/README.md +4 -4
  25. package/lib/handlers/node_modules/@types/node/assert/strict.d.ts +5 -1
  26. package/lib/handlers/node_modules/@types/node/assert.d.ts +904 -67
  27. package/lib/handlers/node_modules/@types/node/async_hooks.d.ts +371 -96
  28. package/lib/handlers/node_modules/@types/node/buffer.d.ts +2199 -25
  29. package/lib/handlers/node_modules/@types/node/child_process.d.ts +1151 -308
  30. package/lib/handlers/node_modules/@types/node/cluster.d.ts +356 -208
  31. package/lib/handlers/node_modules/@types/node/console.d.ts +324 -45
  32. package/lib/handlers/node_modules/@types/node/constants.d.ts +8 -3
  33. package/lib/handlers/node_modules/@types/node/crypto.d.ts +3230 -846
  34. package/lib/handlers/node_modules/@types/node/dgram.d.ts +478 -74
  35. package/lib/handlers/node_modules/@types/node/diagnostics_channel.d.ts +153 -0
  36. package/lib/handlers/node_modules/@types/node/dns/promises.d.ts +308 -35
  37. package/lib/handlers/node_modules/@types/node/dns.d.ts +444 -107
  38. package/lib/handlers/node_modules/@types/node/dom-events.d.ts +126 -0
  39. package/lib/handlers/node_modules/@types/node/domain.d.ts +162 -16
  40. package/lib/handlers/node_modules/@types/node/events.d.ts +624 -39
  41. package/lib/handlers/node_modules/@types/node/fs/promises.d.ts +911 -365
  42. package/lib/handlers/node_modules/@types/node/fs.d.ts +2611 -978
  43. package/lib/handlers/node_modules/@types/node/globals.d.ts +66 -421
  44. package/lib/handlers/node_modules/@types/node/globals.global.d.ts +1 -1
  45. package/lib/handlers/node_modules/@types/node/http.d.ts +1416 -199
  46. package/lib/handlers/node_modules/@types/node/http2.d.ts +1688 -530
  47. package/lib/handlers/node_modules/@types/node/https.d.ts +532 -26
  48. package/lib/handlers/node_modules/@types/node/index.d.ts +92 -16
  49. package/lib/handlers/node_modules/@types/node/inspector.d.ts +511 -811
  50. package/lib/handlers/node_modules/@types/node/module.d.ts +75 -13
  51. package/lib/handlers/node_modules/@types/node/net.d.ts +710 -167
  52. package/lib/handlers/node_modules/@types/node/os.d.ts +252 -25
  53. package/lib/handlers/node_modules/@types/node/package.json +30 -25
  54. package/lib/handlers/node_modules/@types/node/path.d.ts +59 -31
  55. package/lib/handlers/node_modules/@types/node/perf_hooks.d.ts +420 -105
  56. package/lib/handlers/node_modules/@types/node/process.d.ts +1249 -228
  57. package/lib/handlers/node_modules/@types/node/punycode.d.ts +67 -25
  58. package/lib/handlers/node_modules/@types/node/querystring.d.ts +113 -10
  59. package/lib/handlers/node_modules/@types/node/readline/promises.d.ts +143 -0
  60. package/lib/handlers/node_modules/@types/node/readline.d.ts +570 -109
  61. package/lib/handlers/node_modules/@types/node/repl.d.ts +154 -125
  62. package/lib/handlers/node_modules/@types/node/stream/consumers.d.ts +12 -0
  63. package/lib/handlers/node_modules/@types/node/stream/promises.d.ts +18 -43
  64. package/lib/handlers/node_modules/@types/node/stream/web.d.ts +330 -0
  65. package/lib/handlers/node_modules/@types/node/stream.d.ts +1117 -248
  66. package/lib/handlers/node_modules/@types/node/string_decoder.d.ts +60 -0
  67. package/lib/handlers/node_modules/@types/node/test.d.ts +446 -0
  68. package/lib/handlers/node_modules/@types/node/timers/promises.d.ts +81 -9
  69. package/lib/handlers/node_modules/@types/node/timers.d.ts +84 -17
  70. package/lib/handlers/node_modules/@types/node/tls.d.ts +510 -275
  71. package/lib/handlers/node_modules/@types/node/trace_events.d.ts +120 -10
  72. package/lib/handlers/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
  73. package/lib/handlers/node_modules/@types/node/ts4.8/assert.d.ts +961 -0
  74. package/lib/handlers/node_modules/@types/node/ts4.8/async_hooks.d.ts +501 -0
  75. package/lib/handlers/node_modules/@types/node/ts4.8/buffer.d.ts +2259 -0
  76. package/lib/handlers/node_modules/@types/node/ts4.8/child_process.d.ts +1369 -0
  77. package/lib/handlers/node_modules/@types/node/ts4.8/cluster.d.ts +410 -0
  78. package/lib/handlers/node_modules/@types/node/ts4.8/console.d.ts +412 -0
  79. package/lib/handlers/node_modules/@types/node/ts4.8/constants.d.ts +18 -0
  80. package/lib/handlers/node_modules/@types/node/ts4.8/crypto.d.ts +3964 -0
  81. package/lib/handlers/node_modules/@types/node/ts4.8/dgram.d.ts +545 -0
  82. package/lib/handlers/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +153 -0
  83. package/lib/handlers/node_modules/@types/node/ts4.8/dns/promises.d.ts +370 -0
  84. package/lib/handlers/node_modules/@types/node/ts4.8/dns.d.ts +659 -0
  85. package/lib/handlers/node_modules/@types/node/ts4.8/dom-events.d.ts +126 -0
  86. package/lib/handlers/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
  87. package/lib/handlers/node_modules/@types/node/ts4.8/events.d.ts +678 -0
  88. package/lib/handlers/node_modules/@types/node/ts4.8/fs/promises.d.ts +1138 -0
  89. package/lib/handlers/node_modules/@types/node/ts4.8/fs.d.ts +3872 -0
  90. package/lib/handlers/node_modules/@types/node/ts4.8/globals.d.ts +294 -0
  91. package/lib/handlers/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
  92. package/lib/handlers/node_modules/@types/node/ts4.8/http.d.ts +1651 -0
  93. package/lib/handlers/node_modules/@types/node/ts4.8/http2.d.ts +2134 -0
  94. package/lib/handlers/node_modules/@types/node/ts4.8/https.d.ts +542 -0
  95. package/lib/handlers/node_modules/@types/node/ts4.8/index.d.ts +88 -0
  96. package/lib/handlers/node_modules/@types/node/ts4.8/inspector.d.ts +2741 -0
  97. package/lib/handlers/node_modules/@types/node/ts4.8/module.d.ts +114 -0
  98. package/lib/handlers/node_modules/@types/node/ts4.8/net.d.ts +869 -0
  99. package/lib/handlers/node_modules/@types/node/ts4.8/os.d.ts +466 -0
  100. package/lib/handlers/node_modules/@types/node/ts4.8/path.d.ts +191 -0
  101. package/lib/handlers/node_modules/@types/node/ts4.8/perf_hooks.d.ts +625 -0
  102. package/lib/handlers/node_modules/@types/node/ts4.8/process.d.ts +1482 -0
  103. package/lib/handlers/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
  104. package/lib/handlers/node_modules/@types/node/ts4.8/querystring.d.ts +131 -0
  105. package/lib/handlers/node_modules/@types/node/ts4.8/readline/promises.d.ts +143 -0
  106. package/lib/handlers/node_modules/@types/node/ts4.8/readline.d.ts +653 -0
  107. package/lib/handlers/node_modules/@types/node/ts4.8/repl.d.ts +424 -0
  108. package/lib/handlers/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
  109. package/lib/handlers/node_modules/@types/node/ts4.8/stream/promises.d.ts +42 -0
  110. package/lib/handlers/node_modules/@types/node/ts4.8/stream/web.d.ts +330 -0
  111. package/lib/handlers/node_modules/@types/node/ts4.8/stream.d.ts +1340 -0
  112. package/lib/handlers/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
  113. package/lib/handlers/node_modules/@types/node/ts4.8/test.d.ts +446 -0
  114. package/lib/handlers/node_modules/@types/node/ts4.8/timers/promises.d.ts +93 -0
  115. package/lib/handlers/node_modules/@types/node/ts4.8/timers.d.ts +94 -0
  116. package/lib/handlers/node_modules/@types/node/ts4.8/tls.d.ts +1028 -0
  117. package/lib/handlers/node_modules/@types/node/ts4.8/trace_events.d.ts +171 -0
  118. package/lib/handlers/node_modules/@types/node/ts4.8/tty.d.ts +206 -0
  119. package/lib/handlers/node_modules/@types/node/ts4.8/url.d.ts +897 -0
  120. package/lib/handlers/node_modules/@types/node/ts4.8/util.d.ts +1926 -0
  121. package/lib/handlers/node_modules/@types/node/ts4.8/v8.d.ts +396 -0
  122. package/lib/handlers/node_modules/@types/node/ts4.8/vm.d.ts +509 -0
  123. package/lib/handlers/node_modules/@types/node/ts4.8/wasi.d.ts +158 -0
  124. package/lib/handlers/node_modules/@types/node/ts4.8/worker_threads.d.ts +689 -0
  125. package/lib/handlers/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
  126. package/lib/handlers/node_modules/@types/node/tty.d.ts +163 -23
  127. package/lib/handlers/node_modules/@types/node/url.d.ts +825 -44
  128. package/lib/handlers/node_modules/@types/node/util.d.ts +1842 -72
  129. package/lib/handlers/node_modules/@types/node/v8.d.ts +276 -78
  130. package/lib/handlers/node_modules/@types/node/vm.d.ts +410 -53
  131. package/lib/handlers/node_modules/@types/node/wasi.d.ts +102 -30
  132. package/lib/handlers/node_modules/@types/node/worker_threads.d.ts +559 -152
  133. package/lib/handlers/node_modules/@types/node/zlib.d.ts +234 -78
  134. package/lib/handlers/node_modules/esbuild/README.md +3 -0
  135. package/lib/handlers/node_modules/esbuild/bin/esbuild +0 -0
  136. package/lib/handlers/node_modules/esbuild/install.js +256 -0
  137. package/lib/handlers/node_modules/esbuild/lib/main.d.ts +397 -0
  138. package/lib/handlers/node_modules/esbuild/lib/main.js +1939 -0
  139. package/lib/handlers/node_modules/esbuild/package.json +15 -0
  140. package/lib/handlers/package-lock.json +62 -6
  141. package/lib/handlers/package.json +6 -1
  142. package/lib/handlers/prerender-check.ts +8 -27
  143. package/lib/handlers/prerender.ts +8 -43
  144. package/package.json +1 -1
  145. package/lib/handlers/node_modules/@types/node/base.d.ts +0 -19
  146. package/lib/handlers/node_modules/@types/node/diagnostic_channel.d.ts +0 -34
  147. package/lib/handlers/node_modules/@types/node/ts3.6/assert.d.ts +0 -98
  148. package/lib/handlers/node_modules/@types/node/ts3.6/base.d.ts +0 -68
  149. package/lib/handlers/node_modules/@types/node/ts3.6/index.d.ts +0 -7
  150. package/lib/handlers/node_modules/@types/node/util/types.d.ts +0 -53
@@ -1,79 +1,115 @@
1
+ /**
2
+ * The `vm` module enables compiling and running code within V8 Virtual
3
+ * Machine contexts.
4
+ *
5
+ * **The `vm` module is not a security**
6
+ * **mechanism. Do not use it to run untrusted code.**
7
+ *
8
+ * JavaScript code can be compiled and run immediately or
9
+ * compiled, saved, and run later.
10
+ *
11
+ * A common use case is to run the code in a different V8 Context. This means
12
+ * invoked code has a different global object than the invoking code.
13
+ *
14
+ * One can provide the context by `contextifying` an
15
+ * object. The invoked code treats any property in the context like a
16
+ * global variable. Any changes to global variables caused by the invoked
17
+ * code are reflected in the context object.
18
+ *
19
+ * ```js
20
+ * const vm = require('vm');
21
+ *
22
+ * const x = 1;
23
+ *
24
+ * const context = { x: 2 };
25
+ * vm.createContext(context); // Contextify the object.
26
+ *
27
+ * const code = 'x += 40; var y = 17;';
28
+ * // `x` and `y` are global variables in the context.
29
+ * // Initially, x has the value 2 because that is the value of context.x.
30
+ * vm.runInContext(code, context);
31
+ *
32
+ * console.log(context.x); // 42
33
+ * console.log(context.y); // 17
34
+ *
35
+ * console.log(x); // 1; y is not defined.
36
+ * ```
37
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/vm.js)
38
+ */
1
39
  declare module 'vm' {
2
- interface Context extends NodeJS.Dict<any> { }
40
+ interface Context extends NodeJS.Dict<any> {}
3
41
  interface BaseOptions {
4
42
  /**
5
43
  * Specifies the filename used in stack traces produced by this script.
6
44
  * Default: `''`.
7
45
  */
8
- filename?: string;
46
+ filename?: string | undefined;
9
47
  /**
10
48
  * Specifies the line number offset that is displayed in stack traces produced by this script.
11
49
  * Default: `0`.
12
50
  */
13
- lineOffset?: number;
51
+ lineOffset?: number | undefined;
14
52
  /**
15
53
  * Specifies the column number offset that is displayed in stack traces produced by this script.
16
54
  * @default 0
17
55
  */
18
- columnOffset?: number;
56
+ columnOffset?: number | undefined;
19
57
  }
20
58
  interface ScriptOptions extends BaseOptions {
21
- displayErrors?: boolean;
22
- timeout?: number;
23
- cachedData?: Buffer;
59
+ displayErrors?: boolean | undefined;
60
+ timeout?: number | undefined;
61
+ cachedData?: Buffer | undefined;
24
62
  /** @deprecated in favor of `script.createCachedData()` */
25
- produceCachedData?: boolean;
63
+ produceCachedData?: boolean | undefined;
26
64
  }
27
65
  interface RunningScriptOptions extends BaseOptions {
28
66
  /**
29
67
  * When `true`, if an `Error` occurs while compiling the `code`, the line of code causing the error is attached to the stack trace.
30
68
  * Default: `true`.
31
69
  */
32
- displayErrors?: boolean;
70
+ displayErrors?: boolean | undefined;
33
71
  /**
34
72
  * Specifies the number of milliseconds to execute code before terminating execution.
35
73
  * If execution is terminated, an `Error` will be thrown. This value must be a strictly positive integer.
36
74
  */
37
- timeout?: number;
75
+ timeout?: number | undefined;
38
76
  /**
39
77
  * If `true`, the execution will be terminated when `SIGINT` (Ctrl+C) is received.
40
78
  * Existing handlers for the event that have been attached via `process.on('SIGINT')` will be disabled during script execution, but will continue to work after that.
41
79
  * If execution is terminated, an `Error` will be thrown.
42
80
  * Default: `false`.
43
81
  */
44
- breakOnSigint?: boolean;
82
+ breakOnSigint?: boolean | undefined;
45
83
  /**
46
84
  * If set to `afterEvaluate`, microtasks will be run immediately after the script has run.
47
85
  */
48
- microtaskMode?: 'afterEvaluate';
86
+ microtaskMode?: 'afterEvaluate' | undefined;
49
87
  }
50
88
  interface CompileFunctionOptions extends BaseOptions {
51
89
  /**
52
90
  * Provides an optional data with V8's code cache data for the supplied source.
53
91
  */
54
- cachedData?: Buffer;
92
+ cachedData?: Buffer | undefined;
55
93
  /**
56
94
  * Specifies whether to produce new cache data.
57
95
  * Default: `false`,
58
96
  */
59
- produceCachedData?: boolean;
97
+ produceCachedData?: boolean | undefined;
60
98
  /**
61
99
  * The sandbox/context in which the said function should be compiled in.
62
100
  */
63
- parsingContext?: Context;
64
-
101
+ parsingContext?: Context | undefined;
65
102
  /**
66
103
  * An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling
67
104
  */
68
- contextExtensions?: Object[];
105
+ contextExtensions?: Object[] | undefined;
69
106
  }
70
-
71
107
  interface CreateContextOptions {
72
108
  /**
73
109
  * Human-readable name of the newly created context.
74
110
  * @default 'VM Context i' Where i is an ascending numerical index of the created context.
75
111
  */
76
- name?: string;
112
+ name?: string | undefined;
77
113
  /**
78
114
  * Corresponds to the newly created context for display purposes.
79
115
  * The origin should be formatted like a `URL`, but with only the scheme, host, and port (if necessary),
@@ -81,72 +117,393 @@ declare module 'vm' {
81
117
  * Most notably, this string should omit the trailing slash, as that denotes a path.
82
118
  * @default ''
83
119
  */
84
- origin?: string;
85
- codeGeneration?: {
86
- /**
87
- * If set to false any calls to eval or function constructors (Function, GeneratorFunction, etc)
88
- * will throw an EvalError.
89
- * @default true
90
- */
91
- strings?: boolean;
92
- /**
93
- * If set to false any attempt to compile a WebAssembly module will throw a WebAssembly.CompileError.
94
- * @default true
95
- */
96
- wasm?: boolean;
97
- };
120
+ origin?: string | undefined;
121
+ codeGeneration?:
122
+ | {
123
+ /**
124
+ * If set to false any calls to eval or function constructors (Function, GeneratorFunction, etc)
125
+ * will throw an EvalError.
126
+ * @default true
127
+ */
128
+ strings?: boolean | undefined;
129
+ /**
130
+ * If set to false any attempt to compile a WebAssembly module will throw a WebAssembly.CompileError.
131
+ * @default true
132
+ */
133
+ wasm?: boolean | undefined;
134
+ }
135
+ | undefined;
98
136
  /**
99
137
  * If set to `afterEvaluate`, microtasks will be run immediately after the script has run.
100
138
  */
101
- microtaskMode?: 'afterEvaluate';
139
+ microtaskMode?: 'afterEvaluate' | undefined;
102
140
  }
103
-
104
141
  type MeasureMemoryMode = 'summary' | 'detailed';
105
-
106
142
  interface MeasureMemoryOptions {
107
143
  /**
108
144
  * @default 'summary'
109
145
  */
110
- mode?: MeasureMemoryMode;
111
- context?: Context;
146
+ mode?: MeasureMemoryMode | undefined;
147
+ context?: Context | undefined;
112
148
  }
113
-
114
149
  interface MemoryMeasurement {
115
150
  total: {
116
151
  jsMemoryEstimate: number;
117
152
  jsMemoryRange: [number, number];
118
153
  };
119
154
  }
120
-
155
+ /**
156
+ * Instances of the `vm.Script` class contain precompiled scripts that can be
157
+ * executed in specific contexts.
158
+ * @since v0.3.1
159
+ */
121
160
  class Script {
122
161
  constructor(code: string, options?: ScriptOptions);
123
- runInContext(contextifiedSandbox: Context, options?: RunningScriptOptions): any;
124
- runInNewContext(sandbox?: Context, options?: RunningScriptOptions): any;
162
+ /**
163
+ * Runs the compiled code contained by the `vm.Script` object within the given`contextifiedObject` and returns the result. Running code does not have access
164
+ * to local scope.
165
+ *
166
+ * The following example compiles code that increments a global variable, sets
167
+ * the value of another global variable, then execute the code multiple times.
168
+ * The globals are contained in the `context` object.
169
+ *
170
+ * ```js
171
+ * const vm = require('vm');
172
+ *
173
+ * const context = {
174
+ * animal: 'cat',
175
+ * count: 2
176
+ * };
177
+ *
178
+ * const script = new vm.Script('count += 1; name = "kitty";');
179
+ *
180
+ * vm.createContext(context);
181
+ * for (let i = 0; i < 10; ++i) {
182
+ * script.runInContext(context);
183
+ * }
184
+ *
185
+ * console.log(context);
186
+ * // Prints: { animal: 'cat', count: 12, name: 'kitty' }
187
+ * ```
188
+ *
189
+ * Using the `timeout` or `breakOnSigint` options will result in new event loops
190
+ * and corresponding threads being started, which have a non-zero performance
191
+ * overhead.
192
+ * @since v0.3.1
193
+ * @param contextifiedObject A `contextified` object as returned by the `vm.createContext()` method.
194
+ * @return the result of the very last statement executed in the script.
195
+ */
196
+ runInContext(contextifiedObject: Context, options?: RunningScriptOptions): any;
197
+ /**
198
+ * First contextifies the given `contextObject`, runs the compiled code contained
199
+ * by the `vm.Script` object within the created context, and returns the result.
200
+ * Running code does not have access to local scope.
201
+ *
202
+ * The following example compiles code that sets a global variable, then executes
203
+ * the code multiple times in different contexts. The globals are set on and
204
+ * contained within each individual `context`.
205
+ *
206
+ * ```js
207
+ * const vm = require('vm');
208
+ *
209
+ * const script = new vm.Script('globalVar = "set"');
210
+ *
211
+ * const contexts = [{}, {}, {}];
212
+ * contexts.forEach((context) => {
213
+ * script.runInNewContext(context);
214
+ * });
215
+ *
216
+ * console.log(contexts);
217
+ * // Prints: [{ globalVar: 'set' }, { globalVar: 'set' }, { globalVar: 'set' }]
218
+ * ```
219
+ * @since v0.3.1
220
+ * @param contextObject An object that will be `contextified`. If `undefined`, a new object will be created.
221
+ * @return the result of the very last statement executed in the script.
222
+ */
223
+ runInNewContext(contextObject?: Context, options?: RunningScriptOptions): any;
224
+ /**
225
+ * Runs the compiled code contained by the `vm.Script` within the context of the
226
+ * current `global` object. Running code does not have access to local scope, but _does_ have access to the current `global` object.
227
+ *
228
+ * The following example compiles code that increments a `global` variable then
229
+ * executes that code multiple times:
230
+ *
231
+ * ```js
232
+ * const vm = require('vm');
233
+ *
234
+ * global.globalVar = 0;
235
+ *
236
+ * const script = new vm.Script('globalVar += 1', { filename: 'myfile.vm' });
237
+ *
238
+ * for (let i = 0; i < 1000; ++i) {
239
+ * script.runInThisContext();
240
+ * }
241
+ *
242
+ * console.log(globalVar);
243
+ *
244
+ * // 1000
245
+ * ```
246
+ * @since v0.3.1
247
+ * @return the result of the very last statement executed in the script.
248
+ */
125
249
  runInThisContext(options?: RunningScriptOptions): any;
250
+ /**
251
+ * Creates a code cache that can be used with the `Script` constructor's`cachedData` option. Returns a `Buffer`. This method may be called at any
252
+ * time and any number of times.
253
+ *
254
+ * ```js
255
+ * const script = new vm.Script(`
256
+ * function add(a, b) {
257
+ * return a + b;
258
+ * }
259
+ *
260
+ * const x = add(1, 2);
261
+ * `);
262
+ *
263
+ * const cacheWithoutX = script.createCachedData();
264
+ *
265
+ * script.runInThisContext();
266
+ *
267
+ * const cacheWithX = script.createCachedData();
268
+ * ```
269
+ * @since v10.6.0
270
+ */
126
271
  createCachedData(): Buffer;
127
- cachedDataRejected?: boolean;
272
+ /** @deprecated in favor of `script.createCachedData()` */
273
+ cachedDataProduced?: boolean | undefined;
274
+ cachedDataRejected?: boolean | undefined;
275
+ cachedData?: Buffer | undefined;
128
276
  }
277
+ /**
278
+ * If given a `contextObject`, the `vm.createContext()` method will `prepare
279
+ * that object` so that it can be used in calls to {@link runInContext} or `script.runInContext()`. Inside such scripts,
280
+ * the `contextObject` will be the global object, retaining all of its existing
281
+ * properties but also having the built-in objects and functions any standard [global object](https://es5.github.io/#x15.1) has. Outside of scripts run by the vm module, global variables
282
+ * will remain unchanged.
283
+ *
284
+ * ```js
285
+ * const vm = require('vm');
286
+ *
287
+ * global.globalVar = 3;
288
+ *
289
+ * const context = { globalVar: 1 };
290
+ * vm.createContext(context);
291
+ *
292
+ * vm.runInContext('globalVar *= 2;', context);
293
+ *
294
+ * console.log(context);
295
+ * // Prints: { globalVar: 2 }
296
+ *
297
+ * console.log(global.globalVar);
298
+ * // Prints: 3
299
+ * ```
300
+ *
301
+ * If `contextObject` is omitted (or passed explicitly as `undefined`), a new,
302
+ * empty `contextified` object will be returned.
303
+ *
304
+ * The `vm.createContext()` method is primarily useful for creating a single
305
+ * context that can be used to run multiple scripts. For instance, if emulating a
306
+ * web browser, the method can be used to create a single context representing a
307
+ * window's global object, then run all `<script>` tags together within that
308
+ * context.
309
+ *
310
+ * The provided `name` and `origin` of the context are made visible through the
311
+ * Inspector API.
312
+ * @since v0.3.1
313
+ * @return contextified object.
314
+ */
129
315
  function createContext(sandbox?: Context, options?: CreateContextOptions): Context;
316
+ /**
317
+ * Returns `true` if the given `object` object has been `contextified` using {@link createContext}.
318
+ * @since v0.11.7
319
+ */
130
320
  function isContext(sandbox: Context): boolean;
131
- function runInContext(code: string, contextifiedSandbox: Context, options?: RunningScriptOptions | string): any;
132
- function runInNewContext(code: string, sandbox?: Context, options?: RunningScriptOptions | string): any;
321
+ /**
322
+ * The `vm.runInContext()` method compiles `code`, runs it within the context of
323
+ * the `contextifiedObject`, then returns the result. Running code does not have
324
+ * access to the local scope. The `contextifiedObject` object _must_ have been
325
+ * previously `contextified` using the {@link createContext} method.
326
+ *
327
+ * If `options` is a string, then it specifies the filename.
328
+ *
329
+ * The following example compiles and executes different scripts using a single `contextified` object:
330
+ *
331
+ * ```js
332
+ * const vm = require('vm');
333
+ *
334
+ * const contextObject = { globalVar: 1 };
335
+ * vm.createContext(contextObject);
336
+ *
337
+ * for (let i = 0; i < 10; ++i) {
338
+ * vm.runInContext('globalVar *= 2;', contextObject);
339
+ * }
340
+ * console.log(contextObject);
341
+ * // Prints: { globalVar: 1024 }
342
+ * ```
343
+ * @since v0.3.1
344
+ * @param code The JavaScript code to compile and run.
345
+ * @param contextifiedObject The `contextified` object that will be used as the `global` when the `code` is compiled and run.
346
+ * @return the result of the very last statement executed in the script.
347
+ */
348
+ function runInContext(code: string, contextifiedObject: Context, options?: RunningScriptOptions | string): any;
349
+ /**
350
+ * The `vm.runInNewContext()` first contextifies the given `contextObject` (or
351
+ * creates a new `contextObject` if passed as `undefined`), compiles the `code`,
352
+ * runs it within the created context, then returns the result. Running code
353
+ * does not have access to the local scope.
354
+ *
355
+ * If `options` is a string, then it specifies the filename.
356
+ *
357
+ * The following example compiles and executes code that increments a global
358
+ * variable and sets a new one. These globals are contained in the `contextObject`.
359
+ *
360
+ * ```js
361
+ * const vm = require('vm');
362
+ *
363
+ * const contextObject = {
364
+ * animal: 'cat',
365
+ * count: 2
366
+ * };
367
+ *
368
+ * vm.runInNewContext('count += 1; name = "kitty"', contextObject);
369
+ * console.log(contextObject);
370
+ * // Prints: { animal: 'cat', count: 3, name: 'kitty' }
371
+ * ```
372
+ * @since v0.3.1
373
+ * @param code The JavaScript code to compile and run.
374
+ * @param contextObject An object that will be `contextified`. If `undefined`, a new object will be created.
375
+ * @return the result of the very last statement executed in the script.
376
+ */
377
+ function runInNewContext(code: string, contextObject?: Context, options?: RunningScriptOptions | string): any;
378
+ /**
379
+ * `vm.runInThisContext()` compiles `code`, runs it within the context of the
380
+ * current `global` and returns the result. Running code does not have access to
381
+ * local scope, but does have access to the current `global` object.
382
+ *
383
+ * If `options` is a string, then it specifies the filename.
384
+ *
385
+ * The following example illustrates using both `vm.runInThisContext()` and
386
+ * the JavaScript [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) function to run the same code:
387
+ *
388
+ * ```js
389
+ * const vm = require('vm');
390
+ * let localVar = 'initial value';
391
+ *
392
+ * const vmResult = vm.runInThisContext('localVar = "vm";');
393
+ * console.log(`vmResult: '${vmResult}', localVar: '${localVar}'`);
394
+ * // Prints: vmResult: 'vm', localVar: 'initial value'
395
+ *
396
+ * const evalResult = eval('localVar = "eval";');
397
+ * console.log(`evalResult: '${evalResult}', localVar: '${localVar}'`);
398
+ * // Prints: evalResult: 'eval', localVar: 'eval'
399
+ * ```
400
+ *
401
+ * Because `vm.runInThisContext()` does not have access to the local scope,`localVar` is unchanged. In contrast,
402
+ * [`eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) _does_ have access to the
403
+ * local scope, so the value `localVar` is changed. In this way`vm.runInThisContext()` is much like an [indirect `eval()` call](https://es5.github.io/#x10.4.2), e.g.`(0,eval)('code')`.
404
+ *
405
+ * ## Example: Running an HTTP server within a VM
406
+ *
407
+ * When using either `script.runInThisContext()` or {@link runInThisContext}, the code is executed within the current V8 global
408
+ * context. The code passed to this VM context will have its own isolated scope.
409
+ *
410
+ * In order to run a simple web server using the `http` module the code passed to
411
+ * the context must either call `require('http')` on its own, or have a reference
412
+ * to the `http` module passed to it. For instance:
413
+ *
414
+ * ```js
415
+ * 'use strict';
416
+ * const vm = require('vm');
417
+ *
418
+ * const code = `
419
+ * ((require) => {
420
+ * const http = require('http');
421
+ *
422
+ * http.createServer((request, response) => {
423
+ * response.writeHead(200, { 'Content-Type': 'text/plain' });
424
+ * response.end('Hello World\\n');
425
+ * }).listen(8124);
426
+ *
427
+ * console.log('Server running at http://127.0.0.1:8124/');
428
+ * })`;
429
+ *
430
+ * vm.runInThisContext(code)(require);
431
+ * ```
432
+ *
433
+ * The `require()` in the above case shares the state with the context it is
434
+ * passed from. This may introduce risks when untrusted code is executed, e.g.
435
+ * altering objects in the context in unwanted ways.
436
+ * @since v0.3.1
437
+ * @param code The JavaScript code to compile and run.
438
+ * @return the result of the very last statement executed in the script.
439
+ */
133
440
  function runInThisContext(code: string, options?: RunningScriptOptions | string): any;
441
+ /**
442
+ * Compiles the given code into the provided context (if no context is
443
+ * supplied, the current context is used), and returns it wrapped inside a
444
+ * function with the given `params`.
445
+ * @since v10.10.0
446
+ * @param code The body of the function to compile.
447
+ * @param params An array of strings containing all parameters for the function.
448
+ */
134
449
  function compileFunction(code: string, params?: ReadonlyArray<string>, options?: CompileFunctionOptions): Function;
135
-
136
450
  /**
137
- * Measure the memory known to V8 and used by the current execution context or a specified context.
451
+ * Measure the memory known to V8 and used by all contexts known to the
452
+ * current V8 isolate, or the main context.
138
453
  *
139
454
  * The format of the object that the returned Promise may resolve with is
140
455
  * specific to the V8 engine and may change from one version of V8 to the next.
141
456
  *
142
- * The returned result is different from the statistics returned by
143
- * `v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measures
144
- * the memory reachable by V8 from a specific context, while
145
- * `v8.getHeapSpaceStatistics()` measures the memory used by an instance
146
- * of V8 engine, which can switch among multiple contexts that reference
147
- * objects in the heap of one engine.
457
+ * The returned result is different from the statistics returned by`v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measure the
458
+ * memory reachable by each V8 specific contexts in the current instance of
459
+ * the V8 engine, while the result of `v8.getHeapSpaceStatistics()` measure
460
+ * the memory occupied by each heap space in the current V8 instance.
461
+ *
462
+ * ```js
463
+ * const vm = require('vm');
464
+ * // Measure the memory used by the main context.
465
+ * vm.measureMemory({ mode: 'summary' })
466
+ * // This is the same as vm.measureMemory()
467
+ * .then((result) => {
468
+ * // The current format is:
469
+ * // {
470
+ * // total: {
471
+ * // jsMemoryEstimate: 2418479, jsMemoryRange: [ 2418479, 2745799 ]
472
+ * // }
473
+ * // }
474
+ * console.log(result);
475
+ * });
148
476
  *
477
+ * const context = vm.createContext({ a: 1 });
478
+ * vm.measureMemory({ mode: 'detailed', execution: 'eager' })
479
+ * .then((result) => {
480
+ * // Reference the context here so that it won't be GC'ed
481
+ * // until the measurement is complete.
482
+ * console.log(context.a);
483
+ * // {
484
+ * // total: {
485
+ * // jsMemoryEstimate: 2574732,
486
+ * // jsMemoryRange: [ 2574732, 2904372 ]
487
+ * // },
488
+ * // current: {
489
+ * // jsMemoryEstimate: 2438996,
490
+ * // jsMemoryRange: [ 2438996, 2768636 ]
491
+ * // },
492
+ * // other: [
493
+ * // {
494
+ * // jsMemoryEstimate: 135736,
495
+ * // jsMemoryRange: [ 135736, 465376 ]
496
+ * // }
497
+ * // ]
498
+ * // }
499
+ * console.log(result);
500
+ * });
501
+ * ```
502
+ * @since v13.10.0
149
503
  * @experimental
150
504
  */
151
505
  function measureMemory(options?: MeasureMemoryOptions): Promise<MemoryMeasurement>;
152
506
  }
507
+ declare module 'node:vm' {
508
+ export * from 'vm';
509
+ }