Remove dependency from DatabaseAdapter on cache.js.
This commit is contained in:
@@ -5,12 +5,10 @@
|
||||
import cache from './cache';
|
||||
|
||||
export class Config {
|
||||
constructor(applicationId: string, mount: string) {
|
||||
let DatabaseAdapter = require('./DatabaseAdapter');
|
||||
|
||||
constructor(applicationId, mount) {
|
||||
|
||||
var DatabaseAdapter = require('./DatabaseAdapter');
|
||||
|
||||
var cacheInfo = cache.apps[applicationId];
|
||||
let cacheInfo = cache.apps[applicationId];
|
||||
this.valid = !!cacheInfo;
|
||||
if (!this.valid) {
|
||||
return;
|
||||
@@ -27,7 +25,7 @@ export class Config {
|
||||
this.facebookAppIds = cacheInfo.facebookAppIds;
|
||||
this.enableAnonymousUsers = cacheInfo.enableAnonymousUsers;
|
||||
this.allowClientClassCreation = cacheInfo.allowClientClassCreation;
|
||||
this.database = DatabaseAdapter.getDatabaseConnection(applicationId);
|
||||
this.database = DatabaseAdapter.getDatabaseConnection(applicationId, this.collectionPrefix);
|
||||
this.hooksController = cacheInfo.hooksController;
|
||||
this.filesController = cacheInfo.filesController;
|
||||
this.pushController = cacheInfo.pushController;
|
||||
@@ -36,7 +34,7 @@ export class Config {
|
||||
|
||||
this.mount = mount;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default Config;
|
||||
module.exports = Config;
|
||||
|
||||
@@ -1,23 +1,31 @@
|
||||
var DatabaseAdapter = require('../DatabaseAdapter'),
|
||||
triggers = require('../triggers'),
|
||||
request = require('request');
|
||||
const collection = "_Hooks";
|
||||
/** @flow weak */
|
||||
|
||||
import * as DatabaseAdapter from "../DatabaseAdapter";
|
||||
import * as triggers from "../triggers";
|
||||
import * as Parse from "parse/node";
|
||||
import * as request from "request";
|
||||
|
||||
const DefaultHooksCollectionName = "_Hooks";
|
||||
|
||||
export class HooksController {
|
||||
|
||||
constructor(applicationId) {
|
||||
this.applicationId = applicationId;
|
||||
_applicationId: string;
|
||||
_collectionPrefix: string;
|
||||
_collection;
|
||||
|
||||
constructor(applicationId: string, collectionPrefix: string = '') {
|
||||
this._applicationId = applicationId;
|
||||
this._collectionPrefix = collectionPrefix;
|
||||
}
|
||||
|
||||
database() {
|
||||
return DatabaseAdapter.getDatabaseConnection(this.applicationId);
|
||||
return DatabaseAdapter.getDatabaseConnection(this._applicationId, this._collectionPrefix);
|
||||
}
|
||||
|
||||
collection() {
|
||||
if (this._collection) {
|
||||
return Promise.resolve(this._collection)
|
||||
}
|
||||
return this.database().rawCollection(collection).then((collection) => {
|
||||
return this.database().rawCollection(DefaultHooksCollectionName).then((collection) => {
|
||||
this._collection = collection;
|
||||
return collection;
|
||||
});
|
||||
@@ -40,12 +48,12 @@ export class HooksController {
|
||||
}
|
||||
|
||||
deleteFunction(functionName) {
|
||||
triggers.removeFunction(functionName, this.applicationId);
|
||||
triggers.removeFunction(functionName, this._applicationId);
|
||||
return this.delete({functionName: functionName});
|
||||
}
|
||||
|
||||
deleteTrigger(className, triggerName) {
|
||||
triggers.removeTrigger(triggerName, className, this.applicationId);
|
||||
triggers.removeTrigger(triggerName, className, this._applicationId);
|
||||
return this.delete({className: className, triggerName: triggerName});
|
||||
}
|
||||
|
||||
@@ -60,7 +68,7 @@ export class HooksController {
|
||||
getOne(query) {
|
||||
return this.collection()
|
||||
.then(coll => coll.findOne(query, {_id: 0}))
|
||||
.then(hook => {
|
||||
.then(hook => {
|
||||
return hook;
|
||||
});
|
||||
}
|
||||
@@ -68,7 +76,7 @@ export class HooksController {
|
||||
get(query) {
|
||||
return this.collection()
|
||||
.then(coll => coll.find(query, {_id: 0}).toArray())
|
||||
.then(hooks => {
|
||||
.then(hooks => {
|
||||
return hooks;
|
||||
});
|
||||
}
|
||||
@@ -102,9 +110,9 @@ export class HooksController {
|
||||
var wrappedFunction = wrapToHTTPRequest(hook);
|
||||
wrappedFunction.url = hook.url;
|
||||
if (hook.className) {
|
||||
triggers.addTrigger(hook.triggerName, hook.className, wrappedFunction, this.applicationId)
|
||||
triggers.addTrigger(hook.triggerName, hook.className, wrappedFunction, this._applicationId)
|
||||
} 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
|
||||
//
|
||||
// Allows you to change the underlying database.
|
||||
@@ -13,7 +14,6 @@
|
||||
// * This list is incomplete and the database process is not fully modularized.
|
||||
//
|
||||
// Default is ExportAdapter, which uses mongo.
|
||||
import cache from './cache';
|
||||
|
||||
var ExportAdapter = require('./ExportAdapter');
|
||||
|
||||
@@ -40,14 +40,14 @@ function clearDatabaseURIs() {
|
||||
dbConnections = {};
|
||||
}
|
||||
|
||||
function getDatabaseConnection(appId) {
|
||||
function getDatabaseConnection(appId: string, collectionPrefix: string) {
|
||||
if (dbConnections[appId]) {
|
||||
return dbConnections[appId];
|
||||
}
|
||||
|
||||
var dbURI = (appDatabaseURIs[appId] ? appDatabaseURIs[appId] : databaseURI);
|
||||
dbConnections[appId] = new adapter(dbURI, {
|
||||
collectionPrefix: cache.apps[appId]['collectionPrefix']
|
||||
collectionPrefix: collectionPrefix
|
||||
});
|
||||
dbConnections[appId].connect();
|
||||
return dbConnections[appId];
|
||||
@@ -59,5 +59,5 @@ module.exports = {
|
||||
setAdapter: setAdapter,
|
||||
setDatabaseURI: setDatabaseURI,
|
||||
setAppDatabaseURI: setAppDatabaseURI,
|
||||
clearDatabaseURIs: clearDatabaseURIs,
|
||||
clearDatabaseURIs: clearDatabaseURIs
|
||||
};
|
||||
|
||||
@@ -124,7 +124,7 @@ function ParseServer({
|
||||
const filesController = new FilesController(filesControllerAdapter);
|
||||
const pushController = new PushController(pushControllerAdapter);
|
||||
const loggerController = new LoggerController(loggerControllerAdapter);
|
||||
const hooksController = new HooksController(appId);
|
||||
const hooksController = new HooksController(appId, collectionPrefix);
|
||||
|
||||
cache.apps[appId] = {
|
||||
masterKey: masterKey,
|
||||
@@ -141,7 +141,7 @@ function ParseServer({
|
||||
hooksController: hooksController,
|
||||
enableAnonymousUsers: enableAnonymousUsers,
|
||||
allowClientClassCreation: allowClientClassCreation,
|
||||
oauth: oauth,
|
||||
oauth: oauth
|
||||
};
|
||||
|
||||
// To maintain compatibility. TODO: Remove in v2.1
|
||||
|
||||
Reference in New Issue
Block a user