@@ -26,30 +26,22 @@ import type { RequestOptions } from './RESTController';
26
26
* @param {string } name The function name.
27
27
* @param {object } data The parameters to send to the cloud function.
28
28
* @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>
29
37
* @returns {Promise } A promise that will be resolved with the result
30
38
* of the function.
31
39
*/
32
40
export function run ( name : string , data : any , options : RequestOptions ) : Promise < any > {
33
- options = options || { } ;
34
-
35
41
if ( typeof name !== 'string' || name . length === 0 ) {
36
42
throw new TypeError ( 'Cloud function name must be a string.' ) ;
37
43
}
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 ) ;
53
45
return CoreManager . getCloudController ( ) . run ( name , data , requestOptions ) ;
54
46
}
55
47
@@ -62,10 +54,7 @@ export function run(name: string, data: any, options: RequestOptions): Promise<a
62
54
* of the function.
63
55
*/
64
56
export function getJobsData ( ) : Promise < any > {
65
- const requestOptions = {
66
- useMasterKey : true ,
67
- } ;
68
- return CoreManager . getCloudController ( ) . getJobsData ( requestOptions ) ;
57
+ return CoreManager . getCloudController ( ) . getJobsData ( { useMasterKey : true } ) ;
69
58
}
70
59
71
60
/**
@@ -82,10 +71,7 @@ export function startJob(name: string, data: any): Promise<string> {
82
71
if ( typeof name !== 'string' || name . length === 0 ) {
83
72
throw new TypeError ( 'Cloud job name must be a string.' ) ;
84
73
}
85
- const requestOptions = {
86
- useMasterKey : true ,
87
- } ;
88
- return CoreManager . getCloudController ( ) . startJob ( name , data , requestOptions ) ;
74
+ return CoreManager . getCloudController ( ) . startJob ( name , data , { useMasterKey : true } ) ;
89
75
}
90
76
91
77
/**
@@ -104,17 +90,15 @@ export function getJobStatus(jobStatusId: string): Promise<ParseObject> {
104
90
const DefaultController = {
105
91
run ( name : string , data : any , options : RequestOptions ) {
106
92
const RESTController = CoreManager . getRESTController ( ) ;
107
-
108
93
const payload = encode ( data , true ) ;
109
94
110
95
const request = RESTController . request ( 'POST' , 'functions/' + name , payload , options ) ;
111
-
112
96
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' ) ) {
114
98
throw new ParseError ( ParseError . INVALID_JSON , 'The server returned an invalid response.' ) ;
115
99
}
116
100
const decoded = decode ( res ) ;
117
- if ( decoded && decoded . hasOwnProperty ( 'result' ) ) {
101
+ if ( decoded && Object . hasOwn ( decoded , 'result' ) ) {
118
102
return Promise . resolve ( decoded . result ) ;
119
103
}
120
104
return Promise . resolve ( undefined ) ;
@@ -123,7 +107,6 @@ const DefaultController = {
123
107
124
108
getJobsData ( options : RequestOptions ) {
125
109
const RESTController = CoreManager . getRESTController ( ) ;
126
-
127
110
return RESTController . request ( 'GET' , 'cloud_code/jobs/data' , null , options ) ;
128
111
} ,
129
112
0 commit comments