Move query validation out of mongo adapter

This commit is contained in:
Drew Gross
2016-05-18 18:10:57 -07:00
parent 15fc186a51
commit 643bdc8227
3 changed files with 32 additions and 34 deletions

View File

@@ -185,7 +185,6 @@ export class MongoStorageAdapter {
deleteObjectsByQuery(className, query, validate, schema) {
return this.adaptiveCollection(className)
.then(collection => {
transform.validateQuery(query);
let mongoWhere = transform.transformWhere(className, query, schema);
return collection.deleteMany(mongoWhere)
})

View File

@@ -211,39 +211,9 @@ function transformQueryKeyValue(className, key, value, schema) {
}
}
const validateQuery = query => {
if (query.ACL) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
}
if (query.$or) {
if (query.$or instanceof Array) {
query.$or.forEach(validateQuery);
} else {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Bad $or format - use an array value.');
}
}
if (query.$and) {
if (query.$and instanceof Array) {
query.$and.forEach(validateQuery);
} else {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Bad $and format - use an array value.');
}
}
Object.keys(query).forEach(key => {
if (!specialQuerykeys.includes(key) && !key.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/)) {
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: ${key}`);
}
});
}
// Main exposed method to help run queries.
// restWhere is the "where" clause in REST API form.
// Returns the mongo form of the query.
// Throws a Parse.Error if the input query is invalid.
const specialQuerykeys = ['$and', '$or', '_rperm', '_wperm', '_perishable_token', '_email_verify_token'];
function transformWhere(className, restWhere, schema) {
let mongoWhere = {};
for (let restKey in restWhere) {
@@ -1048,7 +1018,6 @@ var FileCoder = {
module.exports = {
transformKey,
validateQuery,
parseObjectToMongoObjectForCreate,
transformUpdate,
transformWhere,