Skip to content

Add startAfter() and endBefore() to database types #4427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 9, 2021
Merged
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
7 changes: 7 additions & 0 deletions .changeset/young-cups-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@firebase/database-types": minor
"@firebase/database": patch
"firebase": patch
---

Add `startAfter()` and `endBefore()` to the Realtime Database TypeScript definitions.
2 changes: 2 additions & 0 deletions packages/database-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type EventType =
| 'child_removed';

export interface Query {
endBefore(value: number | string | boolean | null, key?: string): Query;
endAt(value: number | string | boolean | null, key?: string): Query;
equalTo(value: number | string | boolean | null, key?: string): Query;
isEqual(other: Query | null): boolean;
Expand Down Expand Up @@ -100,6 +101,7 @@ export interface Query {
orderByValue(): Query;
ref: Reference;
startAt(value: number | string | boolean | null, key?: string): Query;
startAfter(value: number | string | boolean | null, key?: string): Query;
toJSON(): Object;
toString(): string;
}
Expand Down
76 changes: 70 additions & 6 deletions packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5942,8 +5942,8 @@ declare namespace firebase.database {
/**
* Creates a `Query` with the specified ending point.
*
* Using `startAt()`, `endAt()`, and `equalTo()` allows you to choose arbitrary
* starting and ending points for your queries.
* Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
* allows you to choose arbitrary starting and ending points for your queries.
*
* The ending point is inclusive, so children with exactly the specified value
* will be included in the query. The optional key argument can be used to
Expand All @@ -5959,6 +5959,7 @@ declare namespace firebase.database {
* @example
* ```javascript
* // Find all dinosaurs whose names come before Pterodactyl lexicographically.
* // Include Pterodactyl in the result.
* var ref = firebase.database().ref("dinosaurs");
* ref.orderByKey().endAt("pterodactyl").on("child_added", function(snapshot) {
* console.log(snapshot.key);
Expand All @@ -5977,11 +5978,43 @@ declare namespace firebase.database {
value: number | string | boolean | null,
key?: string
): firebase.database.Query;
/**
* Creates a `Query` with the specified ending point (exclusive).
*
* Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
* allows you to choose arbitrary starting and ending points for your queries.
*
* The ending point is exclusive. If only a value is provided, children
* with a value less than the specified value will be included in the query.
* If a key is specified, then children must have a value lesss than or equal
* to the specified value and a a key name less than the specified key.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

*
* @example
* ```javascript
* // Find all dinosaurs whose names come before Pterodactyl lexicographically.
* // Do not include Pterodactyl in the result.
* var ref = firebase.database().ref("dinosaurs");
* ref.orderByKey().endBefore("pterodactyl").on("child_added", function(snapshot) {
* console.log(snapshot.key);
* });
*
* @param value The value to end before. The argument
* type depends on which `orderBy*()` function was used in this query.
* Specify a value that matches the `orderBy*()` type. When used in
* combination with `orderByKey()`, the value must be a string.
* @param key The child key to end before, among the children with the
* previously specified priority. This argument is only allowed if ordering by
* child, value, or priority.
*/
endBefore(
value: number | string | boolean | null,
key?: string
): firebase.database.Query;
/**
* Creates a `Query` that includes children that match the specified value.
*
* Using `startAt()`, `endAt()`, and `equalTo()` allows us to choose arbitrary
* starting and ending points for our queries.
* Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
* allows you to choose arbitrary starting and ending points for your queries.
*
* The optional key argument can be used to further limit the range of the
* query. If it is specified, then children that have exactly the specified
Expand Down Expand Up @@ -6426,8 +6459,8 @@ declare namespace firebase.database {
/**
* Creates a `Query` with the specified starting point.
*
* Using `startAt()`, `endAt()`, and `equalTo()` allows you to choose arbitrary
* starting and ending points for your queries.
* Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
* allows you to choose arbitrary starting and ending points for your queries.
*
* The starting point is inclusive, so children with exactly the specified value
* will be included in the query. The optional key argument can be used to
Expand Down Expand Up @@ -6460,6 +6493,37 @@ declare namespace firebase.database {
value: number | string | boolean | null,
key?: string
): firebase.database.Query;
/**
* Creates a `Query` with the specified starting point (exclusive).
*
* Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
* allows you to choose arbitrary starting and ending points for your queries.
*
* The starting point is exclusive. If only a value is provided, children
* with a value greater than the specified value will be included in the query.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above; "are included"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* If a key is specified, then children must have a value greater than or equal
* to the specified value and a a key name greater than the specified key.
*
* @example
* ```javascript
* // Find all dinosaurs that are more than three meters tall.
* var ref = firebase.database().ref("dinosaurs");
* ref.orderByChild("height").startAfter(3).on("child_added", function(snapshot) {
* console.log(snapshot.key)
* });
* ```
*
* @param value The value to start after. The argument
* type depends on which `orderBy*()` function was used in this query.
* Specify a value that matches the `orderBy*()` type. When used in
* combination with `orderByKey()`, the value must be a string.
* @param key The child key to start after. This argument is only allowed
* if ordering by child, value, or priority.
*/
startAfter(
value: number | string | boolean | null,
key?: string
): firebase.database.Query;
/**
* Returns a JSON-serializable representation of this object.
*
Expand Down