Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 330b824

Browse files
author
exoego
committed
Overhaul dns module
1 parent a296edf commit 330b824

File tree

15 files changed

+271
-320
lines changed

15 files changed

+271
-320
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The following core Node.js modules (v8.7.0+) have been implemented:
2727
| [console](https://nodejs.org/api/console.html) | :heavy_check_mark: |
2828
| [crypto](https://nodejs.org/api/crypto.html) | :heavy_check_mark: |
2929
| [dgram](https://nodejs.org/api/dgram.html) | |
30-
| [dns](https://nodejs.org/api/dns.html) | |
30+
| [dns](https://nodejs.org/api/dns.html) | :heavy_check_mark: |
3131
| [events](https://nodejs.org/api/events.html) | |
3232
| [fs](https://nodejs.org/api/fs.html) | :heavy_check_mark: |
3333
| [http](https://nodejs.org/api/http.html) | |

app/current/src/main/scala/io/scalajs/nodejs/dns/DNS.scala

Lines changed: 7 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,7 @@ import scala.scalajs.js.|
1313
* @see https://nodejs.org/api/dns.html
1414
*/
1515
@js.native
16-
trait DNS extends js.Object {
17-
18-
/////////////////////////////////////////////////////////////////////////////////
19-
// Methods
20-
/////////////////////////////////////////////////////////////////////////////////
21-
22-
/**
23-
* Returns an array of IP address strings that are being used for name resolution.
24-
*/
25-
def getServers(): js.Array[String] = js.native
16+
trait DNS extends IResolver {
2617

2718
/**
2819
* Resolves a hostname (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. options can be an
@@ -42,7 +33,7 @@ trait DNS extends js.Object {
4233
* All properties are optional.
4334
* @example dns.lookup(hostname[, options], callback)
4435
*/
45-
def lookup(hostname: String, options: DnsOptions | Int, callback: DnsCallback1[String]): Unit = js.native
36+
def lookup(hostname: String, options: DnsOptions | Int, callback: DnsCallback2[String, Int]): Unit = js.native
4637

4738
/**
4839
* Resolves a hostname (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. options can be an
@@ -79,156 +70,6 @@ trait DNS extends js.Object {
7970
* @example dns.lookupService('127.0.0.1', 22, (err, hostname, service) => { ... })
8071
*/
8172
def lookupService(address: String, port: Int, callback: DnsCallback2[String, String]): Unit = js.native
82-
83-
/**
84-
* Uses the DNS protocol to resolve a hostname (e.g. 'nodejs.org') into an array of the record types specified by rrtype.
85-
* On error, err is an Error object, where err.code is one of the error codes listed here.
86-
* @param hostname the hostname
87-
* @param rrtype the given rrtype
88-
* Valid values for rrtype are:
89-
* 'A' - IPV4 addresses, default
90-
* 'AAAA' - IPV6 addresses
91-
* 'MX' - mail exchange records
92-
* 'TXT' - text records
93-
* 'SRV' - SRV records
94-
* 'PTR' - PTR records
95-
* 'NS' - name server records
96-
* 'CNAME' - canonical name records
97-
* 'SOA' - start of authority record
98-
* 'NAPTR' - name authority pointer record
99-
* @param callback the callback function has arguments (err, addresses). When successful, addresses will be an array.
100-
* The type of each item in addresses is determined by the record type, and described in the
101-
* documentation for the corresponding lookup methods.
102-
* @example dns.resolve(hostname[, rrtype], callback)
103-
*/
104-
def resolve[A](hostname: String, rrtype: RRType, callback: DnsCallback1[A]): Unit = js.native
105-
106-
/**
107-
* Uses the DNS protocol to resolve a hostname (e.g. 'nodejs.org') into an array of the record types specified by rrtype.
108-
* On error, err is an Error object, where err.code is one of the error codes listed here.
109-
* @param hostname the hostname
110-
* @param callback the callback function has arguments (err, addresses). When successful, addresses will be an array. The type of
111-
* each item in addresses is determined by the record type, and described in the documentation for the corresponding
112-
* lookup methods.
113-
* @example dns.resolve(hostname[, rrtype], callback)
114-
*/
115-
def resolve(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native
116-
117-
/**
118-
* Uses the DNS protocol to resolve a IPv4 addresses (A records) for the hostname. The addresses argument passed to
119-
* the callback function will contain an array of IPv4 addresses (e.g. ['74.125.79.104', '74.125.79.105', '74.125.79.106']).
120-
* @example dns.resolve4(hostname, callback)
121-
*/
122-
def resolve4(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native
123-
124-
/**
125-
* Uses the DNS protocol to resolve a IPv6 addresses (AAAA records) for the hostname. The addresses argument passed
126-
* to the callback function will contain an array of IPv6 addresses.
127-
* @example dns.resolve6(hostname, callback)
128-
*/
129-
def resolve6(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native
130-
131-
/**
132-
* Uses the DNS protocol to resolve CNAME records for the hostname. The addresses argument passed to the callback
133-
* function will contain an array of canonical name records available for the hostname (e.g. ['bar.example.com']).
134-
* @example dns.resolveCname(hostname, callback)
135-
*/
136-
def resolveCname(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native
137-
138-
/**
139-
* Uses the DNS protocol to resolve mail exchange records (MX records) for the hostname. The addresses argument
140-
* passed to the callback function will contain an array of objects containing both a priority and exchange property
141-
* (e.g. [{priority: 10, exchange: 'mx.example.com'}, ...]).
142-
* @example dns.resolveMx(hostname, callback)
143-
*/
144-
def resolveMx(hostname: String, callback: DnsCallback1[MX]): Unit = js.native
145-
146-
/**
147-
* Uses the DNS protocol to resolve regular expression based records (NAPTR records) for the hostname. The callback
148-
* function has arguments (err, addresses). The addresses argument passed to the callback function will contain an
149-
* array of objects with the following properties:
150-
* <ul>
151-
* <li>flags</li>
152-
* <li>service</li>
153-
* <li>regexp</li>
154-
* <li>replacement</li>
155-
* <li>order</li>
156-
* <li>preference</li>
157-
* </ul>
158-
* @example dns.resolveNaptr(hostname, callback)
159-
*/
160-
def resolveNaptr(hostname: String, callback: DnsCallback1[NAPTR]): Unit = js.native
161-
162-
/**
163-
* Uses the DNS protocol to resolve name server records (NS records) for the hostname. The addresses argument passed
164-
* to the callback function will contain an array of name server records available for hostname
165-
* (e.g., ['ns1.example.com', 'ns2.example.com']).
166-
* @example dns.resolveNs(hostname, callback)
167-
*/
168-
def resolveNs(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native
169-
170-
/**
171-
* Uses the DNS protocol to resolve a start of authority record (SOA record) for the hostname. The addresses argument
172-
* passed to the callback function will be an object with the following properties:
173-
* <ul>
174-
* <li>nsname</li>
175-
* <li>hostmaster</li>
176-
* <li>serial</li>
177-
* <li>refresh</li>
178-
* <li>retry</li>
179-
* <li>expire</li>
180-
* <li>minttl</li>
181-
* </ul>
182-
* @example dns.resolveSoa(hostname, callback)
183-
*/
184-
def resolveSoa(hostname: String, callback: DnsCallback1[SOA]): Unit = js.native
185-
186-
/**
187-
* Uses the DNS protocol to resolve service records (SRV records) for the hostname. The addresses argument passed to
188-
* the callback function will be an array of objects with the following properties:
189-
* <ul>
190-
* <li>priority</li>
191-
* <li>weight</li>
192-
* <li>port</li>
193-
* <li>name</li>
194-
* </ul>
195-
* @example dns.resolveSrv(hostname, callback)
196-
*/
197-
def resolveSrv(hostname: String, callback: DnsCallback1[SRV]): Unit = js.native
198-
199-
/**
200-
* Uses the DNS protocol to resolve pointer records (PTR records) for the hostname. The addresses argument passed to
201-
* the callback function will be an array of strings containing the reply records.
202-
* @example dns.resolvePtr(hostname, callback)
203-
*/
204-
def resolvePtr(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native
205-
206-
/**
207-
* Uses the DNS protocol to resolve text queries (TXT records) for the hostname. The addresses argument passed to the
208-
* callback function is is a two-dimentional array of the text records available for hostname
209-
* (e.g., [ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]). Each sub-array contains TXT chunks of one record. Depending on the
210-
* use case, these could be either joined together or treated separately.
211-
* @example dns.resolveTxt(hostname, callback)
212-
*/
213-
def resolveTxt(hostname: String, callback: DnsCallback1[js.Array[js.Array[String]]]): Unit = js.native
214-
215-
/**
216-
* Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an array of hostnames.
217-
* The callback function has arguments (err, hostnames), where hostnames is an array of resolved hostnames for the given ip.
218-
* On error, err is an Error object, where err.code is one of the DNS error codes.
219-
* @example dns.reverse(ip, callback)
220-
*/
221-
def reverse(ipAddress: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native
222-
223-
/**
224-
* Sets the IP addresses of the servers to be used when resolving. The servers argument is an array of IPv4 or IPv6 addresses.
225-
* If a port specified on the address it will be removed.
226-
* An error will be thrown if an invalid address is provided.
227-
* The dns.setServers() method must not be called while a DNS query is in progress.
228-
* @example dns.setServers(servers)
229-
*/
230-
def setServers(servers: js.Array[String]): Unit = js.native
231-
23273
}
23374

23475
/**
@@ -238,6 +79,11 @@ trait DNS extends js.Object {
23879
@JSImport("dns", JSImport.Namespace)
23980
object DNS extends DNS {
24081

82+
@js.native
83+
object promises extends js.Object {
84+
type Resolver = PromisesResolver
85+
}
86+
24187
/////////////////////////////////////////////////////////////////////////////////
24288
// Error Codes
24389
/////////////////////////////////////////////////////////////////////////////////

app/current/src/main/scala/io/scalajs/nodejs/dns/DnsOptions.scala

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@ package io.scalajs.nodejs.dns
22

33
import scala.scalajs.js
44

5-
/**
6-
* DNS Options
7-
* @param family The record family. If present, must be the integer 4 or 6. If not provided, both IP v4
8-
* and v6 addresses are accepted.
9-
* @param hints If present, it should be one or more of the supported getaddrinfo flags. If hints is not
10-
* provided, then no flags are passed to getaddrinfo. Multiple flags can be passed through hints by logically
11-
* ORing their values. See supported getaddrinfo flags for more information on supported flags.</li>
12-
* @param all When true, the callback returns all resolved addresses in an array, otherwise returns a
13-
* single address. Defaults to false.
14-
*/
155
class DnsOptions(var family: js.UndefOr[Int] = js.undefined,
166
var hints: js.UndefOr[Int] = js.undefined,
17-
var all: js.UndefOr[Boolean] = js.undefined)
7+
var all: js.UndefOr[Boolean] = js.undefined,
8+
var verbatim: js.UndefOr[Boolean] = js.undefined)
189
extends js.Object

app/current/src/main/scala/io/scalajs/nodejs/dns/MX.scala

Lines changed: 0 additions & 18 deletions
This file was deleted.

app/current/src/main/scala/io/scalajs/nodejs/dns/NAPTR.scala

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.scalajs.nodejs.dns
2+
3+
import com.thoughtworks.enableMembersIf
4+
5+
import scala.scalajs.js
6+
import scala.scalajs.js.annotation.JSImport
7+
8+
@js.native
9+
@enableMembersIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs10)
10+
@JSImport("dns", "promises.Resolver")
11+
class PromisesResolver extends js.Object {
12+
def getServers(): js.Array[String] = js.native
13+
def setServers(servers: js.Array[String]): Unit = js.native
14+
15+
def resolve(hostname: String, rrtype: RRType): js.Promise[ResolveResult] = js.native
16+
def resolve(hostname: String): js.Promise[js.Array[String]] = js.native
17+
def resolve4(hostname: String, options: TtlOptions = js.native): js.Promise[js.Array[String]] = js.native
18+
def resolve6(hostname: String, options: TtlOptions = js.native): js.Promise[js.Array[String]] = js.native
19+
def resolveAny(hostname: String): js.Promise[js.Array[ResolveObject]] = js.native
20+
def resolveCname(hostname: String): js.Promise[js.Array[String]] = js.native
21+
def resolveMx(hostname: String): js.Promise[js.Array[MX]] = js.native
22+
def resolveNaptr(hostname: String): js.Promise[js.Array[NAPTR]] = js.native
23+
def resolveNs(hostname: String): js.Promise[js.Array[String]] = js.native
24+
def resolveSoa(hostname: String): js.Promise[js.Array[SOA]] = js.native
25+
def resolveSrv(hostname: String): js.Promise[js.Array[SRV]] = js.native
26+
def resolvePtr(hostname: String): js.Promise[js.Array[String]] = js.native
27+
def resolveTxt(hostname: String): js.Promise[js.Array[String]] = js.native
28+
def reverse(ipAddress: String): js.Promise[js.Array[String]] = js.native
29+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package io.scalajs.nodejs.dns
2+
3+
import scala.scalajs.js
4+
5+
@js.native
6+
sealed trait ResolveObject extends js.Object {}
7+
8+
@js.native
9+
trait AddressTtl extends ResolveObject {
10+
val address: String = js.native
11+
val ttl: Int = js.native
12+
}
13+
14+
@js.native
15+
trait ValueOnly extends ResolveObject {
16+
val value: String = js.native
17+
}
18+
19+
@js.native
20+
trait MX extends ResolveObject {
21+
val priority: Int = js.native
22+
val exchange: String = js.native
23+
}
24+
25+
@js.native
26+
trait NAPTR extends ResolveObject {
27+
val flags: String = js.native
28+
val service: String = js.native
29+
val regexp: String = js.native
30+
val replacement: String = js.native
31+
val order: Int = js.native
32+
val preference: Int = js.native
33+
}
34+
35+
@js.native
36+
trait SOA extends ResolveObject {
37+
val nsname: String = js.native
38+
val hostmaster: String = js.native
39+
val serial: Int = js.native
40+
val refresh: Int = js.native
41+
val retry: Int = js.native
42+
val expire: Int = js.native
43+
val minttl: Int = js.native
44+
}
45+
46+
@js.native
47+
trait SRV extends ResolveObject {
48+
val name: String = js.native
49+
val priority: Int = js.native
50+
val port: Int = js.native
51+
val weight: Int = js.native
52+
}
53+
54+
@js.native
55+
trait TXT extends ResolveObject {
56+
val `type`: String = js.native
57+
val entires: js.Array[js.Array[String]] = js.native
58+
}

0 commit comments

Comments
 (0)