Skip to content

Commit 842c42c

Browse files
authored
Update Cloud Code (#1211)
* Update CloudCode.js Hi all, Not sure if my formatting is perfect but closes #1176 (removes pre. SDK 2.0 success functions), and adds documentation for LiveQuery triggers. Also, for me, when I google "Parse Javascript SDK", it takes me to v1.11.0. Is there any way we can add "This SDK is outdated" or some other warning to point users to the latest SDK? Thank you! * Update CloudCode.js
1 parent d2a5641 commit 842c42c

File tree

1 file changed

+61
-24
lines changed

1 file changed

+61
-24
lines changed

src/CloudCode.js

+61-24
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@
6262
*
6363
* 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.
6464
* ```
65-
* Parse.Cloud.beforeDelete('MyCustomClass', (request, response) => {
65+
* Parse.Cloud.beforeDelete('MyCustomClass', (request) => {
6666
* // code here
6767
* })
6868
*
69-
* Parse.Cloud.beforeDelete(Parse.User, (request, response) => {
69+
* Parse.Cloud.beforeDelete(Parse.User, (request) => {
7070
* // code here
7171
* })
7272
*```
7373
*
7474
* @method beforeDelete
7575
* @name Parse.Cloud.beforeDelete
7676
* @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}.
77+
* @param {Function} func The function to run before a delete. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
7878
*/
7979

8080
/**
@@ -86,19 +86,19 @@
8686
* 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.
8787
*
8888
* ```
89-
* Parse.Cloud.beforeSave('MyCustomClass', (request, response) => {
89+
* Parse.Cloud.beforeSave('MyCustomClass', (request) => {
9090
* // code here
9191
* })
9292
*
93-
* Parse.Cloud.beforeSave(Parse.User, (request, response) => {
93+
* Parse.Cloud.beforeSave(Parse.User, (request) => {
9494
* // code here
9595
* })
9696
* ```
9797
*
9898
* @method beforeSave
9999
* @name Parse.Cloud.beforeSave
100100
* @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}.
101+
* @param {Function} func The function to run before a save. This function should take just one parameter, {@link Parse.Cloud.TriggerRequest}.
102102
*/
103103

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

169+
/**
170+
* @method beforeConnect
171+
* @name Parse.Cloud.beforeConnect
172+
* @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}.
173+
*/
174+
/**
175+
*
176+
* Registers a before connect function.
177+
*
178+
* **Available in Cloud Code only.**
179+
*
180+
* Example: restrict LiveQueries to logged in users.
181+
* ```
182+
* Parse.Cloud.beforeConnect((request) => {
183+
* if (!request.user) {
184+
* throw "Please login before you attempt to connect."
185+
* }
186+
* });
187+
* ```
188+
*/
189+
190+
/**
191+
* @method beforeSubscribe
192+
* @name Parse.Cloud.beforeSubscribe
193+
* @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.
194+
* @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}.
195+
*/
196+
/**
197+
*
198+
* Registers a before subscribe function.
199+
*
200+
* **Available in Cloud Code only.**
201+
* Example: restrict subscriptions to MyObject to Admin accounts only.
202+
* ```
203+
* Parse.Cloud.beforeSubscribe('MyObject', (request) => {
204+
* if (!request.user.get('Admin')) {
205+
* throw new Parse.Error(101, 'You are not authorized to subscribe to MyObject.');
206+
* }
207+
* let query = request.query; // the Parse.Query
208+
* query.select("name","year")
209+
* });
210+
* ```
211+
*/
212+
213+
169214
/**
170215
* Makes an HTTP Request.
171216
*
@@ -229,6 +274,16 @@
229274
* @property {Object} log The current logger inside Parse Server.
230275
*/
231276

277+
/**
278+
* @typedef Parse.Cloud.ConnectTriggerRequest
279+
* @property {String} installationId If set, the installationId triggering the request.
280+
* @property {Boolean} useMasterKey If true, means the master key was used.
281+
* @property {Parse.User} user If set, the user that made the request.
282+
* @property {Integer} clients The number of clients connected.
283+
* @property {Integer} subscriptions The number of subscriptions connected.
284+
* @property {String} sessionToken If set, the session of the user that made the request.
285+
*/
286+
232287
/**
233288
* @typedef Parse.Cloud.FunctionRequest
234289
* @property {String} installationId If set, the installationId triggering the request.
@@ -249,24 +304,6 @@
249304
* @property {function} success If success is called, will end the job successfullly with the optional completion message to be stored in the job status.
250305
*/
251306

252-
/**
253-
* @typedef Parse.Cloud.BeforeSaveResponse
254-
* @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.
255-
* @property {function} error If called, will reject the save. An optional error message may be passed in.
256-
*/
257-
258-
/**
259-
* @typedef Parse.Cloud.BeforeDeleteResponse
260-
* @property {function} success If called, will allow the delete to happen.
261-
* @property {function} error If called, will reject the save. An optional error message may be passed in.
262-
*/
263-
264-
/**
265-
* @typedef Parse.Cloud.FunctionResponse
266-
* @property {function} success If success is called, will return a successful response with the optional argument to the caller.
267-
* @property {function} error If error is called, will return an error response with an optionally passed message.
268-
*/
269-
270307
/**
271308
* @typedef Parse.Cloud.HTTPOptions
272309
* @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.

0 commit comments

Comments
 (0)