Merge pull request #693 from ParsePlatform/nlutsenko.collectionPrefix
Remove dependency from DatabaseAdapter on cache.js.
This commit is contained in:
@@ -384,7 +384,7 @@ describe('miscellaneous', function() {
|
|||||||
obj.set('foo', 'bar');
|
obj.set('foo', 'bar');
|
||||||
return obj.save();
|
return obj.save();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
var db = DatabaseAdapter.getDatabaseConnection(appId);
|
var db = DatabaseAdapter.getDatabaseConnection(appId, 'test_');
|
||||||
return db.mongoFind('TestObject', {}, {});
|
return db.mongoFind('TestObject', {}, {});
|
||||||
}).then((results) => {
|
}).then((results) => {
|
||||||
expect(results.length).toEqual(1);
|
expect(results.length).toEqual(1);
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
var Parse = require('parse/node').Parse;
|
var Parse = require('parse/node').Parse;
|
||||||
var DatabaseAdapter = require('../src/DatabaseAdapter');
|
var DatabaseAdapter = require('../src/DatabaseAdapter');
|
||||||
|
|
||||||
var database = DatabaseAdapter.getDatabaseConnection('test');
|
let database = DatabaseAdapter.getDatabaseConnection('test', 'test_');
|
||||||
|
|
||||||
describe('a GlobalConfig', () => {
|
describe('a GlobalConfig', () => {
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
'use strict';
|
||||||
// These tests check the Installations functionality of the REST API.
|
// These tests check the Installations functionality of the REST API.
|
||||||
// Ported from installation_collection_test.go
|
// Ported from installation_collection_test.go
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ var Parse = require('parse/node').Parse;
|
|||||||
var rest = require('../src/rest');
|
var rest = require('../src/rest');
|
||||||
|
|
||||||
var config = new Config('test');
|
var config = new Config('test');
|
||||||
var database = DatabaseAdapter.getDatabaseConnection('test');
|
let database = DatabaseAdapter.getDatabaseConnection('test', 'test_');
|
||||||
|
|
||||||
describe('Installations', () => {
|
describe('Installations', () => {
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ var rest = require('../src/rest');
|
|||||||
var request = require('request');
|
var request = require('request');
|
||||||
|
|
||||||
var config = new Config('test');
|
var config = new Config('test');
|
||||||
var database = DatabaseAdapter.getDatabaseConnection('test');
|
var database = DatabaseAdapter.getDatabaseConnection('test', 'test_');
|
||||||
|
|
||||||
describe('rest create', () => {
|
describe('rest create', () => {
|
||||||
it('handles _id', (done) => {
|
it('handles _id', (done) => {
|
||||||
|
|||||||
@@ -5,12 +5,10 @@
|
|||||||
import cache from './cache';
|
import cache from './cache';
|
||||||
|
|
||||||
export class Config {
|
export class Config {
|
||||||
|
constructor(applicationId: string, mount: string) {
|
||||||
|
let DatabaseAdapter = require('./DatabaseAdapter');
|
||||||
|
|
||||||
constructor(applicationId, mount) {
|
let cacheInfo = cache.apps[applicationId];
|
||||||
|
|
||||||
var DatabaseAdapter = require('./DatabaseAdapter');
|
|
||||||
|
|
||||||
var cacheInfo = cache.apps[applicationId];
|
|
||||||
this.valid = !!cacheInfo;
|
this.valid = !!cacheInfo;
|
||||||
if (!this.valid) {
|
if (!this.valid) {
|
||||||
return;
|
return;
|
||||||
@@ -27,7 +25,7 @@ export class Config {
|
|||||||
this.facebookAppIds = cacheInfo.facebookAppIds;
|
this.facebookAppIds = cacheInfo.facebookAppIds;
|
||||||
this.enableAnonymousUsers = cacheInfo.enableAnonymousUsers;
|
this.enableAnonymousUsers = cacheInfo.enableAnonymousUsers;
|
||||||
this.allowClientClassCreation = cacheInfo.allowClientClassCreation;
|
this.allowClientClassCreation = cacheInfo.allowClientClassCreation;
|
||||||
this.database = DatabaseAdapter.getDatabaseConnection(applicationId);
|
this.database = DatabaseAdapter.getDatabaseConnection(applicationId, this.collectionPrefix);
|
||||||
this.hooksController = cacheInfo.hooksController;
|
this.hooksController = cacheInfo.hooksController;
|
||||||
this.filesController = cacheInfo.filesController;
|
this.filesController = cacheInfo.filesController;
|
||||||
this.pushController = cacheInfo.pushController;
|
this.pushController = cacheInfo.pushController;
|
||||||
@@ -36,7 +34,7 @@ export class Config {
|
|||||||
|
|
||||||
this.mount = mount;
|
this.mount = mount;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export default Config;
|
export default Config;
|
||||||
module.exports = Config;
|
module.exports = Config;
|
||||||
|
|||||||
@@ -1,23 +1,31 @@
|
|||||||
var DatabaseAdapter = require('../DatabaseAdapter'),
|
/** @flow weak */
|
||||||
triggers = require('../triggers'),
|
|
||||||
request = require('request');
|
import * as DatabaseAdapter from "../DatabaseAdapter";
|
||||||
const collection = "_Hooks";
|
import * as triggers from "../triggers";
|
||||||
|
import * as Parse from "parse/node";
|
||||||
|
import * as request from "request";
|
||||||
|
|
||||||
|
const DefaultHooksCollectionName = "_Hooks";
|
||||||
|
|
||||||
export class HooksController {
|
export class HooksController {
|
||||||
|
_applicationId: string;
|
||||||
constructor(applicationId) {
|
_collectionPrefix: string;
|
||||||
this.applicationId = applicationId;
|
_collection;
|
||||||
|
|
||||||
|
constructor(applicationId: string, collectionPrefix: string = '') {
|
||||||
|
this._applicationId = applicationId;
|
||||||
|
this._collectionPrefix = collectionPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
database() {
|
database() {
|
||||||
return DatabaseAdapter.getDatabaseConnection(this.applicationId);
|
return DatabaseAdapter.getDatabaseConnection(this._applicationId, this._collectionPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
collection() {
|
collection() {
|
||||||
if (this._collection) {
|
if (this._collection) {
|
||||||
return Promise.resolve(this._collection)
|
return Promise.resolve(this._collection)
|
||||||
}
|
}
|
||||||
return this.database().rawCollection(collection).then((collection) => {
|
return this.database().rawCollection(DefaultHooksCollectionName).then((collection) => {
|
||||||
this._collection = collection;
|
this._collection = collection;
|
||||||
return collection;
|
return collection;
|
||||||
});
|
});
|
||||||
@@ -40,12 +48,12 @@ export class HooksController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
deleteFunction(functionName) {
|
deleteFunction(functionName) {
|
||||||
triggers.removeFunction(functionName, this.applicationId);
|
triggers.removeFunction(functionName, this._applicationId);
|
||||||
return this.delete({functionName: functionName});
|
return this.delete({functionName: functionName});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteTrigger(className, triggerName) {
|
deleteTrigger(className, triggerName) {
|
||||||
triggers.removeTrigger(triggerName, className, this.applicationId);
|
triggers.removeTrigger(triggerName, className, this._applicationId);
|
||||||
return this.delete({className: className, triggerName: triggerName});
|
return this.delete({className: className, triggerName: triggerName});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +68,7 @@ export class HooksController {
|
|||||||
getOne(query) {
|
getOne(query) {
|
||||||
return this.collection()
|
return this.collection()
|
||||||
.then(coll => coll.findOne(query, {_id: 0}))
|
.then(coll => coll.findOne(query, {_id: 0}))
|
||||||
.then(hook => {
|
.then(hook => {
|
||||||
return hook;
|
return hook;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -68,7 +76,7 @@ export class HooksController {
|
|||||||
get(query) {
|
get(query) {
|
||||||
return this.collection()
|
return this.collection()
|
||||||
.then(coll => coll.find(query, {_id: 0}).toArray())
|
.then(coll => coll.find(query, {_id: 0}).toArray())
|
||||||
.then(hooks => {
|
.then(hooks => {
|
||||||
return hooks;
|
return hooks;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -102,9 +110,9 @@ export class HooksController {
|
|||||||
var wrappedFunction = wrapToHTTPRequest(hook);
|
var wrappedFunction = wrapToHTTPRequest(hook);
|
||||||
wrappedFunction.url = hook.url;
|
wrappedFunction.url = hook.url;
|
||||||
if (hook.className) {
|
if (hook.className) {
|
||||||
triggers.addTrigger(hook.triggerName, hook.className, wrappedFunction, this.applicationId)
|
triggers.addTrigger(hook.triggerName, hook.className, wrappedFunction, this._applicationId)
|
||||||
} else {
|
} else {
|
||||||
triggers.addFunction(hook.functionName, wrappedFunction, null, this.applicationId);
|
triggers.addFunction(hook.functionName, wrappedFunction, null, this._applicationId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/** @flow weak */
|
||||||
// Database Adapter
|
// Database Adapter
|
||||||
//
|
//
|
||||||
// Allows you to change the underlying database.
|
// Allows you to change the underlying database.
|
||||||
@@ -13,7 +14,6 @@
|
|||||||
// * This list is incomplete and the database process is not fully modularized.
|
// * This list is incomplete and the database process is not fully modularized.
|
||||||
//
|
//
|
||||||
// Default is ExportAdapter, which uses mongo.
|
// Default is ExportAdapter, which uses mongo.
|
||||||
import cache from './cache';
|
|
||||||
|
|
||||||
var ExportAdapter = require('./ExportAdapter');
|
var ExportAdapter = require('./ExportAdapter');
|
||||||
|
|
||||||
@@ -40,14 +40,14 @@ function clearDatabaseURIs() {
|
|||||||
dbConnections = {};
|
dbConnections = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDatabaseConnection(appId) {
|
function getDatabaseConnection(appId: string, collectionPrefix: string) {
|
||||||
if (dbConnections[appId]) {
|
if (dbConnections[appId]) {
|
||||||
return dbConnections[appId];
|
return dbConnections[appId];
|
||||||
}
|
}
|
||||||
|
|
||||||
var dbURI = (appDatabaseURIs[appId] ? appDatabaseURIs[appId] : databaseURI);
|
var dbURI = (appDatabaseURIs[appId] ? appDatabaseURIs[appId] : databaseURI);
|
||||||
dbConnections[appId] = new adapter(dbURI, {
|
dbConnections[appId] = new adapter(dbURI, {
|
||||||
collectionPrefix: cache.apps[appId]['collectionPrefix']
|
collectionPrefix: collectionPrefix
|
||||||
});
|
});
|
||||||
dbConnections[appId].connect();
|
dbConnections[appId].connect();
|
||||||
return dbConnections[appId];
|
return dbConnections[appId];
|
||||||
@@ -59,5 +59,5 @@ module.exports = {
|
|||||||
setAdapter: setAdapter,
|
setAdapter: setAdapter,
|
||||||
setDatabaseURI: setDatabaseURI,
|
setDatabaseURI: setDatabaseURI,
|
||||||
setAppDatabaseURI: setAppDatabaseURI,
|
setAppDatabaseURI: setAppDatabaseURI,
|
||||||
clearDatabaseURIs: clearDatabaseURIs,
|
clearDatabaseURIs: clearDatabaseURIs
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ function ParseServer({
|
|||||||
const filesController = new FilesController(filesControllerAdapter);
|
const filesController = new FilesController(filesControllerAdapter);
|
||||||
const pushController = new PushController(pushControllerAdapter);
|
const pushController = new PushController(pushControllerAdapter);
|
||||||
const loggerController = new LoggerController(loggerControllerAdapter);
|
const loggerController = new LoggerController(loggerControllerAdapter);
|
||||||
const hooksController = new HooksController(appId);
|
const hooksController = new HooksController(appId, collectionPrefix);
|
||||||
|
|
||||||
cache.apps[appId] = {
|
cache.apps[appId] = {
|
||||||
masterKey: masterKey,
|
masterKey: masterKey,
|
||||||
@@ -141,7 +141,7 @@ function ParseServer({
|
|||||||
hooksController: hooksController,
|
hooksController: hooksController,
|
||||||
enableAnonymousUsers: enableAnonymousUsers,
|
enableAnonymousUsers: enableAnonymousUsers,
|
||||||
allowClientClassCreation: allowClientClassCreation,
|
allowClientClassCreation: allowClientClassCreation,
|
||||||
oauth: oauth,
|
oauth: oauth
|
||||||
};
|
};
|
||||||
|
|
||||||
// To maintain compatibility. TODO: Remove in v2.1
|
// To maintain compatibility. TODO: Remove in v2.1
|
||||||
|
|||||||
Reference in New Issue
Block a user