better names and comments

This commit is contained in:
Drew Gross
2016-04-26 13:08:58 -07:00
parent 449ca115b1
commit 71ae7bee94
2 changed files with 13 additions and 13 deletions

View File

@@ -173,7 +173,7 @@ export class MongoStorageAdapter {
// If no objects match, reject with OBJECT_NOT_FOUND. If objects are found and deleted, resolve with undefined. // If no objects match, reject with OBJECT_NOT_FOUND. If objects are found and deleted, resolve with undefined.
// If there is some other error, reject with INTERNAL_SERVER_ERROR. // If there is some other error, reject with INTERNAL_SERVER_ERROR.
// Currently accepts the validate for lecacy reasons. Currently accepts the schema, that may not actually be necessary. // Currently accepts validate for legacy reasons. Currently accepts the schema, that may not actually be necessary.
deleteObjectsByQuery(className, query, validate, schema) { deleteObjectsByQuery(className, query, validate, schema) {
return this.adaptiveCollection(className) return this.adaptiveCollection(className)
.then(collection => { .then(collection => {

View File

@@ -139,7 +139,7 @@ const valueAsDate = value => {
return false; return false;
} }
function transformQueryKeyValue(className, key, value, { validate } = {}, parseFormatSchema) { function transformQueryKeyValue(className, key, value, { validate } = {}, schema) {
switch(key) { switch(key) {
case 'createdAt': case 'createdAt':
if (valueAsDate(value)) { if (valueAsDate(value)) {
@@ -168,12 +168,12 @@ function transformQueryKeyValue(className, key, value, { validate } = {}, parseF
if (!(value instanceof Array)) { if (!(value instanceof Array)) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $or format - use an array value'); throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $or format - use an array value');
} }
return {key: '$or', value: value.map(subQuery => transformWhere(className, subQuery, {}, parseFormatSchema))}; return {key: '$or', value: value.map(subQuery => transformWhere(className, subQuery, {}, schema))};
case '$and': case '$and':
if (!(value instanceof Array)) { if (!(value instanceof Array)) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $and format - use an array value'); throw new Parse.Error(Parse.Error.INVALID_QUERY, 'bad $and format - use an array value');
} }
return {key: '$and', value: value.map(subQuery => transformWhere(className, subQuery, {}, parseFormatSchema))}; return {key: '$and', value: value.map(subQuery => transformWhere(className, subQuery, {}, schema))};
default: default:
// Other auth data // Other auth data
const authDataMatch = key.match(/^authData\.([a-zA-Z0-9_]+)\.id$/); const authDataMatch = key.match(/^authData\.([a-zA-Z0-9_]+)\.id$/);
@@ -188,16 +188,16 @@ function transformQueryKeyValue(className, key, value, { validate } = {}, parseF
} }
const expectedTypeIsArray = const expectedTypeIsArray =
parseFormatSchema && schema &&
parseFormatSchema.fields[key] && schema.fields[key] &&
parseFormatSchema.fields[key].type === 'Array'; schema.fields[key].type === 'Array';
const expectedTypeIsPointer = const expectedTypeIsPointer =
parseFormatSchema && schema &&
parseFormatSchema.fields[key] && schema.fields[key] &&
parseFormatSchema.fields[key].type === 'Pointer'; schema.fields[key].type === 'Pointer';
if (expectedTypeIsPointer || !parseFormatSchema && value && value.__type === 'Pointer') { if (expectedTypeIsPointer || !schema && value && value.__type === 'Pointer') {
key = '_p_' + key; key = '_p_' + key;
} }
@@ -222,13 +222,13 @@ function transformQueryKeyValue(className, key, value, { validate } = {}, parseF
// restWhere is the "where" clause in REST API form. // restWhere is the "where" clause in REST API form.
// Returns the mongo form of the query. // Returns the mongo form of the query.
// Throws a Parse.Error if the input query is invalid. // Throws a Parse.Error if the input query is invalid.
function transformWhere(className, restWhere, { validate = true } = {}, parseFormatSchema) { function transformWhere(className, restWhere, { validate = true } = {}, schema) {
let mongoWhere = {}; let mongoWhere = {};
if (restWhere['ACL']) { if (restWhere['ACL']) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.'); throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
} }
for (let restKey in restWhere) { for (let restKey in restWhere) {
let out = transformQueryKeyValue(className, restKey, restWhere[restKey], { validate }, parseFormatSchema); let out = transformQueryKeyValue(className, restKey, restWhere[restKey], { validate }, schema);
mongoWhere[out.key] = out.value; mongoWhere[out.key] = out.value;
} }
return mongoWhere; return mongoWhere;