@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,24 +1,99 @@
1
+ /**
2
+ * The `readline` module provides an interface for reading data from a `Readable` stream (such as `process.stdin`) one line at a time.
3
+ *
4
+ * To use the promise-based APIs:
5
+ *
6
+ * ```js
7
+ * import * as readline from 'node:readline/promises';
8
+ * ```
9
+ *
10
+ * To use the callback and sync APIs:
11
+ *
12
+ * ```js
13
+ * import * as readline from 'node:readline';
14
+ * ```
15
+ *
16
+ * The following simple example illustrates the basic use of the `readline` module.
17
+ *
18
+ * ```js
19
+ * import * as readline from 'node:readline/promises';
20
+ * import { stdin as input, stdout as output } from 'node:process';
21
+ *
22
+ * const rl = readline.createInterface({ input, output });
23
+ *
24
+ * const answer = await rl.question('What do you think of Node.js? ');
25
+ *
26
+ * console.log(`Thank you for your valuable feedback: ${answer}`);
27
+ *
28
+ * rl.close();
29
+ * ```
30
+ *
31
+ * Once this code is invoked, the Node.js application will not terminate until the`readline.Interface` is closed because the interface waits for data to be
32
+ * received on the `input` stream.
33
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/readline.js)
34
+ */
1
35
  declare module 'readline' {
2
- import { Abortable, EventEmitter } from 'events';
36
+ import { Abortable, EventEmitter } from 'node:events';
37
+ import * as promises from 'node:readline/promises';
3
38
 
4
- interface Key {
5
- sequence?: string;
6
- name?: string;
7
- ctrl?: boolean;
8
- meta?: boolean;
9
- shift?: boolean;
39
+ export { promises };
40
+ export interface Key {
41
+ sequence?: string | undefined;
42
+ name?: string | undefined;
43
+ ctrl?: boolean | undefined;
44
+ meta?: boolean | undefined;
45
+ shift?: boolean | undefined;
10
46
  }
11
-
12
- class Interface extends EventEmitter {
47
+ /**
48
+ * Instances of the `readline.Interface` class are constructed using the`readline.createInterface()` method. Every instance is associated with a
49
+ * single `input` `Readable` stream and a single `output` `Writable` stream.
50
+ * The `output` stream is used to print prompts for user input that arrives on,
51
+ * and is read from, the `input` stream.
52
+ * @since v0.1.104
53
+ */
54
+ export class Interface extends EventEmitter {
13
55
  readonly terminal: boolean;
14
-
15
- // Need direct access to line/cursor data, for use in external processes
16
- // see: https://github.com/nodejs/node/issues/30347
17
- /** The current input data */
56
+ /**
57
+ * The current input data being processed by node.
58
+ *
59
+ * This can be used when collecting input from a TTY stream to retrieve the
60
+ * current value that has been processed thus far, prior to the `line` event
61
+ * being emitted. Once the `line` event has been emitted, this property will
62
+ * be an empty string.
63
+ *
64
+ * Be aware that modifying the value during the instance runtime may have
65
+ * unintended consequences if `rl.cursor` is not also controlled.
66
+ *
67
+ * **If not using a TTY stream for input, use the `'line'` event.**
68
+ *
69
+ * One possible use case would be as follows:
70
+ *
71
+ * ```js
72
+ * const values = ['lorem ipsum', 'dolor sit amet'];
73
+ * const rl = readline.createInterface(process.stdin);
74
+ * const showResults = debounce(() => {
75
+ * console.log(
76
+ * '\n',
77
+ * values.filter((val) => val.startsWith(rl.line)).join(' ')
78
+ * );
79
+ * }, 300);
80
+ * process.stdin.on('keypress', (c, k) => {
81
+ * showResults();
82
+ * });
83
+ * ```
84
+ * @since v0.1.98
85
+ */
18
86
  readonly line: string;
19
- /** The current cursor position in the input line */
87
+ /**
88
+ * The cursor position relative to `rl.line`.
89
+ *
90
+ * This will track where the current cursor lands in the input string, when
91
+ * reading input from a TTY stream. The position of cursor determines the
92
+ * portion of the input string that will be modified as input is processed,
93
+ * as well as the column where the terminal caret will be rendered.
94
+ * @since v0.1.98
95
+ */
20
96
  readonly cursor: number;
21
-
22
97
  /**
23
98
  * NOTE: According to the documentation:
24
99
  *
@@ -37,24 +112,145 @@ declare module 'readline' {
37
112
  * @see https://nodejs.org/dist/latest-v10.x/docs/api/readline.html#readline_class_interface
38
113
  */
39
114
  protected constructor(options: ReadLineOptions);
40
-
115
+ /**
116
+ * The `rl.getPrompt()` method returns the current prompt used by `rl.prompt()`.
117
+ * @since v15.3.0
118
+ * @return the current prompt string
119
+ */
41
120
  getPrompt(): string;
121
+ /**
122
+ * The `rl.setPrompt()` method sets the prompt that will be written to `output`whenever `rl.prompt()` is called.
123
+ * @since v0.1.98
124
+ */
42
125
  setPrompt(prompt: string): void;
126
+ /**
127
+ * The `rl.prompt()` method writes the `readline.Interface` instances configured`prompt` to a new line in `output` in order to provide a user with a new
128
+ * location at which to provide input.
129
+ *
130
+ * When called, `rl.prompt()` will resume the `input` stream if it has been
131
+ * paused.
132
+ *
133
+ * If the `readline.Interface` was created with `output` set to `null` or`undefined` the prompt is not written.
134
+ * @since v0.1.98
135
+ * @param preserveCursor If `true`, prevents the cursor placement from being reset to `0`.
136
+ */
43
137
  prompt(preserveCursor?: boolean): void;
138
+ /**
139
+ * The `rl.question()` method displays the `query` by writing it to the `output`,
140
+ * waits for user input to be provided on `input`, then invokes the `callback`function passing the provided input as the first argument.
141
+ *
142
+ * When called, `rl.question()` will resume the `input` stream if it has been
143
+ * paused.
144
+ *
145
+ * If the `readline.Interface` was created with `output` set to `null` or`undefined` the `query` is not written.
146
+ *
147
+ * The `callback` function passed to `rl.question()` does not follow the typical
148
+ * pattern of accepting an `Error` object or `null` as the first argument.
149
+ * The `callback` is called with the provided answer as the only argument.
150
+ *
151
+ * Example usage:
152
+ *
153
+ * ```js
154
+ * rl.question('What is your favorite food? ', (answer) => {
155
+ * console.log(`Oh, so your favorite food is ${answer}`);
156
+ * });
157
+ * ```
158
+ *
159
+ * Using an `AbortController` to cancel a question.
160
+ *
161
+ * ```js
162
+ * const ac = new AbortController();
163
+ * const signal = ac.signal;
164
+ *
165
+ * rl.question('What is your favorite food? ', { signal }, (answer) => {
166
+ * console.log(`Oh, so your favorite food is ${answer}`);
167
+ * });
168
+ *
169
+ * signal.addEventListener('abort', () => {
170
+ * console.log('The food question timed out');
171
+ * }, { once: true });
172
+ *
173
+ * setTimeout(() => ac.abort(), 10000);
174
+ * ```
175
+ *
176
+ * If this method is invoked as it's util.promisify()ed version, it returns a
177
+ * Promise that fulfills with the answer. If the question is canceled using
178
+ * an `AbortController` it will reject with an `AbortError`.
179
+ *
180
+ * ```js
181
+ * const util = require('util');
182
+ * const question = util.promisify(rl.question).bind(rl);
183
+ *
184
+ * async function questionExample() {
185
+ * try {
186
+ * const answer = await question('What is you favorite food? ');
187
+ * console.log(`Oh, so your favorite food is ${answer}`);
188
+ * } catch (err) {
189
+ * console.error('Question rejected', err);
190
+ * }
191
+ * }
192
+ * questionExample();
193
+ * ```
194
+ * @since v0.3.3
195
+ * @param query A statement or query to write to `output`, prepended to the prompt.
196
+ * @param callback A callback function that is invoked with the user's input in response to the `query`.
197
+ */
44
198
  question(query: string, callback: (answer: string) => void): void;
45
199
  question(query: string, options: Abortable, callback: (answer: string) => void): void;
200
+ /**
201
+ * The `rl.pause()` method pauses the `input` stream, allowing it to be resumed
202
+ * later if necessary.
203
+ *
204
+ * Calling `rl.pause()` does not immediately pause other events (including`'line'`) from being emitted by the `readline.Interface` instance.
205
+ * @since v0.3.4
206
+ */
46
207
  pause(): this;
208
+ /**
209
+ * The `rl.resume()` method resumes the `input` stream if it has been paused.
210
+ * @since v0.3.4
211
+ */
47
212
  resume(): this;
213
+ /**
214
+ * The `rl.close()` method closes the `readline.Interface` instance and
215
+ * relinquishes control over the `input` and `output` streams. When called,
216
+ * the `'close'` event will be emitted.
217
+ *
218
+ * Calling `rl.close()` does not immediately stop other events (including `'line'`)
219
+ * from being emitted by the `readline.Interface` instance.
220
+ * @since v0.1.98
221
+ */
48
222
  close(): void;
223
+ /**
224
+ * The `rl.write()` method will write either `data` or a key sequence identified
225
+ * by `key` to the `output`. The `key` argument is supported only if `output` is
226
+ * a `TTY` text terminal. See `TTY keybindings` for a list of key
227
+ * combinations.
228
+ *
229
+ * If `key` is specified, `data` is ignored.
230
+ *
231
+ * When called, `rl.write()` will resume the `input` stream if it has been
232
+ * paused.
233
+ *
234
+ * If the `readline.Interface` was created with `output` set to `null` or`undefined` the `data` and `key` are not written.
235
+ *
236
+ * ```js
237
+ * rl.write('Delete this!');
238
+ * // Simulate Ctrl+U to delete the line written previously
239
+ * rl.write(null, { ctrl: true, name: 'u' });
240
+ * ```
241
+ *
242
+ * The `rl.write()` method will write the data to the `readline` `Interface`'s`input`_as if it were provided by the user_.
243
+ * @since v0.1.98
244
+ */
49
245
  write(data: string | Buffer, key?: Key): void;
50
-
246
+ write(data: undefined | null | string | Buffer, key: Key): void;
51
247
  /**
52
248
  * Returns the real position of the cursor in relation to the input
53
- * prompt + string. Long input (wrapping) strings, as well as multiple
249
+ * prompt + string. Long input (wrapping) strings, as well as multiple
54
250
  * line prompts are included in the calculations.
251
+ * @since v13.5.0, v12.16.0
55
252
  */
56
253
  getCursorPos(): CursorPos;
57
-
58
254
  /**
59
255
  * events.EventEmitter
60
256
  * 1. close
@@ -67,126 +263,391 @@ declare module 'readline' {
67
263
  * 8. history
68
264
  */
69
265
  addListener(event: string, listener: (...args: any[]) => void): this;
70
- addListener(event: "close", listener: () => void): this;
71
- addListener(event: "line", listener: (input: string) => void): this;
72
- addListener(event: "pause", listener: () => void): this;
73
- addListener(event: "resume", listener: () => void): this;
74
- addListener(event: "SIGCONT", listener: () => void): this;
75
- addListener(event: "SIGINT", listener: () => void): this;
76
- addListener(event: "SIGTSTP", listener: () => void): this;
77
- addListener(event: "history", listener: (history: string[]) => void): this;
78
-
266
+ addListener(event: 'close', listener: () => void): this;
267
+ addListener(event: 'line', listener: (input: string) => void): this;
268
+ addListener(event: 'pause', listener: () => void): this;
269
+ addListener(event: 'resume', listener: () => void): this;
270
+ addListener(event: 'SIGCONT', listener: () => void): this;
271
+ addListener(event: 'SIGINT', listener: () => void): this;
272
+ addListener(event: 'SIGTSTP', listener: () => void): this;
273
+ addListener(event: 'history', listener: (history: string[]) => void): this;
79
274
  emit(event: string | symbol, ...args: any[]): boolean;
80
- emit(event: "close"): boolean;
81
- emit(event: "line", input: string): boolean;
82
- emit(event: "pause"): boolean;
83
- emit(event: "resume"): boolean;
84
- emit(event: "SIGCONT"): boolean;
85
- emit(event: "SIGINT"): boolean;
86
- emit(event: "SIGTSTP"): boolean;
87
- emit(event: "history", history: string[]): boolean;
88
-
275
+ emit(event: 'close'): boolean;
276
+ emit(event: 'line', input: string): boolean;
277
+ emit(event: 'pause'): boolean;
278
+ emit(event: 'resume'): boolean;
279
+ emit(event: 'SIGCONT'): boolean;
280
+ emit(event: 'SIGINT'): boolean;
281
+ emit(event: 'SIGTSTP'): boolean;
282
+ emit(event: 'history', history: string[]): boolean;
89
283
  on(event: string, listener: (...args: any[]) => void): this;
90
- on(event: "close", listener: () => void): this;
91
- on(event: "line", listener: (input: string) => void): this;
92
- on(event: "pause", listener: () => void): this;
93
- on(event: "resume", listener: () => void): this;
94
- on(event: "SIGCONT", listener: () => void): this;
95
- on(event: "SIGINT", listener: () => void): this;
96
- on(event: "SIGTSTP", listener: () => void): this;
97
- on(event: "history", listener: (history: string[]) => void): this;
98
-
284
+ on(event: 'close', listener: () => void): this;
285
+ on(event: 'line', listener: (input: string) => void): this;
286
+ on(event: 'pause', listener: () => void): this;
287
+ on(event: 'resume', listener: () => void): this;
288
+ on(event: 'SIGCONT', listener: () => void): this;
289
+ on(event: 'SIGINT', listener: () => void): this;
290
+ on(event: 'SIGTSTP', listener: () => void): this;
291
+ on(event: 'history', listener: (history: string[]) => void): this;
99
292
  once(event: string, listener: (...args: any[]) => void): this;
100
- once(event: "close", listener: () => void): this;
101
- once(event: "line", listener: (input: string) => void): this;
102
- once(event: "pause", listener: () => void): this;
103
- once(event: "resume", listener: () => void): this;
104
- once(event: "SIGCONT", listener: () => void): this;
105
- once(event: "SIGINT", listener: () => void): this;
106
- once(event: "SIGTSTP", listener: () => void): this;
107
- once(event: "history", listener: (history: string[]) => void): this;
108
-
293
+ once(event: 'close', listener: () => void): this;
294
+ once(event: 'line', listener: (input: string) => void): this;
295
+ once(event: 'pause', listener: () => void): this;
296
+ once(event: 'resume', listener: () => void): this;
297
+ once(event: 'SIGCONT', listener: () => void): this;
298
+ once(event: 'SIGINT', listener: () => void): this;
299
+ once(event: 'SIGTSTP', listener: () => void): this;
300
+ once(event: 'history', listener: (history: string[]) => void): this;
109
301
  prependListener(event: string, listener: (...args: any[]) => void): this;
110
- prependListener(event: "close", listener: () => void): this;
111
- prependListener(event: "line", listener: (input: string) => void): this;
112
- prependListener(event: "pause", listener: () => void): this;
113
- prependListener(event: "resume", listener: () => void): this;
114
- prependListener(event: "SIGCONT", listener: () => void): this;
115
- prependListener(event: "SIGINT", listener: () => void): this;
116
- prependListener(event: "SIGTSTP", listener: () => void): this;
117
- prependListener(event: "history", listener: (history: string[]) => void): this;
118
-
302
+ prependListener(event: 'close', listener: () => void): this;
303
+ prependListener(event: 'line', listener: (input: string) => void): this;
304
+ prependListener(event: 'pause', listener: () => void): this;
305
+ prependListener(event: 'resume', listener: () => void): this;
306
+ prependListener(event: 'SIGCONT', listener: () => void): this;
307
+ prependListener(event: 'SIGINT', listener: () => void): this;
308
+ prependListener(event: 'SIGTSTP', listener: () => void): this;
309
+ prependListener(event: 'history', listener: (history: string[]) => void): this;
119
310
  prependOnceListener(event: string, listener: (...args: any[]) => void): this;
120
- prependOnceListener(event: "close", listener: () => void): this;
121
- prependOnceListener(event: "line", listener: (input: string) => void): this;
122
- prependOnceListener(event: "pause", listener: () => void): this;
123
- prependOnceListener(event: "resume", listener: () => void): this;
124
- prependOnceListener(event: "SIGCONT", listener: () => void): this;
125
- prependOnceListener(event: "SIGINT", listener: () => void): this;
126
- prependOnceListener(event: "SIGTSTP", listener: () => void): this;
127
- prependOnceListener(event: "history", listener: (history: string[]) => void): this;
128
-
311
+ prependOnceListener(event: 'close', listener: () => void): this;
312
+ prependOnceListener(event: 'line', listener: (input: string) => void): this;
313
+ prependOnceListener(event: 'pause', listener: () => void): this;
314
+ prependOnceListener(event: 'resume', listener: () => void): this;
315
+ prependOnceListener(event: 'SIGCONT', listener: () => void): this;
316
+ prependOnceListener(event: 'SIGINT', listener: () => void): this;
317
+ prependOnceListener(event: 'SIGTSTP', listener: () => void): this;
318
+ prependOnceListener(event: 'history', listener: (history: string[]) => void): this;
129
319
  [Symbol.asyncIterator](): AsyncIterableIterator<string>;
130
320
  }
131
-
132
- type ReadLine = Interface; // type forwarded for backwards compatibility
133
-
134
- type Completer = (line: string) => CompleterResult;
135
- type AsyncCompleter = (line: string, callback: (err?: null | Error, result?: CompleterResult) => void) => any;
136
-
137
- type CompleterResult = [string[], string];
138
-
139
- interface ReadLineOptions {
321
+ export type ReadLine = Interface; // type forwarded for backwards compatibility
322
+ export type Completer = (line: string) => CompleterResult;
323
+ export type AsyncCompleter = (line: string, callback: (err?: null | Error, result?: CompleterResult) => void) => void;
324
+ export type CompleterResult = [string[], string];
325
+ export interface ReadLineOptions {
140
326
  input: NodeJS.ReadableStream;
141
- output?: NodeJS.WritableStream;
142
- completer?: Completer | AsyncCompleter;
143
- terminal?: boolean;
327
+ output?: NodeJS.WritableStream | undefined;
328
+ completer?: Completer | AsyncCompleter | undefined;
329
+ terminal?: boolean | undefined;
144
330
  /**
145
331
  * Initial list of history lines. This option makes sense
146
332
  * only if `terminal` is set to `true` by the user or by an internal `output`
147
333
  * check, otherwise the history caching mechanism is not initialized at all.
148
334
  * @default []
149
335
  */
150
- history?: string[];
151
- historySize?: number;
152
- prompt?: string;
153
- crlfDelay?: number;
336
+ history?: string[] | undefined;
337
+ historySize?: number | undefined;
338
+ prompt?: string | undefined;
339
+ crlfDelay?: number | undefined;
154
340
  /**
155
341
  * If `true`, when a new input line added
156
342
  * to the history list duplicates an older one, this removes the older line
157
343
  * from the list.
158
344
  * @default false
159
345
  */
160
- removeHistoryDuplicates?: boolean;
161
- escapeCodeTimeout?: number;
162
- tabSize?: number;
346
+ removeHistoryDuplicates?: boolean | undefined;
347
+ escapeCodeTimeout?: number | undefined;
348
+ tabSize?: number | undefined;
163
349
  }
164
-
165
- function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean): Interface;
166
- function createInterface(options: ReadLineOptions): Interface;
167
- function emitKeypressEvents(stream: NodeJS.ReadableStream, readlineInterface?: Interface): void;
168
-
169
- type Direction = -1 | 0 | 1;
170
-
171
- interface CursorPos {
350
+ /**
351
+ * The `readline.createInterface()` method creates a new `readline.Interface`instance.
352
+ *
353
+ * ```js
354
+ * const readline = require('readline');
355
+ * const rl = readline.createInterface({
356
+ * input: process.stdin,
357
+ * output: process.stdout
358
+ * });
359
+ * ```
360
+ *
361
+ * Once the `readline.Interface` instance is created, the most common case is to
362
+ * listen for the `'line'` event:
363
+ *
364
+ * ```js
365
+ * rl.on('line', (line) => {
366
+ * console.log(`Received: ${line}`);
367
+ * });
368
+ * ```
369
+ *
370
+ * If `terminal` is `true` for this instance then the `output` stream will get
371
+ * the best compatibility if it defines an `output.columns` property and emits
372
+ * a `'resize'` event on the `output` if or when the columns ever change
373
+ * (`process.stdout` does this automatically when it is a TTY).
374
+ *
375
+ * When creating a `readline.Interface` using `stdin` as input, the program
376
+ * will not terminate until it receives `EOF` (Ctrl+D on
377
+ * Linux/macOS, Ctrl+Z followed by Return on
378
+ * Windows).
379
+ * If you want your application to exit without waiting for user input, you can `unref()` the standard input stream:
380
+ *
381
+ * ```js
382
+ * process.stdin.unref();
383
+ * ```
384
+ * @since v0.1.98
385
+ */
386
+ export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean): Interface;
387
+ export function createInterface(options: ReadLineOptions): Interface;
388
+ /**
389
+ * The `readline.emitKeypressEvents()` method causes the given `Readable` stream to begin emitting `'keypress'` events corresponding to received input.
390
+ *
391
+ * Optionally, `interface` specifies a `readline.Interface` instance for which
392
+ * autocompletion is disabled when copy-pasted input is detected.
393
+ *
394
+ * If the `stream` is a `TTY`, then it must be in raw mode.
395
+ *
396
+ * This is automatically called by any readline instance on its `input` if the`input` is a terminal. Closing the `readline` instance does not stop
397
+ * the `input` from emitting `'keypress'` events.
398
+ *
399
+ * ```js
400
+ * readline.emitKeypressEvents(process.stdin);
401
+ * if (process.stdin.isTTY)
402
+ * process.stdin.setRawMode(true);
403
+ * ```
404
+ *
405
+ * ## Example: Tiny CLI
406
+ *
407
+ * The following example illustrates the use of `readline.Interface` class to
408
+ * implement a small command-line interface:
409
+ *
410
+ * ```js
411
+ * const readline = require('readline');
412
+ * const rl = readline.createInterface({
413
+ * input: process.stdin,
414
+ * output: process.stdout,
415
+ * prompt: 'OHAI> '
416
+ * });
417
+ *
418
+ * rl.prompt();
419
+ *
420
+ * rl.on('line', (line) => {
421
+ * switch (line.trim()) {
422
+ * case 'hello':
423
+ * console.log('world!');
424
+ * break;
425
+ * default:
426
+ * console.log(`Say what? I might have heard '${line.trim()}'`);
427
+ * break;
428
+ * }
429
+ * rl.prompt();
430
+ * }).on('close', () => {
431
+ * console.log('Have a great day!');
432
+ * process.exit(0);
433
+ * });
434
+ * ```
435
+ *
436
+ * ## Example: Read file stream line-by-Line
437
+ *
438
+ * A common use case for `readline` is to consume an input file one line at a
439
+ * time. The easiest way to do so is leveraging the `fs.ReadStream` API as
440
+ * well as a `for await...of` loop:
441
+ *
442
+ * ```js
443
+ * const fs = require('fs');
444
+ * const readline = require('readline');
445
+ *
446
+ * async function processLineByLine() {
447
+ * const fileStream = fs.createReadStream('input.txt');
448
+ *
449
+ * const rl = readline.createInterface({
450
+ * input: fileStream,
451
+ * crlfDelay: Infinity
452
+ * });
453
+ * // Note: we use the crlfDelay option to recognize all instances of CR LF
454
+ * // ('\r\n') in input.txt as a single line break.
455
+ *
456
+ * for await (const line of rl) {
457
+ * // Each line in input.txt will be successively available here as `line`.
458
+ * console.log(`Line from file: ${line}`);
459
+ * }
460
+ * }
461
+ *
462
+ * processLineByLine();
463
+ * ```
464
+ *
465
+ * Alternatively, one could use the `'line'` event:
466
+ *
467
+ * ```js
468
+ * const fs = require('fs');
469
+ * const readline = require('readline');
470
+ *
471
+ * const rl = readline.createInterface({
472
+ * input: fs.createReadStream('sample.txt'),
473
+ * crlfDelay: Infinity
474
+ * });
475
+ *
476
+ * rl.on('line', (line) => {
477
+ * console.log(`Line from file: ${line}`);
478
+ * });
479
+ * ```
480
+ *
481
+ * Currently, `for await...of` loop can be a bit slower. If `async` / `await`flow and speed are both essential, a mixed approach can be applied:
482
+ *
483
+ * ```js
484
+ * const { once } = require('events');
485
+ * const { createReadStream } = require('fs');
486
+ * const { createInterface } = require('readline');
487
+ *
488
+ * (async function processLineByLine() {
489
+ * try {
490
+ * const rl = createInterface({
491
+ * input: createReadStream('big-file.txt'),
492
+ * crlfDelay: Infinity
493
+ * });
494
+ *
495
+ * rl.on('line', (line) => {
496
+ * // Process the line.
497
+ * });
498
+ *
499
+ * await once(rl, 'close');
500
+ *
501
+ * console.log('File processed.');
502
+ * } catch (err) {
503
+ * console.error(err);
504
+ * }
505
+ * })();
506
+ * ```
507
+ * @since v0.7.7
508
+ */
509
+ export function emitKeypressEvents(stream: NodeJS.ReadableStream, readlineInterface?: Interface): void;
510
+ export type Direction = -1 | 0 | 1;
511
+ export interface CursorPos {
172
512
  rows: number;
173
513
  cols: number;
174
514
  }
175
-
176
515
  /**
177
- * Clears the current line of this WriteStream in a direction identified by `dir`.
516
+ * The `readline.clearLine()` method clears current line of given `TTY` stream
517
+ * in a specified direction identified by `dir`.
518
+ * @since v0.7.7
519
+ * @param callback Invoked once the operation completes.
520
+ * @return `false` if `stream` wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
178
521
  */
179
- function clearLine(stream: NodeJS.WritableStream, dir: Direction, callback?: () => void): boolean;
522
+ export function clearLine(stream: NodeJS.WritableStream, dir: Direction, callback?: () => void): boolean;
180
523
  /**
181
- * Clears this `WriteStream` from the current cursor down.
524
+ * The `readline.clearScreenDown()` method clears the given `TTY` stream from
525
+ * the current position of the cursor down.
526
+ * @since v0.7.7
527
+ * @param callback Invoked once the operation completes.
528
+ * @return `false` if `stream` wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
182
529
  */
183
- function clearScreenDown(stream: NodeJS.WritableStream, callback?: () => void): boolean;
530
+ export function clearScreenDown(stream: NodeJS.WritableStream, callback?: () => void): boolean;
184
531
  /**
185
- * Moves this WriteStream's cursor to the specified position.
532
+ * The `readline.cursorTo()` method moves cursor to the specified position in a
533
+ * given `TTY` `stream`.
534
+ * @since v0.7.7
535
+ * @param callback Invoked once the operation completes.
536
+ * @return `false` if `stream` wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
186
537
  */
187
- function cursorTo(stream: NodeJS.WritableStream, x: number, y?: number, callback?: () => void): boolean;
538
+ export function cursorTo(stream: NodeJS.WritableStream, x: number, y?: number, callback?: () => void): boolean;
188
539
  /**
189
- * Moves this WriteStream's cursor relative to its current position.
540
+ * The `readline.moveCursor()` method moves the cursor _relative_ to its current
541
+ * position in a given `TTY` `stream`.
542
+ *
543
+ * ## Example: Tiny CLI
544
+ *
545
+ * The following example illustrates the use of `readline.Interface` class to
546
+ * implement a small command-line interface:
547
+ *
548
+ * ```js
549
+ * const readline = require('readline');
550
+ * const rl = readline.createInterface({
551
+ * input: process.stdin,
552
+ * output: process.stdout,
553
+ * prompt: 'OHAI> '
554
+ * });
555
+ *
556
+ * rl.prompt();
557
+ *
558
+ * rl.on('line', (line) => {
559
+ * switch (line.trim()) {
560
+ * case 'hello':
561
+ * console.log('world!');
562
+ * break;
563
+ * default:
564
+ * console.log(`Say what? I might have heard '${line.trim()}'`);
565
+ * break;
566
+ * }
567
+ * rl.prompt();
568
+ * }).on('close', () => {
569
+ * console.log('Have a great day!');
570
+ * process.exit(0);
571
+ * });
572
+ * ```
573
+ *
574
+ * ## Example: Read file stream line-by-Line
575
+ *
576
+ * A common use case for `readline` is to consume an input file one line at a
577
+ * time. The easiest way to do so is leveraging the `fs.ReadStream` API as
578
+ * well as a `for await...of` loop:
579
+ *
580
+ * ```js
581
+ * const fs = require('fs');
582
+ * const readline = require('readline');
583
+ *
584
+ * async function processLineByLine() {
585
+ * const fileStream = fs.createReadStream('input.txt');
586
+ *
587
+ * const rl = readline.createInterface({
588
+ * input: fileStream,
589
+ * crlfDelay: Infinity
590
+ * });
591
+ * // Note: we use the crlfDelay option to recognize all instances of CR LF
592
+ * // ('\r\n') in input.txt as a single line break.
593
+ *
594
+ * for await (const line of rl) {
595
+ * // Each line in input.txt will be successively available here as `line`.
596
+ * console.log(`Line from file: ${line}`);
597
+ * }
598
+ * }
599
+ *
600
+ * processLineByLine();
601
+ * ```
602
+ *
603
+ * Alternatively, one could use the `'line'` event:
604
+ *
605
+ * ```js
606
+ * const fs = require('fs');
607
+ * const readline = require('readline');
608
+ *
609
+ * const rl = readline.createInterface({
610
+ * input: fs.createReadStream('sample.txt'),
611
+ * crlfDelay: Infinity
612
+ * });
613
+ *
614
+ * rl.on('line', (line) => {
615
+ * console.log(`Line from file: ${line}`);
616
+ * });
617
+ * ```
618
+ *
619
+ * Currently, `for await...of` loop can be a bit slower. If `async` / `await`flow and speed are both essential, a mixed approach can be applied:
620
+ *
621
+ * ```js
622
+ * const { once } = require('events');
623
+ * const { createReadStream } = require('fs');
624
+ * const { createInterface } = require('readline');
625
+ *
626
+ * (async function processLineByLine() {
627
+ * try {
628
+ * const rl = createInterface({
629
+ * input: createReadStream('big-file.txt'),
630
+ * crlfDelay: Infinity
631
+ * });
632
+ *
633
+ * rl.on('line', (line) => {
634
+ * // Process the line.
635
+ * });
636
+ *
637
+ * await once(rl, 'close');
638
+ *
639
+ * console.log('File processed.');
640
+ * } catch (err) {
641
+ * console.error(err);
642
+ * }
643
+ * })();
644
+ * ```
645
+ * @since v0.7.7
646
+ * @param callback Invoked once the operation completes.
647
+ * @return `false` if `stream` wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
190
648
  */
191
- function moveCursor(stream: NodeJS.WritableStream, dx: number, dy: number, callback?: () => void): boolean;
649
+ export function moveCursor(stream: NodeJS.WritableStream, dx: number, dy: number, callback?: () => void): boolean;
650
+ }
651
+ declare module 'node:readline' {
652
+ export * from 'readline';
192
653
  }