Skip to content

Commit

Permalink
Miscellaneous fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ldaniels528 committed Feb 23, 2017
1 parent ab2a7f0 commit a05f674
Show file tree
Hide file tree
Showing 20 changed files with 229 additions and 180 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import sbt._

import scala.language.postfixOps

val scalaJsIOVersion = "0.3.0.5"
val scalaJsIOVersion = "0.3.0.6"
val apiVersion = scalaJsIOVersion
val scalaJsVersion = "2.12.1"

organization := "io.scalajs"

homepage := Some(url("https://github.com/scalajs-io/scalajs.io"))
homepage := Some(url("https://github.com/scalajs-io/nodejs"))

lazy val root = (project in file(".")).
enablePlugins(ScalaJSPlugin).
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/io/scalajs/nodejs/crypto/Cipher.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.scalajs.nodejs.crypto

import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.stream.Duplex
import io.scalajs.nodejs.stream.IDuplex

import scala.scalajs.js

Expand All @@ -17,7 +17,7 @@ import scala.scalajs.js
* @author [email protected]
*/
@js.native
trait Cipher extends Duplex {
trait Cipher extends IDuplex {

/**
* Returns any remaining enciphered contents. If output_encoding parameter is one of 'binary', 'base64' or 'hex',
Expand All @@ -27,7 +27,7 @@ trait Cipher extends Duplex {
* Attempts to call cipher.final() more than once will result in an error being thrown.
* @example cipher.final([output_encoding])
*/
def `final`(output_encoding: String ): String = js.native
def `final`(output_encoding: String): String = js.native

/**
* Returns any remaining enciphered contents. If output_encoding parameter is one of 'binary', 'base64' or 'hex',
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/io/scalajs/nodejs/crypto/Decipher.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.scalajs.nodejs.crypto

import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.stream.Duplex
import io.scalajs.nodejs.stream.IDuplex

import scala.scalajs.js

Expand All @@ -17,7 +17,7 @@ import scala.scalajs.js
* @author [email protected]
*/
@js.native
trait Decipher extends Duplex {
trait Decipher extends IDuplex {

/**
* Returns any remaining deciphered contents. If output_encoding parameter is one of 'binary', 'base64' or 'hex',
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/io/scalajs/nodejs/crypto/Hash.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.scalajs.nodejs.crypto

import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.stream.Duplex
import io.scalajs.nodejs.stream.IDuplex

import scala.scalajs.js

Expand All @@ -16,7 +16,7 @@ import scala.scalajs.js
* @author [email protected]
*/
@js.native
trait Hash extends Duplex {
trait Hash extends IDuplex {

/**
* Calculates the digest of all of the data passed to be hashed (using the hash.update() method). The encoding can
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/io/scalajs/nodejs/crypto/Hmac.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.scalajs.nodejs.crypto

import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.stream.Duplex
import io.scalajs.nodejs.stream.IDuplex

import scala.scalajs.js

Expand All @@ -17,7 +17,7 @@ import scala.scalajs.js
* @author [email protected]
*/
@js.native
trait Hmac extends Duplex {
trait Hmac extends IDuplex {

/**
* Calculates the HMAC digest of all of the data passed using hmac.update(). The encoding can be 'hex', 'binary'
Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/io/scalajs/nodejs/crypto/Sign.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.scalajs.nodejs.crypto

import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.stream
import io.scalajs.nodejs.stream.Duplex
import io.scalajs.nodejs.stream.IDuplex

import scala.scalajs.js

Expand All @@ -18,7 +17,7 @@ import scala.scalajs.js
* @author [email protected]
*/
@js.native
trait Sign extends Duplex {
trait Sign extends IDuplex {

def sign(private_key: String): String = js.native

Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/io/scalajs/nodejs/crypto/Verify.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.scalajs.nodejs.crypto

import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.stream
import io.scalajs.nodejs.stream.Duplex
import io.scalajs.nodejs.stream.IDuplex

import scala.scalajs.js

Expand All @@ -17,7 +16,7 @@ import scala.scalajs.js
* @author [email protected]
*/
@js.native
trait Verify extends Duplex {
trait Verify extends IDuplex {

/**
* Updates the Verify content with the given data.
Expand Down
40 changes: 37 additions & 3 deletions src/main/scala/io/scalajs/nodejs/fs/ReadStream.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package io.scalajs.nodejs.fs

import io.scalajs.nodejs.FileDescriptor
import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.stream.Readable
import io.scalajs.util.PromiseHelper.promiseCallback1

import scala.concurrent.Promise
import scala.scalajs.js
import scala.scalajs.js.|

/**
* fs.ReadStream - ReadStream is a Readable Stream.
Expand All @@ -12,12 +16,31 @@ import scala.scalajs.js
@js.native
trait ReadStream extends Readable {

/////////////////////////////////////////////////////////////////////////////////
// Properties
/////////////////////////////////////////////////////////////////////////////////

/**
* The number of bytes read so far.
*/
def bytesRead: Double = js.native

/**
* The path to the file the stream is reading from as specified in the first argument to fs.createReadStream().
* If path is passed as a string, then readStream.path will be a string. If path is passed as a Buffer, then
* readStream.path will be a Buffer.
*/
def path: js.Any = js.native
def path: Buffer | String = js.native

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

/**
* Undocumented method
* @see https://github.com/nodejs/node-v0.x-archive/blob/cfcb1de130867197cbc9c6012b7e84e08e53d032/lib/fs.js#L1597-L1620
*/
def close[A](callback: js.Function1[Unit, A]): Unit = js.native

}

Expand All @@ -33,13 +56,24 @@ object ReadStream {
*/
implicit class ReadStreamExtensions(val stream: ReadStream) extends AnyVal {

@inline
def closeAsync: Promise[Unit] = promiseCallback1[Unit](stream.close)

}

/**
* Read Stream Events
* @author [email protected]
*/
implicit class ReadStreamEvents(val stream: ReadStream) extends AnyVal {

/**
* Emitted when the ReadStream's underlying file descriptor has been closed using the fs.close() method.
* @param listener the event handler
* @since 0.1.93
*/
@inline
def onClose(listener: () => Any): stream.type = stream.on("close", listener)
def onClose[A](listener: () => A): stream.type = stream.on("close", listener)

/**
* Emitted when the ReadStream's file is opened.
Expand All @@ -50,7 +84,7 @@ object ReadStream {
* @since 0.1.93
*/
@inline
def onOpen(listener: FileDescriptor => Any): stream.type = stream.on("open", listener)
def onOpen[A](listener: FileDescriptor => A): stream.type = stream.on("open", listener)

}

Expand Down
37 changes: 34 additions & 3 deletions src/main/scala/io/scalajs/nodejs/fs/WriteStream.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package io.scalajs.nodejs.fs

import io.scalajs.util.PromiseHelper._
import io.scalajs.nodejs.FileDescriptor
import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.stream.Writable

import scala.concurrent.Promise
import scala.scalajs.js
import scala.scalajs.js.|

/**
* fs.WriteStream - WriteStream is a Writable Stream.
Expand All @@ -12,6 +16,10 @@ import scala.scalajs.js
@js.native
trait WriteStream extends Writable {

/////////////////////////////////////////////////////////////////////////////////
// Properties
/////////////////////////////////////////////////////////////////////////////////

/**
* The number of bytes written so far. Does not include data that is still queued for writing.
*/
Expand All @@ -22,7 +30,17 @@ trait WriteStream extends Writable {
* If path is passed as a string, then writeStream.path will be a string. If path is passed as a Buffer, then
* writeStream.path will be a Buffer.
*/
def path: js.Any = js.native
def path: Buffer | String = js.native

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

/**
* Undocumented method
* @see https://github.com/nodejs/node-v0.x-archive/blob/cfcb1de130867197cbc9c6012b7e84e08e53d032/lib/fs.js#L1597-L1620
*/
def close[A](callback: js.Function1[Unit, A]): Unit = js.native

}

Expand All @@ -38,12 +56,24 @@ object WriteStream {
*/
implicit class WriteStreamExtensions(val stream: WriteStream) extends AnyVal {

@inline
def closeAsync: Promise[Unit] = promiseCallback1[Unit](stream.close)

}

/**
* Write Stream Events
* @author [email protected]
*/
implicit class WriteStreamEvents(val stream: WriteStream) extends AnyVal {

/**
* Emitted when the WriteStream's underlying file descriptor has been closed using the fs.close() method.
* @param listener the event handler
* @since 0.1.93
*/
@inline def onClose(listener: () => Any) = stream.on("close", listener)
@inline
def onClose[A](listener: () => A): stream.type = stream.on("close", listener)

/**
* Emitted when the WriteStream's file is opened.
Expand All @@ -53,7 +83,8 @@ object WriteStream {
* </ul>
* @since 0.1.93
*/
@inline def onOpen(listener: FileDescriptor => Any) = stream.on("open", listener)
@inline
def onOpen[A](listener: FileDescriptor => A): stream.type = stream.on("open", listener)

}

Expand Down
6 changes: 2 additions & 4 deletions src/main/scala/io/scalajs/nodejs/http/IncomingMessage.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.scalajs.nodejs.http

import io.scalajs.nodejs.net.Socket
import io.scalajs.nodejs.stream
import io.scalajs.nodejs.net.Socket
import io.scalajs.nodejs.stream.Readable

Expand Down Expand Up @@ -111,10 +109,10 @@ object IncomingMessage {
implicit class IncomingMessageExtensions(val message: IncomingMessage) extends AnyVal {

@inline
def onClose(callback: js.Function) = message.on("close", callback)
def onClose(callback: js.Function): message.type = message.on("close", callback)

@inline
def setTimeout(duration: FiniteDuration, callback: js.Function) =
def setTimeout(duration: FiniteDuration, callback: js.Function): Unit =
message.setTimeout(duration.toMillis.toDouble, callback)

}
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/io/scalajs/nodejs/http/ServerResponse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.scalajs.nodejs.http

import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.events.IEventEmitter
import io.scalajs.nodejs.stream.Duplex
import io.scalajs.nodejs.stream.IDuplex

import scala.scalajs.js

Expand All @@ -12,7 +12,7 @@ import scala.scalajs.js
* @see [[https://nodejs.org/api/http.html#http_class_http_serverresponse]]
*/
@js.native
trait ServerResponse extends IEventEmitter with Duplex {
trait ServerResponse extends IEventEmitter with IDuplex {

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

import io.scalajs.RawOptions
import io.scalajs.nodejs.stream.Duplex
import io.scalajs.nodejs.stream.{Duplex, IDuplex}

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
Expand All @@ -15,7 +15,7 @@ import scala.scalajs.js.|
*/
@js.native
@JSImport("net", "Socket")
class Socket extends Duplex {
class Socket extends IDuplex {

/////////////////////////////////////////////////////////////////////////////////
// Properties
Expand Down
Loading

0 comments on commit a05f674

Please sign in to comment.