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,38 +1,44 @@
1
- // node:console: the global console (the runtime's, in C), and Console, a console writing to the
2
- // streams it's given, as Node's: log, info, debug and dirxml to stdout; warn, error and trace to
3
- // stderr; groups indent every line; count, time and table as Node formats them. Its formatting is
4
- // util.format's and util.inspect's, which the global console's is too.
5
- import { inspect, format, formatWithOptions, stripVTControlCharacters } from "./util.js";
6
- import { codeError, invalidArgType } from "./internal/errors.js";
1
+ // node:console (Node's lib/internal/console/constructor.js and internal/cli_table.js): Console, a
2
+ // console writing to the streams it's given. The global console is the runtime's (in C), writing
3
+ // to the fds; a program that replaces a stdio stream's write gets Node's instead
4
+ // (internal/console_global.js, over this module's Console).
5
+ // Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
6
+ import { previewEntries } from "visaljs:host";
7
+ import { channel } from "./diagnostics_channel.js";
8
+ import { codeError, invalidArgType, invalidArgValue, outOfRange } from "./internal/errors.js";
9
+ import { getStringWidth } from "./internal/string_width.js";
10
+ import { formatWithOptions, inspect } from "./util.js";
11
+ import { isMap, isMapIterator, isSet, isSetIterator, isTypedArray } from "./util_types.js";
7
12
 
8
- const kIsConsole = Symbol("kIsConsole");
9
13
  const kSecond = 1000;
10
14
  const kMinute = 60 * kSecond;
11
15
  const kHour = 60 * kMinute;
12
16
 
13
- /* ---- console.table: Node's internal/cli_table ------------------------------------------------- */
14
-
15
- const isFullWidthCodePoint = (code) => code >= 0x1100 && (code <= 0x115f || code === 0x2329 || code === 0x232a ||
16
- (code >= 0x2e80 && code <= 0x3247 && code !== 0x303f) || (code >= 0x3250 && code <= 0x4dbf) || (code >= 0x4e00 && code <= 0xa4c6) ||
17
- (code >= 0xa960 && code <= 0xa97c) || (code >= 0xac00 && code <= 0xd7a3) || (code >= 0xf900 && code <= 0xfaff) ||
18
- (code >= 0xfe10 && code <= 0xfe19) || (code >= 0xfe30 && code <= 0xfe6b) || (code >= 0xff01 && code <= 0xff60) ||
19
- (code >= 0xffe0 && code <= 0xffe6) || (code >= 0x1b000 && code <= 0x1b001) || (code >= 0x1f200 && code <= 0x1f251) ||
20
- (code >= 0x1f300 && code <= 0x1f64f) || (code >= 0x20000 && code <= 0x3fffd));
21
-
22
- const isZeroWidthCodePoint = (code) => code <= 0x1f || (code >= 0x7f && code <= 0x9f) || (code >= 0x300 && code <= 0x36f) ||
23
- (code >= 0x200b && code <= 0x200f) || (code >= 0x20d0 && code <= 0x20ff) || (code >= 0xfe00 && code <= 0xfe0f) ||
24
- (code >= 0xfe20 && code <= 0xfe2f) || (code >= 0xe0100 && code <= 0xe01ef);
25
-
26
- /* columns on a terminal: wide characters two, combining ones none */
27
- function getStringWidth(str) {
28
- let width = 0;
29
- for (const char of stripVTControlCharacters(str).normalize("NFC")) {
30
- const code = char.codePointAt(0);
31
- if (isFullWidthCodePoint(code)) width += 2;
32
- else if (!isZeroWidthCodePoint(code)) width++;
33
- }
34
- return width;
35
- }
17
+ const onLog = channel("console.log");
18
+ const onWarn = channel("console.warn");
19
+ const onError = channel("console.error");
20
+ const onInfo = channel("console.info");
21
+ const onDebug = channel("console.debug");
22
+
23
+ const kMaxGroupIndentation = 1000;
24
+ const kCounts = Symbol("counts");
25
+ const kGroupIndentationWidth = Symbol("kGroupIndentWidth");
26
+ const kFormatForStderr = Symbol("kFormatForStderr");
27
+ const kFormatForStdout = Symbol("kFormatForStdout");
28
+ const kGetInspectOptions = Symbol("kGetInspectOptions");
29
+ const kColorMode = Symbol("kColorMode");
30
+ const kIsConsole = Symbol("kIsConsole");
31
+ const kWriteToConsole = Symbol("kWriteToConsole");
32
+ export const kBindProperties = Symbol("kBindProperties");
33
+ const kBindStreamsEager = Symbol("kBindStreamsEager");
34
+ export const kBindStreamsLazy = Symbol("kBindStreamsLazy");
35
+ const kUseStdout = Symbol("kUseStdout");
36
+ const kUseStderr = Symbol("kUseStderr");
37
+ const kGroupIndentationString = Symbol("kGroupIndentationString");
38
+
39
+ const optionsMap = new WeakMap();
40
+
41
+ /* ---- console.table (Node's internal/cli_table.js) ------------------------------------------- */
36
42
 
37
43
  const tableChars = {
38
44
  middleMiddle: "─", rowMiddle: "┼", topRight: "┐", topLeft: "┌", leftMiddle: "├", topMiddle: "┬", bottomRight: "┘",
@@ -43,13 +49,14 @@ function renderRow(row, columnWidths) {
43
49
  let out = tableChars.left;
44
50
  for (let i = 0; i < row.length; i++) {
45
51
  const cell = row[i];
46
- out += cell + " ".repeat(columnWidths[i] - getStringWidth(cell)); /* left-aligned, as Node 22's */
52
+ const needed = columnWidths[i] - getStringWidth(cell);
53
+ out += cell + " ".repeat(Math.ceil(needed));
47
54
  if (i !== row.length - 1) out += tableChars.middle;
48
55
  }
49
56
  return out + tableChars.right;
50
57
  }
51
58
 
52
- function renderTable(head, columns) {
59
+ function cliTable(head, columns) {
53
60
  const rows = [];
54
61
  const columnWidths = head.map((h) => getStringWidth(h));
55
62
  const longestColumn = Math.max(...columns.map((a) => a.length));
@@ -57,17 +64,19 @@ function renderTable(head, columns) {
57
64
  const column = columns[i];
58
65
  for (let j = 0; j < longestColumn; j++) {
59
66
  if (rows[j] === undefined) rows[j] = [];
60
- const value = (rows[j][i] = Object.hasOwn(column, j) ? column[j] : "");
67
+ const value = rows[j][i] = Object.hasOwn(column, j) ? column[j] : "";
61
68
  columnWidths[i] = Math.max(columnWidths[i] || 0, getStringWidth(value));
62
69
  }
63
70
  }
64
- const divider = columnWidths.map((w) => tableChars.middleMiddle.repeat(w + 2));
65
- let result = tableChars.topLeft + divider.join(tableChars.topMiddle) + tableChars.topRight + "\n" +
66
- renderRow(head, columnWidths) + "\n" + tableChars.leftMiddle + divider.join(tableChars.rowMiddle) + tableChars.rightMiddle + "\n";
71
+ const divider = columnWidths.map((i) => tableChars.middleMiddle.repeat(i + 2));
72
+ let result = tableChars.topLeft + divider.join(tableChars.topMiddle) + tableChars.topRight + "\n" + renderRow(head, columnWidths) + "\n" +
73
+ tableChars.leftMiddle + divider.join(tableChars.rowMiddle) + tableChars.rightMiddle + "\n";
67
74
  for (const row of rows) result += `${renderRow(row, columnWidths)}\n`;
68
75
  return result + tableChars.bottomLeft + divider.join(tableChars.bottomMiddle) + tableChars.bottomRight;
69
76
  }
70
77
 
78
+ /* ---- console.time (Node's internal/util/debuglog.js) --------------------------------------- */
79
+
71
80
  /* "1.234ms", "1.500s", "1:02.345 (m:ss.mmm)", "1:02:03.456 (h:mm:ss.mmm)" */
72
81
  function formatTime(ms) {
73
82
  let hours = 0;
@@ -99,87 +108,231 @@ const now = () => {
99
108
  return s * 1e3 + ns / 1e6;
100
109
  };
101
110
 
111
+ function timeLogImpl(console, label, implementation, data) {
112
+ const start = console._times.get(label);
113
+ if (start === undefined) {
114
+ process.emitWarning(`No such label '${label}' for ${implementation}`);
115
+ return false;
116
+ }
117
+ console.log("%s: %s", label, formatTime(now() - start), ...(data ?? []));
118
+ return true;
119
+ }
120
+
121
+ /* ---- colors (Node's internal/util/colors.js shouldColorize) --------------------------------- */
122
+
123
+ /* Node's FORCE_COLOR levels (tty's getColorDepth): '', 1, true, 2 and 3 give colors */
124
+ const FORCE_COLORS = new Set(["", "1", "true", "2", "3"]);
125
+
126
+ function shouldColorize(stream) {
127
+ if (process.env.FORCE_COLOR !== undefined) return FORCE_COLORS.has(process.env.FORCE_COLOR);
128
+ return Boolean(stream?.isTTY) && (typeof stream.getColorDepth === "function" ? stream.getColorDepth() > 2 : true);
129
+ }
130
+
102
131
  /* ---- Console ---------------------------------------------------------------------------------- */
103
132
 
104
- /** Console(stdout[, stderr[, ignoreErrors]]) or Console({ stdout, stderr, ignoreErrors,
105
- * colorMode, inspectOptions, groupIndentation }). Callable without new, as Node's; its methods
106
- * are bound, so they can be passed around. */
107
- export function Console(options, stderr, ignoreErrors) {
108
- if (!new.target) return Reflect.construct(Console, [options, stderr, ignoreErrors]);
109
- if (!options || typeof options.write === "function") options = { stdout: options, stderr, ignoreErrors };
110
- const { stdout, ignoreErrors: ignore = true, colorMode = "auto", inspectOptions, groupIndentation = 2 } = options;
111
- const err = options.stderr || stdout;
112
- if (!stdout || typeof stdout.write !== "function") throw codeError(TypeError, "ERR_CONSOLE_WRITABLE_STREAM", "Console expects a writable stream instance for stdout");
113
- if (!err || typeof err.write !== "function") throw codeError(TypeError, "ERR_CONSOLE_WRITABLE_STREAM", "Console expects a writable stream instance for stderr");
114
- if (typeof colorMode !== "boolean" && colorMode !== "auto") {
115
- throw codeError(TypeError, "ERR_INVALID_ARG_VALUE", `The argument 'colorMode' is invalid. Received ${inspect(colorMode)}`);
133
+ /** Console(stdout[, stderr[, ignoreErrors]]) or Console({ stdout, stderr, ignoreErrors, colorMode,
134
+ * inspectOptions, groupIndentation }); callable without new; its methods bound, so they can be
135
+ * passed around */
136
+ export function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
137
+ if (new.target === undefined) return Reflect.construct(Console, arguments);
138
+ if (!options || typeof options.write === "function") options = { stdout: options, stderr: arguments[1], ignoreErrors: arguments[2] };
139
+ const { stdout, stderr = stdout, ignoreErrors = true, colorMode = "auto", inspectOptions, groupIndentation } = options;
140
+ if (!stdout || typeof stdout.write !== "function") {
141
+ throw codeError(TypeError, "ERR_CONSOLE_WRITABLE_STREAM", "Console expects a writable stream instance for stdout");
142
+ }
143
+ if (!stderr || typeof stderr.write !== "function") {
144
+ throw codeError(TypeError, "ERR_CONSOLE_WRITABLE_STREAM", "Console expects a writable stream instance for stderr");
116
145
  }
117
- if (typeof groupIndentation !== "number" || !Number.isInteger(groupIndentation) || groupIndentation < 0 || groupIndentation > 1000) {
118
- throw codeError(RangeError, "ERR_OUT_OF_RANGE", `The value of "groupIndentation" is out of range. It must be >= 0 && <= 1000. Received ${groupIndentation}`);
146
+ if (colorMode !== "auto" && colorMode !== true && colorMode !== false) {
147
+ throw invalidArgValue("colorMode", "must be one of: 'auto', true, false", colorMode);
119
148
  }
120
- if (inspectOptions !== undefined && (inspectOptions === null || typeof inspectOptions !== "object")) {
121
- throw invalidArgType("options.inspectOptions", "of type object", inspectOptions);
149
+ if (groupIndentation !== undefined) {
150
+ if (typeof groupIndentation !== "number") throw invalidArgType("groupIndentation", "of type number", groupIndentation);
151
+ if (!Number.isInteger(groupIndentation)) throw outOfRange("groupIndentation", "an integer", groupIndentation);
152
+ if (groupIndentation < 0 || groupIndentation > kMaxGroupIndentation) {
153
+ throw outOfRange("groupIndentation", `>= 0 && <= ${kMaxGroupIndentation}`, groupIndentation);
154
+ }
122
155
  }
123
- if (inspectOptions?.colors !== undefined && colorMode !== "auto") {
124
- throw codeError(TypeError, "ERR_INCOMPATIBLE_OPTION_PAIR", 'Option "options.inspectOptions.color" cannot be used in combination with option "colorMode"');
156
+ if (inspectOptions !== undefined) {
157
+ if (inspectOptions === null || typeof inspectOptions !== "object" || Array.isArray(inspectOptions)) {
158
+ throw invalidArgType("options.inspectOptions", "of type object", inspectOptions);
159
+ }
160
+ /* one set of options for both streams, or a Map from a stream to its own */
161
+ const inspectOptionsMap = isMap(inspectOptions) ? inspectOptions : new Map([[stdout, inspectOptions], [stderr, inspectOptions]]);
162
+ for (const streamOptions of inspectOptionsMap.values()) {
163
+ if (streamOptions.colors !== undefined && options.colorMode !== undefined) {
164
+ throw codeError(TypeError, "ERR_INCOMPATIBLE_OPTION_PAIR", 'Option "options.inspectOptions.color" cannot be used in combination with option "colorMode"');
165
+ }
166
+ }
167
+ optionsMap.set(this, inspectOptionsMap);
125
168
  }
126
- Object.defineProperties(this, {
127
- _stdout: { value: stdout, writable: true, configurable: true },
128
- _stderr: { value: err, writable: true, configurable: true },
129
- _ignoreErrors: { value: Boolean(ignore), writable: true, configurable: true },
130
- });
131
- this[kIsConsole] = true;
132
- this._colorMode = colorMode;
133
- this._inspectOptions = inspectOptions;
134
- this._groupIndent = "";
135
- this._groupIndentation = groupIndentation;
136
- this._counts = new Map();
137
- this._times = new Map();
138
- /* bound, as Node's: const { log } = console works */
169
+ /* bound, as Node's: const { log } = console works; a subclass's methods are the ones bound */
139
170
  for (const key of Object.keys(Console.prototype)) {
140
- this[key] = Console.prototype[key].bind(this);
171
+ this[key] = this[key].bind(this);
141
172
  Object.defineProperty(this[key], "name", { value: key });
142
173
  }
174
+ this[kBindStreamsEager](stdout, stderr);
175
+ this[kBindProperties](ignoreErrors, colorMode, groupIndentation);
143
176
  }
144
177
 
178
+ const consolePropAttributes = { writable: true, enumerable: false, configurable: true };
179
+
145
180
  Object.defineProperty(Console, Symbol.hasInstance, {
146
- value: (instance) => instance === globalThis.console || Boolean(instance?.[kIsConsole]),
181
+ value: function (instance) {
182
+ return instance?.[kIsConsole] === true || instance === globalThis.console;
183
+ },
147
184
  });
148
185
 
149
- const proto = Console.prototype;
186
+ const kColorInspectOptions = { colors: true };
187
+ const kNoColorInspectOptions = {};
150
188
 
151
- /* a line to a stream: indented by the groups, write errors ignored unless asked not to */
152
- proto._write = function (useStderr, string) {
153
- const stream = useStderr ? this._stderr : this._stdout;
154
- if (this._groupIndent.length !== 0) {
155
- if (string.includes("\n")) string = string.replaceAll("\n", `\n${this._groupIndent}`);
156
- string = this._groupIndent + string;
157
- }
158
- string += "\n";
159
- if (!this._ignoreErrors) return stream.write(string);
160
- try {
161
- if (typeof stream.listenerCount === "function" && stream.listenerCount("error") === 0) stream.once("error", () => {});
162
- stream.write(string, () => {});
163
- } catch {
164
- /* the console doesn't throw for its stream */
165
- }
166
- };
167
- Object.defineProperty(proto, "_write", { enumerable: false });
189
+ function noop() {}
168
190
 
169
- proto._format = function (args) {
170
- return this._inspectOptions ? formatWithOptions(this._inspectOptions, ...args) : format(...args);
171
- };
172
- Object.defineProperty(proto, "_format", { enumerable: false });
191
+ function createWriteErrorHandler(instance, streamSymbol) {
192
+ return (err) => {
193
+ /* the stream's 'error' listener that write() adds: kept until the error is emitted */
194
+ const stream = streamSymbol === kUseStdout ? instance._stdout : instance._stderr;
195
+ if (err !== null && !stream._writableState?.errorEmitted) {
196
+ if (stream.listenerCount?.("error") === 0) stream.once("error", noop);
197
+ }
198
+ };
199
+ }
173
200
 
174
- Object.assign(proto, {
201
+ const isStackOverflowError = (e) => e instanceof RangeError && e.message === "Maximum call stack size exceeded";
202
+
203
+ Object.defineProperties(Console.prototype, {
204
+ [kBindStreamsEager]: {
205
+ ...consolePropAttributes,
206
+ value: function (stdout, stderr) {
207
+ Object.defineProperties(this, {
208
+ _stdout: { ...consolePropAttributes, value: stdout },
209
+ _stderr: { ...consolePropAttributes, value: stderr },
210
+ });
211
+ },
212
+ },
213
+ /* the global console's: process.stdout and process.stderr, looked up when first written */
214
+ [kBindStreamsLazy]: {
215
+ ...consolePropAttributes,
216
+ value: function (object) {
217
+ let stdout;
218
+ let stderr;
219
+ Object.defineProperties(this, {
220
+ _stdout: {
221
+ enumerable: false,
222
+ configurable: true,
223
+ get() { return stdout ||= object.stdout; },
224
+ set(value) { stdout = value; },
225
+ },
226
+ _stderr: {
227
+ enumerable: false,
228
+ configurable: true,
229
+ get() { return stderr ||= object.stderr; },
230
+ set(value) { stderr = value; },
231
+ },
232
+ });
233
+ },
234
+ },
235
+ [kBindProperties]: {
236
+ ...consolePropAttributes,
237
+ value: function (ignoreErrors, colorMode, groupIndentation = 2) {
238
+ Object.defineProperties(this, {
239
+ _stdoutErrorHandler: { ...consolePropAttributes, value: createWriteErrorHandler(this, kUseStdout) },
240
+ _stderrErrorHandler: { ...consolePropAttributes, value: createWriteErrorHandler(this, kUseStderr) },
241
+ _ignoreErrors: { ...consolePropAttributes, value: Boolean(ignoreErrors) },
242
+ _times: { ...consolePropAttributes, value: new Map() },
243
+ [kCounts]: { ...consolePropAttributes, value: new Map() },
244
+ [kColorMode]: { ...consolePropAttributes, value: colorMode },
245
+ [kIsConsole]: { ...consolePropAttributes, value: true },
246
+ [kGroupIndentationWidth]: { ...consolePropAttributes, value: groupIndentation },
247
+ [kGroupIndentationString]: { ...consolePropAttributes, value: "" },
248
+ [Symbol.toStringTag]: { writable: false, enumerable: false, configurable: true, value: "console" },
249
+ });
250
+ },
251
+ },
252
+ [kWriteToConsole]: {
253
+ ...consolePropAttributes,
254
+ value: function (streamSymbol, string) {
255
+ const ignoreErrors = this._ignoreErrors;
256
+ const groupIndent = this[kGroupIndentationString];
257
+ const useStdout = streamSymbol === kUseStdout;
258
+ const stream = useStdout ? this._stdout : this._stderr;
259
+ const errorHandler = useStdout ? this._stdoutErrorHandler : this._stderrErrorHandler;
260
+ if (groupIndent.length !== 0) {
261
+ if (string.includes("\n")) string = string.replace(/\n/g, `\n${groupIndent}`);
262
+ string = groupIndent + string;
263
+ }
264
+ string += "\n";
265
+ if (ignoreErrors === false) return stream.write(string);
266
+ /* errors ignored, but for a stack overflow (Node's), which the program should see */
267
+ try {
268
+ if (stream.listenerCount?.("error") === 0) stream.once("error", noop);
269
+ stream.write(string, errorHandler);
270
+ } catch (e) {
271
+ if (isStackOverflowError(e)) throw e;
272
+ } finally {
273
+ stream.removeListener?.("error", noop);
274
+ }
275
+ },
276
+ },
277
+ [kGetInspectOptions]: {
278
+ ...consolePropAttributes,
279
+ value: function (stream) {
280
+ let color = this[kColorMode];
281
+ if (color === "auto") color = shouldColorize(stream);
282
+ const options = optionsMap.get(this)?.get(stream);
283
+ if (options) {
284
+ if (options.colors === undefined) options.colors = color;
285
+ return options;
286
+ }
287
+ return color ? kColorInspectOptions : kNoColorInspectOptions;
288
+ },
289
+ },
290
+ [kFormatForStdout]: {
291
+ ...consolePropAttributes,
292
+ value: function (args) {
293
+ if (args.length === 1 && typeof args[0] === "string") return args[0];
294
+ return formatWithOptions(this[kGetInspectOptions](this._stdout), ...args);
295
+ },
296
+ },
297
+ [kFormatForStderr]: {
298
+ ...consolePropAttributes,
299
+ value: function (args) {
300
+ if (args.length === 1 && typeof args[0] === "string") return args[0];
301
+ return formatWithOptions(this[kGetInspectOptions](this._stderr), ...args);
302
+ },
303
+ },
304
+ });
305
+
306
+ const keyKey = "Key";
307
+ const valuesKey = "Values";
308
+ const indexKey = "(index)";
309
+ const iterKey = "(iteration index)";
310
+
311
+ const isArray = (v) => Array.isArray(v) || isTypedArray(v) || Buffer.isBuffer(v);
312
+
313
+ const consoleMethods = {
175
314
  log(...args) {
176
- this._write(false, this._format(args));
315
+ if (onLog.hasSubscribers) onLog.publish(args);
316
+ this[kWriteToConsole](kUseStdout, this[kFormatForStdout](args));
317
+ },
318
+ info(...args) {
319
+ if (onInfo.hasSubscribers) onInfo.publish(args);
320
+ this[kWriteToConsole](kUseStdout, this[kFormatForStdout](args));
321
+ },
322
+ debug(...args) {
323
+ if (onDebug.hasSubscribers) onDebug.publish(args);
324
+ this[kWriteToConsole](kUseStdout, this[kFormatForStdout](args));
177
325
  },
178
326
  warn(...args) {
179
- this._write(true, this._format(args));
327
+ if (onWarn.hasSubscribers) onWarn.publish(args);
328
+ this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args));
329
+ },
330
+ error(...args) {
331
+ if (onError.hasSubscribers) onError.publish(args);
332
+ this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args));
180
333
  },
181
334
  dir(object, options) {
182
- this._write(false, inspect(object, { customInspect: false, ...this._inspectOptions, ...options }));
335
+ this[kWriteToConsole](kUseStdout, inspect(object, { customInspect: false, ...this[kGetInspectOptions](this._stdout), ...options }));
183
336
  },
184
337
  time(label = "default") {
185
338
  label = `${label}`;
@@ -191,19 +344,20 @@ Object.assign(proto, {
191
344
  },
192
345
  timeEnd(label = "default") {
193
346
  label = `${label}`;
194
- if (this._timeLog(label, "console.timeEnd()", [])) this._times.delete(label);
347
+ if (timeLogImpl(this, label, "console.timeEnd()")) this._times.delete(label);
195
348
  },
196
349
  timeLog(label = "default", ...data) {
197
- this._timeLog(`${label}`, "console.timeLog()", data);
350
+ timeLogImpl(this, `${label}`, "console.timeLog()", data);
198
351
  },
352
+ /* compiled code has no stack frames: the trace is its message */
199
353
  trace(...args) {
200
- this._write(true, `Trace${args.length ? ": " + this._format(args) : ""}`);
354
+ this.error(`Trace${args.length ? `: ${this[kFormatForStderr](args)}` : ""}`);
201
355
  },
202
356
  assert(expression, ...args) {
203
357
  if (!expression) {
204
- if (typeof args[0] === "string") args[0] = `Assertion failed: ${args[0]}`;
358
+ if (args.length && typeof args[0] === "string") args[0] = `Assertion failed: ${args[0]}`;
205
359
  else args.unshift("Assertion failed");
206
- this.warn(...args);
360
+ Reflect.apply(this.warn, this, args);
207
361
  }
208
362
  },
209
363
  /* only on a terminal: the cursor home, and the screen below it cleared */
@@ -212,53 +366,77 @@ Object.assign(proto, {
212
366
  },
213
367
  count(label = "default") {
214
368
  label = `${label}`;
215
- const count = (this._counts.get(label) ?? 0) + 1;
216
- this._counts.set(label, count);
369
+ const counts = this[kCounts];
370
+ const count = (counts.get(label) ?? 0) + 1;
371
+ counts.set(label, count);
217
372
  this.log(`${label}: ${count}`);
218
373
  },
219
374
  countReset(label = "default") {
220
- label = `${label}`;
221
- if (!this._counts.has(label)) {
375
+ const counts = this[kCounts];
376
+ if (!counts.has(label)) {
222
377
  process.emitWarning(`Count for '${label}' does not exist`);
223
378
  return;
224
379
  }
225
- this._counts.delete(label);
380
+ counts.delete(`${label}`);
226
381
  },
227
382
  group(...data) {
228
- if (data.length > 0) this.log(...data);
229
- this._groupIndent += " ".repeat(this._groupIndentation);
383
+ if (data.length > 0) Reflect.apply(this.log, this, data);
384
+ this[kGroupIndentationString] += " ".repeat(this[kGroupIndentationWidth]);
230
385
  },
231
386
  groupEnd() {
232
- this._groupIndent = this._groupIndent.slice(0, this._groupIndent.length - this._groupIndentation);
387
+ const currentIndentation = this[kGroupIndentationString];
388
+ this[kGroupIndentationString] = currentIndentation.slice(0, currentIndentation.length - this[kGroupIndentationWidth]);
233
389
  },
234
390
  table(tabularData, properties) {
235
391
  if (properties !== undefined && !Array.isArray(properties)) throw invalidArgType("properties", "an instance of Array", properties);
236
392
  if (tabularData === null || typeof tabularData !== "object") return this.log(tabularData);
237
- const final = (k, v) => this.log(renderTable(k, v));
393
+ const final = (k, v) => this.log(cliTable(k, v));
238
394
  const _inspect = (v) => {
239
- const depth = v !== null && typeof v === "object" && !Array.isArray(v) && Object.keys(v).length > 2 ? -1 : 0;
240
- return inspect(v, { depth, maxArrayLength: 3, breakLength: Infinity, ...this._inspectOptions });
395
+ const depth = v !== null && typeof v === "object" && !isArray(v) && Object.keys(v).length > 2 ? -1 : 0;
396
+ return inspect(v, { depth, maxArrayLength: 3, breakLength: Infinity, ...this[kGetInspectOptions](this._stdout) });
241
397
  };
242
398
  const getIndexArray = (length) => Array.from({ length }, (_, i) => _inspect(i));
243
- if (tabularData instanceof Map) {
399
+ const mapIter = isMapIterator(tabularData);
400
+ let isKeyValue = false;
401
+ let i = 0;
402
+ if (mapIter) {
403
+ [tabularData, isKeyValue] = previewEntries(tabularData, true);
404
+ }
405
+ if (isKeyValue || isMap(tabularData)) {
244
406
  const keys = [];
245
407
  const values = [];
246
- for (const [k, v] of tabularData) {
247
- keys.push(_inspect(k));
248
- values.push(_inspect(v));
408
+ let length = 0;
409
+ if (mapIter) {
410
+ for (; i < tabularData.length / 2; ++i) {
411
+ keys.push(_inspect(tabularData[i * 2]));
412
+ values.push(_inspect(tabularData[i * 2 + 1]));
413
+ length++;
414
+ }
415
+ } else {
416
+ for (const { 0: k, 1: v } of tabularData) {
417
+ keys.push(_inspect(k));
418
+ values.push(_inspect(v));
419
+ length++;
420
+ }
249
421
  }
250
- return final(["(iteration index)", "Key", "Values"], [getIndexArray(keys.length), keys, values]);
422
+ return final([iterKey, keyKey, valuesKey], [getIndexArray(length), keys, values]);
251
423
  }
252
- if (tabularData instanceof Set || (typeof tabularData.next === "function" && typeof tabularData[Symbol.iterator] === "function")) {
424
+ const setIter = isSetIterator(tabularData);
425
+ if (setIter) tabularData = previewEntries(tabularData);
426
+ if (setIter || mapIter || isSet(tabularData)) {
253
427
  const values = [];
254
- for (const v of tabularData) values.push(_inspect(v));
255
- return final(["(iteration index)", "Values"], [getIndexArray(values.length), values]);
428
+ let length = 0;
429
+ for (const v of tabularData) {
430
+ values.push(_inspect(v));
431
+ length++;
432
+ }
433
+ return final([iterKey, valuesKey], [getIndexArray(length), values]);
256
434
  }
257
- const map = Object.create(null);
435
+ const map = { __proto__: null };
258
436
  let hasPrimitives = false;
259
437
  const valuesKeyArray = [];
260
438
  const indexKeyArray = Object.keys(tabularData);
261
- for (let i = 0; i < indexKeyArray.length; i++) {
439
+ for (; i < indexKeyArray.length; i++) {
262
440
  const item = tabularData[indexKeyArray[i]];
263
441
  const primitive = item === null || (typeof item !== "function" && typeof item !== "object");
264
442
  if (properties === undefined && primitive) {
@@ -276,14 +454,21 @@ Object.assign(proto, {
276
454
  const keys = Object.keys(map);
277
455
  const values = Object.values(map);
278
456
  if (hasPrimitives) {
279
- keys.push("Values");
457
+ keys.push(valuesKey);
280
458
  values.push(valuesKeyArray);
281
459
  }
282
- keys.unshift("(index)");
460
+ keys.unshift(indexKey);
283
461
  values.unshift(indexKeyArray);
284
462
  return final(keys, values);
285
463
  },
286
- /* V8 inspector APIs: nothing to report to here */
464
+ };
465
+
466
+ for (const method of Reflect.ownKeys(consoleMethods)) Console.prototype[method] = consoleMethods[method];
467
+ Console.prototype.dirxml = Console.prototype.log;
468
+ Console.prototype.groupCollapsed = Console.prototype.group;
469
+
470
+ /* V8 inspector APIs the global console has: nothing to report to here */
471
+ const inspectorMethods = {
287
472
  profile() {},
288
473
  profileEnd() {},
289
474
  timeStamp() {},
@@ -293,30 +478,13 @@ Object.assign(proto, {
293
478
  createTask() {
294
479
  return { run: (f) => f() };
295
480
  },
296
- });
297
- proto.debug = proto.log;
298
- proto.info = proto.log;
299
- proto.dirxml = proto.log;
300
- proto.error = proto.warn;
301
- proto.groupCollapsed = proto.group;
302
-
303
- proto._timeLog = function (label, name, data) {
304
- const start = this._times.get(label);
305
- if (start === undefined) {
306
- process.emitWarning(`No such label '${label}' for ${name}`);
307
- return false;
308
- }
309
- const ms = now() - start;
310
- this.log("%s: %s", label, formatTime(ms), ...data);
311
- return true;
312
481
  };
313
- Object.defineProperty(proto, "_timeLog", { enumerable: false });
314
482
 
315
483
  /* ---- the module: the global console, with Console, and the V8 extras it lacks ------------------ */
316
484
 
317
485
  const console = globalThis.console;
318
- for (const key of ["profile", "profileEnd", "timeStamp", "context", "createTask"]) {
319
- if (typeof console[key] !== "function") Object.defineProperty(console, key, { value: proto[key], writable: true, configurable: true });
486
+ for (const key of Object.keys(inspectorMethods)) {
487
+ if (typeof console[key] !== "function") Object.defineProperty(console, key, { value: inspectorMethods[key], writable: true, configurable: true });
320
488
  }
321
489
  if (console.Console === undefined) Object.defineProperty(console, "Console", { value: Console, writable: true, configurable: true });
322
490
 
@@ -3,6 +3,7 @@
3
3
  // provided yet throws ERR_VISALJS_UNSUPPORTED when called.
4
4
  import { cryptoTimingSafeEqual } from "visaljs:host";
5
5
  import { codeError, notSupported } from "./internal/errors.js";
6
+ import { lazyClass } from "./internal/features.js";
6
7
  import {
7
8
  createECDH, createSign, createVerify, diffieHellman, ECDH, getCurves, privateDecrypt, privateEncrypt, publicDecrypt, publicEncrypt, Sign,
8
9
  sign, Verify, verify,
@@ -17,10 +18,10 @@ import {
17
18
  createPrivateKey, createPublicKey, createSecretKey, generateKey, generateKeyPair, generateKeyPairSync, generateKeySync, KeyObject,
18
19
  } from "./internal/crypto/keys.js";
19
20
  import { hkdf, hkdfSync, pbkdf2, pbkdf2Sync, scrypt, scryptSync } from "./internal/crypto/kdf.js";
20
- import { randomBytes, randomFill, randomFillSync, randomInt, randomUUID } from "./internal/crypto/random.js";
21
+ import { randomBytes, randomFill, randomFillSync, randomInt, randomUUID, randomUUIDv7 } from "./internal/crypto/random.js";
21
22
  import { isAnyArrayBuffer, isArrayBufferView } from "./internal/crypto/util.js";
22
23
 
23
- export { createHash, createHmac, getHashes, Hash, hash, Hmac, randomBytes, randomFill, randomFillSync, randomInt, randomUUID };
24
+ export { createHash, createHmac, getHashes, Hash, hash, Hmac, randomBytes, randomFill, randomFillSync, randomInt, randomUUID, randomUUIDv7 };
24
25
  export { hkdf, hkdfSync, pbkdf2, pbkdf2Sync, scrypt, scryptSync };
25
26
  export { createPrivateKey, createPublicKey, createSecretKey, generateKey, generateKeyPair, generateKeyPairSync, generateKeySync, KeyObject };
26
27
  export { createECDH, createSign, createVerify, diffieHellman, ECDH, getCurves, privateDecrypt, privateEncrypt, publicDecrypt, publicEncrypt };
@@ -97,7 +98,8 @@ const unsupported = (name) =>
97
98
  export const Certificate = unsupported("Certificate");
98
99
  export const Cipher = unsupported("Cipher");
99
100
  export const Decipher = unsupported("Decipher");
100
- export const X509Certificate = unsupported("X509Certificate");
101
+
102
+ export const X509Certificate = lazyClass("X509Certificate");
101
103
 
102
104
  export default {
103
105
  Certificate, Cipher, Cipheriv, Decipher, Decipheriv, DiffieHellman, DiffieHellmanGroup, ECDH, Hash, Hmac, KeyObject, Sign,
@@ -106,6 +108,6 @@ export default {
106
108
  createVerify, diffieHellman, generateKey, generateKeyPair, generateKeyPairSync, generateKeySync, generatePrime,
107
109
  generatePrimeSync, getCipherInfo, getCiphers, getCurves, getDiffieHellman, getFips, getHashes, getRandomValues, hash, hkdf,
108
110
  hkdfSync, pbkdf2, pbkdf2Sync, privateDecrypt, privateEncrypt, publicDecrypt, publicEncrypt, randomBytes, randomFill,
109
- randomFillSync, randomInt, randomUUID, scrypt, scryptSync, secureHeapUsed, setEngine, setFips, sign, subtle, timingSafeEqual,
111
+ randomFillSync, randomInt, randomUUID, randomUUIDv7, scrypt, scryptSync, secureHeapUsed, setEngine, setFips, sign, subtle, timingSafeEqual,
110
112
  verify, webcrypto,
111
113
  };