Skip to content

Commit

Permalink
fix(firestore): implement queryEqual modular API
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehardy committed Feb 17, 2025
1 parent c27ff78 commit ca7b4e3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/firestore/e2e/Query/isEqual.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ describe('firestore().collection().isEqual()', function () {

it('returns false when not equal (simple checks)', function () {
const { getApp } = modular;
const { getFirestore, collection, query, where, orderBy, limit } = firestoreModular;
const { getFirestore, collection, query, where, orderBy, limit, queryEqual } =
firestoreModular;
const db = getFirestore();
const secondaryDb = getFirestore(getApp('secondaryFromNative'));

Expand All @@ -167,11 +168,11 @@ describe('firestore().collection().isEqual()', function () {
const ref1 = query(collection(db, subCol), where('bar', '==', true));
const ref2 = query(collection(db, subCol), where('bar', '==', true));

const eql1 = queryRef.isEqual(q1);
const eql2 = queryRef.isEqual(q2);
const eql3 = queryRef.isEqual(q3);
const eql4 = queryRef.isEqual(q4);
const eql5 = ref1.isEqual(ref2);
const eql1 = queryEqual(queryRef, q1);
const eql2 = queryEqual(queryRef, q2);
const eql3 = queryEqual(queryRef, q3);
const eql4 = queryEqual(queryRef, q4);
const eql5 = queryEqual(ref1, ref2);

eql1.should.be.False();
eql2.should.be.False();
Expand Down
9 changes: 9 additions & 0 deletions packages/firestore/lib/modular/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,12 @@ export function getDocsFromServer(query) {
export function deleteDoc(reference) {
return reference.delete.call(reference, MODULAR_DEPRECATION_ARG);
}

/**
* @param {Query} left
* @param {Query} right
* @returns boolean true if left equals right
*/
export function queryEqual(left, right) {

Check warning on line 233 in packages/firestore/lib/modular/query.js

View check run for this annotation

Codecov / codecov/patch

packages/firestore/lib/modular/query.js#L233

Added line #L233 was not covered by tests
return left.isEqual.call(left, right, MODULAR_DEPRECATION_ARG);
}
13 changes: 13 additions & 0 deletions packages/firestore/lib/modular/snapshot.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,16 @@ export function snapshotEqual<AppModelType, DbModelType extends DocumentData>(
left: DocumentSnapshot<AppModelType, DbModelType> | QuerySnapshot<AppModelType, DbModelType>,
right: DocumentSnapshot<AppModelType, DbModelType> | QuerySnapshot<AppModelType, DbModelType>,
): boolean;

/**
* Returns true if the provided queries point to the same collection and apply the same constraints.
*
* @param left Query<AppModelType, DbModelType> A Query to compare.
* @param right Query<AppModelType, DbModelType> A Query to compare.
*
* @return boolean true if the references point to the same location in the same Firestore database.
*/
export declare function queryEqual<AppModelType, DbModelType extends DocumentData>(
left: Query<AppModelType, DbModelType>,
right: Query<AppModelType, DbModelType>,
): boolean;

0 comments on commit ca7b4e3

Please sign in to comment.