Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/ParseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1592,12 +1592,13 @@ class ParseQuery<T extends ParseObject = ParseObject> {

/**
* Method to sort the full text search by text score
* `$score` is a special key used only for full text search ranking.
*
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
sortByTextScore() {
this.ascending('$score');
this.select(['$score'] as any);
this.select(['$score']);
return this;
}

Expand Down Expand Up @@ -1794,12 +1795,12 @@ class ParseQuery<T extends ParseObject = ParseObject> {

/**
* Sorts the results in ascending order by the given key.
*
* `$score` is a special key used only for full text search ranking.
* @param {(string|string[])} keys The key to order by, which is a
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
ascending(...keys: string[]): this {
ascending<K extends keyof T['attributes'] | keyof BaseAttributes | '$score'>(...keys: (K | K[])[]): this {
this._order = [];
return this.addAscending.apply(this, keys);
}
Expand All @@ -1812,7 +1813,7 @@ class ParseQuery<T extends ParseObject = ParseObject> {
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
addAscending(...keys: string[]): this {
addAscending<K extends keyof T['attributes'] | keyof BaseAttributes | '$score'>(...keys: (K | K[])[]): this {
if (!this._order) {
this._order = [];
}
Expand All @@ -1833,7 +1834,7 @@ class ParseQuery<T extends ParseObject = ParseObject> {
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
descending(...keys: string[]): this {
descending<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K|K[])[]): this {
this._order = [];
return this.addDescending.apply(this, keys);
}
Expand All @@ -1846,7 +1847,7 @@ class ParseQuery<T extends ParseObject = ParseObject> {
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
addDescending(...keys: string[]): this {
addDescending<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this {
if (!this._order) {
this._order = [];
}
Expand Down Expand Up @@ -1958,10 +1959,12 @@ class ParseQuery<T extends ParseObject = ParseObject> {
* longer configured is not included. To return all auth data regardless of
* the provider configuration, do not select `authData`.
*
* `$score` is a special key used only for full text search ranking.
*
* @param {...string|Array<string>} keys The name(s) of the key(s) to include.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
select<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this {
select<K extends keyof T['attributes'] | keyof BaseAttributes | '$score'>(...keys: (K | K[])[]): this {
if (!this._select) {
this._select = [];
}
Expand Down
15 changes: 9 additions & 6 deletions types/ParseQuery.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
fullText<K extends keyof T['attributes'] | keyof BaseAttributes>(key: K, value: string, options?: FullTextOptions): this;
/**
* Method to sort the full text search by text score
* `$score` is a special key used only for full text search ranking.
*
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
Expand Down Expand Up @@ -751,12 +752,12 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
polygonContains<K extends keyof T['attributes'] | keyof BaseAttributes>(key: K, point: ParseGeoPoint): this;
/**
* Sorts the results in ascending order by the given key.
*
* `$score` is a special key used only for full text search ranking.
* @param {(string|string[])} keys The key to order by, which is a
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
ascending(...keys: string[]): this;
ascending<K extends keyof T['attributes'] | keyof BaseAttributes | '$score'>(...keys: (K | K[])[]): this;
/**
* Sorts the results in ascending order by the given key,
* but can also add secondary sort descriptors without overwriting _order.
Expand All @@ -765,15 +766,15 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
addAscending(...keys: string[]): this;
addAscending<K extends keyof T['attributes'] | keyof BaseAttributes | '$score'>(...keys: (K | K[])[]): this;
/**
* Sorts the results in descending order by the given key.
*
* @param {(string|string[])} keys The key to order by, which is a
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
descending(...keys: string[]): this;
descending<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this;
/**
* Sorts the results in descending order by the given key,
* but can also add secondary sort descriptors without overwriting _order.
Expand All @@ -782,7 +783,7 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
* string of comma separated values, or an Array of keys, or multiple keys.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
addDescending(...keys: string[]): this;
addDescending<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this;
/**
* Sets the number of results to skip before returning any results.
* This is useful for pagination.
Expand Down Expand Up @@ -839,10 +840,12 @@ declare class ParseQuery<T extends ParseObject = ParseObject> {
* longer configured is not included. To return all auth data regardless of
* the provider configuration, do not select `authData`.
*
* `$score` is a special key used only for full text search ranking.
*
* @param {...string|Array<string>} keys The name(s) of the key(s) to include.
* @returns {Parse.Query} Returns the query, so you can chain this call.
*/
select<K extends keyof T['attributes'] | keyof BaseAttributes>(...keys: (K | K[])[]): this;
select<K extends keyof T['attributes'] | keyof BaseAttributes | '$score'>(...keys: (K | K[])[]): this;
/**
* Restricts the fields of the returned Parse.Objects to all keys except the
* provided keys. Exclude takes precedence over select and include.
Expand Down
30 changes: 28 additions & 2 deletions types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1895,22 +1895,40 @@ function testQuery() {

// $ExpectType ParseQuery<MySubClass>
query.addAscending(['attribute1', 'attribute2', 'updatedAt']);

// $ExpectType ParseQuery<MySubClass>
query.addAscending('attribute1', 'attribute2', 'updatedAt');

// $ExpectError
query.addAscending(['attribute1', 'unexistenProp']);
// $ExpectType ParseQuery<MySubClass>
query.addAscending('createdAt');
// $ExpectType ParseQuery<MySubClass>
query.addAscending('updatedAt');
// $ExpectType ParseQuery<MySubClass>
query.addAscending('objectId');

// $ExpectType ParseQuery<MySubClass>
query.addDescending(['attribute1', 'attribute2', 'createdAt']);
// $ExpectError
query.addDescending(['attribute1', 'unexistenProp']);
// $ExpectType ParseQuery<MySubClass>
query.addDescending('createdAt');
// $ExpectType ParseQuery<MySubClass>
query.addDescending('updatedAt');
// $ExpectType ParseQuery<MySubClass>
query.addDescending('objectId');

// $ExpectType ParseQuery<MySubClass>
query.ascending(['attribute1', 'attribute2', 'objectId']);
// $ExpectError
query.ascending(['attribute1', 'nonexistentProp']);
// $ExpectType ParseQuery<MySubClass>
query.ascending('createdAt');
// $ExpectType ParseQuery<MySubClass>
query.ascending('updatedAt');
// $ExpectType ParseQuery<MySubClass>
query.ascending('objectId');
// $ExpectType ParseQuery<MySubClass> ($score only used for full text queries)
query.ascending('$score');

// $ExpectType ParseQuery<MySubClass>
query.containedBy('attribute1', ['a', 'b', 'c']);
Expand Down Expand Up @@ -1953,6 +1971,12 @@ function testQuery() {
query.descending(['attribute1', 'attribute2', 'objectId']);
// $ExpectError
query.descending(['attribute1', 'nonexistentProp']);
// $ExpectType ParseQuery<MySubClass>
query.descending('createdAt');
// $ExpectType ParseQuery<MySubClass>
query.descending('updatedAt');
// $ExpectType ParseQuery<MySubClass>
query.descending('objectId');

// $ExpectType ParseQuery<MySubClass>
query.doesNotExist('attribute1');
Expand Down Expand Up @@ -2134,6 +2158,8 @@ function testQuery() {
query.select('attribute1', 'attribute2');
// $ExpectType ParseQuery<MySubClass>
query.select(['attribute1', 'attribute2']);
// $ExpectType ParseQuery<MySubClass> ($score; only used for full text search ranking)
query.select('$score');
// $ExpectError
query.select('attribute1', 'nonexistentProp');

Expand Down
Loading