Skip to content

Commit 396ae8b

Browse files
committed
docs(search): add ts definitions for SearchQuery and SearchSortBuilder
1 parent c736eeb commit 396ae8b

File tree

2 files changed

+101
-27
lines changed

2 files changed

+101
-27
lines changed

src/search.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ module.exports = function(AV) {
156156
* //or pass an array.
157157
* query.highlights(['title', 'content'])
158158
* </code></pre>
159-
* @param {String[]} highlights a list of fields.
159+
* @param {String|String[]} highlights a list of fields.
160160
* @return {AV.SearchQuery} Returns the query, so you can chain this call.
161161
*/
162162
highlights: function(highlights) {
@@ -286,3 +286,56 @@ module.exports = function(AV) {
286286
}
287287
);
288288
};
289+
290+
/**
291+
* Sorts the results in ascending order by the given key.
292+
*
293+
* @method AV.SearchQuery#ascending
294+
* @param {String} key The key to order by.
295+
* @return {AV.SearchQuery} Returns the query, so you can chain this call.
296+
*/
297+
/**
298+
* Also sorts the results in ascending order by the given key. The previous sort keys have
299+
* precedence over this key.
300+
*
301+
* @method AV.SearchQuery#addAscending
302+
* @param {String} key The key to order by
303+
* @return {AV.SearchQuery} Returns the query so you can chain this call.
304+
*/
305+
/**
306+
* Sorts the results in descending order by the given key.
307+
*
308+
* @method AV.SearchQuery#descending
309+
* @param {String} key The key to order by.
310+
* @return {AV.SearchQuery} Returns the query, so you can chain this call.
311+
*/
312+
/**
313+
* Also sorts the results in descending order by the given key. The previous sort keys have
314+
* precedence over this key.
315+
*
316+
* @method AV.SearchQuery#addDescending
317+
* @param {String} key The key to order by
318+
* @return {AV.SearchQuery} Returns the query so you can chain this call.
319+
*/
320+
/**
321+
* Include nested AV.Objects for the provided key. You can use dot
322+
* notation to specify which fields in the included object are also fetch.
323+
* @method AV.SearchQuery#include
324+
* @param {String[]} keys The name of the key to include.
325+
* @return {AV.SearchQuery} Returns the query, so you can chain this call.
326+
*/
327+
/**
328+
* Sets the number of results to skip before returning any results.
329+
* This is useful for pagination.
330+
* Default is to skip zero results.
331+
* @method AV.SearchQuery#skip
332+
* @param {Number} n the number of results to skip.
333+
* @return {AV.SearchQuery} Returns the query, so you can chain this call.
334+
*/
335+
/**
336+
* Sets the limit of the number of results to return. The default limit is
337+
* 100, with a maximum of 1000 results being returned at a time.
338+
* @method AV.SearchQuery#limit
339+
* @param {Number} n the number of results to limit to.
340+
* @return {AV.SearchQuery} Returns the query, so you can chain this call.
341+
*/

storage.d.ts

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,26 @@ export class Events {
390390
unbind(eventName?: string, callback?: Function, context?: any): Events;
391391
}
392392

393+
declare class BaseQuery extends BaseObject {
394+
className: string;
395+
396+
constructor(objectClass: string);
397+
constructor(objectClass: Object);
398+
399+
addAscending(key: string): this;
400+
addAscending(key: string[]): this;
401+
addDescending(key: string): this;
402+
addDescending(key: string[]): this;
403+
ascending(key: string): this;
404+
ascending(key: string[]): this;
405+
include(...keys: string[]): this;
406+
include(keys: string[]): this;
407+
limit(n: number): this;
408+
skip(n: number): this;
409+
410+
find(options?: AuthOptions): Promise<Object>;
411+
}
412+
393413
/**
394414
* Creates a new AV AV.Query for the given AV.Object subclass.
395415
* @param objectClass -
@@ -446,29 +466,19 @@ export class Events {
446466
* }
447467
* });</pre></p>
448468
*/
449-
export class Query extends BaseObject {
450-
className: string;
451-
452-
constructor(objectClass: any);
453-
469+
export class Query extends BaseQuery {
454470
static or(...querys: Query[]): Query;
455471
static and(...querys: Query[]): Query;
456472
static doCloudQuery<T>(
457473
cql: string,
458474
pvalues?: any,
459-
options?: Query.FindOptions
475+
options?: AuthOptions
460476
): Promise<T>;
461477

462-
addAscending(key: string): Query;
463-
addAscending(key: string[]): Query;
464-
addDescending(key: string): Query;
465-
addDescending(key: string[]): Query;
466-
ascending(key: string): Query;
467-
ascending(key: string[]): Query;
468478
containedIn(key: string, values: any[]): Query;
469479
contains(key: string, substring: string): Query;
470480
containsAll(key: string, values: any[]): Query;
471-
count<T>(options?: Query.CountOptions): Promise<T>;
481+
count<T>(options?: AuthOptions): Promise<T>;
472482
descending(key: string): Query;
473483
descending(key: string[]): Query;
474484
doesNotExist(key: string): Query;
@@ -478,17 +488,13 @@ export class Query extends BaseObject {
478488
endsWith(key: string, suffix: string): Query;
479489
equalTo(key: string, value: any): Query;
480490
exists(key: string): Query;
481-
find<T>(options?: Query.FindOptions): Promise<T>;
482-
first<T>(options?: Query.FirstOptions): Promise<T>;
483-
get<T>(objectId: string, options?: Query.GetOptions): Promise<T>;
491+
first<T>(options?: AuthOptions): Promise<T>;
492+
get<T>(objectId: string, options?: AuthOptions): Promise<T>;
484493
greaterThan(key: string, value: any): Query;
485494
greaterThanOrEqualTo(key: string, value: any): Query;
486-
include(...keys: string[]): Query;
487-
include(keys: string[]): Query;
488495
includeACL(value?: boolean): Query;
489496
lessThan(key: string, value: any): Query;
490497
lessThanOrEqualTo(key: string, value: any): Query;
491-
limit(n: number): Query;
492498
matches(key: string, regex: RegExp, modifiers?: any): Query;
493499
matchesKeyInQuery(key: string, queryKey: string, query: Query): Query;
494500
matchesQuery(key: string, query: Query): Query;
@@ -497,7 +503,6 @@ export class Query extends BaseObject {
497503
notEqualTo(key: string, value: any): Query;
498504
select(...keys: string[]): Query;
499505
select(keys: string[]): Query;
500-
skip(n: number): Query;
501506
startsWith(key: string, prefix: string): Query;
502507
withinGeoBox(key: string, southwest: GeoPoint, northeast: GeoPoint): Query;
503508
withinKilometers(key: string, point: GeoPoint, maxDistance: number): Query;
@@ -514,14 +519,30 @@ declare class LiveQuery extends EventEmitter {
514519
unsubscribe(): Promise<void>;
515520
}
516521

517-
export namespace Query {
518-
interface CountOptions extends AuthOptions {}
519-
interface FindOptions extends AuthOptions {}
520-
interface FirstOptions extends AuthOptions {}
521-
interface GetOptions extends AuthOptions {}
522+
declare class FriendShipQuery extends Query {}
523+
524+
export class earchQuery extends BaseQuery {
525+
sid(sid: string): this;
526+
queryString(q: string): this;
527+
highlights(highlights: string[]): this;
528+
highlights(highlight: string): this;
529+
sortBy(builder: SearchSortBuilder): this;
530+
hits(): number;
531+
hasMore(): boolean;
532+
reset(): void;
522533
}
523534

524-
declare class FriendShipQuery extends Query {}
535+
export class SearchSortBuilder {
536+
constructor();
537+
ascending(key: string, mode?: string, missingKeyBehaviour?: string): this;
538+
descending(key: string, mode?: string, missingKeyBehaviour?: string): this;
539+
whereNear(
540+
key: string,
541+
point?: GeoPoint,
542+
options?: { order?: string; mode?: string; unit?: string }
543+
): this;
544+
build(): string;
545+
}
525546

526547
/**
527548
* Represents a Role on the AV server. Roles represent groupings of

0 commit comments

Comments
 (0)