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

Avoid RawOptions where options have its own class. #64

Merged
merged 1 commit into from
Sep 24, 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait ChildProcess extends IEventEmitter {
def unref(): Unit = js.native
// TODO: Are those available in limited scenario?
//def disconnect(): Unit = js.native
//def send(message: js.Any, sendHandle: Handle = js.native, options: SendOptions | RawOptions = js.native, callback: js.Function1[nodejs.Error, Any] = js.native): Boolean = js.native
//def send(message: js.Any, sendHandle: Handle = js.native, options: SendOptions = js.native, callback: js.Function1[nodejs.Error, Any] = js.native): Boolean = js.native

val channel: js.UndefOr[js.Object] = js.native
val connected: Boolean = js.native
Expand Down
4 changes: 1 addition & 3 deletions app/current/src/main/scala/io/scalajs/nodejs/dns/DNS.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.scalajs.nodejs.dns

import io.scalajs.RawOptions

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.|
Expand Down Expand Up @@ -44,7 +42,7 @@ trait DNS extends js.Object {
* All properties are optional.
* @example dns.lookup(hostname[, options], callback)
*/
def lookup(hostname: String, options: DnsOptions | RawOptions | Int, callback: DnsCallback1[String]): Unit = js.native
def lookup(hostname: String, options: DnsOptions | Int, callback: DnsCallback1[String]): 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.scalajs.nodejs

import io.scalajs.RawOptions
import io.scalajs.util.PromiseHelper._

import scala.concurrent.Future
Expand Down Expand Up @@ -70,7 +69,7 @@ package object dns {
* integer, then it must be 4 or 6.
*/
@inline
def lookupFuture(hostname: String, options: DnsOptions | RawOptions | Int = null): Future[String] = {
def lookupFuture(hostname: String, options: DnsOptions | Int = null): Future[String] = {
promiseWithError1[DnsError, String](dns.lookup(hostname, options, _))
}

Expand Down
93 changes: 42 additions & 51 deletions app/current/src/main/scala/io/scalajs/nodejs/fs/Fs.scala

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions app/current/src/main/scala/io/scalajs/nodejs/fs/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import scala.scalajs.js.|
*/
package object fs {

type Path = Uint8Array | String | URL
type Time = Int | String | js.Date
type BufferLike = TypedArray[_, _] | DataView
type Output = String | Buffer
type Path = Uint8Array | String | URL
type Time = Int | String | js.Date
type BufferLike = TypedArray[_, _] | DataView
type Output = String | Buffer
type FileWriteOptions = FileAppendOptions

@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs10)
type Dirent = Fs.Dirent
Expand Down Expand Up @@ -135,7 +136,7 @@ package object fs {
@inline
def readdirDirentFuture(path: Buffer | String): Future[js.Array[Dirent]] = {
val callback: FsCallback1[js.Array[Dirent]] => Unit = { callback =>
fs.readdir(path, new ReaddirOptions(withFileTypes = true), callback.asInstanceOf[FsCallback1[ReaddirArrays]])
fs.readdir(path, new ReaddirOptions(withFileTypes = true), callback.asInstanceOf[FsCallback1[ReaddirArrays2]])
}
promiseWithError1[FileIOError, js.Array[Dirent]](callback)
}
Expand Down Expand Up @@ -212,12 +213,12 @@ package object fs {
}

@inline
def writeFileFuture(file: String, data: Buffer, options: FileOutputOptions = null): Future[Unit] = {
def writeFileFuture(file: String, data: Buffer, options: FileWriteOptions = null): Future[Unit] = {
promiseWithError0[FileIOError](fs.writeFile(file, data, options, _))
}

@inline
def writeFileFuture(file: String, data: String, options: FileOutputOptions): Future[Unit] = {
def writeFileFuture(file: String, data: String, options: FileWriteOptions): Future[Unit] = {
promiseWithError0[FileIOError](fs.writeFile(file, data, options, _))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.scalajs.nodejs
package http

import io.scalajs.RawOptions
import io.scalajs.util.PromiseHelper._

import scala.concurrent.Future
import scala.scalajs.js
import scala.scalajs.js.|

/**
* The HTTP Agent is used for pooling sockets used in HTTP client requests.
Expand Down Expand Up @@ -75,7 +73,7 @@ trait Agent extends js.Object {
* callback has a signature of (err, stream).
* @example agent.createConnection(options[, callback])
*/
def createConnection(options: ConnectionOptions | RawOptions, callback: js.Function): Unit = js.native
def createConnection(options: ConnectionOptions, callback: js.Function): Unit = js.native

/**
* Destroy any sockets that are currently in use by the agent.
Expand Down
10 changes: 4 additions & 6 deletions app/current/src/main/scala/io/scalajs/nodejs/https/Https.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.scalajs.nodejs.https

import io.scalajs.RawOptions
import io.scalajs.nodejs.events.IEventEmitter
import io.scalajs.nodejs.http.RequestOptions

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

/**
* HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a separate module.
Expand All @@ -33,14 +31,14 @@ trait Https extends IEventEmitter {
* The requestListener is a function which is automatically added to the 'request' event.
* @example https.createServer(options[, requestListener])
*/
def createServer(options: ServerOptions | RawOptions, requestListener: js.Function): Server = js.native
def createServer(options: ServerOptions, requestListener: js.Function): Server = js.native

/**
* Returns a new HTTPS web server object. The options is similar to tls.createServer().
* The requestListener is a function which is automatically added to the 'request' event.
* @example https.createServer(options[, requestListener])
*/
def createServer(options: ServerOptions | RawOptions): Server = js.native
def createServer(options: ServerOptions): Server = js.native

/**
* Like http.get() but for HTTPS.
Expand All @@ -54,14 +52,14 @@ trait Https extends IEventEmitter {
* @example https.get(options, (res) => { ... })
* @see [[io.scalajs.nodejs.http.Http.get()]]
*/
def get(options: RequestOptions | RawOptions, callback: js.Function): Unit = js.native
def get(options: RequestOptions, callback: js.Function): Unit = js.native

/**
* Makes a request to a secure web server.
* @param options can be an object or a string. If options is a string, it is automatically parsed with url.parse().
* @example http.request(options, callback)
*/
def request(options: RequestOptions | RawOptions, callback: js.Function): Unit = js.native
def request(options: RequestOptions, callback: js.Function): Unit = js.native

/**
* Makes a request to a secure web server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package io.scalajs.nodejs

import io.scalajs.nodejs.http.{RequestOptions, ServerResponse}
import io.scalajs.util.PromiseHelper._
import io.scalajs.{RawOptions, nodejs}
import io.scalajs.nodejs

import scala.concurrent.Future
import scala.scalajs.js.|

/**
* https package object
Expand All @@ -21,7 +20,7 @@ package object https {
* Like http.get() but for HTTPS.
*/
@inline
def getFuture(options: RequestOptions | RawOptions): Future[ServerResponse] = {
def getFuture(options: RequestOptions): Future[ServerResponse] = {
promiseCallback1[ServerResponse](https.get(options, _))
}

Expand All @@ -37,7 +36,7 @@ package object https {
* Makes a request to a secure web server.
*/
@inline
def requestFuture(options: RequestOptions | RawOptions): Future[ServerResponse] = {
def requestFuture(options: RequestOptions): Future[ServerResponse] = {
promiseWithError1[nodejs.Error, ServerResponse](https.request(options, _))
}

Expand Down
6 changes: 2 additions & 4 deletions app/current/src/main/scala/io/scalajs/nodejs/net/Socket.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.scalajs.nodejs
package net

import io.scalajs.RawOptions
import io.scalajs.nodejs.stream.IDuplex

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

/**
* net.Socket - This object is an abstraction of a TCP or local socket. net.Socket instances implement a duplex Stream
Expand All @@ -15,7 +13,7 @@ import scala.scalajs.js.|
*/
@js.native
@JSImport("net", "Socket")
class Socket(options: SocketOptions | RawOptions = js.native) extends IDuplex with HasHandle {
class Socket(options: SocketOptions = js.native) extends IDuplex with HasHandle {

/////////////////////////////////////////////////////////////////////////////////
// Properties
Expand Down Expand Up @@ -119,7 +117,7 @@ class Socket(options: SocketOptions | RawOptions = js.native) extends IDuplex wi
* @param connectListener the optional connect listener
* @example socket.connect(options[, connectListener])
*/
def connect(options: ConnectOptions | RawOptions, connectListener: js.Function = js.native): Unit = js.native
def connect(options: ConnectOptions, connectListener: js.Function = js.native): Unit = js.native

/**
* Opens the connection for a given socket.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package io.scalajs.nodejs.querystring

import io.scalajs.RawOptions

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

/**
* Query String
Expand Down Expand Up @@ -43,7 +40,7 @@ trait QueryString extends js.Object {
def parse(str: String,
sep: String = js.native,
eq: String = js.native,
options: QueryDecodeOptions | RawOptions = js.native): js.Dictionary[String] = js.native
options: QueryDecodeOptions = js.native): js.Dictionary[String] = js.native

/**
* The querystring.stringify() method produces a URL query string from a given obj by iterating through the
Expand All @@ -56,7 +53,7 @@ trait QueryString extends js.Object {
def stringify(obj: js.Any,
sep: String = js.native,
eq: String = js.native,
options: QueryEncodeOptions | RawOptions = js.native): String = js.native
options: QueryEncodeOptions = js.native): String = js.native

/**
* The querystring.unescape() method performs decoding of URL percent-encoded characters on the given str.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.scalajs.nodejs

import io.scalajs.RawOptions

import scala.scalajs.js
import scala.scalajs.js.|

/**
* query string package object
Expand All @@ -19,7 +16,7 @@ package object querystring {
def parseAs[T <: js.Object](str: String,
sep: String = null,
eq: String = null,
options: QueryDecodeOptions | RawOptions = null): T = {
options: QueryDecodeOptions = null): T = {
qs.parse(str, sep, eq, options).asInstanceOf[T]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package io.scalajs.nodejs.readline

import io.scalajs.RawOptions
import io.scalajs.nodejs.events.IEventEmitter

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

/**
* Readline allows reading of a stream (such as process.stdin) on a line-by-line basis.
Expand Down Expand Up @@ -37,7 +35,7 @@ trait Readline extends IEventEmitter {
* Creates a readline Interface instance.
* @example readline.createInterface(options)
*/
def createInterface(options: ReadlineOptions | RawOptions): Interface = js.native
def createInterface(options: ReadlineOptions): Interface = js.native

/**
* Move cursor to the specified position in a given TTY stream.
Expand Down
4 changes: 1 addition & 3 deletions app/current/src/main/scala/io/scalajs/nodejs/repl/REPL.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.scalajs.nodejs.repl

import io.scalajs.RawOptions
import io.scalajs.nodejs.events.IEventEmitter
import io.scalajs.nodejs.net.Socket

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

/**
* The repl module provides a Read-Eval-Print-Loop (REPL) implementation that is available
Expand All @@ -22,7 +20,7 @@ trait REPL extends IEventEmitter {
/**
* @example repl.start([options])
*/
def start(options: REPLOptions | RawOptions): REPLServer = js.native
def start(options: REPLOptions): REPLServer = js.native

/**
* @example repl.start([options])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package io.scalajs.nodejs
package stream

import io.scalajs.RawOptions
import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.events.IEventEmitter

import scala.scalajs.js

import scala.scalajs.js.|

/**
* The Readable stream interface is the abstraction for a source of data that you are reading from.
* In other words, data comes out of a Readable stream.
Expand Down Expand Up @@ -75,7 +72,7 @@ trait Readable extends IEventEmitter {
* Multiple destinations can be piped to safely.
* @example readable.pipe(destination[, options])
*/
def pipe(destination: Writable, options: ReadablePipeOptions | RawOptions = js.native): this.type = js.native
def pipe(destination: Writable, options: ReadablePipeOptions = js.native): this.type = js.native

/**
* When chunk is a Buffer or string, the chunk of data will be added to the internal queue for users
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package io.scalajs.nodejs
package tls

import io.scalajs.RawOptions
import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.net.Socket

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

/**
* The tls.TLSSocket is a subclass of net.Socket that performs transparent encryption of written data
Expand All @@ -19,7 +17,7 @@ import scala.scalajs.js.|
*/
@js.native
@JSImport("tls", "TLSSocket")
class TLSSocket(socket: Socket, options: TLSSocketOptions | RawOptions = js.native) extends net.Socket {
class TLSSocket(socket: Socket, options: TLSSocketOptions = js.native) extends net.Socket {

/**
* Returns an object representing the peer's certificate. The returned object has some properties corresponding to
Expand Down
5 changes: 1 addition & 4 deletions app/current/src/main/scala/io/scalajs/nodejs/tls/Tls.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package io.scalajs.nodejs
package tls

import io.scalajs.RawOptions

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

/**
* The tls module provides an implementation of the Transport Layer Security (TLS) and Secure Socket Layer (SSL)
Expand All @@ -23,7 +20,7 @@ trait Tls extends js.Object {
* @param callback See tls.connect().
* @example connect(port[, host][, options][, callback])
*/
def connect(port: Int, host: String, options: TlsConnectOptions | RawOptions, callback: js.Function): Unit = js.native
def connect(port: Int, host: String, options: TlsConnectOptions, callback: js.Function): Unit = js.native

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package io.scalajs.nodejs.url

import io.scalajs.RawOptions

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

/**
* The URLSearchParams API provides read and write access to the query of a URL. The URLSearchParams
Expand Down Expand Up @@ -143,10 +140,10 @@ class URLSearchParams extends js.Object {
/**
* Returns a customizable serialization of a URL String representation of a WHATWG URL object.
* @param url the given [[URL]]
* @param options the given [[RawOptions options]]
* @param options the given [[UrlFormatOptions options]]
* @return a customizable serialization of a URL String representation of a WHATWG URL object.
*/
def format(url: URL, options: UrlFormatOptions | RawOptions = js.native): String = js.native
def format(url: URL, options: UrlFormatOptions = js.native): String = js.native

}

Expand Down
Loading