diff --git a/src/Cloud.js b/src/Cloud.js index b42cbcb0d..612cf02c8 100644 --- a/src/Cloud.js +++ b/src/Cloud.js @@ -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 @@ -40,8 +42,8 @@ import ParseQuery from './ParseQuery'; export function run( name: string, data: mixed, - options: { [key: string]: mixed } -): Promise { + options: RequestOptions +): Promise { options = options || {}; if (typeof name !== 'string' || name.length === 0) { @@ -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 { const requestOptions = { useMasterKey: true }; @@ -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 { if (typeof name !== 'string' || name.length === 0) { throw new TypeError('Cloud job name must be a string.'); @@ -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 { 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); @@ -138,7 +140,7 @@ const DefaultController = { }); }, - getJobsData(options) { + getJobsData(options: RequestOptions) { const RESTController = CoreManager.getRESTController(); return RESTController.request( @@ -149,7 +151,7 @@ const DefaultController = { ); }, - startJob(name, data, options) { + startJob(name, data, options: RequestOptions) { const RESTController = CoreManager.getRESTController(); const payload = encode(data, true); diff --git a/src/CoreManager.js b/src/CoreManager.js index 055f85ef5..9a5881dcc 100644 --- a/src/CoreManager.js +++ b/src/CoreManager.js @@ -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; @@ -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; diff --git a/src/InstallationController.js b/src/InstallationController.js index f4e7628e7..a65f7d8c9 100644 --- a/src/InstallationController.js +++ b/src/InstallationController.js @@ -30,7 +30,7 @@ function generateId() { } const InstallationController = { - currentInstallationId(): Promise { + currentInstallationId(): Promise { if (typeof iidCache === 'string') { return Promise.resolve(iidCache); } diff --git a/src/LocalDatastore.js b/src/LocalDatastore.js index 0afe3c6d3..867c2251d 100644 --- a/src/LocalDatastore.js +++ b/src/LocalDatastore.js @@ -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> { const controller = CoreManager.getLocalDatastoreController(); return controller.fromPinWithName(name); }, - pinWithName(name: string, value: any): Promise { + pinWithName(name: string, value: any): Promise { const controller = CoreManager.getLocalDatastoreController(); return controller.pinWithName(name, value); }, - unPinWithName(name: string): Promise { + unPinWithName(name: string): Promise { const controller = CoreManager.getLocalDatastoreController(); return controller.unPinWithName(name); }, - _getAllContents(): Promise { + _getAllContents(): Promise { const controller = CoreManager.getLocalDatastoreController(); return controller.getAllContents(); }, // Use for testing - _getRawStorage(): Promise { + _getRawStorage(): Promise { const controller = CoreManager.getLocalDatastoreController(); return controller.getRawStorage(); }, - _clear(): Promise { + _clear(): Promise { 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): Promise { + async _handlePinAllWithName(name: string, objects: Array): Promise { const pinName = this.getPinName(name); const toPinPromises = []; const objectKeys = []; @@ -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 { if (!this.isEnabled) { return; } @@ -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; } @@ -386,9 +389,6 @@ const LocalDatastore = { } }; -LocalDatastore.isEnabled = false; -LocalDatastore.isSyncing = false; - module.exports = LocalDatastore; if (process.env.PARSE_BUILD === 'react-native') { diff --git a/src/LocalDatastoreController.react-native.js b/src/LocalDatastoreController.react-native.js index 00ef16ff9..1b348b352 100644 --- a/src/LocalDatastoreController.react-native.js +++ b/src/LocalDatastoreController.react-native.js @@ -22,7 +22,7 @@ const LocalDatastoreController = { return objects; }, - async pinWithName(name: string, value: any): Promise { + async pinWithName(name: string, value: any): Promise { try { const values = JSON.stringify(value); await RNStorage.setItemAsync(name, values); @@ -32,11 +32,11 @@ const LocalDatastoreController = { } }, - unPinWithName(name: string): Promise { + unPinWithName(name: string): Promise { return RNStorage.removeItemAsync(name); }, - async getAllContents(): Promise { + async getAllContents(): Promise { const keys = await RNStorage.getAllKeys(); const batch = []; for (let i = 0; i < keys.length; i += 1) { @@ -75,7 +75,7 @@ const LocalDatastoreController = { return storage; }, - async clear(): Promise { + async clear(): Promise { const keys = await RNStorage.getAllKeys(); const batch = []; for (let i = 0; i < keys.length; i += 1) { diff --git a/src/ParseConfig.js b/src/ParseConfig.js index 225f20344..ecb6b2428 100644 --- a/src/ParseConfig.js +++ b/src/ParseConfig.js @@ -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(() => { @@ -177,7 +177,7 @@ const DefaultController = { }); }, - save(attrs) { + save(attrs: { [key: string]: any }) { const RESTController = CoreManager.getRESTController(); const encodedAttrs = {}; for(const key in attrs){ diff --git a/src/ParseFile.js b/src/ParseFile.js index 74a34da64..04f96cae1 100644 --- a/src/ParseFile.js +++ b/src/ParseFile.js @@ -18,7 +18,8 @@ if (typeof XMLHttpRequest !== 'undefined') { } type Base64 = { base64: string }; -type FileData = Array | Base64 | File; +type Uri = { uri: string }; +type FileData = Array | Base64 | File | Uri; export type FileSource = { format: 'file'; file: File; @@ -64,8 +65,8 @@ class ParseFile { _name: string; _url: ?string; _source: FileSource; - _previousSave: ?Promise; - _data: string; + _previousSave: ?Promise; + _data: ?string; /** * @param name {String} The file's name. This will be prefixed by a unique diff --git a/src/ParseObject.js b/src/ParseObject.js index 8872cebbf..60173a7c7 100644 --- a/src/ParseObject.js +++ b/src/ParseObject.js @@ -271,7 +271,7 @@ class ParseObject { return dirty; } - _toFullJSON(seen: Array): AttributeMap { + _toFullJSON(seen?: Array): AttributeMap { const json: { [key: string]: mixed } = this.toJSON(seen); json.__type = 'Object'; json.className = this.className; @@ -1237,7 +1237,7 @@ class ParseObject { * * @return {Promise} A promise that is fulfilled when the pin completes. */ - pin(): Promise { + pin(): Promise { return ParseObject.pinAllWithName(DEFAULT_PIN, [this]); } @@ -1251,7 +1251,7 @@ class ParseObject { * * @return {Promise} A promise that is fulfilled when the unPin completes. */ - unPin(): Promise { + unPin(): Promise { return ParseObject.unPinAllWithName(DEFAULT_PIN, [this]); } @@ -1290,7 +1290,7 @@ class ParseObject { * @param {String} name Name of Pin. * @return {Promise} A promise that is fulfilled when the pin completes. */ - pinWithName(name: string): Promise { + pinWithName(name: string): Promise { return ParseObject.pinAllWithName(name, [this]); } @@ -1304,7 +1304,7 @@ class ParseObject { * @param {String} name Name of Pin. * @return {Promise} A promise that is fulfilled when the unPin completes. */ - unPinWithName(name: string): Promise { + unPinWithName(name: string): Promise { return ParseObject.unPinAllWithName(name, [this]); } @@ -1320,7 +1320,7 @@ class ParseObject { * * @return {Promise} A promise that is fulfilled when the fetch completes. */ - async fetchFromLocalDatastore(): Promise { + async fetchFromLocalDatastore(): Promise { const localDatastore = CoreManager.getLocalDatastore(); if (!localDatastore.isEnabled) { throw new Error('Parse.enableLocalDatastore() must be called first'); @@ -1559,7 +1559,7 @@ class ParseObject { *
  • batchSize: Number of objects to process per request * */ - static saveAll(list: Array, options = {}) { + static saveAll(list: Array, options: RequestOptions = {}) { const saveOptions = {}; if (options.hasOwnProperty('useMasterKey')) { saveOptions.useMasterKey = options.useMasterKey; @@ -1590,7 +1590,7 @@ class ParseObject { * @static * @return {Parse.Object} A Parse.Object reference. */ - static createWithoutData(id) { + static createWithoutData(id: string) { const obj = new this(); obj.id = id; return obj; @@ -1604,7 +1604,7 @@ class ParseObject { * @static * @return {Parse.Object} A Parse.Object reference */ - static fromJSON(json, override) { + static fromJSON(json: any, override?: boolean) { if (!json.className) { throw new Error('Cannot create an object without a className'); } @@ -1645,7 +1645,7 @@ class ParseObject { * @param {String} className The class name of the subclass * @param {Class} constructor The subclass */ - static registerSubclass(className, constructor) { + static registerSubclass(className: string, constructor: any) { if (typeof className !== 'string') { throw new TypeError('The first argument must be a valid class name.'); } @@ -1829,7 +1829,7 @@ class ParseObject { * @return {Promise} A promise that is fulfilled when the pin completes. * @static */ - static pinAll(objects: Array): Promise { + static pinAll(objects: Array): Promise { const localDatastore = CoreManager.getLocalDatastore(); if (!localDatastore.isEnabled) { return Promise.reject('Parse.enableLocalDatastore() must be called first'); @@ -1855,7 +1855,7 @@ class ParseObject { * @return {Promise} A promise that is fulfilled when the pin completes. * @static */ - static pinAllWithName(name: string, objects: Array): Promise { + static pinAllWithName(name: string, objects: Array): Promise { const localDatastore = CoreManager.getLocalDatastore(); if (!localDatastore.isEnabled) { return Promise.reject('Parse.enableLocalDatastore() must be called first'); @@ -1875,7 +1875,7 @@ class ParseObject { * @return {Promise} A promise that is fulfilled when the unPin completes. * @static */ - static unPinAll(objects: Array): Promise { + static unPinAll(objects: Array): Promise { const localDatastore = CoreManager.getLocalDatastore(); if (!localDatastore.isEnabled) { return Promise.reject('Parse.enableLocalDatastore() must be called first'); @@ -1895,7 +1895,7 @@ class ParseObject { * @return {Promise} A promise that is fulfilled when the unPin completes. * @static */ - static unPinAllWithName(name: string, objects: Array): Promise { + static unPinAllWithName(name: string, objects: Array): Promise { const localDatastore = CoreManager.getLocalDatastore(); if (!localDatastore.isEnabled) { return Promise.reject('Parse.enableLocalDatastore() must be called first'); @@ -1913,7 +1913,7 @@ class ParseObject { * @return {Promise} A promise that is fulfilled when the unPin completes. * @static */ - static unPinAllObjects(): Promise { + static unPinAllObjects(): Promise { const localDatastore = CoreManager.getLocalDatastore(); if (!localDatastore.isEnabled) { return Promise.reject('Parse.enableLocalDatastore() must be called first'); @@ -1933,7 +1933,7 @@ class ParseObject { * @return {Promise} A promise that is fulfilled when the unPin completes. * @static */ - static unPinAllObjectsWithName(name: string): Promise { + static unPinAllObjectsWithName(name: string): Promise { const localDatastore = CoreManager.getLocalDatastore(); if (!localDatastore.isEnabled) { return Promise.reject('Parse.enableLocalDatastore() must be called first'); @@ -1943,7 +1943,7 @@ class ParseObject { } const DefaultController = { - fetch(target: ParseObject | Array, forceFetch: boolean, options: RequestOptions): Promise { + fetch(target: ParseObject | Array, forceFetch: boolean, options: RequestOptions): Promise | ParseObject> { const localDatastore = CoreManager.getLocalDatastore(); if (Array.isArray(target)) { if (target.length < 1) { @@ -2045,7 +2045,7 @@ const DefaultController = { } }, - async destroy(target: ParseObject | Array, options: RequestOptions): Promise { + async destroy(target: ParseObject | Array, options: RequestOptions): Promise | ParseObject> { const batchSize = (options && options.batchSize) ? options.batchSize : DEFAULT_BATCH_SIZE; const localDatastore = CoreManager.getLocalDatastore(); diff --git a/src/ParsePolygon.js b/src/ParsePolygon.js index 4e4f4a3ce..3c3e141bc 100644 --- a/src/ParsePolygon.js +++ b/src/ParsePolygon.js @@ -30,13 +30,13 @@ import ParseGeoPoint from './ParseGeoPoint'; * @alias Parse.Polygon */ class ParsePolygon { - _coordinates: Array; + _coordinates: Array>; /** * @param {(Number[][]|Parse.GeoPoint[])} coordinates An Array of coordinate pairs */ constructor( - arg1: Array, + arg1: Array> | Array, ) { this._coordinates = ParsePolygon._validate(arg1); } @@ -47,11 +47,11 @@ class ParsePolygon { * @property coordinates * @type Array */ - get coordinates(): Array { + get coordinates(): Array> { return this._coordinates; } - set coordinates(coords: Array) { + set coordinates(coords: Array> | Array) { this._coordinates = ParsePolygon._validate(coords); } @@ -59,7 +59,7 @@ class ParsePolygon { * Returns a JSON representation of the Polygon, suitable for Parse. * @return {Object} */ - toJSON(): { __type: string; coordinates: Array;} { + toJSON(): { __type: string; coordinates: Array>;} { ParsePolygon._validate(this._coordinates); return { __type: 'Polygon', @@ -134,7 +134,7 @@ class ParsePolygon { * @param {Array} coords the list of coordinated to validate as a polygon * @throws {TypeError} */ - static _validate(coords: Array) { + static _validate(coords: Array> | Array): Array> { if (!Array.isArray(coords)) { throw new TypeError('Coordinates must be an Array'); } diff --git a/src/ParseQuery.js b/src/ParseQuery.js index 47439c511..300e1c23e 100644 --- a/src/ParseQuery.js +++ b/src/ParseQuery.js @@ -52,7 +52,7 @@ function quote(s: string) { * Extracts the class name from queries. If not all queries have the same * class name an error will be thrown. */ -function _getClassNameFromQueries(queries: Array): string { +function _getClassNameFromQueries(queries: Array): ?string { let className = null; queries.forEach((q) => { if (!className) { @@ -314,7 +314,7 @@ class ParseQuery { /** * Converts string for regular expression at the beginning */ - _regexStartWith(string: string): String { + _regexStartWith(string: string): string { return '^' + quote(string); } @@ -483,7 +483,7 @@ class ParseQuery { * @return {Promise} A promise that is resolved with the result when * the query completes. */ - get(objectId: string, options?: FullOptions): Promise { + get(objectId: string, options?: FullOptions): Promise { this.equalTo('objectId', objectId); const firstOptions = {}; @@ -523,7 +523,7 @@ class ParseQuery { * @return {Promise} A promise that is resolved with the results when * the query completes. */ - find(options?: FullOptions): Promise { + find(options?: FullOptions): Promise> { options = options || {}; const findOptions = {}; @@ -582,7 +582,7 @@ class ParseQuery { * @return {Promise} A promise that is resolved with the count when * the query completes. */ - count(options?: FullOptions): Promise { + count(options?: FullOptions): Promise { options = options || {}; const findOptions = {}; @@ -620,12 +620,12 @@ class ParseQuery { * * @return {Promise} A promise that is resolved with the query completes. */ - distinct(key: string, options?: FullOptions): Promise { + distinct(key: string, options?: FullOptions): Promise> { options = options || {}; - const distinctOptions = { - useMasterKey: true - }; + const distinctOptions = {}; + distinctOptions.useMasterKey = true; + if (options.hasOwnProperty('sessionToken')) { distinctOptions.sessionToken = options.sessionToken; } @@ -655,12 +655,12 @@ class ParseQuery { * * @return {Promise} A promise that is resolved with the query completes. */ - aggregate(pipeline: mixed, options?: FullOptions): Promise { + aggregate(pipeline: mixed, options?: FullOptions): Promise> { options = options || {}; - const aggregateOptions = { - useMasterKey: true, - }; + const aggregateOptions = {}; + aggregateOptions.useMasterKey = true; + if (options.hasOwnProperty('sessionToken')) { aggregateOptions.sessionToken = options.sessionToken; } @@ -697,7 +697,7 @@ class ParseQuery { * @return {Promise} A promise that is resolved with the object when * the query completes. */ - first(options?: FullOptions): Promise { + first(options?: FullOptions): Promise { options = options || {}; const findOptions = {}; @@ -766,7 +766,7 @@ class ParseQuery { * @return {Promise} A promise that will be fulfilled once the * iteration has completed. */ - each(callback: (obj: ParseObject) => any, options?: BatchOptions): Promise { + each(callback: (obj: ParseObject) => any, options?: BatchOptions): Promise> { options = options || {}; if (this._order || this._skip || (this._limit >= 0)) { @@ -968,11 +968,11 @@ class ParseQuery { values = [values]; } - values = values.map(function (value) { - return {"$regex": _this._regexStartWith(value)}; + const regexObject = values.map((value) => { + return { '$regex': _this._regexStartWith(value) }; }); - return this.containsAll(key, values); + return this.containsAll(key, regexObject); } /** @@ -1140,7 +1140,9 @@ class ParseQuery { throw new Error('The value being searched for must be a string.'); } - const fullOptions = { $term: value }; + const fullOptions = {}; + fullOptions.$term = value; + for (const option in options) { switch (option) { case 'language': @@ -1303,7 +1305,7 @@ class ParseQuery { * @param {Array} array of geopoints * @return {Parse.Query} Returns the query, so you can chain this call. */ - withinPolygon(key: string, points: Array): ParseQuery { + withinPolygon(key: string, points: Array>): ParseQuery { return this._addCondition(key, '$geoWithin', { '$polygon': points }); } @@ -1574,7 +1576,7 @@ class ParseQuery { * @param {String} name The name of query source. * @return {Parse.Query} Returns the query, so you can chain this call. */ - fromPinWithName(name: string): ParseQuery { + fromPinWithName(name?: string): ParseQuery { const localDatastore = CoreManager.getLocalDatastore(); if (localDatastore.checkIfEnabled()) { this._queriesLocalDatastore = true; @@ -1585,7 +1587,7 @@ class ParseQuery { } const DefaultController = { - find(className: string, params: QueryJSON, options: RequestOptions): Promise { + find(className: string, params: QueryJSON, options: RequestOptions): Promise> { const RESTController = CoreManager.getRESTController(); return RESTController.request( @@ -1596,7 +1598,7 @@ const DefaultController = { ); }, - aggregate(className: string, params: any, options: RequestOptions): Promise { + aggregate(className: string, params: any, options: RequestOptions): Promise> { const RESTController = CoreManager.getRESTController(); return RESTController.request( diff --git a/src/ParseSession.js b/src/ParseSession.js index f3cfb1b52..f06c58894 100644 --- a/src/ParseSession.js +++ b/src/ParseSession.js @@ -109,7 +109,7 @@ class ParseSession extends ParseObject { ParseObject.registerSubclass('_Session', ParseSession); const DefaultController = { - getSession(options: RequestOptions): Promise { + getSession(options: RequestOptions): Promise { const RESTController = CoreManager.getRESTController(); const session = new ParseSession(); diff --git a/src/ParseUser.js b/src/ParseUser.js index 7cea738aa..d2ecc44d4 100644 --- a/src/ParseUser.js +++ b/src/ParseUser.js @@ -58,7 +58,7 @@ class ParseUser extends ParseObject { * @return {Promise} A promise that is resolved when the replacement * token has been fetched. */ - _upgradeToRevocableSession(options: RequestOptions): Promise { + _upgradeToRevocableSession(options: RequestOptions): Promise { options = options || {}; const upgradeOptions = {}; @@ -77,7 +77,7 @@ class ParseUser extends ParseObject { * Unlike in the Android/iOS SDKs, logInWith is unnecessary, since you can * call linkWith on the user (even if it doesn't exist yet on the server). */ - _linkWith(provider: any, options: { authData?: AuthData }, saveOpts?: FullOptions): Promise { + _linkWith(provider: any, options: { authData?: AuthData }, saveOpts?: FullOptions): Promise { let authType; if (typeof provider === 'string') { authType = provider; @@ -372,7 +372,7 @@ class ParseUser extends ParseObject { * @return {Promise} A promise that is fulfilled when the signup * finishes. */ - signUp(attrs: AttributeMap, options: FullOptions): Promise { + signUp(attrs: AttributeMap, options?: FullOptions): Promise { options = options || {}; const signupOptions = {}; @@ -405,7 +405,7 @@ class ParseUser extends ParseObject { * @return {Promise} A promise that is fulfilled with the user when * the login is complete. */ - logIn(options: FullOptions): Promise { + logIn(options?: FullOptions): Promise { options = options || {}; const loginOptions = {}; @@ -424,7 +424,7 @@ class ParseUser extends ParseObject { * Wrap the default save behavior with functionality to save to local * storage if this is current user. */ - save(...args: Array): Promise { + save(...args: Array): Promise { return super.save.apply(this, args).then(() => { if (this.isCurrent()) { return CoreManager.getUserController().updateUserOnDisk(this); @@ -437,7 +437,7 @@ class ParseUser extends ParseObject { * Wrap the default destroy behavior with functionality that logs out * the current user when it is destroyed */ - destroy(...args: Array): Promise { + destroy(...args: Array): Promise { return super.destroy.apply(this, args).then(() => { if (this.isCurrent()) { return CoreManager.getUserController().removeUserFromDisk(); @@ -450,7 +450,7 @@ class ParseUser extends ParseObject { * Wrap the default fetch behavior with functionality to save to local * storage if this is current user. */ - fetch(...args: Array): Promise { + fetch(...args: Array): Promise { return super.fetch.apply(this, args).then(() => { if (this.isCurrent()) { return CoreManager.getUserController().updateUserOnDisk(this); @@ -463,7 +463,7 @@ class ParseUser extends ParseObject { * Wrap the default fetchWithInclude behavior with functionality to save to local * storage if this is current user. */ - fetchWithInclude(...args: Array): Promise { + fetchWithInclude(...args: Array): Promise { return super.fetchWithInclude.apply(this, args).then(() => { if (this.isCurrent()) { return CoreManager.getUserController().updateUserOnDisk(this); @@ -536,7 +536,7 @@ class ParseUser extends ParseObject { * @return {Promise} A Promise that is resolved with the currently * logged in Parse User */ - static currentAsync(): Promise { + static currentAsync(): Promise { if (!canUseCurrentUser) { return Promise.resolve(null); } @@ -561,7 +561,7 @@ class ParseUser extends ParseObject { * @return {Promise} A promise that is fulfilled with the user when * the signup completes. */ - static signUp(username, password, attrs, options) { + static signUp(username: string, password: string, attrs: AttributeMap, options?: FullOptions) { attrs = attrs || {}; attrs.username = username; attrs.password = password; @@ -584,7 +584,7 @@ class ParseUser extends ParseObject { * @return {Promise} A promise that is fulfilled with the user when * the login completes. */ - static logIn(username, password, options) { + static logIn(username: string, password: string, options?: FullOptions) { if (typeof username !== 'string') { return Promise.reject( new ParseError( @@ -619,7 +619,7 @@ class ParseUser extends ParseObject { * @return {Promise} A promise that is fulfilled with the user when * the login completes. */ - static become(sessionToken, options) { + static become(sessionToken: string, options?: RequestOptions) { if (!canUseCurrentUser) { throw new Error( 'It is not memory-safe to become a user in a server environment' @@ -653,7 +653,7 @@ class ParseUser extends ParseObject { return controller.hydrate(userJSON); } - static logInWith(provider, options) { + static logInWith(provider: any, options?: RequestOptions) { return ParseUser._logInWith(provider, options); } @@ -691,7 +691,7 @@ class ParseUser extends ParseObject { * @static * @returns {Promise} */ - static requestPasswordReset(email, options) { + static requestPasswordReset(email: string, options?: RequestOptions) { options = options || {}; const requestOptions = {}; @@ -733,7 +733,7 @@ class ParseUser extends ParseObject { * completed. If a replacement session token is requested, the promise * will be resolved after a new token has been fetched. */ - static enableRevocableSession(options) { + static enableRevocableSession(options?: RequestOptions) { options = options || {}; CoreManager.set('FORCE_REVOCABLE_SESSION', true); if (canUseCurrentUser) { @@ -767,7 +767,7 @@ class ParseUser extends ParseObject { canUseCurrentUser = false; } - static _registerAuthenticationProvider(provider) { + static _registerAuthenticationProvider(provider: any) { authProviders[provider.getAuthType()] = provider; // Synchronize the current user with the auth provider. ParseUser.currentAsync().then((current) => { @@ -777,7 +777,7 @@ class ParseUser extends ParseObject { }); } - static _logInWith(provider, options) { + static _logInWith(provider: any, options?: RequestOptions) { const user = new ParseUser(); return user._linkWith(provider, options); } @@ -787,7 +787,7 @@ class ParseUser extends ParseObject { currentUserCacheMatchesDisk = false; } - static _setCurrentUserCache(user) { + static _setCurrentUserCache(user: ParseUser) { currentUserCache = user; } } @@ -865,7 +865,7 @@ const DefaultController = { return current; }, - currentUserAsync(): Promise { + currentUserAsync(): Promise { if (currentUserCache) { return Promise.resolve(currentUserCache) } @@ -902,7 +902,7 @@ const DefaultController = { }); }, - signUp(user: ParseUser, attrs: AttributeMap, options: RequestOptions): Promise { + signUp(user: ParseUser, attrs: AttributeMap, options: RequestOptions): Promise { const username = (attrs && attrs.username) || user.get('username'); const password = (attrs && attrs.password) || user.get('password'); @@ -934,7 +934,7 @@ const DefaultController = { }); }, - logIn(user: ParseUser, options: RequestOptions): Promise { + logIn(user: ParseUser, options: RequestOptions): Promise { const RESTController = CoreManager.getRESTController(); const stateController = CoreManager.getObjectStateController(); const auth = { @@ -962,7 +962,7 @@ const DefaultController = { }); }, - become(options: RequestOptions): Promise { + become(options: RequestOptions): Promise { const user = new ParseUser(); const RESTController = CoreManager.getRESTController(); return RESTController.request( @@ -974,7 +974,7 @@ const DefaultController = { }); }, - hydrate(userJSON: AttributeMap) { + hydrate(userJSON: AttributeMap): Promise { const user = new ParseUser(); user._finishFetch(userJSON); user._setExisted(true); @@ -985,7 +985,7 @@ const DefaultController = { } }, - logOut(): Promise { + logOut(): Promise { return DefaultController.currentUserAsync().then((currentUser) => { const path = Storage.generatePath(CURRENT_USER_KEY); let promise = Storage.removeItemAsync(path); diff --git a/src/Storage.js b/src/Storage.js index 0f3c24eb2..9cb121c3e 100644 --- a/src/Storage.js +++ b/src/Storage.js @@ -27,7 +27,7 @@ const Storage = { return controller.getItem(path); }, - getItemAsync(path: string): Promise { + getItemAsync(path: string): Promise { const controller = CoreManager.getStorageController(); if (controller.async === 1) { return controller.getItemAsync(path); @@ -45,7 +45,7 @@ const Storage = { return controller.setItem(path, value); }, - setItemAsync(path: string, value: string): Promise { + setItemAsync(path: string, value: string): Promise { const controller = CoreManager.getStorageController(); if (controller.async === 1) { return controller.setItemAsync(path, value); @@ -63,7 +63,7 @@ const Storage = { return controller.removeItem(path); }, - removeItemAsync(path: string): Promise { + removeItemAsync(path: string): Promise { const controller = CoreManager.getStorageController(); if (controller.async === 1) { return controller.removeItemAsync(path); diff --git a/src/parseDate.js b/src/parseDate.js index 00db1d1d5..936fb602e 100644 --- a/src/parseDate.js +++ b/src/parseDate.js @@ -19,13 +19,13 @@ export default function parseDate(iso8601: string): ?Date { return null; } - const year = match[1] || 0; - const month = (match[2] || 1) - 1; - const day = match[3] || 0; - const hour = match[4] || 0; - const minute = match[5] || 0; - const second = match[6] || 0; - const milli = match[8] || 0; + const year = parseInt(match[1]) || 0; + const month = (parseInt(match[2]) || 1) - 1; + const day = parseInt(match[3]) || 0; + const hour = parseInt(match[4]) || 0; + const minute = parseInt(match[5]) || 0; + const second = parseInt(match[6]) || 0; + const milli = parseInt(match[8]) || 0; return new Date(Date.UTC(year, month, day, hour, minute, second, milli)); }