Skip to content

Commit 09310b5

Browse files
committed
Adds documentation for async functions
1 parent d50284b commit 09310b5

File tree

1 file changed

+16
-38
lines changed

1 file changed

+16
-38
lines changed

src/CloudCode.js

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
* Defines a Cloud Function.
33
*
44
* **Available in Cloud Code only.**
5+
* **Starting parse-server 3.0.0, all cloud hooks and functions are asynchronous**
6+
* **All response objects are removed and replaced by promises / async/await based resolution**
57
*
68
* @method define
79
* @name Parse.Cloud.define
810
* @param {String} name The name of the Cloud Function
9-
* @param {Function} data The Cloud Function to register. This function should take two parameters a {@link Parse.Cloud.FunctionRequest} and a {@link Parse.Cloud.FunctionResponse}
11+
* @param {Function} data The Cloud Function to register. This function can be an async function and should take one parameter a {@link Parse.Cloud.FunctionRequest}.
1012
*/
1113

1214
/**
@@ -16,19 +18,19 @@
1618
*
1719
* If you want to use afterDelete 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.
1820
* ```
19-
* Parse.Cloud.afterDelete('MyCustomClass', (request) => {
21+
* Parse.Cloud.afterDelete('MyCustomClass', async (request) => {
2022
* // code here
2123
* })
2224
*
23-
* Parse.Cloud.afterDelete(Parse.User, (request) => {
25+
* Parse.Cloud.afterDelete(Parse.User, async (request) => {
2426
* // code here
2527
* })
2628
*```
2729
*
2830
* @method afterDelete
2931
* @name Parse.Cloud.afterDelete
3032
* @param {(String|Parse.Object)} arg1 The Parse.Object subclass to register the after delete function for. This can instead be a String that is the className of the subclass.
31-
* @param {Function} func The function to run after a delete. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
33+
* @param {Function} func The function to run after a delete. This function can be async and should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
3234
*/
3335

3436
/**
@@ -40,19 +42,19 @@
4042
* If you want to use afterSave 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.
4143
*
4244
* ```
43-
* Parse.Cloud.afterSave('MyCustomClass', function(request) {
45+
* Parse.Cloud.afterSave('MyCustomClass', async function(request) {
4446
* // code here
4547
* })
4648
*
47-
* Parse.Cloud.afterSave(Parse.User, function(request) {
49+
* Parse.Cloud.afterSave(Parse.User, async function(request) {
4850
* // code here
4951
* })
5052
* ```
5153
*
5254
* @method afterSave
5355
* @name Parse.Cloud.afterSave
5456
* @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.
55-
* @param {Function} func The function to run after a save. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
57+
* @param {Function} func The function to run after a save. This function can be an async function and should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
5658
*/
5759

5860
/**
@@ -62,19 +64,19 @@
6264
*
6365
* 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.
6466
* ```
65-
* Parse.Cloud.beforeDelete('MyCustomClass', (request, response) => {
67+
* Parse.Cloud.beforeDelete('MyCustomClass', (request) => {
6668
* // code here
6769
* })
6870
*
69-
* Parse.Cloud.beforeDelete(Parse.User, (request, response) => {
71+
* Parse.Cloud.beforeDelete(Parse.User, (request) => {
7072
* // code here
7173
* })
7274
*```
7375
*
7476
* @method beforeDelete
7577
* @name Parse.Cloud.beforeDelete
7678
* @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.
77-
* @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}.
79+
* @param {Function} func The function to run before a delete. This function can be async and should take one parameter, a {@link Parse.Cloud.TriggerRequest}.
7880
*/
7981

8082
/**
@@ -86,19 +88,19 @@
8688
* 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.
8789
*
8890
* ```
89-
* Parse.Cloud.beforeSave('MyCustomClass', (request, response) => {
91+
* Parse.Cloud.beforeSave('MyCustomClass', (request) => {
9092
* // code here
9193
* })
9294
*
93-
* Parse.Cloud.beforeSave(Parse.User, (request, response) => {
95+
* Parse.Cloud.beforeSave(Parse.User, (request) => {
9496
* // code here
9597
* })
9698
* ```
9799
*
98100
* @method beforeSave
99101
* @name Parse.Cloud.beforeSave
100102
* @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.
101-
* @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}.
103+
* @param {Function} func The function to run before a save. This function can be async and should take one parameter a {@link Parse.Cloud.TriggerRequest};
102104
*/
103105

104106
/**
@@ -135,7 +137,7 @@
135137
* @method job
136138
* @name Parse.Cloud.job
137139
* @param {String} name The name of the Background Job
138-
* @param {Function} func The Background Job to register. This function should take two parameters a {@link Parse.Cloud.JobRequest} and a {@link Parse.Cloud.JobStatus}
140+
* @param {Function} func The Background Job to register. This function can be async should take a single parameters a {@link Parse.Cloud.JobRequest}
139141
*
140142
*/
141143

@@ -163,31 +165,7 @@
163165
/**
164166
* @typedef Parse.Cloud.JobRequest
165167
* @property {Object} params The params passed to the background job.
166-
*/
167-
168-
/**
169-
* @typedef Parse.Cloud.JobStatus
170-
* @property {function} error If error is called, will end the job unsuccessfully with an optional completion message to be stored in the job status.
171168
* @property {function} message If message is called with a string argument, will update the current message to be stored in the job status.
172-
* @property {function} success If success is called, will end the job successfullly with the optional completion message to be stored in the job status.
173-
*/
174-
175-
/**
176-
* @typedef Parse.Cloud.BeforeSaveResponse
177-
* @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.
178-
* @property {function} error If called, will reject the save. An optional error message may be passed in.
179-
*/
180-
181-
/**
182-
* @typedef Parse.Cloud.BeforeDeleteResponse
183-
* @property {function} success If called, will allow the delete to happen.
184-
* @property {function} error If called, will reject the save. An optional error message may be passed in.
185-
*/
186-
187-
/**
188-
* @typedef Parse.Cloud.FunctionResponse
189-
* @property {function} success If success is called, will return a successful response with the optional argument to the caller.
190-
* @property {function} error If error is called, will return an error response with an optionally passed message.
191169
*/
192170

193171
/**

0 commit comments

Comments
 (0)