@@ -7,7 +7,7 @@ export class AnalyticsController extends AdaptableController {
|
||||
.then(() => {
|
||||
return this.adapter.appOpened(req.body, req);
|
||||
})
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
return { response: response || {} };
|
||||
})
|
||||
.catch(() => {
|
||||
@@ -20,7 +20,7 @@ export class AnalyticsController extends AdaptableController {
|
||||
.then(() => {
|
||||
return this.adapter.trackEvent(req.params.eventName, req.body, req);
|
||||
})
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
return { response: response || {} };
|
||||
})
|
||||
.catch(() => {
|
||||
|
||||
@@ -65,7 +65,7 @@ const specialQuerykeys = [
|
||||
'_failed_login_count',
|
||||
];
|
||||
|
||||
const isSpecialQueryKey = (key) => {
|
||||
const isSpecialQueryKey = key => {
|
||||
return specialQuerykeys.indexOf(key) >= 0;
|
||||
};
|
||||
|
||||
@@ -107,7 +107,7 @@ const validateQuery = (query: any): void => {
|
||||
}
|
||||
}
|
||||
|
||||
Object.keys(query).forEach((key) => {
|
||||
Object.keys(query).forEach(key => {
|
||||
if (query && query[key] && query[key].$regex) {
|
||||
if (typeof query[key].$options === 'string') {
|
||||
if (!query[key].$options.match(/^[imxs]+$/)) {
|
||||
@@ -149,8 +149,8 @@ const filterSensitiveData = (
|
||||
if (isReadOperation && perms.protectedFields) {
|
||||
// extract protectedFields added with the pointer-permission prefix
|
||||
const protectedFieldsPointerPerm = Object.keys(perms.protectedFields)
|
||||
.filter((key) => key.startsWith('userField:'))
|
||||
.map((key) => {
|
||||
.filter(key => key.startsWith('userField:'))
|
||||
.map(key => {
|
||||
return { key: key.substring(10), value: perms.protectedFields[key] };
|
||||
});
|
||||
|
||||
@@ -158,13 +158,13 @@ const filterSensitiveData = (
|
||||
let overrideProtectedFields = false;
|
||||
|
||||
// check if the object grants the current user access based on the extracted fields
|
||||
protectedFieldsPointerPerm.forEach((pointerPerm) => {
|
||||
protectedFieldsPointerPerm.forEach(pointerPerm => {
|
||||
let pointerPermIncludesUser = false;
|
||||
const readUserFieldValue = object[pointerPerm.key];
|
||||
if (readUserFieldValue) {
|
||||
if (Array.isArray(readUserFieldValue)) {
|
||||
pointerPermIncludesUser = readUserFieldValue.some(
|
||||
(user) => user.objectId && user.objectId === userId
|
||||
user => user.objectId && user.objectId === userId
|
||||
);
|
||||
} else {
|
||||
pointerPermIncludesUser =
|
||||
@@ -186,14 +186,14 @@ const filterSensitiveData = (
|
||||
newProtectedFields.push(protectedFields);
|
||||
}
|
||||
// intersect all sets of protectedFields
|
||||
newProtectedFields.forEach((fields) => {
|
||||
newProtectedFields.forEach(fields => {
|
||||
if (fields) {
|
||||
// if there're no protctedFields by other criteria ( id / role / auth)
|
||||
// then we must intersect each set (per userField)
|
||||
if (!protectedFields) {
|
||||
protectedFields = fields;
|
||||
} else {
|
||||
protectedFields = protectedFields.filter((v) => fields.includes(v));
|
||||
protectedFields = protectedFields.filter(v => fields.includes(v));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -205,13 +205,13 @@ const filterSensitiveData = (
|
||||
/* special treat for the user class: don't filter protectedFields if currently loggedin user is
|
||||
the retrieved user */
|
||||
if (!(isUserClass && userId && object.objectId === userId)) {
|
||||
protectedFields && protectedFields.forEach((k) => delete object[k]);
|
||||
protectedFields && protectedFields.forEach(k => delete object[k]);
|
||||
|
||||
// fields not requested by client (excluded),
|
||||
//but were needed to apply protecttedFields
|
||||
perms.protectedFields &&
|
||||
perms.protectedFields.temporaryKeys &&
|
||||
perms.protectedFields.temporaryKeys.forEach((k) => delete object[k]);
|
||||
perms.protectedFields.temporaryKeys.forEach(k => delete object[k]);
|
||||
}
|
||||
|
||||
if (!isUserClass) {
|
||||
@@ -265,7 +265,7 @@ const specialKeysForUpdate = [
|
||||
'_password_history',
|
||||
];
|
||||
|
||||
const isSpecialUpdateKey = (key) => {
|
||||
const isSpecialUpdateKey = key => {
|
||||
return specialKeysForUpdate.indexOf(key) >= 0;
|
||||
};
|
||||
|
||||
@@ -291,7 +291,7 @@ function sanitizeDatabaseResult(originalObject, result): Promise<any> {
|
||||
if (!result) {
|
||||
return Promise.resolve(response);
|
||||
}
|
||||
Object.keys(originalObject).forEach((key) => {
|
||||
Object.keys(originalObject).forEach(key => {
|
||||
const keyUpdate = originalObject[key];
|
||||
// determine if that was an op
|
||||
if (
|
||||
@@ -312,7 +312,7 @@ function joinTableName(className, key) {
|
||||
return `_Join:${key}:${className}`;
|
||||
}
|
||||
|
||||
const flattenUpdateOperatorsForCreate = (object) => {
|
||||
const flattenUpdateOperatorsForCreate = object => {
|
||||
for (const key in object) {
|
||||
if (object[key] && object[key].__op) {
|
||||
switch (object[key].__op) {
|
||||
@@ -367,7 +367,7 @@ const flattenUpdateOperatorsForCreate = (object) => {
|
||||
|
||||
const transformAuthData = (className, object, schema) => {
|
||||
if (object.authData && className === '_User') {
|
||||
Object.keys(object.authData).forEach((provider) => {
|
||||
Object.keys(object.authData).forEach(provider => {
|
||||
const providerData = object.authData[provider];
|
||||
const fieldName = `_auth_data_${provider}`;
|
||||
if (providerData == null) {
|
||||
@@ -387,7 +387,7 @@ const untransformObjectACL = ({ _rperm, _wperm, ...output }) => {
|
||||
if (_rperm || _wperm) {
|
||||
output.ACL = {};
|
||||
|
||||
(_rperm || []).forEach((entry) => {
|
||||
(_rperm || []).forEach(entry => {
|
||||
if (!output.ACL[entry]) {
|
||||
output.ACL[entry] = { read: true };
|
||||
} else {
|
||||
@@ -395,7 +395,7 @@ const untransformObjectACL = ({ _rperm, _wperm, ...output }) => {
|
||||
}
|
||||
});
|
||||
|
||||
(_wperm || []).forEach((entry) => {
|
||||
(_wperm || []).forEach(entry => {
|
||||
if (!output.ACL[entry]) {
|
||||
output.ACL[entry] = { write: true };
|
||||
} else {
|
||||
@@ -442,10 +442,8 @@ class DatabaseController {
|
||||
|
||||
purgeCollection(className: string): Promise<void> {
|
||||
return this.loadSchema()
|
||||
.then((schemaController) => schemaController.getOneSchema(className))
|
||||
.then((schema) =>
|
||||
this.adapter.deleteObjectsByQuery(className, schema, {})
|
||||
);
|
||||
.then(schemaController => schemaController.getOneSchema(className))
|
||||
.then(schema => this.adapter.deleteObjectsByQuery(className, schema, {}));
|
||||
}
|
||||
|
||||
validateClassName(className: string): Promise<void> {
|
||||
@@ -492,7 +490,7 @@ class DatabaseController {
|
||||
// classname through the key.
|
||||
// TODO: make this not in the DatabaseController interface
|
||||
redirectClassNameForKey(className: string, key: string): Promise<?string> {
|
||||
return this.loadSchema().then((schema) => {
|
||||
return this.loadSchema().then(schema => {
|
||||
var t = schema.getExpectedType(className, key);
|
||||
if (t != null && typeof t !== 'string' && t.type === 'Relation') {
|
||||
return t.targetClass;
|
||||
@@ -516,7 +514,7 @@ class DatabaseController {
|
||||
const isMaster = acl === undefined;
|
||||
var aclGroup: string[] = acl || [];
|
||||
return this.loadSchema()
|
||||
.then((s) => {
|
||||
.then(s => {
|
||||
schema = s;
|
||||
if (isMaster) {
|
||||
return Promise.resolve();
|
||||
@@ -552,7 +550,7 @@ class DatabaseController {
|
||||
var aclGroup = acl || [];
|
||||
|
||||
return this.loadSchemaIfNeeded(validSchemaController).then(
|
||||
(schemaController) => {
|
||||
schemaController => {
|
||||
return (isMaster
|
||||
? Promise.resolve()
|
||||
: schemaController.validatePermission(className, aclGroup, 'update')
|
||||
@@ -596,7 +594,7 @@ class DatabaseController {
|
||||
validateQuery(query);
|
||||
return schemaController
|
||||
.getOneSchema(className, true)
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
// If the schema doesn't exist, pretend it exists with no fields. This behavior
|
||||
// will likely need revisiting.
|
||||
if (error === undefined) {
|
||||
@@ -604,8 +602,8 @@ class DatabaseController {
|
||||
}
|
||||
throw error;
|
||||
})
|
||||
.then((schema) => {
|
||||
Object.keys(update).forEach((fieldName) => {
|
||||
.then(schema => {
|
||||
Object.keys(update).forEach(fieldName => {
|
||||
if (fieldName.match(/^authData\.([a-zA-Z0-9_]+)\.id$/)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_KEY_NAME,
|
||||
@@ -628,7 +626,7 @@ class DatabaseController {
|
||||
update[updateOperation] &&
|
||||
typeof update[updateOperation] === 'object' &&
|
||||
Object.keys(update[updateOperation]).some(
|
||||
(innerKey) =>
|
||||
innerKey =>
|
||||
innerKey.includes('$') || innerKey.includes('.')
|
||||
)
|
||||
) {
|
||||
@@ -643,7 +641,7 @@ class DatabaseController {
|
||||
if (validateOnly) {
|
||||
return this.adapter
|
||||
.find(className, schema, query, {})
|
||||
.then((result) => {
|
||||
.then(result => {
|
||||
if (!result || !result.length) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
@@ -699,7 +697,7 @@ class DatabaseController {
|
||||
return result;
|
||||
});
|
||||
})
|
||||
.then((result) => {
|
||||
.then(result => {
|
||||
if (skipSanitization) {
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
@@ -822,7 +820,7 @@ class DatabaseController {
|
||||
doc,
|
||||
this._transactionalSession
|
||||
)
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
// We don't care if they try to delete a non-existent relation.
|
||||
if (error.code == Parse.Error.OBJECT_NOT_FOUND) {
|
||||
return;
|
||||
@@ -848,7 +846,7 @@ class DatabaseController {
|
||||
const aclGroup = acl || [];
|
||||
|
||||
return this.loadSchemaIfNeeded(validSchemaController).then(
|
||||
(schemaController) => {
|
||||
schemaController => {
|
||||
return (isMaster
|
||||
? Promise.resolve()
|
||||
: schemaController.validatePermission(className, aclGroup, 'delete')
|
||||
@@ -875,7 +873,7 @@ class DatabaseController {
|
||||
validateQuery(query);
|
||||
return schemaController
|
||||
.getOneSchema(className)
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
// If the schema doesn't exist, pretend it exists with no fields. This behavior
|
||||
// will likely need revisiting.
|
||||
if (error === undefined) {
|
||||
@@ -883,7 +881,7 @@ class DatabaseController {
|
||||
}
|
||||
throw error;
|
||||
})
|
||||
.then((parseFormatSchema) =>
|
||||
.then(parseFormatSchema =>
|
||||
this.adapter.deleteObjectsByQuery(
|
||||
className,
|
||||
parseFormatSchema,
|
||||
@@ -891,7 +889,7 @@ class DatabaseController {
|
||||
this._transactionalSession
|
||||
)
|
||||
)
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
// When deleting sessions while changing passwords, don't throw an error if they don't have any sessions.
|
||||
if (
|
||||
className === '_Session' &&
|
||||
@@ -932,14 +930,14 @@ class DatabaseController {
|
||||
|
||||
return this.validateClassName(className)
|
||||
.then(() => this.loadSchemaIfNeeded(validSchemaController))
|
||||
.then((schemaController) => {
|
||||
.then(schemaController => {
|
||||
return (isMaster
|
||||
? Promise.resolve()
|
||||
: schemaController.validatePermission(className, aclGroup, 'create')
|
||||
)
|
||||
.then(() => schemaController.enforceClassExists(className))
|
||||
.then(() => schemaController.getOneSchema(className, true))
|
||||
.then((schema) => {
|
||||
.then(schema => {
|
||||
transformAuthData(className, object, schema);
|
||||
flattenUpdateOperatorsForCreate(object);
|
||||
if (validateOnly) {
|
||||
@@ -952,7 +950,7 @@ class DatabaseController {
|
||||
this._transactionalSession
|
||||
);
|
||||
})
|
||||
.then((result) => {
|
||||
.then(result => {
|
||||
if (validateOnly) {
|
||||
return originalObject;
|
||||
}
|
||||
@@ -981,7 +979,7 @@ class DatabaseController {
|
||||
}
|
||||
const fields = Object.keys(object);
|
||||
const schemaFields = Object.keys(classSchema.fields);
|
||||
const newKeys = fields.filter((field) => {
|
||||
const newKeys = fields.filter(field => {
|
||||
// Skip fields that are unset
|
||||
if (
|
||||
object[field] &&
|
||||
@@ -1040,7 +1038,7 @@ class DatabaseController {
|
||||
{ owningId },
|
||||
findOptions
|
||||
)
|
||||
.then((results) => results.map((result) => result.relatedId));
|
||||
.then(results => results.map(result => result.relatedId));
|
||||
}
|
||||
|
||||
// Returns a promise for a list of owning ids given some related ids.
|
||||
@@ -1057,7 +1055,7 @@ class DatabaseController {
|
||||
{ relatedId: { $in: relatedIds } },
|
||||
{ keys: ['owningId'] }
|
||||
)
|
||||
.then((results) => results.map((result) => result.owningId));
|
||||
.then(results => results.map(result => result.owningId));
|
||||
}
|
||||
|
||||
// Modifies query so that it no longer has $in on relation fields, or
|
||||
@@ -1071,7 +1069,7 @@ class DatabaseController {
|
||||
return Promise.all(
|
||||
ors.map((aQuery, index) => {
|
||||
return this.reduceInRelation(className, aQuery, schema).then(
|
||||
(aQuery) => {
|
||||
aQuery => {
|
||||
query['$or'][index] = aQuery;
|
||||
}
|
||||
);
|
||||
@@ -1081,7 +1079,7 @@ class DatabaseController {
|
||||
});
|
||||
}
|
||||
|
||||
const promises = Object.keys(query).map((key) => {
|
||||
const promises = Object.keys(query).map(key => {
|
||||
const t = schema.getExpectedType(className, key);
|
||||
if (!t || t.type !== 'Relation') {
|
||||
return Promise.resolve(query);
|
||||
@@ -1095,16 +1093,16 @@ class DatabaseController {
|
||||
query[key].__type == 'Pointer')
|
||||
) {
|
||||
// Build the list of queries
|
||||
queries = Object.keys(query[key]).map((constraintKey) => {
|
||||
queries = Object.keys(query[key]).map(constraintKey => {
|
||||
let relatedIds;
|
||||
let isNegation = false;
|
||||
if (constraintKey === 'objectId') {
|
||||
relatedIds = [query[key].objectId];
|
||||
} else if (constraintKey == '$in') {
|
||||
relatedIds = query[key]['$in'].map((r) => r.objectId);
|
||||
relatedIds = query[key]['$in'].map(r => r.objectId);
|
||||
} else if (constraintKey == '$nin') {
|
||||
isNegation = true;
|
||||
relatedIds = query[key]['$nin'].map((r) => r.objectId);
|
||||
relatedIds = query[key]['$nin'].map(r => r.objectId);
|
||||
} else if (constraintKey == '$ne') {
|
||||
isNegation = true;
|
||||
relatedIds = [query[key]['$ne'].objectId];
|
||||
@@ -1124,11 +1122,11 @@ class DatabaseController {
|
||||
delete query[key];
|
||||
// execute each query independently to build the list of
|
||||
// $in / $nin
|
||||
const promises = queries.map((q) => {
|
||||
const promises = queries.map(q => {
|
||||
if (!q) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return this.owningIds(className, key, q.relatedIds).then((ids) => {
|
||||
return this.owningIds(className, key, q.relatedIds).then(ids => {
|
||||
if (q.isNegation) {
|
||||
this.addNotInObjectIdsIds(ids, query);
|
||||
} else {
|
||||
@@ -1157,7 +1155,7 @@ class DatabaseController {
|
||||
): ?Promise<void> {
|
||||
if (query['$or']) {
|
||||
return Promise.all(
|
||||
query['$or'].map((aQuery) => {
|
||||
query['$or'].map(aQuery => {
|
||||
return this.reduceRelationKeys(className, aQuery, queryOptions);
|
||||
})
|
||||
);
|
||||
@@ -1171,7 +1169,7 @@ class DatabaseController {
|
||||
relatedTo.object.objectId,
|
||||
queryOptions
|
||||
)
|
||||
.then((ids) => {
|
||||
.then(ids => {
|
||||
delete query['$relatedTo'];
|
||||
this.addInObjectIdsIds(ids, query);
|
||||
return this.reduceRelationKeys(className, query, queryOptions);
|
||||
@@ -1194,7 +1192,7 @@ class DatabaseController {
|
||||
idsFromEq,
|
||||
idsFromIn,
|
||||
ids,
|
||||
].filter((list) => list !== null);
|
||||
].filter(list => list !== null);
|
||||
const totalLength = allIds.reduce((memo, list) => memo + list.length, 0);
|
||||
|
||||
let idsIntersection = [];
|
||||
@@ -1223,7 +1221,7 @@ class DatabaseController {
|
||||
addNotInObjectIdsIds(ids: string[] = [], query: any) {
|
||||
const idsFromNin =
|
||||
query.objectId && query.objectId['$nin'] ? query.objectId['$nin'] : [];
|
||||
let allIds = [...idsFromNin, ...ids].filter((list) => list !== null);
|
||||
let allIds = [...idsFromNin, ...ids].filter(list => list !== null);
|
||||
|
||||
// make a set and spread to remove duplicates
|
||||
allIds = [...new Set(allIds)];
|
||||
@@ -1292,13 +1290,13 @@ class DatabaseController {
|
||||
|
||||
let classExists = true;
|
||||
return this.loadSchemaIfNeeded(validSchemaController).then(
|
||||
(schemaController) => {
|
||||
schemaController => {
|
||||
//Allow volatile classes if querying with Master (for _PushStatus)
|
||||
//TODO: Move volatile classes concept into mongo adapter, postgres adapter shouldn't care
|
||||
//that api.parse.com breaks when _PushStatus exists in mongo.
|
||||
return schemaController
|
||||
.getOneSchema(className, isMaster)
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
// Behavior for non-existent classes is kinda weird on Parse.com. Probably doesn't matter too much.
|
||||
// For now, pretend the class exists but has no objects,
|
||||
if (error === undefined) {
|
||||
@@ -1307,7 +1305,7 @@ class DatabaseController {
|
||||
}
|
||||
throw error;
|
||||
})
|
||||
.then((schema) => {
|
||||
.then(schema => {
|
||||
// Parse.com treats queries on _created_at and _updated_at as if they were queries on createdAt and updatedAt,
|
||||
// so duplicate that behavior here. If both are specified, the correct behavior to match Parse.com is to
|
||||
// use the one that appears first in the sort list.
|
||||
@@ -1329,7 +1327,7 @@ class DatabaseController {
|
||||
caseInsensitive,
|
||||
explain,
|
||||
};
|
||||
Object.keys(sort).forEach((fieldName) => {
|
||||
Object.keys(sort).forEach(fieldName => {
|
||||
if (fieldName.match(/^authData\.([a-zA-Z0-9_]+)\.id$/)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_KEY_NAME,
|
||||
@@ -1441,8 +1439,8 @@ class DatabaseController {
|
||||
} else {
|
||||
return this.adapter
|
||||
.find(className, schema, query, queryOptions)
|
||||
.then((objects) =>
|
||||
objects.map((object) => {
|
||||
.then(objects =>
|
||||
objects.map(object => {
|
||||
object = untransformObjectACL(object);
|
||||
return filterSensitiveData(
|
||||
isMaster,
|
||||
@@ -1456,7 +1454,7 @@ class DatabaseController {
|
||||
);
|
||||
})
|
||||
)
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INTERNAL_SERVER_ERROR,
|
||||
error
|
||||
@@ -1471,10 +1469,8 @@ class DatabaseController {
|
||||
|
||||
deleteSchema(className: string): Promise<void> {
|
||||
return this.loadSchema({ clearCache: true })
|
||||
.then((schemaController) =>
|
||||
schemaController.getOneSchema(className, true)
|
||||
)
|
||||
.catch((error) => {
|
||||
.then(schemaController => schemaController.getOneSchema(className, true))
|
||||
.catch(error => {
|
||||
if (error === undefined) {
|
||||
return { fields: {} };
|
||||
} else {
|
||||
@@ -1486,7 +1482,7 @@ class DatabaseController {
|
||||
.then(() =>
|
||||
this.adapter.count(className, { fields: {} }, null, '', false)
|
||||
)
|
||||
.then((count) => {
|
||||
.then(count => {
|
||||
if (count > 0) {
|
||||
throw new Parse.Error(
|
||||
255,
|
||||
@@ -1495,13 +1491,13 @@ class DatabaseController {
|
||||
}
|
||||
return this.adapter.deleteClass(className);
|
||||
})
|
||||
.then((wasParseCollection) => {
|
||||
.then(wasParseCollection => {
|
||||
if (wasParseCollection) {
|
||||
const relationFieldNames = Object.keys(schema.fields).filter(
|
||||
(fieldName) => schema.fields[fieldName].type === 'Relation'
|
||||
fieldName => schema.fields[fieldName].type === 'Relation'
|
||||
);
|
||||
return Promise.all(
|
||||
relationFieldNames.map((name) =>
|
||||
relationFieldNames.map(name =>
|
||||
this.adapter.deleteClass(joinTableName(className, name))
|
||||
)
|
||||
).then(() => {
|
||||
@@ -1533,7 +1529,7 @@ class DatabaseController {
|
||||
}
|
||||
const perms = schema.getClassLevelPermissions(className);
|
||||
|
||||
const userACL = aclGroup.filter((acl) => {
|
||||
const userACL = aclGroup.filter(acl => {
|
||||
return acl.indexOf('role:') != 0 && acl != '*';
|
||||
});
|
||||
|
||||
@@ -1570,7 +1566,7 @@ class DatabaseController {
|
||||
objectId: userId,
|
||||
};
|
||||
|
||||
const ors = permFields.flatMap((key) => {
|
||||
const ors = permFields.flatMap(key => {
|
||||
// constraint for single pointer setup
|
||||
const q = {
|
||||
[key]: userPointer,
|
||||
@@ -1686,9 +1682,9 @@ class DatabaseController {
|
||||
}, []);
|
||||
|
||||
// intersect all sets of protectedFields
|
||||
protectedKeysSets.forEach((fields) => {
|
||||
protectedKeysSets.forEach(fields => {
|
||||
if (fields) {
|
||||
protectedKeys = protectedKeys.filter((v) => fields.includes(v));
|
||||
protectedKeys = protectedKeys.filter(v => fields.includes(v));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1698,7 +1694,7 @@ class DatabaseController {
|
||||
createTransactionalSession() {
|
||||
return this.adapter
|
||||
.createTransactionalSession()
|
||||
.then((transactionalSession) => {
|
||||
.then(transactionalSession => {
|
||||
this._transactionalSession = transactionalSession;
|
||||
});
|
||||
}
|
||||
@@ -1741,10 +1737,10 @@ class DatabaseController {
|
||||
},
|
||||
};
|
||||
|
||||
const userClassPromise = this.loadSchema().then((schema) =>
|
||||
const userClassPromise = this.loadSchema().then(schema =>
|
||||
schema.enforceClassExists('_User')
|
||||
);
|
||||
const roleClassPromise = this.loadSchema().then((schema) =>
|
||||
const roleClassPromise = this.loadSchema().then(schema =>
|
||||
schema.enforceClassExists('_Role')
|
||||
);
|
||||
|
||||
@@ -1752,7 +1748,7 @@ class DatabaseController {
|
||||
.then(() =>
|
||||
this.adapter.ensureUniqueness('_User', requiredUserFields, ['username'])
|
||||
)
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
logger.warn('Unable to ensure uniqueness for usernames: ', error);
|
||||
throw error;
|
||||
});
|
||||
@@ -1767,7 +1763,7 @@ class DatabaseController {
|
||||
true
|
||||
)
|
||||
)
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
logger.warn(
|
||||
'Unable to create case insensitive username index: ',
|
||||
error
|
||||
@@ -1779,7 +1775,7 @@ class DatabaseController {
|
||||
.then(() =>
|
||||
this.adapter.ensureUniqueness('_User', requiredUserFields, ['email'])
|
||||
)
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
logger.warn(
|
||||
'Unable to ensure uniqueness for user email addresses: ',
|
||||
error
|
||||
@@ -1797,7 +1793,7 @@ class DatabaseController {
|
||||
true
|
||||
)
|
||||
)
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
logger.warn('Unable to create case insensitive email index: ', error);
|
||||
throw error;
|
||||
});
|
||||
@@ -1806,7 +1802,7 @@ class DatabaseController {
|
||||
.then(() =>
|
||||
this.adapter.ensureUniqueness('_Role', requiredRoleFields, ['name'])
|
||||
)
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
logger.warn('Unable to ensure uniqueness for role name: ', error);
|
||||
throw error;
|
||||
});
|
||||
@@ -1828,7 +1824,7 @@ class DatabaseController {
|
||||
]);
|
||||
}
|
||||
|
||||
static _validateQuery: (any) => void;
|
||||
static _validateQuery: any => void;
|
||||
}
|
||||
|
||||
module.exports = DatabaseController;
|
||||
|
||||
@@ -59,7 +59,7 @@ export class FilesController extends AdaptableController {
|
||||
*/
|
||||
expandFilesInObject(config, object) {
|
||||
if (object instanceof Array) {
|
||||
object.map((obj) => this.expandFilesInObject(config, obj));
|
||||
object.map(obj => this.expandFilesInObject(config, obj));
|
||||
return;
|
||||
}
|
||||
if (typeof object !== 'object') {
|
||||
|
||||
@@ -27,9 +27,9 @@ export class HooksController {
|
||||
}
|
||||
|
||||
load() {
|
||||
return this._getHooks().then((hooks) => {
|
||||
return this._getHooks().then(hooks => {
|
||||
hooks = hooks || [];
|
||||
hooks.forEach((hook) => {
|
||||
hooks.forEach(hook => {
|
||||
this.addHookToTriggers(hook);
|
||||
});
|
||||
});
|
||||
@@ -37,7 +37,7 @@ export class HooksController {
|
||||
|
||||
getFunction(functionName) {
|
||||
return this._getHooks({ functionName: functionName }).then(
|
||||
(results) => results[0]
|
||||
results => results[0]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ export class HooksController {
|
||||
return this._getHooks({
|
||||
className: className,
|
||||
triggerName: triggerName,
|
||||
}).then((results) => results[0]);
|
||||
}).then(results => results[0]);
|
||||
}
|
||||
|
||||
getTriggers() {
|
||||
@@ -75,8 +75,8 @@ export class HooksController {
|
||||
_getHooks(query = {}) {
|
||||
return this.database
|
||||
.find(DefaultHooksCollectionName, query)
|
||||
.then((results) => {
|
||||
return results.map((result) => {
|
||||
.then(results => {
|
||||
return results.map(result => {
|
||||
delete result.objectId;
|
||||
return result;
|
||||
});
|
||||
@@ -156,7 +156,7 @@ export class HooksController {
|
||||
|
||||
createHook(aHook) {
|
||||
if (aHook.functionName) {
|
||||
return this.getFunction(aHook.functionName).then((result) => {
|
||||
return this.getFunction(aHook.functionName).then(result => {
|
||||
if (result) {
|
||||
throw new Parse.Error(
|
||||
143,
|
||||
@@ -168,7 +168,7 @@ export class HooksController {
|
||||
});
|
||||
} else if (aHook.className && aHook.triggerName) {
|
||||
return this.getTrigger(aHook.className, aHook.triggerName).then(
|
||||
(result) => {
|
||||
result => {
|
||||
if (result) {
|
||||
throw new Parse.Error(
|
||||
143,
|
||||
@@ -185,7 +185,7 @@ export class HooksController {
|
||||
|
||||
updateHook(aHook) {
|
||||
if (aHook.functionName) {
|
||||
return this.getFunction(aHook.functionName).then((result) => {
|
||||
return this.getFunction(aHook.functionName).then(result => {
|
||||
if (result) {
|
||||
return this.createOrUpdateHook(aHook);
|
||||
}
|
||||
@@ -196,7 +196,7 @@ export class HooksController {
|
||||
});
|
||||
} else if (aHook.className && aHook.triggerName) {
|
||||
return this.getTrigger(aHook.className, aHook.triggerName).then(
|
||||
(result) => {
|
||||
result => {
|
||||
if (result) {
|
||||
return this.createOrUpdateHook(aHook);
|
||||
}
|
||||
@@ -209,7 +209,7 @@ export class HooksController {
|
||||
}
|
||||
|
||||
function wrapToHTTPRequest(hook, key) {
|
||||
return (req) => {
|
||||
return req => {
|
||||
const jsonBody = {};
|
||||
for (var i in req) {
|
||||
jsonBody[i] = req[i];
|
||||
@@ -243,7 +243,7 @@ function wrapToHTTPRequest(hook, key) {
|
||||
'Making outgoing webhook request without webhookKey being set!'
|
||||
);
|
||||
}
|
||||
return request(jsonRequest).then((response) => {
|
||||
return request(jsonRequest).then(response => {
|
||||
let err;
|
||||
let result;
|
||||
let body = response.data;
|
||||
|
||||
@@ -61,7 +61,7 @@ export class LoggerController extends AdaptableController {
|
||||
}
|
||||
|
||||
maskSensitive(argArray) {
|
||||
return argArray.map((e) => {
|
||||
return argArray.map(e => {
|
||||
if (!e) {
|
||||
return e;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ export class LoggerController extends AdaptableController {
|
||||
e.url = this.maskSensitiveUrl(e.url);
|
||||
} else if (Array.isArray(e.url)) {
|
||||
// for strings in array
|
||||
e.url = e.url.map((item) => {
|
||||
e.url = e.url.map(item => {
|
||||
if (typeof item === 'string') {
|
||||
return this.maskSensitiveUrl(item);
|
||||
}
|
||||
@@ -115,7 +115,7 @@ export class LoggerController extends AdaptableController {
|
||||
args = this.maskSensitive([...args]);
|
||||
args = [].concat(
|
||||
level,
|
||||
args.map((arg) => {
|
||||
args.map(arg => {
|
||||
if (typeof arg === 'function') {
|
||||
return arg();
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ class ParseGraphQLController {
|
||||
}
|
||||
if (classConfigs !== null) {
|
||||
if (Array.isArray(classConfigs)) {
|
||||
classConfigs.forEach((classConfig) => {
|
||||
classConfigs.forEach(classConfig => {
|
||||
const errorMessage = this._validateClassConfig(classConfig);
|
||||
if (errorMessage) {
|
||||
errorMessages.push(
|
||||
@@ -334,7 +334,7 @@ class ParseGraphQLController {
|
||||
|
||||
const isValidStringArray = function (array): boolean {
|
||||
return Array.isArray(array)
|
||||
? !array.some((s) => typeof s !== 'string' || s.trim().length < 1)
|
||||
? !array.some(s => typeof s !== 'string' || s.trim().length < 1)
|
||||
: false;
|
||||
};
|
||||
/**
|
||||
|
||||
@@ -137,7 +137,7 @@ export class PushController {
|
||||
pushStatus
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(err => {
|
||||
return pushStatus.fail(err).then(() => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
@@ -41,9 +41,9 @@ export default class SchemaCache {
|
||||
if (!this.ttl) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
return this.cache.get(this.prefix + MAIN_SCHEMA).then((cachedSchemas) => {
|
||||
return this.cache.get(this.prefix + MAIN_SCHEMA).then(cachedSchemas => {
|
||||
cachedSchemas = cachedSchemas || [];
|
||||
const schema = cachedSchemas.find((cachedSchema) => {
|
||||
const schema = cachedSchemas.find(cachedSchema => {
|
||||
return cachedSchema.className === className;
|
||||
});
|
||||
if (schema) {
|
||||
|
||||
@@ -545,7 +545,7 @@ class SchemaData {
|
||||
constructor(allSchemas = [], protectedFields = {}) {
|
||||
this.__data = {};
|
||||
this.__protectedFields = protectedFields;
|
||||
allSchemas.forEach((schema) => {
|
||||
allSchemas.forEach(schema => {
|
||||
if (volatileClasses.includes(schema.className)) {
|
||||
return;
|
||||
}
|
||||
@@ -580,7 +580,7 @@ class SchemaData {
|
||||
});
|
||||
|
||||
// Inject the in-memory classes
|
||||
volatileClasses.forEach((className) => {
|
||||
volatileClasses.forEach(className => {
|
||||
Object.defineProperty(this, className, {
|
||||
get: () => {
|
||||
if (!this.__data[className]) {
|
||||
@@ -721,11 +721,11 @@ export default class SchemaController {
|
||||
}
|
||||
this.reloadDataPromise = this.getAllClasses(options)
|
||||
.then(
|
||||
(allSchemas) => {
|
||||
allSchemas => {
|
||||
this.schemaData = new SchemaData(allSchemas, this.protectedFields);
|
||||
delete this.reloadDataPromise;
|
||||
},
|
||||
(err) => {
|
||||
err => {
|
||||
this.schemaData = new SchemaData();
|
||||
delete this.reloadDataPromise;
|
||||
throw err;
|
||||
@@ -741,7 +741,7 @@ export default class SchemaController {
|
||||
if (options.clearCache) {
|
||||
return this.setAllClasses();
|
||||
}
|
||||
return this._cache.getAllClasses().then((allClasses) => {
|
||||
return this._cache.getAllClasses().then(allClasses => {
|
||||
if (allClasses && allClasses.length) {
|
||||
return Promise.resolve(allClasses);
|
||||
}
|
||||
@@ -752,12 +752,12 @@ export default class SchemaController {
|
||||
setAllClasses(): Promise<Array<Schema>> {
|
||||
return this._dbAdapter
|
||||
.getAllClasses()
|
||||
.then((allSchemas) => allSchemas.map(injectDefaultSchema))
|
||||
.then((allSchemas) => {
|
||||
.then(allSchemas => allSchemas.map(injectDefaultSchema))
|
||||
.then(allSchemas => {
|
||||
/* eslint-disable no-console */
|
||||
this._cache
|
||||
.setAllClasses(allSchemas)
|
||||
.catch((error) =>
|
||||
.catch(error =>
|
||||
console.error('Error saving schema to cache:', error)
|
||||
);
|
||||
/* eslint-enable no-console */
|
||||
@@ -784,13 +784,13 @@ export default class SchemaController {
|
||||
indexes: data.indexes,
|
||||
});
|
||||
}
|
||||
return this._cache.getOneSchema(className).then((cached) => {
|
||||
return this._cache.getOneSchema(className).then(cached => {
|
||||
if (cached && !options.clearCache) {
|
||||
return Promise.resolve(cached);
|
||||
}
|
||||
return this.setAllClasses().then((allSchemas) => {
|
||||
return this.setAllClasses().then(allSchemas => {
|
||||
const oneSchema = allSchemas.find(
|
||||
(schema) => schema.className === className
|
||||
schema => schema.className === className
|
||||
);
|
||||
if (!oneSchema) {
|
||||
return Promise.reject(undefined);
|
||||
@@ -841,7 +841,7 @@ export default class SchemaController {
|
||||
})
|
||||
)
|
||||
.then(convertAdapterSchemaToParseSchema)
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
if (error && error.code === Parse.Error.DUPLICATE_VALUE) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_CLASS_NAME,
|
||||
@@ -861,9 +861,9 @@ export default class SchemaController {
|
||||
database: DatabaseController
|
||||
) {
|
||||
return this.getOneSchema(className)
|
||||
.then((schema) => {
|
||||
.then(schema => {
|
||||
const existingFields = schema.fields;
|
||||
Object.keys(submittedFields).forEach((name) => {
|
||||
Object.keys(submittedFields).forEach(name => {
|
||||
const field = submittedFields[name];
|
||||
if (existingFields[name] && field.__op !== 'Delete') {
|
||||
throw new Parse.Error(255, `Field ${name} exists, cannot update.`);
|
||||
@@ -899,7 +899,7 @@ export default class SchemaController {
|
||||
// Do all deletions first, then a single save to _SCHEMA collection to handle all additions.
|
||||
const deletedFields: string[] = [];
|
||||
const insertedFields = [];
|
||||
Object.keys(submittedFields).forEach((fieldName) => {
|
||||
Object.keys(submittedFields).forEach(fieldName => {
|
||||
if (submittedFields[fieldName].__op === 'Delete') {
|
||||
deletedFields.push(fieldName);
|
||||
} else {
|
||||
@@ -916,14 +916,14 @@ export default class SchemaController {
|
||||
deletePromise // Delete Everything
|
||||
.then(() => this.reloadData({ clearCache: true })) // Reload our Schema, so we have all the new values
|
||||
.then(() => {
|
||||
const promises = insertedFields.map((fieldName) => {
|
||||
const promises = insertedFields.map(fieldName => {
|
||||
const type = submittedFields[fieldName];
|
||||
return this.enforceFieldExists(className, fieldName, type);
|
||||
});
|
||||
return Promise.all(promises);
|
||||
})
|
||||
.then((results) => {
|
||||
enforceFields = results.filter((result) => !!result);
|
||||
.then(results => {
|
||||
enforceFields = results.filter(result => !!result);
|
||||
return this.setPermissions(
|
||||
className,
|
||||
classLevelPermissions,
|
||||
@@ -955,7 +955,7 @@ export default class SchemaController {
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
if (error === undefined) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_CLASS_NAME,
|
||||
@@ -1095,7 +1095,7 @@ export default class SchemaController {
|
||||
}
|
||||
|
||||
const geoPoints = Object.keys(fields).filter(
|
||||
(key) => fields[key] && fields[key].type === 'GeoPoint'
|
||||
key => fields[key] && fields[key].type === 'GeoPoint'
|
||||
);
|
||||
if (geoPoints.length > 1) {
|
||||
return {
|
||||
@@ -1180,7 +1180,7 @@ export default class SchemaController {
|
||||
|
||||
return this._dbAdapter
|
||||
.addFieldIfNotExists(className, fieldName, type)
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
if (error.code == Parse.Error.INCORRECT_TYPE) {
|
||||
// Make sure that we throw errors when it is appropriate to do so.
|
||||
throw error;
|
||||
@@ -1244,7 +1244,7 @@ export default class SchemaController {
|
||||
);
|
||||
}
|
||||
|
||||
fieldNames.forEach((fieldName) => {
|
||||
fieldNames.forEach(fieldName => {
|
||||
if (!fieldNameIsValid(fieldName)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_KEY_NAME,
|
||||
@@ -1258,7 +1258,7 @@ export default class SchemaController {
|
||||
});
|
||||
|
||||
return this.getOneSchema(className, false, { clearCache: true })
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
if (error === undefined) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_CLASS_NAME,
|
||||
@@ -1268,8 +1268,8 @@ export default class SchemaController {
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
.then((schema) => {
|
||||
fieldNames.forEach((fieldName) => {
|
||||
.then(schema => {
|
||||
fieldNames.forEach(fieldName => {
|
||||
if (!schema.fields[fieldName]) {
|
||||
throw new Parse.Error(
|
||||
255,
|
||||
@@ -1283,7 +1283,7 @@ export default class SchemaController {
|
||||
.deleteFields(className, schema, fieldNames)
|
||||
.then(() => {
|
||||
return Promise.all(
|
||||
fieldNames.map((fieldName) => {
|
||||
fieldNames.map(fieldName => {
|
||||
const field = schemaFields[fieldName];
|
||||
if (field && field.type === 'Relation') {
|
||||
//For relations, drop the _Join table
|
||||
@@ -1335,7 +1335,7 @@ export default class SchemaController {
|
||||
promises.push(schema.enforceFieldExists(className, fieldName, expected));
|
||||
}
|
||||
const results = await Promise.all(promises);
|
||||
const enforceFields = results.filter((result) => !!result);
|
||||
const enforceFields = results.filter(result => !!result);
|
||||
|
||||
if (enforceFields.length !== 0) {
|
||||
await this.reloadData({ clearCache: true });
|
||||
@@ -1401,7 +1401,7 @@ export default class SchemaController {
|
||||
}
|
||||
// Check permissions against the aclGroup provided (array of userId/roles)
|
||||
if (
|
||||
aclGroup.some((acl) => {
|
||||
aclGroup.some(acl => {
|
||||
return perms[acl] === true;
|
||||
})
|
||||
) {
|
||||
@@ -1594,7 +1594,7 @@ function buildMergedSchemaObject(
|
||||
// Given a schema promise, construct another schema promise that
|
||||
// validates this field once the schema loads.
|
||||
function thenValidateRequiredColumns(schemaPromise, className, object, query) {
|
||||
return schemaPromise.then((schema) => {
|
||||
return schemaPromise.then(schema => {
|
||||
return schema.validateRequiredColumns(className, object, query);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ export class UserController extends AdaptableController {
|
||||
'_User',
|
||||
{ username: username, emailVerified: true }
|
||||
);
|
||||
return checkIfAlreadyVerified.execute().then((result) => {
|
||||
return checkIfAlreadyVerified.execute().then(result => {
|
||||
if (result.results.length) {
|
||||
return Promise.resolve(result.results.length[0]);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ export class UserController extends AdaptableController {
|
||||
},
|
||||
{ limit: 1 }
|
||||
)
|
||||
.then((results) => {
|
||||
.then(results => {
|
||||
if (results.length != 1) {
|
||||
throw 'Failed to reset password: username / email / token is invalid';
|
||||
}
|
||||
@@ -141,7 +141,7 @@ export class UserController extends AdaptableController {
|
||||
}
|
||||
const token = encodeURIComponent(user._email_verify_token);
|
||||
// We may need to fetch the user in case of update email
|
||||
this.getUserIfNeeded(user).then((user) => {
|
||||
this.getUserIfNeeded(user).then(user => {
|
||||
const username = encodeURIComponent(user.username);
|
||||
|
||||
const link = buildEmailLink(
|
||||
@@ -179,7 +179,7 @@ export class UserController extends AdaptableController {
|
||||
}
|
||||
|
||||
resendVerificationEmail(username) {
|
||||
return this.getUserIfNeeded({ username: username }).then((aUser) => {
|
||||
return this.getUserIfNeeded({ username: username }).then(aUser => {
|
||||
if (!aUser || aUser.emailVerified) {
|
||||
throw undefined;
|
||||
}
|
||||
@@ -216,7 +216,7 @@ export class UserController extends AdaptableController {
|
||||
// TODO: No adapter?
|
||||
}
|
||||
|
||||
return this.setPasswordResetToken(email).then((user) => {
|
||||
return this.setPasswordResetToken(email).then(user => {
|
||||
const token = encodeURIComponent(user._perishable_token);
|
||||
const username = encodeURIComponent(user.username);
|
||||
|
||||
@@ -244,8 +244,8 @@ export class UserController extends AdaptableController {
|
||||
|
||||
updatePassword(username, token, password) {
|
||||
return this.checkResetTokenValidity(username, token)
|
||||
.then((user) => updateUserPassword(user.objectId, password, this.config))
|
||||
.catch((error) => {
|
||||
.then(user => updateUserPassword(user.objectId, password, this.config))
|
||||
.catch(error => {
|
||||
if (error && error.message) {
|
||||
// in case of Parse.Error, fail with the error message only
|
||||
return Promise.reject(error.message);
|
||||
|
||||
Reference in New Issue
Block a user