visaljs 0.0.10 → 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.
- package/README.md +12 -4
- package/THIRD_PARTY_LICENSES +31 -1
- package/cli.js +962 -68
- package/node/include/js_node.h +11 -1
- package/node/prelude/_http_common.js +29 -0
- package/node/prelude/async_hooks.js +50 -11
- package/node/prelude/child_process.js +31 -4
- package/node/prelude/console.js +311 -143
- package/node/prelude/crypto.js +6 -4
- package/node/prelude/dgram.js +1169 -0
- package/node/prelude/diagnostics_channel.js +3 -1
- package/node/prelude/dns.js +250 -45
- package/node/prelude/dns_promises.js +8 -2
- package/node/prelude/fs_promises.js +9 -1
- package/node/prelude/http.js +395 -86
- package/node/prelude/https.js +13 -4
- package/node/prelude/internal/console_class.js +7 -0
- package/node/prelude/internal/console_global.js +25 -0
- package/node/prelude/internal/crypto/key_encryption.js +217 -0
- package/node/prelude/internal/crypto/keys.js +161 -26
- package/node/prelude/internal/crypto/random.js +24 -0
- package/node/prelude/internal/crypto/util.js +2 -1
- package/node/prelude/internal/crypto_x509.js +161 -0
- package/node/prelude/internal/dns_classes.js +6 -0
- package/node/prelude/internal/dns_resolver.js +371 -0
- package/node/prelude/internal/errors.js +9 -0
- package/node/prelude/internal/events_on.js +82 -37
- package/node/prelude/internal/features.js +8 -4
- package/node/prelude/internal/fs_filehandle.js +10 -4
- package/node/prelude/internal/perf_histogram.js +1 -1
- package/node/prelude/internal/process_more.js +32 -17
- package/node/prelude/internal/process_signals.js +8 -2
- package/node/prelude/internal/punycode.ts +163 -0
- package/node/prelude/internal/readline.js +648 -274
- package/node/prelude/internal/readline_editor.js +1240 -0
- package/node/prelude/internal/string_width.js +43 -0
- package/node/prelude/internal/tls/common.js +145 -33
- package/node/prelude/internal/tls/wrap.js +182 -49
- package/node/prelude/internal/tls/x509.js +4 -1
- package/node/prelude/internal/udp.js +177 -0
- package/node/prelude/net.js +13 -1
- package/node/prelude/os.js +24 -6
- package/node/prelude/perf_hooks.js +37 -2
- package/node/prelude/punycode.js +2 -130
- package/node/prelude/readline.js +113 -4
- package/node/prelude/readline_promises.js +56 -32
- package/node/prelude/tls.js +21 -4
- package/node/prelude/util.js +3 -16
- package/node/src/host_dns.c +623 -0
- package/node/src/host_http.c +12 -0
- package/node/src/host_net.c +46 -0
- package/node/src/host_os.c +1 -6
- package/node/src/host_sys.c +70 -0
- package/node/src/host_udp.c +418 -0
- package/node/third_party/c-ares/LICENSE.md +24 -0
- package/node/third_party/c-ares/config/darwin/ares_config.h +573 -0
- package/node/third_party/c-ares/config/freebsd/ares_config.h +573 -0
- package/node/third_party/c-ares/config/linux/ares_config.h +573 -0
- package/node/third_party/c-ares/config/openbsd/ares_config.h +583 -0
- package/node/third_party/c-ares/include/ares.h +1237 -0
- package/node/third_party/c-ares/include/ares_build.h +202 -0
- package/node/third_party/c-ares/include/ares_dns.h +127 -0
- package/node/third_party/c-ares/include/ares_dns_record.h +1119 -0
- package/node/third_party/c-ares/include/ares_nameser.h +510 -0
- package/node/third_party/c-ares/include/ares_version.h +47 -0
- package/node/third_party/c-ares/src/lib/ares_addrinfo2hostent.c +305 -0
- package/node/third_party/c-ares/src/lib/ares_addrinfo_localhost.c +245 -0
- package/node/third_party/c-ares/src/lib/ares_android.c +496 -0
- package/node/third_party/c-ares/src/lib/ares_android.h +38 -0
- package/node/third_party/c-ares/src/lib/ares_cancel.c +87 -0
- package/node/third_party/c-ares/src/lib/ares_close_sockets.c +137 -0
- package/node/third_party/c-ares/src/lib/ares_conn.c +511 -0
- package/node/third_party/c-ares/src/lib/ares_conn.h +202 -0
- package/node/third_party/c-ares/src/lib/ares_cookie.c +461 -0
- package/node/third_party/c-ares/src/lib/ares_data.c +168 -0
- package/node/third_party/c-ares/src/lib/ares_data.h +92 -0
- package/node/third_party/c-ares/src/lib/ares_destroy.c +159 -0
- package/node/third_party/c-ares/src/lib/ares_free_hostent.c +54 -0
- package/node/third_party/c-ares/src/lib/ares_free_string.c +33 -0
- package/node/third_party/c-ares/src/lib/ares_freeaddrinfo.c +67 -0
- package/node/third_party/c-ares/src/lib/ares_getaddrinfo.c +806 -0
- package/node/third_party/c-ares/src/lib/ares_getenv.c +38 -0
- package/node/third_party/c-ares/src/lib/ares_getenv.h +34 -0
- package/node/third_party/c-ares/src/lib/ares_gethostbyaddr.c +229 -0
- package/node/third_party/c-ares/src/lib/ares_gethostbyname.c +341 -0
- package/node/third_party/c-ares/src/lib/ares_getnameinfo.c +437 -0
- package/node/third_party/c-ares/src/lib/ares_hosts_file.c +960 -0
- package/node/third_party/c-ares/src/lib/ares_inet_net_pton.h +31 -0
- package/node/third_party/c-ares/src/lib/ares_init.c +631 -0
- package/node/third_party/c-ares/src/lib/ares_ipv6.h +115 -0
- package/node/third_party/c-ares/src/lib/ares_library_init.c +190 -0
- package/node/third_party/c-ares/src/lib/ares_metrics.c +261 -0
- package/node/third_party/c-ares/src/lib/ares_options.c +492 -0
- package/node/third_party/c-ares/src/lib/ares_parse_into_addrinfo.c +179 -0
- package/node/third_party/c-ares/src/lib/ares_private.h +648 -0
- package/node/third_party/c-ares/src/lib/ares_process.c +1649 -0
- package/node/third_party/c-ares/src/lib/ares_qcache.c +442 -0
- package/node/third_party/c-ares/src/lib/ares_query.c +151 -0
- package/node/third_party/c-ares/src/lib/ares_search.c +623 -0
- package/node/third_party/c-ares/src/lib/ares_send.c +300 -0
- package/node/third_party/c-ares/src/lib/ares_set_socket_functions.c +590 -0
- package/node/third_party/c-ares/src/lib/ares_setup.h +224 -0
- package/node/third_party/c-ares/src/lib/ares_socket.c +427 -0
- package/node/third_party/c-ares/src/lib/ares_socket.h +163 -0
- package/node/third_party/c-ares/src/lib/ares_sortaddrinfo.c +447 -0
- package/node/third_party/c-ares/src/lib/ares_strerror.c +91 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig.c +642 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_files.c +851 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_mac.c +373 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_win.c +673 -0
- package/node/third_party/c-ares/src/lib/ares_timeout.c +162 -0
- package/node/third_party/c-ares/src/lib/ares_update_servers.c +1376 -0
- package/node/third_party/c-ares/src/lib/ares_version.c +36 -0
- package/node/third_party/c-ares/src/lib/config-dos.h +114 -0
- package/node/third_party/c-ares/src/lib/config-win32.h +396 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_array.c +409 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable.c +451 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable.h +174 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_asvp.c +224 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_dict.c +230 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_strvp.c +210 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_szvp.c +188 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpstr.c +186 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpvp.c +194 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_llist.c +385 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_slist.c +479 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_slist.h +207 -0
- package/node/third_party/c-ares/src/lib/event/ares_event.h +191 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_configchg.c +746 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_epoll.c +192 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_kqueue.c +248 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_poll.c +140 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_select.c +159 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_thread.c +575 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_wake_pipe.c +172 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_win32.c +981 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_win32.h +161 -0
- package/node/third_party/c-ares/src/lib/include/ares_array.h +276 -0
- package/node/third_party/c-ares/src/lib/include/ares_buf.h +732 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_asvp.h +130 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_dict.h +123 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_strvp.h +130 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_szvp.h +118 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_vpstr.h +111 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_vpvp.h +128 -0
- package/node/third_party/c-ares/src/lib/include/ares_llist.h +239 -0
- package/node/third_party/c-ares/src/lib/include/ares_mem.h +41 -0
- package/node/third_party/c-ares/src/lib/include/ares_str.h +261 -0
- package/node/third_party/c-ares/src/lib/inet_net_pton.c +451 -0
- package/node/third_party/c-ares/src/lib/inet_ntop.c +219 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_create_query.c +78 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_expand_name.c +99 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_expand_string.c +107 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_fds.c +80 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_getsock.c +85 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_a_reply.c +107 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_mapping.c +982 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.c +309 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.h +72 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_name.c +736 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_parse.c +1360 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_private.h +273 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_record.c +1701 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_write.c +1229 -0
- package/node/third_party/c-ares/src/lib/str/ares_buf.c +1510 -0
- package/node/third_party/c-ares/src/lib/str/ares_str.c +562 -0
- package/node/third_party/c-ares/src/lib/str/ares_strsplit.c +90 -0
- package/node/third_party/c-ares/src/lib/str/ares_strsplit.h +51 -0
- package/node/third_party/c-ares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
- package/node/third_party/c-ares/src/lib/util/ares_iface_ips.c +640 -0
- package/node/third_party/c-ares/src/lib/util/ares_iface_ips.h +140 -0
- package/node/third_party/c-ares/src/lib/util/ares_math.c +167 -0
- package/node/third_party/c-ares/src/lib/util/ares_math.h +58 -0
- package/node/third_party/c-ares/src/lib/util/ares_rand.c +389 -0
- package/node/third_party/c-ares/src/lib/util/ares_rand.h +36 -0
- package/node/third_party/c-ares/src/lib/util/ares_threads.c +613 -0
- package/node/third_party/c-ares/src/lib/util/ares_threads.h +60 -0
- package/node/third_party/c-ares/src/lib/util/ares_time.h +49 -0
- package/node/third_party/c-ares/src/lib/util/ares_timeval.c +95 -0
- package/node/third_party/c-ares/src/lib/util/ares_uri.c +1627 -0
- package/node/third_party/c-ares/src/lib/util/ares_uri.h +252 -0
- package/node/third_party/c-ares/src/lib/windows_port.c +29 -0
- package/package.json +1 -1
- package/prebuilt/darwin-arm64/cares-a6286c65ca9374a3.a +0 -0
- package/prebuilt/darwin-x64/cares-a6286c65ca9374a3.a +0 -0
- package/prebuilt/linux-arm64/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-arm64-musl/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-x64/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-x64-musl/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
- package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
- package/prebuilt/win32-x64/cares-49c9ec95162b912d.a +0 -0
- package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
- package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
- package/runtime/include/js_builtins.h +5 -0
- package/runtime/include/js_crypto.h +11 -0
- package/runtime/include/js_gc.h +13 -10
- package/runtime/include/js_jobs.h +2 -0
- package/runtime/include/js_object.h +58 -0
- package/runtime/include/jscontext.h +1 -0
- package/runtime/src/crypto_internal.h +1 -0
- package/runtime/src/crypto_subtle.c +66 -7
- package/runtime/src/crypto_tls.c +265 -19
- package/runtime/src/gc.c +73 -92
- package/runtime/src/inspect.c +18 -1
- package/runtime/src/jobs.c +37 -22
- package/runtime/src/object.c +49 -2
- package/runtime/src/os.c +16 -6
- package/runtime/src/os.h +2 -0
- package/runtime/src/process.c +97 -10
|
@@ -129,17 +129,19 @@ export class Channel {
|
|
|
129
129
|
this._subscribers = undefined;
|
|
130
130
|
this._stores = undefined;
|
|
131
131
|
this.name = name;
|
|
132
|
+
this._index = undefined;
|
|
132
133
|
channels.set(name, this);
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
/* an active channel's prototype is ActiveChannel's: it is a Channel still */
|
|
137
|
+
/* Object.getPrototypeOf throws on undefined, as Node's: tracingChannel({}) reports that */
|
|
136
138
|
static [Symbol.hasInstance](instance) {
|
|
137
|
-
if (instance === null || (typeof instance !== "object" && typeof instance !== "function")) return false;
|
|
138
139
|
const prototype = Object.getPrototypeOf(instance);
|
|
139
140
|
return prototype === Channel.prototype || prototype === ActiveChannel.prototype;
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
subscribe(subscription) {
|
|
144
|
+
validateFunction(subscription, "subscription");
|
|
143
145
|
markActive(this);
|
|
144
146
|
this.subscribe(subscription);
|
|
145
147
|
}
|
package/node/prelude/dns.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
// node:dns
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
1
|
+
// node:dns (Node's lib/dns.js, and dns.promises as lib/internal/dns/promises.js): lookup through
|
|
2
|
+
// getaddrinfo on libuv's thread pool, as Node's is; lookupService through getnameinfo; Resolver
|
|
3
|
+
// and the resolve* functions through c-ares (internal/dns_resolver.js, linked into programs that
|
|
4
|
+
// name them).
|
|
5
|
+
// Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
|
|
6
|
+
import { dnsLookup, dnsLookupService, errnoName } from "visaljs:host";
|
|
5
7
|
import { bindContext } from "./internal/async_context.js";
|
|
6
|
-
import { codeError, invalidArgType, invalidArgValue } from "./internal/errors.js";
|
|
8
|
+
import { codeError, invalidArgType, invalidArgValue, validateFunction, validatePort, validateString } from "./internal/errors.js";
|
|
9
|
+
import { PromisesResolver, Resolver } from "./internal/dns_classes.js";
|
|
10
|
+
import { lazyFunction } from "./internal/features.js";
|
|
7
11
|
import { isIP } from "./internal/net.js";
|
|
8
12
|
|
|
9
|
-
/* getaddrinfo hints, and the error codes of the resolver */
|
|
13
|
+
/* getaddrinfo's hints (Node's AI_*), and the error codes of the resolver */
|
|
10
14
|
export const ADDRCONFIG = 1024;
|
|
11
15
|
export const V4MAPPED = 2048;
|
|
12
16
|
export const ALL = 256;
|
|
@@ -35,10 +39,16 @@ export const LOADIPHLPAPI = "ELOADIPHLPAPI";
|
|
|
35
39
|
export const ADDRGETNETWORKPARAMS = "EADDRGETNETWORKPARAMS";
|
|
36
40
|
export const CANCELLED = "ECANCELLED";
|
|
37
41
|
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
/** Node's DNSException: a libuv errno (its name when the host gives it: libuv's for getaddrinfo's EAI_*;
|
|
43
|
+
* EAI_NODATA and EAI_NONAME are ENOTFOUND), or a c-ares code */
|
|
44
|
+
function dnsException(code, syscall, hostname, name = undefined) {
|
|
45
|
+
let errno;
|
|
46
|
+
if (typeof code === "number") {
|
|
47
|
+
errno = code;
|
|
48
|
+
code = name ?? errnoName(code);
|
|
49
|
+
if (code === "EAI_NODATA" || code === "EAI_NONAME") code = "ENOTFOUND";
|
|
50
|
+
}
|
|
51
|
+
const error = new Error(`${syscall} ${code}${hostname ? ` ${hostname}` : ""}`);
|
|
42
52
|
error.errno = errno;
|
|
43
53
|
error.code = code;
|
|
44
54
|
error.syscall = syscall;
|
|
@@ -46,61 +56,256 @@ function dnsException(errno, code, syscall, hostname) {
|
|
|
46
56
|
return error;
|
|
47
57
|
}
|
|
48
58
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
/* ---- validation (Node's internal/validators, as dns uses them) ------------------------------ */
|
|
60
|
+
|
|
61
|
+
const validDnsOrders = ["verbatim", "ipv4first", "ipv6first"];
|
|
62
|
+
const validFamilies = [0, 4, 6];
|
|
63
|
+
|
|
64
|
+
function validateOneOf(value, name, oneOf) {
|
|
65
|
+
if (!oneOf.includes(value)) {
|
|
66
|
+
const allowed = oneOf.map((v) => (typeof v === "string" ? `'${v}'` : String(v))).join(", ");
|
|
67
|
+
throw invalidArgValue(name, `must be one of: ${allowed}`, value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function validateBoolean(value, name) {
|
|
72
|
+
if (typeof value !== "boolean") throw invalidArgType(name, "of type boolean", value);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function validateStringWithoutNullBytes(value, name) {
|
|
76
|
+
validateString(value, name);
|
|
77
|
+
if (value.includes("\u0000")) throw invalidArgValue(name, "must be a string without null bytes", value);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
function validateHints(hints) {
|
|
82
|
+
if ((hints & ~(ADDRCONFIG | ALL | V4MAPPED)) !== 0) throw invalidArgValue("hints", "is invalid", hints);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let invalidHostnameWarningEmitted = false;
|
|
86
|
+
function emitInvalidHostnameWarning(hostname) {
|
|
87
|
+
if (invalidHostnameWarningEmitted) return;
|
|
88
|
+
process.emitWarning(`The provided hostname "${hostname}" is not a valid hostname, and is supported in the dns module solely for compatibility.`,
|
|
89
|
+
"DeprecationWarning", "DEP0118");
|
|
90
|
+
invalidHostnameWarningEmitted = true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let dnsOrder = "verbatim";
|
|
94
|
+
|
|
95
|
+
export function setDefaultResultOrder(value) {
|
|
96
|
+
validateOneOf(value, "dnsOrder", validDnsOrders);
|
|
97
|
+
dnsOrder = value;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function getDefaultResultOrder() {
|
|
101
|
+
return dnsOrder;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* ---- lookup and lookupService ------------------------------------------------------------- */
|
|
105
|
+
|
|
106
|
+
/* lookup's options → [family, all, hints, order] (Node's argument parsing) */
|
|
107
|
+
function lookupOptions(options) {
|
|
108
|
+
let family = 0, all = false, hints = 0, order = dnsOrder;
|
|
109
|
+
if (typeof options === "number") {
|
|
110
|
+
validateOneOf(options, "family", validFamilies);
|
|
111
|
+
return [options + 0, all, hints, order];
|
|
112
|
+
}
|
|
113
|
+
if (options?.hints != null) {
|
|
114
|
+
if (typeof options.hints !== "number") throw invalidArgType("options.hints", "of type number", options.hints);
|
|
115
|
+
hints = options.hints >>> 0;
|
|
116
|
+
validateHints(hints);
|
|
117
|
+
}
|
|
118
|
+
if (options?.family != null) {
|
|
119
|
+
if (options.family === "IPv4") family = 4;
|
|
120
|
+
else if (options.family === "IPv6") family = 6;
|
|
121
|
+
else {
|
|
122
|
+
validateOneOf(options.family, "options.family", validFamilies);
|
|
123
|
+
family = options.family + 0;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (options?.all != null) {
|
|
127
|
+
validateBoolean(options.all, "options.all");
|
|
128
|
+
all = options.all;
|
|
129
|
+
}
|
|
130
|
+
if (options?.verbatim != null) {
|
|
131
|
+
validateBoolean(options.verbatim, "options.verbatim");
|
|
132
|
+
order = options.verbatim ? "verbatim" : "ipv4first";
|
|
133
|
+
}
|
|
134
|
+
if (options?.order != null) {
|
|
135
|
+
validateOneOf(options.order, "options.order", validDnsOrders);
|
|
136
|
+
order = options.order;
|
|
137
|
+
}
|
|
138
|
+
return [family, all, hints, order];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* getaddrinfo's addresses in the order asked for (Node's sorts them in C, stably) */
|
|
142
|
+
function ordered(list, order) {
|
|
143
|
+
if (order === "verbatim") return list;
|
|
144
|
+
const first = order === "ipv4first" ? 4 : 6;
|
|
145
|
+
return [...list.filter(([, f]) => f === first), ...list.filter(([, f]) => f !== first)];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* getaddrinfo: done(error | null, [[address, family], …]); the hostname is neither empty nor an IP */
|
|
149
|
+
function getaddrinfo(hostname, family, order, done) {
|
|
150
|
+
const r = dnsLookup(hostname, family, bindContext((errno, code, list) => {
|
|
151
|
+
if (errno) done(dnsException(errno, "getaddrinfo", hostname, code));
|
|
152
|
+
else done(null, ordered(list, order));
|
|
153
|
+
}));
|
|
154
|
+
if (r < 0) process.nextTick(done, dnsException(r, "getaddrinfo", hostname));
|
|
54
155
|
}
|
|
55
156
|
|
|
56
157
|
/** lookup(hostname[, options | family], callback): callback(err, address, family), or with
|
|
57
158
|
* { all: true } callback(err, [{ address, family }, …]) */
|
|
58
159
|
export function lookup(hostname, options, callback) {
|
|
59
|
-
|
|
60
|
-
let all = false;
|
|
61
|
-
if (typeof hostname !== "string" && hostname) throw invalidArgType("hostname", "of type string", hostname);
|
|
160
|
+
if (hostname) validateStringWithoutNullBytes(hostname, "hostname");
|
|
62
161
|
if (typeof options === "function") {
|
|
63
162
|
callback = options;
|
|
163
|
+
options = undefined;
|
|
64
164
|
} else if (typeof options === "number") {
|
|
65
|
-
|
|
66
|
-
} else if (options !== undefined && options !==
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (typeof options.hints !== "number") throw invalidArgType("options.hints", "of type number", options.hints);
|
|
72
|
-
const hints = options.hints >>> 0;
|
|
73
|
-
if ((hints & ~(ADDRCONFIG | ALL | V4MAPPED)) !== 0) throw invalidArgValue("hints", "is invalid", hints);
|
|
74
|
-
}
|
|
165
|
+
validateFunction(callback, "callback");
|
|
166
|
+
} else if (options !== undefined && typeof options !== "object") {
|
|
167
|
+
validateFunction(arguments.length === 2 ? options : callback, "callback");
|
|
168
|
+
throw invalidArgType("options", "of type integer or an instance of Object", options);
|
|
169
|
+
} else {
|
|
170
|
+
validateFunction(callback, "callback");
|
|
75
171
|
}
|
|
76
|
-
|
|
172
|
+
const [family, all] = lookupOptions(options);
|
|
77
173
|
if (!hostname) {
|
|
78
|
-
|
|
174
|
+
emitInvalidHostnameWarning(hostname);
|
|
175
|
+
if (all) process.nextTick(callback, null, []);
|
|
176
|
+
else process.nextTick(callback, null, null, family === 6 ? 6 : 4);
|
|
79
177
|
return {};
|
|
80
178
|
}
|
|
81
179
|
const matched = isIP(hostname);
|
|
82
180
|
if (matched) {
|
|
83
|
-
process.nextTick(
|
|
181
|
+
if (all) process.nextTick(callback, null, [{ address: hostname, family: matched }]);
|
|
182
|
+
else process.nextTick(callback, null, hostname, matched);
|
|
84
183
|
return {};
|
|
85
184
|
}
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
else if (all) callback(null, list.map(([address,
|
|
185
|
+
getaddrinfo(hostname, family, lookupOptions(options)[3], (err, list) => {
|
|
186
|
+
if (err) callback(err);
|
|
187
|
+
else if (all) callback(null, list.map(([address, f]) => ({ address, family: f })));
|
|
89
188
|
else callback(null, list[0][0], list[0][1]);
|
|
189
|
+
});
|
|
190
|
+
return {};
|
|
191
|
+
}
|
|
192
|
+
Object.defineProperty(lookup, Symbol.for("nodejs.util.promisify.customArgs"), { value: ["address", "family"], enumerable: false });
|
|
193
|
+
|
|
194
|
+
function lookupServiceArgs(args, names) {
|
|
195
|
+
if (args.length !== names.length) {
|
|
196
|
+
const quoted = names.map((n) => `"${n}"`);
|
|
197
|
+
const list = quoted.length > 2 ? `${quoted.slice(0, -1).join(", ")}, and ${quoted.at(-1)}` : quoted.join(" and ");
|
|
198
|
+
throw codeError(TypeError, "ERR_MISSING_ARGS", `The ${list} arguments must be specified`);
|
|
199
|
+
}
|
|
200
|
+
const [address, port] = args;
|
|
201
|
+
validateString(address, "address");
|
|
202
|
+
if (isIP(address) === 0) throw invalidArgValue("address", "is invalid", address);
|
|
203
|
+
validatePort(port);
|
|
204
|
+
return [address, +port + 0];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/* getnameinfo: done(error | null, hostname, service) */
|
|
208
|
+
function getnameinfo(address, port, done) {
|
|
209
|
+
return dnsLookupService(address, port, bindContext((errno, hostname, service, code) => {
|
|
210
|
+
if (errno) done(dnsException(errno, "getnameinfo", address, code));
|
|
211
|
+
else done(null, hostname, service);
|
|
90
212
|
}));
|
|
91
|
-
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** lookupService(address, port, callback): callback(err, hostname, service) */
|
|
216
|
+
export function lookupService(address, port, callback) {
|
|
217
|
+
[address, port] = lookupServiceArgs(arguments, ["address", "port", "callback"]);
|
|
218
|
+
validateFunction(callback, "callback");
|
|
219
|
+
const err = getnameinfo(address, port, callback);
|
|
220
|
+
if (err) throw dnsException(err, "getnameinfo", address);
|
|
92
221
|
return {};
|
|
93
222
|
}
|
|
223
|
+
Object.defineProperty(lookupService, Symbol.for("nodejs.util.promisify.customArgs"), { value: ["hostname", "service"], enumerable: false });
|
|
94
224
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
225
|
+
/* ---- Resolver and the default resolver's functions (internal/dns_resolver.js) ---------------- */
|
|
226
|
+
|
|
227
|
+
export { Resolver };
|
|
228
|
+
|
|
229
|
+
const resolverFunction = (prefix, key) => {
|
|
230
|
+
const f = lazyFunction(`${prefix}${key}`, key === "getServers" ? 0 : 2);
|
|
231
|
+
Object.defineProperty(f, "name", { value: key });
|
|
232
|
+
return f;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
export const getServers = /* @__PURE__ */ resolverFunction("dns.", "getServers");
|
|
236
|
+
export const setServers = /* @__PURE__ */ resolverFunction("dns.", "setServers");
|
|
237
|
+
export const resolve = /* @__PURE__ */ resolverFunction("dns.", "resolve");
|
|
238
|
+
export const resolve4 = /* @__PURE__ */ resolverFunction("dns.", "resolve4");
|
|
239
|
+
export const resolve6 = /* @__PURE__ */ resolverFunction("dns.", "resolve6");
|
|
240
|
+
export const resolveAny = /* @__PURE__ */ resolverFunction("dns.", "resolveAny");
|
|
241
|
+
export const resolveCaa = /* @__PURE__ */ resolverFunction("dns.", "resolveCaa");
|
|
242
|
+
export const resolveCname = /* @__PURE__ */ resolverFunction("dns.", "resolveCname");
|
|
243
|
+
export const resolveMx = /* @__PURE__ */ resolverFunction("dns.", "resolveMx");
|
|
244
|
+
export const resolveNaptr = /* @__PURE__ */ resolverFunction("dns.", "resolveNaptr");
|
|
245
|
+
export const resolveNs = /* @__PURE__ */ resolverFunction("dns.", "resolveNs");
|
|
246
|
+
export const resolvePtr = /* @__PURE__ */ resolverFunction("dns.", "resolvePtr");
|
|
247
|
+
export const resolveSoa = /* @__PURE__ */ resolverFunction("dns.", "resolveSoa");
|
|
248
|
+
export const resolveSrv = /* @__PURE__ */ resolverFunction("dns.", "resolveSrv");
|
|
249
|
+
export const resolveTlsa = /* @__PURE__ */ resolverFunction("dns.", "resolveTlsa");
|
|
250
|
+
export const resolveTxt = /* @__PURE__ */ resolverFunction("dns.", "resolveTxt");
|
|
251
|
+
export const reverse = /* @__PURE__ */ resolverFunction("dns.", "reverse");
|
|
252
|
+
|
|
253
|
+
/* ---- dns.promises ------------------------------------------------------------------------------ */
|
|
254
|
+
|
|
255
|
+
const errorCodes = {
|
|
256
|
+
NODATA, FORMERR, SERVFAIL, NOTFOUND, NOTIMP, REFUSED, BADQUERY, BADNAME, BADFAMILY, BADRESP, CONNREFUSED, TIMEOUT, EOF, FILE, NOMEM,
|
|
257
|
+
DESTRUCTION, BADSTR, BADFLAGS, NONAME, BADHINTS, NOTINITIALIZED, LOADIPHLPAPI, ADDRGETNETWORKPARAMS, CANCELLED,
|
|
104
258
|
};
|
|
105
259
|
|
|
106
|
-
|
|
260
|
+
const resolverKeys = ["getServers", "setServers", "resolve", "resolve4", "resolve6", "resolveAny", "resolveCaa", "resolveCname", "resolveMx",
|
|
261
|
+
"resolveNaptr", "resolveNs", "resolvePtr", "resolveSoa", "resolveSrv", "resolveTlsa", "resolveTxt", "reverse"];
|
|
262
|
+
|
|
263
|
+
/* in a pure call, so a program that only looks names up drops the promise API */
|
|
264
|
+
export const promises = /* @__PURE__ */ (() => {
|
|
265
|
+
const promises = {
|
|
266
|
+
lookup(hostname, options) {
|
|
267
|
+
if (hostname) validateStringWithoutNullBytes(hostname, "hostname");
|
|
268
|
+
if (options !== undefined && typeof options !== "number" && typeof options !== "object") {
|
|
269
|
+
throw invalidArgType("options", "of type integer or an instance of Object", options);
|
|
270
|
+
}
|
|
271
|
+
const [family, all, , order] = lookupOptions(options);
|
|
272
|
+
return new Promise((resolvePromise, reject) => {
|
|
273
|
+
if (!hostname) {
|
|
274
|
+
emitInvalidHostnameWarning(hostname);
|
|
275
|
+
resolvePromise(all ? [] : { address: null, family: family === 6 ? 6 : 4 });
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const matched = isIP(hostname);
|
|
279
|
+
if (matched !== 0) {
|
|
280
|
+
const result = { address: hostname, family: matched };
|
|
281
|
+
resolvePromise(all ? [result] : result);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
getaddrinfo(hostname, family, order, (err, list) => {
|
|
285
|
+
if (err) reject(err);
|
|
286
|
+
else if (all) resolvePromise(list.map(([address, f]) => ({ address, family: f })));
|
|
287
|
+
else resolvePromise({ address: list[0][0], family: list[0][1] });
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
},
|
|
291
|
+
lookupService(address, port) {
|
|
292
|
+
[address, port] = lookupServiceArgs(arguments, ["address", "port"]);
|
|
293
|
+
return new Promise((resolvePromise, reject) => {
|
|
294
|
+
const err = getnameinfo(address, port, (e, hostname, service) => (e ? reject(e) : resolvePromise({ hostname, service })));
|
|
295
|
+
if (err) reject(dnsException(err, "getnameinfo", address));
|
|
296
|
+
});
|
|
297
|
+
},
|
|
298
|
+
Resolver: PromisesResolver,
|
|
299
|
+
getDefaultResultOrder,
|
|
300
|
+
setDefaultResultOrder,
|
|
301
|
+
...errorCodes,
|
|
302
|
+
};
|
|
303
|
+
for (const key of resolverKeys) promises[key] = resolverFunction("dns.promises.", key);
|
|
304
|
+
return promises;
|
|
305
|
+
})();
|
|
306
|
+
|
|
307
|
+
export default {
|
|
308
|
+
lookup, lookupService, Resolver, getDefaultResultOrder, setDefaultResultOrder, getServers, setServers, resolve, resolve4, resolve6,
|
|
309
|
+
resolveAny, resolveCaa, resolveCname, resolveMx, resolveNaptr, resolveNs, resolvePtr, resolveSoa, resolveSrv, resolveTlsa, resolveTxt,
|
|
310
|
+
reverse, ADDRCONFIG, V4MAPPED, ALL, ...errorCodes, promises,
|
|
311
|
+
};
|
|
@@ -3,8 +3,14 @@ import { promises } from "./dns.js";
|
|
|
3
3
|
|
|
4
4
|
export {
|
|
5
5
|
ADDRGETNETWORKPARAMS, BADFAMILY, BADFLAGS, BADHINTS, BADNAME, BADQUERY, BADRESP, BADSTR, CANCELLED, CONNREFUSED, DESTRUCTION, EOF, FILE,
|
|
6
|
-
FORMERR, LOADIPHLPAPI, NODATA, NOMEM, NONAME, NOTFOUND, NOTIMP, NOTINITIALIZED, REFUSED, SERVFAIL, TIMEOUT,
|
|
6
|
+
FORMERR, LOADIPHLPAPI, NODATA, NOMEM, NONAME, NOTFOUND, NOTIMP, NOTINITIALIZED, REFUSED, SERVFAIL, TIMEOUT, getDefaultResultOrder,
|
|
7
|
+
setDefaultResultOrder,
|
|
7
8
|
} from "./dns.js";
|
|
8
|
-
export
|
|
9
|
+
export { PromisesResolver as Resolver } from "./internal/dns_classes.js";
|
|
10
|
+
|
|
11
|
+
export const {
|
|
12
|
+
lookup, lookupService, getServers, setServers, resolve, resolve4, resolve6, resolveAny, resolveCaa, resolveCname, resolveMx, resolveNaptr,
|
|
13
|
+
resolveNs, resolvePtr, resolveSoa, resolveSrv, resolveTlsa, resolveTxt, reverse,
|
|
14
|
+
} = promises;
|
|
9
15
|
|
|
10
16
|
export default promises;
|
|
@@ -12,7 +12,15 @@ import { AbortError } from "./internal/streams/errors.js";
|
|
|
12
12
|
import { validateAbortSignal, validateBoolean } from "./internal/streams/validators.js";
|
|
13
13
|
import { resolve } from "./path.js";
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
/* done at once, settled on a later turn of the loop, as Node's run on its thread pool: what the
|
|
16
|
+
* caller's ticks and promise jobs do first (an abort) comes before */
|
|
17
|
+
const promised = (fn) => (...args) => new Promise((resolve, reject) => {
|
|
18
|
+
try {
|
|
19
|
+
setImmediate(resolve, fn(...args));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
setImmediate(reject, e);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
16
24
|
|
|
17
25
|
function checkAborted(signal) {
|
|
18
26
|
if (signal?.aborted) throw new AbortError(undefined, { cause: signal.reason });
|