Skip to content

Commit fe4fdea

Browse files
New Query API
1 parent b07f822 commit fe4fdea

38 files changed

+2596
-1992
lines changed

packages/firestore/exp/index.d.ts

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -273,28 +273,50 @@ export type WhereFilterOp =
273273
export class Query<T = DocumentData> {
274274
protected constructor();
275275
readonly firestore: FirebaseFirestore;
276-
where(
277-
fieldPath: string | FieldPath,
278-
opStr: WhereFilterOp,
279-
value: any
280-
): Query<T>;
281-
orderBy(
282-
fieldPath: string | FieldPath,
283-
directionStr?: OrderByDirection
284-
): Query<T>;
285-
limit(limit: number): Query<T>;
286-
limitToLast(limit: number): Query<T>;
287-
startAt(snapshot: DocumentSnapshot<any>): Query<T>;
288-
startAt(...fieldValues: any[]): Query<T>;
289-
startAfter(snapshot: DocumentSnapshot<any>): Query<T>;
290-
startAfter(...fieldValues: any[]): Query<T>;
291-
endBefore(snapshot: DocumentSnapshot<any>): Query<T>;
292-
endBefore(...fieldValues: any[]): Query<T>;
293-
endAt(snapshot: DocumentSnapshot<any>): Query<T>;
294-
endAt(...fieldValues: any[]): Query<T>;
276+
295277
withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
296278
}
297279

280+
export type QueryConstraintType =
281+
| 'where'
282+
| 'orderBy'
283+
| 'limit'
284+
| 'limitToLast'
285+
| 'startAt'
286+
| 'startAfter'
287+
| 'endAt'
288+
| 'endBefore';
289+
290+
export class QueryConstraint {
291+
private constructor();
292+
readonly type: QueryConstraintType;
293+
}
294+
295+
export function query<T>(
296+
query: CollectionReference<T> | Query<T>,
297+
...constraints: QueryConstraint[]
298+
): Query<T>;
299+
300+
export function where(
301+
fieldPath: string | FieldPath,
302+
opStr: WhereFilterOp,
303+
value: any
304+
): QueryConstraint;
305+
export function orderBy(
306+
fieldPath: string | FieldPath,
307+
directionStr?: OrderByDirection
308+
): QueryConstraint;
309+
export function limit(limit: number): QueryConstraint;
310+
export function limitToLast(limit: number): QueryConstraint;
311+
export function startAt(snapshot: DocumentSnapshot<any>): QueryConstraint;
312+
export function startAt(...fieldValues: any[]): QueryConstraint;
313+
export function startAfter(snapshot: DocumentSnapshot<any>): QueryConstraint;
314+
export function startAfter(...fieldValues: any[]): QueryConstraint;
315+
export function endBefore(snapshot: DocumentSnapshot<any>): QueryConstraint;
316+
export function endBefore(...fieldValues: any[]): QueryConstraint;
317+
export function endAt(snapshot: DocumentSnapshot<any>): QueryConstraint;
318+
export function endAt(...fieldValues: any[]): QueryConstraint;
319+
298320
export class QuerySnapshot<T = DocumentData> {
299321
private constructor();
300322
readonly query: Query<T>;

packages/firestore/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
const karmaBase = require('../../config/karma.base');
1919
const { argv } = require('yargs');
2020

21-
module.exports = function (config) {
21+
module.exports = function(config) {
2222
const karmaConfig = Object.assign({}, karmaBase, {
2323
// files to load into karma
2424
files: getTestFiles(argv),

packages/firestore/lite/index.d.ts

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -228,28 +228,50 @@ export type WhereFilterOp =
228228
export class Query<T = DocumentData> {
229229
protected constructor();
230230
readonly firestore: FirebaseFirestore;
231-
where(
232-
fieldPath: string | FieldPath,
233-
opStr: WhereFilterOp,
234-
value: any
235-
): Query<T>;
236-
orderBy(
237-
fieldPath: string | FieldPath,
238-
directionStr?: OrderByDirection
239-
): Query<T>;
240-
limit(limit: number): Query<T>;
241-
limitToLast(limit: number): Query<T>;
242-
startAt(snapshot: DocumentSnapshot<any>): Query<T>;
243-
startAt(...fieldValues: any[]): Query<T>;
244-
startAfter(snapshot: DocumentSnapshot<any>): Query<T>;
245-
startAfter(...fieldValues: any[]): Query<T>;
246-
endBefore(snapshot: DocumentSnapshot<any>): Query<T>;
247-
endBefore(...fieldValues: any[]): Query<T>;
248-
endAt(snapshot: DocumentSnapshot<any>): Query<T>;
249-
endAt(...fieldValues: any[]): Query<T>;
231+
250232
withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
251233
}
252234

235+
export type QueryConstraintType =
236+
| 'where'
237+
| 'orderBy'
238+
| 'limit'
239+
| 'limitToLast'
240+
| 'startAt'
241+
| 'startAfter'
242+
| 'endAt'
243+
| 'endBefore';
244+
245+
export class QueryConstraint {
246+
private constructor();
247+
readonly type: QueryConstraintType;
248+
}
249+
250+
export function query<T>(
251+
query: CollectionReference<T> | Query<T>,
252+
...constraints: QueryConstraint[]
253+
): Query<T>;
254+
255+
export function where(
256+
fieldPath: string | FieldPath,
257+
opStr: WhereFilterOp,
258+
value: any
259+
): QueryConstraint;
260+
export function orderBy(
261+
fieldPath: string | FieldPath,
262+
directionStr?: OrderByDirection
263+
): QueryConstraint;
264+
export function limit(limit: number): QueryConstraint;
265+
export function limitToLast(limit: number): QueryConstraint;
266+
export function startAt(snapshot: DocumentSnapshot<any>): QueryConstraint;
267+
export function startAt<T>(...fieldValues: any[]): QueryConstraint;
268+
export function startAfter(snapshot: DocumentSnapshot<any>): QueryConstraint;
269+
export function startAfter(...fieldValues: any[]): QueryConstraint;
270+
export function endBefore(snapshot: DocumentSnapshot<any>): QueryConstraint;
271+
export function endBefore(...fieldValues: any[]): QueryConstraint;
272+
export function endAt(snapshot: DocumentSnapshot<any>): QueryConstraint;
273+
export function endAt(...fieldValues: any[]): QueryConstraint;
274+
253275
export class QuerySnapshot<T = DocumentData> {
254276
private constructor();
255277
readonly query: Query<T>;

packages/firestore/lite/index.node.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,17 @@ export {
4242
updateDoc,
4343
addDoc,
4444
refEqual,
45-
queryEqual
45+
queryEqual,
46+
QueryConstraint,
47+
startAt,
48+
startAfter,
49+
endAt,
50+
endBefore,
51+
query,
52+
limit,
53+
limitToLast,
54+
where,
55+
orderBy
4656
} from './src/api/reference';
4757

4858
// TOOD(firestorelite): Add tests when Queries are usable

0 commit comments

Comments
 (0)