diff --git a/types/parse/index.d.ts b/types/parse/index.d.ts index 94c142984b..94a3e41bd8 100644 --- a/types/parse/index.d.ts +++ b/types/parse/index.d.ts @@ -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 // David Poetzsch-Heffter @@ -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; name(): string; - url(): string; - save(options?: FullOptions): Promise; + save(options?: SuccessFailureOptions): Promise; + toJSON(): { __type: string, name: string, url: string }; + url(options?: { forceSecure: boolean }): string; } /** @@ -357,12 +366,9 @@ declare namespace Parse { static destroyAll(list: T[], options?: Object.DestroyAllOptions): Promise; static extend(className: string | { className: string }, protoProps?: any, classProps?: any): any; static fetchAll(list: T[], options: Object.FetchAllOptions): Promise; - static fetchAllIfNeeded(list: T[], options: Object.FetchAllOptions): Promise; - static fetchAllWithInclude( - list: T[], - keys: string | Array>, - options: RequestOptions, - ): Promise; + static fetchAllIfNeeded(list: T[], options?: Object.FetchAllOptions): Promise; + static fetchAllIfNeededWithInclude(list: T[], keys: string | Array>, options?: RequestOptions): Promise; + static fetchAllWithInclude(list: T[], keys: string | Array>, options?: RequestOptions): Promise; static fromJSON(json: any, override?: boolean): T; static pinAll(objects: Object[]): Promise; static pinAllWithName(name: string, objects: Object[]): Promise; @@ -388,7 +394,7 @@ declare namespace Parse { escape(attr: string): string; existed(): boolean; fetch(options?: Object.FetchOptions): Promise; - fetchFromLocalDatastore(): Promise | void; + fetchFromLocalDatastore(): Promise; fetchWithInclude(keys: string | Array>, options?: RequestOptions): Promise; get>(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 extends Object { - static get(options?: SuccessFailureOptions): Promise; + static get(options?: UseMasterKeyOption): Promise; static current(): Config; - static save(attr: any): Promise; + static save(attr: any, options?: { [attr: string]: boolean }): Promise; get(attr: string): any; escape(attr: string): any; diff --git a/types/parse/parse-tests.ts b/types/parse/parse-tests.ts index ee38af7e98..2dd4fade70 100644 --- a/types/parse/parse-tests.ts +++ b/types/parse/parse-tests.ts @@ -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 { 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