summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2021-10-10 15:46:11 +0530
committerGitHub <noreply@github.com>2021-10-10 15:46:11 +0530
commit29f9e14457998085ec38cce597558d88b3d804e7 (patch)
treeb437b5aa1d629490599c2eee4c3088f6877ae6d0
parent25771b3d9b36a7262d42809bfbb5497ed8057780 (diff)
feat: stabilize Deno.resolveDns (#12368)
-rw-r--r--cli/diagnostics.rs2
-rw-r--r--cli/dts/lib.deno.ns.d.ts85
-rw-r--r--cli/dts/lib.deno.unstable.d.ts86
-rw-r--r--cli/tests/integration/mod.rs4
-rw-r--r--ext/net/ops.rs4
-rw-r--r--runtime/js/90_deno_ns.js2
6 files changed, 88 insertions, 95 deletions
diff --git a/cli/diagnostics.rs b/cli/diagnostics.rs
index 260f3a53d..459475117 100644
--- a/cli/diagnostics.rs
+++ b/cli/diagnostics.rs
@@ -30,7 +30,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
"Metrics",
"OpMetrics",
"RecordType",
- "ResolveDnsOptions",
"SRVRecord",
"SetRawOptions",
"SignalStream",
@@ -54,7 +53,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
"dlopen",
"osRelease",
"ppid",
- "resolveDns",
"setRaw",
"shutdown",
"Signal",
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts
index 4bd0b1fdc..35d02776e 100644
--- a/cli/dts/lib.deno.ns.d.ts
+++ b/cli/dts/lib.deno.ns.d.ts
@@ -2480,4 +2480,89 @@ declare namespace Deno {
request: Request,
options?: UpgradeWebSocketOptions,
): WebSocketUpgrade;
+
+ /** The type of the resource record.
+ * Only the listed types are supported currently. */
+ export type RecordType =
+ | "A"
+ | "AAAA"
+ | "ANAME"
+ | "CNAME"
+ | "MX"
+ | "PTR"
+ | "SRV"
+ | "TXT";
+
+ export interface ResolveDnsOptions {
+ /** The name server to be used for lookups.
+ * If not specified, defaults to the system configuration e.g. `/etc/resolv.conf` on Unix. */
+ nameServer?: {
+ /** The IP address of the name server */
+ ipAddr: string;
+ /** The port number the query will be sent to.
+ * If not specified, defaults to 53. */
+ port?: number;
+ };
+ }
+
+ /** If `resolveDns` is called with "MX" record type specified, it will return an array of this interface. */
+ export interface MXRecord {
+ preference: number;
+ exchange: string;
+ }
+
+ /** If `resolveDns` is called with "SRV" record type specified, it will return an array of this interface. */
+ export interface SRVRecord {
+ priority: number;
+ weight: number;
+ port: number;
+ target: string;
+ }
+
+ export function resolveDns(
+ query: string,
+ recordType: "A" | "AAAA" | "ANAME" | "CNAME" | "PTR",
+ options?: ResolveDnsOptions,
+ ): Promise<string[]>;
+
+ export function resolveDns(
+ query: string,
+ recordType: "MX",
+ options?: ResolveDnsOptions,
+ ): Promise<MXRecord[]>;
+
+ export function resolveDns(
+ query: string,
+ recordType: "SRV",
+ options?: ResolveDnsOptions,
+ ): Promise<SRVRecord[]>;
+
+ export function resolveDns(
+ query: string,
+ recordType: "TXT",
+ options?: ResolveDnsOptions,
+ ): Promise<string[][]>;
+
+ /**
+ * Performs DNS resolution against the given query, returning resolved records.
+ * Fails in the cases such as:
+ * - the query is in invalid format
+ * - the options have an invalid parameter, e.g. `nameServer.port` is beyond the range of 16-bit unsigned integer
+ * - timed out
+ *
+ * ```ts
+ * const a = await Deno.resolveDns("example.com", "A");
+ *
+ * const aaaa = await Deno.resolveDns("example.com", "AAAA", {
+ * nameServer: { ipAddr: "8.8.8.8", port: 53 },
+ * });
+ * ```
+ *
+ * Requires `allow-net` permission.
+ */
+ export function resolveDns(
+ query: string,
+ recordType: RecordType,
+ options?: ResolveDnsOptions,
+ ): Promise<string[] | MXRecord[] | SRVRecord[] | string[][]>;
}
diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts
index 763393e50..a024713a8 100644
--- a/cli/dts/lib.deno.unstable.d.ts
+++ b/cli/dts/lib.deno.unstable.d.ts
@@ -1014,92 +1014,6 @@ declare namespace Deno {
};
}
- /** The type of the resource record.
- * Only the listed types are supported currently. */
- export type RecordType =
- | "A"
- | "AAAA"
- | "ANAME"
- | "CNAME"
- | "MX"
- | "PTR"
- | "SRV"
- | "TXT";
-
- export interface ResolveDnsOptions {
- /** The name server to be used for lookups.
- * If not specified, defaults to the system configuration e.g. `/etc/resolv.conf` on Unix. */
- nameServer?: {
- /** The IP address of the name server */
- ipAddr: string;
- /** The port number the query will be sent to.
- * If not specified, defaults to 53. */
- port?: number;
- };
- }
-
- /** If `resolveDns` is called with "MX" record type specified, it will return an array of this interface. */
- export interface MXRecord {
- preference: number;
- exchange: string;
- }
-
- /** If `resolveDns` is called with "SRV" record type specified, it will return an array of this interface. */
- export interface SRVRecord {
- priority: number;
- weight: number;
- port: number;
- target: string;
- }
-
- export function resolveDns(
- query: string,
- recordType: "A" | "AAAA" | "ANAME" | "CNAME" | "PTR",
- options?: ResolveDnsOptions,
- ): Promise<string[]>;
-
- export function resolveDns(
- query: string,
- recordType: "MX",
- options?: ResolveDnsOptions,
- ): Promise<MXRecord[]>;
-
- export function resolveDns(
- query: string,
- recordType: "SRV",
- options?: ResolveDnsOptions,
- ): Promise<SRVRecord[]>;
-
- export function resolveDns(
- query: string,
- recordType: "TXT",
- options?: ResolveDnsOptions,
- ): Promise<string[][]>;
-
- /** ** UNSTABLE**: new API, yet to be vetted.
- *
- * Performs DNS resolution against the given query, returning resolved records.
- * Fails in the cases such as:
- * - the query is in invalid format
- * - the options have an invalid parameter, e.g. `nameServer.port` is beyond the range of 16-bit unsigned integer
- * - timed out
- *
- * ```ts
- * const a = await Deno.resolveDns("example.com", "A");
- *
- * const aaaa = await Deno.resolveDns("example.com", "AAAA", {
- * nameServer: { ipAddr: "8.8.8.8", port: 1234 },
- * });
- * ```
- *
- * Requires `allow-net` permission.
- */
- export function resolveDns(
- query: string,
- recordType: RecordType,
- options?: ResolveDnsOptions,
- ): Promise<string[] | MXRecord[] | SRVRecord[] | string[][]>;
-
/** **UNSTABLE**: new API, yet to be vetted.
*
* A generic transport listener for message-oriented protocols. */
diff --git a/cli/tests/integration/mod.rs b/cli/tests/integration/mod.rs
index 65a8a7516..251fca515 100644
--- a/cli/tests/integration/mod.rs
+++ b/cli/tests/integration/mod.rs
@@ -925,7 +925,6 @@ async fn test_resolve_dns() {
.env("NO_COLOR", "1")
.arg("run")
.arg("--allow-net")
- .arg("--unstable")
.arg("resolve_dns.ts")
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
@@ -951,7 +950,6 @@ async fn test_resolve_dns() {
.env("NO_COLOR", "1")
.arg("run")
.arg("--allow-net=127.0.0.1:4553")
- .arg("--unstable")
.arg("resolve_dns.ts")
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
@@ -977,7 +975,6 @@ async fn test_resolve_dns() {
.env("NO_COLOR", "1")
.arg("run")
.arg("--allow-net=deno.land")
- .arg("--unstable")
.arg("resolve_dns.ts")
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
@@ -999,7 +996,6 @@ async fn test_resolve_dns() {
.current_dir(util::testdata_path())
.env("NO_COLOR", "1")
.arg("run")
- .arg("--unstable")
.arg("resolve_dns.ts")
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
diff --git a/ext/net/ops.rs b/ext/net/ops.rs
index 43a562e0f..8c8d32da5 100644
--- a/ext/net/ops.rs
+++ b/ext/net/ops.rs
@@ -538,7 +538,7 @@ where
#[derive(Serialize, PartialEq, Debug)]
#[serde(untagged)]
-enum DnsReturnRecord {
+pub enum DnsReturnRecord {
A(String),
Aaaa(String),
Aname(String),
@@ -583,7 +583,7 @@ pub struct NameServer {
port: u16,
}
-async fn op_dns_resolve<NP>(
+pub async fn op_dns_resolve<NP>(
state: Rc<RefCell<OpState>>,
args: ResolveAddrArgs,
_: (),
diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js
index 177a0dea0..ddc18d425 100644
--- a/runtime/js/90_deno_ns.js
+++ b/runtime/js/90_deno_ns.js
@@ -102,6 +102,7 @@
Permissions: __bootstrap.permissions.Permissions,
PermissionStatus: __bootstrap.permissions.PermissionStatus,
serveHttp: __bootstrap.http.serveHttp,
+ resolveDns: __bootstrap.net.resolveDns,
upgradeWebSocket: __bootstrap.http.upgradeWebSocket,
};
@@ -121,7 +122,6 @@
applySourceMap: __bootstrap.errorStack.opApplySourceMap,
formatDiagnostics: __bootstrap.errorStack.opFormatDiagnostics,
sleepSync: __bootstrap.timers.sleepSync,
- resolveDns: __bootstrap.net.resolveDns,
listen: __bootstrap.netUnstable.listen,
connect: __bootstrap.netUnstable.connect,
listenDatagram: __bootstrap.netUnstable.listenDatagram,