Skip to content
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

Overload getAll function to allow array destructuring #515

Merged
merged 8 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ export class Firestore {
* console.log(`Second document: ${JSON.stringify(docs[1])}`);
* });
*/
getAll(...documentRefsOrReadOptions: Array<DocumentReference|ReadOptions>):
cxam marked this conversation as resolved.
Show resolved Hide resolved
Promise<DocumentSnapshot[]>;
getAll(
documentRef: DocumentReference,
...moreDocumentRefsOrReadOptions: Array<DocumentReference|ReadOptions>):
cxam marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 2 additions & 0 deletions dev/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export class Transaction {
* });
* });
*/
getAll(...documentRefsOrReadOptions: Array<DocumentReference|ReadOptions>):
Promise<DocumentSnapshot[]>;
getAll(
documentRef: DocumentReference,
...moreDocumentRefsOrReadOptions: Array<DocumentReference|ReadOptions>):
Expand Down
59 changes: 59 additions & 0 deletions dev/system-test/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ describe('Firestore class', () => {
});
});

it('getAll() supports array destructuring', () => {
const ref1 = randomCol.doc('doc1');
const ref2 = randomCol.doc('doc2');
return Promise.all([ref1.set({foo: 'a'}), ref2.set({foo: 'a'})])
.then(() => {
return firestore.getAll(...[ref1, ref2]);
})
.then(docs => {
expect(docs.length).to.equal(2);
});
});

it('getAll() supports field mask', () => {
const ref1 = randomCol.doc('doc1');
return ref1.set({foo: 'a', bar: 'b'})
Expand All @@ -87,6 +99,19 @@ describe('Firestore class', () => {
expect(docs[0].data()).to.deep.equal({foo: 'a'});
});
});

it('getAll() supports array destructuring with field mask', () => {
const ref1 = randomCol.doc('doc1');
const ref2 = randomCol.doc('doc2');
return Promise.all([ref1.set({f: 'a', b: 'b'}), ref2.set({f: 'a', b: 'b'})])
.then(() => {
return firestore.getAll(...[ref1, ref2], {fieldMask: ['f']});
})
.then(docs => {
expect(docs[0].data()).to.deep.equal({f: 'a'});
expect(docs[1].data()).to.deep.equal({f: 'a'});
});
});
});

describe('CollectionReference class', () => {
Expand Down Expand Up @@ -1383,6 +1408,22 @@ describe('Transaction class', () => {
});
});

it('getAll() supports array destructuring', () => {
const ref1 = randomCol.doc('doc1');
const ref2 = randomCol.doc('doc2');
return Promise.all([ref1.set({}), ref2.set({})])
.then(() => {
return firestore.runTransaction(updateFunction => {
return updateFunction.getAll(...[ref1, ref2]).then(docs => {
return Promise.resolve(docs.length);
});
});
})
.then(res => {
expect(res).to.equal(2);
cxam marked this conversation as resolved.
Show resolved Hide resolved
});
});

it('getAll() supports field mask', () => {
const ref1 = randomCol.doc('doc1');
return ref1.set({foo: 'a', bar: 'b'}).then(() => {
Expand All @@ -1397,6 +1438,24 @@ describe('Transaction class', () => {
});
});

it('getAll() supports array destructuring with field mask', () => {
const ref1 = randomCol.doc('doc1');
const ref2 = randomCol.doc('doc2');
return Promise.all([ref1.set({f: 'a', b: 'b'}), ref2.set({f: 'a', b: 'b'})])
.then(() => {
return firestore.runTransaction(updateFunction => {
return updateFunction.getAll(...[ref1, ref2], {fieldMask: ['f']})
.then(docs => {
expect(docs[0].data()).to.deep.equal({f: 'a'});
expect(docs[1].data()).to.deep.equal({f: 'a'});
});
});
})
.then(res => {
expect(res).to.equal(2);
});
});

it('has get() with query', () => {
const ref = randomCol.doc('doc');
const query = randomCol.where('foo', '==', 'bar');
Expand Down
4 changes: 4 additions & 0 deletions types/firestore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ declare namespace FirebaseFirestore {
* @return A Promise that resolves with an array of resulting document
* snapshots.
*/
getAll(...documentRefsOrReadOptions: Array<DocumentReference|ReadOptions>):
Promise<DocumentSnapshot[]>;
getAll(
documentRef: DocumentReference,
...moreDocumentRefsOrReadOptions: Array<DocumentReference|ReadOptions>
Expand Down Expand Up @@ -266,6 +268,8 @@ declare namespace FirebaseFirestore {
* @return A Promise that resolves with an array of resulting document
* snapshots.
*/
getAll(...documentRefsOrReadOptions: Array<DocumentReference|ReadOptions>):
Promise<DocumentSnapshot[]>;
getAll(
documentRef: DocumentReference,
...moreDocumentRefsOrReadOptions: Array<DocumentReference|ReadOptions>
Expand Down