Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/Cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import decode from './decode';
import encode from './encode';
import ParseError from './ParseError';
import ParseQuery from './ParseQuery';
import ParseObject from './ParseObject';
import type { RequestOptions } from './RESTController';

/**
* Contains functions for calling and declaring
Expand All @@ -40,8 +42,8 @@ import ParseQuery from './ParseQuery';
export function run(
name: string,
data: mixed,
options: { [key: string]: mixed }
): Promise {
options: RequestOptions
): Promise<mixed> {
options = options || {};

if (typeof name !== 'string' || name.length === 0) {
Expand All @@ -66,7 +68,7 @@ export function run(
* @return {Promise} A promise that will be resolved with the result
* of the function.
*/
export function getJobsData(): Promise {
export function getJobsData(): Promise<Object> {
const requestOptions = {
useMasterKey: true
};
Expand All @@ -79,13 +81,13 @@ export function getJobsData(): Promise {
* @name Parse.Cloud.startJob
* @param {String} name The function name.
* @param {Object} data The parameters to send to the cloud function.
* @return {Promise} A promise that will be resolved with the result
* of the function.
* @return {Promise} A promise that will be resolved with the jobStatusId
* of the job.
*/
export function startJob(
name: string,
data: mixed,
): Promise {
): Promise<string> {

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

const DefaultController = {
run(name, data, options) {
run(name, data, options: RequestOptions) {
const RESTController = CoreManager.getRESTController();

const payload = encode(data, true);
Expand Down Expand Up @@ -138,7 +140,7 @@ const DefaultController = {
});
},

getJobsData(options) {
getJobsData(options: RequestOptions) {
const RESTController = CoreManager.getRESTController();

return RESTController.request(
Expand All @@ -149,7 +151,7 @@ const DefaultController = {
);
},

startJob(name, data, options) {
startJob(name, data, options: RequestOptions) {
const RESTController = CoreManager.getRESTController();

const payload = encode(data, true);
Expand Down
22 changes: 10 additions & 12 deletions src/CoreManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,25 @@ import type { QueryJSON } from './ParseQuery';
import type ParseUser from './ParseUser';
import type { AuthData } from './ParseUser';
import type { PushData } from './Push';
import type { RequestOptions, FullOptions } from './RESTController';

type RequestOptions = {
useMasterKey?: boolean;
sessionToken?: string;
installationId?: string;
};
type AnalyticsController = {
track: (name: string, dimensions: { [key: string]: string }) => Promise;
};
type CloudController = {
run: (name: string, data: mixed, options: { [key: string]: mixed }) => Promise;
getJobsData: (options: { [key: string]: mixed }) => Promise;
startJob: (name: string, data: mixed, options: { [key: string]: mixed }) => Promise;
run: (name: string, data: mixed, options: RequestOptions) => Promise;
getJobsData: (options: RequestOptions) => Promise;
startJob: (name: string, data: mixed, options: RequestOptions) => Promise;
};
type ConfigController = {
current: () => Promise;
get: () => Promise;
save: (attrs: { [key: string]: any }) => Promise;
};
type FileController = {
saveFile: (name: string, source: FileSource) => Promise;
saveBase64: (name: string, source: FileSource) => Promise;
saveFile: (name: string, source: FileSource, options: FullOptions) => Promise;
saveBase64: (name: string, source: FileSource, options: FullOptions) => Promise;
download: (uri: string) => Promise;
};
type InstallationController = {
currentInstallationId: () => Promise;
Expand Down Expand Up @@ -75,8 +73,8 @@ type QueryController = {
aggregate: (className: string, params: any, options: RequestOptions) => Promise;
};
type RESTController = {
request: (method: string, path: string, data: mixed) => Promise;
ajax: (method: string, url: string, data: any, headers?: any) => Promise;
request: (method: string, path: string, data: mixed, options: RequestOptions) => Promise;
ajax: (method: string, url: string, data: any, headers?: any, options: FullOptions) => Promise;
};
type SchemaController = {
purge: (className: string) => Promise;
Expand Down
2 changes: 1 addition & 1 deletion src/InstallationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function generateId() {
}

const InstallationController = {
currentInstallationId(): Promise {
currentInstallationId(): Promise<string> {
if (typeof iidCache === 'string') {
return Promise.resolve(iidCache);
}
Expand Down
24 changes: 12 additions & 12 deletions src/LocalDatastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,43 @@ import { DEFAULT_PIN, PIN_PREFIX, OBJECT_PREFIX } from './LocalDatastoreUtils';
* @static
*/
const LocalDatastore = {
fromPinWithName(name: string): Promise {
isEnabled: false,
isSyncing: false,

fromPinWithName(name: string): Promise<Array<Object>> {
const controller = CoreManager.getLocalDatastoreController();
return controller.fromPinWithName(name);
},

pinWithName(name: string, value: any): Promise {
pinWithName(name: string, value: any): Promise<void> {
const controller = CoreManager.getLocalDatastoreController();
return controller.pinWithName(name, value);
},

unPinWithName(name: string): Promise {
unPinWithName(name: string): Promise<void> {
const controller = CoreManager.getLocalDatastoreController();
return controller.unPinWithName(name);
},

_getAllContents(): Promise {
_getAllContents(): Promise<Object> {
const controller = CoreManager.getLocalDatastoreController();
return controller.getAllContents();
},

// Use for testing
_getRawStorage(): Promise {
_getRawStorage(): Promise<Object> {
const controller = CoreManager.getLocalDatastoreController();
return controller.getRawStorage();
},

_clear(): Promise {
_clear(): Promise<void> {
const controller = CoreManager.getLocalDatastoreController();
return controller.clear();
},

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

// Called when an object is save / fetched
// Update object pin value
async _updateObjectIfPinned(object: ParseObject): Promise {
async _updateObjectIfPinned(object: ParseObject): Promise<void> {
if (!this.isEnabled) {
return;
}
Expand Down Expand Up @@ -275,7 +278,7 @@ const LocalDatastore = {
},

// Update pin and references of the unsaved object
async _updateLocalIdForObject(localId, object: ParseObject) {
async _updateLocalIdForObject(localId: string, object: ParseObject) {
if (!this.isEnabled) {
return;
}
Expand Down Expand Up @@ -386,9 +389,6 @@ const LocalDatastore = {
}
};

LocalDatastore.isEnabled = false;
LocalDatastore.isSyncing = false;

module.exports = LocalDatastore;

if (process.env.PARSE_BUILD === 'react-native') {
Expand Down
8 changes: 4 additions & 4 deletions src/LocalDatastoreController.react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const LocalDatastoreController = {
return objects;
},

async pinWithName(name: string, value: any): Promise {
async pinWithName(name: string, value: any): Promise<void> {
try {
const values = JSON.stringify(value);
await RNStorage.setItemAsync(name, values);
Expand All @@ -32,11 +32,11 @@ const LocalDatastoreController = {
}
},

unPinWithName(name: string): Promise {
unPinWithName(name: string): Promise<void> {
return RNStorage.removeItemAsync(name);
},

async getAllContents(): Promise {
async getAllContents(): Promise<Object> {
const keys = await RNStorage.getAllKeys();
const batch = [];
for (let i = 0; i < keys.length; i += 1) {
Expand Down Expand Up @@ -75,7 +75,7 @@ const LocalDatastoreController = {
return storage;
},

async clear(): Promise {
async clear(): Promise<void> {
const keys = await RNStorage.getAllKeys();
const batch = [];
for (let i = 0; i < keys.length; i += 1) {
Expand Down
4 changes: 2 additions & 2 deletions src/ParseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ParseConfig {
* @return {Promise} A promise that is resolved with a newly-created
* configuration object or with the current with the update.
*/
static save(attrs) {
static save(attrs: { [key: string]: any }) {
const controller = CoreManager.getConfigController();
//To avoid a mismatch with the local and the cloud config we get a new version
return controller.save(attrs).then(() => {
Expand Down Expand Up @@ -177,7 +177,7 @@ const DefaultController = {
});
},

save(attrs) {
save(attrs: { [key: string]: any }) {
const RESTController = CoreManager.getRESTController();
const encodedAttrs = {};
for(const key in attrs){
Expand Down
7 changes: 4 additions & 3 deletions src/ParseFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ if (typeof XMLHttpRequest !== 'undefined') {
}

type Base64 = { base64: string };
type FileData = Array<number> | Base64 | File;
type Uri = { uri: string };
type FileData = Array<number> | Base64 | File | Uri;
export type FileSource = {
format: 'file';
file: File;
Expand Down Expand Up @@ -64,8 +65,8 @@ class ParseFile {
_name: string;
_url: ?string;
_source: FileSource;
_previousSave: ?Promise;
_data: string;
_previousSave: ?Promise<ParseFile>;
_data: ?string;

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