@@ -26,30 +26,22 @@ import type { RequestOptions } from './RESTController';
2626 * @param {string } name The function name.
2727 * @param {object } data The parameters to send to the cloud function.
2828 * @param {object } options
29+ * Valid options are:<ul>
30+ * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
31+ * be used for this request.
32+ * <li>sessionToken: A valid session token, used for making a request on
33+ * behalf of a specific user.
34+ * <li>installationId: the installationId which made the request
35+ * <li>context: A dictionary that is accessible in Cloud Code triggers.
36+ * </ul>
2937 * @returns {Promise } A promise that will be resolved with the result
3038 * of the function.
3139 */
3240export function run ( name : string , data : any , options : RequestOptions ) : Promise < any > {
33- options = options || { } ;
34-
3541 if ( typeof name !== 'string' || name . length === 0 ) {
3642 throw new TypeError ( 'Cloud function name must be a string.' ) ;
3743 }
38-
39- const requestOptions : RequestOptions = { } ;
40- if ( options . hasOwnProperty ( 'useMasterKey' ) ) {
41- requestOptions . useMasterKey = ! ! options . useMasterKey ;
42- }
43- if ( options . sessionToken ) {
44- requestOptions . sessionToken = options . sessionToken ;
45- }
46- if ( options . installationId ) {
47- requestOptions . installationId = options . installationId ;
48- }
49- if ( options . context && typeof options . context === 'object' ) {
50- requestOptions . context = options . context ;
51- }
52-
44+ const requestOptions = ParseObject . _getRequestOptions ( options ) ;
5345 return CoreManager . getCloudController ( ) . run ( name , data , requestOptions ) ;
5446}
5547
@@ -62,10 +54,7 @@ export function run(name: string, data: any, options: RequestOptions): Promise<a
6254 * of the function.
6355 */
6456export function getJobsData ( ) : Promise < any > {
65- const requestOptions = {
66- useMasterKey : true ,
67- } ;
68- return CoreManager . getCloudController ( ) . getJobsData ( requestOptions ) ;
57+ return CoreManager . getCloudController ( ) . getJobsData ( { useMasterKey : true } ) ;
6958}
7059
7160/**
@@ -82,10 +71,7 @@ export function startJob(name: string, data: any): Promise<string> {
8271 if ( typeof name !== 'string' || name . length === 0 ) {
8372 throw new TypeError ( 'Cloud job name must be a string.' ) ;
8473 }
85- const requestOptions = {
86- useMasterKey : true ,
87- } ;
88- return CoreManager . getCloudController ( ) . startJob ( name , data , requestOptions ) ;
74+ return CoreManager . getCloudController ( ) . startJob ( name , data , { useMasterKey : true } ) ;
8975}
9076
9177/**
@@ -104,17 +90,15 @@ export function getJobStatus(jobStatusId: string): Promise<ParseObject> {
10490const DefaultController = {
10591 run ( name : string , data : any , options : RequestOptions ) {
10692 const RESTController = CoreManager . getRESTController ( ) ;
107-
10893 const payload = encode ( data , true ) ;
10994
11095 const request = RESTController . request ( 'POST' , 'functions/' + name , payload , options ) ;
111-
11296 return request . then ( res => {
113- if ( typeof res === 'object' && Object . keys ( res ) . length > 0 && ! res . hasOwnProperty ( 'result' ) ) {
97+ if ( typeof res === 'object' && Object . keys ( res ) . length > 0 && ! Object . hasOwn ( res , 'result' ) ) {
11498 throw new ParseError ( ParseError . INVALID_JSON , 'The server returned an invalid response.' ) ;
11599 }
116100 const decoded = decode ( res ) ;
117- if ( decoded && decoded . hasOwnProperty ( 'result' ) ) {
101+ if ( decoded && Object . hasOwn ( decoded , 'result' ) ) {
118102 return Promise . resolve ( decoded . result ) ;
119103 }
120104 return Promise . resolve ( undefined ) ;
@@ -123,7 +107,6 @@ const DefaultController = {
123107
124108 getJobsData ( options : RequestOptions ) {
125109 const RESTController = CoreManager . getRESTController ( ) ;
126-
127110 return RESTController . request ( 'GET' , 'cloud_code/jobs/data' , null , options ) ;
128111 } ,
129112
0 commit comments