-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
fix(firestore): type definitions #8378
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import FirestoreFieldPath from '../FirestoreFieldPath'; | ||
|
||
export const FieldPath = FirestoreFieldPath; | ||
|
||
export function documentId() { | ||
return FieldPath.documentId(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,11 +100,11 @@ export type QueryNonFilterConstraint = | |
* @throws if any of the provided query constraints cannot be combined with the | ||
* existing or new constraints. | ||
*/ | ||
export function query<T>( | ||
query: Query<T>, | ||
export declare function query<AppModelType, DbModelType extends DocumentData>( | ||
query: Query<AppModelType, DbModelType>, | ||
compositeFilter: QueryCompositeFilterConstraint, | ||
...queryConstraints: QueryNonFilterConstraint[] | ||
): Query<T>; | ||
): Query<AppModelType, DbModelType>; | ||
|
||
/** | ||
* Creates a new immutable instance of {@link Query} that is extended to also | ||
|
@@ -116,7 +116,10 @@ export function query<T>( | |
* @throws if any of the provided query constraints cannot be combined with the | ||
* existing or new constraints. | ||
*/ | ||
export function query<T>(query: Query<T>, ...queryConstraints: IQueryConstraint[]): Query<T>; | ||
export declare function query<AppModelType, DbModelType extends DocumentData>( | ||
query: Query<AppModelType, DbModelType>, | ||
...queryConstraints: QueryConstraint[] | ||
): Query<AppModelType, DbModelType>; | ||
|
||
export function query<T>( | ||
query: Query<T>, | ||
|
@@ -173,7 +176,7 @@ export type OrderByDirection = 'desc' | 'asc'; | |
*/ | ||
export function orderBy( | ||
fieldPath: string | FieldPath, | ||
directionStr: OrderByDirection = 'asc', | ||
directionStr?: OrderByDirection, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep this as it was before, no harm in the additional default information I think |
||
): QueryOrderByConstraint; | ||
|
||
/** | ||
|
@@ -285,7 +288,9 @@ export declare function getDocFromServer<T>( | |
* | ||
* @returns A `Promise` that will be resolved with the results of the query. | ||
*/ | ||
export function getDocs<T>(query: Query<T>): Promise<QuerySnapshot<T>>; | ||
export declare function getDocs<AppModelType, DbModelType extends DocumentData>( | ||
query: Query<AppModelType, DbModelType>, | ||
): Promise<QuerySnapshot<AppModelType, DbModelType>>; | ||
|
||
/** | ||
* Executes the query and returns the results as a `QuerySnapshot` from cache. | ||
|
@@ -294,15 +299,19 @@ export function getDocs<T>(query: Query<T>): Promise<QuerySnapshot<T>>; | |
* | ||
* @returns A `Promise` that will be resolved with the results of the query. | ||
*/ | ||
export function getDocsFromCache<T>(query: Query<T>): Promise<QuerySnapshot<T>>; | ||
export declare function getDocsFromCache<AppModelType, DbModelType extends DocumentData>( | ||
query: Query<AppModelType, DbModelType>, | ||
): Promise<QuerySnapshot<AppModelType, DbModelType>>; | ||
|
||
/** | ||
* Executes the query and returns the results as a `QuerySnapshot` from the | ||
* server. Returns an error if the network is not available. | ||
* | ||
* @returns A `Promise` that will be resolved with the results of the query. | ||
*/ | ||
export function getDocsFromServer<T>(query: Query<T>): Promise<QuerySnapshot<T>>; | ||
export declare function getDocsFromServer<AppModelType, DbModelType extends DocumentData>( | ||
query: Query<AppModelType, DbModelType>, | ||
): Promise<QuerySnapshot<AppModelType, DbModelType>>; | ||
|
||
/** | ||
* Deletes the document referred to by the specified `DocumentReference`. | ||
|
@@ -311,53 +320,25 @@ export function getDocsFromServer<T>(query: Query<T>): Promise<QuerySnapshot<T>> | |
* @returns A Promise resolved once the document has been successfully | ||
* deleted from the backend (note that it won't resolve while you're offline). | ||
*/ | ||
export function deleteDoc(reference: DocumentReference<unknown>): Promise<void>; | ||
export declare function deleteDoc<AppModelType, DbModelType extends DocumentData>( | ||
reference: DocumentReference<AppModelType, DbModelType>, | ||
): Promise<void>; | ||
|
||
/** | ||
* Creates a `QueryConstraint` with the specified ending point. | ||
* | ||
* 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 | ||
* further limit the range of the query. If it is specified, then children that | ||
* have exactly the specified value must also have a key name less than or equal | ||
* to the specified key. | ||
* Creates a QueryEndAtConstraint that modifies the result set to end at the provided fields relative to the order of the query. | ||
* The order of the field values must match the order of the order by clauses of the query. | ||
* | ||
* You can read more about `endAt()` in | ||
* {@link https://firebase.google.com/docs/database/web/lists-of-data#filtering_data | Filtering data}. | ||
* | ||
* @param value - The value to end at. 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 at, among the children with the previously | ||
* specified priority. This argument is only allowed if ordering by child, | ||
* value, or priority. | ||
* @param fieldValues | ||
*/ | ||
export function endAt(value: number | string | boolean | null, key?: string): QueryConstraint; | ||
export declare function endAt(...fieldValues: unknown[]): QueryEndAtConstraint; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also need to add the other way of calling endAt:
|
||
|
||
/** | ||
* Creates a `QueryConstraint` 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 less than or equal | ||
* to the specified value and a key name less than the specified key. | ||
* Creates a QueryEndAtConstraint that modifies the result set to end before the provided fields relative to the order of the query. | ||
* The order of the field values must match the order of the order by clauses of the query. | ||
* | ||
* @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. | ||
* @param fieldValues | ||
*/ | ||
export function endBefore(value: number | string | boolean | null, key?: string): QueryConstraint; | ||
export declare function endBefore(...fieldValues: unknown[]): QueryEndAtConstraint; | ||
|
||
/** | ||
* Creates a new `QueryConstraint` that is limited to return only the last | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,27 +130,25 @@ export function startAfter(...docOrFields) { | |
} | ||
|
||
/** | ||
* @param {number | string | boolean | null} value | ||
* @param {string?} key | ||
* @returns {QueryConstraint} | ||
* Creates a QueryEndAtConstraint that modifies the result set to end at the provided fields relative to the order of the query. | ||
* The order of the field values must match the order of the order by clauses of the query. | ||
* | ||
* @param {*} fieldValues | ||
*/ | ||
export function endAt(value, key) { | ||
if (!key) { | ||
return new QueryConstraint('endAt', value); | ||
} | ||
return new QueryConstraint('endAt', value, key); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export function endAt(fieldValues) { | ||
throw new Error('endAt is not implemented'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be revised to match the firebase-js-sdk: I think it should literally be: endAt(...fieldValues) {
return new QueryConstraint('endAt', ...fieldValues);
} |
||
|
||
/** | ||
* @param {number | string | boolean | null} value | ||
* @param {string?} key | ||
* @returns {QueryConstraint} | ||
* Creates a QueryEndAtConstraint that modifies the result set to end before the provided fields relative to the order of the query. | ||
* The order of the field values must match the order of the order by clauses of the query. | ||
* | ||
* @param {*} fieldValues | ||
*/ | ||
export function endBefore(value, key) { | ||
if (!key) { | ||
return new QueryConstraint('endBefore', value); | ||
} | ||
return new QueryConstraint('endBefore', value, key); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export function endBefore(fieldValues) { | ||
throw new Error('endBefore is not implemented'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just double checking, @mikehardy, in the firebase-js-sdk documentation, it returns a Promise<Query | null>. But we currently return a
Query
. Should we match the firebase-js-sdk in this instance? (I assume yes!).