Skip to content

Commit 17f1d82

Browse files
committed
Merge branch 'expose-ejson'. Add ddp-random to package.json
2 parents 98ac175 + e300eab commit 17f1d82

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

README.markdown

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Node DDP Client
33

44
A callback style DDP ([Meteor](http://meteor.com/)'s Distributed Data Protocol) node client, originally based alansikora's [node-js_ddp-client](https://github.com/alansikora/node-js_ddp-client) and Meteor's python client. Uses a more callback style approach.
55

6-
The client implements the pre1 and pre2 versions of DDP.
6+
The client implements the pre1 and pre2 versions of DDP.
77

88
Installation
99
============
@@ -21,13 +21,13 @@ Please see the example in `examples/example.js`. Or here for reference:
2121
var DDPClient = require("ddp");
2222

2323
var ddpclient = new DDPClient({
24-
host: "localhost",
24+
host: "localhost",
2525
port: 3000,
2626
/* optional: */
2727
auto_reconnect: true,
2828
auto_reconnect_timer: 500,
2929
use_ejson: true, // Use Meteor's EJSON to preserve certain data types.
30-
use_ssl: false,
30+
use_ssl: false,
3131
maintain_collections: true // Set to false to maintain your own collections.
3232
});
3333

@@ -58,10 +58,10 @@ ddpclient.connect(function(error) {
5858
function (err, result) { // callback which returns the method call results
5959
console.log('called function, result: ' + result);
6060
},
61-
function () { // callback which fires when server has finished
61+
function () { // callback which fires when server has finished
6262
console.log('updated'); // sending any updated documents as a result of
63-
console.log(ddpclient.collections.posts); // calling this method
64-
}
63+
console.log(ddpclient.collections.posts); // calling this method
64+
}
6565
);
6666
}, 3000);
6767

@@ -86,9 +86,9 @@ ddpclient.on('message', function (msg) {
8686
console.log("ddp message: " + msg);
8787
});
8888

89-
/*
89+
/*
9090
* If you need to do something specific on close or errors.
91-
* You can also disable auto_reconnect and
91+
* You can also disable auto_reconnect and
9292
* call ddpclient.connect() when you are ready to re-connect.
9393
*/
9494
ddpclient.on('socket-close', function(code, message) {
@@ -99,6 +99,10 @@ ddpclient.on('socket-error', function(error) {
9999
console.log("Error: %j", error);
100100
});
101101

102+
/*
103+
* If use_ejson is true, you can access the EJSON object used by ddp.
104+
*/
105+
var oid = new ddpclient.EJSON.ObjectID();
102106
```
103107

104108
Unimplemented Features
@@ -117,3 +121,4 @@ Contributions:
117121
* Mike Bannister (@possiblities)
118122
* Chris Mather (@eventedmind)
119123
* James Gill (@jagill)
124+
* Vaughn Iverson

lib/ddp-client.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ DDPClient = function(opts) {
2929
self.ddp_version = ('ddp_version' in opts) ? opts.ddp_version : 'pre2';
3030
self.supported_ddp_versions = ['pre2', 'pre1'];
3131

32+
// Expose EJSON object, so client can use EJSON.addType(...)
33+
if (self.use_ejson)
34+
self.EJSON = EJSON
35+
3236
// very very simple collections (name -> [{id -> document}])
3337
if (self.maintain_collections)
3438
self.collections = {};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"underscore": "1.5.2",
2525
"ddp-ejson": "0.8.1-2",
2626
"ddp-srp": "0.8.1-1",
27-
"faye-websocket": "~0.7.1"
27+
"faye-websocket": "~0.7.1",
28+
"ddp-random": "~0.8.1-1"
2829
},
2930
"devDependencies": {
3031
"mocha": "1.9.x",

test/ddp-client.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ describe('EJSON', function() {
102102
done();
103103
});
104104

105+
it('should expose the EJSON object', function(done) {
106+
var ddpclient = new DDPClient();
107+
108+
assert(ddpclient.EJSON);
109+
assert(ddpclient.EJSON.addType);
110+
111+
done();
112+
});
113+
105114
it('should not be used when disabled', function(done) {
106115
var ddpclient = new DDPClient({ use_ejson : false });
107116

0 commit comments

Comments
 (0)