Skip to content

Commit 05614aa

Browse files
Add startAfter() and endBefore() to database types (#4427)
1 parent 3956203 commit 05614aa

File tree

3 files changed

+79
-6
lines changed

3 files changed

+79
-6
lines changed

.changeset/young-cups-drum.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@firebase/database-types": minor
3+
"@firebase/database": patch
4+
"firebase": patch
5+
---
6+
7+
Add `startAfter()` and `endBefore()` to the Realtime Database TypeScript definitions.

packages/database-types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type EventType =
7171
| 'child_removed';
7272

7373
export interface Query {
74+
endBefore(value: number | string | boolean | null, key?: string): Query;
7475
endAt(value: number | string | boolean | null, key?: string): Query;
7576
equalTo(value: number | string | boolean | null, key?: string): Query;
7677
isEqual(other: Query | null): boolean;
@@ -100,6 +101,7 @@ export interface Query {
100101
orderByValue(): Query;
101102
ref: Reference;
102103
startAt(value: number | string | boolean | null, key?: string): Query;
104+
startAfter(value: number | string | boolean | null, key?: string): Query;
103105
toJSON(): Object;
104106
toString(): string;
105107
}

packages/firebase/index.d.ts

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5942,8 +5942,8 @@ declare namespace firebase.database {
59425942
/**
59435943
* Creates a `Query` with the specified ending point.
59445944
*
5945-
* Using `startAt()`, `endAt()`, and `equalTo()` allows you to choose arbitrary
5946-
* starting and ending points for your queries.
5945+
* Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
5946+
* allows you to choose arbitrary starting and ending points for your queries.
59475947
*
59485948
* The ending point is inclusive, so children with exactly the specified value
59495949
* will be included in the query. The optional key argument can be used to
@@ -5959,6 +5959,7 @@ declare namespace firebase.database {
59595959
* @example
59605960
* ```javascript
59615961
* // Find all dinosaurs whose names come before Pterodactyl lexicographically.
5962+
* // Include Pterodactyl in the result.
59625963
* var ref = firebase.database().ref("dinosaurs");
59635964
* ref.orderByKey().endAt("pterodactyl").on("child_added", function(snapshot) {
59645965
* console.log(snapshot.key);
@@ -5977,11 +5978,43 @@ declare namespace firebase.database {
59775978
value: number | string | boolean | null,
59785979
key?: string
59795980
): firebase.database.Query;
5981+
/**
5982+
* Creates a `Query` with the specified ending point (exclusive).
5983+
*
5984+
* Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
5985+
* allows you to choose arbitrary starting and ending points for your queries.
5986+
*
5987+
* The ending point is exclusive. If only a value is provided, children
5988+
* with a value less than the specified value will be included in the query.
5989+
* If a key is specified, then children must have a value lesss than or equal
5990+
* to the specified value and a a key name less than the specified key.
5991+
*
5992+
* @example
5993+
* ```javascript
5994+
* // Find all dinosaurs whose names come before Pterodactyl lexicographically.
5995+
* // Do not include Pterodactyl in the result.
5996+
* var ref = firebase.database().ref("dinosaurs");
5997+
* ref.orderByKey().endBefore("pterodactyl").on("child_added", function(snapshot) {
5998+
* console.log(snapshot.key);
5999+
* });
6000+
*
6001+
* @param value The value to end before. The argument
6002+
* type depends on which `orderBy*()` function was used in this query.
6003+
* Specify a value that matches the `orderBy*()` type. When used in
6004+
* combination with `orderByKey()`, the value must be a string.
6005+
* @param key The child key to end before, among the children with the
6006+
* previously specified priority. This argument is only allowed if ordering by
6007+
* child, value, or priority.
6008+
*/
6009+
endBefore(
6010+
value: number | string | boolean | null,
6011+
key?: string
6012+
): firebase.database.Query;
59806013
/**
59816014
* Creates a `Query` that includes children that match the specified value.
59826015
*
5983-
* Using `startAt()`, `endAt()`, and `equalTo()` allows us to choose arbitrary
5984-
* starting and ending points for our queries.
6016+
* Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
6017+
* allows you to choose arbitrary starting and ending points for your queries.
59856018
*
59866019
* The optional key argument can be used to further limit the range of the
59876020
* query. If it is specified, then children that have exactly the specified
@@ -6426,8 +6459,8 @@ declare namespace firebase.database {
64266459
/**
64276460
* Creates a `Query` with the specified starting point.
64286461
*
6429-
* Using `startAt()`, `endAt()`, and `equalTo()` allows you to choose arbitrary
6430-
* starting and ending points for your queries.
6462+
* Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
6463+
* allows you to choose arbitrary starting and ending points for your queries.
64316464
*
64326465
* The starting point is inclusive, so children with exactly the specified value
64336466
* will be included in the query. The optional key argument can be used to
@@ -6460,6 +6493,37 @@ declare namespace firebase.database {
64606493
value: number | string | boolean | null,
64616494
key?: string
64626495
): firebase.database.Query;
6496+
/**
6497+
* Creates a `Query` with the specified starting point (exclusive).
6498+
*
6499+
* Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
6500+
* allows you to choose arbitrary starting and ending points for your queries.
6501+
*
6502+
* The starting point is exclusive. If only a value is provided, children
6503+
* with a value greater than the specified value will be included in the query.
6504+
* If a key is specified, then children must have a value greater than or equal
6505+
* to the specified value and a a key name greater than the specified key.
6506+
*
6507+
* @example
6508+
* ```javascript
6509+
* // Find all dinosaurs that are more than three meters tall.
6510+
* var ref = firebase.database().ref("dinosaurs");
6511+
* ref.orderByChild("height").startAfter(3).on("child_added", function(snapshot) {
6512+
* console.log(snapshot.key)
6513+
* });
6514+
* ```
6515+
*
6516+
* @param value The value to start after. The argument
6517+
* type depends on which `orderBy*()` function was used in this query.
6518+
* Specify a value that matches the `orderBy*()` type. When used in
6519+
* combination with `orderByKey()`, the value must be a string.
6520+
* @param key The child key to start after. This argument is only allowed
6521+
* if ordering by child, value, or priority.
6522+
*/
6523+
startAfter(
6524+
value: number | string | boolean | null,
6525+
key?: string
6526+
): firebase.database.Query;
64636527
/**
64646528
* Returns a JSON-serializable representation of this object.
64656529
*

0 commit comments

Comments
 (0)