From 51256153206267f2a4113da390152a4c8efbc1bb Mon Sep 17 00:00:00 2001 From: Git Automerge Date: Fri, 23 Mar 2018 10:18:46 -0500 Subject: [PATCH 1/6] added aggregate and distinct to Parse --- types/parse/index.d.ts | 15 ++++++++++++++- types/parse/parse-tests.ts | 12 +++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/types/parse/index.d.ts b/types/parse/index.d.ts index 15d653a791..9a158d9287 100644 --- a/types/parse/index.d.ts +++ b/types/parse/index.d.ts @@ -607,6 +607,7 @@ declare namespace Parse { static or(...var_args: Query[]): Query; + aggregate(pipeline: Query.AggregationOptions|Query.AggregationOptions[]): Query; addAscending(key: string): Query; addAscending(key: string[]): Query; addDescending(key: string): Query; @@ -623,6 +624,7 @@ declare namespace Parse { doesNotExist(key: string): Query; doesNotMatchKeyInQuery(key: string, queryKey: string, query: Query): Query; doesNotMatchQuery(key: string, query: Query): Query; + distinct(key: string): Query; each(callback: Function, options?: Query.EachOptions): Promise; endsWith(key: string, suffix: string): Query; equalTo(key: string, value: any): Query; @@ -659,6 +661,17 @@ declare namespace Parse { interface FindOptions extends SuccessFailureOptions, ScopeOptions { } interface FirstOptions extends SuccessFailureOptions, ScopeOptions { } interface GetOptions extends SuccessFailureOptions, ScopeOptions { } + + // According to http://docs.parseplatform.org/rest/guide/#aggregate-queries + interface AggregationOptions { + group?: { objectId?: string, [key:string]: any }; + match?: {[key: string]: any}; + project?: {[key: string]: any}; + limit?: number; + skip?: number; + // Sort documentation https://docs.mongodb.com/v3.2/reference/operator/aggregation/sort/#pipe._S_sort + sort?: {[key: string]: 1|-1}; + } } /** @@ -1151,4 +1164,4 @@ declare module "parse/node" { declare module "parse" { import * as parse from "parse/node"; export = parse -} \ No newline at end of file +} diff --git a/types/parse/parse-tests.ts b/types/parse/parse-tests.ts index ceb5693087..60b688ec6e 100644 --- a/types/parse/parse-tests.ts +++ b/types/parse/parse-tests.ts @@ -134,6 +134,16 @@ function test_query() { query.include("score"); query.include(["score.team"]); + // Find objects that match the aggregation pipeline + query.aggregate({ + group:{ + objectId: '$name' + } + }); + + // Find objects with distinct key + query.distinct('name'); + const testQuery = Parse.Query.or(query, query); } @@ -396,7 +406,7 @@ function test_cloud_functions() { Parse.Cloud.beforeSave('MyCustomClass', (request: Parse.Cloud.BeforeSaveRequest, response: Parse.Cloud.BeforeSaveResponse) => { - + if (request.object.isNew()) { if (!request.object.has('immutable')) return response.error('Field immutable is required') } else { From bdc72814b1fd0c6599aa2a8c120d62e304a78348 Mon Sep 17 00:00:00 2001 From: Git Automerge Date: Fri, 23 Mar 2018 10:21:07 -0500 Subject: [PATCH 2/6] space --- types/parse/parse-tests.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/parse/parse-tests.ts b/types/parse/parse-tests.ts index 60b688ec6e..b72ae74d7f 100644 --- a/types/parse/parse-tests.ts +++ b/types/parse/parse-tests.ts @@ -406,7 +406,6 @@ function test_cloud_functions() { Parse.Cloud.beforeSave('MyCustomClass', (request: Parse.Cloud.BeforeSaveRequest, response: Parse.Cloud.BeforeSaveResponse) => { - if (request.object.isNew()) { if (!request.object.has('immutable')) return response.error('Field immutable is required') } else { From c474a09bc9e6fdc0633d31c4ffe339ff393b521c Mon Sep 17 00:00:00 2001 From: Git Automerge Date: Fri, 23 Mar 2018 10:21:38 -0500 Subject: [PATCH 3/6] back to normal --- types/parse/parse-tests.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/parse/parse-tests.ts b/types/parse/parse-tests.ts index b72ae74d7f..60b688ec6e 100644 --- a/types/parse/parse-tests.ts +++ b/types/parse/parse-tests.ts @@ -406,6 +406,7 @@ function test_cloud_functions() { Parse.Cloud.beforeSave('MyCustomClass', (request: Parse.Cloud.BeforeSaveRequest, response: Parse.Cloud.BeforeSaveResponse) => { + if (request.object.isNew()) { if (!request.object.has('immutable')) return response.error('Field immutable is required') } else { From ae78157df74dc4367b9eb741c10e8c443a3d98af Mon Sep 17 00:00:00 2001 From: Git Automerge Date: Fri, 23 Mar 2018 10:29:32 -0500 Subject: [PATCH 4/6] added right api version number and changed project link --- types/parse/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/parse/index.d.ts b/types/parse/index.d.ts index 9a158d9287..d454f1a4d2 100644 --- a/types/parse/index.d.ts +++ b/types/parse/index.d.ts @@ -1,5 +1,5 @@ -// Type definitions for parse 2.4 -// Project: https://parse.com/ +// Type definitions for parse 1.11.1 +// Project: https://parseplatform.org/ // Definitions by: Ullisen Media Group // David Poetzsch-Heffter // Cedric Kemp From 7fa71c0fb6382d94163c04c4d04c12b6b76cc5de Mon Sep 17 00:00:00 2001 From: Git Automerge Date: Fri, 23 Mar 2018 10:39:09 -0500 Subject: [PATCH 5/6] added new definitions contributor --- types/parse/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/parse/index.d.ts b/types/parse/index.d.ts index d454f1a4d2..9f63ed97fb 100644 --- a/types/parse/index.d.ts +++ b/types/parse/index.d.ts @@ -5,6 +5,7 @@ // Cedric Kemp // Flavio Negrão // Wes Grimes +// Otherwise SAS // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 From 6f6324a0ab089f94b8cf0fe2ac07ff8d4786798f Mon Sep 17 00:00:00 2001 From: Git Automerge Date: Fri, 23 Mar 2018 14:59:24 -0500 Subject: [PATCH 6/6] added Parse.Promise catch function --- types/parse/index.d.ts | 2 ++ types/parse/parse-tests.ts | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/types/parse/index.d.ts b/types/parse/index.d.ts index 9f63ed97fb..908281f84d 100644 --- a/types/parse/index.d.ts +++ b/types/parse/index.d.ts @@ -89,6 +89,7 @@ declare namespace Parse { 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; + catch(resolvedCallback: (...values: T[]) => U, rejectedCallback?: (reason: any) => U): IPromise; } class Promise implements IPromise { @@ -110,6 +111,7 @@ declare namespace Parse { rejectedCallback?: (reason: any) => IPromise): IPromise; then(resolvedCallback: (...values: T[]) => U, rejectedCallback?: (reason: any) => U): IPromise; + catch(resolvedCallback: (...values: T[]) => U, rejectedCallback?: (reason: any) => U): IPromise; } interface Pointer { diff --git a/types/parse/parse-tests.ts b/types/parse/parse-tests.ts index 60b688ec6e..acb194ed6a 100644 --- a/types/parse/parse-tests.ts +++ b/types/parse/parse-tests.ts @@ -514,6 +514,15 @@ function test_promise() { // failed }); + // Test promise with a query + const query = new Parse.Query('Test'); + query.find() + .then(() => { + // success + }).catch(() => { + // error + }); + // can check whether an object is a Parse.Promise object or not Parse.Promise.is(resolved); }