Skip to content

Commit a4b1706

Browse files
committed
Stable Version 0.2.1.
Fixes #2 Fixes #3
1 parent 71a34db commit a4b1706

File tree

7 files changed

+252
-101
lines changed

7 files changed

+252
-101
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
##### 0.2.1 - 26 March 2015
2+
3+
###### Backwards compatible bug fixes
4+
- #2 - Should not be saving relations (duplicating data)
5+
- #3 - Need to use removeCircular
6+
17
##### 0.2.0 - 10 March 2015
28

3-
- Converted to ES6.
9+
###### Other
10+
- #1 - Convert to ES6.
411

512
##### 0.1.0 - 18 February 2015
613

CONTRIBUTING.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Contributing Guide
22

3-
First, feel free to contact me with questions. [Mailing List](https://groups.io/org/groupsio/jsdata). [Issues](https://github.com/js-data/js-data-mongodb/issues).
3+
First, support is handled via the [Mailing List](https://groups.io/org/groupsio/jsdata). Ask your questions there.
4+
5+
When submitting issues on GitHub, please include as much detail as possible to make debugging quick and easy.
6+
7+
- good - Your versions of js-data, js-data-mongodb, etc., relevant console logs/error, code examples that revealed the issue
8+
- better - A [plnkr](http://plnkr.co/), [fiddle](http://jsfiddle.net/), or [bin](http://jsbin.com/?html,output) that demonstrates the issue
9+
- best - A Pull Request that fixes the issue, including test coverage for the issue and the fix
10+
11+
[Github Issues](https://github.com/js-data/js-data-mongodb/issues).
12+
13+
#### Pull Requests
414

515
1. Contribute to the issue that is the reason you'll be developing in the first place
616
1. Fork js-data-mongodb

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* js-data-mongodb
3-
* http://github.com/js-data/js-data-mongodb
3+
* https://github.com/js-data/js-data-mongodb
44
*
55
* Copyright (c) 2014-2015 Jason Dobry <http://www.js-data.io/docs/dsmongodbadapter>
66
* Licensed under the MIT license. <https://github.com/js-data/js-data-mongodb/blob/master/LICENSE>

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,17 @@ var User = store.defineResource({
5252

5353
### Contributing
5454

55-
First, feel free to contact me with questions. [Mailing List](https://groups.io/org/groupsio/jsdata). [Issues](https://github.com/js-data/js-data-mongodb/issues).
55+
First, support is handled via the [Mailing List](https://groups.io/org/groupsio/jsdata). Ask your questions there.
56+
57+
When submitting issues on GitHub, please include as much detail as possible to make debugging quick and easy.
58+
59+
- good - Your versions of js-data, js-data-mongodb, etc., relevant console logs/error, code examples that revealed the issue
60+
- better - A [plnkr](http://plnkr.co/), [fiddle](http://jsfiddle.net/), or [bin](http://jsbin.com/?html,output) that demonstrates the issue
61+
- best - A Pull Request that fixes the issue, including test coverage for the issue and the fix
62+
63+
[Github Issues](https://github.com/js-data/js-data-mongodb/issues).
64+
65+
#### Pull Requests
5666

5767
1. Contribute to the issue that is the reason you'll be developing in the first place
5868
1. Fork js-data-mongodb

dist/js-data-mongodb.js

Lines changed: 170 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,43 @@ module.exports =
4545
/* 0 */
4646
/***/ function(module, exports, __webpack_require__) {
4747

48+
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
49+
4850
var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
4951

5052
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
5153

5254
var MongoClient = __webpack_require__(1).MongoClient;
53-
var JSData = __webpack_require__(2);
54-
var underscore = __webpack_require__(3);
55-
var keys = __webpack_require__(4);
56-
var map = __webpack_require__(5);
57-
var isEmpty = __webpack_require__(6);
58-
var forEach = JSData.DSUtils.forEach;
59-
var contains = JSData.DSUtils.contains;
60-
var isObject = JSData.DSUtils.isObject;
61-
var isString = JSData.DSUtils.isString;
62-
var forOwn = JSData.DSUtils.forOwn;
55+
56+
var JSData = _interopRequire(__webpack_require__(2));
57+
58+
var underscore = _interopRequire(__webpack_require__(3));
59+
60+
var keys = _interopRequire(__webpack_require__(4));
61+
62+
var omit = _interopRequire(__webpack_require__(7));
63+
64+
var map = _interopRequire(__webpack_require__(5));
65+
66+
var isEmpty = _interopRequire(__webpack_require__(6));
67+
68+
var DSUtils = JSData.DSUtils;
69+
var deepMixIn = DSUtils.deepMixIn;
70+
var forEach = DSUtils.forEach;
71+
var contains = DSUtils.contains;
72+
var isObject = DSUtils.isObject;
73+
var isString = DSUtils.isString;
74+
var copy = DSUtils.copy;
75+
var forOwn = DSUtils.forOwn;
76+
var removeCircular = DSUtils.removeCircular;
6377

6478
var reserved = ["orderBy", "sort", "limit", "offset", "skip", "where"];
6579

6680
var DSMongoDBAdapter = (function () {
6781
function DSMongoDBAdapter(uri) {
6882
_classCallCheck(this, DSMongoDBAdapter);
6983

70-
this.client = new JSData.DSUtils.Promise(function (resolve, reject) {
84+
this.client = new DSUtils.Promise(function (resolve, reject) {
7185
MongoClient.connect(uri, function (err, db) {
7286
return err ? reject(err) : resolve(db);
7387
});
@@ -227,10 +241,9 @@ module.exports =
227241
},
228242
find: {
229243
value: function find(resourceConfig, id, options) {
230-
var _this = this;
231244
options = options || {};
232-
return _this.getClient().then(function (client) {
233-
return new JSData.DSUtils.Promise(function (resolve, reject) {
245+
return this.getClient().then(function (client) {
246+
return new DSUtils.Promise(function (resolve, reject) {
234247
var params = {};
235248
params[resourceConfig.idAttribute] = id;
236249
client.collection(resourceConfig.table || underscore(resourceConfig.name)).findOne(params, options, function (err, r) {
@@ -248,13 +261,11 @@ module.exports =
248261
},
249262
findAll: {
250263
value: function findAll(resourceConfig, params, options) {
251-
var _this = this;
252-
options = options || {};
253-
options = JSData.DSUtils.deepMixIn({}, options);
254-
JSData.DSUtils.deepMixIn(options, _this.getQueryOptions(resourceConfig, params));
255-
var query = _this.getQuery(resourceConfig, params);
256-
return _this.getClient().then(function (client) {
257-
return new JSData.DSUtils.Promise(function (resolve, reject) {
264+
options = options ? copy(options) : {};
265+
deepMixIn(options, this.getQueryOptions(resourceConfig, params));
266+
var query = this.getQuery(resourceConfig, params);
267+
return this.getClient().then(function (client) {
268+
return new DSUtils.Promise(function (resolve, reject) {
258269
client.collection(resourceConfig.table || underscore(resourceConfig.name)).find(query, options).toArray(function (err, r) {
259270
if (err) {
260271
reject(err);
@@ -268,10 +279,10 @@ module.exports =
268279
},
269280
create: {
270281
value: function create(resourceConfig, attrs, options) {
271-
var _this = this;
272282
options = options || {};
273-
return _this.getClient().then(function (client) {
274-
return new JSData.DSUtils.Promise(function (resolve, reject) {
283+
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
284+
return this.getClient().then(function (client) {
285+
return new DSUtils.Promise(function (resolve, reject) {
275286
client.collection(resourceConfig.table || underscore(resourceConfig.name)).insert(attrs, options, function (err, r) {
276287
if (err) {
277288
reject(err);
@@ -286,11 +297,12 @@ module.exports =
286297
update: {
287298
value: function update(resourceConfig, id, attrs, options) {
288299
var _this = this;
289-
options = options || {};
290300

291-
return _this.find(resourceConfig, id, options).then(function () {
301+
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
302+
options = options || {};
303+
return this.find(resourceConfig, id, options).then(function () {
292304
return _this.getClient().then(function (client) {
293-
return new JSData.DSUtils.Promise(function (resolve, reject) {
305+
return new DSUtils.Promise(function (resolve, reject) {
294306
var params = {};
295307
params[resourceConfig.idAttribute] = id;
296308
client.collection(resourceConfig.table || underscore(resourceConfig.name)).update(params, { $set: attrs }, options, function (err) {
@@ -310,19 +322,21 @@ module.exports =
310322
updateAll: {
311323
value: function updateAll(resourceConfig, attrs, params, options) {
312324
var _this = this;
325+
313326
var ids = [];
314-
options = options || {};
315-
var _options = JSData.DSUtils.deepMixIn({}, options);
327+
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
328+
options = options ? copy(options) : {};
329+
var _options = copy(options);
316330
_options.multi = true;
317-
return _this.getClient().then(function (client) {
331+
return this.getClient().then(function (client) {
318332
var queryOptions = _this.getQueryOptions(resourceConfig, params);
319333
queryOptions.$set = attrs;
320334
var query = _this.getQuery(resourceConfig, params);
321335
return _this.findAll(resourceConfig, params, options).then(function (items) {
322336
ids = map(items, function (item) {
323337
return item[resourceConfig.idAttribute];
324338
});
325-
return new JSData.DSUtils.Promise(function (resolve, reject) {
339+
return new DSUtils.Promise(function (resolve, reject) {
326340
client.collection(resourceConfig.table || underscore(resourceConfig.name)).update(query, queryOptions, _options, function (err) {
327341
if (err) {
328342
reject(err);
@@ -343,10 +357,9 @@ module.exports =
343357
},
344358
destroy: {
345359
value: function destroy(resourceConfig, id, options) {
346-
var _this = this;
347360
options = options || {};
348-
return _this.getClient().then(function (client) {
349-
return new JSData.DSUtils.Promise(function (resolve, reject) {
361+
return this.getClient().then(function (client) {
362+
return new DSUtils.Promise(function (resolve, reject) {
350363
var params = {};
351364
params[resourceConfig.idAttribute] = id;
352365
client.collection(resourceConfig.table || underscore(resourceConfig.name)).remove(params, options, function (err) {
@@ -363,12 +376,12 @@ module.exports =
363376
destroyAll: {
364377
value: function destroyAll(resourceConfig, params, options) {
365378
var _this = this;
366-
options = options || {};
367-
return _this.getClient().then(function (client) {
368-
options = JSData.DSUtils.deepMixIn({}, options);
369-
JSData.DSUtils.deepMixIn(options, _this.getQueryOptions(resourceConfig, params));
379+
380+
options = options ? copy(options) : {};
381+
return this.getClient().then(function (client) {
382+
deepMixIn(options, _this.getQueryOptions(resourceConfig, params));
370383
var query = _this.getQuery(resourceConfig, params);
371-
return new JSData.DSUtils.Promise(function (resolve, reject) {
384+
return new DSUtils.Promise(function (resolve, reject) {
372385
client.collection(resourceConfig.table || underscore(resourceConfig.name)).remove(query, options, function (err) {
373386
if (err) {
374387
reject(err);
@@ -423,5 +436,123 @@ module.exports =
423436

424437
module.exports = require("mout/lang/isEmpty");
425438

439+
/***/ },
440+
/* 7 */
441+
/***/ function(module, exports, __webpack_require__) {
442+
443+
var slice = __webpack_require__(8);
444+
var contains = __webpack_require__(9);
445+
446+
/**
447+
* Return a copy of the object, filtered to only contain properties except the blacklisted keys.
448+
*/
449+
function omit(obj, var_keys){
450+
var keys = typeof arguments[1] !== 'string'? arguments[1] : slice(arguments, 1),
451+
out = {};
452+
453+
for (var property in obj) {
454+
if (obj.hasOwnProperty(property) && !contains(keys, property)) {
455+
out[property] = obj[property];
456+
}
457+
}
458+
return out;
459+
}
460+
461+
module.exports = omit;
462+
463+
464+
465+
466+
/***/ },
467+
/* 8 */
468+
/***/ function(module, exports, __webpack_require__) {
469+
470+
471+
472+
/**
473+
* Create slice of source array or array-like object
474+
*/
475+
function slice(arr, start, end){
476+
var len = arr.length;
477+
478+
if (start == null) {
479+
start = 0;
480+
} else if (start < 0) {
481+
start = Math.max(len + start, 0);
482+
} else {
483+
start = Math.min(start, len);
484+
}
485+
486+
if (end == null) {
487+
end = len;
488+
} else if (end < 0) {
489+
end = Math.max(len + end, 0);
490+
} else {
491+
end = Math.min(end, len);
492+
}
493+
494+
var result = [];
495+
while (start < end) {
496+
result.push(arr[start++]);
497+
}
498+
499+
return result;
500+
}
501+
502+
module.exports = slice;
503+
504+
505+
506+
507+
/***/ },
508+
/* 9 */
509+
/***/ function(module, exports, __webpack_require__) {
510+
511+
var indexOf = __webpack_require__(10);
512+
513+
/**
514+
* If array contains values.
515+
*/
516+
function contains(arr, val) {
517+
return indexOf(arr, val) !== -1;
518+
}
519+
module.exports = contains;
520+
521+
522+
523+
/***/ },
524+
/* 10 */
525+
/***/ function(module, exports, __webpack_require__) {
526+
527+
528+
529+
/**
530+
* Array.indexOf
531+
*/
532+
function indexOf(arr, item, fromIndex) {
533+
fromIndex = fromIndex || 0;
534+
if (arr == null) {
535+
return -1;
536+
}
537+
538+
var len = arr.length,
539+
i = fromIndex < 0 ? len + fromIndex : fromIndex;
540+
while (i < len) {
541+
// we iterate over sparse items since there is no way to make it
542+
// work properly on IE 7-8. see #64
543+
if (arr[i] === item) {
544+
return i;
545+
}
546+
547+
i++;
548+
}
549+
550+
return -1;
551+
}
552+
553+
module.exports = indexOf;
554+
555+
556+
426557
/***/ }
427558
/******/ ]);

0 commit comments

Comments
 (0)