diff --git a/dev/src/index.js b/dev/src/index.js index 9da190fb1..12bd64d5e 100644 --- a/dev/src/index.js +++ b/dev/src/index.js @@ -591,15 +591,28 @@ class Firestore { * with an array of CollectionReferences. * * @example - * firestore.getCollections().then(collections => { + * firestore.listCollections().then(collections => { * for (let collection of collections) { * console.log(`Found collection with id: ${collection.id}`); * } * }); */ + listCollections() { + const rootDocument = new DocumentReference(this, this._referencePath); + return rootDocument.listCollections(); + } + + /** + * Fetches the root collections that are associated with this Firestore + * database. + * + * @deprecated Use `.listCollections()`. + * + * @returns {Promise.>} A Promise that resolves + * with an array of CollectionReferences. + */ getCollections() { - let rootDocument = new DocumentReference(this, this._referencePath); - return rootDocument.getCollections(); + return this.listCollections(); } /** diff --git a/dev/src/reference.ts b/dev/src/reference.ts index 665346eb7..1999175d8 100644 --- a/dev/src/reference.ts +++ b/dev/src/reference.ts @@ -254,13 +254,13 @@ export class DocumentReference { * @example * let documentRef = firestore.doc('col/doc'); * - * documentRef.getCollections().then(collections => { + * documentRef.listCollections().then(collections => { * for (let collection of collections) { * console.log(`Found subcollection with id: ${collection.id}`); * } * }); */ - getCollections(): Promise { + listCollections(): Promise { const request = {parent: this._path.formattedName}; return this._firestore.request('listCollectionIds', request, requestTag()) @@ -279,6 +279,18 @@ export class DocumentReference { }); } + /** + * Fetches the subcollections that are direct children of this document. + * + * @deprecated Use `.listCollections()`. + * + * @returns {Promise.>} A Promise that resolves + * with an array of CollectionReferences. + */ + getCollections(): Promise { + return this.listCollections(); + } + /** * Create a document with the provided object values. This will fail the write * if a document exists at its location. diff --git a/dev/system-test/firestore.ts b/dev/system-test/firestore.ts index 27ca815a7..e1e422dce 100644 --- a/dev/system-test/firestore.ts +++ b/dev/system-test/firestore.ts @@ -424,7 +424,7 @@ describe('DocumentReference class', function() { }); }); - it('has getCollections() method', function() { + it('has listCollections() method', function() { let collections = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']; let promises : Promise<{}>[] = []; @@ -434,7 +434,7 @@ describe('DocumentReference class', function() { return Promise.all(promises) .then(() => { - return randomCol.doc('doc').getCollections(); + return randomCol.doc('doc').listCollections(); }) .then(response => { assert.equal(response.length, collections.length); diff --git a/dev/test/document.js b/dev/test/document.js index a84557b54..8aeae73b5 100644 --- a/dev/test/document.js +++ b/dev/test/document.js @@ -1762,7 +1762,7 @@ describe('update document', function() { }); }); -describe('getCollections() method', function() { +describe('listCollections() method', function() { it('sorts results', function() { const overrides = { listCollectionIds: (request, options, callback) => { @@ -1776,6 +1776,7 @@ describe('getCollections() method', function() { }; return createInstance(overrides).then(firestore => { + // We are using `getCollections()` to ensure 100% code coverage return firestore.doc('coll/doc').getCollections().then(collections => { assert.equal(collections[0].path, 'coll/doc/first'); assert.equal(collections[1].path, 'coll/doc/second'); diff --git a/dev/test/index.js b/dev/test/index.js index a406e5305..84ca8d876 100644 --- a/dev/test/index.js +++ b/dev/test/index.js @@ -703,7 +703,7 @@ describe('collection() method', function() { }); }); -describe('getCollections() method', function() { +describe('listCollections() method', function() { it('returns collections', function() { const overrides = { listCollectionIds: (request, options, callback) => { @@ -716,6 +716,7 @@ describe('getCollections() method', function() { }; return createInstance(overrides).then(firestore => { + // We are using `getCollections()` to ensure 100% code coverage return firestore.getCollections().then(collections => { assert.equal(collections[0].path, 'first'); assert.equal(collections[1].path, 'second'); diff --git a/dev/test/typescript.ts b/dev/test/typescript.ts index 983e26041..cc12868f3 100644 --- a/dev/test/typescript.ts +++ b/dev/test/typescript.ts @@ -67,6 +67,8 @@ xdescribe('firestore.d.ts', function() { }); firestore.getCollections().then((collections:CollectionReference[]) => { }); + firestore.listCollections().then((collections:CollectionReference[]) => { + }); const transactionResult: Promise = firestore.runTransaction( (updateFunction: Transaction) => { return Promise.resolve("string") @@ -144,6 +146,8 @@ xdescribe('firestore.d.ts', function() { const subcollection: CollectionReference = docRef.collection('coll'); docRef.getCollections().then((collections:CollectionReference[]) => { }); + docRef.listCollections().then((collections:CollectionReference[]) => { + }); docRef.get().then((snapshot: DocumentSnapshot) => { }); docRef.create(documentData).then( diff --git a/types/firestore.d.ts b/types/firestore.d.ts index 5b8a6a148..a55a23067 100644 --- a/types/firestore.d.ts +++ b/types/firestore.d.ts @@ -135,10 +135,20 @@ declare namespace FirebaseFirestore { * Fetches the root collections that are associated with this Firestore * database. * + * @deprecated Use `.listCollections()`. + * * @returns A Promise that resolves with an array of CollectionReferences. */ getCollections() : Promise; + /** + * Fetches the root collections that are associated with this Firestore + * database. + * + * @returns A Promise that resolves with an array of CollectionReferences. + */ + listCollections() : Promise; + /** * Executes the given updateFunction and commits the changes applied within * the transaction. @@ -501,10 +511,19 @@ declare namespace FirebaseFirestore { /** * Fetches the subcollections that are direct children of this document. * + * @deprecated Use `.listCollections()`. + * * @returns A Promise that resolves with an array of CollectionReferences. */ getCollections() : Promise; + /** + * Fetches the subcollections that are direct children of this document. + * + * @returns A Promise that resolves with an array of CollectionReferences. + */ + listCollections() : Promise; + /** * Creates a document referred to by this `DocumentReference` with the * provided object values. The write fails if the document already exists