@@ -5,12 +5,12 @@ var mongodb = require('mongodb');
5
5
var MongoClient = mongodb . MongoClient ;
6
6
var Parse = require ( 'parse/node' ) . Parse ;
7
7
8
- var Schema = require ( './Schema' ) ;
9
- var transform = require ( './transform' ) ;
8
+ var Schema = require ( './../ Schema' ) ;
9
+ var transform = require ( './../ transform' ) ;
10
10
11
11
// options can contain:
12
12
// collectionPrefix: the string to put in front of every collection name.
13
- function ExportAdapter ( mongoURI , options = { } ) {
13
+ function DatabaseController ( mongoURI , options = { } ) {
14
14
this . mongoURI = mongoURI ;
15
15
16
16
this . collectionPrefix = options . collectionPrefix ;
@@ -27,7 +27,7 @@ function ExportAdapter(mongoURI, options = {}) {
27
27
// connection is successful.
28
28
// this.db will be populated with a Mongo "Db" object when the
29
29
// promise resolves successfully.
30
- ExportAdapter . prototype . connect = function ( ) {
30
+ DatabaseController . prototype . connect = function ( ) {
31
31
if ( this . connectionPromise ) {
32
32
// There's already a connection in progress.
33
33
return this . connectionPromise ;
@@ -43,15 +43,15 @@ ExportAdapter.prototype.connect = function() {
43
43
44
44
// Returns a promise for a Mongo collection.
45
45
// Generally just for internal use.
46
- ExportAdapter . prototype . collection = function ( className ) {
46
+ DatabaseController . prototype . collection = function ( className ) {
47
47
if ( ! Schema . classNameIsValid ( className ) ) {
48
48
throw new Parse . Error ( Parse . Error . INVALID_CLASS_NAME ,
49
49
'invalid className: ' + className ) ;
50
50
}
51
51
return this . rawCollection ( className ) ;
52
52
} ;
53
53
54
- ExportAdapter . prototype . rawCollection = function ( className ) {
54
+ DatabaseController . prototype . rawCollection = function ( className ) {
55
55
return this . connect ( ) . then ( ( ) => {
56
56
return this . db . collection ( this . collectionPrefix + className ) ;
57
57
} ) ;
@@ -64,7 +64,7 @@ function returnsTrue() {
64
64
// Returns a promise for a schema object.
65
65
// If we are provided a acceptor, then we run it on the schema.
66
66
// If the schema isn't accepted, we reload it at most once.
67
- ExportAdapter . prototype . loadSchema = function ( acceptor = returnsTrue ) {
67
+ DatabaseController . prototype . loadSchema = function ( acceptor = returnsTrue ) {
68
68
69
69
if ( ! this . schemaPromise ) {
70
70
this . schemaPromise = this . collection ( '_SCHEMA' ) . then ( ( coll ) => {
@@ -88,8 +88,8 @@ ExportAdapter.prototype.loadSchema = function(acceptor = returnsTrue) {
88
88
89
89
// Returns a promise for the classname that is related to the given
90
90
// classname through the key.
91
- // TODO: make this not in the ExportAdapter interface
92
- ExportAdapter . prototype . redirectClassNameForKey = function ( className , key ) {
91
+ // TODO: make this not in the DatabaseController interface
92
+ DatabaseController . prototype . redirectClassNameForKey = function ( className , key ) {
93
93
return this . loadSchema ( ) . then ( ( schema ) => {
94
94
var t = schema . getExpectedType ( className , key ) ;
95
95
var match = t . match ( / ^ r e l a t i o n < ( .* ) > $ / ) ;
@@ -105,15 +105,15 @@ ExportAdapter.prototype.redirectClassNameForKey = function(className, key) {
105
105
// Returns a promise that resolves to the new schema.
106
106
// This does not update this.schema, because in a situation like a
107
107
// batch request, that could confuse other users of the schema.
108
- ExportAdapter . prototype . validateObject = function ( className , object , query ) {
108
+ DatabaseController . prototype . validateObject = function ( className , object , query ) {
109
109
return this . loadSchema ( ) . then ( ( schema ) => {
110
110
return schema . validateObject ( className , object , query ) ;
111
111
} ) ;
112
112
} ;
113
113
114
114
// Like transform.untransformObject but you need to provide a className.
115
115
// Filters out any data that shouldn't be on this REST-formatted object.
116
- ExportAdapter . prototype . untransformObject = function (
116
+ DatabaseController . prototype . untransformObject = function (
117
117
schema , isMaster , aclGroup , className , mongoObject ) {
118
118
var object = transform . untransformObject ( schema , className , mongoObject ) ;
119
119
@@ -138,7 +138,7 @@ ExportAdapter.prototype.untransformObject = function(
138
138
// acl: a list of strings. If the object to be updated has an ACL,
139
139
// one of the provided strings must provide the caller with
140
140
// write permissions.
141
- ExportAdapter . prototype . update = function ( className , query , update , options ) {
141
+ DatabaseController . prototype . update = function ( className , query , update , options ) {
142
142
var acceptor = function ( schema ) {
143
143
return schema . hasKeys ( className , Object . keys ( query ) ) ;
144
144
} ;
@@ -196,7 +196,7 @@ ExportAdapter.prototype.update = function(className, query, update, options) {
196
196
// Returns a promise that resolves successfully when these are
197
197
// processed.
198
198
// This mutates update.
199
- ExportAdapter . prototype . handleRelationUpdates = function ( className ,
199
+ DatabaseController . prototype . handleRelationUpdates = function ( className ,
200
200
objectId ,
201
201
update ) {
202
202
var pending = [ ] ;
@@ -243,7 +243,7 @@ ExportAdapter.prototype.handleRelationUpdates = function(className,
243
243
244
244
// Adds a relation.
245
245
// Returns a promise that resolves successfully iff the add was successful.
246
- ExportAdapter . prototype . addRelation = function ( key , fromClassName ,
246
+ DatabaseController . prototype . addRelation = function ( key , fromClassName ,
247
247
fromId , toId ) {
248
248
var doc = {
249
249
relatedId : toId ,
@@ -258,7 +258,7 @@ ExportAdapter.prototype.addRelation = function(key, fromClassName,
258
258
// Removes a relation.
259
259
// Returns a promise that resolves successfully iff the remove was
260
260
// successful.
261
- ExportAdapter . prototype . removeRelation = function ( key , fromClassName ,
261
+ DatabaseController . prototype . removeRelation = function ( key , fromClassName ,
262
262
fromId , toId ) {
263
263
var doc = {
264
264
relatedId : toId ,
@@ -277,7 +277,7 @@ ExportAdapter.prototype.removeRelation = function(key, fromClassName,
277
277
// acl: a list of strings. If the object to be updated has an ACL,
278
278
// one of the provided strings must provide the caller with
279
279
// write permissions.
280
- ExportAdapter . prototype . destroy = function ( className , query , options = { } ) {
280
+ DatabaseController . prototype . destroy = function ( className , query , options = { } ) {
281
281
var isMaster = ! ( 'acl' in options ) ;
282
282
var aclGroup = options . acl || [ ] ;
283
283
@@ -320,7 +320,7 @@ ExportAdapter.prototype.destroy = function(className, query, options = {}) {
320
320
321
321
// Inserts an object into the database.
322
322
// Returns a promise that resolves successfully iff the object saved.
323
- ExportAdapter . prototype . create = function ( className , object , options ) {
323
+ DatabaseController . prototype . create = function ( className , object , options ) {
324
324
var schema ;
325
325
var isMaster = ! ( 'acl' in options ) ;
326
326
var aclGroup = options . acl || [ ] ;
@@ -346,7 +346,7 @@ ExportAdapter.prototype.create = function(className, object, options) {
346
346
// This should only be used for testing - use 'find' for normal code
347
347
// to avoid Mongo-format dependencies.
348
348
// Returns a promise that resolves to a list of items.
349
- ExportAdapter . prototype . mongoFind = function ( className , query , options = { } ) {
349
+ DatabaseController . prototype . mongoFind = function ( className , query , options = { } ) {
350
350
return this . collection ( className ) . then ( ( coll ) => {
351
351
return coll . find ( query , options ) . toArray ( ) ;
352
352
} ) ;
@@ -355,7 +355,7 @@ ExportAdapter.prototype.mongoFind = function(className, query, options = {}) {
355
355
// Deletes everything in the database matching the current collectionPrefix
356
356
// Won't delete collections in the system namespace
357
357
// Returns a promise.
358
- ExportAdapter . prototype . deleteEverything = function ( ) {
358
+ DatabaseController . prototype . deleteEverything = function ( ) {
359
359
this . schemaPromise = null ;
360
360
361
361
return this . connect ( ) . then ( ( ) => {
@@ -390,7 +390,7 @@ function keysForQuery(query) {
390
390
391
391
// Returns a promise for a list of related ids given an owning id.
392
392
// className here is the owning className.
393
- ExportAdapter . prototype . relatedIds = function ( className , key , owningId ) {
393
+ DatabaseController . prototype . relatedIds = function ( className , key , owningId ) {
394
394
var joinTable = '_Join:' + key + ':' + className ;
395
395
return this . collection ( joinTable ) . then ( ( coll ) => {
396
396
return coll . find ( { owningId : owningId } ) . toArray ( ) ;
@@ -401,7 +401,7 @@ ExportAdapter.prototype.relatedIds = function(className, key, owningId) {
401
401
402
402
// Returns a promise for a list of owning ids given some related ids.
403
403
// className here is the owning className.
404
- ExportAdapter . prototype . owningIds = function ( className , key , relatedIds ) {
404
+ DatabaseController . prototype . owningIds = function ( className , key , relatedIds ) {
405
405
var joinTable = '_Join:' + key + ':' + className ;
406
406
return this . collection ( joinTable ) . then ( ( coll ) => {
407
407
return coll . find ( { relatedId : { '$in' : relatedIds } } ) . toArray ( ) ;
@@ -414,7 +414,7 @@ ExportAdapter.prototype.owningIds = function(className, key, relatedIds) {
414
414
// equal-to-pointer constraints on relation fields.
415
415
// Returns a promise that resolves when query is mutated
416
416
// TODO: this only handles one of these at a time - make it handle more
417
- ExportAdapter . prototype . reduceInRelation = function ( className , query , schema ) {
417
+ DatabaseController . prototype . reduceInRelation = function ( className , query , schema ) {
418
418
// Search for an in-relation or equal-to-relation
419
419
for ( var key in query ) {
420
420
if ( query [ key ] &&
@@ -442,7 +442,7 @@ ExportAdapter.prototype.reduceInRelation = function(className, query, schema) {
442
442
443
443
// Modifies query so that it no longer has $relatedTo
444
444
// Returns a promise that resolves when query is mutated
445
- ExportAdapter . prototype . reduceRelationKeys = function ( className , query ) {
445
+ DatabaseController . prototype . reduceRelationKeys = function ( className , query ) {
446
446
var relatedTo = query [ '$relatedTo' ] ;
447
447
if ( relatedTo ) {
448
448
return this . relatedIds (
@@ -461,7 +461,7 @@ ExportAdapter.prototype.reduceRelationKeys = function(className, query) {
461
461
// none, then build the geoindex.
462
462
// This could be improved a lot but it's not clear if that's a good
463
463
// idea. Or even if this behavior is a good idea.
464
- ExportAdapter . prototype . smartFind = function ( coll , where , options ) {
464
+ DatabaseController . prototype . smartFind = function ( coll , where , options ) {
465
465
return coll . find ( where , options ) . toArray ( )
466
466
. then ( ( result ) => {
467
467
return result ;
@@ -502,7 +502,7 @@ ExportAdapter.prototype.smartFind = function(coll, where, options) {
502
502
// TODO: make userIds not needed here. The db adapter shouldn't know
503
503
// anything about users, ideally. Then, improve the format of the ACL
504
504
// arg to work like the others.
505
- ExportAdapter . prototype . find = function ( className , query , options = { } ) {
505
+ DatabaseController . prototype . find = function ( className , query , options = { } ) {
506
506
var mongoOptions = { } ;
507
507
if ( options . skip ) {
508
508
mongoOptions . skip = options . skip ;
@@ -568,4 +568,4 @@ ExportAdapter.prototype.find = function(className, query, options = {}) {
568
568
} ) ;
569
569
} ;
570
570
571
- module . exports = ExportAdapter ;
571
+ module . exports = DatabaseController ;
0 commit comments