Skip to content

Commit 3c061bf

Browse files
committed
Fix a bunch of flow typing
1 parent 5002c27 commit 3c061bf

13 files changed

+60
-46
lines changed

src/Cloud.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function run(
4343
name: string,
4444
data: mixed,
4545
options: { [key: string]: mixed }
46-
) {
46+
): ParsePromise {
4747
options = options || {};
4848

4949
if (typeof name !== 'string' || name.length === 0) {

src/CoreManager.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
* @flow
1010
*/
1111

12-
import type { AttributeMap } from './ObjectStateMutations';
12+
import type { AttributeMap, ObjectCache, OpsMap, State } from './ObjectStateMutations';
1313
import type { FileSource } from './ParseFile';
14+
import type { Op } from './ParseOp';
1415
import type ParseObject from './ParseObject';
1516
import type ParsePromise from './ParsePromise';
1617
import type { QueryJSON } from './ParseQuery';
@@ -44,21 +45,21 @@ type ObjectController = {
4445
destroy: (object: ParseObject, options: RequestOptions) => ParsePromise;
4546
};
4647
type ObjectStateController = {
47-
getState: (obj: ParseObject) => ?State;
48-
initializeState: (obj: ParseObject, initial?: State) => State;
49-
removeState: (obj: ParseObject) => ?State;
50-
getServerData: (obj: ParseObject) => AttributeMap;
51-
setServerData: (obj: ParseObject, attributes: AttributeMap) => void;
52-
getPendingOps: (obj: ParseObject) => Array<OpsMap>;
53-
setPendingOp: (obj: ParseObject, attr: string, op: ?Op) => void;
54-
pushPendingState: (obj: ParseObject) => void;
55-
popPendingState: (obj: ParseObject) => OpsMap;
56-
mergeFirstPendingState: (obj: ParseObject) => void;
57-
getObjectCache: (obj: ParseObject) => ObjectCache;
58-
estimateAttribute: (obj: ParseObject, attr: string) => mixed;
59-
estimateAttributes: (obj: ParseObject) => AttributeMap;
60-
commitServerChanges: (obj: ParseObject, changes: AttributeMap) => void;
61-
enqueueTask: (obj: ParseObject, task: () => ParsePromise) => void;
48+
getState: (obj: any) => ?State;
49+
initializeState: (obj: any, initial?: State) => State;
50+
removeState: (obj: any) => ?State;
51+
getServerData: (obj: any) => AttributeMap;
52+
setServerData: (obj: any, attributes: AttributeMap) => void;
53+
getPendingOps: (obj: any) => Array<OpsMap>;
54+
setPendingOp: (obj: any, attr: string, op: ?Op) => void;
55+
pushPendingState: (obj: any) => void;
56+
popPendingState: (obj: any) => OpsMap;
57+
mergeFirstPendingState: (obj: any) => void;
58+
getObjectCache: (obj: any) => ObjectCache;
59+
estimateAttribute: (obj: any, attr: string) => mixed;
60+
estimateAttributes: (obj: any) => AttributeMap;
61+
commitServerChanges: (obj: any, changes: AttributeMap) => void;
62+
enqueueTask: (obj: any, task: () => ParsePromise) => ParsePromise;
6263
clearAllState: () => void;
6364
};
6465
type PushController = {
@@ -82,6 +83,7 @@ type StorageController = {
8283
getItemAsync?: (path: string) => ParsePromise;
8384
setItemAsync?: (path: string, value: string) => ParsePromise;
8485
removeItemAsync?: (path: string) => ParsePromise;
86+
clear: () => void;
8587
} | {
8688
async: 1;
8789
getItem?: (path: string) => ?string;
@@ -90,6 +92,7 @@ type StorageController = {
9092
getItemAsync: (path: string) => ParsePromise;
9193
setItemAsync: (path: string, value: string) => ParsePromise;
9294
removeItemAsync: (path: string) => ParsePromise;
95+
clear: () => void;
9396
};
9497
type UserController = {
9598
setCurrentUser: (user: ParseUser) => ParsePromise;
@@ -100,6 +103,7 @@ type UserController = {
100103
become: (options: RequestOptions) => ParsePromise;
101104
logOut: () => ParsePromise;
102105
requestPasswordReset: (email: string, options: RequestOptions) => ParsePromise;
106+
updateUserOnDisk: (user: ParseUser) => ParsePromise;
103107
upgradeToRevocableSession: (user: ParseUser, options: RequestOptions) => ParsePromise;
104108
linkWith: (user: ParseUser, authData: AuthData) => ParsePromise;
105109
};

src/ParseConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default class ParseConfig {
4848
* @method escape
4949
* @param {String} attr The name of an attribute.
5050
*/
51-
escape(attr: string) {
51+
escape(attr: string): string {
5252
var html = this._escapedAttributes[attr];
5353
if (html) {
5454
return html;

src/ParseObject.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export default class ParseObject {
179179
/**
180180
* Returns a unique identifier used to pull data from the State Controller.
181181
*/
182-
_getStateIdentifier(): string {
182+
_getStateIdentifier(): mixed {
183183
if (singleInstance) {
184184
let id = this.id;
185185
if (!id) {
@@ -254,7 +254,7 @@ export default class ParseObject {
254254
return dirty;
255255
}
256256

257-
_toFullJSON(seen): AttributeMap {
257+
_toFullJSON(seen: Array<any>): AttributeMap {
258258
var json: { [key: string]: mixed } = this.toJSON(seen);
259259
json.__type = 'Object';
260260
json.className = this.className;
@@ -398,7 +398,7 @@ export default class ParseObject {
398398
* @method toJSON
399399
* @return {Object}
400400
*/
401-
toJSON(seen): AttributeMap {
401+
toJSON(seen: Array<any>): AttributeMap {
402402
var seenEntry = this.id ? this.className + ':' + this.id : this;
403403
var seen = seen || [seenEntry];
404404
var json = {};
@@ -829,7 +829,7 @@ export default class ParseObject {
829829
* @return {} False if the data is valid. An error object otherwise.
830830
* @see Parse.Object#set
831831
*/
832-
validate(attrs: AttributeMap) {
832+
validate(attrs: AttributeMap): ParseError | boolean {
833833
if (attrs.hasOwnProperty('ACL') && !(attrs.ACL instanceof ParseACL)) {
834834
return new ParseError(
835835
ParseError.OTHER_CAUSE,
@@ -915,7 +915,7 @@ export default class ParseObject {
915915
* @return {Parse.Promise} A promise that is fulfilled when the fetch
916916
* completes.
917917
*/
918-
fetch(options: RequestOptions) {
918+
fetch(options: RequestOptions): ParsePromise {
919919
options = options || {};
920920
var fetchOptions = {};
921921
if (options.hasOwnProperty('useMasterKey')) {
@@ -979,12 +979,16 @@ export default class ParseObject {
979979
arg1: ?string | { [attr: string]: mixed },
980980
arg2: FullOptions | mixed,
981981
arg3?: FullOptions
982-
) {
982+
): ParsePromise {
983983
var attrs;
984984
var options;
985985
if (typeof arg1 === 'object' || typeof arg1 === 'undefined') {
986986
attrs = arg1;
987-
options = arg2;
987+
if (typeof arg2 === 'object') {
988+
options = arg2;
989+
} else {
990+
options = {};
991+
}
988992
} else {
989993
attrs = {};
990994
attrs[arg1] = arg2;
@@ -1049,7 +1053,7 @@ export default class ParseObject {
10491053
* @return {Parse.Promise} A promise that is fulfilled when the destroy
10501054
* completes.
10511055
*/
1052-
destroy(options: RequestOptions) {
1056+
destroy(options: RequestOptions): ParsePromise {
10531057
options = options || {};
10541058
var destroyOptions = {};
10551059
if (options.hasOwnProperty('useMasterKey')) {
@@ -1772,8 +1776,7 @@ var DefaultController = {
17721776
}
17731777

17741778
stateController.pushPendingState(target._getStateIdentifier());
1775-
let enqueueTask = stateController.enqueueTask(target._getStateIdentifier(), task);
1776-
return enqueueTask.then(() => {
1779+
return stateController.enqueueTask(target._getStateIdentifier(), task).then(() => {
17771780
return target;
17781781
}, (error) => {
17791782
return ParsePromise.error(error);

src/ParseQuery.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export default class ParseQuery {
108108
_order: Array<string>;
109109
_extraOptions: { [key: string]: mixed };
110110

111-
constructor(objectClass) {
111+
constructor(objectClass: string | ParseObject) {
112112
if (typeof objectClass === 'string') {
113113
if (objectClass === 'User' && CoreManager.get('PERFORM_USER_REWRITE')) {
114114
this.className = '_User';
@@ -215,7 +215,7 @@ export default class ParseQuery {
215215
* @return {Parse.Promise} A promise that is resolved with the result when
216216
* the query completes.
217217
*/
218-
get(objectId: string, options?: FullOptions) {
218+
get(objectId: string, options?: FullOptions): ParsePromise {
219219
this.equalTo('objectId', objectId);
220220

221221
var firstOptions = {};
@@ -398,7 +398,7 @@ export default class ParseQuery {
398398
* @return {Parse.Promise} A promise that will be fulfilled once the
399399
* iteration has completed.
400400
*/
401-
each(callback: (obj: ParseObject) => any, options?: FullOptions) {
401+
each(callback: (obj: ParseObject) => any, options?: FullOptions): ParsePromise {
402402
options = options || {};
403403

404404
if (this._order || this._skip || (this._limit >= 0)) {

src/ParseRole.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default class ParseRole extends ParseObject {
104104
return this.relation('roles');
105105
}
106106

107-
validate(attrs: AttributeMap, options?: mixed) {
107+
validate(attrs: AttributeMap, options?: mixed): ParseError | boolean {
108108
var isInvalid = super.validate(attrs, options);
109109
if (isInvalid) {
110110
return isInvalid;

src/ParseUser.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default class ParseUser extends ParseObject {
5656
* @return {Parse.Promise} A promise that is resolved when the replacement
5757
* token has been fetched.
5858
*/
59-
_upgradeToRevocableSession(options: RequestOptions) {
59+
_upgradeToRevocableSession(options: RequestOptions): ParsePromise {
6060
options = options || {};
6161

6262
var upgradeOptions = {};
@@ -358,7 +358,7 @@ export default class ParseUser extends ParseObject {
358358
* @return {Parse.Promise} A promise that is fulfilled when the signup
359359
* finishes.
360360
*/
361-
signUp(attrs: AttributeMap, options: FullOptions) {
361+
signUp(attrs: AttributeMap, options: FullOptions): ParsePromise {
362362
options = options || {};
363363

364364
var signupOptions = {};
@@ -388,7 +388,7 @@ export default class ParseUser extends ParseObject {
388388
* @return {Parse.Promise} A promise that is fulfilled with the user when
389389
* the login is complete.
390390
*/
391-
logIn(options: FullOptions) {
391+
logIn(options: FullOptions): ParsePromise {
392392
options = options || {};
393393

394394
var loginOptions = {};
@@ -404,7 +404,7 @@ export default class ParseUser extends ParseObject {
404404
* Wrap the default save behavior with functionality to save to local
405405
* storage if this is current user.
406406
*/
407-
save(...args) {
407+
save(...args: Array<any>): ParsePromise {
408408
return super.save.apply(this, args).then(() => {
409409
if (this.isCurrent()) {
410410
return CoreManager.getUserController().updateUserOnDisk(this);
@@ -417,7 +417,7 @@ export default class ParseUser extends ParseObject {
417417
* Wrap the default fetch behavior with functionality to save to local
418418
* storage if this is current user.
419419
*/
420-
fetch(...args) {
420+
fetch(...args: Array<any>): ParsePromise {
421421
return super.fetch.apply(this, args).then(() => {
422422
if (this.isCurrent()) {
423423
return CoreManager.getUserController().updateUserOnDisk(this);

src/RESTController.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type FullOptions = {
2424
error?: any;
2525
useMasterKey?: boolean;
2626
sessionToken?: string;
27-
}
27+
};
2828

2929
var XHR = null;
3030
if (typeof XMLHttpRequest !== 'undefined') {
@@ -70,7 +70,7 @@ function ajaxIE9(method: string, url: string, data: any) {
7070
return promise;
7171
}
7272

73-
var RESTController = {
73+
const RESTController = {
7474
ajax(method: string, url: string, data: any, headers?: any) {
7575
if (useXDomainRequest) {
7676
return ajaxIE9(method, url, data, headers);

src/SingleInstanceState.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
import * as ObjectStateMutations from './ObjectStateMutations';
1313

14+
import type { Op } from './ParseOp';
15+
import type ParsePromise from './ParsePromise';
16+
import type { AttributeMap, ObjectCache, OpsMap, State } from './ObjectStateMutations';
17+
1418
type ObjectIdentifier = {
1519
className: string;
1620
id: string
@@ -120,7 +124,7 @@ export function commitServerChanges(obj: ObjectIdentifier, changes: AttributeMap
120124
ObjectStateMutations.commitServerChanges(state.serverData, state.objectCache, changes);
121125
}
122126

123-
export function enqueueTask(obj: ObjectIdentifier, task: () => ParsePromise) {
127+
export function enqueueTask(obj: ObjectIdentifier, task: () => ParsePromise): ParsePromise {
124128
let state = initializeState(obj);
125129
return state.tasks.enqueue(task);
126130
}

src/Storage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var Storage = {
3636
return ParsePromise.as(controller.getItem(path));
3737
},
3838

39-
setItem(path: string, value: string) {
39+
setItem(path: string, value: string): void {
4040
var controller = CoreManager.getStorageController();
4141
if (controller.async === 1) {
4242
throw new Error(
@@ -54,7 +54,7 @@ var Storage = {
5454
return ParsePromise.as(controller.setItem(path, value));
5555
},
5656

57-
removeItem(path: string) {
57+
removeItem(path: string): void {
5858
var controller = CoreManager.getStorageController();
5959
if (controller.async === 1) {
6060
throw new Error(

0 commit comments

Comments
 (0)