Skip to content

Commit 7c5b0d9

Browse files
authored
Fix: Remove options from Parse.Schema (#959)
* Fix: Remove options from Parse.Schema Closes: #941 Fixes Documentation `useMasterKey: true` is sent with every Parse.Schema request so passing it and sessionToken as a parameter is redundant. * improve coverage * nit
1 parent b8b75ef commit 7c5b0d9

File tree

2 files changed

+31
-147
lines changed

2 files changed

+31
-147
lines changed

src/ParseSchema.js

Lines changed: 22 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*/
1111

1212
import CoreManager from './CoreManager';
13-
import type { RequestOptions, FullOptions } from './RESTController';
1413

1514
const FIELD_TYPES = ['String', 'Number', 'Boolean', 'Date', 'File', 'GeoPoint', 'Polygon', 'Array', 'Object', 'Pointer', 'Relation'];
1615

@@ -21,7 +20,7 @@ const FIELD_TYPES = ['String', 'Number', 'Boolean', 'Date', 'File', 'GeoPoint',
2120
* <pre>
2221
* const schema = new Parse.Schema('MyClass');
2322
* schema.addString('field');
24-
* schema.addIndex('index_name', {'field', 1});
23+
* schema.addIndex('index_name', { 'field': 1 });
2524
* schema.save();
2625
* </pre>
2726
* </p>
@@ -51,22 +50,12 @@ class ParseSchema {
5150
/**
5251
* Static method to get all schemas
5352
*
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-
*
6253
* @return {Promise} A promise that is resolved with the result when
6354
* the query completes.
6455
*/
65-
static all(options: FullOptions) {
66-
options = options || {};
56+
static all() {
6757
const controller = CoreManager.getSchemaController();
68-
69-
return controller.get('', options)
58+
return controller.get('')
7059
.then((response) => {
7160
if (response.results.length === 0) {
7261
throw new Error('Schema not found.');
@@ -78,24 +67,14 @@ class ParseSchema {
7867
/**
7968
* Get the Schema from Parse
8069
*
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-
*
8970
* @return {Promise} A promise that is resolved with the result when
9071
* the query completes.
9172
*/
92-
get(options: FullOptions) {
73+
get() {
9374
this.assertClassName();
9475

95-
options = options || {};
9676
const controller = CoreManager.getSchemaController();
97-
98-
return controller.get(this.className, options)
77+
return controller.get(this.className)
9978
.then((response) => {
10079
if (!response) {
10180
throw new Error('Schema not found.');
@@ -107,52 +86,31 @@ class ParseSchema {
10786
/**
10887
* Create a new Schema on Parse
10988
*
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-
*
11889
* @return {Promise} A promise that is resolved with the result when
11990
* the query completes.
12091
*/
121-
save(options: FullOptions) {
92+
save() {
12293
this.assertClassName();
12394

124-
options = options || {};
12595
const controller = CoreManager.getSchemaController();
12696
const params = {
12797
className: this.className,
12898
fields: this._fields,
12999
indexes: this._indexes,
130100
};
131101

132-
return controller.create(this.className, params, options)
133-
.then((response) => {
134-
return response;
135-
});
102+
return controller.create(this.className, params);
136103
}
137104

138105
/**
139106
* Update a Schema on Parse
140107
*
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-
*
149108
* @return {Promise} A promise that is resolved with the result when
150109
* the query completes.
151110
*/
152-
update(options: FullOptions) {
111+
update() {
153112
this.assertClassName();
154113

155-
options = options || {};
156114
const controller = CoreManager.getSchemaController();
157115
const params = {
158116
className: this.className,
@@ -163,37 +121,21 @@ class ParseSchema {
163121
this._fields = {};
164122
this._indexes = {};
165123

166-
return controller.update(this.className, params, options)
167-
.then((response) => {
168-
return response;
169-
});
124+
return controller.update(this.className, params);
170125
}
171126

172127
/**
173128
* Removing a Schema from Parse
174129
* Can only be used on Schema without objects
175130
*
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-
*
184131
* @return {Promise} A promise that is resolved with the result when
185132
* the query completes.
186133
*/
187-
delete(options: FullOptions) {
134+
delete() {
188135
this.assertClassName();
189136

190-
options = options || {};
191137
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);
197139
}
198140

199141
/**
@@ -206,11 +148,7 @@ class ParseSchema {
206148
this.assertClassName();
207149

208150
const controller = CoreManager.getSchemaController();
209-
210-
return controller.purge(this.className)
211-
.then((response) => {
212-
return response;
213-
});
151+
return controller.purge(this.className);
214152
}
215153

216154
/**
@@ -425,34 +363,30 @@ class ParseSchema {
425363
}
426364

427365
const DefaultController = {
428-
send(className: string, method: string, params: any, options: RequestOptions): Promise {
366+
send(className: string, method: string, params: any = {}): Promise {
429367
const RESTController = CoreManager.getRESTController();
430-
const requestOptions = { useMasterKey: true };
431-
if (options.hasOwnProperty('sessionToken')) {
432-
requestOptions.sessionToken = options.sessionToken;
433-
}
434368
return RESTController.request(
435369
method,
436370
`schemas/${className}`,
437371
params,
438-
requestOptions
372+
{ useMasterKey: true }
439373
);
440374
},
441375

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');
444378
},
445379

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);
448382
},
449383

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);
452386
},
453387

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');
456390
},
457391

458392
purge(className: string): Promise {

src/__tests__/ParseSchema-test.js

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,13 @@ describe('ParseSchema', () => {
170170
update() {},
171171
delete() {},
172172
purge() {},
173-
create(className, params, options) {
173+
create(className, params) {
174174
expect(className).toBe('SchemaTest');
175175
expect(params).toEqual({
176176
className: 'SchemaTest',
177177
fields: { name: { type: 'String'} },
178178
indexes: { testIndex: { name: 1 } }
179179
});
180-
expect(options).toEqual({});
181180
return Promise.resolve([]);
182181
},
183182
});
@@ -198,14 +197,13 @@ describe('ParseSchema', () => {
198197
create() {},
199198
delete() {},
200199
purge() {},
201-
update(className, params, options) {
200+
update(className, params) {
202201
expect(className).toBe('SchemaTest');
203202
expect(params).toEqual({
204203
className: 'SchemaTest',
205204
fields: { name: { type: 'String'} },
206205
indexes: { testIndex: { name: 1 } }
207206
});
208-
expect(options).toEqual({});
209207
return Promise.resolve([]);
210208
},
211209
});
@@ -226,9 +224,8 @@ describe('ParseSchema', () => {
226224
update() {},
227225
get() {},
228226
purge() {},
229-
delete(className, options) {
227+
delete(className) {
230228
expect(className).toBe('SchemaTest');
231-
expect(options).toEqual({});
232229
return Promise.resolve([]);
233230
},
234231
});
@@ -267,9 +264,8 @@ describe('ParseSchema', () => {
267264
update() {},
268265
delete() {},
269266
purge() {},
270-
get(className, options) {
267+
get(className) {
271268
expect(className).toBe('SchemaTest');
272-
expect(options).toEqual({});
273269
return Promise.resolve([]);
274270
},
275271
});
@@ -281,37 +277,15 @@ describe('ParseSchema', () => {
281277
});
282278
});
283279

284-
it('can get schema with options', (done) => {
285-
CoreManager.setSchemaController({
286-
send() {},
287-
create() {},
288-
update() {},
289-
delete() {},
290-
purge() {},
291-
get(className, options) {
292-
expect(className).toBe('SchemaTest');
293-
expect(options).toEqual({ sessionToken: 1234 });
294-
return Promise.resolve([]);
295-
},
296-
});
297-
298-
const schema = new ParseSchema('SchemaTest');
299-
schema.get({ sessionToken: 1234 }).then((results) => {
300-
expect(results).toEqual([]);
301-
done();
302-
});
303-
});
304-
305280
it('cannot get empty schema', (done) => {
306281
CoreManager.setSchemaController({
307282
send() {},
308283
create() {},
309284
update() {},
310285
delete() {},
311286
purge() {},
312-
get(className, options) {
287+
get(className) {
313288
expect(className).toBe('SchemaTest');
314-
expect(options).toEqual({});
315289
return Promise.resolve(null);
316290
},
317291
});
@@ -334,9 +308,8 @@ describe('ParseSchema', () => {
334308
update() {},
335309
delete() {},
336310
purge() {},
337-
get(className, options) {
311+
get(className) {
338312
expect(className).toBe('');
339-
expect(options).toEqual({});
340313
return Promise.resolve({
341314
results: ['all']
342315
});
@@ -349,38 +322,15 @@ describe('ParseSchema', () => {
349322
});
350323
});
351324

352-
it('can get all schema with options', (done) => {
353-
CoreManager.setSchemaController({
354-
send() {},
355-
create() {},
356-
update() {},
357-
delete() {},
358-
purge() {},
359-
get(className, options) {
360-
expect(className).toBe('');
361-
expect(options).toEqual({ sessionToken: 1234 });
362-
return Promise.resolve({
363-
results: ['all']
364-
});
365-
},
366-
});
367-
368-
ParseSchema.all({ sessionToken: 1234 }).then((results) => {
369-
expect(results[0]).toEqual('all');
370-
done();
371-
});
372-
});
373-
374325
it('cannot get all schema when empty', (done) => {
375326
CoreManager.setSchemaController({
376327
send() {},
377328
create() {},
378329
update() {},
379330
delete() {},
380331
purge() {},
381-
get(className, options) {
332+
get(className) {
382333
expect(className).toBe('');
383-
expect(options).toEqual({});
384334
return Promise.resolve({
385335
results: []
386336
});
@@ -410,9 +360,9 @@ describe('SchemaController', () => {
410360
CoreManager.setRESTController({ request: request, ajax: ajax });
411361
});
412362

413-
it('save schema with sessionToken', (done) => {
363+
it('save schema', (done) => {
414364
const schema = new ParseSchema('SchemaTest');
415-
schema.save({ sessionToken: 1234 }).then((results) => {
365+
schema.save().then((results) => {
416366
expect(results).toEqual([]);
417367
done();
418368
});

0 commit comments

Comments
 (0)