Skip to content

s/getQuery/getDocs #3461

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 1 commit into from
Jul 24, 2020
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
6 changes: 3 additions & 3 deletions packages/firestore/exp-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,11 @@ export function getDocFromCache<T>(
export function getDocFromServer<T>(
reference: DocumentReference<T>
): Promise<DocumentSnapshot<T>>;
export function getQuery<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
export function getQueryFromCache<T>(
export function getDocs<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
export function getDocsFromCache<T>(
query: Query<T>
): Promise<QuerySnapshot<T>>;
export function getQueryFromServer<T>(
export function getDocsFromServer<T>(
query: Query<T>
): Promise<QuerySnapshot<T>>;

Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/exp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export {
getDoc,
getDocFromCache,
getDocFromServer,
getQuery,
getQueryFromCache,
getQueryFromServer,
getDocs,
getDocsFromCache,
getDocsFromServer,
onSnapshot,
onSnapshotsInSync,
setDoc,
Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/exp/src/api/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function getDocFromServer<T>(
});
}

export function getQuery<T>(
export function getDocs<T>(
query: firestore.Query<T>
): Promise<QuerySnapshot<T>> {
const internalQuery = cast<Query<T>>(query, Query);
Expand All @@ -127,7 +127,7 @@ export function getQuery<T>(
});
}

export function getQueryFromCache<T>(
export function getDocsFromCache<T>(
query: firestore.Query<T>
): Promise<QuerySnapshot<T>> {
const internalQuery = cast<Query<T>>(query, Query);
Expand All @@ -140,7 +140,7 @@ export function getQueryFromCache<T>(
});
}

export function getQueryFromServer<T>(
export function getDocsFromServer<T>(
query: firestore.Query<T>
): Promise<QuerySnapshot<T>> {
const internalQuery = cast<Query<T>>(query, Query);
Expand Down
12 changes: 6 additions & 6 deletions packages/firestore/exp/test/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import {
getDoc,
getDocFromCache,
getDocFromServer,
getQuery,
getQueryFromCache,
getQueryFromServer,
getDocs,
getDocsFromCache,
getDocsFromServer,
increment,
initializeFirestore,
onSnapshot,
Expand Down Expand Up @@ -519,11 +519,11 @@ export class Query<T = legacy.DocumentData> implements legacy.Query<T> {
get(options?: legacy.GetOptions): Promise<QuerySnapshot<T>> {
let query: Promise<exp.QuerySnapshot<T>>;
if (options?.source === 'cache') {
query = getQueryFromCache(this._delegate);
query = getDocsFromCache(this._delegate);
} else if (options?.source === 'server') {
query = getQueryFromServer(this._delegate);
query = getDocsFromServer(this._delegate);
} else {
query = getQuery(this._delegate);
query = getDocs(this._delegate);
}
return query.then(result => new QuerySnapshot(this.firestore, result));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/lite-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export class CollectionReference<T = DocumentData> extends Query<T> {
export function getDoc<T>(
reference: DocumentReference<T>
): Promise<DocumentSnapshot<T>>;
export function getQuery<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
export function getDocs<T>(query: Query<T>): Promise<QuerySnapshot<T>>;

export function addDoc<T>(
reference: CollectionReference<T>,
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/lite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export {
doc,
parent,
getDoc,
getQuery,
getDocs,
deleteDoc,
setDoc,
updateDoc,
Expand Down
3 changes: 1 addition & 2 deletions packages/firestore/lite/src/api/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,7 @@ export function getDoc<T>(
});
}

// TODO(firestorelite): Consider renaming to getDocs
export function getQuery<T>(
export function getDocs<T>(
query: firestore.Query<T>
): Promise<firestore.QuerySnapshot<T>> {
const internalQuery = cast<Query<T>>(query, Query);
Expand Down
52 changes: 26 additions & 26 deletions packages/firestore/lite/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
refEqual,
queryEqual,
collectionGroup,
getQuery,
getDocs,
orderBy,
startAfter,
query,
Expand Down Expand Up @@ -373,7 +373,7 @@ describe('WriteBatch', () => {
batch.set(doc(coll), { doc: 2 });
await batch.commit();

// TODO(firestorelite): Verify collection contents once getQuery is added
// TODO(firestorelite): Verify collection contents once getDocs is added
});
});

Expand Down Expand Up @@ -780,14 +780,14 @@ describe('Query', () => {

it('supports default query', () => {
return withTestCollectionAndInitialData([{ foo: 1 }], async collRef => {
const result = await getQuery(collRef);
const result = await getDocs(collRef);
verifyResults(result, { foo: 1 });
});
});

it('supports empty results', () => {
return withTestCollectionAndInitialData([], async collRef => {
const result = await getQuery(collRef);
const result = await getDocs(collRef);
verifyResults(result);
});
});
Expand All @@ -797,7 +797,7 @@ describe('Query', () => {
[{ foo: 1 }, { foo: 2 }],
async collRef => {
const query1 = query(collRef, where('foo', '==', 1));
const result = await getQuery(query1);
const result = await getDocs(query1);
verifyResults(result, { foo: 1 });
}
);
Expand All @@ -808,7 +808,7 @@ describe('Query', () => {
[{ foo: 1 }, { foo: 2 }],
async collRef => {
const query1 = query(collRef, where(new FieldPath('foo'), '==', 1));
const result = await getQuery(query1);
const result = await getDocs(query1);
verifyResults(result, { foo: 1 });
}
);
Expand All @@ -819,7 +819,7 @@ describe('Query', () => {
[{ foo: 1 }, { foo: 2 }],
async collRef => {
const query1 = query(collRef, orderBy('foo'));
const result = await getQuery(query1);
const result = await getDocs(query1);
verifyResults(result, { foo: 1 }, { foo: 2 });
}
);
Expand All @@ -830,7 +830,7 @@ describe('Query', () => {
[{ foo: 1 }, { foo: 2 }],
async collRef => {
const query1 = query(collRef, orderBy('foo', 'asc'));
const result = await getQuery(query1);
const result = await getDocs(query1);
verifyResults(result, { foo: 1 }, { foo: 2 });
}
);
Expand All @@ -841,7 +841,7 @@ describe('Query', () => {
[{ foo: 1 }, { foo: 2 }],
async collRef => {
const query1 = query(collRef, orderBy('foo', 'desc'));
const result = await getQuery(query1);
const result = await getDocs(query1);
verifyResults(result, { foo: 2 }, { foo: 1 });
}
);
Expand All @@ -852,7 +852,7 @@ describe('Query', () => {
[{ foo: 1 }, { foo: 2 }],
async collRef => {
const query1 = query(collRef, orderBy('foo'), limit(1));
const result = await getQuery(query1);
const result = await getDocs(query1);
verifyResults(result, { foo: 1 });
}
);
Expand All @@ -863,7 +863,7 @@ describe('Query', () => {
[{ foo: 1 }, { foo: 2 }, { foo: 3 }],
async collRef => {
const query1 = query(collRef, orderBy('foo'), limitToLast(2));
const result = await getQuery(query1);
const result = await getDocs(query1);
verifyResults(result, { foo: 2 }, { foo: 3 });
}
);
Expand All @@ -874,7 +874,7 @@ describe('Query', () => {
[{ foo: 1 }, { foo: 2 }],
async collRef => {
const query1 = query(collRef, orderBy('foo'), startAt(2));
const result = await getQuery(query1);
const result = await getDocs(query1);
verifyResults(result, { foo: 2 });
}
);
Expand All @@ -885,7 +885,7 @@ describe('Query', () => {
[{ foo: 1 }, { foo: 2 }],
async collRef => {
const query1 = query(collRef, orderBy('foo'), startAfter(1));
const result = await getQuery(query1);
const result = await getDocs(query1);
verifyResults(result, { foo: 2 });
}
);
Expand All @@ -896,7 +896,7 @@ describe('Query', () => {
[{ foo: 1 }, { foo: 2 }],
async collRef => {
const query1 = query(collRef, orderBy('foo'), endAt(1));
const result = await getQuery(query1);
const result = await getDocs(query1);
verifyResults(result, { foo: 1 });
}
);
Expand All @@ -907,7 +907,7 @@ describe('Query', () => {
[{ foo: 1 }, { foo: 2 }],
async collRef => {
const query1 = query(collRef, orderBy('foo'), endBefore(2));
const result = await getQuery(query1);
const result = await getDocs(query1);
verifyResults(result, { foo: 1 });
}
);
Expand All @@ -918,12 +918,12 @@ describe('Query', () => {
[{ foo: 1 }, { foo: 2 }],
async collRef => {
let query1 = query(collRef, orderBy('foo'), limit(1));
let result = await getQuery(query1);
let result = await getDocs(query1);
verifyResults(result, { foo: 1 });

// Pass the document snapshot from the previous result
query1 = query(query1, startAfter(result.docs[0]));
result = await getQuery(query1);
result = await getDocs(query1);
verifyResults(result, { foo: 2 });
}
);
Expand All @@ -945,7 +945,7 @@ describe('Query', () => {
await setDoc(barDoc, { bar: 1 });

const query1 = collectionGroup(collRef.firestore, collectionGroupId);
const result = await getQuery(query1);
const result = await getDocs(query1);

verifyResults(result, { bar: 1 }, { foo: 1 });
});
Expand Down Expand Up @@ -1028,16 +1028,16 @@ describe('equality', () => {
const query1b = query(collRef, limit(10));
const query2 = query(collRef, limit(100));

const snap1a = await getQuery(query1a);
const snap1b = await getQuery(query1b);
const snap2 = await getQuery(query2);
const snap1a = await getDocs(query1a);
const snap1b = await getDocs(query1b);
const snap2 = await getDocs(query2);

expect(snapshotEqual(snap1a, snap1b)).to.be.true;
expect(snapshotEqual(snap1a, snap2)).to.be.false;

// Re-run the query with an additional result.
await addDoc(collRef, { foo: 3 });
const snap1c = await getQuery(query1a);
const snap1c = await getDocs(query1a);
expect(snapshotEqual(snap1a, snap1c)).to.be.false;
}
);
Expand All @@ -1047,14 +1047,14 @@ describe('equality', () => {
return withTestCollectionAndInitialData(
[{ foo: 1 }, { foo: 2 }],
async collRef => {
const snap1a = await getQuery(collRef);
const snap1b = await getQuery(collRef);
const snap1a = await getDocs(collRef);
const snap1b = await getDocs(collRef);
expect(snapshotEqual(snap1a.docs[0], snap1b.docs[0])).to.be.true;
expect(snapshotEqual(snap1a.docs[0], snap1a.docs[0])).to.be.true;

// Modify the document and obtain the snapshot again.
await updateDoc(snap1a.docs[0].ref, { foo: 3 });
const snap3 = await getQuery(collRef);
const snap3 = await getDocs(collRef);
expect(snapshotEqual(snap1a.docs[0], snap3.docs[0])).to.be.false;
}
);
Expand Down Expand Up @@ -1088,7 +1088,7 @@ describe('withConverter() support', () => {
return withTestCollection(async coll => {
coll = coll.withConverter(postConverter);
await setDoc(doc(coll, 'post1'), new Post('post1', 'author1'));
const posts = await getQuery(coll);
const posts = await getDocs(coll);
expect(posts.size).to.equal(1);
expect(posts.docs[0].data()!.byline()).to.equal('post1, by author1');
});
Expand Down