Skip to content

Commit f96367e

Browse files
committed
Continued development:
1. Implemented the node-zookeeper module 2. Refactored the kafka-node module 3. Renamed the xxxFactory classes to xxxClass 4. Improved the compatibility of various modules
1 parent 55dd57f commit f96367e

File tree

78 files changed

+1349
-352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1349
-352
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ MEANS.js goes to great lengths to make all the things you love about writing Sca
4747
```bash
4848
$ sbt "project examples" clean fastOptJS
4949
$ cd examples
50-
$ node ./examples.js timers
50+
$ node ./examples.js IntermediateTimers
5151
```
5252

5353
<a name="NodeJS"></a>
@@ -62,13 +62,16 @@ modules implemented for most web applications.
6262
The following modules have been implemented thus far:
6363

6464
* body-parser
65+
* buffer
6566
* events
6667
* express
6768
* express-ws
6869
* fs
6970
* http
71+
* kafka-node
7072
* mongodb
7173
* net
74+
* node-zookeeper-client
7275
* stream
7376
* util
7477

angularjs/src/main/scala/com/github/ldaniels528/meansjs/angularjs/JQLite.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait JQLite extends Element {
1818
* @param className the given class name
1919
* @return the [[JQLite instance]]
2020
*/
21-
def addClass(className: String): this.type
21+
def addClass(className: String): this.type = js.native
2222

2323
/**
2424
* A function returning one or more space-separated class names to be added to the existing class name(s).

build.sbt

+21-13
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.0.6"
7+
val apiVersion = "0.0.7"
88
val paradisePluginVersion = "2.1.0"
99
val _scalaVersion = "2.11.8"
1010
val scalaJsDomVersion = "0.9.0"
@@ -25,7 +25,7 @@ val commonSettings = Seq(
2525
)
2626

2727
lazy val root = (project in file(".")).
28-
aggregate(core, angularjs, express, facebook, kafkanode, linkedin, mongodb, nodejs)
28+
aggregate(core, angularjs, express, facebook, kafka_node, linkedin, mongodb, nodejs)
2929

3030
lazy val core = (project in file("core")).
3131
enablePlugins(ScalaJSPlugin).
@@ -36,72 +36,80 @@ lazy val core = (project in file("core")).
3636
)
3737

3838
lazy val angularjs = (project in file("angularjs")).
39-
enablePlugins(ScalaJSPlugin).
4039
dependsOn(core).
40+
enablePlugins(ScalaJSPlugin).
4141
settings(commonSettings: _*).
4242
settings(
4343
name := "means-angularjs",
4444
description := "AngularJS bindings for Scala.js"
4545
)
4646

4747
lazy val facebook = (project in file("facebook")).
48-
enablePlugins(ScalaJSPlugin).
4948
dependsOn(core, angularjs).
49+
enablePlugins(ScalaJSPlugin).
5050
settings(commonSettings: _*).
5151
settings(
5252
name := "means-facebook",
5353
description := "Facebook buildings for Scala.js"
5454
)
5555

5656
lazy val express = (project in file("express")).
57-
enablePlugins(ScalaJSPlugin).
5857
dependsOn(core, nodejs).
58+
enablePlugins(ScalaJSPlugin).
5959
settings(commonSettings: _*).
6060
settings(
6161
name := "means-express",
6262
description := "Express.js bindings for Scala.js"
6363
)
6464

6565
lazy val linkedin = (project in file("linkedin")).
66-
enablePlugins(ScalaJSPlugin).
6766
dependsOn(core, angularjs).
67+
enablePlugins(ScalaJSPlugin).
6868
settings(commonSettings: _*).
6969
settings(
7070
name := "means-linkedin",
7171
description := "LinkedIn buildings for Scala.js"
7272
)
7373

74-
lazy val kafkanode = (project in file("kafkanode")).
74+
lazy val kafka_node = (project in file("kafka_node")).
75+
dependsOn(core, nodejs, node_zookeeper).
7576
enablePlugins(ScalaJSPlugin).
76-
dependsOn(core, nodejs).
7777
settings(commonSettings: _*).
7878
settings(
7979
name := "means-kafka-node",
8080
description := "Kafka bindings for Scala.js"
8181
)
8282

8383
lazy val mongodb = (project in file("mongodb")).
84-
enablePlugins(ScalaJSPlugin).
8584
dependsOn(core, nodejs).
85+
enablePlugins(ScalaJSPlugin).
8686
settings(commonSettings: _*).
8787
settings(
8888
name := "means-mongodb",
8989
description := "MongoDB bindings for Scala.js"
9090
)
9191

9292
lazy val nodejs = (project in file("nodejs")).
93-
enablePlugins(ScalaJSPlugin).
9493
dependsOn(core).
94+
enablePlugins(ScalaJSPlugin).
9595
settings(commonSettings: _*).
9696
settings(
9797
name := "means-nodejs",
9898
description := "Node.js bindings for Scala.js"
9999
)
100100

101-
lazy val examples = (project in file("examples")).
102-
aggregate(core, express, kafkanode, mongodb, nodejs).
101+
lazy val node_zookeeper = (project in file("node_zookeeper")).
102+
dependsOn(core, nodejs).
103103
enablePlugins(ScalaJSPlugin).
104-
dependsOn(core, express, kafkanode, mongodb, nodejs).
104+
settings(commonSettings: _*).
105+
settings(
106+
name := "means-node-zookeeper-client",
107+
description := "Zookeeper client bindings for Scala.js"
108+
)
109+
110+
lazy val examples = (project in file("examples")).
111+
aggregate(core, express, kafka_node, mongodb, nodejs, node_zookeeper).
112+
dependsOn(core, express, kafka_node, mongodb, nodejs, node_zookeeper).
105113
enablePlugins(ScalaJSPlugin).
106114
settings(commonSettings: _*).
107115
settings(

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

+4-8
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ object ScalaJsHelper {
3636
////////////////////////////////////////////////////////////////////////
3737

3838
/**
39-
* Exception Enrichment
39+
* Exception Extensions
4040
* @param cause the given [[Throwable exception]]
4141
4242
*/
43-
implicit class ExceptionEnrichment(val cause: Throwable) extends AnyVal {
43+
implicit class ExceptionExtensions(val cause: Throwable) extends AnyVal {
4444

4545
def displayMessage = Option(cause.getMessage) match {
4646
case Some(s) if s.startsWith(HttpError) => cleanUp(s.drop(HttpError.length))
@@ -69,11 +69,11 @@ object ScalaJsHelper {
6969
}
7070

7171
/**
72-
* Time Measurement Enrichment
72+
* Time Measurement Extensions
7373
* @param task the given [[Future task]]
7474
* @tparam T the return type of the task
7575
*/
76-
implicit class TimeEnrichment[T](val task: Future[T]) extends AnyVal {
76+
implicit class TimeExtensions[T](val task: Future[T]) extends AnyVal {
7777

7878
def withTimer(action: String, showHeader: Boolean = true)(implicit ec: ExecutionContext) = time(action, task, showHeader)
7979

@@ -233,10 +233,6 @@ object ScalaJsHelper {
233233
case index => Some(index)
234234
}
235235

236-
@inline def isBlank: Boolean = string == null || string.trim.isEmpty
237-
238-
@inline def nonBlank: Boolean = string != null && string.trim.nonEmpty
239-
240236
@inline def isValidEmail: Boolean = string.matches("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
241237

242238
@inline def parseAs[T] = JSON.parse(string).asInstanceOf[T]

examples/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"express-ws": "^2.0.0-beta",
1111
"fs": "0.0.2",
1212
"html": "0.0.10",
13-
"mongoose": "4.4.11"
13+
"kafka-node": "^0.3.2",
14+
"mongoose": "4.4.11",
15+
"node-zookeeper-client": "^0.2.2"
1416
}
1517
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Buffers Example
3+
4+
*/
5+
(function () {
6+
7+
const buf1 = Buffer.from('ABC');
8+
const buf2 = Buffer.from('BCD');
9+
const buf3 = Buffer.from('ABCD');
10+
11+
// Prints: 0
12+
console.log(buf1.compare(buf1));
13+
// Prints: -1
14+
console.log(buf1.compare(buf2));
15+
// Prints: 1
16+
console.log(buf1.compare(buf3));
17+
// Prints: 1
18+
console.log(buf2.compare(buf1));
19+
// Prints: 1
20+
console.log(buf2.compare(buf3));
21+
22+
// produces sort order [buf1, buf3, buf2]
23+
console.log([buf1, buf2, buf3].sort(Buffer.compare));
24+
25+
// iterate the 3rd buffer
26+
const it = buf3.entries();
27+
var result = null;
28+
do {
29+
result = it.next();
30+
console.log(result);
31+
} while (!result.done);
32+
33+
})();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Transaction Example
3+
4+
*/
5+
(function() {
6+
7+
const zookeeper = require("node-zookeeper-client");
8+
const client = zookeeper.createClient(process.argv[2] || 'localhost:2181');
9+
10+
client.once('connected', function () {
11+
console.log("Creating '/txn'...");
12+
client.transaction().
13+
create('/txn').
14+
create('/txn/1', new Buffer('transaction')).
15+
setData('/txn/1', new Buffer('test'), -1).
16+
check('/txn/1').
17+
remove('/txn/1', -1).
18+
remove('/txn').
19+
commit(function (error, results) {
20+
if (error) {
21+
console.log(
22+
'Failed to execute the transaction: %s, results: %j',
23+
error,
24+
results
25+
);
26+
27+
return;
28+
}
29+
30+
console.log('Transaction completed.');
31+
client.close();
32+
});
33+
});
34+
35+
client.connect();
36+
})();

examples/src/main/scala/examples/Examples.scala

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
package examples
22

33
import com.github.ldaniels528.meansjs.nodejs._
4-
import examples.nodejs.events.EventEmitting
5-
import examples.nodejs.express.ExpressTest
6-
import examples.nodejs.http.HttpServerTest
7-
import examples.nodejs.kafka.{ProducerEnhanced, ProducerExample}
8-
import examples.nodejs.mongodb.MongoClientTest
9-
import examples.nodejs.net.NetServerTest
10-
import examples.nodejs.timers.IntermediateTimers
4+
import examples.nodejs.{buffers, events, express, http, kafka, mongodb, net, timers, zookeeper}
115
import org.scalajs.dom.console
126

137
import scala.scalajs.js
@@ -19,23 +13,28 @@ import scala.scalajs.js.annotation.JSExportAll
1913
*/
2014
@JSExportAll
2115
object Examples extends js.JSApp {
22-
private val names = js.Array("events", "express", "http", "mongodb", "net", "timers")
16+
private val names = js.Array(
17+
"Buffers", "EventEmitting", "ExpressTest", "HttpServerTest", "IntermediateTimers", "MongoClientTest",
18+
"NetServerTest", "ProducerExample", "ProducerEnhanced", "TransactionExample"
19+
)
2320

2421
override def main(): Unit = ()
2522

2623
def start(require: Require) = {
2724
process.argv.drop(2) foreach {
28-
case "EventEmitting" => new EventEmitting(require)
29-
case "express" => new ExpressTest(require)
30-
case "http" => new HttpServerTest(require)
31-
case "mongodb" => new MongoClientTest(require)
32-
case "net" => new NetServerTest(require)
33-
case "ProducerExample" => new ProducerExample(require)
34-
case "ProducerEnhanced" => new ProducerEnhanced(require)
35-
case "timers" => new IntermediateTimers(require)
25+
case "Buffers" => new buffers.Buffers(require)
26+
case "EventEmitting" => new events.EventEmitting(require)
27+
case "ExpressTest" => new express.ExpressTest(require)
28+
case "HttpServerTest" => new http.HttpServerTest(require)
29+
case "IntermediateTimers" => new timers.IntermediateTimers(require)
30+
case "MongoClientTest" => new mongodb.MongoClientTest(require)
31+
case "NetServerTest" => new net.NetServerTest(require)
32+
case "ProducerExample" => new kafka.ProducerExample(require)
33+
case "ProducerEnhanced" => new kafka.ProducerEnhanced(require)
34+
case "StateExample" => new zookeeper.StateExample(require)
35+
case "TransactionExample" => new zookeeper.TransactionExample(require)
3636
case arg =>
37-
console.warn(s"No example found for $arg - Choose from ${names.mkString(", ")}")
38-
new IntermediateTimers(require)
37+
console.warn(s"Syntax: examples.js <exampleName> - Choose one: ${names.mkString(", ")}")
3938
}
4039
}
4140

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package examples.nodejs.buffers
2+
3+
import com.github.ldaniels528.meansjs.nodejs.JsIterator.IteratorResult
4+
import com.github.ldaniels528.meansjs.nodejs.Require
5+
import com.github.ldaniels528.meansjs.nodejs.buffer._
6+
import org.scalajs.dom.console
7+
8+
import scala.scalajs.js
9+
10+
/**
11+
* Buffers Example
12+
13+
*/
14+
class Buffers(require: Require) {
15+
16+
val buf1 = Buffer.from("ABC")
17+
val buf2 = Buffer.from("BCD")
18+
val buf3 = Buffer.from("ABCD")
19+
20+
// Prints: 0
21+
console.log(buf1.compare(buf1))
22+
// Prints: -1
23+
console.log(buf1.compare(buf2))
24+
// Prints: 1
25+
console.log(buf1.compare(buf3))
26+
// Prints: 1
27+
console.log(buf2.compare(buf1))
28+
// Prints: 1
29+
console.log(buf2.compare(buf3))
30+
31+
// produces sort order [buf1, buf3, buf2]
32+
console.log(js.Array(buf1, buf2, buf3).sort((buf1: Buffer, buf2: Buffer) => Buffer.compare(buf1, buf2)))
33+
34+
// iterate the 3rd buffer
35+
val it = buf3.entries()
36+
var result: IteratorResult = _
37+
do {
38+
result = it.next()
39+
console.log(result)
40+
} while (!result.done)
41+
}

0 commit comments

Comments
 (0)