Skip to content

update function and freeze schema #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ExportAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ ExportAdapter.prototype.redirectClassNameForKey = function(className, key) {
// Returns a promise that resolves to the new schema.
// This does not update this.schema, because in a situation like a
// batch request, that could confuse other users of the schema.
ExportAdapter.prototype.validateObject = function(className, object) {
ExportAdapter.prototype.validateObject = function(className, object, freeze) {
return this.loadSchema().then((schema) => {
return schema.validateObject(className, object);
return schema.validateObject(className, object, freeze);
});
};

Expand Down
3 changes: 2 additions & 1 deletion RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ RestWrite.prototype.execute = function() {

// Validates this operation against the schema.
RestWrite.prototype.validateSchema = function() {
return this.config.database.validateObject(this.className, this.data);
var schemaFrozen = (process.env.NODE_ENV !== 'development') ? !(this.auth && this.auth.isMaster) : false;
return this.config.database.validateObject(this.className, this.data, schemaFrozen);
};

// Runs any beforeSave triggers against this operation.
Expand Down
10 changes: 5 additions & 5 deletions Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,18 @@ Schema.prototype.validateField = function(className, key, type, freeze) {

// Given a schema promise, construct another schema promise that
// validates this field once the schema loads.
function thenValidateField(schemaPromise, className, key, type) {
function thenValidateField(schemaPromise, className, key, type, freeze) {
return schemaPromise.then((schema) => {
return schema.validateField(className, key, type);
return schema.validateField(className, key, type, freeze);
});
}

// Validates an object provided in REST format.
// Returns a promise that resolves to the new schema if this object is
// valid.
Schema.prototype.validateObject = function(className, object) {
Schema.prototype.validateObject = function(className, object, freeze) {
var geocount = 0;
var promise = this.validateClassName(className);
var promise = this.validateClassName(className, freeze);
for (var key in object) {
var expected = getType(object[key]);
if (expected === 'geopoint') {
Expand All @@ -224,7 +224,7 @@ Schema.prototype.validateObject = function(className, object) {
if (!expected) {
continue;
}
promise = thenValidateField(promise, className, key, expected);
promise = thenValidateField(promise, className, key, expected, freeze);
}
return promise;
};
Expand Down
10 changes: 8 additions & 2 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ function handleCloudFunction(req) {
var response = createResponseObject(resolve, reject);
var request = {
params: req.body || {},
<<<<<<< HEAD
master : req.auth ? req.auth.isMaster : false,
user : req.auth && req.auth.user ? req.auth.user : undefined,
installationId : req.auth && req.auth.installationId ? req.auth.installationId : undefined
=======
user: req.auth && req.auth.user || {}
>>>>>>> upstream/master
};
Parse.Cloud.Functions[req.params.functionName](request, response);
});
Expand All @@ -34,10 +40,10 @@ function createResponseObject(resolve, reject) {
error: function(error) {
reject(new Parse.Error(Parse.Error.SCRIPT_FAILED, error));
}
}
};
}

router.route('POST', '/functions/:functionName', handleCloudFunction);
router.route('POST', '/functions/:functionName+', handleCloudFunction);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the + sign here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • will allow to have a structured calls on functions, such as
Parse.Cloud.run('workflow/list', { objs : true}), 

extending functions reach.
It is an optional route parameter from express, it will be ignored if it is not present and it will work as pervious.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It requires latest express and path-to-regexp version, otherwise it will fallback to initial behaviour.



module.exports = router;