@@ -45,29 +45,43 @@ module.exports =
45
45
/* 0 */
46
46
/***/ function ( module , exports , __webpack_require__ ) {
47
47
48
+ var _interopRequire = function ( obj ) { return obj && obj . __esModule ? obj [ "default" ] : obj ; } ;
49
+
48
50
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 ; } ; } ) ( ) ;
49
51
50
52
var _classCallCheck = function ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } } ;
51
53
52
54
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 ;
63
77
64
78
var reserved = [ "orderBy" , "sort" , "limit" , "offset" , "skip" , "where" ] ;
65
79
66
80
var DSMongoDBAdapter = ( function ( ) {
67
81
function DSMongoDBAdapter ( uri ) {
68
82
_classCallCheck ( this , DSMongoDBAdapter ) ;
69
83
70
- this . client = new JSData . DSUtils . Promise ( function ( resolve , reject ) {
84
+ this . client = new DSUtils . Promise ( function ( resolve , reject ) {
71
85
MongoClient . connect ( uri , function ( err , db ) {
72
86
return err ? reject ( err ) : resolve ( db ) ;
73
87
} ) ;
@@ -227,10 +241,9 @@ module.exports =
227
241
} ,
228
242
find : {
229
243
value : function find ( resourceConfig , id , options ) {
230
- var _this = this ;
231
244
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 ) {
234
247
var params = { } ;
235
248
params [ resourceConfig . idAttribute ] = id ;
236
249
client . collection ( resourceConfig . table || underscore ( resourceConfig . name ) ) . findOne ( params , options , function ( err , r ) {
@@ -248,13 +261,11 @@ module.exports =
248
261
} ,
249
262
findAll : {
250
263
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 ) {
258
269
client . collection ( resourceConfig . table || underscore ( resourceConfig . name ) ) . find ( query , options ) . toArray ( function ( err , r ) {
259
270
if ( err ) {
260
271
reject ( err ) ;
@@ -268,10 +279,10 @@ module.exports =
268
279
} ,
269
280
create : {
270
281
value : function create ( resourceConfig , attrs , options ) {
271
- var _this = this ;
272
282
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 ) {
275
286
client . collection ( resourceConfig . table || underscore ( resourceConfig . name ) ) . insert ( attrs , options , function ( err , r ) {
276
287
if ( err ) {
277
288
reject ( err ) ;
@@ -286,11 +297,12 @@ module.exports =
286
297
update : {
287
298
value : function update ( resourceConfig , id , attrs , options ) {
288
299
var _this = this ;
289
- options = options || { } ;
290
300
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 ( ) {
292
304
return _this . getClient ( ) . then ( function ( client ) {
293
- return new JSData . DSUtils . Promise ( function ( resolve , reject ) {
305
+ return new DSUtils . Promise ( function ( resolve , reject ) {
294
306
var params = { } ;
295
307
params [ resourceConfig . idAttribute ] = id ;
296
308
client . collection ( resourceConfig . table || underscore ( resourceConfig . name ) ) . update ( params , { $set : attrs } , options , function ( err ) {
@@ -310,19 +322,21 @@ module.exports =
310
322
updateAll : {
311
323
value : function updateAll ( resourceConfig , attrs , params , options ) {
312
324
var _this = this ;
325
+
313
326
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 ) ;
316
330
_options . multi = true ;
317
- return _this . getClient ( ) . then ( function ( client ) {
331
+ return this . getClient ( ) . then ( function ( client ) {
318
332
var queryOptions = _this . getQueryOptions ( resourceConfig , params ) ;
319
333
queryOptions . $set = attrs ;
320
334
var query = _this . getQuery ( resourceConfig , params ) ;
321
335
return _this . findAll ( resourceConfig , params , options ) . then ( function ( items ) {
322
336
ids = map ( items , function ( item ) {
323
337
return item [ resourceConfig . idAttribute ] ;
324
338
} ) ;
325
- return new JSData . DSUtils . Promise ( function ( resolve , reject ) {
339
+ return new DSUtils . Promise ( function ( resolve , reject ) {
326
340
client . collection ( resourceConfig . table || underscore ( resourceConfig . name ) ) . update ( query , queryOptions , _options , function ( err ) {
327
341
if ( err ) {
328
342
reject ( err ) ;
@@ -343,10 +357,9 @@ module.exports =
343
357
} ,
344
358
destroy : {
345
359
value : function destroy ( resourceConfig , id , options ) {
346
- var _this = this ;
347
360
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 ) {
350
363
var params = { } ;
351
364
params [ resourceConfig . idAttribute ] = id ;
352
365
client . collection ( resourceConfig . table || underscore ( resourceConfig . name ) ) . remove ( params , options , function ( err ) {
@@ -363,12 +376,12 @@ module.exports =
363
376
destroyAll : {
364
377
value : function destroyAll ( resourceConfig , params , options ) {
365
378
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 ) ) ;
370
383
var query = _this . getQuery ( resourceConfig , params ) ;
371
- return new JSData . DSUtils . Promise ( function ( resolve , reject ) {
384
+ return new DSUtils . Promise ( function ( resolve , reject ) {
372
385
client . collection ( resourceConfig . table || underscore ( resourceConfig . name ) ) . remove ( query , options , function ( err ) {
373
386
if ( err ) {
374
387
reject ( err ) ;
@@ -423,5 +436,123 @@ module.exports =
423
436
424
437
module . exports = require ( "mout/lang/isEmpty" ) ;
425
438
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
+
426
557
/***/ }
427
558
/******/ ] ) ;
0 commit comments