Skip to content

Update Cloud Code #1

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

Merged
merged 1 commit into from
Aug 19, 2020
Merged
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
85 changes: 61 additions & 24 deletions src/CloudCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@
*
* If you want to use beforeDelete for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), you should pass the class itself and not the String for arg1.
* ```
* Parse.Cloud.beforeDelete('MyCustomClass', (request, response) => {
* Parse.Cloud.beforeDelete('MyCustomClass', (request) => {
* // code here
* })
*
* Parse.Cloud.beforeDelete(Parse.User, (request, response) => {
* Parse.Cloud.beforeDelete(Parse.User, (request) => {
* // code here
* })
*```
*
* @method beforeDelete
* @name Parse.Cloud.beforeDelete
* @param {(String|Parse.Object)} arg1 The Parse.Object subclass to register the before delete function for. This can instead be a String that is the className of the subclass.
* @param {Function} func The function to run before a delete. This function should take two parameters a {@link Parse.Cloud.TriggerRequest} and a {@link Parse.Cloud.BeforeDeleteResponse}.
* @param {Function} func The function to run after a save. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
*/

/**
Expand All @@ -86,19 +86,19 @@
* If you want to use beforeSave for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), you should pass the class itself and not the String for arg1.
*
* ```
* Parse.Cloud.beforeSave('MyCustomClass', (request, response) => {
* Parse.Cloud.beforeSave('MyCustomClass', (request) => {
* // code here
* })
*
* Parse.Cloud.beforeSave(Parse.User, (request, response) => {
* Parse.Cloud.beforeSave(Parse.User, (request) => {
* // code here
* })
* ```
*
* @method beforeSave
* @name Parse.Cloud.beforeSave
* @param {(String|Parse.Object)} arg1 The Parse.Object subclass to register the after save function for. This can instead be a String that is the className of the subclass.
* @param {Function} func The function to run before a save. This function should take two parameters a {@link Parse.Cloud.TriggerRequest} and a {@link Parse.Cloud.BeforeSaveResponse}.
* @param {Function} func The function to run after a save. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
*/

/**
Expand Down Expand Up @@ -166,6 +166,51 @@
* @param {Function} func The function to run after a file saves. This function should take one parameter, a {@link Parse.Cloud.FileTriggerRequest}.
*/

/**
* @method beforeConnect
* @name Parse.Cloud.beforeConnect
* @param {Function} func The function to before connection is made. This function can be async and should take just one parameter, {@link Parse.Cloud.ConnectTriggerRequest}.
*/
/**
*
* Registers a before connect function.
*
* **Available in Cloud Code only.**
*
* Example: restrict LiveQueries to logged in users.
* ```
* Parse.Cloud.beforeConnect((request) => {
* if (!request.user) {
* throw "Please login before you attempt to connect."
* }
* });
* ```
*/

/**
* @method beforeSubscribe
* @name Parse.Cloud.beforeSubscribe
* @param {(String|Parse.Object)} arg1 The Parse.Object subclass to register the before subscription function for. This can instead be a String that is the className of the subclass.
* @param {Function} func The function to run before a subscription. This function can be async and should take one parameter, a {@link Parse.Cloud.TriggerRequest}.
*/
/**
*
* Registers a before subscribe function.
*
* **Available in Cloud Code only.**
* Example: restrict subscriptions to MyObject to Admin accounts only.
* ```
* Parse.Cloud.beforeSubscribe('MyObject', (request) => {
* if (!request.user.get('Admin')) {
* throw new Parse.Error(101, 'You are not authorized to subscribe to MyObject.');
* }
* let query = request.query; // the Parse.Query
* query.select("name","year")
* });
* ```
*/


/**
* Makes an HTTP Request.
*
Expand Down Expand Up @@ -229,6 +274,16 @@
* @property {Object} log The current logger inside Parse Server.
*/

/**
* @typedef Parse.Cloud.ConnectTriggerRequest
* @property {String} installationId If set, the installationId triggering the request.
* @property {Boolean} useMasterKey If true, means the master key was used.
* @property {Parse.User} user If set, the user that made the request.
* @property {Integer} clients The number of clients connected.
* @property {Integer} subscriptions The number of subscriptions connected.
* @property {String} sessionToken If set, the session of the user that made the request.
*/

/**
* @typedef Parse.Cloud.FunctionRequest
* @property {String} installationId If set, the installationId triggering the request.
Expand All @@ -249,24 +304,6 @@
* @property {function} success If success is called, will end the job successfullly with the optional completion message to be stored in the job status.
*/

/**
* @typedef Parse.Cloud.BeforeSaveResponse
* @property {function} success If called, will allow the save to happen. If a Parse.Object is passed in, then the passed in object will be saved instead.
* @property {function} error If called, will reject the save. An optional error message may be passed in.
*/

/**
* @typedef Parse.Cloud.BeforeDeleteResponse
* @property {function} success If called, will allow the delete to happen.
* @property {function} error If called, will reject the save. An optional error message may be passed in.
*/

/**
* @typedef Parse.Cloud.FunctionResponse
* @property {function} success If success is called, will return a successful response with the optional argument to the caller.
* @property {function} error If error is called, will return an error response with an optionally passed message.
*/

/**
* @typedef Parse.Cloud.HTTPOptions
* @property {String|Object} body The body of the request. If it is a JSON object, then the Content-Type set in the headers must be application/x-www-form-urlencoded or application/json. You can also set this to a {@link Buffer} object to send raw bytes. If you use a Buffer, you should also set the Content-Type header explicitly to describe what these bytes represent.
Expand Down