feat(parse): add missing Parse.Cloud job functions (#38192)

* feat(parse): add Cloud job functions; SaveOptions.cascadSave; Object.revert(keys)

* Apply suggestions from code review

Co-Authored-By: Yago Tomé <yagotome@gmail.com>

* refactor(SaveOptions): move cascadeSave opt to its own interface

...in order to keep consistency with the rest of the options.

* refactor: upgrade version to 2.2.9
This commit is contained in:
Raschid J.F. Rafeally
2019-09-09 05:48:49 -07:00
committed by Mine Starks
co-authored by Yago Tomé
parent 2c1824785a
commit dc941aa63a
2 changed files with 45 additions and 3 deletions
+29 -2
View File
@@ -1,4 +1,4 @@
// Type definitions for parse 2.2.1
// Type definitions for parse 2.2.9
// Project: https://parseplatform.org/
// Definitions by: Ullisen Media Group <http://ullisenmedia.com>
// David Poetzsch-Heffter <https://github.com/dpoetzsch>
@@ -13,6 +13,7 @@
// Julien Quere <https://github.com/jlnquere>
// Yago Tomé <https://github.com/yagotome>
// Thibault MOCELLIN <https://github.com/tybi>
// Raschid JF Rafaelly <https://github.com/RaschidJFR>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
@@ -31,6 +32,11 @@ declare namespace Parse {
batchSize?: number;
}
interface CascadeSaveOption {
/** If `false`, nested objects will not be saved (default is `true`). */
cascadeSave?: boolean;
}
interface SuccessOption {
success?: Function;
}
@@ -346,6 +352,7 @@ declare namespace Parse {
remove(attr: string, item: any): this | false;
removeAll(attr: string, items: any): this | false;
revert(): void;
revert(...keys: string[]): void;
save(attrs?: { [key: string]: any } | null, options?: Object.SaveOptions): Promise<this>;
save(key: string, value: any, options?: Object.SaveOptions): Promise<this>;
save(attrs: object, options?: Object.SaveOptions): Promise<this>;
@@ -368,7 +375,7 @@ declare namespace Parse {
interface FetchOptions extends SuccessFailureOptions, ScopeOptions { }
interface SaveOptions extends SuccessFailureOptions, SilentOption, ScopeOptions, WaitOption { }
interface SaveOptions extends CascadeSaveOption, SuccessFailureOptions, SilentOption, ScopeOptions, WaitOption { }
interface SaveAllOptions extends BatchSizeOption, ScopeOptions { }
@@ -830,11 +837,31 @@ subscription.on('close', () => {});
function beforeFind(arg1: any, func?: (request: BeforeFindRequest) => Promise<Query> | Query): void;
function afterFind(arg1: any, func?: (request: AfterFindRequest) => Promise<any> | any): void;
function define(name: string, func?: (request: FunctionRequest) => Promise<any> | any): void;
/**
* Gets data for the current set of cloud jobs.
* @returns A promise that will be resolved with the result of the function.
*/
function getJobsData(): Promise<Object>;
/**
* Gets job status by Id
* @param jobStatusId The Id of Job Status.
* @returns Status of Job.
*/
function getJobStatus(jobStatusId: string): Promise<Object>;
function httpRequest(options: HTTPOptions): Promise<HttpResponse>;
function job(name: string, func?: (request: JobRequest) => Promise<void> | void): HttpResponse;
function run(name: string, data?: any, options?: RunOptions): Promise<any>;
/**
* Starts a given cloud job, which will process asynchronously.
* @param jobName The function name.
* @param data The parameters to send to the cloud function.
* @returns A promise that will be resolved with the jobStatusId of the job.
*/
function startJob(jobName: string, data: any): Promise<string>;
function useMasterKey(): void;
interface RunOptions extends SuccessFailureOptions, ScopeOptions { }
/**
+16 -1
View File
@@ -22,6 +22,13 @@ function test_object() {
const game = new Game();
game.save(null, {
useMasterKey: true,
sessionToken: 'sometoken',
cascadeSave: false,
})
.then(result => result);
if (!game.isNew()) {
console.error("Game should be new");
}
@@ -286,6 +293,8 @@ function test_user_acl_roles() {
game.save({ score: '10' }, { useMasterKey: true }).then(function (game) {
// Update game then revert it to the last saved state.
game.set("score", '20');
game.revert('score');
game.revert('score', 'ACL');
game.revert();
}, function (error) {
// The save failed
@@ -396,7 +405,7 @@ function test_cloud_functions() {
const CUSTOM_ERROR_IMMUTABLE_FIELD = 1002
Parse.Cloud.beforeSave('MyCustomClass', async (request: Parse.Cloud.BeforeSaveRequest) => {
if (request.object.isNew()) {
if (!request.object.has('immutable')) throw new Error('Field immutable is required')
} else {
@@ -452,6 +461,12 @@ function test_cloud_functions() {
Parse.Cloud.job('AJob', (request: Parse.Cloud.JobRequest) => {
request.message('Message to associate with this job run');
});
Parse.Cloud.startJob('AJob', {}).then(v => v);
Parse.Cloud.getJobStatus('AJob').then(v => v);
Parse.Cloud.getJobsData().then(v => v);
}
class PlaceObject extends Parse.Object { }