Begin isolating object creation code into an externalizable API. (#1569)

* Tidy up transformKeyValue

* Specialize transformKeyValue for object creation

* remove keys that never appear in creation requests

* rename function

* remove local var

* early exit for simple keys

* Refactor create

* Force class creation when creating an object

* Pass parameters to key value transformer

* No need to check for array in this func

* start using Parse Format schema in MongoTransform

* Remove call to getExpectedType

* add tests to ensure client can't see _PushStatus
This commit is contained in:
Drew
2016-04-20 13:35:48 -07:00
parent 59b4047de8
commit 9776362ab2
6 changed files with 225 additions and 71 deletions

View File

@@ -91,7 +91,7 @@ const requiredColumns = Object.freeze({
_Role: ["name", "ACL"]
});
const systemClasses = Object.freeze(['_User', '_Installation', '_Role', '_Session', '_Product']);
const systemClasses = Object.freeze(['_User', '_Installation', '_Role', '_Session', '_Product', '_PushStatus']);
// 10 alpha numberic chars + uppercase
const userIdRegex = /^[a-zA-Z0-9]{10}$/;
@@ -341,12 +341,8 @@ class SchemaController {
// Returns a promise that resolves successfully to the new schema
// object or fails with a reason.
// If 'freeze' is true, refuse to update the schema.
// WARNING: this function has side-effects, and doesn't actually
// do any validation of the format of the className. You probably
// should use classNameIsValid or addClassIfNotExists or something
// like that instead. TODO: rename or remove this function.
validateClassName(className, freeze) {
// If 'freeze' is true, refuse to modify the schema.
enforceClassExists(className, freeze) {
if (this.data[className]) {
return Promise.resolve(this);
}
@@ -366,7 +362,7 @@ class SchemaController {
return this.reloadData();
}).then(() => {
// Ensure that the schema now validates
return this.validateClassName(className, true);
return this.enforceClassExists(className, true);
}, () => {
// The schema still doesn't validate. Give up
throw new Parse.Error(Parse.Error.INVALID_JSON, 'schema class name does not revalidate');
@@ -547,7 +543,7 @@ class SchemaController {
// valid.
validateObject(className, object, query) {
let geocount = 0;
let promise = this.validateClassName(className);
let promise = this.enforceClassExists(className);
for (let fieldName in object) {
if (object[fieldName] === undefined) {
continue;
@@ -642,15 +638,6 @@ class SchemaController {
return this.reloadData().then(() => !!(this.data[className]));
}
// Helper function to check if a field is a pointer, returns true or false.
isPointer(className, key) {
let expected = this.getExpectedType(className, key);
if (expected && expected.charAt(0) == '*') {
return true;
}
return false;
};
getRelationFields(className) {
if (this.data && this.data[className]) {
let classData = this.data[className];