mirror of
https://github.com/denoland/deno
synced 2024-10-30 06:43:53 +00:00
feat: stabilize Deno.resolveDns (#12368)
This commit is contained in:
parent
25771b3d9b
commit
29f9e14457
6 changed files with 88 additions and 95 deletions
|
@ -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",
|
||||
|
|
85
cli/dts/lib.deno.ns.d.ts
vendored
85
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -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[][]>;
|
||||
}
|
||||
|
|
86
cli/dts/lib.deno.unstable.d.ts
vendored
86
cli/dts/lib.deno.unstable.d.ts
vendored
|
@ -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. */
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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,
|
||||
_: (),
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue