Feature/parse/various (#38878)

* 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

* fix(Parse.Config): update params for functions `get` and `save`

* feat(LiveQuerySubscription): add default events

* fix(Query): function subscribe() should return a Promise

* improve(File): add missing constructor variations

* bump version to 2.3.0

* feat(Object): add function

* fix(ParseObject): remove  as return type of fetchFromLocalDatastore()

* refactor(parse/File): use union type instead of several constructors

* feat(parse/File): add function getData()

* chore(parse): bump version
This commit is contained in:
Raschid J.F. Rafeally
2019-12-06 16:37:22 -08:00
committed by Ron Buckton
co-authored by Yago Tomé
parent 3b047be851
commit bdaccfdf4b
2 changed files with 53 additions and 17 deletions
+21 -13
View File
@@ -1,4 +1,4 @@
// Type definitions for parse 2.9
// Type definitions for parse 2.10
// Project: https://parseplatform.org/
// Definitions by: Ullisen Media Group <https://github.com/ullisenmedia>
// David Poetzsch-Heffter <https://github.com/dpoetzsch>
@@ -254,10 +254,19 @@ declare namespace Parse {
* extension.
*/
class File {
constructor(name: string, data: any, type?: string);
constructor(name: string, data: number[] | { base64: string } | Blob | { uri: string }, type?: string);
/**
* Return the data for the file, downloading it if not already present.
* Data is present if initialized with Byte Array, Base64 or Saved with Uri.
* Data is cleared if saved with File object selected with a file upload control
*
* @returns Promise that is resolved with base64 data
*/
getData(): Promise<string>;
name(): string;
url(): string;
save(options?: FullOptions): Promise<File>;
save(options?: SuccessFailureOptions): Promise<File>;
toJSON(): { __type: string, name: string, url: string };
url(options?: { forceSecure: boolean }): string;
}
/**
@@ -357,12 +366,9 @@ declare namespace Parse {
static destroyAll<T extends Object>(list: T[], options?: Object.DestroyAllOptions): Promise<T[]>;
static extend(className: string | { className: string }, protoProps?: any, classProps?: any): any;
static fetchAll<T extends Object>(list: T[], options: Object.FetchAllOptions): Promise<T[]>;
static fetchAllIfNeeded<T extends Object>(list: T[], options: Object.FetchAllOptions): Promise<T[]>;
static fetchAllWithInclude<T extends Object>(
list: T[],
keys: string | Array<string | Array<string>>,
options: RequestOptions,
): Promise<T[]>;
static fetchAllIfNeeded<T extends Object>(list: T[], options?: Object.FetchAllOptions): Promise<T[]>;
static fetchAllIfNeededWithInclude<T extends Object>(list: T[], keys: string | Array<string | Array<string>>, options?: RequestOptions): Promise<T[]>;
static fetchAllWithInclude<T extends Object>(list: T[], keys: string | Array<string | Array<string>>, options?: RequestOptions): Promise<T[]>;
static fromJSON<T extends Object>(json: any, override?: boolean): T;
static pinAll(objects: Object[]): Promise<void>;
static pinAllWithName(name: string, objects: Object[]): Promise<void>;
@@ -388,7 +394,7 @@ declare namespace Parse {
escape(attr: string): string;
existed(): boolean;
fetch(options?: Object.FetchOptions): Promise<this>;
fetchFromLocalDatastore(): Promise<this> | void;
fetchFromLocalDatastore(): Promise<this>;
fetchWithInclude(keys: string | Array<string | Array<string>>, options?: RequestOptions): Promise<this>;
get<K extends Exclude<keyof T, symbol | number>>(attr: K): T[K];
getACL(): ACL | undefined;
@@ -709,6 +715,8 @@ subscription.on('close', () => {});
*/
constructor(id: string, query: string, sessionToken?: string);
on(event: 'open' | 'create' | 'update' | 'enter' | 'leave' | 'delete' | 'close', listener: (object: Object) => void): this;
/**
* Closes the subscription.
*
@@ -740,9 +748,9 @@ subscription.on('close', () => {});
}
class Config<T extends any = any> extends Object<T> {
static get(options?: SuccessFailureOptions): Promise<Config>;
static get(options?: UseMasterKeyOption): Promise<Config>;
static current(): Config;
static save(attr: any): Promise<Config>;
static save(attr: any, options?: { [attr: string]: boolean }): Promise<Config>;
get(attr: string): any;
escape(attr: string): any;
+32 -4
View File
@@ -11,7 +11,8 @@ class Game extends Parse.Object {
}
function test_config() {
Parse.Config.save({ foo: 'bar' });
Parse.Config.save({ foo: 'bar' }, { foo: true });
Parse.Config.get({ useMasterKey: true });
}
function test_object() {
@@ -170,6 +171,31 @@ async function test_query_promise() {
}
}
async function test_live_query() {
const subscription = await new Parse.Query('Test').subscribe();
subscription.on('close', (object) => {
(object instanceof Parse.Object) == true;
});
subscription.on('create', (object) => {
(object instanceof Parse.Object) == true;
});
subscription.on('delete', (object) => {
(object instanceof Parse.Object) == true;
});
subscription.on('enter', (object) => {
(object instanceof Parse.Object) == true;
});
subscription.on('leave', (object) => {
(object instanceof Parse.Object) == true;
});
subscription.on('open', (object) => {
(object instanceof Parse.Object) == true;
});
subscription.on('update', (object) => {
(object instanceof Parse.Object) == true;
});
}
function return_a_generic_query(): Parse.Query<Game> {
return new Parse.Query(Game);
}
@@ -182,10 +208,12 @@ function test_file() {
const base64 = 'V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=';
let file = new Parse.File('myfile.txt', { base64: base64 });
file = new Parse.File('nana', { uri: 'http://example.com/image.jps' });
const bytes = [0xbe, 0xef, 0xca, 0xfe];
file = new Parse.File('myfile.txt', bytes);
file = new Parse.File('myfile.zzz', {}, 'image/png');
file = new Parse.File('myfile.zzz', new Blob(), 'image/png');
const src = file.url();
@@ -699,7 +727,7 @@ function test_generic_object() {
const exampleAttrFromOptions = objWithAttrsAndOptions.attributes.example // number
const exampleGetFromOptions = objWithAttrsAndOptions.get('example') // number
// const badAttr2 = objWithAttrsAndOptions.attributes.other // error
}
function test_to_json_generic() {
@@ -771,7 +799,7 @@ function test_set_generic() {
exampleObjAny.set('propA', 'some value')
const exampleObjTyped = new Parse.Object<{ example: boolean }>('TestObject')
// Parse.Object.set({}) type checks existing keys, does not allow new keys
const setThingObj = exampleObjTyped.set({ example: false })
setThingObj && setThingObj.attributes.example // boolean