10
10
*/
11
11
12
12
import CoreManager from './CoreManager' ;
13
- import type { RequestOptions , FullOptions } from './RESTController' ;
14
13
15
14
const FIELD_TYPES = [ 'String' , 'Number' , 'Boolean' , 'Date' , 'File' , 'GeoPoint' , 'Polygon' , 'Array' , 'Object' , 'Pointer' , 'Relation' ] ;
16
15
@@ -21,7 +20,7 @@ const FIELD_TYPES = ['String', 'Number', 'Boolean', 'Date', 'File', 'GeoPoint',
21
20
* <pre>
22
21
* const schema = new Parse.Schema('MyClass');
23
22
* schema.addString('field');
24
- * schema.addIndex('index_name', {'field', 1 });
23
+ * schema.addIndex('index_name', { 'field': 1 });
25
24
* schema.save();
26
25
* </pre>
27
26
* </p>
@@ -51,22 +50,12 @@ class ParseSchema {
51
50
/**
52
51
* Static method to get all schemas
53
52
*
54
- * @param {Object } options
55
- * Valid options are:<ul>
56
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
57
- * be used for this request.
58
- * <li>sessionToken: A valid session token, used for making a request on
59
- * behalf of a specific user.
60
- * </ul>
61
- *
62
53
* @return {Promise } A promise that is resolved with the result when
63
54
* the query completes.
64
55
*/
65
- static all ( options : FullOptions ) {
66
- options = options || { } ;
56
+ static all ( ) {
67
57
const controller = CoreManager . getSchemaController ( ) ;
68
-
69
- return controller . get ( '' , options )
58
+ return controller . get ( '' )
70
59
. then ( ( response ) => {
71
60
if ( response . results . length === 0 ) {
72
61
throw new Error ( 'Schema not found.' ) ;
@@ -78,24 +67,14 @@ class ParseSchema {
78
67
/**
79
68
* Get the Schema from Parse
80
69
*
81
- * @param {Object } options
82
- * Valid options are:<ul>
83
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
84
- * be used for this request.
85
- * <li>sessionToken: A valid session token, used for making a request on
86
- * behalf of a specific user.
87
- * </ul>
88
- *
89
70
* @return {Promise } A promise that is resolved with the result when
90
71
* the query completes.
91
72
*/
92
- get ( options : FullOptions ) {
73
+ get ( ) {
93
74
this . assertClassName ( ) ;
94
75
95
- options = options || { } ;
96
76
const controller = CoreManager . getSchemaController ( ) ;
97
-
98
- return controller . get ( this . className , options )
77
+ return controller . get ( this . className )
99
78
. then ( ( response ) => {
100
79
if ( ! response ) {
101
80
throw new Error ( 'Schema not found.' ) ;
@@ -107,52 +86,31 @@ class ParseSchema {
107
86
/**
108
87
* Create a new Schema on Parse
109
88
*
110
- * @param {Object } options
111
- * Valid options are:<ul>
112
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
113
- * be used for this request.
114
- * <li>sessionToken: A valid session token, used for making a request on
115
- * behalf of a specific user.
116
- * </ul>
117
- *
118
89
* @return {Promise } A promise that is resolved with the result when
119
90
* the query completes.
120
91
*/
121
- save ( options : FullOptions ) {
92
+ save ( ) {
122
93
this . assertClassName ( ) ;
123
94
124
- options = options || { } ;
125
95
const controller = CoreManager . getSchemaController ( ) ;
126
96
const params = {
127
97
className : this . className ,
128
98
fields : this . _fields ,
129
99
indexes : this . _indexes ,
130
100
} ;
131
101
132
- return controller . create ( this . className , params , options )
133
- . then ( ( response ) => {
134
- return response ;
135
- } ) ;
102
+ return controller . create ( this . className , params ) ;
136
103
}
137
104
138
105
/**
139
106
* Update a Schema on Parse
140
107
*
141
- * @param {Object } options
142
- * Valid options are:<ul>
143
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
144
- * be used for this request.
145
- * <li>sessionToken: A valid session token, used for making a request on
146
- * behalf of a specific user.
147
- * </ul>
148
- *
149
108
* @return {Promise } A promise that is resolved with the result when
150
109
* the query completes.
151
110
*/
152
- update ( options : FullOptions ) {
111
+ update ( ) {
153
112
this . assertClassName ( ) ;
154
113
155
- options = options || { } ;
156
114
const controller = CoreManager . getSchemaController ( ) ;
157
115
const params = {
158
116
className : this . className ,
@@ -163,37 +121,21 @@ class ParseSchema {
163
121
this . _fields = { } ;
164
122
this . _indexes = { } ;
165
123
166
- return controller . update ( this . className , params , options )
167
- . then ( ( response ) => {
168
- return response ;
169
- } ) ;
124
+ return controller . update ( this . className , params ) ;
170
125
}
171
126
172
127
/**
173
128
* Removing a Schema from Parse
174
129
* Can only be used on Schema without objects
175
130
*
176
- * @param {Object } options
177
- * Valid options are:<ul>
178
- * <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
179
- * be used for this request.
180
- * <li>sessionToken: A valid session token, used for making a request on
181
- * behalf of a specific user.
182
- * </ul>
183
- *
184
131
* @return {Promise } A promise that is resolved with the result when
185
132
* the query completes.
186
133
*/
187
- delete ( options : FullOptions ) {
134
+ delete ( ) {
188
135
this . assertClassName ( ) ;
189
136
190
- options = options || { } ;
191
137
const controller = CoreManager . getSchemaController ( ) ;
192
-
193
- return controller . delete ( this . className , options )
194
- . then ( ( response ) => {
195
- return response ;
196
- } ) ;
138
+ return controller . delete ( this . className ) ;
197
139
}
198
140
199
141
/**
@@ -206,11 +148,7 @@ class ParseSchema {
206
148
this . assertClassName ( ) ;
207
149
208
150
const controller = CoreManager . getSchemaController ( ) ;
209
-
210
- return controller . purge ( this . className )
211
- . then ( ( response ) => {
212
- return response ;
213
- } ) ;
151
+ return controller . purge ( this . className ) ;
214
152
}
215
153
216
154
/**
@@ -425,34 +363,30 @@ class ParseSchema {
425
363
}
426
364
427
365
const DefaultController = {
428
- send ( className : string , method : string , params : any , options : RequestOptions ) : Promise {
366
+ send ( className : string , method : string , params : any = { } ) : Promise {
429
367
const RESTController = CoreManager . getRESTController ( ) ;
430
- const requestOptions = { useMasterKey : true } ;
431
- if ( options . hasOwnProperty ( 'sessionToken' ) ) {
432
- requestOptions . sessionToken = options . sessionToken ;
433
- }
434
368
return RESTController . request (
435
369
method ,
436
370
`schemas/${ className } ` ,
437
371
params ,
438
- requestOptions
372
+ { useMasterKey : true }
439
373
) ;
440
374
} ,
441
375
442
- get ( className : string , options : RequestOptions ) : Promise {
443
- return this . send ( className , 'GET' , { } , options ) ;
376
+ get ( className : string ) : Promise {
377
+ return this . send ( className , 'GET' ) ;
444
378
} ,
445
379
446
- create ( className : string , params : any , options : RequestOptions ) : Promise {
447
- return this . send ( className , 'POST' , params , options ) ;
380
+ create ( className : string , params : any ) : Promise {
381
+ return this . send ( className , 'POST' , params ) ;
448
382
} ,
449
383
450
- update ( className : string , params : any , options : RequestOptions ) : Promise {
451
- return this . send ( className , 'PUT' , params , options ) ;
384
+ update ( className : string , params : any ) : Promise {
385
+ return this . send ( className , 'PUT' , params ) ;
452
386
} ,
453
387
454
- delete ( className : string , options : RequestOptions ) : Promise {
455
- return this . send ( className , 'DELETE' , { } , options ) ;
388
+ delete ( className : string ) : Promise {
389
+ return this . send ( className , 'DELETE' ) ;
456
390
} ,
457
391
458
392
purge ( className : string ) : Promise {
0 commit comments