Skip to content

Commit 66fc06b

Browse files
committed
Stable Version 0.4.0
1 parent a590f30 commit 66fc06b

File tree

7 files changed

+71
-104
lines changed

7 files changed

+71
-104
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
##### 0.4.0 - 02 July 2015
2+
3+
Stable Version 0.4.0
4+
5+
Upgraded dependencies
6+
17
##### 0.3.0 - 02 June 2015
28

39
###### Backwards compatible bug fixes

Gruntfile.js

-4
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ module.exports = function (grunt) {
4949
},
5050
externals: [
5151
'mout/string/underscore',
52-
'mout/object/keys',
5352
'mout/array/map',
54-
'mout/lang/isEmpty',
55-
'mout/object/omit',
5653
'js-data',
57-
'js-data-schema',
5854
'mongodb',
5955
'bson'
6056
],

dist/js-data-mongodb.js

+42-80
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,19 @@ module.exports =
5151

5252
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
5353

54-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
55-
5654
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
5755

58-
var _mongodb = __webpack_require__(2);
59-
60-
var _bson = __webpack_require__(3);
61-
62-
var _jsData = __webpack_require__(4);
63-
64-
var _jsData2 = _interopRequireDefault(_jsData);
65-
66-
var _moutStringUnderscore = __webpack_require__(5);
67-
68-
var _moutStringUnderscore2 = _interopRequireDefault(_moutStringUnderscore);
69-
70-
var _moutObjectKeys = __webpack_require__(1);
71-
72-
var _moutObjectKeys2 = _interopRequireDefault(_moutObjectKeys);
73-
74-
var _moutObjectOmit = __webpack_require__(6);
75-
76-
var _moutObjectOmit2 = _interopRequireDefault(_moutObjectOmit);
77-
78-
var _moutArrayMap = __webpack_require__(7);
79-
80-
var _moutArrayMap2 = _interopRequireDefault(_moutArrayMap);
81-
82-
var _moutLangIsEmpty = __webpack_require__(8);
83-
84-
var _moutLangIsEmpty2 = _interopRequireDefault(_moutLangIsEmpty);
85-
86-
var DSUtils = _jsData2['default'].DSUtils;
56+
var mongodb = __webpack_require__(1);
57+
var MongoClient = mongodb.MongoClient;
58+
var bson = __webpack_require__(2);
59+
var ObjectID = bson.ObjectID;
60+
var JSData = __webpack_require__(3);
61+
var underscore = __webpack_require__(4);
62+
var map = __webpack_require__(5);
63+
var DSUtils = JSData.DSUtils;
64+
var keys = DSUtils.keys;
65+
var omit = DSUtils.omit;
66+
var isEmpty = DSUtils.isEmpty;
8767
var deepMixIn = DSUtils.deepMixIn;
8868
var forEach = DSUtils.forEach;
8969
var contains = DSUtils.contains;
@@ -111,7 +91,7 @@ module.exports =
11191
this.defaults = new Defaults();
11292
deepMixIn(this.defaults, uri);
11393
this.client = new DSUtils.Promise(function (resolve, reject) {
114-
_mongodb.MongoClient.connect(uri.uri, function (err, db) {
94+
MongoClient.connect(uri.uri, function (err, db) {
11595
return err ? reject(err) : resolve(db);
11696
});
11797
});
@@ -128,7 +108,7 @@ module.exports =
128108
params = params || {};
129109
params.where = params.where || {};
130110

131-
forEach((0, _moutObjectKeys2['default'])(params), function (k) {
111+
forEach(keys(params), function (k) {
132112
var v = params[k];
133113
if (!contains(reserved, k)) {
134114
if (isObject(v)) {
@@ -144,7 +124,7 @@ module.exports =
144124

145125
var query = {};
146126

147-
if (!(0, _moutLangIsEmpty2['default'])(params.where)) {
127+
if (!isEmpty(params.where)) {
148128
forOwn(params.where, function (criteria, field) {
149129
if (!isObject(criteria)) {
150130
params.where[field] = {
@@ -303,11 +283,11 @@ module.exports =
303283
return new DSUtils.Promise(function (resolve, reject) {
304284
var params = {};
305285
params[resourceConfig.idAttribute] = id;
306-
if (resourceConfig.idAttribute === '_id' && typeof id === 'string' && _bson.ObjectID.isValid(id)) {
307-
params[resourceConfig.idAttribute] = _bson.ObjectID.createFromHexString(id);
286+
if (resourceConfig.idAttribute === '_id' && typeof id === 'string' && ObjectID.isValid(id)) {
287+
params[resourceConfig.idAttribute] = ObjectID.createFromHexString(id);
308288
}
309289
options.fields = options.fields || {};
310-
client.collection(resourceConfig.table || (0, _moutStringUnderscore2['default'])(resourceConfig.name)).findOne(params, options, function (err, r) {
290+
client.collection(resourceConfig.table || underscore(resourceConfig.name)).findOne(params, options, function (err, r) {
311291
if (err) {
312292
reject(err);
313293
} else if (!r) {
@@ -330,7 +310,7 @@ module.exports =
330310
return this.getClient().then(function (client) {
331311
return new DSUtils.Promise(function (resolve, reject) {
332312
options.fields = options.fields || {};
333-
client.collection(resourceConfig.table || (0, _moutStringUnderscore2['default'])(resourceConfig.name)).find(query, options).toArray(function (err, r) {
313+
client.collection(resourceConfig.table || underscore(resourceConfig.name)).find(query, options).toArray(function (err, r) {
334314
if (err) {
335315
reject(err);
336316
} else {
@@ -346,10 +326,10 @@ module.exports =
346326
var _this3 = this;
347327

348328
options = this.origify(options);
349-
attrs = removeCircular((0, _moutObjectOmit2['default'])(attrs, resourceConfig.relationFields || []));
329+
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
350330
return this.getClient().then(function (client) {
351331
return new DSUtils.Promise(function (resolve, reject) {
352-
var collection = client.collection(resourceConfig.table || (0, _moutStringUnderscore2['default'])(resourceConfig.name));
332+
var collection = client.collection(resourceConfig.table || underscore(resourceConfig.name));
353333
var method = collection.insertOne ? DSUtils.isArray(attrs) ? 'insertMany' : 'insertOne' : 'insert';
354334
collection[method](attrs, options, function (err, r) {
355335
if (err) {
@@ -368,18 +348,18 @@ module.exports =
368348
value: function update(resourceConfig, id, attrs, options) {
369349
var _this4 = this;
370350

371-
attrs = removeCircular((0, _moutObjectOmit2['default'])(attrs, resourceConfig.relationFields || []));
351+
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
372352
options = this.origify(options);
373353
return this.find(resourceConfig, id, options).then(function () {
374354
return _this4.getClient();
375355
}).then(function (client) {
376356
return new DSUtils.Promise(function (resolve, reject) {
377357
var params = {};
378358
params[resourceConfig.idAttribute] = id;
379-
if (resourceConfig.idAttribute === '_id' && typeof id === 'string' && _bson.ObjectID.isValid(id)) {
380-
params[resourceConfig.idAttribute] = _bson.ObjectID.createFromHexString(id);
359+
if (resourceConfig.idAttribute === '_id' && typeof id === 'string' && ObjectID.isValid(id)) {
360+
params[resourceConfig.idAttribute] = ObjectID.createFromHexString(id);
381361
}
382-
var collection = client.collection(resourceConfig.table || (0, _moutStringUnderscore2['default'])(resourceConfig.name));
362+
var collection = client.collection(resourceConfig.table || underscore(resourceConfig.name));
383363
collection[collection.updateOne ? 'updateOne' : 'update'](params, { $set: attrs }, options, function (err) {
384364
if (err) {
385365
reject(err);
@@ -398,7 +378,7 @@ module.exports =
398378
var _this5 = this;
399379

400380
var ids = [];
401-
attrs = removeCircular((0, _moutObjectOmit2['default'])(attrs, resourceConfig.relationFields || []));
381+
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
402382
options = this.origify(options ? copy(options) : {});
403383
var _options = copy(options);
404384
_options.multi = true;
@@ -407,15 +387,15 @@ module.exports =
407387
queryOptions.$set = attrs;
408388
var query = _this5.getQuery(resourceConfig, params);
409389
return _this5.findAll(resourceConfig, params, options).then(function (items) {
410-
ids = (0, _moutArrayMap2['default'])(items, function (item) {
390+
ids = map(items, function (item) {
411391
var id = item[resourceConfig.idAttribute];
412-
if (resourceConfig.idAttribute === '_id' && typeof id === 'string' && _bson.ObjectID.isValid(id)) {
413-
return _bson.ObjectID.createFromHexString(id);
392+
if (resourceConfig.idAttribute === '_id' && typeof id === 'string' && ObjectID.isValid(id)) {
393+
return ObjectID.createFromHexString(id);
414394
}
415395
return id;
416396
});
417397
return new DSUtils.Promise(function (resolve, reject) {
418-
var collection = client.collection(resourceConfig.table || (0, _moutStringUnderscore2['default'])(resourceConfig.name));
398+
var collection = client.collection(resourceConfig.table || underscore(resourceConfig.name));
419399
collection[collection.updateMany ? 'updateMany' : 'update'](query, queryOptions, _options, function (err) {
420400
if (err) {
421401
reject(err);
@@ -441,10 +421,10 @@ module.exports =
441421
return new DSUtils.Promise(function (resolve, reject) {
442422
var params = {};
443423
params[resourceConfig.idAttribute] = id;
444-
if (resourceConfig.idAttribute === '_id' && typeof id === 'string' && _bson.ObjectID.isValid(id)) {
445-
params[resourceConfig.idAttribute] = _bson.ObjectID.createFromHexString(id);
424+
if (resourceConfig.idAttribute === '_id' && typeof id === 'string' && ObjectID.isValid(id)) {
425+
params[resourceConfig.idAttribute] = ObjectID.createFromHexString(id);
446426
}
447-
var collection = client.collection(resourceConfig.table || (0, _moutStringUnderscore2['default'])(resourceConfig.name));
427+
var collection = client.collection(resourceConfig.table || underscore(resourceConfig.name));
448428
collection[collection.deleteOne ? 'deleteOne' : 'remove'](params, options, function (err) {
449429
if (err) {
450430
reject(err);
@@ -465,7 +445,7 @@ module.exports =
465445
deepMixIn(options, _this6.getQueryOptions(resourceConfig, params));
466446
var query = _this6.getQuery(resourceConfig, params);
467447
return new DSUtils.Promise(function (resolve, reject) {
468-
var collection = client.collection(resourceConfig.table || (0, _moutStringUnderscore2['default'])(resourceConfig.name));
448+
var collection = client.collection(resourceConfig.table || underscore(resourceConfig.name));
469449
collection[collection.deleteMany ? 'deleteMany' : 'remove'](query, options, function (err) {
470450
if (err) {
471451
reject(err);
@@ -486,51 +466,33 @@ module.exports =
486466

487467
/***/ },
488468
/* 1 */
489-
/***/ function(module, exports, __webpack_require__) {
490-
491-
module.exports = require("mout/object/keys");
492-
493-
/***/ },
494-
/* 2 */
495-
/***/ function(module, exports, __webpack_require__) {
469+
/***/ function(module, exports) {
496470

497471
module.exports = require("mongodb");
498472

499473
/***/ },
500-
/* 3 */
501-
/***/ function(module, exports, __webpack_require__) {
474+
/* 2 */
475+
/***/ function(module, exports) {
502476

503477
module.exports = require("bson");
504478

505479
/***/ },
506-
/* 4 */
507-
/***/ function(module, exports, __webpack_require__) {
480+
/* 3 */
481+
/***/ function(module, exports) {
508482

509483
module.exports = require("js-data");
510484

511485
/***/ },
512-
/* 5 */
513-
/***/ function(module, exports, __webpack_require__) {
486+
/* 4 */
487+
/***/ function(module, exports) {
514488

515489
module.exports = require("mout/string/underscore");
516490

517491
/***/ },
518-
/* 6 */
519-
/***/ function(module, exports, __webpack_require__) {
520-
521-
module.exports = require("mout/object/omit");
522-
523-
/***/ },
524-
/* 7 */
525-
/***/ function(module, exports, __webpack_require__) {
492+
/* 5 */
493+
/***/ function(module, exports) {
526494

527495
module.exports = require("mout/array/map");
528496

529-
/***/ },
530-
/* 8 */
531-
/***/ function(module, exports, __webpack_require__) {
532-
533-
module.exports = require("mout/lang/isEmpty");
534-
535497
/***/ }
536498
/******/ ]);

mocha.start.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
var assert = require('chai').assert;
55
var mocha = require('mocha');
66
var sinon = require('sinon');
7-
var DSMongoDBAdapter = require('./');
87
var JSData = require('js-data');
8+
JSData.DSUtils.Promise = require('bluebird');
9+
var DSMongoDBAdapter = require('./');
910

1011
var adapter, store, DSUtils, DSErrors, User, Post, Comment;
1112

package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "js-data-mongodb",
33
"description": "MongoDB adapter for js-data.",
4-
"version": "0.3.0",
4+
"version": "0.4.0",
55
"homepage": "http://www.js-data.io/docs/dsmongodbadapter",
66
"repository": {
77
"type": "git",
@@ -27,31 +27,31 @@
2727
"mongodb"
2828
],
2929
"devDependencies": {
30-
"babel-core": "5.4.7",
31-
"babel-loader": "5.1.3",
32-
"chai": "2.3.0",
30+
"babel-core": "5.6.15",
31+
"babel-loader": "5.2.2",
32+
"bluebird": "^2.9.30",
33+
"chai": "3.0.0",
3334
"grunt": "0.4.5",
3435
"grunt-contrib-watch": "0.6.1",
3536
"grunt-karma-coveralls": "2.5.3",
3637
"grunt-mocha-test": "0.12.7",
37-
"grunt-webpack": "1.0.8",
38+
"grunt-webpack": "1.0.11",
3839
"jit-grunt": "0.9.1",
3940
"jshint": "2.8.0",
4041
"jshint-loader": "0.8.3",
4142
"sinon": "1.14.1",
4243
"time-grunt": "1.2.1",
43-
"webpack": "1.9.10",
44-
"webpack-dev-server": "1.9.0"
44+
"webpack-dev-server": "1.10.1"
4545
},
4646
"scripts": {
4747
"test": "grunt test"
4848
},
4949
"dependencies": {
50-
"bson": "0.3.2",
50+
"bson": "0.3.x",
5151
"mout": "0.11.0"
5252
},
5353
"peerDependencies": {
54-
"js-data": ">=1.5.7",
55-
"mongodb": ">= 1.3.x"
54+
"js-data": ">=2.0.0",
55+
"mongodb": ">=1.3.x"
5656
}
5757
}

src/index.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { MongoClient } from 'mongodb';
2-
import { ObjectID } from 'bson';
3-
import JSData from 'js-data';
4-
import underscore from 'mout/string/underscore';
5-
import keys from 'mout/object/keys';
6-
import omit from 'mout/object/omit';
7-
import map from 'mout/array/map';
8-
import isEmpty from 'mout/lang/isEmpty';
1+
let mongodb = require('mongodb');
2+
let MongoClient = mongodb.MongoClient;
3+
let bson = require('bson');
4+
let ObjectID = bson.ObjectID;
5+
let JSData = require('js-data');
6+
let underscore = require('mout/string/underscore');
7+
let map = require('mout/array/map');
98
let { DSUtils } = JSData;
10-
let { deepMixIn, forEach, contains, isObject, isString, copy, forOwn, removeCircular } = DSUtils;
9+
let { keys, omit, isEmpty, deepMixIn, forEach, contains, isObject, isString, copy, forOwn, removeCircular } = DSUtils;
1110

1211
let reserved = [
1312
'orderBy',

test/create.spec.js

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ describe('DSMongoDBAdapter#create', function () {
1818
return adapter.find(User, id).catch(function (err) {
1919
assert.equal(err.message, 'Not Found!');
2020
});
21+
}).catch(function (err) {
22+
console.log(err);
23+
throw err;
2124
});
2225
});
2326
});

0 commit comments

Comments
 (0)