Skip to content

Commit 4b1b3eb

Browse files
committed
Continued development
1. Continued work on the multer module (node) 2. Continued work on the mongodb module (node)
1 parent 78aa121 commit 4b1b3eb

File tree

19 files changed

+256
-33
lines changed

19 files changed

+256
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ The following NodeJS modules have been implemented thus far:
8383
| https | 6.1.0 | means-node-core | Node.js Core |
8484
| jwt-simple | 0.5.0 | means-node-jwt-simple | JWT(JSON Web Token) encode and decode module |
8585
| kafka-node | 0.0.11 | means-node-kafkanode | A node binding for librdkafka |
86-
| mongodb | 2.1 | means-node-mongodb | Node.js MongoDB Driver |
86+
| mongodb | 2.1.18 | means-node-mongodb | Node.js MongoDB Driver |
8787
| multer | 1.1.0 | means-node-multer | Multer is a node.js middleware for handling multipart/form-data. |
8888
| net | 6.1.0 | means-node-core | Node.js Core |
8989
| oppressor | 0.0.1 | means-node-oppressor | Streaming http compression response negotiator. |

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import sbt.Keys._
44
import sbt.Project.projectToRef
55
import sbt._
66

7-
val apiVersion = "0.1.8"
7+
val apiVersion = "0.1.9"
88
val paradisePluginVersion = "3.0.0-M1" //"2.1.0"
99
val _scalaVersion = "2.11.8"
1010
val scalaJsDomVersion = "0.9.0"

core/src/main/scala/com/github/ldaniels528/meansjs/util/ScalaJsHelper.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.github.ldaniels528.meansjs.util
33
import scala.concurrent.{Future, Promise}
44
import scala.language.implicitConversions
55
import scala.scalajs.js
6+
import scala.scalajs.js.JSConverters._
67
import scala.scalajs.runtime.wrapJavaScriptException
78

89
/**
@@ -12,13 +13,11 @@ import scala.scalajs.runtime.wrapJavaScriptException
1213
object ScalaJsHelper {
1314

1415
////////////////////////////////////////////////////////////////////////
15-
// Convenience Functions
16+
// Concurrency Functions
1617
////////////////////////////////////////////////////////////////////////
1718

1819
implicit def promise2Future[T](promise: js.Promise[T]): Future[T] = promise.toFuture
1920

20-
implicit def exception2JsError(cause: Throwable): js.Error = js.Error(cause.getMessage)
21-
2221
/**
2322
* Converts a JavaScript-style callback to a Scala-style future
2423
* @param f the given callback function
@@ -79,6 +78,10 @@ object ScalaJsHelper {
7978
promise.future
8079
}
8180

81+
////////////////////////////////////////////////////////////////////////
82+
// Convenience Functions
83+
////////////////////////////////////////////////////////////////////////
84+
8285
@inline
8386
def die[T](message: String): T = throw new IllegalStateException(message)
8487

@@ -168,6 +171,8 @@ object ScalaJsHelper {
168171

169172
@inline def contains(value: T): Boolean = valueA.exists(_ == value)
170173

174+
@inline def flat = valueA.flatMap(Option(_).orUndefined)
175+
171176
@inline def orDie(message: String): js.UndefOr[T] = if (valueA.isDefined) valueA else throw new IllegalArgumentException(message)
172177

173178
}

node/core/src/main/scala/com/github/ldaniels528/meansjs/nodejs/http/ServerResponse.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.ldaniels528.meansjs.nodejs.http
22

3+
import com.github.ldaniels528.meansjs.nodejs.events.EventEmitter
34
import com.github.ldaniels528.meansjs.nodejs.stream.Writable
45

56
import scala.scalajs.js
@@ -10,7 +11,7 @@ import scala.scalajs.js
1011
* @see [[https://nodejs.org/api/http.html#http_class_http_serverresponse]]
1112
*/
1213
@js.native
13-
trait ServerResponse extends Writable {
14+
trait ServerResponse extends EventEmitter with Writable {
1415

1516
/////////////////////////////////////////////////////////////////////////////////
1617
// Properties
@@ -142,7 +143,7 @@ object ServerResponse {
142143
* Server Response Extensions
143144
144145
*/
145-
implicit class ServerResponseEnrich(val response: ServerResponse) extends AnyVal {
146+
implicit class ServerResponseExtensions(val response: ServerResponse) extends AnyVal {
146147

147148
@inline
148149
def badRequest() = response.sendStatus(400)

node/express/src/main/scala/com/github/ldaniels528/meansjs/nodejs/express/Application.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,25 @@ trait Application extends Router with EventEmitter {
8989
* This method is identical to Node’s http.Server.listen().
9090
* @example app.listen(port, [hostname], [backlog], [callback])
9191
*/
92-
def listen(port: Int, hostname: String, backlog: Int, callback: js.Function): Server = js.native
92+
def listen(port: Int, hostname: String, backlog: Int, callback: js.Function): Unit = js.native
9393

9494
/**
9595
* Binds and listens for connections on the specified host and port.
9696
* This method is identical to Node’s http.Server.listen().
9797
*/
98-
def listen(port: Int, hostname: String, backlog: Int): Server = js.native
98+
def listen(port: Int, hostname: String, backlog: Int): Unit = js.native
9999

100100
/**
101101
* Binds and listens for connections on the specified host and port.
102102
* This method is identical to Node’s http.Server.listen().
103103
*/
104-
def listen(port: Int, hostname: String, callback: js.Function): Server = js.native
104+
def listen(port: Int, hostname: String, callback: js.Function): Unit = js.native
105105

106106
/**
107107
* Binds and listens for connections on the specified host and port.
108108
* This method is identical to Node’s http.Server.listen().
109109
*/
110-
def listen(port: Int, hostname: String): Server = js.native
110+
def listen(port: Int, hostname: String): Unit = js.native
111111

112112
/**
113113
* Binds and listens for connections on the specified host and port.
@@ -119,7 +119,7 @@ trait Application extends Router with EventEmitter {
119119
* Binds and listens for connections on the specified host and port.
120120
* This method is identical to Node’s http.Server.listen().
121121
*/
122-
def listen(port: Int): Server = js.native
122+
def listen(port: Int): Unit = js.native
123123

124124
/**
125125
* Returns the canonical path of the app, a string.

node/mongodb/src/main/scala/com/github/ldaniels528/meansjs/nodejs/mongodb/Collection.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.scalajs.js
66
/**
77
* Mongo Collection
88
9-
* @see [[https://mongodb.github.io/node-mongodb-native/api-articles/nodekoarticle1.html]]
9+
* @see [[http://mongodb.github.io/node-mongodb-native/2.1/api/index.html]]
1010
*/
1111
@js.native
1212
trait Collection extends js.Object {
@@ -765,23 +765,23 @@ trait Collection extends js.Object {
765765
* @param options Optional settings.
766766
* @param callback The command result callback
767767
*/
768-
def updateMany(filter: js.Any, update: js.Any, options: js.Any, callback: js.Function2[MongoError, UpdateWriteOpResultObject, Any]): Unit = js.native
768+
def updateMany(filter: js.Any, update: js.Any, options: UpdateOptions, callback: js.Function2[MongoError, UpdateWriteOpResultObject, Any]): Unit = js.native
769769

770770
/**
771771
* Update multiple documents on MongoDB
772772
* @param filter The Filter used to select the document to update
773773
* @param update The update operations to be applied to the document
774774
* @param callback The command result callback
775775
*/
776-
def updateMany(filter: js.Any, update: js.Any, callback: js.Function2[MongoError, UpdateWriteOpResultObject, Any]): Unit = js.native
776+
def updateMany(filter: js.Any, update: UpdateOptions, callback: js.Function2[MongoError, UpdateWriteOpResultObject, Any]): Unit = js.native
777777

778778
/**
779779
* Update multiple documents on MongoDB
780780
* @param filter The Filter used to select the document to update
781781
* @param update The update operations to be applied to the document
782782
* @param options Optional settings.
783783
*/
784-
def updateMany(filter: js.Any, update: js.Any, options: js.Any = null): js.Promise[UpdateWriteOpResultObject] = js.native
784+
def updateMany(filter: js.Any, update: js.Any, options: UpdateOptions = null): js.Promise[UpdateWriteOpResultObject] = js.native
785785

786786
/**
787787
* Update a single document on MongoDB
@@ -791,7 +791,7 @@ trait Collection extends js.Object {
791791
* @param callback The command result callback
792792
* @return [[js.Promise]] if no callback passed
793793
*/
794-
def updateOne(filter: js.Any, update: js.Any, options: js.Any, callback: js.Function2[MongoError, UpdateWriteOpResultObject, Any]): Unit = js.native
794+
def updateOne(filter: js.Any, update: js.Any, options: UpdateOptions, callback: js.Function2[MongoError, UpdateWriteOpResultObject, Any]): Unit = js.native
795795

796796
/**
797797
* Update a single document on MongoDB
@@ -809,7 +809,7 @@ trait Collection extends js.Object {
809809
* @param options Optional settings.
810810
* @return [[js.Promise]] if no callback passed
811811
*/
812-
def updateOne(filter: js.Any, update: js.Any, options: js.Any = null): js.Promise[UpdateWriteOpResultObject] = js.native
812+
def updateOne(filter: js.Any, update: js.Any, options: UpdateOptions = null): js.Promise[UpdateWriteOpResultObject] = js.native
813813

814814
}
815815

node/mongodb/src/main/scala/com/github/ldaniels528/meansjs/nodejs/mongodb/InsertWriteOpResult.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ object InsertWriteOpResult {
5151
*/
5252
@js.native
5353
trait Result extends js.Object {
54+
// ok == 1 when successful
5455
var ok: Int = js.native
56+
5557
// Is 1 if the command executed correctly.
5658
var n: Int = js.native // The total count of documents inserted.
5759
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.github.ldaniels528.meansjs.nodejs.mongodb
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.ScalaJSDefined
5+
6+
/**
7+
* Document Update Options
8+
* @param w The write concern
9+
* @param wtimeout The write concern timeout.
10+
* @param j Specify a journal write concern.
11+
* @param upsert Update operation is an upsert.
12+
*/
13+
@ScalaJSDefined
14+
class UpdateOptions(w: js.UndefOr[Int],
15+
wtimeout: js.UndefOr[Int],
16+
j: js.UndefOr[Boolean],
17+
upsert: js.UndefOr[Boolean]) extends js.Object
18+
19+
/**
20+
* Update Options Companion
21+
22+
*/
23+
object UpdateOptions {
24+
25+
def apply(w: js.UndefOr[Int] = js.undefined,
26+
wtimeout: js.UndefOr[Int] = js.undefined,
27+
j: js.UndefOr[Boolean] = js.undefined,
28+
upsert: js.UndefOr[Boolean] = js.undefined) = {
29+
new UpdateOptions(w, wtimeout, j, upsert)
30+
}
31+
32+
}
33+

node/mongodb/src/main/scala/com/github/ldaniels528/meansjs/nodejs/mongodb/UpdateWriteOpResultObject.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ object UpdateWriteOpResultObject {
4444
@js.native
4545
trait Result extends js.Object {
4646
// Is 1 if the command executed correctly.
47-
var ok: js.Any = js.native
47+
var ok: Int = js.native
4848

4949
// The total count of documents scanned.
50-
var n: js.Any = js.native
50+
var n: Int = js.native
5151

5252
// The total count of documents modified.
53-
var nModified: js.Any = js.native
53+
var nModified: Int = js.native
54+
5455
}
5556

5657
}

node/mongodb/src/main/scala/com/github/ldaniels528/meansjs/nodejs/mongodb/WriteOptions.scala

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,26 @@ import scala.scalajs.js.annotation.ScalaJSDefined
88
99
*/
1010
@ScalaJSDefined
11-
class WriteOptions extends js.Object {
12-
var w: Int = _
13-
}
11+
class WriteOptions(w: js.UndefOr[Int],
12+
wtimeout: js.UndefOr[Int],
13+
j: js.UndefOr[Boolean],
14+
upsert: js.UndefOr[Boolean],
15+
multi: js.UndefOr[Boolean],
16+
bypassDocumentValidation: js.UndefOr[Boolean]) extends js.Object
1417

1518
/**
1619
* Write Options Companion
1720
1821
*/
1922
object WriteOptions {
2023

21-
def apply(w: Int): WriteOptions = {
22-
val options = new WriteOptions()
23-
options.w = w
24-
options
24+
def apply(w: js.UndefOr[Int] = js.undefined,
25+
wtimeout: js.UndefOr[Int] = js.undefined,
26+
j: js.UndefOr[Boolean] = js.undefined,
27+
upsert: js.UndefOr[Boolean] = js.undefined,
28+
multi: js.UndefOr[Boolean] = js.undefined,
29+
bypassDocumentValidation: js.UndefOr[Boolean] = js.undefined) = {
30+
new WriteOptions(w, wtimeout, j, upsert, multi, bypassDocumentValidation)
2531
}
2632

2733
}

node/mongodb/src/main/scala/com/github/ldaniels528/meansjs/nodejs/mongodb/package.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ package object mongodb {
9797
@inline
9898
def $position(pos: => Int) = "$position" -> pos
9999

100+
/**
101+
* The $set operator replaces the value of a field with the specified value.
102+
* @example { $set: { field1: value1, ... } }
103+
*/
104+
@inline
105+
def $set(value: => js.Any) = "$set" -> value
106+
100107
/**
101108
* Performs text search.
102109
* @example db.articles.find( { $text: { $search: "coffee" } } )
@@ -131,7 +138,7 @@ package object mongodb {
131138
* @example { $addToSet: {letters: [ "c", "d" ] } }
132139
*/
133140
@inline
134-
def $addToSet(value: => js.Any) = attribute -> doc("$addToSet" -> value)
141+
def $addToSet(value: => js.Any) = attribute -> doc("$addToSet" -> value)
135142

136143
/**
137144
* The $all is equivalent to an $and operation of the specified values; i.e. the following statement:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.github.ldaniels528.meansjs.nodejs.multer
2+
3+
import scala.scalajs.js
4+
5+
/**
6+
* Disk Storage
7+
8+
*/
9+
@js.native
10+
trait DiskStorage extends js.Object {
11+
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.github.ldaniels528.meansjs.nodejs.multer
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.ScalaJSDefined
5+
6+
/**
7+
* Disk Storage Options
8+
9+
*/
10+
@ScalaJSDefined
11+
class DiskStorageOptions() extends js.Object
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.github.ldaniels528.meansjs.nodejs.multer
2+
3+
import scala.scalajs.js
4+
5+
/**
6+
* Memory Storage
7+
8+
*/
9+
@js.native
10+
trait MemoryStorage extends js.Object {
11+
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.github.ldaniels528.meansjs.nodejs.multer
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.ScalaJSDefined
5+
6+
/**
7+
* Memory Storage Options
8+
9+
*/
10+
@ScalaJSDefined
11+
class MemoryStorageOptions() extends js.Object

0 commit comments

Comments
 (0)