Skip to content

Commit 05e8c79

Browse files
authored
Improve Flow Layout (#790)
* first pass * polygon flow * undo * test fix * remove flow-weak
1 parent c91ebd6 commit 05e8c79

14 files changed

+129
-126
lines changed

src/Cloud.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import decode from './decode';
1414
import encode from './encode';
1515
import ParseError from './ParseError';
1616
import ParseQuery from './ParseQuery';
17+
import ParseObject from './ParseObject';
18+
import type { RequestOptions } from './RESTController';
1719

1820
/**
1921
* Contains functions for calling and declaring
@@ -40,8 +42,8 @@ import ParseQuery from './ParseQuery';
4042
export function run(
4143
name: string,
4244
data: mixed,
43-
options: { [key: string]: mixed }
44-
): Promise {
45+
options: RequestOptions
46+
): Promise<mixed> {
4547
options = options || {};
4648

4749
if (typeof name !== 'string' || name.length === 0) {
@@ -66,7 +68,7 @@ export function run(
6668
* @return {Promise} A promise that will be resolved with the result
6769
* of the function.
6870
*/
69-
export function getJobsData(): Promise {
71+
export function getJobsData(): Promise<Object> {
7072
const requestOptions = {
7173
useMasterKey: true
7274
};
@@ -79,13 +81,13 @@ export function getJobsData(): Promise {
7981
* @name Parse.Cloud.startJob
8082
* @param {String} name The function name.
8183
* @param {Object} data The parameters to send to the cloud function.
82-
* @return {Promise} A promise that will be resolved with the result
83-
* of the function.
84+
* @return {Promise} A promise that will be resolved with the jobStatusId
85+
* of the job.
8486
*/
8587
export function startJob(
8688
name: string,
8789
data: mixed,
88-
): Promise {
90+
): Promise<string> {
8991

9092
if (typeof name !== 'string' || name.length === 0) {
9193
throw new TypeError('Cloud job name must be a string.');
@@ -103,13 +105,13 @@ export function startJob(
103105
* @param {String} jobStatusId The Id of Job Status.
104106
* @return {Parse.Object} Status of Job.
105107
*/
106-
export function getJobStatus(jobStatusId: string): Promise {
108+
export function getJobStatus(jobStatusId: string): Promise<ParseObject> {
107109
const query = new ParseQuery('_JobStatus');
108110
return query.get(jobStatusId, { useMasterKey: true });
109111
}
110112

111113
const DefaultController = {
112-
run(name, data, options) {
114+
run(name, data, options: RequestOptions) {
113115
const RESTController = CoreManager.getRESTController();
114116

115117
const payload = encode(data, true);
@@ -138,7 +140,7 @@ const DefaultController = {
138140
});
139141
},
140142

141-
getJobsData(options) {
143+
getJobsData(options: RequestOptions) {
142144
const RESTController = CoreManager.getRESTController();
143145

144146
return RESTController.request(
@@ -149,7 +151,7 @@ const DefaultController = {
149151
);
150152
},
151153

152-
startJob(name, data, options) {
154+
startJob(name, data, options: RequestOptions) {
153155
const RESTController = CoreManager.getRESTController();
154156

155157
const payload = encode(data, true);

src/CoreManager.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,25 @@ import type { QueryJSON } from './ParseQuery';
1818
import type ParseUser from './ParseUser';
1919
import type { AuthData } from './ParseUser';
2020
import type { PushData } from './Push';
21+
import type { RequestOptions, FullOptions } from './RESTController';
2122

22-
type RequestOptions = {
23-
useMasterKey?: boolean;
24-
sessionToken?: string;
25-
installationId?: string;
26-
};
2723
type AnalyticsController = {
2824
track: (name: string, dimensions: { [key: string]: string }) => Promise;
2925
};
3026
type CloudController = {
31-
run: (name: string, data: mixed, options: { [key: string]: mixed }) => Promise;
32-
getJobsData: (options: { [key: string]: mixed }) => Promise;
33-
startJob: (name: string, data: mixed, options: { [key: string]: mixed }) => Promise;
27+
run: (name: string, data: mixed, options: RequestOptions) => Promise;
28+
getJobsData: (options: RequestOptions) => Promise;
29+
startJob: (name: string, data: mixed, options: RequestOptions) => Promise;
3430
};
3531
type ConfigController = {
3632
current: () => Promise;
3733
get: () => Promise;
34+
save: (attrs: { [key: string]: any }) => Promise;
3835
};
3936
type FileController = {
40-
saveFile: (name: string, source: FileSource) => Promise;
41-
saveBase64: (name: string, source: FileSource) => Promise;
37+
saveFile: (name: string, source: FileSource, options: FullOptions) => Promise;
38+
saveBase64: (name: string, source: FileSource, options: FullOptions) => Promise;
39+
download: (uri: string) => Promise;
4240
};
4341
type InstallationController = {
4442
currentInstallationId: () => Promise;
@@ -75,8 +73,8 @@ type QueryController = {
7573
aggregate: (className: string, params: any, options: RequestOptions) => Promise;
7674
};
7775
type RESTController = {
78-
request: (method: string, path: string, data: mixed) => Promise;
79-
ajax: (method: string, url: string, data: any, headers?: any) => Promise;
76+
request: (method: string, path: string, data: mixed, options: RequestOptions) => Promise;
77+
ajax: (method: string, url: string, data: any, headers?: any, options: FullOptions) => Promise;
8078
};
8179
type SchemaController = {
8280
purge: (className: string) => Promise;

src/InstallationController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function generateId() {
3030
}
3131

3232
const InstallationController = {
33-
currentInstallationId(): Promise {
33+
currentInstallationId(): Promise<string> {
3434
if (typeof iidCache === 'string') {
3535
return Promise.resolve(iidCache);
3636
}

src/LocalDatastore.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,43 @@ import { DEFAULT_PIN, PIN_PREFIX, OBJECT_PREFIX } from './LocalDatastoreUtils';
3636
* @static
3737
*/
3838
const LocalDatastore = {
39-
fromPinWithName(name: string): Promise {
39+
isEnabled: false,
40+
isSyncing: false,
41+
42+
fromPinWithName(name: string): Promise<Array<Object>> {
4043
const controller = CoreManager.getLocalDatastoreController();
4144
return controller.fromPinWithName(name);
4245
},
4346

44-
pinWithName(name: string, value: any): Promise {
47+
pinWithName(name: string, value: any): Promise<void> {
4548
const controller = CoreManager.getLocalDatastoreController();
4649
return controller.pinWithName(name, value);
4750
},
4851

49-
unPinWithName(name: string): Promise {
52+
unPinWithName(name: string): Promise<void> {
5053
const controller = CoreManager.getLocalDatastoreController();
5154
return controller.unPinWithName(name);
5255
},
5356

54-
_getAllContents(): Promise {
57+
_getAllContents(): Promise<Object> {
5558
const controller = CoreManager.getLocalDatastoreController();
5659
return controller.getAllContents();
5760
},
5861

5962
// Use for testing
60-
_getRawStorage(): Promise {
63+
_getRawStorage(): Promise<Object> {
6164
const controller = CoreManager.getLocalDatastoreController();
6265
return controller.getRawStorage();
6366
},
6467

65-
_clear(): Promise {
68+
_clear(): Promise<void> {
6669
const controller = CoreManager.getLocalDatastoreController();
6770
return controller.clear();
6871
},
6972

7073
// Pin the object and children recursively
7174
// Saves the object and children key to Pin Name
72-
async _handlePinAllWithName(name: string, objects: Array<ParseObject>): Promise {
75+
async _handlePinAllWithName(name: string, objects: Array<ParseObject>): Promise<void> {
7376
const pinName = this.getPinName(name);
7477
const toPinPromises = [];
7578
const objectKeys = [];
@@ -226,7 +229,7 @@ const LocalDatastore = {
226229

227230
// Called when an object is save / fetched
228231
// Update object pin value
229-
async _updateObjectIfPinned(object: ParseObject): Promise {
232+
async _updateObjectIfPinned(object: ParseObject): Promise<void> {
230233
if (!this.isEnabled) {
231234
return;
232235
}
@@ -275,7 +278,7 @@ const LocalDatastore = {
275278
},
276279

277280
// Update pin and references of the unsaved object
278-
async _updateLocalIdForObject(localId, object: ParseObject) {
281+
async _updateLocalIdForObject(localId: string, object: ParseObject) {
279282
if (!this.isEnabled) {
280283
return;
281284
}
@@ -386,9 +389,6 @@ const LocalDatastore = {
386389
}
387390
};
388391

389-
LocalDatastore.isEnabled = false;
390-
LocalDatastore.isSyncing = false;
391-
392392
module.exports = LocalDatastore;
393393

394394
if (process.env.PARSE_BUILD === 'react-native') {

src/LocalDatastoreController.react-native.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const LocalDatastoreController = {
2222
return objects;
2323
},
2424

25-
async pinWithName(name: string, value: any): Promise {
25+
async pinWithName(name: string, value: any): Promise<void> {
2626
try {
2727
const values = JSON.stringify(value);
2828
await RNStorage.setItemAsync(name, values);
@@ -32,11 +32,11 @@ const LocalDatastoreController = {
3232
}
3333
},
3434

35-
unPinWithName(name: string): Promise {
35+
unPinWithName(name: string): Promise<void> {
3636
return RNStorage.removeItemAsync(name);
3737
},
3838

39-
async getAllContents(): Promise {
39+
async getAllContents(): Promise<Object> {
4040
const keys = await RNStorage.getAllKeys();
4141
const batch = [];
4242
for (let i = 0; i < keys.length; i += 1) {
@@ -75,7 +75,7 @@ const LocalDatastoreController = {
7575
return storage;
7676
},
7777

78-
async clear(): Promise {
78+
async clear(): Promise<void> {
7979
const keys = await RNStorage.getAllKeys();
8080
const batch = [];
8181
for (let i = 0; i < keys.length; i += 1) {

src/ParseConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ParseConfig {
8888
* @return {Promise} A promise that is resolved with a newly-created
8989
* configuration object or with the current with the update.
9090
*/
91-
static save(attrs) {
91+
static save(attrs: { [key: string]: any }) {
9292
const controller = CoreManager.getConfigController();
9393
//To avoid a mismatch with the local and the cloud config we get a new version
9494
return controller.save(attrs).then(() => {
@@ -177,7 +177,7 @@ const DefaultController = {
177177
});
178178
},
179179

180-
save(attrs) {
180+
save(attrs: { [key: string]: any }) {
181181
const RESTController = CoreManager.getRESTController();
182182
const encodedAttrs = {};
183183
for(const key in attrs){

src/ParseFile.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ if (typeof XMLHttpRequest !== 'undefined') {
1818
}
1919

2020
type Base64 = { base64: string };
21-
type FileData = Array<number> | Base64 | File;
21+
type Uri = { uri: string };
22+
type FileData = Array<number> | Base64 | File | Uri;
2223
export type FileSource = {
2324
format: 'file';
2425
file: File;
@@ -64,8 +65,8 @@ class ParseFile {
6465
_name: string;
6566
_url: ?string;
6667
_source: FileSource;
67-
_previousSave: ?Promise;
68-
_data: string;
68+
_previousSave: ?Promise<ParseFile>;
69+
_data: ?string;
6970

7071
/**
7172
* @param name {String} The file's name. This will be prefixed by a unique

0 commit comments

Comments
 (0)