diff --git a/parse/parse.d.ts b/parse/parse.d.ts index e624b2ebcd..4035019c8d 100644 --- a/parse/parse.d.ts +++ b/parse/parse.d.ts @@ -67,29 +67,30 @@ declare namespace Parse { interface IPromise { - then(resolvedCallback: (value: T) => IPromise, rejectedCallback?: (reason: any) => IPromise): IPromise; - then(resolvedCallback: (value: T) => U, rejectedCallback?: (reason: any) => IPromise): IPromise; - then(resolvedCallback: (value: T) => U, rejectedCallback?: (reason: any) => U): IPromise; + then(resolvedCallback: (...values: T[]) => IPromise, rejectedCallback?: (reason: any) => IPromise): IPromise; + then(resolvedCallback: (...values: T[]) => U, rejectedCallback?: (reason: any) => IPromise): IPromise; + then(resolvedCallback: (...values: T[]) => U, rejectedCallback?: (reason: any) => U): IPromise; } - class Promise { + class Promise implements IPromise { static as(resolvedValue: U): Promise; - static error(error: U): Promise; + static error(error: U): Promise; static is(possiblePromise: any): Boolean; - static when(promises: Promise[]): Promise; + static when(promises: IPromise[]): Promise; + static when(...promises: IPromise[]): Promise; always(callback: Function): Promise; done(callback: Function): Promise; fail(callback: Function): Promise; reject(error: any): void; resolve(result: any): void; - then(resolvedCallback: (value: T) => Promise, - rejectedCallback?: (reason: any) => Promise): IPromise; - then(resolvedCallback: (value: T) => U, - rejectedCallback?: (reason: any) => IPromise): IPromise; - then(resolvedCallback: (value: T) => U, - rejectedCallback?: (reason: any) => U): IPromise; + then(resolvedCallback: (...values: T[]) => IPromise, + rejectedCallback?: (reason: any) => IPromise): IPromise; + then(resolvedCallback: (...values: T[]) => U, + rejectedCallback?: (reason: any) => IPromise): IPromise; + then(resolvedCallback: (...values: T[]) => U, + rejectedCallback?: (reason: any) => U): IPromise; } interface IBaseObject { @@ -306,7 +307,9 @@ declare namespace Parse { */ class Object extends BaseObject { - id: any; + id: string; + createdAt: Date; + updatedAt: Date; attributes: any; cid: string; changed: boolean; @@ -319,7 +322,9 @@ declare namespace Parse { static fetchAll(list: Object[], options: SuccessFailureOptions): Promise; static fetchAllIfNeeded(list: Object[], options: SuccessFailureOptions): Promise; static destroyAll(list: Object[], options?: Object.DestroyAllOptions): Promise; - static saveAll(list: Object[], options?: Object.SaveAllOptions): Promise; + static saveAll(list: T[], options?: Object.SaveAllOptions): Promise; + + static registerSubclass(className: string, clazz: new (options?: any) => T): void; initialize(): void; add(attr: string, item: any): Object; @@ -333,7 +338,7 @@ declare namespace Parse { dirtyKeys(): string[]; escape(attr: string): string; existed(): boolean; - fetch(options?: Object.FetchOptions): Promise; + fetch(options?: Object.FetchOptions): Promise; get(attr: string): any; getACL(): ACL; has(attr: string): boolean; @@ -345,7 +350,8 @@ declare namespace Parse { previousAttributes(): any; relation(attr: string): Relation; remove(attr: string, item: any): any; - save(options?: Object.SaveOptions, arg2?: any, arg3?: any): Promise; + save(attrs?: { [key: string]: any }, options?: Object.SaveOptions): Promise; + save(key: string, value: any, options?: Object.SaveOptions): Promise; set(key: string, value: any, options?: Object.SetOptions): boolean; setACL(acl: ACL, options?: SuccessFailureOptions): boolean; unset(attr: string, options?: any): any; @@ -587,7 +593,7 @@ declare namespace Parse { endsWith(key: string, suffix: string): Query; equalTo(key: string, value: any): Query; exists(key: string): Query; - find(options?: Query.FindOptions): Promise; + find(options?: Query.FindOptions): Promise; first(options?: Query.FirstOptions): Promise; get(objectId: string, options?: Query.GetOptions): Promise; greaterThan(key: string, value: any): Query; @@ -642,6 +648,21 @@ declare namespace Parse { setName(name: string, options?: SuccessFailureOptions): any; } + class Config extends Object { + static get(options?: SuccessFailureOptions): Promise; + static current(): Config; + + get(attr: string): any; + escape(attr: string): any; + } + + class Session extends Object { + static current(): Promise; + + getSessionToken(): string; + isCurrentSessionRevocable(): boolean; + } + /** * Routers map faux-URLs to actions, and fire events when routes are * matched. Creating a new one sets its `routes` hash, if not set statically. @@ -698,11 +719,10 @@ declare namespace Parse { static allowCustomUserClass(isAllowed: boolean): void; static become(sessionToken: string, options?: SuccessFailureOptions): Promise; static requestPasswordReset(email: string, options?: SuccessFailureOptions): Promise; + static extend(protoProps?: any, classProps?: any): any; signUp(attrs: any, options?: SuccessFailureOptions): Promise; logIn(options?: SuccessFailureOptions): Promise; - fetch(options?: SuccessFailureOptions): Promise; - save(arg1: any, arg2: any, arg3: any): Promise; authenticated(): boolean; isCurrent(): boolean; @@ -822,9 +842,9 @@ declare namespace Parse { } interface JobStatus { - error?: Function; - message?: Function; - success?: Function; + error?: (response: any) => void; + message?: (response: any) => void; + success?: (response: any) => void; } interface FunctionRequest { @@ -835,8 +855,8 @@ declare namespace Parse { } interface FunctionResponse { - success?: (response: HttpResponse) => void; - error?: (response: HttpResponse) => void; + success?: (response: any) => void; + error?: (response: any) => void; } interface Cookie { @@ -845,12 +865,18 @@ declare namespace Parse { value?: string; } - interface AfterSaveRequest extends FunctionRequest {} + interface SaveRequest extends FunctionRequest { + object: Object; + } + + interface AfterSaveRequest extends SaveRequest {} interface AfterDeleteRequest extends FunctionRequest {} interface BeforeDeleteRequest extends FunctionRequest {} interface BeforeDeleteResponse extends FunctionResponse {} - interface BeforeSaveRequest extends FunctionRequest {} - interface BeforeSaveResponse extends FunctionResponse {} + interface BeforeSaveRequest extends SaveRequest {} + interface BeforeSaveResponse extends FunctionResponse { + success?: () => void; + } function afterDelete(arg1: any, func?: (request: AfterDeleteRequest) => void): void; function afterSave(arg1: any, func?: (request: AfterSaveRequest) => void): void; @@ -911,7 +937,10 @@ declare namespace Parse { } - enum ErrorCode { + /* + * We need to inline the codes in order to make compilation work without this type definition as dependency. + */ + const enum ErrorCode { OTHER_CAUSE = -1, INTERNAL_SERVER_ERROR = 1, @@ -1043,10 +1072,10 @@ declare namespace Parse { * Call this method first to set up your authentication tokens for Parse. * You can get your keys from the Data Browser on parse.com. * @param {String} applicationId Your Parse Application ID. - * @param {String} javaScriptKey Your Parse JavaScript Key. + * @param {String} javaScriptKey (optional) Your Parse JavaScript Key (Not needed for parse-server) * @param {String} masterKey (optional) Your Parse Master Key. (Node.js only!) */ - function initialize(applicationId: string, javaScriptKey: string, masterKey?: string): void; + function initialize(applicationId: string, javaScriptKey?: string, masterKey?: string): void; }