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

Overhaul dns module #69

Merged
merged 1 commit into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The following core Node.js modules (v8.7.0+) have been implemented:
| [console](https://nodejs.org/api/console.html) | :heavy_check_mark: |
| [crypto](https://nodejs.org/api/crypto.html) | :heavy_check_mark: |
| [dgram](https://nodejs.org/api/dgram.html) | |
| [dns](https://nodejs.org/api/dns.html) | |
| [dns](https://nodejs.org/api/dns.html) | :heavy_check_mark: |
| [events](https://nodejs.org/api/events.html) | |
| [fs](https://nodejs.org/api/fs.html) | :heavy_check_mark: |
| [http](https://nodejs.org/api/http.html) | |
Expand Down
168 changes: 7 additions & 161 deletions app/current/src/main/scala/io/scalajs/nodejs/dns/DNS.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ import scala.scalajs.js.|
* @see https://nodejs.org/api/dns.html
*/
@js.native
trait DNS extends js.Object {

/////////////////////////////////////////////////////////////////////////////////
// Methods
/////////////////////////////////////////////////////////////////////////////////

/**
* Returns an array of IP address strings that are being used for name resolution.
*/
def getServers(): js.Array[String] = js.native
trait DNS extends IResolver {

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

/**
* Resolves a hostname (e.g. 'nodejs.org') into the first found A (IPv4) or AAAA (IPv6) record. options can be an
Expand Down Expand Up @@ -79,156 +70,6 @@ trait DNS extends js.Object {
* @example dns.lookupService('127.0.0.1', 22, (err, hostname, service) => { ... })
*/
def lookupService(address: String, port: Int, callback: DnsCallback2[String, String]): Unit = js.native

/**
* Uses the DNS protocol to resolve a hostname (e.g. 'nodejs.org') into an array of the record types specified by rrtype.
* On error, err is an Error object, where err.code is one of the error codes listed here.
* @param hostname the hostname
* @param rrtype the given rrtype
* Valid values for rrtype are:
* 'A' - IPV4 addresses, default
* 'AAAA' - IPV6 addresses
* 'MX' - mail exchange records
* 'TXT' - text records
* 'SRV' - SRV records
* 'PTR' - PTR records
* 'NS' - name server records
* 'CNAME' - canonical name records
* 'SOA' - start of authority record
* 'NAPTR' - name authority pointer record
* @param callback the callback function has arguments (err, addresses). When successful, addresses will be an array.
* The type of each item in addresses is determined by the record type, and described in the
* documentation for the corresponding lookup methods.
* @example dns.resolve(hostname[, rrtype], callback)
*/
def resolve[A](hostname: String, rrtype: RRType, callback: DnsCallback1[A]): Unit = js.native

/**
* Uses the DNS protocol to resolve a hostname (e.g. 'nodejs.org') into an array of the record types specified by rrtype.
* On error, err is an Error object, where err.code is one of the error codes listed here.
* @param hostname the hostname
* @param callback the callback function has arguments (err, addresses). When successful, addresses will be an array. The type of
* each item in addresses is determined by the record type, and described in the documentation for the corresponding
* lookup methods.
* @example dns.resolve(hostname[, rrtype], callback)
*/
def resolve(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native

/**
* Uses the DNS protocol to resolve a IPv4 addresses (A records) for the hostname. The addresses argument passed to
* the callback function will contain an array of IPv4 addresses (e.g. ['74.125.79.104', '74.125.79.105', '74.125.79.106']).
* @example dns.resolve4(hostname, callback)
*/
def resolve4(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native

/**
* Uses the DNS protocol to resolve a IPv6 addresses (AAAA records) for the hostname. The addresses argument passed
* to the callback function will contain an array of IPv6 addresses.
* @example dns.resolve6(hostname, callback)
*/
def resolve6(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native

/**
* Uses the DNS protocol to resolve CNAME records for the hostname. The addresses argument passed to the callback
* function will contain an array of canonical name records available for the hostname (e.g. ['bar.example.com']).
* @example dns.resolveCname(hostname, callback)
*/
def resolveCname(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native

/**
* Uses the DNS protocol to resolve mail exchange records (MX records) for the hostname. The addresses argument
* passed to the callback function will contain an array of objects containing both a priority and exchange property
* (e.g. [{priority: 10, exchange: 'mx.example.com'}, ...]).
* @example dns.resolveMx(hostname, callback)
*/
def resolveMx(hostname: String, callback: DnsCallback1[MX]): Unit = js.native

/**
* Uses the DNS protocol to resolve regular expression based records (NAPTR records) for the hostname. The callback
* function has arguments (err, addresses). The addresses argument passed to the callback function will contain an
* array of objects with the following properties:
* <ul>
* <li>flags</li>
* <li>service</li>
* <li>regexp</li>
* <li>replacement</li>
* <li>order</li>
* <li>preference</li>
* </ul>
* @example dns.resolveNaptr(hostname, callback)
*/
def resolveNaptr(hostname: String, callback: DnsCallback1[NAPTR]): Unit = js.native

/**
* Uses the DNS protocol to resolve name server records (NS records) for the hostname. The addresses argument passed
* to the callback function will contain an array of name server records available for hostname
* (e.g., ['ns1.example.com', 'ns2.example.com']).
* @example dns.resolveNs(hostname, callback)
*/
def resolveNs(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native

/**
* Uses the DNS protocol to resolve a start of authority record (SOA record) for the hostname. The addresses argument
* passed to the callback function will be an object with the following properties:
* <ul>
* <li>nsname</li>
* <li>hostmaster</li>
* <li>serial</li>
* <li>refresh</li>
* <li>retry</li>
* <li>expire</li>
* <li>minttl</li>
* </ul>
* @example dns.resolveSoa(hostname, callback)
*/
def resolveSoa(hostname: String, callback: DnsCallback1[SOA]): Unit = js.native

/**
* Uses the DNS protocol to resolve service records (SRV records) for the hostname. The addresses argument passed to
* the callback function will be an array of objects with the following properties:
* <ul>
* <li>priority</li>
* <li>weight</li>
* <li>port</li>
* <li>name</li>
* </ul>
* @example dns.resolveSrv(hostname, callback)
*/
def resolveSrv(hostname: String, callback: DnsCallback1[SRV]): Unit = js.native

/**
* Uses the DNS protocol to resolve pointer records (PTR records) for the hostname. The addresses argument passed to
* the callback function will be an array of strings containing the reply records.
* @example dns.resolvePtr(hostname, callback)
*/
def resolvePtr(hostname: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native

/**
* Uses the DNS protocol to resolve text queries (TXT records) for the hostname. The addresses argument passed to the
* callback function is is a two-dimentional array of the text records available for hostname
* (e.g., [ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]). Each sub-array contains TXT chunks of one record. Depending on the
* use case, these could be either joined together or treated separately.
* @example dns.resolveTxt(hostname, callback)
*/
def resolveTxt(hostname: String, callback: DnsCallback1[js.Array[js.Array[String]]]): Unit = js.native

/**
* Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an array of hostnames.
* The callback function has arguments (err, hostnames), where hostnames is an array of resolved hostnames for the given ip.
* On error, err is an Error object, where err.code is one of the DNS error codes.
* @example dns.reverse(ip, callback)
*/
def reverse(ipAddress: String, callback: DnsCallback1[js.Array[String]]): Unit = js.native

/**
* Sets the IP addresses of the servers to be used when resolving. The servers argument is an array of IPv4 or IPv6 addresses.
* If a port specified on the address it will be removed.
* An error will be thrown if an invalid address is provided.
* The dns.setServers() method must not be called while a DNS query is in progress.
* @example dns.setServers(servers)
*/
def setServers(servers: js.Array[String]): Unit = js.native

}

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

@js.native
object promises extends js.Object {
type Resolver = PromisesResolver
}

/////////////////////////////////////////////////////////////////////////////////
// Error Codes
/////////////////////////////////////////////////////////////////////////////////
Expand Down
13 changes: 2 additions & 11 deletions app/current/src/main/scala/io/scalajs/nodejs/dns/DnsOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,8 @@ package io.scalajs.nodejs.dns

import scala.scalajs.js

/**
* DNS Options
* @param family The record family. If present, must be the integer 4 or 6. If not provided, both IP v4
* and v6 addresses are accepted.
* @param hints If present, it should be one or more of the supported getaddrinfo flags. If hints is not
* provided, then no flags are passed to getaddrinfo. Multiple flags can be passed through hints by logically
* ORing their values. See supported getaddrinfo flags for more information on supported flags.</li>
* @param all When true, the callback returns all resolved addresses in an array, otherwise returns a
* single address. Defaults to false.
*/
class DnsOptions(var family: js.UndefOr[Int] = js.undefined,
var hints: js.UndefOr[Int] = js.undefined,
var all: js.UndefOr[Boolean] = js.undefined)
var all: js.UndefOr[Boolean] = js.undefined,
var verbatim: js.UndefOr[Boolean] = js.undefined)
extends js.Object
18 changes: 0 additions & 18 deletions app/current/src/main/scala/io/scalajs/nodejs/dns/MX.scala

This file was deleted.

26 changes: 0 additions & 26 deletions app/current/src/main/scala/io/scalajs/nodejs/dns/NAPTR.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.scalajs.nodejs.dns

import com.thoughtworks.enableMembersIf

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@enableMembersIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs10)
@JSImport("dns", "promises.Resolver")
class PromisesResolver extends js.Object {
def getServers(): js.Array[String] = js.native
def setServers(servers: js.Array[String]): Unit = js.native

def resolve(hostname: String, rrtype: RRType): js.Promise[ResolveResult] = js.native
def resolve(hostname: String): js.Promise[js.Array[String]] = js.native
def resolve4(hostname: String, options: TtlOptions = js.native): js.Promise[js.Array[String]] = js.native
def resolve6(hostname: String, options: TtlOptions = js.native): js.Promise[js.Array[String]] = js.native
def resolveAny(hostname: String): js.Promise[js.Array[ResolveObject]] = js.native
def resolveCname(hostname: String): js.Promise[js.Array[String]] = js.native
def resolveMx(hostname: String): js.Promise[js.Array[MX]] = js.native
def resolveNaptr(hostname: String): js.Promise[js.Array[NAPTR]] = js.native
def resolveNs(hostname: String): js.Promise[js.Array[String]] = js.native
def resolveSoa(hostname: String): js.Promise[js.Array[SOA]] = js.native
def resolveSrv(hostname: String): js.Promise[js.Array[SRV]] = js.native
def resolvePtr(hostname: String): js.Promise[js.Array[String]] = js.native
def resolveTxt(hostname: String): js.Promise[js.Array[String]] = js.native
def reverse(ipAddress: String): js.Promise[js.Array[String]] = js.native
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.scalajs.nodejs.dns

import scala.scalajs.js

@js.native
sealed trait ResolveObject extends js.Object {}

@js.native
trait AddressTtl extends ResolveObject {
val address: String = js.native
val ttl: Int = js.native
}

@js.native
trait ValueOnly extends ResolveObject {
val value: String = js.native
}

@js.native
trait MX extends ResolveObject {
val priority: Int = js.native
val exchange: String = js.native
}

@js.native
trait NAPTR extends ResolveObject {
val flags: String = js.native
val service: String = js.native
val regexp: String = js.native
val replacement: String = js.native
val order: Int = js.native
val preference: Int = js.native
}

@js.native
trait SOA extends ResolveObject {
val nsname: String = js.native
val hostmaster: String = js.native
val serial: Int = js.native
val refresh: Int = js.native
val retry: Int = js.native
val expire: Int = js.native
val minttl: Int = js.native
}

@js.native
trait SRV extends ResolveObject {
val name: String = js.native
val priority: Int = js.native
val port: Int = js.native
val weight: Int = js.native
}

@js.native
trait TXT extends ResolveObject {
val `type`: String = js.native
val entires: js.Array[js.Array[String]] = js.native
}
Loading