Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Continued development 1. Improved the completeness of the crypto module (node) 2. Implemented the path module (node) 3. Implemented the multer module (node) 4. Refactor error classes

# Conflicts:
#	README.md
  • Loading branch information
ldaniels528 committed May 18, 2016
2 parents 7de0974 + e406271 commit 78aa121
Show file tree
Hide file tree
Showing 63 changed files with 1,174 additions and 277 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ The following NodeJS modules have been implemented thus far:
| bcrypt | 0.0.3 | means-node-bcrypt | A native JS bcrypt library for NodeJS. |
| body-parser | 1.15.1 | means-node-body-parser| Body parsing middleware. |
| buffer | 6.1.0 | means-node-core | Node.js Core (Global) |
| crypto | 6.1.0 | means-node-core | The crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign and verify functions. |
| drama | 0.1.3 | means-node-drama | drama is an Actor model implementation for JavaScript and Node.js |
| events | 6.1.0 | means-node-core | Node.js Core |
| express | 4.13.4 | means-node-express | Fast, unopinionated, minimalist web framework for Node.js |
Expand All @@ -83,18 +84,20 @@ The following NodeJS modules have been implemented thus far:
| jwt-simple | 0.5.0 | means-node-jwt-simple | JWT(JSON Web Token) encode and decode module |
| kafka-node | 0.0.11 | means-node-kafkanode | A node binding for librdkafka |
| mongodb | 2.1 | means-node-mongodb | Node.js MongoDB Driver |
| multer | 1.1.0 | means-node-multer | Multer is a node.js middleware for handling multipart/form-data. |
| net | 6.1.0 | means-node-core | Node.js Core |
| oppressor | 0.0.1 | means-node-oppressor | Streaming http compression response negotiator. |
| os | 6.1.0 | means-node-os | Node.js Core |
| node-zookeeper-client | 0.2.2 | means-node-zookeeper-client | A higher-level ZooKeeper client based on node-zookeeper with support for locking and master election. |
| path | 6.1.0 | means-node-core | This module contains utilities for handling and transforming file paths. |
| readline | 6.1.0 | means-node-core | Node.js Core |
| repl | 6.1.0 | means-node-repl | Node.js Core |
| request | 2.72.1 | means-node-request | Simplified HTTP request client. |
| splitargs | 0.0.7 | means-node-elgs-splitargs | Splits strings into tokens by given separator except treating quoted part as a single token. |
| stream | 6.1.0 | means-node-core | Node.js Core |
| string-decoder | 6.1.0 | means-node-string-decoder | Node.js Core |
| url | 6.1.0 | means-node-core | Node.js Core |
| util | 6.1.0 | means-node-core | Node.js Core |
| util | 6.1.0 | means-node-core | The util module is primarily designed to support the needs of Node.js's internal APIs. |
| xml2js | 0.4.16 | means-node-xml2js | Simple XML to JavaScript object converter. |
| zlib | 6.1.0 | means-node-zlib | This provides bindings to Gzip/Gunzip, Deflate/Inflate, and DeflateRaw/InflateRaw classes. |

Expand Down
20 changes: 15 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sbt.Keys._
import sbt.Project.projectToRef
import sbt._

val apiVersion = "0.1.7"
val apiVersion = "0.1.8"
val paradisePluginVersion = "3.0.0-M1" //"2.1.0"
val _scalaVersion = "2.11.8"
val scalaJsDomVersion = "0.9.0"
Expand Down Expand Up @@ -41,7 +41,8 @@ lazy val root = (project in file(".")).
// node
node_core, node_adal, node_amqp, node_async, node_azure, node_bcrypt, node_body_parser, node_crypto,
node_drama, node_elgs_splitargs, node_express, node_express_ws, node_filed, node_jwt_simple, node_kafka,
node_mongodb, node_oppressor, node_os, node_repl, node_request, node_string_decoder, node_xml2js, node_zlib, node_zookeeper
node_mongodb, node_multer, node_oppressor, node_os, node_repl, node_request, node_string_decoder, node_xml2js,
node_zlib, node_zookeeper
)

lazy val core = (project in file("core")).
Expand Down Expand Up @@ -307,6 +308,15 @@ lazy val node_mongodb = (project in file("node/mongodb")).
description := "NodeJS/mongodb facade for Scala.js"
)

lazy val node_multer = (project in file("node/multer")).
dependsOn(core, node_express).
enablePlugins(ScalaJSPlugin).
settings(commonSettings: _*).
settings(
name := "means-node-multer",
description := "NodeJS/multer facade for Scala.js"
)

lazy val node_oppressor = (project in file("node/oppressor")).
dependsOn(core, node_core).
enablePlugins(ScalaJSPlugin).
Expand All @@ -322,7 +332,7 @@ lazy val node_os = (project in file("node/os")).
settings(commonSettings: _*).
settings(
name := "means-node-os",
description := "NodeJS/os facade for Scala.js"
description := "NodeJS/OS facade for Scala.js"
)

lazy val node_repl = (project in file("node/repl")).
Expand Down Expand Up @@ -382,11 +392,11 @@ lazy val node_zookeeper = (project in file("node/zookeeper-client")).
lazy val examples = (project in file("examples")).
aggregate(
core, node_core, node_adal, node_amqp, node_async, node_azure, node_bcrypt, node_body_parser, node_crypto, node_drama,
node_elgs_splitargs, node_express, node_express_ws, node_filed, node_jwt_simple, node_kafka, node_mongodb,
node_elgs_splitargs, node_express, node_express_ws, node_filed, node_jwt_simple, node_kafka, node_mongodb, node_multer,
node_oppressor, node_os, node_repl, node_request, node_string_decoder, node_xml2js, node_zlib, node_zookeeper).
dependsOn(
core, node_core, node_adal, node_amqp, node_async, node_azure, node_bcrypt, node_body_parser, node_crypto, node_drama,
node_elgs_splitargs, node_express, node_express_ws, node_filed, node_jwt_simple, node_kafka, node_mongodb,
node_elgs_splitargs, node_express, node_express_ws, node_filed, node_jwt_simple, node_kafka, node_mongodb, node_multer,
node_oppressor, node_os, node_repl, node_request, node_string_decoder, node_xml2js, node_zlib, node_zookeeper).
enablePlugins(ScalaJSPlugin).
settings(commonSettings: _*).
Expand Down
23 changes: 23 additions & 0 deletions examples/src/main/javascript/nodejs/codecs/MD5Example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* MD5 Example
* @author [email protected]
*/
(function () {

const filename = process.argv[2];
const crypto = require("crypto");
const fs = require("fs");

const md5sum = crypto.createHash("md5");

const stream = fs.ReadStream(filename);
stream.on("data", function (d) {
md5sum.update(d);
});

stream.on("end", function () {
var md5 = md5sum.digest("hex");
console.log(md5 + " " + filename);
});

})();
13 changes: 13 additions & 0 deletions examples/src/main/javascript/nodejs/codecs/StreamingHashExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Streaming Hash Example
*/
(function () {

const crypto = require("crypto");
const fs = require("fs");
const hash = crypto.createHash("sha256");

const input = fs.createReadStream("test.js");
input.pipe(hash).pipe(process.stdout);

})();
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

async.waterfall([
function (callback) {
callback(null, 'one', 'two');
callback(null, "one", "two");
},
function (arg1, arg2, callback) {
// arg1 now equals 'one' and arg2 now equals 'two'
callback(null, 'three');
// arg1 now equals "one" and arg2 now equals "two"
callback(null, "three");
},
function (arg1, callback) {
// arg1 now equals 'three'
callback(null, 'done');
// arg1 now equals "three"
callback(null, "done");
}
], function (err, result) {
// result now equals 'done'
// result now equals "done"
console.log("result = %s", result)
});

Expand Down
4 changes: 4 additions & 0 deletions examples/src/main/scala/examples/Examples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package examples

import com.github.ldaniels528.meansjs.nodejs._
import examples.nodejs.actors.ActorsExample
import examples.nodejs.codecs.MD5Example
import examples.nodejs.concurrency._
import examples.nodejs.datastores._
import examples.nodejs.general._
Expand Down Expand Up @@ -34,15 +35,18 @@ object Examples extends js.JSApp {
"JwtSimpleExample" -> ((bootstrap: Bootstrap) => new JwtSimpleExample(bootstrap)),
"KafkaProducerExample" -> ((bootstrap: Bootstrap) => new KafkaProducerExample(bootstrap)),
"KafkaProducerEnhanced" -> ((bootstrap: Bootstrap) => new KafkaProducerEnhanced(bootstrap)),
"MD5Example"-> ((bootstrap: Bootstrap) => new MD5Example(bootstrap)),
"MongoAggregateExample" -> ((bootstrap: Bootstrap) => new MongoAggregateExample(bootstrap)),
"MongoClientExample" -> ((bootstrap: Bootstrap) => new MongoClientExample(bootstrap)),
"MongoGridExample" -> ((bootstrap: Bootstrap) => new MongoGridExample(bootstrap)),
"MongoGridFSBucketExample" -> ((bootstrap: Bootstrap) => new MongoGridFSBucketExample(bootstrap)),
"MongoGridStoreExample" -> ((bootstrap: Bootstrap) => new MongoGridStoreExample(bootstrap)),
"MongoStreamExample" -> ((bootstrap: Bootstrap) => new MongoStreamExample(bootstrap)),
"NetServerExample" -> ((bootstrap: Bootstrap) => new NetServerExample(bootstrap)),
"PathExamples" -> ((bootstrap: Bootstrap) => new PathExamples(bootstrap)),
"ProcessExample" -> ((bootstrap: Bootstrap) => new ProcessExample(bootstrap)),
"REPLExample" -> ((bootstrap: Bootstrap) => new REPLExample(bootstrap)),
"ScopingTest" -> ((bootstrap: Bootstrap) => new ScopingTest(bootstrap)),
"ServerWithCompression" -> ((bootstrap: Bootstrap) => new ServerWithCompression(bootstrap)),
"StringDecoderExample" -> ((bootstrap: Bootstrap) => new StringDecoderExample(bootstrap)),
"TimersExample" -> ((bootstrap: Bootstrap) => new TimersExample(bootstrap)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package examples.nodejs.azure
import com.github.ldaniels528.meansjs.nodejs.adal.{AdalNode, AuthenticationResponse}
import com.github.ldaniels528.meansjs.nodejs.azure.arm.keyvault.AzureArmKeyVault
import com.github.ldaniels528.meansjs.nodejs.azure.common.{AzureCommon, KeyVaultParameters, TokenCloudCredentialOptions}
import com.github.ldaniels528.meansjs.nodejs.errors.ErrorClass
import com.github.ldaniels528.meansjs.nodejs.{Bootstrap, console, process}
import com.github.ldaniels528.meansjs.nodejs.{Bootstrap, console, errors, process}
import com.github.ldaniels528.meansjs.util.ScalaJsHelper._

import scala.scalajs.js
Expand All @@ -14,6 +13,7 @@ import scala.scalajs.js
* @author [email protected]
*/
class KeyVaultExample(bootstrap: Bootstrap) {

import bootstrap._

val AzureCommon = require[AzureCommon]("azure-common")
Expand All @@ -28,9 +28,9 @@ class KeyVaultExample(bootstrap: Bootstrap) {
val resourceId = process.argv.drop(3).headOption getOrElse ""

val context = AdalNode.AuthenticationContext("https://login.windows.net/myorg.com")
context.acquireTokenWithUsernamePassword(resourceId, userName, password, clientId, (err: ErrorClass, response: AuthenticationResponse) => {
context.acquireTokenWithUsernamePassword(resourceId, userName, password, clientId, (err: errors.Error, response: AuthenticationResponse) => {
if (isDefined(err)) {
throw new Error("Unable to authenticate: " + err.stack)
throw new RuntimeException("Unable to authenticate: " + err.stack)
}

val credentials = AzureCommon.TokenCloudCredentials(TokenCloudCredentialOptions(
Expand Down Expand Up @@ -58,7 +58,7 @@ class KeyVaultExample(bootstrap: Bootstrap) {
)

console.info("Creating vault...")
client.vaults.createOrUpdate(resourceGroup, vaultName, parameters, (err: js.Error, result: js.Any) => {
client.vaults.createOrUpdate(resourceGroup, vaultName, parameters, (err: errors.Error, result: js.Any) => {
if (isDefined(err)) throw new IllegalStateException(err.message)
console.info("Vault created: %j", result)
})
Expand Down
32 changes: 32 additions & 0 deletions examples/src/main/scala/examples/nodejs/codecs/MD5Example.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package examples.nodejs.codecs

import com.github.ldaniels528.meansjs.nodejs.buffer.Buffer
import com.github.ldaniels528.meansjs.nodejs.crypto.Crypto
import com.github.ldaniels528.meansjs.nodejs.fs.Fs
import com.github.ldaniels528.meansjs.nodejs.{Bootstrap, _}

/**
* MD5 Example
* @author [email protected]
*/
class MD5Example(bootstrap: Bootstrap) {
import bootstrap._

val crypto = require[Crypto]("crypto")
val fs = require[Fs]("fs")

process.argv.drop(3).headOption match {
case Some(filename) =>
val md5sum = crypto.createHash("md5")
val stream = fs.ReadStream(filename)
stream.onData((d: Buffer) => md5sum.update(d))
stream.onEnd(() => {
val md5 = md5sum.digest("hex")
console.log(md5 + " " + filename)
})
case None =>
console.warn("No input file was specified")
console.log("Usage: MD5Example <filename>")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package examples.nodejs.codecs

import com.github.ldaniels528.meansjs.nodejs.{Bootstrap, _}
import com.github.ldaniels528.meansjs.nodejs.crypto.Crypto
import com.github.ldaniels528.meansjs.nodejs.fs.Fs

/**
* Streaming Hash Example
* @author [email protected]
*/
class StreamingHashExample(bootstrap: Bootstrap) {
import bootstrap._

val crypto = require[Crypto]("crypto")
val fs = require[Fs]("fs")
val hash = crypto.createHash("sha256")

val input = fs.createReadStream("test.js")
input.pipe(hash).pipe(process.stdout)

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AsyncForEachOfExample(bootstrap: Bootstrap) {
val configs = js.Dictionary[js.Any]()

async.forEachOf(obj, (value: String, key: String, callback: js.Function1[Any, Any]) => {
fs.readFile(localPath + value, "utf8", (err: js.Error, data: String) => {
fs.readFile(localPath + value, "utf8", (err: errors.Error, data: String) => {
if (isDefined(err)) callback(err)
else {
Try {
Expand All @@ -45,7 +45,7 @@ class AsyncForEachOfExample(bootstrap: Bootstrap) {
}
console.log("Done A")
})
}, (err: js.Error) => {
}, (err: errors.Error) => {
if (isDefined(err)) console.error(err.message)
// configs is now a map of JSON data
doSomethingWith("A", configs)
Expand All @@ -59,15 +59,15 @@ class AsyncForEachOfExample(bootstrap: Bootstrap) {
val envFiles = js.Dictionary("dev" -> "/dev.json", "test" -> "/test.json", "prod" -> "/prod.json")
val configs = js.Dictionary[js.Any]()

async.forEachOfFuture(envFiles) { (value: String, key: String, callback: js.Function1[js.Error, Any]) =>
fs.readFile(localPath + value, "utf8", (err: js.Error, data: String) => {
async.forEachOfFuture(envFiles) { (value: String, key: String, callback: js.Function1[errors.Error, Any]) =>
fs.readFile(localPath + value, "utf8", (err: errors.Error, data: String) => {
if (isDefined(err)) callback(err)
else {
Try {
configs(key) = JSON.parse(data)
} match {
case Success(_) => callback(null)
case Failure(e) => callback(e)
case Failure(e) => callback(errors.Error(e))
}
}
console.log("Done B")
Expand All @@ -83,15 +83,15 @@ class AsyncForEachOfExample(bootstrap: Bootstrap) {
val files = js.Array("/dev.json", "/test.json", "/prod.json")
val configs = js.Dictionary[js.Any]()

async.forEachOfFuture(files) { (value: String, index: Int, callback: js.Function1[js.Error, Any]) =>
fs.readFile(localPath + value, "utf8", (err: js.Error, data: String) => {
async.forEachOfFuture(files) { (value: String, index: Int, callback: js.Function1[errors.Error, Any]) =>
fs.readFile(localPath + value, "utf8", (err: errors.Error, data: String) => {
if (isDefined(err)) callback(err)
else {
Try {
configs(envs(index)) = JSON.parse(data)
} match {
case Success(_) => callback(null)
case Failure(e) => callback(e)
case Failure(e) => callback(errors.Error(e))
}
}
console.log("Done C")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package examples.nodejs.concurrency

import com.github.ldaniels528.meansjs.nodejs.Bootstrap
import com.github.ldaniels528.meansjs.nodejs.{Bootstrap, errors}
import com.github.ldaniels528.meansjs.nodejs.async.Async
import org.scalajs.dom.console

Expand All @@ -20,15 +20,15 @@ class AsyncWaterfallExample(bootstrap: Bootstrap) {

def exampleA(): Unit = {
async.waterfall(js.Array(
(callback: js.Function3[js.Error, String, String, Unit]) => callback(null, "one", "two"),
(callback: js.Function3[errors.Error, String, String, Unit]) => callback(null, "one", "two"),

// arg1 now equals "one" and arg2 now equals "two"
(arg1: String, arg2: String, callback: js.Function2[js.Error, String, Unit]) => callback(null, "three"),
(arg1: String, arg2: String, callback: js.Function2[errors.Error, String, Unit]) => callback(null, "three"),

// arg1 now equals "three"
(arg1: String, callback: js.Function2[js.Error, String, Unit]) => callback(null, "done")
(arg1: String, callback: js.Function2[errors.Error, String, Unit]) => callback(null, "done")
),
(err: js.Error, result: String) => {
(err: errors.Error, result: String) => {
// result now equals "done"
console.log("result = %s", result)
})
Expand All @@ -37,26 +37,26 @@ class AsyncWaterfallExample(bootstrap: Bootstrap) {
def exampleB(): Unit = {
async.waterfallFuture[String](js.Array(
// start with two args
(callback: js.Function3[js.Error, String, String, Unit]) => callback(null, "one", "two"),
(callback: js.Function3[errors.Error, String, String, Unit]) => callback(null, "one", "two"),

// arg1 now equals "one" and arg2 now equals "two"
(arg1: String, arg2: String, callback: js.Function2[js.Error, String, Unit]) => callback(null, "three"),
(arg1: String, arg2: String, callback: js.Function2[errors.Error, String, Unit]) => callback(null, "three"),

// arg1 now equals "three"
(arg1: String, callback: js.Function2[js.Error, String, Unit]) => callback(null, "done")
(arg1: String, callback: js.Function2[errors.Error, String, Unit]) => callback(null, "done")
)) foreach (result => console.log("result = %s", result))
}

def exampleC() {
async.waterfallFuture[Int](js.Array(
// start with n = 1
(callback: js.Function2[js.Error, Int, Any]) => callback(null, 1),
(callback: js.Function2[errors.Error, Int, Any]) => callback(null, 1),

// multiply by 2: n = n * 2
(n: Int, callback: js.Function2[js.Error, Int, Any]) => callback(null, n * 2),
(n: Int, callback: js.Function2[errors.Error, Int, Any]) => callback(null, n * 2),

// multiply by 10: n = n * 10
(n: Int, callback: js.Function2[js.Error, Int, Any]) => callback(null, n * 10)
(n: Int, callback: js.Function2[errors.Error, Int, Any]) => callback(null, n * 10)
)) foreach (n => console.log("n = %d", n))
}

Expand Down
Loading

0 comments on commit 78aa121

Please sign in to comment.