Merge pull request #24491 from owsas/master

Added aggregation and distinct functions to Parse.Query
This commit is contained in:
Nathan Shively-Sanders
2018-03-26 10:26:06 -07:00
committed by GitHub
2 changed files with 39 additions and 4 deletions
+19 -3
View File
@@ -1,10 +1,11 @@
// 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 <http://ullisenmedia.com>
// David Poetzsch-Heffter <https://github.com/dpoetzsch>
// Cedric Kemp <https://github.com/jaeggerr>
// Flavio Negrão <https://github.com/flavionegrao>
// Wes Grimes <https://github.com/wesleygrimes>
// Otherwise SAS <https://github.com/owsas>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
@@ -88,6 +89,7 @@ declare namespace Parse {
then<U>(resolvedCallback: (...values: T[]) => IPromise<U>, rejectedCallback?: (reason: any) => IPromise<U>): IPromise<U>;
then<U>(resolvedCallback: (...values: T[]) => U, rejectedCallback?: (reason: any) => IPromise<U>): IPromise<U>;
then<U>(resolvedCallback: (...values: T[]) => U, rejectedCallback?: (reason: any) => U): IPromise<U>;
catch<U>(resolvedCallback: (...values: T[]) => U, rejectedCallback?: (reason: any) => U): IPromise<U>;
}
class Promise<T> implements IPromise<T> {
@@ -109,6 +111,7 @@ declare namespace Parse {
rejectedCallback?: (reason: any) => IPromise<U>): IPromise<U>;
then<U>(resolvedCallback: (...values: T[]) => U,
rejectedCallback?: (reason: any) => U): IPromise<U>;
catch<U>(resolvedCallback: (...values: T[]) => U, rejectedCallback?: (reason: any) => U): IPromise<U>;
}
interface Pointer {
@@ -607,6 +610,7 @@ declare namespace Parse {
static or<U extends Object>(...var_args: Query<U>[]): Query<U>;
aggregate(pipeline: Query.AggregationOptions|Query.AggregationOptions[]): Query<T>;
addAscending(key: string): Query<T>;
addAscending(key: string[]): Query<T>;
addDescending(key: string): Query<T>;
@@ -623,6 +627,7 @@ declare namespace Parse {
doesNotExist(key: string): Query<T>;
doesNotMatchKeyInQuery<U extends Object>(key: string, queryKey: string, query: Query<U>): Query<T>;
doesNotMatchQuery<U extends Object>(key: string, query: Query<U>): Query<T>;
distinct(key: string): Query<T>;
each(callback: Function, options?: Query.EachOptions): Promise<void>;
endsWith(key: string, suffix: string): Query<T>;
equalTo(key: string, value: any): Query<T>;
@@ -659,6 +664,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 +1167,4 @@ declare module "parse/node" {
declare module "parse" {
import * as parse from "parse/node";
export = parse
}
}
+20 -1
View File
@@ -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 {
@@ -504,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);
}