@@ -87,10 +87,10 @@ DatabaseController.prototype.redirectClassNameForKey = function(className, key)
87
87
// Returns a promise that resolves to the new schema.
88
88
// This does not update this.schema, because in a situation like a
89
89
// batch request, that could confuse other users of the schema.
90
- DatabaseController . prototype . validateObject = function ( className , object , query , options ) {
90
+ DatabaseController . prototype . validateObject = function ( className , object , query , { acl } ) {
91
91
let schema ;
92
- let isMaster = ! ( ' acl' in options ) ;
93
- var aclGroup = options . acl || [ ] ;
92
+ let isMaster = acl === undefined ;
93
+ var aclGroup = acl || [ ] ;
94
94
return this . loadSchema ( ) . then ( s => {
95
95
schema = s ;
96
96
if ( isMaster ) {
@@ -131,14 +131,18 @@ DatabaseController.prototype.untransformObject = function(
131
131
// acl: a list of strings. If the object to be updated has an ACL,
132
132
// one of the provided strings must provide the caller with
133
133
// write permissions.
134
- DatabaseController . prototype . update = function ( className , query , update , options = { } ) {
134
+ DatabaseController . prototype . update = function ( className , query , update , {
135
+ acl,
136
+ many,
137
+ upsert,
138
+ } = { } ) {
135
139
136
140
const originalUpdate = update ;
137
141
// Make a copy of the object, so we don't mutate the incoming data.
138
142
update = deepcopy ( update ) ;
139
143
140
- var isMaster = ! ( ' acl' in options ) ;
141
- var aclGroup = options . acl || [ ] ;
144
+ var isMaster = acl === undefined ;
145
+ var aclGroup = acl || [ ] ;
142
146
var mongoUpdate , schema ;
143
147
return this . loadSchema ( )
144
148
. then ( s => {
@@ -158,13 +162,13 @@ DatabaseController.prototype.update = function(className, query, update, options
158
162
return Promise . resolve ( ) ;
159
163
}
160
164
var mongoWhere = this . transform . transformWhere ( schema , className , query , { validate : ! this . skipValidation } ) ;
161
- if ( options . acl ) {
162
- mongoWhere = this . transform . addWriteACL ( mongoWhere , options . acl ) ;
165
+ if ( acl ) {
166
+ mongoWhere = this . transform . addWriteACL ( mongoWhere , acl ) ;
163
167
}
164
168
mongoUpdate = this . transform . transformUpdate ( schema , className , update , { validate : ! this . skipValidation } ) ;
165
- if ( options . many ) {
169
+ if ( many ) {
166
170
return collection . updateMany ( mongoWhere , mongoUpdate ) ;
167
- } else if ( options . upsert ) {
171
+ } else if ( upsert ) {
168
172
return collection . upsertOne ( mongoWhere , mongoUpdate ) ;
169
173
} else {
170
174
return collection . findOneAndUpdate ( mongoWhere , mongoUpdate ) ;
@@ -203,9 +207,7 @@ function sanitizeDatabaseResult(originalObject, result) {
203
207
// Returns a promise that resolves successfully when these are
204
208
// processed.
205
209
// This mutates update.
206
- DatabaseController . prototype . handleRelationUpdates = function ( className ,
207
- objectId ,
208
- update ) {
210
+ DatabaseController . prototype . handleRelationUpdates = function ( className , objectId , update ) {
209
211
var pending = [ ] ;
210
212
var deleteMe = [ ] ;
211
213
objectId = update . objectId || objectId ;
@@ -282,9 +284,9 @@ DatabaseController.prototype.removeRelation = function(key, fromClassName, fromI
282
284
// acl: a list of strings. If the object to be updated has an ACL,
283
285
// one of the provided strings must provide the caller with
284
286
// write permissions.
285
- DatabaseController . prototype . destroy = function ( className , query , options = { } ) {
286
- var isMaster = ! ( ' acl' in options ) ;
287
- var aclGroup = options . acl || [ ] ;
287
+ DatabaseController . prototype . destroy = function ( className , query , { acl } = { } ) {
288
+ var isMaster = acl !== undefined ;
289
+ var aclGroup = acl || [ ] ;
288
290
289
291
var schema ;
290
292
return this . loadSchema ( )
@@ -304,8 +306,8 @@ DatabaseController.prototype.destroy = function(className, query, options = {})
304
306
}
305
307
}
306
308
let mongoWhere = this . transform . transformWhere ( schema , className , query , { validate : ! this . skipValidation } ) ;
307
- if ( options . acl ) {
308
- mongoWhere = this . transform . addWriteACL ( mongoWhere , options . acl ) ;
309
+ if ( acl ) {
310
+ mongoWhere = this . transform . addWriteACL ( mongoWhere , acl ) ;
309
311
}
310
312
return collection . deleteMany ( mongoWhere ) ;
311
313
} )
@@ -320,13 +322,13 @@ DatabaseController.prototype.destroy = function(className, query, options = {})
320
322
321
323
// Inserts an object into the database.
322
324
// Returns a promise that resolves successfully iff the object saved.
323
- DatabaseController . prototype . create = function ( className , object , options = { } ) {
325
+ DatabaseController . prototype . create = function ( className , object , { acl } = { } ) {
324
326
// Make a copy of the object, so we don't mutate the incoming data.
325
327
let originalObject = object ;
326
328
object = deepcopy ( object ) ;
327
329
328
- var isMaster = ! ( ' acl' in options ) ;
329
- var aclGroup = options . acl || [ ] ;
330
+ var isMaster = acl === undefined ;
331
+ var aclGroup = acl || [ ] ;
330
332
331
333
return this . validateClassName ( className )
332
334
. then ( ( ) => this . loadSchema ( ) )
@@ -570,27 +572,33 @@ DatabaseController.prototype.addNotInObjectIdsIds = function(ids = null, query)
570
572
// TODO: make userIds not needed here. The db adapter shouldn't know
571
573
// anything about users, ideally. Then, improve the format of the ACL
572
574
// arg to work like the others.
573
- DatabaseController . prototype . find = function ( className , query , options = { } ) {
575
+ DatabaseController . prototype . find = function ( className , query , {
576
+ skip,
577
+ limit,
578
+ acl,
579
+ sort,
580
+ count,
581
+ } = { } ) {
574
582
let mongoOptions = { } ;
575
- if ( options . skip ) {
576
- mongoOptions . skip = options . skip ;
583
+ if ( skip ) {
584
+ mongoOptions . skip = skip ;
577
585
}
578
- if ( options . limit ) {
579
- mongoOptions . limit = options . limit ;
586
+ if ( limit ) {
587
+ mongoOptions . limit = limit ;
580
588
}
581
- let isMaster = ! ( ' acl' in options ) ;
582
- let aclGroup = options . acl || [ ] ;
589
+ let isMaster = acl === undefined ;
590
+ let aclGroup = acl || [ ] ;
583
591
let schema = null ;
584
592
let op = typeof query . objectId == 'string' && Object . keys ( query ) . length === 1 ?
585
593
'get' :
586
594
'find' ;
587
595
return this . loadSchema ( ) . then ( s => {
588
596
schema = s ;
589
- if ( options . sort ) {
597
+ if ( sort ) {
590
598
mongoOptions . sort = { } ;
591
- for ( let key in options . sort ) {
599
+ for ( let key in sort ) {
592
600
let mongoKey = this . transform . transformKey ( schema , className , key ) ;
593
- mongoOptions . sort [ mongoKey ] = options . sort [ key ] ;
601
+ mongoOptions . sort [ mongoKey ] = sort [ key ] ;
594
602
}
595
603
}
596
604
@@ -618,7 +626,7 @@ DatabaseController.prototype.find = function(className, query, options = {}) {
618
626
if ( ! isMaster ) {
619
627
mongoWhere = this . transform . addReadACL ( mongoWhere , aclGroup ) ;
620
628
}
621
- if ( options . count ) {
629
+ if ( count ) {
622
630
delete mongoOptions . limit ;
623
631
return collection . count ( mongoWhere , mongoOptions ) ;
624
632
} else {
0 commit comments