visaljs 0.0.9 → 0.0.11

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 (232) hide show
  1. package/README.md +12 -4
  2. package/THIRD_PARTY_LICENSES +31 -1
  3. package/cli.js +3745 -890
  4. package/node/include/js_node.h +12 -1
  5. package/node/prelude/_http_common.js +29 -0
  6. package/node/prelude/async_hooks.js +50 -11
  7. package/node/prelude/child_process.js +31 -4
  8. package/node/prelude/console.js +311 -143
  9. package/node/prelude/crypto.js +6 -4
  10. package/node/prelude/dgram.js +1169 -0
  11. package/node/prelude/diagnostics_channel.js +3 -1
  12. package/node/prelude/dns.js +250 -45
  13. package/node/prelude/dns_promises.js +8 -2
  14. package/node/prelude/fs_promises.js +9 -1
  15. package/node/prelude/http.js +405 -94
  16. package/node/prelude/https.js +13 -4
  17. package/node/prelude/internal/console_class.js +7 -0
  18. package/node/prelude/internal/console_global.js +25 -0
  19. package/node/prelude/internal/crypto/key_encryption.js +217 -0
  20. package/node/prelude/internal/crypto/keys.js +161 -26
  21. package/node/prelude/internal/crypto/random.js +24 -0
  22. package/node/prelude/internal/crypto/util.js +2 -1
  23. package/node/prelude/internal/crypto_x509.js +161 -0
  24. package/node/prelude/internal/dns_classes.js +6 -0
  25. package/node/prelude/internal/dns_resolver.js +371 -0
  26. package/node/prelude/internal/errors.js +9 -0
  27. package/node/prelude/internal/events_on.js +82 -37
  28. package/node/prelude/internal/features.js +8 -4
  29. package/node/prelude/internal/fs_filehandle.js +10 -4
  30. package/node/prelude/internal/http_chars.ts +22 -0
  31. package/node/prelude/internal/perf_histogram.js +1 -1
  32. package/node/prelude/internal/process_more.js +32 -17
  33. package/node/prelude/internal/process_signals.js +8 -2
  34. package/node/prelude/internal/punycode.ts +163 -0
  35. package/node/prelude/internal/readline.js +648 -274
  36. package/node/prelude/internal/readline_editor.js +1240 -0
  37. package/node/prelude/internal/string_width.js +43 -0
  38. package/node/prelude/internal/tls/common.js +145 -33
  39. package/node/prelude/internal/tls/wrap.js +182 -49
  40. package/node/prelude/internal/tls/x509.js +4 -1
  41. package/node/prelude/internal/udp.js +177 -0
  42. package/node/prelude/net.js +30 -14
  43. package/node/prelude/os.js +24 -6
  44. package/node/prelude/perf_hooks.js +37 -2
  45. package/node/prelude/punycode.js +2 -130
  46. package/node/prelude/readline.js +113 -4
  47. package/node/prelude/readline_promises.js +56 -32
  48. package/node/prelude/tls.js +21 -4
  49. package/node/prelude/util.js +3 -16
  50. package/node/src/host_dns.c +623 -0
  51. package/node/src/host_http.c +12 -0
  52. package/node/src/host_net.c +46 -0
  53. package/node/src/host_os.c +1 -6
  54. package/node/src/host_sys.c +79 -0
  55. package/node/src/host_udp.c +418 -0
  56. package/node/third_party/c-ares/LICENSE.md +24 -0
  57. package/node/third_party/c-ares/config/darwin/ares_config.h +573 -0
  58. package/node/third_party/c-ares/config/freebsd/ares_config.h +573 -0
  59. package/node/third_party/c-ares/config/linux/ares_config.h +573 -0
  60. package/node/third_party/c-ares/config/openbsd/ares_config.h +583 -0
  61. package/node/third_party/c-ares/include/ares.h +1237 -0
  62. package/node/third_party/c-ares/include/ares_build.h +202 -0
  63. package/node/third_party/c-ares/include/ares_dns.h +127 -0
  64. package/node/third_party/c-ares/include/ares_dns_record.h +1119 -0
  65. package/node/third_party/c-ares/include/ares_nameser.h +510 -0
  66. package/node/third_party/c-ares/include/ares_version.h +47 -0
  67. package/node/third_party/c-ares/src/lib/ares_addrinfo2hostent.c +305 -0
  68. package/node/third_party/c-ares/src/lib/ares_addrinfo_localhost.c +245 -0
  69. package/node/third_party/c-ares/src/lib/ares_android.c +496 -0
  70. package/node/third_party/c-ares/src/lib/ares_android.h +38 -0
  71. package/node/third_party/c-ares/src/lib/ares_cancel.c +87 -0
  72. package/node/third_party/c-ares/src/lib/ares_close_sockets.c +137 -0
  73. package/node/third_party/c-ares/src/lib/ares_conn.c +511 -0
  74. package/node/third_party/c-ares/src/lib/ares_conn.h +202 -0
  75. package/node/third_party/c-ares/src/lib/ares_cookie.c +461 -0
  76. package/node/third_party/c-ares/src/lib/ares_data.c +168 -0
  77. package/node/third_party/c-ares/src/lib/ares_data.h +92 -0
  78. package/node/third_party/c-ares/src/lib/ares_destroy.c +159 -0
  79. package/node/third_party/c-ares/src/lib/ares_free_hostent.c +54 -0
  80. package/node/third_party/c-ares/src/lib/ares_free_string.c +33 -0
  81. package/node/third_party/c-ares/src/lib/ares_freeaddrinfo.c +67 -0
  82. package/node/third_party/c-ares/src/lib/ares_getaddrinfo.c +806 -0
  83. package/node/third_party/c-ares/src/lib/ares_getenv.c +38 -0
  84. package/node/third_party/c-ares/src/lib/ares_getenv.h +34 -0
  85. package/node/third_party/c-ares/src/lib/ares_gethostbyaddr.c +229 -0
  86. package/node/third_party/c-ares/src/lib/ares_gethostbyname.c +341 -0
  87. package/node/third_party/c-ares/src/lib/ares_getnameinfo.c +437 -0
  88. package/node/third_party/c-ares/src/lib/ares_hosts_file.c +960 -0
  89. package/node/third_party/c-ares/src/lib/ares_inet_net_pton.h +31 -0
  90. package/node/third_party/c-ares/src/lib/ares_init.c +631 -0
  91. package/node/third_party/c-ares/src/lib/ares_ipv6.h +115 -0
  92. package/node/third_party/c-ares/src/lib/ares_library_init.c +190 -0
  93. package/node/third_party/c-ares/src/lib/ares_metrics.c +261 -0
  94. package/node/third_party/c-ares/src/lib/ares_options.c +492 -0
  95. package/node/third_party/c-ares/src/lib/ares_parse_into_addrinfo.c +179 -0
  96. package/node/third_party/c-ares/src/lib/ares_private.h +648 -0
  97. package/node/third_party/c-ares/src/lib/ares_process.c +1649 -0
  98. package/node/third_party/c-ares/src/lib/ares_qcache.c +442 -0
  99. package/node/third_party/c-ares/src/lib/ares_query.c +151 -0
  100. package/node/third_party/c-ares/src/lib/ares_search.c +623 -0
  101. package/node/third_party/c-ares/src/lib/ares_send.c +300 -0
  102. package/node/third_party/c-ares/src/lib/ares_set_socket_functions.c +590 -0
  103. package/node/third_party/c-ares/src/lib/ares_setup.h +224 -0
  104. package/node/third_party/c-ares/src/lib/ares_socket.c +427 -0
  105. package/node/third_party/c-ares/src/lib/ares_socket.h +163 -0
  106. package/node/third_party/c-ares/src/lib/ares_sortaddrinfo.c +447 -0
  107. package/node/third_party/c-ares/src/lib/ares_strerror.c +91 -0
  108. package/node/third_party/c-ares/src/lib/ares_sysconfig.c +642 -0
  109. package/node/third_party/c-ares/src/lib/ares_sysconfig_files.c +851 -0
  110. package/node/third_party/c-ares/src/lib/ares_sysconfig_mac.c +373 -0
  111. package/node/third_party/c-ares/src/lib/ares_sysconfig_win.c +673 -0
  112. package/node/third_party/c-ares/src/lib/ares_timeout.c +162 -0
  113. package/node/third_party/c-ares/src/lib/ares_update_servers.c +1376 -0
  114. package/node/third_party/c-ares/src/lib/ares_version.c +36 -0
  115. package/node/third_party/c-ares/src/lib/config-dos.h +114 -0
  116. package/node/third_party/c-ares/src/lib/config-win32.h +396 -0
  117. package/node/third_party/c-ares/src/lib/dsa/ares_array.c +409 -0
  118. package/node/third_party/c-ares/src/lib/dsa/ares_htable.c +451 -0
  119. package/node/third_party/c-ares/src/lib/dsa/ares_htable.h +174 -0
  120. package/node/third_party/c-ares/src/lib/dsa/ares_htable_asvp.c +224 -0
  121. package/node/third_party/c-ares/src/lib/dsa/ares_htable_dict.c +230 -0
  122. package/node/third_party/c-ares/src/lib/dsa/ares_htable_strvp.c +210 -0
  123. package/node/third_party/c-ares/src/lib/dsa/ares_htable_szvp.c +188 -0
  124. package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpstr.c +186 -0
  125. package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpvp.c +194 -0
  126. package/node/third_party/c-ares/src/lib/dsa/ares_llist.c +385 -0
  127. package/node/third_party/c-ares/src/lib/dsa/ares_slist.c +479 -0
  128. package/node/third_party/c-ares/src/lib/dsa/ares_slist.h +207 -0
  129. package/node/third_party/c-ares/src/lib/event/ares_event.h +191 -0
  130. package/node/third_party/c-ares/src/lib/event/ares_event_configchg.c +746 -0
  131. package/node/third_party/c-ares/src/lib/event/ares_event_epoll.c +192 -0
  132. package/node/third_party/c-ares/src/lib/event/ares_event_kqueue.c +248 -0
  133. package/node/third_party/c-ares/src/lib/event/ares_event_poll.c +140 -0
  134. package/node/third_party/c-ares/src/lib/event/ares_event_select.c +159 -0
  135. package/node/third_party/c-ares/src/lib/event/ares_event_thread.c +575 -0
  136. package/node/third_party/c-ares/src/lib/event/ares_event_wake_pipe.c +172 -0
  137. package/node/third_party/c-ares/src/lib/event/ares_event_win32.c +981 -0
  138. package/node/third_party/c-ares/src/lib/event/ares_event_win32.h +161 -0
  139. package/node/third_party/c-ares/src/lib/include/ares_array.h +276 -0
  140. package/node/third_party/c-ares/src/lib/include/ares_buf.h +732 -0
  141. package/node/third_party/c-ares/src/lib/include/ares_htable_asvp.h +130 -0
  142. package/node/third_party/c-ares/src/lib/include/ares_htable_dict.h +123 -0
  143. package/node/third_party/c-ares/src/lib/include/ares_htable_strvp.h +130 -0
  144. package/node/third_party/c-ares/src/lib/include/ares_htable_szvp.h +118 -0
  145. package/node/third_party/c-ares/src/lib/include/ares_htable_vpstr.h +111 -0
  146. package/node/third_party/c-ares/src/lib/include/ares_htable_vpvp.h +128 -0
  147. package/node/third_party/c-ares/src/lib/include/ares_llist.h +239 -0
  148. package/node/third_party/c-ares/src/lib/include/ares_mem.h +41 -0
  149. package/node/third_party/c-ares/src/lib/include/ares_str.h +261 -0
  150. package/node/third_party/c-ares/src/lib/inet_net_pton.c +451 -0
  151. package/node/third_party/c-ares/src/lib/inet_ntop.c +219 -0
  152. package/node/third_party/c-ares/src/lib/legacy/ares_create_query.c +78 -0
  153. package/node/third_party/c-ares/src/lib/legacy/ares_expand_name.c +99 -0
  154. package/node/third_party/c-ares/src/lib/legacy/ares_expand_string.c +107 -0
  155. package/node/third_party/c-ares/src/lib/legacy/ares_fds.c +80 -0
  156. package/node/third_party/c-ares/src/lib/legacy/ares_getsock.c +85 -0
  157. package/node/third_party/c-ares/src/lib/legacy/ares_parse_a_reply.c +107 -0
  158. package/node/third_party/c-ares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
  159. package/node/third_party/c-ares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
  160. package/node/third_party/c-ares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
  161. package/node/third_party/c-ares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
  162. package/node/third_party/c-ares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
  163. package/node/third_party/c-ares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
  164. package/node/third_party/c-ares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
  165. package/node/third_party/c-ares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
  166. package/node/third_party/c-ares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
  167. package/node/third_party/c-ares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
  168. package/node/third_party/c-ares/src/lib/record/ares_dns_mapping.c +982 -0
  169. package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.c +309 -0
  170. package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.h +72 -0
  171. package/node/third_party/c-ares/src/lib/record/ares_dns_name.c +736 -0
  172. package/node/third_party/c-ares/src/lib/record/ares_dns_parse.c +1360 -0
  173. package/node/third_party/c-ares/src/lib/record/ares_dns_private.h +273 -0
  174. package/node/third_party/c-ares/src/lib/record/ares_dns_record.c +1701 -0
  175. package/node/third_party/c-ares/src/lib/record/ares_dns_write.c +1229 -0
  176. package/node/third_party/c-ares/src/lib/str/ares_buf.c +1510 -0
  177. package/node/third_party/c-ares/src/lib/str/ares_str.c +562 -0
  178. package/node/third_party/c-ares/src/lib/str/ares_strsplit.c +90 -0
  179. package/node/third_party/c-ares/src/lib/str/ares_strsplit.h +51 -0
  180. package/node/third_party/c-ares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
  181. package/node/third_party/c-ares/src/lib/util/ares_iface_ips.c +640 -0
  182. package/node/third_party/c-ares/src/lib/util/ares_iface_ips.h +140 -0
  183. package/node/third_party/c-ares/src/lib/util/ares_math.c +167 -0
  184. package/node/third_party/c-ares/src/lib/util/ares_math.h +58 -0
  185. package/node/third_party/c-ares/src/lib/util/ares_rand.c +389 -0
  186. package/node/third_party/c-ares/src/lib/util/ares_rand.h +36 -0
  187. package/node/third_party/c-ares/src/lib/util/ares_threads.c +613 -0
  188. package/node/third_party/c-ares/src/lib/util/ares_threads.h +60 -0
  189. package/node/third_party/c-ares/src/lib/util/ares_time.h +49 -0
  190. package/node/third_party/c-ares/src/lib/util/ares_timeval.c +95 -0
  191. package/node/third_party/c-ares/src/lib/util/ares_uri.c +1627 -0
  192. package/node/third_party/c-ares/src/lib/util/ares_uri.h +252 -0
  193. package/node/third_party/c-ares/src/lib/windows_port.c +29 -0
  194. package/package.json +1 -1
  195. package/prebuilt/darwin-arm64/cares-a6286c65ca9374a3.a +0 -0
  196. package/prebuilt/darwin-x64/cares-a6286c65ca9374a3.a +0 -0
  197. package/prebuilt/linux-arm64/cares-4ba05ac8e948af8e.a +0 -0
  198. package/prebuilt/linux-arm64-musl/cares-4ba05ac8e948af8e.a +0 -0
  199. package/prebuilt/linux-x64/cares-4ba05ac8e948af8e.a +0 -0
  200. package/prebuilt/linux-x64-musl/cares-4ba05ac8e948af8e.a +0 -0
  201. package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
  202. package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
  203. package/prebuilt/win32-x64/cares-49c9ec95162b912d.a +0 -0
  204. package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
  205. package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
  206. package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
  207. package/runtime/include/js_buffer.h +185 -0
  208. package/runtime/include/js_builtins.h +58 -0
  209. package/runtime/include/js_crypto.h +11 -0
  210. package/runtime/include/js_exception.h +3 -0
  211. package/runtime/include/js_function.h +1 -1
  212. package/runtime/include/js_gc.h +13 -10
  213. package/runtime/include/js_jobs.h +2 -0
  214. package/runtime/include/js_object.h +79 -3
  215. package/runtime/include/js_ops.h +27 -0
  216. package/runtime/include/js_runtime.h +1 -0
  217. package/runtime/include/js_web.h +0 -3
  218. package/runtime/include/jscontext.h +8 -0
  219. package/runtime/src/builtins.c +17 -4
  220. package/runtime/src/crypto_internal.h +1 -0
  221. package/runtime/src/crypto_subtle.c +66 -7
  222. package/runtime/src/crypto_tls.c +265 -19
  223. package/runtime/src/function.c +37 -10
  224. package/runtime/src/gc.c +76 -93
  225. package/runtime/src/inspect.c +18 -1
  226. package/runtime/src/iterator.c +5 -1
  227. package/runtime/src/jobs.c +37 -22
  228. package/runtime/src/object.c +91 -8
  229. package/runtime/src/os.c +16 -6
  230. package/runtime/src/os.h +2 -0
  231. package/runtime/src/process.c +97 -10
  232. package/runtime/src/typedarray.c +23 -0
@@ -1,8 +1,117 @@
1
- // node:readline (internal/readline.js): Interface, createInterface, the cursor's escapes, and
2
- // node:readline/promises as promises.
1
+ // node:readline (Node's lib/readline.js): Interface, with the callback question() and the old
2
+ // underscored names of its methods, createInterface, the cursor functions, emitKeypressEvents
3
+ // (with the terminal editor, internal/readline_editor.js), and readline/promises as promises.
4
+ // Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
5
+ import { features, lazyFunction } from "./internal/features.js";
6
+ import {
7
+ abortError, addAbortListener, clearLine, clearScreenDown, cursorTo, Interface as BaseInterface, InterfaceConstructor, kAddHistory,
8
+ kDecoder, kDeleteLeft, kDeleteLineLeft, kDeleteLineRight, kDeleteRight, kDeleteWordLeft, kDeleteWordRight, kGetDisplayPos, kHistoryNext,
9
+ kHistoryPrev, kInsertString, kLine, kLine_buffer, kMoveCursor, kNormalWrite, kOldPrompt, kOnLine, kPreviousKey, kPrompt, kQuestion,
10
+ kQuestionCallback, kQuestionCancel, kRefreshLine, kSawKeyPress, kSawReturnAt, kSetRawMode, kTabComplete, kTtyWrite, kWordLeft,
11
+ kWordRight, kWriteToOutput, moveCursor, validateAbortSignal,
12
+ } from "./internal/readline.js";
3
13
  import promises from "./readline_promises.js";
4
- import { Interface, clearLine, clearScreenDown, createInterface, cursorTo, emitKeypressEvents, moveCursor } from "./internal/readline.js";
5
14
 
6
- export { Interface, clearLine, clearScreenDown, createInterface, cursorTo, emitKeypressEvents, moveCursor, promises };
15
+ const kEmptyObject = Object.freeze({ __proto__: null });
16
+ const kPromisifyCustom = Symbol.for("nodejs.util.promisify.custom");
17
+
18
+ export const emitKeypressEvents = lazyFunction("emitKeypressEvents", 2);
19
+
20
+ /** Interface(input, output, completer, terminal), or with an options object; callable without new */
21
+ export function Interface(input, output, completer, terminal) {
22
+ if (!(this instanceof Interface)) return new Interface(input, output, completer, terminal);
23
+ /* a completer of one argument: its result, given to the callback */
24
+ if (input?.input && typeof input.completer === "function" && input.completer.length !== 2) {
25
+ const { completer } = input;
26
+ input.completer = (v, cb) => cb(null, completer(v));
27
+ } else if (typeof completer === "function" && completer.length !== 2) {
28
+ const realCompleter = completer;
29
+ completer = (v, cb) => cb(null, realCompleter(v));
30
+ }
31
+ InterfaceConstructor.call(this, input, output, completer, terminal);
32
+ /* a terminal is the editor's (internal/readline_editor.js): a dumb one gets its plain writer */
33
+ if (this.terminal && process.env.TERM === "dumb") this._ttyWrite = features.ttyWriteDumb.bind(this);
34
+ }
35
+
36
+ Object.setPrototypeOf(Interface.prototype, BaseInterface.prototype);
37
+ Object.setPrototypeOf(Interface, BaseInterface);
38
+
39
+ Interface.prototype.question = function question(query, options, cb) {
40
+ cb = typeof options === "function" ? options : cb;
41
+ if (options === null || typeof options !== "object") options = kEmptyObject;
42
+ if (options.signal) {
43
+ validateAbortSignal(options.signal, "options.signal");
44
+ if (options.signal.aborted) return;
45
+ const onAbort = () => {
46
+ this[kQuestionCancel]();
47
+ };
48
+ const disposable = addAbortListener(options.signal, onAbort);
49
+ const originalCb = cb;
50
+ cb = typeof cb === "function" ? (answer) => {
51
+ disposable[Symbol.dispose]();
52
+ return originalCb(answer);
53
+ } : disposable[Symbol.dispose];
54
+ }
55
+ if (typeof cb === "function") this[kQuestion](query, cb);
56
+ };
57
+
58
+ Interface.prototype.question[kPromisifyCustom] = function question(query, options) {
59
+ if (options === null || typeof options !== "object") options = kEmptyObject;
60
+ if (options.signal?.aborted) return Promise.reject(abortError(undefined, { cause: options.signal.reason }));
61
+ return new Promise((resolve, reject) => {
62
+ let cb = resolve;
63
+ if (options.signal) {
64
+ const onAbort = () => {
65
+ reject(abortError(undefined, { cause: options.signal.reason }));
66
+ };
67
+ const disposable = addAbortListener(options.signal, onAbort);
68
+ cb = (answer) => {
69
+ disposable[Symbol.dispose]();
70
+ resolve(answer);
71
+ };
72
+ }
73
+ this.question(query, options, cb);
74
+ });
75
+ };
76
+
77
+ export function createInterface(input, output, completer, terminal) {
78
+ return new Interface(input, output, completer, terminal);
79
+ }
80
+
81
+ /* the methods' old names: each symbol reads the underscored method, which a program may replace */
82
+ const underscored = [
83
+ [kSetRawMode, "_setRawMode"], [kOnLine, "_onLine"], [kWriteToOutput, "_writeToOutput"], [kAddHistory, "_addHistory"],
84
+ [kRefreshLine, "_refreshLine"], [kNormalWrite, "_normalWrite"], [kInsertString, "_insertString"], [kTabComplete, "_tabComplete"],
85
+ [kWordLeft, "_wordLeft"], [kWordRight, "_wordRight"], [kDeleteLeft, "_deleteLeft"], [kDeleteRight, "_deleteRight"],
86
+ [kDeleteWordLeft, "_deleteWordLeft"], [kDeleteWordRight, "_deleteWordRight"], [kDeleteLineLeft, "_deleteLineLeft"],
87
+ [kDeleteLineRight, "_deleteLineRight"], [kLine, "_line"], [kHistoryNext, "_historyNext"], [kHistoryPrev, "_historyPrev"],
88
+ [kGetDisplayPos, "_getDisplayPos"], [kMoveCursor, "_moveCursor"], [kTtyWrite, "_ttyWrite"],
89
+ ];
90
+ for (const [symbol, name] of underscored) {
91
+ Object.defineProperty(Interface.prototype, symbol, { get() { return this[name]; }, configurable: true });
92
+ }
93
+ /* and the state's */
94
+ const state = [[kDecoder, "_decoder"], [kLine_buffer, "_line_buffer"], [kOldPrompt, "_oldPrompt"], [kPreviousKey, "_previousKey"],
95
+ [kPrompt, "_prompt"], [kQuestionCallback, "_questionCallback"], [kSawKeyPress, "_sawKeyPress"], [kSawReturnAt, "_sawReturnAt"]];
96
+ for (const [symbol, name] of state) {
97
+ Object.defineProperty(Interface.prototype, name, {
98
+ get() { return this[symbol]; },
99
+ set(value) { this[symbol] = value; },
100
+ configurable: true,
101
+ });
102
+ }
103
+
104
+ /* the editor's methods (the editor module gives the rest of the underscored names) */
105
+ Interface.prototype._setRawMode = BaseInterface.prototype[kSetRawMode];
106
+ Interface.prototype._onLine = BaseInterface.prototype[kOnLine];
107
+ Interface.prototype._writeToOutput = BaseInterface.prototype[kWriteToOutput];
108
+ Interface.prototype._addHistory = BaseInterface.prototype[kAddHistory];
109
+ Interface.prototype._refreshLine = BaseInterface.prototype[kRefreshLine];
110
+ Interface.prototype._normalWrite = BaseInterface.prototype[kNormalWrite];
111
+ Interface.prototype._getDisplayPos = BaseInterface.prototype[kGetDisplayPos];
112
+ Interface.prototype._getCursorPos = BaseInterface.prototype.getCursorPos;
113
+ Interface.prototype._moveCursor = BaseInterface.prototype[kMoveCursor];
114
+
115
+ export { clearLine, clearScreenDown, cursorTo, moveCursor, promises };
7
116
 
8
117
  export default { Interface, clearLine, clearScreenDown, createInterface, cursorTo, emitKeypressEvents, moveCursor, promises };
@@ -1,31 +1,31 @@
1
- // node:readline/promises: node:readline's Interface with question() as a promise, and Readline,
2
- // cursor moves queued and written by commit().
3
- import { codeError } from "./internal/errors.js";
1
+ // node:readline/promises (Node's lib/readline/promises.js and internal/readline/promises.js):
2
+ // Interface with question() as a promise, and Readline, cursor moves queued and written by commit().
3
+ // Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
4
+ import { invalidArgType, outOfRange } from "./internal/errors.js";
4
5
  import {
5
- Interface as BaseInterface, abortError, clearLineEscape, cursorToEscape, kQuestion, kQuestionCancel, moveCursorEscape,
6
+ abortError, addAbortListener, CSI, Interface as BaseInterface, kQuestion, kQuestionCancel, kQuestionReject, validateAbortSignal,
6
7
  } from "./internal/readline.js";
7
8
 
9
+ const kEmptyObject = Object.freeze({ __proto__: null });
10
+
8
11
  export class Interface extends BaseInterface {
9
- /** The next line, or an AbortError when the signal aborts first. */
10
- question(query, options = {}) {
12
+ question(query, options = kEmptyObject) {
11
13
  return new Promise((resolve, reject) => {
12
14
  let cb = resolve;
13
- const signal = options?.signal;
14
- if (signal) {
15
- if (signal === null || typeof signal !== "object" || !("aborted" in signal)) {
16
- throw codeError(TypeError, "ERR_INVALID_ARG_TYPE", 'The "options.signal" property must be an instance of AbortSignal.');
17
- }
18
- if (signal.aborted) return reject(abortError(signal));
15
+ if (options?.signal) {
16
+ validateAbortSignal(options.signal, "options.signal");
17
+ if (options.signal.aborted) return reject(abortError(undefined, { cause: options.signal.reason }));
19
18
  const onAbort = () => {
20
19
  this[kQuestionCancel]();
21
- reject(abortError(signal));
20
+ reject(abortError(undefined, { cause: options.signal.reason }));
22
21
  };
23
- signal.addEventListener("abort", onAbort, { once: true });
22
+ const disposable = addAbortListener(options.signal, onAbort);
24
23
  cb = (answer) => {
25
- signal.removeEventListener("abort", onAbort);
24
+ disposable[Symbol.dispose]();
26
25
  resolve(answer);
27
26
  };
28
27
  }
28
+ this[kQuestionReject] = reject;
29
29
  this[kQuestion](query, cb);
30
30
  });
31
31
  }
@@ -35,48 +35,72 @@ export function createInterface(input, output, completer, terminal) {
35
35
  return new Interface(input, output, completer, terminal);
36
36
  }
37
37
 
38
- /** Cursor moves on a stream, queued until commit() (or written at once with autoCommit). */
38
+ function validateInteger(value, name, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
39
+ if (typeof value !== "number") throw invalidArgType(name, "of type number", value);
40
+ if (!Number.isInteger(value)) throw outOfRange(name, "an integer", value);
41
+ if (value < min || value > max) throw outOfRange(name, `>= ${min} && <= ${max}`, value);
42
+ }
43
+
44
+ /* Node's isWritable: a stream that can still be written */
45
+ const isWritable = (stream) => stream !== null && typeof stream === "object" && typeof stream.write === "function" &&
46
+ stream.writable !== false && !stream.writableEnded && !stream.destroyed;
47
+
39
48
  export class Readline {
49
+ #autoCommit = false;
40
50
  #stream;
41
51
  #todo = [];
42
- #autoCommit;
43
52
 
44
53
  constructor(stream, options = undefined) {
45
- if (stream === null || typeof stream !== "object" || typeof stream.write !== "function") {
46
- throw codeError(TypeError, "ERR_INVALID_ARG_TYPE", 'The "stream" argument must be an instance of Writable.');
47
- }
54
+ if (!isWritable(stream)) throw invalidArgType("stream", "an instance of Writable", stream);
48
55
  this.#stream = stream;
49
- this.#autoCommit = Boolean(options?.autoCommit);
56
+ if (options?.autoCommit != null) {
57
+ if (typeof options.autoCommit !== "boolean") throw invalidArgType("options.autoCommit", "of type boolean", options.autoCommit);
58
+ this.#autoCommit = options.autoCommit;
59
+ }
50
60
  }
51
61
 
52
- #add(data) {
62
+ #queue(data) {
53
63
  if (this.#autoCommit) process.nextTick(() => this.#stream.write(data));
54
64
  else this.#todo.push(data);
55
- return this;
56
65
  }
57
66
 
58
67
  cursorTo(x, y = undefined) {
59
- return this.#add(cursorToEscape(x, y));
68
+ validateInteger(x, "x");
69
+ if (y != null) validateInteger(y, "y");
70
+ this.#queue(y == null ? CSI`${x + 1}G` : CSI`${y + 1};${x + 1}H`);
71
+ return this;
60
72
  }
61
73
 
62
74
  moveCursor(dx, dy) {
63
- if (!dx && !dy) return this;
64
- return this.#add(moveCursorEscape(dx, dy));
75
+ if (dx || dy) {
76
+ validateInteger(dx, "dx");
77
+ validateInteger(dy, "dy");
78
+ let data = "";
79
+ if (dx < 0) data += CSI`${-dx}D`;
80
+ else if (dx > 0) data += CSI`${dx}C`;
81
+ if (dy < 0) data += CSI`${-dy}A`;
82
+ else if (dy > 0) data += CSI`${dy}B`;
83
+ this.#queue(data);
84
+ }
85
+ return this;
65
86
  }
66
87
 
67
88
  clearLine(dir) {
68
- return this.#add(clearLineEscape(dir));
89
+ validateInteger(dir, "dir", -1, 1);
90
+ this.#queue(dir < 0 ? CSI.kClearToLineBeginning : dir > 0 ? CSI.kClearToLineEnd : CSI.kClearLine);
91
+ return this;
69
92
  }
70
93
 
71
94
  clearScreenDown() {
72
- return this.#add("\x1b[0J");
95
+ this.#queue(CSI.kClearScreenDown);
96
+ return this;
73
97
  }
74
98
 
75
- /** Writes what's queued: resolved once written. */
76
99
  commit() {
77
- const data = this.#todo.join("");
78
- this.#todo = [];
79
- return new Promise((resolve) => this.#stream.write(data, resolve));
100
+ return new Promise((resolve) => {
101
+ this.#stream.write(this.#todo.join(""), resolve);
102
+ this.#todo = [];
103
+ });
80
104
  }
81
105
 
82
106
  rollback() {
@@ -5,10 +5,10 @@
5
5
  // Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
6
6
  import { fsReadFile, tlsRootCertificates } from "visaljs:host";
7
7
  import { EventEmitter } from "./events.js";
8
- import { invalidArgType, invalidArgValue, validateString } from "./internal/errors.js";
8
+ import { codeError, invalidArgType, invalidArgValue, validateString } from "./internal/errors.js";
9
9
  import { cipherNames, createSecureContext, defaults, extraCAs, SecureContext } from "./internal/tls/common.js";
10
10
  import { checkServerIdentity, connect, convertALPNProtocols, createServer, Server, TLSSocket } from "./internal/tls/wrap.js";
11
- import { toPem } from "./internal/tls/x509.js";
11
+ import { certificatesOf, parseCertificate, toPem } from "./internal/tls/x509.js";
12
12
  import { Duplex } from "./stream.js";
13
13
 
14
14
  export { checkServerIdentity, connect, convertALPNProtocols, createSecureContext, createServer, SecureContext, Server, TLSSocket };
@@ -18,6 +18,10 @@ export const CLIENT_RENEG_WINDOW = 600;
18
18
 
19
19
  export const getCiphers = () => cipherNames();
20
20
 
21
+ /* RFC 8879's: none (BoringSSL takes the algorithms from its user, and visaljs gives it none) */
22
+ const compressionAlgorithms = [];
23
+ export const getCertificateCompressionAlgorithms = () => compressionAlgorithms;
24
+
21
25
  let bundled;
22
26
  const bundledRoots = () => (bundled ??= Object.freeze(tlsRootCertificates()));
23
27
 
@@ -66,7 +70,20 @@ export function setDefaultCACertificates(certs) {
66
70
  throw invalidArgType(`certs[${i}]`, "of type string or an instance of ArrayBufferView", certs[i]);
67
71
  }
68
72
  }
69
- defaults.defaultCA = certs.map((c) => (typeof c === "string" ? c : Buffer.from(c.buffer, c.byteOffset, c.byteLength).toString("latin1")));
73
+ /* as Node's store: each certificate once, re-encoded; one OpenSSL can't read, or none of those given, changes nothing */
74
+ const ders = new Map();
75
+ for (const cert of certs) {
76
+ for (const der of certificatesOf(cert)) {
77
+ try {
78
+ parseCertificate(der);
79
+ } catch {
80
+ throw codeError(Error, "ERR_OSSL_PEM_ASN1_LIB", "error:0480000D:PEM routines::ASN1 lib");
81
+ }
82
+ ders.set(der.toString("latin1"), der);
83
+ }
84
+ }
85
+ if (certs.length > 0 && ders.size === 0) throw codeError(Error, "ERR_CRYPTO_OPERATION_FAILED", "No valid certificates found in the provided array");
86
+ defaults.defaultCA = [...ders.values()].map((der) => toPem(der));
70
87
  defaultPems = undefined;
71
88
  }
72
89
 
@@ -127,7 +144,7 @@ const tls = {
127
144
  set DEFAULT_MIN_VERSION(v) { defaults.DEFAULT_MIN_VERSION = v; },
128
145
  get DEFAULT_MAX_VERSION() { return defaults.DEFAULT_MAX_VERSION; },
129
146
  set DEFAULT_MAX_VERSION(v) { defaults.DEFAULT_MAX_VERSION = v; },
130
- getCiphers,
147
+ getCiphers, getCertificateCompressionAlgorithms,
131
148
  get rootCertificates() { return bundledRoots(); },
132
149
  getCACertificates, setDefaultCACertificates, convertALPNProtocols, checkServerIdentity, createSecureContext, SecureContext,
133
150
  TLSSocket, Server, createServer, connect, createSecurePair,
@@ -6,8 +6,9 @@
6
6
  // TextDecoder, the globals (the runtime's encoding component).
7
7
  import { utilFormat, utilFormatWithOptions, utilInspect } from "visaljs:host";
8
8
  import { isDeepStrictEqual } from "./internal/comparisons.js";
9
- import { validateFunction, validateString } from "./internal/errors.js";
9
+ import { validateFunction } from "./internal/errors.js";
10
10
  import { lazyClass, lazyFunction } from "./internal/features.js";
11
+ import { stripVTControlCharacters } from "./internal/string_width.js";
11
12
  import types, { isPromise } from "./util_types.js";
12
13
 
13
14
  export { types };
@@ -32,15 +33,7 @@ export const format = utilFormat;
32
33
  export const formatWithOptions = utilFormatWithOptions;
33
34
  export const TextEncoder = globalThis.TextEncoder;
34
35
  export const TextDecoder = globalThis.TextDecoder;
35
-
36
- /* ANSI escape codes, as Node's internal/util/inspect.js matches them: an OSC sequence (a terminal
37
- hyperlink: ESC ] … BEL) whole, or a CSI sequence */
38
- const ansi = new RegExp(
39
- "(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))" +
40
- "|[\\u001B\\u009B][[\\]()#;?]*" +
41
- "(?:\\d{1,4}(?:[;:]\\d{0,4})*)?" +
42
- "[\\dA-PR-TZcf-nq-uy=><~]", "g",
43
- );
36
+ export { stripVTControlCharacters };
44
37
 
45
38
  const kCustomPromisifiedSymbol = Symbol.for("nodejs.util.promisify.custom");
46
39
  /* names to make an object of when the callback gets several values, e.g. ['bytesRead', 'buffer'] */
@@ -93,12 +86,6 @@ export function promisify(original) {
93
86
 
94
87
  promisify.custom = kCustomPromisifiedSymbol;
95
88
 
96
- /** The string without its ANSI escape codes (colors, cursor movements, …). */
97
- export function stripVTControlCharacters(str) {
98
- validateString(str, "str");
99
- if (!str.includes("\u001B") && !str.includes("\u009B")) return str; /* no escape introducer */
100
- return str.replace(ansi, "");
101
- }
102
89
 
103
90
  const codesWarned = new Set();
104
91